2 * This file contains the handling of command.
3 * It prepares command and sends it to firmware when it is ready.
6 #include <net/iw_handler.h>
15 static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode);
17 static u16 commands_allowed_in_ps[] = {
22 * @brief This function checks if the commans is allowed
25 * @param command the command ID
26 * @return TRUE or FALSE
28 static u8 is_command_allowed_in_ps(__le16 command)
32 for (i = 0; i < ARRAY_SIZE(commands_allowed_in_ps); i++) {
33 if (command == cpu_to_le16(commands_allowed_in_ps[i]))
40 static int wlan_cmd_hw_spec(wlan_private * priv, struct cmd_ds_command *cmd)
42 struct cmd_ds_get_hw_spec *hwspec = &cmd->params.hwspec;
44 lbs_deb_enter(LBS_DEB_CMD);
46 cmd->command = cpu_to_le16(CMD_GET_HW_SPEC);
47 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_get_hw_spec) + S_DS_GEN);
48 memcpy(hwspec->permanentaddr, priv->adapter->current_addr, ETH_ALEN);
50 lbs_deb_leave(LBS_DEB_CMD);
54 static int wlan_cmd_802_11_ps_mode(wlan_private * priv,
55 struct cmd_ds_command *cmd,
58 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
59 wlan_adapter *adapter = priv->adapter;
61 lbs_deb_enter(LBS_DEB_CMD);
63 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
64 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
66 psm->action = cpu_to_le16(cmd_action);
67 psm->multipledtim = 0;
69 case CMD_SUBCMD_ENTER_PS:
70 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
71 lbs_deb_cmd("locallisteninterval %d\n",
72 adapter->locallisteninterval);
74 psm->locallisteninterval =
75 cpu_to_le16(adapter->locallisteninterval);
76 psm->nullpktinterval =
77 cpu_to_le16(adapter->nullpktinterval);
79 cpu_to_le16(priv->adapter->multipledtim);
82 case CMD_SUBCMD_EXIT_PS:
83 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
86 case CMD_SUBCMD_SLEEP_CONFIRMED:
87 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
94 lbs_deb_leave(LBS_DEB_CMD);
98 static int wlan_cmd_802_11_inactivity_timeout(wlan_private * priv,
99 struct cmd_ds_command *cmd,
100 u16 cmd_action, void *pdata_buf)
102 u16 *timeout = pdata_buf;
104 lbs_deb_enter(LBS_DEB_CMD);
106 cmd->command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
108 cpu_to_le16(sizeof(struct cmd_ds_802_11_inactivity_timeout)
111 cmd->params.inactivity_timeout.action = cpu_to_le16(cmd_action);
114 cmd->params.inactivity_timeout.timeout = cpu_to_le16(*timeout);
116 cmd->params.inactivity_timeout.timeout = 0;
118 lbs_deb_leave(LBS_DEB_CMD);
122 static int wlan_cmd_802_11_sleep_params(wlan_private * priv,
123 struct cmd_ds_command *cmd,
126 wlan_adapter *adapter = priv->adapter;
127 struct cmd_ds_802_11_sleep_params *sp = &cmd->params.sleep_params;
129 lbs_deb_enter(LBS_DEB_CMD);
131 cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
133 cmd->command = cpu_to_le16(CMD_802_11_SLEEP_PARAMS);
135 if (cmd_action == CMD_ACT_GET) {
136 memset(&adapter->sp, 0, sizeof(struct sleep_params));
137 memset(sp, 0, sizeof(struct cmd_ds_802_11_sleep_params));
138 sp->action = cpu_to_le16(cmd_action);
139 } else if (cmd_action == CMD_ACT_SET) {
140 sp->action = cpu_to_le16(cmd_action);
141 sp->error = cpu_to_le16(adapter->sp.sp_error);
142 sp->offset = cpu_to_le16(adapter->sp.sp_offset);
143 sp->stabletime = cpu_to_le16(adapter->sp.sp_stabletime);
144 sp->calcontrol = (u8) adapter->sp.sp_calcontrol;
145 sp->externalsleepclk = (u8) adapter->sp.sp_extsleepclk;
146 sp->reserved = cpu_to_le16(adapter->sp.sp_reserved);
149 lbs_deb_leave(LBS_DEB_CMD);
153 static int wlan_cmd_802_11_set_wep(wlan_private * priv,
154 struct cmd_ds_command *cmd,
158 struct cmd_ds_802_11_set_wep *wep = &cmd->params.wep;
159 wlan_adapter *adapter = priv->adapter;
161 struct assoc_request * assoc_req = pdata_buf;
163 lbs_deb_enter(LBS_DEB_CMD);
165 cmd->command = cpu_to_le16(CMD_802_11_SET_WEP);
166 cmd->size = cpu_to_le16(sizeof(*wep) + S_DS_GEN);
168 if (cmd_act == CMD_ACT_ADD) {
172 lbs_deb_cmd("Invalid association request!");
177 wep->action = cpu_to_le16(CMD_ACT_ADD);
179 /* default tx key index */
180 wep->keyindex = cpu_to_le16((u16)(assoc_req->wep_tx_keyidx &
181 (u32)CMD_WEP_KEY_INDEX_MASK));
183 /* Copy key types and material to host command structure */
184 for (i = 0; i < 4; i++) {
185 struct enc_key * pkey = &assoc_req->wep_keys[i];
190 cpu_to_le16(CMD_TYPE_WEP_40_BIT);
191 memmove(&wep->keymaterial[i], pkey->key,
193 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
195 case KEY_LEN_WEP_104:
197 cpu_to_le16(CMD_TYPE_WEP_104_BIT);
198 memmove(&wep->keymaterial[i], pkey->key,
200 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
205 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
212 } else if (cmd_act == CMD_ACT_REMOVE) {
213 /* ACT_REMOVE clears _all_ WEP keys */
214 wep->action = cpu_to_le16(CMD_ACT_REMOVE);
216 /* default tx key index */
217 wep->keyindex = cpu_to_le16((u16)(adapter->wep_tx_keyidx &
218 (u32)CMD_WEP_KEY_INDEX_MASK));
219 lbs_deb_cmd("SET_WEP: remove key %d\n", adapter->wep_tx_keyidx);
225 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
229 static int wlan_cmd_802_11_enable_rsn(wlan_private * priv,
230 struct cmd_ds_command *cmd,
234 struct cmd_ds_802_11_enable_rsn *penableRSN = &cmd->params.enbrsn;
235 u32 * enable = pdata_buf;
237 lbs_deb_enter(LBS_DEB_CMD);
239 cmd->command = cpu_to_le16(CMD_802_11_ENABLE_RSN);
240 cmd->size = cpu_to_le16(sizeof(*penableRSN) + S_DS_GEN);
241 penableRSN->action = cpu_to_le16(cmd_action);
243 if (cmd_action == CMD_ACT_SET) {
245 penableRSN->enable = cpu_to_le16(CMD_ENABLE_RSN);
247 penableRSN->enable = cpu_to_le16(CMD_DISABLE_RSN);
248 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
251 lbs_deb_leave(LBS_DEB_CMD);
256 static void set_one_wpa_key(struct MrvlIEtype_keyParamSet * pkeyparamset,
257 struct enc_key * pkey)
259 lbs_deb_enter(LBS_DEB_CMD);
261 if (pkey->flags & KEY_INFO_WPA_ENABLED) {
262 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
264 if (pkey->flags & KEY_INFO_WPA_UNICAST) {
265 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
267 if (pkey->flags & KEY_INFO_WPA_MCAST) {
268 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
271 pkeyparamset->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
272 pkeyparamset->keytypeid = cpu_to_le16(pkey->type);
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));
279 lbs_deb_leave(LBS_DEB_CMD);
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 struct cmd_ds_802_11_key_material *pkeymaterial =
288 &cmd->params.keymaterial;
289 struct assoc_request * assoc_req = pdata_buf;
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 + sizeof (pkeymaterial->action));
304 memset(&pkeymaterial->keyParamSet, 0, sizeof(pkeymaterial->keyParamSet));
306 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
307 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
308 &assoc_req->wpa_unicast_key);
312 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
313 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
314 &assoc_req->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 lbs_deb_enter(LBS_DEB_CMD);
336 cmd->command = cpu_to_le16(CMD_802_11_RESET);
337 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
338 reset->action = cpu_to_le16(cmd_action);
340 lbs_deb_leave(LBS_DEB_CMD);
344 static int wlan_cmd_802_11_get_log(wlan_private * priv,
345 struct cmd_ds_command *cmd)
347 lbs_deb_enter(LBS_DEB_CMD);
348 cmd->command = cpu_to_le16(CMD_802_11_GET_LOG);
350 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_log) + S_DS_GEN);
352 lbs_deb_leave(LBS_DEB_CMD);
356 static int wlan_cmd_802_11_get_stat(wlan_private * priv,
357 struct cmd_ds_command *cmd)
359 lbs_deb_enter(LBS_DEB_CMD);
360 cmd->command = cpu_to_le16(CMD_802_11_GET_STAT);
362 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) + S_DS_GEN);
364 lbs_deb_leave(LBS_DEB_CMD);
368 static int wlan_cmd_802_11_snmp_mib(wlan_private * priv,
369 struct cmd_ds_command *cmd,
371 int cmd_oid, void *pdata_buf)
373 struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib;
374 wlan_adapter *adapter = priv->adapter;
377 lbs_deb_enter(LBS_DEB_CMD);
379 lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
381 cmd->command = cpu_to_le16(CMD_802_11_SNMP_MIB);
382 cmd->size = cpu_to_le16(sizeof(*pSNMPMIB) + S_DS_GEN);
385 case OID_802_11_INFRASTRUCTURE_MODE:
387 u8 mode = (u8) (size_t) pdata_buf;
388 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
389 pSNMPMIB->oid = cpu_to_le16((u16) DESIRED_BSSTYPE_I);
390 pSNMPMIB->bufsize = sizeof(u8);
391 if (mode == IW_MODE_ADHOC) {
392 ucTemp = SNMP_MIB_VALUE_ADHOC;
394 /* Infra and Auto modes */
395 ucTemp = SNMP_MIB_VALUE_INFRA;
398 memmove(pSNMPMIB->value, &ucTemp, sizeof(u8));
403 case OID_802_11D_ENABLE:
407 pSNMPMIB->oid = cpu_to_le16((u16) DOT11D_I);
409 if (cmd_action == CMD_ACT_SET) {
410 pSNMPMIB->querytype = CMD_ACT_SET;
411 pSNMPMIB->bufsize = sizeof(u16);
412 ulTemp = *(u32 *)pdata_buf;
413 *((__le16 *)(pSNMPMIB->value)) =
414 cpu_to_le16((u16) ulTemp);
419 case OID_802_11_FRAGMENTATION_THRESHOLD:
423 pSNMPMIB->oid = cpu_to_le16((u16) FRAGTHRESH_I);
425 if (cmd_action == CMD_ACT_GET) {
426 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
427 } else if (cmd_action == CMD_ACT_SET) {
428 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
429 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
430 ulTemp = *((u32 *) pdata_buf);
431 *((__le16 *)(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 = cpu_to_le16(CMD_ACT_GET);
447 } else if (cmd_action == CMD_ACT_SET) {
448 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
449 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
450 ulTemp = *((u32 *)pdata_buf);
451 *(__le16 *)(pSNMPMIB->value) =
452 cpu_to_le16((u16) ulTemp);
457 case OID_802_11_TX_RETRYCOUNT:
458 pSNMPMIB->oid = cpu_to_le16((u16) SHORT_RETRYLIM_I);
460 if (cmd_action == CMD_ACT_GET) {
461 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
462 } else if (cmd_action == CMD_ACT_SET) {
463 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
464 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
465 *((__le16 *)(pSNMPMIB->value)) =
466 cpu_to_le16((u16) adapter->txretrycount);
475 "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
476 le16_to_cpu(cmd->command), le16_to_cpu(cmd->size),
477 le16_to_cpu(cmd->seqnum), le16_to_cpu(cmd->result));
480 "SNMP_CMD: action 0x%x, oid 0x%x, oidsize 0x%x, value 0x%x\n",
481 le16_to_cpu(pSNMPMIB->querytype), le16_to_cpu(pSNMPMIB->oid),
482 le16_to_cpu(pSNMPMIB->bufsize),
483 le16_to_cpu(*(__le16 *) pSNMPMIB->value));
485 lbs_deb_leave(LBS_DEB_CMD);
489 static int wlan_cmd_802_11_radio_control(wlan_private * priv,
490 struct cmd_ds_command *cmd,
493 wlan_adapter *adapter = priv->adapter;
494 struct cmd_ds_802_11_radio_control *pradiocontrol = &cmd->params.radio;
496 lbs_deb_enter(LBS_DEB_CMD);
499 cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control)) +
501 cmd->command = cpu_to_le16(CMD_802_11_RADIO_CONTROL);
503 pradiocontrol->action = cpu_to_le16(cmd_action);
505 switch (adapter->preamble) {
506 case CMD_TYPE_SHORT_PREAMBLE:
507 pradiocontrol->control = cpu_to_le16(SET_SHORT_PREAMBLE);
510 case CMD_TYPE_LONG_PREAMBLE:
511 pradiocontrol->control = cpu_to_le16(SET_LONG_PREAMBLE);
514 case CMD_TYPE_AUTO_PREAMBLE:
516 pradiocontrol->control = cpu_to_le16(SET_AUTO_PREAMBLE);
520 if (adapter->radioon)
521 pradiocontrol->control |= cpu_to_le16(TURN_ON_RF);
523 pradiocontrol->control &= cpu_to_le16(~TURN_ON_RF);
525 lbs_deb_leave(LBS_DEB_CMD);
529 static int wlan_cmd_802_11_rf_tx_power(wlan_private * priv,
530 struct cmd_ds_command *cmd,
531 u16 cmd_action, void *pdata_buf)
534 struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
536 lbs_deb_enter(LBS_DEB_CMD);
539 cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN);
540 cmd->command = cpu_to_le16(CMD_802_11_RF_TX_POWER);
541 prtp->action = cpu_to_le16(cmd_action);
543 lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
544 le16_to_cpu(cmd->size), le16_to_cpu(cmd->command),
545 le16_to_cpu(prtp->action));
547 switch (cmd_action) {
548 case CMD_ACT_TX_POWER_OPT_GET:
549 prtp->action = cpu_to_le16(CMD_ACT_GET);
550 prtp->currentlevel = 0;
553 case CMD_ACT_TX_POWER_OPT_SET_HIGH:
554 prtp->action = cpu_to_le16(CMD_ACT_SET);
555 prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_HIGH);
558 case CMD_ACT_TX_POWER_OPT_SET_MID:
559 prtp->action = cpu_to_le16(CMD_ACT_SET);
560 prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_MID);
563 case CMD_ACT_TX_POWER_OPT_SET_LOW:
564 prtp->action = cpu_to_le16(CMD_ACT_SET);
565 prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
569 lbs_deb_leave(LBS_DEB_CMD);
573 static int wlan_cmd_802_11_rate_adapt_rateset(wlan_private * priv,
574 struct cmd_ds_command *cmd,
577 struct cmd_ds_802_11_rate_adapt_rateset
578 *rateadapt = &cmd->params.rateset;
579 wlan_adapter *adapter = priv->adapter;
581 lbs_deb_enter(LBS_DEB_CMD);
583 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
585 cmd->command = cpu_to_le16(CMD_802_11_RATE_ADAPT_RATESET);
587 rateadapt->action = cpu_to_le16(cmd_action);
588 rateadapt->enablehwauto = cpu_to_le16(adapter->enablehwauto);
589 rateadapt->bitmap = cpu_to_le16(adapter->ratebitmap);
591 lbs_deb_leave(LBS_DEB_CMD);
595 static int wlan_cmd_802_11_data_rate(wlan_private * priv,
596 struct cmd_ds_command *cmd,
599 struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
600 wlan_adapter *adapter = priv->adapter;
602 lbs_deb_enter(LBS_DEB_CMD);
604 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
606 cmd->command = cpu_to_le16(CMD_802_11_DATA_RATE);
607 memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate));
608 pdatarate->action = cpu_to_le16(cmd_action);
610 if (cmd_action == CMD_ACT_SET_TX_FIX_RATE) {
611 pdatarate->rates[0] = libertas_data_rate_to_fw_index(adapter->cur_rate);
612 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n",
614 } else if (cmd_action == CMD_ACT_SET_TX_AUTO) {
615 lbs_deb_cmd("DATA_RATE: setting auto\n");
618 lbs_deb_leave(LBS_DEB_CMD);
622 static int wlan_cmd_mac_multicast_adr(wlan_private * priv,
623 struct cmd_ds_command *cmd,
626 struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
627 wlan_adapter *adapter = priv->adapter;
629 lbs_deb_enter(LBS_DEB_CMD);
630 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
632 cmd->command = cpu_to_le16(CMD_MAC_MULTICAST_ADR);
634 lbs_deb_cmd("MULTICAST_ADR: setting %d addresses\n", pMCastAdr->nr_of_adrs);
635 pMCastAdr->action = cpu_to_le16(cmd_action);
636 pMCastAdr->nr_of_adrs =
637 cpu_to_le16((u16) adapter->nr_of_multicastmacaddr);
638 memcpy(pMCastAdr->maclist, adapter->multicastlist,
639 adapter->nr_of_multicastmacaddr * ETH_ALEN);
641 lbs_deb_leave(LBS_DEB_CMD);
645 static int wlan_cmd_802_11_rf_channel(wlan_private * priv,
646 struct cmd_ds_command *cmd,
647 int option, void *pdata_buf)
649 struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel;
651 lbs_deb_enter(LBS_DEB_CMD);
652 cmd->command = cpu_to_le16(CMD_802_11_RF_CHANNEL);
653 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel) +
656 if (option == CMD_OPT_802_11_RF_CHANNEL_SET) {
657 rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf));
660 rfchan->action = cpu_to_le16(option);
662 lbs_deb_leave(LBS_DEB_CMD);
666 static int wlan_cmd_802_11_rssi(wlan_private * priv,
667 struct cmd_ds_command *cmd)
669 wlan_adapter *adapter = priv->adapter;
671 lbs_deb_enter(LBS_DEB_CMD);
672 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
673 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
674 cmd->params.rssi.N = cpu_to_le16(priv->adapter->bcn_avg_factor);
676 /* reset Beacon SNR/NF/RSSI values */
677 adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
678 adapter->SNR[TYPE_BEACON][TYPE_AVG] = 0;
679 adapter->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
680 adapter->NF[TYPE_BEACON][TYPE_AVG] = 0;
681 adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
682 adapter->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
684 lbs_deb_leave(LBS_DEB_CMD);
688 static int wlan_cmd_reg_access(wlan_private * priv,
689 struct cmd_ds_command *cmdptr,
690 u8 cmd_action, void *pdata_buf)
692 struct wlan_offset_value *offval;
694 lbs_deb_enter(LBS_DEB_CMD);
696 offval = (struct wlan_offset_value *)pdata_buf;
698 switch (cmdptr->command) {
699 case CMD_MAC_REG_ACCESS:
701 struct cmd_ds_mac_reg_access *macreg;
704 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
707 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
710 macreg->action = cpu_to_le16(cmd_action);
711 macreg->offset = cpu_to_le16((u16) offval->offset);
712 macreg->value = cpu_to_le32(offval->value);
717 case CMD_BBP_REG_ACCESS:
719 struct cmd_ds_bbp_reg_access *bbpreg;
723 (struct cmd_ds_bbp_reg_access)
726 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
729 bbpreg->action = cpu_to_le16(cmd_action);
730 bbpreg->offset = cpu_to_le16((u16) offval->offset);
731 bbpreg->value = (u8) offval->value;
736 case CMD_RF_REG_ACCESS:
738 struct cmd_ds_rf_reg_access *rfreg;
742 (struct cmd_ds_rf_reg_access) +
745 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
748 rfreg->action = cpu_to_le16(cmd_action);
749 rfreg->offset = cpu_to_le16((u16) offval->offset);
750 rfreg->value = (u8) offval->value;
759 lbs_deb_leave(LBS_DEB_CMD);
763 static int wlan_cmd_802_11_mac_address(wlan_private * priv,
764 struct cmd_ds_command *cmd,
767 wlan_adapter *adapter = priv->adapter;
769 lbs_deb_enter(LBS_DEB_CMD);
770 cmd->command = cpu_to_le16(CMD_802_11_MAC_ADDRESS);
771 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
775 cmd->params.macadd.action = cpu_to_le16(cmd_action);
777 if (cmd_action == CMD_ACT_SET) {
778 memcpy(cmd->params.macadd.macadd,
779 adapter->current_addr, ETH_ALEN);
780 lbs_deb_hex(LBS_DEB_CMD, "SET_CMD: MAC addr", adapter->current_addr, 6);
783 lbs_deb_leave(LBS_DEB_CMD);
787 static int wlan_cmd_802_11_eeprom_access(wlan_private * priv,
788 struct cmd_ds_command *cmd,
789 int cmd_action, void *pdata_buf)
791 struct wlan_ioctl_regrdwr *ea = pdata_buf;
793 lbs_deb_enter(LBS_DEB_CMD);
795 cmd->command = cpu_to_le16(CMD_802_11_EEPROM_ACCESS);
796 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
800 cmd->params.rdeeprom.action = cpu_to_le16(ea->action);
801 cmd->params.rdeeprom.offset = cpu_to_le16(ea->offset);
802 cmd->params.rdeeprom.bytecount = cpu_to_le16(ea->NOB);
803 cmd->params.rdeeprom.value = 0;
805 lbs_deb_leave(LBS_DEB_CMD);
809 static int wlan_cmd_bt_access(wlan_private * priv,
810 struct cmd_ds_command *cmd,
811 u16 cmd_action, void *pdata_buf)
813 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
814 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
816 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
817 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
819 bt_access->action = cpu_to_le16(cmd_action);
821 switch (cmd_action) {
822 case CMD_ACT_BT_ACCESS_ADD:
823 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
824 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
826 case CMD_ACT_BT_ACCESS_DEL:
827 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
828 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
830 case CMD_ACT_BT_ACCESS_LIST:
831 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
833 case CMD_ACT_BT_ACCESS_RESET:
835 case CMD_ACT_BT_ACCESS_SET_INVERT:
836 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
838 case CMD_ACT_BT_ACCESS_GET_INVERT:
843 lbs_deb_leave(LBS_DEB_CMD);
847 static int wlan_cmd_fwt_access(wlan_private * priv,
848 struct cmd_ds_command *cmd,
849 u16 cmd_action, void *pdata_buf)
851 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
852 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
854 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
855 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
859 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
861 memset(fwt_access, 0, sizeof(*fwt_access));
863 fwt_access->action = cpu_to_le16(cmd_action);
865 lbs_deb_leave(LBS_DEB_CMD);
869 static int wlan_cmd_mesh_access(wlan_private * priv,
870 struct cmd_ds_command *cmd,
871 u16 cmd_action, void *pdata_buf)
873 struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
874 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
876 cmd->command = cpu_to_le16(CMD_MESH_ACCESS);
877 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access) + S_DS_GEN);
881 memcpy(mesh_access, pdata_buf, sizeof(*mesh_access));
883 memset(mesh_access, 0, sizeof(*mesh_access));
885 mesh_access->action = cpu_to_le16(cmd_action);
887 lbs_deb_leave(LBS_DEB_CMD);
891 void libertas_queue_cmd(wlan_adapter * adapter, struct cmd_ctrl_node *cmdnode, u8 addtail)
894 struct cmd_ds_command *cmdptr;
896 lbs_deb_enter(LBS_DEB_HOST);
899 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
903 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
905 lbs_deb_host("QUEUE_CMD: cmdptr is NULL\n");
909 /* Exit_PS command needs to be queued in the header always. */
910 if (cmdptr->command == CMD_802_11_PS_MODE) {
911 struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
912 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
913 if (adapter->psstate != PS_STATE_FULL_POWER)
918 spin_lock_irqsave(&adapter->driver_lock, flags);
921 list_add_tail((struct list_head *)cmdnode,
922 &adapter->cmdpendingq);
924 list_add((struct list_head *)cmdnode, &adapter->cmdpendingq);
926 spin_unlock_irqrestore(&adapter->driver_lock, flags);
928 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
929 le16_to_cpu(((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command));
932 lbs_deb_leave(LBS_DEB_HOST);
936 * TODO: Fix the issue when DownloadcommandToStation is being called the
937 * second time when the command times out. All the cmdptr->xxx are in little
938 * endian and therefore all the comparissions will fail.
939 * For now - we are not performing the endian conversion the second time - but
940 * for PS and DEEP_SLEEP we need to worry
942 static int DownloadcommandToStation(wlan_private * priv,
943 struct cmd_ctrl_node *cmdnode)
946 struct cmd_ds_command *cmdptr;
947 wlan_adapter *adapter = priv->adapter;
952 lbs_deb_enter(LBS_DEB_HOST);
954 if (!adapter || !cmdnode) {
955 lbs_deb_host("DNLD_CMD: adapter or cmdmode is NULL\n");
957 spin_lock_irqsave(&adapter->driver_lock, flags);
958 __libertas_cleanup_and_insert_cmd(priv, cmdnode);
959 spin_unlock_irqrestore(&adapter->driver_lock, flags);
965 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
967 spin_lock_irqsave(&adapter->driver_lock, flags);
968 if (!cmdptr || !cmdptr->size) {
969 lbs_deb_host("DNLD_CMD: cmdptr is NULL or zero\n");
970 __libertas_cleanup_and_insert_cmd(priv, cmdnode);
971 spin_unlock_irqrestore(&adapter->driver_lock, flags);
976 adapter->cur_cmd = cmdnode;
977 adapter->cur_cmd_retcode = 0;
978 spin_unlock_irqrestore(&adapter->driver_lock, flags);
980 cmdsize = cmdptr->size;
981 command = cpu_to_le16(cmdptr->command);
983 lbs_deb_host("DNLD_CMD: command 0x%04x, size %d, jiffies %lu\n",
984 command, le16_to_cpu(cmdptr->size), jiffies);
985 lbs_deb_hex(LBS_DEB_HOST, "DNLD_CMD", cmdnode->bufvirtualaddr, cmdsize);
987 cmdnode->cmdwaitqwoken = 0;
988 cmdsize = cpu_to_le16(cmdsize);
990 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
993 lbs_deb_host("DNLD_CMD: hw_host_to_card failed\n");
994 spin_lock_irqsave(&adapter->driver_lock, flags);
995 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
996 adapter->cur_cmd = NULL;
997 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1002 lbs_deb_cmd("DNLD_CMD: sent command 0x%04x, jiffies %lu\n", command, jiffies);
1004 /* Setup the timer after transmit command */
1005 if (command == CMD_802_11_SCAN || command == CMD_802_11_AUTHENTICATE
1006 || command == CMD_802_11_ASSOCIATE)
1007 mod_timer(&adapter->command_timer, jiffies + (10*HZ));
1009 mod_timer(&adapter->command_timer, jiffies + (5*HZ));
1014 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1018 static int wlan_cmd_mac_control(wlan_private * priv,
1019 struct cmd_ds_command *cmd)
1021 struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
1023 lbs_deb_enter(LBS_DEB_CMD);
1025 cmd->command = cpu_to_le16(CMD_MAC_CONTROL);
1026 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
1027 mac->action = cpu_to_le16(priv->adapter->currentpacketfilter);
1029 lbs_deb_cmd("MAC_CONTROL: action 0x%x, size %d\n",
1030 le16_to_cpu(mac->action), le16_to_cpu(cmd->size));
1032 lbs_deb_leave(LBS_DEB_CMD);
1037 * This function inserts command node to cmdfreeq
1038 * after cleans it. Requires adapter->driver_lock held.
1040 void __libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
1042 wlan_adapter *adapter = priv->adapter;
1047 cleanup_cmdnode(ptempcmd);
1048 list_add_tail((struct list_head *)ptempcmd, &adapter->cmdfreeq);
1051 static void libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
1053 unsigned long flags;
1055 spin_lock_irqsave(&priv->adapter->driver_lock, flags);
1056 __libertas_cleanup_and_insert_cmd(priv, ptempcmd);
1057 spin_unlock_irqrestore(&priv->adapter->driver_lock, flags);
1060 int libertas_set_radio_control(wlan_private * priv)
1064 lbs_deb_enter(LBS_DEB_CMD);
1066 ret = libertas_prepare_and_send_command(priv,
1067 CMD_802_11_RADIO_CONTROL,
1069 CMD_OPTION_WAITFORRSP, 0, NULL);
1071 lbs_deb_cmd("RADIO_SET: radio %d, preamble %d\n",
1072 priv->adapter->radioon, priv->adapter->preamble);
1074 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1078 int libertas_set_mac_packet_filter(wlan_private * priv)
1082 lbs_deb_enter(LBS_DEB_CMD);
1084 /* Send MAC control command to station */
1085 ret = libertas_prepare_and_send_command(priv,
1086 CMD_MAC_CONTROL, 0, 0, 0, NULL);
1088 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1093 * @brief This function prepare the command before send to firmware.
1095 * @param priv A pointer to wlan_private structure
1096 * @param cmd_no command number
1097 * @param cmd_action command action: GET or SET
1098 * @param wait_option wait option: wait response or not
1099 * @param cmd_oid cmd oid: treated as sub command
1100 * @param pdata_buf A pointer to informaion buffer
1103 int libertas_prepare_and_send_command(wlan_private * priv,
1106 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1109 wlan_adapter *adapter = priv->adapter;
1110 struct cmd_ctrl_node *cmdnode;
1111 struct cmd_ds_command *cmdptr;
1112 unsigned long flags;
1114 lbs_deb_enter(LBS_DEB_HOST);
1117 lbs_deb_host("PREP_CMD: adapter is NULL\n");
1122 if (adapter->surpriseremoved) {
1123 lbs_deb_host("PREP_CMD: card removed\n");
1128 cmdnode = libertas_get_free_cmd_ctrl_node(priv);
1130 if (cmdnode == NULL) {
1131 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1133 /* Wake up main thread to execute next command */
1134 wake_up_interruptible(&priv->waitq);
1139 libertas_set_cmd_ctrl_node(priv, cmdnode, cmd_oid, wait_option, pdata_buf);
1141 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1143 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
1146 lbs_deb_host("PREP_CMD: cmdptr is NULL\n");
1147 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1152 /* Set sequence number, command and INT option */
1154 cmdptr->seqnum = cpu_to_le16(adapter->seqnum);
1156 cmdptr->command = cpu_to_le16(cmd_no);
1160 case CMD_GET_HW_SPEC:
1161 ret = wlan_cmd_hw_spec(priv, cmdptr);
1163 case CMD_802_11_PS_MODE:
1164 ret = wlan_cmd_802_11_ps_mode(priv, cmdptr, cmd_action);
1167 case CMD_802_11_SCAN:
1168 ret = libertas_cmd_80211_scan(priv, cmdptr, pdata_buf);
1171 case CMD_MAC_CONTROL:
1172 ret = wlan_cmd_mac_control(priv, cmdptr);
1175 case CMD_802_11_ASSOCIATE:
1176 case CMD_802_11_REASSOCIATE:
1177 ret = libertas_cmd_80211_associate(priv, cmdptr, pdata_buf);
1180 case CMD_802_11_DEAUTHENTICATE:
1181 ret = libertas_cmd_80211_deauthenticate(priv, cmdptr);
1184 case CMD_802_11_SET_WEP:
1185 ret = wlan_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf);
1188 case CMD_802_11_AD_HOC_START:
1189 ret = libertas_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
1194 case CMD_802_11_RESET:
1195 ret = wlan_cmd_802_11_reset(priv, cmdptr, cmd_action);
1198 case CMD_802_11_GET_LOG:
1199 ret = wlan_cmd_802_11_get_log(priv, cmdptr);
1202 case CMD_802_11_AUTHENTICATE:
1203 ret = libertas_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
1206 case CMD_802_11_GET_STAT:
1207 ret = wlan_cmd_802_11_get_stat(priv, cmdptr);
1210 case CMD_802_11_SNMP_MIB:
1211 ret = wlan_cmd_802_11_snmp_mib(priv, cmdptr,
1212 cmd_action, cmd_oid, pdata_buf);
1215 case CMD_MAC_REG_ACCESS:
1216 case CMD_BBP_REG_ACCESS:
1217 case CMD_RF_REG_ACCESS:
1218 ret = wlan_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf);
1221 case CMD_802_11_RF_CHANNEL:
1222 ret = wlan_cmd_802_11_rf_channel(priv, cmdptr,
1223 cmd_action, pdata_buf);
1226 case CMD_802_11_RF_TX_POWER:
1227 ret = wlan_cmd_802_11_rf_tx_power(priv, cmdptr,
1228 cmd_action, pdata_buf);
1231 case CMD_802_11_RADIO_CONTROL:
1232 ret = wlan_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
1235 case CMD_802_11_DATA_RATE:
1236 ret = wlan_cmd_802_11_data_rate(priv, cmdptr, cmd_action);
1238 case CMD_802_11_RATE_ADAPT_RATESET:
1239 ret = wlan_cmd_802_11_rate_adapt_rateset(priv,
1240 cmdptr, cmd_action);
1243 case CMD_MAC_MULTICAST_ADR:
1244 ret = wlan_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
1247 case CMD_802_11_AD_HOC_JOIN:
1248 ret = libertas_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
1251 case CMD_802_11_RSSI:
1252 ret = wlan_cmd_802_11_rssi(priv, cmdptr);
1255 case CMD_802_11_AD_HOC_STOP:
1256 ret = libertas_cmd_80211_ad_hoc_stop(priv, cmdptr);
1259 case CMD_802_11_ENABLE_RSN:
1260 ret = wlan_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action,
1264 case CMD_802_11_KEY_MATERIAL:
1265 ret = wlan_cmd_802_11_key_material(priv, cmdptr, cmd_action,
1266 cmd_oid, pdata_buf);
1269 case CMD_802_11_PAIRWISE_TSC:
1271 case CMD_802_11_GROUP_TSC:
1274 case CMD_802_11_MAC_ADDRESS:
1275 ret = wlan_cmd_802_11_mac_address(priv, cmdptr, cmd_action);
1278 case CMD_802_11_EEPROM_ACCESS:
1279 ret = wlan_cmd_802_11_eeprom_access(priv, cmdptr,
1280 cmd_action, pdata_buf);
1283 case CMD_802_11_SET_AFC:
1284 case CMD_802_11_GET_AFC:
1286 cmdptr->command = cpu_to_le16(cmd_no);
1287 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1290 memmove(&cmdptr->params.afc,
1291 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1296 case CMD_802_11D_DOMAIN_INFO:
1297 ret = libertas_cmd_802_11d_domain_info(priv, cmdptr,
1298 cmd_no, cmd_action);
1301 case CMD_802_11_SLEEP_PARAMS:
1302 ret = wlan_cmd_802_11_sleep_params(priv, cmdptr, cmd_action);
1304 case CMD_802_11_INACTIVITY_TIMEOUT:
1305 ret = wlan_cmd_802_11_inactivity_timeout(priv, cmdptr,
1306 cmd_action, pdata_buf);
1307 libertas_set_cmd_ctrl_node(priv, cmdnode, 0, 0, pdata_buf);
1310 case CMD_802_11_TPC_CFG:
1311 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
1313 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1316 memmove(&cmdptr->params.tpccfg,
1317 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1321 case CMD_802_11_LED_GPIO_CTRL:
1323 struct mrvlietypes_ledgpio *gpio =
1324 (struct mrvlietypes_ledgpio*)
1325 cmdptr->params.ledgpio.data;
1327 memmove(&cmdptr->params.ledgpio,
1329 sizeof(struct cmd_ds_802_11_led_ctrl));
1332 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
1334 #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1336 cpu_to_le16(gpio->header.len + S_DS_GEN +
1337 ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1338 gpio->header.len = cpu_to_le16(gpio->header.len);
1343 case CMD_802_11_PWR_CFG:
1344 cmdptr->command = cpu_to_le16(CMD_802_11_PWR_CFG);
1346 cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) +
1348 memmove(&cmdptr->params.pwrcfg, pdata_buf,
1349 sizeof(struct cmd_ds_802_11_pwr_cfg));
1354 ret = wlan_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf);
1357 case CMD_FWT_ACCESS:
1358 ret = wlan_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf);
1361 case CMD_MESH_ACCESS:
1362 ret = wlan_cmd_mesh_access(priv, cmdptr, cmd_action, pdata_buf);
1366 cmdptr->command = cpu_to_le16(CMD_GET_TSF);
1367 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1371 case CMD_802_11_TX_RATE_QUERY:
1372 cmdptr->command = cpu_to_le16(CMD_802_11_TX_RATE_QUERY);
1373 cmdptr->size = cpu_to_le16(sizeof(struct cmd_tx_rate_query) +
1375 adapter->txrate = 0;
1379 lbs_deb_host("PREP_CMD: unknown command 0x%04x\n", cmd_no);
1384 /* return error, since the command preparation failed */
1386 lbs_deb_host("PREP_CMD: command preparation failed\n");
1387 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1392 cmdnode->cmdwaitqwoken = 0;
1394 libertas_queue_cmd(adapter, cmdnode, 1);
1395 adapter->nr_cmd_pending++;
1396 wake_up_interruptible(&priv->waitq);
1398 if (wait_option & CMD_OPTION_WAITFORRSP) {
1399 lbs_deb_host("PREP_CMD: wait for response\n");
1401 wait_event_interruptible(cmdnode->cmdwait_q,
1402 cmdnode->cmdwaitqwoken);
1405 spin_lock_irqsave(&adapter->driver_lock, flags);
1406 if (adapter->cur_cmd_retcode) {
1407 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
1408 adapter->cur_cmd_retcode);
1409 adapter->cur_cmd_retcode = 0;
1412 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1415 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1418 EXPORT_SYMBOL_GPL(libertas_prepare_and_send_command);
1421 * @brief This function allocates the command buffer and link
1422 * it to command free queue.
1424 * @param priv A pointer to wlan_private structure
1427 int libertas_allocate_cmd_buffer(wlan_private * priv)
1432 struct cmd_ctrl_node *tempcmd_array;
1433 u8 *ptempvirtualaddr;
1434 wlan_adapter *adapter = priv->adapter;
1436 lbs_deb_enter(LBS_DEB_HOST);
1438 /* Allocate and initialize cmdCtrlNode */
1439 ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
1441 if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) {
1442 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
1446 adapter->cmd_array = tempcmd_array;
1448 /* Allocate and initialize command buffers */
1449 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1450 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1451 if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) {
1452 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
1457 /* Update command buffer virtual */
1458 tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
1461 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1462 init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
1463 libertas_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
1469 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1474 * @brief This function frees the command buffer.
1476 * @param priv A pointer to wlan_private structure
1479 int libertas_free_cmd_buffer(wlan_private * priv)
1481 u32 ulbufsize; /* Someone needs to die for this. Slowly and painfully */
1483 struct cmd_ctrl_node *tempcmd_array;
1484 wlan_adapter *adapter = priv->adapter;
1486 lbs_deb_enter(LBS_DEB_HOST);
1488 /* need to check if cmd array is allocated or not */
1489 if (adapter->cmd_array == NULL) {
1490 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
1494 tempcmd_array = adapter->cmd_array;
1496 /* Release shared memory buffers */
1497 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1498 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1499 if (tempcmd_array[i].bufvirtualaddr) {
1500 kfree(tempcmd_array[i].bufvirtualaddr);
1501 tempcmd_array[i].bufvirtualaddr = NULL;
1505 /* Release cmd_ctrl_node */
1506 if (adapter->cmd_array) {
1507 kfree(adapter->cmd_array);
1508 adapter->cmd_array = NULL;
1512 lbs_deb_leave(LBS_DEB_HOST);
1517 * @brief This function gets a free command node if available in
1518 * command free queue.
1520 * @param priv A pointer to wlan_private structure
1521 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1523 struct cmd_ctrl_node *libertas_get_free_cmd_ctrl_node(wlan_private * priv)
1525 struct cmd_ctrl_node *tempnode;
1526 wlan_adapter *adapter = priv->adapter;
1527 unsigned long flags;
1529 lbs_deb_enter(LBS_DEB_HOST);
1534 spin_lock_irqsave(&adapter->driver_lock, flags);
1536 if (!list_empty(&adapter->cmdfreeq)) {
1537 tempnode = (struct cmd_ctrl_node *)adapter->cmdfreeq.next;
1538 list_del((struct list_head *)tempnode);
1540 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1544 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1547 cleanup_cmdnode(tempnode);
1549 lbs_deb_leave(LBS_DEB_HOST);
1554 * @brief This function cleans command node.
1556 * @param ptempnode A pointer to cmdCtrlNode structure
1559 static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
1561 lbs_deb_enter(LBS_DEB_HOST);
1565 ptempnode->cmdwaitqwoken = 1;
1566 wake_up_interruptible(&ptempnode->cmdwait_q);
1567 ptempnode->status = 0;
1568 ptempnode->cmd_oid = (u32) 0;
1569 ptempnode->wait_option = 0;
1570 ptempnode->pdata_buf = NULL;
1572 if (ptempnode->bufvirtualaddr != NULL)
1573 memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
1575 lbs_deb_leave(LBS_DEB_HOST);
1579 * @brief This function initializes the command node.
1581 * @param priv A pointer to wlan_private structure
1582 * @param ptempnode A pointer to cmd_ctrl_node structure
1583 * @param cmd_oid cmd oid: treated as sub command
1584 * @param wait_option wait option: wait response or not
1585 * @param pdata_buf A pointer to informaion buffer
1588 void libertas_set_cmd_ctrl_node(wlan_private * priv,
1589 struct cmd_ctrl_node *ptempnode,
1590 u32 cmd_oid, u16 wait_option, void *pdata_buf)
1592 lbs_deb_enter(LBS_DEB_HOST);
1597 ptempnode->cmd_oid = cmd_oid;
1598 ptempnode->wait_option = wait_option;
1599 ptempnode->pdata_buf = pdata_buf;
1601 lbs_deb_leave(LBS_DEB_HOST);
1605 * @brief This function executes next command in command
1606 * pending queue. It will put fimware back to PS mode
1609 * @param priv A pointer to wlan_private structure
1612 int libertas_execute_next_command(wlan_private * priv)
1614 wlan_adapter *adapter = priv->adapter;
1615 struct cmd_ctrl_node *cmdnode = NULL;
1616 struct cmd_ds_command *cmdptr;
1617 unsigned long flags;
1620 // Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1621 // only caller to us is libertas_thread() and we get even when a
1622 // data packet is received
1623 lbs_deb_enter(LBS_DEB_THREAD);
1625 spin_lock_irqsave(&adapter->driver_lock, flags);
1627 if (adapter->cur_cmd) {
1628 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
1629 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1634 if (!list_empty(&adapter->cmdpendingq)) {
1635 cmdnode = (struct cmd_ctrl_node *)
1636 adapter->cmdpendingq.next;
1639 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1642 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1644 if (is_command_allowed_in_ps(cmdptr->command)) {
1645 if ((adapter->psstate == PS_STATE_SLEEP) ||
1646 (adapter->psstate == PS_STATE_PRE_SLEEP)) {
1648 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
1649 le16_to_cpu(cmdptr->command),
1654 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
1655 "0x%04x in psstate %d\n",
1656 le16_to_cpu(cmdptr->command),
1658 } else if (adapter->psstate != PS_STATE_FULL_POWER) {
1660 * 1. Non-PS command:
1661 * Queue it. set needtowakeup to TRUE if current state
1662 * is SLEEP, otherwise call libertas_ps_wakeup to send Exit_PS.
1663 * 2. PS command but not Exit_PS:
1665 * 3. PS command Exit_PS:
1666 * Set needtowakeup to TRUE if current state is SLEEP,
1667 * otherwise send this command down to firmware
1670 if (cmdptr->command !=
1671 cpu_to_le16(CMD_802_11_PS_MODE)) {
1672 /* Prepare to send Exit PS,
1673 * this non PS command will be sent later */
1674 if ((adapter->psstate == PS_STATE_SLEEP)
1675 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1677 /* w/ new scheme, it will not reach here.
1678 since it is blocked in main_thread. */
1679 adapter->needtowakeup = 1;
1681 libertas_ps_wakeup(priv, 0);
1687 * PS command. Ignore it if it is not Exit_PS.
1688 * otherwise send it down immediately.
1690 struct cmd_ds_802_11_ps_mode *psm =
1691 &cmdptr->params.psmode;
1694 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
1697 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
1699 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
1700 list_del((struct list_head *)cmdnode);
1701 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1707 if ((adapter->psstate == PS_STATE_SLEEP) ||
1708 (adapter->psstate == PS_STATE_PRE_SLEEP)) {
1710 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
1711 list_del((struct list_head *)cmdnode);
1712 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1713 adapter->needtowakeup = 1;
1720 "EXEC_NEXT_CMD: sending EXIT_PS\n");
1723 list_del((struct list_head *)cmdnode);
1724 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
1725 le16_to_cpu(cmdptr->command));
1726 DownloadcommandToStation(priv, cmdnode);
1729 * check if in power save mode, if yes, put the device back
1732 if ((adapter->psmode != WLAN802_11POWERMODECAM) &&
1733 (adapter->psstate == PS_STATE_FULL_POWER) &&
1734 (adapter->connect_status == LIBERTAS_CONNECTED)) {
1735 if (adapter->secinfo.WPAenabled ||
1736 adapter->secinfo.WPA2enabled) {
1737 /* check for valid WPA group keys */
1738 if (adapter->wpa_mcast_key.len ||
1739 adapter->wpa_unicast_key.len) {
1741 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1742 " go back to PS_SLEEP");
1743 libertas_ps_sleep(priv, 0);
1747 "EXEC_NEXT_CMD: cmdpendingq empty, "
1748 "go back to PS_SLEEP");
1749 libertas_ps_sleep(priv, 0);
1756 lbs_deb_leave(LBS_DEB_THREAD);
1760 void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str)
1762 union iwreq_data iwrq;
1765 lbs_deb_enter(LBS_DEB_WEXT);
1767 memset(&iwrq, 0, sizeof(union iwreq_data));
1768 memset(buf, 0, sizeof(buf));
1770 snprintf(buf, sizeof(buf) - 1, "%s", str);
1772 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1774 /* Send Event to upper layer */
1775 lbs_deb_wext("event indication string %s\n", (char *)buf);
1776 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
1777 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
1779 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
1781 lbs_deb_leave(LBS_DEB_WEXT);
1784 static int sendconfirmsleep(wlan_private * priv, u8 * cmdptr, u16 size)
1786 unsigned long flags;
1787 wlan_adapter *adapter = priv->adapter;
1790 lbs_deb_enter(LBS_DEB_HOST);
1792 lbs_deb_host("SEND_SLEEPC_CMD: before download, cmd size %d\n",
1795 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm command", cmdptr, size);
1797 ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
1798 priv->dnld_sent = DNLD_RES_RECEIVED;
1800 spin_lock_irqsave(&adapter->driver_lock, flags);
1801 if (adapter->intcounter || adapter->currenttxskb)
1802 lbs_deb_host("SEND_SLEEPC_CMD: intcounter %d, currenttxskb %p\n",
1803 adapter->intcounter, adapter->currenttxskb);
1804 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1808 "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
1810 spin_lock_irqsave(&adapter->driver_lock, flags);
1811 if (!adapter->intcounter) {
1812 adapter->psstate = PS_STATE_SLEEP;
1814 lbs_deb_host("SEND_SLEEPC_CMD: after sent, intcounter %d\n",
1815 adapter->intcounter);
1817 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1819 lbs_deb_host("SEND_SLEEPC_CMD: sent confirm sleep\n");
1822 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1826 void libertas_ps_sleep(wlan_private * priv, int wait_option)
1828 lbs_deb_enter(LBS_DEB_HOST);
1831 * PS is currently supported only in Infrastructure mode
1832 * Remove this check if it is to be supported in IBSS mode also
1835 libertas_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1836 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
1838 lbs_deb_leave(LBS_DEB_HOST);
1842 * @brief This function sends Exit_PS command to firmware.
1844 * @param priv A pointer to wlan_private structure
1845 * @param wait_option wait response or not
1848 void libertas_ps_wakeup(wlan_private * priv, int wait_option)
1852 lbs_deb_enter(LBS_DEB_HOST);
1854 Localpsmode = cpu_to_le32(WLAN802_11POWERMODECAM);
1856 libertas_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1858 wait_option, 0, &Localpsmode);
1860 lbs_deb_leave(LBS_DEB_HOST);
1864 * @brief This function checks condition and prepares to
1865 * send sleep confirm command to firmware if ok.
1867 * @param priv A pointer to wlan_private structure
1868 * @param psmode Power Saving mode
1871 void libertas_ps_confirm_sleep(wlan_private * priv, u16 psmode)
1873 unsigned long flags =0;
1874 wlan_adapter *adapter = priv->adapter;
1877 lbs_deb_enter(LBS_DEB_HOST);
1879 if (priv->dnld_sent) {
1881 lbs_deb_host("dnld_sent was set");
1884 spin_lock_irqsave(&adapter->driver_lock, flags);
1885 if (adapter->cur_cmd) {
1887 lbs_deb_host("cur_cmd was set");
1889 if (adapter->intcounter > 0) {
1891 lbs_deb_host("intcounter %d", adapter->intcounter);
1893 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1896 lbs_deb_host("sending libertas_ps_confirm_sleep\n");
1897 sendconfirmsleep(priv, (u8 *) & adapter->libertas_ps_confirm_sleep,
1898 sizeof(struct PS_CMD_ConfirmSleep));
1900 lbs_deb_host("sleep confirm has been delayed\n");
1903 lbs_deb_leave(LBS_DEB_HOST);