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_rate_adapt_rateset(wlan_private * priv,
569 struct cmd_ds_command *cmd,
572 struct cmd_ds_802_11_rate_adapt_rateset
573 *rateadapt = &cmd->params.rateset;
574 wlan_adapter *adapter = priv->adapter;
576 lbs_deb_enter(LBS_DEB_CMD);
578 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
580 cmd->command = cpu_to_le16(CMD_802_11_RATE_ADAPT_RATESET);
582 rateadapt->action = cpu_to_le16(cmd_action);
583 rateadapt->enablehwauto = cpu_to_le16(adapter->enablehwauto);
584 rateadapt->bitmap = cpu_to_le16(adapter->ratebitmap);
586 lbs_deb_leave(LBS_DEB_CMD);
590 static int wlan_cmd_802_11_data_rate(wlan_private * priv,
591 struct cmd_ds_command *cmd,
594 struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
595 wlan_adapter *adapter = priv->adapter;
597 lbs_deb_enter(LBS_DEB_CMD);
599 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
601 cmd->command = cpu_to_le16(CMD_802_11_DATA_RATE);
602 memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate));
603 pdatarate->action = cpu_to_le16(cmd_action);
605 if (cmd_action == CMD_ACT_SET_TX_FIX_RATE) {
606 pdatarate->rates[0] = libertas_data_rate_to_fw_index(adapter->cur_rate);
607 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n",
609 } else if (cmd_action == CMD_ACT_SET_TX_AUTO) {
610 lbs_deb_cmd("DATA_RATE: setting auto\n");
613 lbs_deb_leave(LBS_DEB_CMD);
617 static int wlan_cmd_mac_multicast_adr(wlan_private * priv,
618 struct cmd_ds_command *cmd,
621 struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
622 wlan_adapter *adapter = priv->adapter;
624 lbs_deb_enter(LBS_DEB_CMD);
625 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
627 cmd->command = cpu_to_le16(CMD_MAC_MULTICAST_ADR);
629 lbs_deb_cmd("MULTICAST_ADR: setting %d addresses\n", pMCastAdr->nr_of_adrs);
630 pMCastAdr->action = cpu_to_le16(cmd_action);
631 pMCastAdr->nr_of_adrs =
632 cpu_to_le16((u16) adapter->nr_of_multicastmacaddr);
633 memcpy(pMCastAdr->maclist, adapter->multicastlist,
634 adapter->nr_of_multicastmacaddr * ETH_ALEN);
636 lbs_deb_leave(LBS_DEB_CMD);
640 static int wlan_cmd_802_11_rf_channel(wlan_private * priv,
641 struct cmd_ds_command *cmd,
642 int option, void *pdata_buf)
644 struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel;
646 lbs_deb_enter(LBS_DEB_CMD);
647 cmd->command = cpu_to_le16(CMD_802_11_RF_CHANNEL);
648 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel) +
651 if (option == CMD_OPT_802_11_RF_CHANNEL_SET) {
652 rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf));
655 rfchan->action = cpu_to_le16(option);
657 lbs_deb_leave(LBS_DEB_CMD);
661 static int wlan_cmd_802_11_rssi(wlan_private * priv,
662 struct cmd_ds_command *cmd)
664 wlan_adapter *adapter = priv->adapter;
666 lbs_deb_enter(LBS_DEB_CMD);
667 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
668 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
669 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
671 /* reset Beacon SNR/NF/RSSI values */
672 adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
673 adapter->SNR[TYPE_BEACON][TYPE_AVG] = 0;
674 adapter->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
675 adapter->NF[TYPE_BEACON][TYPE_AVG] = 0;
676 adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
677 adapter->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
679 lbs_deb_leave(LBS_DEB_CMD);
683 static int wlan_cmd_reg_access(wlan_private * priv,
684 struct cmd_ds_command *cmdptr,
685 u8 cmd_action, void *pdata_buf)
687 struct wlan_offset_value *offval;
689 lbs_deb_enter(LBS_DEB_CMD);
691 offval = (struct wlan_offset_value *)pdata_buf;
693 switch (cmdptr->command) {
694 case CMD_MAC_REG_ACCESS:
696 struct cmd_ds_mac_reg_access *macreg;
699 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
702 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
705 macreg->action = cpu_to_le16(cmd_action);
706 macreg->offset = cpu_to_le16((u16) offval->offset);
707 macreg->value = cpu_to_le32(offval->value);
712 case CMD_BBP_REG_ACCESS:
714 struct cmd_ds_bbp_reg_access *bbpreg;
718 (struct cmd_ds_bbp_reg_access)
721 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
724 bbpreg->action = cpu_to_le16(cmd_action);
725 bbpreg->offset = cpu_to_le16((u16) offval->offset);
726 bbpreg->value = (u8) offval->value;
731 case CMD_RF_REG_ACCESS:
733 struct cmd_ds_rf_reg_access *rfreg;
737 (struct cmd_ds_rf_reg_access) +
740 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
743 rfreg->action = cpu_to_le16(cmd_action);
744 rfreg->offset = cpu_to_le16((u16) offval->offset);
745 rfreg->value = (u8) offval->value;
754 lbs_deb_leave(LBS_DEB_CMD);
758 static int wlan_cmd_802_11_mac_address(wlan_private * priv,
759 struct cmd_ds_command *cmd,
762 wlan_adapter *adapter = priv->adapter;
764 lbs_deb_enter(LBS_DEB_CMD);
765 cmd->command = cpu_to_le16(CMD_802_11_MAC_ADDRESS);
766 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
770 cmd->params.macadd.action = cpu_to_le16(cmd_action);
772 if (cmd_action == CMD_ACT_SET) {
773 memcpy(cmd->params.macadd.macadd,
774 adapter->current_addr, ETH_ALEN);
775 lbs_deb_hex(LBS_DEB_CMD, "SET_CMD: MAC addr", adapter->current_addr, 6);
778 lbs_deb_leave(LBS_DEB_CMD);
782 static int wlan_cmd_802_11_eeprom_access(wlan_private * priv,
783 struct cmd_ds_command *cmd,
784 int cmd_action, void *pdata_buf)
786 struct wlan_ioctl_regrdwr *ea = pdata_buf;
788 lbs_deb_enter(LBS_DEB_CMD);
790 cmd->command = cpu_to_le16(CMD_802_11_EEPROM_ACCESS);
791 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
795 cmd->params.rdeeprom.action = cpu_to_le16(ea->action);
796 cmd->params.rdeeprom.offset = cpu_to_le16(ea->offset);
797 cmd->params.rdeeprom.bytecount = cpu_to_le16(ea->NOB);
798 cmd->params.rdeeprom.value = 0;
800 lbs_deb_leave(LBS_DEB_CMD);
804 static int wlan_cmd_bt_access(wlan_private * priv,
805 struct cmd_ds_command *cmd,
806 u16 cmd_action, void *pdata_buf)
808 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
809 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
811 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
812 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
814 bt_access->action = cpu_to_le16(cmd_action);
816 switch (cmd_action) {
817 case CMD_ACT_BT_ACCESS_ADD:
818 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
819 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
821 case CMD_ACT_BT_ACCESS_DEL:
822 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
823 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
825 case CMD_ACT_BT_ACCESS_LIST:
826 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
828 case CMD_ACT_BT_ACCESS_RESET:
830 case CMD_ACT_BT_ACCESS_SET_INVERT:
831 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
833 case CMD_ACT_BT_ACCESS_GET_INVERT:
838 lbs_deb_leave(LBS_DEB_CMD);
842 static int wlan_cmd_fwt_access(wlan_private * priv,
843 struct cmd_ds_command *cmd,
844 u16 cmd_action, void *pdata_buf)
846 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
847 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
849 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
850 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
854 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
856 memset(fwt_access, 0, sizeof(*fwt_access));
858 fwt_access->action = cpu_to_le16(cmd_action);
860 lbs_deb_leave(LBS_DEB_CMD);
864 static int wlan_cmd_mesh_access(wlan_private * priv,
865 struct cmd_ds_command *cmd,
866 u16 cmd_action, void *pdata_buf)
868 struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
869 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
871 cmd->command = cpu_to_le16(CMD_MESH_ACCESS);
872 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access) + S_DS_GEN);
876 memcpy(mesh_access, pdata_buf, sizeof(*mesh_access));
878 memset(mesh_access, 0, sizeof(*mesh_access));
880 mesh_access->action = cpu_to_le16(cmd_action);
882 lbs_deb_leave(LBS_DEB_CMD);
886 void libertas_queue_cmd(wlan_adapter * adapter, struct cmd_ctrl_node *cmdnode, u8 addtail)
889 struct cmd_ds_command *cmdptr;
891 lbs_deb_enter(LBS_DEB_HOST);
894 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
898 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
900 lbs_deb_host("QUEUE_CMD: cmdptr is NULL\n");
904 /* Exit_PS command needs to be queued in the header always. */
905 if (cmdptr->command == CMD_802_11_PS_MODE) {
906 struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
907 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
908 if (adapter->psstate != PS_STATE_FULL_POWER)
913 spin_lock_irqsave(&adapter->driver_lock, flags);
916 list_add_tail((struct list_head *)cmdnode,
917 &adapter->cmdpendingq);
919 list_add((struct list_head *)cmdnode, &adapter->cmdpendingq);
921 spin_unlock_irqrestore(&adapter->driver_lock, flags);
923 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
924 le16_to_cpu(((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command));
927 lbs_deb_leave(LBS_DEB_HOST);
931 * TODO: Fix the issue when DownloadcommandToStation is being called the
932 * second time when the command times out. All the cmdptr->xxx are in little
933 * endian and therefore all the comparissions will fail.
934 * For now - we are not performing the endian conversion the second time - but
935 * for PS and DEEP_SLEEP we need to worry
937 static int DownloadcommandToStation(wlan_private * priv,
938 struct cmd_ctrl_node *cmdnode)
941 struct cmd_ds_command *cmdptr;
942 wlan_adapter *adapter = priv->adapter;
947 lbs_deb_enter(LBS_DEB_HOST);
949 if (!adapter || !cmdnode) {
950 lbs_deb_host("DNLD_CMD: adapter or cmdmode is NULL\n");
952 spin_lock_irqsave(&adapter->driver_lock, flags);
953 __libertas_cleanup_and_insert_cmd(priv, cmdnode);
954 spin_unlock_irqrestore(&adapter->driver_lock, flags);
960 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
962 spin_lock_irqsave(&adapter->driver_lock, flags);
963 if (!cmdptr || !cmdptr->size) {
964 lbs_deb_host("DNLD_CMD: cmdptr is NULL or zero\n");
965 __libertas_cleanup_and_insert_cmd(priv, cmdnode);
966 spin_unlock_irqrestore(&adapter->driver_lock, flags);
971 adapter->cur_cmd = cmdnode;
972 adapter->cur_cmd_retcode = 0;
973 spin_unlock_irqrestore(&adapter->driver_lock, flags);
975 cmdsize = cmdptr->size;
976 command = cpu_to_le16(cmdptr->command);
978 lbs_deb_host("DNLD_CMD: command 0x%04x, size %d, jiffies %lu\n",
979 command, le16_to_cpu(cmdptr->size), jiffies);
980 lbs_deb_hex(LBS_DEB_HOST, "DNLD_CMD", cmdnode->bufvirtualaddr, cmdsize);
982 cmdnode->cmdwaitqwoken = 0;
983 cmdsize = cpu_to_le16(cmdsize);
985 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
988 lbs_deb_host("DNLD_CMD: hw_host_to_card failed\n");
989 spin_lock_irqsave(&adapter->driver_lock, flags);
990 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
991 adapter->cur_cmd = NULL;
992 spin_unlock_irqrestore(&adapter->driver_lock, flags);
997 lbs_deb_cmd("DNLD_CMD: sent command 0x%04x, jiffies %lu\n", command, jiffies);
999 /* Setup the timer after transmit command */
1000 if (command == CMD_802_11_SCAN || command == CMD_802_11_AUTHENTICATE
1001 || command == CMD_802_11_ASSOCIATE)
1002 mod_timer(&adapter->command_timer, jiffies + (10*HZ));
1004 mod_timer(&adapter->command_timer, jiffies + (5*HZ));
1009 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1013 static int wlan_cmd_mac_control(wlan_private * priv,
1014 struct cmd_ds_command *cmd)
1016 struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
1018 lbs_deb_enter(LBS_DEB_CMD);
1020 cmd->command = cpu_to_le16(CMD_MAC_CONTROL);
1021 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
1022 mac->action = cpu_to_le16(priv->adapter->currentpacketfilter);
1024 lbs_deb_cmd("MAC_CONTROL: action 0x%x, size %d\n",
1025 le16_to_cpu(mac->action), le16_to_cpu(cmd->size));
1027 lbs_deb_leave(LBS_DEB_CMD);
1032 * This function inserts command node to cmdfreeq
1033 * after cleans it. Requires adapter->driver_lock held.
1035 void __libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
1037 wlan_adapter *adapter = priv->adapter;
1042 cleanup_cmdnode(ptempcmd);
1043 list_add_tail((struct list_head *)ptempcmd, &adapter->cmdfreeq);
1046 static void libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
1048 unsigned long flags;
1050 spin_lock_irqsave(&priv->adapter->driver_lock, flags);
1051 __libertas_cleanup_and_insert_cmd(priv, ptempcmd);
1052 spin_unlock_irqrestore(&priv->adapter->driver_lock, flags);
1055 int libertas_set_radio_control(wlan_private * priv)
1059 lbs_deb_enter(LBS_DEB_CMD);
1061 ret = libertas_prepare_and_send_command(priv,
1062 CMD_802_11_RADIO_CONTROL,
1064 CMD_OPTION_WAITFORRSP, 0, NULL);
1066 lbs_deb_cmd("RADIO_SET: radio %d, preamble %d\n",
1067 priv->adapter->radioon, priv->adapter->preamble);
1069 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1073 int libertas_set_mac_packet_filter(wlan_private * priv)
1077 lbs_deb_enter(LBS_DEB_CMD);
1079 /* Send MAC control command to station */
1080 ret = libertas_prepare_and_send_command(priv,
1081 CMD_MAC_CONTROL, 0, 0, 0, NULL);
1083 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1088 * @brief This function prepare the command before send to firmware.
1090 * @param priv A pointer to wlan_private structure
1091 * @param cmd_no command number
1092 * @param cmd_action command action: GET or SET
1093 * @param wait_option wait option: wait response or not
1094 * @param cmd_oid cmd oid: treated as sub command
1095 * @param pdata_buf A pointer to informaion buffer
1098 int libertas_prepare_and_send_command(wlan_private * priv,
1101 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1104 wlan_adapter *adapter = priv->adapter;
1105 struct cmd_ctrl_node *cmdnode;
1106 struct cmd_ds_command *cmdptr;
1107 unsigned long flags;
1109 lbs_deb_enter(LBS_DEB_HOST);
1112 lbs_deb_host("PREP_CMD: adapter is NULL\n");
1117 if (adapter->surpriseremoved) {
1118 lbs_deb_host("PREP_CMD: card removed\n");
1123 cmdnode = libertas_get_free_cmd_ctrl_node(priv);
1125 if (cmdnode == NULL) {
1126 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1128 /* Wake up main thread to execute next command */
1129 wake_up_interruptible(&priv->waitq);
1134 libertas_set_cmd_ctrl_node(priv, cmdnode, cmd_oid, wait_option, pdata_buf);
1136 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1138 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
1141 lbs_deb_host("PREP_CMD: cmdptr is NULL\n");
1142 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1147 /* Set sequence number, command and INT option */
1149 cmdptr->seqnum = cpu_to_le16(adapter->seqnum);
1151 cmdptr->command = cpu_to_le16(cmd_no);
1155 case CMD_GET_HW_SPEC:
1156 ret = wlan_cmd_hw_spec(priv, cmdptr);
1158 case CMD_802_11_PS_MODE:
1159 ret = wlan_cmd_802_11_ps_mode(priv, cmdptr, cmd_action);
1162 case CMD_802_11_SCAN:
1163 ret = libertas_cmd_80211_scan(priv, cmdptr, pdata_buf);
1166 case CMD_MAC_CONTROL:
1167 ret = wlan_cmd_mac_control(priv, cmdptr);
1170 case CMD_802_11_ASSOCIATE:
1171 case CMD_802_11_REASSOCIATE:
1172 ret = libertas_cmd_80211_associate(priv, cmdptr, pdata_buf);
1175 case CMD_802_11_DEAUTHENTICATE:
1176 ret = libertas_cmd_80211_deauthenticate(priv, cmdptr);
1179 case CMD_802_11_SET_WEP:
1180 ret = wlan_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf);
1183 case CMD_802_11_AD_HOC_START:
1184 ret = libertas_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
1189 case CMD_802_11_RESET:
1190 ret = wlan_cmd_802_11_reset(priv, cmdptr, cmd_action);
1193 case CMD_802_11_GET_LOG:
1194 ret = wlan_cmd_802_11_get_log(priv, cmdptr);
1197 case CMD_802_11_AUTHENTICATE:
1198 ret = libertas_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
1201 case CMD_802_11_GET_STAT:
1202 ret = wlan_cmd_802_11_get_stat(priv, cmdptr);
1205 case CMD_802_11_SNMP_MIB:
1206 ret = wlan_cmd_802_11_snmp_mib(priv, cmdptr,
1207 cmd_action, cmd_oid, pdata_buf);
1210 case CMD_MAC_REG_ACCESS:
1211 case CMD_BBP_REG_ACCESS:
1212 case CMD_RF_REG_ACCESS:
1213 ret = wlan_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf);
1216 case CMD_802_11_RF_CHANNEL:
1217 ret = wlan_cmd_802_11_rf_channel(priv, cmdptr,
1218 cmd_action, pdata_buf);
1221 case CMD_802_11_RF_TX_POWER:
1222 ret = wlan_cmd_802_11_rf_tx_power(priv, cmdptr,
1223 cmd_action, pdata_buf);
1226 case CMD_802_11_RADIO_CONTROL:
1227 ret = wlan_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
1230 case CMD_802_11_DATA_RATE:
1231 ret = wlan_cmd_802_11_data_rate(priv, cmdptr, cmd_action);
1233 case CMD_802_11_RATE_ADAPT_RATESET:
1234 ret = wlan_cmd_802_11_rate_adapt_rateset(priv,
1235 cmdptr, cmd_action);
1238 case CMD_MAC_MULTICAST_ADR:
1239 ret = wlan_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
1242 case CMD_802_11_AD_HOC_JOIN:
1243 ret = libertas_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
1246 case CMD_802_11_RSSI:
1247 ret = wlan_cmd_802_11_rssi(priv, cmdptr);
1250 case CMD_802_11_AD_HOC_STOP:
1251 ret = libertas_cmd_80211_ad_hoc_stop(priv, cmdptr);
1254 case CMD_802_11_ENABLE_RSN:
1255 ret = wlan_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action,
1259 case CMD_802_11_KEY_MATERIAL:
1260 ret = wlan_cmd_802_11_key_material(priv, cmdptr, cmd_action,
1261 cmd_oid, pdata_buf);
1264 case CMD_802_11_PAIRWISE_TSC:
1266 case CMD_802_11_GROUP_TSC:
1269 case CMD_802_11_MAC_ADDRESS:
1270 ret = wlan_cmd_802_11_mac_address(priv, cmdptr, cmd_action);
1273 case CMD_802_11_EEPROM_ACCESS:
1274 ret = wlan_cmd_802_11_eeprom_access(priv, cmdptr,
1275 cmd_action, pdata_buf);
1278 case CMD_802_11_SET_AFC:
1279 case CMD_802_11_GET_AFC:
1281 cmdptr->command = cpu_to_le16(cmd_no);
1282 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1285 memmove(&cmdptr->params.afc,
1286 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1291 case CMD_802_11D_DOMAIN_INFO:
1292 ret = libertas_cmd_802_11d_domain_info(priv, cmdptr,
1293 cmd_no, cmd_action);
1296 case CMD_802_11_SLEEP_PARAMS:
1297 ret = wlan_cmd_802_11_sleep_params(priv, cmdptr, cmd_action);
1299 case CMD_802_11_INACTIVITY_TIMEOUT:
1300 ret = wlan_cmd_802_11_inactivity_timeout(priv, cmdptr,
1301 cmd_action, pdata_buf);
1302 libertas_set_cmd_ctrl_node(priv, cmdnode, 0, 0, pdata_buf);
1305 case CMD_802_11_TPC_CFG:
1306 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
1308 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1311 memmove(&cmdptr->params.tpccfg,
1312 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1316 case CMD_802_11_LED_GPIO_CTRL:
1318 struct mrvlietypes_ledgpio *gpio =
1319 (struct mrvlietypes_ledgpio*)
1320 cmdptr->params.ledgpio.data;
1322 memmove(&cmdptr->params.ledgpio,
1324 sizeof(struct cmd_ds_802_11_led_ctrl));
1327 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
1329 #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1331 cpu_to_le16(gpio->header.len + S_DS_GEN +
1332 ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1333 gpio->header.len = cpu_to_le16(gpio->header.len);
1338 case CMD_802_11_PWR_CFG:
1339 cmdptr->command = cpu_to_le16(CMD_802_11_PWR_CFG);
1341 cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) +
1343 memmove(&cmdptr->params.pwrcfg, pdata_buf,
1344 sizeof(struct cmd_ds_802_11_pwr_cfg));
1349 ret = wlan_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf);
1352 case CMD_FWT_ACCESS:
1353 ret = wlan_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf);
1356 case CMD_MESH_ACCESS:
1357 ret = wlan_cmd_mesh_access(priv, cmdptr, cmd_action, pdata_buf);
1361 cmdptr->command = cpu_to_le16(CMD_GET_TSF);
1362 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1367 lbs_deb_host("PREP_CMD: unknown command 0x%04x\n", cmd_no);
1372 /* return error, since the command preparation failed */
1374 lbs_deb_host("PREP_CMD: command preparation failed\n");
1375 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1380 cmdnode->cmdwaitqwoken = 0;
1382 libertas_queue_cmd(adapter, cmdnode, 1);
1383 adapter->nr_cmd_pending++;
1384 wake_up_interruptible(&priv->waitq);
1386 if (wait_option & CMD_OPTION_WAITFORRSP) {
1387 lbs_deb_host("PREP_CMD: wait for response\n");
1389 wait_event_interruptible(cmdnode->cmdwait_q,
1390 cmdnode->cmdwaitqwoken);
1393 spin_lock_irqsave(&adapter->driver_lock, flags);
1394 if (adapter->cur_cmd_retcode) {
1395 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
1396 adapter->cur_cmd_retcode);
1397 adapter->cur_cmd_retcode = 0;
1400 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1403 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1406 EXPORT_SYMBOL_GPL(libertas_prepare_and_send_command);
1409 * @brief This function allocates the command buffer and link
1410 * it to command free queue.
1412 * @param priv A pointer to wlan_private structure
1415 int libertas_allocate_cmd_buffer(wlan_private * priv)
1420 struct cmd_ctrl_node *tempcmd_array;
1421 u8 *ptempvirtualaddr;
1422 wlan_adapter *adapter = priv->adapter;
1424 lbs_deb_enter(LBS_DEB_HOST);
1426 /* Allocate and initialize cmdCtrlNode */
1427 ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
1429 if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) {
1430 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
1434 adapter->cmd_array = tempcmd_array;
1436 /* Allocate and initialize command buffers */
1437 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1438 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1439 if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) {
1440 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
1445 /* Update command buffer virtual */
1446 tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
1449 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1450 init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
1451 libertas_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
1457 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1462 * @brief This function frees the command buffer.
1464 * @param priv A pointer to wlan_private structure
1467 int libertas_free_cmd_buffer(wlan_private * priv)
1469 u32 ulbufsize; /* Someone needs to die for this. Slowly and painfully */
1471 struct cmd_ctrl_node *tempcmd_array;
1472 wlan_adapter *adapter = priv->adapter;
1474 lbs_deb_enter(LBS_DEB_HOST);
1476 /* need to check if cmd array is allocated or not */
1477 if (adapter->cmd_array == NULL) {
1478 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
1482 tempcmd_array = adapter->cmd_array;
1484 /* Release shared memory buffers */
1485 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1486 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1487 if (tempcmd_array[i].bufvirtualaddr) {
1488 kfree(tempcmd_array[i].bufvirtualaddr);
1489 tempcmd_array[i].bufvirtualaddr = NULL;
1493 /* Release cmd_ctrl_node */
1494 if (adapter->cmd_array) {
1495 kfree(adapter->cmd_array);
1496 adapter->cmd_array = NULL;
1500 lbs_deb_leave(LBS_DEB_HOST);
1505 * @brief This function gets a free command node if available in
1506 * command free queue.
1508 * @param priv A pointer to wlan_private structure
1509 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1511 struct cmd_ctrl_node *libertas_get_free_cmd_ctrl_node(wlan_private * priv)
1513 struct cmd_ctrl_node *tempnode;
1514 wlan_adapter *adapter = priv->adapter;
1515 unsigned long flags;
1517 lbs_deb_enter(LBS_DEB_HOST);
1522 spin_lock_irqsave(&adapter->driver_lock, flags);
1524 if (!list_empty(&adapter->cmdfreeq)) {
1525 tempnode = (struct cmd_ctrl_node *)adapter->cmdfreeq.next;
1526 list_del((struct list_head *)tempnode);
1528 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1532 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1535 cleanup_cmdnode(tempnode);
1537 lbs_deb_leave(LBS_DEB_HOST);
1542 * @brief This function cleans command node.
1544 * @param ptempnode A pointer to cmdCtrlNode structure
1547 static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
1549 lbs_deb_enter(LBS_DEB_HOST);
1553 ptempnode->cmdwaitqwoken = 1;
1554 wake_up_interruptible(&ptempnode->cmdwait_q);
1555 ptempnode->status = 0;
1556 ptempnode->cmd_oid = (u32) 0;
1557 ptempnode->wait_option = 0;
1558 ptempnode->pdata_buf = NULL;
1560 if (ptempnode->bufvirtualaddr != NULL)
1561 memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
1563 lbs_deb_leave(LBS_DEB_HOST);
1567 * @brief This function initializes the command node.
1569 * @param priv A pointer to wlan_private structure
1570 * @param ptempnode A pointer to cmd_ctrl_node structure
1571 * @param cmd_oid cmd oid: treated as sub command
1572 * @param wait_option wait option: wait response or not
1573 * @param pdata_buf A pointer to informaion buffer
1576 void libertas_set_cmd_ctrl_node(wlan_private * priv,
1577 struct cmd_ctrl_node *ptempnode,
1578 u32 cmd_oid, u16 wait_option, void *pdata_buf)
1580 lbs_deb_enter(LBS_DEB_HOST);
1585 ptempnode->cmd_oid = cmd_oid;
1586 ptempnode->wait_option = wait_option;
1587 ptempnode->pdata_buf = pdata_buf;
1589 lbs_deb_leave(LBS_DEB_HOST);
1593 * @brief This function executes next command in command
1594 * pending queue. It will put fimware back to PS mode
1597 * @param priv A pointer to wlan_private structure
1600 int libertas_execute_next_command(wlan_private * priv)
1602 wlan_adapter *adapter = priv->adapter;
1603 struct cmd_ctrl_node *cmdnode = NULL;
1604 struct cmd_ds_command *cmdptr;
1605 unsigned long flags;
1608 // Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1609 // only caller to us is libertas_thread() and we get even when a
1610 // data packet is received
1611 lbs_deb_enter(LBS_DEB_THREAD);
1613 spin_lock_irqsave(&adapter->driver_lock, flags);
1615 if (adapter->cur_cmd) {
1616 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
1617 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1622 if (!list_empty(&adapter->cmdpendingq)) {
1623 cmdnode = (struct cmd_ctrl_node *)
1624 adapter->cmdpendingq.next;
1627 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1630 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1632 if (is_command_allowed_in_ps(cmdptr->command)) {
1633 if ((adapter->psstate == PS_STATE_SLEEP) ||
1634 (adapter->psstate == PS_STATE_PRE_SLEEP)) {
1636 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
1637 le16_to_cpu(cmdptr->command),
1642 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
1643 "0x%04x in psstate %d\n",
1644 le16_to_cpu(cmdptr->command),
1646 } else if (adapter->psstate != PS_STATE_FULL_POWER) {
1648 * 1. Non-PS command:
1649 * Queue it. set needtowakeup to TRUE if current state
1650 * is SLEEP, otherwise call libertas_ps_wakeup to send Exit_PS.
1651 * 2. PS command but not Exit_PS:
1653 * 3. PS command Exit_PS:
1654 * Set needtowakeup to TRUE if current state is SLEEP,
1655 * otherwise send this command down to firmware
1658 if (cmdptr->command !=
1659 cpu_to_le16(CMD_802_11_PS_MODE)) {
1660 /* Prepare to send Exit PS,
1661 * this non PS command will be sent later */
1662 if ((adapter->psstate == PS_STATE_SLEEP)
1663 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1665 /* w/ new scheme, it will not reach here.
1666 since it is blocked in main_thread. */
1667 adapter->needtowakeup = 1;
1669 libertas_ps_wakeup(priv, 0);
1675 * PS command. Ignore it if it is not Exit_PS.
1676 * otherwise send it down immediately.
1678 struct cmd_ds_802_11_ps_mode *psm =
1679 &cmdptr->params.psmode;
1682 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
1685 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
1687 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
1688 list_del((struct list_head *)cmdnode);
1689 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1695 if ((adapter->psstate == PS_STATE_SLEEP) ||
1696 (adapter->psstate == PS_STATE_PRE_SLEEP)) {
1698 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
1699 list_del((struct list_head *)cmdnode);
1700 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1701 adapter->needtowakeup = 1;
1708 "EXEC_NEXT_CMD: sending EXIT_PS\n");
1711 list_del((struct list_head *)cmdnode);
1712 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
1713 le16_to_cpu(cmdptr->command));
1714 DownloadcommandToStation(priv, cmdnode);
1717 * check if in power save mode, if yes, put the device back
1720 if ((adapter->psmode != WLAN802_11POWERMODECAM) &&
1721 (adapter->psstate == PS_STATE_FULL_POWER) &&
1722 (adapter->connect_status == LIBERTAS_CONNECTED)) {
1723 if (adapter->secinfo.WPAenabled ||
1724 adapter->secinfo.WPA2enabled) {
1725 /* check for valid WPA group keys */
1726 if (adapter->wpa_mcast_key.len ||
1727 adapter->wpa_unicast_key.len) {
1729 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1730 " go back to PS_SLEEP");
1731 libertas_ps_sleep(priv, 0);
1735 "EXEC_NEXT_CMD: cmdpendingq empty, "
1736 "go back to PS_SLEEP");
1737 libertas_ps_sleep(priv, 0);
1744 lbs_deb_leave(LBS_DEB_THREAD);
1748 void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str)
1750 union iwreq_data iwrq;
1753 lbs_deb_enter(LBS_DEB_WEXT);
1755 memset(&iwrq, 0, sizeof(union iwreq_data));
1756 memset(buf, 0, sizeof(buf));
1758 snprintf(buf, sizeof(buf) - 1, "%s", str);
1760 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1762 /* Send Event to upper layer */
1763 lbs_deb_wext("event indication string %s\n", (char *)buf);
1764 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
1765 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
1767 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
1769 lbs_deb_leave(LBS_DEB_WEXT);
1772 static int sendconfirmsleep(wlan_private * priv, u8 * cmdptr, u16 size)
1774 unsigned long flags;
1775 wlan_adapter *adapter = priv->adapter;
1778 lbs_deb_enter(LBS_DEB_HOST);
1780 lbs_deb_host("SEND_SLEEPC_CMD: before download, cmd size %d\n",
1783 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm command", cmdptr, size);
1785 ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
1786 priv->dnld_sent = DNLD_RES_RECEIVED;
1788 spin_lock_irqsave(&adapter->driver_lock, flags);
1789 if (adapter->intcounter || adapter->currenttxskb)
1790 lbs_deb_host("SEND_SLEEPC_CMD: intcounter %d, currenttxskb %p\n",
1791 adapter->intcounter, adapter->currenttxskb);
1792 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1796 "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
1798 spin_lock_irqsave(&adapter->driver_lock, flags);
1799 if (!adapter->intcounter) {
1800 adapter->psstate = PS_STATE_SLEEP;
1802 lbs_deb_host("SEND_SLEEPC_CMD: after sent, intcounter %d\n",
1803 adapter->intcounter);
1805 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1807 lbs_deb_host("SEND_SLEEPC_CMD: sent confirm sleep\n");
1810 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1814 void libertas_ps_sleep(wlan_private * priv, int wait_option)
1816 lbs_deb_enter(LBS_DEB_HOST);
1819 * PS is currently supported only in Infrastructure mode
1820 * Remove this check if it is to be supported in IBSS mode also
1823 libertas_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1824 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
1826 lbs_deb_leave(LBS_DEB_HOST);
1830 * @brief This function sends Exit_PS command to firmware.
1832 * @param priv A pointer to wlan_private structure
1833 * @param wait_option wait response or not
1836 void libertas_ps_wakeup(wlan_private * priv, int wait_option)
1840 lbs_deb_enter(LBS_DEB_HOST);
1842 Localpsmode = cpu_to_le32(WLAN802_11POWERMODECAM);
1844 libertas_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1846 wait_option, 0, &Localpsmode);
1848 lbs_deb_leave(LBS_DEB_HOST);
1852 * @brief This function checks condition and prepares to
1853 * send sleep confirm command to firmware if ok.
1855 * @param priv A pointer to wlan_private structure
1856 * @param psmode Power Saving mode
1859 void libertas_ps_confirm_sleep(wlan_private * priv, u16 psmode)
1861 unsigned long flags =0;
1862 wlan_adapter *adapter = priv->adapter;
1865 lbs_deb_enter(LBS_DEB_HOST);
1867 if (priv->dnld_sent) {
1869 lbs_deb_host("dnld_sent was set");
1872 spin_lock_irqsave(&adapter->driver_lock, flags);
1873 if (adapter->cur_cmd) {
1875 lbs_deb_host("cur_cmd was set");
1877 if (adapter->intcounter > 0) {
1879 lbs_deb_host("intcounter %d", adapter->intcounter);
1881 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1884 lbs_deb_host("sending libertas_ps_confirm_sleep\n");
1885 sendconfirmsleep(priv, (u8 *) & adapter->libertas_ps_confirm_sleep,
1886 sizeof(struct PS_CMD_ConfirmSleep));
1888 lbs_deb_host("sleep confirm has been delayed\n");
1891 lbs_deb_leave(LBS_DEB_HOST);