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(u16 command)
30 int count = sizeof(commands_allowed_in_ps)
31 / sizeof(commands_allowed_in_ps[0]);
34 for (i = 0; i < count; i++) {
35 if (command == cpu_to_le16(commands_allowed_in_ps[i]))
42 static int wlan_cmd_hw_spec(wlan_private * priv, struct cmd_ds_command *cmd)
44 struct cmd_ds_get_hw_spec *hwspec = &cmd->params.hwspec;
46 lbs_deb_enter(LBS_DEB_CMD);
48 cmd->command = cpu_to_le16(cmd_get_hw_spec);
50 cpu_to_le16(sizeof(struct cmd_ds_get_hw_spec) + S_DS_GEN);
51 memcpy(hwspec->permanentaddr, priv->adapter->current_addr, ETH_ALEN);
53 lbs_deb_leave(LBS_DEB_CMD);
57 static int wlan_cmd_802_11_ps_mode(wlan_private * priv,
58 struct cmd_ds_command *cmd,
61 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
62 u16 action = cmd_action;
63 wlan_adapter *adapter = priv->adapter;
65 lbs_deb_enter(LBS_DEB_CMD);
67 cmd->command = cpu_to_le16(cmd_802_11_ps_mode);
69 cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
71 psm->action = cpu_to_le16(cmd_action);
72 psm->multipledtim = 0;
74 case cmd_subcmd_enter_ps:
75 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
76 lbs_deb_cmd("locallisteninterval = %d\n",
77 adapter->locallisteninterval);
79 psm->locallisteninterval =
80 cpu_to_le16(adapter->locallisteninterval);
81 psm->nullpktinterval =
82 cpu_to_le16(adapter->nullpktinterval);
84 cpu_to_le16(priv->adapter->multipledtim);
87 case cmd_subcmd_exit_ps:
88 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
91 case cmd_subcmd_sleep_confirmed:
92 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
99 lbs_deb_leave(LBS_DEB_CMD);
103 static int wlan_cmd_802_11_inactivity_timeout(wlan_private * priv,
104 struct cmd_ds_command *cmd,
105 u16 cmd_action, void *pdata_buf)
107 u16 *timeout = pdata_buf;
109 cmd->command = cpu_to_le16(cmd_802_11_inactivity_timeout);
111 cpu_to_le16(sizeof(struct cmd_ds_802_11_inactivity_timeout)
114 cmd->params.inactivity_timeout.action = cpu_to_le16(cmd_action);
117 cmd->params.inactivity_timeout.timeout =
118 cpu_to_le16(*timeout);
120 cmd->params.inactivity_timeout.timeout = 0;
125 static int wlan_cmd_802_11_sleep_params(wlan_private * priv,
126 struct cmd_ds_command *cmd,
129 wlan_adapter *adapter = priv->adapter;
130 struct cmd_ds_802_11_sleep_params *sp = &cmd->params.sleep_params;
132 lbs_deb_enter(LBS_DEB_CMD);
135 cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
137 cmd->command = cpu_to_le16(cmd_802_11_sleep_params);
139 if (cmd_action == cmd_act_get) {
140 memset(&adapter->sp, 0, sizeof(struct sleep_params));
141 memset(sp, 0, sizeof(struct cmd_ds_802_11_sleep_params));
142 sp->action = cpu_to_le16(cmd_action);
143 } else if (cmd_action == cmd_act_set) {
144 sp->action = cpu_to_le16(cmd_action);
145 sp->error = cpu_to_le16(adapter->sp.sp_error);
146 sp->offset = cpu_to_le16(adapter->sp.sp_offset);
147 sp->stabletime = cpu_to_le16(adapter->sp.sp_stabletime);
148 sp->calcontrol = (u8) adapter->sp.sp_calcontrol;
149 sp->externalsleepclk = (u8) adapter->sp.sp_extsleepclk;
150 sp->reserved = cpu_to_le16(adapter->sp.sp_reserved);
153 lbs_deb_leave(LBS_DEB_CMD);
157 static int wlan_cmd_802_11_set_wep(wlan_private * priv,
158 struct cmd_ds_command *cmd,
162 struct cmd_ds_802_11_set_wep *wep = &cmd->params.wep;
163 wlan_adapter *adapter = priv->adapter;
165 struct assoc_request * assoc_req = pdata_buf;
167 lbs_deb_enter(LBS_DEB_CMD);
169 cmd->command = cpu_to_le16(cmd_802_11_set_wep);
170 cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_set_wep))
173 if (cmd_act == cmd_act_add) {
177 lbs_deb_cmd("Invalid association request!");
182 wep->action = cpu_to_le16(cmd_act_add);
184 /* default tx key index */
185 wep->keyindex = cpu_to_le16((u16)
186 (assoc_req->wep_tx_keyidx &
187 (u32)cmd_WEP_KEY_INDEX_MASK));
189 lbs_deb_cmd("Tx key Index: %u\n", wep->keyindex);
191 /* Copy key types and material to host command structure */
192 for (i = 0; i < 4; i++) {
193 struct WLAN_802_11_KEY * pkey = &assoc_req->wep_keys[i];
197 wep->keytype[i] = cmd_type_wep_40_bit;
198 memmove(&wep->keymaterial[i], pkey->key,
201 case KEY_LEN_WEP_104:
202 wep->keytype[i] = cmd_type_wep_104_bit;
203 memmove(&wep->keymaterial[i], pkey->key,
209 lbs_deb_cmd("Invalid WEP key %d length of %d\n",
216 } else if (cmd_act == cmd_act_remove) {
217 /* ACT_REMOVE clears _all_ WEP keys */
218 wep->action = cpu_to_le16(cmd_act_remove);
220 /* default tx key index */
221 wep->keyindex = cpu_to_le16((u16)
222 (adapter->wep_tx_keyidx &
223 (u32)cmd_WEP_KEY_INDEX_MASK));
229 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
233 static int wlan_cmd_802_11_enable_rsn(wlan_private * priv,
234 struct cmd_ds_command *cmd,
237 struct cmd_ds_802_11_enable_rsn *penableRSN = &cmd->params.enbrsn;
238 wlan_adapter *adapter = priv->adapter;
240 cmd->command = cpu_to_le16(cmd_802_11_enable_rsn);
242 cpu_to_le16(sizeof(struct cmd_ds_802_11_enable_rsn) +
244 penableRSN->action = cpu_to_le16(cmd_action);
245 if (adapter->secinfo.WPAenabled || adapter->secinfo.WPA2enabled) {
246 penableRSN->enable = cpu_to_le16(cmd_enable_rsn);
248 penableRSN->enable = cpu_to_le16(cmd_disable_rsn);
255 static void set_one_wpa_key(struct MrvlIEtype_keyParamSet * pkeyparamset,
256 struct WLAN_802_11_KEY * pkey)
258 pkeyparamset->keytypeid = cpu_to_le16(pkey->type);
260 if (pkey->flags & KEY_INFO_WPA_ENABLED) {
261 pkeyparamset->keyinfo = cpu_to_le16(KEY_INFO_WPA_ENABLED);
263 pkeyparamset->keyinfo = cpu_to_le16(!KEY_INFO_WPA_ENABLED);
266 if (pkey->flags & KEY_INFO_WPA_UNICAST) {
267 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
268 } else if (pkey->flags & KEY_INFO_WPA_MCAST) {
269 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
272 pkeyparamset->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
273 pkeyparamset->keylen = cpu_to_le16(pkey->len);
274 memcpy(pkeyparamset->key, pkey->key, pkey->len);
275 pkeyparamset->length = cpu_to_le16( sizeof(pkeyparamset->keytypeid)
276 + sizeof(pkeyparamset->keyinfo)
277 + sizeof(pkeyparamset->keylen)
278 + sizeof(pkeyparamset->key));
281 static int wlan_cmd_802_11_key_material(wlan_private * priv,
282 struct cmd_ds_command *cmd,
284 u32 cmd_oid, void *pdata_buf)
286 wlan_adapter *adapter = priv->adapter;
287 struct cmd_ds_802_11_key_material *pkeymaterial =
288 &cmd->params.keymaterial;
292 lbs_deb_enter(LBS_DEB_CMD);
294 cmd->command = cpu_to_le16(cmd_802_11_key_material);
295 pkeymaterial->action = cpu_to_le16(cmd_action);
297 if (cmd_action == cmd_act_get) {
298 cmd->size = cpu_to_le16( S_DS_GEN
299 + sizeof (pkeymaterial->action));
304 memset(&pkeymaterial->keyParamSet, 0, sizeof(pkeymaterial->keyParamSet));
306 if (adapter->wpa_unicast_key.len) {
307 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
308 &adapter->wpa_unicast_key);
312 if (adapter->wpa_mcast_key.len) {
313 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
314 &adapter->wpa_mcast_key);
318 cmd->size = cpu_to_le16( S_DS_GEN
319 + sizeof (pkeymaterial->action)
320 + index * sizeof(struct MrvlIEtype_keyParamSet));
325 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
329 static int wlan_cmd_802_11_reset(wlan_private * priv,
330 struct cmd_ds_command *cmd, int cmd_action)
332 struct cmd_ds_802_11_reset *reset = &cmd->params.reset;
334 cmd->command = cpu_to_le16(cmd_802_11_reset);
335 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
336 reset->action = cpu_to_le16(cmd_action);
341 static int wlan_cmd_802_11_get_log(wlan_private * priv,
342 struct cmd_ds_command *cmd)
344 cmd->command = cpu_to_le16(cmd_802_11_get_log);
346 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_log) + S_DS_GEN);
351 static int wlan_cmd_802_11_get_stat(wlan_private * priv,
352 struct cmd_ds_command *cmd)
354 cmd->command = cpu_to_le16(cmd_802_11_get_stat);
356 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) +
362 static int wlan_cmd_802_11_snmp_mib(wlan_private * priv,
363 struct cmd_ds_command *cmd,
365 int cmd_oid, void *pdata_buf)
367 struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib;
368 wlan_adapter *adapter = priv->adapter;
371 lbs_deb_enter(LBS_DEB_CMD);
373 lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
375 cmd->command = cpu_to_le16(cmd_802_11_snmp_mib);
377 cpu_to_le16(sizeof(struct cmd_ds_802_11_snmp_mib) +
381 case OID_802_11_INFRASTRUCTURE_MODE:
383 u8 mode = (u8) (size_t) pdata_buf;
384 pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
385 pSNMPMIB->oid = cpu_to_le16((u16) desired_bsstype_i);
386 pSNMPMIB->bufsize = sizeof(u8);
387 if (mode == IW_MODE_ADHOC) {
388 ucTemp = SNMP_MIB_VALUE_ADHOC;
390 /* Infra and Auto modes */
391 ucTemp = SNMP_MIB_VALUE_INFRA;
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);
488 lbs_deb_leave(LBS_DEB_CMD);
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 =
500 lbs_deb_enter(LBS_DEB_CMD);
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);
529 lbs_deb_leave(LBS_DEB_CMD);
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;
540 lbs_deb_enter(LBS_DEB_CMD);
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_deb_cmd("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));
575 lbs_deb_leave(LBS_DEB_CMD);
579 static int wlan_cmd_802_11_rf_antenna(wlan_private * priv,
580 struct cmd_ds_command *cmd,
581 u16 cmd_action, void *pdata_buf)
583 struct cmd_ds_802_11_rf_antenna *rant = &cmd->params.rant;
585 cmd->command = cpu_to_le16(cmd_802_11_rf_antenna);
587 cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_antenna) +
590 rant->action = cpu_to_le16(cmd_action);
591 if ((cmd_action == cmd_act_set_rx) ||
592 (cmd_action == cmd_act_set_tx)) {
594 cpu_to_le16((u16) (*(u32 *) pdata_buf));
600 static int wlan_cmd_802_11_rate_adapt_rateset(wlan_private * priv,
601 struct cmd_ds_command *cmd,
604 struct cmd_ds_802_11_rate_adapt_rateset
605 *rateadapt = &cmd->params.rateset;
606 wlan_adapter *adapter = priv->adapter;
609 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
611 cmd->command = cpu_to_le16(cmd_802_11_rate_adapt_rateset);
613 lbs_deb_enter(LBS_DEB_CMD);
615 rateadapt->action = cmd_action;
616 rateadapt->enablehwauto = adapter->enablehwauto;
617 rateadapt->bitmap = adapter->ratebitmap;
619 lbs_deb_leave(LBS_DEB_CMD);
623 static int wlan_cmd_802_11_data_rate(wlan_private * priv,
624 struct cmd_ds_command *cmd,
627 struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
628 wlan_adapter *adapter = priv->adapter;
629 u16 action = cmd_action;
631 lbs_deb_enter(LBS_DEB_CMD);
634 cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
637 cmd->command = cpu_to_le16(cmd_802_11_data_rate);
639 memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate));
641 pdatarate->action = cpu_to_le16(cmd_action);
643 if (action == cmd_act_set_tx_fix_rate) {
644 pdatarate->datarate[0] = libertas_data_rate_to_index(adapter->datarate);
645 lbs_deb_cmd("Setting FW for fixed rate 0x%02X\n",
647 } else if (action == cmd_act_set_tx_auto) {
648 lbs_deb_cmd("Setting FW for AUTO rate\n");
651 lbs_deb_leave(LBS_DEB_CMD);
655 static int wlan_cmd_mac_multicast_adr(wlan_private * priv,
656 struct cmd_ds_command *cmd,
659 struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
660 wlan_adapter *adapter = priv->adapter;
663 cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
665 cmd->command = cpu_to_le16(cmd_mac_multicast_adr);
667 pMCastAdr->action = cpu_to_le16(cmd_action);
668 pMCastAdr->nr_of_adrs =
669 cpu_to_le16((u16) adapter->nr_of_multicastmacaddr);
670 memcpy(pMCastAdr->maclist, adapter->multicastlist,
671 adapter->nr_of_multicastmacaddr * ETH_ALEN);
676 static int wlan_cmd_802_11_rf_channel(wlan_private * priv,
677 struct cmd_ds_command *cmd,
678 int option, void *pdata_buf)
680 struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel;
682 cmd->command = cpu_to_le16(cmd_802_11_rf_channel);
683 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel)
686 if (option == cmd_opt_802_11_rf_channel_set) {
687 rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf));
690 rfchan->action = cpu_to_le16(option);
695 static int wlan_cmd_802_11_rssi(wlan_private * priv,
696 struct cmd_ds_command *cmd)
698 wlan_adapter *adapter = priv->adapter;
700 cmd->command = cpu_to_le16(cmd_802_11_rssi);
702 cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
703 cmd->params.rssi.N = priv->adapter->bcn_avg_factor;
705 /* reset Beacon SNR/NF/RSSI values */
706 adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
707 adapter->SNR[TYPE_BEACON][TYPE_AVG] = 0;
708 adapter->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
709 adapter->NF[TYPE_BEACON][TYPE_AVG] = 0;
710 adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
711 adapter->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
716 static int wlan_cmd_reg_access(wlan_private * priv,
717 struct cmd_ds_command *cmdptr,
718 u8 cmd_action, void *pdata_buf)
720 struct wlan_offset_value *offval;
722 lbs_deb_enter(LBS_DEB_CMD);
724 offval = (struct wlan_offset_value *)pdata_buf;
726 switch (cmdptr->command) {
727 case cmd_mac_reg_access:
729 struct cmd_ds_mac_reg_access *macreg;
733 (struct cmd_ds_mac_reg_access)
736 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
739 macreg->action = cpu_to_le16(cmd_action);
740 macreg->offset = cpu_to_le16((u16) offval->offset);
741 macreg->value = cpu_to_le32(offval->value);
746 case cmd_bbp_reg_access:
748 struct cmd_ds_bbp_reg_access *bbpreg;
752 (struct cmd_ds_bbp_reg_access)
755 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
758 bbpreg->action = cpu_to_le16(cmd_action);
759 bbpreg->offset = cpu_to_le16((u16) offval->offset);
760 bbpreg->value = (u8) offval->value;
765 case cmd_rf_reg_access:
767 struct cmd_ds_rf_reg_access *rfreg;
771 (struct cmd_ds_rf_reg_access) +
774 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
777 rfreg->action = cpu_to_le16(cmd_action);
778 rfreg->offset = cpu_to_le16((u16) offval->offset);
779 rfreg->value = (u8) offval->value;
788 lbs_deb_leave(LBS_DEB_CMD);
792 static int wlan_cmd_802_11_mac_address(wlan_private * priv,
793 struct cmd_ds_command *cmd,
796 wlan_adapter *adapter = priv->adapter;
798 cmd->command = cpu_to_le16(cmd_802_11_mac_address);
800 cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
804 cmd->params.macadd.action = cpu_to_le16(cmd_action);
806 if (cmd_action == cmd_act_set) {
807 memcpy(cmd->params.macadd.macadd,
808 adapter->current_addr, ETH_ALEN);
809 lbs_dbg_hex("SET_CMD: MAC ADDRESS-", adapter->current_addr, 6);
815 static int wlan_cmd_802_11_eeprom_access(wlan_private * priv,
816 struct cmd_ds_command *cmd,
817 int cmd_action, void *pdata_buf)
819 struct wlan_ioctl_regrdwr *ea = pdata_buf;
821 lbs_deb_enter(LBS_DEB_CMD);
823 cmd->command = cpu_to_le16(cmd_802_11_eeprom_access);
825 cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
829 cmd->params.rdeeprom.action = cpu_to_le16(ea->action);
830 cmd->params.rdeeprom.offset = cpu_to_le16(ea->offset);
831 cmd->params.rdeeprom.bytecount = cpu_to_le16(ea->NOB);
832 cmd->params.rdeeprom.value = 0;
837 static int wlan_cmd_bt_access(wlan_private * priv,
838 struct cmd_ds_command *cmd,
839 u16 cmd_action, void *pdata_buf)
841 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
842 lbs_deb_cmd("BT CMD(%d)\n", cmd_action);
844 cmd->command = cpu_to_le16(cmd_bt_access);
845 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access)
848 bt_access->action = cpu_to_le16(cmd_action);
850 switch (cmd_action) {
851 case cmd_act_bt_access_add:
852 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
853 lbs_dbg_hex("BT_ADD: blinded mac address-", bt_access->addr1, 6);
855 case cmd_act_bt_access_del:
856 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
857 lbs_dbg_hex("BT_DEL: blinded mac address-", bt_access->addr1, 6);
859 case cmd_act_bt_access_list:
860 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
862 case cmd_act_bt_access_reset:
864 case cmd_act_bt_access_set_invert:
865 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
867 case cmd_act_bt_access_get_invert:
875 static int wlan_cmd_fwt_access(wlan_private * priv,
876 struct cmd_ds_command *cmd,
877 u16 cmd_action, void *pdata_buf)
879 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
880 lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
882 cmd->command = cpu_to_le16(cmd_fwt_access);
883 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access)
888 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
890 memset(fwt_access, 0, sizeof(*fwt_access));
892 fwt_access->action = cpu_to_le16(cmd_action);
897 static int wlan_cmd_mesh_access(wlan_private * priv,
898 struct cmd_ds_command *cmd,
899 u16 cmd_action, void *pdata_buf)
901 struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
902 lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
904 cmd->command = cpu_to_le16(cmd_mesh_access);
905 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access)
910 memcpy(mesh_access, pdata_buf, sizeof(*mesh_access));
912 memset(mesh_access, 0, sizeof(*mesh_access));
914 mesh_access->action = cpu_to_le16(cmd_action);
919 void libertas_queue_cmd(wlan_adapter * adapter, struct cmd_ctrl_node *cmdnode, u8 addtail)
922 struct cmd_ds_command *cmdptr;
924 lbs_deb_enter(LBS_DEB_CMD);
927 lbs_deb_cmd("QUEUE_CMD: cmdnode is NULL\n");
931 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
933 lbs_deb_cmd("QUEUE_CMD: cmdptr is NULL\n");
937 /* Exit_PS command needs to be queued in the header always. */
938 if (cmdptr->command == cmd_802_11_ps_mode) {
939 struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
940 if (psm->action == cmd_subcmd_exit_ps) {
941 if (adapter->psstate != PS_STATE_FULL_POWER)
946 spin_lock_irqsave(&adapter->driver_lock, flags);
949 list_add_tail((struct list_head *)cmdnode,
950 &adapter->cmdpendingq);
952 list_add((struct list_head *)cmdnode, &adapter->cmdpendingq);
954 spin_unlock_irqrestore(&adapter->driver_lock, flags);
956 lbs_deb_cmd("QUEUE_CMD: Inserted node=%p, cmd=0x%x in cmdpendingq\n",
958 ((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command);
961 lbs_deb_leave(LBS_DEB_CMD);
965 * TODO: Fix the issue when DownloadcommandToStation is being called the
966 * second time when the command timesout. All the cmdptr->xxx are in little
967 * endian and therefore all the comparissions will fail.
968 * For now - we are not performing the endian conversion the second time - but
969 * for PS and DEEP_SLEEP we need to worry
971 static int DownloadcommandToStation(wlan_private * priv,
972 struct cmd_ctrl_node *cmdnode)
975 struct cmd_ds_command *cmdptr;
976 wlan_adapter *adapter = priv->adapter;
981 lbs_deb_enter(LBS_DEB_CMD);
983 if (!adapter || !cmdnode) {
984 lbs_deb_cmd("DNLD_CMD: adapter = %p, cmdnode = %p\n",
987 spin_lock_irqsave(&adapter->driver_lock, flags);
988 __libertas_cleanup_and_insert_cmd(priv, cmdnode);
989 spin_unlock_irqrestore(&adapter->driver_lock, flags);
995 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
998 spin_lock_irqsave(&adapter->driver_lock, flags);
999 if (!cmdptr || !cmdptr->size) {
1000 lbs_deb_cmd("DNLD_CMD: cmdptr is Null or cmd size is Zero, "
1002 __libertas_cleanup_and_insert_cmd(priv, cmdnode);
1003 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1008 adapter->cur_cmd = cmdnode;
1009 adapter->cur_cmd_retcode = 0;
1010 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1011 lbs_deb_cmd("DNLD_CMD:: Before download, size of cmd = %d\n",
1014 cmdsize = cmdptr->size;
1016 command = cpu_to_le16(cmdptr->command);
1018 cmdnode->cmdwaitqwoken = 0;
1019 cmdsize = cpu_to_le16(cmdsize);
1021 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
1024 lbs_deb_cmd("DNLD_CMD: Host to Card failed\n");
1025 spin_lock_irqsave(&adapter->driver_lock, flags);
1026 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
1027 adapter->cur_cmd = NULL;
1028 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1033 lbs_deb_cmd("DNLD_CMD: Sent command 0x%x @ %lu\n", command, jiffies);
1034 lbs_dbg_hex("DNLD_CMD: command", cmdnode->bufvirtualaddr, cmdsize);
1036 /* Setup the timer after transmit command */
1037 if (command == cmd_802_11_scan
1038 || command == cmd_802_11_authenticate
1039 || command == cmd_802_11_associate)
1040 mod_timer(&adapter->command_timer, jiffies + (10*HZ));
1042 mod_timer(&adapter->command_timer, jiffies + (5*HZ));
1047 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1051 static int wlan_cmd_mac_control(wlan_private * priv,
1052 struct cmd_ds_command *cmd)
1054 struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
1056 lbs_deb_enter(LBS_DEB_CMD);
1058 cmd->command = cpu_to_le16(cmd_mac_control);
1060 cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
1061 mac->action = cpu_to_le16(priv->adapter->currentpacketfilter);
1063 lbs_deb_cmd("wlan_cmd_mac_control(): action=0x%X size=%d\n",
1064 mac->action, cmd->size);
1066 lbs_deb_leave(LBS_DEB_CMD);
1071 * This function inserts command node to cmdfreeq
1072 * after cleans it. Requires adapter->driver_lock held.
1074 void __libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
1076 wlan_adapter *adapter = priv->adapter;
1081 cleanup_cmdnode(ptempcmd);
1082 list_add_tail((struct list_head *)ptempcmd, &adapter->cmdfreeq);
1087 void libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
1089 unsigned long flags;
1091 spin_lock_irqsave(&priv->adapter->driver_lock, flags);
1092 __libertas_cleanup_and_insert_cmd(priv, ptempcmd);
1093 spin_unlock_irqrestore(&priv->adapter->driver_lock, flags);
1096 int libertas_set_radio_control(wlan_private * priv)
1100 lbs_deb_enter(LBS_DEB_CMD);
1102 ret = libertas_prepare_and_send_command(priv,
1103 cmd_802_11_radio_control,
1105 cmd_option_waitforrsp, 0, NULL);
1107 lbs_deb_cmd("RADIO_SET: on or off: 0x%X, preamble = 0x%X\n",
1108 priv->adapter->radioon, priv->adapter->preamble);
1110 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1114 int libertas_set_mac_packet_filter(wlan_private * priv)
1118 lbs_deb_enter(LBS_DEB_CMD);
1120 lbs_deb_cmd("libertas_set_mac_packet_filter value = %x\n",
1121 priv->adapter->currentpacketfilter);
1123 /* Send MAC control command to station */
1124 ret = libertas_prepare_and_send_command(priv,
1125 cmd_mac_control, 0, 0, 0, NULL);
1127 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1132 * @brief This function prepare the command before send to firmware.
1134 * @param priv A pointer to wlan_private structure
1135 * @param cmd_no command number
1136 * @param cmd_action command action: GET or SET
1137 * @param wait_option wait option: wait response or not
1138 * @param cmd_oid cmd oid: treated as sub command
1139 * @param pdata_buf A pointer to informaion buffer
1142 int libertas_prepare_and_send_command(wlan_private * priv,
1145 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1148 wlan_adapter *adapter = priv->adapter;
1149 struct cmd_ctrl_node *cmdnode;
1150 struct cmd_ds_command *cmdptr;
1151 unsigned long flags;
1153 lbs_deb_enter(LBS_DEB_CMD);
1156 lbs_deb_cmd("PREP_CMD: adapter is Null\n");
1161 if (adapter->surpriseremoved) {
1162 lbs_deb_cmd("PREP_CMD: Card is Removed\n");
1167 cmdnode = libertas_get_free_cmd_ctrl_node(priv);
1169 if (cmdnode == NULL) {
1170 lbs_deb_cmd("PREP_CMD: No free cmdnode\n");
1172 /* Wake up main thread to execute next command */
1173 wake_up_interruptible(&priv->mainthread.waitq);
1178 libertas_set_cmd_ctrl_node(priv, cmdnode, cmd_oid, wait_option, pdata_buf);
1180 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1182 lbs_deb_cmd("PREP_CMD: Val of cmd ptr=%p, command=0x%X\n",
1186 lbs_deb_cmd("PREP_CMD: bufvirtualaddr of cmdnode is NULL\n");
1187 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1192 /* Set sequence number, command and INT option */
1194 cmdptr->seqnum = cpu_to_le16(adapter->seqnum);
1196 cmdptr->command = cmd_no;
1200 case cmd_get_hw_spec:
1201 ret = wlan_cmd_hw_spec(priv, cmdptr);
1203 case cmd_802_11_ps_mode:
1204 ret = wlan_cmd_802_11_ps_mode(priv, cmdptr, cmd_action);
1207 case cmd_802_11_scan:
1208 ret = libertas_cmd_80211_scan(priv, cmdptr, pdata_buf);
1211 case cmd_mac_control:
1212 ret = wlan_cmd_mac_control(priv, cmdptr);
1215 case cmd_802_11_associate:
1216 case cmd_802_11_reassociate:
1217 ret = libertas_cmd_80211_associate(priv, cmdptr, pdata_buf);
1220 case cmd_802_11_deauthenticate:
1221 ret = libertas_cmd_80211_deauthenticate(priv, cmdptr);
1224 case cmd_802_11_set_wep:
1225 ret = wlan_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf);
1228 case cmd_802_11_ad_hoc_start:
1229 ret = libertas_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
1234 case cmd_802_11_reset:
1235 ret = wlan_cmd_802_11_reset(priv, cmdptr, cmd_action);
1238 case cmd_802_11_get_log:
1239 ret = wlan_cmd_802_11_get_log(priv, cmdptr);
1242 case cmd_802_11_authenticate:
1243 ret = libertas_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
1246 case cmd_802_11_get_stat:
1247 ret = wlan_cmd_802_11_get_stat(priv, cmdptr);
1250 case cmd_802_11_snmp_mib:
1251 ret = wlan_cmd_802_11_snmp_mib(priv, cmdptr,
1252 cmd_action, cmd_oid, pdata_buf);
1255 case cmd_mac_reg_access:
1256 case cmd_bbp_reg_access:
1257 case cmd_rf_reg_access:
1258 ret = wlan_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf);
1261 case cmd_802_11_rf_channel:
1262 ret = wlan_cmd_802_11_rf_channel(priv, cmdptr,
1263 cmd_action, pdata_buf);
1266 case cmd_802_11_rf_tx_power:
1267 ret = wlan_cmd_802_11_rf_tx_power(priv, cmdptr,
1268 cmd_action, pdata_buf);
1271 case cmd_802_11_radio_control:
1272 ret = wlan_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
1275 case cmd_802_11_rf_antenna:
1276 ret = wlan_cmd_802_11_rf_antenna(priv, cmdptr,
1277 cmd_action, pdata_buf);
1280 case cmd_802_11_data_rate:
1281 ret = wlan_cmd_802_11_data_rate(priv, cmdptr, cmd_action);
1283 case cmd_802_11_rate_adapt_rateset:
1284 ret = wlan_cmd_802_11_rate_adapt_rateset(priv,
1285 cmdptr, cmd_action);
1288 case cmd_mac_multicast_adr:
1289 ret = wlan_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
1292 case cmd_802_11_ad_hoc_join:
1293 ret = libertas_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
1296 case cmd_802_11_rssi:
1297 ret = wlan_cmd_802_11_rssi(priv, cmdptr);
1300 case cmd_802_11_ad_hoc_stop:
1301 ret = libertas_cmd_80211_ad_hoc_stop(priv, cmdptr);
1304 case cmd_802_11_enable_rsn:
1305 ret = wlan_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action);
1308 case cmd_802_11_key_material:
1309 ret = wlan_cmd_802_11_key_material(priv, cmdptr,
1310 cmd_action, cmd_oid,
1314 case cmd_802_11_pairwise_tsc:
1316 case cmd_802_11_group_tsc:
1319 case cmd_802_11_mac_address:
1320 ret = wlan_cmd_802_11_mac_address(priv, cmdptr, cmd_action);
1323 case cmd_802_11_eeprom_access:
1324 ret = wlan_cmd_802_11_eeprom_access(priv, cmdptr,
1325 cmd_action, pdata_buf);
1328 case cmd_802_11_set_afc:
1329 case cmd_802_11_get_afc:
1331 cmdptr->command = cpu_to_le16(cmd_no);
1333 cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1336 memmove(&cmdptr->params.afc,
1337 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1342 case cmd_802_11d_domain_info:
1343 ret = libertas_cmd_802_11d_domain_info(priv, cmdptr,
1344 cmd_no, cmd_action);
1347 case cmd_802_11_sleep_params:
1348 ret = wlan_cmd_802_11_sleep_params(priv, cmdptr, cmd_action);
1350 case cmd_802_11_inactivity_timeout:
1351 ret = wlan_cmd_802_11_inactivity_timeout(priv, cmdptr,
1352 cmd_action, pdata_buf);
1353 libertas_set_cmd_ctrl_node(priv, cmdnode, 0, 0, pdata_buf);
1356 case cmd_802_11_tpc_cfg:
1357 cmdptr->command = cpu_to_le16(cmd_802_11_tpc_cfg);
1359 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1362 memmove(&cmdptr->params.tpccfg,
1363 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1367 case cmd_802_11_led_gpio_ctrl:
1369 struct mrvlietypes_ledgpio *gpio =
1370 (struct mrvlietypes_ledgpio*)
1371 cmdptr->params.ledgpio.data;
1373 memmove(&cmdptr->params.ledgpio,
1375 sizeof(struct cmd_ds_802_11_led_ctrl));
1378 cpu_to_le16(cmd_802_11_led_gpio_ctrl);
1380 #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1382 cpu_to_le16(gpio->header.len + S_DS_GEN +
1383 ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1384 gpio->header.len = cpu_to_le16(gpio->header.len);
1389 case cmd_802_11_pwr_cfg:
1390 cmdptr->command = cpu_to_le16(cmd_802_11_pwr_cfg);
1392 cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) +
1394 memmove(&cmdptr->params.pwrcfg, pdata_buf,
1395 sizeof(struct cmd_ds_802_11_pwr_cfg));
1400 ret = wlan_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf);
1403 case cmd_fwt_access:
1404 ret = wlan_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf);
1407 case cmd_mesh_access:
1408 ret = wlan_cmd_mesh_access(priv, cmdptr, cmd_action, pdata_buf);
1412 cmdptr->command = cpu_to_le16(cmd_get_tsf);
1414 cpu_to_le16(sizeof(struct cmd_ds_get_tsf)
1418 case cmd_802_11_tx_rate_query:
1420 cpu_to_le16(cmd_802_11_tx_rate_query);
1422 cpu_to_le16(sizeof(struct cmd_tx_rate_query) +
1424 adapter->txrate = 0;
1428 lbs_deb_cmd("PREP_CMD: unknown command- %#x\n", cmd_no);
1433 /* return error, since the command preparation failed */
1435 lbs_deb_cmd("PREP_CMD: command preparation failed\n");
1436 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1441 cmdnode->cmdwaitqwoken = 0;
1443 libertas_queue_cmd(adapter, cmdnode, 1);
1444 adapter->nr_cmd_pending++;
1445 wake_up_interruptible(&priv->mainthread.waitq);
1447 if (wait_option & cmd_option_waitforrsp) {
1448 lbs_deb_cmd("PREP_CMD: Wait for CMD response\n");
1450 wait_event_interruptible(cmdnode->cmdwait_q,
1451 cmdnode->cmdwaitqwoken);
1454 spin_lock_irqsave(&adapter->driver_lock, flags);
1455 if (adapter->cur_cmd_retcode) {
1456 lbs_deb_cmd("PREP_CMD: command failed with return code=%d\n",
1457 adapter->cur_cmd_retcode);
1458 adapter->cur_cmd_retcode = 0;
1461 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1464 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1467 EXPORT_SYMBOL_GPL(libertas_prepare_and_send_command);
1470 * @brief This function allocates the command buffer and link
1471 * it to command free queue.
1473 * @param priv A pointer to wlan_private structure
1476 int libertas_allocate_cmd_buffer(wlan_private * priv)
1481 struct cmd_ctrl_node *tempcmd_array;
1482 u8 *ptempvirtualaddr;
1483 wlan_adapter *adapter = priv->adapter;
1485 lbs_deb_enter(LBS_DEB_CMD);
1487 /* Allocate and initialize cmdCtrlNode */
1488 ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
1490 if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) {
1492 "ALLOC_CMD_BUF: failed to allocate tempcmd_array\n");
1496 adapter->cmd_array = tempcmd_array;
1498 /* Allocate and initialize command buffers */
1499 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1500 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1501 if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) {
1503 "ALLOC_CMD_BUF: ptempvirtualaddr: out of memory\n");
1508 /* Update command buffer virtual */
1509 tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
1512 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1513 init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
1514 libertas_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
1520 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1525 * @brief This function frees the command buffer.
1527 * @param priv A pointer to wlan_private structure
1530 int libertas_free_cmd_buffer(wlan_private * priv)
1534 struct cmd_ctrl_node *tempcmd_array;
1535 wlan_adapter *adapter = priv->adapter;
1537 lbs_deb_enter(LBS_DEB_CMD);
1539 /* need to check if cmd array is allocated or not */
1540 if (adapter->cmd_array == NULL) {
1541 lbs_deb_cmd("FREE_CMD_BUF: cmd_array is Null\n");
1545 tempcmd_array = adapter->cmd_array;
1547 /* Release shared memory buffers */
1548 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1549 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1550 if (tempcmd_array[i].bufvirtualaddr) {
1551 lbs_deb_cmd("Free all the array\n");
1552 kfree(tempcmd_array[i].bufvirtualaddr);
1553 tempcmd_array[i].bufvirtualaddr = NULL;
1557 /* Release cmd_ctrl_node */
1558 if (adapter->cmd_array) {
1559 lbs_deb_cmd("Free cmd_array\n");
1560 kfree(adapter->cmd_array);
1561 adapter->cmd_array = NULL;
1565 lbs_deb_leave(LBS_DEB_CMD);
1570 * @brief This function gets a free command node if available in
1571 * command free queue.
1573 * @param priv A pointer to wlan_private structure
1574 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1576 struct cmd_ctrl_node *libertas_get_free_cmd_ctrl_node(wlan_private * priv)
1578 struct cmd_ctrl_node *tempnode;
1579 wlan_adapter *adapter = priv->adapter;
1580 unsigned long flags;
1585 spin_lock_irqsave(&adapter->driver_lock, flags);
1587 if (!list_empty(&adapter->cmdfreeq)) {
1588 tempnode = (struct cmd_ctrl_node *)adapter->cmdfreeq.next;
1589 list_del((struct list_head *)tempnode);
1591 lbs_deb_cmd("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1595 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1599 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode available\n");
1600 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode Address = %p\n",
1603 cleanup_cmdnode(tempnode);
1610 * @brief This function cleans command node.
1612 * @param ptempnode A pointer to cmdCtrlNode structure
1615 static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
1619 ptempnode->cmdwaitqwoken = 1;
1620 wake_up_interruptible(&ptempnode->cmdwait_q);
1621 ptempnode->status = 0;
1622 ptempnode->cmd_oid = (u32) 0;
1623 ptempnode->wait_option = 0;
1624 ptempnode->pdata_buf = NULL;
1626 if (ptempnode->bufvirtualaddr != NULL)
1627 memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
1632 * @brief This function initializes the command node.
1634 * @param priv A pointer to wlan_private structure
1635 * @param ptempnode A pointer to cmd_ctrl_node structure
1636 * @param cmd_oid cmd oid: treated as sub command
1637 * @param wait_option wait option: wait response or not
1638 * @param pdata_buf A pointer to informaion buffer
1641 void libertas_set_cmd_ctrl_node(wlan_private * priv,
1642 struct cmd_ctrl_node *ptempnode,
1643 u32 cmd_oid, u16 wait_option, void *pdata_buf)
1645 lbs_deb_enter(LBS_DEB_CMD);
1650 ptempnode->cmd_oid = cmd_oid;
1651 ptempnode->wait_option = wait_option;
1652 ptempnode->pdata_buf = pdata_buf;
1654 lbs_deb_leave(LBS_DEB_CMD);
1658 * @brief This function executes next command in command
1659 * pending queue. It will put fimware back to PS mode
1662 * @param priv A pointer to wlan_private structure
1665 int libertas_execute_next_command(wlan_private * priv)
1667 wlan_adapter *adapter = priv->adapter;
1668 struct cmd_ctrl_node *cmdnode = NULL;
1669 struct cmd_ds_command *cmdptr;
1670 unsigned long flags;
1673 lbs_deb_enter(LBS_DEB_CMD);
1675 spin_lock_irqsave(&adapter->driver_lock, flags);
1677 if (adapter->cur_cmd) {
1678 lbs_pr_alert( "EXEC_NEXT_CMD: there is command in processing!\n");
1679 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1684 if (!list_empty(&adapter->cmdpendingq)) {
1685 cmdnode = (struct cmd_ctrl_node *)
1686 adapter->cmdpendingq.next;
1689 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1693 "EXEC_NEXT_CMD: Got next command from cmdpendingq\n");
1694 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1696 if (is_command_allowed_in_ps(cmdptr->command)) {
1697 if ((adapter->psstate == PS_STATE_SLEEP)
1698 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1701 "EXEC_NEXT_CMD: Cannot send cmd 0x%x in psstate %d\n",
1702 cmdptr->command, adapter->psstate);
1706 lbs_deb_cmd("EXEC_NEXT_CMD: OK to send command "
1707 "0x%x in psstate %d\n",
1708 cmdptr->command, adapter->psstate);
1709 } else if (adapter->psstate != PS_STATE_FULL_POWER) {
1711 * 1. Non-PS command:
1712 * Queue it. set needtowakeup to TRUE if current state
1713 * is SLEEP, otherwise call libertas_ps_wakeup to send Exit_PS.
1714 * 2. PS command but not Exit_PS:
1716 * 3. PS command Exit_PS:
1717 * Set needtowakeup to TRUE if current state is SLEEP,
1718 * otherwise send this command down to firmware
1721 if (cmdptr->command !=
1722 cpu_to_le16(cmd_802_11_ps_mode)) {
1723 /* Prepare to send Exit PS,
1724 * this non PS command will be sent later */
1725 if ((adapter->psstate == PS_STATE_SLEEP)
1726 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1728 /* w/ new scheme, it will not reach here.
1729 since it is blocked in main_thread. */
1730 adapter->needtowakeup = 1;
1732 libertas_ps_wakeup(priv, 0);
1738 * PS command. Ignore it if it is not Exit_PS.
1739 * otherwise send it down immediately.
1741 struct cmd_ds_802_11_ps_mode *psm =
1742 &cmdptr->params.psmode;
1745 "EXEC_NEXT_CMD: PS cmd- action=0x%x\n",
1748 cpu_to_le16(cmd_subcmd_exit_ps)) {
1750 "EXEC_NEXT_CMD: Ignore Enter PS cmd\n");
1751 list_del((struct list_head *)cmdnode);
1752 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1758 if ((adapter->psstate == PS_STATE_SLEEP)
1759 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1762 "EXEC_NEXT_CMD: Ignore ExitPS cmd in sleep\n");
1763 list_del((struct list_head *)cmdnode);
1764 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1765 adapter->needtowakeup = 1;
1772 "EXEC_NEXT_CMD: Sending Exit_PS down...\n");
1775 list_del((struct list_head *)cmdnode);
1776 lbs_deb_cmd("EXEC_NEXT_CMD: Sending 0x%04X command\n",
1778 DownloadcommandToStation(priv, cmdnode);
1781 * check if in power save mode, if yes, put the device back
1784 if ((adapter->psmode != wlan802_11powermodecam) &&
1785 (adapter->psstate == PS_STATE_FULL_POWER) &&
1786 (adapter->connect_status == libertas_connected)) {
1787 if (adapter->secinfo.WPAenabled
1788 || adapter->secinfo.WPA2enabled) {
1789 /* check for valid WPA group keys */
1790 if (adapter->wpa_mcast_key.len
1791 || adapter->wpa_unicast_key.len) {
1793 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1794 " go back to PS_SLEEP");
1795 libertas_ps_sleep(priv, 0);
1799 "EXEC_NEXT_CMD: command PendQ is empty,"
1800 " go back to PS_SLEEP");
1801 libertas_ps_sleep(priv, 0);
1808 lbs_deb_leave(LBS_DEB_CMD);
1812 void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str)
1814 union iwreq_data iwrq;
1817 lbs_deb_enter(LBS_DEB_CMD);
1819 memset(&iwrq, 0, sizeof(union iwreq_data));
1820 memset(buf, 0, sizeof(buf));
1822 snprintf(buf, sizeof(buf) - 1, "%s", str);
1824 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1826 /* Send Event to upper layer */
1827 lbs_deb_cmd("Event Indication string = %s\n",
1829 lbs_deb_cmd("Event Indication String length = %d\n", iwrq.data.length);
1831 lbs_deb_cmd("Sending wireless event IWEVCUSTOM for %s\n", str);
1832 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
1834 lbs_deb_leave(LBS_DEB_CMD);
1837 static int sendconfirmsleep(wlan_private * priv, u8 * cmdptr, u16 size)
1839 unsigned long flags;
1840 wlan_adapter *adapter = priv->adapter;
1843 lbs_deb_enter(LBS_DEB_CMD);
1845 lbs_deb_cmd("SEND_SLEEPC_CMD: Before download, size of cmd = %d\n",
1848 lbs_dbg_hex("SEND_SLEEPC_CMD: Sleep confirm command", cmdptr, size);
1850 ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
1851 priv->dnld_sent = DNLD_RES_RECEIVED;
1853 spin_lock_irqsave(&adapter->driver_lock, flags);
1854 if (adapter->intcounter || adapter->currenttxskb)
1855 lbs_deb_cmd("SEND_SLEEPC_CMD: intcounter=%d currenttxskb=%p\n",
1856 adapter->intcounter, adapter->currenttxskb);
1857 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1861 "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
1863 spin_lock_irqsave(&adapter->driver_lock, flags);
1864 if (!adapter->intcounter) {
1865 adapter->psstate = PS_STATE_SLEEP;
1867 lbs_deb_cmd("SEND_SLEEPC_CMD: After sent,IntC=%d\n",
1868 adapter->intcounter);
1870 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1872 lbs_deb_cmd("SEND_SLEEPC_CMD: Sent Confirm Sleep command\n");
1876 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1880 void libertas_ps_sleep(wlan_private * priv, int wait_option)
1882 lbs_deb_enter(LBS_DEB_CMD);
1885 * PS is currently supported only in Infrastructure mode
1886 * Remove this check if it is to be supported in IBSS mode also
1889 libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
1890 cmd_subcmd_enter_ps, wait_option, 0, NULL);
1892 lbs_deb_leave(LBS_DEB_CMD);
1896 * @brief This function sends Eixt_PS command to firmware.
1898 * @param priv A pointer to wlan_private structure
1899 * @param wait_option wait response or not
1902 void libertas_ps_wakeup(wlan_private * priv, int wait_option)
1904 enum WLAN_802_11_POWER_MODE Localpsmode;
1906 lbs_deb_enter(LBS_DEB_CMD);
1908 Localpsmode = wlan802_11powermodecam;
1910 lbs_deb_cmd("Exit_PS: Localpsmode = %d\n", Localpsmode);
1912 libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
1914 wait_option, 0, &Localpsmode);
1916 lbs_deb_leave(LBS_DEB_CMD);
1920 * @brief This function checks condition and prepares to
1921 * send sleep confirm command to firmware if ok.
1923 * @param priv A pointer to wlan_private structure
1924 * @param psmode Power Saving mode
1927 void libertas_ps_confirm_sleep(wlan_private * priv, u16 psmode)
1929 unsigned long flags =0;
1930 wlan_adapter *adapter = priv->adapter;
1933 lbs_deb_enter(LBS_DEB_CMD);
1935 if (priv->dnld_sent) {
1940 spin_lock_irqsave(&adapter->driver_lock, flags);
1941 if (adapter->cur_cmd) {
1945 if (adapter->intcounter > 0) {
1947 lbs_deb_cmd("I%d", adapter->intcounter);
1949 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1952 lbs_deb_cmd("Sending libertas_ps_confirm_sleep\n");
1953 sendconfirmsleep(priv, (u8 *) & adapter->libertas_ps_confirm_sleep,
1954 sizeof(struct PS_CMD_ConfirmSleep));
1956 lbs_deb_cmd("Sleep Confirm has been delayed\n");
1959 lbs_deb_leave(LBS_DEB_CMD);