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;
60 lbs_deb_enter(LBS_DEB_CMD);
62 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
63 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
65 psm->action = cpu_to_le16(cmd_action);
66 psm->multipledtim = 0;
68 case CMD_SUBCMD_ENTER_PS:
69 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
71 psm->locallisteninterval = 0;
72 psm->nullpktinterval = 0;
74 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
77 case CMD_SUBCMD_EXIT_PS:
78 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
81 case CMD_SUBCMD_SLEEP_CONFIRMED:
82 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
89 lbs_deb_leave(LBS_DEB_CMD);
93 static int wlan_cmd_802_11_inactivity_timeout(wlan_private * priv,
94 struct cmd_ds_command *cmd,
95 u16 cmd_action, void *pdata_buf)
97 u16 *timeout = pdata_buf;
99 lbs_deb_enter(LBS_DEB_CMD);
101 cmd->command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
103 cpu_to_le16(sizeof(struct cmd_ds_802_11_inactivity_timeout)
106 cmd->params.inactivity_timeout.action = cpu_to_le16(cmd_action);
109 cmd->params.inactivity_timeout.timeout = cpu_to_le16(*timeout);
111 cmd->params.inactivity_timeout.timeout = 0;
113 lbs_deb_leave(LBS_DEB_CMD);
117 static int wlan_cmd_802_11_sleep_params(wlan_private * priv,
118 struct cmd_ds_command *cmd,
121 wlan_adapter *adapter = priv->adapter;
122 struct cmd_ds_802_11_sleep_params *sp = &cmd->params.sleep_params;
124 lbs_deb_enter(LBS_DEB_CMD);
126 cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
128 cmd->command = cpu_to_le16(CMD_802_11_SLEEP_PARAMS);
130 if (cmd_action == CMD_ACT_GET) {
131 memset(&adapter->sp, 0, sizeof(struct sleep_params));
132 memset(sp, 0, sizeof(struct cmd_ds_802_11_sleep_params));
133 sp->action = cpu_to_le16(cmd_action);
134 } else if (cmd_action == CMD_ACT_SET) {
135 sp->action = cpu_to_le16(cmd_action);
136 sp->error = cpu_to_le16(adapter->sp.sp_error);
137 sp->offset = cpu_to_le16(adapter->sp.sp_offset);
138 sp->stabletime = cpu_to_le16(adapter->sp.sp_stabletime);
139 sp->calcontrol = (u8) adapter->sp.sp_calcontrol;
140 sp->externalsleepclk = (u8) adapter->sp.sp_extsleepclk;
141 sp->reserved = cpu_to_le16(adapter->sp.sp_reserved);
144 lbs_deb_leave(LBS_DEB_CMD);
148 static int wlan_cmd_802_11_set_wep(wlan_private * priv,
149 struct cmd_ds_command *cmd,
153 struct cmd_ds_802_11_set_wep *wep = &cmd->params.wep;
154 wlan_adapter *adapter = priv->adapter;
156 struct assoc_request * assoc_req = pdata_buf;
158 lbs_deb_enter(LBS_DEB_CMD);
160 cmd->command = cpu_to_le16(CMD_802_11_SET_WEP);
161 cmd->size = cpu_to_le16(sizeof(*wep) + S_DS_GEN);
163 if (cmd_act == CMD_ACT_ADD) {
167 lbs_deb_cmd("Invalid association request!");
172 wep->action = cpu_to_le16(CMD_ACT_ADD);
174 /* default tx key index */
175 wep->keyindex = cpu_to_le16((u16)(assoc_req->wep_tx_keyidx &
176 (u32)CMD_WEP_KEY_INDEX_MASK));
178 /* Copy key types and material to host command structure */
179 for (i = 0; i < 4; i++) {
180 struct enc_key * pkey = &assoc_req->wep_keys[i];
185 cpu_to_le16(CMD_TYPE_WEP_40_BIT);
186 memmove(&wep->keymaterial[i], pkey->key,
188 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
190 case KEY_LEN_WEP_104:
192 cpu_to_le16(CMD_TYPE_WEP_104_BIT);
193 memmove(&wep->keymaterial[i], pkey->key,
195 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
200 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
207 } else if (cmd_act == CMD_ACT_REMOVE) {
208 /* ACT_REMOVE clears _all_ WEP keys */
209 wep->action = cpu_to_le16(CMD_ACT_REMOVE);
211 /* default tx key index */
212 wep->keyindex = cpu_to_le16((u16)(adapter->wep_tx_keyidx &
213 (u32)CMD_WEP_KEY_INDEX_MASK));
214 lbs_deb_cmd("SET_WEP: remove key %d\n", adapter->wep_tx_keyidx);
220 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
224 static int wlan_cmd_802_11_enable_rsn(wlan_private * priv,
225 struct cmd_ds_command *cmd,
229 struct cmd_ds_802_11_enable_rsn *penableRSN = &cmd->params.enbrsn;
230 u32 * enable = pdata_buf;
232 lbs_deb_enter(LBS_DEB_CMD);
234 cmd->command = cpu_to_le16(CMD_802_11_ENABLE_RSN);
235 cmd->size = cpu_to_le16(sizeof(*penableRSN) + S_DS_GEN);
236 penableRSN->action = cpu_to_le16(cmd_action);
238 if (cmd_action == CMD_ACT_SET) {
240 penableRSN->enable = cpu_to_le16(CMD_ENABLE_RSN);
242 penableRSN->enable = cpu_to_le16(CMD_DISABLE_RSN);
243 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
246 lbs_deb_leave(LBS_DEB_CMD);
251 static void set_one_wpa_key(struct MrvlIEtype_keyParamSet * pkeyparamset,
252 struct enc_key * pkey)
254 lbs_deb_enter(LBS_DEB_CMD);
256 if (pkey->flags & KEY_INFO_WPA_ENABLED) {
257 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
259 if (pkey->flags & KEY_INFO_WPA_UNICAST) {
260 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
262 if (pkey->flags & KEY_INFO_WPA_MCAST) {
263 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
266 pkeyparamset->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
267 pkeyparamset->keytypeid = cpu_to_le16(pkey->type);
268 pkeyparamset->keylen = cpu_to_le16(pkey->len);
269 memcpy(pkeyparamset->key, pkey->key, pkey->len);
270 pkeyparamset->length = cpu_to_le16( sizeof(pkeyparamset->keytypeid)
271 + sizeof(pkeyparamset->keyinfo)
272 + sizeof(pkeyparamset->keylen)
273 + sizeof(pkeyparamset->key));
274 lbs_deb_leave(LBS_DEB_CMD);
277 static int wlan_cmd_802_11_key_material(wlan_private * priv,
278 struct cmd_ds_command *cmd,
280 u32 cmd_oid, void *pdata_buf)
282 struct cmd_ds_802_11_key_material *pkeymaterial =
283 &cmd->params.keymaterial;
284 struct assoc_request * assoc_req = pdata_buf;
288 lbs_deb_enter(LBS_DEB_CMD);
290 cmd->command = cpu_to_le16(CMD_802_11_KEY_MATERIAL);
291 pkeymaterial->action = cpu_to_le16(cmd_action);
293 if (cmd_action == CMD_ACT_GET) {
294 cmd->size = cpu_to_le16(S_DS_GEN + sizeof (pkeymaterial->action));
299 memset(&pkeymaterial->keyParamSet, 0, sizeof(pkeymaterial->keyParamSet));
301 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
302 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
303 &assoc_req->wpa_unicast_key);
307 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
308 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
309 &assoc_req->wpa_mcast_key);
313 cmd->size = cpu_to_le16( S_DS_GEN
314 + sizeof (pkeymaterial->action)
315 + (index * sizeof(struct MrvlIEtype_keyParamSet)));
320 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
324 static int wlan_cmd_802_11_reset(wlan_private * priv,
325 struct cmd_ds_command *cmd, int cmd_action)
327 struct cmd_ds_802_11_reset *reset = &cmd->params.reset;
329 lbs_deb_enter(LBS_DEB_CMD);
331 cmd->command = cpu_to_le16(CMD_802_11_RESET);
332 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
333 reset->action = cpu_to_le16(cmd_action);
335 lbs_deb_leave(LBS_DEB_CMD);
339 static int wlan_cmd_802_11_get_log(wlan_private * priv,
340 struct cmd_ds_command *cmd)
342 lbs_deb_enter(LBS_DEB_CMD);
343 cmd->command = cpu_to_le16(CMD_802_11_GET_LOG);
345 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_log) + S_DS_GEN);
347 lbs_deb_leave(LBS_DEB_CMD);
351 static int wlan_cmd_802_11_get_stat(wlan_private * priv,
352 struct cmd_ds_command *cmd)
354 lbs_deb_enter(LBS_DEB_CMD);
355 cmd->command = cpu_to_le16(CMD_802_11_GET_STAT);
357 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) + S_DS_GEN);
359 lbs_deb_leave(LBS_DEB_CMD);
363 static int wlan_cmd_802_11_snmp_mib(wlan_private * priv,
364 struct cmd_ds_command *cmd,
366 int cmd_oid, void *pdata_buf)
368 struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib;
369 wlan_adapter *adapter = priv->adapter;
372 lbs_deb_enter(LBS_DEB_CMD);
374 lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
376 cmd->command = cpu_to_le16(CMD_802_11_SNMP_MIB);
377 cmd->size = cpu_to_le16(sizeof(*pSNMPMIB) + S_DS_GEN);
380 case OID_802_11_INFRASTRUCTURE_MODE:
382 u8 mode = (u8) (size_t) pdata_buf;
383 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
384 pSNMPMIB->oid = cpu_to_le16((u16) DESIRED_BSSTYPE_I);
385 pSNMPMIB->bufsize = sizeof(u8);
386 if (mode == IW_MODE_ADHOC) {
387 ucTemp = SNMP_MIB_VALUE_ADHOC;
389 /* Infra and Auto modes */
390 ucTemp = SNMP_MIB_VALUE_INFRA;
393 memmove(pSNMPMIB->value, &ucTemp, sizeof(u8));
398 case OID_802_11D_ENABLE:
402 pSNMPMIB->oid = cpu_to_le16((u16) DOT11D_I);
404 if (cmd_action == CMD_ACT_SET) {
405 pSNMPMIB->querytype = CMD_ACT_SET;
406 pSNMPMIB->bufsize = sizeof(u16);
407 ulTemp = *(u32 *)pdata_buf;
408 *((__le16 *)(pSNMPMIB->value)) =
409 cpu_to_le16((u16) ulTemp);
414 case OID_802_11_FRAGMENTATION_THRESHOLD:
418 pSNMPMIB->oid = cpu_to_le16((u16) FRAGTHRESH_I);
420 if (cmd_action == CMD_ACT_GET) {
421 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
422 } else if (cmd_action == CMD_ACT_SET) {
423 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
424 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
425 ulTemp = *((u32 *) pdata_buf);
426 *((__le16 *)(pSNMPMIB->value)) =
427 cpu_to_le16((u16) ulTemp);
434 case OID_802_11_RTS_THRESHOLD:
438 pSNMPMIB->oid = le16_to_cpu((u16) RTSTHRESH_I);
440 if (cmd_action == CMD_ACT_GET) {
441 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
442 } else if (cmd_action == CMD_ACT_SET) {
443 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
444 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
445 ulTemp = *((u32 *)pdata_buf);
446 *(__le16 *)(pSNMPMIB->value) =
447 cpu_to_le16((u16) ulTemp);
452 case OID_802_11_TX_RETRYCOUNT:
453 pSNMPMIB->oid = cpu_to_le16((u16) SHORT_RETRYLIM_I);
455 if (cmd_action == CMD_ACT_GET) {
456 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
457 } else if (cmd_action == CMD_ACT_SET) {
458 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
459 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
460 *((__le16 *)(pSNMPMIB->value)) =
461 cpu_to_le16((u16) adapter->txretrycount);
470 "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
471 le16_to_cpu(cmd->command), le16_to_cpu(cmd->size),
472 le16_to_cpu(cmd->seqnum), le16_to_cpu(cmd->result));
475 "SNMP_CMD: action 0x%x, oid 0x%x, oidsize 0x%x, value 0x%x\n",
476 le16_to_cpu(pSNMPMIB->querytype), le16_to_cpu(pSNMPMIB->oid),
477 le16_to_cpu(pSNMPMIB->bufsize),
478 le16_to_cpu(*(__le16 *) pSNMPMIB->value));
480 lbs_deb_leave(LBS_DEB_CMD);
484 static int wlan_cmd_802_11_radio_control(wlan_private * priv,
485 struct cmd_ds_command *cmd,
488 wlan_adapter *adapter = priv->adapter;
489 struct cmd_ds_802_11_radio_control *pradiocontrol = &cmd->params.radio;
491 lbs_deb_enter(LBS_DEB_CMD);
494 cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control)) +
496 cmd->command = cpu_to_le16(CMD_802_11_RADIO_CONTROL);
498 pradiocontrol->action = cpu_to_le16(cmd_action);
500 switch (adapter->preamble) {
501 case CMD_TYPE_SHORT_PREAMBLE:
502 pradiocontrol->control = cpu_to_le16(SET_SHORT_PREAMBLE);
505 case CMD_TYPE_LONG_PREAMBLE:
506 pradiocontrol->control = cpu_to_le16(SET_LONG_PREAMBLE);
509 case CMD_TYPE_AUTO_PREAMBLE:
511 pradiocontrol->control = cpu_to_le16(SET_AUTO_PREAMBLE);
515 if (adapter->radioon)
516 pradiocontrol->control |= cpu_to_le16(TURN_ON_RF);
518 pradiocontrol->control &= cpu_to_le16(~TURN_ON_RF);
520 lbs_deb_leave(LBS_DEB_CMD);
524 static int wlan_cmd_802_11_rf_tx_power(wlan_private * priv,
525 struct cmd_ds_command *cmd,
526 u16 cmd_action, void *pdata_buf)
529 struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
531 lbs_deb_enter(LBS_DEB_CMD);
534 cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN);
535 cmd->command = cpu_to_le16(CMD_802_11_RF_TX_POWER);
536 prtp->action = cpu_to_le16(cmd_action);
538 lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
539 le16_to_cpu(cmd->size), le16_to_cpu(cmd->command),
540 le16_to_cpu(prtp->action));
542 switch (cmd_action) {
543 case CMD_ACT_TX_POWER_OPT_GET:
544 prtp->action = cpu_to_le16(CMD_ACT_GET);
545 prtp->currentlevel = 0;
548 case CMD_ACT_TX_POWER_OPT_SET_HIGH:
549 prtp->action = cpu_to_le16(CMD_ACT_SET);
550 prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_HIGH);
553 case CMD_ACT_TX_POWER_OPT_SET_MID:
554 prtp->action = cpu_to_le16(CMD_ACT_SET);
555 prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_MID);
558 case CMD_ACT_TX_POWER_OPT_SET_LOW:
559 prtp->action = cpu_to_le16(CMD_ACT_SET);
560 prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
564 lbs_deb_leave(LBS_DEB_CMD);
568 static int wlan_cmd_802_11_monitor_mode(wlan_private * priv,
569 struct cmd_ds_command *cmd,
570 u16 cmd_action, void *pdata_buf)
572 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
574 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
576 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
579 monitor->action = cpu_to_le16(cmd_action);
580 if (cmd_action == CMD_ACT_SET) {
582 cpu_to_le16((u16) (*(u32 *) pdata_buf));
588 static int wlan_cmd_802_11_rate_adapt_rateset(wlan_private * priv,
589 struct cmd_ds_command *cmd,
592 struct cmd_ds_802_11_rate_adapt_rateset
593 *rateadapt = &cmd->params.rateset;
594 wlan_adapter *adapter = priv->adapter;
596 lbs_deb_enter(LBS_DEB_CMD);
598 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
600 cmd->command = cpu_to_le16(CMD_802_11_RATE_ADAPT_RATESET);
602 rateadapt->action = cpu_to_le16(cmd_action);
603 rateadapt->enablehwauto = cpu_to_le16(adapter->enablehwauto);
604 rateadapt->bitmap = cpu_to_le16(adapter->ratebitmap);
606 lbs_deb_leave(LBS_DEB_CMD);
610 static int wlan_cmd_802_11_data_rate(wlan_private * priv,
611 struct cmd_ds_command *cmd,
614 struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
615 wlan_adapter *adapter = priv->adapter;
617 lbs_deb_enter(LBS_DEB_CMD);
619 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
621 cmd->command = cpu_to_le16(CMD_802_11_DATA_RATE);
622 memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate));
623 pdatarate->action = cpu_to_le16(cmd_action);
625 if (cmd_action == CMD_ACT_SET_TX_FIX_RATE) {
626 pdatarate->rates[0] = libertas_data_rate_to_fw_index(adapter->cur_rate);
627 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n",
629 } else if (cmd_action == CMD_ACT_SET_TX_AUTO) {
630 lbs_deb_cmd("DATA_RATE: setting auto\n");
633 lbs_deb_leave(LBS_DEB_CMD);
637 static int wlan_cmd_mac_multicast_adr(wlan_private * priv,
638 struct cmd_ds_command *cmd,
641 struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
642 wlan_adapter *adapter = priv->adapter;
644 lbs_deb_enter(LBS_DEB_CMD);
645 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
647 cmd->command = cpu_to_le16(CMD_MAC_MULTICAST_ADR);
649 lbs_deb_cmd("MULTICAST_ADR: setting %d addresses\n", pMCastAdr->nr_of_adrs);
650 pMCastAdr->action = cpu_to_le16(cmd_action);
651 pMCastAdr->nr_of_adrs =
652 cpu_to_le16((u16) adapter->nr_of_multicastmacaddr);
653 memcpy(pMCastAdr->maclist, adapter->multicastlist,
654 adapter->nr_of_multicastmacaddr * ETH_ALEN);
656 lbs_deb_leave(LBS_DEB_CMD);
660 static int wlan_cmd_802_11_rf_channel(wlan_private * priv,
661 struct cmd_ds_command *cmd,
662 int option, void *pdata_buf)
664 struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel;
666 lbs_deb_enter(LBS_DEB_CMD);
667 cmd->command = cpu_to_le16(CMD_802_11_RF_CHANNEL);
668 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel) +
671 if (option == CMD_OPT_802_11_RF_CHANNEL_SET) {
672 rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf));
675 rfchan->action = cpu_to_le16(option);
677 lbs_deb_leave(LBS_DEB_CMD);
681 static int wlan_cmd_802_11_rssi(wlan_private * priv,
682 struct cmd_ds_command *cmd)
684 wlan_adapter *adapter = priv->adapter;
686 lbs_deb_enter(LBS_DEB_CMD);
687 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
688 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
689 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
691 /* reset Beacon SNR/NF/RSSI values */
692 adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
693 adapter->SNR[TYPE_BEACON][TYPE_AVG] = 0;
694 adapter->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
695 adapter->NF[TYPE_BEACON][TYPE_AVG] = 0;
696 adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
697 adapter->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
699 lbs_deb_leave(LBS_DEB_CMD);
703 static int wlan_cmd_reg_access(wlan_private * priv,
704 struct cmd_ds_command *cmdptr,
705 u8 cmd_action, void *pdata_buf)
707 struct wlan_offset_value *offval;
709 lbs_deb_enter(LBS_DEB_CMD);
711 offval = (struct wlan_offset_value *)pdata_buf;
713 switch (cmdptr->command) {
714 case CMD_MAC_REG_ACCESS:
716 struct cmd_ds_mac_reg_access *macreg;
719 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
722 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
725 macreg->action = cpu_to_le16(cmd_action);
726 macreg->offset = cpu_to_le16((u16) offval->offset);
727 macreg->value = cpu_to_le32(offval->value);
732 case CMD_BBP_REG_ACCESS:
734 struct cmd_ds_bbp_reg_access *bbpreg;
738 (struct cmd_ds_bbp_reg_access)
741 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
744 bbpreg->action = cpu_to_le16(cmd_action);
745 bbpreg->offset = cpu_to_le16((u16) offval->offset);
746 bbpreg->value = (u8) offval->value;
751 case CMD_RF_REG_ACCESS:
753 struct cmd_ds_rf_reg_access *rfreg;
757 (struct cmd_ds_rf_reg_access) +
760 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
763 rfreg->action = cpu_to_le16(cmd_action);
764 rfreg->offset = cpu_to_le16((u16) offval->offset);
765 rfreg->value = (u8) offval->value;
774 lbs_deb_leave(LBS_DEB_CMD);
778 static int wlan_cmd_802_11_mac_address(wlan_private * priv,
779 struct cmd_ds_command *cmd,
782 wlan_adapter *adapter = priv->adapter;
784 lbs_deb_enter(LBS_DEB_CMD);
785 cmd->command = cpu_to_le16(CMD_802_11_MAC_ADDRESS);
786 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
790 cmd->params.macadd.action = cpu_to_le16(cmd_action);
792 if (cmd_action == CMD_ACT_SET) {
793 memcpy(cmd->params.macadd.macadd,
794 adapter->current_addr, ETH_ALEN);
795 lbs_deb_hex(LBS_DEB_CMD, "SET_CMD: MAC addr", adapter->current_addr, 6);
798 lbs_deb_leave(LBS_DEB_CMD);
802 static int wlan_cmd_802_11_eeprom_access(wlan_private * priv,
803 struct cmd_ds_command *cmd,
804 int cmd_action, void *pdata_buf)
806 struct wlan_ioctl_regrdwr *ea = pdata_buf;
808 lbs_deb_enter(LBS_DEB_CMD);
810 cmd->command = cpu_to_le16(CMD_802_11_EEPROM_ACCESS);
811 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
815 cmd->params.rdeeprom.action = cpu_to_le16(ea->action);
816 cmd->params.rdeeprom.offset = cpu_to_le16(ea->offset);
817 cmd->params.rdeeprom.bytecount = cpu_to_le16(ea->NOB);
818 cmd->params.rdeeprom.value = 0;
820 lbs_deb_leave(LBS_DEB_CMD);
824 static int wlan_cmd_bt_access(wlan_private * priv,
825 struct cmd_ds_command *cmd,
826 u16 cmd_action, void *pdata_buf)
828 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
829 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
831 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
832 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
834 bt_access->action = cpu_to_le16(cmd_action);
836 switch (cmd_action) {
837 case CMD_ACT_BT_ACCESS_ADD:
838 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
839 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
841 case CMD_ACT_BT_ACCESS_DEL:
842 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
843 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
845 case CMD_ACT_BT_ACCESS_LIST:
846 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
848 case CMD_ACT_BT_ACCESS_RESET:
850 case CMD_ACT_BT_ACCESS_SET_INVERT:
851 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
853 case CMD_ACT_BT_ACCESS_GET_INVERT:
858 lbs_deb_leave(LBS_DEB_CMD);
862 static int wlan_cmd_fwt_access(wlan_private * priv,
863 struct cmd_ds_command *cmd,
864 u16 cmd_action, void *pdata_buf)
866 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
867 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
869 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
870 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
874 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
876 memset(fwt_access, 0, sizeof(*fwt_access));
878 fwt_access->action = cpu_to_le16(cmd_action);
880 lbs_deb_leave(LBS_DEB_CMD);
884 static int wlan_cmd_mesh_access(wlan_private * priv,
885 struct cmd_ds_command *cmd,
886 u16 cmd_action, void *pdata_buf)
888 struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
889 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
891 cmd->command = cpu_to_le16(CMD_MESH_ACCESS);
892 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access) + S_DS_GEN);
896 memcpy(mesh_access, pdata_buf, sizeof(*mesh_access));
898 memset(mesh_access, 0, sizeof(*mesh_access));
900 mesh_access->action = cpu_to_le16(cmd_action);
902 lbs_deb_leave(LBS_DEB_CMD);
906 void libertas_queue_cmd(wlan_adapter * adapter, struct cmd_ctrl_node *cmdnode, u8 addtail)
909 struct cmd_ds_command *cmdptr;
911 lbs_deb_enter(LBS_DEB_HOST);
914 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
918 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
920 lbs_deb_host("QUEUE_CMD: cmdptr is NULL\n");
924 /* Exit_PS command needs to be queued in the header always. */
925 if (cmdptr->command == CMD_802_11_PS_MODE) {
926 struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
927 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
928 if (adapter->psstate != PS_STATE_FULL_POWER)
933 spin_lock_irqsave(&adapter->driver_lock, flags);
936 list_add_tail((struct list_head *)cmdnode,
937 &adapter->cmdpendingq);
939 list_add((struct list_head *)cmdnode, &adapter->cmdpendingq);
941 spin_unlock_irqrestore(&adapter->driver_lock, flags);
943 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
944 le16_to_cpu(((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command));
947 lbs_deb_leave(LBS_DEB_HOST);
951 * TODO: Fix the issue when DownloadcommandToStation is being called the
952 * second time when the command times out. All the cmdptr->xxx are in little
953 * endian and therefore all the comparissions will fail.
954 * For now - we are not performing the endian conversion the second time - but
955 * for PS and DEEP_SLEEP we need to worry
957 static int DownloadcommandToStation(wlan_private * priv,
958 struct cmd_ctrl_node *cmdnode)
961 struct cmd_ds_command *cmdptr;
962 wlan_adapter *adapter = priv->adapter;
967 lbs_deb_enter(LBS_DEB_HOST);
969 if (!adapter || !cmdnode) {
970 lbs_deb_host("DNLD_CMD: adapter or cmdmode is NULL\n");
972 spin_lock_irqsave(&adapter->driver_lock, flags);
973 __libertas_cleanup_and_insert_cmd(priv, cmdnode);
974 spin_unlock_irqrestore(&adapter->driver_lock, flags);
980 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
982 spin_lock_irqsave(&adapter->driver_lock, flags);
983 if (!cmdptr || !cmdptr->size) {
984 lbs_deb_host("DNLD_CMD: cmdptr is NULL or zero\n");
985 __libertas_cleanup_and_insert_cmd(priv, cmdnode);
986 spin_unlock_irqrestore(&adapter->driver_lock, flags);
991 adapter->cur_cmd = cmdnode;
992 adapter->cur_cmd_retcode = 0;
993 spin_unlock_irqrestore(&adapter->driver_lock, flags);
995 cmdsize = cmdptr->size;
996 command = cpu_to_le16(cmdptr->command);
998 lbs_deb_host("DNLD_CMD: command 0x%04x, size %d, jiffies %lu\n",
999 command, le16_to_cpu(cmdptr->size), jiffies);
1000 lbs_deb_hex(LBS_DEB_HOST, "DNLD_CMD", cmdnode->bufvirtualaddr, cmdsize);
1002 cmdnode->cmdwaitqwoken = 0;
1003 cmdsize = cpu_to_le16(cmdsize);
1005 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
1008 lbs_deb_host("DNLD_CMD: hw_host_to_card failed\n");
1009 spin_lock_irqsave(&adapter->driver_lock, flags);
1010 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
1011 adapter->cur_cmd = NULL;
1012 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1017 lbs_deb_cmd("DNLD_CMD: sent command 0x%04x, jiffies %lu\n", command, jiffies);
1019 /* Setup the timer after transmit command */
1020 if (command == CMD_802_11_SCAN || command == CMD_802_11_AUTHENTICATE
1021 || command == CMD_802_11_ASSOCIATE)
1022 mod_timer(&adapter->command_timer, jiffies + (10*HZ));
1024 mod_timer(&adapter->command_timer, jiffies + (5*HZ));
1029 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1033 static int wlan_cmd_mac_control(wlan_private * priv,
1034 struct cmd_ds_command *cmd)
1036 struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
1038 lbs_deb_enter(LBS_DEB_CMD);
1040 cmd->command = cpu_to_le16(CMD_MAC_CONTROL);
1041 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
1042 mac->action = cpu_to_le16(priv->adapter->currentpacketfilter);
1044 lbs_deb_cmd("MAC_CONTROL: action 0x%x, size %d\n",
1045 le16_to_cpu(mac->action), le16_to_cpu(cmd->size));
1047 lbs_deb_leave(LBS_DEB_CMD);
1052 * This function inserts command node to cmdfreeq
1053 * after cleans it. Requires adapter->driver_lock held.
1055 void __libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
1057 wlan_adapter *adapter = priv->adapter;
1062 cleanup_cmdnode(ptempcmd);
1063 list_add_tail((struct list_head *)ptempcmd, &adapter->cmdfreeq);
1066 static void libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
1068 unsigned long flags;
1070 spin_lock_irqsave(&priv->adapter->driver_lock, flags);
1071 __libertas_cleanup_and_insert_cmd(priv, ptempcmd);
1072 spin_unlock_irqrestore(&priv->adapter->driver_lock, flags);
1075 int libertas_set_radio_control(wlan_private * priv)
1079 lbs_deb_enter(LBS_DEB_CMD);
1081 ret = libertas_prepare_and_send_command(priv,
1082 CMD_802_11_RADIO_CONTROL,
1084 CMD_OPTION_WAITFORRSP, 0, NULL);
1086 lbs_deb_cmd("RADIO_SET: radio %d, preamble %d\n",
1087 priv->adapter->radioon, priv->adapter->preamble);
1089 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1093 int libertas_set_mac_packet_filter(wlan_private * priv)
1097 lbs_deb_enter(LBS_DEB_CMD);
1099 /* Send MAC control command to station */
1100 ret = libertas_prepare_and_send_command(priv,
1101 CMD_MAC_CONTROL, 0, 0, 0, NULL);
1103 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1108 * @brief This function prepare the command before send to firmware.
1110 * @param priv A pointer to wlan_private structure
1111 * @param cmd_no command number
1112 * @param cmd_action command action: GET or SET
1113 * @param wait_option wait option: wait response or not
1114 * @param cmd_oid cmd oid: treated as sub command
1115 * @param pdata_buf A pointer to informaion buffer
1118 int libertas_prepare_and_send_command(wlan_private * priv,
1121 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1124 wlan_adapter *adapter = priv->adapter;
1125 struct cmd_ctrl_node *cmdnode;
1126 struct cmd_ds_command *cmdptr;
1127 unsigned long flags;
1129 lbs_deb_enter(LBS_DEB_HOST);
1132 lbs_deb_host("PREP_CMD: adapter is NULL\n");
1137 if (adapter->surpriseremoved) {
1138 lbs_deb_host("PREP_CMD: card removed\n");
1143 cmdnode = libertas_get_free_cmd_ctrl_node(priv);
1145 if (cmdnode == NULL) {
1146 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1148 /* Wake up main thread to execute next command */
1149 wake_up_interruptible(&priv->waitq);
1154 libertas_set_cmd_ctrl_node(priv, cmdnode, cmd_oid, wait_option, pdata_buf);
1156 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1158 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
1161 lbs_deb_host("PREP_CMD: cmdptr is NULL\n");
1162 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1167 /* Set sequence number, command and INT option */
1169 cmdptr->seqnum = cpu_to_le16(adapter->seqnum);
1171 cmdptr->command = cpu_to_le16(cmd_no);
1175 case CMD_GET_HW_SPEC:
1176 ret = wlan_cmd_hw_spec(priv, cmdptr);
1178 case CMD_802_11_PS_MODE:
1179 ret = wlan_cmd_802_11_ps_mode(priv, cmdptr, cmd_action);
1182 case CMD_802_11_SCAN:
1183 ret = libertas_cmd_80211_scan(priv, cmdptr, pdata_buf);
1186 case CMD_MAC_CONTROL:
1187 ret = wlan_cmd_mac_control(priv, cmdptr);
1190 case CMD_802_11_ASSOCIATE:
1191 case CMD_802_11_REASSOCIATE:
1192 ret = libertas_cmd_80211_associate(priv, cmdptr, pdata_buf);
1195 case CMD_802_11_DEAUTHENTICATE:
1196 ret = libertas_cmd_80211_deauthenticate(priv, cmdptr);
1199 case CMD_802_11_SET_WEP:
1200 ret = wlan_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf);
1203 case CMD_802_11_AD_HOC_START:
1204 ret = libertas_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
1209 case CMD_802_11_RESET:
1210 ret = wlan_cmd_802_11_reset(priv, cmdptr, cmd_action);
1213 case CMD_802_11_GET_LOG:
1214 ret = wlan_cmd_802_11_get_log(priv, cmdptr);
1217 case CMD_802_11_AUTHENTICATE:
1218 ret = libertas_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
1221 case CMD_802_11_GET_STAT:
1222 ret = wlan_cmd_802_11_get_stat(priv, cmdptr);
1225 case CMD_802_11_SNMP_MIB:
1226 ret = wlan_cmd_802_11_snmp_mib(priv, cmdptr,
1227 cmd_action, cmd_oid, pdata_buf);
1230 case CMD_MAC_REG_ACCESS:
1231 case CMD_BBP_REG_ACCESS:
1232 case CMD_RF_REG_ACCESS:
1233 ret = wlan_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf);
1236 case CMD_802_11_RF_CHANNEL:
1237 ret = wlan_cmd_802_11_rf_channel(priv, cmdptr,
1238 cmd_action, pdata_buf);
1241 case CMD_802_11_RF_TX_POWER:
1242 ret = wlan_cmd_802_11_rf_tx_power(priv, cmdptr,
1243 cmd_action, pdata_buf);
1246 case CMD_802_11_RADIO_CONTROL:
1247 ret = wlan_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
1250 case CMD_802_11_DATA_RATE:
1251 ret = wlan_cmd_802_11_data_rate(priv, cmdptr, cmd_action);
1253 case CMD_802_11_RATE_ADAPT_RATESET:
1254 ret = wlan_cmd_802_11_rate_adapt_rateset(priv,
1255 cmdptr, cmd_action);
1258 case CMD_MAC_MULTICAST_ADR:
1259 ret = wlan_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
1262 case CMD_802_11_MONITOR_MODE:
1263 ret = wlan_cmd_802_11_monitor_mode(priv, cmdptr,
1264 cmd_action, pdata_buf);
1267 case CMD_802_11_AD_HOC_JOIN:
1268 ret = libertas_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
1271 case CMD_802_11_RSSI:
1272 ret = wlan_cmd_802_11_rssi(priv, cmdptr);
1275 case CMD_802_11_AD_HOC_STOP:
1276 ret = libertas_cmd_80211_ad_hoc_stop(priv, cmdptr);
1279 case CMD_802_11_ENABLE_RSN:
1280 ret = wlan_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action,
1284 case CMD_802_11_KEY_MATERIAL:
1285 ret = wlan_cmd_802_11_key_material(priv, cmdptr, cmd_action,
1286 cmd_oid, pdata_buf);
1289 case CMD_802_11_PAIRWISE_TSC:
1291 case CMD_802_11_GROUP_TSC:
1294 case CMD_802_11_MAC_ADDRESS:
1295 ret = wlan_cmd_802_11_mac_address(priv, cmdptr, cmd_action);
1298 case CMD_802_11_EEPROM_ACCESS:
1299 ret = wlan_cmd_802_11_eeprom_access(priv, cmdptr,
1300 cmd_action, pdata_buf);
1303 case CMD_802_11_SET_AFC:
1304 case CMD_802_11_GET_AFC:
1306 cmdptr->command = cpu_to_le16(cmd_no);
1307 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1310 memmove(&cmdptr->params.afc,
1311 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1316 case CMD_802_11D_DOMAIN_INFO:
1317 ret = libertas_cmd_802_11d_domain_info(priv, cmdptr,
1318 cmd_no, cmd_action);
1321 case CMD_802_11_SLEEP_PARAMS:
1322 ret = wlan_cmd_802_11_sleep_params(priv, cmdptr, cmd_action);
1324 case CMD_802_11_INACTIVITY_TIMEOUT:
1325 ret = wlan_cmd_802_11_inactivity_timeout(priv, cmdptr,
1326 cmd_action, pdata_buf);
1327 libertas_set_cmd_ctrl_node(priv, cmdnode, 0, 0, pdata_buf);
1330 case CMD_802_11_TPC_CFG:
1331 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
1333 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1336 memmove(&cmdptr->params.tpccfg,
1337 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1341 case CMD_802_11_LED_GPIO_CTRL:
1343 struct mrvlietypes_ledgpio *gpio =
1344 (struct mrvlietypes_ledgpio*)
1345 cmdptr->params.ledgpio.data;
1347 memmove(&cmdptr->params.ledgpio,
1349 sizeof(struct cmd_ds_802_11_led_ctrl));
1352 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
1354 #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1356 cpu_to_le16(gpio->header.len + S_DS_GEN +
1357 ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1358 gpio->header.len = cpu_to_le16(gpio->header.len);
1363 case CMD_802_11_PWR_CFG:
1364 cmdptr->command = cpu_to_le16(CMD_802_11_PWR_CFG);
1366 cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) +
1368 memmove(&cmdptr->params.pwrcfg, pdata_buf,
1369 sizeof(struct cmd_ds_802_11_pwr_cfg));
1374 ret = wlan_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf);
1377 case CMD_FWT_ACCESS:
1378 ret = wlan_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf);
1381 case CMD_MESH_ACCESS:
1382 ret = wlan_cmd_mesh_access(priv, cmdptr, cmd_action, pdata_buf);
1386 cmdptr->command = cpu_to_le16(CMD_GET_TSF);
1387 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1392 lbs_deb_host("PREP_CMD: unknown command 0x%04x\n", cmd_no);
1397 /* return error, since the command preparation failed */
1399 lbs_deb_host("PREP_CMD: command preparation failed\n");
1400 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1405 cmdnode->cmdwaitqwoken = 0;
1407 libertas_queue_cmd(adapter, cmdnode, 1);
1408 adapter->nr_cmd_pending++;
1409 wake_up_interruptible(&priv->waitq);
1411 if (wait_option & CMD_OPTION_WAITFORRSP) {
1412 lbs_deb_host("PREP_CMD: wait for response\n");
1414 wait_event_interruptible(cmdnode->cmdwait_q,
1415 cmdnode->cmdwaitqwoken);
1418 spin_lock_irqsave(&adapter->driver_lock, flags);
1419 if (adapter->cur_cmd_retcode) {
1420 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
1421 adapter->cur_cmd_retcode);
1422 adapter->cur_cmd_retcode = 0;
1425 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1428 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1431 EXPORT_SYMBOL_GPL(libertas_prepare_and_send_command);
1434 * @brief This function allocates the command buffer and link
1435 * it to command free queue.
1437 * @param priv A pointer to wlan_private structure
1440 int libertas_allocate_cmd_buffer(wlan_private * priv)
1445 struct cmd_ctrl_node *tempcmd_array;
1446 u8 *ptempvirtualaddr;
1447 wlan_adapter *adapter = priv->adapter;
1449 lbs_deb_enter(LBS_DEB_HOST);
1451 /* Allocate and initialize cmdCtrlNode */
1452 ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
1454 if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) {
1455 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
1459 adapter->cmd_array = tempcmd_array;
1461 /* Allocate and initialize command buffers */
1462 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1463 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1464 if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) {
1465 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
1470 /* Update command buffer virtual */
1471 tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
1474 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1475 init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
1476 libertas_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
1482 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1487 * @brief This function frees the command buffer.
1489 * @param priv A pointer to wlan_private structure
1492 int libertas_free_cmd_buffer(wlan_private * priv)
1494 u32 ulbufsize; /* Someone needs to die for this. Slowly and painfully */
1496 struct cmd_ctrl_node *tempcmd_array;
1497 wlan_adapter *adapter = priv->adapter;
1499 lbs_deb_enter(LBS_DEB_HOST);
1501 /* need to check if cmd array is allocated or not */
1502 if (adapter->cmd_array == NULL) {
1503 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
1507 tempcmd_array = adapter->cmd_array;
1509 /* Release shared memory buffers */
1510 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1511 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1512 if (tempcmd_array[i].bufvirtualaddr) {
1513 kfree(tempcmd_array[i].bufvirtualaddr);
1514 tempcmd_array[i].bufvirtualaddr = NULL;
1518 /* Release cmd_ctrl_node */
1519 if (adapter->cmd_array) {
1520 kfree(adapter->cmd_array);
1521 adapter->cmd_array = NULL;
1525 lbs_deb_leave(LBS_DEB_HOST);
1530 * @brief This function gets a free command node if available in
1531 * command free queue.
1533 * @param priv A pointer to wlan_private structure
1534 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1536 struct cmd_ctrl_node *libertas_get_free_cmd_ctrl_node(wlan_private * priv)
1538 struct cmd_ctrl_node *tempnode;
1539 wlan_adapter *adapter = priv->adapter;
1540 unsigned long flags;
1542 lbs_deb_enter(LBS_DEB_HOST);
1547 spin_lock_irqsave(&adapter->driver_lock, flags);
1549 if (!list_empty(&adapter->cmdfreeq)) {
1550 tempnode = (struct cmd_ctrl_node *)adapter->cmdfreeq.next;
1551 list_del((struct list_head *)tempnode);
1553 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1557 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1560 cleanup_cmdnode(tempnode);
1562 lbs_deb_leave(LBS_DEB_HOST);
1567 * @brief This function cleans command node.
1569 * @param ptempnode A pointer to cmdCtrlNode structure
1572 static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
1574 lbs_deb_enter(LBS_DEB_HOST);
1578 ptempnode->cmdwaitqwoken = 1;
1579 wake_up_interruptible(&ptempnode->cmdwait_q);
1580 ptempnode->status = 0;
1581 ptempnode->cmd_oid = (u32) 0;
1582 ptempnode->wait_option = 0;
1583 ptempnode->pdata_buf = NULL;
1585 if (ptempnode->bufvirtualaddr != NULL)
1586 memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
1588 lbs_deb_leave(LBS_DEB_HOST);
1592 * @brief This function initializes the command node.
1594 * @param priv A pointer to wlan_private structure
1595 * @param ptempnode A pointer to cmd_ctrl_node structure
1596 * @param cmd_oid cmd oid: treated as sub command
1597 * @param wait_option wait option: wait response or not
1598 * @param pdata_buf A pointer to informaion buffer
1601 void libertas_set_cmd_ctrl_node(wlan_private * priv,
1602 struct cmd_ctrl_node *ptempnode,
1603 u32 cmd_oid, u16 wait_option, void *pdata_buf)
1605 lbs_deb_enter(LBS_DEB_HOST);
1610 ptempnode->cmd_oid = cmd_oid;
1611 ptempnode->wait_option = wait_option;
1612 ptempnode->pdata_buf = pdata_buf;
1614 lbs_deb_leave(LBS_DEB_HOST);
1618 * @brief This function executes next command in command
1619 * pending queue. It will put fimware back to PS mode
1622 * @param priv A pointer to wlan_private structure
1625 int libertas_execute_next_command(wlan_private * priv)
1627 wlan_adapter *adapter = priv->adapter;
1628 struct cmd_ctrl_node *cmdnode = NULL;
1629 struct cmd_ds_command *cmdptr;
1630 unsigned long flags;
1633 // Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1634 // only caller to us is libertas_thread() and we get even when a
1635 // data packet is received
1636 lbs_deb_enter(LBS_DEB_THREAD);
1638 spin_lock_irqsave(&adapter->driver_lock, flags);
1640 if (adapter->cur_cmd) {
1641 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
1642 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1647 if (!list_empty(&adapter->cmdpendingq)) {
1648 cmdnode = (struct cmd_ctrl_node *)
1649 adapter->cmdpendingq.next;
1652 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1655 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1657 if (is_command_allowed_in_ps(cmdptr->command)) {
1658 if ((adapter->psstate == PS_STATE_SLEEP) ||
1659 (adapter->psstate == PS_STATE_PRE_SLEEP)) {
1661 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
1662 le16_to_cpu(cmdptr->command),
1667 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
1668 "0x%04x in psstate %d\n",
1669 le16_to_cpu(cmdptr->command),
1671 } else if (adapter->psstate != PS_STATE_FULL_POWER) {
1673 * 1. Non-PS command:
1674 * Queue it. set needtowakeup to TRUE if current state
1675 * is SLEEP, otherwise call libertas_ps_wakeup to send Exit_PS.
1676 * 2. PS command but not Exit_PS:
1678 * 3. PS command Exit_PS:
1679 * Set needtowakeup to TRUE if current state is SLEEP,
1680 * otherwise send this command down to firmware
1683 if (cmdptr->command !=
1684 cpu_to_le16(CMD_802_11_PS_MODE)) {
1685 /* Prepare to send Exit PS,
1686 * this non PS command will be sent later */
1687 if ((adapter->psstate == PS_STATE_SLEEP)
1688 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1690 /* w/ new scheme, it will not reach here.
1691 since it is blocked in main_thread. */
1692 adapter->needtowakeup = 1;
1694 libertas_ps_wakeup(priv, 0);
1700 * PS command. Ignore it if it is not Exit_PS.
1701 * otherwise send it down immediately.
1703 struct cmd_ds_802_11_ps_mode *psm =
1704 &cmdptr->params.psmode;
1707 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
1710 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
1712 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
1713 list_del((struct list_head *)cmdnode);
1714 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1720 if ((adapter->psstate == PS_STATE_SLEEP) ||
1721 (adapter->psstate == PS_STATE_PRE_SLEEP)) {
1723 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
1724 list_del((struct list_head *)cmdnode);
1725 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1726 adapter->needtowakeup = 1;
1733 "EXEC_NEXT_CMD: sending EXIT_PS\n");
1736 list_del((struct list_head *)cmdnode);
1737 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
1738 le16_to_cpu(cmdptr->command));
1739 DownloadcommandToStation(priv, cmdnode);
1742 * check if in power save mode, if yes, put the device back
1745 if ((adapter->psmode != WLAN802_11POWERMODECAM) &&
1746 (adapter->psstate == PS_STATE_FULL_POWER) &&
1747 (adapter->connect_status == LIBERTAS_CONNECTED)) {
1748 if (adapter->secinfo.WPAenabled ||
1749 adapter->secinfo.WPA2enabled) {
1750 /* check for valid WPA group keys */
1751 if (adapter->wpa_mcast_key.len ||
1752 adapter->wpa_unicast_key.len) {
1754 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1755 " go back to PS_SLEEP");
1756 libertas_ps_sleep(priv, 0);
1760 "EXEC_NEXT_CMD: cmdpendingq empty, "
1761 "go back to PS_SLEEP");
1762 libertas_ps_sleep(priv, 0);
1769 lbs_deb_leave(LBS_DEB_THREAD);
1773 void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str)
1775 union iwreq_data iwrq;
1778 lbs_deb_enter(LBS_DEB_WEXT);
1780 memset(&iwrq, 0, sizeof(union iwreq_data));
1781 memset(buf, 0, sizeof(buf));
1783 snprintf(buf, sizeof(buf) - 1, "%s", str);
1785 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1787 /* Send Event to upper layer */
1788 lbs_deb_wext("event indication string %s\n", (char *)buf);
1789 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
1790 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
1792 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
1794 lbs_deb_leave(LBS_DEB_WEXT);
1797 static int sendconfirmsleep(wlan_private * priv, u8 * cmdptr, u16 size)
1799 unsigned long flags;
1800 wlan_adapter *adapter = priv->adapter;
1803 lbs_deb_enter(LBS_DEB_HOST);
1805 lbs_deb_host("SEND_SLEEPC_CMD: before download, cmd size %d\n",
1808 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm command", cmdptr, size);
1810 ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
1811 priv->dnld_sent = DNLD_RES_RECEIVED;
1813 spin_lock_irqsave(&adapter->driver_lock, flags);
1814 if (adapter->intcounter || adapter->currenttxskb)
1815 lbs_deb_host("SEND_SLEEPC_CMD: intcounter %d, currenttxskb %p\n",
1816 adapter->intcounter, adapter->currenttxskb);
1817 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1821 "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
1823 spin_lock_irqsave(&adapter->driver_lock, flags);
1824 if (!adapter->intcounter) {
1825 adapter->psstate = PS_STATE_SLEEP;
1827 lbs_deb_host("SEND_SLEEPC_CMD: after sent, intcounter %d\n",
1828 adapter->intcounter);
1830 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1832 lbs_deb_host("SEND_SLEEPC_CMD: sent confirm sleep\n");
1835 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1839 void libertas_ps_sleep(wlan_private * priv, int wait_option)
1841 lbs_deb_enter(LBS_DEB_HOST);
1844 * PS is currently supported only in Infrastructure mode
1845 * Remove this check if it is to be supported in IBSS mode also
1848 libertas_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1849 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
1851 lbs_deb_leave(LBS_DEB_HOST);
1855 * @brief This function sends Exit_PS command to firmware.
1857 * @param priv A pointer to wlan_private structure
1858 * @param wait_option wait response or not
1861 void libertas_ps_wakeup(wlan_private * priv, int wait_option)
1865 lbs_deb_enter(LBS_DEB_HOST);
1867 Localpsmode = cpu_to_le32(WLAN802_11POWERMODECAM);
1869 libertas_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1871 wait_option, 0, &Localpsmode);
1873 lbs_deb_leave(LBS_DEB_HOST);
1877 * @brief This function checks condition and prepares to
1878 * send sleep confirm command to firmware if ok.
1880 * @param priv A pointer to wlan_private structure
1881 * @param psmode Power Saving mode
1884 void libertas_ps_confirm_sleep(wlan_private * priv, u16 psmode)
1886 unsigned long flags =0;
1887 wlan_adapter *adapter = priv->adapter;
1890 lbs_deb_enter(LBS_DEB_HOST);
1892 if (priv->dnld_sent) {
1894 lbs_deb_host("dnld_sent was set");
1897 spin_lock_irqsave(&adapter->driver_lock, flags);
1898 if (adapter->cur_cmd) {
1900 lbs_deb_host("cur_cmd was set");
1902 if (adapter->intcounter > 0) {
1904 lbs_deb_host("intcounter %d", adapter->intcounter);
1906 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1909 lbs_deb_host("sending libertas_ps_confirm_sleep\n");
1910 sendconfirmsleep(priv, (u8 *) & adapter->libertas_ps_confirm_sleep,
1911 sizeof(struct PS_CMD_ConfirmSleep));
1913 lbs_deb_host("sleep confirm has been delayed\n");
1916 lbs_deb_leave(LBS_DEB_HOST);