1 /******************************************************************************
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
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 _RTL871X_IOCTL_SET_C_
31 #include "osdep_service.h"
32 #include "drv_types.h"
33 #include "rtl871x_ioctl_set.h"
34 #include "usb_osintf.h"
37 #define IS_MAC_ADDRESS_BROADCAST(addr) \
39 ((addr[0] == 0xff) && (addr[1] == 0xff) && \
40 (addr[2] == 0xff) && (addr[3] == 0xff) && \
41 (addr[4] == 0xff) && (addr[5] == 0xff)) ? true : false \
44 static u8
validate_ssid(struct ndis_802_11_ssid
*ssid
)
48 if (ssid
->SsidLength
> 32)
50 for (i
= 0; i
< ssid
->SsidLength
; i
++) {
51 /* wifi, printable ascii code must be supported */
52 if (!((ssid
->Ssid
[i
] >= 0x20) && (ssid
->Ssid
[i
] <= 0x7e)))
58 static u8
do_join(struct _adapter
*padapter
)
60 struct list_head
*plist
, *phead
;
62 struct mlme_priv
*pmlmepriv
= &(padapter
->mlmepriv
);
63 struct __queue
*queue
= &(pmlmepriv
->scanned_queue
);
65 phead
= &queue
->queue
;
67 pmlmepriv
->cur_network
.join_res
= -2;
68 pmlmepriv
->fw_state
|= _FW_UNDER_LINKING
;
69 pmlmepriv
->pscanned
= plist
;
70 pmlmepriv
->to_join
= true;
72 /* adhoc mode will start with an empty queue, but skip checking */
73 if (!check_fwstate(pmlmepriv
, WIFI_ADHOC_STATE
) &&
74 list_empty(&queue
->queue
)) {
75 if (pmlmepriv
->fw_state
& _FW_UNDER_LINKING
)
76 pmlmepriv
->fw_state
^= _FW_UNDER_LINKING
;
77 /* when set_ssid/set_bssid for do_join(), but scanning queue
78 * is empty we try to issue sitesurvey firstly
80 if (!pmlmepriv
->sitesurveyctrl
.traffic_busy
)
81 r8712_sitesurvey_cmd(padapter
, &pmlmepriv
->assoc_ssid
);
86 ret
= r8712_select_and_join_from_scan(pmlmepriv
);
88 mod_timer(&pmlmepriv
->assoc_timer
,
89 jiffies
+ msecs_to_jiffies(MAX_JOIN_TIMEOUT
));
91 if (check_fwstate(pmlmepriv
, WIFI_ADHOC_STATE
)) {
92 /* submit r8712_createbss_cmd to change to an
93 * ADHOC_MASTER pmlmepriv->lock has been
94 * acquired by caller...
96 struct wlan_bssid_ex
*pdev_network
=
97 &(padapter
->registrypriv
.dev_network
);
98 pmlmepriv
->fw_state
= WIFI_ADHOC_MASTER_STATE
;
99 pibss
= padapter
->registrypriv
.dev_network
.
101 memcpy(&pdev_network
->Ssid
,
102 &pmlmepriv
->assoc_ssid
,
103 sizeof(struct ndis_802_11_ssid
));
104 r8712_update_registrypriv_dev_network(padapter
);
105 r8712_generate_random_ibss(pibss
);
106 if (r8712_createbss_cmd(padapter
) != _SUCCESS
)
108 pmlmepriv
->to_join
= false;
110 /* can't associate ; reset under-linking */
111 if (pmlmepriv
->fw_state
& _FW_UNDER_LINKING
)
112 pmlmepriv
->fw_state
^=
114 /* when set_ssid/set_bssid for do_join(), but
115 * there are no desired bss in scanning queue
116 * we try to issue sitesurvey first
118 if (!pmlmepriv
->sitesurveyctrl
.traffic_busy
)
119 r8712_sitesurvey_cmd(padapter
,
120 &pmlmepriv
->assoc_ssid
);
127 u8
r8712_set_802_11_bssid(struct _adapter
*padapter
, u8
*bssid
)
131 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
133 if (is_zero_ether_addr(bssid
) || is_broadcast_ether_addr(bssid
)) {
137 spin_lock_irqsave(&pmlmepriv
->lock
, irqL
);
138 if (check_fwstate(pmlmepriv
, _FW_UNDER_SURVEY
|
139 _FW_UNDER_LINKING
)) {
140 status
= check_fwstate(pmlmepriv
, _FW_UNDER_LINKING
);
141 goto _Abort_Set_BSSID
;
143 if (check_fwstate(pmlmepriv
,
144 _FW_LINKED
| WIFI_ADHOC_MASTER_STATE
)) {
145 if (!memcmp(&pmlmepriv
->cur_network
.network
.MacAddress
, bssid
,
147 if (!check_fwstate(pmlmepriv
, WIFI_STATION_STATE
))
148 goto _Abort_Set_BSSID
; /* driver is in
149 * WIFI_ADHOC_MASTER_STATE */
151 r8712_disassoc_cmd(padapter
);
152 if (check_fwstate(pmlmepriv
, _FW_LINKED
))
153 r8712_ind_disconnect(padapter
);
154 r8712_free_assoc_resources(padapter
);
155 if ((check_fwstate(pmlmepriv
,
156 WIFI_ADHOC_MASTER_STATE
))) {
157 _clr_fwstate_(pmlmepriv
,
158 WIFI_ADHOC_MASTER_STATE
);
159 set_fwstate(pmlmepriv
, WIFI_ADHOC_STATE
);
163 memcpy(&pmlmepriv
->assoc_bssid
, bssid
, ETH_ALEN
);
164 pmlmepriv
->assoc_by_bssid
= true;
165 status
= do_join(padapter
);
169 spin_unlock_irqrestore(&pmlmepriv
->lock
, irqL
);
173 void r8712_set_802_11_ssid(struct _adapter
*padapter
,
174 struct ndis_802_11_ssid
*ssid
)
177 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
178 struct wlan_network
*pnetwork
= &pmlmepriv
->cur_network
;
180 if (!padapter
->hw_init_completed
)
182 spin_lock_irqsave(&pmlmepriv
->lock
, irqL
);
183 if (check_fwstate(pmlmepriv
, _FW_UNDER_SURVEY
| _FW_UNDER_LINKING
)) {
184 check_fwstate(pmlmepriv
, _FW_UNDER_LINKING
);
185 goto _Abort_Set_SSID
;
187 if (check_fwstate(pmlmepriv
, _FW_LINKED
| WIFI_ADHOC_MASTER_STATE
)) {
188 if ((pmlmepriv
->assoc_ssid
.SsidLength
== ssid
->SsidLength
) &&
189 (!memcmp(&pmlmepriv
->assoc_ssid
.Ssid
, ssid
->Ssid
,
190 ssid
->SsidLength
))) {
191 if (!check_fwstate(pmlmepriv
, WIFI_STATION_STATE
)) {
192 if (!r8712_is_same_ibss(padapter
,
194 /* if in WIFI_ADHOC_MASTER_STATE or
195 * WIFI_ADHOC_STATE, create bss or
198 r8712_disassoc_cmd(padapter
);
199 if (check_fwstate(pmlmepriv
,
201 r8712_ind_disconnect(padapter
);
202 r8712_free_assoc_resources(padapter
);
203 if (check_fwstate(pmlmepriv
,
204 WIFI_ADHOC_MASTER_STATE
)) {
205 _clr_fwstate_(pmlmepriv
,
206 WIFI_ADHOC_MASTER_STATE
);
207 set_fwstate(pmlmepriv
,
211 goto _Abort_Set_SSID
; /* driver is in
212 * WIFI_ADHOC_MASTER_STATE */
216 r8712_disassoc_cmd(padapter
);
217 if (check_fwstate(pmlmepriv
, _FW_LINKED
))
218 r8712_ind_disconnect(padapter
);
219 r8712_free_assoc_resources(padapter
);
220 if (check_fwstate(pmlmepriv
,
221 WIFI_ADHOC_MASTER_STATE
)) {
222 _clr_fwstate_(pmlmepriv
,
223 WIFI_ADHOC_MASTER_STATE
);
224 set_fwstate(pmlmepriv
, WIFI_ADHOC_STATE
);
228 if (padapter
->securitypriv
.btkip_countermeasure
)
229 goto _Abort_Set_SSID
;
230 if (!validate_ssid(ssid
))
231 goto _Abort_Set_SSID
;
232 memcpy(&pmlmepriv
->assoc_ssid
, ssid
, sizeof(struct ndis_802_11_ssid
));
233 pmlmepriv
->assoc_by_bssid
= false;
238 spin_unlock_irqrestore(&pmlmepriv
->lock
, irqL
);
241 void r8712_set_802_11_infrastructure_mode(struct _adapter
*padapter
,
242 enum NDIS_802_11_NETWORK_INFRASTRUCTURE networktype
)
245 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
246 struct wlan_network
*cur_network
= &pmlmepriv
->cur_network
;
247 enum NDIS_802_11_NETWORK_INFRASTRUCTURE
*pold_state
=
248 &(cur_network
->network
.InfrastructureMode
);
250 if (*pold_state
!= networktype
) {
251 spin_lock_irqsave(&pmlmepriv
->lock
, irqL
);
252 if (check_fwstate(pmlmepriv
, _FW_LINKED
) ||
253 (*pold_state
== Ndis802_11IBSS
))
254 r8712_disassoc_cmd(padapter
);
255 if (check_fwstate(pmlmepriv
,
256 _FW_LINKED
| WIFI_ADHOC_MASTER_STATE
))
257 r8712_free_assoc_resources(padapter
);
258 if (check_fwstate(pmlmepriv
, _FW_LINKED
) ||
259 (*pold_state
== Ndis802_11Infrastructure
) ||
260 (*pold_state
== Ndis802_11IBSS
)) {
261 /* will clr Linked_state before this function,
262 * we must have checked whether issue dis-assoc_cmd or
264 r8712_ind_disconnect(padapter
);
266 *pold_state
= networktype
;
267 /* clear WIFI_STATION_STATE; WIFI_AP_STATE; WIFI_ADHOC_STATE;
268 * WIFI_ADHOC_MASTER_STATE */
269 _clr_fwstate_(pmlmepriv
, WIFI_STATION_STATE
| WIFI_AP_STATE
|
270 WIFI_ADHOC_STATE
| WIFI_ADHOC_MASTER_STATE
);
271 switch (networktype
) {
273 set_fwstate(pmlmepriv
, WIFI_ADHOC_STATE
);
275 case Ndis802_11Infrastructure
:
276 set_fwstate(pmlmepriv
, WIFI_STATION_STATE
);
278 case Ndis802_11APMode
:
279 set_fwstate(pmlmepriv
, WIFI_AP_STATE
);
281 case Ndis802_11AutoUnknown
:
282 case Ndis802_11InfrastructureMax
:
285 spin_unlock_irqrestore(&pmlmepriv
->lock
, irqL
);
289 u8
r8712_set_802_11_disassociate(struct _adapter
*padapter
)
292 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
294 spin_lock_irqsave(&pmlmepriv
->lock
, irqL
);
295 if (check_fwstate(pmlmepriv
, _FW_LINKED
)) {
296 r8712_disassoc_cmd(padapter
);
297 r8712_ind_disconnect(padapter
);
298 r8712_free_assoc_resources(padapter
);
300 spin_unlock_irqrestore(&pmlmepriv
->lock
, irqL
);
304 u8
r8712_set_802_11_bssid_list_scan(struct _adapter
*padapter
)
306 struct mlme_priv
*pmlmepriv
= NULL
;
312 pmlmepriv
= &padapter
->mlmepriv
;
313 if (!padapter
->hw_init_completed
)
315 spin_lock_irqsave(&pmlmepriv
->lock
, irqL
);
316 if (check_fwstate(pmlmepriv
, _FW_UNDER_SURVEY
| _FW_UNDER_LINKING
) ||
317 pmlmepriv
->sitesurveyctrl
.traffic_busy
) {
318 /* Scan or linking is in progress, do nothing. */
319 ret
= (u8
)check_fwstate(pmlmepriv
, _FW_UNDER_SURVEY
);
321 r8712_free_network_queue(padapter
);
322 ret
= r8712_sitesurvey_cmd(padapter
, NULL
);
324 spin_unlock_irqrestore(&pmlmepriv
->lock
, irqL
);
328 u8
r8712_set_802_11_authentication_mode(struct _adapter
*padapter
,
329 enum NDIS_802_11_AUTHENTICATION_MODE authmode
)
331 struct security_priv
*psecuritypriv
= &padapter
->securitypriv
;
334 psecuritypriv
->ndisauthtype
= authmode
;
335 if (psecuritypriv
->ndisauthtype
> 3)
336 psecuritypriv
->AuthAlgrthm
= 2; /* 802.1x */
337 if (r8712_set_auth(padapter
, psecuritypriv
) == _SUCCESS
)
344 u8
r8712_set_802_11_add_wep(struct _adapter
*padapter
,
345 struct NDIS_802_11_WEP
*wep
)
348 struct security_priv
*psecuritypriv
= &padapter
->securitypriv
;
350 keyid
= wep
->KeyIndex
& 0x3fffffff;
351 if (keyid
>= WEP_KEYS
)
353 switch (wep
->KeyLength
) {
355 psecuritypriv
->PrivacyAlgrthm
= _WEP40_
;
358 psecuritypriv
->PrivacyAlgrthm
= _WEP104_
;
361 psecuritypriv
->PrivacyAlgrthm
= _NO_PRIVACY_
;
364 memcpy(psecuritypriv
->DefKey
[keyid
].skey
, &wep
->KeyMaterial
,
366 psecuritypriv
->DefKeylen
[keyid
] = wep
->KeyLength
;
367 psecuritypriv
->PrivacyKeyIndex
= keyid
;
368 if (r8712_set_key(padapter
, psecuritypriv
, keyid
) == _FAIL
)