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