[PATCH] libertas: move contents of fw.h to decl.h
[linux-2.6-block.git] / drivers / net / wireless / libertas / cmd.c
CommitLineData
876c9d3a
MT
1/**
2 * This file contains the handling of command.
3 * It prepares command and sends it to firmware when it is ready.
4 */
5
6#include <net/iw_handler.h>
7#include "host.h"
8#include "hostcmd.h"
876c9d3a
MT
9#include "decl.h"
10#include "defs.h"
11#include "dev.h"
12#include "join.h"
13#include "wext.h"
14
15static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode);
16
17static u16 commands_allowed_in_ps[] = {
18 cmd_802_11_rssi,
19};
20
21/**
22 * @brief This function checks if the commans is allowed
23 * in PS mode not.
24 *
25 * @param command the command ID
26 * @return TRUE or FALSE
27 */
28static u8 is_command_allowed_in_ps(u16 command)
29{
30 int count = sizeof(commands_allowed_in_ps)
31 / sizeof(commands_allowed_in_ps[0]);
32 int i;
33
34 for (i = 0; i < count; i++) {
35 if (command == cpu_to_le16(commands_allowed_in_ps[i]))
36 return 1;
37 }
38
39 return 0;
40}
41
42static int wlan_cmd_hw_spec(wlan_private * priv, struct cmd_ds_command *cmd)
43{
44 struct cmd_ds_get_hw_spec *hwspec = &cmd->params.hwspec;
45
9012b28a 46 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
47
48 cmd->command = cpu_to_le16(cmd_get_hw_spec);
49 cmd->size =
50 cpu_to_le16(sizeof(struct cmd_ds_get_hw_spec) + S_DS_GEN);
51 memcpy(hwspec->permanentaddr, priv->adapter->current_addr, ETH_ALEN);
52
9012b28a 53 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
54 return 0;
55}
56
57static int wlan_cmd_802_11_ps_mode(wlan_private * priv,
58 struct cmd_ds_command *cmd,
59 u16 cmd_action)
60{
61 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
62 u16 action = cmd_action;
63 wlan_adapter *adapter = priv->adapter;
64
9012b28a 65 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
66
67 cmd->command = cpu_to_le16(cmd_802_11_ps_mode);
68 cmd->size =
69 cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
70 S_DS_GEN);
71 psm->action = cpu_to_le16(cmd_action);
72 psm->multipledtim = 0;
73 switch (action) {
74 case cmd_subcmd_enter_ps:
9012b28a
HS
75 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
76 lbs_deb_cmd("locallisteninterval = %d\n",
876c9d3a
MT
77 adapter->locallisteninterval);
78
79 psm->locallisteninterval =
80 cpu_to_le16(adapter->locallisteninterval);
81 psm->nullpktinterval =
82 cpu_to_le16(adapter->nullpktinterval);
83 psm->multipledtim =
84 cpu_to_le16(priv->adapter->multipledtim);
85 break;
86
87 case cmd_subcmd_exit_ps:
9012b28a 88 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
876c9d3a
MT
89 break;
90
91 case cmd_subcmd_sleep_confirmed:
9012b28a 92 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
876c9d3a
MT
93 break;
94
95 default:
96 break;
97 }
98
9012b28a 99 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
100 return 0;
101}
102
103static int wlan_cmd_802_11_inactivity_timeout(wlan_private * priv,
104 struct cmd_ds_command *cmd,
105 u16 cmd_action, void *pdata_buf)
106{
107 u16 *timeout = pdata_buf;
108
109 cmd->command = cpu_to_le16(cmd_802_11_inactivity_timeout);
110 cmd->size =
111 cpu_to_le16(sizeof(struct cmd_ds_802_11_inactivity_timeout)
112 + S_DS_GEN);
113
114 cmd->params.inactivity_timeout.action = cpu_to_le16(cmd_action);
115
116 if (cmd_action)
117 cmd->params.inactivity_timeout.timeout =
118 cpu_to_le16(*timeout);
119 else
120 cmd->params.inactivity_timeout.timeout = 0;
121
122 return 0;
123}
124
125static int wlan_cmd_802_11_sleep_params(wlan_private * priv,
126 struct cmd_ds_command *cmd,
127 u16 cmd_action)
128{
129 wlan_adapter *adapter = priv->adapter;
130 struct cmd_ds_802_11_sleep_params *sp = &cmd->params.sleep_params;
131
9012b28a 132 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
133
134 cmd->size =
135 cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
136 S_DS_GEN);
137 cmd->command = cpu_to_le16(cmd_802_11_sleep_params);
138
139 if (cmd_action == cmd_act_get) {
140 memset(&adapter->sp, 0, sizeof(struct sleep_params));
141 memset(sp, 0, sizeof(struct cmd_ds_802_11_sleep_params));
142 sp->action = cpu_to_le16(cmd_action);
143 } else if (cmd_action == cmd_act_set) {
144 sp->action = cpu_to_le16(cmd_action);
145 sp->error = cpu_to_le16(adapter->sp.sp_error);
146 sp->offset = cpu_to_le16(adapter->sp.sp_offset);
147 sp->stabletime = cpu_to_le16(adapter->sp.sp_stabletime);
148 sp->calcontrol = (u8) adapter->sp.sp_calcontrol;
149 sp->externalsleepclk = (u8) adapter->sp.sp_extsleepclk;
150 sp->reserved = cpu_to_le16(adapter->sp.sp_reserved);
151 }
152
9012b28a 153 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
154 return 0;
155}
156
157static int wlan_cmd_802_11_set_wep(wlan_private * priv,
158 struct cmd_ds_command *cmd,
159 u32 cmd_act,
160 void * pdata_buf)
161{
162 struct cmd_ds_802_11_set_wep *wep = &cmd->params.wep;
163 wlan_adapter *adapter = priv->adapter;
164 int ret = 0;
165 struct assoc_request * assoc_req = pdata_buf;
166
9012b28a 167 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
168
169 cmd->command = cpu_to_le16(cmd_802_11_set_wep);
170 cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_set_wep))
171 + S_DS_GEN);
172
173 if (cmd_act == cmd_act_add) {
174 int i;
175
176 if (!assoc_req) {
9012b28a 177 lbs_deb_cmd("Invalid association request!");
876c9d3a
MT
178 ret = -1;
179 goto done;
180 }
181
182 wep->action = cpu_to_le16(cmd_act_add);
183
184 /* default tx key index */
185 wep->keyindex = cpu_to_le16((u16)
186 (assoc_req->wep_tx_keyidx &
187 (u32)cmd_WEP_KEY_INDEX_MASK));
188
9012b28a 189 lbs_deb_cmd("Tx key Index: %u\n", wep->keyindex);
876c9d3a
MT
190
191 /* Copy key types and material to host command structure */
192 for (i = 0; i < 4; i++) {
193 struct WLAN_802_11_KEY * pkey = &assoc_req->wep_keys[i];
194
195 switch (pkey->len) {
196 case KEY_LEN_WEP_40:
197 wep->keytype[i] = cmd_type_wep_40_bit;
198 memmove(&wep->keymaterial[i], pkey->key,
199 pkey->len);
200 break;
201 case KEY_LEN_WEP_104:
202 wep->keytype[i] = cmd_type_wep_104_bit;
203 memmove(&wep->keymaterial[i], pkey->key,
204 pkey->len);
205 break;
206 case 0:
207 break;
208 default:
9012b28a 209 lbs_deb_cmd("Invalid WEP key %d length of %d\n",
876c9d3a
MT
210 i, pkey->len);
211 ret = -1;
212 goto done;
213 break;
214 }
215 }
216 } else if (cmd_act == cmd_act_remove) {
217 /* ACT_REMOVE clears _all_ WEP keys */
218 wep->action = cpu_to_le16(cmd_act_remove);
219
220 /* default tx key index */
221 wep->keyindex = cpu_to_le16((u16)
222 (adapter->wep_tx_keyidx &
223 (u32)cmd_WEP_KEY_INDEX_MASK));
224 }
225
226 ret = 0;
227
228done:
9012b28a 229 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
876c9d3a
MT
230 return ret;
231}
232
233static int wlan_cmd_802_11_enable_rsn(wlan_private * priv,
234 struct cmd_ds_command *cmd,
235 u16 cmd_action)
236{
237 struct cmd_ds_802_11_enable_rsn *penableRSN = &cmd->params.enbrsn;
238 wlan_adapter *adapter = priv->adapter;
239
240 cmd->command = cpu_to_le16(cmd_802_11_enable_rsn);
241 cmd->size =
242 cpu_to_le16(sizeof(struct cmd_ds_802_11_enable_rsn) +
243 S_DS_GEN);
244 penableRSN->action = cpu_to_le16(cmd_action);
245 if (adapter->secinfo.WPAenabled || adapter->secinfo.WPA2enabled) {
246 penableRSN->enable = cpu_to_le16(cmd_enable_rsn);
247 } else {
248 penableRSN->enable = cpu_to_le16(cmd_disable_rsn);
249 }
250
251 return 0;
252}
253
254
255static void set_one_wpa_key(struct MrvlIEtype_keyParamSet * pkeyparamset,
256 struct WLAN_802_11_KEY * pkey)
257{
258 pkeyparamset->keytypeid = cpu_to_le16(pkey->type);
259
260 if (pkey->flags & KEY_INFO_WPA_ENABLED) {
261 pkeyparamset->keyinfo = cpu_to_le16(KEY_INFO_WPA_ENABLED);
262 } else {
263 pkeyparamset->keyinfo = cpu_to_le16(!KEY_INFO_WPA_ENABLED);
264 }
265
266 if (pkey->flags & KEY_INFO_WPA_UNICAST) {
267 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
268 } else if (pkey->flags & KEY_INFO_WPA_MCAST) {
269 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
270 }
271
272 pkeyparamset->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
273 pkeyparamset->keylen = cpu_to_le16(pkey->len);
274 memcpy(pkeyparamset->key, pkey->key, pkey->len);
275 pkeyparamset->length = cpu_to_le16( sizeof(pkeyparamset->keytypeid)
276 + sizeof(pkeyparamset->keyinfo)
277 + sizeof(pkeyparamset->keylen)
278 + sizeof(pkeyparamset->key));
279}
280
281static int wlan_cmd_802_11_key_material(wlan_private * priv,
282 struct cmd_ds_command *cmd,
283 u16 cmd_action,
284 u32 cmd_oid, void *pdata_buf)
285{
286 wlan_adapter *adapter = priv->adapter;
287 struct cmd_ds_802_11_key_material *pkeymaterial =
288 &cmd->params.keymaterial;
289 int ret = 0;
290 int index = 0;
291
9012b28a 292 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
293
294 cmd->command = cpu_to_le16(cmd_802_11_key_material);
295 pkeymaterial->action = cpu_to_le16(cmd_action);
296
297 if (cmd_action == cmd_act_get) {
298 cmd->size = cpu_to_le16( S_DS_GEN
299 + sizeof (pkeymaterial->action));
300 ret = 0;
301 goto done;
302 }
303
304 memset(&pkeymaterial->keyParamSet, 0, sizeof(pkeymaterial->keyParamSet));
305
306 if (adapter->wpa_unicast_key.len) {
307 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
308 &adapter->wpa_unicast_key);
309 index++;
310 }
311
312 if (adapter->wpa_mcast_key.len) {
313 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
314 &adapter->wpa_mcast_key);
315 index++;
316 }
317
318 cmd->size = cpu_to_le16( S_DS_GEN
319 + sizeof (pkeymaterial->action)
320 + index * sizeof(struct MrvlIEtype_keyParamSet));
321
322 ret = 0;
323
324done:
9012b28a 325 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
876c9d3a
MT
326 return ret;
327}
328
329static int wlan_cmd_802_11_reset(wlan_private * priv,
330 struct cmd_ds_command *cmd, int cmd_action)
331{
332 struct cmd_ds_802_11_reset *reset = &cmd->params.reset;
333
334 cmd->command = cpu_to_le16(cmd_802_11_reset);
335 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
336 reset->action = cpu_to_le16(cmd_action);
337
338 return 0;
339}
340
341static int wlan_cmd_802_11_get_log(wlan_private * priv,
342 struct cmd_ds_command *cmd)
343{
344 cmd->command = cpu_to_le16(cmd_802_11_get_log);
345 cmd->size =
346 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_log) + S_DS_GEN);
347
348 return 0;
349}
350
351static int wlan_cmd_802_11_get_stat(wlan_private * priv,
352 struct cmd_ds_command *cmd)
353{
354 cmd->command = cpu_to_le16(cmd_802_11_get_stat);
355 cmd->size =
356 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) +
357 S_DS_GEN);
358
359 return 0;
360}
361
362static int wlan_cmd_802_11_snmp_mib(wlan_private * priv,
363 struct cmd_ds_command *cmd,
364 int cmd_action,
365 int cmd_oid, void *pdata_buf)
366{
367 struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib;
368 wlan_adapter *adapter = priv->adapter;
369 u8 ucTemp;
370
9012b28a 371 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 372
9012b28a 373 lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
876c9d3a
MT
374
375 cmd->command = cpu_to_le16(cmd_802_11_snmp_mib);
376 cmd->size =
377 cpu_to_le16(sizeof(struct cmd_ds_802_11_snmp_mib) +
378 S_DS_GEN);
379
380 switch (cmd_oid) {
381 case OID_802_11_INFRASTRUCTURE_MODE:
382 {
0dc5a290 383 u8 mode = (u8) (size_t) pdata_buf;
876c9d3a
MT
384 pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
385 pSNMPMIB->oid = cpu_to_le16((u16) desired_bsstype_i);
386 pSNMPMIB->bufsize = sizeof(u8);
0dc5a290 387 if (mode == IW_MODE_ADHOC) {
876c9d3a 388 ucTemp = SNMP_MIB_VALUE_ADHOC;
0dc5a290
DW
389 } else {
390 /* Infra and Auto modes */
391 ucTemp = SNMP_MIB_VALUE_INFRA;
392 }
876c9d3a
MT
393
394 memmove(pSNMPMIB->value, &ucTemp, sizeof(u8));
395
396 break;
397 }
398
399 case OID_802_11D_ENABLE:
400 {
401 u32 ulTemp;
402
403 pSNMPMIB->oid = cpu_to_le16((u16) dot11d_i);
404
405 if (cmd_action == cmd_act_set) {
406 pSNMPMIB->querytype = cmd_act_set;
407 pSNMPMIB->bufsize = sizeof(u16);
408 ulTemp = *(u32 *)pdata_buf;
409 *((unsigned short *)(pSNMPMIB->value)) =
410 cpu_to_le16((u16) ulTemp);
411 }
412 break;
413 }
414
415 case OID_802_11_FRAGMENTATION_THRESHOLD:
416 {
417 u32 ulTemp;
418
419 pSNMPMIB->oid = cpu_to_le16((u16) fragthresh_i);
420
421 if (cmd_action == cmd_act_get) {
422 pSNMPMIB->querytype =
423 cpu_to_le16(cmd_act_get);
424 } else if (cmd_action == cmd_act_set) {
425 pSNMPMIB->querytype =
426 cpu_to_le16(cmd_act_set);
427 pSNMPMIB->bufsize =
428 cpu_to_le16(sizeof(u16));
429 ulTemp = *((u32 *) pdata_buf);
430 *((unsigned short *)(pSNMPMIB->value)) =
431 cpu_to_le16((u16) ulTemp);
432
433 }
434
435 break;
436 }
437
438 case OID_802_11_RTS_THRESHOLD:
439 {
440
441 u32 ulTemp;
442 pSNMPMIB->oid = le16_to_cpu((u16) rtsthresh_i);
443
444 if (cmd_action == cmd_act_get) {
445 pSNMPMIB->querytype =
446 cpu_to_le16(cmd_act_get);
447 } else if (cmd_action == cmd_act_set) {
448 pSNMPMIB->querytype =
449 cpu_to_le16(cmd_act_set);
450 pSNMPMIB->bufsize =
451 cpu_to_le16(sizeof(u16));
452 ulTemp = *((u32 *)
453 pdata_buf);
454 *(unsigned short *)(pSNMPMIB->value) =
455 cpu_to_le16((u16) ulTemp);
456
457 }
458 break;
459 }
460 case OID_802_11_TX_RETRYCOUNT:
461 pSNMPMIB->oid = cpu_to_le16((u16) short_retrylim_i);
462
463 if (cmd_action == cmd_act_get) {
464 pSNMPMIB->querytype =
465 cpu_to_le16(cmd_act_get);
466 } else if (cmd_action == cmd_act_set) {
467 pSNMPMIB->querytype =
468 cpu_to_le16(cmd_act_set);
469 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
470 *((unsigned short *)(pSNMPMIB->value)) =
471 cpu_to_le16((u16) adapter->txretrycount);
472 }
473
474 break;
475 default:
476 break;
477 }
478
9012b28a 479 lbs_deb_cmd(
876c9d3a
MT
480 "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
481 cmd->command, cmd->size, cmd->seqnum, cmd->result);
482
9012b28a 483 lbs_deb_cmd(
876c9d3a
MT
484 "SNMP_CMD: action=0x%x, oid=0x%x, oidsize=0x%x, value=0x%x\n",
485 pSNMPMIB->querytype, pSNMPMIB->oid, pSNMPMIB->bufsize,
486 *(u16 *) pSNMPMIB->value);
487
9012b28a 488 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
489 return 0;
490}
491
492static int wlan_cmd_802_11_radio_control(wlan_private * priv,
493 struct cmd_ds_command *cmd,
494 int cmd_action)
495{
496 wlan_adapter *adapter = priv->adapter;
497 struct cmd_ds_802_11_radio_control *pradiocontrol =
498 &cmd->params.radio;
499
9012b28a 500 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
501
502 cmd->size =
503 cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control)) +
504 S_DS_GEN);
505 cmd->command = cpu_to_le16(cmd_802_11_radio_control);
506
507 pradiocontrol->action = cpu_to_le16(cmd_action);
508
509 switch (adapter->preamble) {
510 case cmd_type_short_preamble:
511 pradiocontrol->control = cpu_to_le16(SET_SHORT_PREAMBLE);
512 break;
513
514 case cmd_type_long_preamble:
515 pradiocontrol->control = cpu_to_le16(SET_LONG_PREAMBLE);
516 break;
517
518 case cmd_type_auto_preamble:
519 default:
520 pradiocontrol->control = cpu_to_le16(SET_AUTO_PREAMBLE);
521 break;
522 }
523
524 if (adapter->radioon)
525 pradiocontrol->control |= cpu_to_le16(TURN_ON_RF);
526 else
527 pradiocontrol->control &= cpu_to_le16(~TURN_ON_RF);
528
9012b28a 529 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
530 return 0;
531}
532
533static int wlan_cmd_802_11_rf_tx_power(wlan_private * priv,
534 struct cmd_ds_command *cmd,
535 u16 cmd_action, void *pdata_buf)
536{
537
538 struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
539
9012b28a 540 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
541
542 cmd->size =
543 cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) +
544 S_DS_GEN);
545 cmd->command = cpu_to_le16(cmd_802_11_rf_tx_power);
546 prtp->action = cmd_action;
547
9012b28a 548 lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n", cmd->size,
876c9d3a
MT
549 cmd->command, prtp->action);
550
551 switch (cmd_action) {
552 case cmd_act_tx_power_opt_get:
553 prtp->action = cpu_to_le16(cmd_act_get);
554 prtp->currentlevel = 0;
555 break;
556
557 case cmd_act_tx_power_opt_set_high:
558 prtp->action = cpu_to_le16(cmd_act_set);
559 prtp->currentlevel =
560 cpu_to_le16(cmd_act_tx_power_index_high);
561 break;
562
563 case cmd_act_tx_power_opt_set_mid:
564 prtp->action = cpu_to_le16(cmd_act_set);
565 prtp->currentlevel =
566 cpu_to_le16(cmd_act_tx_power_index_mid);
567 break;
568
569 case cmd_act_tx_power_opt_set_low:
570 prtp->action = cpu_to_le16(cmd_act_set);
571 prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
572 break;
573 }
9012b28a
HS
574
575 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
576 return 0;
577}
578
579static int wlan_cmd_802_11_rf_antenna(wlan_private * priv,
580 struct cmd_ds_command *cmd,
581 u16 cmd_action, void *pdata_buf)
582{
583 struct cmd_ds_802_11_rf_antenna *rant = &cmd->params.rant;
584
585 cmd->command = cpu_to_le16(cmd_802_11_rf_antenna);
586 cmd->size =
587 cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_antenna) +
588 S_DS_GEN);
589
590 rant->action = cpu_to_le16(cmd_action);
591 if ((cmd_action == cmd_act_set_rx) ||
592 (cmd_action == cmd_act_set_tx)) {
593 rant->antennamode =
594 cpu_to_le16((u16) (*(u32 *) pdata_buf));
595 }
596
597 return 0;
598}
599
600static int wlan_cmd_802_11_rate_adapt_rateset(wlan_private * priv,
601 struct cmd_ds_command *cmd,
602 u16 cmd_action)
603{
604 struct cmd_ds_802_11_rate_adapt_rateset
605 *rateadapt = &cmd->params.rateset;
606 wlan_adapter *adapter = priv->adapter;
607
608 cmd->size =
609 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
610 + S_DS_GEN);
611 cmd->command = cpu_to_le16(cmd_802_11_rate_adapt_rateset);
612
9012b28a 613 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
614
615 rateadapt->action = cmd_action;
616 rateadapt->enablehwauto = adapter->enablehwauto;
617 rateadapt->bitmap = adapter->ratebitmap;
618
9012b28a 619 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
620 return 0;
621}
622
623static int wlan_cmd_802_11_data_rate(wlan_private * priv,
624 struct cmd_ds_command *cmd,
625 u16 cmd_action)
626{
627 struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
628 wlan_adapter *adapter = priv->adapter;
629 u16 action = cmd_action;
630
9012b28a 631 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
632
633 cmd->size =
634 cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
635 S_DS_GEN);
636
637 cmd->command = cpu_to_le16(cmd_802_11_data_rate);
638
639 memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate));
640
641 pdatarate->action = cpu_to_le16(cmd_action);
642
643 if (action == cmd_act_set_tx_fix_rate) {
644 pdatarate->datarate[0] = libertas_data_rate_to_index(adapter->datarate);
9012b28a 645 lbs_deb_cmd("Setting FW for fixed rate 0x%02X\n",
876c9d3a
MT
646 adapter->datarate);
647 } else if (action == cmd_act_set_tx_auto) {
9012b28a 648 lbs_deb_cmd("Setting FW for AUTO rate\n");
876c9d3a
MT
649 }
650
9012b28a 651 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
652 return 0;
653}
654
655static int wlan_cmd_mac_multicast_adr(wlan_private * priv,
656 struct cmd_ds_command *cmd,
657 u16 cmd_action)
658{
659 struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
660 wlan_adapter *adapter = priv->adapter;
661
662 cmd->size =
663 cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
664 S_DS_GEN);
665 cmd->command = cpu_to_le16(cmd_mac_multicast_adr);
666
667 pMCastAdr->action = cpu_to_le16(cmd_action);
668 pMCastAdr->nr_of_adrs =
669 cpu_to_le16((u16) adapter->nr_of_multicastmacaddr);
670 memcpy(pMCastAdr->maclist, adapter->multicastlist,
671 adapter->nr_of_multicastmacaddr * ETH_ALEN);
672
673 return 0;
674}
675
676static int wlan_cmd_802_11_rf_channel(wlan_private * priv,
677 struct cmd_ds_command *cmd,
678 int option, void *pdata_buf)
679{
680 struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel;
681
682 cmd->command = cpu_to_le16(cmd_802_11_rf_channel);
683 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel)
684 + S_DS_GEN);
685
686 if (option == cmd_opt_802_11_rf_channel_set) {
687 rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf));
688 }
689
690 rfchan->action = cpu_to_le16(option);
691
692 return 0;
693}
694
695static int wlan_cmd_802_11_rssi(wlan_private * priv,
696 struct cmd_ds_command *cmd)
697{
698 wlan_adapter *adapter = priv->adapter;
699
700 cmd->command = cpu_to_le16(cmd_802_11_rssi);
701 cmd->size =
702 cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
703 cmd->params.rssi.N = priv->adapter->bcn_avg_factor;
704
705 /* reset Beacon SNR/NF/RSSI values */
706 adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
707 adapter->SNR[TYPE_BEACON][TYPE_AVG] = 0;
708 adapter->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
709 adapter->NF[TYPE_BEACON][TYPE_AVG] = 0;
710 adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
711 adapter->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
712
713 return 0;
714}
715
716static int wlan_cmd_reg_access(wlan_private * priv,
717 struct cmd_ds_command *cmdptr,
718 u8 cmd_action, void *pdata_buf)
719{
720 struct wlan_offset_value *offval;
721
9012b28a 722 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
723
724 offval = (struct wlan_offset_value *)pdata_buf;
725
726 switch (cmdptr->command) {
727 case cmd_mac_reg_access:
728 {
729 struct cmd_ds_mac_reg_access *macreg;
730
731 cmdptr->size =
732 cpu_to_le16(sizeof
733 (struct cmd_ds_mac_reg_access)
734 + S_DS_GEN);
735 macreg =
736 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
737 macreg;
738
739 macreg->action = cpu_to_le16(cmd_action);
740 macreg->offset = cpu_to_le16((u16) offval->offset);
741 macreg->value = cpu_to_le32(offval->value);
742
743 break;
744 }
745
746 case cmd_bbp_reg_access:
747 {
748 struct cmd_ds_bbp_reg_access *bbpreg;
749
750 cmdptr->size =
751 cpu_to_le16(sizeof
752 (struct cmd_ds_bbp_reg_access)
753 + S_DS_GEN);
754 bbpreg =
755 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
756 bbpreg;
757
758 bbpreg->action = cpu_to_le16(cmd_action);
759 bbpreg->offset = cpu_to_le16((u16) offval->offset);
760 bbpreg->value = (u8) offval->value;
761
762 break;
763 }
764
765 case cmd_rf_reg_access:
766 {
767 struct cmd_ds_rf_reg_access *rfreg;
768
769 cmdptr->size =
770 cpu_to_le16(sizeof
771 (struct cmd_ds_rf_reg_access) +
772 S_DS_GEN);
773 rfreg =
774 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
775 rfreg;
776
777 rfreg->action = cpu_to_le16(cmd_action);
778 rfreg->offset = cpu_to_le16((u16) offval->offset);
779 rfreg->value = (u8) offval->value;
780
781 break;
782 }
783
784 default:
785 break;
786 }
787
9012b28a 788 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
789 return 0;
790}
791
792static int wlan_cmd_802_11_mac_address(wlan_private * priv,
793 struct cmd_ds_command *cmd,
794 u16 cmd_action)
795{
796 wlan_adapter *adapter = priv->adapter;
797
798 cmd->command = cpu_to_le16(cmd_802_11_mac_address);
799 cmd->size =
800 cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
801 S_DS_GEN);
802 cmd->result = 0;
803
804 cmd->params.macadd.action = cpu_to_le16(cmd_action);
805
806 if (cmd_action == cmd_act_set) {
807 memcpy(cmd->params.macadd.macadd,
808 adapter->current_addr, ETH_ALEN);
809 lbs_dbg_hex("SET_CMD: MAC ADDRESS-", adapter->current_addr, 6);
810 }
811
812 return 0;
813}
814
815static int wlan_cmd_802_11_eeprom_access(wlan_private * priv,
816 struct cmd_ds_command *cmd,
817 int cmd_action, void *pdata_buf)
818{
819 struct wlan_ioctl_regrdwr *ea = pdata_buf;
820
9012b28a 821 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
822
823 cmd->command = cpu_to_le16(cmd_802_11_eeprom_access);
824 cmd->size =
825 cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
826 S_DS_GEN);
827 cmd->result = 0;
828
829 cmd->params.rdeeprom.action = cpu_to_le16(ea->action);
830 cmd->params.rdeeprom.offset = cpu_to_le16(ea->offset);
831 cmd->params.rdeeprom.bytecount = cpu_to_le16(ea->NOB);
832 cmd->params.rdeeprom.value = 0;
833
834 return 0;
835}
836
837static int wlan_cmd_bt_access(wlan_private * priv,
838 struct cmd_ds_command *cmd,
839 u16 cmd_action, void *pdata_buf)
840{
841 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
9012b28a 842 lbs_deb_cmd("BT CMD(%d)\n", cmd_action);
876c9d3a
MT
843
844 cmd->command = cpu_to_le16(cmd_bt_access);
845 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access)
846 + S_DS_GEN);
847 cmd->result = 0;
848 bt_access->action = cpu_to_le16(cmd_action);
849
850 switch (cmd_action) {
851 case cmd_act_bt_access_add:
852 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
853 lbs_dbg_hex("BT_ADD: blinded mac address-", bt_access->addr1, 6);
854 break;
855 case cmd_act_bt_access_del:
856 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
857 lbs_dbg_hex("BT_DEL: blinded mac address-", bt_access->addr1, 6);
858 break;
859 case cmd_act_bt_access_list:
860 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
861 break;
862 case cmd_act_bt_access_reset:
863 break;
864 default:
865 break;
866 }
867 return 0;
868}
869
870static int wlan_cmd_fwt_access(wlan_private * priv,
871 struct cmd_ds_command *cmd,
872 u16 cmd_action, void *pdata_buf)
873{
874 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
9012b28a 875 lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
876c9d3a
MT
876
877 cmd->command = cpu_to_le16(cmd_fwt_access);
878 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access)
879 + S_DS_GEN);
880 cmd->result = 0;
881
882 if (pdata_buf)
883 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
884 else
885 memset(fwt_access, 0, sizeof(*fwt_access));
886
887 fwt_access->action = cpu_to_le16(cmd_action);
888
889 return 0;
890}
891
892static int wlan_cmd_mesh_access(wlan_private * priv,
893 struct cmd_ds_command *cmd,
894 u16 cmd_action, void *pdata_buf)
895{
896 struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
9012b28a 897 lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
876c9d3a
MT
898
899 cmd->command = cpu_to_le16(cmd_mesh_access);
900 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access)
901 + S_DS_GEN);
902 cmd->result = 0;
903
904 if (pdata_buf)
905 memcpy(mesh_access, pdata_buf, sizeof(*mesh_access));
906 else
907 memset(mesh_access, 0, sizeof(*mesh_access));
908
909 mesh_access->action = cpu_to_le16(cmd_action);
910
911 return 0;
912}
913
914void libertas_queue_cmd(wlan_adapter * adapter, struct cmd_ctrl_node *cmdnode, u8 addtail)
915{
916 unsigned long flags;
917 struct cmd_ds_command *cmdptr;
918
9012b28a 919 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
920
921 if (!cmdnode) {
9012b28a 922 lbs_deb_cmd("QUEUE_CMD: cmdnode is NULL\n");
876c9d3a
MT
923 goto done;
924 }
925
926 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
927 if (!cmdptr) {
9012b28a 928 lbs_deb_cmd("QUEUE_CMD: cmdptr is NULL\n");
876c9d3a
MT
929 goto done;
930 }
931
932 /* Exit_PS command needs to be queued in the header always. */
933 if (cmdptr->command == cmd_802_11_ps_mode) {
934 struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
935 if (psm->action == cmd_subcmd_exit_ps) {
936 if (adapter->psstate != PS_STATE_FULL_POWER)
937 addtail = 0;
938 }
939 }
940
941 spin_lock_irqsave(&adapter->driver_lock, flags);
942
943 if (addtail)
944 list_add_tail((struct list_head *)cmdnode,
945 &adapter->cmdpendingq);
946 else
947 list_add((struct list_head *)cmdnode, &adapter->cmdpendingq);
948
949 spin_unlock_irqrestore(&adapter->driver_lock, flags);
950
9012b28a 951 lbs_deb_cmd("QUEUE_CMD: Inserted node=%p, cmd=0x%x in cmdpendingq\n",
4269e2ad 952 cmdnode,
876c9d3a
MT
953 ((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command);
954
955done:
9012b28a 956 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
957}
958
959/*
960 * TODO: Fix the issue when DownloadcommandToStation is being called the
961 * second time when the command timesout. All the cmdptr->xxx are in little
962 * endian and therefore all the comparissions will fail.
963 * For now - we are not performing the endian conversion the second time - but
964 * for PS and DEEP_SLEEP we need to worry
965 */
966static int DownloadcommandToStation(wlan_private * priv,
967 struct cmd_ctrl_node *cmdnode)
968{
969 unsigned long flags;
970 struct cmd_ds_command *cmdptr;
971 wlan_adapter *adapter = priv->adapter;
972 int ret = 0;
973 u16 cmdsize;
974 u16 command;
975
9012b28a 976 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
977
978 if (!adapter || !cmdnode) {
9012b28a 979 lbs_deb_cmd("DNLD_CMD: adapter = %p, cmdnode = %p\n",
4269e2ad 980 adapter, cmdnode);
876c9d3a
MT
981 if (cmdnode) {
982 spin_lock_irqsave(&adapter->driver_lock, flags);
983 __libertas_cleanup_and_insert_cmd(priv, cmdnode);
984 spin_unlock_irqrestore(&adapter->driver_lock, flags);
985 }
986 ret = -1;
987 goto done;
988 }
989
990 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
991
992
993 spin_lock_irqsave(&adapter->driver_lock, flags);
994 if (!cmdptr || !cmdptr->size) {
9012b28a 995 lbs_deb_cmd("DNLD_CMD: cmdptr is Null or cmd size is Zero, "
876c9d3a
MT
996 "Not sending\n");
997 __libertas_cleanup_and_insert_cmd(priv, cmdnode);
998 spin_unlock_irqrestore(&adapter->driver_lock, flags);
999 ret = -1;
1000 goto done;
1001 }
1002
1003 adapter->cur_cmd = cmdnode;
1004 adapter->cur_cmd_retcode = 0;
1005 spin_unlock_irqrestore(&adapter->driver_lock, flags);
9012b28a 1006 lbs_deb_cmd("DNLD_CMD:: Before download, size of cmd = %d\n",
876c9d3a
MT
1007 cmdptr->size);
1008
1009 cmdsize = cmdptr->size;
1010
1011 command = cpu_to_le16(cmdptr->command);
1012
1013 cmdnode->cmdwaitqwoken = 0;
1014 cmdsize = cpu_to_le16(cmdsize);
1015
208fdd2f 1016 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
876c9d3a
MT
1017
1018 if (ret != 0) {
9012b28a 1019 lbs_deb_cmd("DNLD_CMD: Host to Card failed\n");
876c9d3a
MT
1020 spin_lock_irqsave(&adapter->driver_lock, flags);
1021 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
1022 adapter->cur_cmd = NULL;
1023 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1024 ret = -1;
1025 goto done;
1026 }
1027
9012b28a 1028 lbs_deb_cmd("DNLD_CMD: Sent command 0x%x @ %lu\n", command, jiffies);
876c9d3a
MT
1029 lbs_dbg_hex("DNLD_CMD: command", cmdnode->bufvirtualaddr, cmdsize);
1030
1031 /* Setup the timer after transmit command */
1032 if (command == cmd_802_11_scan
1033 || command == cmd_802_11_authenticate
1034 || command == cmd_802_11_associate)
1035 mod_timer(&adapter->command_timer, jiffies + (10*HZ));
1036 else
1037 mod_timer(&adapter->command_timer, jiffies + (5*HZ));
1038
1039 ret = 0;
1040
9012b28a
HS
1041done:
1042 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
876c9d3a
MT
1043 return ret;
1044}
1045
1046static int wlan_cmd_mac_control(wlan_private * priv,
1047 struct cmd_ds_command *cmd)
1048{
1049 struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
1050
9012b28a 1051 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
1052
1053 cmd->command = cpu_to_le16(cmd_mac_control);
1054 cmd->size =
1055 cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
1056 mac->action = cpu_to_le16(priv->adapter->currentpacketfilter);
1057
9012b28a 1058 lbs_deb_cmd("wlan_cmd_mac_control(): action=0x%X size=%d\n",
876c9d3a
MT
1059 mac->action, cmd->size);
1060
9012b28a 1061 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
1062 return 0;
1063}
1064
1065/**
1066 * This function inserts command node to cmdfreeq
1067 * after cleans it. Requires adapter->driver_lock held.
1068 */
1069void __libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
1070{
1071 wlan_adapter *adapter = priv->adapter;
1072
1073 if (!ptempcmd)
1074 goto done;
1075
1076 cleanup_cmdnode(ptempcmd);
1077 list_add_tail((struct list_head *)ptempcmd, &adapter->cmdfreeq);
1078done:
1079 return;
1080}
1081
1082void libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
1083{
1084 unsigned long flags;
1085
1086 spin_lock_irqsave(&priv->adapter->driver_lock, flags);
1087 __libertas_cleanup_and_insert_cmd(priv, ptempcmd);
1088 spin_unlock_irqrestore(&priv->adapter->driver_lock, flags);
1089}
1090
1091int libertas_set_radio_control(wlan_private * priv)
1092{
1093 int ret = 0;
1094
9012b28a 1095 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
1096
1097 ret = libertas_prepare_and_send_command(priv,
1098 cmd_802_11_radio_control,
1099 cmd_act_set,
1100 cmd_option_waitforrsp, 0, NULL);
1101
9012b28a 1102 lbs_deb_cmd("RADIO_SET: on or off: 0x%X, preamble = 0x%X\n",
876c9d3a
MT
1103 priv->adapter->radioon, priv->adapter->preamble);
1104
9012b28a 1105 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
876c9d3a
MT
1106 return ret;
1107}
1108
1109int libertas_set_mac_packet_filter(wlan_private * priv)
1110{
1111 int ret = 0;
1112
9012b28a 1113 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 1114
9012b28a 1115 lbs_deb_cmd("libertas_set_mac_packet_filter value = %x\n",
876c9d3a
MT
1116 priv->adapter->currentpacketfilter);
1117
1118 /* Send MAC control command to station */
1119 ret = libertas_prepare_and_send_command(priv,
1120 cmd_mac_control, 0, 0, 0, NULL);
1121
9012b28a 1122 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
876c9d3a
MT
1123 return ret;
1124}
1125
1126/**
1127 * @brief This function prepare the command before send to firmware.
1128 *
1129 * @param priv A pointer to wlan_private structure
1130 * @param cmd_no command number
1131 * @param cmd_action command action: GET or SET
1132 * @param wait_option wait option: wait response or not
1133 * @param cmd_oid cmd oid: treated as sub command
1134 * @param pdata_buf A pointer to informaion buffer
1135 * @return 0 or -1
1136 */
1137int libertas_prepare_and_send_command(wlan_private * priv,
1138 u16 cmd_no,
1139 u16 cmd_action,
1140 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1141{
1142 int ret = 0;
1143 wlan_adapter *adapter = priv->adapter;
1144 struct cmd_ctrl_node *cmdnode;
1145 struct cmd_ds_command *cmdptr;
1146 unsigned long flags;
1147
9012b28a 1148 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
1149
1150 if (!adapter) {
9012b28a 1151 lbs_deb_cmd("PREP_CMD: adapter is Null\n");
876c9d3a
MT
1152 ret = -1;
1153 goto done;
1154 }
1155
1156 if (adapter->surpriseremoved) {
9012b28a 1157 lbs_deb_cmd("PREP_CMD: Card is Removed\n");
876c9d3a
MT
1158 ret = -1;
1159 goto done;
1160 }
1161
1162 cmdnode = libertas_get_free_cmd_ctrl_node(priv);
1163
1164 if (cmdnode == NULL) {
9012b28a 1165 lbs_deb_cmd("PREP_CMD: No free cmdnode\n");
876c9d3a
MT
1166
1167 /* Wake up main thread to execute next command */
1168 wake_up_interruptible(&priv->mainthread.waitq);
1169 ret = -1;
1170 goto done;
1171 }
1172
1173 libertas_set_cmd_ctrl_node(priv, cmdnode, cmd_oid, wait_option, pdata_buf);
1174
1175 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1176
9012b28a 1177 lbs_deb_cmd("PREP_CMD: Val of cmd ptr=%p, command=0x%X\n",
4269e2ad 1178 cmdptr, cmd_no);
876c9d3a
MT
1179
1180 if (!cmdptr) {
9012b28a 1181 lbs_deb_cmd("PREP_CMD: bufvirtualaddr of cmdnode is NULL\n");
876c9d3a
MT
1182 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1183 ret = -1;
1184 goto done;
1185 }
1186
1187 /* Set sequence number, command and INT option */
1188 adapter->seqnum++;
1189 cmdptr->seqnum = cpu_to_le16(adapter->seqnum);
1190
1191 cmdptr->command = cmd_no;
1192 cmdptr->result = 0;
1193
1194 switch (cmd_no) {
1195 case cmd_get_hw_spec:
1196 ret = wlan_cmd_hw_spec(priv, cmdptr);
1197 break;
1198 case cmd_802_11_ps_mode:
1199 ret = wlan_cmd_802_11_ps_mode(priv, cmdptr, cmd_action);
1200 break;
1201
1202 case cmd_802_11_scan:
1203 ret = libertas_cmd_80211_scan(priv, cmdptr, pdata_buf);
1204 break;
1205
1206 case cmd_mac_control:
1207 ret = wlan_cmd_mac_control(priv, cmdptr);
1208 break;
1209
1210 case cmd_802_11_associate:
1211 case cmd_802_11_reassociate:
1212 ret = libertas_cmd_80211_associate(priv, cmdptr, pdata_buf);
1213 break;
1214
1215 case cmd_802_11_deauthenticate:
1216 ret = libertas_cmd_80211_deauthenticate(priv, cmdptr);
1217 break;
1218
1219 case cmd_802_11_set_wep:
1220 ret = wlan_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf);
1221 break;
1222
1223 case cmd_802_11_ad_hoc_start:
1224 ret = libertas_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
1225 break;
1226 case cmd_code_dnld:
1227 break;
1228
1229 case cmd_802_11_reset:
1230 ret = wlan_cmd_802_11_reset(priv, cmdptr, cmd_action);
1231 break;
1232
1233 case cmd_802_11_get_log:
1234 ret = wlan_cmd_802_11_get_log(priv, cmdptr);
1235 break;
1236
1237 case cmd_802_11_authenticate:
1238 ret = libertas_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
1239 break;
1240
1241 case cmd_802_11_get_stat:
1242 ret = wlan_cmd_802_11_get_stat(priv, cmdptr);
1243 break;
1244
1245 case cmd_802_11_snmp_mib:
1246 ret = wlan_cmd_802_11_snmp_mib(priv, cmdptr,
1247 cmd_action, cmd_oid, pdata_buf);
1248 break;
1249
1250 case cmd_mac_reg_access:
1251 case cmd_bbp_reg_access:
1252 case cmd_rf_reg_access:
1253 ret = wlan_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf);
1254 break;
1255
1256 case cmd_802_11_rf_channel:
1257 ret = wlan_cmd_802_11_rf_channel(priv, cmdptr,
1258 cmd_action, pdata_buf);
1259 break;
1260
1261 case cmd_802_11_rf_tx_power:
1262 ret = wlan_cmd_802_11_rf_tx_power(priv, cmdptr,
1263 cmd_action, pdata_buf);
1264 break;
1265
1266 case cmd_802_11_radio_control:
1267 ret = wlan_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
1268 break;
1269
1270 case cmd_802_11_rf_antenna:
1271 ret = wlan_cmd_802_11_rf_antenna(priv, cmdptr,
1272 cmd_action, pdata_buf);
1273 break;
1274
1275 case cmd_802_11_data_rate:
1276 ret = wlan_cmd_802_11_data_rate(priv, cmdptr, cmd_action);
1277 break;
1278 case cmd_802_11_rate_adapt_rateset:
1279 ret = wlan_cmd_802_11_rate_adapt_rateset(priv,
1280 cmdptr, cmd_action);
1281 break;
1282
1283 case cmd_mac_multicast_adr:
1284 ret = wlan_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
1285 break;
1286
1287 case cmd_802_11_ad_hoc_join:
1288 ret = libertas_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
1289 break;
1290
1291 case cmd_802_11_rssi:
1292 ret = wlan_cmd_802_11_rssi(priv, cmdptr);
1293 break;
1294
1295 case cmd_802_11_ad_hoc_stop:
1296 ret = libertas_cmd_80211_ad_hoc_stop(priv, cmdptr);
1297 break;
1298
1299 case cmd_802_11_enable_rsn:
1300 ret = wlan_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action);
1301 break;
1302
1303 case cmd_802_11_key_material:
1304 ret = wlan_cmd_802_11_key_material(priv, cmdptr,
1305 cmd_action, cmd_oid,
1306 pdata_buf);
1307 break;
1308
1309 case cmd_802_11_pairwise_tsc:
1310 break;
1311 case cmd_802_11_group_tsc:
1312 break;
1313
1314 case cmd_802_11_mac_address:
1315 ret = wlan_cmd_802_11_mac_address(priv, cmdptr, cmd_action);
1316 break;
1317
1318 case cmd_802_11_eeprom_access:
1319 ret = wlan_cmd_802_11_eeprom_access(priv, cmdptr,
1320 cmd_action, pdata_buf);
1321 break;
1322
1323 case cmd_802_11_set_afc:
1324 case cmd_802_11_get_afc:
1325
1326 cmdptr->command = cpu_to_le16(cmd_no);
1327 cmdptr->size =
1328 cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1329 S_DS_GEN);
1330
1331 memmove(&cmdptr->params.afc,
1332 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1333
1334 ret = 0;
1335 goto done;
1336
1337 case cmd_802_11d_domain_info:
1338 ret = libertas_cmd_802_11d_domain_info(priv, cmdptr,
1339 cmd_no, cmd_action);
1340 break;
1341
1342 case cmd_802_11_sleep_params:
1343 ret = wlan_cmd_802_11_sleep_params(priv, cmdptr, cmd_action);
1344 break;
1345 case cmd_802_11_inactivity_timeout:
1346 ret = wlan_cmd_802_11_inactivity_timeout(priv, cmdptr,
1347 cmd_action, pdata_buf);
1348 libertas_set_cmd_ctrl_node(priv, cmdnode, 0, 0, pdata_buf);
1349 break;
1350
1351 case cmd_802_11_tpc_cfg:
1352 cmdptr->command = cpu_to_le16(cmd_802_11_tpc_cfg);
1353 cmdptr->size =
1354 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1355 S_DS_GEN);
1356
1357 memmove(&cmdptr->params.tpccfg,
1358 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1359
1360 ret = 0;
1361 break;
1362 case cmd_802_11_led_gpio_ctrl:
1363 {
1364 struct mrvlietypes_ledgpio *gpio =
1365 (struct mrvlietypes_ledgpio*)
1366 cmdptr->params.ledgpio.data;
1367
1368 memmove(&cmdptr->params.ledgpio,
1369 pdata_buf,
1370 sizeof(struct cmd_ds_802_11_led_ctrl));
1371
1372 cmdptr->command =
1373 cpu_to_le16(cmd_802_11_led_gpio_ctrl);
1374
1375#define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1376 cmdptr->size =
1377 cpu_to_le16(gpio->header.len + S_DS_GEN +
1378 ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1379 gpio->header.len = cpu_to_le16(gpio->header.len);
1380
1381 ret = 0;
1382 break;
1383 }
1384 case cmd_802_11_pwr_cfg:
1385 cmdptr->command = cpu_to_le16(cmd_802_11_pwr_cfg);
1386 cmdptr->size =
1387 cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) +
1388 S_DS_GEN);
1389 memmove(&cmdptr->params.pwrcfg, pdata_buf,
1390 sizeof(struct cmd_ds_802_11_pwr_cfg));
1391
1392 ret = 0;
1393 break;
1394 case cmd_bt_access:
1395 ret = wlan_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf);
1396 break;
1397
1398 case cmd_fwt_access:
1399 ret = wlan_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf);
1400 break;
1401
1402 case cmd_mesh_access:
1403 ret = wlan_cmd_mesh_access(priv, cmdptr, cmd_action, pdata_buf);
1404 break;
1405
1406 case cmd_get_tsf:
1407 cmdptr->command = cpu_to_le16(cmd_get_tsf);
1408 cmdptr->size =
1409 cpu_to_le16(sizeof(struct cmd_ds_get_tsf)
1410 + S_DS_GEN);
1411 ret = 0;
1412 break;
1413 case cmd_802_11_tx_rate_query:
1414 cmdptr->command =
1415 cpu_to_le16(cmd_802_11_tx_rate_query);
1416 cmdptr->size =
1417 cpu_to_le16(sizeof(struct cmd_tx_rate_query) +
1418 S_DS_GEN);
1419 adapter->txrate = 0;
1420 ret = 0;
1421 break;
1422 default:
9012b28a 1423 lbs_deb_cmd("PREP_CMD: unknown command- %#x\n", cmd_no);
876c9d3a
MT
1424 ret = -1;
1425 break;
1426 }
1427
1428 /* return error, since the command preparation failed */
1429 if (ret != 0) {
9012b28a 1430 lbs_deb_cmd("PREP_CMD: command preparation failed\n");
876c9d3a
MT
1431 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1432 ret = -1;
1433 goto done;
1434 }
1435
1436 cmdnode->cmdwaitqwoken = 0;
1437
1438 libertas_queue_cmd(adapter, cmdnode, 1);
1439 adapter->nr_cmd_pending++;
1440 wake_up_interruptible(&priv->mainthread.waitq);
1441
1442 if (wait_option & cmd_option_waitforrsp) {
9012b28a 1443 lbs_deb_cmd("PREP_CMD: Wait for CMD response\n");
876c9d3a
MT
1444 might_sleep();
1445 wait_event_interruptible(cmdnode->cmdwait_q,
1446 cmdnode->cmdwaitqwoken);
1447 }
1448
1449 spin_lock_irqsave(&adapter->driver_lock, flags);
1450 if (adapter->cur_cmd_retcode) {
9012b28a 1451 lbs_deb_cmd("PREP_CMD: command failed with return code=%d\n",
876c9d3a
MT
1452 adapter->cur_cmd_retcode);
1453 adapter->cur_cmd_retcode = 0;
1454 ret = -1;
1455 }
1456 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1457
1458done:
9012b28a 1459 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
876c9d3a
MT
1460 return ret;
1461}
1462
1463/**
1464 * @brief This function allocates the command buffer and link
1465 * it to command free queue.
1466 *
1467 * @param priv A pointer to wlan_private structure
1468 * @return 0 or -1
1469 */
1470int libertas_allocate_cmd_buffer(wlan_private * priv)
1471{
1472 int ret = 0;
1473 u32 ulbufsize;
1474 u32 i;
1475 struct cmd_ctrl_node *tempcmd_array;
1476 u8 *ptempvirtualaddr;
1477 wlan_adapter *adapter = priv->adapter;
1478
9012b28a 1479 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
1480
1481 /* Allocate and initialize cmdCtrlNode */
1482 ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
1483
fb3dddf2 1484 if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) {
9012b28a 1485 lbs_deb_cmd(
876c9d3a
MT
1486 "ALLOC_CMD_BUF: failed to allocate tempcmd_array\n");
1487 ret = -1;
1488 goto done;
1489 }
876c9d3a 1490 adapter->cmd_array = tempcmd_array;
876c9d3a
MT
1491
1492 /* Allocate and initialize command buffers */
1493 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1494 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
fb3dddf2 1495 if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) {
9012b28a 1496 lbs_deb_cmd(
876c9d3a
MT
1497 "ALLOC_CMD_BUF: ptempvirtualaddr: out of memory\n");
1498 ret = -1;
1499 goto done;
1500 }
1501
876c9d3a
MT
1502 /* Update command buffer virtual */
1503 tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
1504 }
1505
1506 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1507 init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
1508 libertas_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
1509 }
1510
1511 ret = 0;
9012b28a
HS
1512
1513done:
1514 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
876c9d3a
MT
1515 return ret;
1516}
1517
1518/**
1519 * @brief This function frees the command buffer.
1520 *
1521 * @param priv A pointer to wlan_private structure
1522 * @return 0 or -1
1523 */
1524int libertas_free_cmd_buffer(wlan_private * priv)
1525{
1526 u32 ulbufsize;
1527 unsigned int i;
1528 struct cmd_ctrl_node *tempcmd_array;
1529 wlan_adapter *adapter = priv->adapter;
1530
9012b28a 1531 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
1532
1533 /* need to check if cmd array is allocated or not */
1534 if (adapter->cmd_array == NULL) {
9012b28a 1535 lbs_deb_cmd("FREE_CMD_BUF: cmd_array is Null\n");
876c9d3a
MT
1536 goto done;
1537 }
1538
1539 tempcmd_array = adapter->cmd_array;
1540
1541 /* Release shared memory buffers */
1542 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1543 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1544 if (tempcmd_array[i].bufvirtualaddr) {
9012b28a 1545 lbs_deb_cmd("Free all the array\n");
876c9d3a
MT
1546 kfree(tempcmd_array[i].bufvirtualaddr);
1547 tempcmd_array[i].bufvirtualaddr = NULL;
1548 }
1549 }
1550
1551 /* Release cmd_ctrl_node */
1552 if (adapter->cmd_array) {
9012b28a 1553 lbs_deb_cmd("Free cmd_array\n");
876c9d3a
MT
1554 kfree(adapter->cmd_array);
1555 adapter->cmd_array = NULL;
1556 }
1557
1558done:
9012b28a 1559 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
1560 return 0;
1561}
1562
1563/**
1564 * @brief This function gets a free command node if available in
1565 * command free queue.
1566 *
1567 * @param priv A pointer to wlan_private structure
1568 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1569 */
1570struct cmd_ctrl_node *libertas_get_free_cmd_ctrl_node(wlan_private * priv)
1571{
1572 struct cmd_ctrl_node *tempnode;
1573 wlan_adapter *adapter = priv->adapter;
1574 unsigned long flags;
1575
1576 if (!adapter)
1577 return NULL;
1578
1579 spin_lock_irqsave(&adapter->driver_lock, flags);
1580
1581 if (!list_empty(&adapter->cmdfreeq)) {
1582 tempnode = (struct cmd_ctrl_node *)adapter->cmdfreeq.next;
1583 list_del((struct list_head *)tempnode);
1584 } else {
9012b28a 1585 lbs_deb_cmd("GET_CMD_NODE: cmd_ctrl_node is not available\n");
876c9d3a
MT
1586 tempnode = NULL;
1587 }
1588
1589 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1590
1591 if (tempnode) {
9012b28a 1592 /*
876c9d3a
MT
1593 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode available\n");
1594 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode Address = %p\n",
1595 tempnode);
9012b28a 1596 */
876c9d3a
MT
1597 cleanup_cmdnode(tempnode);
1598 }
1599
1600 return tempnode;
1601}
1602
1603/**
1604 * @brief This function cleans command node.
1605 *
1606 * @param ptempnode A pointer to cmdCtrlNode structure
1607 * @return n/a
1608 */
1609static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
1610{
1611 if (!ptempnode)
1612 return;
1613 ptempnode->cmdwaitqwoken = 1;
1614 wake_up_interruptible(&ptempnode->cmdwait_q);
1615 ptempnode->status = 0;
1616 ptempnode->cmd_oid = (u32) 0;
1617 ptempnode->wait_option = 0;
1618 ptempnode->pdata_buf = NULL;
1619
1620 if (ptempnode->bufvirtualaddr != NULL)
1621 memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
1622 return;
1623}
1624
1625/**
1626 * @brief This function initializes the command node.
1627 *
1628 * @param priv A pointer to wlan_private structure
1629 * @param ptempnode A pointer to cmd_ctrl_node structure
1630 * @param cmd_oid cmd oid: treated as sub command
1631 * @param wait_option wait option: wait response or not
1632 * @param pdata_buf A pointer to informaion buffer
1633 * @return 0 or -1
1634 */
1635void libertas_set_cmd_ctrl_node(wlan_private * priv,
1636 struct cmd_ctrl_node *ptempnode,
1637 u32 cmd_oid, u16 wait_option, void *pdata_buf)
1638{
9012b28a 1639 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
1640
1641 if (!ptempnode)
1642 return;
1643
1644 ptempnode->cmd_oid = cmd_oid;
1645 ptempnode->wait_option = wait_option;
1646 ptempnode->pdata_buf = pdata_buf;
1647
9012b28a 1648 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
1649}
1650
1651/**
1652 * @brief This function executes next command in command
1653 * pending queue. It will put fimware back to PS mode
1654 * if applicable.
1655 *
1656 * @param priv A pointer to wlan_private structure
1657 * @return 0 or -1
1658 */
1659int libertas_execute_next_command(wlan_private * priv)
1660{
1661 wlan_adapter *adapter = priv->adapter;
1662 struct cmd_ctrl_node *cmdnode = NULL;
1663 struct cmd_ds_command *cmdptr;
1664 unsigned long flags;
1665 int ret = 0;
1666
9012b28a 1667 lbs_deb_cmd("libertas_execute_next_command\n");
876c9d3a
MT
1668
1669 spin_lock_irqsave(&adapter->driver_lock, flags);
1670
1671 if (adapter->cur_cmd) {
1672 lbs_pr_alert( "EXEC_NEXT_CMD: there is command in processing!\n");
1673 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1674 ret = -1;
1675 goto done;
1676 }
1677
1678 if (!list_empty(&adapter->cmdpendingq)) {
1679 cmdnode = (struct cmd_ctrl_node *)
1680 adapter->cmdpendingq.next;
1681 }
1682
1683 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1684
1685 if (cmdnode) {
9012b28a 1686 lbs_deb_cmd(
876c9d3a
MT
1687 "EXEC_NEXT_CMD: Got next command from cmdpendingq\n");
1688 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1689
1690 if (is_command_allowed_in_ps(cmdptr->command)) {
1691 if ((adapter->psstate == PS_STATE_SLEEP)
1692 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1693 ) {
9012b28a 1694 lbs_deb_cmd(
876c9d3a
MT
1695 "EXEC_NEXT_CMD: Cannot send cmd 0x%x in psstate %d\n",
1696 cmdptr->command, adapter->psstate);
1697 ret = -1;
1698 goto done;
1699 }
9012b28a 1700 lbs_deb_cmd("EXEC_NEXT_CMD: OK to send command "
876c9d3a
MT
1701 "0x%x in psstate %d\n",
1702 cmdptr->command, adapter->psstate);
1703 } else if (adapter->psstate != PS_STATE_FULL_POWER) {
1704 /*
1705 * 1. Non-PS command:
1706 * Queue it. set needtowakeup to TRUE if current state
1707 * is SLEEP, otherwise call libertas_ps_wakeup to send Exit_PS.
1708 * 2. PS command but not Exit_PS:
1709 * Ignore it.
1710 * 3. PS command Exit_PS:
1711 * Set needtowakeup to TRUE if current state is SLEEP,
1712 * otherwise send this command down to firmware
1713 * immediately.
1714 */
1715 if (cmdptr->command !=
1716 cpu_to_le16(cmd_802_11_ps_mode)) {
1717 /* Prepare to send Exit PS,
1718 * this non PS command will be sent later */
1719 if ((adapter->psstate == PS_STATE_SLEEP)
1720 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1721 ) {
1722 /* w/ new scheme, it will not reach here.
1723 since it is blocked in main_thread. */
1724 adapter->needtowakeup = 1;
1725 } else
1726 libertas_ps_wakeup(priv, 0);
1727
1728 ret = 0;
1729 goto done;
1730 } else {
1731 /*
1732 * PS command. Ignore it if it is not Exit_PS.
1733 * otherwise send it down immediately.
1734 */
1735 struct cmd_ds_802_11_ps_mode *psm =
1736 &cmdptr->params.psmode;
1737
9012b28a 1738 lbs_deb_cmd(
876c9d3a
MT
1739 "EXEC_NEXT_CMD: PS cmd- action=0x%x\n",
1740 psm->action);
1741 if (psm->action !=
1742 cpu_to_le16(cmd_subcmd_exit_ps)) {
9012b28a 1743 lbs_deb_cmd(
876c9d3a
MT
1744 "EXEC_NEXT_CMD: Ignore Enter PS cmd\n");
1745 list_del((struct list_head *)cmdnode);
1746 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1747
1748 ret = 0;
1749 goto done;
1750 }
1751
1752 if ((adapter->psstate == PS_STATE_SLEEP)
1753 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1754 ) {
9012b28a 1755 lbs_deb_cmd(
876c9d3a
MT
1756 "EXEC_NEXT_CMD: Ignore ExitPS cmd in sleep\n");
1757 list_del((struct list_head *)cmdnode);
1758 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1759 adapter->needtowakeup = 1;
1760
1761 ret = 0;
1762 goto done;
1763 }
1764
9012b28a 1765 lbs_deb_cmd(
876c9d3a
MT
1766 "EXEC_NEXT_CMD: Sending Exit_PS down...\n");
1767 }
1768 }
1769 list_del((struct list_head *)cmdnode);
9012b28a 1770 lbs_deb_cmd("EXEC_NEXT_CMD: Sending 0x%04X command\n",
876c9d3a
MT
1771 cmdptr->command);
1772 DownloadcommandToStation(priv, cmdnode);
1773 } else {
1774 /*
1775 * check if in power save mode, if yes, put the device back
1776 * to PS mode
1777 */
1778 if ((adapter->psmode != wlan802_11powermodecam) &&
1779 (adapter->psstate == PS_STATE_FULL_POWER) &&
1780 (adapter->connect_status == libertas_connected)) {
1781 if (adapter->secinfo.WPAenabled
1782 || adapter->secinfo.WPA2enabled) {
1783 /* check for valid WPA group keys */
1784 if (adapter->wpa_mcast_key.len
1785 || adapter->wpa_unicast_key.len) {
9012b28a 1786 lbs_deb_cmd(
876c9d3a
MT
1787 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1788 " go back to PS_SLEEP");
1789 libertas_ps_sleep(priv, 0);
1790 }
1791 } else {
9012b28a 1792 lbs_deb_cmd(
876c9d3a
MT
1793 "EXEC_NEXT_CMD: command PendQ is empty,"
1794 " go back to PS_SLEEP");
1795 libertas_ps_sleep(priv, 0);
1796 }
1797 }
1798 }
1799
1800 ret = 0;
1801done:
1802 return ret;
1803}
1804
1805void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str)
1806{
1807 union iwreq_data iwrq;
1808 u8 buf[50];
1809
9012b28a 1810 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
1811
1812 memset(&iwrq, 0, sizeof(union iwreq_data));
1813 memset(buf, 0, sizeof(buf));
1814
1815 snprintf(buf, sizeof(buf) - 1, "%s", str);
1816
1817 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1818
1819 /* Send Event to upper layer */
9012b28a 1820 lbs_deb_cmd("Event Indication string = %s\n",
876c9d3a 1821 (char *)buf);
9012b28a 1822 lbs_deb_cmd("Event Indication String length = %d\n", iwrq.data.length);
876c9d3a 1823
9012b28a 1824 lbs_deb_cmd("Sending wireless event IWEVCUSTOM for %s\n", str);
876c9d3a
MT
1825 wireless_send_event(priv->wlan_dev.netdev, IWEVCUSTOM, &iwrq, buf);
1826
9012b28a 1827 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
1828}
1829
1830static int sendconfirmsleep(wlan_private * priv, u8 * cmdptr, u16 size)
1831{
1832 unsigned long flags;
1833 wlan_adapter *adapter = priv->adapter;
1834 int ret = 0;
1835
9012b28a 1836 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 1837
9012b28a 1838 lbs_deb_cmd("SEND_SLEEPC_CMD: Before download, size of cmd = %d\n",
876c9d3a
MT
1839 size);
1840
1841 lbs_dbg_hex("SEND_SLEEPC_CMD: Sleep confirm command", cmdptr, size);
1842
208fdd2f 1843 ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
876c9d3a
MT
1844 priv->wlan_dev.dnld_sent = DNLD_RES_RECEIVED;
1845
1846 spin_lock_irqsave(&adapter->driver_lock, flags);
1847 if (adapter->intcounter || adapter->currenttxskb)
9012b28a 1848 lbs_deb_cmd("SEND_SLEEPC_CMD: intcounter=%d currenttxskb=%p\n",
876c9d3a
MT
1849 adapter->intcounter, adapter->currenttxskb);
1850 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1851
1852 if (ret) {
1853 lbs_pr_alert(
1854 "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
1855 } else {
1856 spin_lock_irqsave(&adapter->driver_lock, flags);
1857 if (!adapter->intcounter) {
1858 adapter->psstate = PS_STATE_SLEEP;
1859 } else {
9012b28a 1860 lbs_deb_cmd("SEND_SLEEPC_CMD: After sent,IntC=%d\n",
876c9d3a
MT
1861 adapter->intcounter);
1862 }
1863 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1864
9012b28a
HS
1865 lbs_deb_cmd("SEND_SLEEPC_CMD: Sent Confirm Sleep command\n");
1866 lbs_deb_cmd("+");
876c9d3a
MT
1867 }
1868
9012b28a 1869 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
876c9d3a
MT
1870 return ret;
1871}
1872
1873void libertas_ps_sleep(wlan_private * priv, int wait_option)
1874{
9012b28a 1875 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
1876
1877 /*
1878 * PS is currently supported only in Infrastructure mode
1879 * Remove this check if it is to be supported in IBSS mode also
1880 */
1881
1882 libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
1883 cmd_subcmd_enter_ps, wait_option, 0, NULL);
1884
9012b28a 1885 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
1886}
1887
1888/**
1889 * @brief This function sends Eixt_PS command to firmware.
1890 *
1891 * @param priv A pointer to wlan_private structure
1892 * @param wait_option wait response or not
1893 * @return n/a
1894 */
1895void libertas_ps_wakeup(wlan_private * priv, int wait_option)
1896{
1897 enum WLAN_802_11_POWER_MODE Localpsmode;
1898
9012b28a 1899 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
1900
1901 Localpsmode = wlan802_11powermodecam;
1902
9012b28a 1903 lbs_deb_cmd("Exit_PS: Localpsmode = %d\n", Localpsmode);
876c9d3a
MT
1904
1905 libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
1906 cmd_subcmd_exit_ps,
1907 wait_option, 0, &Localpsmode);
1908
9012b28a 1909 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
1910}
1911
1912/**
1913 * @brief This function checks condition and prepares to
1914 * send sleep confirm command to firmware if ok.
1915 *
1916 * @param priv A pointer to wlan_private structure
1917 * @param psmode Power Saving mode
1918 * @return n/a
1919 */
1920void libertas_ps_confirm_sleep(wlan_private * priv, u16 psmode)
1921{
1922 unsigned long flags =0;
1923 wlan_adapter *adapter = priv->adapter;
1924 u8 allowed = 1;
1925
9012b28a 1926 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
1927
1928 if (priv->wlan_dev.dnld_sent) {
1929 allowed = 0;
9012b28a 1930 lbs_deb_cmd("D");
876c9d3a
MT
1931 }
1932
1933 spin_lock_irqsave(&adapter->driver_lock, flags);
1934 if (adapter->cur_cmd) {
1935 allowed = 0;
9012b28a 1936 lbs_deb_cmd("C");
876c9d3a
MT
1937 }
1938 if (adapter->intcounter > 0) {
1939 allowed = 0;
9012b28a 1940 lbs_deb_cmd("I%d", adapter->intcounter);
876c9d3a
MT
1941 }
1942 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1943
1944 if (allowed) {
9012b28a 1945 lbs_deb_cmd("Sending libertas_ps_confirm_sleep\n");
876c9d3a
MT
1946 sendconfirmsleep(priv, (u8 *) & adapter->libertas_ps_confirm_sleep,
1947 sizeof(struct PS_CMD_ConfirmSleep));
1948 } else {
9012b28a 1949 lbs_deb_cmd("Sleep Confirm has been delayed\n");
876c9d3a
MT
1950 }
1951
9012b28a 1952 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a 1953}