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 cmd
->command
= cpu_to_le16(cmd_802_11_inactivity_timeout
);
106 cpu_to_le16(sizeof(struct cmd_ds_802_11_inactivity_timeout
)
109 cmd
->params
.inactivity_timeout
.action
= cpu_to_le16(cmd_action
);
112 cmd
->params
.inactivity_timeout
.timeout
= cpu_to_le16(*timeout
);
114 cmd
->params
.inactivity_timeout
.timeout
= 0;
119 static int wlan_cmd_802_11_sleep_params(wlan_private
* priv
,
120 struct cmd_ds_command
*cmd
,
123 wlan_adapter
*adapter
= priv
->adapter
;
124 struct cmd_ds_802_11_sleep_params
*sp
= &cmd
->params
.sleep_params
;
126 lbs_deb_enter(LBS_DEB_CMD
);
128 cmd
->size
= cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params
)) +
130 cmd
->command
= cpu_to_le16(cmd_802_11_sleep_params
);
132 if (cmd_action
== cmd_act_get
) {
133 memset(&adapter
->sp
, 0, sizeof(struct sleep_params
));
134 memset(sp
, 0, sizeof(struct cmd_ds_802_11_sleep_params
));
135 sp
->action
= cpu_to_le16(cmd_action
);
136 } else if (cmd_action
== cmd_act_set
) {
137 sp
->action
= cpu_to_le16(cmd_action
);
138 sp
->error
= cpu_to_le16(adapter
->sp
.sp_error
);
139 sp
->offset
= cpu_to_le16(adapter
->sp
.sp_offset
);
140 sp
->stabletime
= cpu_to_le16(adapter
->sp
.sp_stabletime
);
141 sp
->calcontrol
= (u8
) adapter
->sp
.sp_calcontrol
;
142 sp
->externalsleepclk
= (u8
) adapter
->sp
.sp_extsleepclk
;
143 sp
->reserved
= cpu_to_le16(adapter
->sp
.sp_reserved
);
146 lbs_deb_leave(LBS_DEB_CMD
);
150 static int wlan_cmd_802_11_set_wep(wlan_private
* priv
,
151 struct cmd_ds_command
*cmd
,
155 struct cmd_ds_802_11_set_wep
*wep
= &cmd
->params
.wep
;
156 wlan_adapter
*adapter
= priv
->adapter
;
158 struct assoc_request
* assoc_req
= pdata_buf
;
160 lbs_deb_enter(LBS_DEB_CMD
);
162 cmd
->command
= cpu_to_le16(cmd_802_11_set_wep
);
163 cmd
->size
= cpu_to_le16(sizeof(*wep
) + S_DS_GEN
);
165 if (cmd_act
== cmd_act_add
) {
169 lbs_deb_cmd("Invalid association request!");
174 wep
->action
= cpu_to_le16(cmd_act_add
);
176 /* default tx key index */
177 wep
->keyindex
= cpu_to_le16((u16
)(assoc_req
->wep_tx_keyidx
&
178 (u32
)cmd_WEP_KEY_INDEX_MASK
));
180 lbs_deb_cmd("Tx key Index: %u\n", le16_to_cpu(wep
->keyindex
));
182 /* Copy key types and material to host command structure */
183 for (i
= 0; i
< 4; i
++) {
184 struct WLAN_802_11_KEY
* pkey
= &assoc_req
->wep_keys
[i
];
189 cpu_to_le16(cmd_type_wep_40_bit
);
190 memmove(&wep
->keymaterial
[i
], pkey
->key
,
193 case KEY_LEN_WEP_104
:
195 cpu_to_le16(cmd_type_wep_104_bit
);
196 memmove(&wep
->keymaterial
[i
], pkey
->key
,
202 lbs_deb_cmd("Invalid WEP key %d length of %d\n",
209 } else if (cmd_act
== cmd_act_remove
) {
210 /* ACT_REMOVE clears _all_ WEP keys */
211 wep
->action
= cpu_to_le16(cmd_act_remove
);
213 /* default tx key index */
214 wep
->keyindex
= cpu_to_le16((u16
)(adapter
->wep_tx_keyidx
&
215 (u32
)cmd_WEP_KEY_INDEX_MASK
));
221 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
225 static int wlan_cmd_802_11_enable_rsn(wlan_private
* priv
,
226 struct cmd_ds_command
*cmd
,
230 struct cmd_ds_802_11_enable_rsn
*penableRSN
= &cmd
->params
.enbrsn
;
231 struct assoc_request
* assoc_req
= pdata_buf
;
233 lbs_deb_enter(LBS_DEB_CMD
);
235 cmd
->command
= cpu_to_le16(cmd_802_11_enable_rsn
);
236 cmd
->size
= cpu_to_le16(sizeof(*penableRSN
) + S_DS_GEN
);
237 penableRSN
->action
= cpu_to_le16(cmd_action
);
238 if (assoc_req
->secinfo
.WPAenabled
|| assoc_req
->secinfo
.WPA2enabled
) {
239 penableRSN
->enable
= cpu_to_le16(cmd_enable_rsn
);
241 penableRSN
->enable
= cpu_to_le16(cmd_disable_rsn
);
244 lbs_deb_leave(LBS_DEB_CMD
);
249 static void set_one_wpa_key(struct MrvlIEtype_keyParamSet
* pkeyparamset
,
250 struct WLAN_802_11_KEY
* pkey
)
252 pkeyparamset
->keytypeid
= cpu_to_le16(pkey
->type
);
254 if (pkey
->flags
& KEY_INFO_WPA_ENABLED
) {
255 pkeyparamset
->keyinfo
|= cpu_to_le16(KEY_INFO_WPA_ENABLED
);
257 if (pkey
->flags
& KEY_INFO_WPA_UNICAST
) {
258 pkeyparamset
->keyinfo
|= cpu_to_le16(KEY_INFO_WPA_UNICAST
);
260 if (pkey
->flags
& KEY_INFO_WPA_MCAST
) {
261 pkeyparamset
->keyinfo
|= cpu_to_le16(KEY_INFO_WPA_MCAST
);
264 pkeyparamset
->type
= cpu_to_le16(TLV_TYPE_KEY_MATERIAL
);
265 pkeyparamset
->keylen
= cpu_to_le16(pkey
->len
);
266 memcpy(pkeyparamset
->key
, pkey
->key
, pkey
->len
);
267 pkeyparamset
->length
= cpu_to_le16( sizeof(pkeyparamset
->keytypeid
)
268 + sizeof(pkeyparamset
->keyinfo
)
269 + sizeof(pkeyparamset
->keylen
)
270 + sizeof(pkeyparamset
->key
));
273 static int wlan_cmd_802_11_key_material(wlan_private
* priv
,
274 struct cmd_ds_command
*cmd
,
276 u32 cmd_oid
, void *pdata_buf
)
278 struct cmd_ds_802_11_key_material
*pkeymaterial
=
279 &cmd
->params
.keymaterial
;
280 struct assoc_request
* assoc_req
= pdata_buf
;
284 lbs_deb_enter(LBS_DEB_CMD
);
286 cmd
->command
= cpu_to_le16(cmd_802_11_key_material
);
287 pkeymaterial
->action
= cpu_to_le16(cmd_action
);
289 if (cmd_action
== cmd_act_get
) {
290 cmd
->size
= cpu_to_le16(S_DS_GEN
+ sizeof (pkeymaterial
->action
));
295 memset(&pkeymaterial
->keyParamSet
, 0, sizeof(pkeymaterial
->keyParamSet
));
297 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY
, &assoc_req
->flags
)) {
298 set_one_wpa_key(&pkeymaterial
->keyParamSet
[index
],
299 &assoc_req
->wpa_unicast_key
);
303 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY
, &assoc_req
->flags
)) {
304 set_one_wpa_key(&pkeymaterial
->keyParamSet
[index
],
305 &assoc_req
->wpa_mcast_key
);
309 cmd
->size
= cpu_to_le16( S_DS_GEN
310 + sizeof (pkeymaterial
->action
)
311 + (index
* sizeof(struct MrvlIEtype_keyParamSet
)));
316 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
320 static int wlan_cmd_802_11_reset(wlan_private
* priv
,
321 struct cmd_ds_command
*cmd
, int cmd_action
)
323 struct cmd_ds_802_11_reset
*reset
= &cmd
->params
.reset
;
325 cmd
->command
= cpu_to_le16(cmd_802_11_reset
);
326 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_reset
) + S_DS_GEN
);
327 reset
->action
= cpu_to_le16(cmd_action
);
332 static int wlan_cmd_802_11_get_log(wlan_private
* priv
,
333 struct cmd_ds_command
*cmd
)
335 cmd
->command
= cpu_to_le16(cmd_802_11_get_log
);
337 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_log
) + S_DS_GEN
);
342 static int wlan_cmd_802_11_get_stat(wlan_private
* priv
,
343 struct cmd_ds_command
*cmd
)
345 cmd
->command
= cpu_to_le16(cmd_802_11_get_stat
);
347 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat
) + S_DS_GEN
);
352 static int wlan_cmd_802_11_snmp_mib(wlan_private
* priv
,
353 struct cmd_ds_command
*cmd
,
355 int cmd_oid
, void *pdata_buf
)
357 struct cmd_ds_802_11_snmp_mib
*pSNMPMIB
= &cmd
->params
.smib
;
358 wlan_adapter
*adapter
= priv
->adapter
;
361 lbs_deb_enter(LBS_DEB_CMD
);
363 lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid
);
365 cmd
->command
= cpu_to_le16(cmd_802_11_snmp_mib
);
366 cmd
->size
= cpu_to_le16(sizeof(*pSNMPMIB
) + S_DS_GEN
);
369 case OID_802_11_INFRASTRUCTURE_MODE
:
371 u8 mode
= (u8
) (size_t) pdata_buf
;
372 pSNMPMIB
->querytype
= cpu_to_le16(cmd_act_set
);
373 pSNMPMIB
->oid
= cpu_to_le16((u16
) desired_bsstype_i
);
374 pSNMPMIB
->bufsize
= sizeof(u8
);
375 if (mode
== IW_MODE_ADHOC
) {
376 ucTemp
= SNMP_MIB_VALUE_ADHOC
;
378 /* Infra and Auto modes */
379 ucTemp
= SNMP_MIB_VALUE_INFRA
;
382 memmove(pSNMPMIB
->value
, &ucTemp
, sizeof(u8
));
387 case OID_802_11D_ENABLE
:
391 pSNMPMIB
->oid
= cpu_to_le16((u16
) dot11d_i
);
393 if (cmd_action
== cmd_act_set
) {
394 pSNMPMIB
->querytype
= cmd_act_set
;
395 pSNMPMIB
->bufsize
= sizeof(u16
);
396 ulTemp
= *(u32
*)pdata_buf
;
397 *((__le16
*)(pSNMPMIB
->value
)) =
398 cpu_to_le16((u16
) ulTemp
);
403 case OID_802_11_FRAGMENTATION_THRESHOLD
:
407 pSNMPMIB
->oid
= cpu_to_le16((u16
) fragthresh_i
);
409 if (cmd_action
== cmd_act_get
) {
410 pSNMPMIB
->querytype
= cpu_to_le16(cmd_act_get
);
411 } else if (cmd_action
== cmd_act_set
) {
412 pSNMPMIB
->querytype
= cpu_to_le16(cmd_act_set
);
413 pSNMPMIB
->bufsize
= cpu_to_le16(sizeof(u16
));
414 ulTemp
= *((u32
*) pdata_buf
);
415 *((__le16
*)(pSNMPMIB
->value
)) =
416 cpu_to_le16((u16
) ulTemp
);
423 case OID_802_11_RTS_THRESHOLD
:
427 pSNMPMIB
->oid
= le16_to_cpu((u16
) rtsthresh_i
);
429 if (cmd_action
== cmd_act_get
) {
430 pSNMPMIB
->querytype
= cpu_to_le16(cmd_act_get
);
431 } else if (cmd_action
== cmd_act_set
) {
432 pSNMPMIB
->querytype
= cpu_to_le16(cmd_act_set
);
433 pSNMPMIB
->bufsize
= cpu_to_le16(sizeof(u16
));
434 ulTemp
= *((u32
*)pdata_buf
);
435 *(__le16
*)(pSNMPMIB
->value
) =
436 cpu_to_le16((u16
) ulTemp
);
441 case OID_802_11_TX_RETRYCOUNT
:
442 pSNMPMIB
->oid
= cpu_to_le16((u16
) short_retrylim_i
);
444 if (cmd_action
== cmd_act_get
) {
445 pSNMPMIB
->querytype
= cpu_to_le16(cmd_act_get
);
446 } else if (cmd_action
== cmd_act_set
) {
447 pSNMPMIB
->querytype
= cpu_to_le16(cmd_act_set
);
448 pSNMPMIB
->bufsize
= cpu_to_le16(sizeof(u16
));
449 *((__le16
*)(pSNMPMIB
->value
)) =
450 cpu_to_le16((u16
) adapter
->txretrycount
);
459 "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
460 le16_to_cpu(cmd
->command
), le16_to_cpu(cmd
->size
),
461 le16_to_cpu(cmd
->seqnum
), le16_to_cpu(cmd
->result
));
464 "SNMP_CMD: action=0x%x, oid=0x%x, oidsize=0x%x, value=0x%x\n",
465 le16_to_cpu(pSNMPMIB
->querytype
), le16_to_cpu(pSNMPMIB
->oid
),
466 le16_to_cpu(pSNMPMIB
->bufsize
),
467 le16_to_cpu(*(__le16
*) pSNMPMIB
->value
));
469 lbs_deb_leave(LBS_DEB_CMD
);
473 static int wlan_cmd_802_11_radio_control(wlan_private
* priv
,
474 struct cmd_ds_command
*cmd
,
477 wlan_adapter
*adapter
= priv
->adapter
;
478 struct cmd_ds_802_11_radio_control
*pradiocontrol
= &cmd
->params
.radio
;
480 lbs_deb_enter(LBS_DEB_CMD
);
483 cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control
)) +
485 cmd
->command
= cpu_to_le16(cmd_802_11_radio_control
);
487 pradiocontrol
->action
= cpu_to_le16(cmd_action
);
489 switch (adapter
->preamble
) {
490 case cmd_type_short_preamble
:
491 pradiocontrol
->control
= cpu_to_le16(SET_SHORT_PREAMBLE
);
494 case cmd_type_long_preamble
:
495 pradiocontrol
->control
= cpu_to_le16(SET_LONG_PREAMBLE
);
498 case cmd_type_auto_preamble
:
500 pradiocontrol
->control
= cpu_to_le16(SET_AUTO_PREAMBLE
);
504 if (adapter
->radioon
)
505 pradiocontrol
->control
|= cpu_to_le16(TURN_ON_RF
);
507 pradiocontrol
->control
&= cpu_to_le16(~TURN_ON_RF
);
509 lbs_deb_leave(LBS_DEB_CMD
);
513 static int wlan_cmd_802_11_rf_tx_power(wlan_private
* priv
,
514 struct cmd_ds_command
*cmd
,
515 u16 cmd_action
, void *pdata_buf
)
518 struct cmd_ds_802_11_rf_tx_power
*prtp
= &cmd
->params
.txp
;
520 lbs_deb_enter(LBS_DEB_CMD
);
523 cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power
)) + S_DS_GEN
);
524 cmd
->command
= cpu_to_le16(cmd_802_11_rf_tx_power
);
525 prtp
->action
= cpu_to_le16(cmd_action
);
527 lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
528 le16_to_cpu(cmd
->size
), le16_to_cpu(cmd
->command
),
529 le16_to_cpu(prtp
->action
));
531 switch (cmd_action
) {
532 case cmd_act_tx_power_opt_get
:
533 prtp
->action
= cpu_to_le16(cmd_act_get
);
534 prtp
->currentlevel
= 0;
537 case cmd_act_tx_power_opt_set_high
:
538 prtp
->action
= cpu_to_le16(cmd_act_set
);
539 prtp
->currentlevel
= cpu_to_le16(cmd_act_tx_power_index_high
);
542 case cmd_act_tx_power_opt_set_mid
:
543 prtp
->action
= cpu_to_le16(cmd_act_set
);
544 prtp
->currentlevel
= cpu_to_le16(cmd_act_tx_power_index_mid
);
547 case cmd_act_tx_power_opt_set_low
:
548 prtp
->action
= cpu_to_le16(cmd_act_set
);
549 prtp
->currentlevel
= cpu_to_le16(*((u16
*) pdata_buf
));
553 lbs_deb_leave(LBS_DEB_CMD
);
557 static int wlan_cmd_802_11_rf_antenna(wlan_private
* priv
,
558 struct cmd_ds_command
*cmd
,
559 u16 cmd_action
, void *pdata_buf
)
561 struct cmd_ds_802_11_rf_antenna
*rant
= &cmd
->params
.rant
;
563 cmd
->command
= cpu_to_le16(cmd_802_11_rf_antenna
);
564 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_antenna
) +
567 rant
->action
= cpu_to_le16(cmd_action
);
568 if ((cmd_action
== cmd_act_set_rx
) || (cmd_action
== cmd_act_set_tx
)) {
569 rant
->antennamode
= cpu_to_le16((u16
) (*(u32
*) pdata_buf
));
575 static int wlan_cmd_802_11_rate_adapt_rateset(wlan_private
* priv
,
576 struct cmd_ds_command
*cmd
,
579 struct cmd_ds_802_11_rate_adapt_rateset
580 *rateadapt
= &cmd
->params
.rateset
;
581 wlan_adapter
*adapter
= priv
->adapter
;
584 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset
)
586 cmd
->command
= cpu_to_le16(cmd_802_11_rate_adapt_rateset
);
588 lbs_deb_enter(LBS_DEB_CMD
);
590 rateadapt
->action
= cpu_to_le16(cmd_action
);
591 rateadapt
->enablehwauto
= cpu_to_le16(adapter
->enablehwauto
);
592 rateadapt
->bitmap
= cpu_to_le16(adapter
->ratebitmap
);
594 lbs_deb_leave(LBS_DEB_CMD
);
598 static int wlan_cmd_802_11_data_rate(wlan_private
* priv
,
599 struct cmd_ds_command
*cmd
,
602 struct cmd_ds_802_11_data_rate
*pdatarate
= &cmd
->params
.drate
;
603 wlan_adapter
*adapter
= priv
->adapter
;
605 lbs_deb_enter(LBS_DEB_CMD
);
607 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate
) +
610 cmd
->command
= cpu_to_le16(cmd_802_11_data_rate
);
612 memset(pdatarate
, 0, sizeof(struct cmd_ds_802_11_data_rate
));
614 pdatarate
->action
= cpu_to_le16(cmd_action
);
616 if (cmd_action
== cmd_act_set_tx_fix_rate
) {
617 pdatarate
->datarate
[0] = libertas_data_rate_to_index(adapter
->datarate
);
618 lbs_deb_cmd("Setting FW for fixed rate 0x%02X\n",
620 } else if (cmd_action
== cmd_act_set_tx_auto
) {
621 lbs_deb_cmd("Setting FW for AUTO rate\n");
624 lbs_deb_leave(LBS_DEB_CMD
);
628 static int wlan_cmd_mac_multicast_adr(wlan_private
* priv
,
629 struct cmd_ds_command
*cmd
,
632 struct cmd_ds_mac_multicast_adr
*pMCastAdr
= &cmd
->params
.madr
;
633 wlan_adapter
*adapter
= priv
->adapter
;
635 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr
) +
637 cmd
->command
= cpu_to_le16(cmd_mac_multicast_adr
);
639 pMCastAdr
->action
= cpu_to_le16(cmd_action
);
640 pMCastAdr
->nr_of_adrs
=
641 cpu_to_le16((u16
) adapter
->nr_of_multicastmacaddr
);
642 memcpy(pMCastAdr
->maclist
, adapter
->multicastlist
,
643 adapter
->nr_of_multicastmacaddr
* ETH_ALEN
);
648 static int wlan_cmd_802_11_rf_channel(wlan_private
* priv
,
649 struct cmd_ds_command
*cmd
,
650 int option
, void *pdata_buf
)
652 struct cmd_ds_802_11_rf_channel
*rfchan
= &cmd
->params
.rfchannel
;
654 cmd
->command
= cpu_to_le16(cmd_802_11_rf_channel
);
655 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel
) +
658 if (option
== cmd_opt_802_11_rf_channel_set
) {
659 rfchan
->currentchannel
= cpu_to_le16(*((u16
*) pdata_buf
));
662 rfchan
->action
= cpu_to_le16(option
);
667 static int wlan_cmd_802_11_rssi(wlan_private
* priv
,
668 struct cmd_ds_command
*cmd
)
670 wlan_adapter
*adapter
= priv
->adapter
;
672 cmd
->command
= cpu_to_le16(cmd_802_11_rssi
);
673 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi
) + S_DS_GEN
);
674 cmd
->params
.rssi
.N
= cpu_to_le16(priv
->adapter
->bcn_avg_factor
);
676 /* reset Beacon SNR/NF/RSSI values */
677 adapter
->SNR
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
678 adapter
->SNR
[TYPE_BEACON
][TYPE_AVG
] = 0;
679 adapter
->NF
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
680 adapter
->NF
[TYPE_BEACON
][TYPE_AVG
] = 0;
681 adapter
->RSSI
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
682 adapter
->RSSI
[TYPE_BEACON
][TYPE_AVG
] = 0;
687 static int wlan_cmd_reg_access(wlan_private
* priv
,
688 struct cmd_ds_command
*cmdptr
,
689 u8 cmd_action
, void *pdata_buf
)
691 struct wlan_offset_value
*offval
;
693 lbs_deb_enter(LBS_DEB_CMD
);
695 offval
= (struct wlan_offset_value
*)pdata_buf
;
697 switch (cmdptr
->command
) {
698 case cmd_mac_reg_access
:
700 struct cmd_ds_mac_reg_access
*macreg
;
703 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access
)
706 (struct cmd_ds_mac_reg_access
*)&cmdptr
->params
.
709 macreg
->action
= cpu_to_le16(cmd_action
);
710 macreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
711 macreg
->value
= cpu_to_le32(offval
->value
);
716 case cmd_bbp_reg_access
:
718 struct cmd_ds_bbp_reg_access
*bbpreg
;
722 (struct cmd_ds_bbp_reg_access
)
725 (struct cmd_ds_bbp_reg_access
*)&cmdptr
->params
.
728 bbpreg
->action
= cpu_to_le16(cmd_action
);
729 bbpreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
730 bbpreg
->value
= (u8
) offval
->value
;
735 case cmd_rf_reg_access
:
737 struct cmd_ds_rf_reg_access
*rfreg
;
741 (struct cmd_ds_rf_reg_access
) +
744 (struct cmd_ds_rf_reg_access
*)&cmdptr
->params
.
747 rfreg
->action
= cpu_to_le16(cmd_action
);
748 rfreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
749 rfreg
->value
= (u8
) offval
->value
;
758 lbs_deb_leave(LBS_DEB_CMD
);
762 static int wlan_cmd_802_11_mac_address(wlan_private
* priv
,
763 struct cmd_ds_command
*cmd
,
766 wlan_adapter
*adapter
= priv
->adapter
;
768 cmd
->command
= cpu_to_le16(cmd_802_11_mac_address
);
769 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address
) +
773 cmd
->params
.macadd
.action
= cpu_to_le16(cmd_action
);
775 if (cmd_action
== cmd_act_set
) {
776 memcpy(cmd
->params
.macadd
.macadd
,
777 adapter
->current_addr
, ETH_ALEN
);
778 lbs_dbg_hex("SET_CMD: MAC ADDRESS-", adapter
->current_addr
, 6);
784 static int wlan_cmd_802_11_eeprom_access(wlan_private
* priv
,
785 struct cmd_ds_command
*cmd
,
786 int cmd_action
, void *pdata_buf
)
788 struct wlan_ioctl_regrdwr
*ea
= pdata_buf
;
790 lbs_deb_enter(LBS_DEB_CMD
);
792 cmd
->command
= cpu_to_le16(cmd_802_11_eeprom_access
);
793 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access
) +
797 cmd
->params
.rdeeprom
.action
= cpu_to_le16(ea
->action
);
798 cmd
->params
.rdeeprom
.offset
= cpu_to_le16(ea
->offset
);
799 cmd
->params
.rdeeprom
.bytecount
= cpu_to_le16(ea
->NOB
);
800 cmd
->params
.rdeeprom
.value
= 0;
805 static int wlan_cmd_bt_access(wlan_private
* priv
,
806 struct cmd_ds_command
*cmd
,
807 u16 cmd_action
, void *pdata_buf
)
809 struct cmd_ds_bt_access
*bt_access
= &cmd
->params
.bt
;
810 lbs_deb_cmd("BT CMD(%d)\n", cmd_action
);
812 cmd
->command
= cpu_to_le16(cmd_bt_access
);
813 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_bt_access
) + S_DS_GEN
);
815 bt_access
->action
= cpu_to_le16(cmd_action
);
817 switch (cmd_action
) {
818 case cmd_act_bt_access_add
:
819 memcpy(bt_access
->addr1
, pdata_buf
, 2 * ETH_ALEN
);
820 lbs_dbg_hex("BT_ADD: blinded mac address-", bt_access
->addr1
, 6);
822 case cmd_act_bt_access_del
:
823 memcpy(bt_access
->addr1
, pdata_buf
, 1 * ETH_ALEN
);
824 lbs_dbg_hex("BT_DEL: blinded mac address-", bt_access
->addr1
, 6);
826 case cmd_act_bt_access_list
:
827 bt_access
->id
= cpu_to_le32(*(u32
*) pdata_buf
);
829 case cmd_act_bt_access_reset
:
831 case cmd_act_bt_access_set_invert
:
832 bt_access
->id
= cpu_to_le32(*(u32
*) pdata_buf
);
834 case cmd_act_bt_access_get_invert
:
842 static int wlan_cmd_fwt_access(wlan_private
* priv
,
843 struct cmd_ds_command
*cmd
,
844 u16 cmd_action
, void *pdata_buf
)
846 struct cmd_ds_fwt_access
*fwt_access
= &cmd
->params
.fwt
;
847 lbs_deb_cmd("FWT CMD(%d)\n", cmd_action
);
849 cmd
->command
= cpu_to_le16(cmd_fwt_access
);
850 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_fwt_access
) + S_DS_GEN
);
854 memcpy(fwt_access
, pdata_buf
, sizeof(*fwt_access
));
856 memset(fwt_access
, 0, sizeof(*fwt_access
));
858 fwt_access
->action
= cpu_to_le16(cmd_action
);
863 static int wlan_cmd_mesh_access(wlan_private
* priv
,
864 struct cmd_ds_command
*cmd
,
865 u16 cmd_action
, void *pdata_buf
)
867 struct cmd_ds_mesh_access
*mesh_access
= &cmd
->params
.mesh
;
868 lbs_deb_cmd("FWT CMD(%d)\n", cmd_action
);
870 cmd
->command
= cpu_to_le16(cmd_mesh_access
);
871 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_mesh_access
) + S_DS_GEN
);
875 memcpy(mesh_access
, pdata_buf
, sizeof(*mesh_access
));
877 memset(mesh_access
, 0, sizeof(*mesh_access
));
879 mesh_access
->action
= cpu_to_le16(cmd_action
);
884 void libertas_queue_cmd(wlan_adapter
* adapter
, struct cmd_ctrl_node
*cmdnode
, u8 addtail
)
887 struct cmd_ds_command
*cmdptr
;
889 lbs_deb_enter(LBS_DEB_CMD
);
892 lbs_deb_cmd("QUEUE_CMD: cmdnode is NULL\n");
896 cmdptr
= (struct cmd_ds_command
*)cmdnode
->bufvirtualaddr
;
898 lbs_deb_cmd("QUEUE_CMD: cmdptr is NULL\n");
902 /* Exit_PS command needs to be queued in the header always. */
903 if (cmdptr
->command
== cmd_802_11_ps_mode
) {
904 struct cmd_ds_802_11_ps_mode
*psm
= &cmdptr
->params
.psmode
;
905 if (psm
->action
== cpu_to_le16(cmd_subcmd_exit_ps
)) {
906 if (adapter
->psstate
!= PS_STATE_FULL_POWER
)
911 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
914 list_add_tail((struct list_head
*)cmdnode
,
915 &adapter
->cmdpendingq
);
917 list_add((struct list_head
*)cmdnode
, &adapter
->cmdpendingq
);
919 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
921 lbs_deb_cmd("QUEUE_CMD: Inserted node=%p, cmd=0x%x in cmdpendingq\n",
923 le16_to_cpu(((struct cmd_ds_gen
*)cmdnode
->bufvirtualaddr
)->command
));
926 lbs_deb_leave(LBS_DEB_CMD
);
930 * TODO: Fix the issue when DownloadcommandToStation is being called the
931 * second time when the command timesout. All the cmdptr->xxx are in little
932 * endian and therefore all the comparissions will fail.
933 * For now - we are not performing the endian conversion the second time - but
934 * for PS and DEEP_SLEEP we need to worry
936 static int DownloadcommandToStation(wlan_private
* priv
,
937 struct cmd_ctrl_node
*cmdnode
)
940 struct cmd_ds_command
*cmdptr
;
941 wlan_adapter
*adapter
= priv
->adapter
;
946 lbs_deb_enter(LBS_DEB_CMD
);
948 if (!adapter
|| !cmdnode
) {
949 lbs_deb_cmd("DNLD_CMD: adapter = %p, cmdnode = %p\n",
952 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
953 __libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
954 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
960 cmdptr
= (struct cmd_ds_command
*)cmdnode
->bufvirtualaddr
;
963 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
964 if (!cmdptr
|| !cmdptr
->size
) {
965 lbs_deb_cmd("DNLD_CMD: cmdptr is Null or cmd size is Zero, "
967 __libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
968 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
973 adapter
->cur_cmd
= cmdnode
;
974 adapter
->cur_cmd_retcode
= 0;
975 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
976 lbs_deb_cmd("DNLD_CMD:: Before download, size of cmd = %d\n",
977 le16_to_cpu(cmdptr
->size
));
979 cmdsize
= cmdptr
->size
;
981 command
= cpu_to_le16(cmdptr
->command
);
983 cmdnode
->cmdwaitqwoken
= 0;
984 cmdsize
= cpu_to_le16(cmdsize
);
986 ret
= priv
->hw_host_to_card(priv
, MVMS_CMD
, (u8
*) cmdptr
, cmdsize
);
989 lbs_deb_cmd("DNLD_CMD: Host to Card failed\n");
990 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
991 __libertas_cleanup_and_insert_cmd(priv
, adapter
->cur_cmd
);
992 adapter
->cur_cmd
= NULL
;
993 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
998 lbs_deb_cmd("DNLD_CMD: Sent command 0x%x @ %lu\n", command
, jiffies
);
999 lbs_dbg_hex("DNLD_CMD: command", cmdnode
->bufvirtualaddr
, cmdsize
);
1001 /* Setup the timer after transmit command */
1002 if (command
== cmd_802_11_scan
|| command
== cmd_802_11_authenticate
1003 || command
== cmd_802_11_associate
)
1004 mod_timer(&adapter
->command_timer
, jiffies
+ (10*HZ
));
1006 mod_timer(&adapter
->command_timer
, jiffies
+ (5*HZ
));
1011 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
1015 static int wlan_cmd_mac_control(wlan_private
* priv
,
1016 struct cmd_ds_command
*cmd
)
1018 struct cmd_ds_mac_control
*mac
= &cmd
->params
.macctrl
;
1020 lbs_deb_enter(LBS_DEB_CMD
);
1022 cmd
->command
= cpu_to_le16(cmd_mac_control
);
1023 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_mac_control
) + S_DS_GEN
);
1024 mac
->action
= cpu_to_le16(priv
->adapter
->currentpacketfilter
);
1026 lbs_deb_cmd("wlan_cmd_mac_control(): action=0x%X size=%d\n",
1027 le16_to_cpu(mac
->action
), le16_to_cpu(cmd
->size
));
1029 lbs_deb_leave(LBS_DEB_CMD
);
1034 * This function inserts command node to cmdfreeq
1035 * after cleans it. Requires adapter->driver_lock held.
1037 void __libertas_cleanup_and_insert_cmd(wlan_private
* priv
, struct cmd_ctrl_node
*ptempcmd
)
1039 wlan_adapter
*adapter
= priv
->adapter
;
1044 cleanup_cmdnode(ptempcmd
);
1045 list_add_tail((struct list_head
*)ptempcmd
, &adapter
->cmdfreeq
);
1050 void libertas_cleanup_and_insert_cmd(wlan_private
* priv
, struct cmd_ctrl_node
*ptempcmd
)
1052 unsigned long flags
;
1054 spin_lock_irqsave(&priv
->adapter
->driver_lock
, flags
);
1055 __libertas_cleanup_and_insert_cmd(priv
, ptempcmd
);
1056 spin_unlock_irqrestore(&priv
->adapter
->driver_lock
, flags
);
1059 int libertas_set_radio_control(wlan_private
* priv
)
1063 lbs_deb_enter(LBS_DEB_CMD
);
1065 ret
= libertas_prepare_and_send_command(priv
,
1066 cmd_802_11_radio_control
,
1068 cmd_option_waitforrsp
, 0, NULL
);
1070 lbs_deb_cmd("RADIO_SET: on or off: 0x%X, preamble = 0x%X\n",
1071 priv
->adapter
->radioon
, priv
->adapter
->preamble
);
1073 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
1077 int libertas_set_mac_packet_filter(wlan_private
* priv
)
1081 lbs_deb_enter(LBS_DEB_CMD
);
1083 lbs_deb_cmd("libertas_set_mac_packet_filter value = %x\n",
1084 priv
->adapter
->currentpacketfilter
);
1086 /* Send MAC control command to station */
1087 ret
= libertas_prepare_and_send_command(priv
,
1088 cmd_mac_control
, 0, 0, 0, NULL
);
1090 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
1095 * @brief This function prepare the command before send to firmware.
1097 * @param priv A pointer to wlan_private structure
1098 * @param cmd_no command number
1099 * @param cmd_action command action: GET or SET
1100 * @param wait_option wait option: wait response or not
1101 * @param cmd_oid cmd oid: treated as sub command
1102 * @param pdata_buf A pointer to informaion buffer
1105 int libertas_prepare_and_send_command(wlan_private
* priv
,
1108 u16 wait_option
, u32 cmd_oid
, void *pdata_buf
)
1111 wlan_adapter
*adapter
= priv
->adapter
;
1112 struct cmd_ctrl_node
*cmdnode
;
1113 struct cmd_ds_command
*cmdptr
;
1114 unsigned long flags
;
1116 lbs_deb_enter(LBS_DEB_CMD
);
1119 lbs_deb_cmd("PREP_CMD: adapter is Null\n");
1124 if (adapter
->surpriseremoved
) {
1125 lbs_deb_cmd("PREP_CMD: Card is Removed\n");
1130 cmdnode
= libertas_get_free_cmd_ctrl_node(priv
);
1132 if (cmdnode
== NULL
) {
1133 lbs_deb_cmd("PREP_CMD: No free cmdnode\n");
1135 /* Wake up main thread to execute next command */
1136 wake_up_interruptible(&priv
->mainthread
.waitq
);
1141 libertas_set_cmd_ctrl_node(priv
, cmdnode
, cmd_oid
, wait_option
, pdata_buf
);
1143 cmdptr
= (struct cmd_ds_command
*)cmdnode
->bufvirtualaddr
;
1145 lbs_deb_cmd("PREP_CMD: Val of cmd ptr=%p, command=0x%X\n",
1149 lbs_deb_cmd("PREP_CMD: bufvirtualaddr of cmdnode is NULL\n");
1150 libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
1155 /* Set sequence number, command and INT option */
1157 cmdptr
->seqnum
= cpu_to_le16(adapter
->seqnum
);
1159 cmdptr
->command
= cpu_to_le16(cmd_no
);
1163 case cmd_get_hw_spec
:
1164 ret
= wlan_cmd_hw_spec(priv
, cmdptr
);
1166 case cmd_802_11_ps_mode
:
1167 ret
= wlan_cmd_802_11_ps_mode(priv
, cmdptr
, cmd_action
);
1170 case cmd_802_11_scan
:
1171 ret
= libertas_cmd_80211_scan(priv
, cmdptr
, pdata_buf
);
1174 case cmd_mac_control
:
1175 ret
= wlan_cmd_mac_control(priv
, cmdptr
);
1178 case cmd_802_11_associate
:
1179 case cmd_802_11_reassociate
:
1180 ret
= libertas_cmd_80211_associate(priv
, cmdptr
, pdata_buf
);
1183 case cmd_802_11_deauthenticate
:
1184 ret
= libertas_cmd_80211_deauthenticate(priv
, cmdptr
);
1187 case cmd_802_11_set_wep
:
1188 ret
= wlan_cmd_802_11_set_wep(priv
, cmdptr
, cmd_action
, pdata_buf
);
1191 case cmd_802_11_ad_hoc_start
:
1192 ret
= libertas_cmd_80211_ad_hoc_start(priv
, cmdptr
, pdata_buf
);
1197 case cmd_802_11_reset
:
1198 ret
= wlan_cmd_802_11_reset(priv
, cmdptr
, cmd_action
);
1201 case cmd_802_11_get_log
:
1202 ret
= wlan_cmd_802_11_get_log(priv
, cmdptr
);
1205 case cmd_802_11_authenticate
:
1206 ret
= libertas_cmd_80211_authenticate(priv
, cmdptr
, pdata_buf
);
1209 case cmd_802_11_get_stat
:
1210 ret
= wlan_cmd_802_11_get_stat(priv
, cmdptr
);
1213 case cmd_802_11_snmp_mib
:
1214 ret
= wlan_cmd_802_11_snmp_mib(priv
, cmdptr
,
1215 cmd_action
, cmd_oid
, pdata_buf
);
1218 case cmd_mac_reg_access
:
1219 case cmd_bbp_reg_access
:
1220 case cmd_rf_reg_access
:
1221 ret
= wlan_cmd_reg_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1224 case cmd_802_11_rf_channel
:
1225 ret
= wlan_cmd_802_11_rf_channel(priv
, cmdptr
,
1226 cmd_action
, pdata_buf
);
1229 case cmd_802_11_rf_tx_power
:
1230 ret
= wlan_cmd_802_11_rf_tx_power(priv
, cmdptr
,
1231 cmd_action
, pdata_buf
);
1234 case cmd_802_11_radio_control
:
1235 ret
= wlan_cmd_802_11_radio_control(priv
, cmdptr
, cmd_action
);
1238 case cmd_802_11_rf_antenna
:
1239 ret
= wlan_cmd_802_11_rf_antenna(priv
, cmdptr
,
1240 cmd_action
, pdata_buf
);
1243 case cmd_802_11_data_rate
:
1244 ret
= wlan_cmd_802_11_data_rate(priv
, cmdptr
, cmd_action
);
1246 case cmd_802_11_rate_adapt_rateset
:
1247 ret
= wlan_cmd_802_11_rate_adapt_rateset(priv
,
1248 cmdptr
, cmd_action
);
1251 case cmd_mac_multicast_adr
:
1252 ret
= wlan_cmd_mac_multicast_adr(priv
, cmdptr
, cmd_action
);
1255 case cmd_802_11_ad_hoc_join
:
1256 ret
= libertas_cmd_80211_ad_hoc_join(priv
, cmdptr
, pdata_buf
);
1259 case cmd_802_11_rssi
:
1260 ret
= wlan_cmd_802_11_rssi(priv
, cmdptr
);
1263 case cmd_802_11_ad_hoc_stop
:
1264 ret
= libertas_cmd_80211_ad_hoc_stop(priv
, cmdptr
);
1267 case cmd_802_11_enable_rsn
:
1268 ret
= wlan_cmd_802_11_enable_rsn(priv
, cmdptr
, cmd_action
,
1272 case cmd_802_11_key_material
:
1273 ret
= wlan_cmd_802_11_key_material(priv
, cmdptr
, cmd_action
,
1274 cmd_oid
, pdata_buf
);
1277 case cmd_802_11_pairwise_tsc
:
1279 case cmd_802_11_group_tsc
:
1282 case cmd_802_11_mac_address
:
1283 ret
= wlan_cmd_802_11_mac_address(priv
, cmdptr
, cmd_action
);
1286 case cmd_802_11_eeprom_access
:
1287 ret
= wlan_cmd_802_11_eeprom_access(priv
, cmdptr
,
1288 cmd_action
, pdata_buf
);
1291 case cmd_802_11_set_afc
:
1292 case cmd_802_11_get_afc
:
1294 cmdptr
->command
= cpu_to_le16(cmd_no
);
1295 cmdptr
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_afc
) +
1298 memmove(&cmdptr
->params
.afc
,
1299 pdata_buf
, sizeof(struct cmd_ds_802_11_afc
));
1304 case cmd_802_11d_domain_info
:
1305 ret
= libertas_cmd_802_11d_domain_info(priv
, cmdptr
,
1306 cmd_no
, cmd_action
);
1309 case cmd_802_11_sleep_params
:
1310 ret
= wlan_cmd_802_11_sleep_params(priv
, cmdptr
, cmd_action
);
1312 case cmd_802_11_inactivity_timeout
:
1313 ret
= wlan_cmd_802_11_inactivity_timeout(priv
, cmdptr
,
1314 cmd_action
, pdata_buf
);
1315 libertas_set_cmd_ctrl_node(priv
, cmdnode
, 0, 0, pdata_buf
);
1318 case cmd_802_11_tpc_cfg
:
1319 cmdptr
->command
= cpu_to_le16(cmd_802_11_tpc_cfg
);
1321 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg
) +
1324 memmove(&cmdptr
->params
.tpccfg
,
1325 pdata_buf
, sizeof(struct cmd_ds_802_11_tpc_cfg
));
1329 case cmd_802_11_led_gpio_ctrl
:
1331 struct mrvlietypes_ledgpio
*gpio
=
1332 (struct mrvlietypes_ledgpio
*)
1333 cmdptr
->params
.ledgpio
.data
;
1335 memmove(&cmdptr
->params
.ledgpio
,
1337 sizeof(struct cmd_ds_802_11_led_ctrl
));
1340 cpu_to_le16(cmd_802_11_led_gpio_ctrl
);
1342 #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1344 cpu_to_le16(gpio
->header
.len
+ S_DS_GEN
+
1345 ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN
);
1346 gpio
->header
.len
= cpu_to_le16(gpio
->header
.len
);
1351 case cmd_802_11_pwr_cfg
:
1352 cmdptr
->command
= cpu_to_le16(cmd_802_11_pwr_cfg
);
1354 cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg
) +
1356 memmove(&cmdptr
->params
.pwrcfg
, pdata_buf
,
1357 sizeof(struct cmd_ds_802_11_pwr_cfg
));
1362 ret
= wlan_cmd_bt_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1365 case cmd_fwt_access
:
1366 ret
= wlan_cmd_fwt_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1369 case cmd_mesh_access
:
1370 ret
= wlan_cmd_mesh_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1374 cmdptr
->command
= cpu_to_le16(cmd_get_tsf
);
1375 cmdptr
->size
= cpu_to_le16(sizeof(struct cmd_ds_get_tsf
) +
1379 case cmd_802_11_tx_rate_query
:
1380 cmdptr
->command
= cpu_to_le16(cmd_802_11_tx_rate_query
);
1381 cmdptr
->size
= cpu_to_le16(sizeof(struct cmd_tx_rate_query
) +
1383 adapter
->txrate
= 0;
1387 lbs_deb_cmd("PREP_CMD: unknown command- %#x\n", cmd_no
);
1392 /* return error, since the command preparation failed */
1394 lbs_deb_cmd("PREP_CMD: command preparation failed\n");
1395 libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
1400 cmdnode
->cmdwaitqwoken
= 0;
1402 libertas_queue_cmd(adapter
, cmdnode
, 1);
1403 adapter
->nr_cmd_pending
++;
1404 wake_up_interruptible(&priv
->mainthread
.waitq
);
1406 if (wait_option
& cmd_option_waitforrsp
) {
1407 lbs_deb_cmd("PREP_CMD: Wait for CMD response\n");
1409 wait_event_interruptible(cmdnode
->cmdwait_q
,
1410 cmdnode
->cmdwaitqwoken
);
1413 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1414 if (adapter
->cur_cmd_retcode
) {
1415 lbs_deb_cmd("PREP_CMD: command failed with return code=%d\n",
1416 adapter
->cur_cmd_retcode
);
1417 adapter
->cur_cmd_retcode
= 0;
1420 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1423 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
1426 EXPORT_SYMBOL_GPL(libertas_prepare_and_send_command
);
1429 * @brief This function allocates the command buffer and link
1430 * it to command free queue.
1432 * @param priv A pointer to wlan_private structure
1435 int libertas_allocate_cmd_buffer(wlan_private
* priv
)
1440 struct cmd_ctrl_node
*tempcmd_array
;
1441 u8
*ptempvirtualaddr
;
1442 wlan_adapter
*adapter
= priv
->adapter
;
1444 lbs_deb_enter(LBS_DEB_CMD
);
1446 /* Allocate and initialize cmdCtrlNode */
1447 ulbufsize
= sizeof(struct cmd_ctrl_node
) * MRVDRV_NUM_OF_CMD_BUFFER
;
1449 if (!(tempcmd_array
= kzalloc(ulbufsize
, GFP_KERNEL
))) {
1451 "ALLOC_CMD_BUF: failed to allocate tempcmd_array\n");
1455 adapter
->cmd_array
= tempcmd_array
;
1457 /* Allocate and initialize command buffers */
1458 ulbufsize
= MRVDRV_SIZE_OF_CMD_BUFFER
;
1459 for (i
= 0; i
< MRVDRV_NUM_OF_CMD_BUFFER
; i
++) {
1460 if (!(ptempvirtualaddr
= kzalloc(ulbufsize
, GFP_KERNEL
))) {
1462 "ALLOC_CMD_BUF: ptempvirtualaddr: out of memory\n");
1467 /* Update command buffer virtual */
1468 tempcmd_array
[i
].bufvirtualaddr
= ptempvirtualaddr
;
1471 for (i
= 0; i
< MRVDRV_NUM_OF_CMD_BUFFER
; i
++) {
1472 init_waitqueue_head(&tempcmd_array
[i
].cmdwait_q
);
1473 libertas_cleanup_and_insert_cmd(priv
, &tempcmd_array
[i
]);
1479 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
1484 * @brief This function frees the command buffer.
1486 * @param priv A pointer to wlan_private structure
1489 int libertas_free_cmd_buffer(wlan_private
* priv
)
1491 u32 ulbufsize
; /* Someone needs to die for this. Slowly and painfully */
1493 struct cmd_ctrl_node
*tempcmd_array
;
1494 wlan_adapter
*adapter
= priv
->adapter
;
1496 lbs_deb_enter(LBS_DEB_CMD
);
1498 /* need to check if cmd array is allocated or not */
1499 if (adapter
->cmd_array
== NULL
) {
1500 lbs_deb_cmd("FREE_CMD_BUF: cmd_array is Null\n");
1504 tempcmd_array
= adapter
->cmd_array
;
1506 /* Release shared memory buffers */
1507 ulbufsize
= MRVDRV_SIZE_OF_CMD_BUFFER
;
1508 for (i
= 0; i
< MRVDRV_NUM_OF_CMD_BUFFER
; i
++) {
1509 if (tempcmd_array
[i
].bufvirtualaddr
) {
1510 lbs_deb_cmd("Free all the array\n");
1511 kfree(tempcmd_array
[i
].bufvirtualaddr
);
1512 tempcmd_array
[i
].bufvirtualaddr
= NULL
;
1516 /* Release cmd_ctrl_node */
1517 if (adapter
->cmd_array
) {
1518 lbs_deb_cmd("Free cmd_array\n");
1519 kfree(adapter
->cmd_array
);
1520 adapter
->cmd_array
= NULL
;
1524 lbs_deb_leave(LBS_DEB_CMD
);
1529 * @brief This function gets a free command node if available in
1530 * command free queue.
1532 * @param priv A pointer to wlan_private structure
1533 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1535 struct cmd_ctrl_node
*libertas_get_free_cmd_ctrl_node(wlan_private
* priv
)
1537 struct cmd_ctrl_node
*tempnode
;
1538 wlan_adapter
*adapter
= priv
->adapter
;
1539 unsigned long flags
;
1544 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1546 if (!list_empty(&adapter
->cmdfreeq
)) {
1547 tempnode
= (struct cmd_ctrl_node
*)adapter
->cmdfreeq
.next
;
1548 list_del((struct list_head
*)tempnode
);
1550 lbs_deb_cmd("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1554 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1558 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode available\n");
1559 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode Address = %p\n",
1562 cleanup_cmdnode(tempnode
);
1569 * @brief This function cleans command node.
1571 * @param ptempnode A pointer to cmdCtrlNode structure
1574 static void cleanup_cmdnode(struct cmd_ctrl_node
*ptempnode
)
1578 ptempnode
->cmdwaitqwoken
= 1;
1579 wake_up_interruptible(&ptempnode
->cmdwait_q
);
1580 ptempnode
->status
= 0;
1581 ptempnode
->cmd_oid
= (u32
) 0;
1582 ptempnode
->wait_option
= 0;
1583 ptempnode
->pdata_buf
= NULL
;
1585 if (ptempnode
->bufvirtualaddr
!= NULL
)
1586 memset(ptempnode
->bufvirtualaddr
, 0, MRVDRV_SIZE_OF_CMD_BUFFER
);
1591 * @brief This function initializes the command node.
1593 * @param priv A pointer to wlan_private structure
1594 * @param ptempnode A pointer to cmd_ctrl_node structure
1595 * @param cmd_oid cmd oid: treated as sub command
1596 * @param wait_option wait option: wait response or not
1597 * @param pdata_buf A pointer to informaion buffer
1600 void libertas_set_cmd_ctrl_node(wlan_private
* priv
,
1601 struct cmd_ctrl_node
*ptempnode
,
1602 u32 cmd_oid
, u16 wait_option
, void *pdata_buf
)
1604 lbs_deb_enter(LBS_DEB_CMD
);
1609 ptempnode
->cmd_oid
= cmd_oid
;
1610 ptempnode
->wait_option
= wait_option
;
1611 ptempnode
->pdata_buf
= pdata_buf
;
1613 lbs_deb_leave(LBS_DEB_CMD
);
1617 * @brief This function executes next command in command
1618 * pending queue. It will put fimware back to PS mode
1621 * @param priv A pointer to wlan_private structure
1624 int libertas_execute_next_command(wlan_private
* priv
)
1626 wlan_adapter
*adapter
= priv
->adapter
;
1627 struct cmd_ctrl_node
*cmdnode
= NULL
;
1628 struct cmd_ds_command
*cmdptr
;
1629 unsigned long flags
;
1632 lbs_deb_enter(LBS_DEB_CMD
);
1634 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1636 if (adapter
->cur_cmd
) {
1637 lbs_pr_alert( "EXEC_NEXT_CMD: there is command in processing!\n");
1638 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1643 if (!list_empty(&adapter
->cmdpendingq
)) {
1644 cmdnode
= (struct cmd_ctrl_node
*)
1645 adapter
->cmdpendingq
.next
;
1648 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1652 "EXEC_NEXT_CMD: Got next command from cmdpendingq\n");
1653 cmdptr
= (struct cmd_ds_command
*)cmdnode
->bufvirtualaddr
;
1655 if (is_command_allowed_in_ps(cmdptr
->command
)) {
1656 if ((adapter
->psstate
== PS_STATE_SLEEP
) ||
1657 (adapter
->psstate
== PS_STATE_PRE_SLEEP
)) {
1659 "EXEC_NEXT_CMD: Cannot send cmd 0x%x in psstate %d\n",
1660 le16_to_cpu(cmdptr
->command
),
1665 lbs_deb_cmd("EXEC_NEXT_CMD: OK to send command "
1666 "0x%x in psstate %d\n",
1667 le16_to_cpu(cmdptr
->command
),
1669 } else if (adapter
->psstate
!= PS_STATE_FULL_POWER
) {
1671 * 1. Non-PS command:
1672 * Queue it. set needtowakeup to TRUE if current state
1673 * is SLEEP, otherwise call libertas_ps_wakeup to send Exit_PS.
1674 * 2. PS command but not Exit_PS:
1676 * 3. PS command Exit_PS:
1677 * Set needtowakeup to TRUE if current state is SLEEP,
1678 * otherwise send this command down to firmware
1681 if (cmdptr
->command
!=
1682 cpu_to_le16(cmd_802_11_ps_mode
)) {
1683 /* Prepare to send Exit PS,
1684 * this non PS command will be sent later */
1685 if ((adapter
->psstate
== PS_STATE_SLEEP
)
1686 || (adapter
->psstate
== PS_STATE_PRE_SLEEP
)
1688 /* w/ new scheme, it will not reach here.
1689 since it is blocked in main_thread. */
1690 adapter
->needtowakeup
= 1;
1692 libertas_ps_wakeup(priv
, 0);
1698 * PS command. Ignore it if it is not Exit_PS.
1699 * otherwise send it down immediately.
1701 struct cmd_ds_802_11_ps_mode
*psm
=
1702 &cmdptr
->params
.psmode
;
1705 "EXEC_NEXT_CMD: PS cmd- action=0x%x\n",
1708 cpu_to_le16(cmd_subcmd_exit_ps
)) {
1710 "EXEC_NEXT_CMD: Ignore Enter PS cmd\n");
1711 list_del((struct list_head
*)cmdnode
);
1712 libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
1718 if ((adapter
->psstate
== PS_STATE_SLEEP
) ||
1719 (adapter
->psstate
== PS_STATE_PRE_SLEEP
)) {
1721 "EXEC_NEXT_CMD: Ignore ExitPS cmd in sleep\n");
1722 list_del((struct list_head
*)cmdnode
);
1723 libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
1724 adapter
->needtowakeup
= 1;
1731 "EXEC_NEXT_CMD: Sending Exit_PS down...\n");
1734 list_del((struct list_head
*)cmdnode
);
1735 lbs_deb_cmd("EXEC_NEXT_CMD: Sending 0x%04X command\n",
1736 le16_to_cpu(cmdptr
->command
));
1737 DownloadcommandToStation(priv
, cmdnode
);
1740 * check if in power save mode, if yes, put the device back
1743 if ((adapter
->psmode
!= wlan802_11powermodecam
) &&
1744 (adapter
->psstate
== PS_STATE_FULL_POWER
) &&
1745 (adapter
->connect_status
== libertas_connected
)) {
1746 if (adapter
->secinfo
.WPAenabled
||
1747 adapter
->secinfo
.WPA2enabled
) {
1748 /* check for valid WPA group keys */
1749 if (adapter
->wpa_mcast_key
.len
||
1750 adapter
->wpa_unicast_key
.len
) {
1752 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1753 " go back to PS_SLEEP");
1754 libertas_ps_sleep(priv
, 0);
1758 "EXEC_NEXT_CMD: command PendQ is empty,"
1759 " go back to PS_SLEEP");
1760 libertas_ps_sleep(priv
, 0);
1767 lbs_deb_leave(LBS_DEB_CMD
);
1771 void libertas_send_iwevcustom_event(wlan_private
* priv
, s8
* str
)
1773 union iwreq_data iwrq
;
1776 lbs_deb_enter(LBS_DEB_CMD
);
1778 memset(&iwrq
, 0, sizeof(union iwreq_data
));
1779 memset(buf
, 0, sizeof(buf
));
1781 snprintf(buf
, sizeof(buf
) - 1, "%s", str
);
1783 iwrq
.data
.length
= strlen(buf
) + 1 + IW_EV_LCP_LEN
;
1785 /* Send Event to upper layer */
1786 lbs_deb_cmd("Event Indication string = %s\n", (char *)buf
);
1787 lbs_deb_cmd("Event Indication String length = %d\n", iwrq
.data
.length
);
1789 lbs_deb_cmd("Sending wireless event IWEVCUSTOM for %s\n", str
);
1790 wireless_send_event(priv
->dev
, IWEVCUSTOM
, &iwrq
, buf
);
1792 lbs_deb_leave(LBS_DEB_CMD
);
1795 static int sendconfirmsleep(wlan_private
* priv
, u8
* cmdptr
, u16 size
)
1797 unsigned long flags
;
1798 wlan_adapter
*adapter
= priv
->adapter
;
1801 lbs_deb_enter(LBS_DEB_CMD
);
1803 lbs_deb_cmd("SEND_SLEEPC_CMD: Before download, size of cmd = %d\n",
1806 lbs_dbg_hex("SEND_SLEEPC_CMD: Sleep confirm command", cmdptr
, size
);
1808 ret
= priv
->hw_host_to_card(priv
, MVMS_CMD
, cmdptr
, size
);
1809 priv
->dnld_sent
= DNLD_RES_RECEIVED
;
1811 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1812 if (adapter
->intcounter
|| adapter
->currenttxskb
)
1813 lbs_deb_cmd("SEND_SLEEPC_CMD: intcounter=%d currenttxskb=%p\n",
1814 adapter
->intcounter
, adapter
->currenttxskb
);
1815 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1819 "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
1821 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1822 if (!adapter
->intcounter
) {
1823 adapter
->psstate
= PS_STATE_SLEEP
;
1825 lbs_deb_cmd("SEND_SLEEPC_CMD: After sent,IntC=%d\n",
1826 adapter
->intcounter
);
1828 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1830 lbs_deb_cmd("SEND_SLEEPC_CMD: Sent Confirm Sleep command\n");
1834 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
1838 void libertas_ps_sleep(wlan_private
* priv
, int wait_option
)
1840 lbs_deb_enter(LBS_DEB_CMD
);
1843 * PS is currently supported only in Infrastructure mode
1844 * Remove this check if it is to be supported in IBSS mode also
1847 libertas_prepare_and_send_command(priv
, cmd_802_11_ps_mode
,
1848 cmd_subcmd_enter_ps
, wait_option
, 0, NULL
);
1850 lbs_deb_leave(LBS_DEB_CMD
);
1854 * @brief This function sends Eixt_PS command to firmware.
1856 * @param priv A pointer to wlan_private structure
1857 * @param wait_option wait response or not
1860 void libertas_ps_wakeup(wlan_private
* priv
, int wait_option
)
1864 lbs_deb_enter(LBS_DEB_CMD
);
1866 Localpsmode
= cpu_to_le32(wlan802_11powermodecam
);
1868 lbs_deb_cmd("Exit_PS: Localpsmode = %d\n", wlan802_11powermodecam
);
1870 libertas_prepare_and_send_command(priv
, cmd_802_11_ps_mode
,
1872 wait_option
, 0, &Localpsmode
);
1874 lbs_deb_leave(LBS_DEB_CMD
);
1878 * @brief This function checks condition and prepares to
1879 * send sleep confirm command to firmware if ok.
1881 * @param priv A pointer to wlan_private structure
1882 * @param psmode Power Saving mode
1885 void libertas_ps_confirm_sleep(wlan_private
* priv
, u16 psmode
)
1887 unsigned long flags
=0;
1888 wlan_adapter
*adapter
= priv
->adapter
;
1891 lbs_deb_enter(LBS_DEB_CMD
);
1893 if (priv
->dnld_sent
) {
1898 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1899 if (adapter
->cur_cmd
) {
1903 if (adapter
->intcounter
> 0) {
1905 lbs_deb_cmd("I%d", adapter
->intcounter
);
1907 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1910 lbs_deb_cmd("Sending libertas_ps_confirm_sleep\n");
1911 sendconfirmsleep(priv
, (u8
*) & adapter
->libertas_ps_confirm_sleep
,
1912 sizeof(struct PS_CMD_ConfirmSleep
));
1914 lbs_deb_cmd("Sleep Confirm has been delayed\n");
1917 lbs_deb_leave(LBS_DEB_CMD
);