2 * This file contains the handling of command.
3 * It prepares command and sends it to firmware when it is ready.
6 #include <net/iw_handler.h>
15 static void cleanup_cmdnode(struct cmd_ctrl_node
*ptempnode
);
17 static u16 commands_allowed_in_ps
[] = {
22 * @brief This function checks if the commans is allowed
25 * @param command the command ID
26 * @return TRUE or FALSE
28 static u8
is_command_allowed_in_ps(__le16 command
)
32 for (i
= 0; i
< ARRAY_SIZE(commands_allowed_in_ps
); i
++) {
33 if (command
== cpu_to_le16(commands_allowed_in_ps
[i
]))
40 static int wlan_cmd_hw_spec(wlan_private
* priv
, struct cmd_ds_command
*cmd
)
42 struct cmd_ds_get_hw_spec
*hwspec
= &cmd
->params
.hwspec
;
44 lbs_deb_enter(LBS_DEB_CMD
);
46 cmd
->command
= cpu_to_le16(CMD_GET_HW_SPEC
);
47 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_get_hw_spec
) + S_DS_GEN
);
48 memcpy(hwspec
->permanentaddr
, priv
->adapter
->current_addr
, ETH_ALEN
);
50 lbs_deb_leave(LBS_DEB_CMD
);
54 static int wlan_cmd_802_11_ps_mode(wlan_private
* priv
,
55 struct cmd_ds_command
*cmd
,
58 struct cmd_ds_802_11_ps_mode
*psm
= &cmd
->params
.psmode
;
59 wlan_adapter
*adapter
= priv
->adapter
;
61 lbs_deb_enter(LBS_DEB_CMD
);
63 cmd
->command
= cpu_to_le16(CMD_802_11_PS_MODE
);
64 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode
) +
66 psm
->action
= cpu_to_le16(cmd_action
);
67 psm
->multipledtim
= 0;
69 case CMD_SUBCMD_ENTER_PS
:
70 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
71 lbs_deb_cmd("locallisteninterval %d\n",
72 adapter
->locallisteninterval
);
74 psm
->locallisteninterval
=
75 cpu_to_le16(adapter
->locallisteninterval
);
76 psm
->nullpktinterval
=
77 cpu_to_le16(adapter
->nullpktinterval
);
79 cpu_to_le16(priv
->adapter
->multipledtim
);
82 case CMD_SUBCMD_EXIT_PS
:
83 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
86 case CMD_SUBCMD_SLEEP_CONFIRMED
:
87 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
94 lbs_deb_leave(LBS_DEB_CMD
);
98 static int wlan_cmd_802_11_inactivity_timeout(wlan_private
* priv
,
99 struct cmd_ds_command
*cmd
,
100 u16 cmd_action
, void *pdata_buf
)
102 u16
*timeout
= pdata_buf
;
104 lbs_deb_enter(LBS_DEB_CMD
);
106 cmd
->command
= cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT
);
108 cpu_to_le16(sizeof(struct cmd_ds_802_11_inactivity_timeout
)
111 cmd
->params
.inactivity_timeout
.action
= cpu_to_le16(cmd_action
);
114 cmd
->params
.inactivity_timeout
.timeout
= cpu_to_le16(*timeout
);
116 cmd
->params
.inactivity_timeout
.timeout
= 0;
118 lbs_deb_leave(LBS_DEB_CMD
);
122 static int wlan_cmd_802_11_sleep_params(wlan_private
* priv
,
123 struct cmd_ds_command
*cmd
,
126 wlan_adapter
*adapter
= priv
->adapter
;
127 struct cmd_ds_802_11_sleep_params
*sp
= &cmd
->params
.sleep_params
;
129 lbs_deb_enter(LBS_DEB_CMD
);
131 cmd
->size
= cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params
)) +
133 cmd
->command
= cpu_to_le16(CMD_802_11_SLEEP_PARAMS
);
135 if (cmd_action
== CMD_ACT_GET
) {
136 memset(&adapter
->sp
, 0, sizeof(struct sleep_params
));
137 memset(sp
, 0, sizeof(struct cmd_ds_802_11_sleep_params
));
138 sp
->action
= cpu_to_le16(cmd_action
);
139 } else if (cmd_action
== CMD_ACT_SET
) {
140 sp
->action
= cpu_to_le16(cmd_action
);
141 sp
->error
= cpu_to_le16(adapter
->sp
.sp_error
);
142 sp
->offset
= cpu_to_le16(adapter
->sp
.sp_offset
);
143 sp
->stabletime
= cpu_to_le16(adapter
->sp
.sp_stabletime
);
144 sp
->calcontrol
= (u8
) adapter
->sp
.sp_calcontrol
;
145 sp
->externalsleepclk
= (u8
) adapter
->sp
.sp_extsleepclk
;
146 sp
->reserved
= cpu_to_le16(adapter
->sp
.sp_reserved
);
149 lbs_deb_leave(LBS_DEB_CMD
);
153 static int wlan_cmd_802_11_set_wep(wlan_private
* priv
,
154 struct cmd_ds_command
*cmd
,
158 struct cmd_ds_802_11_set_wep
*wep
= &cmd
->params
.wep
;
159 wlan_adapter
*adapter
= priv
->adapter
;
161 struct assoc_request
* assoc_req
= pdata_buf
;
163 lbs_deb_enter(LBS_DEB_CMD
);
165 cmd
->command
= cpu_to_le16(CMD_802_11_SET_WEP
);
166 cmd
->size
= cpu_to_le16(sizeof(*wep
) + S_DS_GEN
);
168 if (cmd_act
== CMD_ACT_ADD
) {
172 lbs_deb_cmd("Invalid association request!");
177 wep
->action
= cpu_to_le16(CMD_ACT_ADD
);
179 /* default tx key index */
180 wep
->keyindex
= cpu_to_le16((u16
)(assoc_req
->wep_tx_keyidx
&
181 (u32
)CMD_WEP_KEY_INDEX_MASK
));
183 /* Copy key types and material to host command structure */
184 for (i
= 0; i
< 4; i
++) {
185 struct enc_key
* pkey
= &assoc_req
->wep_keys
[i
];
190 cpu_to_le16(CMD_TYPE_WEP_40_BIT
);
191 memmove(&wep
->keymaterial
[i
], pkey
->key
,
193 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i
);
195 case KEY_LEN_WEP_104
:
197 cpu_to_le16(CMD_TYPE_WEP_104_BIT
);
198 memmove(&wep
->keymaterial
[i
], pkey
->key
,
200 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i
);
205 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
212 } else if (cmd_act
== CMD_ACT_REMOVE
) {
213 /* ACT_REMOVE clears _all_ WEP keys */
214 wep
->action
= cpu_to_le16(CMD_ACT_REMOVE
);
216 /* default tx key index */
217 wep
->keyindex
= cpu_to_le16((u16
)(adapter
->wep_tx_keyidx
&
218 (u32
)CMD_WEP_KEY_INDEX_MASK
));
219 lbs_deb_cmd("SET_WEP: remove key %d\n", adapter
->wep_tx_keyidx
);
225 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
229 static int wlan_cmd_802_11_enable_rsn(wlan_private
* priv
,
230 struct cmd_ds_command
*cmd
,
234 struct cmd_ds_802_11_enable_rsn
*penableRSN
= &cmd
->params
.enbrsn
;
235 u32
* enable
= pdata_buf
;
237 lbs_deb_enter(LBS_DEB_CMD
);
239 cmd
->command
= cpu_to_le16(CMD_802_11_ENABLE_RSN
);
240 cmd
->size
= cpu_to_le16(sizeof(*penableRSN
) + S_DS_GEN
);
241 penableRSN
->action
= cpu_to_le16(cmd_action
);
243 if (cmd_action
== CMD_ACT_SET
) {
245 penableRSN
->enable
= cpu_to_le16(CMD_ENABLE_RSN
);
247 penableRSN
->enable
= cpu_to_le16(CMD_DISABLE_RSN
);
248 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable
);
251 lbs_deb_leave(LBS_DEB_CMD
);
256 static void set_one_wpa_key(struct MrvlIEtype_keyParamSet
* pkeyparamset
,
257 struct enc_key
* pkey
)
259 lbs_deb_enter(LBS_DEB_CMD
);
261 if (pkey
->flags
& KEY_INFO_WPA_ENABLED
) {
262 pkeyparamset
->keyinfo
|= cpu_to_le16(KEY_INFO_WPA_ENABLED
);
264 if (pkey
->flags
& KEY_INFO_WPA_UNICAST
) {
265 pkeyparamset
->keyinfo
|= cpu_to_le16(KEY_INFO_WPA_UNICAST
);
267 if (pkey
->flags
& KEY_INFO_WPA_MCAST
) {
268 pkeyparamset
->keyinfo
|= cpu_to_le16(KEY_INFO_WPA_MCAST
);
271 pkeyparamset
->type
= cpu_to_le16(TLV_TYPE_KEY_MATERIAL
);
272 pkeyparamset
->keytypeid
= cpu_to_le16(pkey
->type
);
273 pkeyparamset
->keylen
= cpu_to_le16(pkey
->len
);
274 memcpy(pkeyparamset
->key
, pkey
->key
, pkey
->len
);
275 pkeyparamset
->length
= cpu_to_le16( sizeof(pkeyparamset
->keytypeid
)
276 + sizeof(pkeyparamset
->keyinfo
)
277 + sizeof(pkeyparamset
->keylen
)
278 + sizeof(pkeyparamset
->key
));
279 lbs_deb_leave(LBS_DEB_CMD
);
282 static int wlan_cmd_802_11_key_material(wlan_private
* priv
,
283 struct cmd_ds_command
*cmd
,
285 u32 cmd_oid
, void *pdata_buf
)
287 struct cmd_ds_802_11_key_material
*pkeymaterial
=
288 &cmd
->params
.keymaterial
;
289 struct assoc_request
* assoc_req
= pdata_buf
;
293 lbs_deb_enter(LBS_DEB_CMD
);
295 cmd
->command
= cpu_to_le16(CMD_802_11_KEY_MATERIAL
);
296 pkeymaterial
->action
= cpu_to_le16(cmd_action
);
298 if (cmd_action
== CMD_ACT_GET
) {
299 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof (pkeymaterial
->action
));
304 memset(&pkeymaterial
->keyParamSet
, 0, sizeof(pkeymaterial
->keyParamSet
));
306 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY
, &assoc_req
->flags
)) {
307 set_one_wpa_key(&pkeymaterial
->keyParamSet
[index
],
308 &assoc_req
->wpa_unicast_key
);
312 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY
, &assoc_req
->flags
)) {
313 set_one_wpa_key(&pkeymaterial
->keyParamSet
[index
],
314 &assoc_req
->wpa_mcast_key
);
318 cmd
->size
= cpu_to_le16( S_DS_GEN
319 + sizeof (pkeymaterial
->action
)
320 + (index
* sizeof(struct MrvlIEtype_keyParamSet
)));
325 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
329 static int wlan_cmd_802_11_reset(wlan_private
* priv
,
330 struct cmd_ds_command
*cmd
, int cmd_action
)
332 struct cmd_ds_802_11_reset
*reset
= &cmd
->params
.reset
;
334 lbs_deb_enter(LBS_DEB_CMD
);
336 cmd
->command
= cpu_to_le16(CMD_802_11_RESET
);
337 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_reset
) + S_DS_GEN
);
338 reset
->action
= cpu_to_le16(cmd_action
);
340 lbs_deb_leave(LBS_DEB_CMD
);
344 static int wlan_cmd_802_11_get_log(wlan_private
* priv
,
345 struct cmd_ds_command
*cmd
)
347 lbs_deb_enter(LBS_DEB_CMD
);
348 cmd
->command
= cpu_to_le16(CMD_802_11_GET_LOG
);
350 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_log
) + S_DS_GEN
);
352 lbs_deb_leave(LBS_DEB_CMD
);
356 static int wlan_cmd_802_11_get_stat(wlan_private
* priv
,
357 struct cmd_ds_command
*cmd
)
359 lbs_deb_enter(LBS_DEB_CMD
);
360 cmd
->command
= cpu_to_le16(CMD_802_11_GET_STAT
);
362 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat
) + S_DS_GEN
);
364 lbs_deb_leave(LBS_DEB_CMD
);
368 static int wlan_cmd_802_11_snmp_mib(wlan_private
* priv
,
369 struct cmd_ds_command
*cmd
,
371 int cmd_oid
, void *pdata_buf
)
373 struct cmd_ds_802_11_snmp_mib
*pSNMPMIB
= &cmd
->params
.smib
;
374 wlan_adapter
*adapter
= priv
->adapter
;
377 lbs_deb_enter(LBS_DEB_CMD
);
379 lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid
);
381 cmd
->command
= cpu_to_le16(CMD_802_11_SNMP_MIB
);
382 cmd
->size
= cpu_to_le16(sizeof(*pSNMPMIB
) + S_DS_GEN
);
385 case OID_802_11_INFRASTRUCTURE_MODE
:
387 u8 mode
= (u8
) (size_t) pdata_buf
;
388 pSNMPMIB
->querytype
= cpu_to_le16(CMD_ACT_SET
);
389 pSNMPMIB
->oid
= cpu_to_le16((u16
) DESIRED_BSSTYPE_I
);
390 pSNMPMIB
->bufsize
= sizeof(u8
);
391 if (mode
== IW_MODE_ADHOC
) {
392 ucTemp
= SNMP_MIB_VALUE_ADHOC
;
394 /* Infra and Auto modes */
395 ucTemp
= SNMP_MIB_VALUE_INFRA
;
398 memmove(pSNMPMIB
->value
, &ucTemp
, sizeof(u8
));
403 case OID_802_11D_ENABLE
:
407 pSNMPMIB
->oid
= cpu_to_le16((u16
) DOT11D_I
);
409 if (cmd_action
== CMD_ACT_SET
) {
410 pSNMPMIB
->querytype
= CMD_ACT_SET
;
411 pSNMPMIB
->bufsize
= sizeof(u16
);
412 ulTemp
= *(u32
*)pdata_buf
;
413 *((__le16
*)(pSNMPMIB
->value
)) =
414 cpu_to_le16((u16
) ulTemp
);
419 case OID_802_11_FRAGMENTATION_THRESHOLD
:
423 pSNMPMIB
->oid
= cpu_to_le16((u16
) FRAGTHRESH_I
);
425 if (cmd_action
== CMD_ACT_GET
) {
426 pSNMPMIB
->querytype
= cpu_to_le16(CMD_ACT_GET
);
427 } else if (cmd_action
== CMD_ACT_SET
) {
428 pSNMPMIB
->querytype
= cpu_to_le16(CMD_ACT_SET
);
429 pSNMPMIB
->bufsize
= cpu_to_le16(sizeof(u16
));
430 ulTemp
= *((u32
*) pdata_buf
);
431 *((__le16
*)(pSNMPMIB
->value
)) =
432 cpu_to_le16((u16
) ulTemp
);
439 case OID_802_11_RTS_THRESHOLD
:
443 pSNMPMIB
->oid
= le16_to_cpu((u16
) RTSTHRESH_I
);
445 if (cmd_action
== CMD_ACT_GET
) {
446 pSNMPMIB
->querytype
= cpu_to_le16(CMD_ACT_GET
);
447 } else if (cmd_action
== CMD_ACT_SET
) {
448 pSNMPMIB
->querytype
= cpu_to_le16(CMD_ACT_SET
);
449 pSNMPMIB
->bufsize
= cpu_to_le16(sizeof(u16
));
450 ulTemp
= *((u32
*)pdata_buf
);
451 *(__le16
*)(pSNMPMIB
->value
) =
452 cpu_to_le16((u16
) ulTemp
);
457 case OID_802_11_TX_RETRYCOUNT
:
458 pSNMPMIB
->oid
= cpu_to_le16((u16
) SHORT_RETRYLIM_I
);
460 if (cmd_action
== CMD_ACT_GET
) {
461 pSNMPMIB
->querytype
= cpu_to_le16(CMD_ACT_GET
);
462 } else if (cmd_action
== CMD_ACT_SET
) {
463 pSNMPMIB
->querytype
= cpu_to_le16(CMD_ACT_SET
);
464 pSNMPMIB
->bufsize
= cpu_to_le16(sizeof(u16
));
465 *((__le16
*)(pSNMPMIB
->value
)) =
466 cpu_to_le16((u16
) adapter
->txretrycount
);
475 "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
476 le16_to_cpu(cmd
->command
), le16_to_cpu(cmd
->size
),
477 le16_to_cpu(cmd
->seqnum
), le16_to_cpu(cmd
->result
));
480 "SNMP_CMD: action 0x%x, oid 0x%x, oidsize 0x%x, value 0x%x\n",
481 le16_to_cpu(pSNMPMIB
->querytype
), le16_to_cpu(pSNMPMIB
->oid
),
482 le16_to_cpu(pSNMPMIB
->bufsize
),
483 le16_to_cpu(*(__le16
*) pSNMPMIB
->value
));
485 lbs_deb_leave(LBS_DEB_CMD
);
489 static int wlan_cmd_802_11_radio_control(wlan_private
* priv
,
490 struct cmd_ds_command
*cmd
,
493 wlan_adapter
*adapter
= priv
->adapter
;
494 struct cmd_ds_802_11_radio_control
*pradiocontrol
= &cmd
->params
.radio
;
496 lbs_deb_enter(LBS_DEB_CMD
);
499 cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control
)) +
501 cmd
->command
= cpu_to_le16(CMD_802_11_RADIO_CONTROL
);
503 pradiocontrol
->action
= cpu_to_le16(cmd_action
);
505 switch (adapter
->preamble
) {
506 case CMD_TYPE_SHORT_PREAMBLE
:
507 pradiocontrol
->control
= cpu_to_le16(SET_SHORT_PREAMBLE
);
510 case CMD_TYPE_LONG_PREAMBLE
:
511 pradiocontrol
->control
= cpu_to_le16(SET_LONG_PREAMBLE
);
514 case CMD_TYPE_AUTO_PREAMBLE
:
516 pradiocontrol
->control
= cpu_to_le16(SET_AUTO_PREAMBLE
);
520 if (adapter
->radioon
)
521 pradiocontrol
->control
|= cpu_to_le16(TURN_ON_RF
);
523 pradiocontrol
->control
&= cpu_to_le16(~TURN_ON_RF
);
525 lbs_deb_leave(LBS_DEB_CMD
);
529 static int wlan_cmd_802_11_rf_tx_power(wlan_private
* priv
,
530 struct cmd_ds_command
*cmd
,
531 u16 cmd_action
, void *pdata_buf
)
534 struct cmd_ds_802_11_rf_tx_power
*prtp
= &cmd
->params
.txp
;
536 lbs_deb_enter(LBS_DEB_CMD
);
539 cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power
)) + S_DS_GEN
);
540 cmd
->command
= cpu_to_le16(CMD_802_11_RF_TX_POWER
);
541 prtp
->action
= cpu_to_le16(cmd_action
);
543 lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
544 le16_to_cpu(cmd
->size
), le16_to_cpu(cmd
->command
),
545 le16_to_cpu(prtp
->action
));
547 switch (cmd_action
) {
548 case CMD_ACT_TX_POWER_OPT_GET
:
549 prtp
->action
= cpu_to_le16(CMD_ACT_GET
);
550 prtp
->currentlevel
= 0;
553 case CMD_ACT_TX_POWER_OPT_SET_HIGH
:
554 prtp
->action
= cpu_to_le16(CMD_ACT_SET
);
555 prtp
->currentlevel
= cpu_to_le16(CMD_ACT_TX_POWER_INDEX_HIGH
);
558 case CMD_ACT_TX_POWER_OPT_SET_MID
:
559 prtp
->action
= cpu_to_le16(CMD_ACT_SET
);
560 prtp
->currentlevel
= cpu_to_le16(CMD_ACT_TX_POWER_INDEX_MID
);
563 case CMD_ACT_TX_POWER_OPT_SET_LOW
:
564 prtp
->action
= cpu_to_le16(CMD_ACT_SET
);
565 prtp
->currentlevel
= cpu_to_le16(*((u16
*) pdata_buf
));
569 lbs_deb_leave(LBS_DEB_CMD
);
573 static int wlan_cmd_802_11_rf_antenna(wlan_private
* priv
,
574 struct cmd_ds_command
*cmd
,
575 u16 cmd_action
, void *pdata_buf
)
577 struct cmd_ds_802_11_rf_antenna
*rant
= &cmd
->params
.rant
;
579 lbs_deb_enter(LBS_DEB_CMD
);
580 cmd
->command
= cpu_to_le16(CMD_802_11_RF_ANTENNA
);
581 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_antenna
) +
584 rant
->action
= cpu_to_le16(cmd_action
);
585 if ((cmd_action
== CMD_ACT_SET_RX
) || (cmd_action
== CMD_ACT_SET_TX
)) {
586 rant
->antennamode
= cpu_to_le16((u16
) (*(u32
*) pdata_buf
));
589 lbs_deb_leave(LBS_DEB_CMD
);
593 static int wlan_cmd_802_11_rate_adapt_rateset(wlan_private
* priv
,
594 struct cmd_ds_command
*cmd
,
597 struct cmd_ds_802_11_rate_adapt_rateset
598 *rateadapt
= &cmd
->params
.rateset
;
599 wlan_adapter
*adapter
= priv
->adapter
;
601 lbs_deb_enter(LBS_DEB_CMD
);
603 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset
)
605 cmd
->command
= cpu_to_le16(CMD_802_11_RATE_ADAPT_RATESET
);
607 rateadapt
->action
= cpu_to_le16(cmd_action
);
608 rateadapt
->enablehwauto
= cpu_to_le16(adapter
->enablehwauto
);
609 rateadapt
->bitmap
= cpu_to_le16(adapter
->ratebitmap
);
611 lbs_deb_leave(LBS_DEB_CMD
);
615 static int wlan_cmd_802_11_data_rate(wlan_private
* priv
,
616 struct cmd_ds_command
*cmd
,
619 struct cmd_ds_802_11_data_rate
*pdatarate
= &cmd
->params
.drate
;
620 wlan_adapter
*adapter
= priv
->adapter
;
622 lbs_deb_enter(LBS_DEB_CMD
);
624 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate
) +
626 cmd
->command
= cpu_to_le16(CMD_802_11_DATA_RATE
);
627 memset(pdatarate
, 0, sizeof(struct cmd_ds_802_11_data_rate
));
628 pdatarate
->action
= cpu_to_le16(cmd_action
);
630 if (cmd_action
== CMD_ACT_SET_TX_FIX_RATE
) {
631 pdatarate
->rates
[0] = libertas_data_rate_to_fw_index(adapter
->cur_rate
);
632 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n",
634 } else if (cmd_action
== CMD_ACT_SET_TX_AUTO
) {
635 lbs_deb_cmd("DATA_RATE: setting auto\n");
638 lbs_deb_leave(LBS_DEB_CMD
);
642 static int wlan_cmd_mac_multicast_adr(wlan_private
* priv
,
643 struct cmd_ds_command
*cmd
,
646 struct cmd_ds_mac_multicast_adr
*pMCastAdr
= &cmd
->params
.madr
;
647 wlan_adapter
*adapter
= priv
->adapter
;
649 lbs_deb_enter(LBS_DEB_CMD
);
650 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr
) +
652 cmd
->command
= cpu_to_le16(CMD_MAC_MULTICAST_ADR
);
654 lbs_deb_cmd("MULTICAST_ADR: setting %d addresses\n", pMCastAdr
->nr_of_adrs
);
655 pMCastAdr
->action
= cpu_to_le16(cmd_action
);
656 pMCastAdr
->nr_of_adrs
=
657 cpu_to_le16((u16
) adapter
->nr_of_multicastmacaddr
);
658 memcpy(pMCastAdr
->maclist
, adapter
->multicastlist
,
659 adapter
->nr_of_multicastmacaddr
* ETH_ALEN
);
661 lbs_deb_leave(LBS_DEB_CMD
);
665 static int wlan_cmd_802_11_rf_channel(wlan_private
* priv
,
666 struct cmd_ds_command
*cmd
,
667 int option
, void *pdata_buf
)
669 struct cmd_ds_802_11_rf_channel
*rfchan
= &cmd
->params
.rfchannel
;
671 lbs_deb_enter(LBS_DEB_CMD
);
672 cmd
->command
= cpu_to_le16(CMD_802_11_RF_CHANNEL
);
673 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel
) +
676 if (option
== CMD_OPT_802_11_RF_CHANNEL_SET
) {
677 rfchan
->currentchannel
= cpu_to_le16(*((u16
*) pdata_buf
));
680 rfchan
->action
= cpu_to_le16(option
);
682 lbs_deb_leave(LBS_DEB_CMD
);
686 static int wlan_cmd_802_11_rssi(wlan_private
* priv
,
687 struct cmd_ds_command
*cmd
)
689 wlan_adapter
*adapter
= priv
->adapter
;
691 lbs_deb_enter(LBS_DEB_CMD
);
692 cmd
->command
= cpu_to_le16(CMD_802_11_RSSI
);
693 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi
) + S_DS_GEN
);
694 cmd
->params
.rssi
.N
= cpu_to_le16(priv
->adapter
->bcn_avg_factor
);
696 /* reset Beacon SNR/NF/RSSI values */
697 adapter
->SNR
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
698 adapter
->SNR
[TYPE_BEACON
][TYPE_AVG
] = 0;
699 adapter
->NF
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
700 adapter
->NF
[TYPE_BEACON
][TYPE_AVG
] = 0;
701 adapter
->RSSI
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
702 adapter
->RSSI
[TYPE_BEACON
][TYPE_AVG
] = 0;
704 lbs_deb_leave(LBS_DEB_CMD
);
708 static int wlan_cmd_reg_access(wlan_private
* priv
,
709 struct cmd_ds_command
*cmdptr
,
710 u8 cmd_action
, void *pdata_buf
)
712 struct wlan_offset_value
*offval
;
714 lbs_deb_enter(LBS_DEB_CMD
);
716 offval
= (struct wlan_offset_value
*)pdata_buf
;
718 switch (cmdptr
->command
) {
719 case CMD_MAC_REG_ACCESS
:
721 struct cmd_ds_mac_reg_access
*macreg
;
724 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access
)
727 (struct cmd_ds_mac_reg_access
*)&cmdptr
->params
.
730 macreg
->action
= cpu_to_le16(cmd_action
);
731 macreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
732 macreg
->value
= cpu_to_le32(offval
->value
);
737 case CMD_BBP_REG_ACCESS
:
739 struct cmd_ds_bbp_reg_access
*bbpreg
;
743 (struct cmd_ds_bbp_reg_access
)
746 (struct cmd_ds_bbp_reg_access
*)&cmdptr
->params
.
749 bbpreg
->action
= cpu_to_le16(cmd_action
);
750 bbpreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
751 bbpreg
->value
= (u8
) offval
->value
;
756 case CMD_RF_REG_ACCESS
:
758 struct cmd_ds_rf_reg_access
*rfreg
;
762 (struct cmd_ds_rf_reg_access
) +
765 (struct cmd_ds_rf_reg_access
*)&cmdptr
->params
.
768 rfreg
->action
= cpu_to_le16(cmd_action
);
769 rfreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
770 rfreg
->value
= (u8
) offval
->value
;
779 lbs_deb_leave(LBS_DEB_CMD
);
783 static int wlan_cmd_802_11_mac_address(wlan_private
* priv
,
784 struct cmd_ds_command
*cmd
,
787 wlan_adapter
*adapter
= priv
->adapter
;
789 lbs_deb_enter(LBS_DEB_CMD
);
790 cmd
->command
= cpu_to_le16(CMD_802_11_MAC_ADDRESS
);
791 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address
) +
795 cmd
->params
.macadd
.action
= cpu_to_le16(cmd_action
);
797 if (cmd_action
== CMD_ACT_SET
) {
798 memcpy(cmd
->params
.macadd
.macadd
,
799 adapter
->current_addr
, ETH_ALEN
);
800 lbs_deb_hex(LBS_DEB_CMD
, "SET_CMD: MAC addr", adapter
->current_addr
, 6);
803 lbs_deb_leave(LBS_DEB_CMD
);
807 static int wlan_cmd_802_11_eeprom_access(wlan_private
* priv
,
808 struct cmd_ds_command
*cmd
,
809 int cmd_action
, void *pdata_buf
)
811 struct wlan_ioctl_regrdwr
*ea
= pdata_buf
;
813 lbs_deb_enter(LBS_DEB_CMD
);
815 cmd
->command
= cpu_to_le16(CMD_802_11_EEPROM_ACCESS
);
816 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access
) +
820 cmd
->params
.rdeeprom
.action
= cpu_to_le16(ea
->action
);
821 cmd
->params
.rdeeprom
.offset
= cpu_to_le16(ea
->offset
);
822 cmd
->params
.rdeeprom
.bytecount
= cpu_to_le16(ea
->NOB
);
823 cmd
->params
.rdeeprom
.value
= 0;
825 lbs_deb_leave(LBS_DEB_CMD
);
829 static int wlan_cmd_bt_access(wlan_private
* priv
,
830 struct cmd_ds_command
*cmd
,
831 u16 cmd_action
, void *pdata_buf
)
833 struct cmd_ds_bt_access
*bt_access
= &cmd
->params
.bt
;
834 lbs_deb_enter_args(LBS_DEB_CMD
, "action %d", cmd_action
);
836 cmd
->command
= cpu_to_le16(CMD_BT_ACCESS
);
837 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_bt_access
) + S_DS_GEN
);
839 bt_access
->action
= cpu_to_le16(cmd_action
);
841 switch (cmd_action
) {
842 case CMD_ACT_BT_ACCESS_ADD
:
843 memcpy(bt_access
->addr1
, pdata_buf
, 2 * ETH_ALEN
);
844 lbs_deb_hex(LBS_DEB_MESH
, "BT_ADD: blinded MAC addr", bt_access
->addr1
, 6);
846 case CMD_ACT_BT_ACCESS_DEL
:
847 memcpy(bt_access
->addr1
, pdata_buf
, 1 * ETH_ALEN
);
848 lbs_deb_hex(LBS_DEB_MESH
, "BT_DEL: blinded MAC addr", bt_access
->addr1
, 6);
850 case CMD_ACT_BT_ACCESS_LIST
:
851 bt_access
->id
= cpu_to_le32(*(u32
*) pdata_buf
);
853 case CMD_ACT_BT_ACCESS_RESET
:
855 case CMD_ACT_BT_ACCESS_SET_INVERT
:
856 bt_access
->id
= cpu_to_le32(*(u32
*) pdata_buf
);
858 case CMD_ACT_BT_ACCESS_GET_INVERT
:
863 lbs_deb_leave(LBS_DEB_CMD
);
867 static int wlan_cmd_fwt_access(wlan_private
* priv
,
868 struct cmd_ds_command
*cmd
,
869 u16 cmd_action
, void *pdata_buf
)
871 struct cmd_ds_fwt_access
*fwt_access
= &cmd
->params
.fwt
;
872 lbs_deb_enter_args(LBS_DEB_CMD
, "action %d", cmd_action
);
874 cmd
->command
= cpu_to_le16(CMD_FWT_ACCESS
);
875 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_fwt_access
) + S_DS_GEN
);
879 memcpy(fwt_access
, pdata_buf
, sizeof(*fwt_access
));
881 memset(fwt_access
, 0, sizeof(*fwt_access
));
883 fwt_access
->action
= cpu_to_le16(cmd_action
);
885 lbs_deb_leave(LBS_DEB_CMD
);
889 static int wlan_cmd_mesh_access(wlan_private
* priv
,
890 struct cmd_ds_command
*cmd
,
891 u16 cmd_action
, void *pdata_buf
)
893 struct cmd_ds_mesh_access
*mesh_access
= &cmd
->params
.mesh
;
894 lbs_deb_enter_args(LBS_DEB_CMD
, "action %d", cmd_action
);
896 cmd
->command
= cpu_to_le16(CMD_MESH_ACCESS
);
897 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_mesh_access
) + S_DS_GEN
);
901 memcpy(mesh_access
, pdata_buf
, sizeof(*mesh_access
));
903 memset(mesh_access
, 0, sizeof(*mesh_access
));
905 mesh_access
->action
= cpu_to_le16(cmd_action
);
907 lbs_deb_leave(LBS_DEB_CMD
);
911 void libertas_queue_cmd(wlan_adapter
* adapter
, struct cmd_ctrl_node
*cmdnode
, u8 addtail
)
914 struct cmd_ds_command
*cmdptr
;
916 lbs_deb_enter(LBS_DEB_HOST
);
919 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
923 cmdptr
= (struct cmd_ds_command
*)cmdnode
->bufvirtualaddr
;
925 lbs_deb_host("QUEUE_CMD: cmdptr is NULL\n");
929 /* Exit_PS command needs to be queued in the header always. */
930 if (cmdptr
->command
== CMD_802_11_PS_MODE
) {
931 struct cmd_ds_802_11_ps_mode
*psm
= &cmdptr
->params
.psmode
;
932 if (psm
->action
== cpu_to_le16(CMD_SUBCMD_EXIT_PS
)) {
933 if (adapter
->psstate
!= PS_STATE_FULL_POWER
)
938 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
941 list_add_tail((struct list_head
*)cmdnode
,
942 &adapter
->cmdpendingq
);
944 list_add((struct list_head
*)cmdnode
, &adapter
->cmdpendingq
);
946 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
948 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
949 le16_to_cpu(((struct cmd_ds_gen
*)cmdnode
->bufvirtualaddr
)->command
));
952 lbs_deb_leave(LBS_DEB_HOST
);
956 * TODO: Fix the issue when DownloadcommandToStation is being called the
957 * second time when the command times out. All the cmdptr->xxx are in little
958 * endian and therefore all the comparissions will fail.
959 * For now - we are not performing the endian conversion the second time - but
960 * for PS and DEEP_SLEEP we need to worry
962 static int DownloadcommandToStation(wlan_private
* priv
,
963 struct cmd_ctrl_node
*cmdnode
)
966 struct cmd_ds_command
*cmdptr
;
967 wlan_adapter
*adapter
= priv
->adapter
;
972 lbs_deb_enter(LBS_DEB_HOST
);
974 if (!adapter
|| !cmdnode
) {
975 lbs_deb_host("DNLD_CMD: adapter or cmdmode is NULL\n");
977 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
978 __libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
979 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
985 cmdptr
= (struct cmd_ds_command
*)cmdnode
->bufvirtualaddr
;
987 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
988 if (!cmdptr
|| !cmdptr
->size
) {
989 lbs_deb_host("DNLD_CMD: cmdptr is NULL or zero\n");
990 __libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
991 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
996 adapter
->cur_cmd
= cmdnode
;
997 adapter
->cur_cmd_retcode
= 0;
998 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1000 cmdsize
= cmdptr
->size
;
1001 command
= cpu_to_le16(cmdptr
->command
);
1003 lbs_deb_host("DNLD_CMD: command 0x%04x, size %d, jiffies %lu\n",
1004 command
, le16_to_cpu(cmdptr
->size
), jiffies
);
1005 lbs_deb_hex(LBS_DEB_HOST
, "DNLD_CMD", cmdnode
->bufvirtualaddr
, cmdsize
);
1007 cmdnode
->cmdwaitqwoken
= 0;
1008 cmdsize
= cpu_to_le16(cmdsize
);
1010 ret
= priv
->hw_host_to_card(priv
, MVMS_CMD
, (u8
*) cmdptr
, cmdsize
);
1013 lbs_deb_host("DNLD_CMD: hw_host_to_card failed\n");
1014 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1015 __libertas_cleanup_and_insert_cmd(priv
, adapter
->cur_cmd
);
1016 adapter
->cur_cmd
= NULL
;
1017 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1022 lbs_deb_cmd("DNLD_CMD: sent command 0x%04x, jiffies %lu\n", command
, jiffies
);
1024 /* Setup the timer after transmit command */
1025 if (command
== CMD_802_11_SCAN
|| command
== CMD_802_11_AUTHENTICATE
1026 || command
== CMD_802_11_ASSOCIATE
)
1027 mod_timer(&adapter
->command_timer
, jiffies
+ (10*HZ
));
1029 mod_timer(&adapter
->command_timer
, jiffies
+ (5*HZ
));
1034 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
1038 static int wlan_cmd_mac_control(wlan_private
* priv
,
1039 struct cmd_ds_command
*cmd
)
1041 struct cmd_ds_mac_control
*mac
= &cmd
->params
.macctrl
;
1043 lbs_deb_enter(LBS_DEB_CMD
);
1045 cmd
->command
= cpu_to_le16(CMD_MAC_CONTROL
);
1046 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_mac_control
) + S_DS_GEN
);
1047 mac
->action
= cpu_to_le16(priv
->adapter
->currentpacketfilter
);
1049 lbs_deb_cmd("MAC_CONTROL: action 0x%x, size %d\n",
1050 le16_to_cpu(mac
->action
), le16_to_cpu(cmd
->size
));
1052 lbs_deb_leave(LBS_DEB_CMD
);
1057 * This function inserts command node to cmdfreeq
1058 * after cleans it. Requires adapter->driver_lock held.
1060 void __libertas_cleanup_and_insert_cmd(wlan_private
* priv
, struct cmd_ctrl_node
*ptempcmd
)
1062 wlan_adapter
*adapter
= priv
->adapter
;
1067 cleanup_cmdnode(ptempcmd
);
1068 list_add_tail((struct list_head
*)ptempcmd
, &adapter
->cmdfreeq
);
1071 static void libertas_cleanup_and_insert_cmd(wlan_private
* priv
, struct cmd_ctrl_node
*ptempcmd
)
1073 unsigned long flags
;
1075 spin_lock_irqsave(&priv
->adapter
->driver_lock
, flags
);
1076 __libertas_cleanup_and_insert_cmd(priv
, ptempcmd
);
1077 spin_unlock_irqrestore(&priv
->adapter
->driver_lock
, flags
);
1080 int libertas_set_radio_control(wlan_private
* priv
)
1084 lbs_deb_enter(LBS_DEB_CMD
);
1086 ret
= libertas_prepare_and_send_command(priv
,
1087 CMD_802_11_RADIO_CONTROL
,
1089 CMD_OPTION_WAITFORRSP
, 0, NULL
);
1091 lbs_deb_cmd("RADIO_SET: radio %d, preamble %d\n",
1092 priv
->adapter
->radioon
, priv
->adapter
->preamble
);
1094 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
1098 int libertas_set_mac_packet_filter(wlan_private
* priv
)
1102 lbs_deb_enter(LBS_DEB_CMD
);
1104 /* Send MAC control command to station */
1105 ret
= libertas_prepare_and_send_command(priv
,
1106 CMD_MAC_CONTROL
, 0, 0, 0, NULL
);
1108 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
1113 * @brief This function prepare the command before send to firmware.
1115 * @param priv A pointer to wlan_private structure
1116 * @param cmd_no command number
1117 * @param cmd_action command action: GET or SET
1118 * @param wait_option wait option: wait response or not
1119 * @param cmd_oid cmd oid: treated as sub command
1120 * @param pdata_buf A pointer to informaion buffer
1123 int libertas_prepare_and_send_command(wlan_private
* priv
,
1126 u16 wait_option
, u32 cmd_oid
, void *pdata_buf
)
1129 wlan_adapter
*adapter
= priv
->adapter
;
1130 struct cmd_ctrl_node
*cmdnode
;
1131 struct cmd_ds_command
*cmdptr
;
1132 unsigned long flags
;
1134 lbs_deb_enter(LBS_DEB_HOST
);
1137 lbs_deb_host("PREP_CMD: adapter is NULL\n");
1142 if (adapter
->surpriseremoved
) {
1143 lbs_deb_host("PREP_CMD: card removed\n");
1148 cmdnode
= libertas_get_free_cmd_ctrl_node(priv
);
1150 if (cmdnode
== NULL
) {
1151 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1153 /* Wake up main thread to execute next command */
1154 wake_up_interruptible(&priv
->waitq
);
1159 libertas_set_cmd_ctrl_node(priv
, cmdnode
, cmd_oid
, wait_option
, pdata_buf
);
1161 cmdptr
= (struct cmd_ds_command
*)cmdnode
->bufvirtualaddr
;
1163 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no
);
1166 lbs_deb_host("PREP_CMD: cmdptr is NULL\n");
1167 libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
1172 /* Set sequence number, command and INT option */
1174 cmdptr
->seqnum
= cpu_to_le16(adapter
->seqnum
);
1176 cmdptr
->command
= cpu_to_le16(cmd_no
);
1180 case CMD_GET_HW_SPEC
:
1181 ret
= wlan_cmd_hw_spec(priv
, cmdptr
);
1183 case CMD_802_11_PS_MODE
:
1184 ret
= wlan_cmd_802_11_ps_mode(priv
, cmdptr
, cmd_action
);
1187 case CMD_802_11_SCAN
:
1188 ret
= libertas_cmd_80211_scan(priv
, cmdptr
, pdata_buf
);
1191 case CMD_MAC_CONTROL
:
1192 ret
= wlan_cmd_mac_control(priv
, cmdptr
);
1195 case CMD_802_11_ASSOCIATE
:
1196 case CMD_802_11_REASSOCIATE
:
1197 ret
= libertas_cmd_80211_associate(priv
, cmdptr
, pdata_buf
);
1200 case CMD_802_11_DEAUTHENTICATE
:
1201 ret
= libertas_cmd_80211_deauthenticate(priv
, cmdptr
);
1204 case CMD_802_11_SET_WEP
:
1205 ret
= wlan_cmd_802_11_set_wep(priv
, cmdptr
, cmd_action
, pdata_buf
);
1208 case CMD_802_11_AD_HOC_START
:
1209 ret
= libertas_cmd_80211_ad_hoc_start(priv
, cmdptr
, pdata_buf
);
1214 case CMD_802_11_RESET
:
1215 ret
= wlan_cmd_802_11_reset(priv
, cmdptr
, cmd_action
);
1218 case CMD_802_11_GET_LOG
:
1219 ret
= wlan_cmd_802_11_get_log(priv
, cmdptr
);
1222 case CMD_802_11_AUTHENTICATE
:
1223 ret
= libertas_cmd_80211_authenticate(priv
, cmdptr
, pdata_buf
);
1226 case CMD_802_11_GET_STAT
:
1227 ret
= wlan_cmd_802_11_get_stat(priv
, cmdptr
);
1230 case CMD_802_11_SNMP_MIB
:
1231 ret
= wlan_cmd_802_11_snmp_mib(priv
, cmdptr
,
1232 cmd_action
, cmd_oid
, pdata_buf
);
1235 case CMD_MAC_REG_ACCESS
:
1236 case CMD_BBP_REG_ACCESS
:
1237 case CMD_RF_REG_ACCESS
:
1238 ret
= wlan_cmd_reg_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1241 case CMD_802_11_RF_CHANNEL
:
1242 ret
= wlan_cmd_802_11_rf_channel(priv
, cmdptr
,
1243 cmd_action
, pdata_buf
);
1246 case CMD_802_11_RF_TX_POWER
:
1247 ret
= wlan_cmd_802_11_rf_tx_power(priv
, cmdptr
,
1248 cmd_action
, pdata_buf
);
1251 case CMD_802_11_RADIO_CONTROL
:
1252 ret
= wlan_cmd_802_11_radio_control(priv
, cmdptr
, cmd_action
);
1255 case CMD_802_11_RF_ANTENNA
:
1256 ret
= wlan_cmd_802_11_rf_antenna(priv
, cmdptr
,
1257 cmd_action
, pdata_buf
);
1260 case CMD_802_11_DATA_RATE
:
1261 ret
= wlan_cmd_802_11_data_rate(priv
, cmdptr
, cmd_action
);
1263 case CMD_802_11_RATE_ADAPT_RATESET
:
1264 ret
= wlan_cmd_802_11_rate_adapt_rateset(priv
,
1265 cmdptr
, cmd_action
);
1268 case CMD_MAC_MULTICAST_ADR
:
1269 ret
= wlan_cmd_mac_multicast_adr(priv
, cmdptr
, cmd_action
);
1272 case CMD_802_11_AD_HOC_JOIN
:
1273 ret
= libertas_cmd_80211_ad_hoc_join(priv
, cmdptr
, pdata_buf
);
1276 case CMD_802_11_RSSI
:
1277 ret
= wlan_cmd_802_11_rssi(priv
, cmdptr
);
1280 case CMD_802_11_AD_HOC_STOP
:
1281 ret
= libertas_cmd_80211_ad_hoc_stop(priv
, cmdptr
);
1284 case CMD_802_11_ENABLE_RSN
:
1285 ret
= wlan_cmd_802_11_enable_rsn(priv
, cmdptr
, cmd_action
,
1289 case CMD_802_11_KEY_MATERIAL
:
1290 ret
= wlan_cmd_802_11_key_material(priv
, cmdptr
, cmd_action
,
1291 cmd_oid
, pdata_buf
);
1294 case CMD_802_11_PAIRWISE_TSC
:
1296 case CMD_802_11_GROUP_TSC
:
1299 case CMD_802_11_MAC_ADDRESS
:
1300 ret
= wlan_cmd_802_11_mac_address(priv
, cmdptr
, cmd_action
);
1303 case CMD_802_11_EEPROM_ACCESS
:
1304 ret
= wlan_cmd_802_11_eeprom_access(priv
, cmdptr
,
1305 cmd_action
, pdata_buf
);
1308 case CMD_802_11_SET_AFC
:
1309 case CMD_802_11_GET_AFC
:
1311 cmdptr
->command
= cpu_to_le16(cmd_no
);
1312 cmdptr
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_afc
) +
1315 memmove(&cmdptr
->params
.afc
,
1316 pdata_buf
, sizeof(struct cmd_ds_802_11_afc
));
1321 case CMD_802_11D_DOMAIN_INFO
:
1322 ret
= libertas_cmd_802_11d_domain_info(priv
, cmdptr
,
1323 cmd_no
, cmd_action
);
1326 case CMD_802_11_SLEEP_PARAMS
:
1327 ret
= wlan_cmd_802_11_sleep_params(priv
, cmdptr
, cmd_action
);
1329 case CMD_802_11_INACTIVITY_TIMEOUT
:
1330 ret
= wlan_cmd_802_11_inactivity_timeout(priv
, cmdptr
,
1331 cmd_action
, pdata_buf
);
1332 libertas_set_cmd_ctrl_node(priv
, cmdnode
, 0, 0, pdata_buf
);
1335 case CMD_802_11_TPC_CFG
:
1336 cmdptr
->command
= cpu_to_le16(CMD_802_11_TPC_CFG
);
1338 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg
) +
1341 memmove(&cmdptr
->params
.tpccfg
,
1342 pdata_buf
, sizeof(struct cmd_ds_802_11_tpc_cfg
));
1346 case CMD_802_11_LED_GPIO_CTRL
:
1348 struct mrvlietypes_ledgpio
*gpio
=
1349 (struct mrvlietypes_ledgpio
*)
1350 cmdptr
->params
.ledgpio
.data
;
1352 memmove(&cmdptr
->params
.ledgpio
,
1354 sizeof(struct cmd_ds_802_11_led_ctrl
));
1357 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL
);
1359 #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1361 cpu_to_le16(gpio
->header
.len
+ S_DS_GEN
+
1362 ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN
);
1363 gpio
->header
.len
= cpu_to_le16(gpio
->header
.len
);
1368 case CMD_802_11_PWR_CFG
:
1369 cmdptr
->command
= cpu_to_le16(CMD_802_11_PWR_CFG
);
1371 cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg
) +
1373 memmove(&cmdptr
->params
.pwrcfg
, pdata_buf
,
1374 sizeof(struct cmd_ds_802_11_pwr_cfg
));
1379 ret
= wlan_cmd_bt_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1382 case CMD_FWT_ACCESS
:
1383 ret
= wlan_cmd_fwt_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1386 case CMD_MESH_ACCESS
:
1387 ret
= wlan_cmd_mesh_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1391 cmdptr
->command
= cpu_to_le16(CMD_GET_TSF
);
1392 cmdptr
->size
= cpu_to_le16(sizeof(struct cmd_ds_get_tsf
) +
1396 case CMD_802_11_TX_RATE_QUERY
:
1397 cmdptr
->command
= cpu_to_le16(CMD_802_11_TX_RATE_QUERY
);
1398 cmdptr
->size
= cpu_to_le16(sizeof(struct cmd_tx_rate_query
) +
1400 adapter
->txrate
= 0;
1404 lbs_deb_host("PREP_CMD: unknown command 0x%04x\n", cmd_no
);
1409 /* return error, since the command preparation failed */
1411 lbs_deb_host("PREP_CMD: command preparation failed\n");
1412 libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
1417 cmdnode
->cmdwaitqwoken
= 0;
1419 libertas_queue_cmd(adapter
, cmdnode
, 1);
1420 adapter
->nr_cmd_pending
++;
1421 wake_up_interruptible(&priv
->waitq
);
1423 if (wait_option
& CMD_OPTION_WAITFORRSP
) {
1424 lbs_deb_host("PREP_CMD: wait for response\n");
1426 wait_event_interruptible(cmdnode
->cmdwait_q
,
1427 cmdnode
->cmdwaitqwoken
);
1430 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1431 if (adapter
->cur_cmd_retcode
) {
1432 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
1433 adapter
->cur_cmd_retcode
);
1434 adapter
->cur_cmd_retcode
= 0;
1437 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1440 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
1443 EXPORT_SYMBOL_GPL(libertas_prepare_and_send_command
);
1446 * @brief This function allocates the command buffer and link
1447 * it to command free queue.
1449 * @param priv A pointer to wlan_private structure
1452 int libertas_allocate_cmd_buffer(wlan_private
* priv
)
1457 struct cmd_ctrl_node
*tempcmd_array
;
1458 u8
*ptempvirtualaddr
;
1459 wlan_adapter
*adapter
= priv
->adapter
;
1461 lbs_deb_enter(LBS_DEB_HOST
);
1463 /* Allocate and initialize cmdCtrlNode */
1464 ulbufsize
= sizeof(struct cmd_ctrl_node
) * MRVDRV_NUM_OF_CMD_BUFFER
;
1466 if (!(tempcmd_array
= kzalloc(ulbufsize
, GFP_KERNEL
))) {
1467 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
1471 adapter
->cmd_array
= tempcmd_array
;
1473 /* Allocate and initialize command buffers */
1474 ulbufsize
= MRVDRV_SIZE_OF_CMD_BUFFER
;
1475 for (i
= 0; i
< MRVDRV_NUM_OF_CMD_BUFFER
; i
++) {
1476 if (!(ptempvirtualaddr
= kzalloc(ulbufsize
, GFP_KERNEL
))) {
1477 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
1482 /* Update command buffer virtual */
1483 tempcmd_array
[i
].bufvirtualaddr
= ptempvirtualaddr
;
1486 for (i
= 0; i
< MRVDRV_NUM_OF_CMD_BUFFER
; i
++) {
1487 init_waitqueue_head(&tempcmd_array
[i
].cmdwait_q
);
1488 libertas_cleanup_and_insert_cmd(priv
, &tempcmd_array
[i
]);
1494 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
1499 * @brief This function frees the command buffer.
1501 * @param priv A pointer to wlan_private structure
1504 int libertas_free_cmd_buffer(wlan_private
* priv
)
1506 u32 ulbufsize
; /* Someone needs to die for this. Slowly and painfully */
1508 struct cmd_ctrl_node
*tempcmd_array
;
1509 wlan_adapter
*adapter
= priv
->adapter
;
1511 lbs_deb_enter(LBS_DEB_HOST
);
1513 /* need to check if cmd array is allocated or not */
1514 if (adapter
->cmd_array
== NULL
) {
1515 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
1519 tempcmd_array
= adapter
->cmd_array
;
1521 /* Release shared memory buffers */
1522 ulbufsize
= MRVDRV_SIZE_OF_CMD_BUFFER
;
1523 for (i
= 0; i
< MRVDRV_NUM_OF_CMD_BUFFER
; i
++) {
1524 if (tempcmd_array
[i
].bufvirtualaddr
) {
1525 kfree(tempcmd_array
[i
].bufvirtualaddr
);
1526 tempcmd_array
[i
].bufvirtualaddr
= NULL
;
1530 /* Release cmd_ctrl_node */
1531 if (adapter
->cmd_array
) {
1532 kfree(adapter
->cmd_array
);
1533 adapter
->cmd_array
= NULL
;
1537 lbs_deb_leave(LBS_DEB_HOST
);
1542 * @brief This function gets a free command node if available in
1543 * command free queue.
1545 * @param priv A pointer to wlan_private structure
1546 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1548 struct cmd_ctrl_node
*libertas_get_free_cmd_ctrl_node(wlan_private
* priv
)
1550 struct cmd_ctrl_node
*tempnode
;
1551 wlan_adapter
*adapter
= priv
->adapter
;
1552 unsigned long flags
;
1554 lbs_deb_enter(LBS_DEB_HOST
);
1559 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1561 if (!list_empty(&adapter
->cmdfreeq
)) {
1562 tempnode
= (struct cmd_ctrl_node
*)adapter
->cmdfreeq
.next
;
1563 list_del((struct list_head
*)tempnode
);
1565 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1569 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1572 cleanup_cmdnode(tempnode
);
1574 lbs_deb_leave(LBS_DEB_HOST
);
1579 * @brief This function cleans command node.
1581 * @param ptempnode A pointer to cmdCtrlNode structure
1584 static void cleanup_cmdnode(struct cmd_ctrl_node
*ptempnode
)
1586 lbs_deb_enter(LBS_DEB_HOST
);
1590 ptempnode
->cmdwaitqwoken
= 1;
1591 wake_up_interruptible(&ptempnode
->cmdwait_q
);
1592 ptempnode
->status
= 0;
1593 ptempnode
->cmd_oid
= (u32
) 0;
1594 ptempnode
->wait_option
= 0;
1595 ptempnode
->pdata_buf
= NULL
;
1597 if (ptempnode
->bufvirtualaddr
!= NULL
)
1598 memset(ptempnode
->bufvirtualaddr
, 0, MRVDRV_SIZE_OF_CMD_BUFFER
);
1600 lbs_deb_leave(LBS_DEB_HOST
);
1604 * @brief This function initializes the command node.
1606 * @param priv A pointer to wlan_private structure
1607 * @param ptempnode A pointer to cmd_ctrl_node structure
1608 * @param cmd_oid cmd oid: treated as sub command
1609 * @param wait_option wait option: wait response or not
1610 * @param pdata_buf A pointer to informaion buffer
1613 void libertas_set_cmd_ctrl_node(wlan_private
* priv
,
1614 struct cmd_ctrl_node
*ptempnode
,
1615 u32 cmd_oid
, u16 wait_option
, void *pdata_buf
)
1617 lbs_deb_enter(LBS_DEB_HOST
);
1622 ptempnode
->cmd_oid
= cmd_oid
;
1623 ptempnode
->wait_option
= wait_option
;
1624 ptempnode
->pdata_buf
= pdata_buf
;
1626 lbs_deb_leave(LBS_DEB_HOST
);
1630 * @brief This function executes next command in command
1631 * pending queue. It will put fimware back to PS mode
1634 * @param priv A pointer to wlan_private structure
1637 int libertas_execute_next_command(wlan_private
* priv
)
1639 wlan_adapter
*adapter
= priv
->adapter
;
1640 struct cmd_ctrl_node
*cmdnode
= NULL
;
1641 struct cmd_ds_command
*cmdptr
;
1642 unsigned long flags
;
1645 // Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1646 // only caller to us is libertas_thread() and we get even when a
1647 // data packet is received
1648 lbs_deb_enter(LBS_DEB_THREAD
);
1650 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1652 if (adapter
->cur_cmd
) {
1653 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
1654 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1659 if (!list_empty(&adapter
->cmdpendingq
)) {
1660 cmdnode
= (struct cmd_ctrl_node
*)
1661 adapter
->cmdpendingq
.next
;
1664 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1667 cmdptr
= (struct cmd_ds_command
*)cmdnode
->bufvirtualaddr
;
1669 if (is_command_allowed_in_ps(cmdptr
->command
)) {
1670 if ((adapter
->psstate
== PS_STATE_SLEEP
) ||
1671 (adapter
->psstate
== PS_STATE_PRE_SLEEP
)) {
1673 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
1674 le16_to_cpu(cmdptr
->command
),
1679 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
1680 "0x%04x in psstate %d\n",
1681 le16_to_cpu(cmdptr
->command
),
1683 } else if (adapter
->psstate
!= PS_STATE_FULL_POWER
) {
1685 * 1. Non-PS command:
1686 * Queue it. set needtowakeup to TRUE if current state
1687 * is SLEEP, otherwise call libertas_ps_wakeup to send Exit_PS.
1688 * 2. PS command but not Exit_PS:
1690 * 3. PS command Exit_PS:
1691 * Set needtowakeup to TRUE if current state is SLEEP,
1692 * otherwise send this command down to firmware
1695 if (cmdptr
->command
!=
1696 cpu_to_le16(CMD_802_11_PS_MODE
)) {
1697 /* Prepare to send Exit PS,
1698 * this non PS command will be sent later */
1699 if ((adapter
->psstate
== PS_STATE_SLEEP
)
1700 || (adapter
->psstate
== PS_STATE_PRE_SLEEP
)
1702 /* w/ new scheme, it will not reach here.
1703 since it is blocked in main_thread. */
1704 adapter
->needtowakeup
= 1;
1706 libertas_ps_wakeup(priv
, 0);
1712 * PS command. Ignore it if it is not Exit_PS.
1713 * otherwise send it down immediately.
1715 struct cmd_ds_802_11_ps_mode
*psm
=
1716 &cmdptr
->params
.psmode
;
1719 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
1722 cpu_to_le16(CMD_SUBCMD_EXIT_PS
)) {
1724 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
1725 list_del((struct list_head
*)cmdnode
);
1726 libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
1732 if ((adapter
->psstate
== PS_STATE_SLEEP
) ||
1733 (adapter
->psstate
== PS_STATE_PRE_SLEEP
)) {
1735 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
1736 list_del((struct list_head
*)cmdnode
);
1737 libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
1738 adapter
->needtowakeup
= 1;
1745 "EXEC_NEXT_CMD: sending EXIT_PS\n");
1748 list_del((struct list_head
*)cmdnode
);
1749 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
1750 le16_to_cpu(cmdptr
->command
));
1751 DownloadcommandToStation(priv
, cmdnode
);
1754 * check if in power save mode, if yes, put the device back
1757 if ((adapter
->psmode
!= WLAN802_11POWERMODECAM
) &&
1758 (adapter
->psstate
== PS_STATE_FULL_POWER
) &&
1759 (adapter
->connect_status
== LIBERTAS_CONNECTED
)) {
1760 if (adapter
->secinfo
.WPAenabled
||
1761 adapter
->secinfo
.WPA2enabled
) {
1762 /* check for valid WPA group keys */
1763 if (adapter
->wpa_mcast_key
.len
||
1764 adapter
->wpa_unicast_key
.len
) {
1766 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1767 " go back to PS_SLEEP");
1768 libertas_ps_sleep(priv
, 0);
1772 "EXEC_NEXT_CMD: cmdpendingq empty, "
1773 "go back to PS_SLEEP");
1774 libertas_ps_sleep(priv
, 0);
1781 lbs_deb_leave(LBS_DEB_THREAD
);
1785 void libertas_send_iwevcustom_event(wlan_private
* priv
, s8
* str
)
1787 union iwreq_data iwrq
;
1790 lbs_deb_enter(LBS_DEB_WEXT
);
1792 memset(&iwrq
, 0, sizeof(union iwreq_data
));
1793 memset(buf
, 0, sizeof(buf
));
1795 snprintf(buf
, sizeof(buf
) - 1, "%s", str
);
1797 iwrq
.data
.length
= strlen(buf
) + 1 + IW_EV_LCP_LEN
;
1799 /* Send Event to upper layer */
1800 lbs_deb_wext("event indication string %s\n", (char *)buf
);
1801 lbs_deb_wext("event indication length %d\n", iwrq
.data
.length
);
1802 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str
);
1804 wireless_send_event(priv
->dev
, IWEVCUSTOM
, &iwrq
, buf
);
1806 lbs_deb_leave(LBS_DEB_WEXT
);
1809 static int sendconfirmsleep(wlan_private
* priv
, u8
* cmdptr
, u16 size
)
1811 unsigned long flags
;
1812 wlan_adapter
*adapter
= priv
->adapter
;
1815 lbs_deb_enter(LBS_DEB_HOST
);
1817 lbs_deb_host("SEND_SLEEPC_CMD: before download, cmd size %d\n",
1820 lbs_deb_hex(LBS_DEB_HOST
, "sleep confirm command", cmdptr
, size
);
1822 ret
= priv
->hw_host_to_card(priv
, MVMS_CMD
, cmdptr
, size
);
1823 priv
->dnld_sent
= DNLD_RES_RECEIVED
;
1825 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1826 if (adapter
->intcounter
|| adapter
->currenttxskb
)
1827 lbs_deb_host("SEND_SLEEPC_CMD: intcounter %d, currenttxskb %p\n",
1828 adapter
->intcounter
, adapter
->currenttxskb
);
1829 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1833 "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
1835 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1836 if (!adapter
->intcounter
) {
1837 adapter
->psstate
= PS_STATE_SLEEP
;
1839 lbs_deb_host("SEND_SLEEPC_CMD: after sent, intcounter %d\n",
1840 adapter
->intcounter
);
1842 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1844 lbs_deb_host("SEND_SLEEPC_CMD: sent confirm sleep\n");
1847 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
1851 void libertas_ps_sleep(wlan_private
* priv
, int wait_option
)
1853 lbs_deb_enter(LBS_DEB_HOST
);
1856 * PS is currently supported only in Infrastructure mode
1857 * Remove this check if it is to be supported in IBSS mode also
1860 libertas_prepare_and_send_command(priv
, CMD_802_11_PS_MODE
,
1861 CMD_SUBCMD_ENTER_PS
, wait_option
, 0, NULL
);
1863 lbs_deb_leave(LBS_DEB_HOST
);
1867 * @brief This function sends Exit_PS command to firmware.
1869 * @param priv A pointer to wlan_private structure
1870 * @param wait_option wait response or not
1873 void libertas_ps_wakeup(wlan_private
* priv
, int wait_option
)
1877 lbs_deb_enter(LBS_DEB_HOST
);
1879 Localpsmode
= cpu_to_le32(WLAN802_11POWERMODECAM
);
1881 libertas_prepare_and_send_command(priv
, CMD_802_11_PS_MODE
,
1883 wait_option
, 0, &Localpsmode
);
1885 lbs_deb_leave(LBS_DEB_HOST
);
1889 * @brief This function checks condition and prepares to
1890 * send sleep confirm command to firmware if ok.
1892 * @param priv A pointer to wlan_private structure
1893 * @param psmode Power Saving mode
1896 void libertas_ps_confirm_sleep(wlan_private
* priv
, u16 psmode
)
1898 unsigned long flags
=0;
1899 wlan_adapter
*adapter
= priv
->adapter
;
1902 lbs_deb_enter(LBS_DEB_HOST
);
1904 if (priv
->dnld_sent
) {
1906 lbs_deb_host("dnld_sent was set");
1909 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1910 if (adapter
->cur_cmd
) {
1912 lbs_deb_host("cur_cmd was set");
1914 if (adapter
->intcounter
> 0) {
1916 lbs_deb_host("intcounter %d", adapter
->intcounter
);
1918 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1921 lbs_deb_host("sending libertas_ps_confirm_sleep\n");
1922 sendconfirmsleep(priv
, (u8
*) & adapter
->libertas_ps_confirm_sleep
,
1923 sizeof(struct PS_CMD_ConfirmSleep
));
1925 lbs_deb_host("sleep confirm has been delayed\n");
1928 lbs_deb_leave(LBS_DEB_HOST
);