Merge branch 'for-3.11' of git://linux-nfs.org/~bfields/linux
[linux-2.6.git] / drivers / staging / rtl8712 / mlme_linux.c
blobf569a7081be599ddd645fb55f928a3067340a9f7
1 /******************************************************************************
2 * mlme_linux.c
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU
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.
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.
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
20 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved.
23 * Contact information:
24 * WLAN FAE <wlanfae@realtek.com>.
25 * Larry Finger <Larry.Finger@lwfinger.net>
27 ******************************************************************************/
29 #define _MLME_OSDEP_C_
31 #include "osdep_service.h"
32 #include "drv_types.h"
33 #include "mlme_osdep.h"
35 static void sitesurvey_ctrl_handler(void *FunctionContext)
37 struct _adapter *adapter = (struct _adapter *)FunctionContext;
39 _r8712_sitesurvey_ctrl_handler(adapter);
40 _set_timer(&adapter->mlmepriv.sitesurveyctrl.sitesurvey_ctrl_timer,
41 3000);
44 static void join_timeout_handler (void *FunctionContext)
46 struct _adapter *adapter = (struct _adapter *)FunctionContext;
47 _r8712_join_timeout_handler(adapter);
50 static void _scan_timeout_handler (void *FunctionContext)
52 struct _adapter *adapter = (struct _adapter *)FunctionContext;
53 r8712_scan_timeout_handler(adapter);
56 static void dhcp_timeout_handler (void *FunctionContext)
58 struct _adapter *adapter = (struct _adapter *)FunctionContext;
59 _r8712_dhcp_timeout_handler(adapter);
62 static void wdg_timeout_handler (void *FunctionContext)
64 struct _adapter *adapter = (struct _adapter *)FunctionContext;
66 _r8712_wdg_timeout_handler(adapter);
68 _set_timer(&adapter->mlmepriv.wdg_timer, 2000);
71 void r8712_init_mlme_timer(struct _adapter *padapter)
73 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
75 _init_timer(&(pmlmepriv->assoc_timer), padapter->pnetdev,
76 join_timeout_handler, (pmlmepriv->nic_hdl));
77 _init_timer(&(pmlmepriv->sitesurveyctrl.sitesurvey_ctrl_timer),
78 padapter->pnetdev, sitesurvey_ctrl_handler,
79 (u8 *)(pmlmepriv->nic_hdl));
80 _init_timer(&(pmlmepriv->scan_to_timer), padapter->pnetdev,
81 _scan_timeout_handler, (pmlmepriv->nic_hdl));
82 _init_timer(&(pmlmepriv->dhcp_timer), padapter->pnetdev,
83 dhcp_timeout_handler, (u8 *)(pmlmepriv->nic_hdl));
84 _init_timer(&(pmlmepriv->wdg_timer), padapter->pnetdev,
85 wdg_timeout_handler, (u8 *)(pmlmepriv->nic_hdl));
88 void r8712_os_indicate_connect(struct _adapter *adapter)
90 r8712_indicate_wx_assoc_event(adapter);
91 netif_carrier_on(adapter->pnetdev);
94 static struct RT_PMKID_LIST backupPMKIDList[NUM_PMKID_CACHE];
95 void r8712_os_indicate_disconnect(struct _adapter *adapter)
97 u8 backupPMKIDIndex = 0;
98 u8 backupTKIPCountermeasure = 0x00;
100 r8712_indicate_wx_disassoc_event(adapter);
101 netif_carrier_off(adapter->pnetdev);
102 if (adapter->securitypriv.AuthAlgrthm == 2) { /*/802.1x*/
103 /* We have to backup the PMK information for WiFi PMK Caching
104 * test item. Backup the btkip_countermeasure information.
105 * When the countermeasure is trigger, the driver have to
106 * disconnect with AP for 60 seconds.
109 memcpy(&backupPMKIDList[0], &adapter->securitypriv.
110 PMKIDList[0], sizeof(struct RT_PMKID_LIST) *
111 NUM_PMKID_CACHE);
112 backupPMKIDIndex = adapter->securitypriv.PMKIDIndex;
113 backupTKIPCountermeasure = adapter->securitypriv.
114 btkip_countermeasure;
115 memset((unsigned char *)&adapter->securitypriv, 0,
116 sizeof(struct security_priv));
117 _init_timer(&(adapter->securitypriv.tkip_timer),
118 adapter->pnetdev, r8712_use_tkipkey_handler,
119 adapter);
120 /* Restore the PMK information to securitypriv structure
121 * for the following connection. */
122 memcpy(&adapter->securitypriv.PMKIDList[0],
123 &backupPMKIDList[0],
124 sizeof(struct RT_PMKID_LIST) * NUM_PMKID_CACHE);
125 adapter->securitypriv.PMKIDIndex = backupPMKIDIndex;
126 adapter->securitypriv.btkip_countermeasure =
127 backupTKIPCountermeasure;
128 } else { /*reset values in securitypriv*/
129 struct security_priv *psec_priv = &adapter->securitypriv;
131 psec_priv->AuthAlgrthm = 0; /*open system*/
132 psec_priv->PrivacyAlgrthm = _NO_PRIVACY_;
133 psec_priv->PrivacyKeyIndex = 0;
134 psec_priv->XGrpPrivacy = _NO_PRIVACY_;
135 psec_priv->XGrpKeyid = 1;
136 psec_priv->ndisauthtype = Ndis802_11AuthModeOpen;
137 psec_priv->ndisencryptstatus = Ndis802_11WEPDisabled;
138 psec_priv->wps_phase = false;
142 void r8712_report_sec_ie(struct _adapter *adapter, u8 authmode, u8 *sec_ie)
144 uint len;
145 u8 *buff, *p, i;
146 union iwreq_data wrqu;
148 buff = NULL;
149 if (authmode == _WPA_IE_ID_) {
150 buff = _malloc(IW_CUSTOM_MAX);
151 if (buff == NULL)
152 return;
153 memset(buff, 0, IW_CUSTOM_MAX);
154 p = buff;
155 p += sprintf(p, "ASSOCINFO(ReqIEs=");
156 len = sec_ie[1] + 2;
157 len = (len < IW_CUSTOM_MAX) ? len : IW_CUSTOM_MAX - 1;
158 for (i = 0; i < len; i++)
159 p += sprintf(p, "%02x", sec_ie[i]);
160 p += sprintf(p, ")");
161 memset(&wrqu, 0, sizeof(wrqu));
162 wrqu.data.length = p-buff;
163 wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ?
164 wrqu.data.length : IW_CUSTOM_MAX;
165 wireless_send_event(adapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
166 kfree(buff);