]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/rtl8712/mlme_linux.c
Merge branches 'acpi-ec', 'acpi-battery' and 'acpi-pmic'
[karo-tx-linux.git] / drivers / staging / rtl8712 / mlme_linux.c
1 /******************************************************************************
2  * mlme_linux.c
3  *
4  * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5  * Linux device driver for RTL8192SU
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of version 2 of the GNU General Public License as
9  * published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19  *
20  * Modifications for inclusion into the Linux staging tree are
21  * Copyright(c) 2010 Larry Finger. All rights reserved.
22  *
23  * Contact information:
24  * WLAN FAE <wlanfae@realtek.com>.
25  * Larry Finger <Larry.Finger@lwfinger.net>
26  *
27  ******************************************************************************/
28
29 #define _MLME_OSDEP_C_
30
31 #include "osdep_service.h"
32 #include "drv_types.h"
33 #include "mlme_osdep.h"
34
35 static void sitesurvey_ctrl_handler(void *FunctionContext)
36 {
37         struct _adapter *adapter = (struct _adapter *)FunctionContext;
38
39         _r8712_sitesurvey_ctrl_handler(adapter);
40         _set_timer(&adapter->mlmepriv.sitesurveyctrl.sitesurvey_ctrl_timer,
41                    3000);
42 }
43
44 static void join_timeout_handler (void *FunctionContext)
45 {
46         struct _adapter *adapter = (struct _adapter *)FunctionContext;
47
48         _r8712_join_timeout_handler(adapter);
49 }
50
51 static void _scan_timeout_handler (void *FunctionContext)
52 {
53         struct _adapter *adapter = (struct _adapter *)FunctionContext;
54
55         r8712_scan_timeout_handler(adapter);
56 }
57
58 static void dhcp_timeout_handler (void *FunctionContext)
59 {
60         struct _adapter *adapter = (struct _adapter *)FunctionContext;
61
62         _r8712_dhcp_timeout_handler(adapter);
63 }
64
65 static void wdg_timeout_handler (void *FunctionContext)
66 {
67         struct _adapter *adapter = (struct _adapter *)FunctionContext;
68
69         _r8712_wdg_timeout_handler(adapter);
70
71         _set_timer(&adapter->mlmepriv.wdg_timer, 2000);
72 }
73
74 void r8712_init_mlme_timer(struct _adapter *padapter)
75 {
76         struct  mlme_priv *pmlmepriv = &padapter->mlmepriv;
77
78         _init_timer(&(pmlmepriv->assoc_timer), padapter->pnetdev,
79                     join_timeout_handler, (pmlmepriv->nic_hdl));
80         _init_timer(&(pmlmepriv->sitesurveyctrl.sitesurvey_ctrl_timer),
81                     padapter->pnetdev, sitesurvey_ctrl_handler,
82                     (u8 *)(pmlmepriv->nic_hdl));
83         _init_timer(&(pmlmepriv->scan_to_timer), padapter->pnetdev,
84                     _scan_timeout_handler, (pmlmepriv->nic_hdl));
85         _init_timer(&(pmlmepriv->dhcp_timer), padapter->pnetdev,
86                     dhcp_timeout_handler, (u8 *)(pmlmepriv->nic_hdl));
87         _init_timer(&(pmlmepriv->wdg_timer), padapter->pnetdev,
88                     wdg_timeout_handler, (u8 *)(pmlmepriv->nic_hdl));
89 }
90
91 void r8712_os_indicate_connect(struct _adapter *adapter)
92 {
93         r8712_indicate_wx_assoc_event(adapter);
94         netif_carrier_on(adapter->pnetdev);
95 }
96
97 static struct RT_PMKID_LIST   backupPMKIDList[NUM_PMKID_CACHE];
98 void r8712_os_indicate_disconnect(struct _adapter *adapter)
99 {
100         u8 backupPMKIDIndex = 0;
101         u8 backupTKIPCountermeasure = 0x00;
102
103         r8712_indicate_wx_disassoc_event(adapter);
104         netif_carrier_off(adapter->pnetdev);
105         if (adapter->securitypriv.AuthAlgrthm == 2) { /*/802.1x*/
106                 /* We have to backup the PMK information for WiFi PMK Caching
107                  * test item. Backup the btkip_countermeasure information.
108                  * When the countermeasure is trigger, the driver have to
109                  * disconnect with AP for 60 seconds.
110                  */
111
112                 memcpy(&backupPMKIDList[0], &adapter->securitypriv.
113                         PMKIDList[0], sizeof(struct RT_PMKID_LIST) *
114                         NUM_PMKID_CACHE);
115                 backupPMKIDIndex = adapter->securitypriv.PMKIDIndex;
116                 backupTKIPCountermeasure = adapter->securitypriv.
117                                            btkip_countermeasure;
118                 memset((unsigned char *)&adapter->securitypriv, 0,
119                          sizeof(struct security_priv));
120                 _init_timer(&(adapter->securitypriv.tkip_timer),
121                             adapter->pnetdev, r8712_use_tkipkey_handler,
122                             adapter);
123                 /* Restore the PMK information to securitypriv structure
124                  * for the following connection. */
125                 memcpy(&adapter->securitypriv.PMKIDList[0],
126                         &backupPMKIDList[0],
127                         sizeof(struct RT_PMKID_LIST) * NUM_PMKID_CACHE);
128                 adapter->securitypriv.PMKIDIndex = backupPMKIDIndex;
129                 adapter->securitypriv.btkip_countermeasure =
130                                          backupTKIPCountermeasure;
131         } else { /*reset values in securitypriv*/
132                 struct security_priv *psec_priv = &adapter->securitypriv;
133
134                 psec_priv->AuthAlgrthm = 0; /*open system*/
135                 psec_priv->PrivacyAlgrthm = _NO_PRIVACY_;
136                 psec_priv->PrivacyKeyIndex = 0;
137                 psec_priv->XGrpPrivacy = _NO_PRIVACY_;
138                 psec_priv->XGrpKeyid = 1;
139                 psec_priv->ndisauthtype = Ndis802_11AuthModeOpen;
140                 psec_priv->ndisencryptstatus = Ndis802_11WEPDisabled;
141                 psec_priv->wps_phase = false;
142         }
143 }
144
145 void r8712_report_sec_ie(struct _adapter *adapter, u8 authmode, u8 *sec_ie)
146 {
147         uint len;
148         u8 *buff, *p, i;
149         union iwreq_data wrqu;
150
151         buff = NULL;
152         if (authmode == _WPA_IE_ID_) {
153                 buff = kzalloc(IW_CUSTOM_MAX, GFP_ATOMIC);
154                 if (buff == NULL)
155                         return;
156                 p = buff;
157                 p += sprintf(p, "ASSOCINFO(ReqIEs=");
158                 len = sec_ie[1] + 2;
159                 len =  (len < IW_CUSTOM_MAX) ? len : IW_CUSTOM_MAX - 1;
160                 for (i = 0; i < len; i++)
161                         p += sprintf(p, "%02x", sec_ie[i]);
162                 p += sprintf(p, ")");
163                 memset(&wrqu, 0, sizeof(wrqu));
164                 wrqu.data.length = p-buff;
165                 wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ?
166                                    wrqu.data.length : IW_CUSTOM_MAX;
167                 wireless_send_event(adapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
168                 kfree(buff);
169         }
170 }