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 
rtw_init_mlme_timer(struct adapter * padapter)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 
rtw_os_indicate_connect(struct adapter * adapter)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 
rtw_os_indicate_scan_done(struct adapter * padapter,bool aborted)30 void rtw_os_indicate_scan_done(struct adapter *padapter, bool aborted)
31 {
32 	indicate_wx_scan_complete_event(padapter);
33 }
34 
35 static struct rt_pmkid_list backup_pmkid[NUM_PMKID_CACHE];
36 
rtw_reset_securitypriv(struct adapter * adapter)37 void rtw_reset_securitypriv(struct adapter *adapter)
38 {
39 	u8	backup_index = 0;
40 	u8	backup_counter = 0x00;
41 	u32	backup_time = 0;
42 
43 	if (adapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) {
44 		/* 802.1x */
45 		/*  We have to backup the PMK information for WiFi PMK Caching test item. */
46 		/*  Backup the btkip_countermeasure information. */
47 		/*  When the countermeasure is trigger, the driver have to disconnect with AP for 60 seconds. */
48 		memcpy(&backup_pmkid[0], &adapter->securitypriv.PMKIDList[0], sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
49 		backup_index = adapter->securitypriv.PMKIDIndex;
50 		backup_counter = adapter->securitypriv.btkip_countermeasure;
51 		backup_time = adapter->securitypriv.btkip_countermeasure_time;
52 		memset((unsigned char *)&adapter->securitypriv, 0, sizeof(struct security_priv));
53 
54 		/*  Restore the PMK information to securitypriv structure for the following connection. */
55 		memcpy(&adapter->securitypriv.PMKIDList[0],
56 			    &backup_pmkid[0],
57 			    sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
58 		adapter->securitypriv.PMKIDIndex = backup_index;
59 		adapter->securitypriv.btkip_countermeasure = backup_counter;
60 		adapter->securitypriv.btkip_countermeasure_time = backup_time;
61 		adapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
62 		adapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
63 	} else {
64 		/* reset values in securitypriv */
65 		struct security_priv *psec_priv = &adapter->securitypriv;
66 
67 		psec_priv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
68 		psec_priv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
69 		psec_priv->dot11PrivacyKeyIndex = 0;
70 		psec_priv->dot118021XGrpPrivacy = _NO_PRIVACY_;
71 		psec_priv->dot118021XGrpKeyid = 1;
72 		psec_priv->ndisauthtype = Ndis802_11AuthModeOpen;
73 		psec_priv->ndisencryptstatus = Ndis802_11WEPDisabled;
74 	}
75 }
76 
rtw_os_indicate_disconnect(struct adapter * adapter)77 void rtw_os_indicate_disconnect(struct adapter *adapter)
78 {
79 	netif_carrier_off(adapter->pnetdev); /*  Do it first for tx broadcast pkt after disconnection issue! */
80 	rtw_indicate_wx_disassoc_event(adapter);
81 	 rtw_reset_securitypriv(adapter);
82 }
83 
rtw_report_sec_ie(struct adapter * adapter,u8 authmode,u8 * sec_ie)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 		 ("+rtw_report_sec_ie, authmode=%d\n", authmode));
92 	buff = NULL;
93 	if (authmode == _WPA_IE_ID_) {
94 		RT_TRACE(_module_mlme_osdep_c_, _drv_info_,
95 			 ("rtw_report_sec_ie, authmode=%d\n", 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 = p-buff;
109 		wrqu.data.length = min_t(__u16, wrqu.data.length, IW_CUSTOM_MAX);
110 		wireless_send_event(adapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
111 		kfree(buff);
112 	}
113 }
114 
init_addba_retry_timer(struct adapter * padapter,struct sta_info * psta)115 void init_addba_retry_timer(struct adapter *padapter, struct sta_info *psta)
116 {
117 	timer_setup(&psta->addba_retry_timer, addba_timer_hdl, 0);
118 }
119 
init_mlme_ext_timer(struct adapter * padapter)120 void init_mlme_ext_timer(struct adapter *padapter)
121 {
122 	struct	mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
123 
124 	timer_setup(&pmlmeext->survey_timer, survey_timer_hdl, 0);
125 	timer_setup(&pmlmeext->link_timer, link_timer_hdl, 0);
126 }
127 
128 #ifdef CONFIG_88EU_AP_MODE
129 
rtw_indicate_sta_assoc_event(struct adapter * padapter,struct sta_info * psta)130 void rtw_indicate_sta_assoc_event(struct adapter *padapter, struct sta_info *psta)
131 {
132 	union iwreq_data wrqu;
133 	struct sta_priv *pstapriv = &padapter->stapriv;
134 
135 	if (!psta)
136 		return;
137 
138 	if (psta->aid > NUM_STA)
139 		return;
140 
141 	if (pstapriv->sta_aid[psta->aid - 1] != psta)
142 		return;
143 
144 	wrqu.addr.sa_family = ARPHRD_ETHER;
145 
146 	memcpy(wrqu.addr.sa_data, psta->hwaddr, ETH_ALEN);
147 
148 	DBG_88E("+rtw_indicate_sta_assoc_event\n");
149 
150 	wireless_send_event(padapter->pnetdev, IWEVREGISTERED, &wrqu, NULL);
151 }
152 
rtw_indicate_sta_disassoc_event(struct adapter * padapter,struct sta_info * psta)153 void rtw_indicate_sta_disassoc_event(struct adapter *padapter, struct sta_info *psta)
154 {
155 	union iwreq_data wrqu;
156 	struct sta_priv *pstapriv = &padapter->stapriv;
157 
158 	if (!psta)
159 		return;
160 
161 	if (psta->aid > NUM_STA)
162 		return;
163 
164 	if (pstapriv->sta_aid[psta->aid - 1] != psta)
165 		return;
166 
167 	wrqu.addr.sa_family = ARPHRD_ETHER;
168 
169 	memcpy(wrqu.addr.sa_data, psta->hwaddr, ETH_ALEN);
170 
171 	DBG_88E("+rtw_indicate_sta_disassoc_event\n");
172 
173 	wireless_send_event(padapter->pnetdev, IWEVEXPIRED, &wrqu, NULL);
174 }
175 
176 #endif
177