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>
16 static void cleanup_cmdnode(struct cmd_ctrl_node
*ptempnode
);
18 static u16 commands_allowed_in_ps
[] = {
23 * @brief This function checks if the commans is allowed
26 * @param command the command ID
27 * @return TRUE or FALSE
29 static u8
is_command_allowed_in_ps(u16 command
)
31 int count
= sizeof(commands_allowed_in_ps
)
32 / sizeof(commands_allowed_in_ps
[0]);
35 for (i
= 0; i
< count
; i
++) {
36 if (command
== cpu_to_le16(commands_allowed_in_ps
[i
]))
43 static int wlan_cmd_hw_spec(wlan_private
* priv
, struct cmd_ds_command
*cmd
)
45 struct cmd_ds_get_hw_spec
*hwspec
= &cmd
->params
.hwspec
;
49 cmd
->command
= cpu_to_le16(cmd_get_hw_spec
);
51 cpu_to_le16(sizeof(struct cmd_ds_get_hw_spec
) + S_DS_GEN
);
52 memcpy(hwspec
->permanentaddr
, priv
->adapter
->current_addr
, ETH_ALEN
);
58 static int wlan_cmd_802_11_ps_mode(wlan_private
* priv
,
59 struct cmd_ds_command
*cmd
,
62 struct cmd_ds_802_11_ps_mode
*psm
= &cmd
->params
.psmode
;
63 u16 action
= cmd_action
;
64 wlan_adapter
*adapter
= priv
->adapter
;
68 cmd
->command
= cpu_to_le16(cmd_802_11_ps_mode
);
70 cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode
) +
72 psm
->action
= cpu_to_le16(cmd_action
);
73 psm
->multipledtim
= 0;
75 case cmd_subcmd_enter_ps
:
76 lbs_pr_debug(1, "PS command:" "SubCode- Enter PS\n");
77 lbs_pr_debug(1, "locallisteninterval = %d\n",
78 adapter
->locallisteninterval
);
80 psm
->locallisteninterval
=
81 cpu_to_le16(adapter
->locallisteninterval
);
82 psm
->nullpktinterval
=
83 cpu_to_le16(adapter
->nullpktinterval
);
85 cpu_to_le16(priv
->adapter
->multipledtim
);
88 case cmd_subcmd_exit_ps
:
89 lbs_pr_debug(1, "PS command:" "SubCode- Exit PS\n");
92 case cmd_subcmd_sleep_confirmed
:
93 lbs_pr_debug(1, "PS command: SubCode- sleep confirm\n");
104 static int wlan_cmd_802_11_inactivity_timeout(wlan_private
* priv
,
105 struct cmd_ds_command
*cmd
,
106 u16 cmd_action
, void *pdata_buf
)
108 u16
*timeout
= pdata_buf
;
110 cmd
->command
= cpu_to_le16(cmd_802_11_inactivity_timeout
);
112 cpu_to_le16(sizeof(struct cmd_ds_802_11_inactivity_timeout
)
115 cmd
->params
.inactivity_timeout
.action
= cpu_to_le16(cmd_action
);
118 cmd
->params
.inactivity_timeout
.timeout
=
119 cpu_to_le16(*timeout
);
121 cmd
->params
.inactivity_timeout
.timeout
= 0;
126 static int wlan_cmd_802_11_sleep_params(wlan_private
* priv
,
127 struct cmd_ds_command
*cmd
,
130 wlan_adapter
*adapter
= priv
->adapter
;
131 struct cmd_ds_802_11_sleep_params
*sp
= &cmd
->params
.sleep_params
;
136 cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params
)) +
138 cmd
->command
= cpu_to_le16(cmd_802_11_sleep_params
);
140 if (cmd_action
== cmd_act_get
) {
141 memset(&adapter
->sp
, 0, sizeof(struct sleep_params
));
142 memset(sp
, 0, sizeof(struct cmd_ds_802_11_sleep_params
));
143 sp
->action
= cpu_to_le16(cmd_action
);
144 } else if (cmd_action
== cmd_act_set
) {
145 sp
->action
= cpu_to_le16(cmd_action
);
146 sp
->error
= cpu_to_le16(adapter
->sp
.sp_error
);
147 sp
->offset
= cpu_to_le16(adapter
->sp
.sp_offset
);
148 sp
->stabletime
= cpu_to_le16(adapter
->sp
.sp_stabletime
);
149 sp
->calcontrol
= (u8
) adapter
->sp
.sp_calcontrol
;
150 sp
->externalsleepclk
= (u8
) adapter
->sp
.sp_extsleepclk
;
151 sp
->reserved
= cpu_to_le16(adapter
->sp
.sp_reserved
);
158 static int wlan_cmd_802_11_set_wep(wlan_private
* priv
,
159 struct cmd_ds_command
*cmd
,
163 struct cmd_ds_802_11_set_wep
*wep
= &cmd
->params
.wep
;
164 wlan_adapter
*adapter
= priv
->adapter
;
166 struct assoc_request
* assoc_req
= pdata_buf
;
170 cmd
->command
= cpu_to_le16(cmd_802_11_set_wep
);
171 cmd
->size
= cpu_to_le16((sizeof(struct cmd_ds_802_11_set_wep
))
174 if (cmd_act
== cmd_act_add
) {
178 lbs_pr_debug(1, "Invalid association request!");
183 wep
->action
= cpu_to_le16(cmd_act_add
);
185 /* default tx key index */
186 wep
->keyindex
= cpu_to_le16((u16
)
187 (assoc_req
->wep_tx_keyidx
&
188 (u32
)cmd_WEP_KEY_INDEX_MASK
));
190 lbs_pr_debug(1, "Tx key Index: %u\n", wep
->keyindex
);
192 /* Copy key types and material to host command structure */
193 for (i
= 0; i
< 4; i
++) {
194 struct WLAN_802_11_KEY
* pkey
= &assoc_req
->wep_keys
[i
];
198 wep
->keytype
[i
] = cmd_type_wep_40_bit
;
199 memmove(&wep
->keymaterial
[i
], pkey
->key
,
202 case KEY_LEN_WEP_104
:
203 wep
->keytype
[i
] = cmd_type_wep_104_bit
;
204 memmove(&wep
->keymaterial
[i
], pkey
->key
,
210 lbs_pr_debug(1, "Invalid WEP key %d length of %d\n",
217 } else if (cmd_act
== cmd_act_remove
) {
218 /* ACT_REMOVE clears _all_ WEP keys */
219 wep
->action
= cpu_to_le16(cmd_act_remove
);
221 /* default tx key index */
222 wep
->keyindex
= cpu_to_le16((u16
)
223 (adapter
->wep_tx_keyidx
&
224 (u32
)cmd_WEP_KEY_INDEX_MASK
));
234 static int wlan_cmd_802_11_enable_rsn(wlan_private
* priv
,
235 struct cmd_ds_command
*cmd
,
238 struct cmd_ds_802_11_enable_rsn
*penableRSN
= &cmd
->params
.enbrsn
;
239 wlan_adapter
*adapter
= priv
->adapter
;
241 cmd
->command
= cpu_to_le16(cmd_802_11_enable_rsn
);
243 cpu_to_le16(sizeof(struct cmd_ds_802_11_enable_rsn
) +
245 penableRSN
->action
= cpu_to_le16(cmd_action
);
246 if (adapter
->secinfo
.WPAenabled
|| adapter
->secinfo
.WPA2enabled
) {
247 penableRSN
->enable
= cpu_to_le16(cmd_enable_rsn
);
249 penableRSN
->enable
= cpu_to_le16(cmd_disable_rsn
);
256 static void set_one_wpa_key(struct MrvlIEtype_keyParamSet
* pkeyparamset
,
257 struct WLAN_802_11_KEY
* pkey
)
259 pkeyparamset
->keytypeid
= cpu_to_le16(pkey
->type
);
261 if (pkey
->flags
& KEY_INFO_WPA_ENABLED
) {
262 pkeyparamset
->keyinfo
= cpu_to_le16(KEY_INFO_WPA_ENABLED
);
264 pkeyparamset
->keyinfo
= cpu_to_le16(!KEY_INFO_WPA_ENABLED
);
267 if (pkey
->flags
& KEY_INFO_WPA_UNICAST
) {
268 pkeyparamset
->keyinfo
|= cpu_to_le16(KEY_INFO_WPA_UNICAST
);
269 } else if (pkey
->flags
& KEY_INFO_WPA_MCAST
) {
270 pkeyparamset
->keyinfo
|= cpu_to_le16(KEY_INFO_WPA_MCAST
);
273 pkeyparamset
->type
= cpu_to_le16(TLV_TYPE_KEY_MATERIAL
);
274 pkeyparamset
->keylen
= cpu_to_le16(pkey
->len
);
275 memcpy(pkeyparamset
->key
, pkey
->key
, pkey
->len
);
276 pkeyparamset
->length
= cpu_to_le16( sizeof(pkeyparamset
->keytypeid
)
277 + sizeof(pkeyparamset
->keyinfo
)
278 + sizeof(pkeyparamset
->keylen
)
279 + sizeof(pkeyparamset
->key
));
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 wlan_adapter
*adapter
= priv
->adapter
;
288 struct cmd_ds_802_11_key_material
*pkeymaterial
=
289 &cmd
->params
.keymaterial
;
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
300 + sizeof (pkeymaterial
->action
));
305 memset(&pkeymaterial
->keyParamSet
, 0, sizeof(pkeymaterial
->keyParamSet
));
307 if (adapter
->wpa_unicast_key
.len
) {
308 set_one_wpa_key(&pkeymaterial
->keyParamSet
[index
],
309 &adapter
->wpa_unicast_key
);
313 if (adapter
->wpa_mcast_key
.len
) {
314 set_one_wpa_key(&pkeymaterial
->keyParamSet
[index
],
315 &adapter
->wpa_mcast_key
);
319 cmd
->size
= cpu_to_le16( S_DS_GEN
320 + sizeof (pkeymaterial
->action
)
321 + index
* sizeof(struct MrvlIEtype_keyParamSet
));
330 static int wlan_cmd_802_11_reset(wlan_private
* priv
,
331 struct cmd_ds_command
*cmd
, int cmd_action
)
333 struct cmd_ds_802_11_reset
*reset
= &cmd
->params
.reset
;
335 cmd
->command
= cpu_to_le16(cmd_802_11_reset
);
336 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_reset
) + S_DS_GEN
);
337 reset
->action
= cpu_to_le16(cmd_action
);
342 static int wlan_cmd_802_11_get_log(wlan_private
* priv
,
343 struct cmd_ds_command
*cmd
)
345 cmd
->command
= cpu_to_le16(cmd_802_11_get_log
);
347 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_log
) + S_DS_GEN
);
352 static int wlan_cmd_802_11_get_stat(wlan_private
* priv
,
353 struct cmd_ds_command
*cmd
)
355 cmd
->command
= cpu_to_le16(cmd_802_11_get_stat
);
357 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat
) +
363 static int wlan_cmd_802_11_snmp_mib(wlan_private
* priv
,
364 struct cmd_ds_command
*cmd
,
366 int cmd_oid
, void *pdata_buf
)
368 struct cmd_ds_802_11_snmp_mib
*pSNMPMIB
= &cmd
->params
.smib
;
369 wlan_adapter
*adapter
= priv
->adapter
;
374 lbs_pr_debug(1, "SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid
);
376 cmd
->command
= cpu_to_le16(cmd_802_11_snmp_mib
);
378 cpu_to_le16(sizeof(struct cmd_ds_802_11_snmp_mib
) +
382 case OID_802_11_INFRASTRUCTURE_MODE
:
384 enum WLAN_802_11_NETWORK_INFRASTRUCTURE mode
=
385 (enum WLAN_802_11_NETWORK_INFRASTRUCTURE
) pdata_buf
;
386 pSNMPMIB
->querytype
= cpu_to_le16(cmd_act_set
);
387 pSNMPMIB
->oid
= cpu_to_le16((u16
) desired_bsstype_i
);
388 pSNMPMIB
->bufsize
= sizeof(u8
);
389 if (mode
== wlan802_11infrastructure
)
390 ucTemp
= SNMP_MIB_VALUE_INFRA
;
392 ucTemp
= SNMP_MIB_VALUE_ADHOC
;
394 memmove(pSNMPMIB
->value
, &ucTemp
, sizeof(u8
));
399 case OID_802_11D_ENABLE
:
403 pSNMPMIB
->oid
= cpu_to_le16((u16
) dot11d_i
);
405 if (cmd_action
== cmd_act_set
) {
406 pSNMPMIB
->querytype
= cmd_act_set
;
407 pSNMPMIB
->bufsize
= sizeof(u16
);
408 ulTemp
= *(u32
*)pdata_buf
;
409 *((unsigned short *)(pSNMPMIB
->value
)) =
410 cpu_to_le16((u16
) ulTemp
);
415 case OID_802_11_FRAGMENTATION_THRESHOLD
:
419 pSNMPMIB
->oid
= cpu_to_le16((u16
) fragthresh_i
);
421 if (cmd_action
== cmd_act_get
) {
422 pSNMPMIB
->querytype
=
423 cpu_to_le16(cmd_act_get
);
424 } else if (cmd_action
== cmd_act_set
) {
425 pSNMPMIB
->querytype
=
426 cpu_to_le16(cmd_act_set
);
428 cpu_to_le16(sizeof(u16
));
429 ulTemp
= *((u32
*) pdata_buf
);
430 *((unsigned short *)(pSNMPMIB
->value
)) =
431 cpu_to_le16((u16
) ulTemp
);
438 case OID_802_11_RTS_THRESHOLD
:
442 pSNMPMIB
->oid
= le16_to_cpu((u16
) rtsthresh_i
);
444 if (cmd_action
== cmd_act_get
) {
445 pSNMPMIB
->querytype
=
446 cpu_to_le16(cmd_act_get
);
447 } else if (cmd_action
== cmd_act_set
) {
448 pSNMPMIB
->querytype
=
449 cpu_to_le16(cmd_act_set
);
451 cpu_to_le16(sizeof(u16
));
454 *(unsigned short *)(pSNMPMIB
->value
) =
455 cpu_to_le16((u16
) ulTemp
);
460 case OID_802_11_TX_RETRYCOUNT
:
461 pSNMPMIB
->oid
= cpu_to_le16((u16
) short_retrylim_i
);
463 if (cmd_action
== cmd_act_get
) {
464 pSNMPMIB
->querytype
=
465 cpu_to_le16(cmd_act_get
);
466 } else if (cmd_action
== cmd_act_set
) {
467 pSNMPMIB
->querytype
=
468 cpu_to_le16(cmd_act_set
);
469 pSNMPMIB
->bufsize
= cpu_to_le16(sizeof(u16
));
470 *((unsigned short *)(pSNMPMIB
->value
)) =
471 cpu_to_le16((u16
) adapter
->txretrycount
);
480 "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
481 cmd
->command
, cmd
->size
, cmd
->seqnum
, cmd
->result
);
484 "SNMP_CMD: action=0x%x, oid=0x%x, oidsize=0x%x, value=0x%x\n",
485 pSNMPMIB
->querytype
, pSNMPMIB
->oid
, pSNMPMIB
->bufsize
,
486 *(u16
*) pSNMPMIB
->value
);
492 static int wlan_cmd_802_11_radio_control(wlan_private
* priv
,
493 struct cmd_ds_command
*cmd
,
496 wlan_adapter
*adapter
= priv
->adapter
;
497 struct cmd_ds_802_11_radio_control
*pradiocontrol
=
503 cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control
)) +
505 cmd
->command
= cpu_to_le16(cmd_802_11_radio_control
);
507 pradiocontrol
->action
= cpu_to_le16(cmd_action
);
509 switch (adapter
->preamble
) {
510 case cmd_type_short_preamble
:
511 pradiocontrol
->control
= cpu_to_le16(SET_SHORT_PREAMBLE
);
514 case cmd_type_long_preamble
:
515 pradiocontrol
->control
= cpu_to_le16(SET_LONG_PREAMBLE
);
518 case cmd_type_auto_preamble
:
520 pradiocontrol
->control
= cpu_to_le16(SET_AUTO_PREAMBLE
);
524 if (adapter
->radioon
)
525 pradiocontrol
->control
|= cpu_to_le16(TURN_ON_RF
);
527 pradiocontrol
->control
&= cpu_to_le16(~TURN_ON_RF
);
533 static int wlan_cmd_802_11_rf_tx_power(wlan_private
* priv
,
534 struct cmd_ds_command
*cmd
,
535 u16 cmd_action
, void *pdata_buf
)
538 struct cmd_ds_802_11_rf_tx_power
*prtp
= &cmd
->params
.txp
;
543 cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power
)) +
545 cmd
->command
= cpu_to_le16(cmd_802_11_rf_tx_power
);
546 prtp
->action
= cmd_action
;
548 lbs_pr_debug(1, "RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n", cmd
->size
,
549 cmd
->command
, prtp
->action
);
551 switch (cmd_action
) {
552 case cmd_act_tx_power_opt_get
:
553 prtp
->action
= cpu_to_le16(cmd_act_get
);
554 prtp
->currentlevel
= 0;
557 case cmd_act_tx_power_opt_set_high
:
558 prtp
->action
= cpu_to_le16(cmd_act_set
);
560 cpu_to_le16(cmd_act_tx_power_index_high
);
563 case cmd_act_tx_power_opt_set_mid
:
564 prtp
->action
= cpu_to_le16(cmd_act_set
);
566 cpu_to_le16(cmd_act_tx_power_index_mid
);
569 case cmd_act_tx_power_opt_set_low
:
570 prtp
->action
= cpu_to_le16(cmd_act_set
);
571 prtp
->currentlevel
= cpu_to_le16(*((u16
*) pdata_buf
));
578 static int wlan_cmd_802_11_rf_antenna(wlan_private
* priv
,
579 struct cmd_ds_command
*cmd
,
580 u16 cmd_action
, void *pdata_buf
)
582 struct cmd_ds_802_11_rf_antenna
*rant
= &cmd
->params
.rant
;
584 cmd
->command
= cpu_to_le16(cmd_802_11_rf_antenna
);
586 cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_antenna
) +
589 rant
->action
= cpu_to_le16(cmd_action
);
590 if ((cmd_action
== cmd_act_set_rx
) ||
591 (cmd_action
== cmd_act_set_tx
)) {
593 cpu_to_le16((u16
) (*(u32
*) pdata_buf
));
599 static int wlan_cmd_802_11_rate_adapt_rateset(wlan_private
* priv
,
600 struct cmd_ds_command
*cmd
,
603 struct cmd_ds_802_11_rate_adapt_rateset
604 *rateadapt
= &cmd
->params
.rateset
;
605 wlan_adapter
*adapter
= priv
->adapter
;
608 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset
)
610 cmd
->command
= cpu_to_le16(cmd_802_11_rate_adapt_rateset
);
614 rateadapt
->action
= cmd_action
;
615 rateadapt
->enablehwauto
= adapter
->enablehwauto
;
616 rateadapt
->bitmap
= adapter
->ratebitmap
;
622 static int wlan_cmd_802_11_data_rate(wlan_private
* priv
,
623 struct cmd_ds_command
*cmd
,
626 struct cmd_ds_802_11_data_rate
*pdatarate
= &cmd
->params
.drate
;
627 wlan_adapter
*adapter
= priv
->adapter
;
628 u16 action
= cmd_action
;
633 cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate
) +
636 cmd
->command
= cpu_to_le16(cmd_802_11_data_rate
);
638 memset(pdatarate
, 0, sizeof(struct cmd_ds_802_11_data_rate
));
640 pdatarate
->action
= cpu_to_le16(cmd_action
);
642 if (action
== cmd_act_set_tx_fix_rate
) {
643 pdatarate
->datarate
[0] = libertas_data_rate_to_index(adapter
->datarate
);
644 lbs_pr_debug(1, "Setting FW for fixed rate 0x%02X\n",
646 } else if (action
== cmd_act_set_tx_auto
) {
647 lbs_pr_debug(1, "Setting FW for AUTO rate\n");
654 static int wlan_cmd_mac_multicast_adr(wlan_private
* priv
,
655 struct cmd_ds_command
*cmd
,
658 struct cmd_ds_mac_multicast_adr
*pMCastAdr
= &cmd
->params
.madr
;
659 wlan_adapter
*adapter
= priv
->adapter
;
662 cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr
) +
664 cmd
->command
= cpu_to_le16(cmd_mac_multicast_adr
);
666 pMCastAdr
->action
= cpu_to_le16(cmd_action
);
667 pMCastAdr
->nr_of_adrs
=
668 cpu_to_le16((u16
) adapter
->nr_of_multicastmacaddr
);
669 memcpy(pMCastAdr
->maclist
, adapter
->multicastlist
,
670 adapter
->nr_of_multicastmacaddr
* ETH_ALEN
);
675 static int wlan_cmd_802_11_rf_channel(wlan_private
* priv
,
676 struct cmd_ds_command
*cmd
,
677 int option
, void *pdata_buf
)
679 struct cmd_ds_802_11_rf_channel
*rfchan
= &cmd
->params
.rfchannel
;
681 cmd
->command
= cpu_to_le16(cmd_802_11_rf_channel
);
682 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel
)
685 if (option
== cmd_opt_802_11_rf_channel_set
) {
686 rfchan
->currentchannel
= cpu_to_le16(*((u16
*) pdata_buf
));
689 rfchan
->action
= cpu_to_le16(option
);
694 static int wlan_cmd_802_11_rssi(wlan_private
* priv
,
695 struct cmd_ds_command
*cmd
)
697 wlan_adapter
*adapter
= priv
->adapter
;
699 cmd
->command
= cpu_to_le16(cmd_802_11_rssi
);
701 cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi
) + S_DS_GEN
);
702 cmd
->params
.rssi
.N
= priv
->adapter
->bcn_avg_factor
;
704 /* reset Beacon SNR/NF/RSSI values */
705 adapter
->SNR
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
706 adapter
->SNR
[TYPE_BEACON
][TYPE_AVG
] = 0;
707 adapter
->NF
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
708 adapter
->NF
[TYPE_BEACON
][TYPE_AVG
] = 0;
709 adapter
->RSSI
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
710 adapter
->RSSI
[TYPE_BEACON
][TYPE_AVG
] = 0;
715 static int wlan_cmd_reg_access(wlan_private
* priv
,
716 struct cmd_ds_command
*cmdptr
,
717 u8 cmd_action
, void *pdata_buf
)
719 struct wlan_offset_value
*offval
;
723 offval
= (struct wlan_offset_value
*)pdata_buf
;
725 switch (cmdptr
->command
) {
726 case cmd_mac_reg_access
:
728 struct cmd_ds_mac_reg_access
*macreg
;
732 (struct cmd_ds_mac_reg_access
)
735 (struct cmd_ds_mac_reg_access
*)&cmdptr
->params
.
738 macreg
->action
= cpu_to_le16(cmd_action
);
739 macreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
740 macreg
->value
= cpu_to_le32(offval
->value
);
745 case cmd_bbp_reg_access
:
747 struct cmd_ds_bbp_reg_access
*bbpreg
;
751 (struct cmd_ds_bbp_reg_access
)
754 (struct cmd_ds_bbp_reg_access
*)&cmdptr
->params
.
757 bbpreg
->action
= cpu_to_le16(cmd_action
);
758 bbpreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
759 bbpreg
->value
= (u8
) offval
->value
;
764 case cmd_rf_reg_access
:
766 struct cmd_ds_rf_reg_access
*rfreg
;
770 (struct cmd_ds_rf_reg_access
) +
773 (struct cmd_ds_rf_reg_access
*)&cmdptr
->params
.
776 rfreg
->action
= cpu_to_le16(cmd_action
);
777 rfreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
778 rfreg
->value
= (u8
) offval
->value
;
791 static int wlan_cmd_802_11_mac_address(wlan_private
* priv
,
792 struct cmd_ds_command
*cmd
,
795 wlan_adapter
*adapter
= priv
->adapter
;
797 cmd
->command
= cpu_to_le16(cmd_802_11_mac_address
);
799 cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address
) +
803 cmd
->params
.macadd
.action
= cpu_to_le16(cmd_action
);
805 if (cmd_action
== cmd_act_set
) {
806 memcpy(cmd
->params
.macadd
.macadd
,
807 adapter
->current_addr
, ETH_ALEN
);
808 lbs_dbg_hex("SET_CMD: MAC ADDRESS-", adapter
->current_addr
, 6);
814 static int wlan_cmd_802_11_eeprom_access(wlan_private
* priv
,
815 struct cmd_ds_command
*cmd
,
816 int cmd_action
, void *pdata_buf
)
818 struct wlan_ioctl_regrdwr
*ea
= pdata_buf
;
822 cmd
->command
= cpu_to_le16(cmd_802_11_eeprom_access
);
824 cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access
) +
828 cmd
->params
.rdeeprom
.action
= cpu_to_le16(ea
->action
);
829 cmd
->params
.rdeeprom
.offset
= cpu_to_le16(ea
->offset
);
830 cmd
->params
.rdeeprom
.bytecount
= cpu_to_le16(ea
->NOB
);
831 cmd
->params
.rdeeprom
.value
= 0;
836 static int wlan_cmd_bt_access(wlan_private
* priv
,
837 struct cmd_ds_command
*cmd
,
838 u16 cmd_action
, void *pdata_buf
)
840 struct cmd_ds_bt_access
*bt_access
= &cmd
->params
.bt
;
841 lbs_pr_debug(1, "BT CMD(%d)\n", cmd_action
);
843 cmd
->command
= cpu_to_le16(cmd_bt_access
);
844 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_bt_access
)
847 bt_access
->action
= cpu_to_le16(cmd_action
);
849 switch (cmd_action
) {
850 case cmd_act_bt_access_add
:
851 memcpy(bt_access
->addr1
, pdata_buf
, 2 * ETH_ALEN
);
852 lbs_dbg_hex("BT_ADD: blinded mac address-", bt_access
->addr1
, 6);
854 case cmd_act_bt_access_del
:
855 memcpy(bt_access
->addr1
, pdata_buf
, 1 * ETH_ALEN
);
856 lbs_dbg_hex("BT_DEL: blinded mac address-", bt_access
->addr1
, 6);
858 case cmd_act_bt_access_list
:
859 bt_access
->id
= cpu_to_le32(*(u32
*) pdata_buf
);
861 case cmd_act_bt_access_reset
:
869 static int wlan_cmd_fwt_access(wlan_private
* priv
,
870 struct cmd_ds_command
*cmd
,
871 u16 cmd_action
, void *pdata_buf
)
873 struct cmd_ds_fwt_access
*fwt_access
= &cmd
->params
.fwt
;
874 lbs_pr_debug(1, "FWT CMD(%d)\n", cmd_action
);
876 cmd
->command
= cpu_to_le16(cmd_fwt_access
);
877 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_fwt_access
)
882 memcpy(fwt_access
, pdata_buf
, sizeof(*fwt_access
));
884 memset(fwt_access
, 0, sizeof(*fwt_access
));
886 fwt_access
->action
= cpu_to_le16(cmd_action
);
891 static int wlan_cmd_mesh_access(wlan_private
* priv
,
892 struct cmd_ds_command
*cmd
,
893 u16 cmd_action
, void *pdata_buf
)
895 struct cmd_ds_mesh_access
*mesh_access
= &cmd
->params
.mesh
;
896 lbs_pr_debug(1, "FWT CMD(%d)\n", cmd_action
);
898 cmd
->command
= cpu_to_le16(cmd_mesh_access
);
899 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_mesh_access
)
904 memcpy(mesh_access
, pdata_buf
, sizeof(*mesh_access
));
906 memset(mesh_access
, 0, sizeof(*mesh_access
));
908 mesh_access
->action
= cpu_to_le16(cmd_action
);
913 void libertas_queue_cmd(wlan_adapter
* adapter
, struct cmd_ctrl_node
*cmdnode
, u8 addtail
)
916 struct cmd_ds_command
*cmdptr
;
921 lbs_pr_debug(1, "QUEUE_CMD: cmdnode is NULL\n");
925 cmdptr
= (struct cmd_ds_command
*)cmdnode
->bufvirtualaddr
;
927 lbs_pr_debug(1, "QUEUE_CMD: cmdptr is NULL\n");
931 /* Exit_PS command needs to be queued in the header always. */
932 if (cmdptr
->command
== cmd_802_11_ps_mode
) {
933 struct cmd_ds_802_11_ps_mode
*psm
= &cmdptr
->params
.psmode
;
934 if (psm
->action
== cmd_subcmd_exit_ps
) {
935 if (adapter
->psstate
!= PS_STATE_FULL_POWER
)
940 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
943 list_add_tail((struct list_head
*)cmdnode
,
944 &adapter
->cmdpendingq
);
946 list_add((struct list_head
*)cmdnode
, &adapter
->cmdpendingq
);
948 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
950 lbs_pr_debug(1, "QUEUE_CMD: Inserted node=0x%x, cmd=0x%x in cmdpendingq\n",
952 ((struct cmd_ds_gen
*)cmdnode
->bufvirtualaddr
)->command
);
960 * TODO: Fix the issue when DownloadcommandToStation is being called the
961 * second time when the command timesout. All the cmdptr->xxx are in little
962 * endian and therefore all the comparissions will fail.
963 * For now - we are not performing the endian conversion the second time - but
964 * for PS and DEEP_SLEEP we need to worry
966 static int DownloadcommandToStation(wlan_private
* priv
,
967 struct cmd_ctrl_node
*cmdnode
)
970 struct cmd_ds_command
*cmdptr
;
971 wlan_adapter
*adapter
= priv
->adapter
;
978 if (!adapter
|| !cmdnode
) {
979 lbs_pr_debug(1, "DNLD_CMD: adapter = %#x, cmdnode = %#x\n",
980 (int)adapter
, (int)cmdnode
);
982 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
983 __libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
984 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
990 cmdptr
= (struct cmd_ds_command
*)cmdnode
->bufvirtualaddr
;
993 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
994 if (!cmdptr
|| !cmdptr
->size
) {
995 lbs_pr_debug(1, "DNLD_CMD: cmdptr is Null or cmd size is Zero, "
997 __libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
998 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1003 adapter
->cur_cmd
= cmdnode
;
1004 adapter
->cur_cmd_retcode
= 0;
1005 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1006 lbs_pr_debug(1, "DNLD_CMD:: Before download, size of cmd = %d\n",
1009 cmdsize
= cmdptr
->size
;
1011 command
= cpu_to_le16(cmdptr
->command
);
1013 cmdnode
->cmdwaitqwoken
= 0;
1014 cmdsize
= cpu_to_le16(cmdsize
);
1016 ret
= libertas_sbi_host_to_card(priv
, MVMS_CMD
, (u8
*) cmdptr
, cmdsize
);
1019 lbs_pr_debug(1, "DNLD_CMD: Host to Card failed\n");
1020 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1021 __libertas_cleanup_and_insert_cmd(priv
, adapter
->cur_cmd
);
1022 adapter
->cur_cmd
= NULL
;
1023 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1028 lbs_pr_debug(1, "DNLD_CMD: Sent command 0x%x @ %lu\n", command
, jiffies
);
1029 lbs_dbg_hex("DNLD_CMD: command", cmdnode
->bufvirtualaddr
, cmdsize
);
1031 /* Setup the timer after transmit command */
1032 if (command
== cmd_802_11_scan
1033 || command
== cmd_802_11_authenticate
1034 || command
== cmd_802_11_associate
)
1035 mod_timer(&adapter
->command_timer
, jiffies
+ (10*HZ
));
1037 mod_timer(&adapter
->command_timer
, jiffies
+ (5*HZ
));
1046 static int wlan_cmd_mac_control(wlan_private
* priv
,
1047 struct cmd_ds_command
*cmd
)
1049 struct cmd_ds_mac_control
*mac
= &cmd
->params
.macctrl
;
1053 cmd
->command
= cpu_to_le16(cmd_mac_control
);
1055 cpu_to_le16(sizeof(struct cmd_ds_mac_control
) + S_DS_GEN
);
1056 mac
->action
= cpu_to_le16(priv
->adapter
->currentpacketfilter
);
1058 lbs_pr_debug(1, "wlan_cmd_mac_control(): action=0x%X size=%d\n",
1059 mac
->action
, cmd
->size
);
1066 * This function inserts command node to cmdfreeq
1067 * after cleans it. Requires adapter->driver_lock held.
1069 void __libertas_cleanup_and_insert_cmd(wlan_private
* priv
, struct cmd_ctrl_node
*ptempcmd
)
1071 wlan_adapter
*adapter
= priv
->adapter
;
1076 cleanup_cmdnode(ptempcmd
);
1077 list_add_tail((struct list_head
*)ptempcmd
, &adapter
->cmdfreeq
);
1082 void libertas_cleanup_and_insert_cmd(wlan_private
* priv
, struct cmd_ctrl_node
*ptempcmd
)
1084 unsigned long flags
;
1086 spin_lock_irqsave(&priv
->adapter
->driver_lock
, flags
);
1087 __libertas_cleanup_and_insert_cmd(priv
, ptempcmd
);
1088 spin_unlock_irqrestore(&priv
->adapter
->driver_lock
, flags
);
1091 int libertas_set_radio_control(wlan_private
* priv
)
1097 ret
= libertas_prepare_and_send_command(priv
,
1098 cmd_802_11_radio_control
,
1100 cmd_option_waitforrsp
, 0, NULL
);
1102 lbs_pr_debug(1, "RADIO_SET: on or off: 0x%X, preamble = 0x%X\n",
1103 priv
->adapter
->radioon
, priv
->adapter
->preamble
);
1109 int libertas_set_mac_packet_filter(wlan_private
* priv
)
1115 lbs_pr_debug(1, "libertas_set_mac_packet_filter value = %x\n",
1116 priv
->adapter
->currentpacketfilter
);
1118 /* Send MAC control command to station */
1119 ret
= libertas_prepare_and_send_command(priv
,
1120 cmd_mac_control
, 0, 0, 0, NULL
);
1127 * @brief This function prepare the command before send to firmware.
1129 * @param priv A pointer to wlan_private structure
1130 * @param cmd_no command number
1131 * @param cmd_action command action: GET or SET
1132 * @param wait_option wait option: wait response or not
1133 * @param cmd_oid cmd oid: treated as sub command
1134 * @param pdata_buf A pointer to informaion buffer
1137 int libertas_prepare_and_send_command(wlan_private
* priv
,
1140 u16 wait_option
, u32 cmd_oid
, void *pdata_buf
)
1143 wlan_adapter
*adapter
= priv
->adapter
;
1144 struct cmd_ctrl_node
*cmdnode
;
1145 struct cmd_ds_command
*cmdptr
;
1146 unsigned long flags
;
1151 lbs_pr_debug(1, "PREP_CMD: adapter is Null\n");
1156 if (adapter
->surpriseremoved
) {
1157 lbs_pr_debug(1, "PREP_CMD: Card is Removed\n");
1162 cmdnode
= libertas_get_free_cmd_ctrl_node(priv
);
1164 if (cmdnode
== NULL
) {
1165 lbs_pr_debug(1, "PREP_CMD: No free cmdnode\n");
1167 /* Wake up main thread to execute next command */
1168 wake_up_interruptible(&priv
->mainthread
.waitq
);
1173 libertas_set_cmd_ctrl_node(priv
, cmdnode
, cmd_oid
, wait_option
, pdata_buf
);
1175 cmdptr
= (struct cmd_ds_command
*)cmdnode
->bufvirtualaddr
;
1177 lbs_pr_debug(1, "PREP_CMD: Val of cmd ptr =0x%x, command=0x%X\n",
1178 (u32
) cmdptr
, cmd_no
);
1181 lbs_pr_debug(1, "PREP_CMD: bufvirtualaddr of cmdnode is NULL\n");
1182 libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
1187 /* Set sequence number, command and INT option */
1189 cmdptr
->seqnum
= cpu_to_le16(adapter
->seqnum
);
1191 cmdptr
->command
= cmd_no
;
1195 case cmd_get_hw_spec
:
1196 ret
= wlan_cmd_hw_spec(priv
, cmdptr
);
1198 case cmd_802_11_ps_mode
:
1199 ret
= wlan_cmd_802_11_ps_mode(priv
, cmdptr
, cmd_action
);
1202 case cmd_802_11_scan
:
1203 ret
= libertas_cmd_80211_scan(priv
, cmdptr
, pdata_buf
);
1206 case cmd_mac_control
:
1207 ret
= wlan_cmd_mac_control(priv
, cmdptr
);
1210 case cmd_802_11_associate
:
1211 case cmd_802_11_reassociate
:
1212 ret
= libertas_cmd_80211_associate(priv
, cmdptr
, pdata_buf
);
1215 case cmd_802_11_deauthenticate
:
1216 ret
= libertas_cmd_80211_deauthenticate(priv
, cmdptr
);
1219 case cmd_802_11_set_wep
:
1220 ret
= wlan_cmd_802_11_set_wep(priv
, cmdptr
, cmd_action
, pdata_buf
);
1223 case cmd_802_11_ad_hoc_start
:
1224 ret
= libertas_cmd_80211_ad_hoc_start(priv
, cmdptr
, pdata_buf
);
1229 case cmd_802_11_reset
:
1230 ret
= wlan_cmd_802_11_reset(priv
, cmdptr
, cmd_action
);
1233 case cmd_802_11_get_log
:
1234 ret
= wlan_cmd_802_11_get_log(priv
, cmdptr
);
1237 case cmd_802_11_authenticate
:
1238 ret
= libertas_cmd_80211_authenticate(priv
, cmdptr
, pdata_buf
);
1241 case cmd_802_11_get_stat
:
1242 ret
= wlan_cmd_802_11_get_stat(priv
, cmdptr
);
1245 case cmd_802_11_snmp_mib
:
1246 ret
= wlan_cmd_802_11_snmp_mib(priv
, cmdptr
,
1247 cmd_action
, cmd_oid
, pdata_buf
);
1250 case cmd_mac_reg_access
:
1251 case cmd_bbp_reg_access
:
1252 case cmd_rf_reg_access
:
1253 ret
= wlan_cmd_reg_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1256 case cmd_802_11_rf_channel
:
1257 ret
= wlan_cmd_802_11_rf_channel(priv
, cmdptr
,
1258 cmd_action
, pdata_buf
);
1261 case cmd_802_11_rf_tx_power
:
1262 ret
= wlan_cmd_802_11_rf_tx_power(priv
, cmdptr
,
1263 cmd_action
, pdata_buf
);
1266 case cmd_802_11_radio_control
:
1267 ret
= wlan_cmd_802_11_radio_control(priv
, cmdptr
, cmd_action
);
1270 case cmd_802_11_rf_antenna
:
1271 ret
= wlan_cmd_802_11_rf_antenna(priv
, cmdptr
,
1272 cmd_action
, pdata_buf
);
1275 case cmd_802_11_data_rate
:
1276 ret
= wlan_cmd_802_11_data_rate(priv
, cmdptr
, cmd_action
);
1278 case cmd_802_11_rate_adapt_rateset
:
1279 ret
= wlan_cmd_802_11_rate_adapt_rateset(priv
,
1280 cmdptr
, cmd_action
);
1283 case cmd_mac_multicast_adr
:
1284 ret
= wlan_cmd_mac_multicast_adr(priv
, cmdptr
, cmd_action
);
1287 case cmd_802_11_ad_hoc_join
:
1288 ret
= libertas_cmd_80211_ad_hoc_join(priv
, cmdptr
, pdata_buf
);
1291 case cmd_802_11_rssi
:
1292 ret
= wlan_cmd_802_11_rssi(priv
, cmdptr
);
1295 case cmd_802_11_ad_hoc_stop
:
1296 ret
= libertas_cmd_80211_ad_hoc_stop(priv
, cmdptr
);
1299 case cmd_802_11_enable_rsn
:
1300 ret
= wlan_cmd_802_11_enable_rsn(priv
, cmdptr
, cmd_action
);
1303 case cmd_802_11_key_material
:
1304 ret
= wlan_cmd_802_11_key_material(priv
, cmdptr
,
1305 cmd_action
, cmd_oid
,
1309 case cmd_802_11_pairwise_tsc
:
1311 case cmd_802_11_group_tsc
:
1314 case cmd_802_11_mac_address
:
1315 ret
= wlan_cmd_802_11_mac_address(priv
, cmdptr
, cmd_action
);
1318 case cmd_802_11_eeprom_access
:
1319 ret
= wlan_cmd_802_11_eeprom_access(priv
, cmdptr
,
1320 cmd_action
, pdata_buf
);
1323 case cmd_802_11_set_afc
:
1324 case cmd_802_11_get_afc
:
1326 cmdptr
->command
= cpu_to_le16(cmd_no
);
1328 cpu_to_le16(sizeof(struct cmd_ds_802_11_afc
) +
1331 memmove(&cmdptr
->params
.afc
,
1332 pdata_buf
, sizeof(struct cmd_ds_802_11_afc
));
1337 case cmd_802_11d_domain_info
:
1338 ret
= libertas_cmd_802_11d_domain_info(priv
, cmdptr
,
1339 cmd_no
, cmd_action
);
1342 case cmd_802_11_sleep_params
:
1343 ret
= wlan_cmd_802_11_sleep_params(priv
, cmdptr
, cmd_action
);
1345 case cmd_802_11_inactivity_timeout
:
1346 ret
= wlan_cmd_802_11_inactivity_timeout(priv
, cmdptr
,
1347 cmd_action
, pdata_buf
);
1348 libertas_set_cmd_ctrl_node(priv
, cmdnode
, 0, 0, pdata_buf
);
1351 case cmd_802_11_tpc_cfg
:
1352 cmdptr
->command
= cpu_to_le16(cmd_802_11_tpc_cfg
);
1354 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg
) +
1357 memmove(&cmdptr
->params
.tpccfg
,
1358 pdata_buf
, sizeof(struct cmd_ds_802_11_tpc_cfg
));
1362 case cmd_802_11_led_gpio_ctrl
:
1364 struct mrvlietypes_ledgpio
*gpio
=
1365 (struct mrvlietypes_ledgpio
*)
1366 cmdptr
->params
.ledgpio
.data
;
1368 memmove(&cmdptr
->params
.ledgpio
,
1370 sizeof(struct cmd_ds_802_11_led_ctrl
));
1373 cpu_to_le16(cmd_802_11_led_gpio_ctrl
);
1375 #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1377 cpu_to_le16(gpio
->header
.len
+ S_DS_GEN
+
1378 ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN
);
1379 gpio
->header
.len
= cpu_to_le16(gpio
->header
.len
);
1384 case cmd_802_11_pwr_cfg
:
1385 cmdptr
->command
= cpu_to_le16(cmd_802_11_pwr_cfg
);
1387 cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg
) +
1389 memmove(&cmdptr
->params
.pwrcfg
, pdata_buf
,
1390 sizeof(struct cmd_ds_802_11_pwr_cfg
));
1395 ret
= wlan_cmd_bt_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1398 case cmd_fwt_access
:
1399 ret
= wlan_cmd_fwt_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1402 case cmd_mesh_access
:
1403 ret
= wlan_cmd_mesh_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1407 cmdptr
->command
= cpu_to_le16(cmd_get_tsf
);
1409 cpu_to_le16(sizeof(struct cmd_ds_get_tsf
)
1413 case cmd_802_11_tx_rate_query
:
1415 cpu_to_le16(cmd_802_11_tx_rate_query
);
1417 cpu_to_le16(sizeof(struct cmd_tx_rate_query
) +
1419 adapter
->txrate
= 0;
1423 lbs_pr_debug(1, "PREP_CMD: unknown command- %#x\n", cmd_no
);
1428 /* return error, since the command preparation failed */
1430 lbs_pr_debug(1, "PREP_CMD: command preparation failed\n");
1431 libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
1436 cmdnode
->cmdwaitqwoken
= 0;
1438 libertas_queue_cmd(adapter
, cmdnode
, 1);
1439 adapter
->nr_cmd_pending
++;
1440 wake_up_interruptible(&priv
->mainthread
.waitq
);
1442 if (wait_option
& cmd_option_waitforrsp
) {
1443 lbs_pr_debug(1, "PREP_CMD: Wait for CMD response\n");
1445 wait_event_interruptible(cmdnode
->cmdwait_q
,
1446 cmdnode
->cmdwaitqwoken
);
1449 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1450 if (adapter
->cur_cmd_retcode
) {
1451 lbs_pr_debug(1, "PREP_CMD: command failed with return code=%d\n",
1452 adapter
->cur_cmd_retcode
);
1453 adapter
->cur_cmd_retcode
= 0;
1456 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1464 * @brief This function allocates the command buffer and link
1465 * it to command free queue.
1467 * @param priv A pointer to wlan_private structure
1470 int libertas_allocate_cmd_buffer(wlan_private
* priv
)
1475 struct cmd_ctrl_node
*tempcmd_array
;
1476 u8
*ptempvirtualaddr
;
1477 wlan_adapter
*adapter
= priv
->adapter
;
1481 /* Allocate and initialize cmdCtrlNode */
1482 ulbufsize
= sizeof(struct cmd_ctrl_node
) * MRVDRV_NUM_OF_CMD_BUFFER
;
1484 if (!(tempcmd_array
= kmalloc(ulbufsize
, GFP_KERNEL
))) {
1486 "ALLOC_CMD_BUF: failed to allocate tempcmd_array\n");
1491 adapter
->cmd_array
= tempcmd_array
;
1492 memset(adapter
->cmd_array
, 0, ulbufsize
);
1494 /* Allocate and initialize command buffers */
1495 ulbufsize
= MRVDRV_SIZE_OF_CMD_BUFFER
;
1496 for (i
= 0; i
< MRVDRV_NUM_OF_CMD_BUFFER
; i
++) {
1497 if (!(ptempvirtualaddr
= kmalloc(ulbufsize
, GFP_KERNEL
))) {
1499 "ALLOC_CMD_BUF: ptempvirtualaddr: out of memory\n");
1504 memset(ptempvirtualaddr
, 0, ulbufsize
);
1506 /* Update command buffer virtual */
1507 tempcmd_array
[i
].bufvirtualaddr
= ptempvirtualaddr
;
1510 for (i
= 0; i
< MRVDRV_NUM_OF_CMD_BUFFER
; i
++) {
1511 init_waitqueue_head(&tempcmd_array
[i
].cmdwait_q
);
1512 libertas_cleanup_and_insert_cmd(priv
, &tempcmd_array
[i
]);
1522 * @brief This function frees the command buffer.
1524 * @param priv A pointer to wlan_private structure
1527 int libertas_free_cmd_buffer(wlan_private
* priv
)
1531 struct cmd_ctrl_node
*tempcmd_array
;
1532 wlan_adapter
*adapter
= priv
->adapter
;
1536 /* need to check if cmd array is allocated or not */
1537 if (adapter
->cmd_array
== NULL
) {
1538 lbs_pr_debug(1, "FREE_CMD_BUF: cmd_array is Null\n");
1542 tempcmd_array
= adapter
->cmd_array
;
1544 /* Release shared memory buffers */
1545 ulbufsize
= MRVDRV_SIZE_OF_CMD_BUFFER
;
1546 for (i
= 0; i
< MRVDRV_NUM_OF_CMD_BUFFER
; i
++) {
1547 if (tempcmd_array
[i
].bufvirtualaddr
) {
1548 lbs_pr_debug(1, "Free all the array\n");
1549 kfree(tempcmd_array
[i
].bufvirtualaddr
);
1550 tempcmd_array
[i
].bufvirtualaddr
= NULL
;
1554 /* Release cmd_ctrl_node */
1555 if (adapter
->cmd_array
) {
1556 lbs_pr_debug(1, "Free cmd_array\n");
1557 kfree(adapter
->cmd_array
);
1558 adapter
->cmd_array
= NULL
;
1567 * @brief This function gets a free command node if available in
1568 * command free queue.
1570 * @param priv A pointer to wlan_private structure
1571 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1573 struct cmd_ctrl_node
*libertas_get_free_cmd_ctrl_node(wlan_private
* priv
)
1575 struct cmd_ctrl_node
*tempnode
;
1576 wlan_adapter
*adapter
= priv
->adapter
;
1577 unsigned long flags
;
1582 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1584 if (!list_empty(&adapter
->cmdfreeq
)) {
1585 tempnode
= (struct cmd_ctrl_node
*)adapter
->cmdfreeq
.next
;
1586 list_del((struct list_head
*)tempnode
);
1588 lbs_pr_debug(1, "GET_CMD_NODE: cmd_ctrl_node is not available\n");
1592 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1595 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode available\n");
1596 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode Address = %p\n",
1598 cleanup_cmdnode(tempnode
);
1605 * @brief This function cleans command node.
1607 * @param ptempnode A pointer to cmdCtrlNode structure
1610 static void cleanup_cmdnode(struct cmd_ctrl_node
*ptempnode
)
1614 ptempnode
->cmdwaitqwoken
= 1;
1615 wake_up_interruptible(&ptempnode
->cmdwait_q
);
1616 ptempnode
->status
= 0;
1617 ptempnode
->cmd_oid
= (u32
) 0;
1618 ptempnode
->wait_option
= 0;
1619 ptempnode
->pdata_buf
= NULL
;
1621 if (ptempnode
->bufvirtualaddr
!= NULL
)
1622 memset(ptempnode
->bufvirtualaddr
, 0, MRVDRV_SIZE_OF_CMD_BUFFER
);
1627 * @brief This function initializes the command node.
1629 * @param priv A pointer to wlan_private structure
1630 * @param ptempnode A pointer to cmd_ctrl_node structure
1631 * @param cmd_oid cmd oid: treated as sub command
1632 * @param wait_option wait option: wait response or not
1633 * @param pdata_buf A pointer to informaion buffer
1636 void libertas_set_cmd_ctrl_node(wlan_private
* priv
,
1637 struct cmd_ctrl_node
*ptempnode
,
1638 u32 cmd_oid
, u16 wait_option
, void *pdata_buf
)
1645 ptempnode
->cmd_oid
= cmd_oid
;
1646 ptempnode
->wait_option
= wait_option
;
1647 ptempnode
->pdata_buf
= pdata_buf
;
1653 * @brief This function executes next command in command
1654 * pending queue. It will put fimware back to PS mode
1657 * @param priv A pointer to wlan_private structure
1660 int libertas_execute_next_command(wlan_private
* priv
)
1662 wlan_adapter
*adapter
= priv
->adapter
;
1663 struct cmd_ctrl_node
*cmdnode
= NULL
;
1664 struct cmd_ds_command
*cmdptr
;
1665 unsigned long flags
;
1668 lbs_pr_debug(1, "libertas_execute_next_command\n");
1670 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1672 if (adapter
->cur_cmd
) {
1673 lbs_pr_alert( "EXEC_NEXT_CMD: there is command in processing!\n");
1674 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1679 if (!list_empty(&adapter
->cmdpendingq
)) {
1680 cmdnode
= (struct cmd_ctrl_node
*)
1681 adapter
->cmdpendingq
.next
;
1684 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1688 "EXEC_NEXT_CMD: Got next command from cmdpendingq\n");
1689 cmdptr
= (struct cmd_ds_command
*)cmdnode
->bufvirtualaddr
;
1691 if (is_command_allowed_in_ps(cmdptr
->command
)) {
1692 if ((adapter
->psstate
== PS_STATE_SLEEP
)
1693 || (adapter
->psstate
== PS_STATE_PRE_SLEEP
)
1696 "EXEC_NEXT_CMD: Cannot send cmd 0x%x in psstate %d\n",
1697 cmdptr
->command
, adapter
->psstate
);
1701 lbs_pr_debug(1, "EXEC_NEXT_CMD: OK to send command "
1702 "0x%x in psstate %d\n",
1703 cmdptr
->command
, adapter
->psstate
);
1704 } else if (adapter
->psstate
!= PS_STATE_FULL_POWER
) {
1706 * 1. Non-PS command:
1707 * Queue it. set needtowakeup to TRUE if current state
1708 * is SLEEP, otherwise call libertas_ps_wakeup to send Exit_PS.
1709 * 2. PS command but not Exit_PS:
1711 * 3. PS command Exit_PS:
1712 * Set needtowakeup to TRUE if current state is SLEEP,
1713 * otherwise send this command down to firmware
1716 if (cmdptr
->command
!=
1717 cpu_to_le16(cmd_802_11_ps_mode
)) {
1718 /* Prepare to send Exit PS,
1719 * this non PS command will be sent later */
1720 if ((adapter
->psstate
== PS_STATE_SLEEP
)
1721 || (adapter
->psstate
== PS_STATE_PRE_SLEEP
)
1723 /* w/ new scheme, it will not reach here.
1724 since it is blocked in main_thread. */
1725 adapter
->needtowakeup
= 1;
1727 libertas_ps_wakeup(priv
, 0);
1733 * PS command. Ignore it if it is not Exit_PS.
1734 * otherwise send it down immediately.
1736 struct cmd_ds_802_11_ps_mode
*psm
=
1737 &cmdptr
->params
.psmode
;
1740 "EXEC_NEXT_CMD: PS cmd- action=0x%x\n",
1743 cpu_to_le16(cmd_subcmd_exit_ps
)) {
1745 "EXEC_NEXT_CMD: Ignore Enter PS cmd\n");
1746 list_del((struct list_head
*)cmdnode
);
1747 libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
1753 if ((adapter
->psstate
== PS_STATE_SLEEP
)
1754 || (adapter
->psstate
== PS_STATE_PRE_SLEEP
)
1757 "EXEC_NEXT_CMD: Ignore ExitPS cmd in sleep\n");
1758 list_del((struct list_head
*)cmdnode
);
1759 libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
1760 adapter
->needtowakeup
= 1;
1767 "EXEC_NEXT_CMD: Sending Exit_PS down...\n");
1770 list_del((struct list_head
*)cmdnode
);
1771 lbs_pr_debug(1, "EXEC_NEXT_CMD: Sending 0x%04X command\n",
1773 DownloadcommandToStation(priv
, cmdnode
);
1776 * check if in power save mode, if yes, put the device back
1779 if ((adapter
->psmode
!= wlan802_11powermodecam
) &&
1780 (adapter
->psstate
== PS_STATE_FULL_POWER
) &&
1781 (adapter
->connect_status
== libertas_connected
)) {
1782 if (adapter
->secinfo
.WPAenabled
1783 || adapter
->secinfo
.WPA2enabled
) {
1784 /* check for valid WPA group keys */
1785 if (adapter
->wpa_mcast_key
.len
1786 || adapter
->wpa_unicast_key
.len
) {
1788 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1789 " go back to PS_SLEEP");
1790 libertas_ps_sleep(priv
, 0);
1794 "EXEC_NEXT_CMD: command PendQ is empty,"
1795 " go back to PS_SLEEP");
1796 libertas_ps_sleep(priv
, 0);
1806 void libertas_send_iwevcustom_event(wlan_private
* priv
, s8
* str
)
1808 union iwreq_data iwrq
;
1813 memset(&iwrq
, 0, sizeof(union iwreq_data
));
1814 memset(buf
, 0, sizeof(buf
));
1816 snprintf(buf
, sizeof(buf
) - 1, "%s", str
);
1818 iwrq
.data
.length
= strlen(buf
) + 1 + IW_EV_LCP_LEN
;
1820 /* Send Event to upper layer */
1821 lbs_pr_debug(1, "Event Indication string = %s\n",
1823 lbs_pr_debug(1, "Event Indication String length = %d\n", iwrq
.data
.length
);
1825 lbs_pr_debug(1, "Sending wireless event IWEVCUSTOM for %s\n", str
);
1826 wireless_send_event(priv
->wlan_dev
.netdev
, IWEVCUSTOM
, &iwrq
, buf
);
1832 static int sendconfirmsleep(wlan_private
* priv
, u8
* cmdptr
, u16 size
)
1834 unsigned long flags
;
1835 wlan_adapter
*adapter
= priv
->adapter
;
1840 lbs_pr_debug(1, "SEND_SLEEPC_CMD: Before download, size of cmd = %d\n",
1843 lbs_dbg_hex("SEND_SLEEPC_CMD: Sleep confirm command", cmdptr
, size
);
1845 ret
= libertas_sbi_host_to_card(priv
, MVMS_CMD
, cmdptr
, size
);
1846 priv
->wlan_dev
.dnld_sent
= DNLD_RES_RECEIVED
;
1848 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1849 if (adapter
->intcounter
|| adapter
->currenttxskb
)
1850 lbs_pr_debug(1, "SEND_SLEEPC_CMD: intcounter=%d currenttxskb=%p\n",
1851 adapter
->intcounter
, adapter
->currenttxskb
);
1852 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1856 "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
1858 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1859 if (!adapter
->intcounter
) {
1860 adapter
->psstate
= PS_STATE_SLEEP
;
1862 lbs_pr_debug(1, "SEND_SLEEPC_CMD: After sent,IntC=%d\n",
1863 adapter
->intcounter
);
1865 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1867 lbs_pr_debug(1, "SEND_SLEEPC_CMD: Sent Confirm Sleep command\n");
1868 lbs_pr_debug(1, "+");
1875 void libertas_ps_sleep(wlan_private
* priv
, int wait_option
)
1881 * PS is currently supported only in Infrastructure mode
1882 * Remove this check if it is to be supported in IBSS mode also
1885 libertas_prepare_and_send_command(priv
, cmd_802_11_ps_mode
,
1886 cmd_subcmd_enter_ps
, wait_option
, 0, NULL
);
1893 * @brief This function sends Eixt_PS command to firmware.
1895 * @param priv A pointer to wlan_private structure
1896 * @param wait_option wait response or not
1899 void libertas_ps_wakeup(wlan_private
* priv
, int wait_option
)
1901 enum WLAN_802_11_POWER_MODE Localpsmode
;
1905 Localpsmode
= wlan802_11powermodecam
;
1907 lbs_pr_debug(1, "Exit_PS: Localpsmode = %d\n", Localpsmode
);
1909 libertas_prepare_and_send_command(priv
, cmd_802_11_ps_mode
,
1911 wait_option
, 0, &Localpsmode
);
1918 * @brief This function checks condition and prepares to
1919 * send sleep confirm command to firmware if ok.
1921 * @param priv A pointer to wlan_private structure
1922 * @param psmode Power Saving mode
1925 void libertas_ps_confirm_sleep(wlan_private
* priv
, u16 psmode
)
1927 unsigned long flags
=0;
1928 wlan_adapter
*adapter
= priv
->adapter
;
1933 if (priv
->wlan_dev
.dnld_sent
) {
1935 lbs_pr_debug(1, "D");
1938 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1939 if (adapter
->cur_cmd
) {
1941 lbs_pr_debug(1, "C");
1943 if (adapter
->intcounter
> 0) {
1945 lbs_pr_debug(1, "I%d", adapter
->intcounter
);
1947 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1950 lbs_pr_debug(1, "Sending libertas_ps_confirm_sleep\n");
1951 sendconfirmsleep(priv
, (u8
*) & adapter
->libertas_ps_confirm_sleep
,
1952 sizeof(struct PS_CMD_ConfirmSleep
));
1954 lbs_pr_debug(1, "Sleep Confirm has been delayed\n");