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