xref: /linux/drivers/net/wireless/quantenna/qtnfmac/cfg80211.c (revision 597473720f4dc69749542bfcfed4a927a43d935e)
1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */
3 
4 #include <linux/kernel.h>
5 #include <linux/etherdevice.h>
6 #include <linux/vmalloc.h>
7 #include <linux/ieee80211.h>
8 #include <net/cfg80211.h>
9 #include <net/netlink.h>
10 
11 #include "cfg80211.h"
12 #include "commands.h"
13 #include "core.h"
14 #include "util.h"
15 #include "bus.h"
16 
17 /* Supported rates to be advertised to the cfg80211 */
18 static struct ieee80211_rate qtnf_rates_2g[] = {
19 	{.bitrate = 10, .hw_value = 2, },
20 	{.bitrate = 20, .hw_value = 4, },
21 	{.bitrate = 55, .hw_value = 11, },
22 	{.bitrate = 110, .hw_value = 22, },
23 	{.bitrate = 60, .hw_value = 12, },
24 	{.bitrate = 90, .hw_value = 18, },
25 	{.bitrate = 120, .hw_value = 24, },
26 	{.bitrate = 180, .hw_value = 36, },
27 	{.bitrate = 240, .hw_value = 48, },
28 	{.bitrate = 360, .hw_value = 72, },
29 	{.bitrate = 480, .hw_value = 96, },
30 	{.bitrate = 540, .hw_value = 108, },
31 };
32 
33 /* Supported rates to be advertised to the cfg80211 */
34 static struct ieee80211_rate qtnf_rates_5g[] = {
35 	{.bitrate = 60, .hw_value = 12, },
36 	{.bitrate = 90, .hw_value = 18, },
37 	{.bitrate = 120, .hw_value = 24, },
38 	{.bitrate = 180, .hw_value = 36, },
39 	{.bitrate = 240, .hw_value = 48, },
40 	{.bitrate = 360, .hw_value = 72, },
41 	{.bitrate = 480, .hw_value = 96, },
42 	{.bitrate = 540, .hw_value = 108, },
43 };
44 
45 /* Supported crypto cipher suits to be advertised to cfg80211 */
46 static const u32 qtnf_cipher_suites[] = {
47 	WLAN_CIPHER_SUITE_TKIP,
48 	WLAN_CIPHER_SUITE_CCMP,
49 	WLAN_CIPHER_SUITE_AES_CMAC,
50 };
51 
52 /* Supported mgmt frame types to be advertised to cfg80211 */
53 static const struct ieee80211_txrx_stypes
54 qtnf_mgmt_stypes[NUM_NL80211_IFTYPES] = {
55 	[NL80211_IFTYPE_STATION] = {
56 		.tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
57 		      BIT(IEEE80211_STYPE_AUTH >> 4),
58 		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
59 		      BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
60 		      BIT(IEEE80211_STYPE_AUTH >> 4),
61 	},
62 	[NL80211_IFTYPE_AP] = {
63 		.tx = BIT(IEEE80211_STYPE_ACTION >> 4),
64 		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
65 		      BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
66 		      BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
67 		      BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
68 		      BIT(IEEE80211_STYPE_AUTH >> 4),
69 	},
70 };
71 
72 static int
73 qtnf_validate_iface_combinations(struct wiphy *wiphy,
74 				 struct qtnf_vif *change_vif,
75 				 enum nl80211_iftype new_type)
76 {
77 	struct qtnf_wmac *mac;
78 	struct qtnf_vif *vif;
79 	int i;
80 	int ret = 0;
81 	struct iface_combination_params params = {
82 		.num_different_channels = 1,
83 	};
84 
85 	mac = wiphy_priv(wiphy);
86 	if (!mac)
87 		return -EFAULT;
88 
89 	for (i = 0; i < QTNF_MAX_INTF; i++) {
90 		vif = &mac->iflist[i];
91 		if (vif->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
92 			params.iftype_num[vif->wdev.iftype]++;
93 	}
94 
95 	if (change_vif) {
96 		params.iftype_num[new_type]++;
97 		params.iftype_num[change_vif->wdev.iftype]--;
98 	} else {
99 		params.iftype_num[new_type]++;
100 	}
101 
102 	ret = cfg80211_check_combinations(wiphy, &params);
103 
104 	return ret;
105 }
106 
107 static int
108 qtnf_change_virtual_intf(struct wiphy *wiphy,
109 			 struct net_device *dev,
110 			 enum nl80211_iftype type,
111 			 struct vif_params *params)
112 {
113 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
114 	u8 *mac_addr = NULL;
115 	int use4addr = 0;
116 	int ret;
117 
118 	ret = qtnf_validate_iface_combinations(wiphy, vif, type);
119 	if (ret) {
120 		pr_err("VIF%u.%u combination check: failed to set type %d\n",
121 		       vif->mac->macid, vif->vifid, type);
122 		return ret;
123 	}
124 
125 	if (params) {
126 		mac_addr = params->macaddr;
127 		use4addr = params->use_4addr;
128 	}
129 
130 	qtnf_scan_done(vif->mac, true);
131 
132 	ret = qtnf_cmd_send_change_intf_type(vif, type, use4addr, mac_addr);
133 	if (ret) {
134 		pr_err("VIF%u.%u: failed to change type to %d\n",
135 		       vif->mac->macid, vif->vifid, type);
136 		return ret;
137 	}
138 
139 	vif->wdev.iftype = type;
140 	return 0;
141 }
142 
143 int qtnf_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
144 {
145 	struct net_device *netdev =  wdev->netdev;
146 	struct qtnf_vif *vif;
147 
148 	if (WARN_ON(!netdev))
149 		return -EFAULT;
150 
151 	vif = qtnf_netdev_get_priv(wdev->netdev);
152 
153 	qtnf_scan_done(vif->mac, true);
154 
155 	/* Stop data */
156 	netif_tx_stop_all_queues(netdev);
157 	if (netif_carrier_ok(netdev))
158 		netif_carrier_off(netdev);
159 
160 	if (netdev->reg_state == NETREG_REGISTERED)
161 		unregister_netdevice(netdev);
162 
163 	if (qtnf_cmd_send_del_intf(vif))
164 		pr_err("VIF%u.%u: failed to delete VIF\n", vif->mac->macid,
165 		       vif->vifid);
166 
167 	vif->netdev->ieee80211_ptr = NULL;
168 	vif->netdev = NULL;
169 	vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
170 
171 	return 0;
172 }
173 
174 static struct wireless_dev *qtnf_add_virtual_intf(struct wiphy *wiphy,
175 						  const char *name,
176 						  unsigned char name_assign_t,
177 						  enum nl80211_iftype type,
178 						  struct vif_params *params)
179 {
180 	struct qtnf_wmac *mac;
181 	struct qtnf_vif *vif;
182 	u8 *mac_addr = NULL;
183 	int use4addr = 0;
184 	int ret;
185 
186 	mac = wiphy_priv(wiphy);
187 
188 	if (!mac)
189 		return ERR_PTR(-EFAULT);
190 
191 	ret = qtnf_validate_iface_combinations(wiphy, NULL, type);
192 	if (ret) {
193 		pr_err("MAC%u invalid combination: failed to add type %d\n",
194 		       mac->macid, type);
195 		return ERR_PTR(ret);
196 	}
197 
198 	switch (type) {
199 	case NL80211_IFTYPE_STATION:
200 	case NL80211_IFTYPE_AP:
201 		vif = qtnf_mac_get_free_vif(mac);
202 		if (!vif) {
203 			pr_err("MAC%u: no free VIF available\n", mac->macid);
204 			return ERR_PTR(-EFAULT);
205 		}
206 
207 		eth_zero_addr(vif->mac_addr);
208 		eth_zero_addr(vif->bssid);
209 		vif->bss_priority = QTNF_DEF_BSS_PRIORITY;
210 		memset(&vif->wdev, 0, sizeof(vif->wdev));
211 		vif->wdev.wiphy = wiphy;
212 		vif->wdev.iftype = type;
213 		break;
214 	default:
215 		pr_err("MAC%u: unsupported IF type %d\n", mac->macid, type);
216 		return ERR_PTR(-ENOTSUPP);
217 	}
218 
219 	if (params) {
220 		mac_addr = params->macaddr;
221 		use4addr = params->use_4addr;
222 	}
223 
224 	ret = qtnf_cmd_send_add_intf(vif, type, use4addr, mac_addr);
225 	if (ret) {
226 		pr_err("VIF%u.%u: failed to add VIF %pM\n",
227 		       mac->macid, vif->vifid, mac_addr);
228 		goto err_cmd;
229 	}
230 
231 	if (!is_valid_ether_addr(vif->mac_addr)) {
232 		pr_err("VIF%u.%u: FW reported bad MAC: %pM\n",
233 		       mac->macid, vif->vifid, vif->mac_addr);
234 		ret = -EINVAL;
235 		goto err_mac;
236 	}
237 
238 	ret = qtnf_core_net_attach(mac, vif, name, name_assign_t);
239 	if (ret) {
240 		pr_err("VIF%u.%u: failed to attach netdev\n", mac->macid,
241 		       vif->vifid);
242 		goto err_net;
243 	}
244 
245 	vif->wdev.netdev = vif->netdev;
246 	return &vif->wdev;
247 
248 err_net:
249 	vif->netdev = NULL;
250 err_mac:
251 	qtnf_cmd_send_del_intf(vif);
252 err_cmd:
253 	vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
254 
255 	return ERR_PTR(ret);
256 }
257 
258 static int qtnf_mgmt_set_appie(struct qtnf_vif *vif,
259 			       const struct cfg80211_beacon_data *info)
260 {
261 	int ret = 0;
262 
263 	if (!info->beacon_ies || !info->beacon_ies_len) {
264 		ret = qtnf_cmd_send_mgmt_set_appie(vif, QLINK_IE_SET_BEACON_IES,
265 						   NULL, 0);
266 	} else {
267 		ret = qtnf_cmd_send_mgmt_set_appie(vif, QLINK_IE_SET_BEACON_IES,
268 						   info->beacon_ies,
269 						   info->beacon_ies_len);
270 	}
271 
272 	if (ret)
273 		goto out;
274 
275 	if (!info->proberesp_ies || !info->proberesp_ies_len) {
276 		ret = qtnf_cmd_send_mgmt_set_appie(vif,
277 						   QLINK_IE_SET_PROBE_RESP_IES,
278 						   NULL, 0);
279 	} else {
280 		ret = qtnf_cmd_send_mgmt_set_appie(vif,
281 						   QLINK_IE_SET_PROBE_RESP_IES,
282 						   info->proberesp_ies,
283 						   info->proberesp_ies_len);
284 	}
285 
286 	if (ret)
287 		goto out;
288 
289 	if (!info->assocresp_ies || !info->assocresp_ies_len) {
290 		ret = qtnf_cmd_send_mgmt_set_appie(vif,
291 						   QLINK_IE_SET_ASSOC_RESP,
292 						   NULL, 0);
293 	} else {
294 		ret = qtnf_cmd_send_mgmt_set_appie(vif,
295 						   QLINK_IE_SET_ASSOC_RESP,
296 						   info->assocresp_ies,
297 						   info->assocresp_ies_len);
298 	}
299 
300 out:
301 	return ret;
302 }
303 
304 static int qtnf_change_beacon(struct wiphy *wiphy, struct net_device *dev,
305 			      struct cfg80211_beacon_data *info)
306 {
307 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
308 
309 	return qtnf_mgmt_set_appie(vif, info);
310 }
311 
312 static int qtnf_start_ap(struct wiphy *wiphy, struct net_device *dev,
313 			 struct cfg80211_ap_settings *settings)
314 {
315 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
316 	int ret;
317 
318 	ret = qtnf_cmd_send_start_ap(vif, settings);
319 	if (ret)
320 		pr_err("VIF%u.%u: failed to start AP\n", vif->mac->macid,
321 		       vif->vifid);
322 
323 	return ret;
324 }
325 
326 static int qtnf_stop_ap(struct wiphy *wiphy, struct net_device *dev)
327 {
328 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
329 	int ret;
330 
331 	qtnf_scan_done(vif->mac, true);
332 
333 	ret = qtnf_cmd_send_stop_ap(vif);
334 	if (ret)
335 		pr_err("VIF%u.%u: failed to stop AP operation in FW\n",
336 		       vif->mac->macid, vif->vifid);
337 
338 	netif_carrier_off(vif->netdev);
339 
340 	return ret;
341 }
342 
343 static int qtnf_set_wiphy_params(struct wiphy *wiphy, u32 changed)
344 {
345 	struct qtnf_wmac *mac = wiphy_priv(wiphy);
346 	struct qtnf_vif *vif;
347 	int ret;
348 
349 	vif = qtnf_mac_get_base_vif(mac);
350 	if (!vif) {
351 		pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
352 		return -EFAULT;
353 	}
354 
355 	ret = qtnf_cmd_send_update_phy_params(mac, changed);
356 	if (ret)
357 		pr_err("MAC%u: failed to update PHY params\n", mac->macid);
358 
359 	return ret;
360 }
361 
362 static void
363 qtnf_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
364 			 u16 frame_type, bool reg)
365 {
366 	struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
367 	u16 mgmt_type;
368 	u16 new_mask;
369 	u16 qlink_frame_type = 0;
370 
371 	mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
372 
373 	if (reg)
374 		new_mask = vif->mgmt_frames_bitmask | BIT(mgmt_type);
375 	else
376 		new_mask = vif->mgmt_frames_bitmask & ~BIT(mgmt_type);
377 
378 	if (new_mask == vif->mgmt_frames_bitmask)
379 		return;
380 
381 	switch (frame_type & IEEE80211_FCTL_STYPE) {
382 	case IEEE80211_STYPE_REASSOC_REQ:
383 	case IEEE80211_STYPE_ASSOC_REQ:
384 		qlink_frame_type = QLINK_MGMT_FRAME_ASSOC_REQ;
385 		break;
386 	case IEEE80211_STYPE_AUTH:
387 		qlink_frame_type = QLINK_MGMT_FRAME_AUTH;
388 		break;
389 	case IEEE80211_STYPE_PROBE_REQ:
390 		qlink_frame_type = QLINK_MGMT_FRAME_PROBE_REQ;
391 		break;
392 	case IEEE80211_STYPE_ACTION:
393 		qlink_frame_type = QLINK_MGMT_FRAME_ACTION;
394 		break;
395 	default:
396 		pr_warn("VIF%u.%u: unsupported frame type: %X\n",
397 			vif->mac->macid, vif->vifid,
398 			(frame_type & IEEE80211_FCTL_STYPE) >> 4);
399 		return;
400 	}
401 
402 	if (qtnf_cmd_send_register_mgmt(vif, qlink_frame_type, reg)) {
403 		pr_warn("VIF%u.%u: failed to %sregister mgmt frame type 0x%x\n",
404 			vif->mac->macid, vif->vifid, reg ? "" : "un",
405 			frame_type);
406 		return;
407 	}
408 
409 	vif->mgmt_frames_bitmask = new_mask;
410 	pr_debug("VIF%u.%u: %sregistered mgmt frame type 0x%x\n",
411 		 vif->mac->macid, vif->vifid, reg ? "" : "un", frame_type);
412 }
413 
414 static int
415 qtnf_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
416 	     struct cfg80211_mgmt_tx_params *params, u64 *cookie)
417 {
418 	struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
419 	const struct ieee80211_mgmt *mgmt_frame = (void *)params->buf;
420 	u32 short_cookie = prandom_u32();
421 	u16 flags = 0;
422 	u16 freq;
423 
424 	*cookie = short_cookie;
425 
426 	if (params->offchan)
427 		flags |= QLINK_MGMT_FRAME_TX_FLAG_OFFCHAN;
428 
429 	if (params->no_cck)
430 		flags |= QLINK_MGMT_FRAME_TX_FLAG_NO_CCK;
431 
432 	if (params->dont_wait_for_ack)
433 		flags |= QLINK_MGMT_FRAME_TX_FLAG_ACK_NOWAIT;
434 
435 	/* If channel is not specified, pass "freq = 0" to tell device
436 	 * firmware to use current channel.
437 	 */
438 	if (params->chan)
439 		freq = params->chan->center_freq;
440 	else
441 		freq = 0;
442 
443 	pr_debug("%s freq:%u; FC:%.4X; DA:%pM; len:%zu; C:%.8X; FL:%.4X\n",
444 		 wdev->netdev->name, freq,
445 		 le16_to_cpu(mgmt_frame->frame_control), mgmt_frame->da,
446 		 params->len, short_cookie, flags);
447 
448 	return qtnf_cmd_send_mgmt_frame(vif, short_cookie, flags,
449 					freq,
450 					params->buf, params->len);
451 }
452 
453 static int
454 qtnf_get_station(struct wiphy *wiphy, struct net_device *dev,
455 		 const u8 *mac, struct station_info *sinfo)
456 {
457 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
458 
459 	sinfo->generation = vif->generation;
460 	return qtnf_cmd_get_sta_info(vif, mac, sinfo);
461 }
462 
463 static int
464 qtnf_dump_station(struct wiphy *wiphy, struct net_device *dev,
465 		  int idx, u8 *mac, struct station_info *sinfo)
466 {
467 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
468 	const struct qtnf_sta_node *sta_node;
469 	int ret;
470 
471 	switch (vif->wdev.iftype) {
472 	case NL80211_IFTYPE_STATION:
473 		if (idx != 0 || !vif->wdev.current_bss)
474 			return -ENOENT;
475 
476 		ether_addr_copy(mac, vif->bssid);
477 		break;
478 	case NL80211_IFTYPE_AP:
479 		sta_node = qtnf_sta_list_lookup_index(&vif->sta_list, idx);
480 		if (unlikely(!sta_node))
481 			return -ENOENT;
482 
483 		ether_addr_copy(mac, sta_node->mac_addr);
484 		break;
485 	default:
486 		return -ENOTSUPP;
487 	}
488 
489 	ret = qtnf_cmd_get_sta_info(vif, mac, sinfo);
490 
491 	if (vif->wdev.iftype == NL80211_IFTYPE_AP) {
492 		if (ret == -ENOENT) {
493 			cfg80211_del_sta(vif->netdev, mac, GFP_KERNEL);
494 			sinfo->filled = 0;
495 		}
496 	}
497 
498 	sinfo->generation = vif->generation;
499 
500 	return ret;
501 }
502 
503 static int qtnf_add_key(struct wiphy *wiphy, struct net_device *dev,
504 			u8 key_index, bool pairwise, const u8 *mac_addr,
505 			struct key_params *params)
506 {
507 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
508 	int ret;
509 
510 	ret = qtnf_cmd_send_add_key(vif, key_index, pairwise, mac_addr, params);
511 	if (ret)
512 		pr_err("VIF%u.%u: failed to add key: cipher=%x idx=%u pw=%u\n",
513 		       vif->mac->macid, vif->vifid, params->cipher, key_index,
514 		       pairwise);
515 
516 	return ret;
517 }
518 
519 static int qtnf_del_key(struct wiphy *wiphy, struct net_device *dev,
520 			u8 key_index, bool pairwise, const u8 *mac_addr)
521 {
522 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
523 	int ret;
524 
525 	ret = qtnf_cmd_send_del_key(vif, key_index, pairwise, mac_addr);
526 	if (ret) {
527 		if (ret == -ENOENT) {
528 			pr_debug("VIF%u.%u: key index %d out of bounds\n",
529 				 vif->mac->macid, vif->vifid, key_index);
530 		} else {
531 			pr_err("VIF%u.%u: failed to delete key: idx=%u pw=%u\n",
532 			       vif->mac->macid, vif->vifid,
533 			       key_index, pairwise);
534 		}
535 	}
536 
537 	return ret;
538 }
539 
540 static int qtnf_set_default_key(struct wiphy *wiphy, struct net_device *dev,
541 				u8 key_index, bool unicast, bool multicast)
542 {
543 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
544 	int ret;
545 
546 	ret = qtnf_cmd_send_set_default_key(vif, key_index, unicast, multicast);
547 	if (ret)
548 		pr_err("VIF%u.%u: failed to set dflt key: idx=%u uc=%u mc=%u\n",
549 		       vif->mac->macid, vif->vifid, key_index, unicast,
550 		       multicast);
551 
552 	return ret;
553 }
554 
555 static int
556 qtnf_set_default_mgmt_key(struct wiphy *wiphy, struct net_device *dev,
557 			  u8 key_index)
558 {
559 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
560 	int ret;
561 
562 	ret = qtnf_cmd_send_set_default_mgmt_key(vif, key_index);
563 	if (ret)
564 		pr_err("VIF%u.%u: failed to set default MGMT key: idx=%u\n",
565 		       vif->mac->macid, vif->vifid, key_index);
566 
567 	return ret;
568 }
569 
570 static int
571 qtnf_change_station(struct wiphy *wiphy, struct net_device *dev,
572 		    const u8 *mac, struct station_parameters *params)
573 {
574 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
575 	int ret;
576 
577 	ret = qtnf_cmd_send_change_sta(vif, mac, params);
578 	if (ret)
579 		pr_err("VIF%u.%u: failed to change STA %pM\n",
580 		       vif->mac->macid, vif->vifid, mac);
581 
582 	return ret;
583 }
584 
585 static int
586 qtnf_del_station(struct wiphy *wiphy, struct net_device *dev,
587 		 struct station_del_parameters *params)
588 {
589 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
590 	int ret;
591 
592 	if (params->mac &&
593 	    (vif->wdev.iftype == NL80211_IFTYPE_AP) &&
594 	    !is_broadcast_ether_addr(params->mac) &&
595 	    !qtnf_sta_list_lookup(&vif->sta_list, params->mac))
596 		return 0;
597 
598 	ret = qtnf_cmd_send_del_sta(vif, params);
599 	if (ret)
600 		pr_err("VIF%u.%u: failed to delete STA %pM\n",
601 		       vif->mac->macid, vif->vifid, params->mac);
602 
603 	return ret;
604 }
605 
606 static int
607 qtnf_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
608 {
609 	struct qtnf_wmac *mac = wiphy_priv(wiphy);
610 	int ret;
611 
612 	cancel_delayed_work_sync(&mac->scan_timeout);
613 
614 	mac->scan_req = request;
615 
616 	ret = qtnf_cmd_send_scan(mac);
617 	if (ret) {
618 		pr_err("MAC%u: failed to start scan\n", mac->macid);
619 		mac->scan_req = NULL;
620 		goto out;
621 	}
622 
623 	pr_debug("MAC%u: scan started\n", mac->macid);
624 	queue_delayed_work(mac->bus->workqueue, &mac->scan_timeout,
625 			   QTNF_SCAN_TIMEOUT_SEC * HZ);
626 
627 out:
628 	return ret;
629 }
630 
631 static int
632 qtnf_connect(struct wiphy *wiphy, struct net_device *dev,
633 	     struct cfg80211_connect_params *sme)
634 {
635 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
636 	int ret;
637 
638 	if (vif->wdev.iftype != NL80211_IFTYPE_STATION)
639 		return -EOPNOTSUPP;
640 
641 	if (sme->auth_type == NL80211_AUTHTYPE_SAE &&
642 	    !(sme->flags & CONNECT_REQ_EXTERNAL_AUTH_SUPPORT)) {
643 		pr_err("can not offload authentication to userspace\n");
644 		return -EOPNOTSUPP;
645 	}
646 
647 	if (sme->bssid)
648 		ether_addr_copy(vif->bssid, sme->bssid);
649 	else
650 		eth_zero_addr(vif->bssid);
651 
652 	ret = qtnf_cmd_send_connect(vif, sme);
653 	if (ret) {
654 		pr_err("VIF%u.%u: failed to connect\n",
655 		       vif->mac->macid, vif->vifid);
656 		goto out;
657 	}
658 
659 out:
660 	return ret;
661 }
662 
663 static int
664 qtnf_external_auth(struct wiphy *wiphy, struct net_device *dev,
665 		   struct cfg80211_external_auth_params *auth)
666 {
667 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
668 	int ret;
669 
670 	if (vif->wdev.iftype != NL80211_IFTYPE_STATION)
671 		return -EOPNOTSUPP;
672 
673 	if (!ether_addr_equal(vif->bssid, auth->bssid))
674 		pr_warn("unexpected bssid: %pM", auth->bssid);
675 
676 	ret = qtnf_cmd_send_external_auth(vif, auth);
677 	if (ret) {
678 		pr_err("VIF%u.%u: failed to report external auth\n",
679 		       vif->mac->macid, vif->vifid);
680 		goto out;
681 	}
682 
683 out:
684 	return ret;
685 }
686 
687 static int
688 qtnf_disconnect(struct wiphy *wiphy, struct net_device *dev,
689 		u16 reason_code)
690 {
691 	struct qtnf_wmac *mac = wiphy_priv(wiphy);
692 	struct qtnf_vif *vif;
693 	int ret = 0;
694 
695 	vif = qtnf_mac_get_base_vif(mac);
696 	if (!vif) {
697 		pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
698 		return -EFAULT;
699 	}
700 
701 	if (vif->wdev.iftype != NL80211_IFTYPE_STATION) {
702 		ret = -EOPNOTSUPP;
703 		goto out;
704 	}
705 
706 	ret = qtnf_cmd_send_disconnect(vif, reason_code);
707 	if (ret)
708 		pr_err("VIF%u.%u: failed to disconnect\n",
709 		       mac->macid, vif->vifid);
710 
711 	if (vif->wdev.current_bss) {
712 		netif_carrier_off(vif->netdev);
713 		cfg80211_disconnected(vif->netdev, reason_code,
714 				      NULL, 0, true, GFP_KERNEL);
715 	}
716 
717 out:
718 	return ret;
719 }
720 
721 static int
722 qtnf_dump_survey(struct wiphy *wiphy, struct net_device *dev,
723 		 int idx, struct survey_info *survey)
724 {
725 	struct qtnf_wmac *mac = wiphy_priv(wiphy);
726 	struct wireless_dev *wdev = dev->ieee80211_ptr;
727 	struct ieee80211_supported_band *sband;
728 	const struct cfg80211_chan_def *chandef = &wdev->chandef;
729 	struct ieee80211_channel *chan;
730 	struct qtnf_chan_stats stats;
731 	int ret;
732 
733 	sband = wiphy->bands[NL80211_BAND_2GHZ];
734 	if (sband && idx >= sband->n_channels) {
735 		idx -= sband->n_channels;
736 		sband = NULL;
737 	}
738 
739 	if (!sband)
740 		sband = wiphy->bands[NL80211_BAND_5GHZ];
741 
742 	if (!sband || idx >= sband->n_channels)
743 		return -ENOENT;
744 
745 	chan = &sband->channels[idx];
746 	memset(&stats, 0, sizeof(stats));
747 
748 	survey->channel = chan;
749 	survey->filled = 0x0;
750 
751 	if (chandef->chan) {
752 		if (chan->hw_value == chandef->chan->hw_value)
753 			survey->filled = SURVEY_INFO_IN_USE;
754 	}
755 
756 	ret = qtnf_cmd_get_chan_stats(mac, chan->hw_value, &stats);
757 	switch (ret) {
758 	case 0:
759 		if (unlikely(stats.chan_num != chan->hw_value)) {
760 			pr_err("received stats for channel %d instead of %d\n",
761 			       stats.chan_num, chan->hw_value);
762 			ret = -EINVAL;
763 			break;
764 		}
765 
766 		survey->filled |= SURVEY_INFO_TIME |
767 				 SURVEY_INFO_TIME_SCAN |
768 				 SURVEY_INFO_TIME_BUSY |
769 				 SURVEY_INFO_TIME_RX |
770 				 SURVEY_INFO_TIME_TX |
771 				 SURVEY_INFO_NOISE_DBM;
772 
773 		survey->time_scan = stats.cca_try;
774 		survey->time = stats.cca_try;
775 		survey->time_tx = stats.cca_tx;
776 		survey->time_rx = stats.cca_rx;
777 		survey->time_busy = stats.cca_busy;
778 		survey->noise = stats.chan_noise;
779 		break;
780 	case -ENOENT:
781 		pr_debug("no stats for channel %u\n", chan->hw_value);
782 		ret = 0;
783 		break;
784 	default:
785 		pr_debug("failed to get chan(%d) stats from card\n",
786 			 chan->hw_value);
787 		break;
788 	}
789 
790 	return ret;
791 }
792 
793 static int
794 qtnf_get_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
795 		 struct cfg80211_chan_def *chandef)
796 {
797 	struct net_device *ndev = wdev->netdev;
798 	struct qtnf_vif *vif;
799 	int ret;
800 
801 	if (!ndev)
802 		return -ENODEV;
803 
804 	vif = qtnf_netdev_get_priv(wdev->netdev);
805 
806 	ret = qtnf_cmd_get_channel(vif, chandef);
807 	if (ret) {
808 		pr_err("%s: failed to get channel: %d\n", ndev->name, ret);
809 		ret = -ENODATA;
810 		goto out;
811 	}
812 
813 	if (!cfg80211_chandef_valid(chandef)) {
814 		pr_err("%s: bad channel freq=%u cf1=%u cf2=%u bw=%u\n",
815 		       ndev->name, chandef->chan->center_freq,
816 		       chandef->center_freq1, chandef->center_freq2,
817 		       chandef->width);
818 		ret = -ENODATA;
819 		goto out;
820 	}
821 
822 out:
823 	return ret;
824 }
825 
826 static int qtnf_channel_switch(struct wiphy *wiphy, struct net_device *dev,
827 			       struct cfg80211_csa_settings *params)
828 {
829 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
830 	int ret;
831 
832 	pr_debug("%s: chan(%u) count(%u) radar(%u) block_tx(%u)\n", dev->name,
833 		 params->chandef.chan->hw_value, params->count,
834 		 params->radar_required, params->block_tx);
835 
836 	if (!cfg80211_chandef_valid(&params->chandef)) {
837 		pr_err("%s: invalid channel\n", dev->name);
838 		return -EINVAL;
839 	}
840 
841 	ret = qtnf_cmd_send_chan_switch(vif, params);
842 	if (ret)
843 		pr_warn("%s: failed to switch to channel (%u)\n",
844 			dev->name, params->chandef.chan->hw_value);
845 
846 	return ret;
847 }
848 
849 static int qtnf_start_radar_detection(struct wiphy *wiphy,
850 				      struct net_device *ndev,
851 				      struct cfg80211_chan_def *chandef,
852 				      u32 cac_time_ms)
853 {
854 	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
855 	int ret;
856 
857 	if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
858 		return -ENOTSUPP;
859 
860 	ret = qtnf_cmd_start_cac(vif, chandef, cac_time_ms);
861 	if (ret)
862 		pr_err("%s: failed to start CAC ret=%d\n", ndev->name, ret);
863 
864 	return ret;
865 }
866 
867 static int qtnf_set_mac_acl(struct wiphy *wiphy,
868 			    struct net_device *dev,
869 			    const struct cfg80211_acl_data *params)
870 {
871 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
872 	int ret;
873 
874 	ret = qtnf_cmd_set_mac_acl(vif, params);
875 	if (ret)
876 		pr_err("%s: failed to set mac ACL ret=%d\n", dev->name, ret);
877 
878 	return ret;
879 }
880 
881 static int qtnf_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
882 			       bool enabled, int timeout)
883 {
884 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
885 	int ret;
886 
887 	ret = qtnf_cmd_send_pm_set(vif, enabled ? QLINK_PM_AUTO_STANDBY :
888 				   QLINK_PM_OFF, timeout);
889 	if (ret)
890 		pr_err("%s: failed to set PM mode ret=%d\n", dev->name, ret);
891 
892 	return ret;
893 }
894 
895 #ifdef CONFIG_PM
896 static int qtnf_suspend(struct wiphy *wiphy, struct cfg80211_wowlan *wowlan)
897 {
898 	struct qtnf_wmac *mac = wiphy_priv(wiphy);
899 	struct qtnf_vif *vif;
900 	int ret = 0;
901 
902 	vif = qtnf_mac_get_base_vif(mac);
903 	if (!vif) {
904 		pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
905 		ret = -EFAULT;
906 		goto exit;
907 	}
908 
909 	if (!wowlan) {
910 		pr_debug("WoWLAN triggers are not enabled\n");
911 		qtnf_virtual_intf_cleanup(vif->netdev);
912 		goto exit;
913 	}
914 
915 	qtnf_scan_done(vif->mac, true);
916 
917 	ret = qtnf_cmd_send_wowlan_set(vif, wowlan);
918 	if (ret) {
919 		pr_err("MAC%u: failed to set WoWLAN triggers\n",
920 		       mac->macid);
921 		goto exit;
922 	}
923 
924 exit:
925 	return ret;
926 }
927 
928 static int qtnf_resume(struct wiphy *wiphy)
929 {
930 	struct qtnf_wmac *mac = wiphy_priv(wiphy);
931 	struct qtnf_vif *vif;
932 	int ret = 0;
933 
934 	vif = qtnf_mac_get_base_vif(mac);
935 	if (!vif) {
936 		pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
937 		ret = -EFAULT;
938 		goto exit;
939 	}
940 
941 	ret = qtnf_cmd_send_wowlan_set(vif, NULL);
942 	if (ret) {
943 		pr_err("MAC%u: failed to reset WoWLAN triggers\n",
944 		       mac->macid);
945 		goto exit;
946 	}
947 
948 exit:
949 	return ret;
950 }
951 
952 static void qtnf_set_wakeup(struct wiphy *wiphy, bool enabled)
953 {
954 	struct qtnf_wmac *mac = wiphy_priv(wiphy);
955 	struct qtnf_bus *bus = mac->bus;
956 
957 	device_set_wakeup_enable(bus->dev, enabled);
958 }
959 #endif
960 
961 static struct cfg80211_ops qtn_cfg80211_ops = {
962 	.add_virtual_intf	= qtnf_add_virtual_intf,
963 	.change_virtual_intf	= qtnf_change_virtual_intf,
964 	.del_virtual_intf	= qtnf_del_virtual_intf,
965 	.start_ap		= qtnf_start_ap,
966 	.change_beacon		= qtnf_change_beacon,
967 	.stop_ap		= qtnf_stop_ap,
968 	.set_wiphy_params	= qtnf_set_wiphy_params,
969 	.mgmt_frame_register	= qtnf_mgmt_frame_register,
970 	.mgmt_tx		= qtnf_mgmt_tx,
971 	.change_station		= qtnf_change_station,
972 	.del_station		= qtnf_del_station,
973 	.get_station		= qtnf_get_station,
974 	.dump_station		= qtnf_dump_station,
975 	.add_key		= qtnf_add_key,
976 	.del_key		= qtnf_del_key,
977 	.set_default_key	= qtnf_set_default_key,
978 	.set_default_mgmt_key	= qtnf_set_default_mgmt_key,
979 	.scan			= qtnf_scan,
980 	.connect		= qtnf_connect,
981 	.external_auth		= qtnf_external_auth,
982 	.disconnect		= qtnf_disconnect,
983 	.dump_survey		= qtnf_dump_survey,
984 	.get_channel		= qtnf_get_channel,
985 	.channel_switch		= qtnf_channel_switch,
986 	.start_radar_detection	= qtnf_start_radar_detection,
987 	.set_mac_acl		= qtnf_set_mac_acl,
988 	.set_power_mgmt		= qtnf_set_power_mgmt,
989 #ifdef CONFIG_PM
990 	.suspend		= qtnf_suspend,
991 	.resume			= qtnf_resume,
992 	.set_wakeup		= qtnf_set_wakeup,
993 #endif
994 };
995 
996 static void qtnf_cfg80211_reg_notifier(struct wiphy *wiphy_in,
997 				       struct regulatory_request *req)
998 {
999 	struct qtnf_wmac *mac = wiphy_priv(wiphy_in);
1000 	struct qtnf_bus *bus = mac->bus;
1001 	struct wiphy *wiphy;
1002 	unsigned int mac_idx;
1003 	enum nl80211_band band;
1004 	int ret;
1005 
1006 	pr_debug("MAC%u: initiator=%d alpha=%c%c\n", mac->macid, req->initiator,
1007 		 req->alpha2[0], req->alpha2[1]);
1008 
1009 	ret = qtnf_cmd_reg_notify(bus, req);
1010 	if (ret) {
1011 		if (ret == -EOPNOTSUPP) {
1012 			pr_warn("reg update not supported\n");
1013 		} else if (ret == -EALREADY) {
1014 			pr_info("regulatory domain is already set to %c%c",
1015 				req->alpha2[0], req->alpha2[1]);
1016 		} else {
1017 			pr_err("failed to update reg domain to %c%c\n",
1018 			       req->alpha2[0], req->alpha2[1]);
1019 		}
1020 
1021 		return;
1022 	}
1023 
1024 	for (mac_idx = 0; mac_idx < QTNF_MAX_MAC; ++mac_idx) {
1025 		if (!(bus->hw_info.mac_bitmap & (1 << mac_idx)))
1026 			continue;
1027 
1028 		mac = bus->mac[mac_idx];
1029 		if (!mac)
1030 			continue;
1031 
1032 		wiphy = priv_to_wiphy(mac);
1033 
1034 		for (band = 0; band < NUM_NL80211_BANDS; ++band) {
1035 			if (!wiphy->bands[band])
1036 				continue;
1037 
1038 			ret = qtnf_cmd_band_info_get(mac, wiphy->bands[band]);
1039 			if (ret)
1040 				pr_err("failed to get chan info for mac %u band %u\n",
1041 				       mac_idx, band);
1042 		}
1043 	}
1044 }
1045 
1046 struct wiphy *qtnf_wiphy_allocate(struct qtnf_bus *bus)
1047 {
1048 	struct wiphy *wiphy;
1049 
1050 	if (bus->hw_info.hw_capab & QLINK_HW_CAPAB_DFS_OFFLOAD)
1051 		qtn_cfg80211_ops.start_radar_detection = NULL;
1052 
1053 	if (!(bus->hw_info.hw_capab & QLINK_HW_CAPAB_PWR_MGMT))
1054 		qtn_cfg80211_ops.set_power_mgmt	= NULL;
1055 
1056 	wiphy = wiphy_new(&qtn_cfg80211_ops, sizeof(struct qtnf_wmac));
1057 	if (!wiphy)
1058 		return NULL;
1059 
1060 	set_wiphy_dev(wiphy, bus->dev);
1061 
1062 	return wiphy;
1063 }
1064 
1065 static int
1066 qtnf_wiphy_setup_if_comb(struct wiphy *wiphy, struct qtnf_mac_info *mac_info)
1067 {
1068 	struct ieee80211_iface_combination *if_comb;
1069 	size_t n_if_comb;
1070 	u16 interface_modes = 0;
1071 	size_t i, j;
1072 
1073 	if_comb = mac_info->if_comb;
1074 	n_if_comb = mac_info->n_if_comb;
1075 
1076 	if (!if_comb || !n_if_comb)
1077 		return -ENOENT;
1078 
1079 	for (i = 0; i < n_if_comb; i++) {
1080 		if_comb[i].radar_detect_widths = mac_info->radar_detect_widths;
1081 
1082 		for (j = 0; j < if_comb[i].n_limits; j++)
1083 			interface_modes |= if_comb[i].limits[j].types;
1084 	}
1085 
1086 	wiphy->iface_combinations = if_comb;
1087 	wiphy->n_iface_combinations = n_if_comb;
1088 	wiphy->interface_modes = interface_modes;
1089 
1090 	return 0;
1091 }
1092 
1093 int qtnf_wiphy_register(struct qtnf_hw_info *hw_info, struct qtnf_wmac *mac)
1094 {
1095 	struct wiphy *wiphy = priv_to_wiphy(mac);
1096 	struct qtnf_mac_info *macinfo = &mac->macinfo;
1097 	int ret;
1098 
1099 	if (!wiphy) {
1100 		pr_err("invalid wiphy pointer\n");
1101 		return -EFAULT;
1102 	}
1103 
1104 	wiphy->frag_threshold = macinfo->frag_thr;
1105 	wiphy->rts_threshold = macinfo->rts_thr;
1106 	wiphy->retry_short = macinfo->sretry_limit;
1107 	wiphy->retry_long = macinfo->lretry_limit;
1108 	wiphy->coverage_class = macinfo->coverage_class;
1109 
1110 	wiphy->max_scan_ssids =
1111 		(hw_info->max_scan_ssids) ? hw_info->max_scan_ssids : 1;
1112 	wiphy->max_scan_ie_len = QTNF_MAX_VSIE_LEN;
1113 	wiphy->mgmt_stypes = qtnf_mgmt_stypes;
1114 	wiphy->max_remain_on_channel_duration = 5000;
1115 	wiphy->max_acl_mac_addrs = macinfo->max_acl_mac_addrs;
1116 	wiphy->max_num_csa_counters = 2;
1117 
1118 	ret = qtnf_wiphy_setup_if_comb(wiphy, macinfo);
1119 	if (ret)
1120 		goto out;
1121 
1122 	/* Initialize cipher suits */
1123 	wiphy->cipher_suites = qtnf_cipher_suites;
1124 	wiphy->n_cipher_suites = ARRAY_SIZE(qtnf_cipher_suites);
1125 	wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1126 	wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
1127 			WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
1128 			WIPHY_FLAG_AP_UAPSD |
1129 			WIPHY_FLAG_HAS_CHANNEL_SWITCH |
1130 			WIPHY_FLAG_4ADDR_STATION;
1131 	wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
1132 
1133 	if (hw_info->hw_capab & QLINK_HW_CAPAB_DFS_OFFLOAD)
1134 		wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD);
1135 
1136 	if (hw_info->hw_capab & QLINK_HW_CAPAB_SCAN_DWELL)
1137 		wiphy_ext_feature_set(wiphy,
1138 				      NL80211_EXT_FEATURE_SET_SCAN_DWELL);
1139 
1140 	wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1141 				    NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2;
1142 
1143 	wiphy->available_antennas_tx = macinfo->num_tx_chain;
1144 	wiphy->available_antennas_rx = macinfo->num_rx_chain;
1145 
1146 	wiphy->max_ap_assoc_sta = macinfo->max_ap_assoc_sta;
1147 	wiphy->ht_capa_mod_mask = &macinfo->ht_cap_mod_mask;
1148 	wiphy->vht_capa_mod_mask = &macinfo->vht_cap_mod_mask;
1149 
1150 	ether_addr_copy(wiphy->perm_addr, mac->macaddr);
1151 
1152 	if (hw_info->hw_capab & QLINK_HW_CAPAB_STA_INACT_TIMEOUT)
1153 		wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER;
1154 
1155 	if (hw_info->hw_capab & QLINK_HW_CAPAB_SCAN_RANDOM_MAC_ADDR)
1156 		wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
1157 
1158 	if (!(hw_info->hw_capab & QLINK_HW_CAPAB_OBSS_SCAN))
1159 		wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
1160 
1161 	if (hw_info->hw_capab & QLINK_HW_CAPAB_SAE)
1162 		wiphy->features |= NL80211_FEATURE_SAE;
1163 
1164 #ifdef CONFIG_PM
1165 	if (macinfo->wowlan)
1166 		wiphy->wowlan = macinfo->wowlan;
1167 #endif
1168 
1169 	if (hw_info->hw_capab & QLINK_HW_CAPAB_REG_UPDATE) {
1170 		wiphy->regulatory_flags |= REGULATORY_STRICT_REG |
1171 			REGULATORY_CUSTOM_REG;
1172 		wiphy->reg_notifier = qtnf_cfg80211_reg_notifier;
1173 		wiphy_apply_custom_regulatory(wiphy, hw_info->rd);
1174 	} else {
1175 		wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
1176 	}
1177 
1178 	if (mac->macinfo.extended_capabilities_len) {
1179 		wiphy->extended_capabilities =
1180 			mac->macinfo.extended_capabilities;
1181 		wiphy->extended_capabilities_mask =
1182 			mac->macinfo.extended_capabilities_mask;
1183 		wiphy->extended_capabilities_len =
1184 			mac->macinfo.extended_capabilities_len;
1185 	}
1186 
1187 	strlcpy(wiphy->fw_version, hw_info->fw_version,
1188 		sizeof(wiphy->fw_version));
1189 	wiphy->hw_version = hw_info->hw_version;
1190 
1191 	ret = wiphy_register(wiphy);
1192 	if (ret < 0)
1193 		goto out;
1194 
1195 	if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED)
1196 		ret = regulatory_set_wiphy_regd(wiphy, hw_info->rd);
1197 	else if (isalpha(hw_info->rd->alpha2[0]) &&
1198 		 isalpha(hw_info->rd->alpha2[1]))
1199 		ret = regulatory_hint(wiphy, hw_info->rd->alpha2);
1200 
1201 out:
1202 	return ret;
1203 }
1204 
1205 void qtnf_netdev_updown(struct net_device *ndev, bool up)
1206 {
1207 	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
1208 
1209 	if (qtnf_cmd_send_updown_intf(vif, up))
1210 		pr_err("failed to send %s command to VIF%u.%u\n",
1211 		       up ? "UP" : "DOWN", vif->mac->macid, vif->vifid);
1212 }
1213 
1214 void qtnf_virtual_intf_cleanup(struct net_device *ndev)
1215 {
1216 	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
1217 	struct qtnf_wmac *mac = wiphy_priv(vif->wdev.wiphy);
1218 
1219 	if (vif->wdev.iftype == NL80211_IFTYPE_STATION)
1220 		qtnf_disconnect(vif->wdev.wiphy, ndev,
1221 				WLAN_REASON_DEAUTH_LEAVING);
1222 
1223 	qtnf_scan_done(mac, true);
1224 }
1225 
1226 void qtnf_cfg80211_vif_reset(struct qtnf_vif *vif)
1227 {
1228 	if (vif->wdev.iftype == NL80211_IFTYPE_STATION)
1229 		cfg80211_disconnected(vif->netdev, WLAN_REASON_DEAUTH_LEAVING,
1230 				      NULL, 0, 1, GFP_KERNEL);
1231 
1232 	cfg80211_shutdown_all_interfaces(vif->wdev.wiphy);
1233 }
1234 
1235 void qtnf_band_init_rates(struct ieee80211_supported_band *band)
1236 {
1237 	switch (band->band) {
1238 	case NL80211_BAND_2GHZ:
1239 		band->bitrates = qtnf_rates_2g;
1240 		band->n_bitrates = ARRAY_SIZE(qtnf_rates_2g);
1241 		break;
1242 	case NL80211_BAND_5GHZ:
1243 		band->bitrates = qtnf_rates_5g;
1244 		band->n_bitrates = ARRAY_SIZE(qtnf_rates_5g);
1245 		break;
1246 	default:
1247 		band->bitrates = NULL;
1248 		band->n_bitrates = 0;
1249 		break;
1250 	}
1251 }
1252