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