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 <rtw_ioctl_set.h>
20 #include <xmit_osdep.h>
22 #include "ioctl_cfg80211.h"
24 #define RTW_MAX_MGMT_TX_CNT 8
26 #define RTW_MAX_REMAIN_ON_CHANNEL_DURATION 65535 /* ms */
27 #define RTW_MAX_NUM_PMKIDS 4
29 #define RTW_CH_MAX_2G_CHANNEL 14 /* Max channel in 2G band */
31 static const u32 rtw_cipher_suites[] = {
32 WLAN_CIPHER_SUITE_WEP40,
33 WLAN_CIPHER_SUITE_WEP104,
34 WLAN_CIPHER_SUITE_TKIP,
35 WLAN_CIPHER_SUITE_CCMP,
38 #define RATETAB_ENT(_rate, _rateid, _flags) { \
40 .hw_value = (_rateid), \
44 #define CHAN2G(_channel, _freq, _flags) { \
45 .band = IEEE80211_BAND_2GHZ, \
46 .center_freq = (_freq), \
47 .hw_value = (_channel), \
49 .max_antenna_gain = 0, \
53 #define CHAN5G(_channel, _flags) { \
54 .band = IEEE80211_BAND_5GHZ, \
55 .center_freq = 5000 + (5 * (_channel)), \
56 .hw_value = (_channel), \
58 .max_antenna_gain = 0, \
62 static struct ieee80211_rate rtw_rates[] = {
63 RATETAB_ENT(10, 0x1, 0),
64 RATETAB_ENT(20, 0x2, 0),
65 RATETAB_ENT(55, 0x4, 0),
66 RATETAB_ENT(110, 0x8, 0),
67 RATETAB_ENT(60, 0x10, 0),
68 RATETAB_ENT(90, 0x20, 0),
69 RATETAB_ENT(120, 0x40, 0),
70 RATETAB_ENT(180, 0x80, 0),
71 RATETAB_ENT(240, 0x100, 0),
72 RATETAB_ENT(360, 0x200, 0),
73 RATETAB_ENT(480, 0x400, 0),
74 RATETAB_ENT(540, 0x800, 0),
77 #define rtw_a_rates (rtw_rates + 4)
78 #define RTW_A_RATES_NUM 8
79 #define rtw_g_rates (rtw_rates + 0)
80 #define RTW_G_RATES_NUM 12
82 #define RTW_2G_CHANNELS_NUM 14
83 #define RTW_5G_CHANNELS_NUM 37
85 static struct ieee80211_channel rtw_2ghz_channels[] = {
102 static struct ieee80211_channel rtw_5ghz_a_channels[] = {
103 CHAN5G(34, 0), CHAN5G(36, 0),
104 CHAN5G(38, 0), CHAN5G(40, 0),
105 CHAN5G(42, 0), CHAN5G(44, 0),
106 CHAN5G(46, 0), CHAN5G(48, 0),
107 CHAN5G(52, 0), CHAN5G(56, 0),
108 CHAN5G(60, 0), CHAN5G(64, 0),
109 CHAN5G(100, 0), CHAN5G(104, 0),
110 CHAN5G(108, 0), CHAN5G(112, 0),
111 CHAN5G(116, 0), CHAN5G(120, 0),
112 CHAN5G(124, 0), CHAN5G(128, 0),
113 CHAN5G(132, 0), CHAN5G(136, 0),
114 CHAN5G(140, 0), CHAN5G(149, 0),
115 CHAN5G(153, 0), CHAN5G(157, 0),
116 CHAN5G(161, 0), CHAN5G(165, 0),
117 CHAN5G(184, 0), CHAN5G(188, 0),
118 CHAN5G(192, 0), CHAN5G(196, 0),
119 CHAN5G(200, 0), CHAN5G(204, 0),
120 CHAN5G(208, 0), CHAN5G(212, 0),
124 static void rtw_2g_channels_init(struct ieee80211_channel *channels)
126 memcpy((void *)channels, (void *)rtw_2ghz_channels,
127 sizeof(struct ieee80211_channel) * RTW_2G_CHANNELS_NUM);
130 static void rtw_5g_channels_init(struct ieee80211_channel *channels)
132 memcpy((void *)channels, (void *)rtw_5ghz_a_channels,
133 sizeof(struct ieee80211_channel) * RTW_5G_CHANNELS_NUM);
136 static void rtw_2g_rates_init(struct ieee80211_rate *rates)
138 memcpy(rates, rtw_g_rates,
139 sizeof(struct ieee80211_rate) * RTW_G_RATES_NUM);
142 static void rtw_5g_rates_init(struct ieee80211_rate *rates)
144 memcpy(rates, rtw_a_rates,
145 sizeof(struct ieee80211_rate) * RTW_A_RATES_NUM);
148 static struct ieee80211_supported_band *
149 rtw_spt_band_alloc(enum ieee80211_band band)
151 struct ieee80211_supported_band *spt_band = NULL;
152 int n_channels, n_bitrates;
154 if (band == IEEE80211_BAND_2GHZ) {
155 n_channels = RTW_2G_CHANNELS_NUM;
156 n_bitrates = RTW_G_RATES_NUM;
157 } else if (band == IEEE80211_BAND_5GHZ) {
158 n_channels = RTW_5G_CHANNELS_NUM;
159 n_bitrates = RTW_A_RATES_NUM;
163 spt_band = kzalloc(sizeof(struct ieee80211_supported_band) +
164 sizeof(struct ieee80211_channel) * n_channels +
165 sizeof(struct ieee80211_rate) * n_bitrates,
171 (struct ieee80211_channel *)(((u8 *) spt_band) +
173 ieee80211_supported_band));
175 (struct ieee80211_rate *)(((u8 *) spt_band->channels) +
176 sizeof(struct ieee80211_channel) *
178 spt_band->band = band;
179 spt_band->n_channels = n_channels;
180 spt_band->n_bitrates = n_bitrates;
182 if (band == IEEE80211_BAND_2GHZ) {
183 rtw_2g_channels_init(spt_band->channels);
184 rtw_2g_rates_init(spt_band->bitrates);
185 } else if (band == IEEE80211_BAND_5GHZ) {
186 rtw_5g_channels_init(spt_band->channels);
187 rtw_5g_rates_init(spt_band->bitrates);
190 /* spt_band.ht_cap */
196 static const struct ieee80211_txrx_stypes
197 rtw_cfg80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
198 [NL80211_IFTYPE_ADHOC] = {
200 .rx = BIT(IEEE80211_STYPE_ACTION >> 4)
202 [NL80211_IFTYPE_STATION] = {
204 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
205 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
207 [NL80211_IFTYPE_AP] = {
209 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
210 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
211 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
212 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
213 BIT(IEEE80211_STYPE_AUTH >> 4) |
214 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
215 BIT(IEEE80211_STYPE_ACTION >> 4)
217 [NL80211_IFTYPE_AP_VLAN] = {
220 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
221 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
222 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
223 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
224 BIT(IEEE80211_STYPE_AUTH >> 4) |
225 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
226 BIT(IEEE80211_STYPE_ACTION >> 4)
228 [NL80211_IFTYPE_P2P_CLIENT] = {
230 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
231 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
233 [NL80211_IFTYPE_P2P_GO] = {
235 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
236 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
237 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
238 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
239 BIT(IEEE80211_STYPE_AUTH >> 4) |
240 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
241 BIT(IEEE80211_STYPE_ACTION >> 4)
245 #define MAX_BSSINFO_LEN 1000
246 static int rtw_cfg80211_inform_bss(struct rtw_adapter *padapter,
247 struct wlan_network *pnetwork)
250 struct ieee80211_channel *notify_channel;
251 struct cfg80211_bss *bss;
252 /* struct ieee80211_supported_band *band; */
255 u64 notify_timestamp;
256 u16 notify_capability;
261 u8 buf[MAX_BSSINFO_LEN], *pbuf;
263 struct ieee80211_hdr *pwlanhdr;
264 struct wireless_dev *wdev = padapter->rtw_wdev;
265 struct wiphy *wiphy = wdev->wiphy;
266 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
268 /* DBG_8723A("%s\n", __func__); */
270 if (pnetwork->network.IELength > MAX_IE_SZ) {
271 DBG_8723A("%s IE Length too long > %d byte\n", __func__,
276 channel = pnetwork->network.DSConfig;
277 if (channel <= RTW_CH_MAX_2G_CHANNEL)
278 freq = ieee80211_channel_to_frequency(channel,
279 IEEE80211_BAND_2GHZ);
281 freq = ieee80211_channel_to_frequency(channel,
282 IEEE80211_BAND_5GHZ);
284 notify_channel = ieee80211_get_channel(wiphy, freq);
286 notify_timestamp = jiffies_to_msecs(jiffies) * 1000; /* uSec */
290 rtw_get_beacon_interval23a_from_ie(pnetwork->network.IEs));
293 rtw_get_capability23a_from_ie(pnetwork->network.IEs));
295 notify_ie = pnetwork->network.IEs + _FIXED_IE_LENGTH_;
296 notify_ielen = pnetwork->network.IELength - _FIXED_IE_LENGTH_;
298 /* We've set wiphy's signal_type as CFG80211_SIGNAL_TYPE_MBM:
299 * signal strength in mBm (100*dBm)
301 if (check_fwstate(pmlmepriv, _FW_LINKED) &&
302 is_same_network23a(&pmlmepriv->cur_network.network,
303 &pnetwork->network)) {
304 notify_signal = 100 * translate_percentage_to_dbm(padapter->recvpriv.signal_strength); /* dbm */
306 notify_signal = 100 * translate_percentage_to_dbm(pnetwork->network.PhyInfo.SignalStrength); /* dbm */
310 pwlanhdr = (struct ieee80211_hdr *)pbuf;
312 pwlanhdr->seq_ctrl = 0;
314 if (pnetwork->network.reserved == 1) { /* WIFI_BEACON */
315 eth_broadcast_addr(pwlanhdr->addr1);
316 pwlanhdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
317 IEEE80211_STYPE_BEACON);
319 ether_addr_copy(pwlanhdr->addr1, myid(&padapter->eeprompriv));
320 pwlanhdr->frame_control =
321 cpu_to_le16(IEEE80211_FTYPE_MGMT |
322 IEEE80211_STYPE_PROBE_RESP);
325 ether_addr_copy(pwlanhdr->addr2, pnetwork->network.MacAddress);
326 ether_addr_copy(pwlanhdr->addr3, pnetwork->network.MacAddress);
328 pbuf += sizeof(struct ieee80211_hdr_3addr);
329 len = sizeof(struct ieee80211_hdr_3addr);
331 memcpy(pbuf, pnetwork->network.IEs, pnetwork->network.IELength);
332 len += pnetwork->network.IELength;
334 bss = cfg80211_inform_bss_frame(wiphy, notify_channel,
335 (struct ieee80211_mgmt *)buf, len,
336 notify_signal, GFP_ATOMIC);
338 if (unlikely(!bss)) {
339 DBG_8723A("rtw_cfg80211_inform_bss error\n");
343 cfg80211_put_bss(wiphy, bss);
349 void rtw_cfg80211_indicate_connect(struct rtw_adapter *padapter)
351 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
352 struct wlan_network *cur_network = &pmlmepriv->cur_network;
353 struct wireless_dev *pwdev = padapter->rtw_wdev;
355 DBG_8723A("%s(padapter =%p)\n", __func__, padapter);
357 if (pwdev->iftype != NL80211_IFTYPE_STATION &&
358 pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
361 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
364 if (padapter->mlmepriv.to_roaming > 0) {
365 struct wiphy *wiphy = pwdev->wiphy;
366 struct ieee80211_channel *notify_channel;
368 u16 channel = cur_network->network.DSConfig;
370 if (channel <= RTW_CH_MAX_2G_CHANNEL)
372 ieee80211_channel_to_frequency(channel,
373 IEEE80211_BAND_2GHZ);
376 ieee80211_channel_to_frequency(channel,
377 IEEE80211_BAND_5GHZ);
379 notify_channel = ieee80211_get_channel(wiphy, freq);
381 DBG_8723A("%s call cfg80211_roamed\n", __func__);
382 cfg80211_roamed(padapter->pnetdev, notify_channel,
383 cur_network->network.MacAddress,
384 pmlmepriv->assoc_req +
385 sizeof(struct ieee80211_hdr_3addr) + 2,
386 pmlmepriv->assoc_req_len -
387 sizeof(struct ieee80211_hdr_3addr) - 2,
388 pmlmepriv->assoc_rsp +
389 sizeof(struct ieee80211_hdr_3addr) + 6,
390 pmlmepriv->assoc_rsp_len -
391 sizeof(struct ieee80211_hdr_3addr) - 6,
394 cfg80211_connect_result(padapter->pnetdev,
395 cur_network->network.MacAddress,
396 pmlmepriv->assoc_req +
397 sizeof(struct ieee80211_hdr_3addr) + 2,
398 pmlmepriv->assoc_req_len -
399 sizeof(struct ieee80211_hdr_3addr) - 2,
400 pmlmepriv->assoc_rsp +
401 sizeof(struct ieee80211_hdr_3addr) + 6,
402 pmlmepriv->assoc_rsp_len -
403 sizeof(struct ieee80211_hdr_3addr) - 6,
404 WLAN_STATUS_SUCCESS, GFP_ATOMIC);
408 void rtw_cfg80211_indicate_disconnect(struct rtw_adapter *padapter)
410 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
411 struct wireless_dev *pwdev = padapter->rtw_wdev;
413 DBG_8723A("%s(padapter =%p)\n", __func__, padapter);
415 if (pwdev->iftype != NL80211_IFTYPE_STATION &&
416 pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
419 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
422 if (!padapter->mlmepriv.not_indic_disco) {
423 if (check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING)) {
424 cfg80211_connect_result(padapter->pnetdev, NULL, NULL,
426 WLAN_STATUS_UNSPECIFIED_FAILURE,
429 cfg80211_disconnected(padapter->pnetdev, 0, NULL,
435 #ifdef CONFIG_8723AU_AP_MODE
436 static int set_pairwise_key(struct rtw_adapter *padapter, struct sta_info *psta)
438 struct cmd_obj *ph2c;
439 struct set_stakey_parm *psetstakey_para;
440 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
443 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
449 psetstakey_para = kzalloc(sizeof(struct set_stakey_parm), GFP_KERNEL);
450 if (psetstakey_para == NULL) {
456 init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
458 psetstakey_para->algorithm = psta->dot118021XPrivacy;
460 ether_addr_copy(psetstakey_para->addr, psta->hwaddr);
462 memcpy(psetstakey_para->key, &psta->dot118021x_UncstKey, 16);
464 res = rtw_enqueue_cmd23a(pcmdpriv, ph2c);
470 static int set_group_key(struct rtw_adapter *padapter, u8 *key, u32 alg,
474 struct cmd_obj *pcmd;
475 struct setkey_parm *psetkeyparm;
476 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
479 DBG_8723A("%s\n", __func__);
486 pcmd = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
491 psetkeyparm = kzalloc(sizeof(struct setkey_parm), GFP_KERNEL);
498 psetkeyparm->keyid = keyid;
500 padapter->mlmepriv.key_mask |= BIT(psetkeyparm->keyid);
502 psetkeyparm->algorithm = alg;
504 psetkeyparm->set_tx = 1;
507 case WLAN_CIPHER_SUITE_WEP40:
510 case WLAN_CIPHER_SUITE_WEP104:
513 case WLAN_CIPHER_SUITE_TKIP:
514 case WLAN_CIPHER_SUITE_CCMP:
519 memcpy(&psetkeyparm->key[0], key, keylen);
521 pcmd->cmdcode = _SetKey_CMD_;
522 pcmd->parmbuf = (u8 *) psetkeyparm;
523 pcmd->cmdsz = (sizeof(struct setkey_parm));
527 res = rtw_enqueue_cmd23a(pcmdpriv, pcmd);
533 static int set_wep_key(struct rtw_adapter *padapter, u8 *key, u16 keylen,
540 alg = WLAN_CIPHER_SUITE_WEP40;
543 alg = WLAN_CIPHER_SUITE_WEP104;
549 return set_group_key(padapter, key, alg, keyid);
552 static int rtw_cfg80211_ap_set_encryption(struct net_device *dev,
553 struct ieee_param *param,
559 struct sta_info *psta = NULL, *pbcmc_sta = NULL;
560 struct rtw_adapter *padapter = netdev_priv(dev);
561 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
562 struct security_priv *psecuritypriv = &padapter->securitypriv;
563 struct sta_priv *pstapriv = &padapter->stapriv;
565 DBG_8723A("%s\n", __func__);
567 param->u.crypt.err = 0;
568 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
570 /* sizeof(struct ieee_param) = 64 bytes; */
571 /* if (param_len != (u32) ((u8 *) param->u.crypt.key -
572 (u8 *) param) + param->u.crypt.key_len) */
573 if (param_len != sizeof(struct ieee_param) + param->u.crypt.key_len) {
578 if (is_broadcast_ether_addr(param->sta_addr)) {
579 if (param->u.crypt.idx >= WEP_KEYS) {
584 psta = rtw_get_stainfo23a(pstapriv, param->sta_addr);
587 DBG_8723A("rtw_set_encryption(), sta has already "
588 "been removed or never been added\n");
593 if (strcmp(param->u.crypt.alg, "none") == 0 && (psta == NULL)) {
594 /* todo:clear default encryption keys */
596 DBG_8723A("clear default encryption keys, keyid =%d\n",
602 if (strcmp(param->u.crypt.alg, "WEP") == 0 && (psta == NULL)) {
603 DBG_8723A("r871x_set_encryption, crypt.alg = WEP\n");
605 wep_key_idx = param->u.crypt.idx;
606 wep_key_len = param->u.crypt.key_len;
608 DBG_8723A("r871x_set_encryption, wep_key_idx =%d, len =%d\n",
609 wep_key_idx, wep_key_len);
611 if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) {
616 if (wep_key_len > 0) {
617 wep_key_len = wep_key_len <= 5 ? 5 : 13;
620 if (psecuritypriv->bWepDefaultKeyIdxSet == 0) {
621 /* wep default key has not been set, so use
622 this key index as default key. */
624 psecuritypriv->ndisencryptstatus =
625 Ndis802_11Encryption1Enabled;
626 psecuritypriv->dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP40;
627 psecuritypriv->dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_WEP40;
629 if (wep_key_len == 13) {
630 psecuritypriv->dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP104;
631 psecuritypriv->dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_WEP104;
634 psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
637 memcpy(&psecuritypriv->wep_key[wep_key_idx].key,
638 param->u.crypt.key, wep_key_len);
640 psecuritypriv->wep_key[wep_key_idx].keylen = wep_key_len;
642 set_wep_key(padapter, param->u.crypt.key, wep_key_len,
649 if (!psta && check_fwstate(pmlmepriv, WIFI_AP_STATE)) { /* group key */
650 if (param->u.crypt.set_tx == 0) { /* group key */
651 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
652 DBG_8723A("%s, set group_key, WEP\n", __func__);
654 memcpy(psecuritypriv->
655 dot118021XGrpKey[param->u.crypt.idx].
656 skey, param->u.crypt.key,
657 (param->u.crypt.key_len >
658 16 ? 16 : param->u.crypt.key_len));
660 psecuritypriv->dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_WEP40;
661 if (param->u.crypt.key_len == 13) {
662 psecuritypriv->dot118021XGrpPrivacy =
663 WLAN_CIPHER_SUITE_WEP104;
666 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
667 DBG_8723A("%s, set group_key, TKIP\n",
670 psecuritypriv->dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_TKIP;
672 memcpy(psecuritypriv->
673 dot118021XGrpKey[param->u.crypt.idx].
674 skey, param->u.crypt.key,
675 (param->u.crypt.key_len >
676 16 ? 16 : param->u.crypt.key_len));
678 /* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */
680 memcpy(psecuritypriv->
681 dot118021XGrptxmickey[param->u.crypt.
683 ¶m->u.crypt.key[16], 8);
684 memcpy(psecuritypriv->
685 dot118021XGrprxmickey[param->u.crypt.
687 ¶m->u.crypt.key[24], 8);
689 psecuritypriv->busetkipkey = 1;
691 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
692 DBG_8723A("%s, set group_key, CCMP\n",
695 psecuritypriv->dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_CCMP;
697 memcpy(psecuritypriv->
698 dot118021XGrpKey[param->u.crypt.idx].
699 skey, param->u.crypt.key,
700 (param->u.crypt.key_len >
701 16 ? 16 : param->u.crypt.key_len));
703 DBG_8723A("%s, set group_key, none\n",
706 psecuritypriv->dot118021XGrpPrivacy =
710 psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx;
712 psecuritypriv->binstallGrpkey = 1;
714 psecuritypriv->dot11PrivacyAlgrthm =
715 psecuritypriv->dot118021XGrpPrivacy;
717 set_group_key(padapter, param->u.crypt.key,
718 psecuritypriv->dot118021XGrpPrivacy,
721 pbcmc_sta = rtw_get_bcmc_stainfo23a(padapter);
723 pbcmc_sta->ieee8021x_blocked = false;
724 /* rx will use bmc_sta's dot118021XPrivacy */
725 pbcmc_sta->dot118021XPrivacy =
726 psecuritypriv->dot118021XGrpPrivacy;
735 if (psecuritypriv->dot11AuthAlgrthm ==
736 dot11AuthAlgrthm_8021X && psta) { /* psk/802_1x */
737 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
738 if (param->u.crypt.set_tx == 1) {
740 memcpy(psta->dot118021x_UncstKey.skey,
742 (param->u.crypt.key_len >
743 16 ? 16 : param->u.crypt.key_len));
745 if (!strcmp(param->u.crypt.alg, "WEP")) {
746 DBG_8723A("%s, set pairwise key, WEP\n",
749 psta->dot118021XPrivacy = WLAN_CIPHER_SUITE_WEP40;
750 if (param->u.crypt.key_len == 13) {
751 psta->dot118021XPrivacy =
752 WLAN_CIPHER_SUITE_WEP104;
754 } else if (!strcmp(param->u.crypt.alg, "TKIP")) {
755 DBG_8723A("%s, set pairwise key, "
758 psta->dot118021XPrivacy = WLAN_CIPHER_SUITE_TKIP;
760 /* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */
762 memcpy(psta->dot11tkiptxmickey.skey,
763 ¶m->u.crypt.key[16], 8);
764 memcpy(psta->dot11tkiprxmickey.skey,
765 ¶m->u.crypt.key[24], 8);
767 psecuritypriv->busetkipkey = 1;
769 } else if (!strcmp(param->u.crypt.alg, "CCMP")) {
771 DBG_8723A("%s, set pairwise key, "
774 psta->dot118021XPrivacy = WLAN_CIPHER_SUITE_CCMP;
776 DBG_8723A("%s, set pairwise key, "
779 psta->dot118021XPrivacy = 0;
782 set_pairwise_key(padapter, psta);
784 psta->ieee8021x_blocked = false;
786 psta->bpairwise_key_installed = true;
787 } else { /* group key??? */
788 if (!strcmp(param->u.crypt.alg, "WEP")) {
789 memcpy(psecuritypriv->
790 dot118021XGrpKey[param->u.crypt.
793 (param->u.crypt.key_len >
794 16 ? 16 : param->u.crypt.
797 psecuritypriv->dot118021XGrpPrivacy =
798 WLAN_CIPHER_SUITE_WEP40;
799 if (param->u.crypt.key_len == 13) {
801 dot118021XGrpPrivacy =
802 WLAN_CIPHER_SUITE_WEP104;
804 } else if (!strcmp(param->u.crypt.alg, "TKIP")) {
805 psecuritypriv->dot118021XGrpPrivacy =
806 WLAN_CIPHER_SUITE_TKIP;
808 memcpy(psecuritypriv->
809 dot118021XGrpKey[param->u.crypt.
812 (param->u.crypt.key_len >
813 16 ? 16 : param->u.crypt.
816 /* DEBUG_ERR("set key length :param->u"
817 ".crypt.key_len =%d\n",
818 param->u.crypt.key_len); */
820 memcpy(psecuritypriv->
821 dot118021XGrptxmickey[param->u.
823 skey, ¶m->u.crypt.key[16],
825 memcpy(psecuritypriv->
826 dot118021XGrprxmickey[param->u.
828 skey, ¶m->u.crypt.key[24],
831 psecuritypriv->busetkipkey = 1;
833 } else if (!strcmp(param->u.crypt.alg, "CCMP")) {
834 psecuritypriv->dot118021XGrpPrivacy =
835 WLAN_CIPHER_SUITE_CCMP;
837 memcpy(psecuritypriv->
838 dot118021XGrpKey[param->u.crypt.
841 (param->u.crypt.key_len >
842 16 ? 16 : param->u.crypt.
845 psecuritypriv->dot118021XGrpPrivacy =
849 psecuritypriv->dot118021XGrpKeyid =
852 psecuritypriv->binstallGrpkey = 1;
854 psecuritypriv->dot11PrivacyAlgrthm =
855 psecuritypriv->dot118021XGrpPrivacy;
857 set_group_key(padapter, param->u.crypt.key,
859 dot118021XGrpPrivacy,
862 pbcmc_sta = rtw_get_bcmc_stainfo23a(padapter);
864 /* rx will use bmc_sta's
866 pbcmc_sta->ieee8021x_blocked = false;
867 pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy;
880 static int rtw_cfg80211_set_encryption(struct net_device *dev,
881 struct ieee_param *param, u32 param_len)
886 struct rtw_adapter *padapter = netdev_priv(dev);
887 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
888 struct security_priv *psecuritypriv = &padapter->securitypriv;
890 DBG_8723A("%s\n", __func__);
892 param->u.crypt.err = 0;
893 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
896 (u32) ((u8 *) param->u.crypt.key - (u8 *) param) +
897 param->u.crypt.key_len) {
902 if (is_broadcast_ether_addr(param->sta_addr)) {
903 if (param->u.crypt.idx >= WEP_KEYS) {
912 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
913 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_,
914 ("wpa_set_encryption, crypt.alg = WEP\n"));
915 DBG_8723A("wpa_set_encryption, crypt.alg = WEP\n");
917 wep_key_idx = param->u.crypt.idx;
918 wep_key_len = param->u.crypt.key_len;
920 if ((wep_key_idx > WEP_KEYS) || (wep_key_len <= 0)) {
925 if (psecuritypriv->bWepDefaultKeyIdxSet == 0) {
926 /* wep default key has not been set, so use this
927 key index as default key. */
929 wep_key_len = wep_key_len <= 5 ? 5 : 13;
931 psecuritypriv->ndisencryptstatus =
932 Ndis802_11Encryption1Enabled;
933 psecuritypriv->dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP40;
934 psecuritypriv->dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_WEP40;
936 if (wep_key_len == 13) {
937 psecuritypriv->dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP104;
938 psecuritypriv->dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_WEP104;
941 psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
944 memcpy(&psecuritypriv->wep_key[wep_key_idx].key,
945 param->u.crypt.key, wep_key_len);
947 psecuritypriv->wep_key[wep_key_idx].keylen = wep_key_len;
949 rtw_set_key23a(padapter, psecuritypriv, wep_key_idx, 0);
954 if (padapter->securitypriv.dot11AuthAlgrthm ==
955 dot11AuthAlgrthm_8021X) { /* 802_1x */
956 struct sta_info *psta, *pbcmc_sta;
957 struct sta_priv *pstapriv = &padapter->stapriv;
959 if (check_fwstate(pmlmepriv,
960 WIFI_STATION_STATE | WIFI_MP_STATE)) {
962 psta = rtw_get_stainfo23a(pstapriv, get_bssid(pmlmepriv));
964 DBG_8723A("%s, : Obtain Sta_info fail\n",
967 /* Jeff: don't disable ieee8021x_blocked
968 while clearing key */
969 if (strcmp(param->u.crypt.alg, "none") != 0)
970 psta->ieee8021x_blocked = false;
972 if ((padapter->securitypriv.ndisencryptstatus ==
973 Ndis802_11Encryption2Enabled) ||
974 (padapter->securitypriv.ndisencryptstatus ==
975 Ndis802_11Encryption3Enabled)) {
976 psta->dot118021XPrivacy =
977 padapter->securitypriv.
981 if (param->u.crypt.set_tx == 1) {
983 DBG_8723A("%s, : param->u.crypt.set_tx"
984 " == 1\n", __func__);
986 memcpy(psta->dot118021x_UncstKey.skey,
988 (param->u.crypt.key_len >
989 16 ? 16 : param->u.crypt.
992 if (strcmp(param->u.crypt.alg,
994 memcpy(psta->dot11tkiptxmickey.
996 ¶m->u.crypt.key[16],
998 memcpy(psta->dot11tkiprxmickey.
1000 ¶m->u.crypt.key[24],
1003 padapter->securitypriv.
1006 DBG_8723A(" ~~~~set sta key:unicastkey\n");
1008 rtw_setstakey_cmd23a(padapter,
1009 (unsigned char *)psta,
1011 } else { /* group key */
1012 memcpy(padapter->securitypriv.
1013 dot118021XGrpKey[param->u.crypt.
1016 (param->u.crypt.key_len >
1017 16 ? 16 : param->u.crypt.
1019 memcpy(padapter->securitypriv.
1020 dot118021XGrptxmickey[param->u.
1022 skey, ¶m->u.crypt.key[16],
1024 memcpy(padapter->securitypriv.
1025 dot118021XGrprxmickey[param->u.
1027 skey, ¶m->u.crypt.key[24],
1029 padapter->securitypriv.binstallGrpkey =
1031 /* DEBUG_ERR((" param->u.crypt.key_len"
1032 "=%d\n", param->u.crypt.key_len)); */
1034 (" ~~~~set sta key:groupkey\n");
1036 padapter->securitypriv.
1037 dot118021XGrpKeyid =
1040 rtw_set_key23a(padapter,
1041 &padapter->securitypriv,
1042 param->u.crypt.idx, 1);
1046 pbcmc_sta = rtw_get_bcmc_stainfo23a(padapter);
1048 /* Jeff: don't disable ieee8021x_blocked
1049 while clearing key */
1050 if (strcmp(param->u.crypt.alg, "none") != 0)
1051 pbcmc_sta->ieee8021x_blocked = false;
1053 if ((padapter->securitypriv.ndisencryptstatus ==
1054 Ndis802_11Encryption2Enabled) ||
1055 (padapter->securitypriv.ndisencryptstatus ==
1056 Ndis802_11Encryption3Enabled)) {
1057 pbcmc_sta->dot118021XPrivacy =
1058 padapter->securitypriv.
1059 dot11PrivacyAlgrthm;
1062 } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { /* adhoc mode */
1068 DBG_8723A("%s, ret =%d\n", __func__, ret);
1075 static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev,
1076 u8 key_index, bool pairwise,
1077 const u8 *mac_addr, struct key_params *params)
1081 struct ieee_param *param;
1083 struct wireless_dev *rtw_wdev = wiphy_to_wdev(wiphy);
1084 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
1085 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1087 DBG_8723A("%s(%s): adding key for %pM\n", __func__, ndev->name,
1089 DBG_8723A("cipher = 0x%x\n", params->cipher);
1090 DBG_8723A("key_len = 0x%x\n", params->key_len);
1091 DBG_8723A("seq_len = 0x%x\n", params->seq_len);
1092 DBG_8723A("key_index =%d\n", key_index);
1093 DBG_8723A("pairwise =%d\n", pairwise);
1095 param_len = sizeof(struct ieee_param) + params->key_len;
1096 param = kzalloc(param_len, GFP_KERNEL);
1100 param->cmd = IEEE_CMD_SET_ENCRYPTION;
1101 eth_broadcast_addr(param->sta_addr);
1103 switch (params->cipher) {
1104 case IW_AUTH_CIPHER_NONE:
1105 /* todo: remove key */
1109 case WLAN_CIPHER_SUITE_WEP40:
1110 case WLAN_CIPHER_SUITE_WEP104:
1113 case WLAN_CIPHER_SUITE_TKIP:
1116 case WLAN_CIPHER_SUITE_CCMP:
1125 strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
1127 if (!mac_addr || is_broadcast_ether_addr(mac_addr)) {
1128 param->u.crypt.set_tx = 0; /* for wpa/wpa2 group key */
1130 param->u.crypt.set_tx = 1; /* for wpa/wpa2 pairwise key */
1133 /* param->u.crypt.idx = key_index - 1; */
1134 param->u.crypt.idx = key_index;
1136 if (params->seq_len && params->seq) {
1137 memcpy(param->u.crypt.seq, params->seq, params->seq_len);
1140 if (params->key_len && params->key) {
1141 param->u.crypt.key_len = params->key_len;
1142 memcpy(param->u.crypt.key, params->key, params->key_len);
1145 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
1146 ret = rtw_cfg80211_set_encryption(ndev, param, param_len);
1147 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1148 #ifdef CONFIG_8723AU_AP_MODE
1150 ether_addr_copy(param->sta_addr, mac_addr);
1152 ret = rtw_cfg80211_ap_set_encryption(ndev, param, param_len);
1155 DBG_8723A("error! fw_state = 0x%x, iftype =%d\n",
1156 pmlmepriv->fw_state, rtw_wdev->iftype);
1167 cfg80211_rtw_get_key(struct wiphy *wiphy, struct net_device *ndev,
1168 u8 key_index, bool pairwise, const u8 *mac_addr,
1170 void (*callback) (void *cookie, struct key_params *))
1172 DBG_8723A("%s(%s)\n", __func__, ndev->name);
1176 static int cfg80211_rtw_del_key(struct wiphy *wiphy, struct net_device *ndev,
1177 u8 key_index, bool pairwise,
1180 struct rtw_adapter *padapter = netdev_priv(ndev);
1181 struct security_priv *psecuritypriv = &padapter->securitypriv;
1183 DBG_8723A("%s(%s): key_index =%d\n", __func__, ndev->name, key_index);
1185 if (key_index == psecuritypriv->dot11PrivacyKeyIndex) {
1186 /* clear the flag of wep default key set. */
1187 psecuritypriv->bWepDefaultKeyIdxSet = 0;
1193 static int cfg80211_rtw_set_default_key(struct wiphy *wiphy,
1194 struct net_device *ndev, u8 key_index,
1195 bool unicast, bool multicast)
1197 struct rtw_adapter *padapter = netdev_priv(ndev);
1198 struct security_priv *psecuritypriv = &padapter->securitypriv;
1200 DBG_8723A("%s(%s): key_index =%d, unicast =%d, multicast =%d.\n",
1201 __func__, ndev->name, key_index, unicast, multicast);
1203 if (key_index < NUM_WEP_KEYS &&
1204 (psecuritypriv->dot11PrivacyAlgrthm == WLAN_CIPHER_SUITE_WEP40 ||
1205 psecuritypriv->dot11PrivacyAlgrthm == WLAN_CIPHER_SUITE_WEP104)) {
1206 /* set wep default key */
1207 psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
1209 psecuritypriv->dot11PrivacyKeyIndex = key_index;
1211 psecuritypriv->dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP40;
1212 psecuritypriv->dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_WEP40;
1213 if (psecuritypriv->wep_key[key_index].keylen == 13) {
1214 psecuritypriv->dot11PrivacyAlgrthm =
1215 WLAN_CIPHER_SUITE_WEP104;
1216 psecuritypriv->dot118021XGrpPrivacy =
1217 WLAN_CIPHER_SUITE_WEP104;
1220 /* set the flag to represent that wep default key
1222 psecuritypriv->bWepDefaultKeyIdxSet = 1;
1228 static int cfg80211_rtw_get_station(struct wiphy *wiphy,
1229 struct net_device *ndev,
1230 const u8 *mac, struct station_info *sinfo)
1233 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
1234 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1235 struct sta_info *psta = NULL;
1236 struct sta_priv *pstapriv = &padapter->stapriv;
1241 DBG_8723A("%s(%s): mac ==%p\n", __func__, ndev->name, mac);
1246 psta = rtw_get_stainfo23a(pstapriv, mac);
1248 DBG_8723A("%s, sta_info is null\n", __func__);
1252 DBG_8723A("%s(%s): mac =" MAC_FMT "\n", __func__, ndev->name,
1255 /* for infra./P2PClient mode */
1256 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) &&
1257 check_fwstate(pmlmepriv, _FW_LINKED)) {
1258 struct wlan_network *cur_network = &pmlmepriv->cur_network;
1260 if (!ether_addr_equal(mac, cur_network->network.MacAddress)) {
1261 DBG_8723A("%s, mismatch bssid =" MAC_FMT "\n", __func__,
1262 MAC_ARG(cur_network->network.MacAddress));
1267 sinfo->filled |= STATION_INFO_SIGNAL;
1268 sinfo->signal = translate_percentage_to_dbm(padapter->recvpriv.
1271 sinfo->filled |= STATION_INFO_TX_BITRATE;
1272 sinfo->txrate.legacy = rtw_get_cur_max_rate23a(padapter);
1274 sinfo->filled |= STATION_INFO_RX_PACKETS;
1275 sinfo->rx_packets = sta_rx_data_pkts(psta);
1277 sinfo->filled |= STATION_INFO_TX_PACKETS;
1278 sinfo->tx_packets = psta->sta_stats.tx_pkts;
1281 /* for Ad-Hoc/AP mode */
1282 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
1283 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ||
1284 check_fwstate(pmlmepriv, WIFI_AP_STATE)) &&
1285 check_fwstate(pmlmepriv, _FW_LINKED)
1287 /* TODO: should acquire station info... */
1294 int cfg80211_infrastructure_mode(struct rtw_adapter* padapter,
1295 enum nl80211_iftype ifmode)
1297 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1298 struct wlan_network *cur_network = &pmlmepriv->cur_network;
1299 enum nl80211_iftype old_mode;
1301 old_mode = cur_network->network.ifmode;
1303 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_notice_,
1304 ("+%s: old =%d new =%d fw_state = 0x%08x\n", __func__,
1305 old_mode, ifmode, get_fwstate(pmlmepriv)));
1307 if (old_mode != ifmode) {
1308 spin_lock_bh(&pmlmepriv->lock);
1310 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1313 if (old_mode == NL80211_IFTYPE_AP ||
1314 old_mode == NL80211_IFTYPE_P2P_GO) {
1315 /* change to other mode from Ndis802_11APMode */
1316 cur_network->join_res = -1;
1318 #ifdef CONFIG_8723AU_AP_MODE
1319 stop_ap_mode23a(padapter);
1323 if (check_fwstate(pmlmepriv, _FW_LINKED) ||
1324 old_mode == NL80211_IFTYPE_ADHOC)
1325 rtw_disassoc_cmd23a(padapter, 0, true);
1327 if (check_fwstate(pmlmepriv, _FW_LINKED) ||
1328 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))
1329 rtw_free_assoc_resources23a(padapter, 1);
1331 if (old_mode == NL80211_IFTYPE_STATION ||
1332 old_mode == NL80211_IFTYPE_P2P_CLIENT ||
1333 old_mode == NL80211_IFTYPE_ADHOC) {
1334 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
1335 /* will clr Linked_state; before this function,
1336 we must have chked whether issue
1337 dis-assoc_cmd or not */
1338 rtw_indicate_disconnect23a(padapter);
1342 cur_network->network.ifmode = ifmode;
1344 _clr_fwstate_(pmlmepriv, ~WIFI_NULL_STATE);
1347 case NL80211_IFTYPE_ADHOC:
1348 set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
1351 case NL80211_IFTYPE_P2P_CLIENT:
1352 case NL80211_IFTYPE_STATION:
1353 set_fwstate(pmlmepriv, WIFI_STATION_STATE);
1356 case NL80211_IFTYPE_P2P_GO:
1357 case NL80211_IFTYPE_AP:
1358 set_fwstate(pmlmepriv, WIFI_AP_STATE);
1359 #ifdef CONFIG_8723AU_AP_MODE
1360 start_ap_mode23a(padapter);
1361 /* rtw_indicate_connect23a(padapter); */
1369 /* SecClearAllKeys(adapter); */
1371 /* RT_TRACE(COMP_OID_SET, DBG_LOUD,
1372 ("set_infrastructure: fw_state:%x after changing mode\n", */
1373 /* get_fwstate(pmlmepriv))); */
1375 spin_unlock_bh(&pmlmepriv->lock);
1381 static int cfg80211_rtw_change_iface(struct wiphy *wiphy,
1382 struct net_device *ndev,
1383 enum nl80211_iftype type, u32 *flags,
1384 struct vif_params *params)
1386 enum nl80211_iftype old_type;
1387 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
1388 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1389 struct wireless_dev *rtw_wdev = wiphy_to_wdev(wiphy);
1392 DBG_8723A("%s(%s): call netdev_open23a\n", __func__, ndev->name);
1394 old_type = rtw_wdev->iftype;
1395 DBG_8723A("%s(%s): old_iftype =%d, new_iftype =%d\n",
1396 __func__, ndev->name, old_type, type);
1398 if (old_type != type) {
1399 pmlmeext->action_public_rxseq = 0xffff;
1400 pmlmeext->action_public_dialog_token = 0xff;
1404 case NL80211_IFTYPE_ADHOC:
1405 case NL80211_IFTYPE_P2P_CLIENT:
1406 case NL80211_IFTYPE_STATION:
1407 case NL80211_IFTYPE_P2P_GO:
1408 case NL80211_IFTYPE_AP:
1409 case NL80211_IFTYPE_UNSPECIFIED:
1415 rtw_wdev->iftype = type;
1417 if (cfg80211_infrastructure_mode(padapter, type) != _SUCCESS) {
1418 rtw_wdev->iftype = old_type;
1423 rtw_setopmode_cmd23a(padapter, type);
1429 void rtw_cfg80211_indicate_scan_done(struct rtw_wdev_priv *pwdev_priv,
1432 spin_lock_bh(&pwdev_priv->scan_req_lock);
1433 if (pwdev_priv->scan_request != NULL) {
1434 DBG_8723A("%s with scan req\n", __func__);
1436 if (pwdev_priv->scan_request->wiphy !=
1437 pwdev_priv->rtw_wdev->wiphy)
1438 DBG_8723A("error wiphy compare\n");
1440 cfg80211_scan_done(pwdev_priv->scan_request, aborted);
1442 pwdev_priv->scan_request = NULL;
1444 DBG_8723A("%s without scan req\n", __func__);
1446 spin_unlock_bh(&pwdev_priv->scan_req_lock);
1449 void rtw_cfg80211_surveydone_event_callback(struct rtw_adapter *padapter)
1451 struct list_head *plist, *phead, *ptmp;
1452 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1453 struct rtw_queue *queue = &pmlmepriv->scanned_queue;
1454 struct wlan_network *pnetwork;
1456 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
1458 phead = get_list_head(queue);
1460 list_for_each_safe(plist, ptmp, phead) {
1461 pnetwork = container_of(plist, struct wlan_network, list);
1463 /* report network only if the current channel set
1464 contains the channel to which this network belongs */
1465 if (rtw_ch_set_search_ch23a
1466 (padapter->mlmeextpriv.channel_set,
1467 pnetwork->network.DSConfig) >= 0)
1468 rtw_cfg80211_inform_bss(padapter, pnetwork);
1471 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
1473 /* call this after other things have been done */
1474 rtw_cfg80211_indicate_scan_done(wdev_to_priv(padapter->rtw_wdev),
1478 static int rtw_cfg80211_set_probe_req_wpsp2pie(struct rtw_adapter *padapter,
1484 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1486 DBG_8723A("%s, ielen =%d\n", __func__, len);
1489 wps_ie = rtw_get_wps_ie23a(buf, len, NULL, &wps_ielen);
1491 DBG_8723A("probe_req_wps_ielen =%d\n", wps_ielen);
1493 if (pmlmepriv->wps_probe_req_ie) {
1494 pmlmepriv->wps_probe_req_ie_len = 0;
1495 kfree(pmlmepriv->wps_probe_req_ie);
1496 pmlmepriv->wps_probe_req_ie = NULL;
1499 pmlmepriv->wps_probe_req_ie = kmemdup(wps_ie,
1502 if (pmlmepriv->wps_probe_req_ie == NULL) {
1503 DBG_8723A("%s()-%d: kmalloc() ERROR!\n",
1504 __func__, __LINE__);
1507 pmlmepriv->wps_probe_req_ie_len = wps_ielen;
1514 static int cfg80211_rtw_scan(struct wiphy *wiphy,
1515 struct cfg80211_scan_request *request)
1520 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
1521 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1522 struct cfg80211_ssid ssid[RTW_SSID_SCAN_AMOUNT];
1523 struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT];
1524 struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
1525 struct cfg80211_ssid *ssids = request->ssids;
1526 bool need_indicate_scan_done = false;
1528 DBG_8723A("%s(%s)\n", __func__, padapter->pnetdev->name);
1530 spin_lock_bh(&pwdev_priv->scan_req_lock);
1531 pwdev_priv->scan_request = request;
1532 spin_unlock_bh(&pwdev_priv->scan_req_lock);
1534 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1535 DBG_8723A("%s under WIFI_AP_STATE\n", __func__);
1536 /* need_indicate_scan_done = true; */
1537 /* goto check_need_indicate_scan_done; */
1540 if (rtw_pwr_wakeup(padapter) == _FAIL) {
1541 need_indicate_scan_done = true;
1542 goto check_need_indicate_scan_done;
1545 if (request->ie && request->ie_len > 0) {
1546 rtw_cfg80211_set_probe_req_wpsp2pie(padapter,
1551 if (pmlmepriv->LinkDetectInfo.bBusyTraffic == true) {
1552 DBG_8723A("%s, bBusyTraffic == true\n", __func__);
1553 need_indicate_scan_done = true;
1554 goto check_need_indicate_scan_done;
1556 if (rtw_is_scan_deny(padapter)) {
1557 DBG_8723A("%s(%s): scan deny\n", __func__,
1558 padapter->pnetdev->name);
1559 need_indicate_scan_done = true;
1560 goto check_need_indicate_scan_done;
1563 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING) ==
1565 DBG_8723A("%s, fwstate = 0x%x\n", __func__, pmlmepriv->fw_state);
1566 need_indicate_scan_done = true;
1567 goto check_need_indicate_scan_done;
1570 memset(ssid, 0, sizeof(struct cfg80211_ssid) * RTW_SSID_SCAN_AMOUNT);
1571 /* parsing request ssids, n_ssids */
1572 for (i = 0; i < request->n_ssids && i < RTW_SSID_SCAN_AMOUNT; i++) {
1573 DBG_8723A("ssid =%s, len =%d\n", ssids[i].ssid,
1575 memcpy(ssid[i].ssid, ssids[i].ssid, ssids[i].ssid_len);
1576 ssid[i].ssid_len = ssids[i].ssid_len;
1579 /* parsing channels, n_channels */
1581 sizeof(struct rtw_ieee80211_channel) * RTW_CHANNEL_SCAN_AMOUNT);
1583 if (request->n_channels == 1) {
1584 for (i = 0; i < request->n_channels &&
1585 i < RTW_CHANNEL_SCAN_AMOUNT; i++) {
1586 DBG_8723A("%s:(%s):" CHAN_FMT "\n",
1587 __func__, padapter->pnetdev->name,
1588 CHAN_ARG(request->channels[i]));
1589 ch[i].hw_value = request->channels[i]->hw_value;
1590 ch[i].flags = request->channels[i]->flags;
1594 spin_lock_bh(&pmlmepriv->lock);
1595 if (request->n_channels == 1) {
1596 memcpy(&ch[1], &ch[0], sizeof(struct rtw_ieee80211_channel));
1597 memcpy(&ch[2], &ch[0], sizeof(struct rtw_ieee80211_channel));
1598 _status = rtw_sitesurvey_cmd23a(padapter, ssid,
1599 RTW_SSID_SCAN_AMOUNT, ch, 3);
1601 _status = rtw_sitesurvey_cmd23a(padapter, ssid,
1602 RTW_SSID_SCAN_AMOUNT, NULL, 0);
1604 spin_unlock_bh(&pmlmepriv->lock);
1606 if (_status == false)
1609 check_need_indicate_scan_done:
1610 if (need_indicate_scan_done)
1611 rtw_cfg80211_surveydone_event_callback(padapter);
1615 static int cfg80211_rtw_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1617 DBG_8723A("%s\n", __func__);
1621 static int cfg80211_rtw_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
1622 struct cfg80211_ibss_params *params)
1624 DBG_8723A("%s(%s)\n", __func__, ndev->name);
1628 static int cfg80211_rtw_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
1630 DBG_8723A("%s(%s)\n", __func__, ndev->name);
1634 static int rtw_cfg80211_set_wpa_version(struct security_priv *psecuritypriv,
1637 DBG_8723A("%s, wpa_version =%d\n", __func__, wpa_version);
1640 psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
1644 if (wpa_version & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2)) {
1645 psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPAPSK;
1649 if (wpa_version & NL80211_WPA_VERSION_2)
1651 psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK;
1658 static int rtw_cfg80211_set_auth_type(struct security_priv *psecuritypriv,
1659 enum nl80211_auth_type sme_auth_type)
1661 DBG_8723A("%s, nl80211_auth_type =%d\n", __func__, sme_auth_type);
1663 switch (sme_auth_type) {
1664 case NL80211_AUTHTYPE_AUTOMATIC:
1665 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
1668 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1669 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
1671 if (psecuritypriv->ndisauthtype > Ndis802_11AuthModeWPA)
1672 psecuritypriv->dot11AuthAlgrthm =
1673 dot11AuthAlgrthm_8021X;
1675 case NL80211_AUTHTYPE_SHARED_KEY:
1676 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
1678 psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
1681 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
1682 /* return -ENOTSUPP; */
1688 static int rtw_cfg80211_set_cipher(struct security_priv *psecuritypriv,
1689 u32 cipher, bool ucast)
1691 u32 ndisencryptstatus = Ndis802_11EncryptionDisabled;
1693 u32 *profile_cipher = ucast ? &psecuritypriv->dot11PrivacyAlgrthm :
1694 &psecuritypriv->dot118021XGrpPrivacy;
1696 DBG_8723A("%s, ucast =%d, cipher = 0x%x\n", __func__, ucast, cipher);
1699 *profile_cipher = 0;
1700 psecuritypriv->ndisencryptstatus = ndisencryptstatus;
1705 case IW_AUTH_CIPHER_NONE:
1706 *profile_cipher = 0;
1707 ndisencryptstatus = Ndis802_11EncryptionDisabled;
1709 case WLAN_CIPHER_SUITE_WEP40:
1710 *profile_cipher = WLAN_CIPHER_SUITE_WEP40;
1711 ndisencryptstatus = Ndis802_11Encryption1Enabled;
1713 case WLAN_CIPHER_SUITE_WEP104:
1714 *profile_cipher = WLAN_CIPHER_SUITE_WEP104;
1715 ndisencryptstatus = Ndis802_11Encryption1Enabled;
1717 case WLAN_CIPHER_SUITE_TKIP:
1718 *profile_cipher = WLAN_CIPHER_SUITE_TKIP;
1719 ndisencryptstatus = Ndis802_11Encryption2Enabled;
1721 case WLAN_CIPHER_SUITE_CCMP:
1722 *profile_cipher = WLAN_CIPHER_SUITE_CCMP;
1723 ndisencryptstatus = Ndis802_11Encryption3Enabled;
1726 DBG_8723A("Unsupported cipher: 0x%x\n", cipher);
1731 psecuritypriv->ndisencryptstatus = ndisencryptstatus;
1736 static int rtw_cfg80211_set_key_mgt(struct security_priv *psecuritypriv,
1739 DBG_8723A("%s, key_mgt = 0x%x\n", __func__, key_mgt);
1741 if (key_mgt == WLAN_AKM_SUITE_8021X)
1742 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1743 else if (key_mgt == WLAN_AKM_SUITE_PSK)
1744 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1746 DBG_8723A("Invalid key mgt: 0x%x\n", key_mgt);
1751 static int rtw_cfg80211_set_wpa_ie(struct rtw_adapter *padapter, const u8 *pie,
1755 int group_cipher = 0, pairwise_cipher = 0;
1757 const u8 *pwpa, *pwpa2;
1760 if (!pie || !ielen) {
1761 /* Treat this as normal case, but need to clear
1763 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
1766 if (ielen > MAX_WPA_IE_LEN + MAX_WPS_IE_LEN + MAX_P2P_IE_LEN) {
1770 buf = kmemdup(pie, ielen, GFP_KERNEL);
1777 DBG_8723A("set wpa_ie(length:%zu):\n", ielen);
1778 for (i = 0; i < ielen; i = i + 8)
1779 DBG_8723A("0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n",
1781 buf[i + 2], buf[i + 3], buf[i + 4],
1782 buf[i + 5], buf[i + 6], buf[i + 7]);
1783 if (ielen < RSN_HEADER_LEN) {
1784 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_,
1785 ("Ie len too short %d\n", (int)ielen));
1790 pwpa = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1791 WLAN_OUI_TYPE_MICROSOFT_WPA,
1793 if (pwpa && pwpa[1] > 0) {
1794 if (rtw_parse_wpa_ie23a(pwpa, pwpa[1] + 2, &group_cipher,
1795 &pairwise_cipher, NULL) == _SUCCESS) {
1796 padapter->securitypriv.dot11AuthAlgrthm =
1797 dot11AuthAlgrthm_8021X;
1798 padapter->securitypriv.ndisauthtype =
1799 Ndis802_11AuthModeWPAPSK;
1800 memcpy(padapter->securitypriv.supplicant_ie, pwpa,
1803 DBG_8723A("got wpa_ie, wpa_ielen:%u\n", pwpa[1]);
1807 pwpa2 = cfg80211_find_ie(WLAN_EID_RSN, buf, ielen);
1808 if (pwpa2 && pwpa2[1] > 0) {
1809 if (rtw_parse_wpa2_ie23a (pwpa2, pwpa2[1] + 2, &group_cipher,
1810 &pairwise_cipher, NULL) == _SUCCESS) {
1811 padapter->securitypriv.dot11AuthAlgrthm =
1812 dot11AuthAlgrthm_8021X;
1813 padapter->securitypriv.ndisauthtype =
1814 Ndis802_11AuthModeWPA2PSK;
1815 memcpy(padapter->securitypriv.supplicant_ie, pwpa2,
1818 DBG_8723A("got wpa2_ie, wpa2_ielen:%u\n", pwpa2[1]);
1822 if (group_cipher == 0) {
1823 group_cipher = WPA_CIPHER_NONE;
1825 if (pairwise_cipher == 0) {
1826 pairwise_cipher = WPA_CIPHER_NONE;
1829 switch (group_cipher) {
1830 case WPA_CIPHER_NONE:
1831 padapter->securitypriv.dot118021XGrpPrivacy = 0;
1832 padapter->securitypriv.ndisencryptstatus =
1833 Ndis802_11EncryptionDisabled;
1835 case WPA_CIPHER_WEP40:
1836 padapter->securitypriv.dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_WEP40;
1837 padapter->securitypriv.ndisencryptstatus =
1838 Ndis802_11Encryption1Enabled;
1840 case WPA_CIPHER_TKIP:
1841 padapter->securitypriv.dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_TKIP;
1842 padapter->securitypriv.ndisencryptstatus =
1843 Ndis802_11Encryption2Enabled;
1845 case WPA_CIPHER_CCMP:
1846 padapter->securitypriv.dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_CCMP;
1847 padapter->securitypriv.ndisencryptstatus =
1848 Ndis802_11Encryption3Enabled;
1850 case WPA_CIPHER_WEP104:
1851 padapter->securitypriv.dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_WEP104;
1852 padapter->securitypriv.ndisencryptstatus =
1853 Ndis802_11Encryption1Enabled;
1857 switch (pairwise_cipher) {
1858 case WPA_CIPHER_NONE:
1859 padapter->securitypriv.dot11PrivacyAlgrthm = 0;
1860 padapter->securitypriv.ndisencryptstatus =
1861 Ndis802_11EncryptionDisabled;
1863 case WPA_CIPHER_WEP40:
1864 padapter->securitypriv.dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP40;
1865 padapter->securitypriv.ndisencryptstatus =
1866 Ndis802_11Encryption1Enabled;
1868 case WPA_CIPHER_TKIP:
1869 padapter->securitypriv.dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_TKIP;
1870 padapter->securitypriv.ndisencryptstatus =
1871 Ndis802_11Encryption2Enabled;
1873 case WPA_CIPHER_CCMP:
1874 padapter->securitypriv.dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_CCMP;
1875 padapter->securitypriv.ndisencryptstatus =
1876 Ndis802_11Encryption3Enabled;
1878 case WPA_CIPHER_WEP104:
1879 padapter->securitypriv.dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP104;
1880 padapter->securitypriv.ndisencryptstatus =
1881 Ndis802_11Encryption1Enabled;
1885 { /* handle wps_ie */
1889 wps_ie = rtw_get_wps_ie23a(buf, ielen, NULL, &wps_ielen);
1890 if (wps_ie && wps_ielen > 0) {
1891 DBG_8723A("got wps_ie, wps_ielen:%u\n", wps_ielen);
1892 padapter->securitypriv.wps_ie_len =
1894 MAX_WPS_IE_LEN ? wps_ielen : MAX_WPS_IE_LEN;
1895 memcpy(padapter->securitypriv.wps_ie, wps_ie,
1896 padapter->securitypriv.wps_ie_len);
1897 set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS);
1899 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
1903 /* TKIP and AES disallow multicast packets until installing group key */
1904 if (padapter->securitypriv.dot11PrivacyAlgrthm ==
1905 WLAN_CIPHER_SUITE_TKIP ||
1906 padapter->securitypriv.dot11PrivacyAlgrthm ==
1907 WLAN_CIPHER_SUITE_CCMP)
1908 /* WPS open need to enable multicast */
1909 /* check_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS) == true)*/
1910 rtl8723a_off_rcr_am(padapter);
1912 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_,
1913 ("rtw_set_wpa_ie: pairwise_cipher = 0x%08x padapter->"
1914 "securitypriv.ndisencryptstatus =%d padapter->"
1915 "securitypriv.ndisauthtype =%d\n", pairwise_cipher,
1916 padapter->securitypriv.ndisencryptstatus,
1917 padapter->securitypriv.ndisauthtype));
1922 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
1926 static int rtw_cfg80211_add_wep(struct rtw_adapter *padapter,
1927 struct rtw_wep_key *wep, u8 keyid)
1930 struct security_priv *psecuritypriv = &padapter->securitypriv;
1932 if (keyid >= NUM_WEP_KEYS) {
1933 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_,
1934 ("%s:keyid>4 =>fail\n", __func__));
1939 switch (wep->keylen) {
1941 psecuritypriv->dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP40;
1942 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1943 ("%s:wep->KeyLength = 5\n", __func__));
1946 psecuritypriv->dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP104;
1947 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1948 ("%s:wep->KeyLength = 13\n", __func__));
1951 psecuritypriv->dot11PrivacyAlgrthm = 0;
1952 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1953 ("%s:wep->KeyLength!= 5 or 13\n", __func__));
1958 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1959 ("%s:before memcpy, wep->KeyLength = 0x%x keyid =%x\n",
1960 __func__, wep->keylen, keyid));
1962 memcpy(&psecuritypriv->wep_key[keyid], wep, sizeof(struct rtw_wep_key));
1964 psecuritypriv->dot11PrivacyKeyIndex = keyid;
1966 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
1967 ("%s:security key material : "
1968 "%x %x %x %x %x %x %x %x %x %x %x %x %x\n", __func__,
1969 psecuritypriv->wep_key[keyid].key[0],
1970 psecuritypriv->wep_key[keyid].key[1],
1971 psecuritypriv->wep_key[keyid].key[2],
1972 psecuritypriv->wep_key[keyid].key[3],
1973 psecuritypriv->wep_key[keyid].key[4],
1974 psecuritypriv->wep_key[keyid].key[5],
1975 psecuritypriv->wep_key[keyid].key[6],
1976 psecuritypriv->wep_key[keyid].key[7],
1977 psecuritypriv->wep_key[keyid].key[8],
1978 psecuritypriv->wep_key[keyid].key[9],
1979 psecuritypriv->wep_key[keyid].key[10],
1980 psecuritypriv->wep_key[keyid].key[11],
1981 psecuritypriv->wep_key[keyid].key[12]));
1983 res = rtw_set_key23a(padapter, psecuritypriv, keyid, 1);
1990 static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
1991 struct cfg80211_connect_params *sme)
1994 struct list_head *phead, *plist, *ptmp;
1995 struct wlan_network *pnetwork = NULL;
1996 enum ndis_802_11_auth_mode authmode;
1997 struct cfg80211_ssid ndis_ssid;
2001 const u8 *src_bssid;
2002 /* u8 matched_by_bssid = false; */
2003 /* u8 matched_by_ssid = false; */
2005 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
2006 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2007 struct security_priv *psecuritypriv = &padapter->securitypriv;
2008 struct rtw_queue *queue = &pmlmepriv->scanned_queue;
2010 DBG_8723A("=>" "%s(%s)\n", __func__, ndev->name);
2011 DBG_8723A("privacy =%d, key =%p, key_len =%d, key_idx =%d\n",
2012 sme->privacy, sme->key, sme->key_len, sme->key_idx);
2014 if (_FAIL == rtw_pwr_wakeup(padapter)) {
2019 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
2024 if (!sme->ssid || !sme->ssid_len) {
2029 if (sme->ssid_len > IW_ESSID_MAX_SIZE) {
2034 memset(&ndis_ssid, 0, sizeof(struct cfg80211_ssid));
2035 ndis_ssid.ssid_len = sme->ssid_len;
2036 memcpy(ndis_ssid.ssid, sme->ssid, sme->ssid_len);
2038 DBG_8723A("ssid =%s, len =%zu\n", ndis_ssid.ssid, sme->ssid_len);
2041 DBG_8723A("bssid =" MAC_FMT "\n", MAC_ARG(sme->bssid));
2043 if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) {
2045 DBG_8723A("%s, fw_state = 0x%x, goto exit\n", __func__,
2046 pmlmepriv->fw_state);
2049 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) {
2050 rtw_scan_abort23a(padapter);
2053 spin_lock_bh(&queue->lock);
2055 phead = get_list_head(queue);
2057 list_for_each_safe(plist, ptmp, phead) {
2058 pnetwork = container_of(plist, struct wlan_network, list);
2060 dst_ssid = pnetwork->network.Ssid.ssid;
2061 dst_bssid = pnetwork->network.MacAddress;
2064 if (!ether_addr_equal(pnetwork->network.MacAddress,
2069 if (sme->ssid && sme->ssid_len) {
2070 if (pnetwork->network.Ssid.ssid_len != sme->ssid_len ||
2071 memcmp(pnetwork->network.Ssid.ssid, sme->ssid,
2077 src_bssid = sme->bssid;
2079 if (ether_addr_equal(dst_bssid, src_bssid)) {
2080 DBG_8723A("matched by bssid\n");
2082 ndis_ssid.ssid_len =
2083 pnetwork->network.Ssid.ssid_len;
2084 memcpy(ndis_ssid.ssid,
2085 pnetwork->network.Ssid.ssid,
2086 pnetwork->network.Ssid.ssid_len);
2092 } else if (sme->ssid && sme->ssid_len) {
2093 src_ssid = ndis_ssid.ssid;
2095 if ((!memcmp(dst_ssid, src_ssid, ndis_ssid.ssid_len)) &&
2096 (pnetwork->network.Ssid.ssid_len ==
2097 ndis_ssid.ssid_len)) {
2098 DBG_8723A("matched by ssid\n");
2105 spin_unlock_bh(&queue->lock);
2107 if (!matched || (pnetwork == NULL)) {
2109 DBG_8723A("connect, matched == false, goto exit\n");
2113 if (cfg80211_infrastructure_mode(
2114 padapter, pnetwork->network.ifmode) != _SUCCESS) {
2119 psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled;
2120 psecuritypriv->dot11PrivacyAlgrthm = 0;
2121 psecuritypriv->dot118021XGrpPrivacy = 0;
2122 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
2123 psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
2126 rtw_cfg80211_set_wpa_version(psecuritypriv,
2127 sme->crypto.wpa_versions);
2131 ret = rtw_cfg80211_set_auth_type(psecuritypriv, sme->auth_type);
2136 DBG_8723A("%s, ie_len =%zu\n", __func__, sme->ie_len);
2138 ret = rtw_cfg80211_set_wpa_ie(padapter, sme->ie, sme->ie_len);
2142 if (sme->crypto.n_ciphers_pairwise) {
2143 ret = rtw_cfg80211_set_cipher(psecuritypriv,
2144 sme->crypto.ciphers_pairwise[0],
2150 /* For WEP Shared auth */
2151 if ((psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Shared ||
2152 psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Auto) &&
2154 struct rtw_wep_key wep_key;
2155 u8 wep_key_idx, wep_key_len;
2156 DBG_8723A("%s(): Shared/Auto WEP\n", __func__);
2158 wep_key_idx = sme->key_idx;
2159 wep_key_len = sme->key_len;
2161 if (wep_key_idx > WEP_KEYS || !wep_key_len ||
2162 wep_key_len > WLAN_KEY_LEN_WEP104) {
2167 wep_key_len = wep_key_len <= 5 ? 5 : 13;
2169 memset(&wep_key, 0, sizeof(struct rtw_wep_key));
2171 wep_key.keylen = wep_key_len;
2173 if (wep_key_len == 13) {
2174 padapter->securitypriv.dot11PrivacyAlgrthm =
2175 WLAN_CIPHER_SUITE_WEP104;
2176 padapter->securitypriv.dot118021XGrpPrivacy =
2177 WLAN_CIPHER_SUITE_WEP104;
2179 padapter->securitypriv.dot11PrivacyAlgrthm =
2180 WLAN_CIPHER_SUITE_WEP40;
2181 padapter->securitypriv.dot118021XGrpPrivacy =
2182 WLAN_CIPHER_SUITE_WEP40;
2185 memcpy(wep_key.key, (void *)sme->key, wep_key.keylen);
2187 if (rtw_cfg80211_add_wep(padapter, &wep_key, wep_key_idx) !=
2195 ret = rtw_cfg80211_set_cipher(psecuritypriv,
2196 sme->crypto.cipher_group, false);
2200 if (sme->crypto.n_akm_suites) {
2201 ret = rtw_cfg80211_set_key_mgt(psecuritypriv,
2202 sme->crypto.akm_suites[0]);
2207 authmode = psecuritypriv->ndisauthtype;
2208 rtw_set_802_11_authentication_mode23a(padapter, authmode);
2210 /* rtw_set_802_11_encryption_mode(padapter,
2211 padapter->securitypriv.ndisencryptstatus); */
2213 if (rtw_set_802_11_ssid23a(padapter, &ndis_ssid) == false) {
2218 DBG_8723A("set ssid:dot11AuthAlgrthm =%d, dot11PrivacyAlgrthm =%d, "
2219 "dot118021XGrpPrivacy =%d\n", psecuritypriv->dot11AuthAlgrthm,
2220 psecuritypriv->dot11PrivacyAlgrthm,
2221 psecuritypriv->dot118021XGrpPrivacy);
2225 DBG_8723A("<=%s, ret %d\n", __func__, ret);
2230 static int cfg80211_rtw_disconnect(struct wiphy *wiphy, struct net_device *ndev,
2233 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
2235 DBG_8723A("%s(%s)\n", __func__, ndev->name);
2237 rtw_set_roaming(padapter, 0);
2239 if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
2240 rtw_scan_abort23a(padapter);
2241 LeaveAllPowerSaveMode23a(padapter);
2242 rtw_disassoc_cmd23a(padapter, 500, false);
2244 DBG_8723A("%s...call rtw_indicate_disconnect23a\n", __func__);
2246 padapter->mlmepriv.not_indic_disco = true;
2247 rtw_indicate_disconnect23a(padapter);
2248 padapter->mlmepriv.not_indic_disco = false;
2250 rtw_free_assoc_resources23a(padapter, 1);
2256 static int cfg80211_rtw_set_txpower(struct wiphy *wiphy,
2257 struct wireless_dev *wdev,
2258 enum nl80211_tx_power_setting type, int mbm)
2260 DBG_8723A("%s\n", __func__);
2264 static int cfg80211_rtw_get_txpower(struct wiphy *wiphy,
2265 struct wireless_dev *wdev, int *dbm)
2267 DBG_8723A("%s\n", __func__);
2272 inline bool rtw_cfg80211_pwr_mgmt(struct rtw_adapter *adapter)
2274 struct rtw_wdev_priv *rtw_wdev_priv = wdev_to_priv(adapter->rtw_wdev);
2275 return rtw_wdev_priv->power_mgmt;
2278 static int cfg80211_rtw_set_power_mgmt(struct wiphy *wiphy,
2279 struct net_device *ndev,
2280 bool enabled, int timeout)
2282 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
2283 struct rtw_wdev_priv *rtw_wdev_priv = wdev_to_priv(padapter->rtw_wdev);
2285 DBG_8723A("%s(%s): enabled:%u, timeout:%d\n",
2286 __func__, ndev->name, enabled, timeout);
2288 rtw_wdev_priv->power_mgmt = enabled;
2291 LPS_Leave23a(padapter);
2296 static int cfg80211_rtw_set_pmksa(struct wiphy *wiphy,
2297 struct net_device *netdev,
2298 struct cfg80211_pmksa *pmksa)
2300 u8 index, blInserted = false;
2301 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
2302 struct security_priv *psecuritypriv = &padapter->securitypriv;
2304 DBG_8723A("%s(%s)\n", __func__, netdev->name);
2306 if (is_zero_ether_addr(pmksa->bssid))
2311 /* overwrite PMKID */
2312 for (index = 0; index < NUM_PMKID_CACHE; index++) {
2313 if (ether_addr_equal(psecuritypriv->PMKIDList[index].Bssid,
2315 /* BSSID is matched, the same AP => rewrite with
2317 DBG_8723A("%s(%s): BSSID exists in the PMKList.\n",
2318 __func__, netdev->name);
2320 memcpy(psecuritypriv->PMKIDList[index].PMKID,
2321 pmksa->pmkid, WLAN_PMKID_LEN);
2322 psecuritypriv->PMKIDList[index].bUsed = true;
2323 psecuritypriv->PMKIDIndex = index + 1;
2330 /* Find a new entry */
2331 DBG_8723A("%s(%s): Use new entry index = %d for this PMKID\n",
2332 __func__, netdev->name, psecuritypriv->PMKIDIndex);
2335 psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].
2336 Bssid, pmksa->bssid);
2337 memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].
2338 PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
2340 psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed =
2342 psecuritypriv->PMKIDIndex++;
2343 if (psecuritypriv->PMKIDIndex == 16) {
2344 psecuritypriv->PMKIDIndex = 0;
2351 static int cfg80211_rtw_del_pmksa(struct wiphy *wiphy,
2352 struct net_device *netdev,
2353 struct cfg80211_pmksa *pmksa)
2355 u8 index, bMatched = false;
2356 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
2357 struct security_priv *psecuritypriv = &padapter->securitypriv;
2359 DBG_8723A("%s(%s)\n", __func__, netdev->name);
2361 for (index = 0; index < NUM_PMKID_CACHE; index++) {
2362 if (ether_addr_equal(psecuritypriv->PMKIDList[index].Bssid,
2364 /* BSSID is matched, the same AP => Remove this PMKID
2365 information and reset it. */
2366 eth_zero_addr(psecuritypriv->PMKIDList[index].Bssid);
2367 memset(psecuritypriv->PMKIDList[index].PMKID, 0x00,
2369 psecuritypriv->PMKIDList[index].bUsed = false;
2375 if (false == bMatched) {
2376 DBG_8723A("%s(%s): do not have matched BSSID\n", __func__,
2384 static int cfg80211_rtw_flush_pmksa(struct wiphy *wiphy,
2385 struct net_device *netdev)
2387 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
2388 struct security_priv *psecuritypriv = &padapter->securitypriv;
2390 DBG_8723A("%s(%s)\n", __func__, netdev->name);
2392 memset(&psecuritypriv->PMKIDList[0], 0x00,
2393 sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
2394 psecuritypriv->PMKIDIndex = 0;
2399 #ifdef CONFIG_8723AU_AP_MODE
2400 void rtw_cfg80211_indicate_sta_assoc(struct rtw_adapter *padapter,
2401 u8 *pmgmt_frame, uint frame_len)
2405 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2406 struct net_device *ndev = padapter->pnetdev;
2408 DBG_8723A("%s(padapter =%p,%s)\n", __func__, padapter, ndev->name);
2410 #if defined(RTW_USE_CFG80211_STA_EVENT)
2412 struct station_info sinfo;
2414 if (ieee80211_is_assoc_req(hdr->frame_control))
2415 ie_offset = _ASOCREQ_IE_OFFSET_;
2416 else /* WIFI_REASSOCREQ */
2417 ie_offset = _REASOCREQ_IE_OFFSET_;
2420 sinfo.filled = STATION_INFO_ASSOC_REQ_IES;
2421 sinfo.assoc_req_ies = pmgmt_frame + WLAN_HDR_A3_LEN + ie_offset;
2422 sinfo.assoc_req_ies_len =
2423 frame_len - WLAN_HDR_A3_LEN - ie_offset;
2424 cfg80211_new_sta(ndev, hdr->addr2, &sinfo, GFP_ATOMIC);
2426 #else /* defined(RTW_USE_CFG80211_STA_EVENT) */
2427 channel = pmlmeext->cur_channel;
2428 if (channel <= RTW_CH_MAX_2G_CHANNEL)
2429 freq = ieee80211_channel_to_frequency(channel,
2430 IEEE80211_BAND_2GHZ);
2432 freq = ieee80211_channel_to_frequency(channel,
2433 IEEE80211_BAND_5GHZ);
2435 cfg80211_rx_mgmt(padapter->rtw_wdev, freq, 0, pmgmt_frame, frame_len,
2437 #endif /* defined(RTW_USE_CFG80211_STA_EVENT) */
2440 void rtw_cfg80211_indicate_sta_disassoc(struct rtw_adapter *padapter,
2442 unsigned short reason)
2448 struct ieee80211_hdr *pwlanhdr;
2450 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2451 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
2452 struct net_device *ndev = padapter->pnetdev;
2454 DBG_8723A("%s(padapter =%p,%s)\n", __func__, padapter, ndev->name);
2456 memset(mgmt_buf, 0, 128);
2458 #if defined(RTW_USE_CFG80211_STA_EVENT)
2459 cfg80211_del_sta(ndev, da, GFP_ATOMIC);
2460 #else /* defined(RTW_USE_CFG80211_STA_EVENT) */
2461 channel = pmlmeext->cur_channel;
2462 if (channel <= RTW_CH_MAX_2G_CHANNEL)
2463 freq = ieee80211_channel_to_frequency(channel,
2464 IEEE80211_BAND_2GHZ);
2466 freq = ieee80211_channel_to_frequency(channel,
2467 IEEE80211_BAND_5GHZ);
2469 pmgmt_frame = mgmt_buf;
2470 pwlanhdr = (struct ieee80211_hdr *)pmgmt_frame;
2472 pwlanhdr->frame_control =
2473 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH);
2475 ether_addr_copy(pwlanhdr->addr1, myid(&padapter->eeprompriv));
2476 ether_addr_copy(pwlanhdr->addr2, da);
2477 ether_addr_copy(pwlanhdr->addr3, get_my_bssid23a(&pmlmeinfo->network));
2479 pwlanhdr->seq_ctrl =
2480 cpu_to_le16(IEEE80211_SN_TO_SEQ(pmlmeext->mgnt_seq));
2481 pmlmeext->mgnt_seq++;
2483 pmgmt_frame += sizeof(struct ieee80211_hdr_3addr);
2484 frame_len = sizeof(struct ieee80211_hdr_3addr);
2486 reason = cpu_to_le16(reason);
2487 pmgmt_frame = rtw_set_fixed_ie23a(pmgmt_frame,
2488 WLAN_REASON_PREV_AUTH_NOT_VALID,
2489 (unsigned char *)&reason, &frame_len);
2491 cfg80211_rx_mgmt(padapter->rtw_wdev, freq, 0, mgmt_buf, frame_len,
2493 #endif /* defined(RTW_USE_CFG80211_STA_EVENT) */
2496 static int rtw_cfg80211_monitor_if_open(struct net_device *ndev)
2500 DBG_8723A("%s\n", __func__);
2505 static int rtw_cfg80211_monitor_if_close(struct net_device *ndev)
2509 DBG_8723A("%s\n", __func__);
2514 static int rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb,
2515 struct net_device *ndev)
2520 int dot11_hdr_len = 24;
2522 unsigned char *pdata;
2523 unsigned char src_mac_addr[6];
2524 unsigned char dst_mac_addr[6];
2525 struct ieee80211_hdr *dot11_hdr;
2526 struct ieee80211_radiotap_header *rtap_hdr;
2527 struct rtw_adapter *padapter = netdev_priv(ndev);
2529 DBG_8723A("%s(%s)\n", __func__, ndev->name);
2531 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
2534 rtap_hdr = (struct ieee80211_radiotap_header *)skb->data;
2535 if (unlikely(rtap_hdr->it_version))
2538 rtap_len = ieee80211_get_radiotap_len(skb->data);
2539 if (unlikely(skb->len < rtap_len))
2542 if (rtap_len != 14) {
2543 DBG_8723A("radiotap len (should be 14): %d\n", rtap_len);
2547 /* Skip the ratio tap header */
2548 skb_pull(skb, rtap_len);
2550 dot11_hdr = (struct ieee80211_hdr *)skb->data;
2551 /* Check if the QoS bit is set */
2552 if (ieee80211_is_data(dot11_hdr->frame_control)) {
2553 /* Check if this ia a Wireless Distribution System (WDS) frame
2554 * which has 4 MAC addresses
2556 if (ieee80211_is_data_qos(dot11_hdr->frame_control))
2557 qos_len = IEEE80211_QOS_CTL_LEN;
2558 if (ieee80211_has_a4(dot11_hdr->frame_control))
2561 memcpy(dst_mac_addr, dot11_hdr->addr1, sizeof(dst_mac_addr));
2562 memcpy(src_mac_addr, dot11_hdr->addr2, sizeof(src_mac_addr));
2565 * Skip the 802.11 header, QoS (if any) and SNAP,
2566 * but leave spaces for two MAC addresses
2568 skb_pull(skb, dot11_hdr_len + qos_len + snap_len -
2570 pdata = (unsigned char *)skb->data;
2571 ether_addr_copy(pdata, dst_mac_addr);
2572 ether_addr_copy(pdata + ETH_ALEN, src_mac_addr);
2574 DBG_8723A("should be eapol packet\n");
2576 /* Use the real net device to transmit the packet */
2577 ret = rtw_xmit23a_entry23a(skb, padapter->pnetdev);
2581 } else if (ieee80211_is_action(dot11_hdr->frame_control)) {
2582 struct ieee80211_mgmt *mgmt;
2583 /* only for action frames */
2584 struct xmit_frame *pmgntframe;
2585 struct pkt_attrib *pattrib;
2586 unsigned char *pframe;
2587 /* u8 category, action, OUI_Subtype, dialogToken = 0; */
2588 /* unsigned char *frame_body; */
2589 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2590 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2592 u8 category, action;
2594 mgmt = (struct ieee80211_mgmt *)dot11_hdr;
2596 DBG_8723A("RTW_Tx:da =" MAC_FMT " via %s(%s)\n",
2597 MAC_ARG(mgmt->da), __func__, ndev->name);
2598 category = mgmt->u.action.category;
2599 action = mgmt->u.action.u.wme_action.action_code;
2600 if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
2601 DBG_8723A("RTW_Tx:%s\n", action_public_str23a(action));
2603 DBG_8723A("RTW_Tx:category(%u), action(%u)\n", category,
2606 /* starting alloc mgmt frame to dump it */
2607 pmgntframe = alloc_mgtxmitframe23a(pxmitpriv);
2608 if (pmgntframe == NULL)
2611 /* update attribute */
2612 pattrib = &pmgntframe->attrib;
2613 update_mgntframe_attrib23a(padapter, pattrib);
2614 pattrib->retry_ctrl = false;
2616 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2618 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2620 memcpy(pframe, skb->data, len);
2621 pattrib->pktlen = len;
2623 /* update seq number */
2624 pmlmeext->mgnt_seq = le16_to_cpu(dot11_hdr->seq_ctrl) >> 4;
2625 pattrib->seqnum = pmlmeext->mgnt_seq;
2626 pmlmeext->mgnt_seq++;
2628 pattrib->last_txcmdsz = pattrib->pktlen;
2630 dump_mgntframe23a(padapter, pmgntframe);
2641 rtw_cfg80211_monitor_if_set_mac_address(struct net_device *ndev, void *addr)
2645 DBG_8723A("%s\n", __func__);
2650 static const struct net_device_ops rtw_cfg80211_monitor_if_ops = {
2651 .ndo_open = rtw_cfg80211_monitor_if_open,
2652 .ndo_stop = rtw_cfg80211_monitor_if_close,
2653 .ndo_start_xmit = rtw_cfg80211_monitor_if_xmit_entry,
2654 .ndo_set_mac_address = rtw_cfg80211_monitor_if_set_mac_address,
2657 static int rtw_cfg80211_add_monitor_if(struct rtw_adapter *padapter, char *name,
2658 struct net_device **ndev)
2661 struct net_device *mon_ndev = NULL;
2662 struct wireless_dev *mon_wdev = NULL;
2663 struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
2666 DBG_8723A("%s(%s): without specific name\n",
2667 __func__, padapter->pnetdev->name);
2672 if (pwdev_priv->pmon_ndev) {
2673 DBG_8723A("%s(%s): monitor interface exist: %s\n", __func__,
2674 padapter->pnetdev->name, pwdev_priv->pmon_ndev->name);
2679 mon_ndev = alloc_etherdev(sizeof(struct rtw_adapter));
2681 DBG_8723A("%s(%s): allocate ndev fail\n", __func__,
2682 padapter->pnetdev->name);
2687 mon_ndev->type = ARPHRD_IEEE80211_RADIOTAP;
2688 strncpy(mon_ndev->name, name, IFNAMSIZ);
2689 mon_ndev->name[IFNAMSIZ - 1] = 0;
2690 mon_ndev->destructor = rtw_ndev_destructor;
2692 mon_ndev->netdev_ops = &rtw_cfg80211_monitor_if_ops;
2695 mon_wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
2697 DBG_8723A("%s(%s): allocate mon_wdev fail\n", __func__,
2698 padapter->pnetdev->name);
2703 mon_wdev->wiphy = padapter->rtw_wdev->wiphy;
2704 mon_wdev->netdev = mon_ndev;
2705 mon_wdev->iftype = NL80211_IFTYPE_MONITOR;
2706 mon_ndev->ieee80211_ptr = mon_wdev;
2708 ret = register_netdevice(mon_ndev);
2713 *ndev = pwdev_priv->pmon_ndev = mon_ndev;
2714 memcpy(pwdev_priv->ifname_mon, name, IFNAMSIZ + 1);
2722 if (ret && mon_ndev) {
2723 free_netdev(mon_ndev);
2724 *ndev = mon_ndev = NULL;
2730 static struct wireless_dev *
2731 cfg80211_rtw_add_virtual_intf(struct wiphy *wiphy, const char *name,
2732 enum nl80211_iftype type, u32 *flags,
2733 struct vif_params *params)
2736 struct net_device *ndev = NULL;
2737 struct rtw_adapter *padapter = wiphy_to_adapter(wiphy);
2739 DBG_8723A("%s(%s): wiphy:%s, name:%s, type:%d\n", __func__,
2740 padapter->pnetdev->name, wiphy_name(wiphy), name, type);
2743 case NL80211_IFTYPE_ADHOC:
2744 case NL80211_IFTYPE_AP_VLAN:
2745 case NL80211_IFTYPE_WDS:
2746 case NL80211_IFTYPE_MESH_POINT:
2749 case NL80211_IFTYPE_MONITOR:
2751 rtw_cfg80211_add_monitor_if(padapter, (char *)name, &ndev);
2754 case NL80211_IFTYPE_P2P_CLIENT:
2755 case NL80211_IFTYPE_STATION:
2759 case NL80211_IFTYPE_P2P_GO:
2760 case NL80211_IFTYPE_AP:
2765 DBG_8723A("Unsupported interface type\n");
2769 DBG_8723A("%s(%s): ndev:%p, ret:%d\n", __func__,
2770 padapter->pnetdev->name,
2773 return ndev ? ndev->ieee80211_ptr : ERR_PTR(ret);
2776 static int cfg80211_rtw_del_virtual_intf(struct wiphy *wiphy,
2777 struct wireless_dev *wdev)
2779 struct rtw_wdev_priv *pwdev_priv =
2780 (struct rtw_wdev_priv *)wiphy_priv(wiphy);
2781 struct net_device *ndev;
2782 ndev = wdev ? wdev->netdev : NULL;
2787 unregister_netdevice(ndev);
2789 if (ndev == pwdev_priv->pmon_ndev) {
2790 pwdev_priv->pmon_ndev = NULL;
2791 pwdev_priv->ifname_mon[0] = '\0';
2792 DBG_8723A("%s(%s): remove monitor interface\n",
2793 __func__, ndev->name);
2800 static int rtw_add_beacon(struct rtw_adapter *adapter, const u8 *head,
2801 size_t head_len, const u8 *tail, size_t tail_len)
2805 uint len, wps_ielen = 0;
2806 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
2807 /* struct sta_priv *pstapriv = &padapter->stapriv; */
2809 DBG_8723A("%s beacon_head_len =%zu, beacon_tail_len =%zu\n",
2810 __func__, head_len, tail_len);
2812 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true)
2818 pbuf = kzalloc(head_len + tail_len, GFP_KERNEL);
2821 /* 24 = beacon header len. */
2822 memcpy(pbuf, (void *)head + 24, head_len - 24);
2823 memcpy(pbuf + head_len - 24, (void *)tail, tail_len);
2825 len = head_len + tail_len - 24;
2827 /* check wps ie if inclued */
2828 if (rtw_get_wps_ie23a
2829 (pbuf + _FIXED_IE_LENGTH_, len - _FIXED_IE_LENGTH_, NULL,
2831 DBG_8723A("add bcn, wps_ielen =%d\n", wps_ielen);
2833 /* pbss_network->IEs will not include p2p_ie, wfd ie */
2834 rtw_ies_remove_ie23a(pbuf, &len, _BEACON_IE_OFFSET_,
2835 WLAN_EID_VENDOR_SPECIFIC, P2P_OUI23A, 4);
2836 rtw_ies_remove_ie23a(pbuf, &len, _BEACON_IE_OFFSET_,
2837 WLAN_EID_VENDOR_SPECIFIC, WFD_OUI23A, 4);
2839 if (rtw_check_beacon_data23a(adapter, pbuf, len) == _SUCCESS) {
2850 static int cfg80211_rtw_start_ap(struct wiphy *wiphy, struct net_device *ndev,
2851 struct cfg80211_ap_settings *settings)
2854 struct rtw_adapter *adapter = wiphy_to_adapter(wiphy);
2856 DBG_8723A("%s(%s): hidden_ssid:%d, auth_type:%d\n",
2857 __func__, ndev->name, settings->hidden_ssid,
2858 settings->auth_type);
2860 ret = rtw_add_beacon(adapter, settings->beacon.head,
2861 settings->beacon.head_len, settings->beacon.tail,
2862 settings->beacon.tail_len);
2864 adapter->mlmeextpriv.mlmext_info.hidden_ssid_mode =
2865 settings->hidden_ssid;
2867 if (settings->ssid && settings->ssid_len) {
2868 struct wlan_bssid_ex *pbss_network =
2869 &adapter->mlmepriv.cur_network.network;
2870 struct wlan_bssid_ex *pbss_network_ext =
2871 &adapter->mlmeextpriv.mlmext_info.network;
2873 memcpy(pbss_network->Ssid.ssid, (void *)settings->ssid,
2874 settings->ssid_len);
2875 pbss_network->Ssid.ssid_len = settings->ssid_len;
2876 memcpy(pbss_network_ext->Ssid.ssid, (void *)settings->ssid,
2877 settings->ssid_len);
2878 pbss_network_ext->Ssid.ssid_len = settings->ssid_len;
2884 static int cfg80211_rtw_change_beacon(struct wiphy *wiphy,
2885 struct net_device *ndev,
2886 struct cfg80211_beacon_data *info)
2889 struct rtw_adapter *adapter = wiphy_to_adapter(wiphy);
2891 DBG_8723A("%s(%s)\n", __func__, ndev->name);
2893 ret = rtw_add_beacon(adapter, info->head, info->head_len, info->tail,
2899 static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
2901 DBG_8723A("%s(%s)\n", __func__, ndev->name);
2905 static int cfg80211_rtw_add_station(struct wiphy *wiphy,
2906 struct net_device *ndev, const u8 *mac,
2907 struct station_parameters *params)
2909 DBG_8723A("%s(%s)\n", __func__, ndev->name);
2914 static int cfg80211_rtw_del_station(struct wiphy *wiphy,
2915 struct net_device *ndev, const u8 *mac)
2918 struct list_head *phead, *plist, *ptmp;
2920 struct sta_info *psta;
2921 struct rtw_adapter *padapter = netdev_priv(ndev);
2922 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2923 struct sta_priv *pstapriv = &padapter->stapriv;
2925 DBG_8723A("+%s(%s)\n", __func__, ndev->name);
2927 if (check_fwstate(pmlmepriv, (_FW_LINKED | WIFI_AP_STATE)) != true) {
2928 DBG_8723A("%s, fw_state != FW_LINKED|WIFI_AP_STATE\n",
2934 DBG_8723A("flush all sta, and cam_entry\n");
2936 flush_all_cam_entry23a(padapter); /* clear CAM */
2938 ret = rtw_sta_flush23a(padapter);
2943 DBG_8723A("free sta macaddr =" MAC_FMT "\n", MAC_ARG(mac));
2945 if (is_broadcast_ether_addr(mac))
2948 spin_lock_bh(&pstapriv->asoc_list_lock);
2950 phead = &pstapriv->asoc_list;
2952 /* check asoc_queue */
2953 list_for_each_safe(plist, ptmp, phead) {
2954 psta = container_of(plist, struct sta_info, asoc_list);
2956 if (ether_addr_equal(mac, psta->hwaddr)) {
2957 if (psta->dot8021xalg == 1 &&
2958 psta->bpairwise_key_installed == false) {
2959 DBG_8723A("%s, sta's dot8021xalg = 1 and "
2960 "key_installed = false\n", __func__);
2962 DBG_8723A("free psta =%p, aid =%d\n", psta,
2965 list_del_init(&psta->asoc_list);
2966 pstapriv->asoc_list_cnt--;
2968 /* spin_unlock_bh(&pstapriv->asoc_list_lock); */
2970 ap_free_sta23a(padapter, psta, true,
2971 WLAN_REASON_DEAUTH_LEAVING);
2972 /* spin_lock_bh(&pstapriv->asoc_list_lock); */
2981 spin_unlock_bh(&pstapriv->asoc_list_lock);
2983 associated_clients_update23a(padapter, updated);
2985 DBG_8723A("-%s(%s)\n", __func__, ndev->name);
2990 static int cfg80211_rtw_change_station(struct wiphy *wiphy,
2991 struct net_device *ndev, const u8 *mac,
2992 struct station_parameters *params)
2994 DBG_8723A("%s(%s)\n", __func__, ndev->name);
2998 static int cfg80211_rtw_dump_station(struct wiphy *wiphy,
2999 struct net_device *ndev, int idx, u8 *mac,
3000 struct station_info *sinfo)
3002 DBG_8723A("%s(%s)\n", __func__, ndev->name);
3004 /* TODO: dump scanned queue */
3009 static int cfg80211_rtw_change_bss(struct wiphy *wiphy, struct net_device *ndev,
3010 struct bss_parameters *params)
3012 DBG_8723A("%s(%s)\n", __func__, ndev->name);
3015 #endif /* CONFIG_8723AU_AP_MODE */
3017 void rtw_cfg80211_rx_action(struct rtw_adapter *adapter, u8 *frame,
3018 uint frame_len, const char *msg)
3020 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *)frame;
3024 channel = rtw_get_oper_ch23a(adapter);
3026 DBG_8723A("RTW_Rx:cur_ch =%d\n", channel);
3028 DBG_8723A("RTW_Rx:%s\n", msg);
3030 DBG_8723A("RTW_Rx:category(%u), action(%u)\n",
3031 hdr->u.action.category,
3032 hdr->u.action.u.wme_action.action_code);
3034 if (channel <= RTW_CH_MAX_2G_CHANNEL)
3035 freq = ieee80211_channel_to_frequency(channel,
3036 IEEE80211_BAND_2GHZ);
3038 freq = ieee80211_channel_to_frequency(channel,
3039 IEEE80211_BAND_5GHZ);
3041 cfg80211_rx_mgmt(adapter->rtw_wdev, freq, 0, frame, frame_len,
3045 static int _cfg80211_rtw_mgmt_tx(struct rtw_adapter *padapter, u8 tx_ch,
3046 const u8 *buf, size_t len)
3048 struct xmit_frame *pmgntframe;
3049 struct pkt_attrib *pattrib;
3050 unsigned char *pframe;
3052 struct ieee80211_hdr *pwlanhdr;
3053 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
3054 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3056 if (_FAIL == rtw_pwr_wakeup(padapter)) {
3061 rtw_set_scan_deny(padapter, 1000);
3063 rtw_scan_abort23a(padapter);
3065 if (tx_ch != rtw_get_oper_ch23a(padapter)) {
3066 if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED))
3067 pmlmeext->cur_channel = tx_ch;
3068 set_channel_bwmode23a(padapter, tx_ch,
3069 HAL_PRIME_CHNL_OFFSET_DONT_CARE,
3070 HT_CHANNEL_WIDTH_20);
3073 /* starting alloc mgmt frame to dump it */
3074 pmgntframe = alloc_mgtxmitframe23a(pxmitpriv);
3076 /* ret = -ENOMEM; */
3081 /* update attribute */
3082 pattrib = &pmgntframe->attrib;
3083 update_mgntframe_attrib23a(padapter, pattrib);
3084 pattrib->retry_ctrl = false;
3086 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3088 pframe = (u8 *) (pmgntframe->buf_addr) + TXDESC_OFFSET;
3090 memcpy(pframe, (void *)buf, len);
3091 pattrib->pktlen = len;
3093 pwlanhdr = (struct ieee80211_hdr *)pframe;
3094 /* update seq number */
3095 pmlmeext->mgnt_seq = le16_to_cpu(pwlanhdr->seq_ctrl) >> 4;
3096 pattrib->seqnum = pmlmeext->mgnt_seq;
3097 pmlmeext->mgnt_seq++;
3099 pattrib->last_txcmdsz = pattrib->pktlen;
3101 ret = dump_mgntframe23a_and_wait_ack23a(padapter, pmgntframe);
3103 if (ret != _SUCCESS)
3104 DBG_8723A("%s, ack == false\n", __func__);
3106 DBG_8723A("%s, ack == true\n", __func__);
3110 DBG_8723A("%s, ret =%d\n", __func__, ret);
3115 static int cfg80211_rtw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
3116 struct cfg80211_mgmt_tx_params *params,
3119 struct rtw_adapter *padapter =
3120 (struct rtw_adapter *)wiphy_to_adapter(wiphy);
3123 u32 dump_limit = RTW_MAX_MGMT_TX_CNT;
3126 u8 category, action;
3127 unsigned long start = jiffies;
3128 size_t len = params->len;
3129 struct ieee80211_channel *chan = params->chan;
3130 const u8 *buf = params->buf;
3131 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *)buf;
3132 u8 tx_ch = (u8) ieee80211_frequency_to_channel(chan->center_freq);
3134 if (!ieee80211_is_action(hdr->frame_control))
3137 /* cookie generation */
3138 *cookie = (unsigned long)buf;
3140 DBG_8723A("%s(%s): len =%zu, ch =%d\n", __func__,
3141 padapter->pnetdev->name, len, tx_ch);
3143 /* indicate ack before issue frame to avoid racing with rsp frame */
3144 cfg80211_mgmt_tx_status(padapter->rtw_wdev, *cookie, buf, len, ack,
3147 DBG_8723A("RTW_Tx:tx_ch =%d, da =" MAC_FMT "\n", tx_ch,
3149 category = hdr->u.action.category;
3150 action = hdr->u.action.u.wme_action.action_code;
3151 if (category == WLAN_CATEGORY_PUBLIC)
3152 DBG_8723A("RTW_Tx:%s\n", action_public_str23a(action));
3154 DBG_8723A("RTW_Tx:category(%u), action(%u)\n",
3159 tx_ret = _cfg80211_rtw_mgmt_tx(padapter, tx_ch, buf, len);
3160 } while (dump_cnt < dump_limit && tx_ret != _SUCCESS);
3162 if (tx_ret != _SUCCESS || dump_cnt > 1) {
3163 DBG_8723A("%s(%s): %s (%d/%d) in %d ms\n",
3164 __func__, padapter->pnetdev->name,
3165 tx_ret == _SUCCESS ? "OK" : "FAIL", dump_cnt,
3166 dump_limit, jiffies_to_msecs(jiffies - start));
3172 static void cfg80211_rtw_mgmt_frame_register(struct wiphy *wiphy,
3173 struct wireless_dev *wdev,
3174 u16 frame_type, bool reg)
3176 if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
3182 static struct cfg80211_ops rtw_cfg80211_ops = {
3183 .change_virtual_intf = cfg80211_rtw_change_iface,
3184 .add_key = cfg80211_rtw_add_key,
3185 .get_key = cfg80211_rtw_get_key,
3186 .del_key = cfg80211_rtw_del_key,
3187 .set_default_key = cfg80211_rtw_set_default_key,
3188 .get_station = cfg80211_rtw_get_station,
3189 .scan = cfg80211_rtw_scan,
3190 .set_wiphy_params = cfg80211_rtw_set_wiphy_params,
3191 .connect = cfg80211_rtw_connect,
3192 .disconnect = cfg80211_rtw_disconnect,
3193 .join_ibss = cfg80211_rtw_join_ibss,
3194 .leave_ibss = cfg80211_rtw_leave_ibss,
3195 .set_tx_power = cfg80211_rtw_set_txpower,
3196 .get_tx_power = cfg80211_rtw_get_txpower,
3197 .set_power_mgmt = cfg80211_rtw_set_power_mgmt,
3198 .set_pmksa = cfg80211_rtw_set_pmksa,
3199 .del_pmksa = cfg80211_rtw_del_pmksa,
3200 .flush_pmksa = cfg80211_rtw_flush_pmksa,
3202 #ifdef CONFIG_8723AU_AP_MODE
3203 .add_virtual_intf = cfg80211_rtw_add_virtual_intf,
3204 .del_virtual_intf = cfg80211_rtw_del_virtual_intf,
3206 .start_ap = cfg80211_rtw_start_ap,
3207 .change_beacon = cfg80211_rtw_change_beacon,
3208 .stop_ap = cfg80211_rtw_stop_ap,
3210 .add_station = cfg80211_rtw_add_station,
3211 .del_station = cfg80211_rtw_del_station,
3212 .change_station = cfg80211_rtw_change_station,
3213 .dump_station = cfg80211_rtw_dump_station,
3214 .change_bss = cfg80211_rtw_change_bss,
3215 #endif /* CONFIG_8723AU_AP_MODE */
3217 .mgmt_tx = cfg80211_rtw_mgmt_tx,
3218 .mgmt_frame_register = cfg80211_rtw_mgmt_frame_register,
3221 static void rtw_cfg80211_init_ht_capab(struct ieee80211_sta_ht_cap *ht_cap,
3222 enum ieee80211_band band, u8 rf_type)
3225 #define MAX_BIT_RATE_40MHZ_MCS15 300 /* Mbps */
3226 #define MAX_BIT_RATE_40MHZ_MCS7 150 /* Mbps */
3228 ht_cap->ht_supported = true;
3230 ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
3231 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20 |
3232 IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
3235 *Maximum length of AMPDU that the STA can receive.
3236 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
3238 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3240 /*Minimum MPDU start spacing , */
3241 ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
3243 ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
3246 *hw->wiphy->bands[IEEE80211_BAND_2GHZ]
3249 *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7
3250 *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15
3251 *if rx_ant >= 3 rx_mask[2]= 0xff;
3252 *if BW_40 rx_mask[4]= 0x01;
3253 *highest supported RX rate
3255 if (rf_type == RF_1T1R) {
3256 ht_cap->mcs.rx_mask[0] = 0xFF;
3257 ht_cap->mcs.rx_mask[1] = 0x00;
3258 ht_cap->mcs.rx_mask[4] = 0x01;
3260 ht_cap->mcs.rx_highest = MAX_BIT_RATE_40MHZ_MCS7;
3261 } else if ((rf_type == RF_1T2R) || (rf_type == RF_2T2R)) {
3262 ht_cap->mcs.rx_mask[0] = 0xFF;
3263 ht_cap->mcs.rx_mask[1] = 0xFF;
3264 ht_cap->mcs.rx_mask[4] = 0x01;
3266 ht_cap->mcs.rx_highest = MAX_BIT_RATE_40MHZ_MCS15;
3268 DBG_8723A("%s, error rf_type =%d\n", __func__, rf_type);
3273 void rtw_cfg80211_init_wiphy(struct rtw_adapter *padapter)
3276 struct ieee80211_supported_band *bands;
3277 struct wireless_dev *pwdev = padapter->rtw_wdev;
3278 struct wiphy *wiphy = pwdev->wiphy;
3280 rf_type = rtl8723a_get_rf_type(padapter);
3282 DBG_8723A("%s:rf_type =%d\n", __func__, rf_type);
3284 /* if (padapter->registrypriv.wireless_mode & WIRELESS_11G) */
3286 bands = wiphy->bands[IEEE80211_BAND_2GHZ];
3288 rtw_cfg80211_init_ht_capab(&bands->ht_cap,
3289 IEEE80211_BAND_2GHZ,
3293 /* if (padapter->registrypriv.wireless_mode & WIRELESS_11A) */
3295 bands = wiphy->bands[IEEE80211_BAND_5GHZ];
3297 rtw_cfg80211_init_ht_capab(&bands->ht_cap,
3298 IEEE80211_BAND_5GHZ,
3303 static void rtw_cfg80211_preinit_wiphy(struct rtw_adapter *padapter,
3304 struct wiphy *wiphy)
3306 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
3308 wiphy->max_scan_ssids = RTW_SSID_SCAN_AMOUNT;
3309 wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
3310 wiphy->max_num_pmkids = RTW_MAX_NUM_PMKIDS;
3312 wiphy->max_remain_on_channel_duration =
3313 RTW_MAX_REMAIN_ON_CHANNEL_DURATION;
3315 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
3316 BIT(NL80211_IFTYPE_ADHOC) |
3317 #ifdef CONFIG_8723AU_AP_MODE
3318 BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR) |
3322 #ifdef CONFIG_8723AU_AP_MODE
3323 wiphy->mgmt_stypes = rtw_cfg80211_default_mgmt_stypes;
3324 #endif /* CONFIG_8723AU_AP_MODE */
3326 wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
3329 wiphy->iface_combinations = &rtw_combinations;
3330 wiphy->n_iface_combinations = 1;
3333 wiphy->cipher_suites = rtw_cipher_suites;
3334 wiphy->n_cipher_suites = ARRAY_SIZE(rtw_cipher_suites);
3336 /* if (padapter->registrypriv.wireless_mode & WIRELESS_11G) */
3337 wiphy->bands[IEEE80211_BAND_2GHZ] =
3338 rtw_spt_band_alloc(IEEE80211_BAND_2GHZ);
3339 /* if (padapter->registrypriv.wireless_mode & WIRELESS_11A) */
3340 wiphy->bands[IEEE80211_BAND_5GHZ] =
3341 rtw_spt_band_alloc(IEEE80211_BAND_5GHZ);
3343 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3344 wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX | WIPHY_FLAG_HAVE_AP_SME;
3346 if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE)
3347 wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
3349 wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
3352 int rtw_wdev_alloc(struct rtw_adapter *padapter, struct device *dev)
3355 struct wiphy *wiphy;
3356 struct wireless_dev *wdev;
3357 struct rtw_wdev_priv *pwdev_priv;
3358 struct net_device *pnetdev = padapter->pnetdev;
3360 DBG_8723A("%s(padapter =%p)\n", __func__, padapter);
3363 wiphy = wiphy_new(&rtw_cfg80211_ops, sizeof(struct rtw_wdev_priv));
3365 DBG_8723A("Couldn't allocate wiphy device\n");
3371 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
3373 DBG_8723A("Couldn't allocate wireless device\n");
3378 set_wiphy_dev(wiphy, dev);
3379 rtw_cfg80211_preinit_wiphy(padapter, wiphy);
3381 ret = wiphy_register(wiphy);
3383 DBG_8723A("Couldn't register wiphy device\n");
3387 wdev->wiphy = wiphy;
3388 wdev->netdev = pnetdev;
3389 /* wdev->iftype = NL80211_IFTYPE_STATION; */
3390 /* for rtw_setopmode_cmd23a() in cfg80211_rtw_change_iface() */
3391 wdev->iftype = NL80211_IFTYPE_MONITOR;
3392 padapter->rtw_wdev = wdev;
3393 pnetdev->ieee80211_ptr = wdev;
3395 /* init pwdev_priv */
3396 pwdev_priv = wdev_to_priv(wdev);
3397 pwdev_priv->rtw_wdev = wdev;
3398 pwdev_priv->pmon_ndev = NULL;
3399 pwdev_priv->ifname_mon[0] = '\0';
3400 pwdev_priv->padapter = padapter;
3401 pwdev_priv->scan_request = NULL;
3402 spin_lock_init(&pwdev_priv->scan_req_lock);
3404 pwdev_priv->p2p_enabled = false;
3406 if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE)
3407 pwdev_priv->power_mgmt = true;
3409 pwdev_priv->power_mgmt = false;
3420 void rtw_wdev_free(struct wireless_dev *wdev)
3422 DBG_8723A("%s(wdev =%p)\n", __func__, wdev);
3427 kfree(wdev->wiphy->bands[IEEE80211_BAND_2GHZ]);
3428 kfree(wdev->wiphy->bands[IEEE80211_BAND_5GHZ]);
3430 wiphy_free(wdev->wiphy);
3435 void rtw_wdev_unregister(struct wireless_dev *wdev)
3437 struct rtw_wdev_priv *pwdev_priv;
3439 DBG_8723A("%s(wdev =%p)\n", __func__, wdev);
3444 pwdev_priv = wdev_to_priv(wdev);
3446 rtw_cfg80211_indicate_scan_done(pwdev_priv, true);
3448 if (pwdev_priv->pmon_ndev) {
3449 DBG_8723A("%s, unregister monitor interface\n", __func__);
3450 unregister_netdev(pwdev_priv->pmon_ndev);
3453 wiphy_unregister(wdev->wiphy);