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_CMD_C_
31 #include "osdep_service.h"
32 #include "drv_types.h"
33 #include "recv_osdep.h"
34 #include "mlme_osdep.h"
35 #include "rtl871x_byteorder.h"
38 Caller and the r8712_cmd_thread can protect cmd_q by spin_lock.
39 No irqsave is necessary.
42 static sint
_init_cmd_priv(struct cmd_priv
*pcmdpriv
)
44 sema_init(&(pcmdpriv
->cmd_queue_sema
), 0);
45 sema_init(&(pcmdpriv
->terminate_cmdthread_sema
), 0);
47 _init_queue(&(pcmdpriv
->cmd_queue
));
49 /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
50 pcmdpriv
->cmd_seq
= 1;
51 pcmdpriv
->cmd_allocated_buf
= _malloc(MAX_CMDSZ
+ CMDBUFF_ALIGN_SZ
);
52 if (pcmdpriv
->cmd_allocated_buf
== NULL
)
54 pcmdpriv
->cmd_buf
= pcmdpriv
->cmd_allocated_buf
+ CMDBUFF_ALIGN_SZ
-
55 ((addr_t
)(pcmdpriv
->cmd_allocated_buf
) &
56 (CMDBUFF_ALIGN_SZ
-1));
57 pcmdpriv
->rsp_allocated_buf
= _malloc(MAX_RSPSZ
+ 4);
58 if (pcmdpriv
->rsp_allocated_buf
== NULL
)
60 pcmdpriv
->rsp_buf
= pcmdpriv
->rsp_allocated_buf
+ 4 -
61 ((addr_t
)(pcmdpriv
->rsp_allocated_buf
) & 3);
62 pcmdpriv
->cmd_issued_cnt
= 0;
63 pcmdpriv
->cmd_done_cnt
= 0;
64 pcmdpriv
->rsp_cnt
= 0;
68 static sint
_init_evt_priv(struct evt_priv
*pevtpriv
)
70 /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
71 pevtpriv
->event_seq
= 0;
72 pevtpriv
->evt_allocated_buf
= _malloc(MAX_EVTSZ
+ 4);
74 if (pevtpriv
->evt_allocated_buf
== NULL
)
76 pevtpriv
->evt_buf
= pevtpriv
->evt_allocated_buf
+ 4 -
77 ((addr_t
)(pevtpriv
->evt_allocated_buf
) & 3);
78 pevtpriv
->evt_done_cnt
= 0;
82 static void _free_evt_priv(struct evt_priv
*pevtpriv
)
84 kfree(pevtpriv
->evt_allocated_buf
);
87 static void _free_cmd_priv(struct cmd_priv
*pcmdpriv
)
90 kfree(pcmdpriv
->cmd_allocated_buf
);
91 kfree(pcmdpriv
->rsp_allocated_buf
);
98 _enqueue_cmd can only be called between kernel thread,
99 since only spin_lock is used.
101 ISR/Call-Back functions can't call this sub-function.
105 static sint
_enqueue_cmd(struct __queue
*queue
, struct cmd_obj
*obj
)
111 spin_lock_irqsave(&queue
->lock
, irqL
);
112 list_insert_tail(&obj
->list
, &queue
->queue
);
113 spin_unlock_irqrestore(&queue
->lock
, irqL
);
117 static struct cmd_obj
*_dequeue_cmd(struct __queue
*queue
)
122 spin_lock_irqsave(&(queue
->lock
), irqL
);
123 if (is_list_empty(&(queue
->queue
)))
126 obj
= LIST_CONTAINOR(get_next(&(queue
->queue
)),
127 struct cmd_obj
, list
);
128 list_delete(&obj
->list
);
130 spin_unlock_irqrestore(&(queue
->lock
), irqL
);
134 u32
r8712_init_cmd_priv(struct cmd_priv
*pcmdpriv
)
136 return _init_cmd_priv(pcmdpriv
);
139 u32
r8712_init_evt_priv(struct evt_priv
*pevtpriv
)
141 return _init_evt_priv(pevtpriv
);
144 void r8712_free_evt_priv(struct evt_priv
*pevtpriv
)
146 _free_evt_priv(pevtpriv
);
149 void r8712_free_cmd_priv(struct cmd_priv
*pcmdpriv
)
151 _free_cmd_priv(pcmdpriv
);
154 u32
r8712_enqueue_cmd(struct cmd_priv
*pcmdpriv
, struct cmd_obj
*obj
)
158 if (pcmdpriv
->padapter
->eeprompriv
.bautoload_fail_flag
== true)
160 res
= _enqueue_cmd(&pcmdpriv
->cmd_queue
, obj
);
161 up(&pcmdpriv
->cmd_queue_sema
);
165 u32
r8712_enqueue_cmd_ex(struct cmd_priv
*pcmdpriv
, struct cmd_obj
*obj
)
168 struct __queue
*queue
;
172 if (pcmdpriv
->padapter
->eeprompriv
.bautoload_fail_flag
== true)
174 queue
= &pcmdpriv
->cmd_queue
;
175 spin_lock_irqsave(&queue
->lock
, irqL
);
176 list_insert_tail(&obj
->list
, &queue
->queue
);
177 spin_unlock_irqrestore(&queue
->lock
, irqL
);
178 up(&pcmdpriv
->cmd_queue_sema
);
182 struct cmd_obj
*r8712_dequeue_cmd(struct __queue
*queue
)
184 return _dequeue_cmd(queue
);
187 void r8712_free_cmd_obj(struct cmd_obj
*pcmd
)
189 if ((pcmd
->cmdcode
!= _JoinBss_CMD_
) &&
190 (pcmd
->cmdcode
!= _CreateBss_CMD_
))
191 kfree((unsigned char *)pcmd
->parmbuf
);
192 if (pcmd
->rsp
!= NULL
) {
193 if (pcmd
->rspsz
!= 0)
194 kfree((unsigned char *)pcmd
->rsp
);
196 kfree((unsigned char *)pcmd
);
200 r8712_sitesurvey_cmd(~)
202 MUST TAKE CARE THAT BEFORE CALLING THIS FUNC,
203 YOU SHOULD HAVE LOCKED pmlmepriv->lock
205 u8
r8712_sitesurvey_cmd(struct _adapter
*padapter
,
206 struct ndis_802_11_ssid
*pssid
)
208 struct cmd_obj
*ph2c
;
209 struct sitesurvey_parm
*psurveyPara
;
210 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
211 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
213 ph2c
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
216 psurveyPara
= (struct sitesurvey_parm
*)_malloc(
217 sizeof(struct sitesurvey_parm
));
218 if (psurveyPara
== NULL
) {
219 kfree((unsigned char *) ph2c
);
222 init_h2fwcmd_w_parm_no_rsp(ph2c
, psurveyPara
,
223 GEN_CMD_CODE(_SiteSurvey
));
224 psurveyPara
->bsslimit
= cpu_to_le32(48);
225 psurveyPara
->passive_mode
= cpu_to_le32(1);
226 psurveyPara
->ss_ssidlen
= 0;
227 memset(psurveyPara
->ss_ssid
, 0, IW_ESSID_MAX_SIZE
+ 1);
228 if ((pssid
!= NULL
) && (pssid
->SsidLength
)) {
229 memcpy(psurveyPara
->ss_ssid
, pssid
->Ssid
, pssid
->SsidLength
);
230 psurveyPara
->ss_ssidlen
= cpu_to_le32(pssid
->SsidLength
);
232 set_fwstate(pmlmepriv
, _FW_UNDER_SURVEY
);
233 r8712_enqueue_cmd(pcmdpriv
, ph2c
);
234 _set_timer(&pmlmepriv
->scan_to_timer
, SCANNING_TIMEOUT
);
235 padapter
->ledpriv
.LedControlHandler(padapter
, LED_CTL_SITE_SURVEY
);
239 u8
r8712_setdatarate_cmd(struct _adapter
*padapter
, u8
*rateset
)
241 struct cmd_obj
*ph2c
;
242 struct setdatarate_parm
*pbsetdataratepara
;
243 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
245 ph2c
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
248 pbsetdataratepara
= (struct setdatarate_parm
*)_malloc(
249 sizeof(struct setdatarate_parm
));
250 if (pbsetdataratepara
== NULL
) {
254 init_h2fwcmd_w_parm_no_rsp(ph2c
, pbsetdataratepara
,
255 GEN_CMD_CODE(_SetDataRate
));
256 pbsetdataratepara
->mac_id
= 5;
257 memcpy(pbsetdataratepara
->datarates
, rateset
, NumRates
);
258 r8712_enqueue_cmd(pcmdpriv
, ph2c
);
262 u8
r8712_setbasicrate_cmd(struct _adapter
*padapter
, u8
*rateset
)
264 struct cmd_obj
*ph2c
;
265 struct setbasicrate_parm
*pssetbasicratepara
;
266 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
268 ph2c
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
271 pssetbasicratepara
= (struct setbasicrate_parm
*)_malloc(
272 sizeof(struct setbasicrate_parm
));
273 if (pssetbasicratepara
== NULL
) {
277 init_h2fwcmd_w_parm_no_rsp(ph2c
, pssetbasicratepara
,
279 memcpy(pssetbasicratepara
->basicrates
, rateset
, NumRates
);
280 r8712_enqueue_cmd(pcmdpriv
, ph2c
);
284 /* power tracking mechanism setting */
285 u8
r8712_setptm_cmd(struct _adapter
*padapter
, u8 type
)
287 struct cmd_obj
*ph2c
;
288 struct PT_param
*pptparm
;
289 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
291 ph2c
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
294 pptparm
= (struct PT_param
*)_malloc(sizeof(struct PT_param
));
295 if (pptparm
== NULL
) {
299 init_h2fwcmd_w_parm_no_rsp(ph2c
, pptparm
,
300 GEN_CMD_CODE(_SetPowerTracking
));
301 pptparm
->PT_En
= type
;
302 r8712_enqueue_cmd(pcmdpriv
, ph2c
);
306 u8
r8712_setrfreg_cmd(struct _adapter
*padapter
, u8 offset
, u32 val
)
308 struct cmd_obj
*ph2c
;
309 struct writeRF_parm
*pwriterfparm
;
310 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
312 ph2c
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
315 pwriterfparm
= (struct writeRF_parm
*)_malloc(
316 sizeof(struct writeRF_parm
));
317 if (pwriterfparm
== NULL
) {
321 init_h2fwcmd_w_parm_no_rsp(ph2c
, pwriterfparm
, GEN_CMD_CODE(_SetRFReg
));
322 pwriterfparm
->offset
= offset
;
323 pwriterfparm
->value
= val
;
324 r8712_enqueue_cmd(pcmdpriv
, ph2c
);
328 u8
r8712_getrfreg_cmd(struct _adapter
*padapter
, u8 offset
, u8
*pval
)
330 struct cmd_obj
*ph2c
;
331 struct readRF_parm
*prdrfparm
;
332 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
334 ph2c
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
337 prdrfparm
= (struct readRF_parm
*)_malloc(sizeof(struct readRF_parm
));
338 if (prdrfparm
== NULL
) {
342 _init_listhead(&ph2c
->list
);
343 ph2c
->cmdcode
= GEN_CMD_CODE(_GetRFReg
);
344 ph2c
->parmbuf
= (unsigned char *)prdrfparm
;
345 ph2c
->cmdsz
= sizeof(struct readRF_parm
);
347 ph2c
->rspsz
= sizeof(struct readRF_rsp
);
348 prdrfparm
->offset
= offset
;
349 r8712_enqueue_cmd(pcmdpriv
, ph2c
);
353 void r8712_getbbrfreg_cmdrsp_callback(struct _adapter
*padapter
,
354 struct cmd_obj
*pcmd
)
356 kfree((unsigned char *) pcmd
->parmbuf
);
357 kfree((unsigned char *) pcmd
);
358 padapter
->mppriv
.workparam
.bcompleted
= true;
361 u8
r8712_createbss_cmd(struct _adapter
*padapter
)
363 struct cmd_obj
*pcmd
;
364 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
365 struct wlan_bssid_ex
*pdev_network
=
366 &padapter
->registrypriv
.dev_network
;
368 padapter
->ledpriv
.LedControlHandler(padapter
, LED_CTL_START_TO_LINK
);
369 pcmd
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
372 _init_listhead(&pcmd
->list
);
373 pcmd
->cmdcode
= _CreateBss_CMD_
;
374 pcmd
->parmbuf
= (unsigned char *)pdev_network
;
375 pcmd
->cmdsz
= r8712_get_ndis_wlan_bssid_ex_sz((
376 struct ndis_wlan_bssid_ex
*)
380 /* notes: translate IELength & Length after assign to cmdsz; */
381 pdev_network
->Length
= cpu_to_le32(pcmd
->cmdsz
);
382 pdev_network
->IELength
= cpu_to_le32(pdev_network
->IELength
);
383 pdev_network
->Ssid
.SsidLength
= cpu_to_le32(
384 pdev_network
->Ssid
.SsidLength
);
385 r8712_enqueue_cmd(pcmdpriv
, pcmd
);
389 u8
r8712_joinbss_cmd(struct _adapter
*padapter
, struct wlan_network
*pnetwork
)
393 struct ndis_wlan_bssid_ex
*psecnetwork
;
394 struct cmd_obj
*pcmd
;
395 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
396 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
397 struct qos_priv
*pqospriv
= &pmlmepriv
->qospriv
;
398 struct security_priv
*psecuritypriv
= &padapter
->securitypriv
;
399 struct registry_priv
*pregistrypriv
= &padapter
->registrypriv
;
400 enum NDIS_802_11_NETWORK_INFRASTRUCTURE ndis_network_mode
= pnetwork
->
401 network
.InfrastructureMode
;
403 padapter
->ledpriv
.LedControlHandler(padapter
, LED_CTL_START_TO_LINK
);
404 pcmd
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
407 t_len
= sizeof(u32
) + 6 * sizeof(unsigned char) + 2 +
408 sizeof(struct ndis_802_11_ssid
) + sizeof(u32
) +
410 sizeof(enum NDIS_802_11_NETWORK_TYPE
) +
411 sizeof(struct NDIS_802_11_CONFIGURATION
) +
412 sizeof(enum NDIS_802_11_NETWORK_INFRASTRUCTURE
) +
413 sizeof(NDIS_802_11_RATES_EX
) +
414 sizeof(u32
) + MAX_IE_SZ
;
416 /* for hidden ap to set fw_state here */
417 if (check_fwstate(pmlmepriv
, WIFI_STATION_STATE
|WIFI_ADHOC_STATE
) !=
419 switch (ndis_network_mode
) {
421 pmlmepriv
->fw_state
|= WIFI_ADHOC_STATE
;
423 case Ndis802_11Infrastructure
:
424 pmlmepriv
->fw_state
|= WIFI_STATION_STATE
;
426 case Ndis802_11APMode
:
427 case Ndis802_11AutoUnknown
:
428 case Ndis802_11InfrastructureMax
:
432 psecnetwork
= (struct ndis_wlan_bssid_ex
*)&psecuritypriv
->sec_bss
;
433 if (psecnetwork
== NULL
) {
437 memset(psecnetwork
, 0, t_len
);
438 memcpy(psecnetwork
, &pnetwork
->network
, t_len
);
439 auth
= &psecuritypriv
->authenticator_ie
[0];
440 psecuritypriv
->authenticator_ie
[0] = (unsigned char)
441 psecnetwork
->IELength
;
442 if ((psecnetwork
->IELength
-12) < (256 - 1))
443 memcpy(&psecuritypriv
->authenticator_ie
[1],
444 &psecnetwork
->IEs
[12], psecnetwork
->IELength
-12);
446 memcpy(&psecuritypriv
->authenticator_ie
[1],
447 &psecnetwork
->IEs
[12], (256-1));
448 psecnetwork
->IELength
= 0;
449 /* If the the driver wants to use the bssid to create the connection.
450 * If not, we copy the connecting AP's MAC address to it so that
451 * the driver just has the bssid information for PMKIDList searching.
453 if (pmlmepriv
->assoc_by_bssid
== false)
454 memcpy(&pmlmepriv
->assoc_bssid
[0],
455 &pnetwork
->network
.MacAddress
[0], ETH_ALEN
);
456 psecnetwork
->IELength
= r8712_restruct_sec_ie(padapter
,
457 &pnetwork
->network
.IEs
[0],
458 &psecnetwork
->IEs
[0],
459 pnetwork
->network
.IELength
);
460 pqospriv
->qos_option
= 0;
461 if (pregistrypriv
->wmm_enable
) {
464 tmp_len
= r8712_restruct_wmm_ie(padapter
,
465 &pnetwork
->network
.IEs
[0],
466 &psecnetwork
->IEs
[0],
467 pnetwork
->network
.IELength
,
468 psecnetwork
->IELength
);
469 if (psecnetwork
->IELength
!= tmp_len
) {
470 psecnetwork
->IELength
= tmp_len
;
471 pqospriv
->qos_option
= 1; /* WMM IE in beacon */
473 pqospriv
->qos_option
= 0; /* no WMM IE in beacon */
475 if (pregistrypriv
->ht_enable
) {
476 /* For WEP mode, we will use the bg mode to do the connection
477 * to avoid some IOT issues, especially for Realtek 8192u
480 if ((padapter
->securitypriv
.PrivacyAlgrthm
!= _WEP40_
) &&
481 (padapter
->securitypriv
.PrivacyAlgrthm
!= _WEP104_
)) {
482 /* restructure_ht_ie */
483 r8712_restructure_ht_ie(padapter
,
484 &pnetwork
->network
.IEs
[0],
485 &psecnetwork
->IEs
[0],
486 pnetwork
->network
.IELength
,
487 &psecnetwork
->IELength
);
488 if (check_fwstate(pmlmepriv
, WIFI_ADHOC_STATE
))
489 r8712_add_ht_addt_info(padapter
,
490 &pnetwork
->network
.IEs
[0],
491 &psecnetwork
->IEs
[0],
492 pnetwork
->network
.IELength
,
493 &psecnetwork
->IELength
);
496 psecuritypriv
->supplicant_ie
[0] = (u8
)psecnetwork
->IELength
;
497 if (psecnetwork
->IELength
< 255)
498 memcpy(&psecuritypriv
->supplicant_ie
[1], &psecnetwork
->IEs
[0],
499 psecnetwork
->IELength
);
501 memcpy(&psecuritypriv
->supplicant_ie
[1], &psecnetwork
->IEs
[0],
503 /* get cmdsz before endian conversion */
504 pcmd
->cmdsz
= r8712_get_ndis_wlan_bssid_ex_sz(psecnetwork
);
506 /* wlan_network endian conversion */
507 psecnetwork
->Length
= cpu_to_le32(psecnetwork
->Length
);
508 psecnetwork
->Ssid
.SsidLength
= cpu_to_le32(
509 psecnetwork
->Ssid
.SsidLength
);
510 psecnetwork
->Privacy
= cpu_to_le32(psecnetwork
->Privacy
);
511 psecnetwork
->Rssi
= cpu_to_le32(psecnetwork
->Rssi
);
512 psecnetwork
->NetworkTypeInUse
= cpu_to_le32(
513 psecnetwork
->NetworkTypeInUse
);
514 psecnetwork
->Configuration
.ATIMWindow
= cpu_to_le32(
515 psecnetwork
->Configuration
.ATIMWindow
);
516 psecnetwork
->Configuration
.BeaconPeriod
= cpu_to_le32(
517 psecnetwork
->Configuration
.BeaconPeriod
);
518 psecnetwork
->Configuration
.DSConfig
= cpu_to_le32(
519 psecnetwork
->Configuration
.DSConfig
);
520 psecnetwork
->Configuration
.FHConfig
.DwellTime
= cpu_to_le32(
521 psecnetwork
->Configuration
.FHConfig
.DwellTime
);
522 psecnetwork
->Configuration
.FHConfig
.HopPattern
= cpu_to_le32(
523 psecnetwork
->Configuration
.FHConfig
.HopPattern
);
524 psecnetwork
->Configuration
.FHConfig
.HopSet
= cpu_to_le32(
525 psecnetwork
->Configuration
.FHConfig
.HopSet
);
526 psecnetwork
->Configuration
.FHConfig
.Length
= cpu_to_le32(
527 psecnetwork
->Configuration
.FHConfig
.Length
);
528 psecnetwork
->Configuration
.Length
= cpu_to_le32(
529 psecnetwork
->Configuration
.Length
);
530 psecnetwork
->InfrastructureMode
= cpu_to_le32(
531 psecnetwork
->InfrastructureMode
);
532 psecnetwork
->IELength
= cpu_to_le32(psecnetwork
->IELength
);
534 _init_listhead(&pcmd
->list
);
535 pcmd
->cmdcode
= _JoinBss_CMD_
;
536 pcmd
->parmbuf
= (unsigned char *)psecnetwork
;
539 r8712_enqueue_cmd(pcmdpriv
, pcmd
);
543 u8
r8712_disassoc_cmd(struct _adapter
*padapter
) /* for sta_mode */
545 struct cmd_obj
*pdisconnect_cmd
;
546 struct disconnect_parm
*pdisconnect
;
547 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
549 pdisconnect_cmd
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
550 if (pdisconnect_cmd
== NULL
)
552 pdisconnect
= (struct disconnect_parm
*)_malloc(
553 sizeof(struct disconnect_parm
));
554 if (pdisconnect
== NULL
) {
555 kfree((u8
*)pdisconnect_cmd
);
558 init_h2fwcmd_w_parm_no_rsp(pdisconnect_cmd
, pdisconnect
,
560 r8712_enqueue_cmd(pcmdpriv
, pdisconnect_cmd
);
564 u8
r8712_setopmode_cmd(struct _adapter
*padapter
,
565 enum NDIS_802_11_NETWORK_INFRASTRUCTURE networktype
)
567 struct cmd_obj
*ph2c
;
568 struct setopmode_parm
*psetop
;
570 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
572 ph2c
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
575 psetop
= (struct setopmode_parm
*)_malloc(
576 sizeof(struct setopmode_parm
));
577 if (psetop
== NULL
) {
581 init_h2fwcmd_w_parm_no_rsp(ph2c
, psetop
, _SetOpMode_CMD_
);
582 psetop
->mode
= (u8
)networktype
;
583 r8712_enqueue_cmd(pcmdpriv
, ph2c
);
587 u8
r8712_setstakey_cmd(struct _adapter
*padapter
, u8
*psta
, u8 unicast_key
)
589 struct cmd_obj
*ph2c
;
590 struct set_stakey_parm
*psetstakey_para
;
591 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
592 struct set_stakey_rsp
*psetstakey_rsp
= NULL
;
593 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
594 struct security_priv
*psecuritypriv
= &padapter
->securitypriv
;
595 struct sta_info
*sta
= (struct sta_info
*)psta
;
597 ph2c
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
600 psetstakey_para
= (struct set_stakey_parm
*)_malloc(
601 sizeof(struct set_stakey_parm
));
602 if (psetstakey_para
== NULL
) {
606 psetstakey_rsp
= (struct set_stakey_rsp
*)_malloc(
607 sizeof(struct set_stakey_rsp
));
608 if (psetstakey_rsp
== NULL
) {
610 kfree((u8
*) psetstakey_para
);
613 init_h2fwcmd_w_parm_no_rsp(ph2c
, psetstakey_para
, _SetStaKey_CMD_
);
614 ph2c
->rsp
= (u8
*) psetstakey_rsp
;
615 ph2c
->rspsz
= sizeof(struct set_stakey_rsp
);
616 memcpy(psetstakey_para
->addr
, sta
->hwaddr
, ETH_ALEN
);
617 if (check_fwstate(pmlmepriv
, WIFI_STATION_STATE
))
618 psetstakey_para
->algorithm
= (unsigned char)
619 psecuritypriv
->PrivacyAlgrthm
;
621 GET_ENCRY_ALGO(psecuritypriv
, sta
,
622 psetstakey_para
->algorithm
, false);
623 if (unicast_key
== true)
624 memcpy(&psetstakey_para
->key
, &sta
->x_UncstKey
, 16);
626 memcpy(&psetstakey_para
->key
,
627 &psecuritypriv
->XGrpKey
[
628 psecuritypriv
->XGrpKeyid
- 1]. skey
, 16);
629 r8712_enqueue_cmd(pcmdpriv
, ph2c
);
633 u8
r8712_setrfintfs_cmd(struct _adapter
*padapter
, u8 mode
)
635 struct cmd_obj
*ph2c
;
636 struct setrfintfs_parm
*psetrfintfsparm
;
637 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
639 ph2c
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
642 psetrfintfsparm
= (struct setrfintfs_parm
*)_malloc(
643 sizeof(struct setrfintfs_parm
));
644 if (psetrfintfsparm
== NULL
) {
645 kfree((unsigned char *) ph2c
);
648 init_h2fwcmd_w_parm_no_rsp(ph2c
, psetrfintfsparm
,
649 GEN_CMD_CODE(_SetRFIntFs
));
650 psetrfintfsparm
->rfintfs
= mode
;
651 r8712_enqueue_cmd(pcmdpriv
, ph2c
);
655 u8
r8712_setrttbl_cmd(struct _adapter
*padapter
,
656 struct setratable_parm
*prate_table
)
658 struct cmd_obj
*ph2c
;
659 struct setratable_parm
*psetrttblparm
;
660 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
662 ph2c
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
665 psetrttblparm
= (struct setratable_parm
*)_malloc(
666 sizeof(struct setratable_parm
));
667 if (psetrttblparm
== NULL
) {
668 kfree((unsigned char *)ph2c
);
671 init_h2fwcmd_w_parm_no_rsp(ph2c
, psetrttblparm
,
672 GEN_CMD_CODE(_SetRaTable
));
673 memcpy(psetrttblparm
, prate_table
, sizeof(struct setratable_parm
));
674 r8712_enqueue_cmd(pcmdpriv
, ph2c
);
678 u8
r8712_setMacAddr_cmd(struct _adapter
*padapter
, u8
*mac_addr
)
680 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
681 struct cmd_obj
*ph2c
;
682 struct SetMacAddr_param
*psetMacAddr_para
;
684 ph2c
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
687 psetMacAddr_para
= (struct SetMacAddr_param
*)_malloc(
688 sizeof(struct SetMacAddr_param
));
689 if (psetMacAddr_para
== NULL
) {
693 init_h2fwcmd_w_parm_no_rsp(ph2c
, psetMacAddr_para
,
694 _SetMacAddress_CMD_
);
695 memcpy(psetMacAddr_para
->MacAddr
, mac_addr
, ETH_ALEN
);
696 r8712_enqueue_cmd(pcmdpriv
, ph2c
);
700 u8
r8712_setassocsta_cmd(struct _adapter
*padapter
, u8
*mac_addr
)
702 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
703 struct cmd_obj
*ph2c
;
704 struct set_assocsta_parm
*psetassocsta_para
;
705 struct set_stakey_rsp
*psetassocsta_rsp
= NULL
;
707 ph2c
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
710 psetassocsta_para
= (struct set_assocsta_parm
*)
711 _malloc(sizeof(struct set_assocsta_parm
));
712 if (psetassocsta_para
== NULL
) {
716 psetassocsta_rsp
= (struct set_stakey_rsp
*)_malloc(
717 sizeof(struct set_assocsta_rsp
));
718 if (psetassocsta_rsp
== NULL
) {
720 kfree((u8
*)psetassocsta_para
);
723 init_h2fwcmd_w_parm_no_rsp(ph2c
, psetassocsta_para
, _SetAssocSta_CMD_
);
724 ph2c
->rsp
= (u8
*) psetassocsta_rsp
;
725 ph2c
->rspsz
= sizeof(struct set_assocsta_rsp
);
726 memcpy(psetassocsta_para
->addr
, mac_addr
, ETH_ALEN
);
727 r8712_enqueue_cmd(pcmdpriv
, ph2c
);
731 u8
r8712_addbareq_cmd(struct _adapter
*padapter
, u8 tid
)
733 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
734 struct cmd_obj
*ph2c
;
735 struct addBaReq_parm
*paddbareq_parm
;
737 ph2c
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
740 paddbareq_parm
= (struct addBaReq_parm
*)_malloc(
741 sizeof(struct addBaReq_parm
));
742 if (paddbareq_parm
== NULL
) {
743 kfree((unsigned char *)ph2c
);
746 paddbareq_parm
->tid
= tid
;
747 init_h2fwcmd_w_parm_no_rsp(ph2c
, paddbareq_parm
,
748 GEN_CMD_CODE(_AddBAReq
));
749 r8712_enqueue_cmd_ex(pcmdpriv
, ph2c
);
753 u8
r8712_wdg_wk_cmd(struct _adapter
*padapter
)
755 struct cmd_obj
*ph2c
;
756 struct drvint_cmd_parm
*pdrvintcmd_param
;
757 struct cmd_priv
*pcmdpriv
= &padapter
->cmdpriv
;
759 ph2c
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
762 pdrvintcmd_param
= (struct drvint_cmd_parm
*)_malloc(
763 sizeof(struct drvint_cmd_parm
));
764 if (pdrvintcmd_param
== NULL
) {
765 kfree((unsigned char *)ph2c
);
768 pdrvintcmd_param
->i_cid
= WDG_WK_CID
;
769 pdrvintcmd_param
->sz
= 0;
770 pdrvintcmd_param
->pbuf
= NULL
;
771 init_h2fwcmd_w_parm_no_rsp(ph2c
, pdrvintcmd_param
, _DRV_INT_CMD_
);
772 r8712_enqueue_cmd_ex(pcmdpriv
, ph2c
);
776 void r8712_survey_cmd_callback(struct _adapter
*padapter
, struct cmd_obj
*pcmd
)
778 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
780 if (pcmd
->res
!= H2C_SUCCESS
)
781 clr_fwstate(pmlmepriv
, _FW_UNDER_SURVEY
);
782 r8712_free_cmd_obj(pcmd
);
785 void r8712_disassoc_cmd_callback(struct _adapter
*padapter
,
786 struct cmd_obj
*pcmd
)
789 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
791 if (pcmd
->res
!= H2C_SUCCESS
) {
792 spin_lock_irqsave(&pmlmepriv
->lock
, irqL
);
793 set_fwstate(pmlmepriv
, _FW_LINKED
);
794 spin_unlock_irqrestore(&pmlmepriv
->lock
, irqL
);
797 r8712_free_cmd_obj(pcmd
);
800 void r8712_joinbss_cmd_callback(struct _adapter
*padapter
, struct cmd_obj
*pcmd
)
802 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
804 if ((pcmd
->res
!= H2C_SUCCESS
))
805 _set_timer(&pmlmepriv
->assoc_timer
, 1);
806 r8712_free_cmd_obj(pcmd
);
809 void r8712_createbss_cmd_callback(struct _adapter
*padapter
,
810 struct cmd_obj
*pcmd
)
814 struct sta_info
*psta
= NULL
;
815 struct wlan_network
*pwlan
= NULL
;
816 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
817 struct ndis_wlan_bssid_ex
*pnetwork
= (struct ndis_wlan_bssid_ex
*)
819 struct wlan_network
*tgt_network
= &(pmlmepriv
->cur_network
);
821 if ((pcmd
->res
!= H2C_SUCCESS
))
822 _set_timer(&pmlmepriv
->assoc_timer
, 1);
823 _cancel_timer(&pmlmepriv
->assoc_timer
, &timer_cancelled
);
826 pnetwork
->Length
= le32_to_cpu(pnetwork
->Length
);
827 pnetwork
->Ssid
.SsidLength
= le32_to_cpu(pnetwork
->Ssid
.SsidLength
);
828 pnetwork
->Privacy
= le32_to_cpu(pnetwork
->Privacy
);
829 pnetwork
->Rssi
= le32_to_cpu(pnetwork
->Rssi
);
830 pnetwork
->NetworkTypeInUse
= le32_to_cpu(pnetwork
->NetworkTypeInUse
);
831 pnetwork
->Configuration
.ATIMWindow
= le32_to_cpu(pnetwork
->
832 Configuration
.ATIMWindow
);
833 pnetwork
->Configuration
.DSConfig
= le32_to_cpu(pnetwork
->
834 Configuration
.DSConfig
);
835 pnetwork
->Configuration
.FHConfig
.DwellTime
= le32_to_cpu(pnetwork
->
836 Configuration
.FHConfig
.DwellTime
);
837 pnetwork
->Configuration
.FHConfig
.HopPattern
= le32_to_cpu(pnetwork
->
838 Configuration
.FHConfig
.HopPattern
);
839 pnetwork
->Configuration
.FHConfig
.HopSet
= le32_to_cpu(pnetwork
->
840 Configuration
.FHConfig
.HopSet
);
841 pnetwork
->Configuration
.FHConfig
.Length
= le32_to_cpu(pnetwork
->
842 Configuration
.FHConfig
.Length
);
843 pnetwork
->Configuration
.Length
= le32_to_cpu(pnetwork
->
844 Configuration
.Length
);
845 pnetwork
->InfrastructureMode
= le32_to_cpu(pnetwork
->
847 pnetwork
->IELength
= le32_to_cpu(pnetwork
->IELength
);
849 spin_lock_irqsave(&pmlmepriv
->lock
, irqL
);
850 if ((pmlmepriv
->fw_state
) & WIFI_AP_STATE
) {
851 psta
= r8712_get_stainfo(&padapter
->stapriv
,
852 pnetwork
->MacAddress
);
854 psta
= r8712_alloc_stainfo(&padapter
->stapriv
,
855 pnetwork
->MacAddress
);
857 goto createbss_cmd_fail
;
859 r8712_indicate_connect(padapter
);
861 pwlan
= _r8712_alloc_network(pmlmepriv
);
863 pwlan
= r8712_get_oldest_wlan_network(
864 &pmlmepriv
->scanned_queue
);
866 goto createbss_cmd_fail
;
867 pwlan
->last_scanned
= jiffies
;
869 list_insert_tail(&(pwlan
->list
),
870 &pmlmepriv
->scanned_queue
.queue
);
871 pnetwork
->Length
= r8712_get_ndis_wlan_bssid_ex_sz(pnetwork
);
872 memcpy(&(pwlan
->network
), pnetwork
, pnetwork
->Length
);
874 memcpy(&tgt_network
->network
, pnetwork
,
875 (r8712_get_ndis_wlan_bssid_ex_sz(pnetwork
)));
876 if (pmlmepriv
->fw_state
& _FW_UNDER_LINKING
)
877 pmlmepriv
->fw_state
^= _FW_UNDER_LINKING
;
878 /* we will set _FW_LINKED when there is one more sat to
879 * join us (stassoc_event_callback) */
882 spin_unlock_irqrestore(&pmlmepriv
->lock
, irqL
);
883 r8712_free_cmd_obj(pcmd
);
886 void r8712_setstaKey_cmdrsp_callback(struct _adapter
*padapter
,
887 struct cmd_obj
*pcmd
)
889 struct sta_priv
*pstapriv
= &padapter
->stapriv
;
890 struct set_stakey_rsp
*psetstakey_rsp
= (struct set_stakey_rsp
*)
892 struct sta_info
*psta
= r8712_get_stainfo(pstapriv
,
893 psetstakey_rsp
->addr
);
897 psta
->aid
= psta
->mac_id
= psetstakey_rsp
->keyid
; /*CAM_ID(CAM_ENTRY)*/
899 r8712_free_cmd_obj(pcmd
);
902 void r8712_setassocsta_cmdrsp_callback(struct _adapter
*padapter
,
903 struct cmd_obj
*pcmd
)
906 struct sta_priv
*pstapriv
= &padapter
->stapriv
;
907 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
908 struct set_assocsta_parm
*passocsta_parm
=
909 (struct set_assocsta_parm
*)(pcmd
->parmbuf
);
910 struct set_assocsta_rsp
*passocsta_rsp
=
911 (struct set_assocsta_rsp
*) (pcmd
->rsp
);
912 struct sta_info
*psta
= r8712_get_stainfo(pstapriv
,
913 passocsta_parm
->addr
);
917 psta
->aid
= psta
->mac_id
= passocsta_rsp
->cam_id
;
918 spin_lock_irqsave(&pmlmepriv
->lock
, irqL
);
919 if ((check_fwstate(pmlmepriv
, WIFI_MP_STATE
)) &&
920 (check_fwstate(pmlmepriv
, _FW_UNDER_LINKING
)))
921 pmlmepriv
->fw_state
^= _FW_UNDER_LINKING
;
922 set_fwstate(pmlmepriv
, _FW_LINKED
);
923 spin_unlock_irqrestore(&pmlmepriv
->lock
, irqL
);
924 r8712_free_cmd_obj(pcmd
);