1 // SPDX-License-Identifier: ISC
2 /*
3 * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
4 * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
5 * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
6 */
7
8 #include <linux/etherdevice.h>
9 #include <linux/moduleparam.h>
10 #include <net/netlink.h>
11 #include <net/cfg80211.h>
12 #include "wil6210.h"
13 #include "wmi.h"
14 #include "fw.h"
15
16 #define WIL_MAX_ROC_DURATION_MS 5000
17
18 #define WIL_EDMG_CHANNEL_9_SUBCHANNELS (BIT(0) | BIT(1))
19 #define WIL_EDMG_CHANNEL_10_SUBCHANNELS (BIT(1) | BIT(2))
20 #define WIL_EDMG_CHANNEL_11_SUBCHANNELS (BIT(2) | BIT(3))
21
22 /* WIL_EDMG_BW_CONFIGURATION define the allowed channel bandwidth
23 * configurations as defined by IEEE 802.11 section 9.4.2.251, Table 13.
24 * The value 5 allowing CB1 and CB2 of adjacent channels.
25 */
26 #define WIL_EDMG_BW_CONFIGURATION 5
27
28 /* WIL_EDMG_CHANNELS is a bitmap that indicates the 2.16 GHz channel(s) that
29 * are allowed to be used for EDMG transmissions in the BSS as defined by
30 * IEEE 802.11 section 9.4.2.251.
31 */
32 #define WIL_EDMG_CHANNELS (BIT(0) | BIT(1) | BIT(2) | BIT(3))
33
34 bool disable_ap_sme;
35 module_param(disable_ap_sme, bool, 0444);
36 MODULE_PARM_DESC(disable_ap_sme, " let user space handle AP mode SME");
37
38 #ifdef CONFIG_PM
39 static struct wiphy_wowlan_support wil_wowlan_support = {
40 .flags = WIPHY_WOWLAN_ANY | WIPHY_WOWLAN_DISCONNECT,
41 };
42 #endif
43
44 #define CHAN60G(_channel, _flags) { \
45 .band = NL80211_BAND_60GHZ, \
46 .center_freq = 56160 + (2160 * (_channel)), \
47 .hw_value = (_channel), \
48 .flags = (_flags), \
49 .max_antenna_gain = 0, \
50 .max_power = 40, \
51 }
52
53 static struct ieee80211_channel wil_60ghz_channels[] = {
54 CHAN60G(1, 0),
55 CHAN60G(2, 0),
56 CHAN60G(3, 0),
57 CHAN60G(4, 0),
58 };
59
60 /* Rx channel bonding mode */
61 enum wil_rx_cb_mode {
62 WIL_RX_CB_MODE_DMG,
63 WIL_RX_CB_MODE_EDMG,
64 WIL_RX_CB_MODE_WIDE,
65 };
66
wil_rx_cb_mode_to_n_bonded(u8 cb_mode)67 static int wil_rx_cb_mode_to_n_bonded(u8 cb_mode)
68 {
69 switch (cb_mode) {
70 case WIL_RX_CB_MODE_DMG:
71 case WIL_RX_CB_MODE_EDMG:
72 return 1;
73 case WIL_RX_CB_MODE_WIDE:
74 return 2;
75 default:
76 return 1;
77 }
78 }
79
wil_tx_cb_mode_to_n_bonded(u8 cb_mode)80 static int wil_tx_cb_mode_to_n_bonded(u8 cb_mode)
81 {
82 switch (cb_mode) {
83 case WMI_TX_MODE_DMG:
84 case WMI_TX_MODE_EDMG_CB1:
85 return 1;
86 case WMI_TX_MODE_EDMG_CB2:
87 return 2;
88 default:
89 return 1;
90 }
91 }
92
93 static void
wil_memdup_ie(u8 ** pdst,size_t * pdst_len,const u8 * src,size_t src_len)94 wil_memdup_ie(u8 **pdst, size_t *pdst_len, const u8 *src, size_t src_len)
95 {
96 kfree(*pdst);
97 *pdst = NULL;
98 *pdst_len = 0;
99 if (src_len > 0) {
100 *pdst = kmemdup(src, src_len, GFP_KERNEL);
101 if (*pdst)
102 *pdst_len = src_len;
103 }
104 }
105
wil_num_supported_channels(struct wil6210_priv * wil)106 static int wil_num_supported_channels(struct wil6210_priv *wil)
107 {
108 int num_channels = ARRAY_SIZE(wil_60ghz_channels);
109
110 if (!test_bit(WMI_FW_CAPABILITY_CHANNEL_4, wil->fw_capabilities))
111 num_channels--;
112
113 return num_channels;
114 }
115
update_supported_bands(struct wil6210_priv * wil)116 void update_supported_bands(struct wil6210_priv *wil)
117 {
118 struct wiphy *wiphy = wil_to_wiphy(wil);
119
120 wil_dbg_misc(wil, "update supported bands");
121
122 wiphy->bands[NL80211_BAND_60GHZ]->n_channels =
123 wil_num_supported_channels(wil);
124
125 if (test_bit(WMI_FW_CAPABILITY_CHANNEL_BONDING, wil->fw_capabilities)) {
126 wiphy->bands[NL80211_BAND_60GHZ]->edmg_cap.channels =
127 WIL_EDMG_CHANNELS;
128 wiphy->bands[NL80211_BAND_60GHZ]->edmg_cap.bw_config =
129 WIL_EDMG_BW_CONFIGURATION;
130 }
131 }
132
133 /* Vendor id to be used in vendor specific command and events
134 * to user space.
135 * NOTE: The authoritative place for definition of QCA_NL80211_VENDOR_ID,
136 * vendor subcmd definitions prefixed with QCA_NL80211_VENDOR_SUBCMD, and
137 * qca_wlan_vendor_attr is open source file src/common/qca-vendor.h in
138 * git://w1.fi/srv/git/hostap.git; the values here are just a copy of that
139 */
140
141 #define QCA_NL80211_VENDOR_ID 0x001374
142
143 #define WIL_MAX_RF_SECTORS (128)
144 #define WIL_CID_ALL (0xff)
145
146 enum qca_wlan_vendor_attr_rf_sector {
147 QCA_ATTR_MAC_ADDR = 6,
148 QCA_ATTR_PAD = 13,
149 QCA_ATTR_TSF = 29,
150 QCA_ATTR_DMG_RF_SECTOR_INDEX = 30,
151 QCA_ATTR_DMG_RF_SECTOR_TYPE = 31,
152 QCA_ATTR_DMG_RF_MODULE_MASK = 32,
153 QCA_ATTR_DMG_RF_SECTOR_CFG = 33,
154 QCA_ATTR_DMG_RF_SECTOR_MAX,
155 };
156
157 enum qca_wlan_vendor_attr_dmg_rf_sector_type {
158 QCA_ATTR_DMG_RF_SECTOR_TYPE_RX,
159 QCA_ATTR_DMG_RF_SECTOR_TYPE_TX,
160 QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX
161 };
162
163 enum qca_wlan_vendor_attr_dmg_rf_sector_cfg {
164 QCA_ATTR_DMG_RF_SECTOR_CFG_INVALID = 0,
165 QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX,
166 QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0,
167 QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1,
168 QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2,
169 QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI,
170 QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO,
171 QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16,
172
173 /* keep last */
174 QCA_ATTR_DMG_RF_SECTOR_CFG_AFTER_LAST,
175 QCA_ATTR_DMG_RF_SECTOR_CFG_MAX =
176 QCA_ATTR_DMG_RF_SECTOR_CFG_AFTER_LAST - 1
177 };
178
179 static const struct
180 nla_policy wil_rf_sector_policy[QCA_ATTR_DMG_RF_SECTOR_MAX + 1] = {
181 [QCA_ATTR_MAC_ADDR] = { .len = ETH_ALEN },
182 [QCA_ATTR_DMG_RF_SECTOR_INDEX] = { .type = NLA_U16 },
183 [QCA_ATTR_DMG_RF_SECTOR_TYPE] = { .type = NLA_U8 },
184 [QCA_ATTR_DMG_RF_MODULE_MASK] = { .type = NLA_U32 },
185 [QCA_ATTR_DMG_RF_SECTOR_CFG] = { .type = NLA_NESTED },
186 };
187
188 static const struct
189 nla_policy wil_rf_sector_cfg_policy[QCA_ATTR_DMG_RF_SECTOR_CFG_MAX + 1] = {
190 [QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX] = { .type = NLA_U8 },
191 [QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0] = { .type = NLA_U32 },
192 [QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1] = { .type = NLA_U32 },
193 [QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2] = { .type = NLA_U32 },
194 [QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI] = { .type = NLA_U32 },
195 [QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO] = { .type = NLA_U32 },
196 [QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16] = { .type = NLA_U32 },
197 };
198
199 enum qca_nl80211_vendor_subcmds {
200 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SECTOR_CFG = 139,
201 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SECTOR_CFG = 140,
202 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SELECTED_SECTOR = 141,
203 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SELECTED_SECTOR = 142,
204 };
205
206 static int wil_rf_sector_get_cfg(struct wiphy *wiphy,
207 struct wireless_dev *wdev,
208 const void *data, int data_len);
209 static int wil_rf_sector_set_cfg(struct wiphy *wiphy,
210 struct wireless_dev *wdev,
211 const void *data, int data_len);
212 static int wil_rf_sector_get_selected(struct wiphy *wiphy,
213 struct wireless_dev *wdev,
214 const void *data, int data_len);
215 static int wil_rf_sector_set_selected(struct wiphy *wiphy,
216 struct wireless_dev *wdev,
217 const void *data, int data_len);
218
219 /* vendor specific commands */
220 static const struct wiphy_vendor_command wil_nl80211_vendor_commands[] = {
221 {
222 .info.vendor_id = QCA_NL80211_VENDOR_ID,
223 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SECTOR_CFG,
224 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
225 WIPHY_VENDOR_CMD_NEED_RUNNING,
226 .policy = wil_rf_sector_policy,
227 .doit = wil_rf_sector_get_cfg
228 },
229 {
230 .info.vendor_id = QCA_NL80211_VENDOR_ID,
231 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SECTOR_CFG,
232 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
233 WIPHY_VENDOR_CMD_NEED_RUNNING,
234 .policy = wil_rf_sector_policy,
235 .doit = wil_rf_sector_set_cfg
236 },
237 {
238 .info.vendor_id = QCA_NL80211_VENDOR_ID,
239 .info.subcmd =
240 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SELECTED_SECTOR,
241 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
242 WIPHY_VENDOR_CMD_NEED_RUNNING,
243 .policy = wil_rf_sector_policy,
244 .doit = wil_rf_sector_get_selected
245 },
246 {
247 .info.vendor_id = QCA_NL80211_VENDOR_ID,
248 .info.subcmd =
249 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SELECTED_SECTOR,
250 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
251 WIPHY_VENDOR_CMD_NEED_RUNNING,
252 .policy = wil_rf_sector_policy,
253 .doit = wil_rf_sector_set_selected
254 },
255 };
256
257 static struct ieee80211_supported_band wil_band_60ghz = {
258 .channels = wil_60ghz_channels,
259 .n_channels = ARRAY_SIZE(wil_60ghz_channels),
260 .ht_cap = {
261 .ht_supported = true,
262 .cap = 0, /* TODO */
263 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, /* TODO */
264 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, /* TODO */
265 .mcs = {
266 /* MCS 1..12 - SC PHY */
267 .rx_mask = {0xfe, 0x1f}, /* 1..12 */
268 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, /* TODO */
269 },
270 },
271 };
272
273 static const struct ieee80211_txrx_stypes
274 wil_mgmt_stypes[NUM_NL80211_IFTYPES] = {
275 [NL80211_IFTYPE_STATION] = {
276 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
277 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
278 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
279 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
280 },
281 [NL80211_IFTYPE_AP] = {
282 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
283 BIT(IEEE80211_STYPE_PROBE_RESP >> 4) |
284 BIT(IEEE80211_STYPE_ASSOC_RESP >> 4) |
285 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
286 BIT(IEEE80211_STYPE_AUTH >> 4) |
287 BIT(IEEE80211_STYPE_REASSOC_RESP >> 4),
288 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
289 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
290 BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
291 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
292 BIT(IEEE80211_STYPE_AUTH >> 4) |
293 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
294 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4)
295 },
296 [NL80211_IFTYPE_P2P_CLIENT] = {
297 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
298 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
299 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
300 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
301 },
302 [NL80211_IFTYPE_P2P_GO] = {
303 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
304 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
305 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
306 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
307 },
308 [NL80211_IFTYPE_P2P_DEVICE] = {
309 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
310 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
311 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
312 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
313 },
314 };
315
316 static const u32 wil_cipher_suites[] = {
317 WLAN_CIPHER_SUITE_GCMP,
318 };
319
320 static const char * const key_usage_str[] = {
321 [WMI_KEY_USE_PAIRWISE] = "PTK",
322 [WMI_KEY_USE_RX_GROUP] = "RX_GTK",
323 [WMI_KEY_USE_TX_GROUP] = "TX_GTK",
324 [WMI_KEY_USE_STORE_PTK] = "STORE_PTK",
325 [WMI_KEY_USE_APPLY_PTK] = "APPLY_PTK",
326 };
327
wil_iftype_nl2wmi(enum nl80211_iftype type)328 int wil_iftype_nl2wmi(enum nl80211_iftype type)
329 {
330 static const struct {
331 enum nl80211_iftype nl;
332 enum wmi_network_type wmi;
333 } __nl2wmi[] = {
334 {NL80211_IFTYPE_ADHOC, WMI_NETTYPE_ADHOC},
335 {NL80211_IFTYPE_STATION, WMI_NETTYPE_INFRA},
336 {NL80211_IFTYPE_AP, WMI_NETTYPE_AP},
337 {NL80211_IFTYPE_P2P_CLIENT, WMI_NETTYPE_P2P},
338 {NL80211_IFTYPE_P2P_GO, WMI_NETTYPE_P2P},
339 {NL80211_IFTYPE_MONITOR, WMI_NETTYPE_ADHOC}, /* FIXME */
340 };
341 uint i;
342
343 for (i = 0; i < ARRAY_SIZE(__nl2wmi); i++) {
344 if (__nl2wmi[i].nl == type)
345 return __nl2wmi[i].wmi;
346 }
347
348 return -EOPNOTSUPP;
349 }
350
wil_spec2wmi_ch(u8 spec_ch,u8 * wmi_ch)351 int wil_spec2wmi_ch(u8 spec_ch, u8 *wmi_ch)
352 {
353 switch (spec_ch) {
354 case 1:
355 *wmi_ch = WMI_CHANNEL_1;
356 break;
357 case 2:
358 *wmi_ch = WMI_CHANNEL_2;
359 break;
360 case 3:
361 *wmi_ch = WMI_CHANNEL_3;
362 break;
363 case 4:
364 *wmi_ch = WMI_CHANNEL_4;
365 break;
366 case 5:
367 *wmi_ch = WMI_CHANNEL_5;
368 break;
369 case 6:
370 *wmi_ch = WMI_CHANNEL_6;
371 break;
372 case 9:
373 *wmi_ch = WMI_CHANNEL_9;
374 break;
375 case 10:
376 *wmi_ch = WMI_CHANNEL_10;
377 break;
378 case 11:
379 *wmi_ch = WMI_CHANNEL_11;
380 break;
381 case 12:
382 *wmi_ch = WMI_CHANNEL_12;
383 break;
384 default:
385 return -EINVAL;
386 }
387
388 return 0;
389 }
390
wil_wmi2spec_ch(u8 wmi_ch,u8 * spec_ch)391 int wil_wmi2spec_ch(u8 wmi_ch, u8 *spec_ch)
392 {
393 switch (wmi_ch) {
394 case WMI_CHANNEL_1:
395 *spec_ch = 1;
396 break;
397 case WMI_CHANNEL_2:
398 *spec_ch = 2;
399 break;
400 case WMI_CHANNEL_3:
401 *spec_ch = 3;
402 break;
403 case WMI_CHANNEL_4:
404 *spec_ch = 4;
405 break;
406 case WMI_CHANNEL_5:
407 *spec_ch = 5;
408 break;
409 case WMI_CHANNEL_6:
410 *spec_ch = 6;
411 break;
412 case WMI_CHANNEL_9:
413 *spec_ch = 9;
414 break;
415 case WMI_CHANNEL_10:
416 *spec_ch = 10;
417 break;
418 case WMI_CHANNEL_11:
419 *spec_ch = 11;
420 break;
421 case WMI_CHANNEL_12:
422 *spec_ch = 12;
423 break;
424 default:
425 return -EINVAL;
426 }
427
428 return 0;
429 }
430
wil_cid_fill_sinfo(struct wil6210_vif * vif,int cid,struct station_info * sinfo)431 int wil_cid_fill_sinfo(struct wil6210_vif *vif, int cid,
432 struct station_info *sinfo)
433 {
434 struct wil6210_priv *wil = vif_to_wil(vif);
435 struct wmi_notify_req_cmd cmd = {
436 .cid = cid,
437 .interval_usec = 0,
438 };
439 struct {
440 struct wmi_cmd_hdr wmi;
441 struct wmi_notify_req_done_event evt;
442 } __packed reply;
443 struct wil_net_stats *stats = &wil->sta[cid].stats;
444 int rc;
445 u8 tx_mcs, rx_mcs;
446 u8 tx_rate_flag = RATE_INFO_FLAGS_DMG;
447 u8 rx_rate_flag = RATE_INFO_FLAGS_DMG;
448
449 memset(&reply, 0, sizeof(reply));
450
451 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid, &cmd, sizeof(cmd),
452 WMI_NOTIFY_REQ_DONE_EVENTID, &reply, sizeof(reply),
453 WIL_WMI_CALL_GENERAL_TO_MS);
454 if (rc)
455 return rc;
456
457 tx_mcs = le16_to_cpu(reply.evt.bf_mcs);
458
459 wil_dbg_wmi(wil, "Link status for CID %d MID %d: {\n"
460 " MCS %s TSF 0x%016llx\n"
461 " BF status 0x%08x RSSI %d SQI %d%%\n"
462 " Tx Tpt %d goodput %d Rx goodput %d\n"
463 " Sectors(rx:tx) my %d:%d peer %d:%d\n"
464 " Tx mode %d}\n",
465 cid, vif->mid, WIL_EXTENDED_MCS_CHECK(tx_mcs),
466 le64_to_cpu(reply.evt.tsf), reply.evt.status,
467 reply.evt.rssi,
468 reply.evt.sqi,
469 le32_to_cpu(reply.evt.tx_tpt),
470 le32_to_cpu(reply.evt.tx_goodput),
471 le32_to_cpu(reply.evt.rx_goodput),
472 le16_to_cpu(reply.evt.my_rx_sector),
473 le16_to_cpu(reply.evt.my_tx_sector),
474 le16_to_cpu(reply.evt.other_rx_sector),
475 le16_to_cpu(reply.evt.other_tx_sector),
476 reply.evt.tx_mode);
477
478 sinfo->generation = wil->sinfo_gen;
479
480 sinfo->filled = BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
481 BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
482 BIT_ULL(NL80211_STA_INFO_RX_PACKETS) |
483 BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
484 BIT_ULL(NL80211_STA_INFO_RX_BITRATE) |
485 BIT_ULL(NL80211_STA_INFO_TX_BITRATE) |
486 BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC) |
487 BIT_ULL(NL80211_STA_INFO_TX_FAILED);
488
489 if (wil->use_enhanced_dma_hw && reply.evt.tx_mode != WMI_TX_MODE_DMG) {
490 tx_rate_flag = RATE_INFO_FLAGS_EDMG;
491 rx_rate_flag = RATE_INFO_FLAGS_EDMG;
492 }
493
494 rx_mcs = stats->last_mcs_rx;
495
496 /* check extended MCS (12.1) and convert it into
497 * base MCS (7) + EXTENDED_SC_DMG flag
498 */
499 if (tx_mcs == WIL_EXTENDED_MCS_26) {
500 tx_rate_flag = RATE_INFO_FLAGS_EXTENDED_SC_DMG;
501 tx_mcs = WIL_BASE_MCS_FOR_EXTENDED_26;
502 }
503 if (rx_mcs == WIL_EXTENDED_MCS_26) {
504 rx_rate_flag = RATE_INFO_FLAGS_EXTENDED_SC_DMG;
505 rx_mcs = WIL_BASE_MCS_FOR_EXTENDED_26;
506 }
507
508 sinfo->txrate.flags = tx_rate_flag;
509 sinfo->rxrate.flags = rx_rate_flag;
510 sinfo->txrate.mcs = tx_mcs;
511 sinfo->rxrate.mcs = rx_mcs;
512
513 sinfo->txrate.n_bonded_ch =
514 wil_tx_cb_mode_to_n_bonded(reply.evt.tx_mode);
515 sinfo->rxrate.n_bonded_ch =
516 wil_rx_cb_mode_to_n_bonded(stats->last_cb_mode_rx);
517 sinfo->rx_bytes = stats->rx_bytes;
518 sinfo->rx_packets = stats->rx_packets;
519 sinfo->rx_dropped_misc = stats->rx_dropped;
520 sinfo->tx_bytes = stats->tx_bytes;
521 sinfo->tx_packets = stats->tx_packets;
522 sinfo->tx_failed = stats->tx_errors;
523
524 if (test_bit(wil_vif_fwconnected, vif->status)) {
525 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
526 if (test_bit(WMI_FW_CAPABILITY_RSSI_REPORTING,
527 wil->fw_capabilities))
528 sinfo->signal = reply.evt.rssi;
529 else
530 sinfo->signal = reply.evt.sqi;
531 }
532
533 return rc;
534 }
535
wil_cfg80211_get_station(struct wiphy * wiphy,struct wireless_dev * wdev,const u8 * mac,struct station_info * sinfo)536 static int wil_cfg80211_get_station(struct wiphy *wiphy,
537 struct wireless_dev *wdev,
538 const u8 *mac, struct station_info *sinfo)
539 {
540 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
541 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
542 int rc;
543
544 int cid = wil_find_cid(wil, vif->mid, mac);
545
546 wil_dbg_misc(wil, "get_station: %pM CID %d MID %d\n", mac, cid,
547 vif->mid);
548 if (!wil_cid_valid(wil, cid))
549 return -ENOENT;
550
551 rc = wil_cid_fill_sinfo(vif, cid, sinfo);
552
553 return rc;
554 }
555
556 /*
557 * Find @idx-th active STA for specific MID for station dump.
558 */
wil_find_cid_by_idx(struct wil6210_priv * wil,u8 mid,int idx)559 int wil_find_cid_by_idx(struct wil6210_priv *wil, u8 mid, int idx)
560 {
561 int i;
562
563 for (i = 0; i < wil->max_assoc_sta; i++) {
564 if (wil->sta[i].status == wil_sta_unused)
565 continue;
566 if (wil->sta[i].mid != mid)
567 continue;
568 if (idx == 0)
569 return i;
570 idx--;
571 }
572
573 return -ENOENT;
574 }
575
wil_cfg80211_dump_station(struct wiphy * wiphy,struct wireless_dev * wdev,int idx,u8 * mac,struct station_info * sinfo)576 static int wil_cfg80211_dump_station(struct wiphy *wiphy,
577 struct wireless_dev *wdev, int idx,
578 u8 *mac, struct station_info *sinfo)
579 {
580 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
581 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
582 int rc;
583 int cid = wil_find_cid_by_idx(wil, vif->mid, idx);
584
585 if (!wil_cid_valid(wil, cid))
586 return -ENOENT;
587
588 ether_addr_copy(mac, wil->sta[cid].addr);
589 wil_dbg_misc(wil, "dump_station: %pM CID %d MID %d\n", mac, cid,
590 vif->mid);
591
592 rc = wil_cid_fill_sinfo(vif, cid, sinfo);
593
594 return rc;
595 }
596
wil_cfg80211_start_p2p_device(struct wiphy * wiphy,struct wireless_dev * wdev)597 static int wil_cfg80211_start_p2p_device(struct wiphy *wiphy,
598 struct wireless_dev *wdev)
599 {
600 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
601
602 wil_dbg_misc(wil, "start_p2p_device: entered\n");
603 wil->p2p_dev_started = 1;
604 return 0;
605 }
606
wil_cfg80211_stop_p2p_device(struct wiphy * wiphy,struct wireless_dev * wdev)607 static void wil_cfg80211_stop_p2p_device(struct wiphy *wiphy,
608 struct wireless_dev *wdev)
609 {
610 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
611
612 if (!wil->p2p_dev_started)
613 return;
614
615 wil_dbg_misc(wil, "stop_p2p_device: entered\n");
616 mutex_lock(&wil->mutex);
617 mutex_lock(&wil->vif_mutex);
618 wil_p2p_stop_radio_operations(wil);
619 wil->p2p_dev_started = 0;
620 mutex_unlock(&wil->vif_mutex);
621 mutex_unlock(&wil->mutex);
622 }
623
wil_cfg80211_validate_add_iface(struct wil6210_priv * wil,enum nl80211_iftype new_type)624 static int wil_cfg80211_validate_add_iface(struct wil6210_priv *wil,
625 enum nl80211_iftype new_type)
626 {
627 int i;
628 struct wireless_dev *wdev;
629 struct iface_combination_params params = {
630 .num_different_channels = 1,
631 };
632
633 for (i = 0; i < GET_MAX_VIFS(wil); i++) {
634 if (wil->vifs[i]) {
635 wdev = vif_to_wdev(wil->vifs[i]);
636 params.iftype_num[wdev->iftype]++;
637 }
638 }
639 params.iftype_num[new_type]++;
640 return cfg80211_check_combinations(wil->wiphy, ¶ms);
641 }
642
wil_cfg80211_validate_change_iface(struct wil6210_priv * wil,struct wil6210_vif * vif,enum nl80211_iftype new_type)643 static int wil_cfg80211_validate_change_iface(struct wil6210_priv *wil,
644 struct wil6210_vif *vif,
645 enum nl80211_iftype new_type)
646 {
647 int i, ret = 0;
648 struct wireless_dev *wdev;
649 struct iface_combination_params params = {
650 .num_different_channels = 1,
651 };
652 bool check_combos = false;
653
654 for (i = 0; i < GET_MAX_VIFS(wil); i++) {
655 struct wil6210_vif *vif_pos = wil->vifs[i];
656
657 if (vif_pos && vif != vif_pos) {
658 wdev = vif_to_wdev(vif_pos);
659 params.iftype_num[wdev->iftype]++;
660 check_combos = true;
661 }
662 }
663
664 if (check_combos) {
665 params.iftype_num[new_type]++;
666 ret = cfg80211_check_combinations(wil->wiphy, ¶ms);
667 }
668 return ret;
669 }
670
671 static struct wireless_dev *
wil_cfg80211_add_iface(struct wiphy * wiphy,const char * name,unsigned char name_assign_type,enum nl80211_iftype type,struct vif_params * params)672 wil_cfg80211_add_iface(struct wiphy *wiphy, const char *name,
673 unsigned char name_assign_type,
674 enum nl80211_iftype type,
675 struct vif_params *params)
676 {
677 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
678 struct net_device *ndev_main = wil->main_ndev, *ndev;
679 struct wil6210_vif *vif;
680 struct wireless_dev *p2p_wdev, *wdev;
681 int rc;
682
683 wil_dbg_misc(wil, "add_iface, type %d\n", type);
684
685 /* P2P device is not a real virtual interface, it is a management-only
686 * interface that shares the main interface.
687 * Skip concurrency checks here.
688 */
689 if (type == NL80211_IFTYPE_P2P_DEVICE) {
690 if (wil->p2p_wdev) {
691 wil_err(wil, "P2P_DEVICE interface already created\n");
692 return ERR_PTR(-EINVAL);
693 }
694
695 p2p_wdev = kzalloc_obj(*p2p_wdev);
696 if (!p2p_wdev)
697 return ERR_PTR(-ENOMEM);
698
699 p2p_wdev->iftype = type;
700 p2p_wdev->wiphy = wiphy;
701 /* use our primary ethernet address */
702 ether_addr_copy(p2p_wdev->address, ndev_main->perm_addr);
703
704 wil->p2p_wdev = p2p_wdev;
705
706 return p2p_wdev;
707 }
708
709 if (!wil->wiphy->n_iface_combinations) {
710 wil_err(wil, "virtual interfaces not supported\n");
711 return ERR_PTR(-EINVAL);
712 }
713
714 rc = wil_cfg80211_validate_add_iface(wil, type);
715 if (rc) {
716 wil_err(wil, "iface validation failed, err=%d\n", rc);
717 return ERR_PTR(rc);
718 }
719
720 vif = wil_vif_alloc(wil, name, name_assign_type, type);
721 if (IS_ERR(vif))
722 return ERR_CAST(vif);
723
724 ndev = vif_to_ndev(vif);
725 ether_addr_copy(ndev->perm_addr, ndev_main->perm_addr);
726 if (is_valid_ether_addr(params->macaddr)) {
727 eth_hw_addr_set(ndev, params->macaddr);
728 } else {
729 u8 addr[ETH_ALEN];
730
731 ether_addr_copy(addr, ndev_main->perm_addr);
732 addr[0] = (addr[0] ^ (1 << vif->mid)) | 0x2; /* locally administered */
733 eth_hw_addr_set(ndev, addr);
734 }
735 wdev = vif_to_wdev(vif);
736 ether_addr_copy(wdev->address, ndev->dev_addr);
737
738 rc = wil_vif_add(wil, vif);
739 if (rc)
740 goto out;
741
742 wil_info(wil, "added VIF, mid %d iftype %d MAC %pM\n",
743 vif->mid, type, wdev->address);
744 return wdev;
745 out:
746 wil_vif_free(vif);
747 return ERR_PTR(rc);
748 }
749
wil_vif_prepare_stop(struct wil6210_vif * vif)750 int wil_vif_prepare_stop(struct wil6210_vif *vif)
751 {
752 struct wil6210_priv *wil = vif_to_wil(vif);
753 struct wireless_dev *wdev = vif_to_wdev(vif);
754 struct net_device *ndev;
755 int rc;
756
757 if (wdev->iftype != NL80211_IFTYPE_AP)
758 return 0;
759
760 ndev = vif_to_ndev(vif);
761 if (netif_carrier_ok(ndev)) {
762 rc = wmi_pcp_stop(vif);
763 if (rc) {
764 wil_info(wil, "failed to stop AP, status %d\n",
765 rc);
766 /* continue */
767 }
768 wil_bcast_fini(vif);
769 netif_carrier_off(ndev);
770 }
771
772 return 0;
773 }
774
wil_cfg80211_del_iface(struct wiphy * wiphy,struct wireless_dev * wdev)775 static int wil_cfg80211_del_iface(struct wiphy *wiphy,
776 struct wireless_dev *wdev)
777 {
778 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
779 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
780 int rc;
781
782 wil_dbg_misc(wil, "del_iface\n");
783
784 if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE) {
785 if (wdev != wil->p2p_wdev) {
786 wil_err(wil, "delete of incorrect interface 0x%p\n",
787 wdev);
788 return -EINVAL;
789 }
790
791 wil_cfg80211_stop_p2p_device(wiphy, wdev);
792 wil_p2p_wdev_free(wil);
793 return 0;
794 }
795
796 if (vif->mid == 0) {
797 wil_err(wil, "cannot remove the main interface\n");
798 return -EINVAL;
799 }
800
801 rc = wil_vif_prepare_stop(vif);
802 if (rc)
803 goto out;
804
805 wil_info(wil, "deleted VIF, mid %d iftype %d MAC %pM\n",
806 vif->mid, wdev->iftype, wdev->address);
807
808 wil_vif_remove(wil, vif->mid);
809 out:
810 return rc;
811 }
812
wil_is_safe_switch(enum nl80211_iftype from,enum nl80211_iftype to)813 static bool wil_is_safe_switch(enum nl80211_iftype from,
814 enum nl80211_iftype to)
815 {
816 if (from == NL80211_IFTYPE_STATION &&
817 to == NL80211_IFTYPE_P2P_CLIENT)
818 return true;
819
820 return false;
821 }
822
wil_cfg80211_change_iface(struct wiphy * wiphy,struct net_device * ndev,enum nl80211_iftype type,struct vif_params * params)823 static int wil_cfg80211_change_iface(struct wiphy *wiphy,
824 struct net_device *ndev,
825 enum nl80211_iftype type,
826 struct vif_params *params)
827 {
828 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
829 struct wil6210_vif *vif = ndev_to_vif(ndev);
830 struct wireless_dev *wdev = vif_to_wdev(vif);
831 int rc;
832 bool fw_reset = false;
833
834 wil_dbg_misc(wil, "change_iface: type=%d\n", type);
835
836 if (wiphy->n_iface_combinations) {
837 rc = wil_cfg80211_validate_change_iface(wil, vif, type);
838 if (rc) {
839 wil_err(wil, "iface validation failed, err=%d\n", rc);
840 return rc;
841 }
842 }
843
844 /* do not reset FW when there are active VIFs,
845 * because it can cause significant disruption
846 */
847 if (!wil_has_other_active_ifaces(wil, ndev, true, false) &&
848 netif_running(ndev) && !wil_is_recovery_blocked(wil) &&
849 !wil_is_safe_switch(wdev->iftype, type)) {
850 wil_dbg_misc(wil, "interface is up. resetting...\n");
851 mutex_lock(&wil->mutex);
852 __wil_down(wil);
853 rc = __wil_up(wil);
854 mutex_unlock(&wil->mutex);
855
856 if (rc)
857 return rc;
858 fw_reset = true;
859 }
860
861 switch (type) {
862 case NL80211_IFTYPE_STATION:
863 case NL80211_IFTYPE_AP:
864 case NL80211_IFTYPE_P2P_CLIENT:
865 case NL80211_IFTYPE_P2P_GO:
866 break;
867 case NL80211_IFTYPE_MONITOR:
868 if (params->flags)
869 wil->monitor_flags = params->flags;
870 break;
871 default:
872 return -EOPNOTSUPP;
873 }
874
875 if (vif->mid != 0 && wil_has_active_ifaces(wil, true, false)) {
876 if (!fw_reset)
877 wil_vif_prepare_stop(vif);
878 rc = wmi_port_delete(wil, vif->mid);
879 if (rc)
880 return rc;
881 rc = wmi_port_allocate(wil, vif->mid, ndev->dev_addr, type);
882 if (rc)
883 return rc;
884 }
885
886 wdev->iftype = type;
887 return 0;
888 }
889
wil_cfg80211_scan(struct wiphy * wiphy,struct cfg80211_scan_request * request)890 static int wil_cfg80211_scan(struct wiphy *wiphy,
891 struct cfg80211_scan_request *request)
892 {
893 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
894 struct wireless_dev *wdev = request->wdev;
895 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
896 DEFINE_FLEX(struct wmi_start_scan_cmd, cmd,
897 channel_list, num_channels, 4);
898 uint i, n;
899 int rc;
900
901 wil_dbg_misc(wil, "scan: wdev=0x%p iftype=%d\n", wdev, wdev->iftype);
902
903 /* scan is supported on client interfaces and on AP interface */
904 switch (wdev->iftype) {
905 case NL80211_IFTYPE_STATION:
906 case NL80211_IFTYPE_P2P_CLIENT:
907 case NL80211_IFTYPE_P2P_DEVICE:
908 case NL80211_IFTYPE_AP:
909 break;
910 default:
911 return -EOPNOTSUPP;
912 }
913
914 /* FW don't support scan after connection attempt */
915 if (test_bit(wil_status_dontscan, wil->status)) {
916 wil_err(wil, "Can't scan now\n");
917 return -EBUSY;
918 }
919
920 mutex_lock(&wil->mutex);
921
922 mutex_lock(&wil->vif_mutex);
923 if (vif->scan_request || vif->p2p.discovery_started) {
924 wil_err(wil, "Already scanning\n");
925 mutex_unlock(&wil->vif_mutex);
926 rc = -EAGAIN;
927 goto out;
928 }
929 mutex_unlock(&wil->vif_mutex);
930
931 if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE) {
932 if (!wil->p2p_dev_started) {
933 wil_err(wil, "P2P search requested on stopped P2P device\n");
934 rc = -EIO;
935 goto out;
936 }
937 /* social scan on P2P_DEVICE is handled as p2p search */
938 if (wil_p2p_is_social_scan(request)) {
939 vif->scan_request = request;
940 if (vif->mid == 0)
941 wil->radio_wdev = wdev;
942 rc = wil_p2p_search(vif, request);
943 if (rc) {
944 if (vif->mid == 0)
945 wil->radio_wdev =
946 wil->main_ndev->ieee80211_ptr;
947 vif->scan_request = NULL;
948 }
949 goto out;
950 }
951 }
952
953 (void)wil_p2p_stop_discovery(vif);
954
955 wil_dbg_misc(wil, "Start scan_request 0x%p\n", request);
956 wil_dbg_misc(wil, "SSID count: %d", request->n_ssids);
957
958 for (i = 0; i < request->n_ssids; i++) {
959 wil_dbg_misc(wil, "SSID[%d]", i);
960 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
961 request->ssids[i].ssid,
962 request->ssids[i].ssid_len, true);
963 }
964
965 if (request->n_ssids)
966 rc = wmi_set_ssid(vif, request->ssids[0].ssid_len,
967 request->ssids[0].ssid);
968 else
969 rc = wmi_set_ssid(vif, 0, NULL);
970
971 if (rc) {
972 wil_err(wil, "set SSID for scan request failed: %d\n", rc);
973 goto out;
974 }
975
976 vif->scan_request = request;
977 mod_timer(&vif->scan_timer, jiffies + WIL6210_SCAN_TO);
978
979 cmd->scan_type = WMI_ACTIVE_SCAN;
980 cmd->num_channels = 0;
981 n = min(request->n_channels, 4U);
982 for (i = 0; i < n; i++) {
983 int ch = request->channels[i]->hw_value;
984
985 if (ch == 0) {
986 wil_err(wil,
987 "Scan requested for unknown frequency %dMhz\n",
988 request->channels[i]->center_freq);
989 continue;
990 }
991 /* 0-based channel indexes */
992 cmd->num_channels++;
993 cmd->channel_list[cmd->num_channels - 1].channel = ch - 1;
994 wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch,
995 request->channels[i]->center_freq);
996 }
997
998 if (request->ie_len)
999 wil_hex_dump_misc("Scan IE ", DUMP_PREFIX_OFFSET, 16, 1,
1000 request->ie, request->ie_len, true);
1001 else
1002 wil_dbg_misc(wil, "Scan has no IE's\n");
1003
1004 rc = wmi_set_ie(vif, WMI_FRAME_PROBE_REQ,
1005 request->ie_len, request->ie);
1006 if (rc)
1007 goto out_restore;
1008
1009 if (wil->discovery_mode && cmd->scan_type == WMI_ACTIVE_SCAN) {
1010 cmd->discovery_mode = 1;
1011 wil_dbg_misc(wil, "active scan with discovery_mode=1\n");
1012 }
1013
1014 if (vif->mid == 0)
1015 wil->radio_wdev = wdev;
1016 rc = wmi_send(wil, WMI_START_SCAN_CMDID, vif->mid,
1017 cmd, struct_size(cmd, channel_list, cmd->num_channels));
1018
1019 out_restore:
1020 if (rc) {
1021 timer_delete_sync(&vif->scan_timer);
1022 if (vif->mid == 0)
1023 wil->radio_wdev = wil->main_ndev->ieee80211_ptr;
1024 vif->scan_request = NULL;
1025 }
1026 out:
1027 mutex_unlock(&wil->mutex);
1028 return rc;
1029 }
1030
wil_cfg80211_abort_scan(struct wiphy * wiphy,struct wireless_dev * wdev)1031 static void wil_cfg80211_abort_scan(struct wiphy *wiphy,
1032 struct wireless_dev *wdev)
1033 {
1034 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1035 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
1036
1037 wil_dbg_misc(wil, "wdev=0x%p iftype=%d\n", wdev, wdev->iftype);
1038
1039 mutex_lock(&wil->mutex);
1040 mutex_lock(&wil->vif_mutex);
1041
1042 if (!vif->scan_request)
1043 goto out;
1044
1045 if (wdev != vif->scan_request->wdev) {
1046 wil_dbg_misc(wil, "abort scan was called on the wrong iface\n");
1047 goto out;
1048 }
1049
1050 if (wdev == wil->p2p_wdev && wil->radio_wdev == wil->p2p_wdev)
1051 wil_p2p_stop_radio_operations(wil);
1052 else
1053 wil_abort_scan(vif, true);
1054
1055 out:
1056 mutex_unlock(&wil->vif_mutex);
1057 mutex_unlock(&wil->mutex);
1058 }
1059
wil_print_crypto(struct wil6210_priv * wil,struct cfg80211_crypto_settings * c)1060 static void wil_print_crypto(struct wil6210_priv *wil,
1061 struct cfg80211_crypto_settings *c)
1062 {
1063 int i, n;
1064
1065 wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n",
1066 c->wpa_versions, c->cipher_group);
1067 wil_dbg_misc(wil, "Pairwise ciphers [%d] {\n", c->n_ciphers_pairwise);
1068 n = min_t(int, c->n_ciphers_pairwise, ARRAY_SIZE(c->ciphers_pairwise));
1069 for (i = 0; i < n; i++)
1070 wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
1071 c->ciphers_pairwise[i]);
1072 wil_dbg_misc(wil, "}\n");
1073 wil_dbg_misc(wil, "AKM suites [%d] {\n", c->n_akm_suites);
1074 n = min_t(int, c->n_akm_suites, ARRAY_SIZE(c->akm_suites));
1075 for (i = 0; i < n; i++)
1076 wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
1077 c->akm_suites[i]);
1078 wil_dbg_misc(wil, "}\n");
1079 wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n",
1080 c->control_port, be16_to_cpu(c->control_port_ethertype),
1081 c->control_port_no_encrypt);
1082 }
1083
1084 static const char *
wil_get_auth_type_name(enum nl80211_auth_type auth_type)1085 wil_get_auth_type_name(enum nl80211_auth_type auth_type)
1086 {
1087 switch (auth_type) {
1088 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1089 return "OPEN_SYSTEM";
1090 case NL80211_AUTHTYPE_SHARED_KEY:
1091 return "SHARED_KEY";
1092 case NL80211_AUTHTYPE_FT:
1093 return "FT";
1094 case NL80211_AUTHTYPE_NETWORK_EAP:
1095 return "NETWORK_EAP";
1096 case NL80211_AUTHTYPE_SAE:
1097 return "SAE";
1098 case NL80211_AUTHTYPE_AUTOMATIC:
1099 return "AUTOMATIC";
1100 default:
1101 return "unknown";
1102 }
1103 }
wil_print_connect_params(struct wil6210_priv * wil,struct cfg80211_connect_params * sme)1104 static void wil_print_connect_params(struct wil6210_priv *wil,
1105 struct cfg80211_connect_params *sme)
1106 {
1107 wil_info(wil, "Connecting to:\n");
1108 if (sme->channel) {
1109 wil_info(wil, " Channel: %d freq %d\n",
1110 sme->channel->hw_value, sme->channel->center_freq);
1111 }
1112 if (sme->bssid)
1113 wil_info(wil, " BSSID: %pM\n", sme->bssid);
1114 if (sme->ssid)
1115 print_hex_dump(KERN_INFO, " SSID: ", DUMP_PREFIX_OFFSET,
1116 16, 1, sme->ssid, sme->ssid_len, true);
1117 if (sme->prev_bssid)
1118 wil_info(wil, " Previous BSSID=%pM\n", sme->prev_bssid);
1119 wil_info(wil, " Auth Type: %s\n",
1120 wil_get_auth_type_name(sme->auth_type));
1121 wil_info(wil, " Privacy: %s\n", sme->privacy ? "secure" : "open");
1122 wil_info(wil, " PBSS: %d\n", sme->pbss);
1123 wil_print_crypto(wil, &sme->crypto);
1124 }
1125
wil_ft_connect(struct wiphy * wiphy,struct net_device * ndev,struct cfg80211_connect_params * sme)1126 static int wil_ft_connect(struct wiphy *wiphy,
1127 struct net_device *ndev,
1128 struct cfg80211_connect_params *sme)
1129 {
1130 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1131 struct wil6210_vif *vif = ndev_to_vif(ndev);
1132 struct wmi_ft_auth_cmd auth_cmd;
1133 int rc;
1134
1135 if (!test_bit(WMI_FW_CAPABILITY_FT_ROAMING, wil->fw_capabilities)) {
1136 wil_err(wil, "FT: FW does not support FT roaming\n");
1137 return -EOPNOTSUPP;
1138 }
1139
1140 if (!sme->prev_bssid) {
1141 wil_err(wil, "FT: prev_bssid was not set\n");
1142 return -EINVAL;
1143 }
1144
1145 if (ether_addr_equal(sme->prev_bssid, sme->bssid)) {
1146 wil_err(wil, "FT: can not roam to same AP\n");
1147 return -EINVAL;
1148 }
1149
1150 if (!test_bit(wil_vif_fwconnected, vif->status)) {
1151 wil_err(wil, "FT: roam while not connected\n");
1152 return -EINVAL;
1153 }
1154
1155 if (vif->privacy != sme->privacy) {
1156 wil_err(wil, "FT: privacy mismatch, current (%d) roam (%d)\n",
1157 vif->privacy, sme->privacy);
1158 return -EINVAL;
1159 }
1160
1161 if (sme->pbss) {
1162 wil_err(wil, "FT: roam is not valid for PBSS\n");
1163 return -EINVAL;
1164 }
1165
1166 memset(&auth_cmd, 0, sizeof(auth_cmd));
1167 auth_cmd.channel = sme->channel->hw_value - 1;
1168 ether_addr_copy(auth_cmd.bssid, sme->bssid);
1169
1170 wil_info(wil, "FT: roaming\n");
1171
1172 set_bit(wil_vif_ft_roam, vif->status);
1173 rc = wmi_send(wil, WMI_FT_AUTH_CMDID, vif->mid,
1174 &auth_cmd, sizeof(auth_cmd));
1175 if (rc == 0)
1176 mod_timer(&vif->connect_timer,
1177 jiffies + msecs_to_jiffies(5000));
1178 else
1179 clear_bit(wil_vif_ft_roam, vif->status);
1180
1181 return rc;
1182 }
1183
wil_get_wmi_edmg_channel(struct wil6210_priv * wil,u8 edmg_bw_config,u8 edmg_channels,u8 * wmi_ch)1184 static int wil_get_wmi_edmg_channel(struct wil6210_priv *wil, u8 edmg_bw_config,
1185 u8 edmg_channels, u8 *wmi_ch)
1186 {
1187 if (!edmg_bw_config) {
1188 *wmi_ch = 0;
1189 return 0;
1190 } else if (edmg_bw_config == WIL_EDMG_BW_CONFIGURATION) {
1191 /* convert from edmg channel bitmap into edmg channel number */
1192 switch (edmg_channels) {
1193 case WIL_EDMG_CHANNEL_9_SUBCHANNELS:
1194 return wil_spec2wmi_ch(9, wmi_ch);
1195 case WIL_EDMG_CHANNEL_10_SUBCHANNELS:
1196 return wil_spec2wmi_ch(10, wmi_ch);
1197 case WIL_EDMG_CHANNEL_11_SUBCHANNELS:
1198 return wil_spec2wmi_ch(11, wmi_ch);
1199 default:
1200 wil_err(wil, "Unsupported edmg channel bitmap 0x%x\n",
1201 edmg_channels);
1202 return -EINVAL;
1203 }
1204 } else {
1205 wil_err(wil, "Unsupported EDMG BW configuration %d\n",
1206 edmg_bw_config);
1207 return -EINVAL;
1208 }
1209 }
1210
wil_cfg80211_connect(struct wiphy * wiphy,struct net_device * ndev,struct cfg80211_connect_params * sme)1211 static int wil_cfg80211_connect(struct wiphy *wiphy,
1212 struct net_device *ndev,
1213 struct cfg80211_connect_params *sme)
1214 {
1215 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1216 struct wil6210_vif *vif = ndev_to_vif(ndev);
1217 struct cfg80211_bss *bss;
1218 struct wmi_connect_cmd conn;
1219 const u8 *ssid_eid;
1220 const u8 *rsn_eid;
1221 int ch;
1222 int rc = 0;
1223 bool is_ft_roam = false;
1224 u8 network_type;
1225 enum ieee80211_bss_type bss_type = IEEE80211_BSS_TYPE_ESS;
1226
1227 wil_dbg_misc(wil, "connect, mid=%d\n", vif->mid);
1228 wil_print_connect_params(wil, sme);
1229
1230 if (sme->auth_type == NL80211_AUTHTYPE_FT)
1231 is_ft_roam = true;
1232 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC &&
1233 test_bit(wil_vif_fwconnected, vif->status))
1234 is_ft_roam = true;
1235
1236 if (!is_ft_roam)
1237 if (test_bit(wil_vif_fwconnecting, vif->status) ||
1238 test_bit(wil_vif_fwconnected, vif->status))
1239 return -EALREADY;
1240
1241 if (sme->ie_len > WMI_MAX_IE_LEN) {
1242 wil_err(wil, "IE too large (%td bytes)\n", sme->ie_len);
1243 return -ERANGE;
1244 }
1245
1246 rsn_eid = sme->ie ?
1247 cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
1248 NULL;
1249 if (sme->privacy && !rsn_eid) {
1250 wil_info(wil, "WSC connection\n");
1251 if (is_ft_roam) {
1252 wil_err(wil, "No WSC with FT roam\n");
1253 return -EINVAL;
1254 }
1255 }
1256
1257 if (sme->pbss)
1258 bss_type = IEEE80211_BSS_TYPE_PBSS;
1259
1260 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
1261 sme->ssid, sme->ssid_len,
1262 bss_type, IEEE80211_PRIVACY_ANY);
1263 if (!bss) {
1264 wil_err(wil, "Unable to find BSS\n");
1265 return -ENOENT;
1266 }
1267
1268 ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
1269 if (!ssid_eid) {
1270 wil_err(wil, "No SSID\n");
1271 rc = -ENOENT;
1272 goto out;
1273 }
1274 vif->privacy = sme->privacy;
1275 vif->pbss = sme->pbss;
1276
1277 rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
1278 if (rc)
1279 goto out;
1280
1281 switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
1282 case WLAN_CAPABILITY_DMG_TYPE_AP:
1283 network_type = WMI_NETTYPE_INFRA;
1284 break;
1285 case WLAN_CAPABILITY_DMG_TYPE_PBSS:
1286 network_type = WMI_NETTYPE_P2P;
1287 break;
1288 default:
1289 wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
1290 bss->capability);
1291 rc = -EINVAL;
1292 goto out;
1293 }
1294
1295 ch = bss->channel->hw_value;
1296 if (ch == 0) {
1297 wil_err(wil, "BSS at unknown frequency %dMhz\n",
1298 bss->channel->center_freq);
1299 rc = -EOPNOTSUPP;
1300 goto out;
1301 }
1302
1303 if (is_ft_roam) {
1304 if (network_type != WMI_NETTYPE_INFRA) {
1305 wil_err(wil, "FT: Unsupported BSS type, capability= 0x%04x\n",
1306 bss->capability);
1307 rc = -EINVAL;
1308 goto out;
1309 }
1310 rc = wil_ft_connect(wiphy, ndev, sme);
1311 if (rc == 0)
1312 vif->bss = bss;
1313 goto out;
1314 }
1315
1316 if (vif->privacy) {
1317 /* For secure assoc, remove old keys */
1318 rc = wmi_del_cipher_key(vif, 0, bss->bssid,
1319 WMI_KEY_USE_PAIRWISE);
1320 if (rc) {
1321 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(PTK) failed\n");
1322 goto out;
1323 }
1324 rc = wmi_del_cipher_key(vif, 0, bss->bssid,
1325 WMI_KEY_USE_RX_GROUP);
1326 if (rc) {
1327 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(GTK) failed\n");
1328 goto out;
1329 }
1330 }
1331
1332 /* WMI_CONNECT_CMD */
1333 memset(&conn, 0, sizeof(conn));
1334 conn.network_type = network_type;
1335 if (vif->privacy) {
1336 if (rsn_eid) { /* regular secure connection */
1337 conn.dot11_auth_mode = WMI_AUTH11_SHARED;
1338 conn.auth_mode = WMI_AUTH_WPA2_PSK;
1339 conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
1340 conn.pairwise_crypto_len = 16;
1341 conn.group_crypto_type = WMI_CRYPT_AES_GCMP;
1342 conn.group_crypto_len = 16;
1343 } else { /* WSC */
1344 conn.dot11_auth_mode = WMI_AUTH11_WSC;
1345 conn.auth_mode = WMI_AUTH_NONE;
1346 }
1347 } else { /* insecure connection */
1348 conn.dot11_auth_mode = WMI_AUTH11_OPEN;
1349 conn.auth_mode = WMI_AUTH_NONE;
1350 }
1351
1352 conn.ssid_len = min_t(u8, ssid_eid[1], 32);
1353 memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
1354 conn.channel = ch - 1;
1355
1356 rc = wil_get_wmi_edmg_channel(wil, sme->edmg.bw_config,
1357 sme->edmg.channels, &conn.edmg_channel);
1358 if (rc < 0)
1359 return rc;
1360
1361 ether_addr_copy(conn.bssid, bss->bssid);
1362 ether_addr_copy(conn.dst_mac, bss->bssid);
1363
1364 set_bit(wil_vif_fwconnecting, vif->status);
1365
1366 rc = wmi_send(wil, WMI_CONNECT_CMDID, vif->mid, &conn, sizeof(conn));
1367 if (rc == 0) {
1368 netif_carrier_on(ndev);
1369 if (!wil_has_other_active_ifaces(wil, ndev, false, true))
1370 wil6210_bus_request(wil, WIL_MAX_BUS_REQUEST_KBPS);
1371 vif->bss = bss;
1372 /* Connect can take lots of time */
1373 mod_timer(&vif->connect_timer,
1374 jiffies + msecs_to_jiffies(5000));
1375 } else {
1376 clear_bit(wil_vif_fwconnecting, vif->status);
1377 }
1378
1379 out:
1380 cfg80211_put_bss(wiphy, bss);
1381
1382 return rc;
1383 }
1384
wil_cfg80211_disconnect(struct wiphy * wiphy,struct net_device * ndev,u16 reason_code)1385 static int wil_cfg80211_disconnect(struct wiphy *wiphy,
1386 struct net_device *ndev,
1387 u16 reason_code)
1388 {
1389 int rc;
1390 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1391 struct wil6210_vif *vif = ndev_to_vif(ndev);
1392
1393 wil_dbg_misc(wil, "disconnect: reason=%d, mid=%d\n",
1394 reason_code, vif->mid);
1395
1396 if (!(test_bit(wil_vif_fwconnecting, vif->status) ||
1397 test_bit(wil_vif_fwconnected, vif->status))) {
1398 wil_err(wil, "Disconnect was called while disconnected\n");
1399 return 0;
1400 }
1401
1402 vif->locally_generated_disc = true;
1403 rc = wmi_call(wil, WMI_DISCONNECT_CMDID, vif->mid, NULL, 0,
1404 WMI_DISCONNECT_EVENTID, NULL, 0,
1405 WIL6210_DISCONNECT_TO_MS);
1406 if (rc)
1407 wil_err(wil, "disconnect error %d\n", rc);
1408
1409 return rc;
1410 }
1411
wil_cfg80211_set_wiphy_params(struct wiphy * wiphy,int radio_idx,u32 changed)1412 static int wil_cfg80211_set_wiphy_params(struct wiphy *wiphy, int radio_idx,
1413 u32 changed)
1414 {
1415 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1416 int rc;
1417
1418 /* these parameters are explicitly not supported */
1419 if (changed & (WIPHY_PARAM_RETRY_LONG |
1420 WIPHY_PARAM_FRAG_THRESHOLD |
1421 WIPHY_PARAM_RTS_THRESHOLD))
1422 return -ENOTSUPP;
1423
1424 if (changed & WIPHY_PARAM_RETRY_SHORT) {
1425 rc = wmi_set_mgmt_retry(wil, wiphy->retry_short);
1426 if (rc)
1427 return rc;
1428 }
1429
1430 return 0;
1431 }
1432
wil_cfg80211_mgmt_tx(struct wiphy * wiphy,struct wireless_dev * wdev,struct cfg80211_mgmt_tx_params * params,u64 cookie)1433 int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
1434 struct cfg80211_mgmt_tx_params *params,
1435 u64 cookie)
1436 {
1437 const u8 *buf = params->buf;
1438 size_t len = params->len;
1439 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1440 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
1441 int rc;
1442 bool tx_status;
1443
1444 wil_dbg_misc(wil, "mgmt_tx: channel %d offchan %d, wait %d\n",
1445 params->chan ? params->chan->hw_value : -1,
1446 params->offchan,
1447 params->wait);
1448
1449 /* Note, currently we support the "wait" parameter only on AP mode.
1450 * In other modes, user-space must call remain_on_channel before
1451 * mgmt_tx or listen on a channel other than active one.
1452 */
1453
1454 if (params->chan && params->chan->hw_value == 0) {
1455 wil_err(wil, "invalid channel\n");
1456 return -EINVAL;
1457 }
1458
1459 if (wdev->iftype != NL80211_IFTYPE_AP) {
1460 wil_dbg_misc(wil,
1461 "send WMI_SW_TX_REQ_CMDID on non-AP interfaces\n");
1462 rc = wmi_mgmt_tx(vif, buf, len);
1463 goto out;
1464 }
1465
1466 if (!params->chan || params->chan->hw_value == vif->channel) {
1467 wil_dbg_misc(wil,
1468 "send WMI_SW_TX_REQ_CMDID for on-channel\n");
1469 rc = wmi_mgmt_tx(vif, buf, len);
1470 goto out;
1471 }
1472
1473 if (params->offchan == 0) {
1474 wil_err(wil,
1475 "invalid channel params: current %d requested %d, off-channel not allowed\n",
1476 vif->channel, params->chan->hw_value);
1477 return -EBUSY;
1478 }
1479
1480 /* use the wmi_mgmt_tx_ext only on AP mode and off-channel */
1481 rc = wmi_mgmt_tx_ext(vif, buf, len, params->chan->hw_value,
1482 params->wait);
1483
1484 out:
1485 /* when the sent packet was not acked by receiver(ACK=0), rc will
1486 * be -EAGAIN. In this case this function needs to return success,
1487 * the ACK=0 will be reflected in tx_status.
1488 */
1489 tx_status = (rc == 0);
1490 rc = (rc == -EAGAIN) ? 0 : rc;
1491 cfg80211_mgmt_tx_status(wdev, cookie, buf, len, tx_status, GFP_KERNEL);
1492
1493 return rc;
1494 }
1495
wil_cfg80211_set_channel(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_chan_def * chandef)1496 static int wil_cfg80211_set_channel(struct wiphy *wiphy,
1497 struct net_device *dev,
1498 struct cfg80211_chan_def *chandef)
1499 {
1500 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1501
1502 wil->monitor_chandef = *chandef;
1503
1504 return 0;
1505 }
1506
wil_detect_key_usage(struct wireless_dev * wdev,bool pairwise)1507 static enum wmi_key_usage wil_detect_key_usage(struct wireless_dev *wdev,
1508 bool pairwise)
1509 {
1510 struct wil6210_priv *wil = wdev_to_wil(wdev);
1511 enum wmi_key_usage rc;
1512
1513 if (pairwise) {
1514 rc = WMI_KEY_USE_PAIRWISE;
1515 } else {
1516 switch (wdev->iftype) {
1517 case NL80211_IFTYPE_STATION:
1518 case NL80211_IFTYPE_P2P_CLIENT:
1519 rc = WMI_KEY_USE_RX_GROUP;
1520 break;
1521 case NL80211_IFTYPE_AP:
1522 case NL80211_IFTYPE_P2P_GO:
1523 rc = WMI_KEY_USE_TX_GROUP;
1524 break;
1525 default:
1526 /* TODO: Rx GTK or Tx GTK? */
1527 wil_err(wil, "Can't determine GTK type\n");
1528 rc = WMI_KEY_USE_RX_GROUP;
1529 break;
1530 }
1531 }
1532 wil_dbg_misc(wil, "detect_key_usage: -> %s\n", key_usage_str[rc]);
1533
1534 return rc;
1535 }
1536
1537 static struct wil_sta_info *
wil_find_sta_by_key_usage(struct wil6210_priv * wil,u8 mid,enum wmi_key_usage key_usage,const u8 * mac_addr)1538 wil_find_sta_by_key_usage(struct wil6210_priv *wil, u8 mid,
1539 enum wmi_key_usage key_usage, const u8 *mac_addr)
1540 {
1541 int cid = -EINVAL;
1542
1543 if (key_usage == WMI_KEY_USE_TX_GROUP)
1544 return NULL; /* not needed */
1545
1546 /* supplicant provides Rx group key in STA mode with NULL MAC address */
1547 if (mac_addr)
1548 cid = wil_find_cid(wil, mid, mac_addr);
1549 else if (key_usage == WMI_KEY_USE_RX_GROUP)
1550 cid = wil_find_cid_by_idx(wil, mid, 0);
1551 if (cid < 0) {
1552 wil_err(wil, "No CID for %pM %s\n", mac_addr,
1553 key_usage_str[key_usage]);
1554 return ERR_PTR(cid);
1555 }
1556
1557 return &wil->sta[cid];
1558 }
1559
wil_set_crypto_rx(u8 key_index,enum wmi_key_usage key_usage,struct wil_sta_info * cs,struct key_params * params)1560 void wil_set_crypto_rx(u8 key_index, enum wmi_key_usage key_usage,
1561 struct wil_sta_info *cs,
1562 struct key_params *params)
1563 {
1564 struct wil_tid_crypto_rx_single *cc;
1565 int tid;
1566
1567 if (!cs)
1568 return;
1569
1570 switch (key_usage) {
1571 case WMI_KEY_USE_STORE_PTK:
1572 case WMI_KEY_USE_PAIRWISE:
1573 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1574 cc = &cs->tid_crypto_rx[tid].key_id[key_index];
1575 if (params->seq)
1576 memcpy(cc->pn, params->seq,
1577 IEEE80211_GCMP_PN_LEN);
1578 else
1579 memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
1580 cc->key_set = true;
1581 }
1582 break;
1583 case WMI_KEY_USE_RX_GROUP:
1584 cc = &cs->group_crypto_rx.key_id[key_index];
1585 if (params->seq)
1586 memcpy(cc->pn, params->seq, IEEE80211_GCMP_PN_LEN);
1587 else
1588 memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
1589 cc->key_set = true;
1590 break;
1591 default:
1592 break;
1593 }
1594 }
1595
wil_del_rx_key(u8 key_index,enum wmi_key_usage key_usage,struct wil_sta_info * cs)1596 static void wil_del_rx_key(u8 key_index, enum wmi_key_usage key_usage,
1597 struct wil_sta_info *cs)
1598 {
1599 struct wil_tid_crypto_rx_single *cc;
1600 int tid;
1601
1602 if (!cs)
1603 return;
1604
1605 switch (key_usage) {
1606 case WMI_KEY_USE_PAIRWISE:
1607 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1608 cc = &cs->tid_crypto_rx[tid].key_id[key_index];
1609 cc->key_set = false;
1610 }
1611 break;
1612 case WMI_KEY_USE_RX_GROUP:
1613 cc = &cs->group_crypto_rx.key_id[key_index];
1614 cc->key_set = false;
1615 break;
1616 default:
1617 break;
1618 }
1619 }
1620
wil_cfg80211_add_key(struct wiphy * wiphy,struct wireless_dev * wdev,int link_id,u8 key_index,bool pairwise,const u8 * mac_addr,struct key_params * params)1621 static int wil_cfg80211_add_key(struct wiphy *wiphy,
1622 struct wireless_dev *wdev, int link_id,
1623 u8 key_index, bool pairwise,
1624 const u8 *mac_addr,
1625 struct key_params *params)
1626 {
1627 int rc;
1628 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1629 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
1630 enum wmi_key_usage key_usage = wil_detect_key_usage(wdev, pairwise);
1631 struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, vif->mid,
1632 key_usage,
1633 mac_addr);
1634
1635 if (!params) {
1636 wil_err(wil, "NULL params\n");
1637 return -EINVAL;
1638 }
1639
1640 wil_dbg_misc(wil, "add_key: %pM %s[%d] PN %*phN\n",
1641 mac_addr, key_usage_str[key_usage], key_index,
1642 params->seq_len, params->seq);
1643
1644 if (IS_ERR(cs)) {
1645 /* in FT, sta info may not be available as add_key may be
1646 * sent by host before FW sends WMI_CONNECT_EVENT
1647 */
1648 if (!test_bit(wil_vif_ft_roam, vif->status)) {
1649 wil_err(wil, "Not connected, %pM %s[%d] PN %*phN\n",
1650 mac_addr, key_usage_str[key_usage], key_index,
1651 params->seq_len, params->seq);
1652 return -EINVAL;
1653 }
1654 } else {
1655 wil_del_rx_key(key_index, key_usage, cs);
1656 }
1657
1658 if (params->seq && params->seq_len != IEEE80211_GCMP_PN_LEN) {
1659 wil_err(wil,
1660 "Wrong PN len %d, %pM %s[%d] PN %*phN\n",
1661 params->seq_len, mac_addr,
1662 key_usage_str[key_usage], key_index,
1663 params->seq_len, params->seq);
1664 return -EINVAL;
1665 }
1666
1667 spin_lock_bh(&wil->eap_lock);
1668 if (pairwise && wdev->iftype == NL80211_IFTYPE_STATION &&
1669 (vif->ptk_rekey_state == WIL_REKEY_M3_RECEIVED ||
1670 vif->ptk_rekey_state == WIL_REKEY_WAIT_M4_SENT)) {
1671 key_usage = WMI_KEY_USE_STORE_PTK;
1672 vif->ptk_rekey_state = WIL_REKEY_WAIT_M4_SENT;
1673 wil_dbg_misc(wil, "Store EAPOL key\n");
1674 }
1675 spin_unlock_bh(&wil->eap_lock);
1676
1677 rc = wmi_add_cipher_key(vif, key_index, mac_addr, params->key_len,
1678 params->key, key_usage);
1679 if (!rc && !IS_ERR(cs)) {
1680 /* update local storage used for AP recovery */
1681 if (key_usage == WMI_KEY_USE_TX_GROUP && params->key &&
1682 params->key_len <= WMI_MAX_KEY_LEN) {
1683 vif->gtk_index = key_index;
1684 memcpy(vif->gtk, params->key, params->key_len);
1685 vif->gtk_len = params->key_len;
1686 }
1687 /* in FT set crypto will take place upon receiving
1688 * WMI_RING_EN_EVENTID event
1689 */
1690 wil_set_crypto_rx(key_index, key_usage, cs, params);
1691 }
1692
1693 return rc;
1694 }
1695
wil_cfg80211_del_key(struct wiphy * wiphy,struct wireless_dev * wdev,int link_id,u8 key_index,bool pairwise,const u8 * mac_addr)1696 static int wil_cfg80211_del_key(struct wiphy *wiphy,
1697 struct wireless_dev *wdev, int link_id,
1698 u8 key_index, bool pairwise,
1699 const u8 *mac_addr)
1700 {
1701 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1702 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
1703 enum wmi_key_usage key_usage = wil_detect_key_usage(wdev, pairwise);
1704 struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, vif->mid,
1705 key_usage,
1706 mac_addr);
1707
1708 wil_dbg_misc(wil, "del_key: %pM %s[%d]\n", mac_addr,
1709 key_usage_str[key_usage], key_index);
1710
1711 if (IS_ERR(cs))
1712 wil_info(wil, "Not connected, %pM %s[%d]\n",
1713 mac_addr, key_usage_str[key_usage], key_index);
1714
1715 if (!IS_ERR_OR_NULL(cs))
1716 wil_del_rx_key(key_index, key_usage, cs);
1717
1718 return wmi_del_cipher_key(vif, key_index, mac_addr, key_usage);
1719 }
1720
1721 /* Need to be present or wiphy_new() will WARN */
wil_cfg80211_set_default_key(struct wiphy * wiphy,struct net_device * ndev,int link_id,u8 key_index,bool unicast,bool multicast)1722 static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
1723 struct net_device *ndev, int link_id,
1724 u8 key_index, bool unicast,
1725 bool multicast)
1726 {
1727 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1728
1729 wil_dbg_misc(wil, "set_default_key: entered\n");
1730 return 0;
1731 }
1732
wil_remain_on_channel(struct wiphy * wiphy,struct wireless_dev * wdev,struct ieee80211_channel * chan,unsigned int duration,u64 cookie,const u8 * rx_addr)1733 static int wil_remain_on_channel(struct wiphy *wiphy,
1734 struct wireless_dev *wdev,
1735 struct ieee80211_channel *chan,
1736 unsigned int duration,
1737 u64 cookie, const u8 *rx_addr)
1738 {
1739 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1740 int rc;
1741
1742 wil_dbg_misc(wil,
1743 "remain_on_channel: center_freq=%d, duration=%d iftype=%d\n",
1744 chan->center_freq, duration, wdev->iftype);
1745
1746 rc = wil_p2p_listen(wil, wdev, duration, chan, cookie);
1747 return rc;
1748 }
1749
wil_cancel_remain_on_channel(struct wiphy * wiphy,struct wireless_dev * wdev,u64 cookie)1750 static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
1751 struct wireless_dev *wdev,
1752 u64 cookie)
1753 {
1754 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1755 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
1756
1757 wil_dbg_misc(wil, "cancel_remain_on_channel\n");
1758
1759 return wil_p2p_cancel_listen(vif, cookie);
1760 }
1761
1762 /*
1763 * find a specific IE in a list of IEs
1764 * return a pointer to the beginning of IE in the list
1765 * or NULL if not found
1766 */
_wil_cfg80211_find_ie(const u8 * ies,u16 ies_len,const u8 * ie,u16 ie_len)1767 static const u8 *_wil_cfg80211_find_ie(const u8 *ies, u16 ies_len, const u8 *ie,
1768 u16 ie_len)
1769 {
1770 struct ieee80211_vendor_ie *vie;
1771 u32 oui;
1772
1773 /* IE tag at offset 0, length at offset 1 */
1774 if (ie_len < 2 || 2 + ie[1] > ie_len)
1775 return NULL;
1776
1777 if (ie[0] != WLAN_EID_VENDOR_SPECIFIC)
1778 return cfg80211_find_ie(ie[0], ies, ies_len);
1779
1780 /* make sure there is room for 3 bytes OUI + 1 byte OUI type */
1781 if (ie[1] < 4)
1782 return NULL;
1783 vie = (struct ieee80211_vendor_ie *)ie;
1784 oui = vie->oui[0] << 16 | vie->oui[1] << 8 | vie->oui[2];
1785 return cfg80211_find_vendor_ie(oui, vie->oui_type, ies,
1786 ies_len);
1787 }
1788
1789 /*
1790 * merge the IEs in two lists into a single list.
1791 * do not include IEs from the second list which exist in the first list.
1792 * add only vendor specific IEs from second list to keep
1793 * the merged list sorted (since vendor-specific IE has the
1794 * highest tag number)
1795 * caller must free the allocated memory for merged IEs
1796 */
_wil_cfg80211_merge_extra_ies(const u8 * ies1,u16 ies1_len,const u8 * ies2,u16 ies2_len,u8 ** merged_ies,u16 * merged_len)1797 static int _wil_cfg80211_merge_extra_ies(const u8 *ies1, u16 ies1_len,
1798 const u8 *ies2, u16 ies2_len,
1799 u8 **merged_ies, u16 *merged_len)
1800 {
1801 u8 *buf, *dpos;
1802 const u8 *spos;
1803
1804 if (!ies1)
1805 ies1_len = 0;
1806
1807 if (!ies2)
1808 ies2_len = 0;
1809
1810 if (ies1_len == 0 && ies2_len == 0) {
1811 *merged_ies = NULL;
1812 *merged_len = 0;
1813 return 0;
1814 }
1815
1816 buf = kmalloc(ies1_len + ies2_len, GFP_KERNEL);
1817 if (!buf)
1818 return -ENOMEM;
1819 if (ies1)
1820 memcpy(buf, ies1, ies1_len);
1821 dpos = buf + ies1_len;
1822 spos = ies2;
1823 while (spos && (spos + 1 < ies2 + ies2_len)) {
1824 /* IE tag at offset 0, length at offset 1 */
1825 u16 ielen = 2 + spos[1];
1826
1827 if (spos + ielen > ies2 + ies2_len)
1828 break;
1829 if (spos[0] == WLAN_EID_VENDOR_SPECIFIC &&
1830 (!ies1 || !_wil_cfg80211_find_ie(ies1, ies1_len,
1831 spos, ielen))) {
1832 memcpy(dpos, spos, ielen);
1833 dpos += ielen;
1834 }
1835 spos += ielen;
1836 }
1837
1838 *merged_ies = buf;
1839 *merged_len = dpos - buf;
1840 return 0;
1841 }
1842
wil_print_bcon_data(struct cfg80211_beacon_data * b)1843 static void wil_print_bcon_data(struct cfg80211_beacon_data *b)
1844 {
1845 wil_hex_dump_misc("head ", DUMP_PREFIX_OFFSET, 16, 1,
1846 b->head, b->head_len, true);
1847 wil_hex_dump_misc("tail ", DUMP_PREFIX_OFFSET, 16, 1,
1848 b->tail, b->tail_len, true);
1849 wil_hex_dump_misc("BCON IE ", DUMP_PREFIX_OFFSET, 16, 1,
1850 b->beacon_ies, b->beacon_ies_len, true);
1851 wil_hex_dump_misc("PROBE ", DUMP_PREFIX_OFFSET, 16, 1,
1852 b->probe_resp, b->probe_resp_len, true);
1853 wil_hex_dump_misc("PROBE IE ", DUMP_PREFIX_OFFSET, 16, 1,
1854 b->proberesp_ies, b->proberesp_ies_len, true);
1855 wil_hex_dump_misc("ASSOC IE ", DUMP_PREFIX_OFFSET, 16, 1,
1856 b->assocresp_ies, b->assocresp_ies_len, true);
1857 }
1858
1859 /* internal functions for device reset and starting AP */
1860 static u8 *
_wil_cfg80211_get_proberesp_ies(const u8 * proberesp,u16 proberesp_len,u16 * ies_len)1861 _wil_cfg80211_get_proberesp_ies(const u8 *proberesp, u16 proberesp_len,
1862 u16 *ies_len)
1863 {
1864 u8 *ies = NULL;
1865
1866 if (proberesp) {
1867 struct ieee80211_mgmt *f =
1868 (struct ieee80211_mgmt *)proberesp;
1869 size_t hlen = offsetof(struct ieee80211_mgmt,
1870 u.probe_resp.variable);
1871
1872 ies = f->u.probe_resp.variable;
1873 if (ies_len)
1874 *ies_len = proberesp_len - hlen;
1875 }
1876
1877 return ies;
1878 }
1879
_wil_cfg80211_set_ies(struct wil6210_vif * vif,struct cfg80211_beacon_data * bcon)1880 static int _wil_cfg80211_set_ies(struct wil6210_vif *vif,
1881 struct cfg80211_beacon_data *bcon)
1882 {
1883 int rc;
1884 u16 len = 0, proberesp_len = 0;
1885 u8 *ies = NULL, *proberesp;
1886
1887 /* update local storage used for AP recovery */
1888 wil_memdup_ie(&vif->proberesp, &vif->proberesp_len, bcon->probe_resp,
1889 bcon->probe_resp_len);
1890 wil_memdup_ie(&vif->proberesp_ies, &vif->proberesp_ies_len,
1891 bcon->proberesp_ies, bcon->proberesp_ies_len);
1892 wil_memdup_ie(&vif->assocresp_ies, &vif->assocresp_ies_len,
1893 bcon->assocresp_ies, bcon->assocresp_ies_len);
1894
1895 proberesp = _wil_cfg80211_get_proberesp_ies(bcon->probe_resp,
1896 bcon->probe_resp_len,
1897 &proberesp_len);
1898 rc = _wil_cfg80211_merge_extra_ies(proberesp,
1899 proberesp_len,
1900 bcon->proberesp_ies,
1901 bcon->proberesp_ies_len,
1902 &ies, &len);
1903
1904 if (rc)
1905 goto out;
1906
1907 rc = wmi_set_ie(vif, WMI_FRAME_PROBE_RESP, len, ies);
1908 if (rc)
1909 goto out;
1910
1911 if (bcon->assocresp_ies)
1912 rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_RESP,
1913 bcon->assocresp_ies_len, bcon->assocresp_ies);
1914 else
1915 rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_RESP, len, ies);
1916 #if 0 /* to use beacon IE's, remove this #if 0 */
1917 if (rc)
1918 goto out;
1919
1920 rc = wmi_set_ie(vif, WMI_FRAME_BEACON,
1921 bcon->tail_len, bcon->tail);
1922 #endif
1923 out:
1924 kfree(ies);
1925 return rc;
1926 }
1927
_wil_cfg80211_start_ap(struct wiphy * wiphy,struct net_device * ndev,const u8 * ssid,size_t ssid_len,u32 privacy,int bi,u8 chan,u8 wmi_edmg_channel,struct cfg80211_beacon_data * bcon,u8 hidden_ssid,u32 pbss)1928 static int _wil_cfg80211_start_ap(struct wiphy *wiphy,
1929 struct net_device *ndev,
1930 const u8 *ssid, size_t ssid_len, u32 privacy,
1931 int bi, u8 chan, u8 wmi_edmg_channel,
1932 struct cfg80211_beacon_data *bcon,
1933 u8 hidden_ssid, u32 pbss)
1934 {
1935 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1936 struct wil6210_vif *vif = ndev_to_vif(ndev);
1937 int rc;
1938 struct wireless_dev *wdev = ndev->ieee80211_ptr;
1939 u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
1940 u8 is_go = (wdev->iftype == NL80211_IFTYPE_P2P_GO);
1941 u16 proberesp_len = 0;
1942 u8 *proberesp;
1943 bool ft = false;
1944
1945 if (pbss)
1946 wmi_nettype = WMI_NETTYPE_P2P;
1947
1948 wil_dbg_misc(wil, "start_ap: mid=%d, is_go=%d\n", vif->mid, is_go);
1949 if (is_go && !pbss) {
1950 wil_err(wil, "P2P GO must be in PBSS\n");
1951 return -ENOTSUPP;
1952 }
1953
1954 wil_set_recovery_state(wil, fw_recovery_idle);
1955
1956 proberesp = _wil_cfg80211_get_proberesp_ies(bcon->probe_resp,
1957 bcon->probe_resp_len,
1958 &proberesp_len);
1959 /* check that the probe response IEs has a MDE */
1960 if ((proberesp && proberesp_len > 0 &&
1961 cfg80211_find_ie(WLAN_EID_MOBILITY_DOMAIN,
1962 proberesp,
1963 proberesp_len)))
1964 ft = true;
1965
1966 if (ft) {
1967 if (!test_bit(WMI_FW_CAPABILITY_FT_ROAMING,
1968 wil->fw_capabilities)) {
1969 wil_err(wil, "FW does not support FT roaming\n");
1970 return -ENOTSUPP;
1971 }
1972 set_bit(wil_vif_ft_roam, vif->status);
1973 }
1974
1975 mutex_lock(&wil->mutex);
1976
1977 if (!wil_has_other_active_ifaces(wil, ndev, true, false)) {
1978 __wil_down(wil);
1979 rc = __wil_up(wil);
1980 if (rc)
1981 goto out;
1982 }
1983
1984 rc = wmi_set_ssid(vif, ssid_len, ssid);
1985 if (rc)
1986 goto out;
1987
1988 rc = _wil_cfg80211_set_ies(vif, bcon);
1989 if (rc)
1990 goto out;
1991
1992 vif->privacy = privacy;
1993 vif->channel = chan;
1994 vif->wmi_edmg_channel = wmi_edmg_channel;
1995 vif->hidden_ssid = hidden_ssid;
1996 vif->pbss = pbss;
1997 vif->bi = bi;
1998 memcpy(vif->ssid, ssid, ssid_len);
1999 vif->ssid_len = ssid_len;
2000
2001 netif_carrier_on(ndev);
2002 if (!wil_has_other_active_ifaces(wil, ndev, false, true))
2003 wil6210_bus_request(wil, WIL_MAX_BUS_REQUEST_KBPS);
2004
2005 rc = wmi_pcp_start(vif, bi, wmi_nettype, chan, wmi_edmg_channel,
2006 hidden_ssid, is_go);
2007 if (rc)
2008 goto err_pcp_start;
2009
2010 rc = wil_bcast_init(vif);
2011 if (rc)
2012 goto err_bcast;
2013
2014 goto out; /* success */
2015
2016 err_bcast:
2017 wmi_pcp_stop(vif);
2018 err_pcp_start:
2019 netif_carrier_off(ndev);
2020 if (!wil_has_other_active_ifaces(wil, ndev, false, true))
2021 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
2022 out:
2023 mutex_unlock(&wil->mutex);
2024 return rc;
2025 }
2026
wil_cfg80211_ap_recovery(struct wil6210_priv * wil)2027 void wil_cfg80211_ap_recovery(struct wil6210_priv *wil)
2028 {
2029 int rc, i;
2030 struct wiphy *wiphy = wil_to_wiphy(wil);
2031
2032 for (i = 0; i < GET_MAX_VIFS(wil); i++) {
2033 struct wil6210_vif *vif = wil->vifs[i];
2034 struct net_device *ndev;
2035 struct cfg80211_beacon_data bcon = {};
2036 struct key_params key_params = {};
2037
2038 if (!vif || vif->ssid_len == 0)
2039 continue;
2040
2041 ndev = vif_to_ndev(vif);
2042 bcon.proberesp_ies = vif->proberesp_ies;
2043 bcon.assocresp_ies = vif->assocresp_ies;
2044 bcon.probe_resp = vif->proberesp;
2045 bcon.proberesp_ies_len = vif->proberesp_ies_len;
2046 bcon.assocresp_ies_len = vif->assocresp_ies_len;
2047 bcon.probe_resp_len = vif->proberesp_len;
2048
2049 wil_info(wil,
2050 "AP (vif %d) recovery: privacy %d, bi %d, channel %d, hidden %d, pbss %d\n",
2051 i, vif->privacy, vif->bi, vif->channel,
2052 vif->hidden_ssid, vif->pbss);
2053 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
2054 vif->ssid, vif->ssid_len, true);
2055 rc = _wil_cfg80211_start_ap(wiphy, ndev,
2056 vif->ssid, vif->ssid_len,
2057 vif->privacy, vif->bi,
2058 vif->channel,
2059 vif->wmi_edmg_channel, &bcon,
2060 vif->hidden_ssid, vif->pbss);
2061 if (rc) {
2062 wil_err(wil, "vif %d recovery failed (%d)\n", i, rc);
2063 continue;
2064 }
2065
2066 if (!vif->privacy || vif->gtk_len == 0)
2067 continue;
2068
2069 key_params.key = vif->gtk;
2070 key_params.key_len = vif->gtk_len;
2071 key_params.seq_len = IEEE80211_GCMP_PN_LEN;
2072 rc = wil_cfg80211_add_key(wiphy, vif_to_wdev(vif), -1,
2073 vif->gtk_index,
2074 false, NULL, &key_params);
2075 if (rc)
2076 wil_err(wil, "vif %d recovery add key failed (%d)\n",
2077 i, rc);
2078 }
2079 }
2080
wil_cfg80211_change_beacon(struct wiphy * wiphy,struct net_device * ndev,struct cfg80211_ap_update * params)2081 static int wil_cfg80211_change_beacon(struct wiphy *wiphy,
2082 struct net_device *ndev,
2083 struct cfg80211_ap_update *params)
2084 {
2085 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2086 struct wireless_dev *wdev = ndev->ieee80211_ptr;
2087 struct wil6210_vif *vif = ndev_to_vif(ndev);
2088 struct cfg80211_beacon_data *bcon = ¶ms->beacon;
2089 int rc;
2090 u32 privacy = 0;
2091
2092 wil_dbg_misc(wil, "change_beacon, mid=%d\n", vif->mid);
2093 wil_print_bcon_data(bcon);
2094
2095 if (bcon->tail &&
2096 cfg80211_find_ie(WLAN_EID_RSN, bcon->tail,
2097 bcon->tail_len))
2098 privacy = 1;
2099
2100 memcpy(vif->ssid, wdev->u.ap.ssid, wdev->u.ap.ssid_len);
2101 vif->ssid_len = wdev->u.ap.ssid_len;
2102
2103 /* in case privacy has changed, need to restart the AP */
2104 if (vif->privacy != privacy) {
2105 wil_dbg_misc(wil, "privacy changed %d=>%d. Restarting AP\n",
2106 vif->privacy, privacy);
2107
2108 rc = _wil_cfg80211_start_ap(wiphy, ndev, vif->ssid,
2109 vif->ssid_len, privacy,
2110 wdev->links[0].ap.beacon_interval,
2111 vif->channel,
2112 vif->wmi_edmg_channel, bcon,
2113 vif->hidden_ssid,
2114 vif->pbss);
2115 } else {
2116 rc = _wil_cfg80211_set_ies(vif, bcon);
2117 }
2118
2119 return rc;
2120 }
2121
wil_cfg80211_start_ap(struct wiphy * wiphy,struct net_device * ndev,struct cfg80211_ap_settings * info)2122 static int wil_cfg80211_start_ap(struct wiphy *wiphy,
2123 struct net_device *ndev,
2124 struct cfg80211_ap_settings *info)
2125 {
2126 int rc;
2127 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2128 struct ieee80211_channel *channel = info->chandef.chan;
2129 struct cfg80211_beacon_data *bcon = &info->beacon;
2130 struct cfg80211_crypto_settings *crypto = &info->crypto;
2131 u8 wmi_edmg_channel;
2132 u8 hidden_ssid;
2133
2134 wil_dbg_misc(wil, "start_ap\n");
2135
2136 rc = wil_get_wmi_edmg_channel(wil, info->chandef.edmg.bw_config,
2137 info->chandef.edmg.channels,
2138 &wmi_edmg_channel);
2139 if (rc < 0)
2140 return rc;
2141
2142 if (!channel) {
2143 wil_err(wil, "AP: No channel???\n");
2144 return -EINVAL;
2145 }
2146
2147 switch (info->hidden_ssid) {
2148 case NL80211_HIDDEN_SSID_NOT_IN_USE:
2149 hidden_ssid = WMI_HIDDEN_SSID_DISABLED;
2150 break;
2151
2152 case NL80211_HIDDEN_SSID_ZERO_LEN:
2153 hidden_ssid = WMI_HIDDEN_SSID_SEND_EMPTY;
2154 break;
2155
2156 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
2157 hidden_ssid = WMI_HIDDEN_SSID_CLEAR;
2158 break;
2159
2160 default:
2161 wil_err(wil, "AP: Invalid hidden SSID %d\n", info->hidden_ssid);
2162 return -EOPNOTSUPP;
2163 }
2164 wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
2165 channel->center_freq, info->privacy ? "secure" : "open");
2166 wil_dbg_misc(wil, "Privacy: %d auth_type %d\n",
2167 info->privacy, info->auth_type);
2168 wil_dbg_misc(wil, "Hidden SSID mode: %d\n",
2169 info->hidden_ssid);
2170 wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval,
2171 info->dtim_period);
2172 wil_dbg_misc(wil, "PBSS %d\n", info->pbss);
2173 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
2174 info->ssid, info->ssid_len, true);
2175 wil_print_bcon_data(bcon);
2176 wil_print_crypto(wil, crypto);
2177
2178 rc = _wil_cfg80211_start_ap(wiphy, ndev,
2179 info->ssid, info->ssid_len, info->privacy,
2180 info->beacon_interval, channel->hw_value,
2181 wmi_edmg_channel, bcon, hidden_ssid,
2182 info->pbss);
2183
2184 return rc;
2185 }
2186
wil_cfg80211_stop_ap(struct wiphy * wiphy,struct net_device * ndev,unsigned int link_id)2187 static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
2188 struct net_device *ndev,
2189 unsigned int link_id)
2190 {
2191 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2192 struct wil6210_vif *vif = ndev_to_vif(ndev);
2193 bool last;
2194
2195 wil_dbg_misc(wil, "stop_ap, mid=%d\n", vif->mid);
2196
2197 netif_carrier_off(ndev);
2198 last = !wil_has_other_active_ifaces(wil, ndev, false, true);
2199 if (last) {
2200 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
2201 wil_set_recovery_state(wil, fw_recovery_idle);
2202 set_bit(wil_status_resetting, wil->status);
2203 }
2204
2205 mutex_lock(&wil->mutex);
2206
2207 wmi_pcp_stop(vif);
2208 clear_bit(wil_vif_ft_roam, vif->status);
2209 vif->ssid_len = 0;
2210 wil_memdup_ie(&vif->proberesp, &vif->proberesp_len, NULL, 0);
2211 wil_memdup_ie(&vif->proberesp_ies, &vif->proberesp_ies_len, NULL, 0);
2212 wil_memdup_ie(&vif->assocresp_ies, &vif->assocresp_ies_len, NULL, 0);
2213 memset(vif->gtk, 0, WMI_MAX_KEY_LEN);
2214 vif->gtk_len = 0;
2215
2216 if (last)
2217 __wil_down(wil);
2218 else
2219 wil_bcast_fini(vif);
2220
2221 mutex_unlock(&wil->mutex);
2222
2223 return 0;
2224 }
2225
wil_cfg80211_add_station(struct wiphy * wiphy,struct wireless_dev * wdev,const u8 * mac,struct station_parameters * params)2226 static int wil_cfg80211_add_station(struct wiphy *wiphy,
2227 struct wireless_dev *wdev,
2228 const u8 *mac,
2229 struct station_parameters *params)
2230 {
2231 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2232 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2233
2234 wil_dbg_misc(wil, "add station %pM aid %d mid %d mask 0x%x set 0x%x\n",
2235 mac, params->aid, vif->mid,
2236 params->sta_flags_mask, params->sta_flags_set);
2237
2238 if (!disable_ap_sme) {
2239 wil_err(wil, "not supported with AP SME enabled\n");
2240 return -EOPNOTSUPP;
2241 }
2242
2243 if (params->aid > WIL_MAX_DMG_AID) {
2244 wil_err(wil, "invalid aid\n");
2245 return -EINVAL;
2246 }
2247
2248 return wmi_new_sta(vif, mac, params->aid);
2249 }
2250
wil_cfg80211_del_station(struct wiphy * wiphy,struct wireless_dev * wdev,struct station_del_parameters * params)2251 static int wil_cfg80211_del_station(struct wiphy *wiphy,
2252 struct wireless_dev *wdev,
2253 struct station_del_parameters *params)
2254 {
2255 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2256 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2257
2258 wil_dbg_misc(wil, "del_station: %pM, reason=%d mid=%d\n",
2259 params->mac, params->reason_code, vif->mid);
2260
2261 mutex_lock(&wil->mutex);
2262 wil6210_disconnect(vif, params->mac, params->reason_code);
2263 mutex_unlock(&wil->mutex);
2264
2265 return 0;
2266 }
2267
wil_cfg80211_change_station(struct wiphy * wiphy,struct wireless_dev * wdev,const u8 * mac,struct station_parameters * params)2268 static int wil_cfg80211_change_station(struct wiphy *wiphy,
2269 struct wireless_dev *wdev,
2270 const u8 *mac,
2271 struct station_parameters *params)
2272 {
2273 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2274 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2275 int authorize;
2276 int cid, i;
2277 struct wil_ring_tx_data *txdata = NULL;
2278
2279 wil_dbg_misc(wil, "change station %pM mask 0x%x set 0x%x mid %d\n",
2280 mac, params->sta_flags_mask, params->sta_flags_set,
2281 vif->mid);
2282
2283 if (!disable_ap_sme) {
2284 wil_dbg_misc(wil, "not supported with AP SME enabled\n");
2285 return -EOPNOTSUPP;
2286 }
2287
2288 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
2289 return 0;
2290
2291 cid = wil_find_cid(wil, vif->mid, mac);
2292 if (cid < 0) {
2293 wil_err(wil, "station not found\n");
2294 return -ENOLINK;
2295 }
2296
2297 for (i = 0; i < ARRAY_SIZE(wil->ring2cid_tid); i++)
2298 if (wil->ring2cid_tid[i][0] == cid) {
2299 txdata = &wil->ring_tx_data[i];
2300 break;
2301 }
2302
2303 if (!txdata) {
2304 wil_err(wil, "ring data not found\n");
2305 return -ENOLINK;
2306 }
2307
2308 authorize = params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED);
2309 txdata->dot1x_open = authorize ? 1 : 0;
2310 wil_dbg_misc(wil, "cid %d ring %d authorize %d\n", cid, i,
2311 txdata->dot1x_open);
2312
2313 return 0;
2314 }
2315
2316 /* probe_client handling */
wil_probe_client_handle(struct wil6210_priv * wil,struct wil6210_vif * vif,struct wil_probe_client_req * req)2317 static void wil_probe_client_handle(struct wil6210_priv *wil,
2318 struct wil6210_vif *vif,
2319 struct wil_probe_client_req *req)
2320 {
2321 struct net_device *ndev = vif_to_ndev(vif);
2322 struct wil_sta_info *sta = &wil->sta[req->cid];
2323 /* assume STA is alive if it is still connected,
2324 * else FW will disconnect it
2325 */
2326 bool alive = (sta->status == wil_sta_connected);
2327
2328 cfg80211_probe_status(ndev, sta->addr, req->cookie, -1, alive,
2329 0, false, GFP_KERNEL);
2330 }
2331
next_probe_client(struct wil6210_vif * vif)2332 static struct list_head *next_probe_client(struct wil6210_vif *vif)
2333 {
2334 struct list_head *ret = NULL;
2335
2336 mutex_lock(&vif->probe_client_mutex);
2337
2338 if (!list_empty(&vif->probe_client_pending)) {
2339 ret = vif->probe_client_pending.next;
2340 list_del(ret);
2341 }
2342
2343 mutex_unlock(&vif->probe_client_mutex);
2344
2345 return ret;
2346 }
2347
wil_probe_client_worker(struct work_struct * work)2348 void wil_probe_client_worker(struct work_struct *work)
2349 {
2350 struct wil6210_vif *vif = container_of(work, struct wil6210_vif,
2351 probe_client_worker);
2352 struct wil6210_priv *wil = vif_to_wil(vif);
2353 struct wil_probe_client_req *req;
2354 struct list_head *lh;
2355
2356 while ((lh = next_probe_client(vif)) != NULL) {
2357 req = list_entry(lh, struct wil_probe_client_req, list);
2358
2359 wil_probe_client_handle(wil, vif, req);
2360 kfree(req);
2361 }
2362 }
2363
wil_probe_client_flush(struct wil6210_vif * vif)2364 void wil_probe_client_flush(struct wil6210_vif *vif)
2365 {
2366 struct wil_probe_client_req *req, *t;
2367 struct wil6210_priv *wil = vif_to_wil(vif);
2368
2369 wil_dbg_misc(wil, "probe_client_flush\n");
2370
2371 mutex_lock(&vif->probe_client_mutex);
2372
2373 list_for_each_entry_safe(req, t, &vif->probe_client_pending, list) {
2374 list_del(&req->list);
2375 kfree(req);
2376 }
2377
2378 mutex_unlock(&vif->probe_client_mutex);
2379 }
2380
wil_cfg80211_probe_peer(struct wiphy * wiphy,struct net_device * dev,const u8 * peer,u64 cookie)2381 static int wil_cfg80211_probe_peer(struct wiphy *wiphy,
2382 struct net_device *dev,
2383 const u8 *peer, u64 cookie)
2384 {
2385 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2386 struct wil6210_vif *vif = ndev_to_vif(dev);
2387 struct wil_probe_client_req *req;
2388 int cid = wil_find_cid(wil, vif->mid, peer);
2389
2390 wil_dbg_misc(wil, "probe_client: %pM => CID %d MID %d\n",
2391 peer, cid, vif->mid);
2392
2393 if (cid < 0)
2394 return -ENOLINK;
2395
2396 req = kzalloc_obj(*req);
2397 if (!req)
2398 return -ENOMEM;
2399
2400 req->cid = cid;
2401 req->cookie = cookie;
2402
2403 mutex_lock(&vif->probe_client_mutex);
2404 list_add_tail(&req->list, &vif->probe_client_pending);
2405 mutex_unlock(&vif->probe_client_mutex);
2406
2407 queue_work(wil->wq_service, &vif->probe_client_worker);
2408 return 0;
2409 }
2410
wil_cfg80211_change_bss(struct wiphy * wiphy,struct net_device * dev,struct bss_parameters * params)2411 static int wil_cfg80211_change_bss(struct wiphy *wiphy,
2412 struct net_device *dev,
2413 struct bss_parameters *params)
2414 {
2415 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2416 struct wil6210_vif *vif = ndev_to_vif(dev);
2417
2418 if (params->ap_isolate >= 0) {
2419 wil_dbg_misc(wil, "change_bss: ap_isolate MID %d, %d => %d\n",
2420 vif->mid, vif->ap_isolate, params->ap_isolate);
2421 vif->ap_isolate = params->ap_isolate;
2422 }
2423
2424 return 0;
2425 }
2426
wil_cfg80211_set_power_mgmt(struct wiphy * wiphy,struct net_device * dev,bool enabled,int timeout)2427 static int wil_cfg80211_set_power_mgmt(struct wiphy *wiphy,
2428 struct net_device *dev,
2429 bool enabled, int timeout)
2430 {
2431 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2432 enum wmi_ps_profile_type ps_profile;
2433
2434 wil_dbg_misc(wil, "enabled=%d, timeout=%d\n",
2435 enabled, timeout);
2436
2437 if (enabled)
2438 ps_profile = WMI_PS_PROFILE_TYPE_DEFAULT;
2439 else
2440 ps_profile = WMI_PS_PROFILE_TYPE_PS_DISABLED;
2441
2442 return wil_ps_update(wil, ps_profile);
2443 }
2444
wil_cfg80211_suspend(struct wiphy * wiphy,struct cfg80211_wowlan * wow)2445 static int wil_cfg80211_suspend(struct wiphy *wiphy,
2446 struct cfg80211_wowlan *wow)
2447 {
2448 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2449 int rc;
2450
2451 /* Setting the wakeup trigger based on wow is TBD */
2452
2453 if (test_bit(wil_status_suspended, wil->status)) {
2454 wil_dbg_pm(wil, "trying to suspend while suspended\n");
2455 return 0;
2456 }
2457
2458 rc = wil_can_suspend(wil, false);
2459 if (rc)
2460 goto out;
2461
2462 wil_dbg_pm(wil, "suspending\n");
2463
2464 mutex_lock(&wil->mutex);
2465 mutex_lock(&wil->vif_mutex);
2466 wil_p2p_stop_radio_operations(wil);
2467 wil_abort_scan_all_vifs(wil, true);
2468 mutex_unlock(&wil->vif_mutex);
2469 mutex_unlock(&wil->mutex);
2470
2471 out:
2472 return rc;
2473 }
2474
wil_cfg80211_resume(struct wiphy * wiphy)2475 static int wil_cfg80211_resume(struct wiphy *wiphy)
2476 {
2477 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2478
2479 wil_dbg_pm(wil, "resuming\n");
2480
2481 return 0;
2482 }
2483
2484 static int
wil_cfg80211_sched_scan_start(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_sched_scan_request * request)2485 wil_cfg80211_sched_scan_start(struct wiphy *wiphy,
2486 struct net_device *dev,
2487 struct cfg80211_sched_scan_request *request)
2488 {
2489 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2490 struct wil6210_vif *vif = ndev_to_vif(dev);
2491 int i, rc;
2492
2493 if (vif->mid != 0)
2494 return -EOPNOTSUPP;
2495
2496 wil_dbg_misc(wil,
2497 "sched scan start: n_ssids %d, ie_len %zu, flags 0x%x\n",
2498 request->n_ssids, request->ie_len, request->flags);
2499 for (i = 0; i < request->n_ssids; i++) {
2500 wil_dbg_misc(wil, "SSID[%d]:", i);
2501 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
2502 request->ssids[i].ssid,
2503 request->ssids[i].ssid_len, true);
2504 }
2505 wil_dbg_misc(wil, "channels:");
2506 for (i = 0; i < request->n_channels; i++)
2507 wil_dbg_misc(wil, " %d%s", request->channels[i]->hw_value,
2508 i == request->n_channels - 1 ? "\n" : "");
2509 wil_dbg_misc(wil, "n_match_sets %d, min_rssi_thold %d, delay %d\n",
2510 request->n_match_sets, request->min_rssi_thold,
2511 request->delay);
2512 for (i = 0; i < request->n_match_sets; i++) {
2513 struct cfg80211_match_set *ms = &request->match_sets[i];
2514
2515 wil_dbg_misc(wil, "MATCHSET[%d]: rssi_thold %d\n",
2516 i, ms->rssi_thold);
2517 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
2518 ms->ssid.ssid,
2519 ms->ssid.ssid_len, true);
2520 }
2521 wil_dbg_misc(wil, "n_scan_plans %d\n", request->n_scan_plans);
2522 for (i = 0; i < request->n_scan_plans; i++) {
2523 struct cfg80211_sched_scan_plan *sp = &request->scan_plans[i];
2524
2525 wil_dbg_misc(wil, "SCAN PLAN[%d]: interval %d iterations %d\n",
2526 i, sp->interval, sp->iterations);
2527 }
2528
2529 rc = wmi_set_ie(vif, WMI_FRAME_PROBE_REQ,
2530 request->ie_len, request->ie);
2531 if (rc)
2532 return rc;
2533 return wmi_start_sched_scan(wil, request);
2534 }
2535
2536 static int
wil_cfg80211_sched_scan_stop(struct wiphy * wiphy,struct net_device * dev,u64 reqid)2537 wil_cfg80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2538 u64 reqid)
2539 {
2540 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2541 struct wil6210_vif *vif = ndev_to_vif(dev);
2542 int rc;
2543
2544 if (vif->mid != 0)
2545 return -EOPNOTSUPP;
2546
2547 rc = wmi_stop_sched_scan(wil);
2548 /* device would return error if it thinks PNO is already stopped.
2549 * ignore the return code so user space and driver gets back in-sync
2550 */
2551 wil_dbg_misc(wil, "sched scan stopped (%d)\n", rc);
2552
2553 return 0;
2554 }
2555
2556 static int
wil_cfg80211_update_ft_ies(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_update_ft_ies_params * ftie)2557 wil_cfg80211_update_ft_ies(struct wiphy *wiphy, struct net_device *dev,
2558 struct cfg80211_update_ft_ies_params *ftie)
2559 {
2560 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2561 struct wil6210_vif *vif = ndev_to_vif(dev);
2562 struct cfg80211_bss *bss;
2563 struct wmi_ft_reassoc_cmd reassoc;
2564 int rc = 0;
2565
2566 wil_dbg_misc(wil, "update ft ies, mid=%d\n", vif->mid);
2567 wil_hex_dump_misc("FT IE ", DUMP_PREFIX_OFFSET, 16, 1,
2568 ftie->ie, ftie->ie_len, true);
2569
2570 if (!test_bit(WMI_FW_CAPABILITY_FT_ROAMING, wil->fw_capabilities)) {
2571 wil_err(wil, "FW does not support FT roaming\n");
2572 return -EOPNOTSUPP;
2573 }
2574
2575 rc = wmi_update_ft_ies(vif, ftie->ie_len, ftie->ie);
2576 if (rc)
2577 return rc;
2578
2579 if (!test_bit(wil_vif_ft_roam, vif->status))
2580 /* vif is not roaming */
2581 return 0;
2582
2583 /* wil_vif_ft_roam is set. wil_cfg80211_update_ft_ies is used as
2584 * a trigger for reassoc
2585 */
2586
2587 bss = vif->bss;
2588 if (!bss) {
2589 wil_err(wil, "FT: bss is NULL\n");
2590 return -EINVAL;
2591 }
2592
2593 memset(&reassoc, 0, sizeof(reassoc));
2594 ether_addr_copy(reassoc.bssid, bss->bssid);
2595
2596 rc = wmi_send(wil, WMI_FT_REASSOC_CMDID, vif->mid,
2597 &reassoc, sizeof(reassoc));
2598 if (rc)
2599 wil_err(wil, "FT: reassoc failed (%d)\n", rc);
2600
2601 return rc;
2602 }
2603
wil_cfg80211_set_multicast_to_unicast(struct wiphy * wiphy,struct net_device * dev,const bool enabled)2604 static int wil_cfg80211_set_multicast_to_unicast(struct wiphy *wiphy,
2605 struct net_device *dev,
2606 const bool enabled)
2607 {
2608 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2609
2610 if (wil->multicast_to_unicast == enabled)
2611 return 0;
2612
2613 wil_info(wil, "set multicast to unicast, enabled=%d\n", enabled);
2614 wil->multicast_to_unicast = enabled;
2615
2616 return 0;
2617 }
2618
wil_cfg80211_set_cqm_rssi_config(struct wiphy * wiphy,struct net_device * dev,s32 rssi_thold,u32 rssi_hyst)2619 static int wil_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
2620 struct net_device *dev,
2621 s32 rssi_thold, u32 rssi_hyst)
2622 {
2623 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2624 int rc;
2625
2626 wil->cqm_rssi_thold = rssi_thold;
2627
2628 rc = wmi_set_cqm_rssi_config(wil, rssi_thold, rssi_hyst);
2629 if (rc)
2630 /* reset stored value upon failure */
2631 wil->cqm_rssi_thold = 0;
2632
2633 return rc;
2634 }
2635
2636 static const struct cfg80211_ops wil_cfg80211_ops = {
2637 .add_virtual_intf = wil_cfg80211_add_iface,
2638 .del_virtual_intf = wil_cfg80211_del_iface,
2639 .scan = wil_cfg80211_scan,
2640 .abort_scan = wil_cfg80211_abort_scan,
2641 .connect = wil_cfg80211_connect,
2642 .disconnect = wil_cfg80211_disconnect,
2643 .set_wiphy_params = wil_cfg80211_set_wiphy_params,
2644 .change_virtual_intf = wil_cfg80211_change_iface,
2645 .get_station = wil_cfg80211_get_station,
2646 .dump_station = wil_cfg80211_dump_station,
2647 .remain_on_channel = wil_remain_on_channel,
2648 .cancel_remain_on_channel = wil_cancel_remain_on_channel,
2649 .mgmt_tx = wil_cfg80211_mgmt_tx,
2650 .set_monitor_channel = wil_cfg80211_set_channel,
2651 .add_key = wil_cfg80211_add_key,
2652 .del_key = wil_cfg80211_del_key,
2653 .set_default_key = wil_cfg80211_set_default_key,
2654 /* AP mode */
2655 .change_beacon = wil_cfg80211_change_beacon,
2656 .start_ap = wil_cfg80211_start_ap,
2657 .stop_ap = wil_cfg80211_stop_ap,
2658 .add_station = wil_cfg80211_add_station,
2659 .del_station = wil_cfg80211_del_station,
2660 .change_station = wil_cfg80211_change_station,
2661 .probe_peer = wil_cfg80211_probe_peer,
2662 .change_bss = wil_cfg80211_change_bss,
2663 /* P2P device */
2664 .start_p2p_device = wil_cfg80211_start_p2p_device,
2665 .stop_p2p_device = wil_cfg80211_stop_p2p_device,
2666 .set_power_mgmt = wil_cfg80211_set_power_mgmt,
2667 .set_cqm_rssi_config = wil_cfg80211_set_cqm_rssi_config,
2668 .suspend = wil_cfg80211_suspend,
2669 .resume = wil_cfg80211_resume,
2670 .sched_scan_start = wil_cfg80211_sched_scan_start,
2671 .sched_scan_stop = wil_cfg80211_sched_scan_stop,
2672 .update_ft_ies = wil_cfg80211_update_ft_ies,
2673 .set_multicast_to_unicast = wil_cfg80211_set_multicast_to_unicast,
2674 };
2675
wil_wiphy_init(struct wiphy * wiphy)2676 static void wil_wiphy_init(struct wiphy *wiphy)
2677 {
2678 wiphy->max_scan_ssids = 1;
2679 wiphy->max_scan_ie_len = WMI_MAX_IE_LEN;
2680 wiphy->max_remain_on_channel_duration = WIL_MAX_ROC_DURATION_MS;
2681 wiphy->max_num_pmkids = 0 /* TODO: */;
2682 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
2683 BIT(NL80211_IFTYPE_AP) |
2684 BIT(NL80211_IFTYPE_P2P_CLIENT) |
2685 BIT(NL80211_IFTYPE_P2P_GO) |
2686 BIT(NL80211_IFTYPE_P2P_DEVICE) |
2687 BIT(NL80211_IFTYPE_MONITOR);
2688 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
2689 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
2690 WIPHY_FLAG_PS_ON_BY_DEFAULT;
2691 if (!disable_ap_sme)
2692 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME;
2693 dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
2694 __func__, wiphy->flags);
2695 wiphy->probe_resp_offload =
2696 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
2697 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
2698 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
2699
2700 wiphy->bands[NL80211_BAND_60GHZ] = &wil_band_60ghz;
2701
2702 /* may change after reading FW capabilities */
2703 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
2704
2705 wiphy->cipher_suites = wil_cipher_suites;
2706 wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
2707 wiphy->mgmt_stypes = wil_mgmt_stypes;
2708 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
2709 wiphy->bss_param_support = WIPHY_BSS_PARAM_AP_ISOLATE;
2710
2711 wiphy->n_vendor_commands = ARRAY_SIZE(wil_nl80211_vendor_commands);
2712 wiphy->vendor_commands = wil_nl80211_vendor_commands;
2713
2714 #ifdef CONFIG_PM
2715 wiphy->wowlan = &wil_wowlan_support;
2716 #endif
2717 }
2718
wil_cfg80211_iface_combinations_from_fw(struct wil6210_priv * wil,const struct wil_fw_record_concurrency * conc)2719 int wil_cfg80211_iface_combinations_from_fw(
2720 struct wil6210_priv *wil, const struct wil_fw_record_concurrency *conc)
2721 {
2722 struct wiphy *wiphy = wil_to_wiphy(wil);
2723 u32 total_limits = 0;
2724 u16 n_combos;
2725 const struct wil_fw_concurrency_combo *combo;
2726 const struct wil_fw_concurrency_limit *limit;
2727 struct ieee80211_iface_combination *iface_combinations;
2728 struct ieee80211_iface_limit *iface_limit;
2729 int i, j;
2730
2731 if (wiphy->iface_combinations) {
2732 wil_dbg_misc(wil, "iface_combinations already set, skipping\n");
2733 return 0;
2734 }
2735
2736 combo = (const struct wil_fw_concurrency_combo *)(conc + 1);
2737 n_combos = le16_to_cpu(conc->n_combos);
2738 for (i = 0; i < n_combos; i++) {
2739 total_limits += combo->n_limits;
2740 limit = combo->limits + combo->n_limits;
2741 combo = (struct wil_fw_concurrency_combo *)limit;
2742 }
2743
2744 iface_combinations =
2745 kzalloc(n_combos * sizeof(struct ieee80211_iface_combination) +
2746 total_limits * sizeof(struct ieee80211_iface_limit),
2747 GFP_KERNEL);
2748 if (!iface_combinations)
2749 return -ENOMEM;
2750 iface_limit = (struct ieee80211_iface_limit *)(iface_combinations +
2751 n_combos);
2752 combo = (const struct wil_fw_concurrency_combo *)(conc + 1);
2753 for (i = 0; i < n_combos; i++) {
2754 iface_combinations[i].max_interfaces = combo->max_interfaces;
2755 iface_combinations[i].num_different_channels =
2756 combo->n_diff_channels;
2757 iface_combinations[i].beacon_int_infra_match =
2758 combo->same_bi;
2759 iface_combinations[i].n_limits = combo->n_limits;
2760 wil_dbg_misc(wil,
2761 "iface_combination %d: max_if %d, num_ch %d, bi_match %d\n",
2762 i, iface_combinations[i].max_interfaces,
2763 iface_combinations[i].num_different_channels,
2764 iface_combinations[i].beacon_int_infra_match);
2765 limit = combo->limits;
2766 for (j = 0; j < combo->n_limits; j++) {
2767 iface_limit[j].max = le16_to_cpu(limit[j].max);
2768 iface_limit[j].types = le16_to_cpu(limit[j].types);
2769 wil_dbg_misc(wil,
2770 "limit %d: max %d types 0x%x\n", j,
2771 iface_limit[j].max, iface_limit[j].types);
2772 }
2773 iface_combinations[i].limits = iface_limit;
2774 iface_limit += combo->n_limits;
2775 limit += combo->n_limits;
2776 combo = (struct wil_fw_concurrency_combo *)limit;
2777 }
2778
2779 wil_dbg_misc(wil, "multiple VIFs supported, n_mids %d\n", conc->n_mids);
2780 wil->max_vifs = conc->n_mids + 1; /* including main interface */
2781 if (wil->max_vifs > WIL_MAX_VIFS) {
2782 wil_info(wil, "limited number of VIFs supported(%d, FW %d)\n",
2783 WIL_MAX_VIFS, wil->max_vifs);
2784 wil->max_vifs = WIL_MAX_VIFS;
2785 }
2786 wiphy->n_iface_combinations = n_combos;
2787 wiphy->iface_combinations = iface_combinations;
2788 return 0;
2789 }
2790
wil_cfg80211_init(struct device * dev)2791 struct wil6210_priv *wil_cfg80211_init(struct device *dev)
2792 {
2793 struct wiphy *wiphy;
2794 struct wil6210_priv *wil;
2795 struct ieee80211_channel *ch;
2796
2797 dev_dbg(dev, "%s()\n", __func__);
2798
2799 /* Note: the wireless_dev structure is no longer allocated here.
2800 * Instead, it is allocated as part of the net_device structure
2801 * for main interface and each VIF.
2802 */
2803 wiphy = wiphy_new(&wil_cfg80211_ops, sizeof(struct wil6210_priv));
2804 if (!wiphy)
2805 return ERR_PTR(-ENOMEM);
2806
2807 set_wiphy_dev(wiphy, dev);
2808 wil_wiphy_init(wiphy);
2809
2810 wil = wiphy_to_wil(wiphy);
2811 wil->wiphy = wiphy;
2812
2813 /* default monitor channel */
2814 ch = wiphy->bands[NL80211_BAND_60GHZ]->channels;
2815 cfg80211_chandef_create(&wil->monitor_chandef, ch, NL80211_CHAN_NO_HT);
2816
2817 return wil;
2818 }
2819
wil_cfg80211_deinit(struct wil6210_priv * wil)2820 void wil_cfg80211_deinit(struct wil6210_priv *wil)
2821 {
2822 struct wiphy *wiphy = wil_to_wiphy(wil);
2823
2824 dev_dbg(wil_to_dev(wil), "%s()\n", __func__);
2825
2826 if (!wiphy)
2827 return;
2828
2829 kfree(wiphy->iface_combinations);
2830 wiphy->iface_combinations = NULL;
2831
2832 wiphy_free(wiphy);
2833 /* do not access wil6210_priv after returning from here */
2834 }
2835
wil_p2p_wdev_free(struct wil6210_priv * wil)2836 void wil_p2p_wdev_free(struct wil6210_priv *wil)
2837 {
2838 struct wireless_dev *p2p_wdev;
2839
2840 mutex_lock(&wil->vif_mutex);
2841 p2p_wdev = wil->p2p_wdev;
2842 wil->p2p_wdev = NULL;
2843 wil->radio_wdev = wil->main_ndev->ieee80211_ptr;
2844 mutex_unlock(&wil->vif_mutex);
2845 if (p2p_wdev) {
2846 cfg80211_unregister_wdev(p2p_wdev);
2847 kfree(p2p_wdev);
2848 }
2849 }
2850
wil_rf_sector_status_to_rc(u8 status)2851 static int wil_rf_sector_status_to_rc(u8 status)
2852 {
2853 switch (status) {
2854 case WMI_RF_SECTOR_STATUS_SUCCESS:
2855 return 0;
2856 case WMI_RF_SECTOR_STATUS_BAD_PARAMETERS_ERROR:
2857 return -EINVAL;
2858 case WMI_RF_SECTOR_STATUS_BUSY_ERROR:
2859 return -EAGAIN;
2860 case WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR:
2861 return -EOPNOTSUPP;
2862 default:
2863 return -EINVAL;
2864 }
2865 }
2866
wil_rf_sector_get_cfg(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int data_len)2867 static int wil_rf_sector_get_cfg(struct wiphy *wiphy,
2868 struct wireless_dev *wdev,
2869 const void *data, int data_len)
2870 {
2871 struct wil6210_priv *wil = wdev_to_wil(wdev);
2872 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2873 int rc;
2874 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
2875 u16 sector_index;
2876 u8 sector_type;
2877 u32 rf_modules_vec;
2878 struct wmi_get_rf_sector_params_cmd cmd;
2879 struct {
2880 struct wmi_cmd_hdr wmi;
2881 struct wmi_get_rf_sector_params_done_event evt;
2882 } __packed reply = {
2883 .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
2884 };
2885 struct sk_buff *msg;
2886 struct nlattr *nl_cfgs, *nl_cfg;
2887 u32 i;
2888 struct wmi_rf_sector_info *si;
2889
2890 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
2891 return -EOPNOTSUPP;
2892
2893 rc = nla_parse_deprecated(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data,
2894 data_len, wil_rf_sector_policy, NULL);
2895 if (rc) {
2896 wil_err(wil, "Invalid rf sector ATTR\n");
2897 return rc;
2898 }
2899
2900 if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
2901 !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE] ||
2902 !tb[QCA_ATTR_DMG_RF_MODULE_MASK]) {
2903 wil_err(wil, "Invalid rf sector spec\n");
2904 return -EINVAL;
2905 }
2906
2907 sector_index = nla_get_u16(
2908 tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
2909 if (sector_index >= WIL_MAX_RF_SECTORS) {
2910 wil_err(wil, "Invalid sector index %d\n", sector_index);
2911 return -EINVAL;
2912 }
2913
2914 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
2915 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
2916 wil_err(wil, "Invalid sector type %d\n", sector_type);
2917 return -EINVAL;
2918 }
2919
2920 rf_modules_vec = nla_get_u32(
2921 tb[QCA_ATTR_DMG_RF_MODULE_MASK]);
2922 if (rf_modules_vec >= BIT(WMI_MAX_RF_MODULES_NUM)) {
2923 wil_err(wil, "Invalid rf module mask 0x%x\n", rf_modules_vec);
2924 return -EINVAL;
2925 }
2926
2927 cmd.sector_idx = cpu_to_le16(sector_index);
2928 cmd.sector_type = sector_type;
2929 cmd.rf_modules_vec = rf_modules_vec & 0xFF;
2930 rc = wmi_call(wil, WMI_GET_RF_SECTOR_PARAMS_CMDID, vif->mid,
2931 &cmd, sizeof(cmd), WMI_GET_RF_SECTOR_PARAMS_DONE_EVENTID,
2932 &reply, sizeof(reply),
2933 500);
2934 if (rc)
2935 return rc;
2936 if (reply.evt.status) {
2937 wil_err(wil, "get rf sector cfg failed with status %d\n",
2938 reply.evt.status);
2939 return wil_rf_sector_status_to_rc(reply.evt.status);
2940 }
2941
2942 msg = cfg80211_vendor_cmd_alloc_reply_skb(
2943 wiphy, 64 * WMI_MAX_RF_MODULES_NUM);
2944 if (!msg)
2945 return -ENOMEM;
2946
2947 if (nla_put_u64_64bit(msg, QCA_ATTR_TSF,
2948 le64_to_cpu(reply.evt.tsf),
2949 QCA_ATTR_PAD))
2950 goto nla_put_failure;
2951
2952 nl_cfgs = nla_nest_start_noflag(msg, QCA_ATTR_DMG_RF_SECTOR_CFG);
2953 if (!nl_cfgs)
2954 goto nla_put_failure;
2955 for (i = 0; i < WMI_MAX_RF_MODULES_NUM; i++) {
2956 if (!(rf_modules_vec & BIT(i)))
2957 continue;
2958 nl_cfg = nla_nest_start_noflag(msg, i);
2959 if (!nl_cfg)
2960 goto nla_put_failure;
2961 si = &reply.evt.sectors_info[i];
2962 if (nla_put_u8(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX,
2963 i) ||
2964 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0,
2965 le32_to_cpu(si->etype0)) ||
2966 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1,
2967 le32_to_cpu(si->etype1)) ||
2968 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2,
2969 le32_to_cpu(si->etype2)) ||
2970 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI,
2971 le32_to_cpu(si->psh_hi)) ||
2972 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO,
2973 le32_to_cpu(si->psh_lo)) ||
2974 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16,
2975 le32_to_cpu(si->dtype_swch_off)))
2976 goto nla_put_failure;
2977 nla_nest_end(msg, nl_cfg);
2978 }
2979
2980 nla_nest_end(msg, nl_cfgs);
2981 rc = cfg80211_vendor_cmd_reply(msg);
2982 return rc;
2983 nla_put_failure:
2984 kfree_skb(msg);
2985 return -ENOBUFS;
2986 }
2987
wil_rf_sector_set_cfg(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int data_len)2988 static int wil_rf_sector_set_cfg(struct wiphy *wiphy,
2989 struct wireless_dev *wdev,
2990 const void *data, int data_len)
2991 {
2992 struct wil6210_priv *wil = wdev_to_wil(wdev);
2993 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2994 int rc, tmp;
2995 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
2996 struct nlattr *tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MAX + 1];
2997 u16 sector_index, rf_module_index;
2998 u8 sector_type;
2999 u32 rf_modules_vec = 0;
3000 struct wmi_set_rf_sector_params_cmd cmd;
3001 struct {
3002 struct wmi_cmd_hdr wmi;
3003 struct wmi_set_rf_sector_params_done_event evt;
3004 } __packed reply = {
3005 .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
3006 };
3007 struct nlattr *nl_cfg;
3008 struct wmi_rf_sector_info *si;
3009
3010 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
3011 return -EOPNOTSUPP;
3012
3013 rc = nla_parse_deprecated(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data,
3014 data_len, wil_rf_sector_policy, NULL);
3015 if (rc) {
3016 wil_err(wil, "Invalid rf sector ATTR\n");
3017 return rc;
3018 }
3019
3020 if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
3021 !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE] ||
3022 !tb[QCA_ATTR_DMG_RF_SECTOR_CFG]) {
3023 wil_err(wil, "Invalid rf sector spec\n");
3024 return -EINVAL;
3025 }
3026
3027 sector_index = nla_get_u16(
3028 tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
3029 if (sector_index >= WIL_MAX_RF_SECTORS) {
3030 wil_err(wil, "Invalid sector index %d\n", sector_index);
3031 return -EINVAL;
3032 }
3033
3034 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
3035 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
3036 wil_err(wil, "Invalid sector type %d\n", sector_type);
3037 return -EINVAL;
3038 }
3039
3040 memset(&cmd, 0, sizeof(cmd));
3041
3042 cmd.sector_idx = cpu_to_le16(sector_index);
3043 cmd.sector_type = sector_type;
3044 nla_for_each_nested(nl_cfg, tb[QCA_ATTR_DMG_RF_SECTOR_CFG],
3045 tmp) {
3046 rc = nla_parse_nested_deprecated(tb2,
3047 QCA_ATTR_DMG_RF_SECTOR_CFG_MAX,
3048 nl_cfg,
3049 wil_rf_sector_cfg_policy,
3050 NULL);
3051 if (rc) {
3052 wil_err(wil, "invalid sector cfg\n");
3053 return -EINVAL;
3054 }
3055
3056 if (!tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX] ||
3057 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0] ||
3058 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1] ||
3059 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2] ||
3060 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI] ||
3061 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO] ||
3062 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16]) {
3063 wil_err(wil, "missing cfg params\n");
3064 return -EINVAL;
3065 }
3066
3067 rf_module_index = nla_get_u8(
3068 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX]);
3069 if (rf_module_index >= WMI_MAX_RF_MODULES_NUM) {
3070 wil_err(wil, "invalid RF module index %d\n",
3071 rf_module_index);
3072 return -EINVAL;
3073 }
3074 rf_modules_vec |= BIT(rf_module_index);
3075 si = &cmd.sectors_info[rf_module_index];
3076 si->etype0 = cpu_to_le32(nla_get_u32(
3077 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0]));
3078 si->etype1 = cpu_to_le32(nla_get_u32(
3079 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1]));
3080 si->etype2 = cpu_to_le32(nla_get_u32(
3081 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2]));
3082 si->psh_hi = cpu_to_le32(nla_get_u32(
3083 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI]));
3084 si->psh_lo = cpu_to_le32(nla_get_u32(
3085 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO]));
3086 si->dtype_swch_off = cpu_to_le32(nla_get_u32(
3087 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16]));
3088 }
3089
3090 cmd.rf_modules_vec = rf_modules_vec & 0xFF;
3091 rc = wmi_call(wil, WMI_SET_RF_SECTOR_PARAMS_CMDID, vif->mid,
3092 &cmd, sizeof(cmd), WMI_SET_RF_SECTOR_PARAMS_DONE_EVENTID,
3093 &reply, sizeof(reply),
3094 500);
3095 if (rc)
3096 return rc;
3097 return wil_rf_sector_status_to_rc(reply.evt.status);
3098 }
3099
wil_rf_sector_get_selected(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int data_len)3100 static int wil_rf_sector_get_selected(struct wiphy *wiphy,
3101 struct wireless_dev *wdev,
3102 const void *data, int data_len)
3103 {
3104 struct wil6210_priv *wil = wdev_to_wil(wdev);
3105 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
3106 int rc;
3107 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
3108 u8 sector_type, mac_addr[ETH_ALEN];
3109 int cid = 0;
3110 struct wmi_get_selected_rf_sector_index_cmd cmd;
3111 struct {
3112 struct wmi_cmd_hdr wmi;
3113 struct wmi_get_selected_rf_sector_index_done_event evt;
3114 } __packed reply = {
3115 .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
3116 };
3117 struct sk_buff *msg;
3118
3119 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
3120 return -EOPNOTSUPP;
3121
3122 rc = nla_parse_deprecated(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data,
3123 data_len, wil_rf_sector_policy, NULL);
3124 if (rc) {
3125 wil_err(wil, "Invalid rf sector ATTR\n");
3126 return rc;
3127 }
3128
3129 if (!tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]) {
3130 wil_err(wil, "Invalid rf sector spec\n");
3131 return -EINVAL;
3132 }
3133 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
3134 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
3135 wil_err(wil, "Invalid sector type %d\n", sector_type);
3136 return -EINVAL;
3137 }
3138
3139 if (tb[QCA_ATTR_MAC_ADDR]) {
3140 ether_addr_copy(mac_addr, nla_data(tb[QCA_ATTR_MAC_ADDR]));
3141 cid = wil_find_cid(wil, vif->mid, mac_addr);
3142 if (cid < 0) {
3143 wil_err(wil, "invalid MAC address %pM\n", mac_addr);
3144 return -ENOENT;
3145 }
3146 } else {
3147 if (test_bit(wil_vif_fwconnected, vif->status)) {
3148 wil_err(wil, "must specify MAC address when connected\n");
3149 return -EINVAL;
3150 }
3151 }
3152
3153 memset(&cmd, 0, sizeof(cmd));
3154 cmd.cid = (u8)cid;
3155 cmd.sector_type = sector_type;
3156 rc = wmi_call(wil, WMI_GET_SELECTED_RF_SECTOR_INDEX_CMDID, vif->mid,
3157 &cmd, sizeof(cmd),
3158 WMI_GET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID,
3159 &reply, sizeof(reply),
3160 500);
3161 if (rc)
3162 return rc;
3163 if (reply.evt.status) {
3164 wil_err(wil, "get rf selected sector cfg failed with status %d\n",
3165 reply.evt.status);
3166 return wil_rf_sector_status_to_rc(reply.evt.status);
3167 }
3168
3169 msg = cfg80211_vendor_cmd_alloc_reply_skb(
3170 wiphy, 64 * WMI_MAX_RF_MODULES_NUM);
3171 if (!msg)
3172 return -ENOMEM;
3173
3174 if (nla_put_u64_64bit(msg, QCA_ATTR_TSF,
3175 le64_to_cpu(reply.evt.tsf),
3176 QCA_ATTR_PAD) ||
3177 nla_put_u16(msg, QCA_ATTR_DMG_RF_SECTOR_INDEX,
3178 le16_to_cpu(reply.evt.sector_idx)))
3179 goto nla_put_failure;
3180
3181 rc = cfg80211_vendor_cmd_reply(msg);
3182 return rc;
3183 nla_put_failure:
3184 kfree_skb(msg);
3185 return -ENOBUFS;
3186 }
3187
wil_rf_sector_wmi_set_selected(struct wil6210_priv * wil,u8 mid,u16 sector_index,u8 sector_type,u8 cid)3188 static int wil_rf_sector_wmi_set_selected(struct wil6210_priv *wil,
3189 u8 mid, u16 sector_index,
3190 u8 sector_type, u8 cid)
3191 {
3192 struct wmi_set_selected_rf_sector_index_cmd cmd;
3193 struct {
3194 struct wmi_cmd_hdr wmi;
3195 struct wmi_set_selected_rf_sector_index_done_event evt;
3196 } __packed reply = {
3197 .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
3198 };
3199 int rc;
3200
3201 memset(&cmd, 0, sizeof(cmd));
3202 cmd.sector_idx = cpu_to_le16(sector_index);
3203 cmd.sector_type = sector_type;
3204 cmd.cid = (u8)cid;
3205 rc = wmi_call(wil, WMI_SET_SELECTED_RF_SECTOR_INDEX_CMDID, mid,
3206 &cmd, sizeof(cmd),
3207 WMI_SET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID,
3208 &reply, sizeof(reply),
3209 500);
3210 if (rc)
3211 return rc;
3212 return wil_rf_sector_status_to_rc(reply.evt.status);
3213 }
3214
wil_rf_sector_set_selected(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int data_len)3215 static int wil_rf_sector_set_selected(struct wiphy *wiphy,
3216 struct wireless_dev *wdev,
3217 const void *data, int data_len)
3218 {
3219 struct wil6210_priv *wil = wdev_to_wil(wdev);
3220 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
3221 int rc;
3222 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
3223 u16 sector_index;
3224 u8 sector_type, mac_addr[ETH_ALEN], i;
3225 int cid = 0;
3226
3227 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
3228 return -EOPNOTSUPP;
3229
3230 rc = nla_parse_deprecated(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data,
3231 data_len, wil_rf_sector_policy, NULL);
3232 if (rc) {
3233 wil_err(wil, "Invalid rf sector ATTR\n");
3234 return rc;
3235 }
3236
3237 if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
3238 !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]) {
3239 wil_err(wil, "Invalid rf sector spec\n");
3240 return -EINVAL;
3241 }
3242
3243 sector_index = nla_get_u16(
3244 tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
3245 if (sector_index >= WIL_MAX_RF_SECTORS &&
3246 sector_index != WMI_INVALID_RF_SECTOR_INDEX) {
3247 wil_err(wil, "Invalid sector index %d\n", sector_index);
3248 return -EINVAL;
3249 }
3250
3251 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
3252 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
3253 wil_err(wil, "Invalid sector type %d\n", sector_type);
3254 return -EINVAL;
3255 }
3256
3257 if (tb[QCA_ATTR_MAC_ADDR]) {
3258 ether_addr_copy(mac_addr, nla_data(tb[QCA_ATTR_MAC_ADDR]));
3259 if (!is_broadcast_ether_addr(mac_addr)) {
3260 cid = wil_find_cid(wil, vif->mid, mac_addr);
3261 if (cid < 0) {
3262 wil_err(wil, "invalid MAC address %pM\n",
3263 mac_addr);
3264 return -ENOENT;
3265 }
3266 } else {
3267 if (sector_index != WMI_INVALID_RF_SECTOR_INDEX) {
3268 wil_err(wil, "broadcast MAC valid only with unlocking\n");
3269 return -EINVAL;
3270 }
3271 cid = -1;
3272 }
3273 } else {
3274 if (test_bit(wil_vif_fwconnected, vif->status)) {
3275 wil_err(wil, "must specify MAC address when connected\n");
3276 return -EINVAL;
3277 }
3278 /* otherwise, using cid=0 for unassociated station */
3279 }
3280
3281 if (cid >= 0) {
3282 rc = wil_rf_sector_wmi_set_selected(wil, vif->mid, sector_index,
3283 sector_type, cid);
3284 } else {
3285 /* unlock all cids */
3286 rc = wil_rf_sector_wmi_set_selected(
3287 wil, vif->mid, WMI_INVALID_RF_SECTOR_INDEX,
3288 sector_type, WIL_CID_ALL);
3289 if (rc == -EINVAL) {
3290 for (i = 0; i < wil->max_assoc_sta; i++) {
3291 if (wil->sta[i].mid != vif->mid)
3292 continue;
3293 rc = wil_rf_sector_wmi_set_selected(
3294 wil, vif->mid,
3295 WMI_INVALID_RF_SECTOR_INDEX,
3296 sector_type, i);
3297 /* the FW will silently ignore and return
3298 * success for unused cid, so abort the loop
3299 * on any other error
3300 */
3301 if (rc) {
3302 wil_err(wil, "unlock cid %d failed with status %d\n",
3303 i, rc);
3304 break;
3305 }
3306 }
3307 }
3308 }
3309
3310 return rc;
3311 }
3312