Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / staging / rtl8188eu / 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  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20
21
22 #define _MLME_OSDEP_C_
23
24 #include <osdep_service.h>
25 #include <drv_types.h>
26 #include <mlme_osdep.h>
27
28 void rtw_init_mlme_timer(struct adapter *padapter)
29 {
30         struct  mlme_priv *pmlmepriv = &padapter->mlmepriv;
31
32         setup_timer(&pmlmepriv->assoc_timer, _rtw_join_timeout_handler,
33                     (unsigned long)padapter);
34         setup_timer(&pmlmepriv->scan_to_timer, rtw_scan_timeout_handler,
35                     (unsigned long)padapter);
36         setup_timer(&pmlmepriv->dynamic_chk_timer,
37                     rtw_dynamic_check_timer_handlder, (unsigned long)padapter);
38 }
39
40 void rtw_os_indicate_connect(struct adapter *adapter)
41 {
42         rtw_indicate_wx_assoc_event(adapter);
43         netif_carrier_on(adapter->pnetdev);
44         if (adapter->pid[2] != 0)
45                 rtw_signal_process(adapter->pid[2], SIGALRM);
46 }
47
48 void rtw_os_indicate_scan_done(struct adapter *padapter, bool aborted)
49 {
50         indicate_wx_scan_complete_event(padapter);
51 }
52
53 static struct rt_pmkid_list backup_pmkid[NUM_PMKID_CACHE];
54
55 void rtw_reset_securitypriv(struct adapter *adapter)
56 {
57         u8      backup_index = 0;
58         u8      backup_counter = 0x00;
59         u32     backup_time = 0;
60
61         if (adapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) {
62                 /* 802.1x */
63                 /*  We have to backup the PMK information for WiFi PMK Caching test item. */
64                 /*  Backup the btkip_countermeasure information. */
65                 /*  When the countermeasure is trigger, the driver have to disconnect with AP for 60 seconds. */
66                 memcpy(&backup_pmkid[0], &adapter->securitypriv.PMKIDList[0], sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
67                 backup_index = adapter->securitypriv.PMKIDIndex;
68                 backup_counter = adapter->securitypriv.btkip_countermeasure;
69                 backup_time = adapter->securitypriv.btkip_countermeasure_time;
70                 memset((unsigned char *)&adapter->securitypriv, 0, sizeof(struct security_priv));
71
72                 /*  Restore the PMK information to securitypriv structure for the following connection. */
73                 memcpy(&adapter->securitypriv.PMKIDList[0],
74                             &backup_pmkid[0],
75                             sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
76                 adapter->securitypriv.PMKIDIndex = backup_index;
77                 adapter->securitypriv.btkip_countermeasure = backup_counter;
78                 adapter->securitypriv.btkip_countermeasure_time = backup_time;
79                 adapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
80                 adapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
81         } else {
82                 /* reset values in securitypriv */
83                 struct security_priv *psec_priv = &adapter->securitypriv;
84
85                 psec_priv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;  /* open system */
86                 psec_priv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
87                 psec_priv->dot11PrivacyKeyIndex = 0;
88                 psec_priv->dot118021XGrpPrivacy = _NO_PRIVACY_;
89                 psec_priv->dot118021XGrpKeyid = 1;
90                 psec_priv->ndisauthtype = Ndis802_11AuthModeOpen;
91                 psec_priv->ndisencryptstatus = Ndis802_11WEPDisabled;
92         }
93 }
94
95 void rtw_os_indicate_disconnect(struct adapter *adapter)
96 {
97         netif_carrier_off(adapter->pnetdev); /*  Do it first for tx broadcast pkt after disconnection issue! */
98         rtw_indicate_wx_disassoc_event(adapter);
99          rtw_reset_securitypriv(adapter);
100 }
101
102 void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie)
103 {
104         uint    len;
105         u8      *buff, *p, i;
106         union iwreq_data wrqu;
107
108         RT_TRACE(_module_mlme_osdep_c_, _drv_info_,
109                  ("+rtw_report_sec_ie, authmode=%d\n", authmode));
110         buff = NULL;
111         if (authmode == _WPA_IE_ID_) {
112                 RT_TRACE(_module_mlme_osdep_c_, _drv_info_,
113                          ("rtw_report_sec_ie, authmode=%d\n", authmode));
114                 buff = rtw_malloc(IW_CUSTOM_MAX);
115                 if (!buff)
116                         return;
117                 memset(buff, 0, IW_CUSTOM_MAX);
118                 p = buff;
119                 p += sprintf(p, "ASSOCINFO(ReqIEs =");
120                 len = sec_ie[1]+2;
121                 len =  (len < IW_CUSTOM_MAX) ? len : IW_CUSTOM_MAX;
122                 for (i = 0; i < len; i++)
123                         p += sprintf(p, "%02x", sec_ie[i]);
124                 p += sprintf(p, ")");
125                 memset(&wrqu, 0, sizeof(wrqu));
126                 wrqu.data.length = p-buff;
127                 wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ?
128                                    wrqu.data.length : IW_CUSTOM_MAX;
129                 wireless_send_event(adapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
130                 kfree(buff);
131         }
132 }
133
134 void init_addba_retry_timer(struct adapter *padapter, struct sta_info *psta)
135 {
136         setup_timer(&psta->addba_retry_timer, addba_timer_hdl,
137                     (unsigned long)psta);
138 }
139
140 void init_mlme_ext_timer(struct adapter *padapter)
141 {
142         struct  mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
143
144         setup_timer(&pmlmeext->survey_timer, survey_timer_hdl,
145                     (unsigned long)padapter);
146         setup_timer(&pmlmeext->link_timer, link_timer_hdl,
147                     (unsigned long)padapter);
148 }
149
150 #ifdef CONFIG_88EU_AP_MODE
151
152 void rtw_indicate_sta_assoc_event(struct adapter *padapter, struct sta_info *psta)
153 {
154         union iwreq_data wrqu;
155         struct sta_priv *pstapriv = &padapter->stapriv;
156
157         if (psta == NULL)
158                 return;
159
160         if (psta->aid > NUM_STA)
161                 return;
162
163         if (pstapriv->sta_aid[psta->aid - 1] != psta)
164                 return;
165
166
167         wrqu.addr.sa_family = ARPHRD_ETHER;
168
169         memcpy(wrqu.addr.sa_data, psta->hwaddr, ETH_ALEN);
170
171         DBG_88E("+rtw_indicate_sta_assoc_event\n");
172
173         wireless_send_event(padapter->pnetdev, IWEVREGISTERED, &wrqu, NULL);
174 }
175
176 void rtw_indicate_sta_disassoc_event(struct adapter *padapter, struct sta_info *psta)
177 {
178         union iwreq_data wrqu;
179         struct sta_priv *pstapriv = &padapter->stapriv;
180
181         if (psta == NULL)
182                 return;
183
184         if (psta->aid > NUM_STA)
185                 return;
186
187         if (pstapriv->sta_aid[psta->aid - 1] != psta)
188                 return;
189
190
191         wrqu.addr.sa_family = ARPHRD_ETHER;
192
193         memcpy(wrqu.addr.sa_data, psta->hwaddr, ETH_ALEN);
194
195         DBG_88E("+rtw_indicate_sta_disassoc_event\n");
196
197         wireless_send_event(padapter->pnetdev, IWEVEXPIRED, &wrqu, NULL);
198 }
199
200 #endif