1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3  * mlme_linux.c
4  *
5  * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
6  * Linux device driver for RTL8192SU
7  *
8  * Modifications for inclusion into the Linux staging tree are
9  * Copyright(c) 2010 Larry Finger. All rights reserved.
10  *
11  * Contact information:
12  * WLAN FAE <wlanfae@realtek.com>.
13  * Larry Finger <Larry.Finger@lwfinger.net>
14  *
15  ******************************************************************************/
16 
17 #define _MLME_OSDEP_C_
18 
19 #include "osdep_service.h"
20 #include "drv_types.h"
21 #include "mlme_osdep.h"
22 
sitesurvey_ctrl_handler(struct timer_list * t)23 static void sitesurvey_ctrl_handler(struct timer_list *t)
24 {
25 	struct _adapter *adapter =
26 		from_timer(adapter, t,
27 			   mlmepriv.sitesurveyctrl.sitesurvey_ctrl_timer);
28 
29 	_r8712_sitesurvey_ctrl_handler(adapter);
30 	mod_timer(&adapter->mlmepriv.sitesurveyctrl.sitesurvey_ctrl_timer,
31 		  jiffies + msecs_to_jiffies(3000));
32 }
33 
join_timeout_handler(struct timer_list * t)34 static void join_timeout_handler (struct timer_list *t)
35 {
36 	struct _adapter *adapter =
37 		from_timer(adapter, t, mlmepriv.assoc_timer);
38 
39 	_r8712_join_timeout_handler(adapter);
40 }
41 
_scan_timeout_handler(struct timer_list * t)42 static void _scan_timeout_handler (struct timer_list *t)
43 {
44 	struct _adapter *adapter =
45 		from_timer(adapter, t, mlmepriv.scan_to_timer);
46 
47 	r8712_scan_timeout_handler(adapter);
48 }
49 
dhcp_timeout_handler(struct timer_list * t)50 static void dhcp_timeout_handler (struct timer_list *t)
51 {
52 	struct _adapter *adapter =
53 		from_timer(adapter, t, mlmepriv.dhcp_timer);
54 
55 	_r8712_dhcp_timeout_handler(adapter);
56 }
57 
wdg_timeout_handler(struct timer_list * t)58 static void wdg_timeout_handler (struct timer_list *t)
59 {
60 	struct _adapter *adapter =
61 		from_timer(adapter, t, mlmepriv.wdg_timer);
62 
63 	r8712_wdg_wk_cmd(adapter);
64 
65 	mod_timer(&adapter->mlmepriv.wdg_timer,
66 		  jiffies + msecs_to_jiffies(2000));
67 }
68 
r8712_init_mlme_timer(struct _adapter * adapter)69 void r8712_init_mlme_timer(struct _adapter *adapter)
70 {
71 	struct	mlme_priv *mlmepriv = &adapter->mlmepriv;
72 
73 	timer_setup(&mlmepriv->assoc_timer, join_timeout_handler, 0);
74 	timer_setup(&mlmepriv->sitesurveyctrl.sitesurvey_ctrl_timer,
75 		    sitesurvey_ctrl_handler, 0);
76 	timer_setup(&mlmepriv->scan_to_timer, _scan_timeout_handler, 0);
77 	timer_setup(&mlmepriv->dhcp_timer, dhcp_timeout_handler, 0);
78 	timer_setup(&mlmepriv->wdg_timer, wdg_timeout_handler, 0);
79 }
80 
r8712_os_indicate_connect(struct _adapter * adapter)81 void r8712_os_indicate_connect(struct _adapter *adapter)
82 {
83 	r8712_indicate_wx_assoc_event(adapter);
84 	netif_carrier_on(adapter->pnetdev);
85 }
86 
87 static struct RT_PMKID_LIST backup_PMKID_list[NUM_PMKID_CACHE];
r8712_os_indicate_disconnect(struct _adapter * adapter)88 void r8712_os_indicate_disconnect(struct _adapter *adapter)
89 {
90 	u8 backup_PMKID_index = 0;
91 	u8 backup_TKIP_countermeasure = 0x00;
92 
93 	r8712_indicate_wx_disassoc_event(adapter);
94 	netif_carrier_off(adapter->pnetdev);
95 	if (adapter->securitypriv.AuthAlgrthm == 2) { /*/802.1x*/
96 		/* We have to backup the PMK information for WiFi PMK Caching
97 		 * test item. Backup the btkip_countermeasure information.
98 		 * When the countermeasure is trigger, the driver have to
99 		 * disconnect with AP for 60 seconds.
100 		 */
101 
102 		memcpy(&backup_PMKID_list[0],
103 		       &adapter->securitypriv.PMKIDList[0],
104 		       sizeof(struct RT_PMKID_LIST) * NUM_PMKID_CACHE);
105 		backup_PMKID_index = adapter->securitypriv.PMKIDIndex;
106 		backup_TKIP_countermeasure =
107 			adapter->securitypriv.btkip_countermeasure;
108 		memset((unsigned char *)&adapter->securitypriv, 0,
109 		       sizeof(struct security_priv));
110 		timer_setup(&adapter->securitypriv.tkip_timer,
111 			    r8712_use_tkipkey_handler, 0);
112 		/* Restore the PMK information to securitypriv structure
113 		 * for the following connection.
114 		 */
115 		memcpy(&adapter->securitypriv.PMKIDList[0],
116 		       &backup_PMKID_list[0],
117 		       sizeof(struct RT_PMKID_LIST) * NUM_PMKID_CACHE);
118 		adapter->securitypriv.PMKIDIndex = backup_PMKID_index;
119 		adapter->securitypriv.btkip_countermeasure =
120 					 backup_TKIP_countermeasure;
121 	} else { /*reset values in securitypriv*/
122 		struct security_priv *sec_priv = &adapter->securitypriv;
123 
124 		sec_priv->AuthAlgrthm = 0; /*open system*/
125 		sec_priv->PrivacyAlgrthm = _NO_PRIVACY_;
126 		sec_priv->PrivacyKeyIndex = 0;
127 		sec_priv->XGrpPrivacy = _NO_PRIVACY_;
128 		sec_priv->XGrpKeyid = 1;
129 		sec_priv->ndisauthtype = Ndis802_11AuthModeOpen;
130 		sec_priv->ndisencryptstatus = Ndis802_11WEPDisabled;
131 		sec_priv->wps_phase = false;
132 	}
133 }
134 
r8712_report_sec_ie(struct _adapter * adapter,u8 authmode,u8 * sec_ie)135 void r8712_report_sec_ie(struct _adapter *adapter, u8 authmode, u8 *sec_ie)
136 {
137 	uint len;
138 	u8 *buff, *p, i;
139 	union iwreq_data wrqu;
140 
141 	buff = NULL;
142 	if (authmode == _WPA_IE_ID_) {
143 		buff = kzalloc(IW_CUSTOM_MAX, GFP_ATOMIC);
144 		if (!buff)
145 			return;
146 		p = buff;
147 		p += sprintf(p, "ASSOCINFO(ReqIEs=");
148 		len = sec_ie[1] + 2;
149 		len =  (len < IW_CUSTOM_MAX) ? len : IW_CUSTOM_MAX;
150 		for (i = 0; i < len; i++)
151 			p += sprintf(p, "%02x", sec_ie[i]);
152 		p += sprintf(p, ")");
153 		memset(&wrqu, 0, sizeof(wrqu));
154 		wrqu.data.length = p - buff;
155 		wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ?
156 				   wrqu.data.length : IW_CUSTOM_MAX;
157 		wireless_send_event(adapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
158 		kfree(buff);
159 	}
160 }
161