2 * Copyright (c) 2012-2016 Qualcomm Atheros, Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/etherdevice.h>
21 #define CHAN60G(_channel, _flags) { \
22 .band = IEEE80211_BAND_60GHZ, \
23 .center_freq = 56160 + (2160 * (_channel)), \
24 .hw_value = (_channel), \
26 .max_antenna_gain = 0, \
30 static struct ieee80211_channel wil_60ghz_channels
[] = {
34 /* channel 4 not supported yet */
37 static struct ieee80211_supported_band wil_band_60ghz
= {
38 .channels
= wil_60ghz_channels
,
39 .n_channels
= ARRAY_SIZE(wil_60ghz_channels
),
43 .ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
, /* TODO */
44 .ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
, /* TODO */
46 /* MCS 1..12 - SC PHY */
47 .rx_mask
= {0xfe, 0x1f}, /* 1..12 */
48 .tx_params
= IEEE80211_HT_MCS_TX_DEFINED
, /* TODO */
53 static const struct ieee80211_txrx_stypes
54 wil_mgmt_stypes
[NUM_NL80211_IFTYPES
] = {
55 [NL80211_IFTYPE_STATION
] = {
56 .tx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
57 BIT(IEEE80211_STYPE_PROBE_RESP
>> 4),
58 .rx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
59 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4)
61 [NL80211_IFTYPE_AP
] = {
62 .tx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
63 BIT(IEEE80211_STYPE_PROBE_RESP
>> 4),
64 .rx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
65 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4)
67 [NL80211_IFTYPE_P2P_CLIENT
] = {
68 .tx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
69 BIT(IEEE80211_STYPE_PROBE_RESP
>> 4),
70 .rx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
71 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4)
73 [NL80211_IFTYPE_P2P_GO
] = {
74 .tx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
75 BIT(IEEE80211_STYPE_PROBE_RESP
>> 4),
76 .rx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
77 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4)
81 static const u32 wil_cipher_suites
[] = {
82 WLAN_CIPHER_SUITE_GCMP
,
85 int wil_iftype_nl2wmi(enum nl80211_iftype type
)
88 enum nl80211_iftype nl
;
89 enum wmi_network_type wmi
;
91 {NL80211_IFTYPE_ADHOC
, WMI_NETTYPE_ADHOC
},
92 {NL80211_IFTYPE_STATION
, WMI_NETTYPE_INFRA
},
93 {NL80211_IFTYPE_AP
, WMI_NETTYPE_AP
},
94 {NL80211_IFTYPE_P2P_CLIENT
, WMI_NETTYPE_P2P
},
95 {NL80211_IFTYPE_P2P_GO
, WMI_NETTYPE_P2P
},
96 {NL80211_IFTYPE_MONITOR
, WMI_NETTYPE_ADHOC
}, /* FIXME */
100 for (i
= 0; i
< ARRAY_SIZE(__nl2wmi
); i
++) {
101 if (__nl2wmi
[i
].nl
== type
)
102 return __nl2wmi
[i
].wmi
;
108 int wil_cid_fill_sinfo(struct wil6210_priv
*wil
, int cid
,
109 struct station_info
*sinfo
)
111 struct wmi_notify_req_cmd cmd
= {
116 struct wil6210_mbox_hdr_wmi wmi
;
117 struct wmi_notify_req_done_event evt
;
119 struct wil_net_stats
*stats
= &wil
->sta
[cid
].stats
;
122 rc
= wmi_call(wil
, WMI_NOTIFY_REQ_CMDID
, &cmd
, sizeof(cmd
),
123 WMI_NOTIFY_REQ_DONE_EVENTID
, &reply
, sizeof(reply
), 20);
127 wil_dbg_wmi(wil
, "Link status for CID %d: {\n"
128 " MCS %d TSF 0x%016llx\n"
129 " BF status 0x%08x SNR 0x%08x SQI %d%%\n"
130 " Tx Tpt %d goodput %d Rx goodput %d\n"
131 " Sectors(rx:tx) my %d:%d peer %d:%d\n""}\n",
132 cid
, le16_to_cpu(reply
.evt
.bf_mcs
),
133 le64_to_cpu(reply
.evt
.tsf
), reply
.evt
.status
,
134 le32_to_cpu(reply
.evt
.snr_val
),
136 le32_to_cpu(reply
.evt
.tx_tpt
),
137 le32_to_cpu(reply
.evt
.tx_goodput
),
138 le32_to_cpu(reply
.evt
.rx_goodput
),
139 le16_to_cpu(reply
.evt
.my_rx_sector
),
140 le16_to_cpu(reply
.evt
.my_tx_sector
),
141 le16_to_cpu(reply
.evt
.other_rx_sector
),
142 le16_to_cpu(reply
.evt
.other_tx_sector
));
144 sinfo
->generation
= wil
->sinfo_gen
;
146 sinfo
->filled
= BIT(NL80211_STA_INFO_RX_BYTES
) |
147 BIT(NL80211_STA_INFO_TX_BYTES
) |
148 BIT(NL80211_STA_INFO_RX_PACKETS
) |
149 BIT(NL80211_STA_INFO_TX_PACKETS
) |
150 BIT(NL80211_STA_INFO_RX_BITRATE
) |
151 BIT(NL80211_STA_INFO_TX_BITRATE
) |
152 BIT(NL80211_STA_INFO_RX_DROP_MISC
) |
153 BIT(NL80211_STA_INFO_TX_FAILED
);
155 sinfo
->txrate
.flags
= RATE_INFO_FLAGS_MCS
| RATE_INFO_FLAGS_60G
;
156 sinfo
->txrate
.mcs
= le16_to_cpu(reply
.evt
.bf_mcs
);
157 sinfo
->rxrate
.flags
= RATE_INFO_FLAGS_MCS
| RATE_INFO_FLAGS_60G
;
158 sinfo
->rxrate
.mcs
= stats
->last_mcs_rx
;
159 sinfo
->rx_bytes
= stats
->rx_bytes
;
160 sinfo
->rx_packets
= stats
->rx_packets
;
161 sinfo
->rx_dropped_misc
= stats
->rx_dropped
;
162 sinfo
->tx_bytes
= stats
->tx_bytes
;
163 sinfo
->tx_packets
= stats
->tx_packets
;
164 sinfo
->tx_failed
= stats
->tx_errors
;
166 if (test_bit(wil_status_fwconnected
, wil
->status
)) {
167 sinfo
->filled
|= BIT(NL80211_STA_INFO_SIGNAL
);
168 sinfo
->signal
= reply
.evt
.sqi
;
174 static int wil_cfg80211_get_station(struct wiphy
*wiphy
,
175 struct net_device
*ndev
,
176 const u8
*mac
, struct station_info
*sinfo
)
178 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
181 int cid
= wil_find_cid(wil
, mac
);
183 wil_dbg_misc(wil
, "%s(%pM) CID %d\n", __func__
, mac
, cid
);
187 rc
= wil_cid_fill_sinfo(wil
, cid
, sinfo
);
193 * Find @idx-th active STA for station dump.
195 static int wil_find_cid_by_idx(struct wil6210_priv
*wil
, int idx
)
199 for (i
= 0; i
< ARRAY_SIZE(wil
->sta
); i
++) {
200 if (wil
->sta
[i
].status
== wil_sta_unused
)
210 static int wil_cfg80211_dump_station(struct wiphy
*wiphy
,
211 struct net_device
*dev
, int idx
,
212 u8
*mac
, struct station_info
*sinfo
)
214 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
216 int cid
= wil_find_cid_by_idx(wil
, idx
);
221 ether_addr_copy(mac
, wil
->sta
[cid
].addr
);
222 wil_dbg_misc(wil
, "%s(%pM) CID %d\n", __func__
, mac
, cid
);
224 rc
= wil_cid_fill_sinfo(wil
, cid
, sinfo
);
229 static int wil_cfg80211_change_iface(struct wiphy
*wiphy
,
230 struct net_device
*ndev
,
231 enum nl80211_iftype type
, u32
*flags
,
232 struct vif_params
*params
)
234 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
235 struct wireless_dev
*wdev
= wil
->wdev
;
238 case NL80211_IFTYPE_STATION
:
239 case NL80211_IFTYPE_AP
:
240 case NL80211_IFTYPE_P2P_CLIENT
:
241 case NL80211_IFTYPE_P2P_GO
:
243 case NL80211_IFTYPE_MONITOR
:
245 wil
->monitor_flags
= *flags
;
247 wil
->monitor_flags
= 0;
259 static int wil_cfg80211_scan(struct wiphy
*wiphy
,
260 struct cfg80211_scan_request
*request
)
262 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
263 struct wireless_dev
*wdev
= wil
->wdev
;
265 struct wmi_start_scan_cmd cmd
;
271 if (wil
->scan_request
) {
272 wil_err(wil
, "Already scanning\n");
276 /* check we are client side */
277 switch (wdev
->iftype
) {
278 case NL80211_IFTYPE_STATION
:
279 case NL80211_IFTYPE_P2P_CLIENT
:
285 /* FW don't support scan after connection attempt */
286 if (test_bit(wil_status_dontscan
, wil
->status
)) {
287 wil_err(wil
, "Can't scan now\n");
291 wil_dbg_misc(wil
, "Start scan_request 0x%p\n", request
);
292 wil_dbg_misc(wil
, "SSID count: %d", request
->n_ssids
);
294 for (i
= 0; i
< request
->n_ssids
; i
++) {
295 wil_dbg_misc(wil
, "SSID[%d]", i
);
296 print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET
,
297 request
->ssids
[i
].ssid
,
298 request
->ssids
[i
].ssid_len
);
301 if (request
->n_ssids
)
302 rc
= wmi_set_ssid(wil
, request
->ssids
[0].ssid_len
,
303 request
->ssids
[0].ssid
);
305 rc
= wmi_set_ssid(wil
, 0, NULL
);
308 wil_err(wil
, "set SSID for scan request failed: %d\n", rc
);
312 wil
->scan_request
= request
;
313 mod_timer(&wil
->scan_timer
, jiffies
+ WIL6210_SCAN_TO
);
315 memset(&cmd
, 0, sizeof(cmd
));
316 cmd
.cmd
.num_channels
= 0;
317 n
= min(request
->n_channels
, 4U);
318 for (i
= 0; i
< n
; i
++) {
319 int ch
= request
->channels
[i
]->hw_value
;
323 "Scan requested for unknown frequency %dMhz\n",
324 request
->channels
[i
]->center_freq
);
327 /* 0-based channel indexes */
328 cmd
.cmd
.channel_list
[cmd
.cmd
.num_channels
++].channel
= ch
- 1;
329 wil_dbg_misc(wil
, "Scan for ch %d : %d MHz\n", ch
,
330 request
->channels
[i
]->center_freq
);
334 print_hex_dump_bytes("Scan IE ", DUMP_PREFIX_OFFSET
,
335 request
->ie
, request
->ie_len
);
337 wil_dbg_misc(wil
, "Scan has no IE's\n");
339 rc
= wmi_set_ie(wil
, WMI_FRAME_PROBE_REQ
, request
->ie_len
, request
->ie
);
343 rc
= wmi_send(wil
, WMI_START_SCAN_CMDID
, &cmd
, sizeof(cmd
.cmd
) +
344 cmd
.cmd
.num_channels
* sizeof(cmd
.cmd
.channel_list
[0]));
348 del_timer_sync(&wil
->scan_timer
);
349 wil
->scan_request
= NULL
;
355 static void wil_print_crypto(struct wil6210_priv
*wil
,
356 struct cfg80211_crypto_settings
*c
)
360 wil_dbg_misc(wil
, "WPA versions: 0x%08x cipher group 0x%08x\n",
361 c
->wpa_versions
, c
->cipher_group
);
362 wil_dbg_misc(wil
, "Pairwise ciphers [%d] {\n", c
->n_ciphers_pairwise
);
363 n
= min_t(int, c
->n_ciphers_pairwise
, ARRAY_SIZE(c
->ciphers_pairwise
));
364 for (i
= 0; i
< n
; i
++)
365 wil_dbg_misc(wil
, " [%d] = 0x%08x\n", i
,
366 c
->ciphers_pairwise
[i
]);
367 wil_dbg_misc(wil
, "}\n");
368 wil_dbg_misc(wil
, "AKM suites [%d] {\n", c
->n_akm_suites
);
369 n
= min_t(int, c
->n_akm_suites
, ARRAY_SIZE(c
->akm_suites
));
370 for (i
= 0; i
< n
; i
++)
371 wil_dbg_misc(wil
, " [%d] = 0x%08x\n", i
,
373 wil_dbg_misc(wil
, "}\n");
374 wil_dbg_misc(wil
, "Control port : %d, eth_type 0x%04x no_encrypt %d\n",
375 c
->control_port
, be16_to_cpu(c
->control_port_ethertype
),
376 c
->control_port_no_encrypt
);
379 static void wil_print_connect_params(struct wil6210_priv
*wil
,
380 struct cfg80211_connect_params
*sme
)
382 wil_info(wil
, "Connecting to:\n");
384 wil_info(wil
, " Channel: %d freq %d\n",
385 sme
->channel
->hw_value
, sme
->channel
->center_freq
);
388 wil_info(wil
, " BSSID: %pM\n", sme
->bssid
);
390 print_hex_dump(KERN_INFO
, " SSID: ", DUMP_PREFIX_OFFSET
,
391 16, 1, sme
->ssid
, sme
->ssid_len
, true);
392 wil_info(wil
, " Privacy: %s\n", sme
->privacy
? "secure" : "open");
393 wil_print_crypto(wil
, &sme
->crypto
);
396 static int wil_cfg80211_connect(struct wiphy
*wiphy
,
397 struct net_device
*ndev
,
398 struct cfg80211_connect_params
*sme
)
400 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
401 struct cfg80211_bss
*bss
;
402 struct wmi_connect_cmd conn
;
408 wil_print_connect_params(wil
, sme
);
410 if (test_bit(wil_status_fwconnecting
, wil
->status
) ||
411 test_bit(wil_status_fwconnected
, wil
->status
))
414 if (sme
->ie_len
> WMI_MAX_IE_LEN
) {
415 wil_err(wil
, "IE too large (%td bytes)\n", sme
->ie_len
);
420 cfg80211_find_ie(WLAN_EID_RSN
, sme
->ie
, sme
->ie_len
) :
422 if (sme
->privacy
&& !rsn_eid
)
423 wil_info(wil
, "WSC connection\n");
426 wil_err(wil
, "connect - PBSS not yet supported\n");
430 bss
= cfg80211_get_bss(wiphy
, sme
->channel
, sme
->bssid
,
431 sme
->ssid
, sme
->ssid_len
,
432 IEEE80211_BSS_TYPE_ESS
, IEEE80211_PRIVACY_ANY
);
434 wil_err(wil
, "Unable to find BSS\n");
438 ssid_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_SSID
);
440 wil_err(wil
, "No SSID\n");
444 wil
->privacy
= sme
->privacy
;
447 /* For secure assoc, remove old keys */
448 rc
= wmi_del_cipher_key(wil
, 0, bss
->bssid
,
449 WMI_KEY_USE_PAIRWISE
);
451 wil_err(wil
, "WMI_DELETE_CIPHER_KEY_CMD(PTK) failed\n");
454 rc
= wmi_del_cipher_key(wil
, 0, bss
->bssid
,
455 WMI_KEY_USE_RX_GROUP
);
457 wil_err(wil
, "WMI_DELETE_CIPHER_KEY_CMD(GTK) failed\n");
462 /* WMI_SET_APPIE_CMD. ie may contain rsn info as well as other info
463 * elements. Send it also in case it's empty, to erase previously set
466 rc
= wmi_set_ie(wil
, WMI_FRAME_ASSOC_REQ
, sme
->ie_len
, sme
->ie
);
470 /* WMI_CONNECT_CMD */
471 memset(&conn
, 0, sizeof(conn
));
472 switch (bss
->capability
& WLAN_CAPABILITY_DMG_TYPE_MASK
) {
473 case WLAN_CAPABILITY_DMG_TYPE_AP
:
474 conn
.network_type
= WMI_NETTYPE_INFRA
;
476 case WLAN_CAPABILITY_DMG_TYPE_PBSS
:
477 conn
.network_type
= WMI_NETTYPE_P2P
;
480 wil_err(wil
, "Unsupported BSS type, capability= 0x%04x\n",
485 if (rsn_eid
) { /* regular secure connection */
486 conn
.dot11_auth_mode
= WMI_AUTH11_SHARED
;
487 conn
.auth_mode
= WMI_AUTH_WPA2_PSK
;
488 conn
.pairwise_crypto_type
= WMI_CRYPT_AES_GCMP
;
489 conn
.pairwise_crypto_len
= 16;
490 conn
.group_crypto_type
= WMI_CRYPT_AES_GCMP
;
491 conn
.group_crypto_len
= 16;
493 conn
.dot11_auth_mode
= WMI_AUTH11_WSC
;
494 conn
.auth_mode
= WMI_AUTH_NONE
;
496 } else { /* insecure connection */
497 conn
.dot11_auth_mode
= WMI_AUTH11_OPEN
;
498 conn
.auth_mode
= WMI_AUTH_NONE
;
501 conn
.ssid_len
= min_t(u8
, ssid_eid
[1], 32);
502 memcpy(conn
.ssid
, ssid_eid
+2, conn
.ssid_len
);
504 ch
= bss
->channel
->hw_value
;
506 wil_err(wil
, "BSS at unknown frequency %dMhz\n",
507 bss
->channel
->center_freq
);
511 conn
.channel
= ch
- 1;
513 ether_addr_copy(conn
.bssid
, bss
->bssid
);
514 ether_addr_copy(conn
.dst_mac
, bss
->bssid
);
516 set_bit(wil_status_fwconnecting
, wil
->status
);
518 rc
= wmi_send(wil
, WMI_CONNECT_CMDID
, &conn
, sizeof(conn
));
520 netif_carrier_on(ndev
);
521 /* Connect can take lots of time */
522 mod_timer(&wil
->connect_timer
,
523 jiffies
+ msecs_to_jiffies(2000));
525 clear_bit(wil_status_fwconnecting
, wil
->status
);
529 cfg80211_put_bss(wiphy
, bss
);
534 static int wil_cfg80211_disconnect(struct wiphy
*wiphy
,
535 struct net_device
*ndev
,
539 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
541 wil_dbg_misc(wil
, "%s(reason=%d)\n", __func__
, reason_code
);
543 if (!(test_bit(wil_status_fwconnecting
, wil
->status
) ||
544 test_bit(wil_status_fwconnected
, wil
->status
))) {
545 wil_err(wil
, "%s: Disconnect was called while disconnected\n",
550 rc
= wmi_call(wil
, WMI_DISCONNECT_CMDID
, NULL
, 0,
551 WMI_DISCONNECT_EVENTID
, NULL
, 0,
552 WIL6210_DISCONNECT_TO_MS
);
554 wil_err(wil
, "%s: disconnect error %d\n", __func__
, rc
);
559 int wil_cfg80211_mgmt_tx(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
560 struct cfg80211_mgmt_tx_params
*params
,
563 const u8
*buf
= params
->buf
;
564 size_t len
= params
->len
;
565 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
567 bool tx_status
= false;
568 struct ieee80211_mgmt
*mgmt_frame
= (void *)buf
;
569 struct wmi_sw_tx_req_cmd
*cmd
;
571 struct wil6210_mbox_hdr_wmi wmi
;
572 struct wmi_sw_tx_complete_event evt
;
575 cmd
= kmalloc(sizeof(*cmd
) + len
, GFP_KERNEL
);
581 memcpy(cmd
->dst_mac
, mgmt_frame
->da
, WMI_MAC_LEN
);
582 cmd
->len
= cpu_to_le16(len
);
583 memcpy(cmd
->payload
, buf
, len
);
585 rc
= wmi_call(wil
, WMI_SW_TX_REQ_CMDID
, cmd
, sizeof(*cmd
) + len
,
586 WMI_SW_TX_COMPLETE_EVENTID
, &evt
, sizeof(evt
), 2000);
588 tx_status
= !evt
.evt
.status
;
592 cfg80211_mgmt_tx_status(wdev
, cookie
? *cookie
: 0, buf
, len
,
593 tx_status
, GFP_KERNEL
);
597 static int wil_cfg80211_set_channel(struct wiphy
*wiphy
,
598 struct cfg80211_chan_def
*chandef
)
600 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
601 struct wireless_dev
*wdev
= wil
->wdev
;
603 wdev
->preset_chandef
= *chandef
;
608 static enum wmi_key_usage
wil_detect_key_usage(struct wil6210_priv
*wil
,
611 struct wireless_dev
*wdev
= wil
->wdev
;
612 enum wmi_key_usage rc
;
613 static const char * const key_usage_str
[] = {
614 [WMI_KEY_USE_PAIRWISE
] = "WMI_KEY_USE_PAIRWISE",
615 [WMI_KEY_USE_RX_GROUP
] = "WMI_KEY_USE_RX_GROUP",
616 [WMI_KEY_USE_TX_GROUP
] = "WMI_KEY_USE_TX_GROUP",
620 rc
= WMI_KEY_USE_PAIRWISE
;
622 switch (wdev
->iftype
) {
623 case NL80211_IFTYPE_STATION
:
624 rc
= WMI_KEY_USE_RX_GROUP
;
626 case NL80211_IFTYPE_AP
:
627 rc
= WMI_KEY_USE_TX_GROUP
;
630 /* TODO: Rx GTK or Tx GTK? */
631 wil_err(wil
, "Can't determine GTK type\n");
632 rc
= WMI_KEY_USE_RX_GROUP
;
636 wil_dbg_misc(wil
, "%s() -> %s\n", __func__
, key_usage_str
[rc
]);
641 static int wil_cfg80211_add_key(struct wiphy
*wiphy
,
642 struct net_device
*ndev
,
643 u8 key_index
, bool pairwise
,
645 struct key_params
*params
)
647 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
648 enum wmi_key_usage key_usage
= wil_detect_key_usage(wil
, pairwise
);
650 wil_dbg_misc(wil
, "%s(%pM[%d] %s)\n", __func__
, mac_addr
, key_index
,
651 pairwise
? "PTK" : "GTK");
653 return wmi_add_cipher_key(wil
, key_index
, mac_addr
, params
->key_len
,
654 params
->key
, key_usage
);
657 static int wil_cfg80211_del_key(struct wiphy
*wiphy
,
658 struct net_device
*ndev
,
659 u8 key_index
, bool pairwise
,
662 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
663 enum wmi_key_usage key_usage
= wil_detect_key_usage(wil
, pairwise
);
665 wil_dbg_misc(wil
, "%s(%pM[%d] %s)\n", __func__
, mac_addr
, key_index
,
666 pairwise
? "PTK" : "GTK");
668 return wmi_del_cipher_key(wil
, key_index
, mac_addr
, key_usage
);
671 /* Need to be present or wiphy_new() will WARN */
672 static int wil_cfg80211_set_default_key(struct wiphy
*wiphy
,
673 struct net_device
*ndev
,
674 u8 key_index
, bool unicast
,
680 static int wil_remain_on_channel(struct wiphy
*wiphy
,
681 struct wireless_dev
*wdev
,
682 struct ieee80211_channel
*chan
,
683 unsigned int duration
,
686 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
689 /* TODO: handle duration */
690 wil_info(wil
, "%s(%d, %d ms)\n", __func__
, chan
->center_freq
, duration
);
692 rc
= wmi_set_channel(wil
, chan
->hw_value
);
696 rc
= wmi_rxon(wil
, true);
701 static int wil_cancel_remain_on_channel(struct wiphy
*wiphy
,
702 struct wireless_dev
*wdev
,
705 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
708 wil_info(wil
, "%s()\n", __func__
);
710 rc
= wmi_rxon(wil
, false);
716 * find a specific IE in a list of IEs
717 * return a pointer to the beginning of IE in the list
718 * or NULL if not found
720 static const u8
*_wil_cfg80211_find_ie(const u8
*ies
, u16 ies_len
, const u8
*ie
,
723 struct ieee80211_vendor_ie
*vie
;
726 /* IE tag at offset 0, length at offset 1 */
727 if (ie_len
< 2 || 2 + ie
[1] > ie_len
)
730 if (ie
[0] != WLAN_EID_VENDOR_SPECIFIC
)
731 return cfg80211_find_ie(ie
[0], ies
, ies_len
);
733 /* make sure there is room for 3 bytes OUI + 1 byte OUI type */
736 vie
= (struct ieee80211_vendor_ie
*)ie
;
737 oui
= vie
->oui
[0] << 16 | vie
->oui
[1] << 8 | vie
->oui
[2];
738 return cfg80211_find_vendor_ie(oui
, vie
->oui_type
, ies
,
743 * merge the IEs in two lists into a single list.
744 * do not include IEs from the second list which exist in the first list.
745 * add only vendor specific IEs from second list to keep
746 * the merged list sorted (since vendor-specific IE has the
747 * highest tag number)
748 * caller must free the allocated memory for merged IEs
750 static int _wil_cfg80211_merge_extra_ies(const u8
*ies1
, u16 ies1_len
,
751 const u8
*ies2
, u16 ies2_len
,
752 u8
**merged_ies
, u16
*merged_len
)
757 if (ies1_len
== 0 && ies2_len
== 0) {
763 buf
= kmalloc(ies1_len
+ ies2_len
, GFP_KERNEL
);
766 memcpy(buf
, ies1
, ies1_len
);
767 dpos
= buf
+ ies1_len
;
769 while (spos
+ 1 < ies2
+ ies2_len
) {
770 /* IE tag at offset 0, length at offset 1 */
771 u16 ielen
= 2 + spos
[1];
773 if (spos
+ ielen
> ies2
+ ies2_len
)
775 if (spos
[0] == WLAN_EID_VENDOR_SPECIFIC
&&
776 !_wil_cfg80211_find_ie(ies1
, ies1_len
, spos
, ielen
)) {
777 memcpy(dpos
, spos
, ielen
);
784 *merged_len
= dpos
- buf
;
788 static void wil_print_bcon_data(struct cfg80211_beacon_data
*b
)
790 print_hex_dump_bytes("head ", DUMP_PREFIX_OFFSET
,
791 b
->head
, b
->head_len
);
792 print_hex_dump_bytes("tail ", DUMP_PREFIX_OFFSET
,
793 b
->tail
, b
->tail_len
);
794 print_hex_dump_bytes("BCON IE ", DUMP_PREFIX_OFFSET
,
795 b
->beacon_ies
, b
->beacon_ies_len
);
796 print_hex_dump_bytes("PROBE ", DUMP_PREFIX_OFFSET
,
797 b
->probe_resp
, b
->probe_resp_len
);
798 print_hex_dump_bytes("PROBE IE ", DUMP_PREFIX_OFFSET
,
799 b
->proberesp_ies
, b
->proberesp_ies_len
);
800 print_hex_dump_bytes("ASSOC IE ", DUMP_PREFIX_OFFSET
,
801 b
->assocresp_ies
, b
->assocresp_ies_len
);
804 /* internal functions for device reset and starting AP */
805 static int _wil_cfg80211_set_ies(struct wiphy
*wiphy
,
806 struct cfg80211_beacon_data
*bcon
)
809 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
810 u16 len
= 0, proberesp_len
= 0;
811 u8
*ies
= NULL
, *proberesp
= NULL
;
813 if (bcon
->probe_resp
) {
814 struct ieee80211_mgmt
*f
=
815 (struct ieee80211_mgmt
*)bcon
->probe_resp
;
816 size_t hlen
= offsetof(struct ieee80211_mgmt
,
817 u
.probe_resp
.variable
);
818 proberesp
= f
->u
.probe_resp
.variable
;
819 proberesp_len
= bcon
->probe_resp_len
- hlen
;
821 rc
= _wil_cfg80211_merge_extra_ies(proberesp
,
824 bcon
->proberesp_ies_len
,
830 rc
= wmi_set_ie(wil
, WMI_FRAME_PROBE_RESP
, len
, ies
);
834 if (bcon
->assocresp_ies
)
835 rc
= wmi_set_ie(wil
, WMI_FRAME_ASSOC_RESP
,
836 bcon
->assocresp_ies_len
, bcon
->assocresp_ies
);
838 rc
= wmi_set_ie(wil
, WMI_FRAME_ASSOC_RESP
, len
, ies
);
839 #if 0 /* to use beacon IE's, remove this #if 0 */
843 rc
= wmi_set_ie(wil
, WMI_FRAME_BEACON
, bcon
->tail_len
, bcon
->tail
);
850 static int _wil_cfg80211_start_ap(struct wiphy
*wiphy
,
851 struct net_device
*ndev
,
852 const u8
*ssid
, size_t ssid_len
, u32 privacy
,
854 struct cfg80211_beacon_data
*bcon
,
857 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
859 struct wireless_dev
*wdev
= ndev
->ieee80211_ptr
;
860 u8 wmi_nettype
= wil_iftype_nl2wmi(wdev
->iftype
);
862 wil_set_recovery_state(wil
, fw_recovery_idle
);
864 mutex_lock(&wil
->mutex
);
871 rc
= wmi_set_ssid(wil
, ssid_len
, ssid
);
875 rc
= _wil_cfg80211_set_ies(wiphy
, bcon
);
879 wil
->privacy
= privacy
;
881 wil
->hidden_ssid
= hidden_ssid
;
883 netif_carrier_on(ndev
);
885 rc
= wmi_pcp_start(wil
, bi
, wmi_nettype
, chan
, hidden_ssid
);
889 rc
= wil_bcast_init(wil
);
893 goto out
; /* success */
898 netif_carrier_off(ndev
);
900 mutex_unlock(&wil
->mutex
);
904 static int wil_cfg80211_change_beacon(struct wiphy
*wiphy
,
905 struct net_device
*ndev
,
906 struct cfg80211_beacon_data
*bcon
)
908 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
912 wil_dbg_misc(wil
, "%s()\n", __func__
);
913 wil_print_bcon_data(bcon
);
916 cfg80211_find_ie(WLAN_EID_RSN
, bcon
->tail
,
920 /* in case privacy has changed, need to restart the AP */
921 if (wil
->privacy
!= privacy
) {
922 struct wireless_dev
*wdev
= ndev
->ieee80211_ptr
;
924 wil_dbg_misc(wil
, "privacy changed %d=>%d. Restarting AP\n",
925 wil
->privacy
, privacy
);
927 rc
= _wil_cfg80211_start_ap(wiphy
, ndev
, wdev
->ssid
,
928 wdev
->ssid_len
, privacy
,
929 wdev
->beacon_interval
,
933 rc
= _wil_cfg80211_set_ies(wiphy
, bcon
);
939 static int wil_cfg80211_start_ap(struct wiphy
*wiphy
,
940 struct net_device
*ndev
,
941 struct cfg80211_ap_settings
*info
)
944 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
945 struct ieee80211_channel
*channel
= info
->chandef
.chan
;
946 struct cfg80211_beacon_data
*bcon
= &info
->beacon
;
947 struct cfg80211_crypto_settings
*crypto
= &info
->crypto
;
950 wil_dbg_misc(wil
, "%s()\n", __func__
);
953 wil_err(wil
, "AP: No channel???\n");
958 wil_err(wil
, "AP: PBSS not yet supported\n");
962 switch (info
->hidden_ssid
) {
963 case NL80211_HIDDEN_SSID_NOT_IN_USE
:
964 hidden_ssid
= WMI_HIDDEN_SSID_DISABLED
;
967 case NL80211_HIDDEN_SSID_ZERO_LEN
:
968 hidden_ssid
= WMI_HIDDEN_SSID_SEND_EMPTY
;
971 case NL80211_HIDDEN_SSID_ZERO_CONTENTS
:
972 hidden_ssid
= WMI_HIDDEN_SSID_CLEAR
;
976 wil_err(wil
, "AP: Invalid hidden SSID %d\n", info
->hidden_ssid
);
979 wil_dbg_misc(wil
, "AP on Channel %d %d MHz, %s\n", channel
->hw_value
,
980 channel
->center_freq
, info
->privacy
? "secure" : "open");
981 wil_dbg_misc(wil
, "Privacy: %d auth_type %d\n",
982 info
->privacy
, info
->auth_type
);
983 wil_dbg_misc(wil
, "Hidden SSID mode: %d\n",
985 wil_dbg_misc(wil
, "BI %d DTIM %d\n", info
->beacon_interval
,
987 print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET
,
988 info
->ssid
, info
->ssid_len
);
989 wil_print_bcon_data(bcon
);
990 wil_print_crypto(wil
, crypto
);
992 rc
= _wil_cfg80211_start_ap(wiphy
, ndev
,
993 info
->ssid
, info
->ssid_len
, info
->privacy
,
994 info
->beacon_interval
, channel
->hw_value
,
1000 static int wil_cfg80211_stop_ap(struct wiphy
*wiphy
,
1001 struct net_device
*ndev
)
1003 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
1005 wil_dbg_misc(wil
, "%s()\n", __func__
);
1007 netif_carrier_off(ndev
);
1008 wil_set_recovery_state(wil
, fw_recovery_idle
);
1010 mutex_lock(&wil
->mutex
);
1016 mutex_unlock(&wil
->mutex
);
1021 static int wil_cfg80211_del_station(struct wiphy
*wiphy
,
1022 struct net_device
*dev
,
1023 struct station_del_parameters
*params
)
1025 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
1027 wil_dbg_misc(wil
, "%s(%pM, reason=%d)\n", __func__
, params
->mac
,
1028 params
->reason_code
);
1030 mutex_lock(&wil
->mutex
);
1031 wil6210_disconnect(wil
, params
->mac
, params
->reason_code
, false);
1032 mutex_unlock(&wil
->mutex
);
1037 /* probe_client handling */
1038 static void wil_probe_client_handle(struct wil6210_priv
*wil
,
1039 struct wil_probe_client_req
*req
)
1041 struct net_device
*ndev
= wil_to_ndev(wil
);
1042 struct wil_sta_info
*sta
= &wil
->sta
[req
->cid
];
1043 /* assume STA is alive if it is still connected,
1044 * else FW will disconnect it
1046 bool alive
= (sta
->status
== wil_sta_connected
);
1048 cfg80211_probe_status(ndev
, sta
->addr
, req
->cookie
, alive
, GFP_KERNEL
);
1051 static struct list_head
*next_probe_client(struct wil6210_priv
*wil
)
1053 struct list_head
*ret
= NULL
;
1055 mutex_lock(&wil
->probe_client_mutex
);
1057 if (!list_empty(&wil
->probe_client_pending
)) {
1058 ret
= wil
->probe_client_pending
.next
;
1062 mutex_unlock(&wil
->probe_client_mutex
);
1067 void wil_probe_client_worker(struct work_struct
*work
)
1069 struct wil6210_priv
*wil
= container_of(work
, struct wil6210_priv
,
1070 probe_client_worker
);
1071 struct wil_probe_client_req
*req
;
1072 struct list_head
*lh
;
1074 while ((lh
= next_probe_client(wil
)) != NULL
) {
1075 req
= list_entry(lh
, struct wil_probe_client_req
, list
);
1077 wil_probe_client_handle(wil
, req
);
1082 void wil_probe_client_flush(struct wil6210_priv
*wil
)
1084 struct wil_probe_client_req
*req
, *t
;
1086 wil_dbg_misc(wil
, "%s()\n", __func__
);
1088 mutex_lock(&wil
->probe_client_mutex
);
1090 list_for_each_entry_safe(req
, t
, &wil
->probe_client_pending
, list
) {
1091 list_del(&req
->list
);
1095 mutex_unlock(&wil
->probe_client_mutex
);
1098 static int wil_cfg80211_probe_client(struct wiphy
*wiphy
,
1099 struct net_device
*dev
,
1100 const u8
*peer
, u64
*cookie
)
1102 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
1103 struct wil_probe_client_req
*req
;
1104 int cid
= wil_find_cid(wil
, peer
);
1106 wil_dbg_misc(wil
, "%s(%pM => CID %d)\n", __func__
, peer
, cid
);
1111 req
= kzalloc(sizeof(*req
), GFP_KERNEL
);
1118 mutex_lock(&wil
->probe_client_mutex
);
1119 list_add_tail(&req
->list
, &wil
->probe_client_pending
);
1120 mutex_unlock(&wil
->probe_client_mutex
);
1122 *cookie
= req
->cookie
;
1123 queue_work(wil
->wq_service
, &wil
->probe_client_worker
);
1127 static int wil_cfg80211_change_bss(struct wiphy
*wiphy
,
1128 struct net_device
*dev
,
1129 struct bss_parameters
*params
)
1131 struct wil6210_priv
*wil
= wiphy_to_wil(wiphy
);
1133 if (params
->ap_isolate
>= 0) {
1134 wil_dbg_misc(wil
, "%s(ap_isolate %d => %d)\n", __func__
,
1135 wil
->ap_isolate
, params
->ap_isolate
);
1136 wil
->ap_isolate
= params
->ap_isolate
;
1142 static struct cfg80211_ops wil_cfg80211_ops
= {
1143 .scan
= wil_cfg80211_scan
,
1144 .connect
= wil_cfg80211_connect
,
1145 .disconnect
= wil_cfg80211_disconnect
,
1146 .change_virtual_intf
= wil_cfg80211_change_iface
,
1147 .get_station
= wil_cfg80211_get_station
,
1148 .dump_station
= wil_cfg80211_dump_station
,
1149 .remain_on_channel
= wil_remain_on_channel
,
1150 .cancel_remain_on_channel
= wil_cancel_remain_on_channel
,
1151 .mgmt_tx
= wil_cfg80211_mgmt_tx
,
1152 .set_monitor_channel
= wil_cfg80211_set_channel
,
1153 .add_key
= wil_cfg80211_add_key
,
1154 .del_key
= wil_cfg80211_del_key
,
1155 .set_default_key
= wil_cfg80211_set_default_key
,
1157 .change_beacon
= wil_cfg80211_change_beacon
,
1158 .start_ap
= wil_cfg80211_start_ap
,
1159 .stop_ap
= wil_cfg80211_stop_ap
,
1160 .del_station
= wil_cfg80211_del_station
,
1161 .probe_client
= wil_cfg80211_probe_client
,
1162 .change_bss
= wil_cfg80211_change_bss
,
1165 static void wil_wiphy_init(struct wiphy
*wiphy
)
1167 wiphy
->max_scan_ssids
= 1;
1168 wiphy
->max_scan_ie_len
= WMI_MAX_IE_LEN
;
1169 wiphy
->max_num_pmkids
= 0 /* TODO: */;
1170 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
1171 BIT(NL80211_IFTYPE_AP
) |
1172 BIT(NL80211_IFTYPE_MONITOR
);
1173 /* TODO: enable P2P when integrated with supplicant:
1174 * BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO)
1176 wiphy
->flags
|= WIPHY_FLAG_HAVE_AP_SME
|
1177 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
1178 dev_dbg(wiphy_dev(wiphy
), "%s : flags = 0x%08x\n",
1179 __func__
, wiphy
->flags
);
1180 wiphy
->probe_resp_offload
=
1181 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
1182 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
1183 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
1185 wiphy
->bands
[IEEE80211_BAND_60GHZ
] = &wil_band_60ghz
;
1187 /* TODO: figure this out */
1188 wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_UNSPEC
;
1190 wiphy
->cipher_suites
= wil_cipher_suites
;
1191 wiphy
->n_cipher_suites
= ARRAY_SIZE(wil_cipher_suites
);
1192 wiphy
->mgmt_stypes
= wil_mgmt_stypes
;
1193 wiphy
->features
|= NL80211_FEATURE_SK_TX_STATUS
;
1196 struct wireless_dev
*wil_cfg80211_init(struct device
*dev
)
1199 struct wireless_dev
*wdev
;
1201 dev_dbg(dev
, "%s()\n", __func__
);
1203 wdev
= kzalloc(sizeof(*wdev
), GFP_KERNEL
);
1205 return ERR_PTR(-ENOMEM
);
1207 wdev
->wiphy
= wiphy_new(&wil_cfg80211_ops
,
1208 sizeof(struct wil6210_priv
));
1214 set_wiphy_dev(wdev
->wiphy
, dev
);
1215 wil_wiphy_init(wdev
->wiphy
);
1217 rc
= wiphy_register(wdev
->wiphy
);
1219 goto out_failed_reg
;
1224 wiphy_free(wdev
->wiphy
);
1231 void wil_wdev_free(struct wil6210_priv
*wil
)
1233 struct wireless_dev
*wdev
= wil_to_wdev(wil
);
1235 dev_dbg(wil_to_dev(wil
), "%s()\n", __func__
);
1240 wiphy_unregister(wdev
->wiphy
);
1241 wiphy_free(wdev
->wiphy
);