GNU Linux-libre 4.14.266-gnu1
[releases.git] / drivers / staging / rtl8723bs / os_dep / mlme_linux.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  ******************************************************************************/
15
16
17 #define _MLME_OSDEP_C_
18
19 #include <drv_types.h>
20 #include <rtw_debug.h>
21
22 static void _dynamic_check_timer_handlder (void *FunctionContext)
23 {
24         struct adapter *adapter = FunctionContext;
25
26         rtw_dynamic_check_timer_handlder(adapter);
27
28         _set_timer(&adapter->mlmepriv.dynamic_chk_timer, 2000);
29 }
30
31 static void _rtw_set_scan_deny_timer_hdl(void *FunctionContext)
32 {
33         struct adapter *adapter = FunctionContext;
34         rtw_set_scan_deny_timer_hdl(adapter);
35 }
36
37 void rtw_init_mlme_timer(struct adapter *padapter)
38 {
39         struct  mlme_priv *pmlmepriv = &padapter->mlmepriv;
40
41         _init_timer(&(pmlmepriv->assoc_timer), padapter->pnetdev, _rtw_join_timeout_handler, padapter);
42         /* _init_timer(&(pmlmepriv->sitesurveyctrl.sitesurvey_ctrl_timer), padapter->pnetdev, sitesurvey_ctrl_handler, padapter); */
43         _init_timer(&(pmlmepriv->scan_to_timer), padapter->pnetdev, rtw_scan_timeout_handler, padapter);
44
45         _init_timer(&(pmlmepriv->dynamic_chk_timer), padapter->pnetdev, _dynamic_check_timer_handlder, padapter);
46
47         _init_timer(&(pmlmepriv->set_scan_deny_timer), padapter->pnetdev, _rtw_set_scan_deny_timer_hdl, padapter);
48 }
49
50 void rtw_os_indicate_connect(struct adapter *adapter)
51 {
52         struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
53
54         if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ==true) ||
55                 (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ==true))
56         {
57                 rtw_cfg80211_ibss_indicate_connect(adapter);
58         }
59         else
60                 rtw_cfg80211_indicate_connect(adapter);
61
62         rtw_indicate_wx_assoc_event(adapter);
63         netif_carrier_on(adapter->pnetdev);
64
65         if (adapter->pid[2] != 0)
66                 rtw_signal_process(adapter->pid[2], SIGALRM);
67 }
68
69 void rtw_os_indicate_scan_done(struct adapter *padapter, bool aborted)
70 {
71         rtw_cfg80211_indicate_scan_done(padapter, aborted);
72         indicate_wx_scan_complete_event(padapter);
73 }
74
75 static RT_PMKID_LIST   backupPMKIDList[ NUM_PMKID_CACHE ];
76 void rtw_reset_securitypriv(struct adapter *adapter)
77 {
78         u8 backupPMKIDIndex = 0;
79         u8 backupTKIPCountermeasure = 0x00;
80         u32 backupTKIPcountermeasure_time = 0;
81         /*  add for CONFIG_IEEE80211W, none 11w also can use */
82         struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
83
84         spin_lock_bh(&adapter->security_key_mutex);
85
86         if (adapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)/* 802.1x */
87         {
88                 /*  Added by Albert 2009/02/18 */
89                 /*  We have to backup the PMK information for WiFi PMK Caching test item. */
90                 /*  */
91                 /*  Backup the btkip_countermeasure information. */
92                 /*  When the countermeasure is trigger, the driver have to disconnect with AP for 60 seconds. */
93
94                 memcpy(&backupPMKIDList[ 0 ], &adapter->securitypriv.PMKIDList[ 0 ], sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE);
95                 backupPMKIDIndex = adapter->securitypriv.PMKIDIndex;
96                 backupTKIPCountermeasure = adapter->securitypriv.btkip_countermeasure;
97                 backupTKIPcountermeasure_time = adapter->securitypriv.btkip_countermeasure_time;
98
99                 /* reset RX BIP packet number */
100                 pmlmeext->mgnt_80211w_IPN_rx = 0;
101
102                 memset((unsigned char *)&adapter->securitypriv, 0, sizeof (struct security_priv));
103
104                 /*  Added by Albert 2009/02/18 */
105                 /*  Restore the PMK information to securitypriv structure for the following connection. */
106                 memcpy(&adapter->securitypriv.PMKIDList[ 0 ], &backupPMKIDList[ 0 ], sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE);
107                 adapter->securitypriv.PMKIDIndex = backupPMKIDIndex;
108                 adapter->securitypriv.btkip_countermeasure = backupTKIPCountermeasure;
109                 adapter->securitypriv.btkip_countermeasure_time = backupTKIPcountermeasure_time;
110
111                 adapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
112                 adapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
113
114         }
115         else /* reset values in securitypriv */
116         {
117                 /* if (adapter->mlmepriv.fw_state & WIFI_STATION_STATE) */
118                 /*  */
119                 struct security_priv *psec_priv =&adapter->securitypriv;
120
121                 psec_priv->dot11AuthAlgrthm =dot11AuthAlgrthm_Open;  /* open system */
122                 psec_priv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
123                 psec_priv->dot11PrivacyKeyIndex = 0;
124
125                 psec_priv->dot118021XGrpPrivacy = _NO_PRIVACY_;
126                 psec_priv->dot118021XGrpKeyid = 1;
127
128                 psec_priv->ndisauthtype = Ndis802_11AuthModeOpen;
129                 psec_priv->ndisencryptstatus = Ndis802_11WEPDisabled;
130                 /*  */
131         }
132         /*  add for CONFIG_IEEE80211W, none 11w also can use */
133         spin_unlock_bh(&adapter->security_key_mutex);
134 }
135
136 void rtw_os_indicate_disconnect(struct adapter *adapter)
137 {
138         /* RT_PMKID_LIST   backupPMKIDList[ NUM_PMKID_CACHE ]; */
139
140         netif_carrier_off(adapter->pnetdev); /*  Do it first for tx broadcast pkt after disconnection issue! */
141
142         rtw_cfg80211_indicate_disconnect(adapter);
143
144         rtw_indicate_wx_disassoc_event(adapter);
145
146         /* modify for CONFIG_IEEE80211W, none 11w also can use the same command */
147         rtw_reset_securitypriv_cmd(adapter);
148 }
149
150 void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie)
151 {
152         uint    len;
153         u8 *buff,*p, i;
154         union iwreq_data wrqu;
155
156         RT_TRACE(_module_mlme_osdep_c_, _drv_info_, ("+rtw_report_sec_ie, authmode =%d\n", authmode));
157
158         buff = NULL;
159         if (authmode == _WPA_IE_ID_)
160         {
161                 RT_TRACE(_module_mlme_osdep_c_, _drv_info_, ("rtw_report_sec_ie, authmode =%d\n", authmode));
162
163                 buff = rtw_zmalloc(IW_CUSTOM_MAX);
164                 if (NULL == buff) {
165                         DBG_871X(FUNC_ADPT_FMT ": alloc memory FAIL!!\n",
166                                 FUNC_ADPT_ARG(adapter));
167                         return;
168                 }
169                 p = buff;
170
171                 p+=sprintf(p,"ASSOCINFO(ReqIEs =");
172
173                 len = sec_ie[1]+2;
174                 len = (len < IW_CUSTOM_MAX) ? len:IW_CUSTOM_MAX;
175
176                 for (i = 0;i<len;i++) {
177                         p+=sprintf(p,"%02x", sec_ie[i]);
178                 }
179
180                 p+=sprintf(p,")");
181
182                 memset(&wrqu, 0, sizeof(wrqu));
183
184                 wrqu.data.length =p-buff;
185
186                 wrqu.data.length = (wrqu.data.length<IW_CUSTOM_MAX) ? wrqu.data.length:IW_CUSTOM_MAX;
187
188                 kfree(buff);
189         }
190 }
191
192 void init_addba_retry_timer(struct adapter *padapter, struct sta_info *psta)
193 {
194         _init_timer(&psta->addba_retry_timer, padapter->pnetdev, addba_timer_hdl, psta);
195 }
196
197 void init_mlme_ext_timer(struct adapter *padapter)
198 {
199         struct  mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
200
201         _init_timer(&pmlmeext->survey_timer, padapter->pnetdev, survey_timer_hdl, padapter);
202         _init_timer(&pmlmeext->link_timer, padapter->pnetdev, link_timer_hdl, padapter);
203         _init_timer(&pmlmeext->sa_query_timer, padapter->pnetdev, sa_query_timer_hdl, padapter);
204 }