blob: 30f1d41a16d75d14e6adfdbab2afeb44c9b94795 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
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
16static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode);
17
18static 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 */
29static 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
43static 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
Holger Schurig9012b282007-05-25 11:27:16 -040047 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020048
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
Holger Schurig9012b282007-05-25 11:27:16 -040054 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020055 return 0;
56}
57
58static 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
Holger Schurig9012b282007-05-25 11:27:16 -040066 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020067
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:
Holger Schurig9012b282007-05-25 11:27:16 -040076 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
77 lbs_deb_cmd("locallisteninterval = %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020078 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:
Holger Schurig9012b282007-05-25 11:27:16 -040089 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020090 break;
91
92 case cmd_subcmd_sleep_confirmed:
Holger Schurig9012b282007-05-25 11:27:16 -040093 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020094 break;
95
96 default:
97 break;
98 }
99
Holger Schurig9012b282007-05-25 11:27:16 -0400100 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200101 return 0;
102}
103
104static 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
126static 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
Holger Schurig9012b282007-05-25 11:27:16 -0400133 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200134
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
Holger Schurig9012b282007-05-25 11:27:16 -0400154 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200155 return 0;
156}
157
158static 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
Holger Schurig9012b282007-05-25 11:27:16 -0400168 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200169
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) {
Holger Schurig9012b282007-05-25 11:27:16 -0400178 lbs_deb_cmd("Invalid association request!");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200179 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
Holger Schurig9012b282007-05-25 11:27:16 -0400190 lbs_deb_cmd("Tx key Index: %u\n", wep->keyindex);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200191
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:
Holger Schurig9012b282007-05-25 11:27:16 -0400210 lbs_deb_cmd("Invalid WEP key %d length of %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200211 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
229done:
Holger Schurig9012b282007-05-25 11:27:16 -0400230 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200231 return ret;
232}
233
234static 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
256static 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
282static 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
Holger Schurig9012b282007-05-25 11:27:16 -0400293 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200294
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
325done:
Holger Schurig9012b282007-05-25 11:27:16 -0400326 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200327 return ret;
328}
329
330static 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
342static 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
352static 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
363static 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
Holger Schurig9012b282007-05-25 11:27:16 -0400372 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200373
Holger Schurig9012b282007-05-25 11:27:16 -0400374 lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200375
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 {
Dan Williams0dc5a292007-05-10 22:58:02 -0400384 u8 mode = (u8) (size_t) pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200385 pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
386 pSNMPMIB->oid = cpu_to_le16((u16) desired_bsstype_i);
387 pSNMPMIB->bufsize = sizeof(u8);
Dan Williams0dc5a292007-05-10 22:58:02 -0400388 if (mode == IW_MODE_ADHOC) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200389 ucTemp = SNMP_MIB_VALUE_ADHOC;
Dan Williams0dc5a292007-05-10 22:58:02 -0400390 } else {
391 /* Infra and Auto modes */
392 ucTemp = SNMP_MIB_VALUE_INFRA;
393 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200394
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
Holger Schurig9012b282007-05-25 11:27:16 -0400480 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481 "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
Holger Schurig9012b282007-05-25 11:27:16 -0400484 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200485 "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
Holger Schurig9012b282007-05-25 11:27:16 -0400489 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200490 return 0;
491}
492
493static 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
Holger Schurig9012b282007-05-25 11:27:16 -0400501 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200502
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
Holger Schurig9012b282007-05-25 11:27:16 -0400530 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200531 return 0;
532}
533
534static 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
Holger Schurig9012b282007-05-25 11:27:16 -0400541 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200542
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
Holger Schurig9012b282007-05-25 11:27:16 -0400549 lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n", cmd->size,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200550 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 }
Holger Schurig9012b282007-05-25 11:27:16 -0400575
576 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200577 return 0;
578}
579
580static 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
601static 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
Holger Schurig9012b282007-05-25 11:27:16 -0400614 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200615
616 rateadapt->action = cmd_action;
617 rateadapt->enablehwauto = adapter->enablehwauto;
618 rateadapt->bitmap = adapter->ratebitmap;
619
Holger Schurig9012b282007-05-25 11:27:16 -0400620 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200621 return 0;
622}
623
624static 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
Holger Schurig9012b282007-05-25 11:27:16 -0400632 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200633
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);
Holger Schurig9012b282007-05-25 11:27:16 -0400646 lbs_deb_cmd("Setting FW for fixed rate 0x%02X\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200647 adapter->datarate);
648 } else if (action == cmd_act_set_tx_auto) {
Holger Schurig9012b282007-05-25 11:27:16 -0400649 lbs_deb_cmd("Setting FW for AUTO rate\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200650 }
651
Holger Schurig9012b282007-05-25 11:27:16 -0400652 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200653 return 0;
654}
655
656static 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
677static 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
696static 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
717static 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
Holger Schurig9012b282007-05-25 11:27:16 -0400723 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200724
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
Holger Schurig9012b282007-05-25 11:27:16 -0400789 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200790 return 0;
791}
792
793static 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
816static 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
Holger Schurig9012b282007-05-25 11:27:16 -0400822 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200823
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
838static 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;
Holger Schurig9012b282007-05-25 11:27:16 -0400843 lbs_deb_cmd("BT CMD(%d)\n", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200844
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
871static 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;
Holger Schurig9012b282007-05-25 11:27:16 -0400876 lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200877
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
893static 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;
Holger Schurig9012b282007-05-25 11:27:16 -0400898 lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200899
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
915void 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
Holger Schurig9012b282007-05-25 11:27:16 -0400920 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200921
922 if (!cmdnode) {
Holger Schurig9012b282007-05-25 11:27:16 -0400923 lbs_deb_cmd("QUEUE_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200924 goto done;
925 }
926
927 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
928 if (!cmdptr) {
Holger Schurig9012b282007-05-25 11:27:16 -0400929 lbs_deb_cmd("QUEUE_CMD: cmdptr is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200930 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
Holger Schurig9012b282007-05-25 11:27:16 -0400952 lbs_deb_cmd("QUEUE_CMD: Inserted node=%p, cmd=0x%x in cmdpendingq\n",
Dan Williams4269e2a2007-05-10 23:10:18 -0400953 cmdnode,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200954 ((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command);
955
956done:
Holger Schurig9012b282007-05-25 11:27:16 -0400957 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200958}
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 */
967static 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
Holger Schurig9012b282007-05-25 11:27:16 -0400977 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200978
979 if (!adapter || !cmdnode) {
Holger Schurig9012b282007-05-25 11:27:16 -0400980 lbs_deb_cmd("DNLD_CMD: adapter = %p, cmdnode = %p\n",
Dan Williams4269e2a2007-05-10 23:10:18 -0400981 adapter, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200982 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) {
Holger Schurig9012b282007-05-25 11:27:16 -0400996 lbs_deb_cmd("DNLD_CMD: cmdptr is Null or cmd size is Zero, "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200997 "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);
Holger Schurig9012b282007-05-25 11:27:16 -04001007 lbs_deb_cmd("DNLD_CMD:: Before download, size of cmd = %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001008 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) {
Holger Schurig9012b282007-05-25 11:27:16 -04001020 lbs_deb_cmd("DNLD_CMD: Host to Card failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001021 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
Holger Schurig9012b282007-05-25 11:27:16 -04001029 lbs_deb_cmd("DNLD_CMD: Sent command 0x%x @ %lu\n", command, jiffies);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001030 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
Holger Schurig9012b282007-05-25 11:27:16 -04001042done:
1043 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001044 return ret;
1045}
1046
1047static 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
Holger Schurig9012b282007-05-25 11:27:16 -04001052 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001053
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
Holger Schurig9012b282007-05-25 11:27:16 -04001059 lbs_deb_cmd("wlan_cmd_mac_control(): action=0x%X size=%d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001060 mac->action, cmd->size);
1061
Holger Schurig9012b282007-05-25 11:27:16 -04001062 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001063 return 0;
1064}
1065
1066/**
1067 * This function inserts command node to cmdfreeq
1068 * after cleans it. Requires adapter->driver_lock held.
1069 */
1070void __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);
1079done:
1080 return;
1081}
1082
1083void 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
1092int libertas_set_radio_control(wlan_private * priv)
1093{
1094 int ret = 0;
1095
Holger Schurig9012b282007-05-25 11:27:16 -04001096 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001097
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
Holger Schurig9012b282007-05-25 11:27:16 -04001103 lbs_deb_cmd("RADIO_SET: on or off: 0x%X, preamble = 0x%X\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001104 priv->adapter->radioon, priv->adapter->preamble);
1105
Holger Schurig9012b282007-05-25 11:27:16 -04001106 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001107 return ret;
1108}
1109
1110int libertas_set_mac_packet_filter(wlan_private * priv)
1111{
1112 int ret = 0;
1113
Holger Schurig9012b282007-05-25 11:27:16 -04001114 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001115
Holger Schurig9012b282007-05-25 11:27:16 -04001116 lbs_deb_cmd("libertas_set_mac_packet_filter value = %x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001117 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
Holger Schurig9012b282007-05-25 11:27:16 -04001123 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001124 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 */
1138int 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
Holger Schurig9012b282007-05-25 11:27:16 -04001149 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001150
1151 if (!adapter) {
Holger Schurig9012b282007-05-25 11:27:16 -04001152 lbs_deb_cmd("PREP_CMD: adapter is Null\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001153 ret = -1;
1154 goto done;
1155 }
1156
1157 if (adapter->surpriseremoved) {
Holger Schurig9012b282007-05-25 11:27:16 -04001158 lbs_deb_cmd("PREP_CMD: Card is Removed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001159 ret = -1;
1160 goto done;
1161 }
1162
1163 cmdnode = libertas_get_free_cmd_ctrl_node(priv);
1164
1165 if (cmdnode == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -04001166 lbs_deb_cmd("PREP_CMD: No free cmdnode\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001167
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
Holger Schurig9012b282007-05-25 11:27:16 -04001178 lbs_deb_cmd("PREP_CMD: Val of cmd ptr=%p, command=0x%X\n",
Dan Williams4269e2a2007-05-10 23:10:18 -04001179 cmdptr, cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001180
1181 if (!cmdptr) {
Holger Schurig9012b282007-05-25 11:27:16 -04001182 lbs_deb_cmd("PREP_CMD: bufvirtualaddr of cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001183 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:
Holger Schurig9012b282007-05-25 11:27:16 -04001424 lbs_deb_cmd("PREP_CMD: unknown command- %#x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001425 ret = -1;
1426 break;
1427 }
1428
1429 /* return error, since the command preparation failed */
1430 if (ret != 0) {
Holger Schurig9012b282007-05-25 11:27:16 -04001431 lbs_deb_cmd("PREP_CMD: command preparation failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001432 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) {
Holger Schurig9012b282007-05-25 11:27:16 -04001444 lbs_deb_cmd("PREP_CMD: Wait for CMD response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001445 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) {
Holger Schurig9012b282007-05-25 11:27:16 -04001452 lbs_deb_cmd("PREP_CMD: command failed with return code=%d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001453 adapter->cur_cmd_retcode);
1454 adapter->cur_cmd_retcode = 0;
1455 ret = -1;
1456 }
1457 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1458
1459done:
Holger Schurig9012b282007-05-25 11:27:16 -04001460 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001461 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 */
1471int 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
Holger Schurig9012b282007-05-25 11:27:16 -04001480 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001481
1482 /* Allocate and initialize cmdCtrlNode */
1483 ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
1484
1485 if (!(tempcmd_array = kmalloc(ulbufsize, GFP_KERNEL))) {
Holger Schurig9012b282007-05-25 11:27:16 -04001486 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001487 "ALLOC_CMD_BUF: failed to allocate tempcmd_array\n");
1488 ret = -1;
1489 goto done;
1490 }
1491
1492 adapter->cmd_array = tempcmd_array;
1493 memset(adapter->cmd_array, 0, ulbufsize);
1494
1495 /* Allocate and initialize command buffers */
1496 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1497 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1498 if (!(ptempvirtualaddr = kmalloc(ulbufsize, GFP_KERNEL))) {
Holger Schurig9012b282007-05-25 11:27:16 -04001499 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001500 "ALLOC_CMD_BUF: ptempvirtualaddr: out of memory\n");
1501 ret = -1;
1502 goto done;
1503 }
1504
1505 memset(ptempvirtualaddr, 0, ulbufsize);
1506
1507 /* Update command buffer virtual */
1508 tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
1509 }
1510
1511 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1512 init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
1513 libertas_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
1514 }
1515
1516 ret = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001517
1518done:
1519 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001520 return ret;
1521}
1522
1523/**
1524 * @brief This function frees the command buffer.
1525 *
1526 * @param priv A pointer to wlan_private structure
1527 * @return 0 or -1
1528 */
1529int libertas_free_cmd_buffer(wlan_private * priv)
1530{
1531 u32 ulbufsize;
1532 unsigned int i;
1533 struct cmd_ctrl_node *tempcmd_array;
1534 wlan_adapter *adapter = priv->adapter;
1535
Holger Schurig9012b282007-05-25 11:27:16 -04001536 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001537
1538 /* need to check if cmd array is allocated or not */
1539 if (adapter->cmd_array == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -04001540 lbs_deb_cmd("FREE_CMD_BUF: cmd_array is Null\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001541 goto done;
1542 }
1543
1544 tempcmd_array = adapter->cmd_array;
1545
1546 /* Release shared memory buffers */
1547 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1548 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1549 if (tempcmd_array[i].bufvirtualaddr) {
Holger Schurig9012b282007-05-25 11:27:16 -04001550 lbs_deb_cmd("Free all the array\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001551 kfree(tempcmd_array[i].bufvirtualaddr);
1552 tempcmd_array[i].bufvirtualaddr = NULL;
1553 }
1554 }
1555
1556 /* Release cmd_ctrl_node */
1557 if (adapter->cmd_array) {
Holger Schurig9012b282007-05-25 11:27:16 -04001558 lbs_deb_cmd("Free cmd_array\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001559 kfree(adapter->cmd_array);
1560 adapter->cmd_array = NULL;
1561 }
1562
1563done:
Holger Schurig9012b282007-05-25 11:27:16 -04001564 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001565 return 0;
1566}
1567
1568/**
1569 * @brief This function gets a free command node if available in
1570 * command free queue.
1571 *
1572 * @param priv A pointer to wlan_private structure
1573 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1574 */
1575struct cmd_ctrl_node *libertas_get_free_cmd_ctrl_node(wlan_private * priv)
1576{
1577 struct cmd_ctrl_node *tempnode;
1578 wlan_adapter *adapter = priv->adapter;
1579 unsigned long flags;
1580
1581 if (!adapter)
1582 return NULL;
1583
1584 spin_lock_irqsave(&adapter->driver_lock, flags);
1585
1586 if (!list_empty(&adapter->cmdfreeq)) {
1587 tempnode = (struct cmd_ctrl_node *)adapter->cmdfreeq.next;
1588 list_del((struct list_head *)tempnode);
1589 } else {
Holger Schurig9012b282007-05-25 11:27:16 -04001590 lbs_deb_cmd("GET_CMD_NODE: cmd_ctrl_node is not available\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001591 tempnode = NULL;
1592 }
1593
1594 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1595
1596 if (tempnode) {
Holger Schurig9012b282007-05-25 11:27:16 -04001597 /*
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001598 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode available\n");
1599 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode Address = %p\n",
1600 tempnode);
Holger Schurig9012b282007-05-25 11:27:16 -04001601 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001602 cleanup_cmdnode(tempnode);
1603 }
1604
1605 return tempnode;
1606}
1607
1608/**
1609 * @brief This function cleans command node.
1610 *
1611 * @param ptempnode A pointer to cmdCtrlNode structure
1612 * @return n/a
1613 */
1614static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
1615{
1616 if (!ptempnode)
1617 return;
1618 ptempnode->cmdwaitqwoken = 1;
1619 wake_up_interruptible(&ptempnode->cmdwait_q);
1620 ptempnode->status = 0;
1621 ptempnode->cmd_oid = (u32) 0;
1622 ptempnode->wait_option = 0;
1623 ptempnode->pdata_buf = NULL;
1624
1625 if (ptempnode->bufvirtualaddr != NULL)
1626 memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
1627 return;
1628}
1629
1630/**
1631 * @brief This function initializes the command node.
1632 *
1633 * @param priv A pointer to wlan_private structure
1634 * @param ptempnode A pointer to cmd_ctrl_node structure
1635 * @param cmd_oid cmd oid: treated as sub command
1636 * @param wait_option wait option: wait response or not
1637 * @param pdata_buf A pointer to informaion buffer
1638 * @return 0 or -1
1639 */
1640void libertas_set_cmd_ctrl_node(wlan_private * priv,
1641 struct cmd_ctrl_node *ptempnode,
1642 u32 cmd_oid, u16 wait_option, void *pdata_buf)
1643{
Holger Schurig9012b282007-05-25 11:27:16 -04001644 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001645
1646 if (!ptempnode)
1647 return;
1648
1649 ptempnode->cmd_oid = cmd_oid;
1650 ptempnode->wait_option = wait_option;
1651 ptempnode->pdata_buf = pdata_buf;
1652
Holger Schurig9012b282007-05-25 11:27:16 -04001653 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001654}
1655
1656/**
1657 * @brief This function executes next command in command
1658 * pending queue. It will put fimware back to PS mode
1659 * if applicable.
1660 *
1661 * @param priv A pointer to wlan_private structure
1662 * @return 0 or -1
1663 */
1664int libertas_execute_next_command(wlan_private * priv)
1665{
1666 wlan_adapter *adapter = priv->adapter;
1667 struct cmd_ctrl_node *cmdnode = NULL;
1668 struct cmd_ds_command *cmdptr;
1669 unsigned long flags;
1670 int ret = 0;
1671
Holger Schurig9012b282007-05-25 11:27:16 -04001672 lbs_deb_cmd("libertas_execute_next_command\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001673
1674 spin_lock_irqsave(&adapter->driver_lock, flags);
1675
1676 if (adapter->cur_cmd) {
1677 lbs_pr_alert( "EXEC_NEXT_CMD: there is command in processing!\n");
1678 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1679 ret = -1;
1680 goto done;
1681 }
1682
1683 if (!list_empty(&adapter->cmdpendingq)) {
1684 cmdnode = (struct cmd_ctrl_node *)
1685 adapter->cmdpendingq.next;
1686 }
1687
1688 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1689
1690 if (cmdnode) {
Holger Schurig9012b282007-05-25 11:27:16 -04001691 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001692 "EXEC_NEXT_CMD: Got next command from cmdpendingq\n");
1693 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1694
1695 if (is_command_allowed_in_ps(cmdptr->command)) {
1696 if ((adapter->psstate == PS_STATE_SLEEP)
1697 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1698 ) {
Holger Schurig9012b282007-05-25 11:27:16 -04001699 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001700 "EXEC_NEXT_CMD: Cannot send cmd 0x%x in psstate %d\n",
1701 cmdptr->command, adapter->psstate);
1702 ret = -1;
1703 goto done;
1704 }
Holger Schurig9012b282007-05-25 11:27:16 -04001705 lbs_deb_cmd("EXEC_NEXT_CMD: OK to send command "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001706 "0x%x in psstate %d\n",
1707 cmdptr->command, adapter->psstate);
1708 } else if (adapter->psstate != PS_STATE_FULL_POWER) {
1709 /*
1710 * 1. Non-PS command:
1711 * Queue it. set needtowakeup to TRUE if current state
1712 * is SLEEP, otherwise call libertas_ps_wakeup to send Exit_PS.
1713 * 2. PS command but not Exit_PS:
1714 * Ignore it.
1715 * 3. PS command Exit_PS:
1716 * Set needtowakeup to TRUE if current state is SLEEP,
1717 * otherwise send this command down to firmware
1718 * immediately.
1719 */
1720 if (cmdptr->command !=
1721 cpu_to_le16(cmd_802_11_ps_mode)) {
1722 /* Prepare to send Exit PS,
1723 * this non PS command will be sent later */
1724 if ((adapter->psstate == PS_STATE_SLEEP)
1725 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1726 ) {
1727 /* w/ new scheme, it will not reach here.
1728 since it is blocked in main_thread. */
1729 adapter->needtowakeup = 1;
1730 } else
1731 libertas_ps_wakeup(priv, 0);
1732
1733 ret = 0;
1734 goto done;
1735 } else {
1736 /*
1737 * PS command. Ignore it if it is not Exit_PS.
1738 * otherwise send it down immediately.
1739 */
1740 struct cmd_ds_802_11_ps_mode *psm =
1741 &cmdptr->params.psmode;
1742
Holger Schurig9012b282007-05-25 11:27:16 -04001743 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001744 "EXEC_NEXT_CMD: PS cmd- action=0x%x\n",
1745 psm->action);
1746 if (psm->action !=
1747 cpu_to_le16(cmd_subcmd_exit_ps)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001748 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001749 "EXEC_NEXT_CMD: Ignore Enter PS cmd\n");
1750 list_del((struct list_head *)cmdnode);
1751 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1752
1753 ret = 0;
1754 goto done;
1755 }
1756
1757 if ((adapter->psstate == PS_STATE_SLEEP)
1758 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1759 ) {
Holger Schurig9012b282007-05-25 11:27:16 -04001760 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001761 "EXEC_NEXT_CMD: Ignore ExitPS cmd in sleep\n");
1762 list_del((struct list_head *)cmdnode);
1763 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1764 adapter->needtowakeup = 1;
1765
1766 ret = 0;
1767 goto done;
1768 }
1769
Holger Schurig9012b282007-05-25 11:27:16 -04001770 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001771 "EXEC_NEXT_CMD: Sending Exit_PS down...\n");
1772 }
1773 }
1774 list_del((struct list_head *)cmdnode);
Holger Schurig9012b282007-05-25 11:27:16 -04001775 lbs_deb_cmd("EXEC_NEXT_CMD: Sending 0x%04X command\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001776 cmdptr->command);
1777 DownloadcommandToStation(priv, cmdnode);
1778 } else {
1779 /*
1780 * check if in power save mode, if yes, put the device back
1781 * to PS mode
1782 */
1783 if ((adapter->psmode != wlan802_11powermodecam) &&
1784 (adapter->psstate == PS_STATE_FULL_POWER) &&
1785 (adapter->connect_status == libertas_connected)) {
1786 if (adapter->secinfo.WPAenabled
1787 || adapter->secinfo.WPA2enabled) {
1788 /* check for valid WPA group keys */
1789 if (adapter->wpa_mcast_key.len
1790 || adapter->wpa_unicast_key.len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001791 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001792 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1793 " go back to PS_SLEEP");
1794 libertas_ps_sleep(priv, 0);
1795 }
1796 } else {
Holger Schurig9012b282007-05-25 11:27:16 -04001797 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001798 "EXEC_NEXT_CMD: command PendQ is empty,"
1799 " go back to PS_SLEEP");
1800 libertas_ps_sleep(priv, 0);
1801 }
1802 }
1803 }
1804
1805 ret = 0;
1806done:
1807 return ret;
1808}
1809
1810void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str)
1811{
1812 union iwreq_data iwrq;
1813 u8 buf[50];
1814
Holger Schurig9012b282007-05-25 11:27:16 -04001815 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001816
1817 memset(&iwrq, 0, sizeof(union iwreq_data));
1818 memset(buf, 0, sizeof(buf));
1819
1820 snprintf(buf, sizeof(buf) - 1, "%s", str);
1821
1822 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1823
1824 /* Send Event to upper layer */
Holger Schurig9012b282007-05-25 11:27:16 -04001825 lbs_deb_cmd("Event Indication string = %s\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001826 (char *)buf);
Holger Schurig9012b282007-05-25 11:27:16 -04001827 lbs_deb_cmd("Event Indication String length = %d\n", iwrq.data.length);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001828
Holger Schurig9012b282007-05-25 11:27:16 -04001829 lbs_deb_cmd("Sending wireless event IWEVCUSTOM for %s\n", str);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001830 wireless_send_event(priv->wlan_dev.netdev, IWEVCUSTOM, &iwrq, buf);
1831
Holger Schurig9012b282007-05-25 11:27:16 -04001832 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001833}
1834
1835static int sendconfirmsleep(wlan_private * priv, u8 * cmdptr, u16 size)
1836{
1837 unsigned long flags;
1838 wlan_adapter *adapter = priv->adapter;
1839 int ret = 0;
1840
Holger Schurig9012b282007-05-25 11:27:16 -04001841 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001842
Holger Schurig9012b282007-05-25 11:27:16 -04001843 lbs_deb_cmd("SEND_SLEEPC_CMD: Before download, size of cmd = %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001844 size);
1845
1846 lbs_dbg_hex("SEND_SLEEPC_CMD: Sleep confirm command", cmdptr, size);
1847
1848 ret = libertas_sbi_host_to_card(priv, MVMS_CMD, cmdptr, size);
1849 priv->wlan_dev.dnld_sent = DNLD_RES_RECEIVED;
1850
1851 spin_lock_irqsave(&adapter->driver_lock, flags);
1852 if (adapter->intcounter || adapter->currenttxskb)
Holger Schurig9012b282007-05-25 11:27:16 -04001853 lbs_deb_cmd("SEND_SLEEPC_CMD: intcounter=%d currenttxskb=%p\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001854 adapter->intcounter, adapter->currenttxskb);
1855 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1856
1857 if (ret) {
1858 lbs_pr_alert(
1859 "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
1860 } else {
1861 spin_lock_irqsave(&adapter->driver_lock, flags);
1862 if (!adapter->intcounter) {
1863 adapter->psstate = PS_STATE_SLEEP;
1864 } else {
Holger Schurig9012b282007-05-25 11:27:16 -04001865 lbs_deb_cmd("SEND_SLEEPC_CMD: After sent,IntC=%d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001866 adapter->intcounter);
1867 }
1868 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1869
Holger Schurig9012b282007-05-25 11:27:16 -04001870 lbs_deb_cmd("SEND_SLEEPC_CMD: Sent Confirm Sleep command\n");
1871 lbs_deb_cmd("+");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001872 }
1873
Holger Schurig9012b282007-05-25 11:27:16 -04001874 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001875 return ret;
1876}
1877
1878void libertas_ps_sleep(wlan_private * priv, int wait_option)
1879{
Holger Schurig9012b282007-05-25 11:27:16 -04001880 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001881
1882 /*
1883 * PS is currently supported only in Infrastructure mode
1884 * Remove this check if it is to be supported in IBSS mode also
1885 */
1886
1887 libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
1888 cmd_subcmd_enter_ps, wait_option, 0, NULL);
1889
Holger Schurig9012b282007-05-25 11:27:16 -04001890 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001891}
1892
1893/**
1894 * @brief This function sends Eixt_PS command to firmware.
1895 *
1896 * @param priv A pointer to wlan_private structure
1897 * @param wait_option wait response or not
1898 * @return n/a
1899 */
1900void libertas_ps_wakeup(wlan_private * priv, int wait_option)
1901{
1902 enum WLAN_802_11_POWER_MODE Localpsmode;
1903
Holger Schurig9012b282007-05-25 11:27:16 -04001904 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001905
1906 Localpsmode = wlan802_11powermodecam;
1907
Holger Schurig9012b282007-05-25 11:27:16 -04001908 lbs_deb_cmd("Exit_PS: Localpsmode = %d\n", Localpsmode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001909
1910 libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
1911 cmd_subcmd_exit_ps,
1912 wait_option, 0, &Localpsmode);
1913
Holger Schurig9012b282007-05-25 11:27:16 -04001914 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001915}
1916
1917/**
1918 * @brief This function checks condition and prepares to
1919 * send sleep confirm command to firmware if ok.
1920 *
1921 * @param priv A pointer to wlan_private structure
1922 * @param psmode Power Saving mode
1923 * @return n/a
1924 */
1925void libertas_ps_confirm_sleep(wlan_private * priv, u16 psmode)
1926{
1927 unsigned long flags =0;
1928 wlan_adapter *adapter = priv->adapter;
1929 u8 allowed = 1;
1930
Holger Schurig9012b282007-05-25 11:27:16 -04001931 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001932
1933 if (priv->wlan_dev.dnld_sent) {
1934 allowed = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001935 lbs_deb_cmd("D");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001936 }
1937
1938 spin_lock_irqsave(&adapter->driver_lock, flags);
1939 if (adapter->cur_cmd) {
1940 allowed = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001941 lbs_deb_cmd("C");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001942 }
1943 if (adapter->intcounter > 0) {
1944 allowed = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001945 lbs_deb_cmd("I%d", adapter->intcounter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001946 }
1947 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1948
1949 if (allowed) {
Holger Schurig9012b282007-05-25 11:27:16 -04001950 lbs_deb_cmd("Sending libertas_ps_confirm_sleep\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001951 sendconfirmsleep(priv, (u8 *) & adapter->libertas_ps_confirm_sleep,
1952 sizeof(struct PS_CMD_ConfirmSleep));
1953 } else {
Holger Schurig9012b282007-05-25 11:27:16 -04001954 lbs_deb_cmd("Sleep Confirm has been delayed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001955 }
1956
Holger Schurig9012b282007-05-25 11:27:16 -04001957 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001958}