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 cmd->command = cpu_to_le16(cmd_802_11_inactivity_timeout);
106 cpu_to_le16(sizeof(struct cmd_ds_802_11_inactivity_timeout)
109 cmd->params.inactivity_timeout.action = cpu_to_le16(cmd_action);
112 cmd->params.inactivity_timeout.timeout = cpu_to_le16(*timeout);
114 cmd->params.inactivity_timeout.timeout = 0;
119 static int wlan_cmd_802_11_sleep_params(wlan_private * priv,
120 struct cmd_ds_command *cmd,
123 wlan_adapter *adapter = priv->adapter;
124 struct cmd_ds_802_11_sleep_params *sp = &cmd->params.sleep_params;
126 lbs_deb_enter(LBS_DEB_CMD);
128 cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
130 cmd->command = cpu_to_le16(cmd_802_11_sleep_params);
132 if (cmd_action == cmd_act_get) {
133 memset(&adapter->sp, 0, sizeof(struct sleep_params));
134 memset(sp, 0, sizeof(struct cmd_ds_802_11_sleep_params));
135 sp->action = cpu_to_le16(cmd_action);
136 } else if (cmd_action == cmd_act_set) {
137 sp->action = cpu_to_le16(cmd_action);
138 sp->error = cpu_to_le16(adapter->sp.sp_error);
139 sp->offset = cpu_to_le16(adapter->sp.sp_offset);
140 sp->stabletime = cpu_to_le16(adapter->sp.sp_stabletime);
141 sp->calcontrol = (u8) adapter->sp.sp_calcontrol;
142 sp->externalsleepclk = (u8) adapter->sp.sp_extsleepclk;
143 sp->reserved = cpu_to_le16(adapter->sp.sp_reserved);
146 lbs_deb_leave(LBS_DEB_CMD);
150 static int wlan_cmd_802_11_set_wep(wlan_private * priv,
151 struct cmd_ds_command *cmd,
155 struct cmd_ds_802_11_set_wep *wep = &cmd->params.wep;
156 wlan_adapter *adapter = priv->adapter;
158 struct assoc_request * assoc_req = pdata_buf;
160 lbs_deb_enter(LBS_DEB_CMD);
162 cmd->command = cpu_to_le16(cmd_802_11_set_wep);
163 cmd->size = cpu_to_le16(sizeof(*wep) + S_DS_GEN);
165 if (cmd_act == cmd_act_add) {
169 lbs_deb_cmd("Invalid association request!");
174 wep->action = cpu_to_le16(cmd_act_add);
176 /* default tx key index */
177 wep->keyindex = cpu_to_le16((u16)(assoc_req->wep_tx_keyidx &
178 (u32)cmd_WEP_KEY_INDEX_MASK));
180 lbs_deb_cmd("Tx key Index: %u\n", le16_to_cpu(wep->keyindex));
182 /* Copy key types and material to host command structure */
183 for (i = 0; i < 4; i++) {
184 struct WLAN_802_11_KEY * pkey = &assoc_req->wep_keys[i];
189 cpu_to_le16(cmd_type_wep_40_bit);
190 memmove(&wep->keymaterial[i], pkey->key,
193 case KEY_LEN_WEP_104:
195 cpu_to_le16(cmd_type_wep_104_bit);
196 memmove(&wep->keymaterial[i], pkey->key,
202 lbs_deb_cmd("Invalid WEP key %d length of %d\n",
209 } else if (cmd_act == cmd_act_remove) {
210 /* ACT_REMOVE clears _all_ WEP keys */
211 wep->action = cpu_to_le16(cmd_act_remove);
213 /* default tx key index */
214 wep->keyindex = cpu_to_le16((u16)(adapter->wep_tx_keyidx &
215 (u32)cmd_WEP_KEY_INDEX_MASK));
221 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
225 static int wlan_cmd_802_11_enable_rsn(wlan_private * priv,
226 struct cmd_ds_command *cmd,
230 struct cmd_ds_802_11_enable_rsn *penableRSN = &cmd->params.enbrsn;
231 u32 * enable = pdata_buf;
233 lbs_deb_enter(LBS_DEB_CMD);
235 cmd->command = cpu_to_le16(cmd_802_11_enable_rsn);
236 cmd->size = cpu_to_le16(sizeof(*penableRSN) + S_DS_GEN);
237 penableRSN->action = cpu_to_le16(cmd_action);
239 if (cmd_action == cmd_act_set) {
241 penableRSN->enable = cpu_to_le16(cmd_enable_rsn);
243 penableRSN->enable = cpu_to_le16(cmd_disable_rsn);
246 lbs_deb_leave(LBS_DEB_CMD);
251 static void set_one_wpa_key(struct MrvlIEtype_keyParamSet * pkeyparamset,
252 struct WLAN_802_11_KEY * pkey)
254 pkeyparamset->keytypeid = cpu_to_le16(pkey->type);
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->keylen = cpu_to_le16(pkey->len);
268 memcpy(pkeyparamset->key, pkey->key, pkey->len);
269 pkeyparamset->length = cpu_to_le16( sizeof(pkeyparamset->keytypeid)
270 + sizeof(pkeyparamset->keyinfo)
271 + sizeof(pkeyparamset->keylen)
272 + sizeof(pkeyparamset->key));
275 static int wlan_cmd_802_11_key_material(wlan_private * priv,
276 struct cmd_ds_command *cmd,
278 u32 cmd_oid, void *pdata_buf)
280 struct cmd_ds_802_11_key_material *pkeymaterial =
281 &cmd->params.keymaterial;
282 struct assoc_request * assoc_req = pdata_buf;
286 lbs_deb_enter(LBS_DEB_CMD);
288 cmd->command = cpu_to_le16(cmd_802_11_key_material);
289 pkeymaterial->action = cpu_to_le16(cmd_action);
291 if (cmd_action == cmd_act_get) {
292 cmd->size = cpu_to_le16(S_DS_GEN + sizeof (pkeymaterial->action));
297 memset(&pkeymaterial->keyParamSet, 0, sizeof(pkeymaterial->keyParamSet));
299 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
300 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
301 &assoc_req->wpa_unicast_key);
305 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
306 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
307 &assoc_req->wpa_mcast_key);
311 cmd->size = cpu_to_le16( S_DS_GEN
312 + sizeof (pkeymaterial->action)
313 + (index * sizeof(struct MrvlIEtype_keyParamSet)));
318 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
322 static int wlan_cmd_802_11_reset(wlan_private * priv,
323 struct cmd_ds_command *cmd, int cmd_action)
325 struct cmd_ds_802_11_reset *reset = &cmd->params.reset;
327 cmd->command = cpu_to_le16(cmd_802_11_reset);
328 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
329 reset->action = cpu_to_le16(cmd_action);
334 static int wlan_cmd_802_11_get_log(wlan_private * priv,
335 struct cmd_ds_command *cmd)
337 cmd->command = cpu_to_le16(cmd_802_11_get_log);
339 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_log) + S_DS_GEN);
344 static int wlan_cmd_802_11_get_stat(wlan_private * priv,
345 struct cmd_ds_command *cmd)
347 cmd->command = cpu_to_le16(cmd_802_11_get_stat);
349 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) + S_DS_GEN);
354 static int wlan_cmd_802_11_snmp_mib(wlan_private * priv,
355 struct cmd_ds_command *cmd,
357 int cmd_oid, void *pdata_buf)
359 struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib;
360 wlan_adapter *adapter = priv->adapter;
363 lbs_deb_enter(LBS_DEB_CMD);
365 lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
367 cmd->command = cpu_to_le16(cmd_802_11_snmp_mib);
368 cmd->size = cpu_to_le16(sizeof(*pSNMPMIB) + S_DS_GEN);
371 case OID_802_11_INFRASTRUCTURE_MODE:
373 u8 mode = (u8) (size_t) pdata_buf;
374 pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
375 pSNMPMIB->oid = cpu_to_le16((u16) desired_bsstype_i);
376 pSNMPMIB->bufsize = sizeof(u8);
377 if (mode == IW_MODE_ADHOC) {
378 ucTemp = SNMP_MIB_VALUE_ADHOC;
380 /* Infra and Auto modes */
381 ucTemp = SNMP_MIB_VALUE_INFRA;
384 memmove(pSNMPMIB->value, &ucTemp, sizeof(u8));
389 case OID_802_11D_ENABLE:
393 pSNMPMIB->oid = cpu_to_le16((u16) dot11d_i);
395 if (cmd_action == cmd_act_set) {
396 pSNMPMIB->querytype = cmd_act_set;
397 pSNMPMIB->bufsize = sizeof(u16);
398 ulTemp = *(u32 *)pdata_buf;
399 *((__le16 *)(pSNMPMIB->value)) =
400 cpu_to_le16((u16) ulTemp);
405 case OID_802_11_FRAGMENTATION_THRESHOLD:
409 pSNMPMIB->oid = cpu_to_le16((u16) fragthresh_i);
411 if (cmd_action == cmd_act_get) {
412 pSNMPMIB->querytype = cpu_to_le16(cmd_act_get);
413 } else if (cmd_action == cmd_act_set) {
414 pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
415 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
416 ulTemp = *((u32 *) pdata_buf);
417 *((__le16 *)(pSNMPMIB->value)) =
418 cpu_to_le16((u16) ulTemp);
425 case OID_802_11_RTS_THRESHOLD:
429 pSNMPMIB->oid = le16_to_cpu((u16) rtsthresh_i);
431 if (cmd_action == cmd_act_get) {
432 pSNMPMIB->querytype = cpu_to_le16(cmd_act_get);
433 } else if (cmd_action == cmd_act_set) {
434 pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
435 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
436 ulTemp = *((u32 *)pdata_buf);
437 *(__le16 *)(pSNMPMIB->value) =
438 cpu_to_le16((u16) ulTemp);
443 case OID_802_11_TX_RETRYCOUNT:
444 pSNMPMIB->oid = cpu_to_le16((u16) short_retrylim_i);
446 if (cmd_action == cmd_act_get) {
447 pSNMPMIB->querytype = cpu_to_le16(cmd_act_get);
448 } else if (cmd_action == cmd_act_set) {
449 pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
450 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
451 *((__le16 *)(pSNMPMIB->value)) =
452 cpu_to_le16((u16) adapter->txretrycount);
461 "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
462 le16_to_cpu(cmd->command), le16_to_cpu(cmd->size),
463 le16_to_cpu(cmd->seqnum), le16_to_cpu(cmd->result));
466 "SNMP_CMD: action=0x%x, oid=0x%x, oidsize=0x%x, value=0x%x\n",
467 le16_to_cpu(pSNMPMIB->querytype), le16_to_cpu(pSNMPMIB->oid),
468 le16_to_cpu(pSNMPMIB->bufsize),
469 le16_to_cpu(*(__le16 *) pSNMPMIB->value));
471 lbs_deb_leave(LBS_DEB_CMD);
475 static int wlan_cmd_802_11_radio_control(wlan_private * priv,
476 struct cmd_ds_command *cmd,
479 wlan_adapter *adapter = priv->adapter;
480 struct cmd_ds_802_11_radio_control *pradiocontrol = &cmd->params.radio;
482 lbs_deb_enter(LBS_DEB_CMD);
485 cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control)) +
487 cmd->command = cpu_to_le16(cmd_802_11_radio_control);
489 pradiocontrol->action = cpu_to_le16(cmd_action);
491 switch (adapter->preamble) {
492 case cmd_type_short_preamble:
493 pradiocontrol->control = cpu_to_le16(SET_SHORT_PREAMBLE);
496 case cmd_type_long_preamble:
497 pradiocontrol->control = cpu_to_le16(SET_LONG_PREAMBLE);
500 case cmd_type_auto_preamble:
502 pradiocontrol->control = cpu_to_le16(SET_AUTO_PREAMBLE);
506 if (adapter->radioon)
507 pradiocontrol->control |= cpu_to_le16(TURN_ON_RF);
509 pradiocontrol->control &= cpu_to_le16(~TURN_ON_RF);
511 lbs_deb_leave(LBS_DEB_CMD);
515 static int wlan_cmd_802_11_rf_tx_power(wlan_private * priv,
516 struct cmd_ds_command *cmd,
517 u16 cmd_action, void *pdata_buf)
520 struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
522 lbs_deb_enter(LBS_DEB_CMD);
525 cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN);
526 cmd->command = cpu_to_le16(cmd_802_11_rf_tx_power);
527 prtp->action = cpu_to_le16(cmd_action);
529 lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
530 le16_to_cpu(cmd->size), le16_to_cpu(cmd->command),
531 le16_to_cpu(prtp->action));
533 switch (cmd_action) {
534 case cmd_act_tx_power_opt_get:
535 prtp->action = cpu_to_le16(cmd_act_get);
536 prtp->currentlevel = 0;
539 case cmd_act_tx_power_opt_set_high:
540 prtp->action = cpu_to_le16(cmd_act_set);
541 prtp->currentlevel = cpu_to_le16(cmd_act_tx_power_index_high);
544 case cmd_act_tx_power_opt_set_mid:
545 prtp->action = cpu_to_le16(cmd_act_set);
546 prtp->currentlevel = cpu_to_le16(cmd_act_tx_power_index_mid);
549 case cmd_act_tx_power_opt_set_low:
550 prtp->action = cpu_to_le16(cmd_act_set);
551 prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
555 lbs_deb_leave(LBS_DEB_CMD);
559 static int wlan_cmd_802_11_rf_antenna(wlan_private * priv,
560 struct cmd_ds_command *cmd,
561 u16 cmd_action, void *pdata_buf)
563 struct cmd_ds_802_11_rf_antenna *rant = &cmd->params.rant;
565 cmd->command = cpu_to_le16(cmd_802_11_rf_antenna);
566 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_antenna) +
569 rant->action = cpu_to_le16(cmd_action);
570 if ((cmd_action == cmd_act_set_rx) || (cmd_action == cmd_act_set_tx)) {
571 rant->antennamode = cpu_to_le16((u16) (*(u32 *) pdata_buf));
577 static int wlan_cmd_802_11_rate_adapt_rateset(wlan_private * priv,
578 struct cmd_ds_command *cmd,
581 struct cmd_ds_802_11_rate_adapt_rateset
582 *rateadapt = &cmd->params.rateset;
583 wlan_adapter *adapter = priv->adapter;
586 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
588 cmd->command = cpu_to_le16(cmd_802_11_rate_adapt_rateset);
590 lbs_deb_enter(LBS_DEB_CMD);
592 rateadapt->action = cpu_to_le16(cmd_action);
593 rateadapt->enablehwauto = cpu_to_le16(adapter->enablehwauto);
594 rateadapt->bitmap = cpu_to_le16(adapter->ratebitmap);
596 lbs_deb_leave(LBS_DEB_CMD);
600 static int wlan_cmd_802_11_data_rate(wlan_private * priv,
601 struct cmd_ds_command *cmd,
604 struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
605 wlan_adapter *adapter = priv->adapter;
607 lbs_deb_enter(LBS_DEB_CMD);
609 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
612 cmd->command = cpu_to_le16(cmd_802_11_data_rate);
614 memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate));
616 pdatarate->action = cpu_to_le16(cmd_action);
618 if (cmd_action == cmd_act_set_tx_fix_rate) {
619 pdatarate->datarate[0] = libertas_data_rate_to_index(adapter->datarate);
620 lbs_deb_cmd("Setting FW for fixed rate 0x%02X\n",
622 } else if (cmd_action == cmd_act_set_tx_auto) {
623 lbs_deb_cmd("Setting FW for AUTO rate\n");
626 lbs_deb_leave(LBS_DEB_CMD);
630 static int wlan_cmd_mac_multicast_adr(wlan_private * priv,
631 struct cmd_ds_command *cmd,
634 struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
635 wlan_adapter *adapter = priv->adapter;
637 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
639 cmd->command = cpu_to_le16(cmd_mac_multicast_adr);
641 pMCastAdr->action = cpu_to_le16(cmd_action);
642 pMCastAdr->nr_of_adrs =
643 cpu_to_le16((u16) adapter->nr_of_multicastmacaddr);
644 memcpy(pMCastAdr->maclist, adapter->multicastlist,
645 adapter->nr_of_multicastmacaddr * ETH_ALEN);
650 static int wlan_cmd_802_11_rf_channel(wlan_private * priv,
651 struct cmd_ds_command *cmd,
652 int option, void *pdata_buf)
654 struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel;
656 cmd->command = cpu_to_le16(cmd_802_11_rf_channel);
657 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel) +
660 if (option == cmd_opt_802_11_rf_channel_set) {
661 rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf));
664 rfchan->action = cpu_to_le16(option);
669 static int wlan_cmd_802_11_rssi(wlan_private * priv,
670 struct cmd_ds_command *cmd)
672 wlan_adapter *adapter = priv->adapter;
674 cmd->command = cpu_to_le16(cmd_802_11_rssi);
675 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
676 cmd->params.rssi.N = cpu_to_le16(priv->adapter->bcn_avg_factor);
678 /* reset Beacon SNR/NF/RSSI values */
679 adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
680 adapter->SNR[TYPE_BEACON][TYPE_AVG] = 0;
681 adapter->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
682 adapter->NF[TYPE_BEACON][TYPE_AVG] = 0;
683 adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
684 adapter->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
689 static int wlan_cmd_reg_access(wlan_private * priv,
690 struct cmd_ds_command *cmdptr,
691 u8 cmd_action, void *pdata_buf)
693 struct wlan_offset_value *offval;
695 lbs_deb_enter(LBS_DEB_CMD);
697 offval = (struct wlan_offset_value *)pdata_buf;
699 switch (cmdptr->command) {
700 case cmd_mac_reg_access:
702 struct cmd_ds_mac_reg_access *macreg;
705 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
708 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
711 macreg->action = cpu_to_le16(cmd_action);
712 macreg->offset = cpu_to_le16((u16) offval->offset);
713 macreg->value = cpu_to_le32(offval->value);
718 case cmd_bbp_reg_access:
720 struct cmd_ds_bbp_reg_access *bbpreg;
724 (struct cmd_ds_bbp_reg_access)
727 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
730 bbpreg->action = cpu_to_le16(cmd_action);
731 bbpreg->offset = cpu_to_le16((u16) offval->offset);
732 bbpreg->value = (u8) offval->value;
737 case cmd_rf_reg_access:
739 struct cmd_ds_rf_reg_access *rfreg;
743 (struct cmd_ds_rf_reg_access) +
746 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
749 rfreg->action = cpu_to_le16(cmd_action);
750 rfreg->offset = cpu_to_le16((u16) offval->offset);
751 rfreg->value = (u8) offval->value;
760 lbs_deb_leave(LBS_DEB_CMD);
764 static int wlan_cmd_802_11_mac_address(wlan_private * priv,
765 struct cmd_ds_command *cmd,
768 wlan_adapter *adapter = priv->adapter;
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_dbg_hex("SET_CMD: MAC ADDRESS-", adapter->current_addr, 6);
786 static int wlan_cmd_802_11_eeprom_access(wlan_private * priv,
787 struct cmd_ds_command *cmd,
788 int cmd_action, void *pdata_buf)
790 struct wlan_ioctl_regrdwr *ea = pdata_buf;
792 lbs_deb_enter(LBS_DEB_CMD);
794 cmd->command = cpu_to_le16(cmd_802_11_eeprom_access);
795 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
799 cmd->params.rdeeprom.action = cpu_to_le16(ea->action);
800 cmd->params.rdeeprom.offset = cpu_to_le16(ea->offset);
801 cmd->params.rdeeprom.bytecount = cpu_to_le16(ea->NOB);
802 cmd->params.rdeeprom.value = 0;
807 static int wlan_cmd_bt_access(wlan_private * priv,
808 struct cmd_ds_command *cmd,
809 u16 cmd_action, void *pdata_buf)
811 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
812 lbs_deb_cmd("BT CMD(%d)\n", cmd_action);
814 cmd->command = cpu_to_le16(cmd_bt_access);
815 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
817 bt_access->action = cpu_to_le16(cmd_action);
819 switch (cmd_action) {
820 case cmd_act_bt_access_add:
821 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
822 lbs_dbg_hex("BT_ADD: blinded mac address-", bt_access->addr1, 6);
824 case cmd_act_bt_access_del:
825 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
826 lbs_dbg_hex("BT_DEL: blinded mac address-", bt_access->addr1, 6);
828 case cmd_act_bt_access_list:
829 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
831 case cmd_act_bt_access_reset:
833 case cmd_act_bt_access_set_invert:
834 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
836 case cmd_act_bt_access_get_invert:
844 static int wlan_cmd_fwt_access(wlan_private * priv,
845 struct cmd_ds_command *cmd,
846 u16 cmd_action, void *pdata_buf)
848 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
849 lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
851 cmd->command = cpu_to_le16(cmd_fwt_access);
852 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
856 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
858 memset(fwt_access, 0, sizeof(*fwt_access));
860 fwt_access->action = cpu_to_le16(cmd_action);
865 static int wlan_cmd_mesh_access(wlan_private * priv,
866 struct cmd_ds_command *cmd,
867 u16 cmd_action, void *pdata_buf)
869 struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
870 lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
872 cmd->command = cpu_to_le16(cmd_mesh_access);
873 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access) + S_DS_GEN);
877 memcpy(mesh_access, pdata_buf, sizeof(*mesh_access));
879 memset(mesh_access, 0, sizeof(*mesh_access));
881 mesh_access->action = cpu_to_le16(cmd_action);
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_CMD);
894 lbs_deb_cmd("QUEUE_CMD: cmdnode is NULL\n");
898 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
900 lbs_deb_cmd("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_cmd("QUEUE_CMD: Inserted node=%p, cmd=0x%x in cmdpendingq\n",
925 le16_to_cpu(((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command));
928 lbs_deb_leave(LBS_DEB_CMD);
932 * TODO: Fix the issue when DownloadcommandToStation is being called the
933 * second time when the command timesout. All the cmdptr->xxx are in little
934 * endian and therefore all the comparissions will fail.
935 * For now - we are not performing the endian conversion the second time - but
936 * for PS and DEEP_SLEEP we need to worry
938 static int DownloadcommandToStation(wlan_private * priv,
939 struct cmd_ctrl_node *cmdnode)
942 struct cmd_ds_command *cmdptr;
943 wlan_adapter *adapter = priv->adapter;
948 lbs_deb_enter(LBS_DEB_CMD);
950 if (!adapter || !cmdnode) {
951 lbs_deb_cmd("DNLD_CMD: adapter = %p, cmdnode = %p\n",
954 spin_lock_irqsave(&adapter->driver_lock, flags);
955 __libertas_cleanup_and_insert_cmd(priv, cmdnode);
956 spin_unlock_irqrestore(&adapter->driver_lock, flags);
962 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
965 spin_lock_irqsave(&adapter->driver_lock, flags);
966 if (!cmdptr || !cmdptr->size) {
967 lbs_deb_cmd("DNLD_CMD: cmdptr is Null or cmd size is Zero, "
969 __libertas_cleanup_and_insert_cmd(priv, cmdnode);
970 spin_unlock_irqrestore(&adapter->driver_lock, flags);
975 adapter->cur_cmd = cmdnode;
976 adapter->cur_cmd_retcode = 0;
977 spin_unlock_irqrestore(&adapter->driver_lock, flags);
978 lbs_deb_cmd("DNLD_CMD:: Before download, size of cmd = %d\n",
979 le16_to_cpu(cmdptr->size));
981 cmdsize = cmdptr->size;
983 command = cpu_to_le16(cmdptr->command);
985 cmdnode->cmdwaitqwoken = 0;
986 cmdsize = cpu_to_le16(cmdsize);
988 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
991 lbs_deb_cmd("DNLD_CMD: Host to Card failed\n");
992 spin_lock_irqsave(&adapter->driver_lock, flags);
993 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
994 adapter->cur_cmd = NULL;
995 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1000 lbs_deb_cmd("DNLD_CMD: Sent command 0x%x @ %lu\n", command, jiffies);
1001 lbs_dbg_hex("DNLD_CMD: command", cmdnode->bufvirtualaddr, cmdsize);
1003 /* Setup the timer after transmit command */
1004 if (command == cmd_802_11_scan || command == cmd_802_11_authenticate
1005 || command == cmd_802_11_associate)
1006 mod_timer(&adapter->command_timer, jiffies + (10*HZ));
1008 mod_timer(&adapter->command_timer, jiffies + (5*HZ));
1013 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1017 static int wlan_cmd_mac_control(wlan_private * priv,
1018 struct cmd_ds_command *cmd)
1020 struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
1022 lbs_deb_enter(LBS_DEB_CMD);
1024 cmd->command = cpu_to_le16(cmd_mac_control);
1025 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
1026 mac->action = cpu_to_le16(priv->adapter->currentpacketfilter);
1028 lbs_deb_cmd("wlan_cmd_mac_control(): action=0x%X size=%d\n",
1029 le16_to_cpu(mac->action), le16_to_cpu(cmd->size));
1031 lbs_deb_leave(LBS_DEB_CMD);
1036 * This function inserts command node to cmdfreeq
1037 * after cleans it. Requires adapter->driver_lock held.
1039 void __libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
1041 wlan_adapter *adapter = priv->adapter;
1046 cleanup_cmdnode(ptempcmd);
1047 list_add_tail((struct list_head *)ptempcmd, &adapter->cmdfreeq);
1052 void libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
1054 unsigned long flags;
1056 spin_lock_irqsave(&priv->adapter->driver_lock, flags);
1057 __libertas_cleanup_and_insert_cmd(priv, ptempcmd);
1058 spin_unlock_irqrestore(&priv->adapter->driver_lock, flags);
1061 int libertas_set_radio_control(wlan_private * priv)
1065 lbs_deb_enter(LBS_DEB_CMD);
1067 ret = libertas_prepare_and_send_command(priv,
1068 cmd_802_11_radio_control,
1070 cmd_option_waitforrsp, 0, NULL);
1072 lbs_deb_cmd("RADIO_SET: on or off: 0x%X, preamble = 0x%X\n",
1073 priv->adapter->radioon, priv->adapter->preamble);
1075 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1079 int libertas_set_mac_packet_filter(wlan_private * priv)
1083 lbs_deb_enter(LBS_DEB_CMD);
1085 lbs_deb_cmd("libertas_set_mac_packet_filter value = %x\n",
1086 priv->adapter->currentpacketfilter);
1088 /* Send MAC control command to station */
1089 ret = libertas_prepare_and_send_command(priv,
1090 cmd_mac_control, 0, 0, 0, NULL);
1092 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1097 * @brief This function prepare the command before send to firmware.
1099 * @param priv A pointer to wlan_private structure
1100 * @param cmd_no command number
1101 * @param cmd_action command action: GET or SET
1102 * @param wait_option wait option: wait response or not
1103 * @param cmd_oid cmd oid: treated as sub command
1104 * @param pdata_buf A pointer to informaion buffer
1107 int libertas_prepare_and_send_command(wlan_private * priv,
1110 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1113 wlan_adapter *adapter = priv->adapter;
1114 struct cmd_ctrl_node *cmdnode;
1115 struct cmd_ds_command *cmdptr;
1116 unsigned long flags;
1118 lbs_deb_enter(LBS_DEB_CMD);
1121 lbs_deb_cmd("PREP_CMD: adapter is Null\n");
1126 if (adapter->surpriseremoved) {
1127 lbs_deb_cmd("PREP_CMD: Card is Removed\n");
1132 cmdnode = libertas_get_free_cmd_ctrl_node(priv);
1134 if (cmdnode == NULL) {
1135 lbs_deb_cmd("PREP_CMD: No free cmdnode\n");
1137 /* Wake up main thread to execute next command */
1138 wake_up_interruptible(&priv->mainthread.waitq);
1143 libertas_set_cmd_ctrl_node(priv, cmdnode, cmd_oid, wait_option, pdata_buf);
1145 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1147 lbs_deb_cmd("PREP_CMD: Val of cmd ptr=%p, command=0x%X\n",
1151 lbs_deb_cmd("PREP_CMD: bufvirtualaddr of cmdnode is NULL\n");
1152 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1157 /* Set sequence number, command and INT option */
1159 cmdptr->seqnum = cpu_to_le16(adapter->seqnum);
1161 cmdptr->command = cpu_to_le16(cmd_no);
1165 case cmd_get_hw_spec:
1166 ret = wlan_cmd_hw_spec(priv, cmdptr);
1168 case cmd_802_11_ps_mode:
1169 ret = wlan_cmd_802_11_ps_mode(priv, cmdptr, cmd_action);
1172 case cmd_802_11_scan:
1173 ret = libertas_cmd_80211_scan(priv, cmdptr, pdata_buf);
1176 case cmd_mac_control:
1177 ret = wlan_cmd_mac_control(priv, cmdptr);
1180 case cmd_802_11_associate:
1181 case cmd_802_11_reassociate:
1182 ret = libertas_cmd_80211_associate(priv, cmdptr, pdata_buf);
1185 case cmd_802_11_deauthenticate:
1186 ret = libertas_cmd_80211_deauthenticate(priv, cmdptr);
1189 case cmd_802_11_set_wep:
1190 ret = wlan_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf);
1193 case cmd_802_11_ad_hoc_start:
1194 ret = libertas_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
1199 case cmd_802_11_reset:
1200 ret = wlan_cmd_802_11_reset(priv, cmdptr, cmd_action);
1203 case cmd_802_11_get_log:
1204 ret = wlan_cmd_802_11_get_log(priv, cmdptr);
1207 case cmd_802_11_authenticate:
1208 ret = libertas_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
1211 case cmd_802_11_get_stat:
1212 ret = wlan_cmd_802_11_get_stat(priv, cmdptr);
1215 case cmd_802_11_snmp_mib:
1216 ret = wlan_cmd_802_11_snmp_mib(priv, cmdptr,
1217 cmd_action, cmd_oid, pdata_buf);
1220 case cmd_mac_reg_access:
1221 case cmd_bbp_reg_access:
1222 case cmd_rf_reg_access:
1223 ret = wlan_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf);
1226 case cmd_802_11_rf_channel:
1227 ret = wlan_cmd_802_11_rf_channel(priv, cmdptr,
1228 cmd_action, pdata_buf);
1231 case cmd_802_11_rf_tx_power:
1232 ret = wlan_cmd_802_11_rf_tx_power(priv, cmdptr,
1233 cmd_action, pdata_buf);
1236 case cmd_802_11_radio_control:
1237 ret = wlan_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
1240 case cmd_802_11_rf_antenna:
1241 ret = wlan_cmd_802_11_rf_antenna(priv, cmdptr,
1242 cmd_action, pdata_buf);
1245 case cmd_802_11_data_rate:
1246 ret = wlan_cmd_802_11_data_rate(priv, cmdptr, cmd_action);
1248 case cmd_802_11_rate_adapt_rateset:
1249 ret = wlan_cmd_802_11_rate_adapt_rateset(priv,
1250 cmdptr, cmd_action);
1253 case cmd_mac_multicast_adr:
1254 ret = wlan_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
1257 case cmd_802_11_ad_hoc_join:
1258 ret = libertas_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
1261 case cmd_802_11_rssi:
1262 ret = wlan_cmd_802_11_rssi(priv, cmdptr);
1265 case cmd_802_11_ad_hoc_stop:
1266 ret = libertas_cmd_80211_ad_hoc_stop(priv, cmdptr);
1269 case cmd_802_11_enable_rsn:
1270 ret = wlan_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action,
1274 case cmd_802_11_key_material:
1275 ret = wlan_cmd_802_11_key_material(priv, cmdptr, cmd_action,
1276 cmd_oid, pdata_buf);
1279 case cmd_802_11_pairwise_tsc:
1281 case cmd_802_11_group_tsc:
1284 case cmd_802_11_mac_address:
1285 ret = wlan_cmd_802_11_mac_address(priv, cmdptr, cmd_action);
1288 case cmd_802_11_eeprom_access:
1289 ret = wlan_cmd_802_11_eeprom_access(priv, cmdptr,
1290 cmd_action, pdata_buf);
1293 case cmd_802_11_set_afc:
1294 case cmd_802_11_get_afc:
1296 cmdptr->command = cpu_to_le16(cmd_no);
1297 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1300 memmove(&cmdptr->params.afc,
1301 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1306 case cmd_802_11d_domain_info:
1307 ret = libertas_cmd_802_11d_domain_info(priv, cmdptr,
1308 cmd_no, cmd_action);
1311 case cmd_802_11_sleep_params:
1312 ret = wlan_cmd_802_11_sleep_params(priv, cmdptr, cmd_action);
1314 case cmd_802_11_inactivity_timeout:
1315 ret = wlan_cmd_802_11_inactivity_timeout(priv, cmdptr,
1316 cmd_action, pdata_buf);
1317 libertas_set_cmd_ctrl_node(priv, cmdnode, 0, 0, pdata_buf);
1320 case cmd_802_11_tpc_cfg:
1321 cmdptr->command = cpu_to_le16(cmd_802_11_tpc_cfg);
1323 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1326 memmove(&cmdptr->params.tpccfg,
1327 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1331 case cmd_802_11_led_gpio_ctrl:
1333 struct mrvlietypes_ledgpio *gpio =
1334 (struct mrvlietypes_ledgpio*)
1335 cmdptr->params.ledgpio.data;
1337 memmove(&cmdptr->params.ledgpio,
1339 sizeof(struct cmd_ds_802_11_led_ctrl));
1342 cpu_to_le16(cmd_802_11_led_gpio_ctrl);
1344 #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1346 cpu_to_le16(gpio->header.len + S_DS_GEN +
1347 ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1348 gpio->header.len = cpu_to_le16(gpio->header.len);
1353 case cmd_802_11_pwr_cfg:
1354 cmdptr->command = cpu_to_le16(cmd_802_11_pwr_cfg);
1356 cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) +
1358 memmove(&cmdptr->params.pwrcfg, pdata_buf,
1359 sizeof(struct cmd_ds_802_11_pwr_cfg));
1364 ret = wlan_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf);
1367 case cmd_fwt_access:
1368 ret = wlan_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf);
1371 case cmd_mesh_access:
1372 ret = wlan_cmd_mesh_access(priv, cmdptr, cmd_action, pdata_buf);
1376 cmdptr->command = cpu_to_le16(cmd_get_tsf);
1377 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1381 case cmd_802_11_tx_rate_query:
1382 cmdptr->command = cpu_to_le16(cmd_802_11_tx_rate_query);
1383 cmdptr->size = cpu_to_le16(sizeof(struct cmd_tx_rate_query) +
1385 adapter->txrate = 0;
1389 lbs_deb_cmd("PREP_CMD: unknown command- %#x\n", cmd_no);
1394 /* return error, since the command preparation failed */
1396 lbs_deb_cmd("PREP_CMD: command preparation failed\n");
1397 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1402 cmdnode->cmdwaitqwoken = 0;
1404 libertas_queue_cmd(adapter, cmdnode, 1);
1405 adapter->nr_cmd_pending++;
1406 wake_up_interruptible(&priv->mainthread.waitq);
1408 if (wait_option & cmd_option_waitforrsp) {
1409 lbs_deb_cmd("PREP_CMD: Wait for CMD response\n");
1411 wait_event_interruptible(cmdnode->cmdwait_q,
1412 cmdnode->cmdwaitqwoken);
1415 spin_lock_irqsave(&adapter->driver_lock, flags);
1416 if (adapter->cur_cmd_retcode) {
1417 lbs_deb_cmd("PREP_CMD: command failed with return code=%d\n",
1418 adapter->cur_cmd_retcode);
1419 adapter->cur_cmd_retcode = 0;
1422 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1425 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1428 EXPORT_SYMBOL_GPL(libertas_prepare_and_send_command);
1431 * @brief This function allocates the command buffer and link
1432 * it to command free queue.
1434 * @param priv A pointer to wlan_private structure
1437 int libertas_allocate_cmd_buffer(wlan_private * priv)
1442 struct cmd_ctrl_node *tempcmd_array;
1443 u8 *ptempvirtualaddr;
1444 wlan_adapter *adapter = priv->adapter;
1446 lbs_deb_enter(LBS_DEB_CMD);
1448 /* Allocate and initialize cmdCtrlNode */
1449 ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
1451 if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) {
1453 "ALLOC_CMD_BUF: failed to allocate tempcmd_array\n");
1457 adapter->cmd_array = tempcmd_array;
1459 /* Allocate and initialize command buffers */
1460 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1461 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1462 if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) {
1464 "ALLOC_CMD_BUF: ptempvirtualaddr: out of memory\n");
1469 /* Update command buffer virtual */
1470 tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
1473 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1474 init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
1475 libertas_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
1481 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1486 * @brief This function frees the command buffer.
1488 * @param priv A pointer to wlan_private structure
1491 int libertas_free_cmd_buffer(wlan_private * priv)
1493 u32 ulbufsize; /* Someone needs to die for this. Slowly and painfully */
1495 struct cmd_ctrl_node *tempcmd_array;
1496 wlan_adapter *adapter = priv->adapter;
1498 lbs_deb_enter(LBS_DEB_CMD);
1500 /* need to check if cmd array is allocated or not */
1501 if (adapter->cmd_array == NULL) {
1502 lbs_deb_cmd("FREE_CMD_BUF: cmd_array is Null\n");
1506 tempcmd_array = adapter->cmd_array;
1508 /* Release shared memory buffers */
1509 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1510 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1511 if (tempcmd_array[i].bufvirtualaddr) {
1512 lbs_deb_cmd("Free all the array\n");
1513 kfree(tempcmd_array[i].bufvirtualaddr);
1514 tempcmd_array[i].bufvirtualaddr = NULL;
1518 /* Release cmd_ctrl_node */
1519 if (adapter->cmd_array) {
1520 lbs_deb_cmd("Free cmd_array\n");
1521 kfree(adapter->cmd_array);
1522 adapter->cmd_array = NULL;
1526 lbs_deb_leave(LBS_DEB_CMD);
1531 * @brief This function gets a free command node if available in
1532 * command free queue.
1534 * @param priv A pointer to wlan_private structure
1535 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1537 struct cmd_ctrl_node *libertas_get_free_cmd_ctrl_node(wlan_private * priv)
1539 struct cmd_ctrl_node *tempnode;
1540 wlan_adapter *adapter = priv->adapter;
1541 unsigned long flags;
1546 spin_lock_irqsave(&adapter->driver_lock, flags);
1548 if (!list_empty(&adapter->cmdfreeq)) {
1549 tempnode = (struct cmd_ctrl_node *)adapter->cmdfreeq.next;
1550 list_del((struct list_head *)tempnode);
1552 lbs_deb_cmd("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1556 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1560 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode available\n");
1561 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode Address = %p\n",
1564 cleanup_cmdnode(tempnode);
1571 * @brief This function cleans command node.
1573 * @param ptempnode A pointer to cmdCtrlNode structure
1576 static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
1580 ptempnode->cmdwaitqwoken = 1;
1581 wake_up_interruptible(&ptempnode->cmdwait_q);
1582 ptempnode->status = 0;
1583 ptempnode->cmd_oid = (u32) 0;
1584 ptempnode->wait_option = 0;
1585 ptempnode->pdata_buf = NULL;
1587 if (ptempnode->bufvirtualaddr != NULL)
1588 memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
1593 * @brief This function initializes the command node.
1595 * @param priv A pointer to wlan_private structure
1596 * @param ptempnode A pointer to cmd_ctrl_node structure
1597 * @param cmd_oid cmd oid: treated as sub command
1598 * @param wait_option wait option: wait response or not
1599 * @param pdata_buf A pointer to informaion buffer
1602 void libertas_set_cmd_ctrl_node(wlan_private * priv,
1603 struct cmd_ctrl_node *ptempnode,
1604 u32 cmd_oid, u16 wait_option, void *pdata_buf)
1606 lbs_deb_enter(LBS_DEB_CMD);
1611 ptempnode->cmd_oid = cmd_oid;
1612 ptempnode->wait_option = wait_option;
1613 ptempnode->pdata_buf = pdata_buf;
1615 lbs_deb_leave(LBS_DEB_CMD);
1619 * @brief This function executes next command in command
1620 * pending queue. It will put fimware back to PS mode
1623 * @param priv A pointer to wlan_private structure
1626 int libertas_execute_next_command(wlan_private * priv)
1628 wlan_adapter *adapter = priv->adapter;
1629 struct cmd_ctrl_node *cmdnode = NULL;
1630 struct cmd_ds_command *cmdptr;
1631 unsigned long flags;
1634 lbs_deb_enter(LBS_DEB_CMD);
1636 spin_lock_irqsave(&adapter->driver_lock, flags);
1638 if (adapter->cur_cmd) {
1639 lbs_pr_alert( "EXEC_NEXT_CMD: there is command in processing!\n");
1640 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1645 if (!list_empty(&adapter->cmdpendingq)) {
1646 cmdnode = (struct cmd_ctrl_node *)
1647 adapter->cmdpendingq.next;
1650 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1654 "EXEC_NEXT_CMD: Got next command from cmdpendingq\n");
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%x in psstate %d\n",
1662 le16_to_cpu(cmdptr->command),
1667 lbs_deb_cmd("EXEC_NEXT_CMD: OK to send command "
1668 "0x%x 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%x\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 ExitPS 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 down...\n");
1736 list_del((struct list_head *)cmdnode);
1737 lbs_deb_cmd("EXEC_NEXT_CMD: Sending 0x%04X command\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: command PendQ is empty,"
1761 " go back to PS_SLEEP");
1762 libertas_ps_sleep(priv, 0);
1769 lbs_deb_leave(LBS_DEB_CMD);
1773 void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str)
1775 union iwreq_data iwrq;
1778 lbs_deb_enter(LBS_DEB_CMD);
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_cmd("Event Indication string = %s\n", (char *)buf);
1789 lbs_deb_cmd("Event Indication String length = %d\n", iwrq.data.length);
1791 lbs_deb_cmd("Sending wireless event IWEVCUSTOM for %s\n", str);
1792 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
1794 lbs_deb_leave(LBS_DEB_CMD);
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_CMD);
1805 lbs_deb_cmd("SEND_SLEEPC_CMD: Before download, size of cmd = %d\n",
1808 lbs_dbg_hex("SEND_SLEEPC_CMD: 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_cmd("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_cmd("SEND_SLEEPC_CMD: After sent,IntC=%d\n",
1828 adapter->intcounter);
1830 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1832 lbs_deb_cmd("SEND_SLEEPC_CMD: Sent Confirm Sleep command\n");
1836 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1840 void libertas_ps_sleep(wlan_private * priv, int wait_option)
1842 lbs_deb_enter(LBS_DEB_CMD);
1845 * PS is currently supported only in Infrastructure mode
1846 * Remove this check if it is to be supported in IBSS mode also
1849 libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
1850 cmd_subcmd_enter_ps, wait_option, 0, NULL);
1852 lbs_deb_leave(LBS_DEB_CMD);
1856 * @brief This function sends Eixt_PS command to firmware.
1858 * @param priv A pointer to wlan_private structure
1859 * @param wait_option wait response or not
1862 void libertas_ps_wakeup(wlan_private * priv, int wait_option)
1866 lbs_deb_enter(LBS_DEB_CMD);
1868 Localpsmode = cpu_to_le32(wlan802_11powermodecam);
1870 lbs_deb_cmd("Exit_PS: Localpsmode = %d\n", wlan802_11powermodecam);
1872 libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
1874 wait_option, 0, &Localpsmode);
1876 lbs_deb_leave(LBS_DEB_CMD);
1880 * @brief This function checks condition and prepares to
1881 * send sleep confirm command to firmware if ok.
1883 * @param priv A pointer to wlan_private structure
1884 * @param psmode Power Saving mode
1887 void libertas_ps_confirm_sleep(wlan_private * priv, u16 psmode)
1889 unsigned long flags =0;
1890 wlan_adapter *adapter = priv->adapter;
1893 lbs_deb_enter(LBS_DEB_CMD);
1895 if (priv->dnld_sent) {
1900 spin_lock_irqsave(&adapter->driver_lock, flags);
1901 if (adapter->cur_cmd) {
1905 if (adapter->intcounter > 0) {
1907 lbs_deb_cmd("I%d", adapter->intcounter);
1909 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1912 lbs_deb_cmd("Sending libertas_ps_confirm_sleep\n");
1913 sendconfirmsleep(priv, (u8 *) & adapter->libertas_ps_confirm_sleep,
1914 sizeof(struct PS_CMD_ConfirmSleep));
1916 lbs_deb_cmd("Sleep Confirm has been delayed\n");
1919 lbs_deb_leave(LBS_DEB_CMD);