1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3 *
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 *
6 ******************************************************************************/
7 #include <drv_types.h>
8
_dynamic_check_timer_handler(struct timer_list * t)9 static void _dynamic_check_timer_handler(struct timer_list *t)
10 {
11 struct adapter *adapter =
12 from_timer(adapter, t, mlmepriv.dynamic_chk_timer);
13
14 rtw_dynamic_check_timer_handler(adapter);
15
16 _set_timer(&adapter->mlmepriv.dynamic_chk_timer, 2000);
17 }
18
_rtw_set_scan_deny_timer_hdl(struct timer_list * t)19 static void _rtw_set_scan_deny_timer_hdl(struct timer_list *t)
20 {
21 struct adapter *adapter =
22 from_timer(adapter, t, mlmepriv.set_scan_deny_timer);
23
24 rtw_clear_scan_deny(adapter);
25 }
26
rtw_init_mlme_timer(struct adapter * padapter)27 void rtw_init_mlme_timer(struct adapter *padapter)
28 {
29 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
30
31 timer_setup(&pmlmepriv->assoc_timer, _rtw_join_timeout_handler, 0);
32 timer_setup(&pmlmepriv->scan_to_timer, rtw_scan_timeout_handler, 0);
33 timer_setup(&pmlmepriv->dynamic_chk_timer,
34 _dynamic_check_timer_handler, 0);
35 timer_setup(&pmlmepriv->set_scan_deny_timer,
36 _rtw_set_scan_deny_timer_hdl, 0);
37 }
38
rtw_os_indicate_connect(struct adapter * adapter)39 void rtw_os_indicate_connect(struct adapter *adapter)
40 {
41 struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
42
43 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) ||
44 (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true)) {
45 rtw_cfg80211_ibss_indicate_connect(adapter);
46 } else {
47 rtw_cfg80211_indicate_connect(adapter);
48 }
49
50 netif_carrier_on(adapter->pnetdev);
51
52 if (adapter->pid[2] != 0)
53 rtw_signal_process(adapter->pid[2], SIGALRM);
54 }
55
rtw_os_indicate_scan_done(struct adapter * padapter,bool aborted)56 void rtw_os_indicate_scan_done(struct adapter *padapter, bool aborted)
57 {
58 rtw_cfg80211_indicate_scan_done(padapter, aborted);
59 }
60
61 static struct rt_pmkid_list backupPMKIDList[NUM_PMKID_CACHE];
rtw_reset_securitypriv(struct adapter * adapter)62 void rtw_reset_securitypriv(struct adapter *adapter)
63 {
64 u8 backupPMKIDIndex = 0;
65 u8 backupTKIPCountermeasure = 0x00;
66 u32 backupTKIPcountermeasure_time = 0;
67 /* add for CONFIG_IEEE80211W, none 11w also can use */
68 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
69
70 spin_lock_bh(&adapter->security_key_mutex);
71
72 if (adapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) {
73 /* 802.1x */
74 /* Added by Albert 2009/02/18 */
75 /* We have to backup the PMK information for WiFi PMK Caching test item. */
76 /* */
77 /* Backup the btkip_countermeasure information. */
78 /* When the countermeasure is trigger, the driver have to disconnect with AP for 60 seconds. */
79
80 memcpy(&backupPMKIDList[0], &adapter->securitypriv.PMKIDList[0], sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
81 backupPMKIDIndex = adapter->securitypriv.PMKIDIndex;
82 backupTKIPCountermeasure = adapter->securitypriv.btkip_countermeasure;
83 backupTKIPcountermeasure_time = adapter->securitypriv.btkip_countermeasure_time;
84
85 /* reset RX BIP packet number */
86 pmlmeext->mgnt_80211w_IPN_rx = 0;
87
88 memset((unsigned char *)&adapter->securitypriv, 0, sizeof(struct security_priv));
89
90 /* Added by Albert 2009/02/18 */
91 /* Restore the PMK information to securitypriv structure for the following connection. */
92 memcpy(&adapter->securitypriv.PMKIDList[0], &backupPMKIDList[0], sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
93 adapter->securitypriv.PMKIDIndex = backupPMKIDIndex;
94 adapter->securitypriv.btkip_countermeasure = backupTKIPCountermeasure;
95 adapter->securitypriv.btkip_countermeasure_time = backupTKIPcountermeasure_time;
96
97 adapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
98 adapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
99
100 } else {
101 /* reset values in securitypriv */
102 /* if (adapter->mlmepriv.fw_state & WIFI_STATION_STATE) */
103 /* */
104 struct security_priv *psec_priv = &adapter->securitypriv;
105
106 psec_priv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
107 psec_priv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
108 psec_priv->dot11PrivacyKeyIndex = 0;
109
110 psec_priv->dot118021XGrpPrivacy = _NO_PRIVACY_;
111 psec_priv->dot118021XGrpKeyid = 1;
112
113 psec_priv->ndisauthtype = Ndis802_11AuthModeOpen;
114 psec_priv->ndisencryptstatus = Ndis802_11WEPDisabled;
115 /* */
116 }
117 /* add for CONFIG_IEEE80211W, none 11w also can use */
118 spin_unlock_bh(&adapter->security_key_mutex);
119 }
120
rtw_os_indicate_disconnect(struct adapter * adapter)121 void rtw_os_indicate_disconnect(struct adapter *adapter)
122 {
123 /* struct rt_pmkid_list backupPMKIDList[ NUM_PMKID_CACHE ]; */
124
125 netif_carrier_off(adapter->pnetdev); /* Do it first for tx broadcast pkt after disconnection issue! */
126
127 rtw_cfg80211_indicate_disconnect(adapter);
128
129 /* modify for CONFIG_IEEE80211W, none 11w also can use the same command */
130 rtw_reset_securitypriv_cmd(adapter);
131 }
132
rtw_report_sec_ie(struct adapter * adapter,u8 authmode,u8 * sec_ie)133 void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie)
134 {
135 uint len;
136 u8 *buff, *p, i;
137 union iwreq_data wrqu;
138
139 buff = NULL;
140 if (authmode == WLAN_EID_VENDOR_SPECIFIC) {
141 buff = rtw_zmalloc(IW_CUSTOM_MAX);
142 if (!buff)
143 return;
144
145 p = buff;
146
147 p += scnprintf(p, IW_CUSTOM_MAX - (p - buff), "ASSOCINFO(ReqIEs =");
148
149 len = sec_ie[1] + 2;
150 len = (len < IW_CUSTOM_MAX) ? len : IW_CUSTOM_MAX;
151
152 for (i = 0; i < len; i++)
153 p += scnprintf(p, IW_CUSTOM_MAX - (p - buff), "%02x", sec_ie[i]);
154
155 p += scnprintf(p, IW_CUSTOM_MAX - (p - buff), ")");
156
157 memset(&wrqu, 0, sizeof(wrqu));
158
159 wrqu.data.length = p - buff;
160
161 wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ? wrqu.data.length : IW_CUSTOM_MAX;
162
163 kfree(buff);
164 }
165 }
166
init_addba_retry_timer(struct adapter * padapter,struct sta_info * psta)167 void init_addba_retry_timer(struct adapter *padapter, struct sta_info *psta)
168 {
169 timer_setup(&psta->addba_retry_timer, addba_timer_hdl, 0);
170 }
171
init_mlme_ext_timer(struct adapter * padapter)172 void init_mlme_ext_timer(struct adapter *padapter)
173 {
174 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
175
176 timer_setup(&pmlmeext->survey_timer, survey_timer_hdl, 0);
177 timer_setup(&pmlmeext->link_timer, link_timer_hdl, 0);
178 timer_setup(&pmlmeext->sa_query_timer, sa_query_timer_hdl, 0);
179 }
180