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