1 | // SPDX-License-Identifier: GPL-2.0 |
2 | /****************************************************************************** |
3 | * |
4 | * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. |
5 | * |
6 | ******************************************************************************/ |
7 | |
8 | #include <linux/etherdevice.h> |
9 | #include <drv_types.h> |
10 | #include <rtw_debug.h> |
11 | #include <linux/jiffies.h> |
12 | |
13 | #include <rtw_wifi_regd.h> |
14 | |
15 | #define RTW_MAX_MGMT_TX_CNT (8) |
16 | |
17 | #define RTW_SCAN_IE_LEN_MAX 2304 |
18 | #define RTW_MAX_REMAIN_ON_CHANNEL_DURATION 5000 /* ms */ |
19 | #define RTW_MAX_NUM_PMKIDS 4 |
20 | |
21 | static const u32 rtw_cipher_suites[] = { |
22 | WLAN_CIPHER_SUITE_WEP40, |
23 | WLAN_CIPHER_SUITE_WEP104, |
24 | WLAN_CIPHER_SUITE_TKIP, |
25 | WLAN_CIPHER_SUITE_CCMP, |
26 | WLAN_CIPHER_SUITE_AES_CMAC, |
27 | }; |
28 | |
29 | #define RATETAB_ENT(_rate, _rateid, _flags) \ |
30 | { \ |
31 | .bitrate = (_rate), \ |
32 | .hw_value = (_rateid), \ |
33 | .flags = (_flags), \ |
34 | } |
35 | |
36 | #define CHAN2G(_channel, _freq, _flags) { \ |
37 | .band = NL80211_BAND_2GHZ, \ |
38 | .center_freq = (_freq), \ |
39 | .hw_value = (_channel), \ |
40 | .flags = (_flags), \ |
41 | .max_antenna_gain = 0, \ |
42 | .max_power = 30, \ |
43 | } |
44 | |
45 | /* if wowlan is not supported, kernel generate a disconnect at each suspend |
46 | * cf: /net/wireless/sysfs.c, so register a stub wowlan. |
47 | * Moreover wowlan has to be enabled via a the nl80211_set_wowlan callback. |
48 | * (from user space, e.g. iw phy0 wowlan enable) |
49 | */ |
50 | static __maybe_unused const struct wiphy_wowlan_support wowlan_stub = { |
51 | .flags = WIPHY_WOWLAN_ANY, |
52 | .n_patterns = 0, |
53 | .pattern_max_len = 0, |
54 | .pattern_min_len = 0, |
55 | .max_pkt_offset = 0, |
56 | }; |
57 | |
58 | static struct ieee80211_rate rtw_rates[] = { |
59 | RATETAB_ENT(10, 0x1, 0), |
60 | RATETAB_ENT(20, 0x2, 0), |
61 | RATETAB_ENT(55, 0x4, 0), |
62 | RATETAB_ENT(110, 0x8, 0), |
63 | RATETAB_ENT(60, 0x10, 0), |
64 | RATETAB_ENT(90, 0x20, 0), |
65 | RATETAB_ENT(120, 0x40, 0), |
66 | RATETAB_ENT(180, 0x80, 0), |
67 | RATETAB_ENT(240, 0x100, 0), |
68 | RATETAB_ENT(360, 0x200, 0), |
69 | RATETAB_ENT(480, 0x400, 0), |
70 | RATETAB_ENT(540, 0x800, 0), |
71 | }; |
72 | |
73 | #define rtw_g_rates (rtw_rates + 0) |
74 | #define RTW_G_RATES_NUM 12 |
75 | |
76 | #define RTW_2G_CHANNELS_NUM 14 |
77 | |
78 | static struct ieee80211_channel rtw_2ghz_channels[] = { |
79 | CHAN2G(1, 2412, 0), |
80 | CHAN2G(2, 2417, 0), |
81 | CHAN2G(3, 2422, 0), |
82 | CHAN2G(4, 2427, 0), |
83 | CHAN2G(5, 2432, 0), |
84 | CHAN2G(6, 2437, 0), |
85 | CHAN2G(7, 2442, 0), |
86 | CHAN2G(8, 2447, 0), |
87 | CHAN2G(9, 2452, 0), |
88 | CHAN2G(10, 2457, 0), |
89 | CHAN2G(11, 2462, 0), |
90 | CHAN2G(12, 2467, 0), |
91 | CHAN2G(13, 2472, 0), |
92 | CHAN2G(14, 2484, 0), |
93 | }; |
94 | |
95 | static void rtw_2g_channels_init(struct ieee80211_channel *channels) |
96 | { |
97 | memcpy((void *)channels, (void *)rtw_2ghz_channels, |
98 | sizeof(struct ieee80211_channel) * RTW_2G_CHANNELS_NUM |
99 | ); |
100 | } |
101 | |
102 | static void rtw_2g_rates_init(struct ieee80211_rate *rates) |
103 | { |
104 | memcpy(rates, rtw_g_rates, |
105 | sizeof(struct ieee80211_rate) * RTW_G_RATES_NUM |
106 | ); |
107 | } |
108 | |
109 | static struct ieee80211_supported_band *rtw_spt_band_alloc( |
110 | enum nl80211_band band |
111 | ) |
112 | { |
113 | struct ieee80211_supported_band *spt_band = NULL; |
114 | int n_channels, n_bitrates; |
115 | |
116 | if (band == NL80211_BAND_2GHZ) { |
117 | n_channels = RTW_2G_CHANNELS_NUM; |
118 | n_bitrates = RTW_G_RATES_NUM; |
119 | } else { |
120 | goto exit; |
121 | } |
122 | |
123 | spt_band = rtw_zmalloc(sizeof(struct ieee80211_supported_band) + |
124 | sizeof(struct ieee80211_channel) * n_channels + |
125 | sizeof(struct ieee80211_rate) * n_bitrates); |
126 | if (!spt_band) |
127 | goto exit; |
128 | |
129 | spt_band->channels = (struct ieee80211_channel *)(((u8 *)spt_band) + sizeof(struct ieee80211_supported_band)); |
130 | spt_band->bitrates = (struct ieee80211_rate *)(((u8 *)spt_band->channels) + sizeof(struct ieee80211_channel) * n_channels); |
131 | spt_band->band = band; |
132 | spt_band->n_channels = n_channels; |
133 | spt_band->n_bitrates = n_bitrates; |
134 | |
135 | if (band == NL80211_BAND_2GHZ) { |
136 | rtw_2g_channels_init(channels: spt_band->channels); |
137 | rtw_2g_rates_init(rates: spt_band->bitrates); |
138 | } |
139 | |
140 | /* spt_band.ht_cap */ |
141 | |
142 | exit: |
143 | |
144 | return spt_band; |
145 | } |
146 | |
147 | static const struct ieee80211_txrx_stypes |
148 | rtw_cfg80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = { |
149 | [NL80211_IFTYPE_ADHOC] = { |
150 | .tx = 0xffff, |
151 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
152 | }, |
153 | [NL80211_IFTYPE_STATION] = { |
154 | .tx = 0xffff, |
155 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
156 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
157 | }, |
158 | [NL80211_IFTYPE_AP] = { |
159 | .tx = 0xffff, |
160 | .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | |
161 | BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | |
162 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
163 | BIT(IEEE80211_STYPE_DISASSOC >> 4) | |
164 | BIT(IEEE80211_STYPE_AUTH >> 4) | |
165 | BIT(IEEE80211_STYPE_DEAUTH >> 4) | |
166 | BIT(IEEE80211_STYPE_ACTION >> 4) |
167 | }, |
168 | [NL80211_IFTYPE_AP_VLAN] = { |
169 | /* copy AP */ |
170 | .tx = 0xffff, |
171 | .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | |
172 | BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | |
173 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
174 | BIT(IEEE80211_STYPE_DISASSOC >> 4) | |
175 | BIT(IEEE80211_STYPE_AUTH >> 4) | |
176 | BIT(IEEE80211_STYPE_DEAUTH >> 4) | |
177 | BIT(IEEE80211_STYPE_ACTION >> 4) |
178 | }, |
179 | [NL80211_IFTYPE_P2P_CLIENT] = { |
180 | .tx = 0xffff, |
181 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
182 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
183 | }, |
184 | [NL80211_IFTYPE_P2P_GO] = { |
185 | .tx = 0xffff, |
186 | .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | |
187 | BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | |
188 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
189 | BIT(IEEE80211_STYPE_DISASSOC >> 4) | |
190 | BIT(IEEE80211_STYPE_AUTH >> 4) | |
191 | BIT(IEEE80211_STYPE_DEAUTH >> 4) | |
192 | BIT(IEEE80211_STYPE_ACTION >> 4) |
193 | }, |
194 | }; |
195 | |
196 | static int rtw_ieee80211_channel_to_frequency(int chan, int band) |
197 | { |
198 | if (band == NL80211_BAND_2GHZ) { |
199 | if (chan == 14) |
200 | return 2484; |
201 | else if (chan < 14) |
202 | return 2407 + chan * 5; |
203 | } |
204 | |
205 | return 0; /* not supported */ |
206 | } |
207 | |
208 | #define MAX_BSSINFO_LEN 1000 |
209 | struct cfg80211_bss *rtw_cfg80211_inform_bss(struct adapter *padapter, struct wlan_network *pnetwork) |
210 | { |
211 | struct ieee80211_channel *notify_channel; |
212 | struct cfg80211_bss *bss = NULL; |
213 | /* struct ieee80211_supported_band *band; */ |
214 | u16 channel; |
215 | u32 freq; |
216 | u64 notify_timestamp; |
217 | s32 notify_signal; |
218 | u8 *buf = NULL, *pbuf; |
219 | size_t len, bssinf_len = 0; |
220 | struct ieee80211_hdr *pwlanhdr; |
221 | __le16 *fctrl; |
222 | |
223 | struct wireless_dev *wdev = padapter->rtw_wdev; |
224 | struct wiphy *wiphy = wdev->wiphy; |
225 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
226 | |
227 | bssinf_len = pnetwork->network.ie_length + sizeof(struct ieee80211_hdr_3addr); |
228 | if (bssinf_len > MAX_BSSINFO_LEN) |
229 | goto exit; |
230 | |
231 | { |
232 | u16 wapi_len = 0; |
233 | |
234 | if (rtw_get_wapi_ie(in_ie: pnetwork->network.ies, in_len: pnetwork->network.ie_length, NULL, wapi_len: &wapi_len) > 0) { |
235 | if (wapi_len > 0) |
236 | goto exit; |
237 | } |
238 | } |
239 | |
240 | /* To reduce PBC Overlap rate */ |
241 | /* spin_lock_bh(&pwdev_priv->scan_req_lock); */ |
242 | if (adapter_wdev_data(padapter)->scan_request) { |
243 | u8 *psr = NULL, sr = 0; |
244 | struct ndis_802_11_ssid *pssid = &pnetwork->network.ssid; |
245 | struct cfg80211_scan_request *request = adapter_wdev_data(padapter)->scan_request; |
246 | struct cfg80211_ssid *ssids = request->ssids; |
247 | u32 wpsielen = 0; |
248 | u8 *wpsie = NULL; |
249 | |
250 | wpsie = rtw_get_wps_ie(in_ie: pnetwork->network.ies + _FIXED_IE_LENGTH_, in_len: pnetwork->network.ie_length - _FIXED_IE_LENGTH_, NULL, wps_ielen: &wpsielen); |
251 | |
252 | if (wpsie && wpsielen > 0) |
253 | psr = rtw_get_wps_attr_content(wps_ie: wpsie, wps_ielen: wpsielen, WPS_ATTR_SELECTED_REGISTRAR, buf_content: (u8 *)(&sr), NULL); |
254 | |
255 | if (sr != 0) { |
256 | /* it means under processing WPS */ |
257 | if (request->n_ssids == 1 && request->n_channels == 1) { |
258 | if (ssids[0].ssid_len != 0 && |
259 | (pssid->ssid_length != ssids[0].ssid_len || |
260 | memcmp(p: pssid->ssid, q: ssids[0].ssid, size: ssids[0].ssid_len))) { |
261 | if (psr) |
262 | *psr = 0; /* clear sr */ |
263 | } |
264 | } |
265 | } |
266 | } |
267 | /* spin_unlock_bh(&pwdev_priv->scan_req_lock); */ |
268 | |
269 | channel = pnetwork->network.configuration.ds_config; |
270 | freq = rtw_ieee80211_channel_to_frequency(chan: channel, band: NL80211_BAND_2GHZ); |
271 | |
272 | notify_channel = ieee80211_get_channel(wiphy, freq); |
273 | |
274 | notify_timestamp = ktime_to_us(kt: ktime_get_boottime()); |
275 | |
276 | /* We've set wiphy's signal_type as CFG80211_SIGNAL_TYPE_MBM: signal strength in mBm (100*dBm) */ |
277 | if (check_fwstate(pmlmepriv, _FW_LINKED) == true && |
278 | is_same_network(src: &pmlmepriv->cur_network.network, dst: &pnetwork->network, feature: 0)) { |
279 | notify_signal = 100 * translate_percentage_to_dbm(SignalStrengthIndex: padapter->recvpriv.signal_strength);/* dbm */ |
280 | } else { |
281 | notify_signal = 100 * translate_percentage_to_dbm(SignalStrengthIndex: pnetwork->network.phy_info.signal_strength);/* dbm */ |
282 | } |
283 | |
284 | buf = kzalloc(MAX_BSSINFO_LEN, GFP_ATOMIC); |
285 | if (!buf) |
286 | goto exit; |
287 | pbuf = buf; |
288 | |
289 | pwlanhdr = (struct ieee80211_hdr *)pbuf; |
290 | fctrl = &(pwlanhdr->frame_control); |
291 | *(fctrl) = 0; |
292 | |
293 | SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/); |
294 | /* pmlmeext->mgnt_seq++; */ |
295 | |
296 | if (pnetwork->network.reserved[0] == 1) { /* WIFI_BEACON */ |
297 | eth_broadcast_addr(addr: pwlanhdr->addr1); |
298 | SetFrameSubType(pbuf, WIFI_BEACON); |
299 | } else { |
300 | memcpy(pwlanhdr->addr1, myid(&(padapter->eeprompriv)), ETH_ALEN); |
301 | SetFrameSubType(pbuf, WIFI_PROBERSP); |
302 | } |
303 | |
304 | memcpy(pwlanhdr->addr2, pnetwork->network.mac_address, ETH_ALEN); |
305 | memcpy(pwlanhdr->addr3, pnetwork->network.mac_address, ETH_ALEN); |
306 | |
307 | pbuf += sizeof(struct ieee80211_hdr_3addr); |
308 | len = sizeof(struct ieee80211_hdr_3addr); |
309 | |
310 | memcpy(pbuf, pnetwork->network.ies, pnetwork->network.ie_length); |
311 | len += pnetwork->network.ie_length; |
312 | |
313 | *((__le64 *)pbuf) = cpu_to_le64(notify_timestamp); |
314 | |
315 | bss = cfg80211_inform_bss_frame(wiphy, rx_channel: notify_channel, mgmt: (struct ieee80211_mgmt *)buf, |
316 | len, signal: notify_signal, GFP_ATOMIC); |
317 | |
318 | if (unlikely(!bss)) |
319 | goto exit; |
320 | |
321 | cfg80211_put_bss(wiphy, bss); |
322 | kfree(objp: buf); |
323 | |
324 | exit: |
325 | return bss; |
326 | } |
327 | |
328 | /* |
329 | * Check the given bss is valid by kernel API cfg80211_get_bss() |
330 | * @padapter : the given adapter |
331 | * |
332 | * return true if bss is valid, false for not found. |
333 | */ |
334 | int rtw_cfg80211_check_bss(struct adapter *padapter) |
335 | { |
336 | struct wlan_bssid_ex *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network); |
337 | struct cfg80211_bss *bss = NULL; |
338 | struct ieee80211_channel *notify_channel = NULL; |
339 | u32 freq; |
340 | |
341 | if (!(pnetwork) || !(padapter->rtw_wdev)) |
342 | return false; |
343 | |
344 | freq = rtw_ieee80211_channel_to_frequency(chan: pnetwork->configuration.ds_config, band: NL80211_BAND_2GHZ); |
345 | |
346 | notify_channel = ieee80211_get_channel(wiphy: padapter->rtw_wdev->wiphy, freq); |
347 | bss = cfg80211_get_bss(wiphy: padapter->rtw_wdev->wiphy, channel: notify_channel, |
348 | bssid: pnetwork->mac_address, ssid: pnetwork->ssid.ssid, |
349 | ssid_len: pnetwork->ssid.ssid_length, |
350 | bss_type: IEEE80211_BSS_TYPE_ANY, privacy: IEEE80211_PRIVACY_ANY); |
351 | |
352 | cfg80211_put_bss(wiphy: padapter->rtw_wdev->wiphy, bss); |
353 | |
354 | return (bss != NULL); |
355 | } |
356 | |
357 | void rtw_cfg80211_ibss_indicate_connect(struct adapter *padapter) |
358 | { |
359 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
360 | struct wlan_network *cur_network = &(pmlmepriv->cur_network); |
361 | struct wireless_dev *pwdev = padapter->rtw_wdev; |
362 | struct wiphy *wiphy = pwdev->wiphy; |
363 | int freq = (int)cur_network->network.configuration.ds_config; |
364 | struct ieee80211_channel *chan; |
365 | |
366 | if (pwdev->iftype != NL80211_IFTYPE_ADHOC) |
367 | return; |
368 | |
369 | if (!rtw_cfg80211_check_bss(padapter)) { |
370 | struct wlan_bssid_ex *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network); |
371 | struct wlan_network *scanned = pmlmepriv->cur_network_scanned; |
372 | |
373 | if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) { |
374 | memcpy(&cur_network->network, pnetwork, sizeof(struct wlan_bssid_ex)); |
375 | rtw_cfg80211_inform_bss(padapter, pnetwork: cur_network); |
376 | } else { |
377 | if (!scanned) { |
378 | rtw_warn_on(1); |
379 | return; |
380 | } |
381 | if (!memcmp(p: &(scanned->network.ssid), q: &(pnetwork->ssid), size: sizeof(struct ndis_802_11_ssid)) |
382 | && !memcmp(p: scanned->network.mac_address, q: pnetwork->mac_address, size: sizeof(NDIS_802_11_MAC_ADDRESS)) |
383 | ) |
384 | rtw_cfg80211_inform_bss(padapter, pnetwork: scanned); |
385 | else |
386 | rtw_warn_on(1); |
387 | } |
388 | |
389 | if (!rtw_cfg80211_check_bss(padapter)) |
390 | netdev_dbg(padapter->pnetdev, |
391 | FUNC_ADPT_FMT " BSS not found !!\n" , |
392 | FUNC_ADPT_ARG(padapter)); |
393 | } |
394 | /* notify cfg80211 that device joined an IBSS */ |
395 | chan = ieee80211_get_channel(wiphy, freq); |
396 | cfg80211_ibss_joined(dev: padapter->pnetdev, bssid: cur_network->network.mac_address, channel: chan, GFP_ATOMIC); |
397 | } |
398 | |
399 | void rtw_cfg80211_indicate_connect(struct adapter *padapter) |
400 | { |
401 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
402 | struct wlan_network *cur_network = &(pmlmepriv->cur_network); |
403 | struct wireless_dev *pwdev = padapter->rtw_wdev; |
404 | |
405 | if (pwdev->iftype != NL80211_IFTYPE_STATION |
406 | && pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT |
407 | ) { |
408 | return; |
409 | } |
410 | |
411 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) |
412 | return; |
413 | |
414 | { |
415 | struct wlan_bssid_ex *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network); |
416 | struct wlan_network *scanned = pmlmepriv->cur_network_scanned; |
417 | |
418 | if (!scanned) { |
419 | rtw_warn_on(1); |
420 | goto check_bss; |
421 | } |
422 | |
423 | if (!memcmp(p: scanned->network.mac_address, q: pnetwork->mac_address, size: sizeof(NDIS_802_11_MAC_ADDRESS)) |
424 | && !memcmp(p: &(scanned->network.ssid), q: &(pnetwork->ssid), size: sizeof(struct ndis_802_11_ssid)) |
425 | ) |
426 | rtw_cfg80211_inform_bss(padapter, pnetwork: scanned); |
427 | else |
428 | rtw_warn_on(1); |
429 | } |
430 | |
431 | check_bss: |
432 | if (!rtw_cfg80211_check_bss(padapter)) |
433 | netdev_dbg(padapter->pnetdev, |
434 | FUNC_ADPT_FMT " BSS not found !!\n" , |
435 | FUNC_ADPT_ARG(padapter)); |
436 | |
437 | if (rtw_to_roam(adapter: padapter) > 0) { |
438 | struct wiphy *wiphy = pwdev->wiphy; |
439 | struct ieee80211_channel *notify_channel; |
440 | u32 freq; |
441 | u16 channel = cur_network->network.configuration.ds_config; |
442 | struct cfg80211_roam_info roam_info = {}; |
443 | |
444 | freq = rtw_ieee80211_channel_to_frequency(chan: channel, band: NL80211_BAND_2GHZ); |
445 | |
446 | notify_channel = ieee80211_get_channel(wiphy, freq); |
447 | |
448 | roam_info.links[0].channel = notify_channel; |
449 | roam_info.links[0].bssid = cur_network->network.mac_address; |
450 | roam_info.req_ie = |
451 | pmlmepriv->assoc_req + sizeof(struct ieee80211_hdr_3addr) + 2; |
452 | roam_info.req_ie_len = |
453 | pmlmepriv->assoc_req_len - sizeof(struct ieee80211_hdr_3addr) - 2; |
454 | roam_info.resp_ie = |
455 | pmlmepriv->assoc_rsp + sizeof(struct ieee80211_hdr_3addr) + 6; |
456 | roam_info.resp_ie_len = |
457 | pmlmepriv->assoc_rsp_len - sizeof(struct ieee80211_hdr_3addr) - 6; |
458 | cfg80211_roamed(dev: padapter->pnetdev, info: &roam_info, GFP_ATOMIC); |
459 | } else { |
460 | cfg80211_connect_result(dev: padapter->pnetdev, bssid: cur_network->network.mac_address |
461 | , req_ie: pmlmepriv->assoc_req + sizeof(struct ieee80211_hdr_3addr) + 2 |
462 | , req_ie_len: pmlmepriv->assoc_req_len - sizeof(struct ieee80211_hdr_3addr) - 2 |
463 | , resp_ie: pmlmepriv->assoc_rsp + sizeof(struct ieee80211_hdr_3addr) + 6 |
464 | , resp_ie_len: pmlmepriv->assoc_rsp_len - sizeof(struct ieee80211_hdr_3addr) - 6 |
465 | , status: WLAN_STATUS_SUCCESS, GFP_ATOMIC); |
466 | } |
467 | } |
468 | |
469 | void rtw_cfg80211_indicate_disconnect(struct adapter *padapter) |
470 | { |
471 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
472 | struct wireless_dev *pwdev = padapter->rtw_wdev; |
473 | |
474 | if (pwdev->iftype != NL80211_IFTYPE_STATION |
475 | && pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT |
476 | ) { |
477 | return; |
478 | } |
479 | |
480 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) |
481 | return; |
482 | |
483 | if (!padapter->mlmepriv.not_indic_disco) { |
484 | if (check_fwstate(pmlmepriv: &padapter->mlmepriv, _FW_LINKED)) { |
485 | cfg80211_disconnected(dev: padapter->pnetdev, reason: 0, |
486 | NULL, ie_len: 0, locally_generated: true, GFP_ATOMIC); |
487 | } else { |
488 | cfg80211_connect_result(dev: padapter->pnetdev, NULL, NULL, req_ie_len: 0, NULL, resp_ie_len: 0, |
489 | status: WLAN_STATUS_UNSPECIFIED_FAILURE, GFP_ATOMIC/*GFP_KERNEL*/); |
490 | } |
491 | } |
492 | } |
493 | |
494 | static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len) |
495 | { |
496 | int ret = 0; |
497 | u32 wep_key_idx, wep_key_len; |
498 | struct sta_info *psta = NULL, *pbcmc_sta = NULL; |
499 | struct adapter *padapter = rtw_netdev_priv(netdev: dev); |
500 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
501 | struct security_priv *psecuritypriv = &(padapter->securitypriv); |
502 | struct sta_priv *pstapriv = &padapter->stapriv; |
503 | char *grpkey = padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey; |
504 | char *txkey = padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey; |
505 | char *rxkey = padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey; |
506 | |
507 | param->u.crypt.err = 0; |
508 | param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0'; |
509 | |
510 | if (param_len != sizeof(struct ieee_param) + param->u.crypt.key_len) { |
511 | ret = -EINVAL; |
512 | goto exit; |
513 | } |
514 | |
515 | if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff && |
516 | param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && |
517 | param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) { |
518 | if (param->u.crypt.idx >= WEP_KEYS) { |
519 | ret = -EINVAL; |
520 | goto exit; |
521 | } |
522 | } else { |
523 | psta = rtw_get_stainfo(pstapriv, hwaddr: param->sta_addr); |
524 | if (!psta) |
525 | /* ret = -EINVAL; */ |
526 | goto exit; |
527 | } |
528 | |
529 | if (strcmp(param->u.crypt.alg, "none" ) == 0 && !psta) |
530 | goto exit; |
531 | |
532 | if (strcmp(param->u.crypt.alg, "WEP" ) == 0 && !psta) { |
533 | wep_key_idx = param->u.crypt.idx; |
534 | wep_key_len = param->u.crypt.key_len; |
535 | |
536 | if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) { |
537 | ret = -EINVAL; |
538 | goto exit; |
539 | } |
540 | |
541 | if (wep_key_len > 0) |
542 | wep_key_len = wep_key_len <= 5 ? 5 : 13; |
543 | |
544 | if (psecuritypriv->bWepDefaultKeyIdxSet == 0) { |
545 | /* wep default key has not been set, so use this key index as default key. */ |
546 | |
547 | psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto; |
548 | psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled; |
549 | psecuritypriv->dot11PrivacyAlgrthm = _WEP40_; |
550 | psecuritypriv->dot118021XGrpPrivacy = _WEP40_; |
551 | |
552 | if (wep_key_len == 13) { |
553 | psecuritypriv->dot11PrivacyAlgrthm = _WEP104_; |
554 | psecuritypriv->dot118021XGrpPrivacy = _WEP104_; |
555 | } |
556 | |
557 | psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx; |
558 | } |
559 | |
560 | memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len); |
561 | |
562 | psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len; |
563 | |
564 | rtw_ap_set_wep_key(padapter, key: param->u.crypt.key, keylen: wep_key_len, keyid: wep_key_idx, set_tx: 1); |
565 | |
566 | goto exit; |
567 | } |
568 | |
569 | /* group key */ |
570 | if (!psta && check_fwstate(pmlmepriv, WIFI_AP_STATE)) { |
571 | /* group key */ |
572 | if (param->u.crypt.set_tx == 0) { |
573 | if (strcmp(param->u.crypt.alg, "WEP" ) == 0) { |
574 | memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); |
575 | |
576 | psecuritypriv->dot118021XGrpPrivacy = _WEP40_; |
577 | if (param->u.crypt.key_len == 13) |
578 | psecuritypriv->dot118021XGrpPrivacy = _WEP104_; |
579 | |
580 | } else if (strcmp(param->u.crypt.alg, "TKIP" ) == 0) { |
581 | psecuritypriv->dot118021XGrpPrivacy = _TKIP_; |
582 | |
583 | memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); |
584 | |
585 | /* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */ |
586 | /* set mic key */ |
587 | memcpy(txkey, &(param->u.crypt.key[16]), 8); |
588 | memcpy(rxkey, &(param->u.crypt.key[24]), 8); |
589 | |
590 | psecuritypriv->busetkipkey = true; |
591 | |
592 | } else if (strcmp(param->u.crypt.alg, "CCMP" ) == 0) { |
593 | psecuritypriv->dot118021XGrpPrivacy = _AES_; |
594 | |
595 | memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); |
596 | } else { |
597 | psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; |
598 | } |
599 | |
600 | psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx; |
601 | |
602 | psecuritypriv->binstallGrpkey = true; |
603 | |
604 | psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;/* */ |
605 | |
606 | rtw_ap_set_group_key(padapter, key: param->u.crypt.key, alg: psecuritypriv->dot118021XGrpPrivacy, keyid: param->u.crypt.idx); |
607 | |
608 | pbcmc_sta = rtw_get_bcmc_stainfo(padapter); |
609 | if (pbcmc_sta) { |
610 | pbcmc_sta->ieee8021x_blocked = false; |
611 | pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy;/* rx will use bmc_sta's dot118021XPrivacy */ |
612 | } |
613 | } |
614 | |
615 | goto exit; |
616 | } |
617 | |
618 | if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) { /* psk/802_1x */ |
619 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { |
620 | if (param->u.crypt.set_tx == 1) { /* pairwise key */ |
621 | memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); |
622 | |
623 | if (strcmp(param->u.crypt.alg, "WEP" ) == 0) { |
624 | psta->dot118021XPrivacy = _WEP40_; |
625 | if (param->u.crypt.key_len == 13) |
626 | psta->dot118021XPrivacy = _WEP104_; |
627 | } else if (strcmp(param->u.crypt.alg, "TKIP" ) == 0) { |
628 | psta->dot118021XPrivacy = _TKIP_; |
629 | |
630 | /* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */ |
631 | /* set mic key */ |
632 | memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8); |
633 | memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8); |
634 | |
635 | psecuritypriv->busetkipkey = true; |
636 | |
637 | } else if (strcmp(param->u.crypt.alg, "CCMP" ) == 0) { |
638 | psta->dot118021XPrivacy = _AES_; |
639 | } else { |
640 | psta->dot118021XPrivacy = _NO_PRIVACY_; |
641 | } |
642 | |
643 | rtw_ap_set_pairwise_key(padapter, psta); |
644 | |
645 | psta->ieee8021x_blocked = false; |
646 | |
647 | psta->bpairwise_key_installed = true; |
648 | |
649 | } else { /* group key??? */ |
650 | if (strcmp(param->u.crypt.alg, "WEP" ) == 0) { |
651 | memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); |
652 | |
653 | psecuritypriv->dot118021XGrpPrivacy = _WEP40_; |
654 | if (param->u.crypt.key_len == 13) |
655 | psecuritypriv->dot118021XGrpPrivacy = _WEP104_; |
656 | } else if (strcmp(param->u.crypt.alg, "TKIP" ) == 0) { |
657 | psecuritypriv->dot118021XGrpPrivacy = _TKIP_; |
658 | |
659 | memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); |
660 | |
661 | /* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */ |
662 | /* set mic key */ |
663 | memcpy(txkey, &(param->u.crypt.key[16]), 8); |
664 | memcpy(rxkey, &(param->u.crypt.key[24]), 8); |
665 | |
666 | psecuritypriv->busetkipkey = true; |
667 | |
668 | } else if (strcmp(param->u.crypt.alg, "CCMP" ) == 0) { |
669 | psecuritypriv->dot118021XGrpPrivacy = _AES_; |
670 | |
671 | memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); |
672 | } else { |
673 | psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; |
674 | } |
675 | |
676 | psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx; |
677 | |
678 | psecuritypriv->binstallGrpkey = true; |
679 | |
680 | psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;/* */ |
681 | |
682 | rtw_ap_set_group_key(padapter, key: param->u.crypt.key, alg: psecuritypriv->dot118021XGrpPrivacy, keyid: param->u.crypt.idx); |
683 | |
684 | pbcmc_sta = rtw_get_bcmc_stainfo(padapter); |
685 | if (pbcmc_sta) { |
686 | pbcmc_sta->ieee8021x_blocked = false; |
687 | pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy;/* rx will use bmc_sta's dot118021XPrivacy */ |
688 | } |
689 | } |
690 | } |
691 | } |
692 | |
693 | exit: |
694 | |
695 | return ret; |
696 | } |
697 | |
698 | static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len) |
699 | { |
700 | int ret = 0; |
701 | u8 max_idx; |
702 | u32 wep_key_idx, wep_key_len; |
703 | struct adapter *padapter = rtw_netdev_priv(netdev: dev); |
704 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
705 | struct security_priv *psecuritypriv = &padapter->securitypriv; |
706 | |
707 | param->u.crypt.err = 0; |
708 | param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0'; |
709 | |
710 | if (param_len < (u32)((u8 *)param->u.crypt.key - (u8 *)param) + param->u.crypt.key_len) { |
711 | ret = -EINVAL; |
712 | goto exit; |
713 | } |
714 | |
715 | if (param->sta_addr[0] != 0xff || param->sta_addr[1] != 0xff || |
716 | param->sta_addr[2] != 0xff || param->sta_addr[3] != 0xff || |
717 | param->sta_addr[4] != 0xff || param->sta_addr[5] != 0xff) { |
718 | ret = -EINVAL; |
719 | goto exit; |
720 | } |
721 | |
722 | if (strcmp(param->u.crypt.alg, "WEP" ) == 0) |
723 | max_idx = WEP_KEYS - 1; |
724 | else |
725 | max_idx = BIP_MAX_KEYID; |
726 | |
727 | if (param->u.crypt.idx > max_idx) { |
728 | netdev_err(dev, format: "Error crypt.idx %d > %d\n" , param->u.crypt.idx, max_idx); |
729 | ret = -EINVAL; |
730 | goto exit; |
731 | } |
732 | |
733 | if (strcmp(param->u.crypt.alg, "WEP" ) == 0) { |
734 | wep_key_idx = param->u.crypt.idx; |
735 | wep_key_len = param->u.crypt.key_len; |
736 | |
737 | if (wep_key_len <= 0) { |
738 | ret = -EINVAL; |
739 | goto exit; |
740 | } |
741 | |
742 | if (psecuritypriv->bWepDefaultKeyIdxSet == 0) { |
743 | /* wep default key has not been set, so use this key index as default key. */ |
744 | |
745 | wep_key_len = wep_key_len <= 5 ? 5 : 13; |
746 | |
747 | psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled; |
748 | psecuritypriv->dot11PrivacyAlgrthm = _WEP40_; |
749 | psecuritypriv->dot118021XGrpPrivacy = _WEP40_; |
750 | |
751 | if (wep_key_len == 13) { |
752 | psecuritypriv->dot11PrivacyAlgrthm = _WEP104_; |
753 | psecuritypriv->dot118021XGrpPrivacy = _WEP104_; |
754 | } |
755 | |
756 | psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx; |
757 | } |
758 | |
759 | memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len); |
760 | |
761 | psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len; |
762 | |
763 | rtw_set_key(adapter: padapter, psecuritypriv, keyid: wep_key_idx, set_tx: 0, enqueue: true); |
764 | |
765 | goto exit; |
766 | } |
767 | |
768 | if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) { /* 802_1x */ |
769 | struct sta_info *psta, *pbcmc_sta; |
770 | struct sta_priv *pstapriv = &padapter->stapriv; |
771 | |
772 | if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE) == true) { /* sta mode */ |
773 | psta = rtw_get_stainfo(pstapriv, hwaddr: get_bssid(pmlmepriv)); |
774 | if (psta) { |
775 | /* Jeff: don't disable ieee8021x_blocked while clearing key */ |
776 | if (strcmp(param->u.crypt.alg, "none" ) != 0) |
777 | psta->ieee8021x_blocked = false; |
778 | |
779 | if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) || |
780 | (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled)) { |
781 | psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm; |
782 | } |
783 | |
784 | if (param->u.crypt.set_tx == 1) { /* pairwise key */ |
785 | |
786 | memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); |
787 | |
788 | if (strcmp(param->u.crypt.alg, "TKIP" ) == 0) { /* set mic key */ |
789 | /* DEBUG_ERR(("\nset key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len)); */ |
790 | memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8); |
791 | memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8); |
792 | |
793 | padapter->securitypriv.busetkipkey = false; |
794 | /* _set_timer(&padapter->securitypriv.tkip_timer, 50); */ |
795 | } |
796 | |
797 | rtw_setstakey_cmd(padapter, sta: psta, unicast_key: true, enqueue: true); |
798 | } else { /* group key */ |
799 | if (strcmp(param->u.crypt.alg, "TKIP" ) == 0 || strcmp(param->u.crypt.alg, "CCMP" ) == 0) { |
800 | memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); |
801 | memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8); |
802 | memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8); |
803 | padapter->securitypriv.binstallGrpkey = true; |
804 | |
805 | padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx; |
806 | rtw_set_key(adapter: padapter, psecuritypriv: &padapter->securitypriv, keyid: param->u.crypt.idx, set_tx: 1, enqueue: true); |
807 | } else if (strcmp(param->u.crypt.alg, "BIP" ) == 0) { |
808 | /* save the IGTK key, length 16 bytes */ |
809 | memcpy(padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); |
810 | /* |
811 | for (no = 0;no<16;no++) |
812 | printk(" %02x ", padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey[no]); |
813 | */ |
814 | padapter->securitypriv.dot11wBIPKeyid = param->u.crypt.idx; |
815 | padapter->securitypriv.binstallBIPkey = true; |
816 | } |
817 | } |
818 | } |
819 | |
820 | pbcmc_sta = rtw_get_bcmc_stainfo(padapter); |
821 | if (!pbcmc_sta) { |
822 | /* DEBUG_ERR(("Set OID_802_11_ADD_KEY: bcmc stainfo is null\n")); */ |
823 | } else { |
824 | /* Jeff: don't disable ieee8021x_blocked while clearing key */ |
825 | if (strcmp(param->u.crypt.alg, "none" ) != 0) |
826 | pbcmc_sta->ieee8021x_blocked = false; |
827 | |
828 | if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) || |
829 | (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled)) { |
830 | pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm; |
831 | } |
832 | } |
833 | } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { /* adhoc mode */ |
834 | } |
835 | } |
836 | |
837 | exit: |
838 | |
839 | return ret; |
840 | } |
841 | |
842 | static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev, |
843 | int link_id, u8 key_index, bool pairwise, |
844 | const u8 *mac_addr, struct key_params *params) |
845 | { |
846 | char *alg_name; |
847 | u32 param_len; |
848 | struct ieee_param *param = NULL; |
849 | int ret = 0; |
850 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
851 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
852 | |
853 | param_len = sizeof(struct ieee_param) + params->key_len; |
854 | param = rtw_malloc(param_len); |
855 | if (!param) |
856 | return -1; |
857 | |
858 | memset(param, 0, param_len); |
859 | |
860 | param->cmd = IEEE_CMD_SET_ENCRYPTION; |
861 | eth_broadcast_addr(addr: param->sta_addr); |
862 | |
863 | switch (params->cipher) { |
864 | case IW_AUTH_CIPHER_NONE: |
865 | /* todo: remove key */ |
866 | /* remove = 1; */ |
867 | alg_name = "none" ; |
868 | break; |
869 | case WLAN_CIPHER_SUITE_WEP40: |
870 | case WLAN_CIPHER_SUITE_WEP104: |
871 | alg_name = "WEP" ; |
872 | break; |
873 | case WLAN_CIPHER_SUITE_TKIP: |
874 | alg_name = "TKIP" ; |
875 | break; |
876 | case WLAN_CIPHER_SUITE_CCMP: |
877 | alg_name = "CCMP" ; |
878 | break; |
879 | case WLAN_CIPHER_SUITE_AES_CMAC: |
880 | alg_name = "BIP" ; |
881 | break; |
882 | default: |
883 | ret = -ENOTSUPP; |
884 | goto addkey_end; |
885 | } |
886 | |
887 | strncpy(p: (char *)param->u.crypt.alg, q: alg_name, IEEE_CRYPT_ALG_NAME_LEN); |
888 | |
889 | if (!mac_addr || is_broadcast_ether_addr(addr: mac_addr)) |
890 | param->u.crypt.set_tx = 0; /* for wpa/wpa2 group key */ |
891 | else |
892 | param->u.crypt.set_tx = 1; /* for wpa/wpa2 pairwise key */ |
893 | |
894 | param->u.crypt.idx = key_index; |
895 | |
896 | if (params->seq_len && params->seq) |
897 | memcpy(param->u.crypt.seq, (u8 *)params->seq, params->seq_len); |
898 | |
899 | if (params->key_len && params->key) { |
900 | param->u.crypt.key_len = params->key_len; |
901 | memcpy(param->u.crypt.key, (u8 *)params->key, params->key_len); |
902 | } |
903 | |
904 | if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) { |
905 | ret = rtw_cfg80211_set_encryption(dev: ndev, param, param_len); |
906 | } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) { |
907 | if (mac_addr) |
908 | memcpy(param->sta_addr, (void *)mac_addr, ETH_ALEN); |
909 | |
910 | ret = rtw_cfg80211_ap_set_encryption(dev: ndev, param, param_len); |
911 | } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true |
912 | || check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) { |
913 | ret = rtw_cfg80211_set_encryption(dev: ndev, param, param_len); |
914 | } |
915 | |
916 | addkey_end: |
917 | kfree(objp: param); |
918 | |
919 | return ret; |
920 | } |
921 | |
922 | static int cfg80211_rtw_get_key(struct wiphy *wiphy, struct net_device *ndev, |
923 | int link_id, u8 key_index, bool pairwise, |
924 | const u8 *mac_addr, void *cookie, |
925 | void (*callback)(void *cookie, |
926 | struct key_params*)) |
927 | { |
928 | return 0; |
929 | } |
930 | |
931 | static int cfg80211_rtw_del_key(struct wiphy *wiphy, struct net_device *ndev, |
932 | int link_id, u8 key_index, bool pairwise, |
933 | const u8 *mac_addr) |
934 | { |
935 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
936 | struct security_priv *psecuritypriv = &padapter->securitypriv; |
937 | |
938 | if (key_index == psecuritypriv->dot11PrivacyKeyIndex) { |
939 | /* clear the flag of wep default key set. */ |
940 | psecuritypriv->bWepDefaultKeyIdxSet = 0; |
941 | } |
942 | |
943 | return 0; |
944 | } |
945 | |
946 | static int cfg80211_rtw_set_default_key(struct wiphy *wiphy, |
947 | struct net_device *ndev, int link_id, |
948 | u8 key_index, bool unicast, |
949 | bool multicast) |
950 | { |
951 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
952 | struct security_priv *psecuritypriv = &padapter->securitypriv; |
953 | |
954 | if ((key_index < WEP_KEYS) && ((psecuritypriv->dot11PrivacyAlgrthm == _WEP40_) || (psecuritypriv->dot11PrivacyAlgrthm == _WEP104_))) { /* set wep default key */ |
955 | psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled; |
956 | |
957 | psecuritypriv->dot11PrivacyKeyIndex = key_index; |
958 | |
959 | psecuritypriv->dot11PrivacyAlgrthm = _WEP40_; |
960 | psecuritypriv->dot118021XGrpPrivacy = _WEP40_; |
961 | if (psecuritypriv->dot11DefKeylen[key_index] == 13) { |
962 | psecuritypriv->dot11PrivacyAlgrthm = _WEP104_; |
963 | psecuritypriv->dot118021XGrpPrivacy = _WEP104_; |
964 | } |
965 | |
966 | psecuritypriv->bWepDefaultKeyIdxSet = 1; /* set the flag to represent that wep default key has been set */ |
967 | } |
968 | |
969 | return 0; |
970 | } |
971 | |
972 | static int cfg80211_rtw_get_station(struct wiphy *wiphy, |
973 | struct net_device *ndev, |
974 | const u8 *mac, |
975 | struct station_info *sinfo) |
976 | { |
977 | int ret = 0; |
978 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
979 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
980 | struct sta_info *psta = NULL; |
981 | struct sta_priv *pstapriv = &padapter->stapriv; |
982 | |
983 | sinfo->filled = 0; |
984 | |
985 | if (!mac) { |
986 | ret = -ENOENT; |
987 | goto exit; |
988 | } |
989 | |
990 | psta = rtw_get_stainfo(pstapriv, hwaddr: (u8 *)mac); |
991 | if (!psta) { |
992 | ret = -ENOENT; |
993 | goto exit; |
994 | } |
995 | |
996 | /* for infra./P2PClient mode */ |
997 | if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) |
998 | && check_fwstate(pmlmepriv, _FW_LINKED)) { |
999 | struct wlan_network *cur_network = &(pmlmepriv->cur_network); |
1000 | |
1001 | if (memcmp(p: (u8 *)mac, q: cur_network->network.mac_address, ETH_ALEN)) { |
1002 | ret = -ENOENT; |
1003 | goto exit; |
1004 | } |
1005 | |
1006 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL); |
1007 | sinfo->signal = translate_percentage_to_dbm(SignalStrengthIndex: padapter->recvpriv.signal_strength); |
1008 | |
1009 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); |
1010 | sinfo->txrate.legacy = rtw_get_cur_max_rate(adapter: padapter); |
1011 | |
1012 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS); |
1013 | sinfo->rx_packets = sta_rx_data_pkts(psta); |
1014 | |
1015 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS); |
1016 | sinfo->tx_packets = psta->sta_stats.tx_pkts; |
1017 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED); |
1018 | } |
1019 | |
1020 | /* for Ad-Hoc/AP mode */ |
1021 | if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) || |
1022 | check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) || |
1023 | check_fwstate(pmlmepriv, WIFI_AP_STATE)) && |
1024 | check_fwstate(pmlmepriv, _FW_LINKED)) { |
1025 | /* TODO: should acquire station info... */ |
1026 | } |
1027 | |
1028 | exit: |
1029 | return ret; |
1030 | } |
1031 | |
1032 | static int cfg80211_rtw_change_iface(struct wiphy *wiphy, |
1033 | struct net_device *ndev, |
1034 | enum nl80211_iftype type, |
1035 | struct vif_params *params) |
1036 | { |
1037 | enum nl80211_iftype old_type; |
1038 | enum ndis_802_11_network_infrastructure networkType; |
1039 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
1040 | struct wireless_dev *rtw_wdev = padapter->rtw_wdev; |
1041 | struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); |
1042 | int ret = 0; |
1043 | |
1044 | if (adapter_to_dvobj(padapter)->processing_dev_remove == true) { |
1045 | ret = -EPERM; |
1046 | goto exit; |
1047 | } |
1048 | |
1049 | { |
1050 | if (netdev_open(pnetdev: ndev) != 0) { |
1051 | ret = -EPERM; |
1052 | goto exit; |
1053 | } |
1054 | } |
1055 | |
1056 | if (rtw_pwr_wakeup(padapter) == _FAIL) { |
1057 | ret = -EPERM; |
1058 | goto exit; |
1059 | } |
1060 | |
1061 | old_type = rtw_wdev->iftype; |
1062 | |
1063 | if (old_type != type) { |
1064 | pmlmeext->action_public_rxseq = 0xffff; |
1065 | pmlmeext->action_public_dialog_token = 0xff; |
1066 | } |
1067 | |
1068 | switch (type) { |
1069 | case NL80211_IFTYPE_ADHOC: |
1070 | networkType = Ndis802_11IBSS; |
1071 | break; |
1072 | case NL80211_IFTYPE_STATION: |
1073 | networkType = Ndis802_11Infrastructure; |
1074 | break; |
1075 | case NL80211_IFTYPE_AP: |
1076 | networkType = Ndis802_11APMode; |
1077 | break; |
1078 | default: |
1079 | ret = -EOPNOTSUPP; |
1080 | goto exit; |
1081 | } |
1082 | |
1083 | rtw_wdev->iftype = type; |
1084 | |
1085 | if (rtw_set_802_11_infrastructure_mode(padapter, networktype: networkType) == false) { |
1086 | rtw_wdev->iftype = old_type; |
1087 | ret = -EPERM; |
1088 | goto exit; |
1089 | } |
1090 | |
1091 | rtw_setopmode_cmd(padapter, networktype: networkType, enqueue: true); |
1092 | |
1093 | exit: |
1094 | |
1095 | return ret; |
1096 | } |
1097 | |
1098 | void rtw_cfg80211_indicate_scan_done(struct adapter *adapter, bool aborted) |
1099 | { |
1100 | struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(adapter); |
1101 | struct cfg80211_scan_info info = { |
1102 | .aborted = aborted |
1103 | }; |
1104 | |
1105 | spin_lock_bh(lock: &pwdev_priv->scan_req_lock); |
1106 | if (pwdev_priv->scan_request) { |
1107 | /* avoid WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req); */ |
1108 | if (pwdev_priv->scan_request->wiphy == pwdev_priv->rtw_wdev->wiphy) |
1109 | cfg80211_scan_done(request: pwdev_priv->scan_request, info: &info); |
1110 | |
1111 | pwdev_priv->scan_request = NULL; |
1112 | } |
1113 | spin_unlock_bh(lock: &pwdev_priv->scan_req_lock); |
1114 | } |
1115 | |
1116 | void rtw_cfg80211_unlink_bss(struct adapter *padapter, struct wlan_network *pnetwork) |
1117 | { |
1118 | struct wireless_dev *pwdev = padapter->rtw_wdev; |
1119 | struct wiphy *wiphy = pwdev->wiphy; |
1120 | struct cfg80211_bss *bss = NULL; |
1121 | struct wlan_bssid_ex *select_network = &pnetwork->network; |
1122 | |
1123 | bss = cfg80211_get_bss(wiphy, NULL/*notify_channel*/, |
1124 | bssid: select_network->mac_address, |
1125 | ssid: select_network->ssid.ssid, |
1126 | ssid_len: select_network->ssid.ssid_length, |
1127 | bss_type: IEEE80211_BSS_TYPE_ANY, privacy: IEEE80211_PRIVACY_ANY); |
1128 | |
1129 | if (bss) { |
1130 | cfg80211_unlink_bss(wiphy, bss); |
1131 | cfg80211_put_bss(wiphy: padapter->rtw_wdev->wiphy, bss); |
1132 | } |
1133 | } |
1134 | |
1135 | void rtw_cfg80211_surveydone_event_callback(struct adapter *padapter) |
1136 | { |
1137 | struct list_head *plist, *phead; |
1138 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
1139 | struct __queue *queue = &(pmlmepriv->scanned_queue); |
1140 | struct wlan_network *pnetwork = NULL; |
1141 | |
1142 | spin_lock_bh(lock: &(pmlmepriv->scanned_queue.lock)); |
1143 | |
1144 | phead = get_list_head(queue); |
1145 | list_for_each(plist, phead) |
1146 | { |
1147 | pnetwork = list_entry(plist, struct wlan_network, list); |
1148 | |
1149 | /* report network only if the current channel set contains the channel to which this network belongs */ |
1150 | if (rtw_ch_set_search_ch(ch_set: padapter->mlmeextpriv.channel_set, ch: pnetwork->network.configuration.ds_config) >= 0 |
1151 | && true == rtw_validate_ssid(ssid: &(pnetwork->network.ssid))) { |
1152 | /* ev =translate_scan(padapter, a, pnetwork, ev, stop); */ |
1153 | rtw_cfg80211_inform_bss(padapter, pnetwork); |
1154 | } |
1155 | } |
1156 | |
1157 | spin_unlock_bh(lock: &(pmlmepriv->scanned_queue.lock)); |
1158 | } |
1159 | |
1160 | static int rtw_cfg80211_set_probe_req_wpsp2pie(struct adapter *padapter, char *buf, int len) |
1161 | { |
1162 | int ret = 0; |
1163 | uint wps_ielen = 0; |
1164 | u8 *wps_ie; |
1165 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
1166 | |
1167 | if (len > 0) { |
1168 | wps_ie = rtw_get_wps_ie(in_ie: buf, in_len: len, NULL, wps_ielen: &wps_ielen); |
1169 | if (wps_ie) { |
1170 | if (pmlmepriv->wps_probe_req_ie) { |
1171 | pmlmepriv->wps_probe_req_ie_len = 0; |
1172 | kfree(objp: pmlmepriv->wps_probe_req_ie); |
1173 | pmlmepriv->wps_probe_req_ie = NULL; |
1174 | } |
1175 | |
1176 | pmlmepriv->wps_probe_req_ie = rtw_malloc(wps_ielen); |
1177 | if (!pmlmepriv->wps_probe_req_ie) |
1178 | return -EINVAL; |
1179 | |
1180 | memcpy(pmlmepriv->wps_probe_req_ie, wps_ie, wps_ielen); |
1181 | pmlmepriv->wps_probe_req_ie_len = wps_ielen; |
1182 | } |
1183 | } |
1184 | |
1185 | return ret; |
1186 | } |
1187 | |
1188 | static int cfg80211_rtw_scan(struct wiphy *wiphy |
1189 | , struct cfg80211_scan_request *request) |
1190 | { |
1191 | struct net_device *ndev = wdev_to_ndev(request->wdev); |
1192 | int i; |
1193 | u8 _status = false; |
1194 | int ret = 0; |
1195 | struct ndis_802_11_ssid *ssid = NULL; |
1196 | struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT]; |
1197 | u8 survey_times = 3; |
1198 | u8 survey_times_for_one_ch = 6; |
1199 | struct cfg80211_ssid *ssids = request->ssids; |
1200 | int j = 0; |
1201 | bool need_indicate_scan_done = false; |
1202 | |
1203 | struct adapter *padapter; |
1204 | struct rtw_wdev_priv *pwdev_priv; |
1205 | struct mlme_priv *pmlmepriv; |
1206 | |
1207 | if (!ndev) { |
1208 | ret = -EINVAL; |
1209 | goto exit; |
1210 | } |
1211 | |
1212 | padapter = rtw_netdev_priv(netdev: ndev); |
1213 | pwdev_priv = adapter_wdev_data(padapter); |
1214 | pmlmepriv = &padapter->mlmepriv; |
1215 | /* endif */ |
1216 | |
1217 | spin_lock_bh(lock: &pwdev_priv->scan_req_lock); |
1218 | pwdev_priv->scan_request = request; |
1219 | spin_unlock_bh(lock: &pwdev_priv->scan_req_lock); |
1220 | |
1221 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) { |
1222 | if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS | _FW_UNDER_SURVEY | _FW_UNDER_LINKING) == true) { |
1223 | need_indicate_scan_done = true; |
1224 | goto check_need_indicate_scan_done; |
1225 | } |
1226 | } |
1227 | |
1228 | rtw_ps_deny(padapter, reason: PS_DENY_SCAN); |
1229 | if (rtw_pwr_wakeup(padapter) == _FAIL) { |
1230 | need_indicate_scan_done = true; |
1231 | goto check_need_indicate_scan_done; |
1232 | } |
1233 | |
1234 | if (request->ie && request->ie_len > 0) |
1235 | rtw_cfg80211_set_probe_req_wpsp2pie(padapter, buf: (u8 *)request->ie, len: request->ie_len); |
1236 | |
1237 | if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true) { |
1238 | need_indicate_scan_done = true; |
1239 | goto check_need_indicate_scan_done; |
1240 | } else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true) { |
1241 | ret = -EBUSY; |
1242 | goto check_need_indicate_scan_done; |
1243 | } |
1244 | |
1245 | if (pmlmepriv->LinkDetectInfo.bBusyTraffic == true) { |
1246 | static unsigned long lastscantime; |
1247 | unsigned long passtime; |
1248 | |
1249 | passtime = jiffies_to_msecs(j: jiffies - lastscantime); |
1250 | lastscantime = jiffies; |
1251 | if (passtime > 12000) { |
1252 | need_indicate_scan_done = true; |
1253 | goto check_need_indicate_scan_done; |
1254 | } |
1255 | } |
1256 | |
1257 | if (rtw_is_scan_deny(adapter: padapter)) { |
1258 | need_indicate_scan_done = true; |
1259 | goto check_need_indicate_scan_done; |
1260 | } |
1261 | |
1262 | ssid = kcalloc(RTW_SSID_SCAN_AMOUNT, size: sizeof(*ssid), GFP_KERNEL); |
1263 | if (!ssid) { |
1264 | ret = -ENOMEM; |
1265 | goto check_need_indicate_scan_done; |
1266 | } |
1267 | |
1268 | /* parsing request ssids, n_ssids */ |
1269 | for (i = 0; i < request->n_ssids && i < RTW_SSID_SCAN_AMOUNT; i++) { |
1270 | memcpy(ssid[i].ssid, ssids[i].ssid, ssids[i].ssid_len); |
1271 | ssid[i].ssid_length = ssids[i].ssid_len; |
1272 | } |
1273 | |
1274 | /* parsing channels, n_channels */ |
1275 | memset(ch, 0, sizeof(struct rtw_ieee80211_channel) * RTW_CHANNEL_SCAN_AMOUNT); |
1276 | for (i = 0; i < request->n_channels && i < RTW_CHANNEL_SCAN_AMOUNT; i++) { |
1277 | ch[i].hw_value = request->channels[i]->hw_value; |
1278 | ch[i].flags = request->channels[i]->flags; |
1279 | } |
1280 | |
1281 | spin_lock_bh(lock: &pmlmepriv->lock); |
1282 | if (request->n_channels == 1) { |
1283 | for (i = 1; i < survey_times_for_one_ch; i++) |
1284 | memcpy(&ch[i], &ch[0], sizeof(struct rtw_ieee80211_channel)); |
1285 | _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, ch, ch_num: survey_times_for_one_ch); |
1286 | } else if (request->n_channels <= 4) { |
1287 | for (j = request->n_channels - 1; j >= 0; j--) |
1288 | for (i = 0; i < survey_times; i++) |
1289 | memcpy(&ch[j * survey_times + i], &ch[j], sizeof(struct rtw_ieee80211_channel)); |
1290 | _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, ch, ch_num: survey_times * request->n_channels); |
1291 | } else { |
1292 | _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, NULL, ch_num: 0); |
1293 | } |
1294 | spin_unlock_bh(lock: &pmlmepriv->lock); |
1295 | |
1296 | if (_status == false) |
1297 | ret = -1; |
1298 | |
1299 | check_need_indicate_scan_done: |
1300 | kfree(objp: ssid); |
1301 | if (need_indicate_scan_done) { |
1302 | rtw_cfg80211_surveydone_event_callback(padapter); |
1303 | rtw_cfg80211_indicate_scan_done(adapter: padapter, aborted: false); |
1304 | } |
1305 | |
1306 | rtw_ps_deny_cancel(padapter, reason: PS_DENY_SCAN); |
1307 | |
1308 | exit: |
1309 | return ret; |
1310 | } |
1311 | |
1312 | static int cfg80211_rtw_set_wiphy_params(struct wiphy *wiphy, u32 changed) |
1313 | { |
1314 | return 0; |
1315 | } |
1316 | |
1317 | static int rtw_cfg80211_set_wpa_version(struct security_priv *psecuritypriv, u32 wpa_version) |
1318 | { |
1319 | if (!wpa_version) { |
1320 | psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen; |
1321 | return 0; |
1322 | } |
1323 | |
1324 | if (wpa_version & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2)) |
1325 | psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPAPSK; |
1326 | |
1327 | return 0; |
1328 | } |
1329 | |
1330 | static int rtw_cfg80211_set_auth_type(struct security_priv *psecuritypriv, |
1331 | enum nl80211_auth_type sme_auth_type) |
1332 | { |
1333 | switch (sme_auth_type) { |
1334 | case NL80211_AUTHTYPE_AUTOMATIC: |
1335 | |
1336 | psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto; |
1337 | |
1338 | break; |
1339 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
1340 | |
1341 | psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; |
1342 | |
1343 | if (psecuritypriv->ndisauthtype > Ndis802_11AuthModeWPA) |
1344 | psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; |
1345 | |
1346 | break; |
1347 | case NL80211_AUTHTYPE_SHARED_KEY: |
1348 | |
1349 | psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Shared; |
1350 | |
1351 | psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled; |
1352 | |
1353 | break; |
1354 | default: |
1355 | psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; |
1356 | /* return -ENOTSUPP; */ |
1357 | } |
1358 | |
1359 | return 0; |
1360 | } |
1361 | |
1362 | static int rtw_cfg80211_set_cipher(struct security_priv *psecuritypriv, u32 cipher, bool ucast) |
1363 | { |
1364 | u32 ndisencryptstatus = Ndis802_11EncryptionDisabled; |
1365 | |
1366 | u32 *profile_cipher = ucast ? &psecuritypriv->dot11PrivacyAlgrthm : |
1367 | &psecuritypriv->dot118021XGrpPrivacy; |
1368 | |
1369 | if (!cipher) { |
1370 | *profile_cipher = _NO_PRIVACY_; |
1371 | psecuritypriv->ndisencryptstatus = ndisencryptstatus; |
1372 | return 0; |
1373 | } |
1374 | |
1375 | switch (cipher) { |
1376 | case IW_AUTH_CIPHER_NONE: |
1377 | *profile_cipher = _NO_PRIVACY_; |
1378 | ndisencryptstatus = Ndis802_11EncryptionDisabled; |
1379 | break; |
1380 | case WLAN_CIPHER_SUITE_WEP40: |
1381 | *profile_cipher = _WEP40_; |
1382 | ndisencryptstatus = Ndis802_11Encryption1Enabled; |
1383 | break; |
1384 | case WLAN_CIPHER_SUITE_WEP104: |
1385 | *profile_cipher = _WEP104_; |
1386 | ndisencryptstatus = Ndis802_11Encryption1Enabled; |
1387 | break; |
1388 | case WLAN_CIPHER_SUITE_TKIP: |
1389 | *profile_cipher = _TKIP_; |
1390 | ndisencryptstatus = Ndis802_11Encryption2Enabled; |
1391 | break; |
1392 | case WLAN_CIPHER_SUITE_CCMP: |
1393 | *profile_cipher = _AES_; |
1394 | ndisencryptstatus = Ndis802_11Encryption3Enabled; |
1395 | break; |
1396 | default: |
1397 | return -ENOTSUPP; |
1398 | } |
1399 | |
1400 | if (ucast) { |
1401 | psecuritypriv->ndisencryptstatus = ndisencryptstatus; |
1402 | |
1403 | /* if (psecuritypriv->dot11PrivacyAlgrthm >= _AES_) */ |
1404 | /* psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK; */ |
1405 | } |
1406 | |
1407 | return 0; |
1408 | } |
1409 | |
1410 | static int rtw_cfg80211_set_key_mgt(struct security_priv *psecuritypriv, u32 key_mgt) |
1411 | { |
1412 | if (key_mgt == WLAN_AKM_SUITE_8021X) |
1413 | /* auth_type = UMAC_AUTH_TYPE_8021X; */ |
1414 | psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; |
1415 | else if (key_mgt == WLAN_AKM_SUITE_PSK) { |
1416 | psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; |
1417 | } |
1418 | |
1419 | return 0; |
1420 | } |
1421 | |
1422 | static int rtw_cfg80211_set_wpa_ie(struct adapter *padapter, u8 *pie, size_t ielen) |
1423 | { |
1424 | u8 *buf = NULL; |
1425 | int group_cipher = 0, pairwise_cipher = 0; |
1426 | int ret = 0; |
1427 | int wpa_ielen = 0; |
1428 | int wpa2_ielen = 0; |
1429 | u8 *pwpa, *pwpa2; |
1430 | u8 null_addr[] = {0, 0, 0, 0, 0, 0}; |
1431 | |
1432 | if (!pie || !ielen) { |
1433 | /* Treat this as normal case, but need to clear WIFI_UNDER_WPS */ |
1434 | _clr_fwstate_(pmlmepriv: &padapter->mlmepriv, WIFI_UNDER_WPS); |
1435 | goto exit; |
1436 | } |
1437 | |
1438 | if (ielen > MAX_WPA_IE_LEN + MAX_WPS_IE_LEN + MAX_P2P_IE_LEN) { |
1439 | ret = -EINVAL; |
1440 | goto exit; |
1441 | } |
1442 | |
1443 | buf = rtw_zmalloc(ielen); |
1444 | if (!buf) { |
1445 | ret = -ENOMEM; |
1446 | goto exit; |
1447 | } |
1448 | |
1449 | memcpy(buf, pie, ielen); |
1450 | |
1451 | if (ielen < RSN_HEADER_LEN) { |
1452 | ret = -1; |
1453 | goto exit; |
1454 | } |
1455 | |
1456 | pwpa = rtw_get_wpa_ie(pie: buf, wpa_ie_len: &wpa_ielen, limit: ielen); |
1457 | if (pwpa && wpa_ielen > 0) { |
1458 | if (rtw_parse_wpa_ie(wpa_ie: pwpa, wpa_ie_len: wpa_ielen + 2, group_cipher: &group_cipher, pairwise_cipher: &pairwise_cipher, NULL) == _SUCCESS) { |
1459 | padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; |
1460 | padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK; |
1461 | memcpy(padapter->securitypriv.supplicant_ie, &pwpa[0], wpa_ielen + 2); |
1462 | } |
1463 | } |
1464 | |
1465 | pwpa2 = rtw_get_wpa2_ie(pie: buf, rsn_ie_len: &wpa2_ielen, limit: ielen); |
1466 | if (pwpa2 && wpa2_ielen > 0) { |
1467 | if (rtw_parse_wpa2_ie(wpa_ie: pwpa2, wpa_ie_len: wpa2_ielen + 2, group_cipher: &group_cipher, pairwise_cipher: &pairwise_cipher, NULL) == _SUCCESS) { |
1468 | padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; |
1469 | padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK; |
1470 | memcpy(padapter->securitypriv.supplicant_ie, &pwpa2[0], wpa2_ielen + 2); |
1471 | } |
1472 | } |
1473 | |
1474 | if (group_cipher == 0) |
1475 | group_cipher = WPA_CIPHER_NONE; |
1476 | |
1477 | if (pairwise_cipher == 0) |
1478 | pairwise_cipher = WPA_CIPHER_NONE; |
1479 | |
1480 | switch (group_cipher) { |
1481 | case WPA_CIPHER_NONE: |
1482 | padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_; |
1483 | padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled; |
1484 | break; |
1485 | case WPA_CIPHER_WEP40: |
1486 | padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_; |
1487 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; |
1488 | break; |
1489 | case WPA_CIPHER_TKIP: |
1490 | padapter->securitypriv.dot118021XGrpPrivacy = _TKIP_; |
1491 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled; |
1492 | break; |
1493 | case WPA_CIPHER_CCMP: |
1494 | padapter->securitypriv.dot118021XGrpPrivacy = _AES_; |
1495 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled; |
1496 | break; |
1497 | case WPA_CIPHER_WEP104: |
1498 | padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_; |
1499 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; |
1500 | break; |
1501 | } |
1502 | |
1503 | switch (pairwise_cipher) { |
1504 | case WPA_CIPHER_NONE: |
1505 | padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_; |
1506 | padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled; |
1507 | break; |
1508 | case WPA_CIPHER_WEP40: |
1509 | padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_; |
1510 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; |
1511 | break; |
1512 | case WPA_CIPHER_TKIP: |
1513 | padapter->securitypriv.dot11PrivacyAlgrthm = _TKIP_; |
1514 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled; |
1515 | break; |
1516 | case WPA_CIPHER_CCMP: |
1517 | padapter->securitypriv.dot11PrivacyAlgrthm = _AES_; |
1518 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled; |
1519 | break; |
1520 | case WPA_CIPHER_WEP104: |
1521 | padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_; |
1522 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; |
1523 | break; |
1524 | } |
1525 | |
1526 | {/* handle wps_ie */ |
1527 | uint wps_ielen; |
1528 | u8 *wps_ie; |
1529 | |
1530 | wps_ie = rtw_get_wps_ie(in_ie: buf, in_len: ielen, NULL, wps_ielen: &wps_ielen); |
1531 | if (wps_ie && wps_ielen > 0) { |
1532 | padapter->securitypriv.wps_ie_len = min_t(uint, wps_ielen, MAX_WPS_IE_LEN); |
1533 | memcpy(padapter->securitypriv.wps_ie, wps_ie, padapter->securitypriv.wps_ie_len); |
1534 | set_fwstate(pmlmepriv: &padapter->mlmepriv, WIFI_UNDER_WPS); |
1535 | } else { |
1536 | _clr_fwstate_(pmlmepriv: &padapter->mlmepriv, WIFI_UNDER_WPS); |
1537 | } |
1538 | } |
1539 | |
1540 | /* TKIP and AES disallow multicast packets until installing group key */ |
1541 | if (padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_ |
1542 | || padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_WTMIC_ |
1543 | || padapter->securitypriv.dot11PrivacyAlgrthm == _AES_) |
1544 | /* WPS open need to enable multicast */ |
1545 | /* check_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS) == true) */ |
1546 | rtw_hal_set_hwreg(padapter, variable: HW_VAR_OFF_RCR_AM, val: null_addr); |
1547 | |
1548 | exit: |
1549 | kfree(objp: buf); |
1550 | if (ret) |
1551 | _clr_fwstate_(pmlmepriv: &padapter->mlmepriv, WIFI_UNDER_WPS); |
1552 | return ret; |
1553 | } |
1554 | |
1555 | static int cfg80211_rtw_join_ibss(struct wiphy *wiphy, struct net_device *ndev, |
1556 | struct cfg80211_ibss_params *params) |
1557 | { |
1558 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
1559 | struct ndis_802_11_ssid ndis_ssid; |
1560 | struct security_priv *psecuritypriv = &padapter->securitypriv; |
1561 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
1562 | int ret = 0; |
1563 | |
1564 | if (rtw_pwr_wakeup(padapter) == _FAIL) { |
1565 | ret = -EPERM; |
1566 | goto exit; |
1567 | } |
1568 | |
1569 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { |
1570 | ret = -EPERM; |
1571 | goto exit; |
1572 | } |
1573 | |
1574 | if (!params->ssid || !params->ssid_len) { |
1575 | ret = -EINVAL; |
1576 | goto exit; |
1577 | } |
1578 | |
1579 | if (params->ssid_len > IW_ESSID_MAX_SIZE) { |
1580 | ret = -E2BIG; |
1581 | goto exit; |
1582 | } |
1583 | |
1584 | memset(&ndis_ssid, 0, sizeof(struct ndis_802_11_ssid)); |
1585 | ndis_ssid.ssid_length = params->ssid_len; |
1586 | memcpy(ndis_ssid.ssid, (u8 *)params->ssid, params->ssid_len); |
1587 | |
1588 | psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled; |
1589 | psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_; |
1590 | psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; |
1591 | psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */ |
1592 | psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen; |
1593 | |
1594 | ret = rtw_cfg80211_set_auth_type(psecuritypriv, sme_auth_type: NL80211_AUTHTYPE_OPEN_SYSTEM); |
1595 | rtw_set_802_11_authentication_mode(pdapter: padapter, authmode: psecuritypriv->ndisauthtype); |
1596 | |
1597 | if (rtw_set_802_11_ssid(padapter, ssid: &ndis_ssid) == false) { |
1598 | ret = -1; |
1599 | goto exit; |
1600 | } |
1601 | |
1602 | exit: |
1603 | return ret; |
1604 | } |
1605 | |
1606 | static int cfg80211_rtw_leave_ibss(struct wiphy *wiphy, struct net_device *ndev) |
1607 | { |
1608 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
1609 | struct wireless_dev *rtw_wdev = padapter->rtw_wdev; |
1610 | enum nl80211_iftype old_type; |
1611 | int ret = 0; |
1612 | |
1613 | old_type = rtw_wdev->iftype; |
1614 | |
1615 | rtw_set_to_roam(adapter: padapter, to_roam: 0); |
1616 | |
1617 | if (check_fwstate(pmlmepriv: &padapter->mlmepriv, _FW_LINKED)) { |
1618 | rtw_scan_abort(adapter: padapter); |
1619 | LeaveAllPowerSaveMode(Adapter: padapter); |
1620 | |
1621 | rtw_wdev->iftype = NL80211_IFTYPE_STATION; |
1622 | |
1623 | if (rtw_set_802_11_infrastructure_mode(padapter, networktype: Ndis802_11Infrastructure) == false) { |
1624 | rtw_wdev->iftype = old_type; |
1625 | ret = -EPERM; |
1626 | goto leave_ibss; |
1627 | } |
1628 | rtw_setopmode_cmd(padapter, networktype: Ndis802_11Infrastructure, enqueue: true); |
1629 | } |
1630 | |
1631 | leave_ibss: |
1632 | return ret; |
1633 | } |
1634 | |
1635 | static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev, |
1636 | struct cfg80211_connect_params *sme) |
1637 | { |
1638 | int ret = 0; |
1639 | enum ndis_802_11_authentication_mode authmode; |
1640 | struct ndis_802_11_ssid ndis_ssid; |
1641 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
1642 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
1643 | struct security_priv *psecuritypriv = &padapter->securitypriv; |
1644 | |
1645 | padapter->mlmepriv.not_indic_disco = true; |
1646 | |
1647 | if (adapter_wdev_data(padapter)->block == true) { |
1648 | ret = -EBUSY; |
1649 | goto exit; |
1650 | } |
1651 | |
1652 | rtw_ps_deny(padapter, reason: PS_DENY_JOIN); |
1653 | if (rtw_pwr_wakeup(padapter) == _FAIL) { |
1654 | ret = -EPERM; |
1655 | goto exit; |
1656 | } |
1657 | |
1658 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { |
1659 | ret = -EPERM; |
1660 | goto exit; |
1661 | } |
1662 | |
1663 | if (!sme->ssid || !sme->ssid_len) { |
1664 | ret = -EINVAL; |
1665 | goto exit; |
1666 | } |
1667 | |
1668 | if (sme->ssid_len > IW_ESSID_MAX_SIZE) { |
1669 | ret = -E2BIG; |
1670 | goto exit; |
1671 | } |
1672 | |
1673 | memset(&ndis_ssid, 0, sizeof(struct ndis_802_11_ssid)); |
1674 | ndis_ssid.ssid_length = sme->ssid_len; |
1675 | memcpy(ndis_ssid.ssid, (u8 *)sme->ssid, sme->ssid_len); |
1676 | |
1677 | if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true) { |
1678 | ret = -EBUSY; |
1679 | goto exit; |
1680 | } |
1681 | if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true) |
1682 | rtw_scan_abort(adapter: padapter); |
1683 | |
1684 | psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled; |
1685 | psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_; |
1686 | psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; |
1687 | psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */ |
1688 | psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen; |
1689 | |
1690 | ret = rtw_cfg80211_set_wpa_version(psecuritypriv, wpa_version: sme->crypto.wpa_versions); |
1691 | if (ret < 0) |
1692 | goto exit; |
1693 | |
1694 | ret = rtw_cfg80211_set_auth_type(psecuritypriv, sme_auth_type: sme->auth_type); |
1695 | |
1696 | if (ret < 0) |
1697 | goto exit; |
1698 | |
1699 | ret = rtw_cfg80211_set_wpa_ie(padapter, pie: (u8 *)sme->ie, ielen: sme->ie_len); |
1700 | if (ret < 0) |
1701 | goto exit; |
1702 | |
1703 | if (sme->crypto.n_ciphers_pairwise) { |
1704 | ret = rtw_cfg80211_set_cipher(psecuritypriv, cipher: sme->crypto.ciphers_pairwise[0], ucast: true); |
1705 | if (ret < 0) |
1706 | goto exit; |
1707 | } |
1708 | |
1709 | /* For WEP Shared auth */ |
1710 | if ((psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Shared || |
1711 | psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Auto) && sme->key) { |
1712 | u32 wep_key_idx, wep_key_len, wep_total_len; |
1713 | struct ndis_802_11_wep *pwep = NULL; |
1714 | |
1715 | wep_key_idx = sme->key_idx; |
1716 | wep_key_len = sme->key_len; |
1717 | |
1718 | if (sme->key_idx > WEP_KEYS) { |
1719 | ret = -EINVAL; |
1720 | goto exit; |
1721 | } |
1722 | |
1723 | if (wep_key_len > 0) { |
1724 | wep_key_len = wep_key_len <= 5 ? 5 : 13; |
1725 | wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, key_material); |
1726 | pwep = rtw_malloc(wep_total_len); |
1727 | if (!pwep) { |
1728 | ret = -ENOMEM; |
1729 | goto exit; |
1730 | } |
1731 | |
1732 | memset(pwep, 0, wep_total_len); |
1733 | |
1734 | pwep->key_length = wep_key_len; |
1735 | pwep->length = wep_total_len; |
1736 | |
1737 | if (wep_key_len == 13) { |
1738 | padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_; |
1739 | padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_; |
1740 | } |
1741 | } else { |
1742 | ret = -EINVAL; |
1743 | goto exit; |
1744 | } |
1745 | |
1746 | pwep->key_index = wep_key_idx; |
1747 | pwep->key_index |= 0x80000000; |
1748 | |
1749 | memcpy(pwep->key_material, (void *)sme->key, pwep->key_length); |
1750 | |
1751 | if (rtw_set_802_11_add_wep(padapter, wep: pwep) == (u8)_FAIL) |
1752 | ret = -EOPNOTSUPP; |
1753 | |
1754 | kfree(objp: pwep); |
1755 | |
1756 | if (ret < 0) |
1757 | goto exit; |
1758 | } |
1759 | |
1760 | ret = rtw_cfg80211_set_cipher(psecuritypriv, cipher: sme->crypto.cipher_group, ucast: false); |
1761 | if (ret < 0) |
1762 | return ret; |
1763 | |
1764 | if (sme->crypto.n_akm_suites) { |
1765 | ret = rtw_cfg80211_set_key_mgt(psecuritypriv, key_mgt: sme->crypto.akm_suites[0]); |
1766 | if (ret < 0) |
1767 | goto exit; |
1768 | } |
1769 | |
1770 | authmode = psecuritypriv->ndisauthtype; |
1771 | rtw_set_802_11_authentication_mode(pdapter: padapter, authmode); |
1772 | |
1773 | /* rtw_set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus); */ |
1774 | |
1775 | if (rtw_set_802_11_connect(padapter, bssid: (u8 *)sme->bssid, ssid: &ndis_ssid) == false) { |
1776 | ret = -1; |
1777 | goto exit; |
1778 | } |
1779 | |
1780 | exit: |
1781 | |
1782 | rtw_ps_deny_cancel(padapter, reason: PS_DENY_JOIN); |
1783 | |
1784 | padapter->mlmepriv.not_indic_disco = false; |
1785 | |
1786 | return ret; |
1787 | } |
1788 | |
1789 | static int cfg80211_rtw_disconnect(struct wiphy *wiphy, struct net_device *ndev, |
1790 | u16 reason_code) |
1791 | { |
1792 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
1793 | |
1794 | rtw_set_to_roam(adapter: padapter, to_roam: 0); |
1795 | |
1796 | rtw_scan_abort(adapter: padapter); |
1797 | LeaveAllPowerSaveMode(Adapter: padapter); |
1798 | rtw_disassoc_cmd(padapter, deauth_timeout_ms: 500, enqueue: false); |
1799 | |
1800 | rtw_indicate_disconnect(adapter: padapter); |
1801 | |
1802 | rtw_free_assoc_resources(adapter: padapter, lock_scanned_queue: 1); |
1803 | rtw_pwr_wakeup(padapter); |
1804 | |
1805 | return 0; |
1806 | } |
1807 | |
1808 | static int cfg80211_rtw_set_txpower(struct wiphy *wiphy, |
1809 | struct wireless_dev *wdev, |
1810 | enum nl80211_tx_power_setting type, int mbm) |
1811 | { |
1812 | return 0; |
1813 | } |
1814 | |
1815 | static int cfg80211_rtw_get_txpower(struct wiphy *wiphy, |
1816 | struct wireless_dev *wdev, int *dbm) |
1817 | { |
1818 | *dbm = (12); |
1819 | |
1820 | return 0; |
1821 | } |
1822 | |
1823 | inline bool rtw_cfg80211_pwr_mgmt(struct adapter *adapter) |
1824 | { |
1825 | struct rtw_wdev_priv *rtw_wdev_priv = adapter_wdev_data(adapter); |
1826 | |
1827 | return rtw_wdev_priv->power_mgmt; |
1828 | } |
1829 | |
1830 | static int cfg80211_rtw_set_power_mgmt(struct wiphy *wiphy, |
1831 | struct net_device *ndev, |
1832 | bool enabled, int timeout) |
1833 | { |
1834 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
1835 | struct rtw_wdev_priv *rtw_wdev_priv = adapter_wdev_data(padapter); |
1836 | |
1837 | rtw_wdev_priv->power_mgmt = enabled; |
1838 | |
1839 | if (!enabled) |
1840 | LPS_Leave(padapter, msg: "CFG80211_PWRMGMT" ); |
1841 | |
1842 | return 0; |
1843 | } |
1844 | |
1845 | static int cfg80211_rtw_set_pmksa(struct wiphy *wiphy, |
1846 | struct net_device *ndev, |
1847 | struct cfg80211_pmksa *pmksa) |
1848 | { |
1849 | u8 index, blInserted = false; |
1850 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
1851 | struct security_priv *psecuritypriv = &padapter->securitypriv; |
1852 | |
1853 | if (is_zero_ether_addr(addr: (u8 *)pmksa->bssid)) |
1854 | return -EINVAL; |
1855 | |
1856 | blInserted = false; |
1857 | |
1858 | /* overwrite PMKID */ |
1859 | for (index = 0 ; index < NUM_PMKID_CACHE; index++) { |
1860 | if (!memcmp(p: psecuritypriv->PMKIDList[index].Bssid, q: (u8 *)pmksa->bssid, ETH_ALEN)) { |
1861 | memcpy(psecuritypriv->PMKIDList[index].PMKID, (u8 *)pmksa->pmkid, WLAN_PMKID_LEN); |
1862 | psecuritypriv->PMKIDList[index].bUsed = true; |
1863 | psecuritypriv->PMKIDIndex = index + 1; |
1864 | blInserted = true; |
1865 | break; |
1866 | } |
1867 | } |
1868 | |
1869 | if (!blInserted) { |
1870 | memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].Bssid, (u8 *)pmksa->bssid, ETH_ALEN); |
1871 | memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, (u8 *)pmksa->pmkid, WLAN_PMKID_LEN); |
1872 | |
1873 | psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = true; |
1874 | psecuritypriv->PMKIDIndex++; |
1875 | if (psecuritypriv->PMKIDIndex == 16) |
1876 | psecuritypriv->PMKIDIndex = 0; |
1877 | } |
1878 | |
1879 | return 0; |
1880 | } |
1881 | |
1882 | static int cfg80211_rtw_del_pmksa(struct wiphy *wiphy, |
1883 | struct net_device *ndev, |
1884 | struct cfg80211_pmksa *pmksa) |
1885 | { |
1886 | u8 index, bMatched = false; |
1887 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
1888 | struct security_priv *psecuritypriv = &padapter->securitypriv; |
1889 | |
1890 | for (index = 0 ; index < NUM_PMKID_CACHE; index++) { |
1891 | if (!memcmp(p: psecuritypriv->PMKIDList[index].Bssid, q: (u8 *)pmksa->bssid, ETH_ALEN)) { |
1892 | /* |
1893 | * BSSID is matched, the same AP => Remove this PMKID information |
1894 | * and reset it. |
1895 | */ |
1896 | eth_zero_addr(addr: psecuritypriv->PMKIDList[index].Bssid); |
1897 | memset(psecuritypriv->PMKIDList[index].PMKID, 0x00, WLAN_PMKID_LEN); |
1898 | psecuritypriv->PMKIDList[index].bUsed = false; |
1899 | bMatched = true; |
1900 | break; |
1901 | } |
1902 | } |
1903 | |
1904 | if (!bMatched) |
1905 | return -EINVAL; |
1906 | |
1907 | return 0; |
1908 | } |
1909 | |
1910 | static int cfg80211_rtw_flush_pmksa(struct wiphy *wiphy, |
1911 | struct net_device *ndev) |
1912 | { |
1913 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
1914 | struct security_priv *psecuritypriv = &padapter->securitypriv; |
1915 | |
1916 | memset(&psecuritypriv->PMKIDList[0], 0x00, sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE); |
1917 | psecuritypriv->PMKIDIndex = 0; |
1918 | |
1919 | return 0; |
1920 | } |
1921 | |
1922 | void rtw_cfg80211_indicate_sta_assoc(struct adapter *padapter, u8 *pmgmt_frame, uint frame_len) |
1923 | { |
1924 | struct net_device *ndev = padapter->pnetdev; |
1925 | |
1926 | { |
1927 | struct station_info sinfo = {}; |
1928 | u8 ie_offset; |
1929 | |
1930 | if (GetFrameSubType(pmgmt_frame) == WIFI_ASSOCREQ) |
1931 | ie_offset = _ASOCREQ_IE_OFFSET_; |
1932 | else /* WIFI_REASSOCREQ */ |
1933 | ie_offset = _REASOCREQ_IE_OFFSET_; |
1934 | |
1935 | sinfo.filled = 0; |
1936 | sinfo.assoc_req_ies = pmgmt_frame + WLAN_HDR_A3_LEN + ie_offset; |
1937 | sinfo.assoc_req_ies_len = frame_len - WLAN_HDR_A3_LEN - ie_offset; |
1938 | cfg80211_new_sta(dev: ndev, GetAddr2Ptr(pmgmt_frame), sinfo: &sinfo, GFP_ATOMIC); |
1939 | } |
1940 | } |
1941 | |
1942 | void rtw_cfg80211_indicate_sta_disassoc(struct adapter *padapter, unsigned char *da, unsigned short reason) |
1943 | { |
1944 | struct net_device *ndev = padapter->pnetdev; |
1945 | |
1946 | cfg80211_del_sta(dev: ndev, mac_addr: da, GFP_ATOMIC); |
1947 | } |
1948 | |
1949 | static u8 rtw_get_chan_type(struct adapter *adapter) |
1950 | { |
1951 | struct mlme_ext_priv *mlme_ext = &adapter->mlmeextpriv; |
1952 | |
1953 | switch (mlme_ext->cur_bwmode) { |
1954 | case CHANNEL_WIDTH_20: |
1955 | if (is_supported_ht(adapter->registrypriv.wireless_mode)) |
1956 | return NL80211_CHAN_HT20; |
1957 | else |
1958 | return NL80211_CHAN_NO_HT; |
1959 | case CHANNEL_WIDTH_40: |
1960 | if (mlme_ext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER) |
1961 | return NL80211_CHAN_HT40PLUS; |
1962 | else |
1963 | return NL80211_CHAN_HT40MINUS; |
1964 | default: |
1965 | return NL80211_CHAN_HT20; |
1966 | } |
1967 | |
1968 | return NL80211_CHAN_HT20; |
1969 | } |
1970 | |
1971 | static int cfg80211_rtw_get_channel(struct wiphy *wiphy, struct wireless_dev *wdev, |
1972 | unsigned int link_id, |
1973 | struct cfg80211_chan_def *chandef) |
1974 | { |
1975 | struct adapter *adapter = wiphy_to_adapter(wiphy); |
1976 | struct registry_priv *registrypriv = &adapter->registrypriv; |
1977 | enum nl80211_channel_type chan_type; |
1978 | struct ieee80211_channel *chan = NULL; |
1979 | int channel; |
1980 | int freq; |
1981 | |
1982 | if (!adapter->rtw_wdev) |
1983 | return -ENODEV; |
1984 | |
1985 | channel = rtw_get_oper_ch(adapter); |
1986 | if (!channel) |
1987 | return -ENODATA; |
1988 | |
1989 | freq = rtw_ieee80211_channel_to_frequency(chan: channel, band: NL80211_BAND_2GHZ); |
1990 | |
1991 | chan = ieee80211_get_channel(wiphy: adapter->rtw_wdev->wiphy, freq); |
1992 | |
1993 | if (registrypriv->ht_enable) { |
1994 | chan_type = rtw_get_chan_type(adapter); |
1995 | cfg80211_chandef_create(chandef, channel: chan, chantype: chan_type); |
1996 | } else { |
1997 | cfg80211_chandef_create(chandef, channel: chan, chantype: NL80211_CHAN_NO_HT); |
1998 | } |
1999 | |
2000 | return 0; |
2001 | } |
2002 | |
2003 | static netdev_tx_t rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_device *ndev) |
2004 | { |
2005 | int rtap_len; |
2006 | int qos_len = 0; |
2007 | int dot11_hdr_len = 24; |
2008 | int snap_len = 6; |
2009 | unsigned char *pdata; |
2010 | u16 frame_control; |
2011 | unsigned char src_mac_addr[6]; |
2012 | unsigned char dst_mac_addr[6]; |
2013 | struct ieee80211_hdr *dot11_hdr; |
2014 | struct ieee80211_radiotap_header *rtap_hdr; |
2015 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
2016 | |
2017 | if (!skb) |
2018 | goto fail; |
2019 | |
2020 | if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header))) |
2021 | goto fail; |
2022 | |
2023 | rtap_hdr = (struct ieee80211_radiotap_header *)skb->data; |
2024 | if (unlikely(rtap_hdr->it_version)) |
2025 | goto fail; |
2026 | |
2027 | rtap_len = ieee80211_get_radiotap_len(data: skb->data); |
2028 | if (unlikely(skb->len < rtap_len)) |
2029 | goto fail; |
2030 | |
2031 | if (rtap_len != 14) |
2032 | goto fail; |
2033 | |
2034 | /* Skip the ratio tap header */ |
2035 | skb_pull(skb, len: rtap_len); |
2036 | |
2037 | dot11_hdr = (struct ieee80211_hdr *)skb->data; |
2038 | frame_control = le16_to_cpu(dot11_hdr->frame_control); |
2039 | /* Check if the QoS bit is set */ |
2040 | if ((frame_control & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) { |
2041 | /* Check if this ia a Wireless Distribution System (WDS) frame |
2042 | * which has 4 MAC addresses |
2043 | */ |
2044 | if (frame_control & 0x0080) |
2045 | qos_len = 2; |
2046 | if ((frame_control & 0x0300) == 0x0300) |
2047 | dot11_hdr_len += 6; |
2048 | |
2049 | memcpy(dst_mac_addr, dot11_hdr->addr1, sizeof(dst_mac_addr)); |
2050 | memcpy(src_mac_addr, dot11_hdr->addr2, sizeof(src_mac_addr)); |
2051 | |
2052 | /* Skip the 802.11 header, QoS (if any) and SNAP, but leave spaces for |
2053 | * two MAC addresses |
2054 | */ |
2055 | skb_pull(skb, len: dot11_hdr_len + qos_len + snap_len - sizeof(src_mac_addr) * 2); |
2056 | pdata = (unsigned char *)skb->data; |
2057 | memcpy(pdata, dst_mac_addr, sizeof(dst_mac_addr)); |
2058 | memcpy(pdata + sizeof(dst_mac_addr), src_mac_addr, sizeof(src_mac_addr)); |
2059 | |
2060 | /* Use the real net device to transmit the packet */ |
2061 | _rtw_xmit_entry(pkt: skb, pnetdev: padapter->pnetdev); |
2062 | return NETDEV_TX_OK; |
2063 | |
2064 | } else if ((frame_control & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) == |
2065 | (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION)) { |
2066 | /* only for action frames */ |
2067 | struct xmit_frame *pmgntframe; |
2068 | struct pkt_attrib *pattrib; |
2069 | unsigned char *pframe; |
2070 | /* u8 category, action, OUI_Subtype, dialogToken = 0; */ |
2071 | /* unsigned char *frame_body; */ |
2072 | struct ieee80211_hdr *pwlanhdr; |
2073 | struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); |
2074 | struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); |
2075 | u8 *buf = skb->data; |
2076 | u32 len = skb->len; |
2077 | u8 category, action; |
2078 | |
2079 | if (rtw_action_frame_parse(frame: buf, frame_len: len, category: &category, action: &action) == false) |
2080 | goto fail; |
2081 | |
2082 | /* starting alloc mgmt frame to dump it */ |
2083 | pmgntframe = alloc_mgtxmitframe(pxmitpriv); |
2084 | if (!pmgntframe) |
2085 | goto fail; |
2086 | |
2087 | /* update attribute */ |
2088 | pattrib = &pmgntframe->attrib; |
2089 | update_mgntframe_attrib(padapter, pattrib); |
2090 | pattrib->retry_ctrl = false; |
2091 | |
2092 | memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); |
2093 | |
2094 | pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; |
2095 | |
2096 | memcpy(pframe, (void *)buf, len); |
2097 | pattrib->pktlen = len; |
2098 | |
2099 | pwlanhdr = (struct ieee80211_hdr *)pframe; |
2100 | /* update seq number */ |
2101 | pmlmeext->mgnt_seq = GetSequence(pwlanhdr); |
2102 | pattrib->seqnum = pmlmeext->mgnt_seq; |
2103 | pmlmeext->mgnt_seq++; |
2104 | |
2105 | pattrib->last_txcmdsz = pattrib->pktlen; |
2106 | |
2107 | dump_mgntframe(padapter, pmgntframe); |
2108 | } |
2109 | |
2110 | fail: |
2111 | |
2112 | dev_kfree_skb_any(skb); |
2113 | |
2114 | return NETDEV_TX_OK; |
2115 | } |
2116 | |
2117 | static const struct net_device_ops rtw_cfg80211_monitor_if_ops = { |
2118 | .ndo_start_xmit = rtw_cfg80211_monitor_if_xmit_entry, |
2119 | }; |
2120 | |
2121 | static int rtw_cfg80211_add_monitor_if(struct adapter *padapter, char *name, struct net_device **ndev) |
2122 | { |
2123 | int ret = 0; |
2124 | struct net_device *mon_ndev = NULL; |
2125 | struct wireless_dev *mon_wdev = NULL; |
2126 | struct rtw_netdev_priv_indicator *pnpi; |
2127 | struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter); |
2128 | |
2129 | if (!name) { |
2130 | ret = -EINVAL; |
2131 | goto out; |
2132 | } |
2133 | |
2134 | if (pwdev_priv->pmon_ndev) { |
2135 | ret = -EBUSY; |
2136 | goto out; |
2137 | } |
2138 | |
2139 | mon_ndev = alloc_etherdev(sizeof(struct rtw_netdev_priv_indicator)); |
2140 | if (!mon_ndev) { |
2141 | ret = -ENOMEM; |
2142 | goto out; |
2143 | } |
2144 | |
2145 | mon_ndev->type = ARPHRD_IEEE80211_RADIOTAP; |
2146 | strncpy(p: mon_ndev->name, q: name, IFNAMSIZ); |
2147 | mon_ndev->name[IFNAMSIZ - 1] = 0; |
2148 | mon_ndev->needs_free_netdev = true; |
2149 | mon_ndev->priv_destructor = rtw_ndev_destructor; |
2150 | |
2151 | mon_ndev->netdev_ops = &rtw_cfg80211_monitor_if_ops; |
2152 | |
2153 | pnpi = netdev_priv(dev: mon_ndev); |
2154 | pnpi->priv = padapter; |
2155 | pnpi->sizeof_priv = sizeof(struct adapter); |
2156 | |
2157 | /* wdev */ |
2158 | mon_wdev = rtw_zmalloc(sizeof(struct wireless_dev)); |
2159 | if (!mon_wdev) { |
2160 | ret = -ENOMEM; |
2161 | goto out; |
2162 | } |
2163 | |
2164 | mon_wdev->wiphy = padapter->rtw_wdev->wiphy; |
2165 | mon_wdev->netdev = mon_ndev; |
2166 | mon_wdev->iftype = NL80211_IFTYPE_MONITOR; |
2167 | mon_ndev->ieee80211_ptr = mon_wdev; |
2168 | |
2169 | ret = cfg80211_register_netdevice(dev: mon_ndev); |
2170 | if (ret) |
2171 | goto out; |
2172 | |
2173 | *ndev = pwdev_priv->pmon_ndev = mon_ndev; |
2174 | memcpy(pwdev_priv->ifname_mon, name, IFNAMSIZ + 1); |
2175 | |
2176 | out: |
2177 | if (ret && mon_wdev) { |
2178 | kfree(objp: mon_wdev); |
2179 | mon_wdev = NULL; |
2180 | } |
2181 | |
2182 | if (ret && mon_ndev) { |
2183 | free_netdev(dev: mon_ndev); |
2184 | *ndev = mon_ndev = NULL; |
2185 | } |
2186 | |
2187 | return ret; |
2188 | } |
2189 | |
2190 | static struct wireless_dev * |
2191 | cfg80211_rtw_add_virtual_intf( |
2192 | struct wiphy *wiphy, |
2193 | const char *name, |
2194 | unsigned char name_assign_type, |
2195 | enum nl80211_iftype type, struct vif_params *params) |
2196 | { |
2197 | int ret = 0; |
2198 | struct net_device *ndev = NULL; |
2199 | struct adapter *padapter = wiphy_to_adapter(wiphy); |
2200 | |
2201 | switch (type) { |
2202 | case NL80211_IFTYPE_ADHOC: |
2203 | case NL80211_IFTYPE_AP_VLAN: |
2204 | case NL80211_IFTYPE_WDS: |
2205 | case NL80211_IFTYPE_MESH_POINT: |
2206 | ret = -ENODEV; |
2207 | break; |
2208 | case NL80211_IFTYPE_MONITOR: |
2209 | ret = rtw_cfg80211_add_monitor_if(padapter, name: (char *)name, ndev: &ndev); |
2210 | break; |
2211 | case NL80211_IFTYPE_P2P_CLIENT: |
2212 | case NL80211_IFTYPE_STATION: |
2213 | ret = -ENODEV; |
2214 | break; |
2215 | case NL80211_IFTYPE_P2P_GO: |
2216 | case NL80211_IFTYPE_AP: |
2217 | ret = -ENODEV; |
2218 | break; |
2219 | default: |
2220 | ret = -ENODEV; |
2221 | break; |
2222 | } |
2223 | |
2224 | return ndev ? ndev->ieee80211_ptr : ERR_PTR(error: ret); |
2225 | } |
2226 | |
2227 | static int cfg80211_rtw_del_virtual_intf(struct wiphy *wiphy, |
2228 | struct wireless_dev *wdev |
2229 | ) |
2230 | { |
2231 | struct net_device *ndev = wdev_to_ndev(wdev); |
2232 | int ret = 0; |
2233 | struct adapter *adapter; |
2234 | struct rtw_wdev_priv *pwdev_priv; |
2235 | |
2236 | if (!ndev) { |
2237 | ret = -EINVAL; |
2238 | goto exit; |
2239 | } |
2240 | |
2241 | adapter = rtw_netdev_priv(netdev: ndev); |
2242 | pwdev_priv = adapter_wdev_data(adapter); |
2243 | |
2244 | cfg80211_unregister_netdevice(dev: ndev); |
2245 | |
2246 | if (ndev == pwdev_priv->pmon_ndev) { |
2247 | pwdev_priv->pmon_ndev = NULL; |
2248 | pwdev_priv->ifname_mon[0] = '\0'; |
2249 | } |
2250 | |
2251 | exit: |
2252 | return ret; |
2253 | } |
2254 | |
2255 | static int rtw_add_beacon(struct adapter *adapter, const u8 *head, size_t head_len, const u8 *tail, size_t tail_len) |
2256 | { |
2257 | int ret = 0; |
2258 | u8 *pbuf = NULL; |
2259 | uint len, wps_ielen = 0; |
2260 | struct mlme_priv *pmlmepriv = &(adapter->mlmepriv); |
2261 | |
2262 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true) |
2263 | return -EINVAL; |
2264 | |
2265 | if (head_len < 24) |
2266 | return -EINVAL; |
2267 | |
2268 | pbuf = rtw_zmalloc(head_len + tail_len); |
2269 | if (!pbuf) |
2270 | return -ENOMEM; |
2271 | |
2272 | memcpy(pbuf, (void *)head + 24, head_len - 24);/* 24 =beacon header len. */ |
2273 | memcpy(pbuf + head_len - 24, (void *)tail, tail_len); |
2274 | |
2275 | len = head_len + tail_len - 24; |
2276 | |
2277 | /* check wps ie if inclued */ |
2278 | rtw_get_wps_ie(in_ie: pbuf + _FIXED_IE_LENGTH_, in_len: len - _FIXED_IE_LENGTH_, NULL, wps_ielen: &wps_ielen); |
2279 | |
2280 | /* pbss_network->ies will not include p2p_ie, wfd ie */ |
2281 | rtw_ies_remove_ie(ies: pbuf, ies_len: &len, _BEACON_IE_OFFSET_, eid: WLAN_EID_VENDOR_SPECIFIC, oui: P2P_OUI, oui_len: 4); |
2282 | rtw_ies_remove_ie(ies: pbuf, ies_len: &len, _BEACON_IE_OFFSET_, eid: WLAN_EID_VENDOR_SPECIFIC, oui: WFD_OUI, oui_len: 4); |
2283 | |
2284 | if (rtw_check_beacon_data(padapter: adapter, pbuf, len) == _SUCCESS) |
2285 | ret = 0; |
2286 | else |
2287 | ret = -EINVAL; |
2288 | |
2289 | kfree(objp: pbuf); |
2290 | |
2291 | return ret; |
2292 | } |
2293 | |
2294 | static int cfg80211_rtw_start_ap(struct wiphy *wiphy, struct net_device *ndev, |
2295 | struct cfg80211_ap_settings *settings) |
2296 | { |
2297 | int ret = 0; |
2298 | struct adapter *adapter = rtw_netdev_priv(netdev: ndev); |
2299 | |
2300 | ret = rtw_add_beacon(adapter, head: settings->beacon.head, |
2301 | head_len: settings->beacon.head_len, tail: settings->beacon.tail, |
2302 | tail_len: settings->beacon.tail_len); |
2303 | |
2304 | adapter->mlmeextpriv.mlmext_info.hidden_ssid_mode = settings->hidden_ssid; |
2305 | |
2306 | if (settings->ssid && settings->ssid_len) { |
2307 | struct wlan_bssid_ex *pbss_network = &adapter->mlmepriv.cur_network.network; |
2308 | struct wlan_bssid_ex *pbss_network_ext = &adapter->mlmeextpriv.mlmext_info.network; |
2309 | |
2310 | memcpy(pbss_network->ssid.ssid, (void *)settings->ssid, settings->ssid_len); |
2311 | pbss_network->ssid.ssid_length = settings->ssid_len; |
2312 | memcpy(pbss_network_ext->ssid.ssid, (void *)settings->ssid, settings->ssid_len); |
2313 | pbss_network_ext->ssid.ssid_length = settings->ssid_len; |
2314 | } |
2315 | |
2316 | return ret; |
2317 | } |
2318 | |
2319 | static int cfg80211_rtw_change_beacon(struct wiphy *wiphy, struct net_device *ndev, |
2320 | struct cfg80211_ap_update *info) |
2321 | { |
2322 | struct adapter *adapter = rtw_netdev_priv(netdev: ndev); |
2323 | |
2324 | return rtw_add_beacon(adapter, head: info->beacon.head, |
2325 | head_len: info->beacon.head_len, tail: info->beacon.tail, |
2326 | tail_len: info->beacon.tail_len); |
2327 | } |
2328 | |
2329 | static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev, |
2330 | unsigned int link_id) |
2331 | { |
2332 | return 0; |
2333 | } |
2334 | |
2335 | static int cfg80211_rtw_add_station(struct wiphy *wiphy, |
2336 | struct net_device *ndev, |
2337 | const u8 *mac, |
2338 | struct station_parameters *params) |
2339 | { |
2340 | return 0; |
2341 | } |
2342 | |
2343 | static int cfg80211_rtw_del_station(struct wiphy *wiphy, struct net_device *ndev, |
2344 | struct station_del_parameters *params) |
2345 | { |
2346 | int ret = 0; |
2347 | struct list_head *phead, *plist, *tmp; |
2348 | u8 updated = false; |
2349 | struct sta_info *psta = NULL; |
2350 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
2351 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
2352 | struct sta_priv *pstapriv = &padapter->stapriv; |
2353 | const u8 *mac = params->mac; |
2354 | |
2355 | if (check_fwstate(pmlmepriv, state: (_FW_LINKED | WIFI_AP_STATE)) != true) |
2356 | return -EINVAL; |
2357 | |
2358 | if (!mac) { |
2359 | flush_all_cam_entry(padapter); /* clear CAM */ |
2360 | |
2361 | rtw_sta_flush(padapter); |
2362 | |
2363 | return 0; |
2364 | } |
2365 | |
2366 | if (mac[0] == 0xff && mac[1] == 0xff && |
2367 | mac[2] == 0xff && mac[3] == 0xff && |
2368 | mac[4] == 0xff && mac[5] == 0xff) { |
2369 | return -EINVAL; |
2370 | } |
2371 | |
2372 | spin_lock_bh(lock: &pstapriv->asoc_list_lock); |
2373 | |
2374 | phead = &pstapriv->asoc_list; |
2375 | /* check asoc_queue */ |
2376 | list_for_each_safe(plist, tmp, phead) { |
2377 | psta = list_entry(plist, struct sta_info, asoc_list); |
2378 | |
2379 | if (!memcmp(p: (u8 *)mac, q: psta->hwaddr, ETH_ALEN)) { |
2380 | if (psta->dot8021xalg != 1 || psta->bpairwise_key_installed) { |
2381 | list_del_init(entry: &psta->asoc_list); |
2382 | pstapriv->asoc_list_cnt--; |
2383 | |
2384 | updated = ap_free_sta(padapter, psta, active: true, reason: WLAN_REASON_DEAUTH_LEAVING); |
2385 | |
2386 | psta = NULL; |
2387 | |
2388 | break; |
2389 | } |
2390 | } |
2391 | } |
2392 | |
2393 | spin_unlock_bh(lock: &pstapriv->asoc_list_lock); |
2394 | |
2395 | associated_clients_update(padapter, updated); |
2396 | |
2397 | return ret; |
2398 | } |
2399 | |
2400 | static int cfg80211_rtw_change_station(struct wiphy *wiphy, |
2401 | struct net_device *ndev, |
2402 | const u8 *mac, |
2403 | struct station_parameters *params) |
2404 | { |
2405 | return 0; |
2406 | } |
2407 | |
2408 | static struct sta_info *rtw_sta_info_get_by_idx(const int idx, struct sta_priv *pstapriv) |
2409 | |
2410 | { |
2411 | struct list_head *phead, *plist; |
2412 | struct sta_info *psta = NULL; |
2413 | int i = 0; |
2414 | |
2415 | phead = &pstapriv->asoc_list; |
2416 | plist = get_next(list: phead); |
2417 | |
2418 | /* check asoc_queue */ |
2419 | while (phead != plist) { |
2420 | if (idx == i) |
2421 | psta = container_of(plist, struct sta_info, asoc_list); |
2422 | plist = get_next(list: plist); |
2423 | i++; |
2424 | } |
2425 | return psta; |
2426 | } |
2427 | |
2428 | static int cfg80211_rtw_dump_station(struct wiphy *wiphy, |
2429 | struct net_device *ndev, |
2430 | int idx, u8 *mac, |
2431 | struct station_info *sinfo) |
2432 | { |
2433 | int ret = 0; |
2434 | struct adapter *padapter = rtw_netdev_priv(netdev: ndev); |
2435 | struct sta_info *psta = NULL; |
2436 | struct sta_priv *pstapriv = &padapter->stapriv; |
2437 | |
2438 | spin_lock_bh(lock: &pstapriv->asoc_list_lock); |
2439 | psta = rtw_sta_info_get_by_idx(idx, pstapriv); |
2440 | spin_unlock_bh(lock: &pstapriv->asoc_list_lock); |
2441 | if (psta == NULL) { |
2442 | ret = -ENOENT; |
2443 | goto exit; |
2444 | } |
2445 | memcpy(mac, psta->hwaddr, ETH_ALEN); |
2446 | sinfo->filled = BIT_ULL(NL80211_STA_INFO_SIGNAL); |
2447 | sinfo->signal = psta->rssi; |
2448 | |
2449 | exit: |
2450 | return ret; |
2451 | } |
2452 | |
2453 | static int cfg80211_rtw_change_bss(struct wiphy *wiphy, |
2454 | struct net_device *ndev, |
2455 | struct bss_parameters *params) |
2456 | { |
2457 | return 0; |
2458 | } |
2459 | |
2460 | void rtw_cfg80211_rx_action(struct adapter *adapter, u8 *frame, uint frame_len, const char *msg) |
2461 | { |
2462 | s32 freq; |
2463 | int channel; |
2464 | u8 category, action; |
2465 | |
2466 | channel = rtw_get_oper_ch(adapter); |
2467 | |
2468 | rtw_action_frame_parse(frame, frame_len, category: &category, action: &action); |
2469 | |
2470 | freq = rtw_ieee80211_channel_to_frequency(chan: channel, band: NL80211_BAND_2GHZ); |
2471 | |
2472 | rtw_cfg80211_rx_mgmt(adapter, freq, 0, frame, frame_len, GFP_ATOMIC); |
2473 | } |
2474 | |
2475 | static int _cfg80211_rtw_mgmt_tx(struct adapter *padapter, u8 tx_ch, const u8 *buf, size_t len) |
2476 | { |
2477 | struct xmit_frame *pmgntframe; |
2478 | struct pkt_attrib *pattrib; |
2479 | unsigned char *pframe; |
2480 | int ret = _FAIL; |
2481 | bool __maybe_unused ack = true; |
2482 | struct ieee80211_hdr *pwlanhdr; |
2483 | struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); |
2484 | struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); |
2485 | |
2486 | rtw_set_scan_deny(adapter: padapter, ms: 1000); |
2487 | |
2488 | rtw_scan_abort(adapter: padapter); |
2489 | if (tx_ch != rtw_get_oper_ch(adapter: padapter)) { |
2490 | if (!check_fwstate(pmlmepriv: &padapter->mlmepriv, _FW_LINKED)) |
2491 | pmlmeext->cur_channel = tx_ch; |
2492 | set_channel_bwmode(padapter, channel: tx_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, bwmode: CHANNEL_WIDTH_20); |
2493 | } |
2494 | |
2495 | /* starting alloc mgmt frame to dump it */ |
2496 | pmgntframe = alloc_mgtxmitframe(pxmitpriv); |
2497 | if (!pmgntframe) { |
2498 | /* ret = -ENOMEM; */ |
2499 | ret = _FAIL; |
2500 | goto exit; |
2501 | } |
2502 | |
2503 | /* update attribute */ |
2504 | pattrib = &pmgntframe->attrib; |
2505 | update_mgntframe_attrib(padapter, pattrib); |
2506 | pattrib->retry_ctrl = false; |
2507 | |
2508 | memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); |
2509 | |
2510 | pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; |
2511 | |
2512 | memcpy(pframe, (void *)buf, len); |
2513 | pattrib->pktlen = len; |
2514 | |
2515 | pwlanhdr = (struct ieee80211_hdr *)pframe; |
2516 | /* update seq number */ |
2517 | pmlmeext->mgnt_seq = GetSequence(pwlanhdr); |
2518 | pattrib->seqnum = pmlmeext->mgnt_seq; |
2519 | pmlmeext->mgnt_seq++; |
2520 | |
2521 | pattrib->last_txcmdsz = pattrib->pktlen; |
2522 | |
2523 | if (dump_mgntframe_and_wait_ack(padapter, pmgntframe) != _SUCCESS) { |
2524 | ack = false; |
2525 | ret = _FAIL; |
2526 | |
2527 | } else { |
2528 | msleep(msecs: 50); |
2529 | |
2530 | ret = _SUCCESS; |
2531 | } |
2532 | |
2533 | exit: |
2534 | |
2535 | return ret; |
2536 | } |
2537 | |
2538 | static int cfg80211_rtw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, |
2539 | struct cfg80211_mgmt_tx_params *params, |
2540 | u64 *cookie) |
2541 | { |
2542 | struct net_device *ndev = wdev_to_ndev(wdev); |
2543 | struct ieee80211_channel *chan = params->chan; |
2544 | const u8 *buf = params->buf; |
2545 | size_t len = params->len; |
2546 | int ret = 0; |
2547 | int tx_ret; |
2548 | u32 dump_limit = RTW_MAX_MGMT_TX_CNT; |
2549 | u32 dump_cnt = 0; |
2550 | bool ack = true; |
2551 | u8 tx_ch = (u8)ieee80211_frequency_to_channel(freq: chan->center_freq); |
2552 | u8 category, action; |
2553 | int type = (-1); |
2554 | struct adapter *padapter; |
2555 | struct rtw_wdev_priv *pwdev_priv; |
2556 | |
2557 | if (!ndev) { |
2558 | ret = -EINVAL; |
2559 | goto exit; |
2560 | } |
2561 | |
2562 | padapter = rtw_netdev_priv(netdev: ndev); |
2563 | pwdev_priv = adapter_wdev_data(padapter); |
2564 | |
2565 | /* cookie generation */ |
2566 | *cookie = (unsigned long)buf; |
2567 | |
2568 | /* indicate ack before issue frame to avoid racing with rsp frame */ |
2569 | rtw_cfg80211_mgmt_tx_status(padapter, *cookie, buf, len, ack, GFP_KERNEL); |
2570 | |
2571 | if (rtw_action_frame_parse(frame: buf, frame_len: len, category: &category, action: &action) == false) |
2572 | goto exit; |
2573 | |
2574 | rtw_ps_deny(padapter, reason: PS_DENY_MGNT_TX); |
2575 | if (rtw_pwr_wakeup(padapter) == _FAIL) { |
2576 | ret = -EFAULT; |
2577 | goto cancel_ps_deny; |
2578 | } |
2579 | |
2580 | do { |
2581 | dump_cnt++; |
2582 | tx_ret = _cfg80211_rtw_mgmt_tx(padapter, tx_ch, buf, len); |
2583 | } while (dump_cnt < dump_limit && tx_ret != _SUCCESS); |
2584 | |
2585 | switch (type) { |
2586 | case P2P_GO_NEGO_CONF: |
2587 | rtw_clear_scan_deny(adapter: padapter); |
2588 | break; |
2589 | case P2P_INVIT_RESP: |
2590 | if (pwdev_priv->invit_info.flags & BIT(0) && pwdev_priv->invit_info.status == 0) { |
2591 | rtw_set_scan_deny(adapter: padapter, ms: 5000); |
2592 | rtw_pwr_wakeup_ex(padapter, 5000); |
2593 | rtw_clear_scan_deny(adapter: padapter); |
2594 | } |
2595 | break; |
2596 | } |
2597 | |
2598 | cancel_ps_deny: |
2599 | rtw_ps_deny_cancel(padapter, reason: PS_DENY_MGNT_TX); |
2600 | exit: |
2601 | return ret; |
2602 | } |
2603 | |
2604 | static void rtw_cfg80211_init_ht_capab(struct ieee80211_sta_ht_cap *ht_cap, enum nl80211_band band) |
2605 | { |
2606 | #define MAX_BIT_RATE_40MHZ_MCS15 300 /* Mbps */ |
2607 | #define MAX_BIT_RATE_40MHZ_MCS7 150 /* Mbps */ |
2608 | |
2609 | ht_cap->ht_supported = true; |
2610 | |
2611 | ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | |
2612 | IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20 | |
2613 | IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU; |
2614 | |
2615 | /* |
2616 | *Maximum length of AMPDU that the STA can receive. |
2617 | *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets) |
2618 | */ |
2619 | ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
2620 | |
2621 | /*Minimum MPDU start spacing , */ |
2622 | ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; |
2623 | |
2624 | ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
2625 | |
2626 | /* |
2627 | *hw->wiphy->bands[NL80211_BAND_2GHZ] |
2628 | *base on ant_num |
2629 | *rx_mask: RX mask |
2630 | *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7 |
2631 | *if rx_ant =2 rx_mask[1]= 0xff;==>MCS8-MCS15 |
2632 | *if rx_ant >=3 rx_mask[2]= 0xff; |
2633 | *if BW_40 rx_mask[4]= 0x01; |
2634 | *highest supported RX rate |
2635 | */ |
2636 | ht_cap->mcs.rx_mask[0] = 0xFF; |
2637 | ht_cap->mcs.rx_mask[1] = 0x00; |
2638 | ht_cap->mcs.rx_mask[4] = 0x01; |
2639 | |
2640 | ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7); |
2641 | } |
2642 | |
2643 | void rtw_cfg80211_init_wiphy(struct adapter *padapter) |
2644 | { |
2645 | struct ieee80211_supported_band *bands; |
2646 | struct wireless_dev *pwdev = padapter->rtw_wdev; |
2647 | struct wiphy *wiphy = pwdev->wiphy; |
2648 | |
2649 | { |
2650 | bands = wiphy->bands[NL80211_BAND_2GHZ]; |
2651 | if (bands) |
2652 | rtw_cfg80211_init_ht_capab(ht_cap: &bands->ht_cap, band: NL80211_BAND_2GHZ); |
2653 | } |
2654 | |
2655 | /* copy mac_addr to wiphy */ |
2656 | memcpy(wiphy->perm_addr, padapter->eeprompriv.mac_addr, ETH_ALEN); |
2657 | } |
2658 | |
2659 | static void rtw_cfg80211_preinit_wiphy(struct adapter *padapter, struct wiphy *wiphy) |
2660 | { |
2661 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; |
2662 | |
2663 | wiphy->max_scan_ssids = RTW_SSID_SCAN_AMOUNT; |
2664 | wiphy->max_scan_ie_len = RTW_SCAN_IE_LEN_MAX; |
2665 | wiphy->max_num_pmkids = RTW_MAX_NUM_PMKIDS; |
2666 | |
2667 | wiphy->max_remain_on_channel_duration = RTW_MAX_REMAIN_ON_CHANNEL_DURATION; |
2668 | |
2669 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
2670 | | BIT(NL80211_IFTYPE_ADHOC) |
2671 | | BIT(NL80211_IFTYPE_AP) |
2672 | | BIT(NL80211_IFTYPE_MONITOR) |
2673 | ; |
2674 | |
2675 | wiphy->mgmt_stypes = rtw_cfg80211_default_mgmt_stypes; |
2676 | |
2677 | wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR); |
2678 | |
2679 | wiphy->cipher_suites = rtw_cipher_suites; |
2680 | wiphy->n_cipher_suites = ARRAY_SIZE(rtw_cipher_suites); |
2681 | |
2682 | /* if (padapter->registrypriv.wireless_mode & WIRELESS_11G) */ |
2683 | wiphy->bands[NL80211_BAND_2GHZ] = rtw_spt_band_alloc(band: NL80211_BAND_2GHZ); |
2684 | |
2685 | wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
2686 | wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX | WIPHY_FLAG_HAVE_AP_SME; |
2687 | |
2688 | #if defined(CONFIG_PM) |
2689 | wiphy->max_sched_scan_reqs = 1; |
2690 | #endif |
2691 | |
2692 | #if defined(CONFIG_PM) |
2693 | wiphy->wowlan = &wowlan_stub; |
2694 | #endif |
2695 | |
2696 | if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE) |
2697 | wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; |
2698 | else |
2699 | wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
2700 | } |
2701 | |
2702 | static struct cfg80211_ops rtw_cfg80211_ops = { |
2703 | .change_virtual_intf = cfg80211_rtw_change_iface, |
2704 | .add_key = cfg80211_rtw_add_key, |
2705 | .get_key = cfg80211_rtw_get_key, |
2706 | .del_key = cfg80211_rtw_del_key, |
2707 | .set_default_key = cfg80211_rtw_set_default_key, |
2708 | .get_station = cfg80211_rtw_get_station, |
2709 | .scan = cfg80211_rtw_scan, |
2710 | .set_wiphy_params = cfg80211_rtw_set_wiphy_params, |
2711 | .connect = cfg80211_rtw_connect, |
2712 | .disconnect = cfg80211_rtw_disconnect, |
2713 | .join_ibss = cfg80211_rtw_join_ibss, |
2714 | .leave_ibss = cfg80211_rtw_leave_ibss, |
2715 | .set_tx_power = cfg80211_rtw_set_txpower, |
2716 | .get_tx_power = cfg80211_rtw_get_txpower, |
2717 | .set_power_mgmt = cfg80211_rtw_set_power_mgmt, |
2718 | .set_pmksa = cfg80211_rtw_set_pmksa, |
2719 | .del_pmksa = cfg80211_rtw_del_pmksa, |
2720 | .flush_pmksa = cfg80211_rtw_flush_pmksa, |
2721 | .get_channel = cfg80211_rtw_get_channel, |
2722 | .add_virtual_intf = cfg80211_rtw_add_virtual_intf, |
2723 | .del_virtual_intf = cfg80211_rtw_del_virtual_intf, |
2724 | |
2725 | .start_ap = cfg80211_rtw_start_ap, |
2726 | .change_beacon = cfg80211_rtw_change_beacon, |
2727 | .stop_ap = cfg80211_rtw_stop_ap, |
2728 | |
2729 | .add_station = cfg80211_rtw_add_station, |
2730 | .del_station = cfg80211_rtw_del_station, |
2731 | .change_station = cfg80211_rtw_change_station, |
2732 | .dump_station = cfg80211_rtw_dump_station, |
2733 | .change_bss = cfg80211_rtw_change_bss, |
2734 | |
2735 | .mgmt_tx = cfg80211_rtw_mgmt_tx, |
2736 | }; |
2737 | |
2738 | int rtw_wdev_alloc(struct adapter *padapter, struct device *dev) |
2739 | { |
2740 | int ret = 0; |
2741 | struct wiphy *wiphy; |
2742 | struct wireless_dev *wdev; |
2743 | struct rtw_wdev_priv *pwdev_priv; |
2744 | struct net_device *pnetdev = padapter->pnetdev; |
2745 | |
2746 | /* wiphy */ |
2747 | wiphy = wiphy_new(ops: &rtw_cfg80211_ops, sizeof_priv: sizeof(struct adapter *)); |
2748 | if (!wiphy) { |
2749 | ret = -ENOMEM; |
2750 | goto exit; |
2751 | } |
2752 | set_wiphy_dev(wiphy, dev); |
2753 | *((struct adapter **)wiphy_priv(wiphy)) = padapter; |
2754 | rtw_cfg80211_preinit_wiphy(padapter, wiphy); |
2755 | |
2756 | /* init regulary domain */ |
2757 | rtw_regd_init(wiphy, reg_notifier: rtw_reg_notifier); |
2758 | |
2759 | ret = wiphy_register(wiphy); |
2760 | if (ret < 0) |
2761 | goto free_wiphy; |
2762 | |
2763 | /* wdev */ |
2764 | wdev = rtw_zmalloc(sizeof(struct wireless_dev)); |
2765 | if (!wdev) { |
2766 | ret = -ENOMEM; |
2767 | goto unregister_wiphy; |
2768 | } |
2769 | wdev->wiphy = wiphy; |
2770 | wdev->netdev = pnetdev; |
2771 | |
2772 | wdev->iftype = NL80211_IFTYPE_STATION; /* will be init in rtw_hal_init() */ |
2773 | /* Must sync with _rtw_init_mlme_priv() */ |
2774 | /* pmlmepriv->fw_state = WIFI_STATION_STATE */ |
2775 | padapter->rtw_wdev = wdev; |
2776 | pnetdev->ieee80211_ptr = wdev; |
2777 | |
2778 | /* init pwdev_priv */ |
2779 | pwdev_priv = adapter_wdev_data(padapter); |
2780 | pwdev_priv->rtw_wdev = wdev; |
2781 | pwdev_priv->pmon_ndev = NULL; |
2782 | pwdev_priv->ifname_mon[0] = '\0'; |
2783 | pwdev_priv->padapter = padapter; |
2784 | pwdev_priv->scan_request = NULL; |
2785 | spin_lock_init(&pwdev_priv->scan_req_lock); |
2786 | |
2787 | pwdev_priv->p2p_enabled = false; |
2788 | pwdev_priv->provdisc_req_issued = false; |
2789 | rtw_wdev_invit_info_init(&pwdev_priv->invit_info); |
2790 | rtw_wdev_nego_info_init(&pwdev_priv->nego_info); |
2791 | |
2792 | pwdev_priv->bandroid_scan = false; |
2793 | |
2794 | if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE) |
2795 | pwdev_priv->power_mgmt = true; |
2796 | else |
2797 | pwdev_priv->power_mgmt = false; |
2798 | |
2799 | return ret; |
2800 | |
2801 | unregister_wiphy: |
2802 | wiphy_unregister(wiphy); |
2803 | free_wiphy: |
2804 | wiphy_free(wiphy); |
2805 | exit: |
2806 | return ret; |
2807 | } |
2808 | |
2809 | void rtw_wdev_free(struct wireless_dev *wdev) |
2810 | { |
2811 | if (!wdev) |
2812 | return; |
2813 | |
2814 | kfree(objp: wdev->wiphy->bands[NL80211_BAND_2GHZ]); |
2815 | |
2816 | wiphy_free(wiphy: wdev->wiphy); |
2817 | |
2818 | kfree(objp: wdev); |
2819 | } |
2820 | |
2821 | void rtw_wdev_unregister(struct wireless_dev *wdev) |
2822 | { |
2823 | struct net_device *ndev; |
2824 | struct adapter *adapter; |
2825 | struct rtw_wdev_priv *pwdev_priv; |
2826 | |
2827 | if (!wdev) |
2828 | return; |
2829 | ndev = wdev_to_ndev(wdev); |
2830 | if (!ndev) |
2831 | return; |
2832 | |
2833 | adapter = rtw_netdev_priv(netdev: ndev); |
2834 | pwdev_priv = adapter_wdev_data(adapter); |
2835 | |
2836 | rtw_cfg80211_indicate_scan_done(adapter, aborted: true); |
2837 | |
2838 | if (pwdev_priv->pmon_ndev) |
2839 | unregister_netdev(dev: pwdev_priv->pmon_ndev); |
2840 | |
2841 | wiphy_unregister(wiphy: wdev->wiphy); |
2842 | } |
2843 | |