OSDN Git Service

staging: rtl8723bs: update to the latest driver
[android-x86/kernel.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 = (struct 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 = (struct 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                 memset(&backupPMKIDList[ 0 ], 0x00, sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE);
95
96                 memcpy(&backupPMKIDList[ 0 ], &adapter->securitypriv.PMKIDList[ 0 ], sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE);
97                 backupPMKIDIndex = adapter->securitypriv.PMKIDIndex;
98                 backupTKIPCountermeasure = adapter->securitypriv.btkip_countermeasure;
99                 backupTKIPcountermeasure_time = adapter->securitypriv.btkip_countermeasure_time;
100
101                 /* reset RX BIP packet number */
102                 pmlmeext->mgnt_80211w_IPN_rx = 0;
103
104                 memset((unsigned char *)&adapter->securitypriv, 0, sizeof (struct security_priv));
105
106                 /*  Added by Albert 2009/02/18 */
107                 /*  Restore the PMK information to securitypriv structure for the following connection. */
108                 memcpy(&adapter->securitypriv.PMKIDList[ 0 ], &backupPMKIDList[ 0 ], sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE);
109                 adapter->securitypriv.PMKIDIndex = backupPMKIDIndex;
110                 adapter->securitypriv.btkip_countermeasure = backupTKIPCountermeasure;
111                 adapter->securitypriv.btkip_countermeasure_time = backupTKIPcountermeasure_time;
112
113                 adapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
114                 adapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
115
116         }
117         else /* reset values in securitypriv */
118         {
119                 /* if (adapter->mlmepriv.fw_state & WIFI_STATION_STATE) */
120                 /*  */
121                 struct security_priv *psec_priv =&adapter->securitypriv;
122
123                 psec_priv->dot11AuthAlgrthm =dot11AuthAlgrthm_Open;  /* open system */
124                 psec_priv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
125                 psec_priv->dot11PrivacyKeyIndex = 0;
126
127                 psec_priv->dot118021XGrpPrivacy = _NO_PRIVACY_;
128                 psec_priv->dot118021XGrpKeyid = 1;
129
130                 psec_priv->ndisauthtype = Ndis802_11AuthModeOpen;
131                 psec_priv->ndisencryptstatus = Ndis802_11WEPDisabled;
132                 /*  */
133         }
134         /*  add for CONFIG_IEEE80211W, none 11w also can use */
135         spin_unlock_bh(&adapter->security_key_mutex);
136 }
137
138 void rtw_os_indicate_disconnect(struct adapter *adapter)
139 {
140         /* RT_PMKID_LIST   backupPMKIDList[ NUM_PMKID_CACHE ]; */
141
142         netif_carrier_off(adapter->pnetdev); /*  Do it first for tx broadcast pkt after disconnection issue! */
143
144         rtw_cfg80211_indicate_disconnect(adapter);
145
146         rtw_indicate_wx_disassoc_event(adapter);
147
148          /* modify for CONFIG_IEEE80211W, none 11w also can use the same command */
149          rtw_reset_securitypriv_cmd(adapter);
150 }
151
152 void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie)
153 {
154         uint    len;
155         u8 *buff,*p, i;
156         union iwreq_data wrqu;
157
158         RT_TRACE(_module_mlme_osdep_c_, _drv_info_, ("+rtw_report_sec_ie, authmode =%d\n", authmode));
159
160         buff = NULL;
161         if (authmode == _WPA_IE_ID_)
162         {
163                 RT_TRACE(_module_mlme_osdep_c_, _drv_info_, ("rtw_report_sec_ie, authmode =%d\n", authmode));
164
165                 buff = rtw_zmalloc(IW_CUSTOM_MAX);
166                 if (NULL == buff) {
167                         DBG_871X(FUNC_ADPT_FMT ": alloc memory FAIL!!\n",
168                                 FUNC_ADPT_ARG(adapter));
169                         return;
170                 }
171                 p = buff;
172
173                 p+=sprintf(p,"ASSOCINFO(ReqIEs =");
174
175                 len = sec_ie[1]+2;
176                 len = (len < IW_CUSTOM_MAX) ? len:IW_CUSTOM_MAX;
177
178                 for (i = 0;i<len;i++) {
179                         p+=sprintf(p,"%02x", sec_ie[i]);
180                 }
181
182                 p+=sprintf(p,")");
183
184                 memset(&wrqu, 0, sizeof(wrqu));
185
186                 wrqu.data.length =p-buff;
187
188                 wrqu.data.length = (wrqu.data.length<IW_CUSTOM_MAX) ? wrqu.data.length:IW_CUSTOM_MAX;
189
190                 kfree(buff);
191         }
192 }
193
194 void init_addba_retry_timer(struct adapter *padapter, struct sta_info *psta)
195 {
196         _init_timer(&psta->addba_retry_timer, padapter->pnetdev, addba_timer_hdl, psta);
197 }
198
199 void init_mlme_ext_timer(struct adapter *padapter)
200 {
201         struct  mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
202
203         _init_timer(&pmlmeext->survey_timer, padapter->pnetdev, survey_timer_hdl, padapter);
204         _init_timer(&pmlmeext->link_timer, padapter->pnetdev, link_timer_hdl, padapter);
205         _init_timer(&pmlmeext->sa_query_timer, padapter->pnetdev, sa_query_timer_hdl, padapter);
206 }