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