2 * Copyright (c) 2012-2012 Quantenna Communications, Inc.
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.
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.
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>
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, },
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, },
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
,
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),
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),
81 qtnf_change_virtual_intf(struct wiphy
*wiphy
,
82 struct net_device
*dev
,
83 enum nl80211_iftype type
,
84 struct vif_params
*params
)
86 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(dev
);
91 mac_addr
= params
->macaddr
;
95 qtnf_scan_done(vif
->mac
, true);
97 ret
= qtnf_cmd_send_change_intf_type(vif
, type
, mac_addr
);
99 pr_err("VIF%u.%u: failed to change VIF type: %d\n",
100 vif
->mac
->macid
, vif
->vifid
, ret
);
104 vif
->wdev
.iftype
= type
;
108 int qtnf_del_virtual_intf(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
110 struct net_device
*netdev
= wdev
->netdev
;
111 struct qtnf_vif
*vif
;
113 if (WARN_ON(!netdev
))
116 vif
= qtnf_netdev_get_priv(wdev
->netdev
);
118 qtnf_scan_done(vif
->mac
, true);
120 if (qtnf_cmd_send_del_intf(vif
))
121 pr_err("VIF%u.%u: failed to delete VIF\n", vif
->mac
->macid
,
125 netif_tx_stop_all_queues(netdev
);
126 if (netif_carrier_ok(netdev
))
127 netif_carrier_off(netdev
);
129 if (netdev
->reg_state
== NETREG_REGISTERED
)
130 unregister_netdevice(netdev
);
132 vif
->netdev
->ieee80211_ptr
= NULL
;
134 vif
->wdev
.iftype
= NL80211_IFTYPE_UNSPECIFIED
;
135 eth_zero_addr(vif
->mac_addr
);
140 static struct wireless_dev
*qtnf_add_virtual_intf(struct wiphy
*wiphy
,
142 unsigned char name_assign_t
,
143 enum nl80211_iftype type
,
144 struct vif_params
*params
)
146 struct qtnf_wmac
*mac
;
147 struct qtnf_vif
*vif
;
150 mac
= wiphy_priv(wiphy
);
153 return ERR_PTR(-EFAULT
);
156 case NL80211_IFTYPE_STATION
:
157 case NL80211_IFTYPE_AP
:
158 vif
= qtnf_mac_get_free_vif(mac
);
160 pr_err("MAC%u: no free VIF available\n", mac
->macid
);
161 return ERR_PTR(-EFAULT
);
164 eth_zero_addr(vif
->mac_addr
);
165 vif
->bss_priority
= QTNF_DEF_BSS_PRIORITY
;
166 vif
->wdev
.wiphy
= wiphy
;
167 vif
->wdev
.iftype
= type
;
168 vif
->sta_state
= QTNF_STA_DISCONNECTED
;
171 pr_err("MAC%u: unsupported IF type %d\n", mac
->macid
, type
);
172 return ERR_PTR(-ENOTSUPP
);
176 mac_addr
= params
->macaddr
;
178 if (qtnf_cmd_send_add_intf(vif
, type
, mac_addr
)) {
179 pr_err("VIF%u.%u: failed to add VIF\n", mac
->macid
, vif
->vifid
);
183 if (!is_valid_ether_addr(vif
->mac_addr
)) {
184 pr_err("VIF%u.%u: FW reported bad MAC: %pM\n",
185 mac
->macid
, vif
->vifid
, vif
->mac_addr
);
189 if (qtnf_core_net_attach(mac
, vif
, name
, name_assign_t
, type
)) {
190 pr_err("VIF%u.%u: failed to attach netdev\n", mac
->macid
,
195 vif
->wdev
.netdev
= vif
->netdev
;
201 qtnf_cmd_send_del_intf(vif
);
203 vif
->wdev
.iftype
= NL80211_IFTYPE_UNSPECIFIED
;
205 return ERR_PTR(-EFAULT
);
208 static int qtnf_mgmt_set_appie(struct qtnf_vif
*vif
,
209 const struct cfg80211_beacon_data
*info
)
213 if (!info
->beacon_ies
|| !info
->beacon_ies_len
) {
214 ret
= qtnf_cmd_send_mgmt_set_appie(vif
, QLINK_MGMT_FRAME_BEACON
,
217 ret
= qtnf_cmd_send_mgmt_set_appie(vif
, QLINK_MGMT_FRAME_BEACON
,
219 info
->beacon_ies_len
);
225 if (!info
->proberesp_ies
|| !info
->proberesp_ies_len
) {
226 ret
= qtnf_cmd_send_mgmt_set_appie(vif
,
227 QLINK_MGMT_FRAME_PROBE_RESP
,
230 ret
= qtnf_cmd_send_mgmt_set_appie(vif
,
231 QLINK_MGMT_FRAME_PROBE_RESP
,
233 info
->proberesp_ies_len
);
239 if (!info
->assocresp_ies
|| !info
->assocresp_ies_len
) {
240 ret
= qtnf_cmd_send_mgmt_set_appie(vif
,
241 QLINK_MGMT_FRAME_ASSOC_RESP
,
244 ret
= qtnf_cmd_send_mgmt_set_appie(vif
,
245 QLINK_MGMT_FRAME_ASSOC_RESP
,
247 info
->assocresp_ies_len
);
254 static int qtnf_change_beacon(struct wiphy
*wiphy
, struct net_device
*dev
,
255 struct cfg80211_beacon_data
*info
)
257 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(dev
);
259 if (!(vif
->bss_status
& QTNF_STATE_AP_START
)) {
260 pr_err("VIF%u.%u: not started\n", vif
->mac
->macid
, vif
->vifid
);
264 return qtnf_mgmt_set_appie(vif
, info
);
267 static int qtnf_start_ap(struct wiphy
*wiphy
, struct net_device
*dev
,
268 struct cfg80211_ap_settings
*settings
)
270 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(dev
);
271 struct qtnf_wmac
*mac
= wiphy_priv(wiphy
);
272 struct qtnf_bss_config
*bss_cfg
;
275 if (!cfg80211_chandef_identical(&mac
->chandef
, &settings
->chandef
)) {
276 memcpy(&mac
->chandef
, &settings
->chandef
, sizeof(mac
->chandef
));
278 pr_warn("%s: unexpected chan %u (%u MHz)\n", dev
->name
,
279 settings
->chandef
.chan
->hw_value
,
280 settings
->chandef
.chan
->center_freq
);
283 bss_cfg
= &vif
->bss_cfg
;
284 memset(bss_cfg
, 0, sizeof(*bss_cfg
));
286 bss_cfg
->bcn_period
= settings
->beacon_interval
;
287 bss_cfg
->dtim
= settings
->dtim_period
;
288 bss_cfg
->auth_type
= settings
->auth_type
;
289 bss_cfg
->privacy
= settings
->privacy
;
291 bss_cfg
->ssid_len
= settings
->ssid_len
;
292 memcpy(&bss_cfg
->ssid
, settings
->ssid
, bss_cfg
->ssid_len
);
294 memcpy(&bss_cfg
->crypto
, &settings
->crypto
,
295 sizeof(struct cfg80211_crypto_settings
));
297 ret
= qtnf_cmd_send_config_ap(vif
);
299 pr_err("VIF%u.%u: failed to push config to FW\n",
300 vif
->mac
->macid
, vif
->vifid
);
304 if (!(vif
->bss_status
& QTNF_STATE_AP_CONFIG
)) {
305 pr_err("VIF%u.%u: AP config failed in FW\n", vif
->mac
->macid
,
311 ret
= qtnf_mgmt_set_appie(vif
, &settings
->beacon
);
313 pr_err("VIF%u.%u: failed to add IEs to beacon\n",
314 vif
->mac
->macid
, vif
->vifid
);
318 ret
= qtnf_cmd_send_start_ap(vif
);
320 pr_err("VIF%u.%u: failed to start AP\n", vif
->mac
->macid
,
325 if (!(vif
->bss_status
& QTNF_STATE_AP_START
)) {
326 pr_err("VIF%u.%u: FW failed to start AP operation\n",
327 vif
->mac
->macid
, vif
->vifid
);
335 static int qtnf_stop_ap(struct wiphy
*wiphy
, struct net_device
*dev
)
337 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(dev
);
340 qtnf_scan_done(vif
->mac
, true);
342 ret
= qtnf_cmd_send_stop_ap(vif
);
344 pr_err("VIF%u.%u: failed to stop AP operation in FW\n",
345 vif
->mac
->macid
, vif
->vifid
);
346 vif
->bss_status
&= ~QTNF_STATE_AP_START
;
347 vif
->bss_status
&= ~QTNF_STATE_AP_CONFIG
;
349 netif_carrier_off(vif
->netdev
);
355 static int qtnf_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
357 struct qtnf_wmac
*mac
= wiphy_priv(wiphy
);
358 struct qtnf_vif
*vif
;
361 vif
= qtnf_mac_get_base_vif(mac
);
363 pr_err("MAC%u: primary VIF is not configured\n", mac
->macid
);
367 if (changed
& (WIPHY_PARAM_RETRY_LONG
| WIPHY_PARAM_RETRY_SHORT
)) {
368 pr_err("MAC%u: can't modify retry params\n", mac
->macid
);
372 ret
= qtnf_cmd_send_update_phy_params(mac
, changed
);
374 pr_err("MAC%u: failed to update PHY params\n", mac
->macid
);
380 qtnf_mgmt_frame_register(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
381 u16 frame_type
, bool reg
)
383 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(wdev
->netdev
);
386 u16 qlink_frame_type
= 0;
388 mgmt_type
= (frame_type
& IEEE80211_FCTL_STYPE
) >> 4;
391 new_mask
= vif
->mgmt_frames_bitmask
| BIT(mgmt_type
);
393 new_mask
= vif
->mgmt_frames_bitmask
& ~BIT(mgmt_type
);
395 if (new_mask
== vif
->mgmt_frames_bitmask
)
398 switch (frame_type
& IEEE80211_FCTL_STYPE
) {
399 case IEEE80211_STYPE_PROBE_REQ
:
400 qlink_frame_type
= QLINK_MGMT_FRAME_PROBE_REQ
;
402 case IEEE80211_STYPE_ACTION
:
403 qlink_frame_type
= QLINK_MGMT_FRAME_ACTION
;
406 pr_warn("VIF%u.%u: unsupported frame type: %X\n",
407 vif
->mac
->macid
, vif
->vifid
,
408 (frame_type
& IEEE80211_FCTL_STYPE
) >> 4);
412 if (qtnf_cmd_send_register_mgmt(vif
, qlink_frame_type
, reg
)) {
413 pr_warn("VIF%u.%u: failed to %sregister mgmt frame type 0x%x\n",
414 vif
->mac
->macid
, vif
->vifid
, reg
? "" : "un",
419 vif
->mgmt_frames_bitmask
= new_mask
;
420 pr_debug("VIF%u.%u: %sregistered mgmt frame type 0x%x\n",
421 vif
->mac
->macid
, vif
->vifid
, reg
? "" : "un", frame_type
);
425 qtnf_mgmt_tx(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
426 struct cfg80211_mgmt_tx_params
*params
, u64
*cookie
)
428 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(wdev
->netdev
);
429 const struct ieee80211_mgmt
*mgmt_frame
= (void *)params
->buf
;
430 u32 short_cookie
= prandom_u32();
433 *cookie
= short_cookie
;
436 flags
|= QLINK_MGMT_FRAME_TX_FLAG_OFFCHAN
;
439 flags
|= QLINK_MGMT_FRAME_TX_FLAG_NO_CCK
;
441 if (params
->dont_wait_for_ack
)
442 flags
|= QLINK_MGMT_FRAME_TX_FLAG_ACK_NOWAIT
;
444 pr_debug("%s freq:%u; FC:%.4X; DA:%pM; len:%zu; C:%.8X; FL:%.4X\n",
445 wdev
->netdev
->name
, params
->chan
->center_freq
,
446 le16_to_cpu(mgmt_frame
->frame_control
), mgmt_frame
->da
,
447 params
->len
, short_cookie
, flags
);
449 return qtnf_cmd_send_mgmt_frame(vif
, short_cookie
, flags
,
450 params
->chan
->center_freq
,
451 params
->buf
, params
->len
);
455 qtnf_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
456 const u8
*mac
, struct station_info
*sinfo
)
458 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(dev
);
460 return qtnf_cmd_get_sta_info(vif
, mac
, sinfo
);
464 qtnf_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
465 int idx
, u8
*mac
, struct station_info
*sinfo
)
467 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(dev
);
468 const struct qtnf_sta_node
*sta_node
;
471 sta_node
= qtnf_sta_list_lookup_index(&vif
->sta_list
, idx
);
473 if (unlikely(!sta_node
))
476 ether_addr_copy(mac
, sta_node
->mac_addr
);
478 ret
= qtnf_cmd_get_sta_info(vif
, sta_node
->mac_addr
, sinfo
);
480 if (unlikely(ret
== -ENOENT
)) {
481 qtnf_sta_list_del(&vif
->sta_list
, mac
);
482 cfg80211_del_sta(vif
->netdev
, mac
, GFP_KERNEL
);
489 static int qtnf_add_key(struct wiphy
*wiphy
, struct net_device
*dev
,
490 u8 key_index
, bool pairwise
, const u8
*mac_addr
,
491 struct key_params
*params
)
493 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(dev
);
496 ret
= qtnf_cmd_send_add_key(vif
, key_index
, pairwise
, mac_addr
, params
);
498 pr_err("VIF%u.%u: failed to add key: cipher=%x idx=%u pw=%u\n",
499 vif
->mac
->macid
, vif
->vifid
, params
->cipher
, key_index
,
505 static int qtnf_del_key(struct wiphy
*wiphy
, struct net_device
*dev
,
506 u8 key_index
, bool pairwise
, const u8
*mac_addr
)
508 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(dev
);
511 ret
= qtnf_cmd_send_del_key(vif
, key_index
, pairwise
, mac_addr
);
513 pr_err("VIF%u.%u: failed to delete key: idx=%u pw=%u\n",
514 vif
->mac
->macid
, vif
->vifid
, key_index
, pairwise
);
519 static int qtnf_set_default_key(struct wiphy
*wiphy
, struct net_device
*dev
,
520 u8 key_index
, bool unicast
, bool multicast
)
522 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(dev
);
525 ret
= qtnf_cmd_send_set_default_key(vif
, key_index
, unicast
, multicast
);
527 pr_err("VIF%u.%u: failed to set dflt key: idx=%u uc=%u mc=%u\n",
528 vif
->mac
->macid
, vif
->vifid
, key_index
, unicast
,
535 qtnf_set_default_mgmt_key(struct wiphy
*wiphy
, struct net_device
*dev
,
538 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(dev
);
541 ret
= qtnf_cmd_send_set_default_mgmt_key(vif
, key_index
);
543 pr_err("VIF%u.%u: failed to set default MGMT key: idx=%u\n",
544 vif
->mac
->macid
, vif
->vifid
, key_index
);
550 qtnf_change_station(struct wiphy
*wiphy
, struct net_device
*dev
,
551 const u8
*mac
, struct station_parameters
*params
)
553 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(dev
);
556 ret
= qtnf_cmd_send_change_sta(vif
, mac
, params
);
558 pr_err("VIF%u.%u: failed to change STA %pM\n",
559 vif
->mac
->macid
, vif
->vifid
, mac
);
565 qtnf_del_station(struct wiphy
*wiphy
, struct net_device
*dev
,
566 struct station_del_parameters
*params
)
568 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(dev
);
572 (vif
->wdev
.iftype
== NL80211_IFTYPE_AP
) &&
573 !is_broadcast_ether_addr(params
->mac
) &&
574 !qtnf_sta_list_lookup(&vif
->sta_list
, params
->mac
))
577 ret
= qtnf_cmd_send_del_sta(vif
, params
);
579 pr_err("VIF%u.%u: failed to delete STA %pM\n",
580 vif
->mac
->macid
, vif
->vifid
, params
->mac
);
584 static void qtnf_scan_timeout(unsigned long data
)
586 struct qtnf_wmac
*mac
= (struct qtnf_wmac
*)data
;
588 pr_warn("mac%d scan timed out\n", mac
->macid
);
589 qtnf_scan_done(mac
, true);
593 qtnf_scan(struct wiphy
*wiphy
, struct cfg80211_scan_request
*request
)
595 struct qtnf_wmac
*mac
= wiphy_priv(wiphy
);
597 mac
->scan_req
= request
;
599 if (qtnf_cmd_send_scan(mac
)) {
600 pr_err("MAC%u: failed to start scan\n", mac
->macid
);
601 mac
->scan_req
= NULL
;
605 mac
->scan_timeout
.data
= (unsigned long)mac
;
606 mac
->scan_timeout
.function
= qtnf_scan_timeout
;
607 mod_timer(&mac
->scan_timeout
,
608 jiffies
+ QTNF_SCAN_TIMEOUT_SEC
* HZ
);
614 qtnf_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
615 struct cfg80211_connect_params
*sme
)
617 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(dev
);
618 struct qtnf_wmac
*mac
= wiphy_priv(wiphy
);
619 struct cfg80211_chan_def chandef
;
620 struct qtnf_bss_config
*bss_cfg
;
623 if (vif
->wdev
.iftype
!= NL80211_IFTYPE_STATION
)
626 if (vif
->sta_state
!= QTNF_STA_DISCONNECTED
)
629 bss_cfg
= &vif
->bss_cfg
;
630 memset(bss_cfg
, 0, sizeof(*bss_cfg
));
633 /* FIXME: need to set proper nl80211_channel_type value */
634 cfg80211_chandef_create(&chandef
, sme
->channel
,
636 /* fall-back to minimal safe chandef description */
637 if (!cfg80211_chandef_valid(&chandef
))
638 cfg80211_chandef_create(&chandef
, sme
->channel
,
641 memcpy(&mac
->chandef
, &chandef
, sizeof(mac
->chandef
));
644 bss_cfg
->ssid_len
= sme
->ssid_len
;
645 memcpy(&bss_cfg
->ssid
, sme
->ssid
, bss_cfg
->ssid_len
);
646 bss_cfg
->auth_type
= sme
->auth_type
;
647 bss_cfg
->privacy
= sme
->privacy
;
648 bss_cfg
->mfp
= sme
->mfp
;
650 if ((sme
->bg_scan_period
> 0) &&
651 (sme
->bg_scan_period
<= QTNF_MAX_BG_SCAN_PERIOD
))
652 bss_cfg
->bg_scan_period
= sme
->bg_scan_period
;
653 else if (sme
->bg_scan_period
== -1)
654 bss_cfg
->bg_scan_period
= QTNF_DEFAULT_BG_SCAN_PERIOD
;
656 bss_cfg
->bg_scan_period
= 0; /* disabled */
658 bss_cfg
->connect_flags
= 0;
660 if (sme
->flags
& ASSOC_REQ_DISABLE_HT
)
661 bss_cfg
->connect_flags
|= QLINK_STA_CONNECT_DISABLE_HT
;
662 if (sme
->flags
& ASSOC_REQ_DISABLE_VHT
)
663 bss_cfg
->connect_flags
|= QLINK_STA_CONNECT_DISABLE_VHT
;
664 if (sme
->flags
& ASSOC_REQ_USE_RRM
)
665 bss_cfg
->connect_flags
|= QLINK_STA_CONNECT_USE_RRM
;
667 memcpy(&bss_cfg
->crypto
, &sme
->crypto
, sizeof(bss_cfg
->crypto
));
669 ether_addr_copy(bss_cfg
->bssid
, sme
->bssid
);
671 eth_zero_addr(bss_cfg
->bssid
);
673 ret
= qtnf_cmd_send_connect(vif
, sme
);
675 pr_err("VIF%u.%u: failed to connect\n", vif
->mac
->macid
,
680 vif
->sta_state
= QTNF_STA_CONNECTING
;
685 qtnf_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
688 struct qtnf_wmac
*mac
= wiphy_priv(wiphy
);
689 struct qtnf_vif
*vif
;
692 vif
= qtnf_mac_get_base_vif(mac
);
694 pr_err("MAC%u: primary VIF is not configured\n", mac
->macid
);
698 if (vif
->wdev
.iftype
!= NL80211_IFTYPE_STATION
)
701 if (vif
->sta_state
== QTNF_STA_DISCONNECTED
)
704 ret
= qtnf_cmd_send_disconnect(vif
, reason_code
);
706 pr_err("VIF%u.%u: failed to disconnect\n", mac
->macid
,
711 vif
->sta_state
= QTNF_STA_DISCONNECTED
;
716 qtnf_dump_survey(struct wiphy
*wiphy
, struct net_device
*dev
,
717 int idx
, struct survey_info
*survey
)
719 struct qtnf_wmac
*mac
= wiphy_priv(wiphy
);
720 struct ieee80211_supported_band
*sband
;
721 struct cfg80211_chan_def
*chandef
;
722 struct ieee80211_channel
*chan
;
723 struct qtnf_chan_stats stats
;
724 struct qtnf_vif
*vif
;
727 vif
= qtnf_netdev_get_priv(dev
);
728 chandef
= &mac
->chandef
;
730 sband
= wiphy
->bands
[NL80211_BAND_2GHZ
];
731 if (sband
&& idx
>= sband
->n_channels
) {
732 idx
-= sband
->n_channels
;
737 sband
= wiphy
->bands
[NL80211_BAND_5GHZ
];
739 if (!sband
|| idx
>= sband
->n_channels
)
742 chan
= &sband
->channels
[idx
];
743 memset(&stats
, 0, sizeof(stats
));
745 survey
->channel
= chan
;
746 survey
->filled
= 0x0;
749 if (chan
->hw_value
== chandef
->chan
->hw_value
)
750 survey
->filled
= SURVEY_INFO_IN_USE
;
753 ret
= qtnf_cmd_get_chan_stats(mac
, chan
->hw_value
, &stats
);
756 if (unlikely(stats
.chan_num
!= chan
->hw_value
)) {
757 pr_err("received stats for channel %d instead of %d\n",
758 stats
.chan_num
, chan
->hw_value
);
763 survey
->filled
|= SURVEY_INFO_TIME
|
764 SURVEY_INFO_TIME_SCAN
|
765 SURVEY_INFO_TIME_BUSY
|
766 SURVEY_INFO_TIME_RX
|
767 SURVEY_INFO_TIME_TX
|
768 SURVEY_INFO_NOISE_DBM
;
770 survey
->time_scan
= stats
.cca_try
;
771 survey
->time
= stats
.cca_try
;
772 survey
->time_tx
= stats
.cca_tx
;
773 survey
->time_rx
= stats
.cca_rx
;
774 survey
->time_busy
= stats
.cca_busy
;
775 survey
->noise
= stats
.chan_noise
;
778 pr_debug("no stats for channel %u\n", chan
->hw_value
);
782 pr_debug("failed to get chan(%d) stats from card\n",
792 qtnf_get_channel(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
793 struct cfg80211_chan_def
*chandef
)
795 struct qtnf_wmac
*mac
= wiphy_priv(wiphy
);
796 struct net_device
*ndev
= wdev
->netdev
;
797 struct qtnf_vif
*vif
;
802 vif
= qtnf_netdev_get_priv(wdev
->netdev
);
804 switch (vif
->wdev
.iftype
) {
805 case NL80211_IFTYPE_STATION
:
806 if (vif
->sta_state
== QTNF_STA_DISCONNECTED
) {
807 pr_warn("%s: STA disconnected\n", ndev
->name
);
811 case NL80211_IFTYPE_AP
:
812 if (!(vif
->bss_status
& QTNF_STATE_AP_START
)) {
813 pr_warn("%s: AP not started\n", ndev
->name
);
818 pr_err("unsupported vif type (%d)\n", vif
->wdev
.iftype
);
822 if (!cfg80211_chandef_valid(&mac
->chandef
)) {
823 pr_err("invalid channel settings on %s\n", ndev
->name
);
827 memcpy(chandef
, &mac
->chandef
, sizeof(*chandef
));
831 static int qtnf_channel_switch(struct wiphy
*wiphy
, struct net_device
*dev
,
832 struct cfg80211_csa_settings
*params
)
834 struct qtnf_wmac
*mac
= wiphy_priv(wiphy
);
835 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(dev
);
838 pr_debug("%s: chan(%u) count(%u) radar(%u) block_tx(%u)\n", dev
->name
,
839 params
->chandef
.chan
->hw_value
, params
->count
,
840 params
->radar_required
, params
->block_tx
);
842 switch (vif
->wdev
.iftype
) {
843 case NL80211_IFTYPE_AP
:
844 if (!(vif
->bss_status
& QTNF_STATE_AP_START
)) {
845 pr_warn("AP not started on %s\n", dev
->name
);
850 pr_err("unsupported vif type (%d) on %s\n",
851 vif
->wdev
.iftype
, dev
->name
);
855 if (vif
->vifid
!= 0) {
856 if (!(mac
->status
& QTNF_MAC_CSA_ACTIVE
))
859 if (!cfg80211_chandef_identical(¶ms
->chandef
,
866 if (!cfg80211_chandef_valid(¶ms
->chandef
)) {
867 pr_err("%s: invalid channel\n", dev
->name
);
871 if (cfg80211_chandef_identical(¶ms
->chandef
, &mac
->chandef
)) {
872 pr_err("%s: switch request to the same channel\n", dev
->name
);
876 ret
= qtnf_cmd_send_chan_switch(mac
, params
);
878 pr_warn("%s: failed to switch to channel (%u)\n",
879 dev
->name
, params
->chandef
.chan
->hw_value
);
884 static struct cfg80211_ops qtn_cfg80211_ops
= {
885 .add_virtual_intf
= qtnf_add_virtual_intf
,
886 .change_virtual_intf
= qtnf_change_virtual_intf
,
887 .del_virtual_intf
= qtnf_del_virtual_intf
,
888 .start_ap
= qtnf_start_ap
,
889 .change_beacon
= qtnf_change_beacon
,
890 .stop_ap
= qtnf_stop_ap
,
891 .set_wiphy_params
= qtnf_set_wiphy_params
,
892 .mgmt_frame_register
= qtnf_mgmt_frame_register
,
893 .mgmt_tx
= qtnf_mgmt_tx
,
894 .change_station
= qtnf_change_station
,
895 .del_station
= qtnf_del_station
,
896 .get_station
= qtnf_get_station
,
897 .dump_station
= qtnf_dump_station
,
898 .add_key
= qtnf_add_key
,
899 .del_key
= qtnf_del_key
,
900 .set_default_key
= qtnf_set_default_key
,
901 .set_default_mgmt_key
= qtnf_set_default_mgmt_key
,
903 .connect
= qtnf_connect
,
904 .disconnect
= qtnf_disconnect
,
905 .dump_survey
= qtnf_dump_survey
,
906 .get_channel
= qtnf_get_channel
,
907 .channel_switch
= qtnf_channel_switch
910 static void qtnf_cfg80211_reg_notifier(struct wiphy
*wiphy_in
,
911 struct regulatory_request
*req
)
913 struct qtnf_wmac
*mac
= wiphy_priv(wiphy_in
);
914 struct qtnf_bus
*bus
= mac
->bus
;
916 unsigned int mac_idx
;
917 enum nl80211_band band
;
920 pr_debug("MAC%u: initiator=%d alpha=%c%c\n", mac
->macid
, req
->initiator
,
921 req
->alpha2
[0], req
->alpha2
[1]);
923 ret
= qtnf_cmd_reg_notify(bus
, req
);
925 if (ret
!= -EOPNOTSUPP
&& ret
!= -EALREADY
)
926 pr_err("failed to update reg domain to %c%c\n",
927 req
->alpha2
[0], req
->alpha2
[1]);
931 for (mac_idx
= 0; mac_idx
< QTNF_MAX_MAC
; ++mac_idx
) {
932 if (!(bus
->hw_info
.mac_bitmap
& (1 << mac_idx
)))
935 mac
= bus
->mac
[mac_idx
];
936 wiphy
= priv_to_wiphy(mac
);
938 for (band
= 0; band
< NUM_NL80211_BANDS
; ++band
) {
939 if (!wiphy
->bands
[band
])
942 ret
= qtnf_cmd_get_mac_chan_info(mac
,
945 pr_err("failed to get chan info for mac %u band %u\n",
951 void qtnf_band_setup_htvht_caps(struct qtnf_mac_info
*macinfo
,
952 struct ieee80211_supported_band
*band
)
954 struct ieee80211_sta_ht_cap
*ht_cap
;
955 struct ieee80211_sta_vht_cap
*vht_cap
;
957 ht_cap
= &band
->ht_cap
;
958 ht_cap
->ht_supported
= true;
959 memcpy(&ht_cap
->cap
, &macinfo
->ht_cap
.cap_info
,
961 ht_cap
->ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
962 ht_cap
->ampdu_density
= IEEE80211_HT_MPDU_DENSITY_NONE
;
963 memcpy(&ht_cap
->mcs
, &macinfo
->ht_cap
.mcs
,
964 sizeof(ht_cap
->mcs
));
966 if (macinfo
->phymode_cap
& QLINK_PHYMODE_AC
) {
967 vht_cap
= &band
->vht_cap
;
968 vht_cap
->vht_supported
= true;
969 memcpy(&vht_cap
->cap
,
970 &macinfo
->vht_cap
.vht_cap_info
, sizeof(u32
));
971 /* Update MCS support for VHT */
972 memcpy(&vht_cap
->vht_mcs
,
973 &macinfo
->vht_cap
.supp_mcs
,
974 sizeof(struct ieee80211_vht_mcs_info
));
978 struct wiphy
*qtnf_wiphy_allocate(struct qtnf_bus
*bus
)
982 wiphy
= wiphy_new(&qtn_cfg80211_ops
, sizeof(struct qtnf_wmac
));
986 set_wiphy_dev(wiphy
, bus
->dev
);
991 static int qtnf_wiphy_setup_if_comb(struct wiphy
*wiphy
,
992 struct ieee80211_iface_combination
*if_comb
,
993 const struct qtnf_mac_info
*mac_info
)
995 size_t max_interfaces
= 0;
996 u16 interface_modes
= 0;
999 if (unlikely(!mac_info
->limits
|| !mac_info
->n_limits
))
1002 if_comb
->limits
= mac_info
->limits
;
1003 if_comb
->n_limits
= mac_info
->n_limits
;
1005 for (i
= 0; i
< mac_info
->n_limits
; i
++) {
1006 max_interfaces
+= mac_info
->limits
[i
].max
;
1007 interface_modes
|= mac_info
->limits
[i
].types
;
1010 if_comb
->num_different_channels
= 1;
1011 if_comb
->beacon_int_infra_match
= true;
1012 if_comb
->max_interfaces
= max_interfaces
;
1013 if_comb
->radar_detect_widths
= mac_info
->radar_detect_widths
;
1014 wiphy
->interface_modes
= interface_modes
;
1019 int qtnf_wiphy_register(struct qtnf_hw_info
*hw_info
, struct qtnf_wmac
*mac
)
1021 struct wiphy
*wiphy
= priv_to_wiphy(mac
);
1022 struct ieee80211_iface_combination
*iface_comb
= NULL
;
1026 pr_err("invalid wiphy pointer\n");
1030 iface_comb
= kzalloc(sizeof(*iface_comb
), GFP_KERNEL
);
1034 ret
= qtnf_wiphy_setup_if_comb(wiphy
, iface_comb
, &mac
->macinfo
);
1038 pr_info("MAC%u: phymode=%#x radar=%#x\n", mac
->macid
,
1039 mac
->macinfo
.phymode_cap
, mac
->macinfo
.radar_detect_widths
);
1041 wiphy
->frag_threshold
= mac
->macinfo
.frag_thr
;
1042 wiphy
->rts_threshold
= mac
->macinfo
.rts_thr
;
1043 wiphy
->retry_short
= mac
->macinfo
.sretry_limit
;
1044 wiphy
->retry_long
= mac
->macinfo
.lretry_limit
;
1045 wiphy
->coverage_class
= mac
->macinfo
.coverage_class
;
1047 wiphy
->max_scan_ssids
= QTNF_MAX_SSID_LIST_LENGTH
;
1048 wiphy
->max_scan_ie_len
= QTNF_MAX_VSIE_LEN
;
1049 wiphy
->mgmt_stypes
= qtnf_mgmt_stypes
;
1050 wiphy
->max_remain_on_channel_duration
= 5000;
1052 wiphy
->iface_combinations
= iface_comb
;
1053 wiphy
->n_iface_combinations
= 1;
1054 wiphy
->max_num_csa_counters
= 2;
1056 /* Initialize cipher suits */
1057 wiphy
->cipher_suites
= qtnf_cipher_suites
;
1058 wiphy
->n_cipher_suites
= ARRAY_SIZE(qtnf_cipher_suites
);
1059 wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_MBM
;
1060 wiphy
->flags
|= WIPHY_FLAG_HAVE_AP_SME
|
1061 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
|
1062 WIPHY_FLAG_AP_UAPSD
|
1063 WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
1065 wiphy
->probe_resp_offload
= NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
1066 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
;
1068 wiphy
->available_antennas_tx
= mac
->macinfo
.num_tx_chain
;
1069 wiphy
->available_antennas_rx
= mac
->macinfo
.num_rx_chain
;
1071 wiphy
->max_ap_assoc_sta
= mac
->macinfo
.max_ap_assoc_sta
;
1073 ether_addr_copy(wiphy
->perm_addr
, mac
->macaddr
);
1075 if (hw_info
->hw_capab
& QLINK_HW_SUPPORTS_REG_UPDATE
) {
1076 wiphy
->regulatory_flags
|= REGULATORY_STRICT_REG
|
1077 REGULATORY_CUSTOM_REG
;
1078 wiphy
->reg_notifier
= qtnf_cfg80211_reg_notifier
;
1079 wiphy_apply_custom_regulatory(wiphy
, hw_info
->rd
);
1081 wiphy
->regulatory_flags
|= REGULATORY_WIPHY_SELF_MANAGED
;
1084 ret
= wiphy_register(wiphy
);
1088 if (wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
)
1089 ret
= regulatory_set_wiphy_regd(wiphy
, hw_info
->rd
);
1090 else if (isalpha(hw_info
->rd
->alpha2
[0]) &&
1091 isalpha(hw_info
->rd
->alpha2
[1]))
1092 ret
= regulatory_hint(wiphy
, hw_info
->rd
->alpha2
);
1103 void qtnf_netdev_updown(struct net_device
*ndev
, bool up
)
1105 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(ndev
);
1107 if (qtnf_cmd_send_updown_intf(vif
, up
))
1108 pr_err("failed to send up/down command to FW\n");
1111 void qtnf_virtual_intf_cleanup(struct net_device
*ndev
)
1113 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(ndev
);
1114 struct qtnf_wmac
*mac
= wiphy_priv(vif
->wdev
.wiphy
);
1116 if (vif
->wdev
.iftype
== NL80211_IFTYPE_STATION
) {
1117 switch (vif
->sta_state
) {
1118 case QTNF_STA_DISCONNECTED
:
1120 case QTNF_STA_CONNECTING
:
1121 cfg80211_connect_result(vif
->netdev
,
1122 vif
->bss_cfg
.bssid
, NULL
, 0,
1124 WLAN_STATUS_UNSPECIFIED_FAILURE
,
1126 qtnf_disconnect(vif
->wdev
.wiphy
, ndev
,
1127 WLAN_REASON_DEAUTH_LEAVING
);
1129 case QTNF_STA_CONNECTED
:
1130 cfg80211_disconnected(vif
->netdev
,
1131 WLAN_REASON_DEAUTH_LEAVING
,
1132 NULL
, 0, 1, GFP_KERNEL
);
1133 qtnf_disconnect(vif
->wdev
.wiphy
, ndev
,
1134 WLAN_REASON_DEAUTH_LEAVING
);
1138 vif
->sta_state
= QTNF_STA_DISCONNECTED
;
1141 qtnf_scan_done(mac
, true);
1144 void qtnf_cfg80211_vif_reset(struct qtnf_vif
*vif
)
1146 if (vif
->wdev
.iftype
== NL80211_IFTYPE_STATION
) {
1147 switch (vif
->sta_state
) {
1148 case QTNF_STA_CONNECTING
:
1149 cfg80211_connect_result(vif
->netdev
,
1150 vif
->bss_cfg
.bssid
, NULL
, 0,
1152 WLAN_STATUS_UNSPECIFIED_FAILURE
,
1155 case QTNF_STA_CONNECTED
:
1156 cfg80211_disconnected(vif
->netdev
,
1157 WLAN_REASON_DEAUTH_LEAVING
,
1158 NULL
, 0, 1, GFP_KERNEL
);
1160 case QTNF_STA_DISCONNECTED
:
1165 cfg80211_shutdown_all_interfaces(vif
->wdev
.wiphy
);
1166 vif
->sta_state
= QTNF_STA_DISCONNECTED
;
1169 void qtnf_band_init_rates(struct ieee80211_supported_band
*band
)
1171 switch (band
->band
) {
1172 case NL80211_BAND_2GHZ
:
1173 band
->bitrates
= qtnf_rates_2g
;
1174 band
->n_bitrates
= ARRAY_SIZE(qtnf_rates_2g
);
1176 case NL80211_BAND_5GHZ
:
1177 band
->bitrates
= qtnf_rates_5g
;
1178 band
->n_bitrates
= ARRAY_SIZE(qtnf_rates_5g
);
1181 band
->bitrates
= NULL
;
1182 band
->n_bitrates
= 0;