GNU Linux-libre 5.19-rc6-gnu
[releases.git] / drivers / staging / r8188eu / os_dep / mlme_linux.c
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
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
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
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
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
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
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
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                 memcpy(&backup_pmkid[0], &adapter->securitypriv.PMKIDList[0], sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
70                 backup_index = adapter->securitypriv.PMKIDIndex;
71                 backup_counter = adapter->securitypriv.btkip_countermeasure;
72                 backup_time = adapter->securitypriv.btkip_countermeasure_time;
73                 memset((unsigned char *)&adapter->securitypriv, 0, sizeof(struct security_priv));
74
75                 /*  Restore the PMK information to securitypriv structure for the following connection. */
76                 memcpy(&adapter->securitypriv.PMKIDList[0],
77                             &backup_pmkid[0],
78                             sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
79                 adapter->securitypriv.PMKIDIndex = backup_index;
80                 adapter->securitypriv.btkip_countermeasure = backup_counter;
81                 adapter->securitypriv.btkip_countermeasure_time = backup_time;
82                 adapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
83                 adapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
84         } else {
85                 /* reset values in securitypriv */
86                 struct security_priv *psec_priv = &adapter->securitypriv;
87
88                 psec_priv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;  /* open system */
89                 psec_priv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
90                 psec_priv->dot11PrivacyKeyIndex = 0;
91                 psec_priv->dot118021XGrpPrivacy = _NO_PRIVACY_;
92                 psec_priv->dot118021XGrpKeyid = 1;
93                 psec_priv->ndisauthtype = Ndis802_11AuthModeOpen;
94                 psec_priv->ndisencryptstatus = Ndis802_11WEPDisabled;
95         }
96 }
97
98 void rtw_os_indicate_disconnect(struct adapter *adapter)
99 {
100
101         netif_carrier_off(adapter->pnetdev); /*  Do it first for tx broadcast pkt after disconnection issue! */
102         rtw_indicate_wx_disassoc_event(adapter);
103         rtw_reset_securitypriv(adapter);
104 }
105
106 void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie)
107 {
108         uint    len;
109         u8      *buff, *p, i;
110         union iwreq_data wrqu;
111
112         buff = NULL;
113         if (authmode == _WPA_IE_ID_) {
114                 buff = kzalloc(IW_CUSTOM_MAX, GFP_ATOMIC);
115                 if (!buff)
116                         return;
117                 p = buff;
118                 p += sprintf(p, "ASSOCINFO(ReqIEs =");
119                 len = sec_ie[1] + 2;
120                 len =  (len < IW_CUSTOM_MAX) ? len : IW_CUSTOM_MAX;
121                 for (i = 0; i < len; i++)
122                         p += sprintf(p, "%02x", sec_ie[i]);
123                 p += sprintf(p, ")");
124                 memset(&wrqu, 0, sizeof(wrqu));
125                 wrqu.data.length = p - buff;
126                 wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ?
127                                    wrqu.data.length : IW_CUSTOM_MAX;
128                 wireless_send_event(adapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
129                 kfree(buff);
130         }
131 }
132
133 static void _survey_timer_hdl(struct timer_list *t)
134 {
135         struct adapter *padapter = from_timer(padapter, t, mlmeextpriv.survey_timer);
136
137         survey_timer_hdl(padapter);
138 }
139
140 static void _link_timer_hdl(struct timer_list *t)
141 {
142         struct adapter *padapter = from_timer(padapter, t, mlmeextpriv.link_timer);
143         link_timer_hdl(padapter);
144 }
145
146 static void _addba_timer_hdl(struct timer_list *t)
147 {
148         struct sta_info *psta = from_timer(psta, t, addba_retry_timer);
149         addba_timer_hdl(psta);
150 }
151
152 void init_addba_retry_timer(struct adapter *padapter, struct sta_info *psta)
153 {
154         timer_setup(&psta->addba_retry_timer, _addba_timer_hdl, 0);
155 }
156
157 void init_mlme_ext_timer(struct adapter *padapter)
158 {
159         struct  mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
160
161         timer_setup(&pmlmeext->survey_timer, _survey_timer_hdl, 0);
162         timer_setup(&pmlmeext->link_timer, _link_timer_hdl, 0);
163 }
164
165 void rtw_indicate_sta_assoc_event(struct adapter *padapter, struct sta_info *psta)
166 {
167         union iwreq_data wrqu;
168         struct sta_priv *pstapriv = &padapter->stapriv;
169
170         if (!psta)
171                 return;
172
173         if (psta->aid > NUM_STA)
174                 return;
175
176         if (pstapriv->sta_aid[psta->aid - 1] != psta)
177                 return;
178
179         wrqu.addr.sa_family = ARPHRD_ETHER;
180
181         memcpy(wrqu.addr.sa_data, psta->hwaddr, ETH_ALEN);
182
183         wireless_send_event(padapter->pnetdev, IWEVREGISTERED, &wrqu, NULL);
184 }
185
186 void rtw_indicate_sta_disassoc_event(struct adapter *padapter, struct sta_info *psta)
187 {
188         union iwreq_data wrqu;
189         struct sta_priv *pstapriv = &padapter->stapriv;
190
191         if (!psta)
192                 return;
193
194         if (psta->aid > NUM_STA)
195                 return;
196
197         if (pstapriv->sta_aid[psta->aid - 1] != psta)
198                 return;
199
200         wrqu.addr.sa_family = ARPHRD_ETHER;
201
202         memcpy(wrqu.addr.sa_data, psta->hwaddr, ETH_ALEN);
203
204         wireless_send_event(padapter->pnetdev, IWEVEXPIRED, &wrqu, NULL);
205 }