1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2011 Realtek Corporation. i*/
3
4 #define _MLME_OSDEP_C_
5
6 #include "../include/osdep_service.h"
7 #include "../include/drv_types.h"
8 #include "../include/mlme_osdep.h"
9
rtw_join_timeout_handler(struct timer_list * t)10 void rtw_join_timeout_handler (struct timer_list *t)
11 {
12 struct adapter *adapter = from_timer(adapter, t, mlmepriv.assoc_timer);
13
14 _rtw_join_timeout_handler(adapter);
15 }
16
_rtw_scan_timeout_handler(struct timer_list * t)17 void _rtw_scan_timeout_handler (struct timer_list *t)
18 {
19 struct adapter *adapter = from_timer(adapter, t, mlmepriv.scan_to_timer);
20
21 rtw_scan_timeout_handler(adapter);
22 }
23
_dynamic_check_timer_handlder(struct timer_list * t)24 static void _dynamic_check_timer_handlder(struct timer_list *t)
25 {
26 struct adapter *adapter = from_timer(adapter, t, mlmepriv.dynamic_chk_timer);
27
28 rtw_dynamic_check_timer_handlder(adapter);
29 _set_timer(&adapter->mlmepriv.dynamic_chk_timer, 2000);
30 }
31
rtw_init_mlme_timer(struct adapter * padapter)32 void rtw_init_mlme_timer(struct adapter *padapter)
33 {
34 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
35
36 timer_setup(&pmlmepriv->assoc_timer, rtw_join_timeout_handler, 0);
37 timer_setup(&pmlmepriv->scan_to_timer, _rtw_scan_timeout_handler, 0);
38 timer_setup(&pmlmepriv->dynamic_chk_timer, _dynamic_check_timer_handlder, 0);
39 }
40
rtw_os_indicate_connect(struct adapter * adapter)41 void rtw_os_indicate_connect(struct adapter *adapter)
42 {
43
44 rtw_indicate_wx_assoc_event(adapter);
45 netif_carrier_on(adapter->pnetdev);
46 if (adapter->pid[2] != 0)
47 rtw_signal_process(adapter->pid[2], SIGALRM);
48
49 }
50
rtw_os_indicate_scan_done(struct adapter * padapter,bool aborted)51 void rtw_os_indicate_scan_done(struct adapter *padapter, bool aborted)
52 {
53 indicate_wx_scan_complete_event(padapter);
54 }
55
56 static struct rt_pmkid_list backup_pmkid[NUM_PMKID_CACHE];
57
rtw_reset_securitypriv(struct adapter * adapter)58 void rtw_reset_securitypriv(struct adapter *adapter)
59 {
60 u8 backup_index = 0;
61 u8 backup_counter = 0x00;
62 u32 backup_time = 0;
63
64 if (adapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) {
65 /* 802.1x */
66 /* We have to backup the PMK information for WiFi PMK Caching test item. */
67 /* Backup the btkip_countermeasure information. */
68 /* When the countermeasure is trigger, the driver have to disconnect with AP for 60 seconds. */
69 memset(&backup_pmkid[0], 0x00, sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
70 memcpy(&backup_pmkid[0], &adapter->securitypriv.PMKIDList[0], sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
71 backup_index = adapter->securitypriv.PMKIDIndex;
72 backup_counter = adapter->securitypriv.btkip_countermeasure;
73 backup_time = adapter->securitypriv.btkip_countermeasure_time;
74 memset((unsigned char *)&adapter->securitypriv, 0, sizeof(struct security_priv));
75
76 /* Restore the PMK information to securitypriv structure for the following connection. */
77 memcpy(&adapter->securitypriv.PMKIDList[0],
78 &backup_pmkid[0],
79 sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
80 adapter->securitypriv.PMKIDIndex = backup_index;
81 adapter->securitypriv.btkip_countermeasure = backup_counter;
82 adapter->securitypriv.btkip_countermeasure_time = backup_time;
83 adapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
84 adapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
85 } else {
86 /* reset values in securitypriv */
87 struct security_priv *psec_priv = &adapter->securitypriv;
88
89 psec_priv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
90 psec_priv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
91 psec_priv->dot11PrivacyKeyIndex = 0;
92 psec_priv->dot118021XGrpPrivacy = _NO_PRIVACY_;
93 psec_priv->dot118021XGrpKeyid = 1;
94 psec_priv->ndisauthtype = Ndis802_11AuthModeOpen;
95 psec_priv->ndisencryptstatus = Ndis802_11WEPDisabled;
96 }
97 }
98
rtw_os_indicate_disconnect(struct adapter * adapter)99 void rtw_os_indicate_disconnect(struct adapter *adapter)
100 {
101
102 netif_carrier_off(adapter->pnetdev); /* Do it first for tx broadcast pkt after disconnection issue! */
103 rtw_indicate_wx_disassoc_event(adapter);
104 rtw_reset_securitypriv(adapter);
105 }
106
rtw_report_sec_ie(struct adapter * adapter,u8 authmode,u8 * sec_ie)107 void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie)
108 {
109 uint len;
110 u8 *buff, *p, i;
111 union iwreq_data wrqu;
112
113 buff = NULL;
114 if (authmode == _WPA_IE_ID_) {
115 buff = kzalloc(IW_CUSTOM_MAX, GFP_ATOMIC);
116 if (!buff)
117 return;
118 p = buff;
119 p += sprintf(p, "ASSOCINFO(ReqIEs =");
120 len = sec_ie[1] + 2;
121 len = (len < IW_CUSTOM_MAX) ? len : IW_CUSTOM_MAX;
122 for (i = 0; i < len; i++)
123 p += sprintf(p, "%02x", sec_ie[i]);
124 p += sprintf(p, ")");
125 memset(&wrqu, 0, sizeof(wrqu));
126 wrqu.data.length = p - buff;
127 wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ?
128 wrqu.data.length : IW_CUSTOM_MAX;
129 wireless_send_event(adapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
130 kfree(buff);
131 }
132 }
133
_survey_timer_hdl(struct timer_list * t)134 static void _survey_timer_hdl(struct timer_list *t)
135 {
136 struct adapter *padapter = from_timer(padapter, t, mlmeextpriv.survey_timer);
137
138 survey_timer_hdl(padapter);
139 }
140
_link_timer_hdl(struct timer_list * t)141 static void _link_timer_hdl(struct timer_list *t)
142 {
143 struct adapter *padapter = from_timer(padapter, t, mlmeextpriv.link_timer);
144 link_timer_hdl(padapter);
145 }
146
_addba_timer_hdl(struct timer_list * t)147 static void _addba_timer_hdl(struct timer_list *t)
148 {
149 struct sta_info *psta = from_timer(psta, t, addba_retry_timer);
150 addba_timer_hdl(psta);
151 }
152
init_addba_retry_timer(struct adapter * padapter,struct sta_info * psta)153 void init_addba_retry_timer(struct adapter *padapter, struct sta_info *psta)
154 {
155 timer_setup(&psta->addba_retry_timer, _addba_timer_hdl, 0);
156 }
157
init_mlme_ext_timer(struct adapter * padapter)158 void init_mlme_ext_timer(struct adapter *padapter)
159 {
160 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
161
162 timer_setup(&pmlmeext->survey_timer, _survey_timer_hdl, 0);
163 timer_setup(&pmlmeext->link_timer, _link_timer_hdl, 0);
164 }
165
rtw_indicate_sta_assoc_event(struct adapter * padapter,struct sta_info * psta)166 void rtw_indicate_sta_assoc_event(struct adapter *padapter, struct sta_info *psta)
167 {
168 union iwreq_data wrqu;
169 struct sta_priv *pstapriv = &padapter->stapriv;
170
171 if (!psta)
172 return;
173
174 if (psta->aid > NUM_STA)
175 return;
176
177 if (pstapriv->sta_aid[psta->aid - 1] != psta)
178 return;
179
180 wrqu.addr.sa_family = ARPHRD_ETHER;
181
182 memcpy(wrqu.addr.sa_data, psta->hwaddr, ETH_ALEN);
183
184 DBG_88E("+rtw_indicate_sta_assoc_event\n");
185
186 wireless_send_event(padapter->pnetdev, IWEVREGISTERED, &wrqu, NULL);
187 }
188
rtw_indicate_sta_disassoc_event(struct adapter * padapter,struct sta_info * psta)189 void rtw_indicate_sta_disassoc_event(struct adapter *padapter, struct sta_info *psta)
190 {
191 union iwreq_data wrqu;
192 struct sta_priv *pstapriv = &padapter->stapriv;
193
194 if (!psta)
195 return;
196
197 if (psta->aid > NUM_STA)
198 return;
199
200 if (pstapriv->sta_aid[psta->aid - 1] != psta)
201 return;
202
203 wrqu.addr.sa_family = ARPHRD_ETHER;
204
205 memcpy(wrqu.addr.sa_data, psta->hwaddr, ETH_ALEN);
206
207 DBG_88E("+rtw_indicate_sta_disassoc_event\n");
208
209 wireless_send_event(padapter->pnetdev, IWEVEXPIRED, &wrqu, NULL);
210 }
211