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 memset(&reply, 0, sizeof(reply));
281 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid, &cmd, sizeof(cmd),
282 WMI_NOTIFY_REQ_DONE_EVENTID, &reply, sizeof(reply), 20);
286 wil_dbg_wmi(wil, "Link status for CID %d MID %d: {\n"
287 " MCS %d TSF 0x%016llx\n"
288 " BF status 0x%08x RSSI %d SQI %d%%\n"
289 " Tx Tpt %d goodput %d Rx goodput %d\n"
290 " Sectors(rx:tx) my %d:%d peer %d:%d\n""}\n",
291 cid, vif->mid, le16_to_cpu(reply.evt.bf_mcs),
292 le64_to_cpu(reply.evt.tsf), reply.evt.status,
295 le32_to_cpu(reply.evt.tx_tpt),
296 le32_to_cpu(reply.evt.tx_goodput),
297 le32_to_cpu(reply.evt.rx_goodput),
298 le16_to_cpu(reply.evt.my_rx_sector),
299 le16_to_cpu(reply.evt.my_tx_sector),
300 le16_to_cpu(reply.evt.other_rx_sector),
301 le16_to_cpu(reply.evt.other_tx_sector));
303 sinfo->generation = wil->sinfo_gen;
305 sinfo->filled = BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
306 BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
307 BIT_ULL(NL80211_STA_INFO_RX_PACKETS) |
308 BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
309 BIT_ULL(NL80211_STA_INFO_RX_BITRATE) |
310 BIT_ULL(NL80211_STA_INFO_TX_BITRATE) |
311 BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC) |
312 BIT_ULL(NL80211_STA_INFO_TX_FAILED);
314 sinfo->txrate.flags = RATE_INFO_FLAGS_60G;
315 sinfo->txrate.mcs = le16_to_cpu(reply.evt.bf_mcs);
316 sinfo->rxrate.mcs = stats->last_mcs_rx;
317 sinfo->rx_bytes = stats->rx_bytes;
318 sinfo->rx_packets = stats->rx_packets;
319 sinfo->rx_dropped_misc = stats->rx_dropped;
320 sinfo->tx_bytes = stats->tx_bytes;
321 sinfo->tx_packets = stats->tx_packets;
322 sinfo->tx_failed = stats->tx_errors;
324 if (test_bit(wil_vif_fwconnected, vif->status)) {
325 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
326 if (test_bit(WMI_FW_CAPABILITY_RSSI_REPORTING,
327 wil->fw_capabilities))
328 sinfo->signal = reply.evt.rssi;
330 sinfo->signal = reply.evt.sqi;
336 static int wil_cfg80211_get_station(struct wiphy *wiphy,
337 struct net_device *ndev,
338 const u8 *mac, struct station_info *sinfo)
340 struct wil6210_vif *vif = ndev_to_vif(ndev);
341 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
344 int cid = wil_find_cid(wil, vif->mid, mac);
346 wil_dbg_misc(wil, "get_station: %pM CID %d MID %d\n", mac, cid,
351 rc = wil_cid_fill_sinfo(vif, cid, sinfo);
357 * Find @idx-th active STA for specific MID for station dump.
359 static int wil_find_cid_by_idx(struct wil6210_priv *wil, u8 mid, int idx)
363 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
364 if (wil->sta[i].status == wil_sta_unused)
366 if (wil->sta[i].mid != mid)
376 static int wil_cfg80211_dump_station(struct wiphy *wiphy,
377 struct net_device *dev, int idx,
378 u8 *mac, struct station_info *sinfo)
380 struct wil6210_vif *vif = ndev_to_vif(dev);
381 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
383 int cid = wil_find_cid_by_idx(wil, vif->mid, idx);
388 ether_addr_copy(mac, wil->sta[cid].addr);
389 wil_dbg_misc(wil, "dump_station: %pM CID %d MID %d\n", mac, cid,
392 rc = wil_cid_fill_sinfo(vif, cid, sinfo);
397 static int wil_cfg80211_start_p2p_device(struct wiphy *wiphy,
398 struct wireless_dev *wdev)
400 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
402 wil_dbg_misc(wil, "start_p2p_device: entered\n");
403 wil->p2p_dev_started = 1;
407 static void wil_cfg80211_stop_p2p_device(struct wiphy *wiphy,
408 struct wireless_dev *wdev)
410 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
412 if (!wil->p2p_dev_started)
415 wil_dbg_misc(wil, "stop_p2p_device: entered\n");
416 mutex_lock(&wil->mutex);
417 mutex_lock(&wil->vif_mutex);
418 wil_p2p_stop_radio_operations(wil);
419 wil->p2p_dev_started = 0;
420 mutex_unlock(&wil->vif_mutex);
421 mutex_unlock(&wil->mutex);
424 static int wil_cfg80211_validate_add_iface(struct wil6210_priv *wil,
425 enum nl80211_iftype new_type)
428 struct wireless_dev *wdev;
429 struct iface_combination_params params = {
430 .num_different_channels = 1,
433 for (i = 0; i < wil->max_vifs; i++) {
435 wdev = vif_to_wdev(wil->vifs[i]);
436 params.iftype_num[wdev->iftype]++;
439 params.iftype_num[new_type]++;
440 return cfg80211_check_combinations(wil->wiphy, ¶ms);
443 static int wil_cfg80211_validate_change_iface(struct wil6210_priv *wil,
444 struct wil6210_vif *vif,
445 enum nl80211_iftype new_type)
448 struct wireless_dev *wdev;
449 struct iface_combination_params params = {
450 .num_different_channels = 1,
452 bool check_combos = false;
454 for (i = 0; i < wil->max_vifs; i++) {
455 struct wil6210_vif *vif_pos = wil->vifs[i];
457 if (vif_pos && vif != vif_pos) {
458 wdev = vif_to_wdev(vif_pos);
459 params.iftype_num[wdev->iftype]++;
465 params.iftype_num[new_type]++;
466 ret = cfg80211_check_combinations(wil->wiphy, ¶ms);
471 static struct wireless_dev *
472 wil_cfg80211_add_iface(struct wiphy *wiphy, const char *name,
473 unsigned char name_assign_type,
474 enum nl80211_iftype type,
475 struct vif_params *params)
477 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
478 struct net_device *ndev_main = wil->main_ndev, *ndev;
479 struct wil6210_vif *vif;
480 struct wireless_dev *p2p_wdev, *wdev;
483 wil_dbg_misc(wil, "add_iface, type %d\n", type);
485 /* P2P device is not a real virtual interface, it is a management-only
486 * interface that shares the main interface.
487 * Skip concurrency checks here.
489 if (type == NL80211_IFTYPE_P2P_DEVICE) {
491 wil_err(wil, "P2P_DEVICE interface already created\n");
492 return ERR_PTR(-EINVAL);
495 p2p_wdev = kzalloc(sizeof(*p2p_wdev), GFP_KERNEL);
497 return ERR_PTR(-ENOMEM);
499 p2p_wdev->iftype = type;
500 p2p_wdev->wiphy = wiphy;
501 /* use our primary ethernet address */
502 ether_addr_copy(p2p_wdev->address, ndev_main->perm_addr);
504 wil->p2p_wdev = p2p_wdev;
509 if (!wil->wiphy->n_iface_combinations) {
510 wil_err(wil, "virtual interfaces not supported\n");
511 return ERR_PTR(-EINVAL);
514 rc = wil_cfg80211_validate_add_iface(wil, type);
516 wil_err(wil, "iface validation failed, err=%d\n", rc);
520 vif = wil_vif_alloc(wil, name, name_assign_type, type);
522 return ERR_CAST(vif);
524 ndev = vif_to_ndev(vif);
525 ether_addr_copy(ndev->perm_addr, ndev_main->perm_addr);
526 if (is_valid_ether_addr(params->macaddr)) {
527 ether_addr_copy(ndev->dev_addr, params->macaddr);
529 ether_addr_copy(ndev->dev_addr, ndev_main->perm_addr);
530 ndev->dev_addr[0] = (ndev->dev_addr[0] ^ (1 << vif->mid)) |
531 0x2; /* locally administered */
533 wdev = vif_to_wdev(vif);
534 ether_addr_copy(wdev->address, ndev->dev_addr);
536 rc = wil_vif_add(wil, vif);
540 wil_info(wil, "added VIF, mid %d iftype %d MAC %pM\n",
541 vif->mid, type, wdev->address);
548 int wil_vif_prepare_stop(struct wil6210_vif *vif)
550 struct wil6210_priv *wil = vif_to_wil(vif);
551 struct wireless_dev *wdev = vif_to_wdev(vif);
552 struct net_device *ndev;
555 if (wdev->iftype != NL80211_IFTYPE_AP)
558 ndev = vif_to_ndev(vif);
559 if (netif_carrier_ok(ndev)) {
560 rc = wmi_pcp_stop(vif);
562 wil_info(wil, "failed to stop AP, status %d\n",
567 netif_carrier_off(ndev);
573 static int wil_cfg80211_del_iface(struct wiphy *wiphy,
574 struct wireless_dev *wdev)
576 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
577 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
580 wil_dbg_misc(wil, "del_iface\n");
582 if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE) {
583 if (wdev != wil->p2p_wdev) {
584 wil_err(wil, "delete of incorrect interface 0x%p\n",
589 wil_cfg80211_stop_p2p_device(wiphy, wdev);
590 wil_p2p_wdev_free(wil);
595 wil_err(wil, "cannot remove the main interface\n");
599 rc = wil_vif_prepare_stop(vif);
603 wil_info(wil, "deleted VIF, mid %d iftype %d MAC %pM\n",
604 vif->mid, wdev->iftype, wdev->address);
606 wil_vif_remove(wil, vif->mid);
611 static int wil_cfg80211_change_iface(struct wiphy *wiphy,
612 struct net_device *ndev,
613 enum nl80211_iftype type,
614 struct vif_params *params)
616 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
617 struct wil6210_vif *vif = ndev_to_vif(ndev);
618 struct wireless_dev *wdev = vif_to_wdev(vif);
620 bool fw_reset = false;
622 wil_dbg_misc(wil, "change_iface: type=%d\n", type);
624 if (wiphy->n_iface_combinations) {
625 rc = wil_cfg80211_validate_change_iface(wil, vif, type);
627 wil_err(wil, "iface validation failed, err=%d\n", rc);
632 /* do not reset FW when there are active VIFs,
633 * because it can cause significant disruption
635 if (!wil_has_other_active_ifaces(wil, ndev, true, false) &&
636 netif_running(ndev) && !wil_is_recovery_blocked(wil)) {
637 wil_dbg_misc(wil, "interface is up. resetting...\n");
638 mutex_lock(&wil->mutex);
641 mutex_unlock(&wil->mutex);
649 case NL80211_IFTYPE_STATION:
650 case NL80211_IFTYPE_AP:
651 case NL80211_IFTYPE_P2P_CLIENT:
652 case NL80211_IFTYPE_P2P_GO:
654 case NL80211_IFTYPE_MONITOR:
656 wil->monitor_flags = params->flags;
662 if (vif->mid != 0 && wil_has_active_ifaces(wil, true, false)) {
664 wil_vif_prepare_stop(vif);
665 rc = wmi_port_delete(wil, vif->mid);
668 rc = wmi_port_allocate(wil, vif->mid, ndev->dev_addr, type);
677 static int wil_cfg80211_scan(struct wiphy *wiphy,
678 struct cfg80211_scan_request *request)
680 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
681 struct wireless_dev *wdev = request->wdev;
682 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
684 struct wmi_start_scan_cmd cmd;
690 wil_dbg_misc(wil, "scan: wdev=0x%p iftype=%d\n", wdev, wdev->iftype);
692 /* scan is supported on client interfaces and on AP interface */
693 switch (wdev->iftype) {
694 case NL80211_IFTYPE_STATION:
695 case NL80211_IFTYPE_P2P_CLIENT:
696 case NL80211_IFTYPE_P2P_DEVICE:
697 case NL80211_IFTYPE_AP:
703 /* FW don't support scan after connection attempt */
704 if (test_bit(wil_status_dontscan, wil->status)) {
705 wil_err(wil, "Can't scan now\n");
709 mutex_lock(&wil->mutex);
711 mutex_lock(&wil->vif_mutex);
712 if (vif->scan_request || vif->p2p.discovery_started) {
713 wil_err(wil, "Already scanning\n");
714 mutex_unlock(&wil->vif_mutex);
718 mutex_unlock(&wil->vif_mutex);
720 if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE) {
721 if (!wil->p2p_dev_started) {
722 wil_err(wil, "P2P search requested on stopped P2P device\n");
726 /* social scan on P2P_DEVICE is handled as p2p search */
727 if (wil_p2p_is_social_scan(request)) {
728 vif->scan_request = request;
730 wil->radio_wdev = wdev;
731 rc = wil_p2p_search(vif, request);
735 wil->main_ndev->ieee80211_ptr;
736 vif->scan_request = NULL;
742 (void)wil_p2p_stop_discovery(vif);
744 wil_dbg_misc(wil, "Start scan_request 0x%p\n", request);
745 wil_dbg_misc(wil, "SSID count: %d", request->n_ssids);
747 for (i = 0; i < request->n_ssids; i++) {
748 wil_dbg_misc(wil, "SSID[%d]", i);
749 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
750 request->ssids[i].ssid,
751 request->ssids[i].ssid_len, true);
754 if (request->n_ssids)
755 rc = wmi_set_ssid(vif, request->ssids[0].ssid_len,
756 request->ssids[0].ssid);
758 rc = wmi_set_ssid(vif, 0, NULL);
761 wil_err(wil, "set SSID for scan request failed: %d\n", rc);
765 vif->scan_request = request;
766 mod_timer(&vif->scan_timer, jiffies + WIL6210_SCAN_TO);
768 memset(&cmd, 0, sizeof(cmd));
769 cmd.cmd.scan_type = WMI_ACTIVE_SCAN;
770 cmd.cmd.num_channels = 0;
771 n = min(request->n_channels, 4U);
772 for (i = 0; i < n; i++) {
773 int ch = request->channels[i]->hw_value;
777 "Scan requested for unknown frequency %dMhz\n",
778 request->channels[i]->center_freq);
781 /* 0-based channel indexes */
782 cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1;
783 wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch,
784 request->channels[i]->center_freq);
788 wil_hex_dump_misc("Scan IE ", DUMP_PREFIX_OFFSET, 16, 1,
789 request->ie, request->ie_len, true);
791 wil_dbg_misc(wil, "Scan has no IE's\n");
793 rc = wmi_set_ie(vif, WMI_FRAME_PROBE_REQ,
794 request->ie_len, request->ie);
798 if (wil->discovery_mode && cmd.cmd.scan_type == WMI_ACTIVE_SCAN) {
799 cmd.cmd.discovery_mode = 1;
800 wil_dbg_misc(wil, "active scan with discovery_mode=1\n");
804 wil->radio_wdev = wdev;
805 rc = wmi_send(wil, WMI_START_SCAN_CMDID, vif->mid,
806 &cmd, sizeof(cmd.cmd) +
807 cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
811 del_timer_sync(&vif->scan_timer);
813 wil->radio_wdev = wil->main_ndev->ieee80211_ptr;
814 vif->scan_request = NULL;
817 mutex_unlock(&wil->mutex);
821 static void wil_cfg80211_abort_scan(struct wiphy *wiphy,
822 struct wireless_dev *wdev)
824 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
825 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
827 wil_dbg_misc(wil, "wdev=0x%p iftype=%d\n", wdev, wdev->iftype);
829 mutex_lock(&wil->mutex);
830 mutex_lock(&wil->vif_mutex);
832 if (!vif->scan_request)
835 if (wdev != vif->scan_request->wdev) {
836 wil_dbg_misc(wil, "abort scan was called on the wrong iface\n");
840 if (wdev == wil->p2p_wdev && wil->radio_wdev == wil->p2p_wdev)
841 wil_p2p_stop_radio_operations(wil);
843 wil_abort_scan(vif, true);
846 mutex_unlock(&wil->vif_mutex);
847 mutex_unlock(&wil->mutex);
850 static void wil_print_crypto(struct wil6210_priv *wil,
851 struct cfg80211_crypto_settings *c)
855 wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n",
856 c->wpa_versions, c->cipher_group);
857 wil_dbg_misc(wil, "Pairwise ciphers [%d] {\n", c->n_ciphers_pairwise);
858 n = min_t(int, c->n_ciphers_pairwise, ARRAY_SIZE(c->ciphers_pairwise));
859 for (i = 0; i < n; i++)
860 wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
861 c->ciphers_pairwise[i]);
862 wil_dbg_misc(wil, "}\n");
863 wil_dbg_misc(wil, "AKM suites [%d] {\n", c->n_akm_suites);
864 n = min_t(int, c->n_akm_suites, ARRAY_SIZE(c->akm_suites));
865 for (i = 0; i < n; i++)
866 wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
868 wil_dbg_misc(wil, "}\n");
869 wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n",
870 c->control_port, be16_to_cpu(c->control_port_ethertype),
871 c->control_port_no_encrypt);
874 static void wil_print_connect_params(struct wil6210_priv *wil,
875 struct cfg80211_connect_params *sme)
877 wil_info(wil, "Connecting to:\n");
879 wil_info(wil, " Channel: %d freq %d\n",
880 sme->channel->hw_value, sme->channel->center_freq);
883 wil_info(wil, " BSSID: %pM\n", sme->bssid);
885 print_hex_dump(KERN_INFO, " SSID: ", DUMP_PREFIX_OFFSET,
886 16, 1, sme->ssid, sme->ssid_len, true);
887 wil_info(wil, " Privacy: %s\n", sme->privacy ? "secure" : "open");
888 wil_info(wil, " PBSS: %d\n", sme->pbss);
889 wil_print_crypto(wil, &sme->crypto);
892 static int wil_cfg80211_connect(struct wiphy *wiphy,
893 struct net_device *ndev,
894 struct cfg80211_connect_params *sme)
896 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
897 struct wil6210_vif *vif = ndev_to_vif(ndev);
898 struct cfg80211_bss *bss;
899 struct wmi_connect_cmd conn;
904 enum ieee80211_bss_type bss_type = IEEE80211_BSS_TYPE_ESS;
906 wil_dbg_misc(wil, "connect, mid=%d\n", vif->mid);
907 wil_print_connect_params(wil, sme);
909 if (test_bit(wil_vif_fwconnecting, vif->status) ||
910 test_bit(wil_vif_fwconnected, vif->status))
913 if (sme->ie_len > WMI_MAX_IE_LEN) {
914 wil_err(wil, "IE too large (%td bytes)\n", sme->ie_len);
919 cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
921 if (sme->privacy && !rsn_eid)
922 wil_info(wil, "WSC connection\n");
925 bss_type = IEEE80211_BSS_TYPE_PBSS;
927 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
928 sme->ssid, sme->ssid_len,
929 bss_type, IEEE80211_PRIVACY_ANY);
931 wil_err(wil, "Unable to find BSS\n");
935 ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
937 wil_err(wil, "No SSID\n");
941 vif->privacy = sme->privacy;
942 vif->pbss = sme->pbss;
945 /* For secure assoc, remove old keys */
946 rc = wmi_del_cipher_key(vif, 0, bss->bssid,
947 WMI_KEY_USE_PAIRWISE);
949 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(PTK) failed\n");
952 rc = wmi_del_cipher_key(vif, 0, bss->bssid,
953 WMI_KEY_USE_RX_GROUP);
955 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(GTK) failed\n");
960 /* WMI_SET_APPIE_CMD. ie may contain rsn info as well as other info
961 * elements. Send it also in case it's empty, to erase previously set
964 rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
968 /* WMI_CONNECT_CMD */
969 memset(&conn, 0, sizeof(conn));
970 switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
971 case WLAN_CAPABILITY_DMG_TYPE_AP:
972 conn.network_type = WMI_NETTYPE_INFRA;
974 case WLAN_CAPABILITY_DMG_TYPE_PBSS:
975 conn.network_type = WMI_NETTYPE_P2P;
978 wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
983 if (rsn_eid) { /* regular secure connection */
984 conn.dot11_auth_mode = WMI_AUTH11_SHARED;
985 conn.auth_mode = WMI_AUTH_WPA2_PSK;
986 conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
987 conn.pairwise_crypto_len = 16;
988 conn.group_crypto_type = WMI_CRYPT_AES_GCMP;
989 conn.group_crypto_len = 16;
991 conn.dot11_auth_mode = WMI_AUTH11_WSC;
992 conn.auth_mode = WMI_AUTH_NONE;
994 } else { /* insecure connection */
995 conn.dot11_auth_mode = WMI_AUTH11_OPEN;
996 conn.auth_mode = WMI_AUTH_NONE;
999 conn.ssid_len = min_t(u8, ssid_eid[1], 32);
1000 memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
1002 ch = bss->channel->hw_value;
1004 wil_err(wil, "BSS at unknown frequency %dMhz\n",
1005 bss->channel->center_freq);
1009 conn.channel = ch - 1;
1011 ether_addr_copy(conn.bssid, bss->bssid);
1012 ether_addr_copy(conn.dst_mac, bss->bssid);
1014 set_bit(wil_vif_fwconnecting, vif->status);
1016 rc = wmi_send(wil, WMI_CONNECT_CMDID, vif->mid, &conn, sizeof(conn));
1018 netif_carrier_on(ndev);
1019 if (!wil_has_other_active_ifaces(wil, ndev, false, true))
1020 wil6210_bus_request(wil, WIL_MAX_BUS_REQUEST_KBPS);
1022 /* Connect can take lots of time */
1023 mod_timer(&vif->connect_timer,
1024 jiffies + msecs_to_jiffies(5000));
1026 clear_bit(wil_vif_fwconnecting, vif->status);
1030 cfg80211_put_bss(wiphy, bss);
1035 static int wil_cfg80211_disconnect(struct wiphy *wiphy,
1036 struct net_device *ndev,
1040 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1041 struct wil6210_vif *vif = ndev_to_vif(ndev);
1043 wil_dbg_misc(wil, "disconnect: reason=%d, mid=%d\n",
1044 reason_code, vif->mid);
1046 if (!(test_bit(wil_vif_fwconnecting, vif->status) ||
1047 test_bit(wil_vif_fwconnected, vif->status))) {
1048 wil_err(wil, "Disconnect was called while disconnected\n");
1052 vif->locally_generated_disc = true;
1053 rc = wmi_call(wil, WMI_DISCONNECT_CMDID, vif->mid, NULL, 0,
1054 WMI_DISCONNECT_EVENTID, NULL, 0,
1055 WIL6210_DISCONNECT_TO_MS);
1057 wil_err(wil, "disconnect error %d\n", rc);
1062 static int wil_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1064 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1067 /* these parameters are explicitly not supported */
1068 if (changed & (WIPHY_PARAM_RETRY_LONG |
1069 WIPHY_PARAM_FRAG_THRESHOLD |
1070 WIPHY_PARAM_RTS_THRESHOLD))
1073 if (changed & WIPHY_PARAM_RETRY_SHORT) {
1074 rc = wmi_set_mgmt_retry(wil, wiphy->retry_short);
1082 int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
1083 struct cfg80211_mgmt_tx_params *params,
1086 const u8 *buf = params->buf;
1087 size_t len = params->len;
1088 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1089 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
1093 wil_dbg_misc(wil, "mgmt_tx: channel %d offchan %d, wait %d\n",
1094 params->chan ? params->chan->hw_value : -1,
1098 /* Note, currently we support the "wait" parameter only on AP mode.
1099 * In other modes, user-space must call remain_on_channel before
1100 * mgmt_tx or listen on a channel other than active one.
1103 if (params->chan && params->chan->hw_value == 0) {
1104 wil_err(wil, "invalid channel\n");
1108 if (wdev->iftype != NL80211_IFTYPE_AP) {
1110 "send WMI_SW_TX_REQ_CMDID on non-AP interfaces\n");
1111 rc = wmi_mgmt_tx(vif, buf, len);
1115 if (!params->chan || params->chan->hw_value == vif->channel) {
1117 "send WMI_SW_TX_REQ_CMDID for on-channel\n");
1118 rc = wmi_mgmt_tx(vif, buf, len);
1122 if (params->offchan == 0) {
1124 "invalid channel params: current %d requested %d, off-channel not allowed\n",
1125 vif->channel, params->chan->hw_value);
1129 /* use the wmi_mgmt_tx_ext only on AP mode and off-channel */
1130 rc = wmi_mgmt_tx_ext(vif, buf, len, params->chan->hw_value,
1134 /* when the sent packet was not acked by receiver(ACK=0), rc will
1135 * be -EAGAIN. In this case this function needs to return success,
1136 * the ACK=0 will be reflected in tx_status.
1138 tx_status = (rc == 0);
1139 rc = (rc == -EAGAIN) ? 0 : rc;
1140 cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len,
1141 tx_status, GFP_KERNEL);
1146 static int wil_cfg80211_set_channel(struct wiphy *wiphy,
1147 struct cfg80211_chan_def *chandef)
1149 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1151 wil->monitor_chandef = *chandef;
1156 static enum wmi_key_usage wil_detect_key_usage(struct wireless_dev *wdev,
1159 struct wil6210_priv *wil = wdev_to_wil(wdev);
1160 enum wmi_key_usage rc;
1163 rc = WMI_KEY_USE_PAIRWISE;
1165 switch (wdev->iftype) {
1166 case NL80211_IFTYPE_STATION:
1167 case NL80211_IFTYPE_P2P_CLIENT:
1168 rc = WMI_KEY_USE_RX_GROUP;
1170 case NL80211_IFTYPE_AP:
1171 case NL80211_IFTYPE_P2P_GO:
1172 rc = WMI_KEY_USE_TX_GROUP;
1175 /* TODO: Rx GTK or Tx GTK? */
1176 wil_err(wil, "Can't determine GTK type\n");
1177 rc = WMI_KEY_USE_RX_GROUP;
1181 wil_dbg_misc(wil, "detect_key_usage: -> %s\n", key_usage_str[rc]);
1186 static struct wil_sta_info *
1187 wil_find_sta_by_key_usage(struct wil6210_priv *wil, u8 mid,
1188 enum wmi_key_usage key_usage, const u8 *mac_addr)
1192 if (key_usage == WMI_KEY_USE_TX_GROUP)
1193 return NULL; /* not needed */
1195 /* supplicant provides Rx group key in STA mode with NULL MAC address */
1197 cid = wil_find_cid(wil, mid, mac_addr);
1198 else if (key_usage == WMI_KEY_USE_RX_GROUP)
1199 cid = wil_find_cid_by_idx(wil, mid, 0);
1201 wil_err(wil, "No CID for %pM %s\n", mac_addr,
1202 key_usage_str[key_usage]);
1203 return ERR_PTR(cid);
1206 return &wil->sta[cid];
1209 static void wil_set_crypto_rx(u8 key_index, enum wmi_key_usage key_usage,
1210 struct wil_sta_info *cs,
1211 struct key_params *params)
1213 struct wil_tid_crypto_rx_single *cc;
1219 switch (key_usage) {
1220 case WMI_KEY_USE_PAIRWISE:
1221 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1222 cc = &cs->tid_crypto_rx[tid].key_id[key_index];
1224 memcpy(cc->pn, params->seq,
1225 IEEE80211_GCMP_PN_LEN);
1227 memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
1231 case WMI_KEY_USE_RX_GROUP:
1232 cc = &cs->group_crypto_rx.key_id[key_index];
1234 memcpy(cc->pn, params->seq, IEEE80211_GCMP_PN_LEN);
1236 memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
1244 static void wil_del_rx_key(u8 key_index, enum wmi_key_usage key_usage,
1245 struct wil_sta_info *cs)
1247 struct wil_tid_crypto_rx_single *cc;
1253 switch (key_usage) {
1254 case WMI_KEY_USE_PAIRWISE:
1255 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1256 cc = &cs->tid_crypto_rx[tid].key_id[key_index];
1257 cc->key_set = false;
1260 case WMI_KEY_USE_RX_GROUP:
1261 cc = &cs->group_crypto_rx.key_id[key_index];
1262 cc->key_set = false;
1269 static int wil_cfg80211_add_key(struct wiphy *wiphy,
1270 struct net_device *ndev,
1271 u8 key_index, bool pairwise,
1273 struct key_params *params)
1276 struct wil6210_vif *vif = ndev_to_vif(ndev);
1277 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1278 struct wireless_dev *wdev = vif_to_wdev(vif);
1279 enum wmi_key_usage key_usage = wil_detect_key_usage(wdev, pairwise);
1280 struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, vif->mid,
1285 wil_err(wil, "NULL params\n");
1289 wil_dbg_misc(wil, "add_key: %pM %s[%d] PN %*phN\n",
1290 mac_addr, key_usage_str[key_usage], key_index,
1291 params->seq_len, params->seq);
1294 wil_err(wil, "Not connected, %pM %s[%d] PN %*phN\n",
1295 mac_addr, key_usage_str[key_usage], key_index,
1296 params->seq_len, params->seq);
1300 wil_del_rx_key(key_index, key_usage, cs);
1302 if (params->seq && params->seq_len != IEEE80211_GCMP_PN_LEN) {
1304 "Wrong PN len %d, %pM %s[%d] PN %*phN\n",
1305 params->seq_len, mac_addr,
1306 key_usage_str[key_usage], key_index,
1307 params->seq_len, params->seq);
1311 rc = wmi_add_cipher_key(vif, key_index, mac_addr, params->key_len,
1312 params->key, key_usage);
1314 wil_set_crypto_rx(key_index, key_usage, cs, params);
1319 static int wil_cfg80211_del_key(struct wiphy *wiphy,
1320 struct net_device *ndev,
1321 u8 key_index, bool pairwise,
1324 struct wil6210_vif *vif = ndev_to_vif(ndev);
1325 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1326 struct wireless_dev *wdev = vif_to_wdev(vif);
1327 enum wmi_key_usage key_usage = wil_detect_key_usage(wdev, pairwise);
1328 struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, vif->mid,
1332 wil_dbg_misc(wil, "del_key: %pM %s[%d]\n", mac_addr,
1333 key_usage_str[key_usage], key_index);
1336 wil_info(wil, "Not connected, %pM %s[%d]\n",
1337 mac_addr, key_usage_str[key_usage], key_index);
1339 if (!IS_ERR_OR_NULL(cs))
1340 wil_del_rx_key(key_index, key_usage, cs);
1342 return wmi_del_cipher_key(vif, key_index, mac_addr, key_usage);
1345 /* Need to be present or wiphy_new() will WARN */
1346 static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
1347 struct net_device *ndev,
1348 u8 key_index, bool unicast,
1351 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1353 wil_dbg_misc(wil, "set_default_key: entered\n");
1357 static int wil_remain_on_channel(struct wiphy *wiphy,
1358 struct wireless_dev *wdev,
1359 struct ieee80211_channel *chan,
1360 unsigned int duration,
1363 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1367 "remain_on_channel: center_freq=%d, duration=%d iftype=%d\n",
1368 chan->center_freq, duration, wdev->iftype);
1370 rc = wil_p2p_listen(wil, wdev, duration, chan, cookie);
1374 static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
1375 struct wireless_dev *wdev,
1378 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1379 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
1381 wil_dbg_misc(wil, "cancel_remain_on_channel\n");
1383 return wil_p2p_cancel_listen(vif, cookie);
1387 * find a specific IE in a list of IEs
1388 * return a pointer to the beginning of IE in the list
1389 * or NULL if not found
1391 static const u8 *_wil_cfg80211_find_ie(const u8 *ies, u16 ies_len, const u8 *ie,
1394 struct ieee80211_vendor_ie *vie;
1397 /* IE tag at offset 0, length at offset 1 */
1398 if (ie_len < 2 || 2 + ie[1] > ie_len)
1401 if (ie[0] != WLAN_EID_VENDOR_SPECIFIC)
1402 return cfg80211_find_ie(ie[0], ies, ies_len);
1404 /* make sure there is room for 3 bytes OUI + 1 byte OUI type */
1407 vie = (struct ieee80211_vendor_ie *)ie;
1408 oui = vie->oui[0] << 16 | vie->oui[1] << 8 | vie->oui[2];
1409 return cfg80211_find_vendor_ie(oui, vie->oui_type, ies,
1414 * merge the IEs in two lists into a single list.
1415 * do not include IEs from the second list which exist in the first list.
1416 * add only vendor specific IEs from second list to keep
1417 * the merged list sorted (since vendor-specific IE has the
1418 * highest tag number)
1419 * caller must free the allocated memory for merged IEs
1421 static int _wil_cfg80211_merge_extra_ies(const u8 *ies1, u16 ies1_len,
1422 const u8 *ies2, u16 ies2_len,
1423 u8 **merged_ies, u16 *merged_len)
1434 if (ies1_len == 0 && ies2_len == 0) {
1440 buf = kmalloc(ies1_len + ies2_len, GFP_KERNEL);
1444 memcpy(buf, ies1, ies1_len);
1445 dpos = buf + ies1_len;
1447 while (spos && (spos + 1 < ies2 + ies2_len)) {
1448 /* IE tag at offset 0, length at offset 1 */
1449 u16 ielen = 2 + spos[1];
1451 if (spos + ielen > ies2 + ies2_len)
1453 if (spos[0] == WLAN_EID_VENDOR_SPECIFIC &&
1454 (!ies1 || !_wil_cfg80211_find_ie(ies1, ies1_len,
1456 memcpy(dpos, spos, ielen);
1463 *merged_len = dpos - buf;
1467 static void wil_print_bcon_data(struct cfg80211_beacon_data *b)
1469 wil_hex_dump_misc("head ", DUMP_PREFIX_OFFSET, 16, 1,
1470 b->head, b->head_len, true);
1471 wil_hex_dump_misc("tail ", DUMP_PREFIX_OFFSET, 16, 1,
1472 b->tail, b->tail_len, true);
1473 wil_hex_dump_misc("BCON IE ", DUMP_PREFIX_OFFSET, 16, 1,
1474 b->beacon_ies, b->beacon_ies_len, true);
1475 wil_hex_dump_misc("PROBE ", DUMP_PREFIX_OFFSET, 16, 1,
1476 b->probe_resp, b->probe_resp_len, true);
1477 wil_hex_dump_misc("PROBE IE ", DUMP_PREFIX_OFFSET, 16, 1,
1478 b->proberesp_ies, b->proberesp_ies_len, true);
1479 wil_hex_dump_misc("ASSOC IE ", DUMP_PREFIX_OFFSET, 16, 1,
1480 b->assocresp_ies, b->assocresp_ies_len, true);
1483 /* internal functions for device reset and starting AP */
1484 static int _wil_cfg80211_set_ies(struct wil6210_vif *vif,
1485 struct cfg80211_beacon_data *bcon)
1488 u16 len = 0, proberesp_len = 0;
1489 u8 *ies = NULL, *proberesp = NULL;
1491 if (bcon->probe_resp) {
1492 struct ieee80211_mgmt *f =
1493 (struct ieee80211_mgmt *)bcon->probe_resp;
1494 size_t hlen = offsetof(struct ieee80211_mgmt,
1495 u.probe_resp.variable);
1496 proberesp = f->u.probe_resp.variable;
1497 proberesp_len = bcon->probe_resp_len - hlen;
1499 rc = _wil_cfg80211_merge_extra_ies(proberesp,
1501 bcon->proberesp_ies,
1502 bcon->proberesp_ies_len,
1508 rc = wmi_set_ie(vif, WMI_FRAME_PROBE_RESP, len, ies);
1512 if (bcon->assocresp_ies)
1513 rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_RESP,
1514 bcon->assocresp_ies_len, bcon->assocresp_ies);
1516 rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_RESP, len, ies);
1517 #if 0 /* to use beacon IE's, remove this #if 0 */
1521 rc = wmi_set_ie(vif, WMI_FRAME_BEACON,
1522 bcon->tail_len, bcon->tail);
1529 static int _wil_cfg80211_start_ap(struct wiphy *wiphy,
1530 struct net_device *ndev,
1531 const u8 *ssid, size_t ssid_len, u32 privacy,
1533 struct cfg80211_beacon_data *bcon,
1534 u8 hidden_ssid, u32 pbss)
1536 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1537 struct wil6210_vif *vif = ndev_to_vif(ndev);
1539 struct wireless_dev *wdev = ndev->ieee80211_ptr;
1540 u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
1541 u8 is_go = (wdev->iftype == NL80211_IFTYPE_P2P_GO);
1544 wmi_nettype = WMI_NETTYPE_P2P;
1546 wil_dbg_misc(wil, "start_ap: mid=%d, is_go=%d\n", vif->mid, is_go);
1547 if (is_go && !pbss) {
1548 wil_err(wil, "P2P GO must be in PBSS\n");
1552 wil_set_recovery_state(wil, fw_recovery_idle);
1554 mutex_lock(&wil->mutex);
1556 if (!wil_has_other_active_ifaces(wil, ndev, true, false)) {
1563 rc = wmi_set_ssid(vif, ssid_len, ssid);
1567 rc = _wil_cfg80211_set_ies(vif, bcon);
1571 vif->privacy = privacy;
1572 vif->channel = chan;
1573 vif->hidden_ssid = hidden_ssid;
1576 netif_carrier_on(ndev);
1577 if (!wil_has_other_active_ifaces(wil, ndev, false, true))
1578 wil6210_bus_request(wil, WIL_MAX_BUS_REQUEST_KBPS);
1580 rc = wmi_pcp_start(vif, bi, wmi_nettype, chan, hidden_ssid, is_go);
1584 rc = wil_bcast_init(vif);
1588 goto out; /* success */
1593 netif_carrier_off(ndev);
1594 if (!wil_has_other_active_ifaces(wil, ndev, false, true))
1595 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
1597 mutex_unlock(&wil->mutex);
1601 static int wil_cfg80211_change_beacon(struct wiphy *wiphy,
1602 struct net_device *ndev,
1603 struct cfg80211_beacon_data *bcon)
1605 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1606 struct wil6210_vif *vif = ndev_to_vif(ndev);
1610 wil_dbg_misc(wil, "change_beacon, mid=%d\n", vif->mid);
1611 wil_print_bcon_data(bcon);
1614 cfg80211_find_ie(WLAN_EID_RSN, bcon->tail,
1618 /* in case privacy has changed, need to restart the AP */
1619 if (vif->privacy != privacy) {
1620 struct wireless_dev *wdev = ndev->ieee80211_ptr;
1622 wil_dbg_misc(wil, "privacy changed %d=>%d. Restarting AP\n",
1623 vif->privacy, privacy);
1625 rc = _wil_cfg80211_start_ap(wiphy, ndev, wdev->ssid,
1626 wdev->ssid_len, privacy,
1627 wdev->beacon_interval,
1632 rc = _wil_cfg80211_set_ies(vif, bcon);
1638 static int wil_cfg80211_start_ap(struct wiphy *wiphy,
1639 struct net_device *ndev,
1640 struct cfg80211_ap_settings *info)
1643 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1644 struct ieee80211_channel *channel = info->chandef.chan;
1645 struct cfg80211_beacon_data *bcon = &info->beacon;
1646 struct cfg80211_crypto_settings *crypto = &info->crypto;
1649 wil_dbg_misc(wil, "start_ap\n");
1652 wil_err(wil, "AP: No channel???\n");
1656 switch (info->hidden_ssid) {
1657 case NL80211_HIDDEN_SSID_NOT_IN_USE:
1658 hidden_ssid = WMI_HIDDEN_SSID_DISABLED;
1661 case NL80211_HIDDEN_SSID_ZERO_LEN:
1662 hidden_ssid = WMI_HIDDEN_SSID_SEND_EMPTY;
1665 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
1666 hidden_ssid = WMI_HIDDEN_SSID_CLEAR;
1670 wil_err(wil, "AP: Invalid hidden SSID %d\n", info->hidden_ssid);
1673 wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
1674 channel->center_freq, info->privacy ? "secure" : "open");
1675 wil_dbg_misc(wil, "Privacy: %d auth_type %d\n",
1676 info->privacy, info->auth_type);
1677 wil_dbg_misc(wil, "Hidden SSID mode: %d\n",
1679 wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval,
1681 wil_dbg_misc(wil, "PBSS %d\n", info->pbss);
1682 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
1683 info->ssid, info->ssid_len, true);
1684 wil_print_bcon_data(bcon);
1685 wil_print_crypto(wil, crypto);
1687 rc = _wil_cfg80211_start_ap(wiphy, ndev,
1688 info->ssid, info->ssid_len, info->privacy,
1689 info->beacon_interval, channel->hw_value,
1690 bcon, hidden_ssid, info->pbss);
1695 static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
1696 struct net_device *ndev)
1698 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1699 struct wil6210_vif *vif = ndev_to_vif(ndev);
1702 wil_dbg_misc(wil, "stop_ap, mid=%d\n", vif->mid);
1704 netif_carrier_off(ndev);
1705 last = !wil_has_other_active_ifaces(wil, ndev, false, true);
1707 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
1708 wil_set_recovery_state(wil, fw_recovery_idle);
1709 set_bit(wil_status_resetting, wil->status);
1712 mutex_lock(&wil->mutex);
1719 wil_bcast_fini(vif);
1721 mutex_unlock(&wil->mutex);
1726 static int wil_cfg80211_add_station(struct wiphy *wiphy,
1727 struct net_device *dev,
1729 struct station_parameters *params)
1731 struct wil6210_vif *vif = ndev_to_vif(dev);
1732 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1734 wil_dbg_misc(wil, "add station %pM aid %d mid %d\n",
1735 mac, params->aid, vif->mid);
1737 if (!disable_ap_sme) {
1738 wil_err(wil, "not supported with AP SME enabled\n");
1742 if (params->aid > WIL_MAX_DMG_AID) {
1743 wil_err(wil, "invalid aid\n");
1747 return wmi_new_sta(vif, mac, params->aid);
1750 static int wil_cfg80211_del_station(struct wiphy *wiphy,
1751 struct net_device *dev,
1752 struct station_del_parameters *params)
1754 struct wil6210_vif *vif = ndev_to_vif(dev);
1755 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1757 wil_dbg_misc(wil, "del_station: %pM, reason=%d mid=%d\n",
1758 params->mac, params->reason_code, vif->mid);
1760 mutex_lock(&wil->mutex);
1761 wil6210_disconnect(vif, params->mac, params->reason_code, false);
1762 mutex_unlock(&wil->mutex);
1767 static int wil_cfg80211_change_station(struct wiphy *wiphy,
1768 struct net_device *dev,
1770 struct station_parameters *params)
1772 struct wil6210_vif *vif = ndev_to_vif(dev);
1773 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1776 struct wil_ring_tx_data *txdata = NULL;
1778 wil_dbg_misc(wil, "change station %pM mask 0x%x set 0x%x mid %d\n",
1779 mac, params->sta_flags_mask, params->sta_flags_set,
1782 if (!disable_ap_sme) {
1783 wil_dbg_misc(wil, "not supported with AP SME enabled\n");
1787 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
1790 cid = wil_find_cid(wil, vif->mid, mac);
1792 wil_err(wil, "station not found\n");
1796 for (i = 0; i < ARRAY_SIZE(wil->ring2cid_tid); i++)
1797 if (wil->ring2cid_tid[i][0] == cid) {
1798 txdata = &wil->ring_tx_data[i];
1803 wil_err(wil, "ring data not found\n");
1807 authorize = params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED);
1808 txdata->dot1x_open = authorize ? 1 : 0;
1809 wil_dbg_misc(wil, "cid %d ring %d authorize %d\n", cid, i,
1810 txdata->dot1x_open);
1815 /* probe_client handling */
1816 static void wil_probe_client_handle(struct wil6210_priv *wil,
1817 struct wil6210_vif *vif,
1818 struct wil_probe_client_req *req)
1820 struct net_device *ndev = vif_to_ndev(vif);
1821 struct wil_sta_info *sta = &wil->sta[req->cid];
1822 /* assume STA is alive if it is still connected,
1823 * else FW will disconnect it
1825 bool alive = (sta->status == wil_sta_connected);
1827 cfg80211_probe_status(ndev, sta->addr, req->cookie, alive,
1828 0, false, GFP_KERNEL);
1831 static struct list_head *next_probe_client(struct wil6210_vif *vif)
1833 struct list_head *ret = NULL;
1835 mutex_lock(&vif->probe_client_mutex);
1837 if (!list_empty(&vif->probe_client_pending)) {
1838 ret = vif->probe_client_pending.next;
1842 mutex_unlock(&vif->probe_client_mutex);
1847 void wil_probe_client_worker(struct work_struct *work)
1849 struct wil6210_vif *vif = container_of(work, struct wil6210_vif,
1850 probe_client_worker);
1851 struct wil6210_priv *wil = vif_to_wil(vif);
1852 struct wil_probe_client_req *req;
1853 struct list_head *lh;
1855 while ((lh = next_probe_client(vif)) != NULL) {
1856 req = list_entry(lh, struct wil_probe_client_req, list);
1858 wil_probe_client_handle(wil, vif, req);
1863 void wil_probe_client_flush(struct wil6210_vif *vif)
1865 struct wil_probe_client_req *req, *t;
1866 struct wil6210_priv *wil = vif_to_wil(vif);
1868 wil_dbg_misc(wil, "probe_client_flush\n");
1870 mutex_lock(&vif->probe_client_mutex);
1872 list_for_each_entry_safe(req, t, &vif->probe_client_pending, list) {
1873 list_del(&req->list);
1877 mutex_unlock(&vif->probe_client_mutex);
1880 static int wil_cfg80211_probe_client(struct wiphy *wiphy,
1881 struct net_device *dev,
1882 const u8 *peer, u64 *cookie)
1884 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1885 struct wil6210_vif *vif = ndev_to_vif(dev);
1886 struct wil_probe_client_req *req;
1887 int cid = wil_find_cid(wil, vif->mid, peer);
1889 wil_dbg_misc(wil, "probe_client: %pM => CID %d MID %d\n",
1890 peer, cid, vif->mid);
1895 req = kzalloc(sizeof(*req), GFP_KERNEL);
1902 mutex_lock(&vif->probe_client_mutex);
1903 list_add_tail(&req->list, &vif->probe_client_pending);
1904 mutex_unlock(&vif->probe_client_mutex);
1906 *cookie = req->cookie;
1907 queue_work(wil->wq_service, &vif->probe_client_worker);
1911 static int wil_cfg80211_change_bss(struct wiphy *wiphy,
1912 struct net_device *dev,
1913 struct bss_parameters *params)
1915 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1916 struct wil6210_vif *vif = ndev_to_vif(dev);
1918 if (params->ap_isolate >= 0) {
1919 wil_dbg_misc(wil, "change_bss: ap_isolate MID %d, %d => %d\n",
1920 vif->mid, vif->ap_isolate, params->ap_isolate);
1921 vif->ap_isolate = params->ap_isolate;
1927 static int wil_cfg80211_set_power_mgmt(struct wiphy *wiphy,
1928 struct net_device *dev,
1929 bool enabled, int timeout)
1931 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1932 enum wmi_ps_profile_type ps_profile;
1934 wil_dbg_misc(wil, "enabled=%d, timeout=%d\n",
1938 ps_profile = WMI_PS_PROFILE_TYPE_DEFAULT;
1940 ps_profile = WMI_PS_PROFILE_TYPE_PS_DISABLED;
1942 return wil_ps_update(wil, ps_profile);
1945 static int wil_cfg80211_suspend(struct wiphy *wiphy,
1946 struct cfg80211_wowlan *wow)
1948 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1951 /* Setting the wakeup trigger based on wow is TBD */
1953 if (test_bit(wil_status_suspended, wil->status)) {
1954 wil_dbg_pm(wil, "trying to suspend while suspended\n");
1958 rc = wil_can_suspend(wil, false);
1962 wil_dbg_pm(wil, "suspending\n");
1964 mutex_lock(&wil->mutex);
1965 mutex_lock(&wil->vif_mutex);
1966 wil_p2p_stop_radio_operations(wil);
1967 wil_abort_scan_all_vifs(wil, true);
1968 mutex_unlock(&wil->vif_mutex);
1969 mutex_unlock(&wil->mutex);
1975 static int wil_cfg80211_resume(struct wiphy *wiphy)
1977 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1979 wil_dbg_pm(wil, "resuming\n");
1985 wil_cfg80211_sched_scan_start(struct wiphy *wiphy,
1986 struct net_device *dev,
1987 struct cfg80211_sched_scan_request *request)
1989 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1990 struct wil6210_vif *vif = ndev_to_vif(dev);
1997 "sched scan start: n_ssids %d, ie_len %zu, flags 0x%x\n",
1998 request->n_ssids, request->ie_len, request->flags);
1999 for (i = 0; i < request->n_ssids; i++) {
2000 wil_dbg_misc(wil, "SSID[%d]:", i);
2001 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
2002 request->ssids[i].ssid,
2003 request->ssids[i].ssid_len, true);
2005 wil_dbg_misc(wil, "channels:");
2006 for (i = 0; i < request->n_channels; i++)
2007 wil_dbg_misc(wil, " %d%s", request->channels[i]->hw_value,
2008 i == request->n_channels - 1 ? "\n" : "");
2009 wil_dbg_misc(wil, "n_match_sets %d, min_rssi_thold %d, delay %d\n",
2010 request->n_match_sets, request->min_rssi_thold,
2012 for (i = 0; i < request->n_match_sets; i++) {
2013 struct cfg80211_match_set *ms = &request->match_sets[i];
2015 wil_dbg_misc(wil, "MATCHSET[%d]: rssi_thold %d\n",
2017 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
2019 ms->ssid.ssid_len, true);
2021 wil_dbg_misc(wil, "n_scan_plans %d\n", request->n_scan_plans);
2022 for (i = 0; i < request->n_scan_plans; i++) {
2023 struct cfg80211_sched_scan_plan *sp = &request->scan_plans[i];
2025 wil_dbg_misc(wil, "SCAN PLAN[%d]: interval %d iterations %d\n",
2026 i, sp->interval, sp->iterations);
2029 rc = wmi_set_ie(vif, WMI_FRAME_PROBE_REQ,
2030 request->ie_len, request->ie);
2033 return wmi_start_sched_scan(wil, request);
2037 wil_cfg80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2040 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2041 struct wil6210_vif *vif = ndev_to_vif(dev);
2047 rc = wmi_stop_sched_scan(wil);
2048 /* device would return error if it thinks PNO is already stopped.
2049 * ignore the return code so user space and driver gets back in-sync
2051 wil_dbg_misc(wil, "sched scan stopped (%d)\n", rc);
2056 static const struct cfg80211_ops wil_cfg80211_ops = {
2057 .add_virtual_intf = wil_cfg80211_add_iface,
2058 .del_virtual_intf = wil_cfg80211_del_iface,
2059 .scan = wil_cfg80211_scan,
2060 .abort_scan = wil_cfg80211_abort_scan,
2061 .connect = wil_cfg80211_connect,
2062 .disconnect = wil_cfg80211_disconnect,
2063 .set_wiphy_params = wil_cfg80211_set_wiphy_params,
2064 .change_virtual_intf = wil_cfg80211_change_iface,
2065 .get_station = wil_cfg80211_get_station,
2066 .dump_station = wil_cfg80211_dump_station,
2067 .remain_on_channel = wil_remain_on_channel,
2068 .cancel_remain_on_channel = wil_cancel_remain_on_channel,
2069 .mgmt_tx = wil_cfg80211_mgmt_tx,
2070 .set_monitor_channel = wil_cfg80211_set_channel,
2071 .add_key = wil_cfg80211_add_key,
2072 .del_key = wil_cfg80211_del_key,
2073 .set_default_key = wil_cfg80211_set_default_key,
2075 .change_beacon = wil_cfg80211_change_beacon,
2076 .start_ap = wil_cfg80211_start_ap,
2077 .stop_ap = wil_cfg80211_stop_ap,
2078 .add_station = wil_cfg80211_add_station,
2079 .del_station = wil_cfg80211_del_station,
2080 .change_station = wil_cfg80211_change_station,
2081 .probe_client = wil_cfg80211_probe_client,
2082 .change_bss = wil_cfg80211_change_bss,
2084 .start_p2p_device = wil_cfg80211_start_p2p_device,
2085 .stop_p2p_device = wil_cfg80211_stop_p2p_device,
2086 .set_power_mgmt = wil_cfg80211_set_power_mgmt,
2087 .suspend = wil_cfg80211_suspend,
2088 .resume = wil_cfg80211_resume,
2089 .sched_scan_start = wil_cfg80211_sched_scan_start,
2090 .sched_scan_stop = wil_cfg80211_sched_scan_stop,
2093 static void wil_wiphy_init(struct wiphy *wiphy)
2095 wiphy->max_scan_ssids = 1;
2096 wiphy->max_scan_ie_len = WMI_MAX_IE_LEN;
2097 wiphy->max_remain_on_channel_duration = WIL_MAX_ROC_DURATION_MS;
2098 wiphy->max_num_pmkids = 0 /* TODO: */;
2099 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
2100 BIT(NL80211_IFTYPE_AP) |
2101 BIT(NL80211_IFTYPE_P2P_CLIENT) |
2102 BIT(NL80211_IFTYPE_P2P_GO) |
2103 BIT(NL80211_IFTYPE_P2P_DEVICE) |
2104 BIT(NL80211_IFTYPE_MONITOR);
2105 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
2106 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
2107 WIPHY_FLAG_PS_ON_BY_DEFAULT;
2108 if (!disable_ap_sme)
2109 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME;
2110 dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
2111 __func__, wiphy->flags);
2112 wiphy->probe_resp_offload =
2113 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
2114 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
2115 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
2117 wiphy->bands[NL80211_BAND_60GHZ] = &wil_band_60ghz;
2119 /* may change after reading FW capabilities */
2120 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
2122 wiphy->cipher_suites = wil_cipher_suites;
2123 wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
2124 wiphy->mgmt_stypes = wil_mgmt_stypes;
2125 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
2127 wiphy->n_vendor_commands = ARRAY_SIZE(wil_nl80211_vendor_commands);
2128 wiphy->vendor_commands = wil_nl80211_vendor_commands;
2131 wiphy->wowlan = &wil_wowlan_support;
2135 int wil_cfg80211_iface_combinations_from_fw(
2136 struct wil6210_priv *wil, const struct wil_fw_record_concurrency *conc)
2138 struct wiphy *wiphy = wil_to_wiphy(wil);
2139 u32 total_limits = 0;
2141 const struct wil_fw_concurrency_combo *combo;
2142 const struct wil_fw_concurrency_limit *limit;
2143 struct ieee80211_iface_combination *iface_combinations;
2144 struct ieee80211_iface_limit *iface_limit;
2147 if (wiphy->iface_combinations) {
2148 wil_dbg_misc(wil, "iface_combinations already set, skipping\n");
2152 combo = conc->combos;
2153 n_combos = le16_to_cpu(conc->n_combos);
2154 for (i = 0; i < n_combos; i++) {
2155 total_limits += combo->n_limits;
2156 limit = combo->limits + combo->n_limits;
2157 combo = (struct wil_fw_concurrency_combo *)limit;
2160 iface_combinations =
2161 kzalloc(n_combos * sizeof(struct ieee80211_iface_combination) +
2162 total_limits * sizeof(struct ieee80211_iface_limit),
2164 if (!iface_combinations)
2166 iface_limit = (struct ieee80211_iface_limit *)(iface_combinations +
2168 combo = conc->combos;
2169 for (i = 0; i < n_combos; i++) {
2170 iface_combinations[i].max_interfaces = combo->max_interfaces;
2171 iface_combinations[i].num_different_channels =
2172 combo->n_diff_channels;
2173 iface_combinations[i].beacon_int_infra_match =
2175 iface_combinations[i].n_limits = combo->n_limits;
2177 "iface_combination %d: max_if %d, num_ch %d, bi_match %d\n",
2178 i, iface_combinations[i].max_interfaces,
2179 iface_combinations[i].num_different_channels,
2180 iface_combinations[i].beacon_int_infra_match);
2181 limit = combo->limits;
2182 for (j = 0; j < combo->n_limits; j++) {
2183 iface_limit[j].max = le16_to_cpu(limit[j].max);
2184 iface_limit[j].types = le16_to_cpu(limit[j].types);
2186 "limit %d: max %d types 0x%x\n", j,
2187 iface_limit[j].max, iface_limit[j].types);
2189 iface_combinations[i].limits = iface_limit;
2190 iface_limit += combo->n_limits;
2191 limit += combo->n_limits;
2192 combo = (struct wil_fw_concurrency_combo *)limit;
2195 wil_dbg_misc(wil, "multiple VIFs supported, n_mids %d\n", conc->n_mids);
2196 wil->max_vifs = conc->n_mids + 1; /* including main interface */
2197 if (wil->max_vifs > WIL_MAX_VIFS) {
2198 wil_info(wil, "limited number of VIFs supported(%d, FW %d)\n",
2199 WIL_MAX_VIFS, wil->max_vifs);
2200 wil->max_vifs = WIL_MAX_VIFS;
2202 wiphy->n_iface_combinations = n_combos;
2203 wiphy->iface_combinations = iface_combinations;
2207 struct wil6210_priv *wil_cfg80211_init(struct device *dev)
2209 struct wiphy *wiphy;
2210 struct wil6210_priv *wil;
2211 struct ieee80211_channel *ch;
2213 dev_dbg(dev, "%s()\n", __func__);
2215 /* Note: the wireless_dev structure is no longer allocated here.
2216 * Instead, it is allocated as part of the net_device structure
2217 * for main interface and each VIF.
2219 wiphy = wiphy_new(&wil_cfg80211_ops, sizeof(struct wil6210_priv));
2221 return ERR_PTR(-ENOMEM);
2223 set_wiphy_dev(wiphy, dev);
2224 wil_wiphy_init(wiphy);
2226 wil = wiphy_to_wil(wiphy);
2229 /* default monitor channel */
2230 ch = wiphy->bands[NL80211_BAND_60GHZ]->channels;
2231 cfg80211_chandef_create(&wil->monitor_chandef, ch, NL80211_CHAN_NO_HT);
2236 void wil_cfg80211_deinit(struct wil6210_priv *wil)
2238 struct wiphy *wiphy = wil_to_wiphy(wil);
2240 dev_dbg(wil_to_dev(wil), "%s()\n", __func__);
2245 kfree(wiphy->iface_combinations);
2246 wiphy->iface_combinations = NULL;
2249 /* do not access wil6210_priv after returning from here */
2252 void wil_p2p_wdev_free(struct wil6210_priv *wil)
2254 struct wireless_dev *p2p_wdev;
2256 mutex_lock(&wil->vif_mutex);
2257 p2p_wdev = wil->p2p_wdev;
2258 wil->p2p_wdev = NULL;
2259 wil->radio_wdev = wil->main_ndev->ieee80211_ptr;
2260 mutex_unlock(&wil->vif_mutex);
2262 cfg80211_unregister_wdev(p2p_wdev);
2267 static int wil_rf_sector_status_to_rc(u8 status)
2270 case WMI_RF_SECTOR_STATUS_SUCCESS:
2272 case WMI_RF_SECTOR_STATUS_BAD_PARAMETERS_ERROR:
2274 case WMI_RF_SECTOR_STATUS_BUSY_ERROR:
2276 case WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR:
2283 static int wil_rf_sector_get_cfg(struct wiphy *wiphy,
2284 struct wireless_dev *wdev,
2285 const void *data, int data_len)
2287 struct wil6210_priv *wil = wdev_to_wil(wdev);
2288 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2290 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
2294 struct wmi_get_rf_sector_params_cmd cmd;
2296 struct wmi_cmd_hdr wmi;
2297 struct wmi_get_rf_sector_params_done_event evt;
2298 } __packed reply = {
2299 .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
2301 struct sk_buff *msg;
2302 struct nlattr *nl_cfgs, *nl_cfg;
2304 struct wmi_rf_sector_info *si;
2306 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
2309 rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
2310 wil_rf_sector_policy, NULL);
2312 wil_err(wil, "Invalid rf sector ATTR\n");
2316 if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
2317 !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE] ||
2318 !tb[QCA_ATTR_DMG_RF_MODULE_MASK]) {
2319 wil_err(wil, "Invalid rf sector spec\n");
2323 sector_index = nla_get_u16(
2324 tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
2325 if (sector_index >= WIL_MAX_RF_SECTORS) {
2326 wil_err(wil, "Invalid sector index %d\n", sector_index);
2330 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
2331 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
2332 wil_err(wil, "Invalid sector type %d\n", sector_type);
2336 rf_modules_vec = nla_get_u32(
2337 tb[QCA_ATTR_DMG_RF_MODULE_MASK]);
2338 if (rf_modules_vec >= BIT(WMI_MAX_RF_MODULES_NUM)) {
2339 wil_err(wil, "Invalid rf module mask 0x%x\n", rf_modules_vec);
2343 cmd.sector_idx = cpu_to_le16(sector_index);
2344 cmd.sector_type = sector_type;
2345 cmd.rf_modules_vec = rf_modules_vec & 0xFF;
2346 rc = wmi_call(wil, WMI_GET_RF_SECTOR_PARAMS_CMDID, vif->mid,
2347 &cmd, sizeof(cmd), WMI_GET_RF_SECTOR_PARAMS_DONE_EVENTID,
2348 &reply, sizeof(reply),
2352 if (reply.evt.status) {
2353 wil_err(wil, "get rf sector cfg failed with status %d\n",
2355 return wil_rf_sector_status_to_rc(reply.evt.status);
2358 msg = cfg80211_vendor_cmd_alloc_reply_skb(
2359 wiphy, 64 * WMI_MAX_RF_MODULES_NUM);
2363 if (nla_put_u64_64bit(msg, QCA_ATTR_TSF,
2364 le64_to_cpu(reply.evt.tsf),
2366 goto nla_put_failure;
2368 nl_cfgs = nla_nest_start(msg, QCA_ATTR_DMG_RF_SECTOR_CFG);
2370 goto nla_put_failure;
2371 for (i = 0; i < WMI_MAX_RF_MODULES_NUM; i++) {
2372 if (!(rf_modules_vec & BIT(i)))
2374 nl_cfg = nla_nest_start(msg, i);
2376 goto nla_put_failure;
2377 si = &reply.evt.sectors_info[i];
2378 if (nla_put_u8(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX,
2380 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0,
2381 le32_to_cpu(si->etype0)) ||
2382 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1,
2383 le32_to_cpu(si->etype1)) ||
2384 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2,
2385 le32_to_cpu(si->etype2)) ||
2386 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI,
2387 le32_to_cpu(si->psh_hi)) ||
2388 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO,
2389 le32_to_cpu(si->psh_lo)) ||
2390 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16,
2391 le32_to_cpu(si->dtype_swch_off)))
2392 goto nla_put_failure;
2393 nla_nest_end(msg, nl_cfg);
2396 nla_nest_end(msg, nl_cfgs);
2397 rc = cfg80211_vendor_cmd_reply(msg);
2404 static int wil_rf_sector_set_cfg(struct wiphy *wiphy,
2405 struct wireless_dev *wdev,
2406 const void *data, int data_len)
2408 struct wil6210_priv *wil = wdev_to_wil(wdev);
2409 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2411 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
2412 struct nlattr *tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MAX + 1];
2413 u16 sector_index, rf_module_index;
2415 u32 rf_modules_vec = 0;
2416 struct wmi_set_rf_sector_params_cmd cmd;
2418 struct wmi_cmd_hdr wmi;
2419 struct wmi_set_rf_sector_params_done_event evt;
2420 } __packed reply = {
2421 .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
2423 struct nlattr *nl_cfg;
2424 struct wmi_rf_sector_info *si;
2426 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
2429 rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
2430 wil_rf_sector_policy, NULL);
2432 wil_err(wil, "Invalid rf sector ATTR\n");
2436 if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
2437 !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE] ||
2438 !tb[QCA_ATTR_DMG_RF_SECTOR_CFG]) {
2439 wil_err(wil, "Invalid rf sector spec\n");
2443 sector_index = nla_get_u16(
2444 tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
2445 if (sector_index >= WIL_MAX_RF_SECTORS) {
2446 wil_err(wil, "Invalid sector index %d\n", sector_index);
2450 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
2451 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
2452 wil_err(wil, "Invalid sector type %d\n", sector_type);
2456 memset(&cmd, 0, sizeof(cmd));
2458 cmd.sector_idx = cpu_to_le16(sector_index);
2459 cmd.sector_type = sector_type;
2460 nla_for_each_nested(nl_cfg, tb[QCA_ATTR_DMG_RF_SECTOR_CFG],
2462 rc = nla_parse_nested(tb2, QCA_ATTR_DMG_RF_SECTOR_CFG_MAX,
2463 nl_cfg, wil_rf_sector_cfg_policy,
2466 wil_err(wil, "invalid sector cfg\n");
2470 if (!tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX] ||
2471 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0] ||
2472 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1] ||
2473 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2] ||
2474 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI] ||
2475 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO] ||
2476 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16]) {
2477 wil_err(wil, "missing cfg params\n");
2481 rf_module_index = nla_get_u8(
2482 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX]);
2483 if (rf_module_index >= WMI_MAX_RF_MODULES_NUM) {
2484 wil_err(wil, "invalid RF module index %d\n",
2488 rf_modules_vec |= BIT(rf_module_index);
2489 si = &cmd.sectors_info[rf_module_index];
2490 si->etype0 = cpu_to_le32(nla_get_u32(
2491 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0]));
2492 si->etype1 = cpu_to_le32(nla_get_u32(
2493 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1]));
2494 si->etype2 = cpu_to_le32(nla_get_u32(
2495 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2]));
2496 si->psh_hi = cpu_to_le32(nla_get_u32(
2497 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI]));
2498 si->psh_lo = cpu_to_le32(nla_get_u32(
2499 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO]));
2500 si->dtype_swch_off = cpu_to_le32(nla_get_u32(
2501 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16]));
2504 cmd.rf_modules_vec = rf_modules_vec & 0xFF;
2505 rc = wmi_call(wil, WMI_SET_RF_SECTOR_PARAMS_CMDID, vif->mid,
2506 &cmd, sizeof(cmd), WMI_SET_RF_SECTOR_PARAMS_DONE_EVENTID,
2507 &reply, sizeof(reply),
2511 return wil_rf_sector_status_to_rc(reply.evt.status);
2514 static int wil_rf_sector_get_selected(struct wiphy *wiphy,
2515 struct wireless_dev *wdev,
2516 const void *data, int data_len)
2518 struct wil6210_priv *wil = wdev_to_wil(wdev);
2519 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2521 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
2522 u8 sector_type, mac_addr[ETH_ALEN];
2524 struct wmi_get_selected_rf_sector_index_cmd cmd;
2526 struct wmi_cmd_hdr wmi;
2527 struct wmi_get_selected_rf_sector_index_done_event evt;
2528 } __packed reply = {
2529 .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
2531 struct sk_buff *msg;
2533 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
2536 rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
2537 wil_rf_sector_policy, NULL);
2539 wil_err(wil, "Invalid rf sector ATTR\n");
2543 if (!tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]) {
2544 wil_err(wil, "Invalid rf sector spec\n");
2547 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
2548 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
2549 wil_err(wil, "Invalid sector type %d\n", sector_type);
2553 if (tb[QCA_ATTR_MAC_ADDR]) {
2554 ether_addr_copy(mac_addr, nla_data(tb[QCA_ATTR_MAC_ADDR]));
2555 cid = wil_find_cid(wil, vif->mid, mac_addr);
2557 wil_err(wil, "invalid MAC address %pM\n", mac_addr);
2561 if (test_bit(wil_vif_fwconnected, vif->status)) {
2562 wil_err(wil, "must specify MAC address when connected\n");
2567 memset(&cmd, 0, sizeof(cmd));
2569 cmd.sector_type = sector_type;
2570 rc = wmi_call(wil, WMI_GET_SELECTED_RF_SECTOR_INDEX_CMDID, vif->mid,
2572 WMI_GET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID,
2573 &reply, sizeof(reply),
2577 if (reply.evt.status) {
2578 wil_err(wil, "get rf selected sector cfg failed with status %d\n",
2580 return wil_rf_sector_status_to_rc(reply.evt.status);
2583 msg = cfg80211_vendor_cmd_alloc_reply_skb(
2584 wiphy, 64 * WMI_MAX_RF_MODULES_NUM);
2588 if (nla_put_u64_64bit(msg, QCA_ATTR_TSF,
2589 le64_to_cpu(reply.evt.tsf),
2591 nla_put_u16(msg, QCA_ATTR_DMG_RF_SECTOR_INDEX,
2592 le16_to_cpu(reply.evt.sector_idx)))
2593 goto nla_put_failure;
2595 rc = cfg80211_vendor_cmd_reply(msg);
2602 static int wil_rf_sector_wmi_set_selected(struct wil6210_priv *wil,
2603 u8 mid, u16 sector_index,
2604 u8 sector_type, u8 cid)
2606 struct wmi_set_selected_rf_sector_index_cmd cmd;
2608 struct wmi_cmd_hdr wmi;
2609 struct wmi_set_selected_rf_sector_index_done_event evt;
2610 } __packed reply = {
2611 .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
2615 memset(&cmd, 0, sizeof(cmd));
2616 cmd.sector_idx = cpu_to_le16(sector_index);
2617 cmd.sector_type = sector_type;
2619 rc = wmi_call(wil, WMI_SET_SELECTED_RF_SECTOR_INDEX_CMDID, mid,
2621 WMI_SET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID,
2622 &reply, sizeof(reply),
2626 return wil_rf_sector_status_to_rc(reply.evt.status);
2629 static int wil_rf_sector_set_selected(struct wiphy *wiphy,
2630 struct wireless_dev *wdev,
2631 const void *data, int data_len)
2633 struct wil6210_priv *wil = wdev_to_wil(wdev);
2634 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2636 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
2638 u8 sector_type, mac_addr[ETH_ALEN], i;
2641 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
2644 rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
2645 wil_rf_sector_policy, NULL);
2647 wil_err(wil, "Invalid rf sector ATTR\n");
2651 if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
2652 !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]) {
2653 wil_err(wil, "Invalid rf sector spec\n");
2657 sector_index = nla_get_u16(
2658 tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
2659 if (sector_index >= WIL_MAX_RF_SECTORS &&
2660 sector_index != WMI_INVALID_RF_SECTOR_INDEX) {
2661 wil_err(wil, "Invalid sector index %d\n", sector_index);
2665 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
2666 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
2667 wil_err(wil, "Invalid sector type %d\n", sector_type);
2671 if (tb[QCA_ATTR_MAC_ADDR]) {
2672 ether_addr_copy(mac_addr, nla_data(tb[QCA_ATTR_MAC_ADDR]));
2673 if (!is_broadcast_ether_addr(mac_addr)) {
2674 cid = wil_find_cid(wil, vif->mid, mac_addr);
2676 wil_err(wil, "invalid MAC address %pM\n",
2681 if (sector_index != WMI_INVALID_RF_SECTOR_INDEX) {
2682 wil_err(wil, "broadcast MAC valid only with unlocking\n");
2688 if (test_bit(wil_vif_fwconnected, vif->status)) {
2689 wil_err(wil, "must specify MAC address when connected\n");
2692 /* otherwise, using cid=0 for unassociated station */
2696 rc = wil_rf_sector_wmi_set_selected(wil, vif->mid, sector_index,
2699 /* unlock all cids */
2700 rc = wil_rf_sector_wmi_set_selected(
2701 wil, vif->mid, WMI_INVALID_RF_SECTOR_INDEX,
2702 sector_type, WIL_CID_ALL);
2703 if (rc == -EINVAL) {
2704 for (i = 0; i < WIL6210_MAX_CID; i++) {
2705 if (wil->sta[i].mid != vif->mid)
2707 rc = wil_rf_sector_wmi_set_selected(
2709 WMI_INVALID_RF_SECTOR_INDEX,
2711 /* the FW will silently ignore and return
2712 * success for unused cid, so abort the loop
2713 * on any other error
2716 wil_err(wil, "unlock cid %d failed with status %d\n",