2 * This file contains the handling of command
3 * responses as well as events generated by firmware.
5 #include <linux/delay.h>
6 #include <linux/if_arp.h>
7 #include <linux/netdevice.h>
9 #include <net/iw_handler.h>
20 * @brief This function handles disconnect event. it
21 * reports disconnect to upper layer, clean tx/rx packets,
22 * reset link state etc.
24 * @param priv A pointer to wlan_private structure
27 void libertas_mac_event_disconnected(wlan_private * priv)
29 wlan_adapter *adapter = priv->adapter;
30 union iwreq_data wrqu;
32 if (adapter->connect_status != libertas_connected)
35 lbs_pr_debug(1, "Handles disconnect event.\n");
37 memset(wrqu.ap_addr.sa_data, 0x00, ETH_ALEN);
38 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
41 * Cisco AP sends EAP failure and de-auth in less than 0.5 ms.
42 * It causes problem in the Supplicant
45 msleep_interruptible(1000);
46 wireless_send_event(priv->wlan_dev.netdev, SIOCGIWAP, &wrqu, NULL);
48 /* Free Tx and Rx packets */
49 kfree_skb(priv->adapter->currenttxskb);
50 priv->adapter->currenttxskb = NULL;
52 /* report disconnect to upper layer */
53 netif_stop_queue(priv->wlan_dev.netdev);
54 netif_carrier_off(priv->wlan_dev.netdev);
56 /* reset SNR/NF/RSSI values */
57 memset(adapter->SNR, 0x00, sizeof(adapter->SNR));
58 memset(adapter->NF, 0x00, sizeof(adapter->NF));
59 memset(adapter->RSSI, 0x00, sizeof(adapter->RSSI));
60 memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR));
61 memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF));
62 adapter->nextSNRNF = 0;
63 adapter->numSNRNF = 0;
64 adapter->rxpd_rate = 0;
65 lbs_pr_debug(1, "Current SSID=%s, ssid length=%u\n",
66 adapter->curbssparams.ssid.ssid,
67 adapter->curbssparams.ssid.ssidlength);
68 lbs_pr_debug(1, "Previous SSID=%s, ssid length=%u\n",
69 adapter->previousssid.ssid, adapter->previousssid.ssidlength);
71 /* reset internal flags */
72 adapter->secinfo.WPAenabled = 0;
73 adapter->secinfo.WPA2enabled = 0;
74 adapter->wpa_ie_len = 0;
76 adapter->connect_status = libertas_disconnected;
79 * memorize the previous SSID and BSSID
80 * it could be used for re-assoc
82 memcpy(&adapter->previousssid,
83 &adapter->curbssparams.ssid, sizeof(struct WLAN_802_11_SSID));
84 memcpy(adapter->previousbssid,
85 adapter->curbssparams.bssid, ETH_ALEN);
87 /* need to erase the current SSID and BSSID info */
88 adapter->pattemptedbssdesc = NULL;
89 memset(&adapter->curbssparams, 0, sizeof(adapter->curbssparams));
91 if (adapter->psstate != PS_STATE_FULL_POWER) {
92 /* make firmware to exit PS mode */
93 lbs_pr_debug(1, "Disconnected, so exit PS mode.\n");
94 libertas_ps_wakeup(priv, 0);
99 * @brief This function handles MIC failure event.
101 * @param priv A pointer to wlan_private structure
102 * @para event the event id
105 static void handle_mic_failureevent(wlan_private * priv, u32 event)
109 memset(buf, 0, sizeof(buf));
111 sprintf(buf, "%s", "MLME-MICHAELMICFAILURE.indication ");
113 if (event == MACREG_INT_CODE_MIC_ERR_UNICAST) {
114 strcat(buf, "unicast ");
116 strcat(buf, "multicast ");
119 libertas_send_iwevcustom_event(priv, buf);
122 static int wlan_ret_reg_access(wlan_private * priv,
123 u16 type, struct cmd_ds_command *resp)
125 wlan_adapter *adapter = priv->adapter;
130 case cmd_ret_mac_reg_access:
132 struct cmd_ds_mac_reg_access *reg;
135 (struct cmd_ds_mac_reg_access *)&resp->params.
138 adapter->offsetvalue.offset = reg->offset;
139 adapter->offsetvalue.value = reg->value;
143 case cmd_ret_bbp_reg_access:
145 struct cmd_ds_bbp_reg_access *reg;
147 (struct cmd_ds_bbp_reg_access *)&resp->params.
150 adapter->offsetvalue.offset = reg->offset;
151 adapter->offsetvalue.value = reg->value;
155 case cmd_ret_rf_reg_access:
157 struct cmd_ds_rf_reg_access *reg;
159 (struct cmd_ds_rf_reg_access *)&resp->params.
162 adapter->offsetvalue.offset = reg->offset;
163 adapter->offsetvalue.value = reg->value;
176 static int wlan_ret_get_hw_spec(wlan_private * priv,
177 struct cmd_ds_command *resp)
180 struct cmd_ds_get_hw_spec *hwspec = &resp->params.hwspec;
181 wlan_adapter *adapter = priv->adapter;
186 adapter->fwcapinfo = le32_to_cpu(hwspec->fwcapinfo);
188 adapter->fwreleasenumber = hwspec->fwreleasenumber;
190 lbs_pr_debug(1, "GET_HW_SPEC: FWReleaseVersion- 0x%X\n",
191 adapter->fwreleasenumber);
192 lbs_pr_debug(1, "GET_HW_SPEC: Permanent addr- %2x:%2x:%2x:%2x:%2x:%2x\n",
193 hwspec->permanentaddr[0], hwspec->permanentaddr[1],
194 hwspec->permanentaddr[2], hwspec->permanentaddr[3],
195 hwspec->permanentaddr[4], hwspec->permanentaddr[5]);
196 lbs_pr_debug(1, "GET_HW_SPEC: hwifversion=0x%X version=0x%X\n",
197 hwspec->hwifversion, hwspec->version);
199 adapter->regioncode = le16_to_cpu(hwspec->regioncode);
201 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
202 /* use the region code to search for the index */
203 if (adapter->regioncode == libertas_region_code_to_index[i]) {
204 adapter->regiontableindex = (u16) i;
209 /* if it's unidentified region code, use the default (USA) */
210 if (i >= MRVDRV_MAX_REGION_CODE) {
211 adapter->regioncode = 0x10;
212 adapter->regiontableindex = 0;
214 "unidentified region code, use the default (USA)\n");
217 if (adapter->current_addr[0] == 0xff) {
218 memmove(adapter->current_addr, hwspec->permanentaddr,
222 memcpy(priv->wlan_dev.netdev->dev_addr, adapter->current_addr, ETH_ALEN);
223 memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN);
225 if (libertas_set_regiontable(priv, adapter->regioncode, 0)) {
230 if (libertas_set_universaltable(priv, 0)) {
240 static int wlan_ret_802_11_sleep_params(wlan_private * priv,
241 struct cmd_ds_command *resp)
243 struct cmd_ds_802_11_sleep_params *sp = &resp->params.sleep_params;
244 wlan_adapter *adapter = priv->adapter;
248 lbs_pr_debug(1, "error=%x offset=%x stabletime=%x calcontrol=%x\n"
249 " extsleepclk=%x\n", sp->error, sp->offset,
250 sp->stabletime, sp->calcontrol, sp->externalsleepclk);
251 adapter->sp.sp_error = le16_to_cpu(sp->error);
252 adapter->sp.sp_offset = le16_to_cpu(sp->offset);
253 adapter->sp.sp_stabletime = le16_to_cpu(sp->stabletime);
254 adapter->sp.sp_calcontrol = le16_to_cpu(sp->calcontrol);
255 adapter->sp.sp_extsleepclk = le16_to_cpu(sp->externalsleepclk);
256 adapter->sp.sp_reserved = le16_to_cpu(sp->reserved);
262 static int wlan_ret_802_11_stat(wlan_private * priv,
263 struct cmd_ds_command *resp)
265 /* currently adapter->wlan802_11Stat is unused
267 struct cmd_ds_802_11_get_stat *p11Stat = &resp->params.gstat;
268 wlan_adapter *adapter = priv->adapter;
270 // TODO Convert it to Big endian befor copy
271 memcpy(&adapter->wlan802_11Stat,
272 p11Stat, sizeof(struct cmd_ds_802_11_get_stat));
277 static int wlan_ret_802_11_snmp_mib(wlan_private * priv,
278 struct cmd_ds_command *resp)
280 struct cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
281 u16 oid = le16_to_cpu(smib->oid);
282 u16 querytype = le16_to_cpu(smib->querytype);
286 lbs_pr_debug(1, "SNMP_RESP: value of the oid = %x, querytype=%x\n", oid,
288 lbs_pr_debug(1, "SNMP_RESP: Buf size = %x\n",
289 le16_to_cpu(smib->bufsize));
291 if (querytype == cmd_act_get) {
294 priv->adapter->fragthsd =
296 ((unsigned short *)(smib->value)));
297 lbs_pr_debug(1, "SNMP_RESP: fragthsd =%u\n",
298 priv->adapter->fragthsd);
301 priv->adapter->rtsthsd =
303 ((unsigned short *)(smib->value)));
304 lbs_pr_debug(1, "SNMP_RESP: rtsthsd =%u\n",
305 priv->adapter->rtsthsd);
307 case short_retrylim_i:
308 priv->adapter->txretrycount =
310 ((unsigned short *)(smib->value)));
311 lbs_pr_debug(1, "SNMP_RESP: txretrycount =%u\n",
312 priv->adapter->rtsthsd);
323 static int wlan_ret_802_11_key_material(wlan_private * priv,
324 struct cmd_ds_command *resp)
326 struct cmd_ds_802_11_key_material *pkeymaterial =
327 &resp->params.keymaterial;
328 wlan_adapter *adapter = priv->adapter;
329 u16 action = le16_to_cpu(pkeymaterial->action);
333 /* Copy the returned key to driver private data */
334 if (action == cmd_act_get) {
335 u8 * buf_ptr = (u8 *) &pkeymaterial->keyParamSet;
336 u8 * resp_end = (u8 *) (resp + le16_to_cpu(resp->size));
338 while (buf_ptr < resp_end) {
339 struct MrvlIEtype_keyParamSet * pkeyparamset =
340 (struct MrvlIEtype_keyParamSet *) buf_ptr;
341 struct WLAN_802_11_KEY * pkey;
342 u16 key_info = le16_to_cpu(pkeyparamset->keyinfo);
343 u16 param_set_len = le16_to_cpu(pkeyparamset->length);
345 u16 key_len = le16_to_cpu(pkeyparamset->keylen);
347 end = (u8 *) pkeyparamset + sizeof (pkeyparamset->type)
348 + sizeof (pkeyparamset->length)
350 /* Make sure we don't access past the end of the IEs */
354 if (key_info & KEY_INFO_WPA_UNICAST)
355 pkey = &adapter->wpa_unicast_key;
356 else if (key_info & KEY_INFO_WPA_MCAST)
357 pkey = &adapter->wpa_mcast_key;
361 /* Copy returned key into driver */
362 memset(pkey, 0, sizeof(struct WLAN_802_11_KEY));
363 if (key_len > sizeof(pkey->key))
365 pkey->type = le16_to_cpu(pkeyparamset->keytypeid);
366 pkey->flags = le16_to_cpu(pkeyparamset->keyinfo);
367 pkey->len = le16_to_cpu(pkeyparamset->keylen);
368 memcpy(pkey->key, pkeyparamset->key, pkey->len);
378 static int wlan_ret_802_11_mac_address(wlan_private * priv,
379 struct cmd_ds_command *resp)
381 struct cmd_ds_802_11_mac_address *macadd = &resp->params.macadd;
382 wlan_adapter *adapter = priv->adapter;
386 memcpy(adapter->current_addr, macadd->macadd, ETH_ALEN);
392 static int wlan_ret_802_11_rf_tx_power(wlan_private * priv,
393 struct cmd_ds_command *resp)
395 struct cmd_ds_802_11_rf_tx_power *rtp = &resp->params.txp;
396 wlan_adapter *adapter = priv->adapter;
400 adapter->txpowerlevel = le16_to_cpu(rtp->currentlevel);
402 lbs_pr_debug(1, "Current TxPower Level = %d\n", adapter->txpowerlevel);
408 static int wlan_ret_802_11_rf_antenna(wlan_private * priv,
409 struct cmd_ds_command *resp)
411 struct cmd_ds_802_11_rf_antenna *pAntenna = &resp->params.rant;
412 wlan_adapter *adapter = priv->adapter;
413 u16 action = le16_to_cpu(pAntenna->action);
415 if (action == cmd_act_get_rx)
416 adapter->rxantennamode =
417 le16_to_cpu(pAntenna->antennamode);
419 if (action == cmd_act_get_tx)
420 adapter->txantennamode =
421 le16_to_cpu(pAntenna->antennamode);
423 lbs_pr_debug(1, "RF_ANT_RESP: action = 0x%x, mode = 0x%04x\n",
424 action, le16_to_cpu(pAntenna->antennamode));
429 static int wlan_ret_802_11_rate_adapt_rateset(wlan_private * priv,
430 struct cmd_ds_command *resp)
432 struct cmd_ds_802_11_rate_adapt_rateset *rates =
433 &resp->params.rateset;
434 wlan_adapter *adapter = priv->adapter;
438 if (rates->action == cmd_act_get) {
439 adapter->enablehwauto = rates->enablehwauto;
440 adapter->ratebitmap = rates->bitmap;
448 static int wlan_ret_802_11_data_rate(wlan_private * priv,
449 struct cmd_ds_command *resp)
451 struct cmd_ds_802_11_data_rate *pdatarate = &resp->params.drate;
452 wlan_adapter *adapter = priv->adapter;
457 lbs_dbg_hex("DATA_RATE_RESP: data_rate- ",
458 (u8 *) pdatarate, sizeof(struct cmd_ds_802_11_data_rate));
460 dot11datarate = pdatarate->datarate[0];
461 if (pdatarate->action == cmd_act_get_tx_rate) {
462 memcpy(adapter->libertas_supported_rates, pdatarate->datarate,
463 sizeof(adapter->libertas_supported_rates));
465 adapter->datarate = libertas_index_to_data_rate(dot11datarate);
471 static int wlan_ret_802_11_rf_channel(wlan_private * priv,
472 struct cmd_ds_command *resp)
474 struct cmd_ds_802_11_rf_channel *rfchannel =
475 &resp->params.rfchannel;
476 wlan_adapter *adapter = priv->adapter;
477 u16 action = le16_to_cpu(rfchannel->action);
478 u16 newchannel = le16_to_cpu(rfchannel->currentchannel);
482 if (action == cmd_opt_802_11_rf_channel_get
483 && adapter->curbssparams.channel != newchannel) {
484 lbs_pr_debug(1, "channel Switch: %d to %d\n",
485 adapter->curbssparams.channel, newchannel);
487 /* Update the channel again */
488 adapter->curbssparams.channel = newchannel;
495 static int wlan_ret_802_11_rssi(wlan_private * priv,
496 struct cmd_ds_command *resp)
498 struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp;
499 wlan_adapter *adapter = priv->adapter;
501 /* store the non average value */
502 adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR);
503 adapter->NF[TYPE_BEACON][TYPE_NOAVG] =
504 le16_to_cpu(rssirsp->noisefloor);
506 adapter->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR);
507 adapter->NF[TYPE_BEACON][TYPE_AVG] =
508 le16_to_cpu(rssirsp->avgnoisefloor);
510 adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] =
511 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
512 adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
514 adapter->RSSI[TYPE_BEACON][TYPE_AVG] =
515 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE,
516 adapter->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE);
518 lbs_pr_debug(1, "Beacon RSSI value = 0x%x\n",
519 adapter->RSSI[TYPE_BEACON][TYPE_AVG]);
524 static int wlan_ret_802_11_eeprom_access(wlan_private * priv,
525 struct cmd_ds_command *resp)
527 wlan_adapter *adapter = priv->adapter;
528 struct wlan_ioctl_regrdwr *pbuf;
529 pbuf = (struct wlan_ioctl_regrdwr *) adapter->prdeeprom;
531 lbs_pr_debug(1, "eeprom read len=%x\n",
532 le16_to_cpu(resp->params.rdeeprom.bytecount));
533 if (pbuf->NOB < le16_to_cpu(resp->params.rdeeprom.bytecount)) {
535 lbs_pr_debug(1, "eeprom read return length is too big\n");
538 pbuf->NOB = le16_to_cpu(resp->params.rdeeprom.bytecount);
541 memcpy(&pbuf->value, (u8 *) & resp->params.rdeeprom.value,
542 le16_to_cpu(resp->params.rdeeprom.bytecount));
543 lbs_dbg_hex("adapter", (char *)&pbuf->value,
544 le16_to_cpu(resp->params.rdeeprom.bytecount));
549 static int wlan_ret_get_log(wlan_private * priv,
550 struct cmd_ds_command *resp)
552 struct cmd_ds_802_11_get_log *logmessage =
553 (struct cmd_ds_802_11_get_log *)&resp->params.glog;
554 wlan_adapter *adapter = priv->adapter;
558 /* TODO Convert it to Big Endian before copy */
559 memcpy(&adapter->logmsg, logmessage,
560 sizeof(struct cmd_ds_802_11_get_log));
566 static inline int handle_cmd_response(u16 respcmd,
567 struct cmd_ds_command *resp,
572 wlan_adapter *adapter = priv->adapter;
575 case cmd_ret_mac_reg_access:
576 case cmd_ret_bbp_reg_access:
577 case cmd_ret_rf_reg_access:
578 ret = wlan_ret_reg_access(priv, respcmd, resp);
581 case cmd_ret_hw_spec_info:
582 ret = wlan_ret_get_hw_spec(priv, resp);
585 case cmd_ret_802_11_scan:
586 ret = libertas_ret_80211_scan(priv, resp);
589 case cmd_ret_802_11_get_log:
590 ret = wlan_ret_get_log(priv, resp);
593 case cmd_ret_802_11_associate:
594 case cmd_ret_802_11_reassociate:
595 ret = libertas_ret_80211_associate(priv, resp);
598 case cmd_ret_802_11_disassociate:
599 case cmd_ret_802_11_deauthenticate:
600 ret = libertas_ret_80211_disassociate(priv, resp);
603 case cmd_ret_802_11_ad_hoc_start:
604 case cmd_ret_802_11_ad_hoc_join:
605 ret = libertas_ret_80211_ad_hoc_start(priv, resp);
608 case cmd_ret_802_11_stat:
609 ret = wlan_ret_802_11_stat(priv, resp);
612 case cmd_ret_802_11_snmp_mib:
613 ret = wlan_ret_802_11_snmp_mib(priv, resp);
616 case cmd_ret_802_11_rf_tx_power:
617 ret = wlan_ret_802_11_rf_tx_power(priv, resp);
620 case cmd_ret_802_11_set_afc:
621 case cmd_ret_802_11_get_afc:
622 spin_lock_irqsave(&adapter->driver_lock, flags);
623 memmove(adapter->cur_cmd->pdata_buf,
625 sizeof(struct cmd_ds_802_11_afc));
626 spin_unlock_irqrestore(&adapter->driver_lock, flags);
629 case cmd_ret_802_11_rf_antenna:
630 ret = wlan_ret_802_11_rf_antenna(priv, resp);
633 case cmd_ret_mac_multicast_adr:
634 case cmd_ret_mac_control:
635 case cmd_ret_802_11_set_wep:
636 case cmd_ret_802_11_reset:
637 case cmd_ret_802_11_authenticate:
638 case cmd_ret_802_11_radio_control:
639 case cmd_ret_802_11_beacon_stop:
640 case cmd_ret_802_11_enable_rsn:
643 case cmd_ret_802_11_data_rate:
644 ret = wlan_ret_802_11_data_rate(priv, resp);
646 case cmd_ret_802_11_rate_adapt_rateset:
647 ret = wlan_ret_802_11_rate_adapt_rateset(priv, resp);
649 case cmd_ret_802_11_rf_channel:
650 ret = wlan_ret_802_11_rf_channel(priv, resp);
653 case cmd_ret_802_11_rssi:
654 ret = wlan_ret_802_11_rssi(priv, resp);
657 case cmd_ret_802_11_mac_address:
658 ret = wlan_ret_802_11_mac_address(priv, resp);
661 case cmd_ret_802_11_ad_hoc_stop:
662 ret = libertas_ret_80211_ad_hoc_stop(priv, resp);
665 case cmd_ret_802_11_key_material:
666 lbs_pr_debug(1, "CMD_RESP: KEY_MATERIAL command response\n");
667 ret = wlan_ret_802_11_key_material(priv, resp);
670 case cmd_ret_802_11_eeprom_access:
671 ret = wlan_ret_802_11_eeprom_access(priv, resp);
674 case cmd_ret_802_11d_domain_info:
675 ret = libertas_ret_802_11d_domain_info(priv, resp);
678 case cmd_ret_802_11_sleep_params:
679 ret = wlan_ret_802_11_sleep_params(priv, resp);
681 case cmd_ret_802_11_inactivity_timeout:
682 spin_lock_irqsave(&adapter->driver_lock, flags);
683 *((u16 *) adapter->cur_cmd->pdata_buf) =
684 le16_to_cpu(resp->params.inactivity_timeout.timeout);
685 spin_unlock_irqrestore(&adapter->driver_lock, flags);
688 case cmd_ret_802_11_tpc_cfg:
689 spin_lock_irqsave(&adapter->driver_lock, flags);
690 memmove(adapter->cur_cmd->pdata_buf,
691 &resp->params.tpccfg,
692 sizeof(struct cmd_ds_802_11_tpc_cfg));
693 spin_unlock_irqrestore(&adapter->driver_lock, flags);
695 case cmd_ret_802_11_led_gpio_ctrl:
696 spin_lock_irqsave(&adapter->driver_lock, flags);
697 memmove(adapter->cur_cmd->pdata_buf,
698 &resp->params.ledgpio,
699 sizeof(struct cmd_ds_802_11_led_ctrl));
700 spin_unlock_irqrestore(&adapter->driver_lock, flags);
702 case cmd_ret_802_11_pwr_cfg:
703 spin_lock_irqsave(&adapter->driver_lock, flags);
704 memmove(adapter->cur_cmd->pdata_buf,
705 &resp->params.pwrcfg,
706 sizeof(struct cmd_ds_802_11_pwr_cfg));
707 spin_unlock_irqrestore(&adapter->driver_lock, flags);
711 case cmd_ret_get_tsf:
712 spin_lock_irqsave(&adapter->driver_lock, flags);
713 memcpy(priv->adapter->cur_cmd->pdata_buf,
714 &resp->params.gettsf.tsfvalue, sizeof(u64));
715 spin_unlock_irqrestore(&adapter->driver_lock, flags);
717 case cmd_ret_bt_access:
718 spin_lock_irqsave(&adapter->driver_lock, flags);
719 if (adapter->cur_cmd->pdata_buf)
720 memcpy(adapter->cur_cmd->pdata_buf,
721 &resp->params.bt.addr1, 2 * ETH_ALEN);
722 spin_unlock_irqrestore(&adapter->driver_lock, flags);
724 case cmd_ret_fwt_access:
725 spin_lock_irqsave(&adapter->driver_lock, flags);
726 if (adapter->cur_cmd->pdata_buf)
727 memcpy(adapter->cur_cmd->pdata_buf,
729 sizeof(resp->params.fwt));
730 spin_unlock_irqrestore(&adapter->driver_lock, flags);
732 case cmd_ret_mesh_access:
733 if (adapter->cur_cmd->pdata_buf)
734 memcpy(adapter->cur_cmd->pdata_buf,
736 sizeof(resp->params.mesh));
738 case cmd_rte_802_11_tx_rate_query:
739 priv->adapter->txrate = resp->params.txrate.txrate;
742 lbs_pr_debug(1, "CMD_RESP: Unknown command response %#x\n",
749 int libertas_process_rx_command(wlan_private * priv)
752 struct cmd_ds_command *resp;
753 wlan_adapter *adapter = priv->adapter;
760 lbs_pr_debug(1, "CMD_RESP: @ %lu\n", jiffies);
762 /* Now we got response from FW, cancel the command timer */
763 del_timer(&adapter->command_timer);
765 mutex_lock(&adapter->lock);
766 spin_lock_irqsave(&adapter->driver_lock, flags);
768 if (!adapter->cur_cmd) {
769 lbs_pr_debug(1, "CMD_RESP: NULL cur_cmd=%p\n", adapter->cur_cmd);
771 spin_unlock_irqrestore(&adapter->driver_lock, flags);
774 resp = (struct cmd_ds_command *)(adapter->cur_cmd->bufvirtualaddr);
776 lbs_dbg_hex("CMD_RESP:", adapter->cur_cmd->bufvirtualaddr,
777 priv->wlan_dev.upld_len);
779 respcmd = le16_to_cpu(resp->command);
781 result = le16_to_cpu(resp->result);
783 lbs_pr_debug(1, "CMD_RESP: %x result: %d length: %d\n", respcmd,
784 result, priv->wlan_dev.upld_len);
786 if (!(respcmd & 0x8000)) {
787 lbs_pr_debug(1, "Invalid response to command!");
788 adapter->cur_cmd_retcode = -1;
789 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
790 adapter->nr_cmd_pending--;
791 adapter->cur_cmd = NULL;
792 spin_unlock_irqrestore(&adapter->driver_lock, flags);
797 /* Store the response code to cur_cmd_retcode. */
798 adapter->cur_cmd_retcode = le16_to_cpu(resp->result);
800 if (respcmd == cmd_ret_802_11_ps_mode) {
801 struct cmd_ds_802_11_ps_mode *psmode;
803 psmode = &resp->params.psmode;
805 "CMD_RESP: PS_MODE cmd reply result=%#x action=0x%X\n",
806 resp->result, psmode->action);
807 psmode->action = cpu_to_le16(psmode->action);
810 lbs_pr_debug(1, "CMD_RESP: PS command failed- %#x \n",
812 if (adapter->mode == IW_MODE_ADHOC) {
814 * We should not re-try enter-ps command in
815 * ad-hoc mode. It takes place in
816 * libertas_execute_next_command().
818 if (psmode->action == cmd_subcmd_enter_ps)
820 wlan802_11powermodecam;
822 } else if (psmode->action == cmd_subcmd_enter_ps) {
823 adapter->needtowakeup = 0;
824 adapter->psstate = PS_STATE_AWAKE;
826 lbs_pr_debug(1, "CMD_RESP: Enter_PS command response\n");
827 if (adapter->connect_status != libertas_connected) {
829 * When Deauth Event received before Enter_PS command
830 * response, We need to wake up the firmware.
833 "Disconnected, Going to invoke libertas_ps_wakeup\n");
835 mutex_unlock(&adapter->lock);
836 spin_unlock_irqrestore(&adapter->driver_lock, flags);
837 libertas_ps_wakeup(priv, 0);
838 mutex_lock(&adapter->lock);
839 spin_lock_irqsave(&adapter->driver_lock, flags);
841 } else if (psmode->action == cmd_subcmd_exit_ps) {
842 adapter->needtowakeup = 0;
843 adapter->psstate = PS_STATE_FULL_POWER;
844 lbs_pr_debug(1, "CMD_RESP: Exit_PS command response\n");
846 lbs_pr_debug(1, "CMD_RESP: PS- action=0x%X\n",
850 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
851 adapter->nr_cmd_pending--;
852 adapter->cur_cmd = NULL;
853 spin_unlock_irqrestore(&adapter->driver_lock, flags);
859 if (adapter->cur_cmd->cmdflags & CMD_F_HOSTCMD) {
860 /* Copy the response back to response buffer */
861 memcpy(adapter->cur_cmd->pdata_buf, resp, resp->size);
863 adapter->cur_cmd->cmdflags &= ~CMD_F_HOSTCMD;
866 /* If the command is not successful, cleanup and return failure */
867 if ((result != 0 || !(respcmd & 0x8000))) {
868 lbs_pr_debug(1, "CMD_RESP: command reply %#x result=%#x\n",
869 resp->command, resp->result);
871 * Handling errors here
874 case cmd_ret_hw_spec_info:
875 case cmd_ret_802_11_reset:
876 lbs_pr_debug(1, "CMD_RESP: Reset command failed\n");
881 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
882 adapter->nr_cmd_pending--;
883 adapter->cur_cmd = NULL;
884 spin_unlock_irqrestore(&adapter->driver_lock, flags);
890 spin_unlock_irqrestore(&adapter->driver_lock, flags);
892 ret = handle_cmd_response(respcmd, resp, priv);
894 spin_lock_irqsave(&adapter->driver_lock, flags);
895 if (adapter->cur_cmd) {
896 /* Clean up and Put current command back to cmdfreeq */
897 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
898 adapter->nr_cmd_pending--;
899 WARN_ON(adapter->nr_cmd_pending > 128);
900 adapter->cur_cmd = NULL;
902 spin_unlock_irqrestore(&adapter->driver_lock, flags);
905 mutex_unlock(&adapter->lock);
910 int libertas_process_event(wlan_private * priv)
913 wlan_adapter *adapter = priv->adapter;
916 spin_lock_irq(&adapter->driver_lock);
917 eventcause = adapter->eventcause;
918 spin_unlock_irq(&adapter->driver_lock);
922 lbs_pr_debug(1, "EVENT Cause %x\n", eventcause);
924 switch (eventcause >> SBI_EVENT_CAUSE_SHIFT) {
925 case MACREG_INT_CODE_LINK_SENSED:
926 lbs_pr_debug(1, "EVENT: MACREG_INT_CODE_LINK_SENSED\n");
929 case MACREG_INT_CODE_DEAUTHENTICATED:
930 lbs_pr_debug(1, "EVENT: Deauthenticated\n");
931 libertas_mac_event_disconnected(priv);
934 case MACREG_INT_CODE_DISASSOCIATED:
935 lbs_pr_debug(1, "EVENT: Disassociated\n");
936 libertas_mac_event_disconnected(priv);
939 case MACREG_INT_CODE_LINK_LOSE_NO_SCAN:
940 lbs_pr_debug(1, "EVENT: Link lost\n");
941 libertas_mac_event_disconnected(priv);
944 case MACREG_INT_CODE_PS_SLEEP:
945 lbs_pr_debug(1, "EVENT: SLEEP\n");
946 lbs_pr_debug(1, "_");
948 /* handle unexpected PS SLEEP event */
949 if (adapter->psstate == PS_STATE_FULL_POWER) {
951 "EVENT: In FULL POWER mode - ignore PS SLEEP\n");
954 adapter->psstate = PS_STATE_PRE_SLEEP;
956 libertas_ps_confirm_sleep(priv, (u16) adapter->psmode);
960 case MACREG_INT_CODE_PS_AWAKE:
961 lbs_pr_debug(1, "EVENT: AWAKE \n");
962 lbs_pr_debug(1, "|");
964 /* handle unexpected PS AWAKE event */
965 if (adapter->psstate == PS_STATE_FULL_POWER) {
967 "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
971 adapter->psstate = PS_STATE_AWAKE;
973 if (adapter->needtowakeup) {
975 * wait for the command processing to finish
976 * before resuming sending
977 * adapter->needtowakeup will be set to FALSE
978 * in libertas_ps_wakeup()
980 lbs_pr_debug(1, "Waking up...\n");
981 libertas_ps_wakeup(priv, 0);
985 case MACREG_INT_CODE_MIC_ERR_UNICAST:
986 lbs_pr_debug(1, "EVENT: UNICAST MIC ERROR\n");
987 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST);
990 case MACREG_INT_CODE_MIC_ERR_MULTICAST:
991 lbs_pr_debug(1, "EVENT: MULTICAST MIC ERROR\n");
992 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST);
994 case MACREG_INT_CODE_MIB_CHANGED:
995 case MACREG_INT_CODE_INIT_DONE:
998 case MACREG_INT_CODE_ADHOC_BCN_LOST:
999 lbs_pr_debug(1, "EVENT: HWAC - ADHOC BCN LOST\n");
1002 case MACREG_INT_CODE_RSSI_LOW:
1003 lbs_pr_alert( "EVENT: RSSI_LOW\n");
1005 case MACREG_INT_CODE_SNR_LOW:
1006 lbs_pr_alert( "EVENT: SNR_LOW\n");
1008 case MACREG_INT_CODE_MAX_FAIL:
1009 lbs_pr_alert( "EVENT: MAX_FAIL\n");
1011 case MACREG_INT_CODE_RSSI_HIGH:
1012 lbs_pr_alert( "EVENT: RSSI_HIGH\n");
1014 case MACREG_INT_CODE_SNR_HIGH:
1015 lbs_pr_alert( "EVENT: SNR_HIGH\n");
1019 lbs_pr_alert( "EVENT: unknown event id: %#x\n",
1020 eventcause >> SBI_EVENT_CAUSE_SHIFT);
1024 spin_lock_irq(&adapter->driver_lock);
1025 adapter->eventcause = 0;
1026 spin_unlock_irq(&adapter->driver_lock);