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