1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
8 #include <linux/etherdevice.h>
10 #include <rtw_debug.h>
11 #include <linux/jiffies.h>
13 #include <rtw_wifi_regd.h>
15 #define RTW_MAX_MGMT_TX_CNT (8)
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
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,
29 #define RATETAB_ENT(_rate, _rateid, _flags) \
32 .hw_value = (_rateid), \
36 #define CHAN2G(_channel, _freq, _flags) { \
37 .band = NL80211_BAND_2GHZ, \
38 .center_freq = (_freq), \
39 .hw_value = (_channel), \
41 .max_antenna_gain = 0, \
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)
50 static __maybe_unused const struct wiphy_wowlan_support wowlan_stub = {
51 .flags = WIPHY_WOWLAN_ANY,
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),
73 #define rtw_g_rates (rtw_rates + 0)
74 #define RTW_G_RATES_NUM 12
76 #define RTW_2G_CHANNELS_NUM 14
78 static struct ieee80211_channel rtw_2ghz_channels[] = {
95 static void rtw_2g_channels_init(struct ieee80211_channel *channels)
97 memcpy((void *)channels, (void *)rtw_2ghz_channels,
98 sizeof(struct ieee80211_channel)*RTW_2G_CHANNELS_NUM
102 static void rtw_2g_rates_init(struct ieee80211_rate *rates)
104 memcpy(rates, rtw_g_rates,
105 sizeof(struct ieee80211_rate)*RTW_G_RATES_NUM
109 static struct ieee80211_supported_band *rtw_spt_band_alloc(
110 enum nl80211_band band
113 struct ieee80211_supported_band *spt_band = NULL;
114 int n_channels, n_bitrates;
116 if (band == NL80211_BAND_2GHZ) {
117 n_channels = RTW_2G_CHANNELS_NUM;
118 n_bitrates = RTW_G_RATES_NUM;
123 spt_band = rtw_zmalloc(sizeof(struct ieee80211_supported_band) +
124 sizeof(struct ieee80211_channel) * n_channels +
125 sizeof(struct ieee80211_rate) * n_bitrates);
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;
135 if (band == NL80211_BAND_2GHZ) {
136 rtw_2g_channels_init(spt_band->channels);
137 rtw_2g_rates_init(spt_band->bitrates);
140 /* spt_band.ht_cap */
147 static const struct ieee80211_txrx_stypes
148 rtw_cfg80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
149 [NL80211_IFTYPE_ADHOC] = {
151 .rx = BIT(IEEE80211_STYPE_ACTION >> 4)
153 [NL80211_IFTYPE_STATION] = {
155 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
156 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
158 [NL80211_IFTYPE_AP] = {
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)
168 [NL80211_IFTYPE_AP_VLAN] = {
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)
179 [NL80211_IFTYPE_P2P_CLIENT] = {
181 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
182 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
184 [NL80211_IFTYPE_P2P_GO] = {
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)
196 static int rtw_ieee80211_channel_to_frequency(int chan, int band)
198 if (band == NL80211_BAND_2GHZ) {
202 return 2407 + chan * 5;
205 return 0; /* not supported */
208 #define MAX_BSSINFO_LEN 1000
209 struct cfg80211_bss *rtw_cfg80211_inform_bss(struct adapter *padapter, struct wlan_network *pnetwork)
211 struct ieee80211_channel *notify_channel;
212 struct cfg80211_bss *bss = NULL;
213 /* struct ieee80211_supported_band *band; */
216 u64 notify_timestamp;
218 u8 *buf = NULL, *pbuf;
219 size_t len, bssinf_len = 0;
220 struct ieee80211_hdr *pwlanhdr;
223 struct wireless_dev *wdev = padapter->rtw_wdev;
224 struct wiphy *wiphy = wdev->wiphy;
225 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
227 bssinf_len = pnetwork->network.ie_length + sizeof(struct ieee80211_hdr_3addr);
228 if (bssinf_len > MAX_BSSINFO_LEN)
234 if (rtw_get_wapi_ie(pnetwork->network.ies, pnetwork->network.ie_length, NULL, &wapi_len) > 0) {
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;
250 wpsie = rtw_get_wps_ie(pnetwork->network.ies+_FIXED_IE_LENGTH_, pnetwork->network.ie_length-_FIXED_IE_LENGTH_, NULL, &wpsielen);
252 if (wpsie && wpsielen > 0)
253 psr = rtw_get_wps_attr_content(wpsie, wpsielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL);
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(pssid->ssid, ssids[0].ssid, ssids[0].ssid_len))) {
262 *psr = 0; /* clear sr */
267 /* spin_unlock_bh(&pwdev_priv->scan_req_lock); */
270 channel = pnetwork->network.configuration.ds_config;
271 freq = rtw_ieee80211_channel_to_frequency(channel, NL80211_BAND_2GHZ);
273 notify_channel = ieee80211_get_channel(wiphy, freq);
275 notify_timestamp = ktime_to_us(ktime_get_boottime());
277 /* We've set wiphy's signal_type as CFG80211_SIGNAL_TYPE_MBM: signal strength in mBm (100*dBm) */
278 if (check_fwstate(pmlmepriv, _FW_LINKED) == true &&
279 is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network, 0)) {
280 notify_signal = 100*translate_percentage_to_dbm(padapter->recvpriv.signal_strength);/* dbm */
282 notify_signal = 100*translate_percentage_to_dbm(pnetwork->network.phy_info.signal_strength);/* dbm */
285 buf = kzalloc(MAX_BSSINFO_LEN, GFP_ATOMIC);
290 pwlanhdr = (struct ieee80211_hdr *)pbuf;
291 fctrl = &(pwlanhdr->frame_control);
294 SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/);
295 /* pmlmeext->mgnt_seq++; */
297 if (pnetwork->network.reserved[0] == 1) { /* WIFI_BEACON */
298 eth_broadcast_addr(pwlanhdr->addr1);
299 SetFrameSubType(pbuf, WIFI_BEACON);
301 memcpy(pwlanhdr->addr1, myid(&(padapter->eeprompriv)), ETH_ALEN);
302 SetFrameSubType(pbuf, WIFI_PROBERSP);
305 memcpy(pwlanhdr->addr2, pnetwork->network.mac_address, ETH_ALEN);
306 memcpy(pwlanhdr->addr3, pnetwork->network.mac_address, ETH_ALEN);
309 pbuf += sizeof(struct ieee80211_hdr_3addr);
310 len = sizeof(struct ieee80211_hdr_3addr);
312 memcpy(pbuf, pnetwork->network.ies, pnetwork->network.ie_length);
313 len += pnetwork->network.ie_length;
315 *((__le64 *)pbuf) = cpu_to_le64(notify_timestamp);
317 bss = cfg80211_inform_bss_frame(wiphy, notify_channel, (struct ieee80211_mgmt *)buf,
318 len, notify_signal, GFP_ATOMIC);
323 cfg80211_put_bss(wiphy, bss);
332 Check the given bss is valid by kernel API cfg80211_get_bss()
333 @padapter : the given adapter
335 return true if bss is valid, false for not found.
337 int rtw_cfg80211_check_bss(struct adapter *padapter)
339 struct wlan_bssid_ex *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network);
340 struct cfg80211_bss *bss = NULL;
341 struct ieee80211_channel *notify_channel = NULL;
344 if (!(pnetwork) || !(padapter->rtw_wdev))
347 freq = rtw_ieee80211_channel_to_frequency(pnetwork->configuration.ds_config, NL80211_BAND_2GHZ);
349 notify_channel = ieee80211_get_channel(padapter->rtw_wdev->wiphy, freq);
350 bss = cfg80211_get_bss(padapter->rtw_wdev->wiphy, notify_channel,
351 pnetwork->mac_address, pnetwork->ssid.ssid,
352 pnetwork->ssid.ssid_length,
353 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
355 cfg80211_put_bss(padapter->rtw_wdev->wiphy, bss);
357 return (bss != NULL);
360 void rtw_cfg80211_ibss_indicate_connect(struct adapter *padapter)
362 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
363 struct wlan_network *cur_network = &(pmlmepriv->cur_network);
364 struct wireless_dev *pwdev = padapter->rtw_wdev;
365 struct wiphy *wiphy = pwdev->wiphy;
366 int freq = (int)cur_network->network.configuration.ds_config;
367 struct ieee80211_channel *chan;
369 if (pwdev->iftype != NL80211_IFTYPE_ADHOC)
372 if (!rtw_cfg80211_check_bss(padapter)) {
373 struct wlan_bssid_ex *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network);
374 struct wlan_network *scanned = pmlmepriv->cur_network_scanned;
376 if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) {
378 memcpy(&cur_network->network, pnetwork, sizeof(struct wlan_bssid_ex));
379 rtw_cfg80211_inform_bss(padapter, cur_network);
385 if (!memcmp(&(scanned->network.ssid), &(pnetwork->ssid), sizeof(struct ndis_802_11_ssid))
386 && !memcmp(scanned->network.mac_address, pnetwork->mac_address, sizeof(NDIS_802_11_MAC_ADDRESS))
388 rtw_cfg80211_inform_bss(padapter, scanned);
393 if (!rtw_cfg80211_check_bss(padapter))
394 netdev_dbg(padapter->pnetdev,
395 FUNC_ADPT_FMT " BSS not found !!\n",
396 FUNC_ADPT_ARG(padapter));
398 /* notify cfg80211 that device joined an IBSS */
399 chan = ieee80211_get_channel(wiphy, freq);
400 cfg80211_ibss_joined(padapter->pnetdev, cur_network->network.mac_address, chan, GFP_ATOMIC);
403 void rtw_cfg80211_indicate_connect(struct adapter *padapter)
405 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
406 struct wlan_network *cur_network = &(pmlmepriv->cur_network);
407 struct wireless_dev *pwdev = padapter->rtw_wdev;
409 if (pwdev->iftype != NL80211_IFTYPE_STATION
410 && pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT
415 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
419 struct wlan_bssid_ex *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network);
420 struct wlan_network *scanned = pmlmepriv->cur_network_scanned;
427 if (!memcmp(scanned->network.mac_address, pnetwork->mac_address, sizeof(NDIS_802_11_MAC_ADDRESS))
428 && !memcmp(&(scanned->network.ssid), &(pnetwork->ssid), sizeof(struct ndis_802_11_ssid))
430 rtw_cfg80211_inform_bss(padapter, scanned);
436 if (!rtw_cfg80211_check_bss(padapter))
437 netdev_dbg(padapter->pnetdev,
438 FUNC_ADPT_FMT " BSS not found !!\n",
439 FUNC_ADPT_ARG(padapter));
441 if (rtw_to_roam(padapter) > 0) {
442 struct wiphy *wiphy = pwdev->wiphy;
443 struct ieee80211_channel *notify_channel;
445 u16 channel = cur_network->network.configuration.ds_config;
446 struct cfg80211_roam_info roam_info = {};
448 freq = rtw_ieee80211_channel_to_frequency(channel, NL80211_BAND_2GHZ);
450 notify_channel = ieee80211_get_channel(wiphy, freq);
452 roam_info.links[0].channel = notify_channel;
453 roam_info.links[0].bssid = cur_network->network.mac_address;
455 pmlmepriv->assoc_req+sizeof(struct ieee80211_hdr_3addr)+2;
456 roam_info.req_ie_len =
457 pmlmepriv->assoc_req_len-sizeof(struct ieee80211_hdr_3addr)-2;
459 pmlmepriv->assoc_rsp+sizeof(struct ieee80211_hdr_3addr)+6;
460 roam_info.resp_ie_len =
461 pmlmepriv->assoc_rsp_len-sizeof(struct ieee80211_hdr_3addr)-6;
462 cfg80211_roamed(padapter->pnetdev, &roam_info, GFP_ATOMIC);
464 cfg80211_connect_result(padapter->pnetdev, cur_network->network.mac_address
465 , pmlmepriv->assoc_req+sizeof(struct ieee80211_hdr_3addr)+2
466 , pmlmepriv->assoc_req_len-sizeof(struct ieee80211_hdr_3addr)-2
467 , pmlmepriv->assoc_rsp+sizeof(struct ieee80211_hdr_3addr)+6
468 , pmlmepriv->assoc_rsp_len-sizeof(struct ieee80211_hdr_3addr)-6
469 , WLAN_STATUS_SUCCESS, GFP_ATOMIC);
473 void rtw_cfg80211_indicate_disconnect(struct adapter *padapter)
475 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
476 struct wireless_dev *pwdev = padapter->rtw_wdev;
478 if (pwdev->iftype != NL80211_IFTYPE_STATION
479 && pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT
484 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
487 if (!padapter->mlmepriv.not_indic_disco) {
488 if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
489 cfg80211_disconnected(padapter->pnetdev, 0,
490 NULL, 0, true, GFP_ATOMIC);
492 cfg80211_connect_result(padapter->pnetdev, NULL, NULL, 0, NULL, 0,
493 WLAN_STATUS_UNSPECIFIED_FAILURE, GFP_ATOMIC/*GFP_KERNEL*/);
499 static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len)
502 u32 wep_key_idx, wep_key_len;
503 struct sta_info *psta = NULL, *pbcmc_sta = NULL;
504 struct adapter *padapter = rtw_netdev_priv(dev);
505 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
506 struct security_priv *psecuritypriv = &(padapter->securitypriv);
507 struct sta_priv *pstapriv = &padapter->stapriv;
508 char *grpkey = padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey;
509 char *txkey = padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey;
510 char *rxkey = padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey;
512 param->u.crypt.err = 0;
513 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
515 if (param_len != sizeof(struct ieee_param) + param->u.crypt.key_len) {
520 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
521 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
522 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
523 if (param->u.crypt.idx >= WEP_KEYS) {
528 psta = rtw_get_stainfo(pstapriv, param->sta_addr);
534 if (strcmp(param->u.crypt.alg, "none") == 0 && !psta)
537 if (strcmp(param->u.crypt.alg, "WEP") == 0 && !psta) {
538 wep_key_idx = param->u.crypt.idx;
539 wep_key_len = param->u.crypt.key_len;
541 if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) {
547 wep_key_len = wep_key_len <= 5 ? 5 : 13;
549 if (psecuritypriv->bWepDefaultKeyIdxSet == 0) {
550 /* wep default key has not been set, so use this key index as default key. */
552 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
553 psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
554 psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
555 psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
557 if (wep_key_len == 13) {
558 psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
559 psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
562 psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
565 memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len);
567 psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len;
569 rtw_ap_set_wep_key(padapter, param->u.crypt.key, wep_key_len, wep_key_idx, 1);
576 if (!psta && check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
578 if (param->u.crypt.set_tx == 0) {
579 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
580 memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
582 psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
583 if (param->u.crypt.key_len == 13)
584 psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
586 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
587 psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
589 memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
591 /* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */
593 memcpy(txkey, &(param->u.crypt.key[16]), 8);
594 memcpy(rxkey, &(param->u.crypt.key[24]), 8);
596 psecuritypriv->busetkipkey = true;
598 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
599 psecuritypriv->dot118021XGrpPrivacy = _AES_;
601 memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
603 psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
606 psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx;
608 psecuritypriv->binstallGrpkey = true;
610 psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;/* */
612 rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx);
614 pbcmc_sta = rtw_get_bcmc_stainfo(padapter);
616 pbcmc_sta->ieee8021x_blocked = false;
617 pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy;/* rx will use bmc_sta's dot118021XPrivacy */
626 if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) { /* psk/802_1x */
627 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
628 if (param->u.crypt.set_tx == 1) { /* pairwise key */
629 memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
631 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
632 psta->dot118021XPrivacy = _WEP40_;
633 if (param->u.crypt.key_len == 13)
634 psta->dot118021XPrivacy = _WEP104_;
635 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
636 psta->dot118021XPrivacy = _TKIP_;
638 /* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */
640 memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
641 memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
643 psecuritypriv->busetkipkey = true;
645 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
647 psta->dot118021XPrivacy = _AES_;
649 psta->dot118021XPrivacy = _NO_PRIVACY_;
652 rtw_ap_set_pairwise_key(padapter, psta);
654 psta->ieee8021x_blocked = false;
656 psta->bpairwise_key_installed = true;
658 } else { /* group key??? */
659 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
660 memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
662 psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
663 if (param->u.crypt.key_len == 13)
664 psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
665 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
666 psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
668 memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
670 /* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */
672 memcpy(txkey, &(param->u.crypt.key[16]), 8);
673 memcpy(rxkey, &(param->u.crypt.key[24]), 8);
675 psecuritypriv->busetkipkey = true;
677 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
678 psecuritypriv->dot118021XGrpPrivacy = _AES_;
680 memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
682 psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
685 psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx;
687 psecuritypriv->binstallGrpkey = true;
689 psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;/* */
691 rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx);
693 pbcmc_sta = rtw_get_bcmc_stainfo(padapter);
695 pbcmc_sta->ieee8021x_blocked = false;
696 pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy;/* rx will use bmc_sta's dot118021XPrivacy */
711 static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len)
714 u32 wep_key_idx, wep_key_len;
715 struct adapter *padapter = rtw_netdev_priv(dev);
716 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
717 struct security_priv *psecuritypriv = &padapter->securitypriv;
719 param->u.crypt.err = 0;
720 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
722 if (param_len < (u32) ((u8 *) param->u.crypt.key - (u8 *) param) + param->u.crypt.key_len) {
727 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
728 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
729 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
730 if (param->u.crypt.idx >= WEP_KEYS
731 || param->u.crypt.idx >= BIP_MAX_KEYID) {
742 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
743 wep_key_idx = param->u.crypt.idx;
744 wep_key_len = param->u.crypt.key_len;
746 if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) {
751 if (psecuritypriv->bWepDefaultKeyIdxSet == 0) {
752 /* wep default key has not been set, so use this key index as default key. */
754 wep_key_len = wep_key_len <= 5 ? 5 : 13;
756 psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
757 psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
758 psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
760 if (wep_key_len == 13) {
761 psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
762 psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
765 psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
768 memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len);
770 psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len;
772 rtw_set_key(padapter, psecuritypriv, wep_key_idx, 0, true);
777 if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) { /* 802_1x */
778 struct sta_info *psta, *pbcmc_sta;
779 struct sta_priv *pstapriv = &padapter->stapriv;
781 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE) == true) { /* sta mode */
782 psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
784 /* Jeff: don't disable ieee8021x_blocked while clearing key */
785 if (strcmp(param->u.crypt.alg, "none") != 0)
786 psta->ieee8021x_blocked = false;
789 if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) ||
790 (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled)) {
791 psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
794 if (param->u.crypt.set_tx == 1) { /* pairwise key */
796 memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
798 if (strcmp(param->u.crypt.alg, "TKIP") == 0) { /* set mic key */
799 /* DEBUG_ERR(("\nset key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len)); */
800 memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
801 memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
803 padapter->securitypriv.busetkipkey = false;
804 /* _set_timer(&padapter->securitypriv.tkip_timer, 50); */
807 rtw_setstakey_cmd(padapter, psta, true, true);
808 } else { /* group key */
809 if (strcmp(param->u.crypt.alg, "TKIP") == 0 || strcmp(param->u.crypt.alg, "CCMP") == 0) {
810 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));
811 memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
812 memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
813 padapter->securitypriv.binstallGrpkey = true;
815 padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx;
816 rtw_set_key(padapter, &padapter->securitypriv, param->u.crypt.idx, 1, true);
817 } else if (strcmp(param->u.crypt.alg, "BIP") == 0) {
818 /* save the IGTK key, length 16 bytes */
819 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));
821 for (no = 0;no<16;no++)
822 printk(" %02x ", padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey[no]);
824 padapter->securitypriv.dot11wBIPKeyid = param->u.crypt.idx;
825 padapter->securitypriv.binstallBIPkey = true;
830 pbcmc_sta = rtw_get_bcmc_stainfo(padapter);
832 /* DEBUG_ERR(("Set OID_802_11_ADD_KEY: bcmc stainfo is null\n")); */
834 /* Jeff: don't disable ieee8021x_blocked while clearing key */
835 if (strcmp(param->u.crypt.alg, "none") != 0)
836 pbcmc_sta->ieee8021x_blocked = false;
838 if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) ||
839 (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled)) {
840 pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
843 } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { /* adhoc mode */
852 static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev,
853 int link_id, u8 key_index, bool pairwise,
854 const u8 *mac_addr, struct key_params *params)
858 struct ieee_param *param = NULL;
860 struct adapter *padapter = rtw_netdev_priv(ndev);
861 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
863 param_len = sizeof(struct ieee_param) + params->key_len;
864 param = rtw_malloc(param_len);
868 memset(param, 0, param_len);
870 param->cmd = IEEE_CMD_SET_ENCRYPTION;
871 eth_broadcast_addr(param->sta_addr);
873 switch (params->cipher) {
874 case IW_AUTH_CIPHER_NONE:
875 /* todo: remove key */
879 case WLAN_CIPHER_SUITE_WEP40:
880 case WLAN_CIPHER_SUITE_WEP104:
883 case WLAN_CIPHER_SUITE_TKIP:
886 case WLAN_CIPHER_SUITE_CCMP:
889 case WLAN_CIPHER_SUITE_AES_CMAC:
897 strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
900 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
901 param->u.crypt.set_tx = 0; /* for wpa/wpa2 group key */
903 param->u.crypt.set_tx = 1; /* for wpa/wpa2 pairwise key */
905 param->u.crypt.idx = key_index;
907 if (params->seq_len && params->seq)
908 memcpy(param->u.crypt.seq, (u8 *)params->seq, params->seq_len);
910 if (params->key_len && params->key) {
911 param->u.crypt.key_len = params->key_len;
912 memcpy(param->u.crypt.key, (u8 *)params->key, params->key_len);
915 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) {
916 ret = rtw_cfg80211_set_encryption(ndev, param, param_len);
917 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
919 memcpy(param->sta_addr, (void *)mac_addr, ETH_ALEN);
921 ret = rtw_cfg80211_ap_set_encryption(ndev, param, param_len);
922 } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true
923 || check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) {
924 ret = rtw_cfg80211_set_encryption(ndev, param, param_len);
934 static int cfg80211_rtw_get_key(struct wiphy *wiphy, struct net_device *ndev,
935 int link_id, u8 key_index, bool pairwise,
936 const u8 *mac_addr, void *cookie,
937 void (*callback)(void *cookie,
943 static int cfg80211_rtw_del_key(struct wiphy *wiphy, struct net_device *ndev,
944 int link_id, u8 key_index, bool pairwise,
947 struct adapter *padapter = rtw_netdev_priv(ndev);
948 struct security_priv *psecuritypriv = &padapter->securitypriv;
950 if (key_index == psecuritypriv->dot11PrivacyKeyIndex) {
951 /* clear the flag of wep default key set. */
952 psecuritypriv->bWepDefaultKeyIdxSet = 0;
958 static int cfg80211_rtw_set_default_key(struct wiphy *wiphy,
959 struct net_device *ndev, int link_id, u8 key_index
960 , bool unicast, bool multicast
963 struct adapter *padapter = rtw_netdev_priv(ndev);
964 struct security_priv *psecuritypriv = &padapter->securitypriv;
966 if ((key_index < WEP_KEYS) && ((psecuritypriv->dot11PrivacyAlgrthm == _WEP40_) || (psecuritypriv->dot11PrivacyAlgrthm == _WEP104_))) { /* set wep default key */
967 psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
969 psecuritypriv->dot11PrivacyKeyIndex = key_index;
971 psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
972 psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
973 if (psecuritypriv->dot11DefKeylen[key_index] == 13) {
974 psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
975 psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
978 psecuritypriv->bWepDefaultKeyIdxSet = 1; /* set the flag to represent that wep default key has been set */
985 static int cfg80211_rtw_get_station(struct wiphy *wiphy,
986 struct net_device *ndev,
988 struct station_info *sinfo)
991 struct adapter *padapter = rtw_netdev_priv(ndev);
992 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
993 struct sta_info *psta = NULL;
994 struct sta_priv *pstapriv = &padapter->stapriv;
1003 psta = rtw_get_stainfo(pstapriv, (u8 *)mac);
1009 /* for infra./P2PClient mode */
1010 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)
1011 && check_fwstate(pmlmepriv, _FW_LINKED)) {
1012 struct wlan_network *cur_network = &(pmlmepriv->cur_network);
1014 if (memcmp((u8 *)mac, cur_network->network.mac_address, ETH_ALEN)) {
1019 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
1020 sinfo->signal = translate_percentage_to_dbm(padapter->recvpriv.signal_strength);
1022 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
1023 sinfo->txrate.legacy = rtw_get_cur_max_rate(padapter);
1025 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS);
1026 sinfo->rx_packets = sta_rx_data_pkts(psta);
1028 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
1029 sinfo->tx_packets = psta->sta_stats.tx_pkts;
1030 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
1033 /* for Ad-Hoc/AP mode */
1034 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)
1035 || check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)
1036 || check_fwstate(pmlmepriv, WIFI_AP_STATE))
1037 && check_fwstate(pmlmepriv, _FW_LINKED)) {
1038 /* TODO: should acquire station info... */
1045 static int cfg80211_rtw_change_iface(struct wiphy *wiphy,
1046 struct net_device *ndev,
1047 enum nl80211_iftype type,
1048 struct vif_params *params)
1050 enum nl80211_iftype old_type;
1051 enum ndis_802_11_network_infrastructure networkType;
1052 struct adapter *padapter = rtw_netdev_priv(ndev);
1053 struct wireless_dev *rtw_wdev = padapter->rtw_wdev;
1054 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1057 if (adapter_to_dvobj(padapter)->processing_dev_remove == true) {
1063 if (netdev_open(ndev) != 0) {
1069 if (_FAIL == rtw_pwr_wakeup(padapter)) {
1074 old_type = rtw_wdev->iftype;
1076 if (old_type != type) {
1077 pmlmeext->action_public_rxseq = 0xffff;
1078 pmlmeext->action_public_dialog_token = 0xff;
1082 case NL80211_IFTYPE_ADHOC:
1083 networkType = Ndis802_11IBSS;
1085 case NL80211_IFTYPE_STATION:
1086 networkType = Ndis802_11Infrastructure;
1088 case NL80211_IFTYPE_AP:
1089 networkType = Ndis802_11APMode;
1096 rtw_wdev->iftype = type;
1098 if (rtw_set_802_11_infrastructure_mode(padapter, networkType) == false) {
1099 rtw_wdev->iftype = old_type;
1104 rtw_setopmode_cmd(padapter, networkType, true);
1111 void rtw_cfg80211_indicate_scan_done(struct adapter *adapter, bool aborted)
1113 struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(adapter);
1114 struct cfg80211_scan_info info = {
1118 spin_lock_bh(&pwdev_priv->scan_req_lock);
1119 if (pwdev_priv->scan_request) {
1120 /* avoid WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req); */
1121 if (pwdev_priv->scan_request->wiphy == pwdev_priv->rtw_wdev->wiphy)
1122 cfg80211_scan_done(pwdev_priv->scan_request, &info);
1124 pwdev_priv->scan_request = NULL;
1126 spin_unlock_bh(&pwdev_priv->scan_req_lock);
1129 void rtw_cfg80211_unlink_bss(struct adapter *padapter, struct wlan_network *pnetwork)
1131 struct wireless_dev *pwdev = padapter->rtw_wdev;
1132 struct wiphy *wiphy = pwdev->wiphy;
1133 struct cfg80211_bss *bss = NULL;
1134 struct wlan_bssid_ex *select_network = &pnetwork->network;
1136 bss = cfg80211_get_bss(wiphy, NULL/*notify_channel*/,
1137 select_network->mac_address, select_network->ssid.ssid,
1138 select_network->ssid.ssid_length, 0/*WLAN_CAPABILITY_ESS*/,
1139 0/*WLAN_CAPABILITY_ESS*/);
1142 cfg80211_unlink_bss(wiphy, bss);
1143 cfg80211_put_bss(padapter->rtw_wdev->wiphy, bss);
1147 void rtw_cfg80211_surveydone_event_callback(struct adapter *padapter)
1149 struct list_head *plist, *phead;
1150 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1151 struct __queue *queue = &(pmlmepriv->scanned_queue);
1152 struct wlan_network *pnetwork = NULL;
1154 spin_lock_bh(&(pmlmepriv->scanned_queue.lock));
1156 phead = get_list_head(queue);
1157 list_for_each(plist, phead)
1159 pnetwork = list_entry(plist, struct wlan_network, list);
1161 /* report network only if the current channel set contains the channel to which this network belongs */
1162 if (rtw_ch_set_search_ch(padapter->mlmeextpriv.channel_set, pnetwork->network.configuration.ds_config) >= 0
1163 && true == rtw_validate_ssid(&(pnetwork->network.ssid))) {
1164 /* ev =translate_scan(padapter, a, pnetwork, ev, stop); */
1165 rtw_cfg80211_inform_bss(padapter, pnetwork);
1170 spin_unlock_bh(&(pmlmepriv->scanned_queue.lock));
1173 static int rtw_cfg80211_set_probe_req_wpsp2pie(struct adapter *padapter, char *buf, int len)
1178 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1181 wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen);
1183 if (pmlmepriv->wps_probe_req_ie) {
1184 pmlmepriv->wps_probe_req_ie_len = 0;
1185 kfree(pmlmepriv->wps_probe_req_ie);
1186 pmlmepriv->wps_probe_req_ie = NULL;
1189 pmlmepriv->wps_probe_req_ie = rtw_malloc(wps_ielen);
1190 if (!pmlmepriv->wps_probe_req_ie)
1193 memcpy(pmlmepriv->wps_probe_req_ie, wps_ie, wps_ielen);
1194 pmlmepriv->wps_probe_req_ie_len = wps_ielen;
1202 static int cfg80211_rtw_scan(struct wiphy *wiphy
1203 , struct cfg80211_scan_request *request)
1205 struct net_device *ndev = wdev_to_ndev(request->wdev);
1209 struct ndis_802_11_ssid *ssid = NULL;
1210 struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT];
1211 u8 survey_times = 3;
1212 u8 survey_times_for_one_ch = 6;
1213 struct cfg80211_ssid *ssids = request->ssids;
1215 bool need_indicate_scan_done = false;
1217 struct adapter *padapter;
1218 struct rtw_wdev_priv *pwdev_priv;
1219 struct mlme_priv *pmlmepriv;
1226 padapter = rtw_netdev_priv(ndev);
1227 pwdev_priv = adapter_wdev_data(padapter);
1228 pmlmepriv = &padapter->mlmepriv;
1231 spin_lock_bh(&pwdev_priv->scan_req_lock);
1232 pwdev_priv->scan_request = request;
1233 spin_unlock_bh(&pwdev_priv->scan_req_lock);
1235 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
1236 if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS|_FW_UNDER_SURVEY|_FW_UNDER_LINKING) == true) {
1237 need_indicate_scan_done = true;
1238 goto check_need_indicate_scan_done;
1242 rtw_ps_deny(padapter, PS_DENY_SCAN);
1243 if (_FAIL == rtw_pwr_wakeup(padapter)) {
1244 need_indicate_scan_done = true;
1245 goto check_need_indicate_scan_done;
1248 if (request->ie && request->ie_len > 0)
1249 rtw_cfg80211_set_probe_req_wpsp2pie(padapter, (u8 *)request->ie, request->ie_len);
1251 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true) {
1252 need_indicate_scan_done = true;
1253 goto check_need_indicate_scan_done;
1254 } else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true) {
1256 goto check_need_indicate_scan_done;
1259 if (pmlmepriv->LinkDetectInfo.bBusyTraffic == true) {
1260 static unsigned long lastscantime;
1261 unsigned long passtime;
1263 passtime = jiffies_to_msecs(jiffies - lastscantime);
1264 lastscantime = jiffies;
1265 if (passtime > 12000) {
1266 need_indicate_scan_done = true;
1267 goto check_need_indicate_scan_done;
1271 if (rtw_is_scan_deny(padapter)) {
1272 need_indicate_scan_done = true;
1273 goto check_need_indicate_scan_done;
1276 ssid = kzalloc(RTW_SSID_SCAN_AMOUNT * sizeof(struct ndis_802_11_ssid),
1280 goto check_need_indicate_scan_done;
1283 /* parsing request ssids, n_ssids */
1284 for (i = 0; i < request->n_ssids && i < RTW_SSID_SCAN_AMOUNT; i++) {
1285 memcpy(ssid[i].ssid, ssids[i].ssid, ssids[i].ssid_len);
1286 ssid[i].ssid_length = ssids[i].ssid_len;
1289 /* parsing channels, n_channels */
1290 memset(ch, 0, sizeof(struct rtw_ieee80211_channel)*RTW_CHANNEL_SCAN_AMOUNT);
1291 for (i = 0; i < request->n_channels && i < RTW_CHANNEL_SCAN_AMOUNT; i++) {
1292 ch[i].hw_value = request->channels[i]->hw_value;
1293 ch[i].flags = request->channels[i]->flags;
1296 spin_lock_bh(&pmlmepriv->lock);
1297 if (request->n_channels == 1) {
1298 for (i = 1; i < survey_times_for_one_ch; i++)
1299 memcpy(&ch[i], &ch[0], sizeof(struct rtw_ieee80211_channel));
1300 _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, ch, survey_times_for_one_ch);
1301 } else if (request->n_channels <= 4) {
1302 for (j = request->n_channels - 1; j >= 0; j--)
1303 for (i = 0; i < survey_times; i++)
1304 memcpy(&ch[j*survey_times+i], &ch[j], sizeof(struct rtw_ieee80211_channel));
1305 _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, ch, survey_times * request->n_channels);
1307 _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, NULL, 0);
1309 spin_unlock_bh(&pmlmepriv->lock);
1312 if (_status == false)
1315 check_need_indicate_scan_done:
1317 if (need_indicate_scan_done) {
1318 rtw_cfg80211_surveydone_event_callback(padapter);
1319 rtw_cfg80211_indicate_scan_done(padapter, false);
1322 rtw_ps_deny_cancel(padapter, PS_DENY_SCAN);
1329 static int cfg80211_rtw_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1334 static int rtw_cfg80211_set_wpa_version(struct security_priv *psecuritypriv, u32 wpa_version)
1337 psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
1342 if (wpa_version & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
1343 psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPAPSK;
1349 static int rtw_cfg80211_set_auth_type(struct security_priv *psecuritypriv,
1350 enum nl80211_auth_type sme_auth_type)
1352 switch (sme_auth_type) {
1353 case NL80211_AUTHTYPE_AUTOMATIC:
1355 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
1358 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1360 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
1362 if (psecuritypriv->ndisauthtype > Ndis802_11AuthModeWPA)
1363 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1366 case NL80211_AUTHTYPE_SHARED_KEY:
1368 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
1370 psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
1375 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
1376 /* return -ENOTSUPP; */
1383 static int rtw_cfg80211_set_cipher(struct security_priv *psecuritypriv, u32 cipher, bool ucast)
1385 u32 ndisencryptstatus = Ndis802_11EncryptionDisabled;
1387 u32 *profile_cipher = ucast ? &psecuritypriv->dot11PrivacyAlgrthm :
1388 &psecuritypriv->dot118021XGrpPrivacy;
1392 *profile_cipher = _NO_PRIVACY_;
1393 psecuritypriv->ndisencryptstatus = ndisencryptstatus;
1398 case IW_AUTH_CIPHER_NONE:
1399 *profile_cipher = _NO_PRIVACY_;
1400 ndisencryptstatus = Ndis802_11EncryptionDisabled;
1402 case WLAN_CIPHER_SUITE_WEP40:
1403 *profile_cipher = _WEP40_;
1404 ndisencryptstatus = Ndis802_11Encryption1Enabled;
1406 case WLAN_CIPHER_SUITE_WEP104:
1407 *profile_cipher = _WEP104_;
1408 ndisencryptstatus = Ndis802_11Encryption1Enabled;
1410 case WLAN_CIPHER_SUITE_TKIP:
1411 *profile_cipher = _TKIP_;
1412 ndisencryptstatus = Ndis802_11Encryption2Enabled;
1414 case WLAN_CIPHER_SUITE_CCMP:
1415 *profile_cipher = _AES_;
1416 ndisencryptstatus = Ndis802_11Encryption3Enabled;
1423 psecuritypriv->ndisencryptstatus = ndisencryptstatus;
1425 /* if (psecuritypriv->dot11PrivacyAlgrthm >= _AES_) */
1426 /* psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK; */
1432 static int rtw_cfg80211_set_key_mgt(struct security_priv *psecuritypriv, u32 key_mgt)
1434 if (key_mgt == WLAN_AKM_SUITE_8021X)
1435 /* auth_type = UMAC_AUTH_TYPE_8021X; */
1436 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1437 else if (key_mgt == WLAN_AKM_SUITE_PSK) {
1438 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1444 static int rtw_cfg80211_set_wpa_ie(struct adapter *padapter, u8 *pie, size_t ielen)
1447 int group_cipher = 0, pairwise_cipher = 0;
1452 u8 null_addr[] = {0, 0, 0, 0, 0, 0};
1454 if (!pie || !ielen) {
1455 /* Treat this as normal case, but need to clear WIFI_UNDER_WPS */
1456 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
1460 if (ielen > MAX_WPA_IE_LEN+MAX_WPS_IE_LEN+MAX_P2P_IE_LEN) {
1465 buf = rtw_zmalloc(ielen);
1471 memcpy(buf, pie, ielen);
1473 if (ielen < RSN_HEADER_LEN) {
1478 pwpa = rtw_get_wpa_ie(buf, &wpa_ielen, ielen);
1479 if (pwpa && wpa_ielen > 0) {
1480 if (rtw_parse_wpa_ie(pwpa, wpa_ielen+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1481 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1482 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK;
1483 memcpy(padapter->securitypriv.supplicant_ie, &pwpa[0], wpa_ielen+2);
1487 pwpa2 = rtw_get_wpa2_ie(buf, &wpa2_ielen, ielen);
1488 if (pwpa2 && wpa2_ielen > 0) {
1489 if (rtw_parse_wpa2_ie(pwpa2, wpa2_ielen+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1490 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1491 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK;
1492 memcpy(padapter->securitypriv.supplicant_ie, &pwpa2[0], wpa2_ielen+2);
1496 if (group_cipher == 0)
1497 group_cipher = WPA_CIPHER_NONE;
1499 if (pairwise_cipher == 0)
1500 pairwise_cipher = WPA_CIPHER_NONE;
1502 switch (group_cipher) {
1503 case WPA_CIPHER_NONE:
1504 padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
1505 padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
1507 case WPA_CIPHER_WEP40:
1508 padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_;
1509 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
1511 case WPA_CIPHER_TKIP:
1512 padapter->securitypriv.dot118021XGrpPrivacy = _TKIP_;
1513 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
1515 case WPA_CIPHER_CCMP:
1516 padapter->securitypriv.dot118021XGrpPrivacy = _AES_;
1517 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
1519 case WPA_CIPHER_WEP104:
1520 padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_;
1521 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
1525 switch (pairwise_cipher) {
1526 case WPA_CIPHER_NONE:
1527 padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
1528 padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
1530 case WPA_CIPHER_WEP40:
1531 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
1532 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
1534 case WPA_CIPHER_TKIP:
1535 padapter->securitypriv.dot11PrivacyAlgrthm = _TKIP_;
1536 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
1538 case WPA_CIPHER_CCMP:
1539 padapter->securitypriv.dot11PrivacyAlgrthm = _AES_;
1540 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
1542 case WPA_CIPHER_WEP104:
1543 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
1544 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
1548 {/* handle wps_ie */
1552 wps_ie = rtw_get_wps_ie(buf, ielen, NULL, &wps_ielen);
1553 if (wps_ie && wps_ielen > 0) {
1554 padapter->securitypriv.wps_ie_len = wps_ielen < MAX_WPS_IE_LEN ? wps_ielen : MAX_WPS_IE_LEN;
1555 memcpy(padapter->securitypriv.wps_ie, wps_ie, padapter->securitypriv.wps_ie_len);
1556 set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS);
1558 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
1562 /* TKIP and AES disallow multicast packets until installing group key */
1563 if (padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_
1564 || padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_WTMIC_
1565 || padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)
1566 /* WPS open need to enable multicast */
1567 /* check_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS) == true) */
1568 rtw_hal_set_hwreg(padapter, HW_VAR_OFF_RCR_AM, null_addr);
1573 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
1577 static int cfg80211_rtw_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
1578 struct cfg80211_ibss_params *params)
1580 struct adapter *padapter = rtw_netdev_priv(ndev);
1581 struct ndis_802_11_ssid ndis_ssid;
1582 struct security_priv *psecuritypriv = &padapter->securitypriv;
1583 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1586 if (_FAIL == rtw_pwr_wakeup(padapter)) {
1591 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1596 if (!params->ssid || !params->ssid_len) {
1601 if (params->ssid_len > IW_ESSID_MAX_SIZE) {
1607 memset(&ndis_ssid, 0, sizeof(struct ndis_802_11_ssid));
1608 ndis_ssid.ssid_length = params->ssid_len;
1609 memcpy(ndis_ssid.ssid, (u8 *)params->ssid, params->ssid_len);
1611 psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled;
1612 psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
1613 psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
1614 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
1615 psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
1617 ret = rtw_cfg80211_set_auth_type(psecuritypriv, NL80211_AUTHTYPE_OPEN_SYSTEM);
1618 rtw_set_802_11_authentication_mode(padapter, psecuritypriv->ndisauthtype);
1620 if (rtw_set_802_11_ssid(padapter, &ndis_ssid) == false) {
1629 static int cfg80211_rtw_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
1631 struct adapter *padapter = rtw_netdev_priv(ndev);
1632 struct wireless_dev *rtw_wdev = padapter->rtw_wdev;
1633 enum nl80211_iftype old_type;
1636 old_type = rtw_wdev->iftype;
1638 rtw_set_to_roam(padapter, 0);
1640 if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
1641 rtw_scan_abort(padapter);
1642 LeaveAllPowerSaveMode(padapter);
1644 rtw_wdev->iftype = NL80211_IFTYPE_STATION;
1646 if (rtw_set_802_11_infrastructure_mode(padapter, Ndis802_11Infrastructure) == false) {
1647 rtw_wdev->iftype = old_type;
1651 rtw_setopmode_cmd(padapter, Ndis802_11Infrastructure, true);
1658 static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
1659 struct cfg80211_connect_params *sme)
1662 enum ndis_802_11_authentication_mode authmode;
1663 struct ndis_802_11_ssid ndis_ssid;
1664 struct adapter *padapter = rtw_netdev_priv(ndev);
1665 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1666 struct security_priv *psecuritypriv = &padapter->securitypriv;
1668 padapter->mlmepriv.not_indic_disco = true;
1671 if (adapter_wdev_data(padapter)->block == true) {
1676 rtw_ps_deny(padapter, PS_DENY_JOIN);
1677 if (_FAIL == rtw_pwr_wakeup(padapter)) {
1682 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1687 if (!sme->ssid || !sme->ssid_len) {
1692 if (sme->ssid_len > IW_ESSID_MAX_SIZE) {
1698 memset(&ndis_ssid, 0, sizeof(struct ndis_802_11_ssid));
1699 ndis_ssid.ssid_length = sme->ssid_len;
1700 memcpy(ndis_ssid.ssid, (u8 *)sme->ssid, sme->ssid_len);
1702 if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true) {
1706 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true)
1707 rtw_scan_abort(padapter);
1709 psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled;
1710 psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
1711 psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
1712 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
1713 psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
1715 ret = rtw_cfg80211_set_wpa_version(psecuritypriv, sme->crypto.wpa_versions);
1719 ret = rtw_cfg80211_set_auth_type(psecuritypriv, sme->auth_type);
1724 ret = rtw_cfg80211_set_wpa_ie(padapter, (u8 *)sme->ie, sme->ie_len);
1728 if (sme->crypto.n_ciphers_pairwise) {
1729 ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.ciphers_pairwise[0], true);
1734 /* For WEP Shared auth */
1735 if ((psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Shared ||
1736 psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Auto) && sme->key) {
1737 u32 wep_key_idx, wep_key_len, wep_total_len;
1738 struct ndis_802_11_wep *pwep = NULL;
1740 wep_key_idx = sme->key_idx;
1741 wep_key_len = sme->key_len;
1743 if (sme->key_idx > WEP_KEYS) {
1748 if (wep_key_len > 0) {
1749 wep_key_len = wep_key_len <= 5 ? 5 : 13;
1750 wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, key_material);
1751 pwep = rtw_malloc(wep_total_len);
1757 memset(pwep, 0, wep_total_len);
1759 pwep->key_length = wep_key_len;
1760 pwep->length = wep_total_len;
1762 if (wep_key_len == 13) {
1763 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
1764 padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_;
1771 pwep->key_index = wep_key_idx;
1772 pwep->key_index |= 0x80000000;
1774 memcpy(pwep->key_material, (void *)sme->key, pwep->key_length);
1776 if (rtw_set_802_11_add_wep(padapter, pwep) == (u8)_FAIL)
1785 ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.cipher_group, false);
1789 if (sme->crypto.n_akm_suites) {
1790 ret = rtw_cfg80211_set_key_mgt(psecuritypriv, sme->crypto.akm_suites[0]);
1795 authmode = psecuritypriv->ndisauthtype;
1796 rtw_set_802_11_authentication_mode(padapter, authmode);
1798 /* rtw_set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus); */
1800 if (rtw_set_802_11_connect(padapter, (u8 *)sme->bssid, &ndis_ssid) == false) {
1807 rtw_ps_deny_cancel(padapter, PS_DENY_JOIN);
1809 padapter->mlmepriv.not_indic_disco = false;
1814 static int cfg80211_rtw_disconnect(struct wiphy *wiphy, struct net_device *ndev,
1817 struct adapter *padapter = rtw_netdev_priv(ndev);
1819 rtw_set_to_roam(padapter, 0);
1821 rtw_scan_abort(padapter);
1822 LeaveAllPowerSaveMode(padapter);
1823 rtw_disassoc_cmd(padapter, 500, false);
1825 rtw_indicate_disconnect(padapter);
1827 rtw_free_assoc_resources(padapter, 1);
1828 rtw_pwr_wakeup(padapter);
1833 static int cfg80211_rtw_set_txpower(struct wiphy *wiphy,
1834 struct wireless_dev *wdev,
1835 enum nl80211_tx_power_setting type, int mbm)
1840 static int cfg80211_rtw_get_txpower(struct wiphy *wiphy,
1841 struct wireless_dev *wdev,
1849 inline bool rtw_cfg80211_pwr_mgmt(struct adapter *adapter)
1851 struct rtw_wdev_priv *rtw_wdev_priv = adapter_wdev_data(adapter);
1852 return rtw_wdev_priv->power_mgmt;
1855 static int cfg80211_rtw_set_power_mgmt(struct wiphy *wiphy,
1856 struct net_device *ndev,
1857 bool enabled, int timeout)
1859 struct adapter *padapter = rtw_netdev_priv(ndev);
1860 struct rtw_wdev_priv *rtw_wdev_priv = adapter_wdev_data(padapter);
1862 rtw_wdev_priv->power_mgmt = enabled;
1865 LPS_Leave(padapter, "CFG80211_PWRMGMT");
1870 static int cfg80211_rtw_set_pmksa(struct wiphy *wiphy,
1871 struct net_device *ndev,
1872 struct cfg80211_pmksa *pmksa)
1874 u8 index, blInserted = false;
1875 struct adapter *padapter = rtw_netdev_priv(ndev);
1876 struct security_priv *psecuritypriv = &padapter->securitypriv;
1877 u8 strZeroMacAddress[ETH_ALEN] = { 0x00 };
1879 if (!memcmp((u8 *)pmksa->bssid, strZeroMacAddress, ETH_ALEN))
1884 /* overwrite PMKID */
1885 for (index = 0 ; index < NUM_PMKID_CACHE; index++) {
1886 if (!memcmp(psecuritypriv->PMKIDList[index].Bssid, (u8 *)pmksa->bssid, ETH_ALEN)) {
1888 memcpy(psecuritypriv->PMKIDList[index].PMKID, (u8 *)pmksa->pmkid, WLAN_PMKID_LEN);
1889 psecuritypriv->PMKIDList[index].bUsed = true;
1890 psecuritypriv->PMKIDIndex = index+1;
1898 memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].Bssid, (u8 *)pmksa->bssid, ETH_ALEN);
1899 memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, (u8 *)pmksa->pmkid, WLAN_PMKID_LEN);
1901 psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = true;
1902 psecuritypriv->PMKIDIndex++;
1903 if (psecuritypriv->PMKIDIndex == 16)
1904 psecuritypriv->PMKIDIndex = 0;
1910 static int cfg80211_rtw_del_pmksa(struct wiphy *wiphy,
1911 struct net_device *ndev,
1912 struct cfg80211_pmksa *pmksa)
1914 u8 index, bMatched = false;
1915 struct adapter *padapter = rtw_netdev_priv(ndev);
1916 struct security_priv *psecuritypriv = &padapter->securitypriv;
1918 for (index = 0 ; index < NUM_PMKID_CACHE; index++) {
1919 if (!memcmp(psecuritypriv->PMKIDList[index].Bssid, (u8 *)pmksa->bssid, ETH_ALEN)) {
1921 * BSSID is matched, the same AP => Remove this PMKID information
1924 eth_zero_addr(psecuritypriv->PMKIDList[index].Bssid);
1925 memset(psecuritypriv->PMKIDList[index].PMKID, 0x00, WLAN_PMKID_LEN);
1926 psecuritypriv->PMKIDList[index].bUsed = false;
1938 static int cfg80211_rtw_flush_pmksa(struct wiphy *wiphy,
1939 struct net_device *ndev)
1941 struct adapter *padapter = rtw_netdev_priv(ndev);
1942 struct security_priv *psecuritypriv = &padapter->securitypriv;
1944 memset(&psecuritypriv->PMKIDList[0], 0x00, sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
1945 psecuritypriv->PMKIDIndex = 0;
1950 void rtw_cfg80211_indicate_sta_assoc(struct adapter *padapter, u8 *pmgmt_frame, uint frame_len)
1952 struct net_device *ndev = padapter->pnetdev;
1955 struct station_info sinfo = {};
1957 if (GetFrameSubType(pmgmt_frame) == WIFI_ASSOCREQ)
1958 ie_offset = _ASOCREQ_IE_OFFSET_;
1959 else /* WIFI_REASSOCREQ */
1960 ie_offset = _REASOCREQ_IE_OFFSET_;
1963 sinfo.assoc_req_ies = pmgmt_frame + WLAN_HDR_A3_LEN + ie_offset;
1964 sinfo.assoc_req_ies_len = frame_len - WLAN_HDR_A3_LEN - ie_offset;
1965 cfg80211_new_sta(ndev, GetAddr2Ptr(pmgmt_frame), &sinfo, GFP_ATOMIC);
1969 void rtw_cfg80211_indicate_sta_disassoc(struct adapter *padapter, unsigned char *da, unsigned short reason)
1971 struct net_device *ndev = padapter->pnetdev;
1973 cfg80211_del_sta(ndev, da, GFP_ATOMIC);
1976 static u8 rtw_get_chan_type(struct adapter *adapter)
1978 struct mlme_ext_priv *mlme_ext = &adapter->mlmeextpriv;
1980 switch (mlme_ext->cur_bwmode) {
1981 case CHANNEL_WIDTH_20:
1982 if (is_supported_ht(adapter->registrypriv.wireless_mode))
1983 return NL80211_CHAN_HT20;
1985 return NL80211_CHAN_NO_HT;
1986 case CHANNEL_WIDTH_40:
1987 if (mlme_ext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
1988 return NL80211_CHAN_HT40PLUS;
1990 return NL80211_CHAN_HT40MINUS;
1992 return NL80211_CHAN_HT20;
1995 return NL80211_CHAN_HT20;
1998 static int cfg80211_rtw_get_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
1999 unsigned int link_id,
2000 struct cfg80211_chan_def *chandef)
2002 struct adapter *adapter = wiphy_to_adapter(wiphy);
2003 struct registry_priv *registrypriv = &adapter->registrypriv;
2004 enum nl80211_channel_type chan_type;
2005 struct ieee80211_channel *chan = NULL;
2009 if (!adapter->rtw_wdev)
2012 channel = rtw_get_oper_ch(adapter);
2016 freq = rtw_ieee80211_channel_to_frequency(channel, NL80211_BAND_2GHZ);
2018 chan = ieee80211_get_channel(adapter->rtw_wdev->wiphy, freq);
2020 if (registrypriv->ht_enable) {
2021 chan_type = rtw_get_chan_type(adapter);
2022 cfg80211_chandef_create(chandef, chan, chan_type);
2024 cfg80211_chandef_create(chandef, chan, NL80211_CHAN_NO_HT);
2030 static netdev_tx_t rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_device *ndev)
2034 int dot11_hdr_len = 24;
2036 unsigned char *pdata;
2038 unsigned char src_mac_addr[6];
2039 unsigned char dst_mac_addr[6];
2040 struct ieee80211_hdr *dot11_hdr;
2041 struct ieee80211_radiotap_header *rtap_hdr;
2042 struct adapter *padapter = rtw_netdev_priv(ndev);
2047 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
2050 rtap_hdr = (struct ieee80211_radiotap_header *)skb->data;
2051 if (unlikely(rtap_hdr->it_version))
2054 rtap_len = ieee80211_get_radiotap_len(skb->data);
2055 if (unlikely(skb->len < rtap_len))
2061 /* Skip the ratio tap header */
2062 skb_pull(skb, rtap_len);
2064 dot11_hdr = (struct ieee80211_hdr *)skb->data;
2065 frame_control = le16_to_cpu(dot11_hdr->frame_control);
2066 /* Check if the QoS bit is set */
2067 if ((frame_control & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) {
2068 /* Check if this ia a Wireless Distribution System (WDS) frame
2069 * which has 4 MAC addresses
2071 if (frame_control & 0x0080)
2073 if ((frame_control & 0x0300) == 0x0300)
2076 memcpy(dst_mac_addr, dot11_hdr->addr1, sizeof(dst_mac_addr));
2077 memcpy(src_mac_addr, dot11_hdr->addr2, sizeof(src_mac_addr));
2079 /* Skip the 802.11 header, QoS (if any) and SNAP, but leave spaces for
2082 skb_pull(skb, dot11_hdr_len + qos_len + snap_len - sizeof(src_mac_addr) * 2);
2083 pdata = (unsigned char *)skb->data;
2084 memcpy(pdata, dst_mac_addr, sizeof(dst_mac_addr));
2085 memcpy(pdata + sizeof(dst_mac_addr), src_mac_addr, sizeof(src_mac_addr));
2087 /* Use the real net device to transmit the packet */
2088 return _rtw_xmit_entry(skb, padapter->pnetdev);
2090 } else if ((frame_control & (IEEE80211_FCTL_FTYPE|IEEE80211_FCTL_STYPE)) ==
2091 (IEEE80211_FTYPE_MGMT|IEEE80211_STYPE_ACTION)) {
2092 /* only for action frames */
2093 struct xmit_frame *pmgntframe;
2094 struct pkt_attrib *pattrib;
2095 unsigned char *pframe;
2096 /* u8 category, action, OUI_Subtype, dialogToken = 0; */
2097 /* unsigned char *frame_body; */
2098 struct ieee80211_hdr *pwlanhdr;
2099 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2100 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2101 u8 *buf = skb->data;
2103 u8 category, action;
2105 if (rtw_action_frame_parse(buf, len, &category, &action) == false)
2108 /* starting alloc mgmt frame to dump it */
2109 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2113 /* update attribute */
2114 pattrib = &pmgntframe->attrib;
2115 update_mgntframe_attrib(padapter, pattrib);
2116 pattrib->retry_ctrl = false;
2118 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2120 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2122 memcpy(pframe, (void *)buf, len);
2123 pattrib->pktlen = len;
2125 pwlanhdr = (struct ieee80211_hdr *)pframe;
2126 /* update seq number */
2127 pmlmeext->mgnt_seq = GetSequence(pwlanhdr);
2128 pattrib->seqnum = pmlmeext->mgnt_seq;
2129 pmlmeext->mgnt_seq++;
2132 pattrib->last_txcmdsz = pattrib->pktlen;
2134 dump_mgntframe(padapter, pmgntframe);
2140 dev_kfree_skb_any(skb);
2142 return NETDEV_TX_OK;
2148 static const struct net_device_ops rtw_cfg80211_monitor_if_ops = {
2149 .ndo_start_xmit = rtw_cfg80211_monitor_if_xmit_entry,
2152 static int rtw_cfg80211_add_monitor_if(struct adapter *padapter, char *name, struct net_device **ndev)
2155 struct net_device *mon_ndev = NULL;
2156 struct wireless_dev *mon_wdev = NULL;
2157 struct rtw_netdev_priv_indicator *pnpi;
2158 struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
2165 if (pwdev_priv->pmon_ndev) {
2170 mon_ndev = alloc_etherdev(sizeof(struct rtw_netdev_priv_indicator));
2176 mon_ndev->type = ARPHRD_IEEE80211_RADIOTAP;
2177 strncpy(mon_ndev->name, name, IFNAMSIZ);
2178 mon_ndev->name[IFNAMSIZ - 1] = 0;
2179 mon_ndev->needs_free_netdev = true;
2180 mon_ndev->priv_destructor = rtw_ndev_destructor;
2182 mon_ndev->netdev_ops = &rtw_cfg80211_monitor_if_ops;
2184 pnpi = netdev_priv(mon_ndev);
2185 pnpi->priv = padapter;
2186 pnpi->sizeof_priv = sizeof(struct adapter);
2189 mon_wdev = rtw_zmalloc(sizeof(struct wireless_dev));
2195 mon_wdev->wiphy = padapter->rtw_wdev->wiphy;
2196 mon_wdev->netdev = mon_ndev;
2197 mon_wdev->iftype = NL80211_IFTYPE_MONITOR;
2198 mon_ndev->ieee80211_ptr = mon_wdev;
2200 ret = cfg80211_register_netdevice(mon_ndev);
2204 *ndev = pwdev_priv->pmon_ndev = mon_ndev;
2205 memcpy(pwdev_priv->ifname_mon, name, IFNAMSIZ+1);
2208 if (ret && mon_wdev) {
2213 if (ret && mon_ndev) {
2214 free_netdev(mon_ndev);
2215 *ndev = mon_ndev = NULL;
2221 static struct wireless_dev *
2222 cfg80211_rtw_add_virtual_intf(
2223 struct wiphy *wiphy,
2225 unsigned char name_assign_type,
2226 enum nl80211_iftype type, struct vif_params *params)
2229 struct net_device *ndev = NULL;
2230 struct adapter *padapter = wiphy_to_adapter(wiphy);
2233 case NL80211_IFTYPE_ADHOC:
2234 case NL80211_IFTYPE_AP_VLAN:
2235 case NL80211_IFTYPE_WDS:
2236 case NL80211_IFTYPE_MESH_POINT:
2239 case NL80211_IFTYPE_MONITOR:
2240 ret = rtw_cfg80211_add_monitor_if(padapter, (char *)name, &ndev);
2242 case NL80211_IFTYPE_P2P_CLIENT:
2243 case NL80211_IFTYPE_STATION:
2246 case NL80211_IFTYPE_P2P_GO:
2247 case NL80211_IFTYPE_AP:
2255 return ndev ? ndev->ieee80211_ptr : ERR_PTR(ret);
2258 static int cfg80211_rtw_del_virtual_intf(struct wiphy *wiphy,
2259 struct wireless_dev *wdev
2262 struct net_device *ndev = wdev_to_ndev(wdev);
2264 struct adapter *adapter;
2265 struct rtw_wdev_priv *pwdev_priv;
2272 adapter = rtw_netdev_priv(ndev);
2273 pwdev_priv = adapter_wdev_data(adapter);
2275 cfg80211_unregister_netdevice(ndev);
2277 if (ndev == pwdev_priv->pmon_ndev) {
2278 pwdev_priv->pmon_ndev = NULL;
2279 pwdev_priv->ifname_mon[0] = '\0';
2286 static int rtw_add_beacon(struct adapter *adapter, const u8 *head, size_t head_len, const u8 *tail, size_t tail_len)
2290 uint len, wps_ielen = 0;
2291 struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
2293 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true)
2299 pbuf = rtw_zmalloc(head_len+tail_len);
2303 memcpy(pbuf, (void *)head+24, head_len-24);/* 24 =beacon header len. */
2304 memcpy(pbuf+head_len-24, (void *)tail, tail_len);
2306 len = head_len+tail_len-24;
2308 /* check wps ie if inclued */
2309 rtw_get_wps_ie(pbuf + _FIXED_IE_LENGTH_, len - _FIXED_IE_LENGTH_, NULL, &wps_ielen);
2311 /* pbss_network->ies will not include p2p_ie, wfd ie */
2312 rtw_ies_remove_ie(pbuf, &len, _BEACON_IE_OFFSET_, WLAN_EID_VENDOR_SPECIFIC, P2P_OUI, 4);
2313 rtw_ies_remove_ie(pbuf, &len, _BEACON_IE_OFFSET_, WLAN_EID_VENDOR_SPECIFIC, WFD_OUI, 4);
2315 if (rtw_check_beacon_data(adapter, pbuf, len) == _SUCCESS)
2326 static int cfg80211_rtw_start_ap(struct wiphy *wiphy, struct net_device *ndev,
2327 struct cfg80211_ap_settings *settings)
2330 struct adapter *adapter = rtw_netdev_priv(ndev);
2332 ret = rtw_add_beacon(adapter, settings->beacon.head, settings->beacon.head_len,
2333 settings->beacon.tail, settings->beacon.tail_len);
2335 adapter->mlmeextpriv.mlmext_info.hidden_ssid_mode = settings->hidden_ssid;
2337 if (settings->ssid && settings->ssid_len) {
2338 struct wlan_bssid_ex *pbss_network = &adapter->mlmepriv.cur_network.network;
2339 struct wlan_bssid_ex *pbss_network_ext = &adapter->mlmeextpriv.mlmext_info.network;
2341 memcpy(pbss_network->ssid.ssid, (void *)settings->ssid, settings->ssid_len);
2342 pbss_network->ssid.ssid_length = settings->ssid_len;
2343 memcpy(pbss_network_ext->ssid.ssid, (void *)settings->ssid, settings->ssid_len);
2344 pbss_network_ext->ssid.ssid_length = settings->ssid_len;
2350 static int cfg80211_rtw_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
2351 struct cfg80211_beacon_data *info)
2353 struct adapter *adapter = rtw_netdev_priv(ndev);
2355 return rtw_add_beacon(adapter, info->head, info->head_len, info->tail, info->tail_len);
2358 static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev,
2359 unsigned int link_id)
2364 static int cfg80211_rtw_add_station(struct wiphy *wiphy, struct net_device *ndev,
2366 struct station_parameters *params)
2371 static int cfg80211_rtw_del_station(struct wiphy *wiphy, struct net_device *ndev,
2372 struct station_del_parameters *params)
2375 struct list_head *phead, *plist, *tmp;
2377 struct sta_info *psta = NULL;
2378 struct adapter *padapter = rtw_netdev_priv(ndev);
2379 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2380 struct sta_priv *pstapriv = &padapter->stapriv;
2381 const u8 *mac = params->mac;
2383 if (check_fwstate(pmlmepriv, (_FW_LINKED | WIFI_AP_STATE)) != true)
2387 flush_all_cam_entry(padapter); /* clear CAM */
2389 rtw_sta_flush(padapter);
2394 if (mac[0] == 0xff && mac[1] == 0xff &&
2395 mac[2] == 0xff && mac[3] == 0xff &&
2396 mac[4] == 0xff && mac[5] == 0xff) {
2401 spin_lock_bh(&pstapriv->asoc_list_lock);
2403 phead = &pstapriv->asoc_list;
2404 /* check asoc_queue */
2405 list_for_each_safe(plist, tmp, phead) {
2406 psta = list_entry(plist, struct sta_info, asoc_list);
2408 if (!memcmp((u8 *)mac, psta->hwaddr, ETH_ALEN)) {
2409 if (psta->dot8021xalg != 1 || psta->bpairwise_key_installed) {
2410 list_del_init(&psta->asoc_list);
2411 pstapriv->asoc_list_cnt--;
2413 updated = ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING);
2424 spin_unlock_bh(&pstapriv->asoc_list_lock);
2426 associated_clients_update(padapter, updated);
2432 static int cfg80211_rtw_change_station(struct wiphy *wiphy, struct net_device *ndev,
2433 const u8 *mac, struct station_parameters *params)
2438 static struct sta_info *rtw_sta_info_get_by_idx(const int idx, struct sta_priv *pstapriv)
2441 struct list_head *phead, *plist;
2442 struct sta_info *psta = NULL;
2445 phead = &pstapriv->asoc_list;
2446 plist = get_next(phead);
2448 /* check asoc_queue */
2449 while (phead != plist) {
2451 psta = container_of(plist, struct sta_info, asoc_list);
2452 plist = get_next(plist);
2458 static int cfg80211_rtw_dump_station(struct wiphy *wiphy, struct net_device *ndev,
2459 int idx, u8 *mac, struct station_info *sinfo)
2463 struct adapter *padapter = rtw_netdev_priv(ndev);
2464 struct sta_info *psta = NULL;
2465 struct sta_priv *pstapriv = &padapter->stapriv;
2467 spin_lock_bh(&pstapriv->asoc_list_lock);
2468 psta = rtw_sta_info_get_by_idx(idx, pstapriv);
2469 spin_unlock_bh(&pstapriv->asoc_list_lock);
2474 memcpy(mac, psta->hwaddr, ETH_ALEN);
2475 sinfo->filled = BIT_ULL(NL80211_STA_INFO_SIGNAL);
2476 sinfo->signal = psta->rssi;
2482 static int cfg80211_rtw_change_bss(struct wiphy *wiphy, struct net_device *ndev,
2483 struct bss_parameters *params)
2488 void rtw_cfg80211_rx_action(struct adapter *adapter, u8 *frame, uint frame_len, const char *msg)
2492 u8 category, action;
2494 channel = rtw_get_oper_ch(adapter);
2496 rtw_action_frame_parse(frame, frame_len, &category, &action);
2498 freq = rtw_ieee80211_channel_to_frequency(channel, NL80211_BAND_2GHZ);
2500 rtw_cfg80211_rx_mgmt(adapter, freq, 0, frame, frame_len, GFP_ATOMIC);
2503 static int _cfg80211_rtw_mgmt_tx(struct adapter *padapter, u8 tx_ch, const u8 *buf, size_t len)
2505 struct xmit_frame *pmgntframe;
2506 struct pkt_attrib *pattrib;
2507 unsigned char *pframe;
2509 bool __maybe_unused ack = true;
2510 struct ieee80211_hdr *pwlanhdr;
2511 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2512 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2514 rtw_set_scan_deny(padapter, 1000);
2516 rtw_scan_abort(padapter);
2517 if (tx_ch != rtw_get_oper_ch(padapter)) {
2518 if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED))
2519 pmlmeext->cur_channel = tx_ch;
2520 set_channel_bwmode(padapter, tx_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
2523 /* starting alloc mgmt frame to dump it */
2524 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2526 /* ret = -ENOMEM; */
2531 /* update attribute */
2532 pattrib = &pmgntframe->attrib;
2533 update_mgntframe_attrib(padapter, pattrib);
2534 pattrib->retry_ctrl = false;
2536 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2538 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2540 memcpy(pframe, (void *)buf, len);
2541 pattrib->pktlen = len;
2543 pwlanhdr = (struct ieee80211_hdr *)pframe;
2544 /* update seq number */
2545 pmlmeext->mgnt_seq = GetSequence(pwlanhdr);
2546 pattrib->seqnum = pmlmeext->mgnt_seq;
2547 pmlmeext->mgnt_seq++;
2549 pattrib->last_txcmdsz = pattrib->pktlen;
2551 if (dump_mgntframe_and_wait_ack(padapter, pmgntframe) != _SUCCESS) {
2567 static int cfg80211_rtw_mgmt_tx(struct wiphy *wiphy,
2568 struct wireless_dev *wdev,
2569 struct cfg80211_mgmt_tx_params *params,
2572 struct net_device *ndev = wdev_to_ndev(wdev);
2573 struct ieee80211_channel *chan = params->chan;
2574 const u8 *buf = params->buf;
2575 size_t len = params->len;
2578 u32 dump_limit = RTW_MAX_MGMT_TX_CNT;
2581 u8 tx_ch = (u8)ieee80211_frequency_to_channel(chan->center_freq);
2582 u8 category, action;
2584 struct adapter *padapter;
2585 struct rtw_wdev_priv *pwdev_priv;
2592 padapter = rtw_netdev_priv(ndev);
2593 pwdev_priv = adapter_wdev_data(padapter);
2595 /* cookie generation */
2596 *cookie = (unsigned long) buf;
2598 /* indicate ack before issue frame to avoid racing with rsp frame */
2599 rtw_cfg80211_mgmt_tx_status(padapter, *cookie, buf, len, ack, GFP_KERNEL);
2601 if (rtw_action_frame_parse(buf, len, &category, &action) == false)
2604 rtw_ps_deny(padapter, PS_DENY_MGNT_TX);
2605 if (_FAIL == rtw_pwr_wakeup(padapter)) {
2607 goto cancel_ps_deny;
2612 tx_ret = _cfg80211_rtw_mgmt_tx(padapter, tx_ch, buf, len);
2613 } while (dump_cnt < dump_limit && tx_ret != _SUCCESS);
2616 case P2P_GO_NEGO_CONF:
2617 rtw_clear_scan_deny(padapter);
2619 case P2P_INVIT_RESP:
2620 if (pwdev_priv->invit_info.flags & BIT(0) && pwdev_priv->invit_info.status == 0) {
2621 rtw_set_scan_deny(padapter, 5000);
2622 rtw_pwr_wakeup_ex(padapter, 5000);
2623 rtw_clear_scan_deny(padapter);
2629 rtw_ps_deny_cancel(padapter, PS_DENY_MGNT_TX);
2634 static void rtw_cfg80211_init_ht_capab(struct ieee80211_sta_ht_cap *ht_cap, enum nl80211_band band)
2637 #define MAX_BIT_RATE_40MHZ_MCS15 300 /* Mbps */
2638 #define MAX_BIT_RATE_40MHZ_MCS7 150 /* Mbps */
2640 ht_cap->ht_supported = true;
2642 ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
2643 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20 |
2644 IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
2647 *Maximum length of AMPDU that the STA can receive.
2648 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
2650 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2652 /*Minimum MPDU start spacing , */
2653 ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
2655 ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2658 *hw->wiphy->bands[NL80211_BAND_2GHZ]
2661 *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7
2662 *if rx_ant =2 rx_mask[1]= 0xff;==>MCS8-MCS15
2663 *if rx_ant >=3 rx_mask[2]= 0xff;
2664 *if BW_40 rx_mask[4]= 0x01;
2665 *highest supported RX rate
2667 ht_cap->mcs.rx_mask[0] = 0xFF;
2668 ht_cap->mcs.rx_mask[1] = 0x00;
2669 ht_cap->mcs.rx_mask[4] = 0x01;
2671 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
2674 void rtw_cfg80211_init_wiphy(struct adapter *padapter)
2676 struct ieee80211_supported_band *bands;
2677 struct wireless_dev *pwdev = padapter->rtw_wdev;
2678 struct wiphy *wiphy = pwdev->wiphy;
2681 bands = wiphy->bands[NL80211_BAND_2GHZ];
2683 rtw_cfg80211_init_ht_capab(&bands->ht_cap, NL80211_BAND_2GHZ);
2686 /* copy mac_addr to wiphy */
2687 memcpy(wiphy->perm_addr, padapter->eeprompriv.mac_addr, ETH_ALEN);
2691 static void rtw_cfg80211_preinit_wiphy(struct adapter *padapter, struct wiphy *wiphy)
2694 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2696 wiphy->max_scan_ssids = RTW_SSID_SCAN_AMOUNT;
2697 wiphy->max_scan_ie_len = RTW_SCAN_IE_LEN_MAX;
2698 wiphy->max_num_pmkids = RTW_MAX_NUM_PMKIDS;
2700 wiphy->max_remain_on_channel_duration = RTW_MAX_REMAIN_ON_CHANNEL_DURATION;
2702 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
2703 | BIT(NL80211_IFTYPE_ADHOC)
2704 | BIT(NL80211_IFTYPE_AP)
2705 | BIT(NL80211_IFTYPE_MONITOR)
2708 wiphy->mgmt_stypes = rtw_cfg80211_default_mgmt_stypes;
2710 wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
2712 wiphy->cipher_suites = rtw_cipher_suites;
2713 wiphy->n_cipher_suites = ARRAY_SIZE(rtw_cipher_suites);
2715 /* if (padapter->registrypriv.wireless_mode & WIRELESS_11G) */
2716 wiphy->bands[NL80211_BAND_2GHZ] = rtw_spt_band_alloc(NL80211_BAND_2GHZ);
2718 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
2719 wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX | WIPHY_FLAG_HAVE_AP_SME;
2721 #if defined(CONFIG_PM)
2722 wiphy->max_sched_scan_reqs = 1;
2725 #if defined(CONFIG_PM)
2726 wiphy->wowlan = &wowlan_stub;
2729 if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE)
2730 wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
2732 wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
2735 static struct cfg80211_ops rtw_cfg80211_ops = {
2736 .change_virtual_intf = cfg80211_rtw_change_iface,
2737 .add_key = cfg80211_rtw_add_key,
2738 .get_key = cfg80211_rtw_get_key,
2739 .del_key = cfg80211_rtw_del_key,
2740 .set_default_key = cfg80211_rtw_set_default_key,
2741 .get_station = cfg80211_rtw_get_station,
2742 .scan = cfg80211_rtw_scan,
2743 .set_wiphy_params = cfg80211_rtw_set_wiphy_params,
2744 .connect = cfg80211_rtw_connect,
2745 .disconnect = cfg80211_rtw_disconnect,
2746 .join_ibss = cfg80211_rtw_join_ibss,
2747 .leave_ibss = cfg80211_rtw_leave_ibss,
2748 .set_tx_power = cfg80211_rtw_set_txpower,
2749 .get_tx_power = cfg80211_rtw_get_txpower,
2750 .set_power_mgmt = cfg80211_rtw_set_power_mgmt,
2751 .set_pmksa = cfg80211_rtw_set_pmksa,
2752 .del_pmksa = cfg80211_rtw_del_pmksa,
2753 .flush_pmksa = cfg80211_rtw_flush_pmksa,
2754 .get_channel = cfg80211_rtw_get_channel,
2755 .add_virtual_intf = cfg80211_rtw_add_virtual_intf,
2756 .del_virtual_intf = cfg80211_rtw_del_virtual_intf,
2758 .start_ap = cfg80211_rtw_start_ap,
2759 .change_beacon = cfg80211_rtw_change_beacon,
2760 .stop_ap = cfg80211_rtw_stop_ap,
2762 .add_station = cfg80211_rtw_add_station,
2763 .del_station = cfg80211_rtw_del_station,
2764 .change_station = cfg80211_rtw_change_station,
2765 .dump_station = cfg80211_rtw_dump_station,
2766 .change_bss = cfg80211_rtw_change_bss,
2768 .mgmt_tx = cfg80211_rtw_mgmt_tx,
2771 int rtw_wdev_alloc(struct adapter *padapter, struct device *dev)
2774 struct wiphy *wiphy;
2775 struct wireless_dev *wdev;
2776 struct rtw_wdev_priv *pwdev_priv;
2777 struct net_device *pnetdev = padapter->pnetdev;
2780 wiphy = wiphy_new(&rtw_cfg80211_ops, sizeof(struct adapter *));
2785 set_wiphy_dev(wiphy, dev);
2786 *((struct adapter **)wiphy_priv(wiphy)) = padapter;
2787 rtw_cfg80211_preinit_wiphy(padapter, wiphy);
2789 /* init regulary domain */
2790 rtw_regd_init(wiphy, rtw_reg_notifier);
2792 ret = wiphy_register(wiphy);
2797 wdev = rtw_zmalloc(sizeof(struct wireless_dev));
2800 goto unregister_wiphy;
2802 wdev->wiphy = wiphy;
2803 wdev->netdev = pnetdev;
2805 wdev->iftype = NL80211_IFTYPE_STATION; /* will be init in rtw_hal_init() */
2806 /* Must sync with _rtw_init_mlme_priv() */
2807 /* pmlmepriv->fw_state = WIFI_STATION_STATE */
2808 padapter->rtw_wdev = wdev;
2809 pnetdev->ieee80211_ptr = wdev;
2811 /* init pwdev_priv */
2812 pwdev_priv = adapter_wdev_data(padapter);
2813 pwdev_priv->rtw_wdev = wdev;
2814 pwdev_priv->pmon_ndev = NULL;
2815 pwdev_priv->ifname_mon[0] = '\0';
2816 pwdev_priv->padapter = padapter;
2817 pwdev_priv->scan_request = NULL;
2818 spin_lock_init(&pwdev_priv->scan_req_lock);
2820 pwdev_priv->p2p_enabled = false;
2821 pwdev_priv->provdisc_req_issued = false;
2822 rtw_wdev_invit_info_init(&pwdev_priv->invit_info);
2823 rtw_wdev_nego_info_init(&pwdev_priv->nego_info);
2825 pwdev_priv->bandroid_scan = false;
2827 if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE)
2828 pwdev_priv->power_mgmt = true;
2830 pwdev_priv->power_mgmt = false;
2835 wiphy_unregister(wiphy);
2843 void rtw_wdev_free(struct wireless_dev *wdev)
2848 kfree(wdev->wiphy->bands[NL80211_BAND_2GHZ]);
2850 wiphy_free(wdev->wiphy);
2855 void rtw_wdev_unregister(struct wireless_dev *wdev)
2857 struct net_device *ndev;
2858 struct adapter *adapter;
2859 struct rtw_wdev_priv *pwdev_priv;
2863 ndev = wdev_to_ndev(wdev);
2867 adapter = rtw_netdev_priv(ndev);
2868 pwdev_priv = adapter_wdev_data(adapter);
2870 rtw_cfg80211_indicate_scan_done(adapter, true);
2872 if (pwdev_priv->pmon_ndev)
2873 unregister_netdev(pwdev_priv->pmon_ndev);
2875 wiphy_unregister(wdev->wiphy);