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
;
47 lbs_deb_enter(LBS_DEB_CMD
);
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
);
54 lbs_deb_leave(LBS_DEB_CMD
);
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
;
66 lbs_deb_enter(LBS_DEB_CMD
);
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_deb_cmd("PS command:" "SubCode- Enter PS\n");
77 lbs_deb_cmd("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_deb_cmd("PS command:" "SubCode- Exit PS\n");
92 case cmd_subcmd_sleep_confirmed
:
93 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
100 lbs_deb_leave(LBS_DEB_CMD
);
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
;
133 lbs_deb_enter(LBS_DEB_CMD
);
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
);
154 lbs_deb_leave(LBS_DEB_CMD
);
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
;
168 lbs_deb_enter(LBS_DEB_CMD
);
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_deb_cmd("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_deb_cmd("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_deb_cmd("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
));
230 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
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
;
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
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
));
326 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
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
;
372 lbs_deb_enter(LBS_DEB_CMD
);
374 lbs_deb_cmd("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 u8 mode
= (u8
) (size_t) pdata_buf
;
385 pSNMPMIB
->querytype
= cpu_to_le16(cmd_act_set
);
386 pSNMPMIB
->oid
= cpu_to_le16((u16
) desired_bsstype_i
);
387 pSNMPMIB
->bufsize
= sizeof(u8
);
388 if (mode
== IW_MODE_ADHOC
) {
389 ucTemp
= SNMP_MIB_VALUE_ADHOC
;
391 /* Infra and Auto modes */
392 ucTemp
= SNMP_MIB_VALUE_INFRA
;
395 memmove(pSNMPMIB
->value
, &ucTemp
, sizeof(u8
));
400 case OID_802_11D_ENABLE
:
404 pSNMPMIB
->oid
= cpu_to_le16((u16
) dot11d_i
);
406 if (cmd_action
== cmd_act_set
) {
407 pSNMPMIB
->querytype
= cmd_act_set
;
408 pSNMPMIB
->bufsize
= sizeof(u16
);
409 ulTemp
= *(u32
*)pdata_buf
;
410 *((unsigned short *)(pSNMPMIB
->value
)) =
411 cpu_to_le16((u16
) ulTemp
);
416 case OID_802_11_FRAGMENTATION_THRESHOLD
:
420 pSNMPMIB
->oid
= cpu_to_le16((u16
) fragthresh_i
);
422 if (cmd_action
== cmd_act_get
) {
423 pSNMPMIB
->querytype
=
424 cpu_to_le16(cmd_act_get
);
425 } else if (cmd_action
== cmd_act_set
) {
426 pSNMPMIB
->querytype
=
427 cpu_to_le16(cmd_act_set
);
429 cpu_to_le16(sizeof(u16
));
430 ulTemp
= *((u32
*) pdata_buf
);
431 *((unsigned short *)(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
=
447 cpu_to_le16(cmd_act_get
);
448 } else if (cmd_action
== cmd_act_set
) {
449 pSNMPMIB
->querytype
=
450 cpu_to_le16(cmd_act_set
);
452 cpu_to_le16(sizeof(u16
));
455 *(unsigned short *)(pSNMPMIB
->value
) =
456 cpu_to_le16((u16
) ulTemp
);
461 case OID_802_11_TX_RETRYCOUNT
:
462 pSNMPMIB
->oid
= cpu_to_le16((u16
) short_retrylim_i
);
464 if (cmd_action
== cmd_act_get
) {
465 pSNMPMIB
->querytype
=
466 cpu_to_le16(cmd_act_get
);
467 } else if (cmd_action
== cmd_act_set
) {
468 pSNMPMIB
->querytype
=
469 cpu_to_le16(cmd_act_set
);
470 pSNMPMIB
->bufsize
= cpu_to_le16(sizeof(u16
));
471 *((unsigned short *)(pSNMPMIB
->value
)) =
472 cpu_to_le16((u16
) adapter
->txretrycount
);
481 "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
482 cmd
->command
, cmd
->size
, cmd
->seqnum
, cmd
->result
);
485 "SNMP_CMD: action=0x%x, oid=0x%x, oidsize=0x%x, value=0x%x\n",
486 pSNMPMIB
->querytype
, pSNMPMIB
->oid
, pSNMPMIB
->bufsize
,
487 *(u16
*) pSNMPMIB
->value
);
489 lbs_deb_leave(LBS_DEB_CMD
);
493 static int wlan_cmd_802_11_radio_control(wlan_private
* priv
,
494 struct cmd_ds_command
*cmd
,
497 wlan_adapter
*adapter
= priv
->adapter
;
498 struct cmd_ds_802_11_radio_control
*pradiocontrol
=
501 lbs_deb_enter(LBS_DEB_CMD
);
504 cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control
)) +
506 cmd
->command
= cpu_to_le16(cmd_802_11_radio_control
);
508 pradiocontrol
->action
= cpu_to_le16(cmd_action
);
510 switch (adapter
->preamble
) {
511 case cmd_type_short_preamble
:
512 pradiocontrol
->control
= cpu_to_le16(SET_SHORT_PREAMBLE
);
515 case cmd_type_long_preamble
:
516 pradiocontrol
->control
= cpu_to_le16(SET_LONG_PREAMBLE
);
519 case cmd_type_auto_preamble
:
521 pradiocontrol
->control
= cpu_to_le16(SET_AUTO_PREAMBLE
);
525 if (adapter
->radioon
)
526 pradiocontrol
->control
|= cpu_to_le16(TURN_ON_RF
);
528 pradiocontrol
->control
&= cpu_to_le16(~TURN_ON_RF
);
530 lbs_deb_leave(LBS_DEB_CMD
);
534 static int wlan_cmd_802_11_rf_tx_power(wlan_private
* priv
,
535 struct cmd_ds_command
*cmd
,
536 u16 cmd_action
, void *pdata_buf
)
539 struct cmd_ds_802_11_rf_tx_power
*prtp
= &cmd
->params
.txp
;
541 lbs_deb_enter(LBS_DEB_CMD
);
544 cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power
)) +
546 cmd
->command
= cpu_to_le16(cmd_802_11_rf_tx_power
);
547 prtp
->action
= cmd_action
;
549 lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n", cmd
->size
,
550 cmd
->command
, prtp
->action
);
552 switch (cmd_action
) {
553 case cmd_act_tx_power_opt_get
:
554 prtp
->action
= cpu_to_le16(cmd_act_get
);
555 prtp
->currentlevel
= 0;
558 case cmd_act_tx_power_opt_set_high
:
559 prtp
->action
= cpu_to_le16(cmd_act_set
);
561 cpu_to_le16(cmd_act_tx_power_index_high
);
564 case cmd_act_tx_power_opt_set_mid
:
565 prtp
->action
= cpu_to_le16(cmd_act_set
);
567 cpu_to_le16(cmd_act_tx_power_index_mid
);
570 case cmd_act_tx_power_opt_set_low
:
571 prtp
->action
= cpu_to_le16(cmd_act_set
);
572 prtp
->currentlevel
= cpu_to_le16(*((u16
*) pdata_buf
));
576 lbs_deb_leave(LBS_DEB_CMD
);
580 static int wlan_cmd_802_11_rf_antenna(wlan_private
* priv
,
581 struct cmd_ds_command
*cmd
,
582 u16 cmd_action
, void *pdata_buf
)
584 struct cmd_ds_802_11_rf_antenna
*rant
= &cmd
->params
.rant
;
586 cmd
->command
= cpu_to_le16(cmd_802_11_rf_antenna
);
588 cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_antenna
) +
591 rant
->action
= cpu_to_le16(cmd_action
);
592 if ((cmd_action
== cmd_act_set_rx
) ||
593 (cmd_action
== cmd_act_set_tx
)) {
595 cpu_to_le16((u16
) (*(u32
*) pdata_buf
));
601 static int wlan_cmd_802_11_rate_adapt_rateset(wlan_private
* priv
,
602 struct cmd_ds_command
*cmd
,
605 struct cmd_ds_802_11_rate_adapt_rateset
606 *rateadapt
= &cmd
->params
.rateset
;
607 wlan_adapter
*adapter
= priv
->adapter
;
610 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset
)
612 cmd
->command
= cpu_to_le16(cmd_802_11_rate_adapt_rateset
);
614 lbs_deb_enter(LBS_DEB_CMD
);
616 rateadapt
->action
= cmd_action
;
617 rateadapt
->enablehwauto
= adapter
->enablehwauto
;
618 rateadapt
->bitmap
= adapter
->ratebitmap
;
620 lbs_deb_leave(LBS_DEB_CMD
);
624 static int wlan_cmd_802_11_data_rate(wlan_private
* priv
,
625 struct cmd_ds_command
*cmd
,
628 struct cmd_ds_802_11_data_rate
*pdatarate
= &cmd
->params
.drate
;
629 wlan_adapter
*adapter
= priv
->adapter
;
630 u16 action
= cmd_action
;
632 lbs_deb_enter(LBS_DEB_CMD
);
635 cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate
) +
638 cmd
->command
= cpu_to_le16(cmd_802_11_data_rate
);
640 memset(pdatarate
, 0, sizeof(struct cmd_ds_802_11_data_rate
));
642 pdatarate
->action
= cpu_to_le16(cmd_action
);
644 if (action
== cmd_act_set_tx_fix_rate
) {
645 pdatarate
->datarate
[0] = libertas_data_rate_to_index(adapter
->datarate
);
646 lbs_deb_cmd("Setting FW for fixed rate 0x%02X\n",
648 } else if (action
== cmd_act_set_tx_auto
) {
649 lbs_deb_cmd("Setting FW for AUTO rate\n");
652 lbs_deb_leave(LBS_DEB_CMD
);
656 static int wlan_cmd_mac_multicast_adr(wlan_private
* priv
,
657 struct cmd_ds_command
*cmd
,
660 struct cmd_ds_mac_multicast_adr
*pMCastAdr
= &cmd
->params
.madr
;
661 wlan_adapter
*adapter
= priv
->adapter
;
664 cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr
) +
666 cmd
->command
= cpu_to_le16(cmd_mac_multicast_adr
);
668 pMCastAdr
->action
= cpu_to_le16(cmd_action
);
669 pMCastAdr
->nr_of_adrs
=
670 cpu_to_le16((u16
) adapter
->nr_of_multicastmacaddr
);
671 memcpy(pMCastAdr
->maclist
, adapter
->multicastlist
,
672 adapter
->nr_of_multicastmacaddr
* ETH_ALEN
);
677 static int wlan_cmd_802_11_rf_channel(wlan_private
* priv
,
678 struct cmd_ds_command
*cmd
,
679 int option
, void *pdata_buf
)
681 struct cmd_ds_802_11_rf_channel
*rfchan
= &cmd
->params
.rfchannel
;
683 cmd
->command
= cpu_to_le16(cmd_802_11_rf_channel
);
684 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel
)
687 if (option
== cmd_opt_802_11_rf_channel_set
) {
688 rfchan
->currentchannel
= cpu_to_le16(*((u16
*) pdata_buf
));
691 rfchan
->action
= cpu_to_le16(option
);
696 static int wlan_cmd_802_11_rssi(wlan_private
* priv
,
697 struct cmd_ds_command
*cmd
)
699 wlan_adapter
*adapter
= priv
->adapter
;
701 cmd
->command
= cpu_to_le16(cmd_802_11_rssi
);
703 cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi
) + S_DS_GEN
);
704 cmd
->params
.rssi
.N
= priv
->adapter
->bcn_avg_factor
;
706 /* reset Beacon SNR/NF/RSSI values */
707 adapter
->SNR
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
708 adapter
->SNR
[TYPE_BEACON
][TYPE_AVG
] = 0;
709 adapter
->NF
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
710 adapter
->NF
[TYPE_BEACON
][TYPE_AVG
] = 0;
711 adapter
->RSSI
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
712 adapter
->RSSI
[TYPE_BEACON
][TYPE_AVG
] = 0;
717 static int wlan_cmd_reg_access(wlan_private
* priv
,
718 struct cmd_ds_command
*cmdptr
,
719 u8 cmd_action
, void *pdata_buf
)
721 struct wlan_offset_value
*offval
;
723 lbs_deb_enter(LBS_DEB_CMD
);
725 offval
= (struct wlan_offset_value
*)pdata_buf
;
727 switch (cmdptr
->command
) {
728 case cmd_mac_reg_access
:
730 struct cmd_ds_mac_reg_access
*macreg
;
734 (struct cmd_ds_mac_reg_access
)
737 (struct cmd_ds_mac_reg_access
*)&cmdptr
->params
.
740 macreg
->action
= cpu_to_le16(cmd_action
);
741 macreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
742 macreg
->value
= cpu_to_le32(offval
->value
);
747 case cmd_bbp_reg_access
:
749 struct cmd_ds_bbp_reg_access
*bbpreg
;
753 (struct cmd_ds_bbp_reg_access
)
756 (struct cmd_ds_bbp_reg_access
*)&cmdptr
->params
.
759 bbpreg
->action
= cpu_to_le16(cmd_action
);
760 bbpreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
761 bbpreg
->value
= (u8
) offval
->value
;
766 case cmd_rf_reg_access
:
768 struct cmd_ds_rf_reg_access
*rfreg
;
772 (struct cmd_ds_rf_reg_access
) +
775 (struct cmd_ds_rf_reg_access
*)&cmdptr
->params
.
778 rfreg
->action
= cpu_to_le16(cmd_action
);
779 rfreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
780 rfreg
->value
= (u8
) offval
->value
;
789 lbs_deb_leave(LBS_DEB_CMD
);
793 static int wlan_cmd_802_11_mac_address(wlan_private
* priv
,
794 struct cmd_ds_command
*cmd
,
797 wlan_adapter
*adapter
= priv
->adapter
;
799 cmd
->command
= cpu_to_le16(cmd_802_11_mac_address
);
801 cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address
) +
805 cmd
->params
.macadd
.action
= cpu_to_le16(cmd_action
);
807 if (cmd_action
== cmd_act_set
) {
808 memcpy(cmd
->params
.macadd
.macadd
,
809 adapter
->current_addr
, ETH_ALEN
);
810 lbs_dbg_hex("SET_CMD: MAC ADDRESS-", adapter
->current_addr
, 6);
816 static int wlan_cmd_802_11_eeprom_access(wlan_private
* priv
,
817 struct cmd_ds_command
*cmd
,
818 int cmd_action
, void *pdata_buf
)
820 struct wlan_ioctl_regrdwr
*ea
= pdata_buf
;
822 lbs_deb_enter(LBS_DEB_CMD
);
824 cmd
->command
= cpu_to_le16(cmd_802_11_eeprom_access
);
826 cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access
) +
830 cmd
->params
.rdeeprom
.action
= cpu_to_le16(ea
->action
);
831 cmd
->params
.rdeeprom
.offset
= cpu_to_le16(ea
->offset
);
832 cmd
->params
.rdeeprom
.bytecount
= cpu_to_le16(ea
->NOB
);
833 cmd
->params
.rdeeprom
.value
= 0;
838 static int wlan_cmd_bt_access(wlan_private
* priv
,
839 struct cmd_ds_command
*cmd
,
840 u16 cmd_action
, void *pdata_buf
)
842 struct cmd_ds_bt_access
*bt_access
= &cmd
->params
.bt
;
843 lbs_deb_cmd("BT CMD(%d)\n", cmd_action
);
845 cmd
->command
= cpu_to_le16(cmd_bt_access
);
846 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_bt_access
)
849 bt_access
->action
= cpu_to_le16(cmd_action
);
851 switch (cmd_action
) {
852 case cmd_act_bt_access_add
:
853 memcpy(bt_access
->addr1
, pdata_buf
, 2 * ETH_ALEN
);
854 lbs_dbg_hex("BT_ADD: blinded mac address-", bt_access
->addr1
, 6);
856 case cmd_act_bt_access_del
:
857 memcpy(bt_access
->addr1
, pdata_buf
, 1 * ETH_ALEN
);
858 lbs_dbg_hex("BT_DEL: blinded mac address-", bt_access
->addr1
, 6);
860 case cmd_act_bt_access_list
:
861 bt_access
->id
= cpu_to_le32(*(u32
*) pdata_buf
);
863 case cmd_act_bt_access_reset
:
871 static int wlan_cmd_fwt_access(wlan_private
* priv
,
872 struct cmd_ds_command
*cmd
,
873 u16 cmd_action
, void *pdata_buf
)
875 struct cmd_ds_fwt_access
*fwt_access
= &cmd
->params
.fwt
;
876 lbs_deb_cmd("FWT CMD(%d)\n", cmd_action
);
878 cmd
->command
= cpu_to_le16(cmd_fwt_access
);
879 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_fwt_access
)
884 memcpy(fwt_access
, pdata_buf
, sizeof(*fwt_access
));
886 memset(fwt_access
, 0, sizeof(*fwt_access
));
888 fwt_access
->action
= cpu_to_le16(cmd_action
);
893 static int wlan_cmd_mesh_access(wlan_private
* priv
,
894 struct cmd_ds_command
*cmd
,
895 u16 cmd_action
, void *pdata_buf
)
897 struct cmd_ds_mesh_access
*mesh_access
= &cmd
->params
.mesh
;
898 lbs_deb_cmd("FWT CMD(%d)\n", cmd_action
);
900 cmd
->command
= cpu_to_le16(cmd_mesh_access
);
901 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_mesh_access
)
906 memcpy(mesh_access
, pdata_buf
, sizeof(*mesh_access
));
908 memset(mesh_access
, 0, sizeof(*mesh_access
));
910 mesh_access
->action
= cpu_to_le16(cmd_action
);
915 void libertas_queue_cmd(wlan_adapter
* adapter
, struct cmd_ctrl_node
*cmdnode
, u8 addtail
)
918 struct cmd_ds_command
*cmdptr
;
920 lbs_deb_enter(LBS_DEB_CMD
);
923 lbs_deb_cmd("QUEUE_CMD: cmdnode is NULL\n");
927 cmdptr
= (struct cmd_ds_command
*)cmdnode
->bufvirtualaddr
;
929 lbs_deb_cmd("QUEUE_CMD: cmdptr is NULL\n");
933 /* Exit_PS command needs to be queued in the header always. */
934 if (cmdptr
->command
== cmd_802_11_ps_mode
) {
935 struct cmd_ds_802_11_ps_mode
*psm
= &cmdptr
->params
.psmode
;
936 if (psm
->action
== cmd_subcmd_exit_ps
) {
937 if (adapter
->psstate
!= PS_STATE_FULL_POWER
)
942 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
945 list_add_tail((struct list_head
*)cmdnode
,
946 &adapter
->cmdpendingq
);
948 list_add((struct list_head
*)cmdnode
, &adapter
->cmdpendingq
);
950 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
952 lbs_deb_cmd("QUEUE_CMD: Inserted node=%p, cmd=0x%x in cmdpendingq\n",
954 ((struct cmd_ds_gen
*)cmdnode
->bufvirtualaddr
)->command
);
957 lbs_deb_leave(LBS_DEB_CMD
);
961 * TODO: Fix the issue when DownloadcommandToStation is being called the
962 * second time when the command timesout. All the cmdptr->xxx are in little
963 * endian and therefore all the comparissions will fail.
964 * For now - we are not performing the endian conversion the second time - but
965 * for PS and DEEP_SLEEP we need to worry
967 static int DownloadcommandToStation(wlan_private
* priv
,
968 struct cmd_ctrl_node
*cmdnode
)
971 struct cmd_ds_command
*cmdptr
;
972 wlan_adapter
*adapter
= priv
->adapter
;
977 lbs_deb_enter(LBS_DEB_CMD
);
979 if (!adapter
|| !cmdnode
) {
980 lbs_deb_cmd("DNLD_CMD: adapter = %p, cmdnode = %p\n",
983 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
984 __libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
985 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
991 cmdptr
= (struct cmd_ds_command
*)cmdnode
->bufvirtualaddr
;
994 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
995 if (!cmdptr
|| !cmdptr
->size
) {
996 lbs_deb_cmd("DNLD_CMD: cmdptr is Null or cmd size is Zero, "
998 __libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
999 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1004 adapter
->cur_cmd
= cmdnode
;
1005 adapter
->cur_cmd_retcode
= 0;
1006 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1007 lbs_deb_cmd("DNLD_CMD:: Before download, size of cmd = %d\n",
1010 cmdsize
= cmdptr
->size
;
1012 command
= cpu_to_le16(cmdptr
->command
);
1014 cmdnode
->cmdwaitqwoken
= 0;
1015 cmdsize
= cpu_to_le16(cmdsize
);
1017 ret
= libertas_sbi_host_to_card(priv
, MVMS_CMD
, (u8
*) cmdptr
, cmdsize
);
1020 lbs_deb_cmd("DNLD_CMD: Host to Card failed\n");
1021 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1022 __libertas_cleanup_and_insert_cmd(priv
, adapter
->cur_cmd
);
1023 adapter
->cur_cmd
= NULL
;
1024 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1029 lbs_deb_cmd("DNLD_CMD: Sent command 0x%x @ %lu\n", command
, jiffies
);
1030 lbs_dbg_hex("DNLD_CMD: command", cmdnode
->bufvirtualaddr
, cmdsize
);
1032 /* Setup the timer after transmit command */
1033 if (command
== cmd_802_11_scan
1034 || command
== cmd_802_11_authenticate
1035 || command
== cmd_802_11_associate
)
1036 mod_timer(&adapter
->command_timer
, jiffies
+ (10*HZ
));
1038 mod_timer(&adapter
->command_timer
, jiffies
+ (5*HZ
));
1043 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
1047 static int wlan_cmd_mac_control(wlan_private
* priv
,
1048 struct cmd_ds_command
*cmd
)
1050 struct cmd_ds_mac_control
*mac
= &cmd
->params
.macctrl
;
1052 lbs_deb_enter(LBS_DEB_CMD
);
1054 cmd
->command
= cpu_to_le16(cmd_mac_control
);
1056 cpu_to_le16(sizeof(struct cmd_ds_mac_control
) + S_DS_GEN
);
1057 mac
->action
= cpu_to_le16(priv
->adapter
->currentpacketfilter
);
1059 lbs_deb_cmd("wlan_cmd_mac_control(): action=0x%X size=%d\n",
1060 mac
->action
, cmd
->size
);
1062 lbs_deb_leave(LBS_DEB_CMD
);
1067 * This function inserts command node to cmdfreeq
1068 * after cleans it. Requires adapter->driver_lock held.
1070 void __libertas_cleanup_and_insert_cmd(wlan_private
* priv
, struct cmd_ctrl_node
*ptempcmd
)
1072 wlan_adapter
*adapter
= priv
->adapter
;
1077 cleanup_cmdnode(ptempcmd
);
1078 list_add_tail((struct list_head
*)ptempcmd
, &adapter
->cmdfreeq
);
1083 void libertas_cleanup_and_insert_cmd(wlan_private
* priv
, struct cmd_ctrl_node
*ptempcmd
)
1085 unsigned long flags
;
1087 spin_lock_irqsave(&priv
->adapter
->driver_lock
, flags
);
1088 __libertas_cleanup_and_insert_cmd(priv
, ptempcmd
);
1089 spin_unlock_irqrestore(&priv
->adapter
->driver_lock
, flags
);
1092 int libertas_set_radio_control(wlan_private
* priv
)
1096 lbs_deb_enter(LBS_DEB_CMD
);
1098 ret
= libertas_prepare_and_send_command(priv
,
1099 cmd_802_11_radio_control
,
1101 cmd_option_waitforrsp
, 0, NULL
);
1103 lbs_deb_cmd("RADIO_SET: on or off: 0x%X, preamble = 0x%X\n",
1104 priv
->adapter
->radioon
, priv
->adapter
->preamble
);
1106 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
1110 int libertas_set_mac_packet_filter(wlan_private
* priv
)
1114 lbs_deb_enter(LBS_DEB_CMD
);
1116 lbs_deb_cmd("libertas_set_mac_packet_filter value = %x\n",
1117 priv
->adapter
->currentpacketfilter
);
1119 /* Send MAC control command to station */
1120 ret
= libertas_prepare_and_send_command(priv
,
1121 cmd_mac_control
, 0, 0, 0, NULL
);
1123 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
1128 * @brief This function prepare the command before send to firmware.
1130 * @param priv A pointer to wlan_private structure
1131 * @param cmd_no command number
1132 * @param cmd_action command action: GET or SET
1133 * @param wait_option wait option: wait response or not
1134 * @param cmd_oid cmd oid: treated as sub command
1135 * @param pdata_buf A pointer to informaion buffer
1138 int libertas_prepare_and_send_command(wlan_private
* priv
,
1141 u16 wait_option
, u32 cmd_oid
, void *pdata_buf
)
1144 wlan_adapter
*adapter
= priv
->adapter
;
1145 struct cmd_ctrl_node
*cmdnode
;
1146 struct cmd_ds_command
*cmdptr
;
1147 unsigned long flags
;
1149 lbs_deb_enter(LBS_DEB_CMD
);
1152 lbs_deb_cmd("PREP_CMD: adapter is Null\n");
1157 if (adapter
->surpriseremoved
) {
1158 lbs_deb_cmd("PREP_CMD: Card is Removed\n");
1163 cmdnode
= libertas_get_free_cmd_ctrl_node(priv
);
1165 if (cmdnode
== NULL
) {
1166 lbs_deb_cmd("PREP_CMD: No free cmdnode\n");
1168 /* Wake up main thread to execute next command */
1169 wake_up_interruptible(&priv
->mainthread
.waitq
);
1174 libertas_set_cmd_ctrl_node(priv
, cmdnode
, cmd_oid
, wait_option
, pdata_buf
);
1176 cmdptr
= (struct cmd_ds_command
*)cmdnode
->bufvirtualaddr
;
1178 lbs_deb_cmd("PREP_CMD: Val of cmd ptr=%p, command=0x%X\n",
1182 lbs_deb_cmd("PREP_CMD: bufvirtualaddr of cmdnode is NULL\n");
1183 libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
1188 /* Set sequence number, command and INT option */
1190 cmdptr
->seqnum
= cpu_to_le16(adapter
->seqnum
);
1192 cmdptr
->command
= cmd_no
;
1196 case cmd_get_hw_spec
:
1197 ret
= wlan_cmd_hw_spec(priv
, cmdptr
);
1199 case cmd_802_11_ps_mode
:
1200 ret
= wlan_cmd_802_11_ps_mode(priv
, cmdptr
, cmd_action
);
1203 case cmd_802_11_scan
:
1204 ret
= libertas_cmd_80211_scan(priv
, cmdptr
, pdata_buf
);
1207 case cmd_mac_control
:
1208 ret
= wlan_cmd_mac_control(priv
, cmdptr
);
1211 case cmd_802_11_associate
:
1212 case cmd_802_11_reassociate
:
1213 ret
= libertas_cmd_80211_associate(priv
, cmdptr
, pdata_buf
);
1216 case cmd_802_11_deauthenticate
:
1217 ret
= libertas_cmd_80211_deauthenticate(priv
, cmdptr
);
1220 case cmd_802_11_set_wep
:
1221 ret
= wlan_cmd_802_11_set_wep(priv
, cmdptr
, cmd_action
, pdata_buf
);
1224 case cmd_802_11_ad_hoc_start
:
1225 ret
= libertas_cmd_80211_ad_hoc_start(priv
, cmdptr
, pdata_buf
);
1230 case cmd_802_11_reset
:
1231 ret
= wlan_cmd_802_11_reset(priv
, cmdptr
, cmd_action
);
1234 case cmd_802_11_get_log
:
1235 ret
= wlan_cmd_802_11_get_log(priv
, cmdptr
);
1238 case cmd_802_11_authenticate
:
1239 ret
= libertas_cmd_80211_authenticate(priv
, cmdptr
, pdata_buf
);
1242 case cmd_802_11_get_stat
:
1243 ret
= wlan_cmd_802_11_get_stat(priv
, cmdptr
);
1246 case cmd_802_11_snmp_mib
:
1247 ret
= wlan_cmd_802_11_snmp_mib(priv
, cmdptr
,
1248 cmd_action
, cmd_oid
, pdata_buf
);
1251 case cmd_mac_reg_access
:
1252 case cmd_bbp_reg_access
:
1253 case cmd_rf_reg_access
:
1254 ret
= wlan_cmd_reg_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1257 case cmd_802_11_rf_channel
:
1258 ret
= wlan_cmd_802_11_rf_channel(priv
, cmdptr
,
1259 cmd_action
, pdata_buf
);
1262 case cmd_802_11_rf_tx_power
:
1263 ret
= wlan_cmd_802_11_rf_tx_power(priv
, cmdptr
,
1264 cmd_action
, pdata_buf
);
1267 case cmd_802_11_radio_control
:
1268 ret
= wlan_cmd_802_11_radio_control(priv
, cmdptr
, cmd_action
);
1271 case cmd_802_11_rf_antenna
:
1272 ret
= wlan_cmd_802_11_rf_antenna(priv
, cmdptr
,
1273 cmd_action
, pdata_buf
);
1276 case cmd_802_11_data_rate
:
1277 ret
= wlan_cmd_802_11_data_rate(priv
, cmdptr
, cmd_action
);
1279 case cmd_802_11_rate_adapt_rateset
:
1280 ret
= wlan_cmd_802_11_rate_adapt_rateset(priv
,
1281 cmdptr
, cmd_action
);
1284 case cmd_mac_multicast_adr
:
1285 ret
= wlan_cmd_mac_multicast_adr(priv
, cmdptr
, cmd_action
);
1288 case cmd_802_11_ad_hoc_join
:
1289 ret
= libertas_cmd_80211_ad_hoc_join(priv
, cmdptr
, pdata_buf
);
1292 case cmd_802_11_rssi
:
1293 ret
= wlan_cmd_802_11_rssi(priv
, cmdptr
);
1296 case cmd_802_11_ad_hoc_stop
:
1297 ret
= libertas_cmd_80211_ad_hoc_stop(priv
, cmdptr
);
1300 case cmd_802_11_enable_rsn
:
1301 ret
= wlan_cmd_802_11_enable_rsn(priv
, cmdptr
, cmd_action
);
1304 case cmd_802_11_key_material
:
1305 ret
= wlan_cmd_802_11_key_material(priv
, cmdptr
,
1306 cmd_action
, cmd_oid
,
1310 case cmd_802_11_pairwise_tsc
:
1312 case cmd_802_11_group_tsc
:
1315 case cmd_802_11_mac_address
:
1316 ret
= wlan_cmd_802_11_mac_address(priv
, cmdptr
, cmd_action
);
1319 case cmd_802_11_eeprom_access
:
1320 ret
= wlan_cmd_802_11_eeprom_access(priv
, cmdptr
,
1321 cmd_action
, pdata_buf
);
1324 case cmd_802_11_set_afc
:
1325 case cmd_802_11_get_afc
:
1327 cmdptr
->command
= cpu_to_le16(cmd_no
);
1329 cpu_to_le16(sizeof(struct cmd_ds_802_11_afc
) +
1332 memmove(&cmdptr
->params
.afc
,
1333 pdata_buf
, sizeof(struct cmd_ds_802_11_afc
));
1338 case cmd_802_11d_domain_info
:
1339 ret
= libertas_cmd_802_11d_domain_info(priv
, cmdptr
,
1340 cmd_no
, cmd_action
);
1343 case cmd_802_11_sleep_params
:
1344 ret
= wlan_cmd_802_11_sleep_params(priv
, cmdptr
, cmd_action
);
1346 case cmd_802_11_inactivity_timeout
:
1347 ret
= wlan_cmd_802_11_inactivity_timeout(priv
, cmdptr
,
1348 cmd_action
, pdata_buf
);
1349 libertas_set_cmd_ctrl_node(priv
, cmdnode
, 0, 0, pdata_buf
);
1352 case cmd_802_11_tpc_cfg
:
1353 cmdptr
->command
= cpu_to_le16(cmd_802_11_tpc_cfg
);
1355 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg
) +
1358 memmove(&cmdptr
->params
.tpccfg
,
1359 pdata_buf
, sizeof(struct cmd_ds_802_11_tpc_cfg
));
1363 case cmd_802_11_led_gpio_ctrl
:
1365 struct mrvlietypes_ledgpio
*gpio
=
1366 (struct mrvlietypes_ledgpio
*)
1367 cmdptr
->params
.ledgpio
.data
;
1369 memmove(&cmdptr
->params
.ledgpio
,
1371 sizeof(struct cmd_ds_802_11_led_ctrl
));
1374 cpu_to_le16(cmd_802_11_led_gpio_ctrl
);
1376 #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1378 cpu_to_le16(gpio
->header
.len
+ S_DS_GEN
+
1379 ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN
);
1380 gpio
->header
.len
= cpu_to_le16(gpio
->header
.len
);
1385 case cmd_802_11_pwr_cfg
:
1386 cmdptr
->command
= cpu_to_le16(cmd_802_11_pwr_cfg
);
1388 cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg
) +
1390 memmove(&cmdptr
->params
.pwrcfg
, pdata_buf
,
1391 sizeof(struct cmd_ds_802_11_pwr_cfg
));
1396 ret
= wlan_cmd_bt_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1399 case cmd_fwt_access
:
1400 ret
= wlan_cmd_fwt_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1403 case cmd_mesh_access
:
1404 ret
= wlan_cmd_mesh_access(priv
, cmdptr
, cmd_action
, pdata_buf
);
1408 cmdptr
->command
= cpu_to_le16(cmd_get_tsf
);
1410 cpu_to_le16(sizeof(struct cmd_ds_get_tsf
)
1414 case cmd_802_11_tx_rate_query
:
1416 cpu_to_le16(cmd_802_11_tx_rate_query
);
1418 cpu_to_le16(sizeof(struct cmd_tx_rate_query
) +
1420 adapter
->txrate
= 0;
1424 lbs_deb_cmd("PREP_CMD: unknown command- %#x\n", cmd_no
);
1429 /* return error, since the command preparation failed */
1431 lbs_deb_cmd("PREP_CMD: command preparation failed\n");
1432 libertas_cleanup_and_insert_cmd(priv
, cmdnode
);
1437 cmdnode
->cmdwaitqwoken
= 0;
1439 libertas_queue_cmd(adapter
, cmdnode
, 1);
1440 adapter
->nr_cmd_pending
++;
1441 wake_up_interruptible(&priv
->mainthread
.waitq
);
1443 if (wait_option
& cmd_option_waitforrsp
) {
1444 lbs_deb_cmd("PREP_CMD: Wait for CMD response\n");
1446 wait_event_interruptible(cmdnode
->cmdwait_q
,
1447 cmdnode
->cmdwaitqwoken
);
1450 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1451 if (adapter
->cur_cmd_retcode
) {
1452 lbs_deb_cmd("PREP_CMD: command failed with return code=%d\n",
1453 adapter
->cur_cmd_retcode
);
1454 adapter
->cur_cmd_retcode
= 0;
1457 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1460 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
1465 * @brief This function allocates the command buffer and link
1466 * it to command free queue.
1468 * @param priv A pointer to wlan_private structure
1471 int libertas_allocate_cmd_buffer(wlan_private
* priv
)
1476 struct cmd_ctrl_node
*tempcmd_array
;
1477 u8
*ptempvirtualaddr
;
1478 wlan_adapter
*adapter
= priv
->adapter
;
1480 lbs_deb_enter(LBS_DEB_CMD
);
1482 /* Allocate and initialize cmdCtrlNode */
1483 ulbufsize
= sizeof(struct cmd_ctrl_node
) * MRVDRV_NUM_OF_CMD_BUFFER
;
1485 if (!(tempcmd_array
= kzalloc(ulbufsize
, GFP_KERNEL
))) {
1487 "ALLOC_CMD_BUF: failed to allocate tempcmd_array\n");
1491 adapter
->cmd_array
= tempcmd_array
;
1493 /* Allocate and initialize command buffers */
1494 ulbufsize
= MRVDRV_SIZE_OF_CMD_BUFFER
;
1495 for (i
= 0; i
< MRVDRV_NUM_OF_CMD_BUFFER
; i
++) {
1496 if (!(ptempvirtualaddr
= kzalloc(ulbufsize
, GFP_KERNEL
))) {
1498 "ALLOC_CMD_BUF: ptempvirtualaddr: out of memory\n");
1503 /* Update command buffer virtual */
1504 tempcmd_array
[i
].bufvirtualaddr
= ptempvirtualaddr
;
1507 for (i
= 0; i
< MRVDRV_NUM_OF_CMD_BUFFER
; i
++) {
1508 init_waitqueue_head(&tempcmd_array
[i
].cmdwait_q
);
1509 libertas_cleanup_and_insert_cmd(priv
, &tempcmd_array
[i
]);
1515 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
1520 * @brief This function frees the command buffer.
1522 * @param priv A pointer to wlan_private structure
1525 int libertas_free_cmd_buffer(wlan_private
* priv
)
1529 struct cmd_ctrl_node
*tempcmd_array
;
1530 wlan_adapter
*adapter
= priv
->adapter
;
1532 lbs_deb_enter(LBS_DEB_CMD
);
1534 /* need to check if cmd array is allocated or not */
1535 if (adapter
->cmd_array
== NULL
) {
1536 lbs_deb_cmd("FREE_CMD_BUF: cmd_array is Null\n");
1540 tempcmd_array
= adapter
->cmd_array
;
1542 /* Release shared memory buffers */
1543 ulbufsize
= MRVDRV_SIZE_OF_CMD_BUFFER
;
1544 for (i
= 0; i
< MRVDRV_NUM_OF_CMD_BUFFER
; i
++) {
1545 if (tempcmd_array
[i
].bufvirtualaddr
) {
1546 lbs_deb_cmd("Free all the array\n");
1547 kfree(tempcmd_array
[i
].bufvirtualaddr
);
1548 tempcmd_array
[i
].bufvirtualaddr
= NULL
;
1552 /* Release cmd_ctrl_node */
1553 if (adapter
->cmd_array
) {
1554 lbs_deb_cmd("Free cmd_array\n");
1555 kfree(adapter
->cmd_array
);
1556 adapter
->cmd_array
= NULL
;
1560 lbs_deb_leave(LBS_DEB_CMD
);
1565 * @brief This function gets a free command node if available in
1566 * command free queue.
1568 * @param priv A pointer to wlan_private structure
1569 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1571 struct cmd_ctrl_node
*libertas_get_free_cmd_ctrl_node(wlan_private
* priv
)
1573 struct cmd_ctrl_node
*tempnode
;
1574 wlan_adapter
*adapter
= priv
->adapter
;
1575 unsigned long flags
;
1580 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1582 if (!list_empty(&adapter
->cmdfreeq
)) {
1583 tempnode
= (struct cmd_ctrl_node
*)adapter
->cmdfreeq
.next
;
1584 list_del((struct list_head
*)tempnode
);
1586 lbs_deb_cmd("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1590 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1594 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode available\n");
1595 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
)
1640 lbs_deb_enter(LBS_DEB_CMD
);
1645 ptempnode
->cmd_oid
= cmd_oid
;
1646 ptempnode
->wait_option
= wait_option
;
1647 ptempnode
->pdata_buf
= pdata_buf
;
1649 lbs_deb_leave(LBS_DEB_CMD
);
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_deb_cmd("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_deb_cmd("EXEC_NEXT_CMD: OK to send command "
1702 "0x%x in psstate %d\n",
1703 cmdptr
->command
, adapter
->psstate
);
1704 } else if (adapter
->psstate
!= PS_STATE_FULL_POWER
) {
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_deb_cmd("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
;
1811 lbs_deb_enter(LBS_DEB_CMD
);
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_deb_cmd("Event Indication string = %s\n",
1823 lbs_deb_cmd("Event Indication String length = %d\n", iwrq
.data
.length
);
1825 lbs_deb_cmd("Sending wireless event IWEVCUSTOM for %s\n", str
);
1826 wireless_send_event(priv
->wlan_dev
.netdev
, IWEVCUSTOM
, &iwrq
, buf
);
1828 lbs_deb_leave(LBS_DEB_CMD
);
1831 static int sendconfirmsleep(wlan_private
* priv
, u8
* cmdptr
, u16 size
)
1833 unsigned long flags
;
1834 wlan_adapter
*adapter
= priv
->adapter
;
1837 lbs_deb_enter(LBS_DEB_CMD
);
1839 lbs_deb_cmd("SEND_SLEEPC_CMD: Before download, size of cmd = %d\n",
1842 lbs_dbg_hex("SEND_SLEEPC_CMD: Sleep confirm command", cmdptr
, size
);
1844 ret
= libertas_sbi_host_to_card(priv
, MVMS_CMD
, cmdptr
, size
);
1845 priv
->wlan_dev
.dnld_sent
= DNLD_RES_RECEIVED
;
1847 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1848 if (adapter
->intcounter
|| adapter
->currenttxskb
)
1849 lbs_deb_cmd("SEND_SLEEPC_CMD: intcounter=%d currenttxskb=%p\n",
1850 adapter
->intcounter
, adapter
->currenttxskb
);
1851 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1855 "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
1857 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1858 if (!adapter
->intcounter
) {
1859 adapter
->psstate
= PS_STATE_SLEEP
;
1861 lbs_deb_cmd("SEND_SLEEPC_CMD: After sent,IntC=%d\n",
1862 adapter
->intcounter
);
1864 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1866 lbs_deb_cmd("SEND_SLEEPC_CMD: Sent Confirm Sleep command\n");
1870 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
1874 void libertas_ps_sleep(wlan_private
* priv
, int wait_option
)
1876 lbs_deb_enter(LBS_DEB_CMD
);
1879 * PS is currently supported only in Infrastructure mode
1880 * Remove this check if it is to be supported in IBSS mode also
1883 libertas_prepare_and_send_command(priv
, cmd_802_11_ps_mode
,
1884 cmd_subcmd_enter_ps
, wait_option
, 0, NULL
);
1886 lbs_deb_leave(LBS_DEB_CMD
);
1890 * @brief This function sends Eixt_PS command to firmware.
1892 * @param priv A pointer to wlan_private structure
1893 * @param wait_option wait response or not
1896 void libertas_ps_wakeup(wlan_private
* priv
, int wait_option
)
1898 enum WLAN_802_11_POWER_MODE Localpsmode
;
1900 lbs_deb_enter(LBS_DEB_CMD
);
1902 Localpsmode
= wlan802_11powermodecam
;
1904 lbs_deb_cmd("Exit_PS: Localpsmode = %d\n", Localpsmode
);
1906 libertas_prepare_and_send_command(priv
, cmd_802_11_ps_mode
,
1908 wait_option
, 0, &Localpsmode
);
1910 lbs_deb_leave(LBS_DEB_CMD
);
1914 * @brief This function checks condition and prepares to
1915 * send sleep confirm command to firmware if ok.
1917 * @param priv A pointer to wlan_private structure
1918 * @param psmode Power Saving mode
1921 void libertas_ps_confirm_sleep(wlan_private
* priv
, u16 psmode
)
1923 unsigned long flags
=0;
1924 wlan_adapter
*adapter
= priv
->adapter
;
1927 lbs_deb_enter(LBS_DEB_CMD
);
1929 if (priv
->wlan_dev
.dnld_sent
) {
1934 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
1935 if (adapter
->cur_cmd
) {
1939 if (adapter
->intcounter
> 0) {
1941 lbs_deb_cmd("I%d", adapter
->intcounter
);
1943 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
1946 lbs_deb_cmd("Sending libertas_ps_confirm_sleep\n");
1947 sendconfirmsleep(priv
, (u8
*) & adapter
->libertas_ps_confirm_sleep
,
1948 sizeof(struct PS_CMD_ConfirmSleep
));
1950 lbs_deb_cmd("Sleep Confirm has been delayed\n");
1953 lbs_deb_leave(LBS_DEB_CMD
);