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 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);
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 =
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);
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;
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_pr_debug(1, "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));
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);
615 rateadapt->action = cmd_action;
616 rateadapt->enablehwauto = adapter->enablehwauto;
617 rateadapt->bitmap = adapter->ratebitmap;
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;
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_pr_debug(1, "Setting FW for fixed rate 0x%02X\n",
647 } else if (action == cmd_act_set_tx_auto) {
648 lbs_pr_debug(1, "Setting FW for AUTO rate\n");
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;
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;
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;
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_pr_debug(1, "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:
870 static int wlan_cmd_fwt_access(wlan_private * priv,
871 struct cmd_ds_command *cmd,
872 u16 cmd_action, void *pdata_buf)
874 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
875 lbs_pr_debug(1, "FWT CMD(%d)\n", cmd_action);
877 cmd->command = cpu_to_le16(cmd_fwt_access);
878 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access)
883 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
885 memset(fwt_access, 0, sizeof(*fwt_access));
887 fwt_access->action = cpu_to_le16(cmd_action);
892 static int wlan_cmd_mesh_access(wlan_private * priv,
893 struct cmd_ds_command *cmd,
894 u16 cmd_action, void *pdata_buf)
896 struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
897 lbs_pr_debug(1, "FWT CMD(%d)\n", cmd_action);
899 cmd->command = cpu_to_le16(cmd_mesh_access);
900 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access)
905 memcpy(mesh_access, pdata_buf, sizeof(*mesh_access));
907 memset(mesh_access, 0, sizeof(*mesh_access));
909 mesh_access->action = cpu_to_le16(cmd_action);
914 void libertas_queue_cmd(wlan_adapter * adapter, struct cmd_ctrl_node *cmdnode, u8 addtail)
917 struct cmd_ds_command *cmdptr;
922 lbs_pr_debug(1, "QUEUE_CMD: cmdnode is NULL\n");
926 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
928 lbs_pr_debug(1, "QUEUE_CMD: cmdptr is NULL\n");
932 /* Exit_PS command needs to be queued in the header always. */
933 if (cmdptr->command == cmd_802_11_ps_mode) {
934 struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
935 if (psm->action == cmd_subcmd_exit_ps) {
936 if (adapter->psstate != PS_STATE_FULL_POWER)
941 spin_lock_irqsave(&adapter->driver_lock, flags);
944 list_add_tail((struct list_head *)cmdnode,
945 &adapter->cmdpendingq);
947 list_add((struct list_head *)cmdnode, &adapter->cmdpendingq);
949 spin_unlock_irqrestore(&adapter->driver_lock, flags);
951 lbs_pr_debug(1, "QUEUE_CMD: Inserted node=%p, cmd=0x%x in cmdpendingq\n",
953 ((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command);
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;
979 if (!adapter || !cmdnode) {
980 lbs_pr_debug(1, "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_pr_debug(1, "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_pr_debug(1, "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_pr_debug(1, "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_pr_debug(1, "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));
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;
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_pr_debug(1, "wlan_cmd_mac_control(): action=0x%X size=%d\n",
1060 mac->action, cmd->size);
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)
1098 ret = libertas_prepare_and_send_command(priv,
1099 cmd_802_11_radio_control,
1101 cmd_option_waitforrsp, 0, NULL);
1103 lbs_pr_debug(1, "RADIO_SET: on or off: 0x%X, preamble = 0x%X\n",
1104 priv->adapter->radioon, priv->adapter->preamble);
1110 int libertas_set_mac_packet_filter(wlan_private * priv)
1116 lbs_pr_debug(1, "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);
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;
1152 lbs_pr_debug(1, "PREP_CMD: adapter is Null\n");
1157 if (adapter->surpriseremoved) {
1158 lbs_pr_debug(1, "PREP_CMD: Card is Removed\n");
1163 cmdnode = libertas_get_free_cmd_ctrl_node(priv);
1165 if (cmdnode == NULL) {
1166 lbs_pr_debug(1, "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_pr_debug(1, "PREP_CMD: Val of cmd ptr=%p, command=0x%X\n",
1182 lbs_pr_debug(1, "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_pr_debug(1, "PREP_CMD: unknown command- %#x\n", cmd_no);
1429 /* return error, since the command preparation failed */
1431 lbs_pr_debug(1, "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_pr_debug(1, "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_pr_debug(1, "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);
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;
1482 /* Allocate and initialize cmdCtrlNode */
1483 ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
1485 if (!(tempcmd_array = kmalloc(ulbufsize, GFP_KERNEL))) {
1487 "ALLOC_CMD_BUF: failed to allocate tempcmd_array\n");
1492 adapter->cmd_array = tempcmd_array;
1493 memset(adapter->cmd_array, 0, ulbufsize);
1495 /* Allocate and initialize command buffers */
1496 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1497 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1498 if (!(ptempvirtualaddr = kmalloc(ulbufsize, GFP_KERNEL))) {
1500 "ALLOC_CMD_BUF: ptempvirtualaddr: out of memory\n");
1505 memset(ptempvirtualaddr, 0, ulbufsize);
1507 /* Update command buffer virtual */
1508 tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
1511 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1512 init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
1513 libertas_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
1523 * @brief This function frees the command buffer.
1525 * @param priv A pointer to wlan_private structure
1528 int libertas_free_cmd_buffer(wlan_private * priv)
1532 struct cmd_ctrl_node *tempcmd_array;
1533 wlan_adapter *adapter = priv->adapter;
1537 /* need to check if cmd array is allocated or not */
1538 if (adapter->cmd_array == NULL) {
1539 lbs_pr_debug(1, "FREE_CMD_BUF: cmd_array is Null\n");
1543 tempcmd_array = adapter->cmd_array;
1545 /* Release shared memory buffers */
1546 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1547 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1548 if (tempcmd_array[i].bufvirtualaddr) {
1549 lbs_pr_debug(1, "Free all the array\n");
1550 kfree(tempcmd_array[i].bufvirtualaddr);
1551 tempcmd_array[i].bufvirtualaddr = NULL;
1555 /* Release cmd_ctrl_node */
1556 if (adapter->cmd_array) {
1557 lbs_pr_debug(1, "Free cmd_array\n");
1558 kfree(adapter->cmd_array);
1559 adapter->cmd_array = NULL;
1568 * @brief This function gets a free command node if available in
1569 * command free queue.
1571 * @param priv A pointer to wlan_private structure
1572 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1574 struct cmd_ctrl_node *libertas_get_free_cmd_ctrl_node(wlan_private * priv)
1576 struct cmd_ctrl_node *tempnode;
1577 wlan_adapter *adapter = priv->adapter;
1578 unsigned long flags;
1583 spin_lock_irqsave(&adapter->driver_lock, flags);
1585 if (!list_empty(&adapter->cmdfreeq)) {
1586 tempnode = (struct cmd_ctrl_node *)adapter->cmdfreeq.next;
1587 list_del((struct list_head *)tempnode);
1589 lbs_pr_debug(1, "GET_CMD_NODE: cmd_ctrl_node is not available\n");
1593 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1596 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode available\n");
1597 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode Address = %p\n",
1599 cleanup_cmdnode(tempnode);
1606 * @brief This function cleans command node.
1608 * @param ptempnode A pointer to cmdCtrlNode structure
1611 static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
1615 ptempnode->cmdwaitqwoken = 1;
1616 wake_up_interruptible(&ptempnode->cmdwait_q);
1617 ptempnode->status = 0;
1618 ptempnode->cmd_oid = (u32) 0;
1619 ptempnode->wait_option = 0;
1620 ptempnode->pdata_buf = NULL;
1622 if (ptempnode->bufvirtualaddr != NULL)
1623 memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
1628 * @brief This function initializes the command node.
1630 * @param priv A pointer to wlan_private structure
1631 * @param ptempnode A pointer to cmd_ctrl_node structure
1632 * @param cmd_oid cmd oid: treated as sub command
1633 * @param wait_option wait option: wait response or not
1634 * @param pdata_buf A pointer to informaion buffer
1637 void libertas_set_cmd_ctrl_node(wlan_private * priv,
1638 struct cmd_ctrl_node *ptempnode,
1639 u32 cmd_oid, u16 wait_option, void *pdata_buf)
1646 ptempnode->cmd_oid = cmd_oid;
1647 ptempnode->wait_option = wait_option;
1648 ptempnode->pdata_buf = pdata_buf;
1654 * @brief This function executes next command in command
1655 * pending queue. It will put fimware back to PS mode
1658 * @param priv A pointer to wlan_private structure
1661 int libertas_execute_next_command(wlan_private * priv)
1663 wlan_adapter *adapter = priv->adapter;
1664 struct cmd_ctrl_node *cmdnode = NULL;
1665 struct cmd_ds_command *cmdptr;
1666 unsigned long flags;
1669 lbs_pr_debug(1, "libertas_execute_next_command\n");
1671 spin_lock_irqsave(&adapter->driver_lock, flags);
1673 if (adapter->cur_cmd) {
1674 lbs_pr_alert( "EXEC_NEXT_CMD: there is command in processing!\n");
1675 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1680 if (!list_empty(&adapter->cmdpendingq)) {
1681 cmdnode = (struct cmd_ctrl_node *)
1682 adapter->cmdpendingq.next;
1685 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1689 "EXEC_NEXT_CMD: Got next command from cmdpendingq\n");
1690 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1692 if (is_command_allowed_in_ps(cmdptr->command)) {
1693 if ((adapter->psstate == PS_STATE_SLEEP)
1694 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1697 "EXEC_NEXT_CMD: Cannot send cmd 0x%x in psstate %d\n",
1698 cmdptr->command, adapter->psstate);
1702 lbs_pr_debug(1, "EXEC_NEXT_CMD: OK to send command "
1703 "0x%x in psstate %d\n",
1704 cmdptr->command, adapter->psstate);
1705 } else if (adapter->psstate != PS_STATE_FULL_POWER) {
1707 * 1. Non-PS command:
1708 * Queue it. set needtowakeup to TRUE if current state
1709 * is SLEEP, otherwise call libertas_ps_wakeup to send Exit_PS.
1710 * 2. PS command but not Exit_PS:
1712 * 3. PS command Exit_PS:
1713 * Set needtowakeup to TRUE if current state is SLEEP,
1714 * otherwise send this command down to firmware
1717 if (cmdptr->command !=
1718 cpu_to_le16(cmd_802_11_ps_mode)) {
1719 /* Prepare to send Exit PS,
1720 * this non PS command will be sent later */
1721 if ((adapter->psstate == PS_STATE_SLEEP)
1722 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1724 /* w/ new scheme, it will not reach here.
1725 since it is blocked in main_thread. */
1726 adapter->needtowakeup = 1;
1728 libertas_ps_wakeup(priv, 0);
1734 * PS command. Ignore it if it is not Exit_PS.
1735 * otherwise send it down immediately.
1737 struct cmd_ds_802_11_ps_mode *psm =
1738 &cmdptr->params.psmode;
1741 "EXEC_NEXT_CMD: PS cmd- action=0x%x\n",
1744 cpu_to_le16(cmd_subcmd_exit_ps)) {
1746 "EXEC_NEXT_CMD: Ignore Enter PS cmd\n");
1747 list_del((struct list_head *)cmdnode);
1748 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1754 if ((adapter->psstate == PS_STATE_SLEEP)
1755 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1758 "EXEC_NEXT_CMD: Ignore ExitPS cmd in sleep\n");
1759 list_del((struct list_head *)cmdnode);
1760 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1761 adapter->needtowakeup = 1;
1768 "EXEC_NEXT_CMD: Sending Exit_PS down...\n");
1771 list_del((struct list_head *)cmdnode);
1772 lbs_pr_debug(1, "EXEC_NEXT_CMD: Sending 0x%04X command\n",
1774 DownloadcommandToStation(priv, cmdnode);
1777 * check if in power save mode, if yes, put the device back
1780 if ((adapter->psmode != wlan802_11powermodecam) &&
1781 (adapter->psstate == PS_STATE_FULL_POWER) &&
1782 (adapter->connect_status == libertas_connected)) {
1783 if (adapter->secinfo.WPAenabled
1784 || adapter->secinfo.WPA2enabled) {
1785 /* check for valid WPA group keys */
1786 if (adapter->wpa_mcast_key.len
1787 || adapter->wpa_unicast_key.len) {
1789 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1790 " go back to PS_SLEEP");
1791 libertas_ps_sleep(priv, 0);
1795 "EXEC_NEXT_CMD: command PendQ is empty,"
1796 " go back to PS_SLEEP");
1797 libertas_ps_sleep(priv, 0);
1807 void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str)
1809 union iwreq_data iwrq;
1814 memset(&iwrq, 0, sizeof(union iwreq_data));
1815 memset(buf, 0, sizeof(buf));
1817 snprintf(buf, sizeof(buf) - 1, "%s", str);
1819 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1821 /* Send Event to upper layer */
1822 lbs_pr_debug(1, "Event Indication string = %s\n",
1824 lbs_pr_debug(1, "Event Indication String length = %d\n", iwrq.data.length);
1826 lbs_pr_debug(1, "Sending wireless event IWEVCUSTOM for %s\n", str);
1827 wireless_send_event(priv->wlan_dev.netdev, IWEVCUSTOM, &iwrq, buf);
1833 static int sendconfirmsleep(wlan_private * priv, u8 * cmdptr, u16 size)
1835 unsigned long flags;
1836 wlan_adapter *adapter = priv->adapter;
1841 lbs_pr_debug(1, "SEND_SLEEPC_CMD: Before download, size of cmd = %d\n",
1844 lbs_dbg_hex("SEND_SLEEPC_CMD: Sleep confirm command", cmdptr, size);
1846 ret = libertas_sbi_host_to_card(priv, MVMS_CMD, cmdptr, size);
1847 priv->wlan_dev.dnld_sent = DNLD_RES_RECEIVED;
1849 spin_lock_irqsave(&adapter->driver_lock, flags);
1850 if (adapter->intcounter || adapter->currenttxskb)
1851 lbs_pr_debug(1, "SEND_SLEEPC_CMD: intcounter=%d currenttxskb=%p\n",
1852 adapter->intcounter, adapter->currenttxskb);
1853 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1857 "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
1859 spin_lock_irqsave(&adapter->driver_lock, flags);
1860 if (!adapter->intcounter) {
1861 adapter->psstate = PS_STATE_SLEEP;
1863 lbs_pr_debug(1, "SEND_SLEEPC_CMD: After sent,IntC=%d\n",
1864 adapter->intcounter);
1866 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1868 lbs_pr_debug(1, "SEND_SLEEPC_CMD: Sent Confirm Sleep command\n");
1869 lbs_pr_debug(1, "+");
1876 void libertas_ps_sleep(wlan_private * priv, int wait_option)
1882 * PS is currently supported only in Infrastructure mode
1883 * Remove this check if it is to be supported in IBSS mode also
1886 libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
1887 cmd_subcmd_enter_ps, wait_option, 0, NULL);
1894 * @brief This function sends Eixt_PS command to firmware.
1896 * @param priv A pointer to wlan_private structure
1897 * @param wait_option wait response or not
1900 void libertas_ps_wakeup(wlan_private * priv, int wait_option)
1902 enum WLAN_802_11_POWER_MODE Localpsmode;
1906 Localpsmode = wlan802_11powermodecam;
1908 lbs_pr_debug(1, "Exit_PS: Localpsmode = %d\n", Localpsmode);
1910 libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
1912 wait_option, 0, &Localpsmode);
1919 * @brief This function checks condition and prepares to
1920 * send sleep confirm command to firmware if ok.
1922 * @param priv A pointer to wlan_private structure
1923 * @param psmode Power Saving mode
1926 void libertas_ps_confirm_sleep(wlan_private * priv, u16 psmode)
1928 unsigned long flags =0;
1929 wlan_adapter *adapter = priv->adapter;
1934 if (priv->wlan_dev.dnld_sent) {
1936 lbs_pr_debug(1, "D");
1939 spin_lock_irqsave(&adapter->driver_lock, flags);
1940 if (adapter->cur_cmd) {
1942 lbs_pr_debug(1, "C");
1944 if (adapter->intcounter > 0) {
1946 lbs_pr_debug(1, "I%d", adapter->intcounter);
1948 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1951 lbs_pr_debug(1, "Sending libertas_ps_confirm_sleep\n");
1952 sendconfirmsleep(priv, (u8 *) & adapter->libertas_ps_confirm_sleep,
1953 sizeof(struct PS_CMD_ConfirmSleep));
1955 lbs_pr_debug(1, "Sleep Confirm has been delayed\n");