1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 ******************************************************************************/
15 #define _IOCTL_CFG80211_C_
17 #include <osdep_service.h>
18 #include <drv_types.h>
19 #include <xmit_osdep.h>
21 #include "ioctl_cfg80211.h"
23 #define RTW_MAX_MGMT_TX_CNT 8
25 #define RTW_MAX_REMAIN_ON_CHANNEL_DURATION 65535 /* ms */
26 #define RTW_MAX_NUM_PMKIDS 4
28 static const u32 rtw_cipher_suites[] = {
29 WLAN_CIPHER_SUITE_WEP40,
30 WLAN_CIPHER_SUITE_WEP104,
31 WLAN_CIPHER_SUITE_TKIP,
32 WLAN_CIPHER_SUITE_CCMP,
35 #define RATETAB_ENT(_rate, _rateid, _flags) { \
37 .hw_value = (_rateid), \
41 #define CHAN2G(_channel, _freq, _flags) { \
42 .band = IEEE80211_BAND_2GHZ, \
43 .center_freq = (_freq), \
44 .hw_value = (_channel), \
46 .max_antenna_gain = 0, \
50 #define CHAN5G(_channel, _flags) { \
51 .band = IEEE80211_BAND_5GHZ, \
52 .center_freq = 5000 + (5 * (_channel)), \
53 .hw_value = (_channel), \
55 .max_antenna_gain = 0, \
59 static struct ieee80211_rate rtw_rates[] = {
60 RATETAB_ENT(10, 0x1, 0),
61 RATETAB_ENT(20, 0x2, 0),
62 RATETAB_ENT(55, 0x4, 0),
63 RATETAB_ENT(110, 0x8, 0),
64 RATETAB_ENT(60, 0x10, 0),
65 RATETAB_ENT(90, 0x20, 0),
66 RATETAB_ENT(120, 0x40, 0),
67 RATETAB_ENT(180, 0x80, 0),
68 RATETAB_ENT(240, 0x100, 0),
69 RATETAB_ENT(360, 0x200, 0),
70 RATETAB_ENT(480, 0x400, 0),
71 RATETAB_ENT(540, 0x800, 0),
74 #define rtw_a_rates (rtw_rates + 4)
75 #define RTW_A_RATES_NUM 8
76 #define rtw_g_rates (rtw_rates + 0)
77 #define RTW_G_RATES_NUM 12
79 #define RTW_2G_CHANNELS_NUM 14
80 #define RTW_5G_CHANNELS_NUM 37
82 static struct ieee80211_channel rtw_2ghz_channels[] = {
99 static struct ieee80211_channel rtw_5ghz_a_channels[] = {
100 CHAN5G(34, 0), CHAN5G(36, 0),
101 CHAN5G(38, 0), CHAN5G(40, 0),
102 CHAN5G(42, 0), CHAN5G(44, 0),
103 CHAN5G(46, 0), CHAN5G(48, 0),
104 CHAN5G(52, 0), CHAN5G(56, 0),
105 CHAN5G(60, 0), CHAN5G(64, 0),
106 CHAN5G(100, 0), CHAN5G(104, 0),
107 CHAN5G(108, 0), CHAN5G(112, 0),
108 CHAN5G(116, 0), CHAN5G(120, 0),
109 CHAN5G(124, 0), CHAN5G(128, 0),
110 CHAN5G(132, 0), CHAN5G(136, 0),
111 CHAN5G(140, 0), CHAN5G(149, 0),
112 CHAN5G(153, 0), CHAN5G(157, 0),
113 CHAN5G(161, 0), CHAN5G(165, 0),
114 CHAN5G(184, 0), CHAN5G(188, 0),
115 CHAN5G(192, 0), CHAN5G(196, 0),
116 CHAN5G(200, 0), CHAN5G(204, 0),
117 CHAN5G(208, 0), CHAN5G(212, 0),
121 static void rtw_2g_channels_init(struct ieee80211_channel *channels)
123 memcpy((void *)channels, (void *)rtw_2ghz_channels,
124 sizeof(struct ieee80211_channel) * RTW_2G_CHANNELS_NUM);
127 static void rtw_5g_channels_init(struct ieee80211_channel *channels)
129 memcpy((void *)channels, (void *)rtw_5ghz_a_channels,
130 sizeof(struct ieee80211_channel) * RTW_5G_CHANNELS_NUM);
133 static void rtw_2g_rates_init(struct ieee80211_rate *rates)
135 memcpy(rates, rtw_g_rates,
136 sizeof(struct ieee80211_rate) * RTW_G_RATES_NUM);
139 static void rtw_5g_rates_init(struct ieee80211_rate *rates)
141 memcpy(rates, rtw_a_rates,
142 sizeof(struct ieee80211_rate) * RTW_A_RATES_NUM);
145 static struct ieee80211_supported_band *
146 rtw_spt_band_alloc(enum ieee80211_band band)
148 struct ieee80211_supported_band *spt_band = NULL;
149 int n_channels, n_bitrates;
151 if (band == IEEE80211_BAND_2GHZ) {
152 n_channels = RTW_2G_CHANNELS_NUM;
153 n_bitrates = RTW_G_RATES_NUM;
154 } else if (band == IEEE80211_BAND_5GHZ) {
155 n_channels = RTW_5G_CHANNELS_NUM;
156 n_bitrates = RTW_A_RATES_NUM;
160 spt_band = kzalloc(sizeof(struct ieee80211_supported_band) +
161 sizeof(struct ieee80211_channel) * n_channels +
162 sizeof(struct ieee80211_rate) * n_bitrates,
168 (struct ieee80211_channel *)(((u8 *) spt_band) +
170 ieee80211_supported_band));
172 (struct ieee80211_rate *)(((u8 *) spt_band->channels) +
173 sizeof(struct ieee80211_channel) *
175 spt_band->band = band;
176 spt_band->n_channels = n_channels;
177 spt_band->n_bitrates = n_bitrates;
179 if (band == IEEE80211_BAND_2GHZ) {
180 rtw_2g_channels_init(spt_band->channels);
181 rtw_2g_rates_init(spt_band->bitrates);
182 } else if (band == IEEE80211_BAND_5GHZ) {
183 rtw_5g_channels_init(spt_band->channels);
184 rtw_5g_rates_init(spt_band->bitrates);
187 /* spt_band.ht_cap */
193 static const struct ieee80211_txrx_stypes
194 rtw_cfg80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
195 [NL80211_IFTYPE_ADHOC] = {
197 .rx = BIT(IEEE80211_STYPE_ACTION >> 4)
199 [NL80211_IFTYPE_STATION] = {
201 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
202 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
204 [NL80211_IFTYPE_AP] = {
206 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
207 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
208 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
209 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
210 BIT(IEEE80211_STYPE_AUTH >> 4) |
211 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
212 BIT(IEEE80211_STYPE_ACTION >> 4)
214 [NL80211_IFTYPE_AP_VLAN] = {
217 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
218 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
219 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
220 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
221 BIT(IEEE80211_STYPE_AUTH >> 4) |
222 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
223 BIT(IEEE80211_STYPE_ACTION >> 4)
225 [NL80211_IFTYPE_P2P_CLIENT] = {
227 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
228 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
230 [NL80211_IFTYPE_P2P_GO] = {
232 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
233 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
234 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
235 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
236 BIT(IEEE80211_STYPE_AUTH >> 4) |
237 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
238 BIT(IEEE80211_STYPE_ACTION >> 4)
242 static int rtw_cfg80211_inform_bss(struct rtw_adapter *padapter,
243 struct wlan_network *pnetwork)
246 struct ieee80211_channel *notify_channel;
247 struct cfg80211_bss *bss;
253 struct wireless_dev *wdev = padapter->rtw_wdev;
254 struct wiphy *wiphy = wdev->wiphy;
255 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
257 channel = pnetwork->network.DSConfig;
258 if (channel <= RTW_CH_MAX_2G_CHANNEL)
259 freq = ieee80211_channel_to_frequency(channel,
260 IEEE80211_BAND_2GHZ);
262 freq = ieee80211_channel_to_frequency(channel,
263 IEEE80211_BAND_5GHZ);
265 notify_channel = ieee80211_get_channel(wiphy, freq);
267 notify_ie = pnetwork->network.IEs;
268 notify_ielen = pnetwork->network.IELength;
270 /* We've set wiphy's signal_type as CFG80211_SIGNAL_TYPE_MBM:
271 * signal strength in mBm (100*dBm)
273 if (check_fwstate(pmlmepriv, _FW_LINKED) &&
274 is_same_network23a(&pmlmepriv->cur_network.network,
275 &pnetwork->network)) {
276 notify_signal = 100 * translate_percentage_to_dbm(padapter->recvpriv.signal_strength); /* dbm */
278 notify_signal = 100 * translate_percentage_to_dbm(
279 pnetwork->network.SignalStrength); /* dbm */
282 bss = cfg80211_inform_bss(wiphy, notify_channel,
283 CFG80211_BSS_FTYPE_UNKNOWN,
284 pnetwork->network.MacAddress,
285 pnetwork->network.tsf,
286 pnetwork->network.capability,
287 pnetwork->network.beacon_interval,
288 notify_ie, notify_ielen,
289 notify_signal, GFP_ATOMIC);
291 if (unlikely(!bss)) {
292 DBG_8723A("rtw_cfg80211_inform_bss error\n");
296 cfg80211_put_bss(wiphy, bss);
301 void rtw_cfg80211_indicate_connect(struct rtw_adapter *padapter)
303 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
304 struct wlan_network *cur_network = &pmlmepriv->cur_network;
305 struct wireless_dev *pwdev = padapter->rtw_wdev;
307 DBG_8723A("%s(padapter =%p)\n", __func__, padapter);
309 if (pwdev->iftype != NL80211_IFTYPE_STATION &&
310 pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
313 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
316 if (padapter->mlmepriv.to_roaming > 0) {
317 struct wiphy *wiphy = pwdev->wiphy;
318 struct ieee80211_channel *notify_channel;
320 u16 channel = cur_network->network.DSConfig;
322 if (channel <= RTW_CH_MAX_2G_CHANNEL)
324 ieee80211_channel_to_frequency(channel,
325 IEEE80211_BAND_2GHZ);
328 ieee80211_channel_to_frequency(channel,
329 IEEE80211_BAND_5GHZ);
331 notify_channel = ieee80211_get_channel(wiphy, freq);
333 DBG_8723A("%s call cfg80211_roamed\n", __func__);
334 cfg80211_roamed(padapter->pnetdev, notify_channel,
335 cur_network->network.MacAddress,
336 pmlmepriv->assoc_req +
337 sizeof(struct ieee80211_hdr_3addr) + 2,
338 pmlmepriv->assoc_req_len -
339 sizeof(struct ieee80211_hdr_3addr) - 2,
340 pmlmepriv->assoc_rsp +
341 sizeof(struct ieee80211_hdr_3addr) + 6,
342 pmlmepriv->assoc_rsp_len -
343 sizeof(struct ieee80211_hdr_3addr) - 6,
346 cfg80211_connect_result(padapter->pnetdev,
347 cur_network->network.MacAddress,
348 pmlmepriv->assoc_req +
349 sizeof(struct ieee80211_hdr_3addr) + 2,
350 pmlmepriv->assoc_req_len -
351 sizeof(struct ieee80211_hdr_3addr) - 2,
352 pmlmepriv->assoc_rsp +
353 sizeof(struct ieee80211_hdr_3addr) + 6,
354 pmlmepriv->assoc_rsp_len -
355 sizeof(struct ieee80211_hdr_3addr) - 6,
356 WLAN_STATUS_SUCCESS, GFP_ATOMIC);
360 void rtw_cfg80211_indicate_disconnect(struct rtw_adapter *padapter)
362 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
363 struct wireless_dev *pwdev = padapter->rtw_wdev;
365 DBG_8723A("%s(padapter =%p)\n", __func__, padapter);
367 if (pwdev->iftype != NL80211_IFTYPE_STATION &&
368 pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
371 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
374 if (!padapter->mlmepriv.not_indic_disco) {
375 if (check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING)) {
376 cfg80211_connect_result(padapter->pnetdev, NULL, NULL,
378 WLAN_STATUS_UNSPECIFIED_FAILURE,
381 cfg80211_disconnected(padapter->pnetdev, 0, NULL,
382 0, false, GFP_ATOMIC);
387 #ifdef CONFIG_8723AU_AP_MODE
388 static int set_pairwise_key(struct rtw_adapter *padapter, struct sta_info *psta)
390 struct cmd_obj *ph2c;
391 struct set_stakey_parm *psetstakey_para;
392 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
395 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
401 psetstakey_para = kzalloc(sizeof(struct set_stakey_parm), GFP_KERNEL);
402 if (psetstakey_para == NULL) {
408 init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
410 psetstakey_para->algorithm = psta->dot118021XPrivacy;
412 ether_addr_copy(psetstakey_para->addr, psta->hwaddr);
414 memcpy(psetstakey_para->key, &psta->dot118021x_UncstKey, 16);
416 res = rtw_enqueue_cmd23a(pcmdpriv, ph2c);
422 static int set_group_key(struct rtw_adapter *padapter, struct key_params *parms,
425 struct cmd_obj *pcmd;
426 struct setkey_parm *psetkeyparm;
427 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
430 DBG_8723A("%s\n", __func__);
437 pcmd = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
442 psetkeyparm = kzalloc(sizeof(struct setkey_parm), GFP_KERNEL);
449 psetkeyparm->keyid = keyid;
451 padapter->mlmepriv.key_mask |= BIT(psetkeyparm->keyid);
453 psetkeyparm->algorithm = alg;
455 psetkeyparm->set_tx = 1;
457 memcpy(&psetkeyparm->key, parms->key, parms->key_len);
459 pcmd->cmdcode = _SetKey_CMD_;
460 pcmd->parmbuf = (u8 *) psetkeyparm;
461 pcmd->cmdsz = sizeof(struct setkey_parm);
465 res = rtw_enqueue_cmd23a(pcmdpriv, pcmd);
471 static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, u8 key_index,
472 int set_tx, const u8 *sta_addr,
473 struct key_params *keyparms)
476 struct sta_info *psta = NULL, *pbcmc_sta = NULL;
477 struct rtw_adapter *padapter = netdev_priv(dev);
478 struct security_priv *psecuritypriv = &padapter->securitypriv;
479 struct sta_priv *pstapriv = &padapter->stapriv;
481 DBG_8723A("%s\n", __func__);
483 if (!is_broadcast_ether_addr(sta_addr)) {
484 psta = rtw_get_stainfo23a(pstapriv, sta_addr);
487 DBG_8723A("rtw_set_encryption(), sta has already "
488 "been removed or never been added\n");
493 key_len = keyparms->key_len;
495 if (!psta && (keyparms->cipher == WLAN_CIPHER_SUITE_WEP40 ||
496 keyparms->cipher == WLAN_CIPHER_SUITE_WEP104)) {
497 DBG_8723A("r871x_set_encryption, crypt.alg = WEP\n");
499 DBG_8723A("r871x_set_encryption, wep_key_idx =%d, len =%d\n",
502 if (psecuritypriv->bWepDefaultKeyIdxSet == 0) {
503 /* wep default key has not been set, so use
504 this key index as default key. */
506 psecuritypriv->ndisencryptstatus =
507 Ndis802_11Encryption1Enabled;
508 psecuritypriv->dot11PrivacyAlgrthm = keyparms->cipher;
509 psecuritypriv->dot118021XGrpPrivacy = keyparms->cipher;
511 psecuritypriv->dot11PrivacyKeyIndex = key_index;
514 memcpy(&psecuritypriv->wep_key[key_index].key,
515 keyparms->key, key_len);
517 psecuritypriv->wep_key[key_index].keylen = key_len;
519 set_group_key(padapter, keyparms, keyparms->cipher, key_index);
524 if (!psta) { /* group key */
525 if (set_tx == 0) { /* group key */
526 if (keyparms->cipher == WLAN_CIPHER_SUITE_WEP40 ||
527 keyparms->cipher == WLAN_CIPHER_SUITE_WEP104) {
528 DBG_8723A("%s, set group_key, WEP\n", __func__);
530 memcpy(psecuritypriv->
531 dot118021XGrpKey[key_index].skey,
532 keyparms->key, key_len);
534 psecuritypriv->dot118021XGrpPrivacy =
536 } else if (keyparms->cipher == WLAN_CIPHER_SUITE_TKIP) {
537 DBG_8723A("%s, set group_key, TKIP\n",
540 psecuritypriv->dot118021XGrpPrivacy =
541 WLAN_CIPHER_SUITE_TKIP;
543 memcpy(psecuritypriv->
544 dot118021XGrpKey[key_index].skey,
549 memcpy(psecuritypriv->
550 dot118021XGrptxmickey[key_index].skey,
551 &keyparms->key[16], 8);
552 memcpy(psecuritypriv->
553 dot118021XGrprxmickey[key_index].skey,
554 &keyparms->key[24], 8);
556 psecuritypriv->busetkipkey = 1;
558 } else if (keyparms->cipher == WLAN_CIPHER_SUITE_CCMP) {
559 DBG_8723A("%s, set group_key, CCMP\n",
562 psecuritypriv->dot118021XGrpPrivacy =
563 WLAN_CIPHER_SUITE_CCMP;
565 memcpy(psecuritypriv->
566 dot118021XGrpKey[key_index].skey,
570 DBG_8723A("%s, set group_key, none\n",
573 psecuritypriv->dot118021XGrpPrivacy = 0;
576 psecuritypriv->dot118021XGrpKeyid = key_index;
578 psecuritypriv->binstallGrpkey = 1;
580 psecuritypriv->dot11PrivacyAlgrthm =
581 psecuritypriv->dot118021XGrpPrivacy;
583 set_group_key(padapter, keyparms,
584 psecuritypriv->dot118021XGrpPrivacy,
587 pbcmc_sta = rtw_get_bcmc_stainfo23a(padapter);
589 pbcmc_sta->ieee8021x_blocked = false;
590 /* rx will use bmc_sta's dot118021XPrivacy */
591 pbcmc_sta->dot118021XPrivacy =
592 psecuritypriv->dot118021XGrpPrivacy;
601 if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) {
605 memcpy(psta->dot118021x_UncstKey.skey,
606 keyparms->key, (min(16, key_len)));
608 if (keyparms->cipher == WLAN_CIPHER_SUITE_WEP40 ||
609 keyparms->cipher == WLAN_CIPHER_SUITE_WEP104) {
610 DBG_8723A("%s, set pairwise key, WEP\n",
613 psecuritypriv->dot118021XGrpPrivacy =
615 } else if (keyparms->cipher == WLAN_CIPHER_SUITE_TKIP) {
616 DBG_8723A("%s, set pairwise key, TKIP\n",
619 psta->dot118021XPrivacy =
620 WLAN_CIPHER_SUITE_TKIP;
623 memcpy(psta->dot11tkiptxmickey.skey,
624 &keyparms->key[16], 8);
625 memcpy(psta->dot11tkiprxmickey.skey,
626 &keyparms->key[24], 8);
628 psecuritypriv->busetkipkey = 1;
630 } else if (keyparms->cipher == WLAN_CIPHER_SUITE_CCMP) {
631 DBG_8723A("%s, set pairwise key, CCMP\n",
634 psta->dot118021XPrivacy =
635 WLAN_CIPHER_SUITE_CCMP;
637 DBG_8723A("%s, set pairwise key, none\n",
640 psta->dot118021XPrivacy = 0;
643 set_pairwise_key(padapter, psta);
645 psta->ieee8021x_blocked = false;
647 psta->bpairwise_key_installed = true;
648 } else { /* group key??? */
649 if (keyparms->cipher == WLAN_CIPHER_SUITE_WEP40 ||
650 keyparms->cipher == WLAN_CIPHER_SUITE_WEP104) {
651 memcpy(psecuritypriv->
652 dot118021XGrpKey[key_index].skey,
653 keyparms->key, key_len);
655 psecuritypriv->dot118021XGrpPrivacy =
657 } else if (keyparms->cipher == WLAN_CIPHER_SUITE_TKIP) {
658 psecuritypriv->dot118021XGrpPrivacy =
659 WLAN_CIPHER_SUITE_TKIP;
661 memcpy(psecuritypriv->
662 dot118021XGrpKey[key_index].skey,
667 memcpy(psecuritypriv->
668 dot118021XGrptxmickey[key_index].skey,
669 &keyparms->key[16], 8);
670 memcpy(psecuritypriv->
671 dot118021XGrprxmickey[key_index].skey,
672 &keyparms->key[24], 8);
674 psecuritypriv->busetkipkey = 1;
675 } else if (keyparms->cipher == WLAN_CIPHER_SUITE_CCMP) {
676 psecuritypriv->dot118021XGrpPrivacy =
677 WLAN_CIPHER_SUITE_CCMP;
679 memcpy(psecuritypriv->
680 dot118021XGrpKey[key_index].skey,
684 psecuritypriv->dot118021XGrpPrivacy = 0;
687 psecuritypriv->dot118021XGrpKeyid = key_index;
689 psecuritypriv->binstallGrpkey = 1;
691 psecuritypriv->dot11PrivacyAlgrthm =
692 psecuritypriv->dot118021XGrpPrivacy;
694 set_group_key(padapter, keyparms,
695 psecuritypriv->dot118021XGrpPrivacy,
698 pbcmc_sta = rtw_get_bcmc_stainfo23a(padapter);
700 /* rx will use bmc_sta's
702 pbcmc_sta->ieee8021x_blocked = false;
703 pbcmc_sta->dot118021XPrivacy =
704 psecuritypriv->dot118021XGrpPrivacy;
715 static int rtw_cfg80211_set_encryption(struct net_device *dev, u8 key_index,
716 int set_tx, const u8 *sta_addr,
717 struct key_params *keyparms)
721 struct rtw_adapter *padapter = netdev_priv(dev);
722 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
723 struct security_priv *psecuritypriv = &padapter->securitypriv;
725 DBG_8723A("%s\n", __func__);
727 key_len = keyparms->key_len;
729 if (keyparms->cipher == WLAN_CIPHER_SUITE_WEP40 ||
730 keyparms->cipher == WLAN_CIPHER_SUITE_WEP104) {
731 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_,
732 "wpa_set_encryption, crypt.alg = WEP\n");
733 DBG_8723A("wpa_set_encryption, crypt.alg = WEP\n");
735 if (psecuritypriv->bWepDefaultKeyIdxSet == 0) {
736 /* wep default key has not been set, so use this
737 key index as default key. */
739 psecuritypriv->ndisencryptstatus =
740 Ndis802_11Encryption1Enabled;
741 psecuritypriv->dot11PrivacyAlgrthm = keyparms->cipher;
742 psecuritypriv->dot118021XGrpPrivacy = keyparms->cipher;
744 psecuritypriv->dot11PrivacyKeyIndex = key_index;
747 memcpy(&psecuritypriv->wep_key[key_index].key,
748 keyparms->key, key_len);
750 psecuritypriv->wep_key[key_index].keylen = key_len;
752 rtw_set_key23a(padapter, psecuritypriv, key_index, 0);
757 if (padapter->securitypriv.dot11AuthAlgrthm ==
758 dot11AuthAlgrthm_8021X) { /* 802_1x */
759 struct sta_info *psta, *pbcmc_sta;
760 struct sta_priv *pstapriv = &padapter->stapriv;
762 if (check_fwstate(pmlmepriv,
763 WIFI_STATION_STATE | WIFI_MP_STATE)) {
765 psta = rtw_get_stainfo23a(pstapriv, get_bssid(pmlmepriv));
767 DBG_8723A("%s, : Obtain Sta_info fail\n",
770 /* Jeff: don't disable ieee8021x_blocked
771 while clearing key */
772 if (keyparms->cipher != IW_AUTH_CIPHER_NONE &&
773 keyparms->cipher != 0)
774 psta->ieee8021x_blocked = false;
776 if ((padapter->securitypriv.ndisencryptstatus ==
777 Ndis802_11Encryption2Enabled) ||
778 (padapter->securitypriv.ndisencryptstatus ==
779 Ndis802_11Encryption3Enabled)) {
780 psta->dot118021XPrivacy =
781 padapter->securitypriv.
787 DBG_8723A("%s, : set_tx == 1\n",
790 memcpy(psta->dot118021x_UncstKey.skey,
794 if (keyparms->cipher ==
795 WLAN_CIPHER_SUITE_TKIP) {
796 memcpy(psta->dot11tkiptxmickey.
798 &keyparms->key[16], 8);
799 memcpy(psta->dot11tkiprxmickey.
801 &keyparms->key[24], 8);
803 padapter->securitypriv.
806 DBG_8723A(" ~~~~set sta key:unicastkey\n");
808 rtw_setstakey_cmd23a(padapter,
809 (unsigned char *)psta,
811 } else { /* group key */
812 memcpy(padapter->securitypriv.
813 dot118021XGrpKey[key_index].skey,
816 memcpy(padapter->securitypriv.
817 dot118021XGrptxmickey[key_index].
818 skey, &keyparms->key[16], 8);
819 memcpy(padapter->securitypriv.
820 dot118021XGrprxmickey[key_index].
821 skey, &keyparms->key[24], 8);
822 padapter->securitypriv.binstallGrpkey =
825 (" ~~~~set sta key:groupkey\n");
827 padapter->securitypriv.
828 dot118021XGrpKeyid = key_index;
830 rtw_set_key23a(padapter,
831 &padapter->securitypriv,
836 pbcmc_sta = rtw_get_bcmc_stainfo23a(padapter);
838 /* Jeff: don't disable ieee8021x_blocked
839 while clearing key */
840 if (keyparms->cipher != IW_AUTH_CIPHER_NONE &&
841 keyparms->cipher != 0)
842 pbcmc_sta->ieee8021x_blocked = false;
844 if ((padapter->securitypriv.ndisencryptstatus ==
845 Ndis802_11Encryption2Enabled) ||
846 (padapter->securitypriv.ndisencryptstatus ==
847 Ndis802_11Encryption3Enabled)) {
848 pbcmc_sta->dot118021XPrivacy =
849 padapter->securitypriv.
858 DBG_8723A("%s, ret =%d\n", __func__, ret);
865 static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev,
866 u8 key_index, bool pairwise,
867 const u8 *mac_addr, struct key_params *params)
870 struct wireless_dev *rtw_wdev = wiphy_to_wdev(wiphy);
871 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
872 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
873 u8 sta_addr[ETH_ALEN];
875 DBG_8723A("%s(%s): adding key for %pM\n", __func__, ndev->name,
877 DBG_8723A("cipher = 0x%x\n", params->cipher);
878 DBG_8723A("key_len = 0x%x\n", params->key_len);
879 DBG_8723A("seq_len = 0x%x\n", params->seq_len);
880 DBG_8723A("key_index =%d\n", key_index);
881 DBG_8723A("pairwise =%d\n", pairwise);
883 switch (params->cipher) {
884 case IW_AUTH_CIPHER_NONE:
885 case WLAN_CIPHER_SUITE_WEP40:
886 if (params->key_len != WLAN_KEY_LEN_WEP40) {
890 case WLAN_CIPHER_SUITE_WEP104:
891 if (params->key_len != WLAN_KEY_LEN_WEP104) {
895 case WLAN_CIPHER_SUITE_TKIP:
896 case WLAN_CIPHER_SUITE_CCMP:
903 if (key_index >= WEP_KEYS || params->key_len < 0) {
908 eth_broadcast_addr(sta_addr);
910 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
911 set_tx = 0; /* for wpa/wpa2 group key */
913 set_tx = 1; /* for wpa/wpa2 pairwise key */
915 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
916 ret = rtw_cfg80211_set_encryption(ndev, key_index, set_tx,
918 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
919 #ifdef CONFIG_8723AU_AP_MODE
921 ether_addr_copy(sta_addr, mac_addr);
923 ret = rtw_cfg80211_ap_set_encryption(ndev, key_index, set_tx,
927 DBG_8723A("error! fw_state = 0x%x, iftype =%d\n",
928 pmlmepriv->fw_state, rtw_wdev->iftype);
937 cfg80211_rtw_get_key(struct wiphy *wiphy, struct net_device *ndev,
938 u8 key_index, bool pairwise, const u8 *mac_addr,
940 void (*callback) (void *cookie, struct key_params *))
942 DBG_8723A("%s(%s)\n", __func__, ndev->name);
946 static int cfg80211_rtw_del_key(struct wiphy *wiphy, struct net_device *ndev,
947 u8 key_index, bool pairwise,
950 struct rtw_adapter *padapter = netdev_priv(ndev);
951 struct security_priv *psecuritypriv = &padapter->securitypriv;
953 DBG_8723A("%s(%s): key_index =%d\n", __func__, ndev->name, key_index);
955 if (key_index == psecuritypriv->dot11PrivacyKeyIndex) {
956 /* clear the flag of wep default key set. */
957 psecuritypriv->bWepDefaultKeyIdxSet = 0;
963 static int cfg80211_rtw_set_default_key(struct wiphy *wiphy,
964 struct net_device *ndev, u8 key_index,
965 bool unicast, bool multicast)
967 struct rtw_adapter *padapter = netdev_priv(ndev);
968 struct security_priv *psecuritypriv = &padapter->securitypriv;
970 DBG_8723A("%s(%s): key_index =%d, unicast =%d, multicast =%d.\n",
971 __func__, ndev->name, key_index, unicast, multicast);
973 if (key_index < NUM_WEP_KEYS &&
974 (psecuritypriv->dot11PrivacyAlgrthm == WLAN_CIPHER_SUITE_WEP40 ||
975 psecuritypriv->dot11PrivacyAlgrthm == WLAN_CIPHER_SUITE_WEP104)) {
976 /* set wep default key */
977 psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
979 psecuritypriv->dot11PrivacyKeyIndex = key_index;
981 psecuritypriv->dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP40;
982 psecuritypriv->dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_WEP40;
983 if (psecuritypriv->wep_key[key_index].keylen == 13) {
984 psecuritypriv->dot11PrivacyAlgrthm =
985 WLAN_CIPHER_SUITE_WEP104;
986 psecuritypriv->dot118021XGrpPrivacy =
987 WLAN_CIPHER_SUITE_WEP104;
990 /* set the flag to represent that wep default key
992 psecuritypriv->bWepDefaultKeyIdxSet = 1;
998 static u16 rtw_get_cur_max_rate(struct rtw_adapter *adapter)
1002 u16 rate = 0, max_rate = 0;
1003 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
1004 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1005 struct registry_priv *pregistrypriv = &adapter->registrypriv;
1006 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1007 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
1008 struct ieee80211_ht_cap *pht_capie;
1010 u8 bw_40MHz = 0, short_GI_20 = 0, short_GI_40 = 0;
1013 p = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY,
1014 pcur_bss->IEs, pcur_bss->IELength);
1015 if (p && p[1] > 0) {
1016 pht_capie = (struct ieee80211_ht_cap *)(p + 2);
1018 memcpy(&mcs_rate, &pht_capie->mcs, 2);
1020 /* bw_40MHz = (pht_capie->cap_info&
1021 IEEE80211_HT_CAP_SUP_WIDTH_20_40) ? 1:0; */
1022 /* cur_bwmod is updated by beacon, pmlmeinfo is
1023 updated by association response */
1024 bw_40MHz = (pmlmeext->cur_bwmode &&
1025 (pmlmeinfo->HT_info.ht_param &
1026 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) ? 1:0;
1028 /* short_GI = (pht_capie->cap_info & (IEEE80211_HT_CAP
1029 _SGI_20|IEEE80211_HT_CAP_SGI_40)) ? 1 : 0; */
1030 short_GI_20 = (pmlmeinfo->ht_cap.cap_info &
1031 cpu_to_le16(IEEE80211_HT_CAP_SGI_20)) ? 1:0;
1032 short_GI_40 = (pmlmeinfo->ht_cap.cap_info &
1033 cpu_to_le16(IEEE80211_HT_CAP_SGI_40)) ? 1:0;
1035 rf_type = rtl8723a_get_rf_type(adapter);
1036 max_rate = rtw_mcs_rate23a(rf_type, bw_40MHz &
1037 pregistrypriv->cbw40_enable,
1038 short_GI_20, short_GI_40,
1039 &pmlmeinfo->ht_cap.mcs);
1041 while (pcur_bss->SupportedRates[i] != 0 &&
1042 pcur_bss->SupportedRates[i] != 0xFF) {
1043 rate = pcur_bss->SupportedRates[i] & 0x7F;
1044 if (rate > max_rate)
1049 max_rate = max_rate * 10 / 2;
1055 static int cfg80211_rtw_get_station(struct wiphy *wiphy,
1056 struct net_device *ndev,
1057 const u8 *mac, struct station_info *sinfo)
1060 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
1061 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1062 struct sta_info *psta = NULL;
1063 struct sta_priv *pstapriv = &padapter->stapriv;
1068 DBG_8723A("%s(%s): mac ==%p\n", __func__, ndev->name, mac);
1073 psta = rtw_get_stainfo23a(pstapriv, mac);
1075 DBG_8723A("%s, sta_info is null\n", __func__);
1079 DBG_8723A("%s(%s): mac=%pM\n", __func__, ndev->name, mac);
1081 /* for infra./P2PClient mode */
1082 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) &&
1083 check_fwstate(pmlmepriv, _FW_LINKED)) {
1084 struct wlan_network *cur_network = &pmlmepriv->cur_network;
1086 if (!ether_addr_equal(mac, cur_network->network.MacAddress)) {
1087 DBG_8723A("%s, mismatch bssid=%pM\n",
1088 __func__, cur_network->network.MacAddress);
1093 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
1094 sinfo->signal = translate_percentage_to_dbm(padapter->recvpriv.
1097 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
1098 sinfo->txrate.legacy = rtw_get_cur_max_rate(padapter);
1100 sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS);
1101 sinfo->rx_packets = sta_rx_data_pkts(psta);
1103 sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS);
1104 sinfo->tx_packets = psta->sta_stats.tx_pkts;
1107 /* for Ad-Hoc/AP mode */
1108 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
1109 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ||
1110 check_fwstate(pmlmepriv, WIFI_AP_STATE)) &&
1111 check_fwstate(pmlmepriv, _FW_LINKED)
1113 /* TODO: should acquire station info... */
1120 static int cfg80211_infrastructure_mode(struct rtw_adapter *padapter,
1121 enum nl80211_iftype ifmode)
1123 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1124 struct wlan_network *cur_network = &pmlmepriv->cur_network;
1125 enum nl80211_iftype old_mode;
1127 old_mode = cur_network->network.ifmode;
1129 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_notice_,
1130 "+%s: old =%d new =%d fw_state = 0x%08x\n", __func__,
1131 old_mode, ifmode, get_fwstate(pmlmepriv));
1133 if (old_mode != ifmode) {
1134 spin_lock_bh(&pmlmepriv->lock);
1136 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1139 if (old_mode == NL80211_IFTYPE_AP ||
1140 old_mode == NL80211_IFTYPE_P2P_GO) {
1141 /* change to other mode from Ndis802_11APMode */
1142 cur_network->join_res = -1;
1144 #ifdef CONFIG_8723AU_AP_MODE
1145 stop_ap_mode23a(padapter);
1149 if (check_fwstate(pmlmepriv, _FW_LINKED) ||
1150 old_mode == NL80211_IFTYPE_ADHOC)
1151 rtw_disassoc_cmd23a(padapter, 0, true);
1153 if (check_fwstate(pmlmepriv, _FW_LINKED) ||
1154 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))
1155 rtw_free_assoc_resources23a(padapter, 1);
1157 if (old_mode == NL80211_IFTYPE_STATION ||
1158 old_mode == NL80211_IFTYPE_P2P_CLIENT ||
1159 old_mode == NL80211_IFTYPE_ADHOC) {
1160 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
1161 /* will clr Linked_state; before this function,
1162 we must have chked whether issue
1163 dis-assoc_cmd or not */
1164 rtw_indicate_disconnect23a(padapter);
1168 cur_network->network.ifmode = ifmode;
1170 _clr_fwstate_(pmlmepriv, ~WIFI_NULL_STATE);
1173 case NL80211_IFTYPE_ADHOC:
1174 set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
1177 case NL80211_IFTYPE_P2P_CLIENT:
1178 case NL80211_IFTYPE_STATION:
1179 set_fwstate(pmlmepriv, WIFI_STATION_STATE);
1182 case NL80211_IFTYPE_P2P_GO:
1183 case NL80211_IFTYPE_AP:
1184 set_fwstate(pmlmepriv, WIFI_AP_STATE);
1185 #ifdef CONFIG_8723AU_AP_MODE
1186 start_ap_mode23a(padapter);
1187 /* rtw_indicate_connect23a(padapter); */
1195 /* SecClearAllKeys(adapter); */
1197 spin_unlock_bh(&pmlmepriv->lock);
1203 static int cfg80211_rtw_change_iface(struct wiphy *wiphy,
1204 struct net_device *ndev,
1205 enum nl80211_iftype type, u32 *flags,
1206 struct vif_params *params)
1208 enum nl80211_iftype old_type;
1209 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
1210 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1211 struct wireless_dev *rtw_wdev = wiphy_to_wdev(wiphy);
1214 DBG_8723A("%s(%s): call netdev_open23a\n", __func__, ndev->name);
1216 old_type = rtw_wdev->iftype;
1217 DBG_8723A("%s(%s): old_iftype =%d, new_iftype =%d\n",
1218 __func__, ndev->name, old_type, type);
1220 if (old_type != type) {
1221 pmlmeext->action_public_rxseq = 0xffff;
1222 pmlmeext->action_public_dialog_token = 0xff;
1226 case NL80211_IFTYPE_ADHOC:
1227 case NL80211_IFTYPE_P2P_CLIENT:
1228 case NL80211_IFTYPE_STATION:
1229 case NL80211_IFTYPE_P2P_GO:
1230 case NL80211_IFTYPE_AP:
1231 case NL80211_IFTYPE_UNSPECIFIED:
1237 rtw_wdev->iftype = type;
1239 if (cfg80211_infrastructure_mode(padapter, type) != _SUCCESS) {
1240 rtw_wdev->iftype = old_type;
1245 rtw_setopmode_cmd23a(padapter, type);
1251 void rtw_cfg80211_indicate_scan_done(struct rtw_wdev_priv *pwdev_priv,
1254 spin_lock_bh(&pwdev_priv->scan_req_lock);
1255 if (pwdev_priv->scan_request != NULL) {
1256 DBG_8723A("%s with scan req\n", __func__);
1258 if (pwdev_priv->scan_request->wiphy !=
1259 pwdev_priv->rtw_wdev->wiphy)
1260 DBG_8723A("error wiphy compare\n");
1262 cfg80211_scan_done(pwdev_priv->scan_request, aborted);
1264 pwdev_priv->scan_request = NULL;
1266 DBG_8723A("%s without scan req\n", __func__);
1268 spin_unlock_bh(&pwdev_priv->scan_req_lock);
1271 void rtw_cfg80211_surveydone_event_callback(struct rtw_adapter *padapter)
1273 struct list_head *phead;
1274 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1275 struct rtw_queue *queue = &pmlmepriv->scanned_queue;
1276 struct wlan_network *pnetwork, *ptmp;
1278 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
1279 phead = get_list_head(queue);
1280 list_for_each_entry_safe(pnetwork, ptmp, phead, list) {
1281 /* report network only if the current channel set
1282 contains the channel to which this network belongs */
1283 if (rtw_ch_set_search_ch23a
1284 (padapter->mlmeextpriv.channel_set,
1285 pnetwork->network.DSConfig) >= 0)
1286 rtw_cfg80211_inform_bss(padapter, pnetwork);
1288 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
1290 /* call this after other things have been done */
1291 rtw_cfg80211_indicate_scan_done(wdev_to_priv(padapter->rtw_wdev),
1295 static int rtw_cfg80211_set_probe_req_wpsp2pie(struct rtw_adapter *padapter,
1300 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1302 DBG_8723A("%s, ielen =%d\n", __func__, len);
1305 wps_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1306 WLAN_OUI_TYPE_MICROSOFT_WPS,
1309 DBG_8723A("probe_req_wps_ielen =%d\n", wps_ie[1]);
1311 if (pmlmepriv->wps_probe_req_ie) {
1312 pmlmepriv->wps_probe_req_ie_len = 0;
1313 kfree(pmlmepriv->wps_probe_req_ie);
1314 pmlmepriv->wps_probe_req_ie = NULL;
1317 pmlmepriv->wps_probe_req_ie = kmemdup(wps_ie, wps_ie[1],
1319 if (pmlmepriv->wps_probe_req_ie == NULL) {
1320 DBG_8723A("%s()-%d: kmalloc() ERROR!\n",
1321 __func__, __LINE__);
1324 pmlmepriv->wps_probe_req_ie_len = wps_ie[1];
1331 static int cfg80211_rtw_scan(struct wiphy *wiphy,
1332 struct cfg80211_scan_request *request)
1337 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
1338 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1339 struct cfg80211_ssid ssid[RTW_SSID_SCAN_AMOUNT];
1340 struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT];
1341 struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
1342 struct cfg80211_ssid *ssids = request->ssids;
1343 bool need_indicate_scan_done = false;
1345 DBG_8723A("%s(%s)\n", __func__, padapter->pnetdev->name);
1347 spin_lock_bh(&pwdev_priv->scan_req_lock);
1348 pwdev_priv->scan_request = request;
1349 spin_unlock_bh(&pwdev_priv->scan_req_lock);
1351 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1352 DBG_8723A("%s under WIFI_AP_STATE\n", __func__);
1353 /* need_indicate_scan_done = true; */
1354 /* goto check_need_indicate_scan_done; */
1357 if (rtw_pwr_wakeup(padapter) == _FAIL) {
1358 need_indicate_scan_done = true;
1359 goto check_need_indicate_scan_done;
1362 if (request->ie && request->ie_len > 0) {
1363 rtw_cfg80211_set_probe_req_wpsp2pie(padapter,
1368 if (pmlmepriv->LinkDetectInfo.bBusyTraffic == true) {
1369 DBG_8723A("%s, bBusyTraffic == true\n", __func__);
1370 need_indicate_scan_done = true;
1371 goto check_need_indicate_scan_done;
1373 if (rtw_is_scan_deny(padapter)) {
1374 DBG_8723A("%s(%s): scan deny\n", __func__,
1375 padapter->pnetdev->name);
1376 need_indicate_scan_done = true;
1377 goto check_need_indicate_scan_done;
1380 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING) ==
1382 DBG_8723A("%s, fwstate = 0x%x\n", __func__, pmlmepriv->fw_state);
1383 need_indicate_scan_done = true;
1384 goto check_need_indicate_scan_done;
1387 memset(ssid, 0, sizeof(struct cfg80211_ssid) * RTW_SSID_SCAN_AMOUNT);
1388 /* parsing request ssids, n_ssids */
1389 for (i = 0; i < request->n_ssids && i < RTW_SSID_SCAN_AMOUNT; i++) {
1390 DBG_8723A("ssid =%s, len =%d\n", ssids[i].ssid,
1392 memcpy(ssid[i].ssid, ssids[i].ssid, ssids[i].ssid_len);
1393 ssid[i].ssid_len = ssids[i].ssid_len;
1396 /* parsing channels, n_channels */
1398 sizeof(struct rtw_ieee80211_channel) * RTW_CHANNEL_SCAN_AMOUNT);
1400 if (request->n_channels == 1) {
1401 for (i = 0; i < request->n_channels &&
1402 i < RTW_CHANNEL_SCAN_AMOUNT; i++) {
1403 DBG_8723A("%s:(%s):" CHAN_FMT "\n",
1404 __func__, padapter->pnetdev->name,
1405 CHAN_ARG(request->channels[i]));
1406 ch[i].hw_value = request->channels[i]->hw_value;
1407 ch[i].flags = request->channels[i]->flags;
1411 spin_lock_bh(&pmlmepriv->lock);
1412 if (request->n_channels == 1) {
1413 memcpy(&ch[1], &ch[0], sizeof(struct rtw_ieee80211_channel));
1414 memcpy(&ch[2], &ch[0], sizeof(struct rtw_ieee80211_channel));
1415 _status = rtw_sitesurvey_cmd23a(padapter, ssid,
1416 RTW_SSID_SCAN_AMOUNT, ch, 3);
1418 _status = rtw_sitesurvey_cmd23a(padapter, ssid,
1419 RTW_SSID_SCAN_AMOUNT, NULL, 0);
1421 spin_unlock_bh(&pmlmepriv->lock);
1423 if (_status == false)
1426 check_need_indicate_scan_done:
1427 if (need_indicate_scan_done)
1428 rtw_cfg80211_surveydone_event_callback(padapter);
1432 static int cfg80211_rtw_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1434 DBG_8723A("%s\n", __func__);
1438 static int cfg80211_rtw_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
1439 struct cfg80211_ibss_params *params)
1441 DBG_8723A("%s(%s)\n", __func__, ndev->name);
1445 static int cfg80211_rtw_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
1447 DBG_8723A("%s(%s)\n", __func__, ndev->name);
1451 static int rtw_cfg80211_set_wpa_version(struct security_priv *psecuritypriv,
1454 DBG_8723A("%s, wpa_version =%d\n", __func__, wpa_version);
1457 psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
1461 if (wpa_version & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
1462 psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPAPSK;
1465 if (wpa_version & NL80211_WPA_VERSION_2)
1467 psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK;
1474 static int rtw_cfg80211_set_auth_type(struct security_priv *psecuritypriv,
1475 enum nl80211_auth_type sme_auth_type)
1477 DBG_8723A("%s, nl80211_auth_type =%d\n", __func__, sme_auth_type);
1479 switch (sme_auth_type) {
1480 case NL80211_AUTHTYPE_AUTOMATIC:
1481 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
1484 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1485 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
1487 if (psecuritypriv->ndisauthtype > Ndis802_11AuthModeWPA)
1488 psecuritypriv->dot11AuthAlgrthm =
1489 dot11AuthAlgrthm_8021X;
1491 case NL80211_AUTHTYPE_SHARED_KEY:
1492 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
1494 psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
1497 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
1498 /* return -ENOTSUPP; */
1504 static int rtw_cfg80211_set_cipher(struct security_priv *psecuritypriv,
1505 u32 cipher, bool ucast)
1507 u32 ndisencryptstatus = Ndis802_11EncryptionDisabled;
1509 u32 *profile_cipher = ucast ? &psecuritypriv->dot11PrivacyAlgrthm :
1510 &psecuritypriv->dot118021XGrpPrivacy;
1512 DBG_8723A("%s, ucast =%d, cipher = 0x%x\n", __func__, ucast, cipher);
1515 *profile_cipher = 0;
1516 psecuritypriv->ndisencryptstatus = ndisencryptstatus;
1521 case IW_AUTH_CIPHER_NONE:
1522 *profile_cipher = 0;
1523 ndisencryptstatus = Ndis802_11EncryptionDisabled;
1525 case WLAN_CIPHER_SUITE_WEP40:
1526 *profile_cipher = WLAN_CIPHER_SUITE_WEP40;
1527 ndisencryptstatus = Ndis802_11Encryption1Enabled;
1529 case WLAN_CIPHER_SUITE_WEP104:
1530 *profile_cipher = WLAN_CIPHER_SUITE_WEP104;
1531 ndisencryptstatus = Ndis802_11Encryption1Enabled;
1533 case WLAN_CIPHER_SUITE_TKIP:
1534 *profile_cipher = WLAN_CIPHER_SUITE_TKIP;
1535 ndisencryptstatus = Ndis802_11Encryption2Enabled;
1537 case WLAN_CIPHER_SUITE_CCMP:
1538 *profile_cipher = WLAN_CIPHER_SUITE_CCMP;
1539 ndisencryptstatus = Ndis802_11Encryption3Enabled;
1542 DBG_8723A("Unsupported cipher: 0x%x\n", cipher);
1547 psecuritypriv->ndisencryptstatus = ndisencryptstatus;
1552 static int rtw_cfg80211_set_key_mgt(struct security_priv *psecuritypriv,
1555 DBG_8723A("%s, key_mgt = 0x%x\n", __func__, key_mgt);
1557 if (key_mgt == WLAN_AKM_SUITE_8021X)
1558 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1559 else if (key_mgt == WLAN_AKM_SUITE_PSK)
1560 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1562 DBG_8723A("Invalid key mgt: 0x%x\n", key_mgt);
1567 static int rtw_cfg80211_set_wpa_ie(struct rtw_adapter *padapter, const u8 *pie,
1571 int group_cipher = 0, pairwise_cipher = 0;
1573 const u8 *pwpa, *pwpa2;
1576 if (!pie || !ielen) {
1577 /* Treat this as normal case, but need to clear
1579 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
1582 if (ielen > MAX_WPA_IE_LEN + MAX_WPS_IE_LEN + MAX_P2P_IE_LEN) {
1588 DBG_8723A("set wpa_ie(length:%zu):\n", ielen);
1589 for (i = 0; i < ielen; i = i + 8)
1590 DBG_8723A("0x%.2x 0x%.2x 0x%.2x 0x%.2x "
1591 "0x%.2x 0x%.2x 0x%.2x 0x%.2x\n",
1592 pie[i], pie[i + 1], pie[i + 2], pie[i + 3],
1593 pie[i + 4], pie[i + 5], pie[i + 6], pie[i + 7]);
1594 if (ielen < RSN_HEADER_LEN) {
1595 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_,
1596 "Ie len too short %d\n", (int)ielen);
1601 pwpa = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1602 WLAN_OUI_TYPE_MICROSOFT_WPA,
1604 if (pwpa && pwpa[1] > 0) {
1605 if (rtw_parse_wpa_ie23a(pwpa, pwpa[1] + 2, &group_cipher,
1606 &pairwise_cipher, NULL) == _SUCCESS) {
1607 padapter->securitypriv.dot11AuthAlgrthm =
1608 dot11AuthAlgrthm_8021X;
1609 padapter->securitypriv.ndisauthtype =
1610 Ndis802_11AuthModeWPAPSK;
1611 memcpy(padapter->securitypriv.supplicant_ie, pwpa,
1614 DBG_8723A("got wpa_ie, wpa_ielen:%u\n", pwpa[1]);
1618 pwpa2 = cfg80211_find_ie(WLAN_EID_RSN, pie, ielen);
1619 if (pwpa2 && pwpa2[1] > 0) {
1620 if (rtw_parse_wpa2_ie23a (pwpa2, pwpa2[1] + 2, &group_cipher,
1621 &pairwise_cipher, NULL) == _SUCCESS) {
1622 padapter->securitypriv.dot11AuthAlgrthm =
1623 dot11AuthAlgrthm_8021X;
1624 padapter->securitypriv.ndisauthtype =
1625 Ndis802_11AuthModeWPA2PSK;
1626 memcpy(padapter->securitypriv.supplicant_ie, pwpa2,
1629 DBG_8723A("got wpa2_ie, wpa2_ielen:%u\n", pwpa2[1]);
1633 if (group_cipher == 0) {
1634 group_cipher = WPA_CIPHER_NONE;
1636 if (pairwise_cipher == 0) {
1637 pairwise_cipher = WPA_CIPHER_NONE;
1640 switch (group_cipher) {
1641 case WPA_CIPHER_NONE:
1642 padapter->securitypriv.dot118021XGrpPrivacy = 0;
1643 padapter->securitypriv.ndisencryptstatus =
1644 Ndis802_11EncryptionDisabled;
1646 case WPA_CIPHER_WEP40:
1647 padapter->securitypriv.dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_WEP40;
1648 padapter->securitypriv.ndisencryptstatus =
1649 Ndis802_11Encryption1Enabled;
1651 case WPA_CIPHER_TKIP:
1652 padapter->securitypriv.dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_TKIP;
1653 padapter->securitypriv.ndisencryptstatus =
1654 Ndis802_11Encryption2Enabled;
1656 case WPA_CIPHER_CCMP:
1657 padapter->securitypriv.dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_CCMP;
1658 padapter->securitypriv.ndisencryptstatus =
1659 Ndis802_11Encryption3Enabled;
1661 case WPA_CIPHER_WEP104:
1662 padapter->securitypriv.dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_WEP104;
1663 padapter->securitypriv.ndisencryptstatus =
1664 Ndis802_11Encryption1Enabled;
1668 switch (pairwise_cipher) {
1669 case WPA_CIPHER_NONE:
1670 padapter->securitypriv.dot11PrivacyAlgrthm = 0;
1671 padapter->securitypriv.ndisencryptstatus =
1672 Ndis802_11EncryptionDisabled;
1674 case WPA_CIPHER_WEP40:
1675 padapter->securitypriv.dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP40;
1676 padapter->securitypriv.ndisencryptstatus =
1677 Ndis802_11Encryption1Enabled;
1679 case WPA_CIPHER_TKIP:
1680 padapter->securitypriv.dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_TKIP;
1681 padapter->securitypriv.ndisencryptstatus =
1682 Ndis802_11Encryption2Enabled;
1684 case WPA_CIPHER_CCMP:
1685 padapter->securitypriv.dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_CCMP;
1686 padapter->securitypriv.ndisencryptstatus =
1687 Ndis802_11Encryption3Enabled;
1689 case WPA_CIPHER_WEP104:
1690 padapter->securitypriv.dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP104;
1691 padapter->securitypriv.ndisencryptstatus =
1692 Ndis802_11Encryption1Enabled;
1696 wps_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1697 WLAN_OUI_TYPE_MICROSOFT_WPS,
1699 if (wps_ie && wps_ie[1] > 0) {
1700 DBG_8723A("got wps_ie, wps_ielen:%u\n", wps_ie[1]);
1701 padapter->securitypriv.wps_ie_len = wps_ie[1];
1702 memcpy(padapter->securitypriv.wps_ie, wps_ie,
1703 padapter->securitypriv.wps_ie_len);
1704 set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS);
1706 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
1709 /* TKIP and AES disallow multicast packets until installing group key */
1710 if (padapter->securitypriv.dot11PrivacyAlgrthm ==
1711 WLAN_CIPHER_SUITE_TKIP ||
1712 padapter->securitypriv.dot11PrivacyAlgrthm ==
1713 WLAN_CIPHER_SUITE_CCMP)
1714 /* WPS open need to enable multicast */
1715 /* check_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS) == true)*/
1716 rtl8723a_off_rcr_am(padapter);
1718 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_,
1719 "rtw_set_wpa_ie: pairwise_cipher = 0x%08x padapter->securitypriv.ndisencryptstatus =%d padapter->securitypriv.ndisauthtype =%d\n",
1721 padapter->securitypriv.ndisencryptstatus,
1722 padapter->securitypriv.ndisauthtype);
1726 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
1730 static int rtw_cfg80211_add_wep(struct rtw_adapter *padapter,
1731 struct rtw_wep_key *wep, u8 keyid)
1734 struct security_priv *psecuritypriv = &padapter->securitypriv;
1736 if (keyid >= NUM_WEP_KEYS) {
1737 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_,
1738 "%s:keyid>4 =>fail\n", __func__);
1743 switch (wep->keylen) {
1744 case WLAN_KEY_LEN_WEP40:
1745 psecuritypriv->dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP40;
1746 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1747 "%s:wep->KeyLength = 5\n", __func__);
1749 case WLAN_KEY_LEN_WEP104:
1750 psecuritypriv->dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP104;
1751 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1752 "%s:wep->KeyLength = 13\n", __func__);
1755 psecuritypriv->dot11PrivacyAlgrthm = 0;
1756 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1757 "%s:wep->KeyLength!= 5 or 13\n", __func__);
1762 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1763 "%s:before memcpy, wep->KeyLength = 0x%x keyid =%x\n",
1764 __func__, wep->keylen, keyid);
1766 memcpy(&psecuritypriv->wep_key[keyid], wep, sizeof(struct rtw_wep_key));
1768 psecuritypriv->dot11PrivacyKeyIndex = keyid;
1770 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1771 "%s:security key material : %x %x %x %x %x %x %x %x %x %x %x %x %x\n",
1773 psecuritypriv->wep_key[keyid].key[0],
1774 psecuritypriv->wep_key[keyid].key[1],
1775 psecuritypriv->wep_key[keyid].key[2],
1776 psecuritypriv->wep_key[keyid].key[3],
1777 psecuritypriv->wep_key[keyid].key[4],
1778 psecuritypriv->wep_key[keyid].key[5],
1779 psecuritypriv->wep_key[keyid].key[6],
1780 psecuritypriv->wep_key[keyid].key[7],
1781 psecuritypriv->wep_key[keyid].key[8],
1782 psecuritypriv->wep_key[keyid].key[9],
1783 psecuritypriv->wep_key[keyid].key[10],
1784 psecuritypriv->wep_key[keyid].key[11],
1785 psecuritypriv->wep_key[keyid].key[12]);
1787 res = rtw_set_key23a(padapter, psecuritypriv, keyid, 1);
1794 static int rtw_set_ssid(struct rtw_adapter *padapter,
1795 struct wlan_network *newnetwork)
1797 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1798 struct wlan_network *pnetwork = &pmlmepriv->cur_network;
1799 int status = _SUCCESS;
1802 DBG_8723A_LEVEL(_drv_always_, "set ssid [%s] fw_state = 0x%08x\n",
1803 newnetwork->network.Ssid.ssid, get_fwstate(pmlmepriv));
1805 if (padapter->hw_init_completed == false) {
1806 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_,
1807 "set_ssid: hw_init_completed == false =>exit!!!\n");
1812 spin_lock_bh(&pmlmepriv->lock);
1814 DBG_8723A("Set SSID under fw_state = 0x%08x\n", get_fwstate(pmlmepriv));
1815 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
1816 goto handle_tkip_countermeasure;
1818 if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE)) {
1819 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1820 "set_ssid: _FW_LINKED||WIFI_ADHOC_MASTER_STATE\n");
1822 if (pmlmepriv->assoc_ssid.ssid_len ==
1823 newnetwork->network.Ssid.ssid_len &&
1824 !memcmp(&pmlmepriv->assoc_ssid.ssid,
1825 newnetwork->network.Ssid.ssid,
1826 newnetwork->network.Ssid.ssid_len)) {
1827 if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
1828 RT_TRACE(_module_rtl871x_ioctl_set_c_,
1830 "New SSID is same SSID, fw_state = 0x%08x\n",
1831 get_fwstate(pmlmepriv));
1833 if (rtw_is_same_ibss23a(padapter, pnetwork)) {
1835 * it means driver is in
1836 * WIFI_ADHOC_MASTER_STATE, we needn't
1839 goto release_mlme_lock;
1843 * if in WIFI_ADHOC_MASTER_STATE |
1844 * WIFI_ADHOC_STATE, create bss or
1847 rtw_disassoc_cmd23a(padapter, 0, true);
1849 if (check_fwstate(pmlmepriv, _FW_LINKED))
1850 rtw_indicate_disconnect23a(padapter);
1852 rtw_free_assoc_resources23a(padapter, 1);
1854 if (check_fwstate(pmlmepriv,
1855 WIFI_ADHOC_MASTER_STATE)) {
1856 _clr_fwstate_(pmlmepriv,
1857 WIFI_ADHOC_MASTER_STATE);
1858 set_fwstate(pmlmepriv,
1862 rtw_lps_ctrl_wk_cmd23a(padapter,
1863 LPS_CTRL_JOINBSS, 1);
1866 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1867 "Set SSID not the same ssid\n");
1868 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1869 "set_ssid =[%s] len = 0x%x\n",
1870 newnetwork->network.Ssid.ssid,
1871 newnetwork->network.Ssid.ssid_len);
1872 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1873 "assoc_ssid =[%s] len = 0x%x\n",
1874 pmlmepriv->assoc_ssid.ssid,
1875 pmlmepriv->assoc_ssid.ssid_len);
1877 rtw_disassoc_cmd23a(padapter, 0, true);
1879 if (check_fwstate(pmlmepriv, _FW_LINKED))
1880 rtw_indicate_disconnect23a(padapter);
1882 rtw_free_assoc_resources23a(padapter, 1);
1884 if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
1885 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
1886 set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
1891 handle_tkip_countermeasure:
1893 if (padapter->securitypriv.btkip_countermeasure == true) {
1897 padapter->securitypriv.btkip_countermeasure_time) >
1899 padapter->securitypriv.btkip_countermeasure = false;
1900 padapter->securitypriv.btkip_countermeasure_time = 0;
1903 goto release_mlme_lock;
1907 memcpy(&pmlmepriv->assoc_ssid, &newnetwork->network.Ssid,
1908 sizeof(struct cfg80211_ssid));
1910 pmlmepriv->assoc_by_bssid = false;
1912 pmlmepriv->to_join = true;
1914 if (!check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) {
1915 pmlmepriv->cur_network.join_res = -2;
1917 status = rtw_do_join_network(padapter, newnetwork);
1918 if (status == _SUCCESS) {
1919 pmlmepriv->to_join = false;
1921 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
1922 /* switch to ADHOC_MASTER */
1923 status = rtw_do_join_adhoc(padapter);
1924 if (status != _SUCCESS)
1925 goto release_mlme_lock;
1927 /* can't associate ; reset under-linking */
1928 _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
1930 pmlmepriv->to_join = false;
1935 spin_unlock_bh(&pmlmepriv->lock);
1938 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_,
1939 "-%s: status =%d\n", __func__, status);
1944 static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
1945 struct cfg80211_connect_params *sme)
1948 struct list_head *phead, *plist, *ptmp;
1949 struct wlan_network *pnetwork = NULL;
1950 /* u8 matched_by_bssid = false; */
1951 /* u8 matched_by_ssid = false; */
1953 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
1954 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1955 struct security_priv *psecuritypriv = &padapter->securitypriv;
1956 struct rtw_queue *queue = &pmlmepriv->scanned_queue;
1958 DBG_8723A("=>" "%s(%s)\n", __func__, ndev->name);
1959 DBG_8723A("privacy =%d, key =%p, key_len =%d, key_idx =%d\n",
1960 sme->privacy, sme->key, sme->key_len, sme->key_idx);
1962 if (_FAIL == rtw_pwr_wakeup(padapter)) {
1967 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1972 if (!sme->ssid || !sme->ssid_len ||
1973 sme->ssid_len > IEEE80211_MAX_SSID_LEN) {
1978 DBG_8723A("ssid =%s, len =%zu\n", sme->ssid, sme->ssid_len);
1981 DBG_8723A("bssid=%pM\n", sme->bssid);
1983 if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) {
1985 DBG_8723A("%s, fw_state = 0x%x, goto exit\n", __func__,
1986 pmlmepriv->fw_state);
1989 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) {
1990 rtw_scan_abort23a(padapter);
1993 spin_lock_bh(&queue->lock);
1995 phead = get_list_head(queue);
1997 list_for_each_safe(plist, ptmp, phead) {
1998 pnetwork = container_of(plist, struct wlan_network, list);
2001 if (!ether_addr_equal(pnetwork->network.MacAddress,
2006 if (sme->ssid && sme->ssid_len) {
2007 if (pnetwork->network.Ssid.ssid_len != sme->ssid_len ||
2008 memcmp(pnetwork->network.Ssid.ssid, sme->ssid,
2014 if (ether_addr_equal(pnetwork->network.MacAddress,
2016 DBG_8723A("matched by bssid\n");
2021 } else if (sme->ssid && sme->ssid_len) {
2022 if (!memcmp(pnetwork->network.Ssid.ssid,
2023 sme->ssid, sme->ssid_len) &&
2024 pnetwork->network.Ssid.ssid_len == sme->ssid_len) {
2025 DBG_8723A("matched by ssid\n");
2033 spin_unlock_bh(&queue->lock);
2035 if (!matched || !pnetwork) {
2037 DBG_8723A("connect, matched == false, goto exit\n");
2041 if (cfg80211_infrastructure_mode(
2042 padapter, pnetwork->network.ifmode) != _SUCCESS) {
2047 psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled;
2048 psecuritypriv->dot11PrivacyAlgrthm = 0;
2049 psecuritypriv->dot118021XGrpPrivacy = 0;
2050 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
2051 psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
2053 ret = rtw_cfg80211_set_wpa_version(psecuritypriv,
2054 sme->crypto.wpa_versions);
2058 ret = rtw_cfg80211_set_auth_type(psecuritypriv, sme->auth_type);
2063 DBG_8723A("%s, ie_len =%zu\n", __func__, sme->ie_len);
2065 ret = rtw_cfg80211_set_wpa_ie(padapter, sme->ie, sme->ie_len);
2069 if (sme->crypto.n_ciphers_pairwise) {
2070 ret = rtw_cfg80211_set_cipher(psecuritypriv,
2071 sme->crypto.ciphers_pairwise[0],
2077 /* For WEP Shared auth */
2078 if ((psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Shared ||
2079 psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Auto) &&
2081 struct rtw_wep_key wep_key;
2082 u8 wep_key_idx, wep_key_len;
2083 DBG_8723A("%s(): Shared/Auto WEP\n", __func__);
2085 wep_key_idx = sme->key_idx;
2086 wep_key_len = sme->key_len;
2088 if (wep_key_idx > WEP_KEYS || !wep_key_len ||
2089 wep_key_len > WLAN_KEY_LEN_WEP104) {
2094 wep_key_len = wep_key_len <= 5 ? 5 : 13;
2096 memset(&wep_key, 0, sizeof(struct rtw_wep_key));
2098 wep_key.keylen = wep_key_len;
2100 if (wep_key_len == 13) {
2101 padapter->securitypriv.dot11PrivacyAlgrthm =
2102 WLAN_CIPHER_SUITE_WEP104;
2103 padapter->securitypriv.dot118021XGrpPrivacy =
2104 WLAN_CIPHER_SUITE_WEP104;
2106 padapter->securitypriv.dot11PrivacyAlgrthm =
2107 WLAN_CIPHER_SUITE_WEP40;
2108 padapter->securitypriv.dot118021XGrpPrivacy =
2109 WLAN_CIPHER_SUITE_WEP40;
2112 memcpy(wep_key.key, (void *)sme->key, wep_key.keylen);
2114 if (rtw_cfg80211_add_wep(padapter, &wep_key, wep_key_idx) !=
2122 ret = rtw_cfg80211_set_cipher(psecuritypriv,
2123 sme->crypto.cipher_group, false);
2127 if (sme->crypto.n_akm_suites) {
2128 ret = rtw_cfg80211_set_key_mgt(psecuritypriv,
2129 sme->crypto.akm_suites[0]);
2134 if (psecuritypriv->ndisauthtype > 3)
2135 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
2137 if (rtw_set_auth23a(padapter, psecuritypriv) != _SUCCESS) {
2142 /* rtw_set_802_11_encryption_mode(padapter,
2143 padapter->securitypriv.ndisencryptstatus); */
2145 if (rtw_set_ssid(padapter, pnetwork) != _SUCCESS) {
2150 DBG_8723A("set ssid:dot11AuthAlgrthm =%d, dot11PrivacyAlgrthm =%d, "
2151 "dot118021XGrpPrivacy =%d\n", psecuritypriv->dot11AuthAlgrthm,
2152 psecuritypriv->dot11PrivacyAlgrthm,
2153 psecuritypriv->dot118021XGrpPrivacy);
2157 DBG_8723A("<=%s, ret %d\n", __func__, ret);
2162 static int cfg80211_rtw_disconnect(struct wiphy *wiphy, struct net_device *ndev,
2165 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
2167 DBG_8723A("%s(%s)\n", __func__, ndev->name);
2169 rtw_set_roaming(padapter, 0);
2171 if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
2172 rtw_scan_abort23a(padapter);
2173 LeaveAllPowerSaveMode23a(padapter);
2174 rtw_disassoc_cmd23a(padapter, 500, false);
2176 DBG_8723A("%s...call rtw_indicate_disconnect23a\n", __func__);
2178 padapter->mlmepriv.not_indic_disco = true;
2179 rtw_indicate_disconnect23a(padapter);
2180 padapter->mlmepriv.not_indic_disco = false;
2182 rtw_free_assoc_resources23a(padapter, 1);
2188 static int cfg80211_rtw_set_txpower(struct wiphy *wiphy,
2189 struct wireless_dev *wdev,
2190 enum nl80211_tx_power_setting type, int mbm)
2192 DBG_8723A("%s\n", __func__);
2196 static int cfg80211_rtw_get_txpower(struct wiphy *wiphy,
2197 struct wireless_dev *wdev, int *dbm)
2199 DBG_8723A("%s\n", __func__);
2204 inline bool rtw_cfg80211_pwr_mgmt(struct rtw_adapter *adapter)
2206 struct rtw_wdev_priv *rtw_wdev_priv = wdev_to_priv(adapter->rtw_wdev);
2207 return rtw_wdev_priv->power_mgmt;
2210 static int cfg80211_rtw_set_power_mgmt(struct wiphy *wiphy,
2211 struct net_device *ndev,
2212 bool enabled, int timeout)
2214 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
2215 struct rtw_wdev_priv *rtw_wdev_priv = wdev_to_priv(padapter->rtw_wdev);
2217 DBG_8723A("%s(%s): enabled:%u, timeout:%d\n",
2218 __func__, ndev->name, enabled, timeout);
2220 rtw_wdev_priv->power_mgmt = enabled;
2223 LPS_Leave23a(padapter);
2228 static int cfg80211_rtw_set_pmksa(struct wiphy *wiphy,
2229 struct net_device *netdev,
2230 struct cfg80211_pmksa *pmksa)
2232 u8 index, blInserted = false;
2233 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
2234 struct security_priv *psecuritypriv = &padapter->securitypriv;
2236 DBG_8723A("%s(%s)\n", __func__, netdev->name);
2238 if (is_zero_ether_addr(pmksa->bssid))
2243 /* overwrite PMKID */
2244 for (index = 0; index < NUM_PMKID_CACHE; index++) {
2245 if (ether_addr_equal(psecuritypriv->PMKIDList[index].Bssid,
2247 /* BSSID is matched, the same AP => rewrite with
2249 DBG_8723A("%s(%s): BSSID exists in the PMKList.\n",
2250 __func__, netdev->name);
2252 memcpy(psecuritypriv->PMKIDList[index].PMKID,
2253 pmksa->pmkid, WLAN_PMKID_LEN);
2254 psecuritypriv->PMKIDList[index].bUsed = true;
2255 psecuritypriv->PMKIDIndex = index + 1;
2262 /* Find a new entry */
2263 DBG_8723A("%s(%s): Use new entry index = %d for this PMKID\n",
2264 __func__, netdev->name, psecuritypriv->PMKIDIndex);
2267 psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].
2268 Bssid, pmksa->bssid);
2269 memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].
2270 PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
2272 psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed =
2274 psecuritypriv->PMKIDIndex++;
2275 if (psecuritypriv->PMKIDIndex == 16) {
2276 psecuritypriv->PMKIDIndex = 0;
2283 static int cfg80211_rtw_del_pmksa(struct wiphy *wiphy,
2284 struct net_device *netdev,
2285 struct cfg80211_pmksa *pmksa)
2287 u8 index, bMatched = false;
2288 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
2289 struct security_priv *psecuritypriv = &padapter->securitypriv;
2291 DBG_8723A("%s(%s)\n", __func__, netdev->name);
2293 for (index = 0; index < NUM_PMKID_CACHE; index++) {
2294 if (ether_addr_equal(psecuritypriv->PMKIDList[index].Bssid,
2296 /* BSSID is matched, the same AP => Remove this PMKID
2297 information and reset it. */
2298 eth_zero_addr(psecuritypriv->PMKIDList[index].Bssid);
2299 memset(psecuritypriv->PMKIDList[index].PMKID, 0x00,
2301 psecuritypriv->PMKIDList[index].bUsed = false;
2307 if (false == bMatched) {
2308 DBG_8723A("%s(%s): do not have matched BSSID\n", __func__,
2316 static int cfg80211_rtw_flush_pmksa(struct wiphy *wiphy,
2317 struct net_device *netdev)
2319 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
2320 struct security_priv *psecuritypriv = &padapter->securitypriv;
2322 DBG_8723A("%s(%s)\n", __func__, netdev->name);
2324 memset(&psecuritypriv->PMKIDList[0], 0x00,
2325 sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
2326 psecuritypriv->PMKIDIndex = 0;
2331 #ifdef CONFIG_8723AU_AP_MODE
2332 void rtw_cfg80211_indicate_sta_assoc(struct rtw_adapter *padapter,
2333 u8 *pmgmt_frame, uint frame_len)
2337 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2338 struct net_device *ndev = padapter->pnetdev;
2340 DBG_8723A("%s(padapter =%p,%s)\n", __func__, padapter, ndev->name);
2342 #if defined(RTW_USE_CFG80211_STA_EVENT)
2344 struct station_info sinfo;
2347 if (ieee80211_is_assoc_req(hdr->frame_control))
2348 ie_offset = offsetof(struct ieee80211_mgmt,
2349 u.assoc_req.variable);
2350 else /* WIFI_REASSOCREQ */
2351 ie_offset = offsetof(struct ieee80211_mgmt,
2352 u.reassoc_req.variable);
2355 sinfo.assoc_req_ies = pmgmt_frame + ie_offset;
2356 sinfo.assoc_req_ies_len = frame_len - ie_offset;
2357 cfg80211_new_sta(ndev, hdr->addr2, &sinfo, GFP_ATOMIC);
2359 #else /* defined(RTW_USE_CFG80211_STA_EVENT) */
2360 channel = pmlmeext->cur_channel;
2361 if (channel <= RTW_CH_MAX_2G_CHANNEL)
2362 freq = ieee80211_channel_to_frequency(channel,
2363 IEEE80211_BAND_2GHZ);
2365 freq = ieee80211_channel_to_frequency(channel,
2366 IEEE80211_BAND_5GHZ);
2368 cfg80211_rx_mgmt(padapter->rtw_wdev, freq, 0, pmgmt_frame, frame_len,
2370 #endif /* defined(RTW_USE_CFG80211_STA_EVENT) */
2373 void rtw_cfg80211_indicate_sta_disassoc(struct rtw_adapter *padapter,
2375 unsigned short reason)
2380 struct ieee80211_mgmt mgmt;
2381 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2382 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
2383 struct net_device *ndev = padapter->pnetdev;
2385 DBG_8723A("%s(padapter =%p,%s)\n", __func__, padapter, ndev->name);
2387 memset(&mgmt, 0, sizeof(struct ieee80211_mgmt));
2389 #if defined(RTW_USE_CFG80211_STA_EVENT)
2390 cfg80211_del_sta(ndev, da, GFP_ATOMIC);
2391 #else /* defined(RTW_USE_CFG80211_STA_EVENT) */
2392 channel = pmlmeext->cur_channel;
2393 if (channel <= RTW_CH_MAX_2G_CHANNEL)
2394 freq = ieee80211_channel_to_frequency(channel,
2395 IEEE80211_BAND_2GHZ);
2397 freq = ieee80211_channel_to_frequency(channel,
2398 IEEE80211_BAND_5GHZ);
2400 mgmt.frame_control =
2401 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH);
2403 ether_addr_copy(mgmt.da, myid(&padapter->eeprompriv));
2404 ether_addr_copy(mgmt.sa, da);
2405 ether_addr_copy(mgmt.bssid, get_my_bssid23a(&pmlmeinfo->network));
2407 mgmt.seq_ctrl = cpu_to_le16(IEEE80211_SN_TO_SEQ(pmlmeext->mgnt_seq));
2408 pmlmeext->mgnt_seq++;
2410 mgmt.u.disassoc.reason_code = cpu_to_le16(reason);
2412 frame_len = sizeof(struct ieee80211_hdr_3addr) + 2;
2414 cfg80211_rx_mgmt(padapter->rtw_wdev, freq, 0, (u8 *)&mgmt, frame_len,
2416 #endif /* defined(RTW_USE_CFG80211_STA_EVENT) */
2419 static int rtw_cfg80211_monitor_if_open(struct net_device *ndev)
2421 DBG_8723A("%s\n", __func__);
2426 static int rtw_cfg80211_monitor_if_close(struct net_device *ndev)
2428 DBG_8723A("%s\n", __func__);
2433 static int rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb,
2434 struct net_device *ndev)
2439 int dot11_hdr_len = 24;
2441 unsigned char *pdata;
2442 unsigned char src_mac_addr[6];
2443 unsigned char dst_mac_addr[6];
2444 struct ieee80211_hdr *dot11_hdr;
2445 struct ieee80211_radiotap_header *rtap_hdr;
2446 struct rtw_adapter *padapter = netdev_priv(ndev);
2448 DBG_8723A("%s(%s)\n", __func__, ndev->name);
2450 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
2453 rtap_hdr = (struct ieee80211_radiotap_header *)skb->data;
2454 if (unlikely(rtap_hdr->it_version))
2457 rtap_len = ieee80211_get_radiotap_len(skb->data);
2458 if (unlikely(skb->len < rtap_len))
2461 if (rtap_len != 14) {
2462 DBG_8723A("radiotap len (should be 14): %d\n", rtap_len);
2466 /* Skip the ratio tap header */
2467 skb_pull(skb, rtap_len);
2469 dot11_hdr = (struct ieee80211_hdr *)skb->data;
2470 /* Check if the QoS bit is set */
2471 if (ieee80211_is_data(dot11_hdr->frame_control)) {
2472 /* Check if this ia a Wireless Distribution System (WDS) frame
2473 * which has 4 MAC addresses
2475 if (ieee80211_is_data_qos(dot11_hdr->frame_control))
2476 qos_len = IEEE80211_QOS_CTL_LEN;
2477 if (ieee80211_has_a4(dot11_hdr->frame_control))
2480 memcpy(dst_mac_addr, dot11_hdr->addr1, sizeof(dst_mac_addr));
2481 memcpy(src_mac_addr, dot11_hdr->addr2, sizeof(src_mac_addr));
2484 * Skip the 802.11 header, QoS (if any) and SNAP,
2485 * but leave spaces for two MAC addresses
2487 skb_pull(skb, dot11_hdr_len + qos_len + snap_len -
2489 pdata = (unsigned char *)skb->data;
2490 ether_addr_copy(pdata, dst_mac_addr);
2491 ether_addr_copy(pdata + ETH_ALEN, src_mac_addr);
2493 DBG_8723A("should be eapol packet\n");
2495 /* Use the real net device to transmit the packet */
2496 ret = rtw_xmit23a_entry23a(skb, padapter->pnetdev);
2500 } else if (ieee80211_is_action(dot11_hdr->frame_control)) {
2501 struct ieee80211_mgmt *mgmt;
2502 /* only for action frames */
2503 struct xmit_frame *pmgntframe;
2504 struct pkt_attrib *pattrib;
2505 unsigned char *pframe;
2506 /* u8 category, action, OUI_Subtype, dialogToken = 0; */
2507 /* unsigned char *frame_body; */
2508 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2509 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2511 u8 category, action;
2513 mgmt = (struct ieee80211_mgmt *)dot11_hdr;
2515 DBG_8723A("RTW_Tx:da=%pM via %s(%s)\n",
2516 mgmt->da, __func__, ndev->name);
2517 category = mgmt->u.action.category;
2518 action = mgmt->u.action.u.wme_action.action_code;
2519 DBG_8723A("RTW_Tx:category(%u), action(%u)\n",
2522 /* starting alloc mgmt frame to dump it */
2523 pmgntframe = alloc_mgtxmitframe23a(pxmitpriv);
2524 if (pmgntframe == NULL)
2527 /* update attribute */
2528 pattrib = &pmgntframe->attrib;
2529 update_mgntframe_attrib23a(padapter, pattrib);
2530 pattrib->retry_ctrl = false;
2532 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2534 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2536 memcpy(pframe, skb->data, len);
2537 pattrib->pktlen = len;
2539 /* update seq number */
2540 pmlmeext->mgnt_seq = le16_to_cpu(dot11_hdr->seq_ctrl) >> 4;
2541 pattrib->seqnum = pmlmeext->mgnt_seq;
2542 pmlmeext->mgnt_seq++;
2544 pattrib->last_txcmdsz = pattrib->pktlen;
2546 dump_mgntframe23a(padapter, pmgntframe);
2557 rtw_cfg80211_monitor_if_set_mac_address(struct net_device *ndev, void *addr)
2559 DBG_8723A("%s\n", __func__);
2564 static const struct net_device_ops rtw_cfg80211_monitor_if_ops = {
2565 .ndo_open = rtw_cfg80211_monitor_if_open,
2566 .ndo_stop = rtw_cfg80211_monitor_if_close,
2567 .ndo_start_xmit = rtw_cfg80211_monitor_if_xmit_entry,
2568 .ndo_set_mac_address = rtw_cfg80211_monitor_if_set_mac_address,
2571 static int rtw_cfg80211_add_monitor_if(struct rtw_adapter *padapter, char *name,
2572 unsigned char name_assign_type,
2573 struct net_device **ndev)
2576 struct net_device *mon_ndev = NULL;
2577 struct wireless_dev *mon_wdev = NULL;
2578 struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
2581 DBG_8723A("%s(%s): without specific name\n",
2582 __func__, padapter->pnetdev->name);
2587 if (pwdev_priv->pmon_ndev) {
2588 DBG_8723A("%s(%s): monitor interface exist: %s\n", __func__,
2589 padapter->pnetdev->name, pwdev_priv->pmon_ndev->name);
2594 mon_ndev = alloc_etherdev(sizeof(struct rtw_adapter));
2596 DBG_8723A("%s(%s): allocate ndev fail\n", __func__,
2597 padapter->pnetdev->name);
2602 mon_ndev->type = ARPHRD_IEEE80211_RADIOTAP;
2603 strncpy(mon_ndev->name, name, IFNAMSIZ);
2604 mon_ndev->name[IFNAMSIZ - 1] = 0;
2605 mon_ndev->name_assign_type = name_assign_type;
2606 mon_ndev->destructor = rtw_ndev_destructor;
2608 mon_ndev->netdev_ops = &rtw_cfg80211_monitor_if_ops;
2611 mon_wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
2617 mon_wdev->wiphy = padapter->rtw_wdev->wiphy;
2618 mon_wdev->netdev = mon_ndev;
2619 mon_wdev->iftype = NL80211_IFTYPE_MONITOR;
2620 mon_ndev->ieee80211_ptr = mon_wdev;
2622 ret = register_netdevice(mon_ndev);
2627 *ndev = pwdev_priv->pmon_ndev = mon_ndev;
2628 memcpy(pwdev_priv->ifname_mon, name, IFNAMSIZ + 1);
2636 if (ret && mon_ndev) {
2637 free_netdev(mon_ndev);
2638 *ndev = mon_ndev = NULL;
2644 static struct wireless_dev *
2645 cfg80211_rtw_add_virtual_intf(struct wiphy *wiphy, const char *name,
2646 unsigned char name_assign_type,
2647 enum nl80211_iftype type, u32 *flags,
2648 struct vif_params *params)
2651 struct net_device *ndev = NULL;
2652 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
2654 DBG_8723A("%s(%s): wiphy:%s, name:%s, type:%d\n", __func__,
2655 padapter->pnetdev->name, wiphy_name(wiphy), name, type);
2658 case NL80211_IFTYPE_ADHOC:
2659 case NL80211_IFTYPE_AP_VLAN:
2660 case NL80211_IFTYPE_WDS:
2661 case NL80211_IFTYPE_MESH_POINT:
2664 case NL80211_IFTYPE_MONITOR:
2666 rtw_cfg80211_add_monitor_if(padapter, (char *)name,
2667 name_assign_type, &ndev);
2670 case NL80211_IFTYPE_P2P_CLIENT:
2671 case NL80211_IFTYPE_STATION:
2675 case NL80211_IFTYPE_P2P_GO:
2676 case NL80211_IFTYPE_AP:
2681 DBG_8723A("Unsupported interface type\n");
2685 DBG_8723A("%s(%s): ndev:%p, ret:%d\n", __func__,
2686 padapter->pnetdev->name,
2689 return ndev ? ndev->ieee80211_ptr : ERR_PTR(ret);
2692 static int cfg80211_rtw_del_virtual_intf(struct wiphy *wiphy,
2693 struct wireless_dev *wdev)
2695 struct rtw_wdev_priv *pwdev_priv =
2696 (struct rtw_wdev_priv *)wiphy_priv(wiphy);
2697 struct net_device *ndev;
2698 ndev = wdev ? wdev->netdev : NULL;
2703 unregister_netdevice(ndev);
2705 if (ndev == pwdev_priv->pmon_ndev) {
2706 pwdev_priv->pmon_ndev = NULL;
2707 pwdev_priv->ifname_mon[0] = '\0';
2708 DBG_8723A("%s(%s): remove monitor interface\n",
2709 __func__, ndev->name);
2716 static int rtw_add_beacon(struct rtw_adapter *adapter, const u8 *head,
2717 size_t head_len, const u8 *tail, size_t tail_len)
2721 uint len, ielen, wps_ielen = 0;
2722 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
2723 struct wlan_bssid_ex *bss = &pmlmepriv->cur_network.network;
2724 const struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)head;
2725 struct ieee80211_mgmt *tmpmgmt;
2726 /* struct sta_priv *pstapriv = &padapter->stapriv; */
2728 DBG_8723A("%s beacon_head_len =%zu, beacon_tail_len =%zu\n",
2729 __func__, head_len, tail_len);
2731 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true)
2734 if (head_len < offsetof(struct ieee80211_mgmt, u.beacon.variable))
2737 pbuf = kzalloc(head_len + tail_len, GFP_KERNEL);
2740 tmpmgmt = (struct ieee80211_mgmt *)pbuf;
2742 bss->beacon_interval = get_unaligned_le16(&mgmt->u.beacon.beacon_int);
2743 bss->capability = get_unaligned_le16(&mgmt->u.beacon.capab_info);
2744 bss->tsf = get_unaligned_le64(&mgmt->u.beacon.timestamp);
2746 /* 24 = beacon header len. */
2747 memcpy(pbuf, (void *)head, head_len);
2748 memcpy(pbuf + head_len, (void *)tail, tail_len);
2750 len = head_len + tail_len;
2751 ielen = len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
2752 /* check wps ie if inclued */
2753 if (cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2754 WLAN_OUI_TYPE_MICROSOFT_WPS,
2755 tmpmgmt->u.beacon.variable, ielen))
2756 DBG_8723A("add bcn, wps_ielen =%d\n", wps_ielen);
2758 /* pbss_network->IEs will not include p2p_ie, wfd ie */
2759 rtw_ies_remove_ie23a(tmpmgmt->u.beacon.variable, &ielen, 0,
2760 WLAN_EID_VENDOR_SPECIFIC, P2P_OUI23A, 4);
2761 rtw_ies_remove_ie23a(tmpmgmt->u.beacon.variable, &ielen, 0,
2762 WLAN_EID_VENDOR_SPECIFIC, WFD_OUI23A, 4);
2764 len = ielen + offsetof(struct ieee80211_mgmt, u.beacon.variable);
2765 if (rtw_check_beacon_data23a(adapter, tmpmgmt, len) == _SUCCESS) {
2776 static int cfg80211_rtw_start_ap(struct wiphy *wiphy, struct net_device *ndev,
2777 struct cfg80211_ap_settings *settings)
2780 struct rtw_adapter *adapter = wiphy_to_adapter(wiphy);
2782 DBG_8723A("%s(%s): hidden_ssid:%d, auth_type:%d\n",
2783 __func__, ndev->name, settings->hidden_ssid,
2784 settings->auth_type);
2786 ret = rtw_add_beacon(adapter, settings->beacon.head,
2787 settings->beacon.head_len, settings->beacon.tail,
2788 settings->beacon.tail_len);
2790 adapter->mlmeextpriv.mlmext_info.hidden_ssid_mode =
2791 settings->hidden_ssid;
2793 if (settings->ssid && settings->ssid_len) {
2794 struct wlan_bssid_ex *pbss_network =
2795 &adapter->mlmepriv.cur_network.network;
2796 struct wlan_bssid_ex *pbss_network_ext =
2797 &adapter->mlmeextpriv.mlmext_info.network;
2799 memcpy(pbss_network->Ssid.ssid, (void *)settings->ssid,
2800 settings->ssid_len);
2801 pbss_network->Ssid.ssid_len = settings->ssid_len;
2802 memcpy(pbss_network_ext->Ssid.ssid, (void *)settings->ssid,
2803 settings->ssid_len);
2804 pbss_network_ext->Ssid.ssid_len = settings->ssid_len;
2810 static int cfg80211_rtw_change_beacon(struct wiphy *wiphy,
2811 struct net_device *ndev,
2812 struct cfg80211_beacon_data *info)
2815 struct rtw_adapter *adapter = wiphy_to_adapter(wiphy);
2817 DBG_8723A("%s(%s)\n", __func__, ndev->name);
2819 ret = rtw_add_beacon(adapter, info->head, info->head_len, info->tail,
2825 static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
2827 DBG_8723A("%s(%s)\n", __func__, ndev->name);
2831 static int cfg80211_rtw_add_station(struct wiphy *wiphy,
2832 struct net_device *ndev, const u8 *mac,
2833 struct station_parameters *params)
2835 DBG_8723A("%s(%s)\n", __func__, ndev->name);
2840 static int cfg80211_rtw_del_station(struct wiphy *wiphy,
2841 struct net_device *ndev,
2842 struct station_del_parameters *params)
2844 const u8 *mac = params->mac;
2846 struct list_head *phead;
2848 struct sta_info *psta, *ptmp;
2849 struct rtw_adapter *padapter = netdev_priv(ndev);
2850 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2851 struct sta_priv *pstapriv = &padapter->stapriv;
2853 DBG_8723A("+%s(%s)\n", __func__, ndev->name);
2855 if (check_fwstate(pmlmepriv, (_FW_LINKED | WIFI_AP_STATE)) != true) {
2856 DBG_8723A("%s, fw_state != FW_LINKED|WIFI_AP_STATE\n",
2862 DBG_8723A("flush all sta, and cam_entry\n");
2864 flush_all_cam_entry23a(padapter); /* clear CAM */
2866 ret = rtw_sta_flush23a(padapter);
2871 DBG_8723A("free sta macaddr=%pM\n", mac);
2873 if (is_broadcast_ether_addr(mac))
2876 spin_lock_bh(&pstapriv->asoc_list_lock);
2877 phead = &pstapriv->asoc_list;
2878 /* check asoc_queue */
2879 list_for_each_entry_safe(psta, ptmp, phead, asoc_list) {
2880 if (ether_addr_equal(mac, psta->hwaddr)) {
2881 if (psta->dot8021xalg == 1 &&
2882 psta->bpairwise_key_installed == false) {
2883 DBG_8723A("%s, sta's dot8021xalg = 1 and "
2884 "key_installed = false\n", __func__);
2886 DBG_8723A("free psta =%p, aid =%d\n", psta,
2889 list_del_init(&psta->asoc_list);
2890 pstapriv->asoc_list_cnt--;
2892 /* spin_unlock_bh(&pstapriv->asoc_list_lock); */
2894 ap_free_sta23a(padapter, psta, true,
2895 WLAN_REASON_DEAUTH_LEAVING);
2896 /* spin_lock_bh(&pstapriv->asoc_list_lock); */
2904 spin_unlock_bh(&pstapriv->asoc_list_lock);
2906 associated_clients_update23a(padapter, updated);
2908 DBG_8723A("-%s(%s)\n", __func__, ndev->name);
2913 static int cfg80211_rtw_change_station(struct wiphy *wiphy,
2914 struct net_device *ndev, const u8 *mac,
2915 struct station_parameters *params)
2917 DBG_8723A("%s(%s)\n", __func__, ndev->name);
2921 static int cfg80211_rtw_dump_station(struct wiphy *wiphy,
2922 struct net_device *ndev, int idx, u8 *mac,
2923 struct station_info *sinfo)
2925 DBG_8723A("%s(%s)\n", __func__, ndev->name);
2927 /* TODO: dump scanned queue */
2932 static int cfg80211_rtw_change_bss(struct wiphy *wiphy, struct net_device *ndev,
2933 struct bss_parameters *params)
2935 DBG_8723A("%s(%s)\n", __func__, ndev->name);
2938 #endif /* CONFIG_8723AU_AP_MODE */
2940 static int _cfg80211_rtw_mgmt_tx(struct rtw_adapter *padapter, u8 tx_ch,
2941 const u8 *buf, size_t len)
2943 struct xmit_frame *pmgntframe;
2944 struct pkt_attrib *pattrib;
2945 unsigned char *pframe;
2947 struct ieee80211_hdr *pwlanhdr;
2948 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2949 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2951 if (_FAIL == rtw_pwr_wakeup(padapter)) {
2956 rtw_set_scan_deny(padapter, 1000);
2958 rtw_scan_abort23a(padapter);
2960 if (tx_ch != rtw_get_oper_ch23a(padapter)) {
2961 if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED))
2962 pmlmeext->cur_channel = tx_ch;
2963 set_channel_bwmode23a(padapter, tx_ch,
2964 HAL_PRIME_CHNL_OFFSET_DONT_CARE,
2965 HT_CHANNEL_WIDTH_20);
2968 /* starting alloc mgmt frame to dump it */
2969 pmgntframe = alloc_mgtxmitframe23a(pxmitpriv);
2971 /* ret = -ENOMEM; */
2976 /* update attribute */
2977 pattrib = &pmgntframe->attrib;
2978 update_mgntframe_attrib23a(padapter, pattrib);
2979 pattrib->retry_ctrl = false;
2981 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2983 pframe = (u8 *) (pmgntframe->buf_addr) + TXDESC_OFFSET;
2985 memcpy(pframe, (void *)buf, len);
2986 pattrib->pktlen = len;
2988 pwlanhdr = (struct ieee80211_hdr *)pframe;
2989 /* update seq number */
2990 pmlmeext->mgnt_seq = le16_to_cpu(pwlanhdr->seq_ctrl) >> 4;
2991 pattrib->seqnum = pmlmeext->mgnt_seq;
2992 pmlmeext->mgnt_seq++;
2994 pattrib->last_txcmdsz = pattrib->pktlen;
2996 ret = dump_mgntframe23a_and_wait_ack23a(padapter, pmgntframe);
2998 if (ret != _SUCCESS)
2999 DBG_8723A("%s, ack == false\n", __func__);
3001 DBG_8723A("%s, ack == true\n", __func__);
3005 DBG_8723A("%s, ret =%d\n", __func__, ret);
3010 static int cfg80211_rtw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
3011 struct cfg80211_mgmt_tx_params *params,
3014 struct rtw_adapter *padapter =
3015 (struct rtw_adapter *)wiphy_to_adapter(wiphy);
3018 u32 dump_limit = RTW_MAX_MGMT_TX_CNT;
3021 u8 category, action;
3022 unsigned long start = jiffies;
3023 size_t len = params->len;
3024 struct ieee80211_channel *chan = params->chan;
3025 const u8 *buf = params->buf;
3026 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *)buf;
3027 u8 tx_ch = (u8) ieee80211_frequency_to_channel(chan->center_freq);
3029 if (!ieee80211_is_action(hdr->frame_control))
3032 /* cookie generation */
3033 *cookie = (unsigned long)buf;
3035 DBG_8723A("%s(%s): len =%zu, ch =%d\n", __func__,
3036 padapter->pnetdev->name, len, tx_ch);
3038 /* indicate ack before issue frame to avoid racing with rsp frame */
3039 cfg80211_mgmt_tx_status(padapter->rtw_wdev, *cookie, buf, len, ack,
3042 DBG_8723A("RTW_Tx:tx_ch =%d, da =%pM\n", tx_ch, hdr->da);
3043 category = hdr->u.action.category;
3044 action = hdr->u.action.u.wme_action.action_code;
3045 DBG_8723A("RTW_Tx:category(%u), action(%u)\n", category, action);
3049 tx_ret = _cfg80211_rtw_mgmt_tx(padapter, tx_ch, buf, len);
3050 } while (dump_cnt < dump_limit && tx_ret != _SUCCESS);
3052 if (tx_ret != _SUCCESS || dump_cnt > 1) {
3053 DBG_8723A("%s(%s): %s (%d/%d) in %d ms\n",
3054 __func__, padapter->pnetdev->name,
3055 tx_ret == _SUCCESS ? "OK" : "FAIL", dump_cnt,
3056 dump_limit, jiffies_to_msecs(jiffies - start));
3062 static void cfg80211_rtw_mgmt_frame_register(struct wiphy *wiphy,
3063 struct wireless_dev *wdev,
3064 u16 frame_type, bool reg)
3066 if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
3072 static struct cfg80211_ops rtw_cfg80211_ops = {
3073 .change_virtual_intf = cfg80211_rtw_change_iface,
3074 .add_key = cfg80211_rtw_add_key,
3075 .get_key = cfg80211_rtw_get_key,
3076 .del_key = cfg80211_rtw_del_key,
3077 .set_default_key = cfg80211_rtw_set_default_key,
3078 .get_station = cfg80211_rtw_get_station,
3079 .scan = cfg80211_rtw_scan,
3080 .set_wiphy_params = cfg80211_rtw_set_wiphy_params,
3081 .connect = cfg80211_rtw_connect,
3082 .disconnect = cfg80211_rtw_disconnect,
3083 .join_ibss = cfg80211_rtw_join_ibss,
3084 .leave_ibss = cfg80211_rtw_leave_ibss,
3085 .set_tx_power = cfg80211_rtw_set_txpower,
3086 .get_tx_power = cfg80211_rtw_get_txpower,
3087 .set_power_mgmt = cfg80211_rtw_set_power_mgmt,
3088 .set_pmksa = cfg80211_rtw_set_pmksa,
3089 .del_pmksa = cfg80211_rtw_del_pmksa,
3090 .flush_pmksa = cfg80211_rtw_flush_pmksa,
3092 #ifdef CONFIG_8723AU_AP_MODE
3093 .add_virtual_intf = cfg80211_rtw_add_virtual_intf,
3094 .del_virtual_intf = cfg80211_rtw_del_virtual_intf,
3096 .start_ap = cfg80211_rtw_start_ap,
3097 .change_beacon = cfg80211_rtw_change_beacon,
3098 .stop_ap = cfg80211_rtw_stop_ap,
3100 .add_station = cfg80211_rtw_add_station,
3101 .del_station = cfg80211_rtw_del_station,
3102 .change_station = cfg80211_rtw_change_station,
3103 .dump_station = cfg80211_rtw_dump_station,
3104 .change_bss = cfg80211_rtw_change_bss,
3105 #endif /* CONFIG_8723AU_AP_MODE */
3107 .mgmt_tx = cfg80211_rtw_mgmt_tx,
3108 .mgmt_frame_register = cfg80211_rtw_mgmt_frame_register,
3111 static void rtw_cfg80211_init_ht_capab(struct ieee80211_sta_ht_cap *ht_cap,
3112 enum ieee80211_band band, u8 rf_type)
3115 #define MAX_BIT_RATE_40MHZ_MCS15 300 /* Mbps */
3116 #define MAX_BIT_RATE_40MHZ_MCS7 150 /* Mbps */
3118 ht_cap->ht_supported = true;
3120 ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
3121 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20 |
3122 IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
3125 *Maximum length of AMPDU that the STA can receive.
3126 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
3128 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3130 /*Minimum MPDU start spacing , */
3131 ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
3133 ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
3136 *hw->wiphy->bands[IEEE80211_BAND_2GHZ]
3139 *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7
3140 *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15
3141 *if rx_ant >= 3 rx_mask[2]= 0xff;
3142 *if BW_40 rx_mask[4]= 0x01;
3143 *highest supported RX rate
3145 if (rf_type == RF_1T1R) {
3146 ht_cap->mcs.rx_mask[0] = 0xFF;
3147 ht_cap->mcs.rx_mask[1] = 0x00;
3148 ht_cap->mcs.rx_mask[4] = 0x01;
3150 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
3151 } else if ((rf_type == RF_1T2R) || (rf_type == RF_2T2R)) {
3152 ht_cap->mcs.rx_mask[0] = 0xFF;
3153 ht_cap->mcs.rx_mask[1] = 0xFF;
3154 ht_cap->mcs.rx_mask[4] = 0x01;
3156 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
3158 DBG_8723A("%s, error rf_type =%d\n", __func__, rf_type);
3163 void rtw_cfg80211_init_wiphy(struct rtw_adapter *padapter)
3166 struct ieee80211_supported_band *bands;
3167 struct wireless_dev *pwdev = padapter->rtw_wdev;
3168 struct wiphy *wiphy = pwdev->wiphy;
3170 rf_type = rtl8723a_get_rf_type(padapter);
3172 DBG_8723A("%s:rf_type =%d\n", __func__, rf_type);
3174 /* if (padapter->registrypriv.wireless_mode & WIRELESS_11G) */
3176 bands = wiphy->bands[IEEE80211_BAND_2GHZ];
3178 rtw_cfg80211_init_ht_capab(&bands->ht_cap,
3179 IEEE80211_BAND_2GHZ,
3183 /* if (padapter->registrypriv.wireless_mode & WIRELESS_11A) */
3185 bands = wiphy->bands[IEEE80211_BAND_5GHZ];
3187 rtw_cfg80211_init_ht_capab(&bands->ht_cap,
3188 IEEE80211_BAND_5GHZ,
3193 static void rtw_cfg80211_preinit_wiphy(struct rtw_adapter *padapter,
3194 struct wiphy *wiphy)
3196 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
3198 wiphy->max_scan_ssids = RTW_SSID_SCAN_AMOUNT;
3199 wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
3200 wiphy->max_num_pmkids = RTW_MAX_NUM_PMKIDS;
3202 wiphy->max_remain_on_channel_duration =
3203 RTW_MAX_REMAIN_ON_CHANNEL_DURATION;
3205 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
3206 BIT(NL80211_IFTYPE_ADHOC) |
3207 #ifdef CONFIG_8723AU_AP_MODE
3208 BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR) |
3212 #ifdef CONFIG_8723AU_AP_MODE
3213 wiphy->mgmt_stypes = rtw_cfg80211_default_mgmt_stypes;
3214 #endif /* CONFIG_8723AU_AP_MODE */
3216 wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
3219 wiphy->iface_combinations = &rtw_combinations;
3220 wiphy->n_iface_combinations = 1;
3223 wiphy->cipher_suites = rtw_cipher_suites;
3224 wiphy->n_cipher_suites = ARRAY_SIZE(rtw_cipher_suites);
3226 /* if (padapter->registrypriv.wireless_mode & WIRELESS_11G) */
3227 wiphy->bands[IEEE80211_BAND_2GHZ] =
3228 rtw_spt_band_alloc(IEEE80211_BAND_2GHZ);
3229 /* if (padapter->registrypriv.wireless_mode & WIRELESS_11A) */
3230 wiphy->bands[IEEE80211_BAND_5GHZ] =
3231 rtw_spt_band_alloc(IEEE80211_BAND_5GHZ);
3233 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3234 wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX | WIPHY_FLAG_HAVE_AP_SME;
3236 if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE)
3237 wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
3239 wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
3242 int rtw_wdev_alloc(struct rtw_adapter *padapter, struct device *dev)
3245 struct wiphy *wiphy;
3246 struct wireless_dev *wdev;
3247 struct rtw_wdev_priv *pwdev_priv;
3248 struct net_device *pnetdev = padapter->pnetdev;
3250 DBG_8723A("%s(padapter =%p)\n", __func__, padapter);
3253 wiphy = wiphy_new(&rtw_cfg80211_ops, sizeof(struct rtw_wdev_priv));
3255 DBG_8723A("Couldn't allocate wiphy device\n");
3261 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
3267 set_wiphy_dev(wiphy, dev);
3268 rtw_cfg80211_preinit_wiphy(padapter, wiphy);
3270 ret = wiphy_register(wiphy);
3272 DBG_8723A("Couldn't register wiphy device\n");
3276 wdev->wiphy = wiphy;
3277 wdev->netdev = pnetdev;
3278 /* wdev->iftype = NL80211_IFTYPE_STATION; */
3279 /* for rtw_setopmode_cmd23a() in cfg80211_rtw_change_iface() */
3280 wdev->iftype = NL80211_IFTYPE_MONITOR;
3281 padapter->rtw_wdev = wdev;
3282 pnetdev->ieee80211_ptr = wdev;
3284 /* init pwdev_priv */
3285 pwdev_priv = wdev_to_priv(wdev);
3286 pwdev_priv->rtw_wdev = wdev;
3287 pwdev_priv->pmon_ndev = NULL;
3288 pwdev_priv->ifname_mon[0] = '\0';
3289 pwdev_priv->padapter = padapter;
3290 pwdev_priv->scan_request = NULL;
3291 spin_lock_init(&pwdev_priv->scan_req_lock);
3293 pwdev_priv->p2p_enabled = false;
3295 if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE)
3296 pwdev_priv->power_mgmt = true;
3298 pwdev_priv->power_mgmt = false;
3309 void rtw_wdev_free(struct wireless_dev *wdev)
3311 DBG_8723A("%s(wdev =%p)\n", __func__, wdev);
3316 kfree(wdev->wiphy->bands[IEEE80211_BAND_2GHZ]);
3317 kfree(wdev->wiphy->bands[IEEE80211_BAND_5GHZ]);
3319 wiphy_free(wdev->wiphy);
3324 void rtw_wdev_unregister(struct wireless_dev *wdev)
3326 struct rtw_wdev_priv *pwdev_priv;
3328 DBG_8723A("%s(wdev =%p)\n", __func__, wdev);
3333 pwdev_priv = wdev_to_priv(wdev);
3335 rtw_cfg80211_indicate_scan_done(pwdev_priv, true);
3337 if (pwdev_priv->pmon_ndev) {
3338 DBG_8723A("%s, unregister monitor interface\n", __func__);
3339 unregister_netdev(pwdev_priv->pmon_ndev);
3342 wiphy_unregister(wdev->wiphy);