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