Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/upstream-linus
[linux-btrfs-devel.git] / drivers / staging / rtl8712 / rtl871x_cmd.c
blobba92762dbb1c44f3eb280d2f7c51f7d3d5e37fad
1 /******************************************************************************
2 * rtl871x_cmd.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 _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)
53 return _FAIL;
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)
59 return _FAIL;
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;
65 return _SUCCESS;
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)
75 return _FAIL;
76 pevtpriv->evt_buf = pevtpriv->evt_allocated_buf + 4 -
77 ((addr_t)(pevtpriv->evt_allocated_buf) & 3);
78 pevtpriv->evt_done_cnt = 0;
79 return _SUCCESS;
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)
89 if (pcmdpriv) {
90 kfree(pcmdpriv->cmd_allocated_buf);
91 kfree(pcmdpriv->rsp_allocated_buf);
96 Calling Context:
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)
107 unsigned long irqL;
109 if (obj == NULL)
110 return _SUCCESS;
111 spin_lock_irqsave(&queue->lock, irqL);
112 list_insert_tail(&obj->list, &queue->queue);
113 spin_unlock_irqrestore(&queue->lock, irqL);
114 return _SUCCESS;
117 static struct cmd_obj *_dequeue_cmd(struct __queue *queue)
119 unsigned long irqL;
120 struct cmd_obj *obj;
122 spin_lock_irqsave(&(queue->lock), irqL);
123 if (is_list_empty(&(queue->queue)))
124 obj = NULL;
125 else {
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);
131 return obj;
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)
156 int res;
158 if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag == true)
159 return _FAIL;
160 res = _enqueue_cmd(&pcmdpriv->cmd_queue, obj);
161 up(&pcmdpriv->cmd_queue_sema);
162 return res;
165 u32 r8712_enqueue_cmd_ex(struct cmd_priv *pcmdpriv, struct cmd_obj *obj)
167 unsigned long irqL;
168 struct __queue *queue;
170 if (obj == NULL)
171 return _SUCCESS;
172 if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag == true)
173 return _FAIL;
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);
179 return _SUCCESS;
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(~)
201 ### NOTE:#### (!!!!)
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));
214 if (ph2c == NULL)
215 return _FAIL;
216 psurveyPara = (struct sitesurvey_parm *)_malloc(
217 sizeof(struct sitesurvey_parm));
218 if (psurveyPara == NULL) {
219 kfree((unsigned char *) ph2c);
220 return _FAIL;
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);
236 return _SUCCESS;
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));
246 if (ph2c == NULL)
247 return _FAIL;
248 pbsetdataratepara = (struct setdatarate_parm *)_malloc(
249 sizeof(struct setdatarate_parm));
250 if (pbsetdataratepara == NULL) {
251 kfree((u8 *) ph2c);
252 return _FAIL;
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);
259 return _SUCCESS;
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));
269 if (ph2c == NULL)
270 return _FAIL;
271 pssetbasicratepara = (struct setbasicrate_parm *)_malloc(
272 sizeof(struct setbasicrate_parm));
273 if (pssetbasicratepara == NULL) {
274 kfree((u8 *) ph2c);
275 return _FAIL;
277 init_h2fwcmd_w_parm_no_rsp(ph2c, pssetbasicratepara,
278 _SetBasicRate_CMD_);
279 memcpy(pssetbasicratepara->basicrates, rateset, NumRates);
280 r8712_enqueue_cmd(pcmdpriv, ph2c);
281 return _SUCCESS;
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));
292 if (ph2c == NULL)
293 return _FAIL;
294 pptparm = (struct PT_param *)_malloc(sizeof(struct PT_param));
295 if (pptparm == NULL) {
296 kfree((u8 *) ph2c);
297 return _FAIL;
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);
303 return _SUCCESS;
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));
313 if (ph2c == NULL)
314 return _FAIL;
315 pwriterfparm = (struct writeRF_parm *)_malloc(
316 sizeof(struct writeRF_parm));
317 if (pwriterfparm == NULL) {
318 kfree((u8 *) ph2c);
319 return _FAIL;
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);
325 return _SUCCESS;
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));
335 if (ph2c == NULL)
336 return _FAIL;
337 prdrfparm = (struct readRF_parm *)_malloc(sizeof(struct readRF_parm));
338 if (prdrfparm == NULL) {
339 kfree((u8 *) ph2c);
340 return _FAIL;
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);
346 ph2c->rsp = pval;
347 ph2c->rspsz = sizeof(struct readRF_rsp);
348 prdrfparm->offset = offset;
349 r8712_enqueue_cmd(pcmdpriv, ph2c);
350 return _SUCCESS;
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));
370 if (pcmd == NULL)
371 return _FAIL;
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 *)
377 pdev_network);
378 pcmd->rsp = NULL;
379 pcmd->rspsz = 0;
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);
386 return _SUCCESS;
389 u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork)
391 u8 *auth;
392 uint t_len = 0;
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));
405 if (pcmd == NULL)
406 return _FAIL;
407 t_len = sizeof(u32) + 6 * sizeof(unsigned char) + 2 +
408 sizeof(struct ndis_802_11_ssid) + sizeof(u32) +
409 sizeof(s32) +
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) !=
418 true) {
419 switch (ndis_network_mode) {
420 case Ndis802_11IBSS:
421 pmlmepriv->fw_state |= WIFI_ADHOC_STATE;
422 break;
423 case Ndis802_11Infrastructure:
424 pmlmepriv->fw_state |= WIFI_STATION_STATE;
425 break;
426 case Ndis802_11APMode:
427 case Ndis802_11AutoUnknown:
428 case Ndis802_11InfrastructureMax:
429 break;
432 psecnetwork = (struct ndis_wlan_bssid_ex *)&psecuritypriv->sec_bss;
433 if (psecnetwork == NULL) {
434 kfree(pcmd);
435 return _FAIL;
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);
445 else
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) {
462 u32 tmp_len;
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 */
472 } else
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
478 * SoftAP.
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);
500 else
501 memcpy(&psecuritypriv->supplicant_ie[1], &psecnetwork->IEs[0],
502 255);
503 /* get cmdsz before endian conversion */
504 pcmd->cmdsz = r8712_get_ndis_wlan_bssid_ex_sz(psecnetwork);
505 #ifdef __BIG_ENDIAN
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);
533 #endif
534 _init_listhead(&pcmd->list);
535 pcmd->cmdcode = _JoinBss_CMD_;
536 pcmd->parmbuf = (unsigned char *)psecnetwork;
537 pcmd->rsp = NULL;
538 pcmd->rspsz = 0;
539 r8712_enqueue_cmd(pcmdpriv, pcmd);
540 return _SUCCESS;
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)
551 return _FAIL;
552 pdisconnect = (struct disconnect_parm *)_malloc(
553 sizeof(struct disconnect_parm));
554 if (pdisconnect == NULL) {
555 kfree((u8 *)pdisconnect_cmd);
556 return _FAIL;
558 init_h2fwcmd_w_parm_no_rsp(pdisconnect_cmd, pdisconnect,
559 _DisConnect_CMD_);
560 r8712_enqueue_cmd(pcmdpriv, pdisconnect_cmd);
561 return _SUCCESS;
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));
573 if (ph2c == NULL)
574 return _FAIL;
575 psetop = (struct setopmode_parm *)_malloc(
576 sizeof(struct setopmode_parm));
577 if (psetop == NULL) {
578 kfree((u8 *) ph2c);
579 return _FAIL;
581 init_h2fwcmd_w_parm_no_rsp(ph2c, psetop, _SetOpMode_CMD_);
582 psetop->mode = (u8)networktype;
583 r8712_enqueue_cmd(pcmdpriv, ph2c);
584 return _SUCCESS;
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));
598 if (ph2c == NULL)
599 return _FAIL;
600 psetstakey_para = (struct set_stakey_parm *)_malloc(
601 sizeof(struct set_stakey_parm));
602 if (psetstakey_para == NULL) {
603 kfree((u8 *) ph2c);
604 return _FAIL;
606 psetstakey_rsp = (struct set_stakey_rsp *)_malloc(
607 sizeof(struct set_stakey_rsp));
608 if (psetstakey_rsp == NULL) {
609 kfree((u8 *) ph2c);
610 kfree((u8 *) psetstakey_para);
611 return _FAIL;
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;
620 else
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);
625 else
626 memcpy(&psetstakey_para->key,
627 &psecuritypriv->XGrpKey[
628 psecuritypriv->XGrpKeyid - 1]. skey, 16);
629 r8712_enqueue_cmd(pcmdpriv, ph2c);
630 return _SUCCESS;
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));
640 if (ph2c == NULL)
641 return _FAIL;
642 psetrfintfsparm = (struct setrfintfs_parm *)_malloc(
643 sizeof(struct setrfintfs_parm));
644 if (psetrfintfsparm == NULL) {
645 kfree((unsigned char *) ph2c);
646 return _FAIL;
648 init_h2fwcmd_w_parm_no_rsp(ph2c, psetrfintfsparm,
649 GEN_CMD_CODE(_SetRFIntFs));
650 psetrfintfsparm->rfintfs = mode;
651 r8712_enqueue_cmd(pcmdpriv, ph2c);
652 return _SUCCESS;
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));
663 if (ph2c == NULL)
664 return _FAIL;
665 psetrttblparm = (struct setratable_parm *)_malloc(
666 sizeof(struct setratable_parm));
667 if (psetrttblparm == NULL) {
668 kfree((unsigned char *)ph2c);
669 return _FAIL;
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);
675 return _SUCCESS;
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));
685 if (ph2c == NULL)
686 return _FAIL;
687 psetMacAddr_para = (struct SetMacAddr_param *)_malloc(
688 sizeof(struct SetMacAddr_param));
689 if (psetMacAddr_para == NULL) {
690 kfree((u8 *) ph2c);
691 return _FAIL;
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);
697 return _SUCCESS;
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));
708 if (ph2c == NULL)
709 return _FAIL;
710 psetassocsta_para = (struct set_assocsta_parm *)
711 _malloc(sizeof(struct set_assocsta_parm));
712 if (psetassocsta_para == NULL) {
713 kfree((u8 *) ph2c);
714 return _FAIL;
716 psetassocsta_rsp = (struct set_stakey_rsp *)_malloc(
717 sizeof(struct set_assocsta_rsp));
718 if (psetassocsta_rsp == NULL) {
719 kfree((u8 *)ph2c);
720 kfree((u8 *)psetassocsta_para);
721 return _FAIL;
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);
728 return _SUCCESS;
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));
738 if (ph2c == NULL)
739 return _FAIL;
740 paddbareq_parm = (struct addBaReq_parm *)_malloc(
741 sizeof(struct addBaReq_parm));
742 if (paddbareq_parm == NULL) {
743 kfree((unsigned char *)ph2c);
744 return _FAIL;
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);
750 return _SUCCESS;
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));
760 if (ph2c == NULL)
761 return _FAIL;
762 pdrvintcmd_param = (struct drvint_cmd_parm *)_malloc(
763 sizeof(struct drvint_cmd_parm));
764 if (pdrvintcmd_param == NULL) {
765 kfree((unsigned char *)ph2c);
766 return _FAIL;
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);
773 return _SUCCESS;
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)
788 unsigned long irqL;
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);
795 return;
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)
812 unsigned long irqL;
813 u8 timer_cancelled;
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 *)
818 pcmd->parmbuf;
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);
824 #ifdef __BIG_ENDIAN
825 /* endian_convert */
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->
846 InfrastructureMode);
847 pnetwork->IELength = le32_to_cpu(pnetwork->IELength);
848 #endif
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);
853 if (!psta) {
854 psta = r8712_alloc_stainfo(&padapter->stapriv,
855 pnetwork->MacAddress);
856 if (psta == NULL)
857 goto createbss_cmd_fail ;
859 r8712_indicate_connect(padapter);
860 } else {
861 pwlan = _r8712_alloc_network(pmlmepriv);
862 if (pwlan == NULL) {
863 pwlan = r8712_get_oldest_wlan_network(
864 &pmlmepriv->scanned_queue);
865 if (pwlan == NULL)
866 goto createbss_cmd_fail;
867 pwlan->last_scanned = jiffies;
868 } else
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);
873 pwlan->fixed = true;
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) */
881 createbss_cmd_fail:
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 *)
891 (pcmd->rsp);
892 struct sta_info *psta = r8712_get_stainfo(pstapriv,
893 psetstakey_rsp->addr);
895 if (psta == NULL)
896 goto exit;
897 psta->aid = psta->mac_id = psetstakey_rsp->keyid; /*CAM_ID(CAM_ENTRY)*/
898 exit:
899 r8712_free_cmd_obj(pcmd);
902 void r8712_setassocsta_cmdrsp_callback(struct _adapter *padapter,
903 struct cmd_obj *pcmd)
905 unsigned long irqL;
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);
915 if (psta == NULL)
916 return;
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);