Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rtl871x_cmd.c
Go to the documentation of this file.
1 /******************************************************************************
2  * rtl871x_cmd.c
3  *
4  * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5  * Linux device driver for RTL8192SU
6  *
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.
10  *
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.
15  *
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
19  *
20  * Modifications for inclusion into the Linux staging tree are
21  * Copyright(c) 2010 Larry Finger. All rights reserved.
22  *
23  * Contact information:
24  * WLAN FAE <[email protected]>
25  * Larry Finger <[email protected]>
26  *
27  ******************************************************************************/
28 
29 #define _RTL871X_CMD_C_
30 
31 #include <linux/compiler.h>
32 #include <linux/kernel.h>
33 #include <linux/errno.h>
34 #include <linux/init.h>
35 #include <linux/slab.h>
36 #include <linux/module.h>
37 #include <linux/kref.h>
38 #include <linux/netdevice.h>
39 #include <linux/skbuff.h>
40 #include <linux/usb.h>
41 #include <linux/usb/ch9.h>
42 #include <linux/circ_buf.h>
43 #include <linux/uaccess.h>
44 #include <asm/byteorder.h>
45 #include <linux/atomic.h>
46 #include <linux/semaphore.h>
47 #include <linux/rtnetlink.h>
48 
49 #include "osdep_service.h"
50 #include "drv_types.h"
51 #include "recv_osdep.h"
52 #include "mlme_osdep.h"
53 
54 /*
55 Caller and the r8712_cmd_thread can protect cmd_q by spin_lock.
56 No irqsave is necessary.
57 */
58 
59 static sint _init_cmd_priv(struct cmd_priv *pcmdpriv)
60 {
61  sema_init(&(pcmdpriv->cmd_queue_sema), 0);
62  sema_init(&(pcmdpriv->terminate_cmdthread_sema), 0);
63 
64  _init_queue(&(pcmdpriv->cmd_queue));
65 
66  /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
67  pcmdpriv->cmd_seq = 1;
68  pcmdpriv->cmd_allocated_buf = _malloc(MAX_CMDSZ + CMDBUFF_ALIGN_SZ);
69  if (pcmdpriv->cmd_allocated_buf == NULL)
70  return _FAIL;
71  pcmdpriv->cmd_buf = pcmdpriv->cmd_allocated_buf + CMDBUFF_ALIGN_SZ -
72  ((addr_t)(pcmdpriv->cmd_allocated_buf) &
73  (CMDBUFF_ALIGN_SZ-1));
74  pcmdpriv->rsp_allocated_buf = _malloc(MAX_RSPSZ + 4);
75  if (pcmdpriv->rsp_allocated_buf == NULL)
76  return _FAIL;
77  pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf + 4 -
78  ((addr_t)(pcmdpriv->rsp_allocated_buf) & 3);
79  pcmdpriv->cmd_issued_cnt = 0;
80  pcmdpriv->cmd_done_cnt = 0;
81  pcmdpriv->rsp_cnt = 0;
82  return _SUCCESS;
83 }
84 
85 static sint _init_evt_priv(struct evt_priv *pevtpriv)
86 {
87  /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
88  pevtpriv->event_seq = 0;
89  pevtpriv->evt_allocated_buf = _malloc(MAX_EVTSZ + 4);
90 
91  if (pevtpriv->evt_allocated_buf == NULL)
92  return _FAIL;
93  pevtpriv->evt_buf = pevtpriv->evt_allocated_buf + 4 -
94  ((addr_t)(pevtpriv->evt_allocated_buf) & 3);
95  pevtpriv->evt_done_cnt = 0;
96  return _SUCCESS;
97 }
98 
99 static void _free_evt_priv(struct evt_priv *pevtpriv)
100 {
101  kfree(pevtpriv->evt_allocated_buf);
102 }
103 
104 static void _free_cmd_priv(struct cmd_priv *pcmdpriv)
105 {
106  if (pcmdpriv) {
107  kfree(pcmdpriv->cmd_allocated_buf);
108  kfree(pcmdpriv->rsp_allocated_buf);
109  }
110 }
111 
112 /*
113 Calling Context:
114 
115 _enqueue_cmd can only be called between kernel thread,
116 since only spin_lock is used.
117 
118 ISR/Call-Back functions can't call this sub-function.
119 
120 */
121 
122 static sint _enqueue_cmd(struct __queue *queue, struct cmd_obj *obj)
123 {
124  unsigned long irqL;
125 
126  if (obj == NULL)
127  return _SUCCESS;
128  spin_lock_irqsave(&queue->lock, irqL);
129  list_insert_tail(&obj->list, &queue->queue);
130  spin_unlock_irqrestore(&queue->lock, irqL);
131  return _SUCCESS;
132 }
133 
134 static struct cmd_obj *_dequeue_cmd(struct __queue *queue)
135 {
136  unsigned long irqL;
137  struct cmd_obj *obj;
138 
139  spin_lock_irqsave(&(queue->lock), irqL);
140  if (is_list_empty(&(queue->queue)))
141  obj = NULL;
142  else {
143  obj = LIST_CONTAINOR(get_next(&(queue->queue)),
144  struct cmd_obj, list);
145  list_delete(&obj->list);
146  }
147  spin_unlock_irqrestore(&(queue->lock), irqL);
148  return obj;
149 }
150 
152 {
153  return _init_cmd_priv(pcmdpriv);
154 }
155 
157 {
158  return _init_evt_priv(pevtpriv);
159 }
160 
161 void r8712_free_evt_priv(struct evt_priv *pevtpriv)
162 {
163  _free_evt_priv(pevtpriv);
164 }
165 
166 void r8712_free_cmd_priv(struct cmd_priv *pcmdpriv)
167 {
168  _free_cmd_priv(pcmdpriv);
169 }
170 
171 u32 r8712_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *obj)
172 {
173  int res;
174 
175  if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag == true)
176  return _FAIL;
177  res = _enqueue_cmd(&pcmdpriv->cmd_queue, obj);
178  up(&pcmdpriv->cmd_queue_sema);
179  return res;
180 }
181 
182 u32 r8712_enqueue_cmd_ex(struct cmd_priv *pcmdpriv, struct cmd_obj *obj)
183 {
184  unsigned long irqL;
185  struct __queue *queue;
186 
187  if (obj == NULL)
188  return _SUCCESS;
189  if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag == true)
190  return _FAIL;
191  queue = &pcmdpriv->cmd_queue;
192  spin_lock_irqsave(&queue->lock, irqL);
193  list_insert_tail(&obj->list, &queue->queue);
194  spin_unlock_irqrestore(&queue->lock, irqL);
195  up(&pcmdpriv->cmd_queue_sema);
196  return _SUCCESS;
197 }
198 
199 struct cmd_obj *r8712_dequeue_cmd(struct __queue *queue)
200 {
201  return _dequeue_cmd(queue);
202 }
203 
204 void r8712_free_cmd_obj(struct cmd_obj *pcmd)
205 {
206  if ((pcmd->cmdcode != _JoinBss_CMD_) &&
207  (pcmd->cmdcode != _CreateBss_CMD_))
208  kfree((unsigned char *)pcmd->parmbuf);
209  if (pcmd->rsp != NULL) {
210  if (pcmd->rspsz != 0)
211  kfree((unsigned char *)pcmd->rsp);
212  }
213  kfree((unsigned char *)pcmd);
214 }
215 
216 /*
217 r8712_sitesurvey_cmd(~)
218  ### NOTE:#### (!!!!)
219  MUST TAKE CARE THAT BEFORE CALLING THIS FUNC,
220  YOU SHOULD HAVE LOCKED pmlmepriv->lock
221 */
223  struct ndis_802_11_ssid *pssid)
224 {
225  struct cmd_obj *ph2c;
226  struct sitesurvey_parm *psurveyPara;
227  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
228  struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
229 
230  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
231  if (ph2c == NULL)
232  return _FAIL;
233  psurveyPara = (struct sitesurvey_parm *)_malloc(
234  sizeof(struct sitesurvey_parm));
235  if (psurveyPara == NULL) {
236  kfree((unsigned char *) ph2c);
237  return _FAIL;
238  }
239  init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara,
240  GEN_CMD_CODE(_SiteSurvey));
241  psurveyPara->bsslimit = cpu_to_le32(48);
242  psurveyPara->passive_mode = cpu_to_le32(pmlmepriv->passive_mode);
243  psurveyPara->ss_ssidlen = 0;
244  memset(psurveyPara->ss_ssid, 0, IW_ESSID_MAX_SIZE + 1);
245  if ((pssid != NULL) && (pssid->SsidLength)) {
246  memcpy(psurveyPara->ss_ssid, pssid->Ssid, pssid->SsidLength);
247  psurveyPara->ss_ssidlen = cpu_to_le32(pssid->SsidLength);
248  }
249  set_fwstate(pmlmepriv, _FW_UNDER_SURVEY);
250  r8712_enqueue_cmd(pcmdpriv, ph2c);
251  _set_timer(&pmlmepriv->scan_to_timer, SCANNING_TIMEOUT);
252  padapter->ledpriv.LedControlHandler(padapter, LED_CTL_SITE_SURVEY);
253  padapter->blnEnableRxFF0Filter = 0;
254  return _SUCCESS;
255 }
256 
257 u8 r8712_setdatarate_cmd(struct _adapter *padapter, u8 *rateset)
258 {
259  struct cmd_obj *ph2c;
260  struct setdatarate_parm *pbsetdataratepara;
261  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
262 
263  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
264  if (ph2c == NULL)
265  return _FAIL;
266  pbsetdataratepara = (struct setdatarate_parm *)_malloc(
267  sizeof(struct setdatarate_parm));
268  if (pbsetdataratepara == NULL) {
269  kfree((u8 *) ph2c);
270  return _FAIL;
271  }
272  init_h2fwcmd_w_parm_no_rsp(ph2c, pbsetdataratepara,
273  GEN_CMD_CODE(_SetDataRate));
274  pbsetdataratepara->mac_id = 5;
275  memcpy(pbsetdataratepara->datarates, rateset, NumRates);
276  r8712_enqueue_cmd(pcmdpriv, ph2c);
277  return _SUCCESS;
278 }
279 
280 u8 r8712_set_chplan_cmd(struct _adapter *padapter, int chplan)
281 {
282  struct cmd_obj *ph2c;
283  struct SetChannelPlan_param *psetchplanpara;
284  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
285 
286  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
287  if (ph2c == NULL)
288  return _FAIL;
289  psetchplanpara = (struct SetChannelPlan_param *)
290  _malloc(sizeof(struct SetChannelPlan_param));
291  if (psetchplanpara == NULL) {
292  kfree((u8 *) ph2c);
293  return _FAIL;
294  }
295  init_h2fwcmd_w_parm_no_rsp(ph2c, psetchplanpara,
296  GEN_CMD_CODE(_SetChannelPlan));
297  psetchplanpara->ChannelPlan = chplan;
298  r8712_enqueue_cmd(pcmdpriv, ph2c);
299  return _SUCCESS;
300 }
301 
302 u8 r8712_setbasicrate_cmd(struct _adapter *padapter, u8 *rateset)
303 {
304  struct cmd_obj *ph2c;
305  struct setbasicrate_parm *pssetbasicratepara;
306  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
307 
308  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
309  if (ph2c == NULL)
310  return _FAIL;
311  pssetbasicratepara = (struct setbasicrate_parm *)_malloc(
312  sizeof(struct setbasicrate_parm));
313  if (pssetbasicratepara == NULL) {
314  kfree((u8 *) ph2c);
315  return _FAIL;
316  }
317  init_h2fwcmd_w_parm_no_rsp(ph2c, pssetbasicratepara,
318  _SetBasicRate_CMD_);
319  memcpy(pssetbasicratepara->basicrates, rateset, NumRates);
320  r8712_enqueue_cmd(pcmdpriv, ph2c);
321  return _SUCCESS;
322 }
323 
324 /* power tracking mechanism setting */
325 u8 r8712_setptm_cmd(struct _adapter *padapter, u8 type)
326 {
327  struct cmd_obj *ph2c;
328  struct writePTM_parm *pwriteptmparm;
329  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
330 
331  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
332  if (ph2c == NULL)
333  return _FAIL;
334  pwriteptmparm = (struct writePTM_parm *)
335  _malloc(sizeof(struct writePTM_parm));
336  if (pwriteptmparm == NULL) {
337  kfree((u8 *) ph2c);
338  return _FAIL;
339  }
340  init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteptmparm, GEN_CMD_CODE(_SetPT));
341  pwriteptmparm->type = type;
342  r8712_enqueue_cmd(pcmdpriv, ph2c);
343  return _SUCCESS;
344 }
345 
347 {
348  struct cmd_obj *ph2c;
349  struct writePTM_parm *pwriteptmparm;
350  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
351 
352  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
353  if (ph2c == NULL)
354  return _FAIL;
355  pwriteptmparm = (struct writePTM_parm *)
356  _malloc(sizeof(struct setdig_parm));
357  if (pwriteptmparm == NULL) {
358  kfree((u8 *) ph2c);
359  return _FAIL;
360  }
361  init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteptmparm, GEN_CMD_CODE(_SetDIG));
362  pwriteptmparm->type = type;
363  r8712_enqueue_cmd(pcmdpriv, ph2c);
364  return _SUCCESS;
365 }
366 
367 u8 r8712_setfwra_cmd(struct _adapter *padapter, u8 type)
368 {
369  struct cmd_obj *ph2c;
370  struct writePTM_parm *pwriteptmparm;
371  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
372 
373  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
374  if (ph2c == NULL)
375  return _FAIL;
376  pwriteptmparm = (struct writePTM_parm *)
377  _malloc(sizeof(struct setra_parm));
378  if (pwriteptmparm == NULL) {
379  kfree((u8 *) ph2c);
380  return _FAIL;
381  }
382  init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteptmparm, GEN_CMD_CODE(_SetRA));
383  pwriteptmparm->type = type;
384  r8712_enqueue_cmd(pcmdpriv, ph2c);
385  return _SUCCESS;
386 }
387 
389 {
390  struct cmd_obj *ph2c;
391  struct writeRF_parm *pwriterfparm;
392  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
393 
394  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
395  if (ph2c == NULL)
396  return _FAIL;
397  pwriterfparm = (struct writeRF_parm *)_malloc(
398  sizeof(struct writeRF_parm));
399  if (pwriterfparm == NULL) {
400  kfree((u8 *) ph2c);
401  return _FAIL;
402  }
403  init_h2fwcmd_w_parm_no_rsp(ph2c, pwriterfparm, GEN_CMD_CODE(_SetRFReg));
404  pwriterfparm->offset = offset;
405  pwriterfparm->value = val;
406  r8712_enqueue_cmd(pcmdpriv, ph2c);
407  return _SUCCESS;
408 }
409 
410 u8 r8712_getrfreg_cmd(struct _adapter *padapter, u8 offset, u8 *pval)
411 {
412  struct cmd_obj *ph2c;
413  struct readRF_parm *prdrfparm;
414  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
415 
416  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
417  if (ph2c == NULL)
418  return _FAIL;
419  prdrfparm = (struct readRF_parm *)_malloc(sizeof(struct readRF_parm));
420  if (prdrfparm == NULL) {
421  kfree((u8 *) ph2c);
422  return _FAIL;
423  }
424  _init_listhead(&ph2c->list);
425  ph2c->cmdcode = GEN_CMD_CODE(_GetRFReg);
426  ph2c->parmbuf = (unsigned char *)prdrfparm;
427  ph2c->cmdsz = sizeof(struct readRF_parm);
428  ph2c->rsp = pval;
429  ph2c->rspsz = sizeof(struct readRF_rsp);
430  prdrfparm->offset = offset;
431  r8712_enqueue_cmd(pcmdpriv, ph2c);
432  return _SUCCESS;
433 }
434 
436  struct cmd_obj *pcmd)
437 {
438  kfree(pcmd->parmbuf);
439  kfree(pcmd);
440  padapter->mppriv.workparam.bcompleted = true;
441 }
442 
444  struct cmd_obj *pcmd)
445 {
446  kfree(pcmd->parmbuf);
447  kfree(pcmd);
448 
449  padapter->mppriv.workparam.bcompleted = true;
450 }
451 
452 u8 r8712_createbss_cmd(struct _adapter *padapter)
453 {
454  struct cmd_obj *pcmd;
455  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
456  struct wlan_bssid_ex *pdev_network =
457  &padapter->registrypriv.dev_network;
458 
459  padapter->ledpriv.LedControlHandler(padapter, LED_CTL_START_TO_LINK);
460  pcmd = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
461  if (pcmd == NULL)
462  return _FAIL;
463  _init_listhead(&pcmd->list);
464  pcmd->cmdcode = _CreateBss_CMD_;
465  pcmd->parmbuf = (unsigned char *)pdev_network;
467  struct ndis_wlan_bssid_ex *)
468  pdev_network);
469  pcmd->rsp = NULL;
470  pcmd->rspsz = 0;
471  /* notes: translate IELength & Length after assign to cmdsz; */
472  pdev_network->Length = cpu_to_le32(pcmd->cmdsz);
473  pdev_network->IELength = cpu_to_le32(pdev_network->IELength);
474  pdev_network->Ssid.SsidLength = cpu_to_le32(
475  pdev_network->Ssid.SsidLength);
476  r8712_enqueue_cmd(pcmdpriv, pcmd);
477  return _SUCCESS;
478 }
479 
480 u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork)
481 {
482  u8 *auth;
483  uint t_len = 0;
484  struct ndis_wlan_bssid_ex *psecnetwork;
485  struct cmd_obj *pcmd;
486  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
487  struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
488  struct qos_priv *pqospriv = &pmlmepriv->qospriv;
489  struct security_priv *psecuritypriv = &padapter->securitypriv;
490  struct registry_priv *pregistrypriv = &padapter->registrypriv;
491  enum NDIS_802_11_NETWORK_INFRASTRUCTURE ndis_network_mode = pnetwork->
492  network.InfrastructureMode;
493 
494  padapter->ledpriv.LedControlHandler(padapter, LED_CTL_START_TO_LINK);
495  pcmd = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
496  if (pcmd == NULL)
497  return _FAIL;
498  t_len = sizeof(u32) + 6 * sizeof(unsigned char) + 2 +
499  sizeof(struct ndis_802_11_ssid) + sizeof(u32) +
500  sizeof(s32) +
501  sizeof(enum NDIS_802_11_NETWORK_TYPE) +
502  sizeof(struct NDIS_802_11_CONFIGURATION) +
503  sizeof(enum NDIS_802_11_NETWORK_INFRASTRUCTURE) +
504  sizeof(NDIS_802_11_RATES_EX) +
505  sizeof(u32) + MAX_IE_SZ;
506 
507  /* for hidden ap to set fw_state here */
508  if (check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_ADHOC_STATE) !=
509  true) {
510  switch (ndis_network_mode) {
511  case Ndis802_11IBSS:
512  pmlmepriv->fw_state |= WIFI_ADHOC_STATE;
513  break;
515  pmlmepriv->fw_state |= WIFI_STATION_STATE;
516  break;
517  case Ndis802_11APMode:
520  break;
521  }
522  }
523  psecnetwork = (struct ndis_wlan_bssid_ex *)&psecuritypriv->sec_bss;
524  if (psecnetwork == NULL) {
525  kfree(pcmd);
526  return _FAIL;
527  }
528  memset(psecnetwork, 0, t_len);
529  memcpy(psecnetwork, &pnetwork->network, t_len);
530  auth = &psecuritypriv->authenticator_ie[0];
531  psecuritypriv->authenticator_ie[0] = (unsigned char)
532  psecnetwork->IELength;
533  if ((psecnetwork->IELength-12) < (256 - 1))
534  memcpy(&psecuritypriv->authenticator_ie[1],
535  &psecnetwork->IEs[12], psecnetwork->IELength-12);
536  else
537  memcpy(&psecuritypriv->authenticator_ie[1],
538  &psecnetwork->IEs[12], (256-1));
539  psecnetwork->IELength = 0;
540  /* If the the driver wants to use the bssid to create the connection.
541  * If not, we copy the connecting AP's MAC address to it so that
542  * the driver just has the bssid information for PMKIDList searching.
543  */
544  if (pmlmepriv->assoc_by_bssid == false)
545  memcpy(&pmlmepriv->assoc_bssid[0],
546  &pnetwork->network.MacAddress[0], ETH_ALEN);
547  psecnetwork->IELength = r8712_restruct_sec_ie(padapter,
548  &pnetwork->network.IEs[0],
549  &psecnetwork->IEs[0],
550  pnetwork->network.IELength);
551  pqospriv->qos_option = 0;
552  if (pregistrypriv->wmm_enable) {
553  u32 tmp_len;
554 
555  tmp_len = r8712_restruct_wmm_ie(padapter,
556  &pnetwork->network.IEs[0],
557  &psecnetwork->IEs[0],
558  pnetwork->network.IELength,
559  psecnetwork->IELength);
560  if (psecnetwork->IELength != tmp_len) {
561  psecnetwork->IELength = tmp_len;
562  pqospriv->qos_option = 1; /* WMM IE in beacon */
563  } else
564  pqospriv->qos_option = 0; /* no WMM IE in beacon */
565  }
566  if (pregistrypriv->ht_enable) {
567  /* For WEP mode, we will use the bg mode to do the connection
568  * to avoid some IOT issues, especially for Realtek 8192u
569  * SoftAP.
570  */
571  if ((padapter->securitypriv.PrivacyAlgrthm != _WEP40_) &&
572  (padapter->securitypriv.PrivacyAlgrthm != _WEP104_)) {
573  /* restructure_ht_ie */
574  r8712_restructure_ht_ie(padapter,
575  &pnetwork->network.IEs[0],
576  &psecnetwork->IEs[0],
577  pnetwork->network.IELength,
578  &psecnetwork->IELength);
579  }
580  }
581  psecuritypriv->supplicant_ie[0] = (u8)psecnetwork->IELength;
582  if (psecnetwork->IELength < 255)
583  memcpy(&psecuritypriv->supplicant_ie[1], &psecnetwork->IEs[0],
584  psecnetwork->IELength);
585  else
586  memcpy(&psecuritypriv->supplicant_ie[1], &psecnetwork->IEs[0],
587  255);
588  /* get cmdsz before endian conversion */
589  pcmd->cmdsz = r8712_get_ndis_wlan_bssid_ex_sz(psecnetwork);
590 #ifdef __BIG_ENDIAN
591  /* wlan_network endian conversion */
592  psecnetwork->Length = cpu_to_le32(psecnetwork->Length);
593  psecnetwork->Ssid.SsidLength = cpu_to_le32(
594  psecnetwork->Ssid.SsidLength);
595  psecnetwork->Privacy = cpu_to_le32(psecnetwork->Privacy);
596  psecnetwork->Rssi = cpu_to_le32(psecnetwork->Rssi);
597  psecnetwork->NetworkTypeInUse = cpu_to_le32(
598  psecnetwork->NetworkTypeInUse);
599  psecnetwork->Configuration.ATIMWindow = cpu_to_le32(
600  psecnetwork->Configuration.ATIMWindow);
601  psecnetwork->Configuration.BeaconPeriod = cpu_to_le32(
602  psecnetwork->Configuration.BeaconPeriod);
603  psecnetwork->Configuration.DSConfig = cpu_to_le32(
604  psecnetwork->Configuration.DSConfig);
605  psecnetwork->Configuration.FHConfig.DwellTime = cpu_to_le32(
606  psecnetwork->Configuration.FHConfig.DwellTime);
607  psecnetwork->Configuration.FHConfig.HopPattern = cpu_to_le32(
608  psecnetwork->Configuration.FHConfig.HopPattern);
609  psecnetwork->Configuration.FHConfig.HopSet = cpu_to_le32(
610  psecnetwork->Configuration.FHConfig.HopSet);
611  psecnetwork->Configuration.FHConfig.Length = cpu_to_le32(
612  psecnetwork->Configuration.FHConfig.Length);
613  psecnetwork->Configuration.Length = cpu_to_le32(
614  psecnetwork->Configuration.Length);
615  psecnetwork->InfrastructureMode = cpu_to_le32(
616  psecnetwork->InfrastructureMode);
617  psecnetwork->IELength = cpu_to_le32(psecnetwork->IELength);
618 #endif
619  _init_listhead(&pcmd->list);
620  pcmd->cmdcode = _JoinBss_CMD_;
621  pcmd->parmbuf = (unsigned char *)psecnetwork;
622  pcmd->rsp = NULL;
623  pcmd->rspsz = 0;
624  r8712_enqueue_cmd(pcmdpriv, pcmd);
625  return _SUCCESS;
626 }
627 
628 u8 r8712_disassoc_cmd(struct _adapter *padapter) /* for sta_mode */
629 {
630  struct cmd_obj *pdisconnect_cmd;
631  struct disconnect_parm *pdisconnect;
632  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
633 
634  pdisconnect_cmd = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
635  if (pdisconnect_cmd == NULL)
636  return _FAIL;
637  pdisconnect = (struct disconnect_parm *)_malloc(
638  sizeof(struct disconnect_parm));
639  if (pdisconnect == NULL) {
640  kfree((u8 *)pdisconnect_cmd);
641  return _FAIL;
642  }
643  init_h2fwcmd_w_parm_no_rsp(pdisconnect_cmd, pdisconnect,
644  _DisConnect_CMD_);
645  r8712_enqueue_cmd(pcmdpriv, pdisconnect_cmd);
646  return _SUCCESS;
647 }
648 
649 u8 r8712_setopmode_cmd(struct _adapter *padapter,
650  enum NDIS_802_11_NETWORK_INFRASTRUCTURE networktype)
651 {
652  struct cmd_obj *ph2c;
653  struct setopmode_parm *psetop;
654 
655  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
656 
657  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
658  if (ph2c == NULL)
659  return _FAIL;
660  psetop = (struct setopmode_parm *)_malloc(
661  sizeof(struct setopmode_parm));
662  if (psetop == NULL) {
663  kfree((u8 *) ph2c);
664  return _FAIL;
665  }
666  init_h2fwcmd_w_parm_no_rsp(ph2c, psetop, _SetOpMode_CMD_);
667  psetop->mode = (u8)networktype;
668  r8712_enqueue_cmd(pcmdpriv, ph2c);
669  return _SUCCESS;
670 }
671 
672 u8 r8712_setstakey_cmd(struct _adapter *padapter, u8 *psta, u8 unicast_key)
673 {
674  struct cmd_obj *ph2c;
675  struct set_stakey_parm *psetstakey_para;
676  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
677  struct set_stakey_rsp *psetstakey_rsp = NULL;
678  struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
679  struct security_priv *psecuritypriv = &padapter->securitypriv;
680  struct sta_info *sta = (struct sta_info *)psta;
681 
682  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
683  if (ph2c == NULL)
684  return _FAIL;
685  psetstakey_para = (struct set_stakey_parm *)_malloc(
686  sizeof(struct set_stakey_parm));
687  if (psetstakey_para == NULL) {
688  kfree((u8 *) ph2c);
689  return _FAIL;
690  }
691  psetstakey_rsp = (struct set_stakey_rsp *)_malloc(
692  sizeof(struct set_stakey_rsp));
693  if (psetstakey_rsp == NULL) {
694  kfree((u8 *) ph2c);
695  kfree((u8 *) psetstakey_para);
696  return _FAIL;
697  }
698  init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
699  ph2c->rsp = (u8 *) psetstakey_rsp;
700  ph2c->rspsz = sizeof(struct set_stakey_rsp);
701  memcpy(psetstakey_para->addr, sta->hwaddr, ETH_ALEN);
702  if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
703  psetstakey_para->algorithm = (unsigned char)
704  psecuritypriv->PrivacyAlgrthm;
705  else
706  GET_ENCRY_ALGO(psecuritypriv, sta,
707  psetstakey_para->algorithm, false);
708  if (unicast_key == true)
709  memcpy(&psetstakey_para->key, &sta->x_UncstKey, 16);
710  else
711  memcpy(&psetstakey_para->key,
712  &psecuritypriv->XGrpKey[
713  psecuritypriv->XGrpKeyid - 1]. skey, 16);
714  r8712_enqueue_cmd(pcmdpriv, ph2c);
715  return _SUCCESS;
716 }
717 
719 {
720  struct cmd_obj *ph2c;
721  struct setrfintfs_parm *psetrfintfsparm;
722  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
723 
724  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
725  if (ph2c == NULL)
726  return _FAIL;
727  psetrfintfsparm = (struct setrfintfs_parm *)_malloc(
728  sizeof(struct setrfintfs_parm));
729  if (psetrfintfsparm == NULL) {
730  kfree((unsigned char *) ph2c);
731  return _FAIL;
732  }
733  init_h2fwcmd_w_parm_no_rsp(ph2c, psetrfintfsparm,
734  GEN_CMD_CODE(_SetRFIntFs));
735  psetrfintfsparm->rfintfs = mode;
736  r8712_enqueue_cmd(pcmdpriv, ph2c);
737  return _SUCCESS;
738 }
739 
740 u8 r8712_setrttbl_cmd(struct _adapter *padapter,
741  struct setratable_parm *prate_table)
742 {
743  struct cmd_obj *ph2c;
744  struct setratable_parm *psetrttblparm;
745  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
746 
747  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
748  if (ph2c == NULL)
749  return _FAIL;
750  psetrttblparm = (struct setratable_parm *)_malloc(
751  sizeof(struct setratable_parm));
752  if (psetrttblparm == NULL) {
753  kfree((unsigned char *)ph2c);
754  return _FAIL;
755  }
756  init_h2fwcmd_w_parm_no_rsp(ph2c, psetrttblparm,
757  GEN_CMD_CODE(_SetRaTable));
758  memcpy(psetrttblparm, prate_table, sizeof(struct setratable_parm));
759  r8712_enqueue_cmd(pcmdpriv, ph2c);
760  return _SUCCESS;
761 }
762 
763 u8 r8712_gettssi_cmd(struct _adapter *padapter, u8 offset, u8 *pval)
764 {
765  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
766  struct cmd_obj *ph2c;
767  struct readTSSI_parm *prdtssiparm;
768 
769  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
770  if (ph2c == NULL)
771  return _FAIL;
772  prdtssiparm = (struct readTSSI_parm *)
773  _malloc(sizeof(struct readTSSI_parm));
774  if (prdtssiparm == NULL) {
775  kfree((unsigned char *) ph2c);
776  return _FAIL;
777  }
778  _init_listhead(&ph2c->list);
779  ph2c->cmdcode = GEN_CMD_CODE(_ReadTSSI);
780  ph2c->parmbuf = (unsigned char *)prdtssiparm;
781  ph2c->cmdsz = sizeof(struct readTSSI_parm);
782  ph2c->rsp = pval;
783  ph2c->rspsz = sizeof(struct readTSSI_rsp);
784 
785  prdtssiparm->offset = offset;
786  r8712_enqueue_cmd(pcmdpriv, ph2c);
787  return _SUCCESS;
788 }
789 
791 {
792  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
793  struct cmd_obj *ph2c;
794  struct SetMacAddr_param *psetMacAddr_para;
795 
796  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
797  if (ph2c == NULL)
798  return _FAIL;
799  psetMacAddr_para = (struct SetMacAddr_param *)_malloc(
800  sizeof(struct SetMacAddr_param));
801  if (psetMacAddr_para == NULL) {
802  kfree((u8 *) ph2c);
803  return _FAIL;
804  }
805  init_h2fwcmd_w_parm_no_rsp(ph2c, psetMacAddr_para,
806  _SetMacAddress_CMD_);
807  memcpy(psetMacAddr_para->MacAddr, mac_addr, ETH_ALEN);
808  r8712_enqueue_cmd(pcmdpriv, ph2c);
809  return _SUCCESS;
810 }
811 
813 {
814  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
815  struct cmd_obj *ph2c;
816  struct set_assocsta_parm *psetassocsta_para;
817  struct set_stakey_rsp *psetassocsta_rsp = NULL;
818 
819  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
820  if (ph2c == NULL)
821  return _FAIL;
822  psetassocsta_para = (struct set_assocsta_parm *)
823  _malloc(sizeof(struct set_assocsta_parm));
824  if (psetassocsta_para == NULL) {
825  kfree((u8 *) ph2c);
826  return _FAIL;
827  }
828  psetassocsta_rsp = (struct set_stakey_rsp *)_malloc(
829  sizeof(struct set_assocsta_rsp));
830  if (psetassocsta_rsp == NULL) {
831  kfree((u8 *)ph2c);
832  kfree((u8 *)psetassocsta_para);
833  return _FAIL;
834  }
835  init_h2fwcmd_w_parm_no_rsp(ph2c, psetassocsta_para, _SetAssocSta_CMD_);
836  ph2c->rsp = (u8 *) psetassocsta_rsp;
837  ph2c->rspsz = sizeof(struct set_assocsta_rsp);
838  memcpy(psetassocsta_para->addr, mac_addr, ETH_ALEN);
839  r8712_enqueue_cmd(pcmdpriv, ph2c);
840  return _SUCCESS;
841 }
842 
843 u8 r8712_addbareq_cmd(struct _adapter *padapter, u8 tid)
844 {
845  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
846  struct cmd_obj *ph2c;
847  struct addBaReq_parm *paddbareq_parm;
848 
849  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
850  if (ph2c == NULL)
851  return _FAIL;
852  paddbareq_parm = (struct addBaReq_parm *)_malloc(
853  sizeof(struct addBaReq_parm));
854  if (paddbareq_parm == NULL) {
855  kfree((unsigned char *)ph2c);
856  return _FAIL;
857  }
858  paddbareq_parm->tid = tid;
859  init_h2fwcmd_w_parm_no_rsp(ph2c, paddbareq_parm,
860  GEN_CMD_CODE(_AddBAReq));
861  r8712_enqueue_cmd_ex(pcmdpriv, ph2c);
862  return _SUCCESS;
863 }
864 
865 u8 r8712_wdg_wk_cmd(struct _adapter *padapter)
866 {
867  struct cmd_obj *ph2c;
868  struct drvint_cmd_parm *pdrvintcmd_param;
869  struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
870 
871  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
872  if (ph2c == NULL)
873  return _FAIL;
874  pdrvintcmd_param = (struct drvint_cmd_parm *)_malloc(
875  sizeof(struct drvint_cmd_parm));
876  if (pdrvintcmd_param == NULL) {
877  kfree((unsigned char *)ph2c);
878  return _FAIL;
879  }
880  pdrvintcmd_param->i_cid = WDG_WK_CID;
881  pdrvintcmd_param->sz = 0;
882  pdrvintcmd_param->pbuf = NULL;
883  init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvintcmd_param, _DRV_INT_CMD_);
884  r8712_enqueue_cmd_ex(pcmdpriv, ph2c);
885  return _SUCCESS;
886 }
887 
888 void r8712_survey_cmd_callback(struct _adapter *padapter, struct cmd_obj *pcmd)
889 {
890  struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
891 
892  if (pcmd->res != H2C_SUCCESS)
893  clr_fwstate(pmlmepriv, _FW_UNDER_SURVEY);
894  r8712_free_cmd_obj(pcmd);
895 }
896 
897 void r8712_disassoc_cmd_callback(struct _adapter *padapter,
898  struct cmd_obj *pcmd)
899 {
900  unsigned long irqL;
901  struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
902 
903  if (pcmd->res != H2C_SUCCESS) {
904  spin_lock_irqsave(&pmlmepriv->lock, irqL);
905  set_fwstate(pmlmepriv, _FW_LINKED);
906  spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
907  return;
908  }
909  r8712_free_cmd_obj(pcmd);
910 }
911 
912 void r8712_joinbss_cmd_callback(struct _adapter *padapter, struct cmd_obj *pcmd)
913 {
914  struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
915 
916  if ((pcmd->res != H2C_SUCCESS))
917  _set_timer(&pmlmepriv->assoc_timer, 1);
918  r8712_free_cmd_obj(pcmd);
919 }
920 
922  struct cmd_obj *pcmd)
923 {
924  unsigned long irqL;
925  u8 timer_cancelled;
926  struct sta_info *psta = NULL;
927  struct wlan_network *pwlan = NULL;
928  struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
929  struct ndis_wlan_bssid_ex *pnetwork = (struct ndis_wlan_bssid_ex *)
930  pcmd->parmbuf;
931  struct wlan_network *tgt_network = &(pmlmepriv->cur_network);
932 
933  if ((pcmd->res != H2C_SUCCESS))
934  _set_timer(&pmlmepriv->assoc_timer, 1);
935  _cancel_timer(&pmlmepriv->assoc_timer, &timer_cancelled);
936 #ifdef __BIG_ENDIAN
937  /* endian_convert */
938  pnetwork->Length = le32_to_cpu(pnetwork->Length);
939  pnetwork->Ssid.SsidLength = le32_to_cpu(pnetwork->Ssid.SsidLength);
940  pnetwork->Privacy = le32_to_cpu(pnetwork->Privacy);
941  pnetwork->Rssi = le32_to_cpu(pnetwork->Rssi);
942  pnetwork->NetworkTypeInUse = le32_to_cpu(pnetwork->NetworkTypeInUse);
943  pnetwork->Configuration.ATIMWindow = le32_to_cpu(pnetwork->
944  Configuration.ATIMWindow);
945  pnetwork->Configuration.DSConfig = le32_to_cpu(pnetwork->
946  Configuration.DSConfig);
947  pnetwork->Configuration.FHConfig.DwellTime = le32_to_cpu(pnetwork->
948  Configuration.FHConfig.DwellTime);
949  pnetwork->Configuration.FHConfig.HopPattern = le32_to_cpu(pnetwork->
950  Configuration.FHConfig.HopPattern);
951  pnetwork->Configuration.FHConfig.HopSet = le32_to_cpu(pnetwork->
952  Configuration.FHConfig.HopSet);
953  pnetwork->Configuration.FHConfig.Length = le32_to_cpu(pnetwork->
954  Configuration.FHConfig.Length);
955  pnetwork->Configuration.Length = le32_to_cpu(pnetwork->
956  Configuration.Length);
957  pnetwork->InfrastructureMode = le32_to_cpu(pnetwork->
959  pnetwork->IELength = le32_to_cpu(pnetwork->IELength);
960 #endif
961  spin_lock_irqsave(&pmlmepriv->lock, irqL);
962  if ((pmlmepriv->fw_state) & WIFI_AP_STATE) {
963  psta = r8712_get_stainfo(&padapter->stapriv,
964  pnetwork->MacAddress);
965  if (!psta) {
966  psta = r8712_alloc_stainfo(&padapter->stapriv,
967  pnetwork->MacAddress);
968  if (psta == NULL)
969  goto createbss_cmd_fail ;
970  }
971  r8712_indicate_connect(padapter);
972  } else {
973  pwlan = _r8712_alloc_network(pmlmepriv);
974  if (pwlan == NULL) {
976  &pmlmepriv->scanned_queue);
977  if (pwlan == NULL)
978  goto createbss_cmd_fail;
979  pwlan->last_scanned = jiffies;
980  } else
981  list_insert_tail(&(pwlan->list),
982  &pmlmepriv->scanned_queue.queue);
983  pnetwork->Length = r8712_get_ndis_wlan_bssid_ex_sz(pnetwork);
984  memcpy(&(pwlan->network), pnetwork, pnetwork->Length);
985  pwlan->fixed = true;
986  memcpy(&tgt_network->network, pnetwork,
987  (r8712_get_ndis_wlan_bssid_ex_sz(pnetwork)));
988  if (pmlmepriv->fw_state & _FW_UNDER_LINKING)
989  pmlmepriv->fw_state ^= _FW_UNDER_LINKING;
990  /* we will set _FW_LINKED when there is one more sat to
991  * join us (stassoc_event_callback) */
992  }
993 createbss_cmd_fail:
994  spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
995  r8712_free_cmd_obj(pcmd);
996 }
997 
999  struct cmd_obj *pcmd)
1000 {
1001  struct sta_priv *pstapriv = &padapter->stapriv;
1002  struct set_stakey_rsp *psetstakey_rsp = (struct set_stakey_rsp *)
1003  (pcmd->rsp);
1004  struct sta_info *psta = r8712_get_stainfo(pstapriv,
1005  psetstakey_rsp->addr);
1006 
1007  if (psta == NULL)
1008  goto exit;
1009  psta->aid = psta->mac_id = psetstakey_rsp->keyid; /*CAM_ID(CAM_ENTRY)*/
1010 exit:
1011  r8712_free_cmd_obj(pcmd);
1012 }
1013 
1015  struct cmd_obj *pcmd)
1016 {
1017  unsigned long irqL;
1018  struct sta_priv *pstapriv = &padapter->stapriv;
1019  struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1020  struct set_assocsta_parm *passocsta_parm =
1021  (struct set_assocsta_parm *)(pcmd->parmbuf);
1022  struct set_assocsta_rsp *passocsta_rsp =
1023  (struct set_assocsta_rsp *) (pcmd->rsp);
1024  struct sta_info *psta = r8712_get_stainfo(pstapriv,
1025  passocsta_parm->addr);
1026 
1027  if (psta == NULL)
1028  return;
1029  psta->aid = psta->mac_id = passocsta_rsp->cam_id;
1030  spin_lock_irqsave(&pmlmepriv->lock, irqL);
1031  if ((check_fwstate(pmlmepriv, WIFI_MP_STATE)) &&
1032  (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)))
1033  pmlmepriv->fw_state ^= _FW_UNDER_LINKING;
1034  set_fwstate(pmlmepriv, _FW_LINKED);
1035  spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
1036  r8712_free_cmd_obj(pcmd);
1037 }
1038 
1040  u32 tryPktCnt, u32 tryPktInterval, u32 firstStageTO)
1041 {
1042  struct cmd_obj *ph2c;
1043  struct DisconnectCtrlEx_param *param;
1044  struct cmd_priv *pcmdpriv = &adapter->cmdpriv;
1045 
1046  ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj));
1047  if (ph2c == NULL)
1048  return _FAIL;
1049  param = (struct DisconnectCtrlEx_param *)
1050  _malloc(sizeof(struct DisconnectCtrlEx_param));
1051  if (param == NULL) {
1052  kfree((unsigned char *) ph2c);
1053  return _FAIL;
1054  }
1055  memset(param, 0, sizeof(struct DisconnectCtrlEx_param));
1056 
1057  param->EnableDrvCtrl = (unsigned char)enableDrvCtrl;
1058  param->TryPktCnt = (unsigned char)tryPktCnt;
1059  param->TryPktInterval = (unsigned char)tryPktInterval;
1060  param->FirstStageTO = (unsigned int)firstStageTO;
1061 
1062  init_h2fwcmd_w_parm_no_rsp(ph2c, param,
1063  GEN_CMD_CODE(_DisconnectCtrlEx));
1064  r8712_enqueue_cmd(pcmdpriv, ph2c);
1065  return _SUCCESS;
1066 }