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;
75 adapter->secinfo.auth1xalg = WLAN_1X_AUTH_ALG_NONE;
76 adapter->secinfo.Encryptionmode = CIPHER_NONE;
78 adapter->connect_status = libertas_disconnected;
81 * memorize the previous SSID and BSSID
82 * it could be used for re-assoc
84 memcpy(&adapter->previousssid,
85 &adapter->curbssparams.ssid, sizeof(struct WLAN_802_11_SSID));
86 memcpy(adapter->previousbssid,
87 adapter->curbssparams.bssid, ETH_ALEN);
89 /* need to erase the current SSID and BSSID info */
90 adapter->pattemptedbssdesc = NULL;
91 memset(&adapter->curbssparams, 0, sizeof(adapter->curbssparams));
93 if (adapter->psstate != PS_STATE_FULL_POWER) {
94 /* make firmware to exit PS mode */
95 lbs_pr_debug(1, "Disconnected, so exit PS mode.\n");
96 libertas_ps_wakeup(priv, 0);
101 * @brief This function handles MIC failure event.
103 * @param priv A pointer to wlan_private structure
104 * @para event the event id
107 static void handle_mic_failureevent(wlan_private * priv, u32 event)
111 memset(buf, 0, sizeof(buf));
113 sprintf(buf, "%s", "MLME-MICHAELMICFAILURE.indication ");
115 if (event == MACREG_INT_CODE_MIC_ERR_UNICAST) {
116 strcat(buf, "unicast ");
118 strcat(buf, "multicast ");
121 libertas_send_iwevcustom_event(priv, buf);
124 static int wlan_ret_reg_access(wlan_private * priv,
125 u16 type, struct cmd_ds_command *resp)
127 wlan_adapter *adapter = priv->adapter;
132 case cmd_ret_mac_reg_access:
134 struct cmd_ds_mac_reg_access *reg;
137 (struct cmd_ds_mac_reg_access *)&resp->params.
140 adapter->offsetvalue.offset = reg->offset;
141 adapter->offsetvalue.value = reg->value;
145 case cmd_ret_bbp_reg_access:
147 struct cmd_ds_bbp_reg_access *reg;
149 (struct cmd_ds_bbp_reg_access *)&resp->params.
152 adapter->offsetvalue.offset = reg->offset;
153 adapter->offsetvalue.value = reg->value;
157 case cmd_ret_rf_reg_access:
159 struct cmd_ds_rf_reg_access *reg;
161 (struct cmd_ds_rf_reg_access *)&resp->params.
164 adapter->offsetvalue.offset = reg->offset;
165 adapter->offsetvalue.value = reg->value;
178 static int wlan_ret_get_hw_spec(wlan_private * priv,
179 struct cmd_ds_command *resp)
182 struct cmd_ds_get_hw_spec *hwspec = &resp->params.hwspec;
183 wlan_adapter *adapter = priv->adapter;
188 adapter->fwcapinfo = le32_to_cpu(hwspec->fwcapinfo);
190 adapter->fwreleasenumber = hwspec->fwreleasenumber;
192 lbs_pr_debug(1, "GET_HW_SPEC: FWReleaseVersion- 0x%X\n",
193 adapter->fwreleasenumber);
194 lbs_pr_debug(1, "GET_HW_SPEC: Permanent addr- %2x:%2x:%2x:%2x:%2x:%2x\n",
195 hwspec->permanentaddr[0], hwspec->permanentaddr[1],
196 hwspec->permanentaddr[2], hwspec->permanentaddr[3],
197 hwspec->permanentaddr[4], hwspec->permanentaddr[5]);
198 lbs_pr_debug(1, "GET_HW_SPEC: hwifversion=0x%X version=0x%X\n",
199 hwspec->hwifversion, hwspec->version);
201 adapter->regioncode = le16_to_cpu(hwspec->regioncode);
203 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
204 /* use the region code to search for the index */
205 if (adapter->regioncode == libertas_region_code_to_index[i]) {
206 adapter->regiontableindex = (u16) i;
211 /* if it's unidentified region code, use the default (USA) */
212 if (i >= MRVDRV_MAX_REGION_CODE) {
213 adapter->regioncode = 0x10;
214 adapter->regiontableindex = 0;
216 "unidentified region code, use the default (USA)\n");
219 if (adapter->current_addr[0] == 0xff) {
220 memmove(adapter->current_addr, hwspec->permanentaddr,
224 memcpy(priv->wlan_dev.netdev->dev_addr, adapter->current_addr, ETH_ALEN);
225 memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN);
227 if (libertas_set_regiontable(priv, adapter->regioncode, 0)) {
232 if (libertas_set_universaltable(priv, 0)) {
242 static int wlan_ret_802_11_sleep_params(wlan_private * priv,
243 struct cmd_ds_command *resp)
245 struct cmd_ds_802_11_sleep_params *sp = &resp->params.sleep_params;
246 wlan_adapter *adapter = priv->adapter;
250 lbs_pr_debug(1, "error=%x offset=%x stabletime=%x calcontrol=%x\n"
251 " extsleepclk=%x\n", sp->error, sp->offset,
252 sp->stabletime, sp->calcontrol, sp->externalsleepclk);
253 adapter->sp.sp_error = le16_to_cpu(sp->error);
254 adapter->sp.sp_offset = le16_to_cpu(sp->offset);
255 adapter->sp.sp_stabletime = le16_to_cpu(sp->stabletime);
256 adapter->sp.sp_calcontrol = le16_to_cpu(sp->calcontrol);
257 adapter->sp.sp_extsleepclk = le16_to_cpu(sp->externalsleepclk);
258 adapter->sp.sp_reserved = le16_to_cpu(sp->reserved);
264 static int wlan_ret_802_11_stat(wlan_private * priv,
265 struct cmd_ds_command *resp)
267 /* currently adapter->wlan802_11Stat is unused
269 struct cmd_ds_802_11_get_stat *p11Stat = &resp->params.gstat;
270 wlan_adapter *adapter = priv->adapter;
272 // TODO Convert it to Big endian befor copy
273 memcpy(&adapter->wlan802_11Stat,
274 p11Stat, sizeof(struct cmd_ds_802_11_get_stat));
279 static int wlan_ret_802_11_snmp_mib(wlan_private * priv,
280 struct cmd_ds_command *resp)
282 struct cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
283 u16 oid = le16_to_cpu(smib->oid);
284 u16 querytype = le16_to_cpu(smib->querytype);
288 lbs_pr_debug(1, "SNMP_RESP: value of the oid = %x, querytype=%x\n", oid,
290 lbs_pr_debug(1, "SNMP_RESP: Buf size = %x\n",
291 le16_to_cpu(smib->bufsize));
293 if (querytype == cmd_act_get) {
296 priv->adapter->fragthsd =
298 ((unsigned short *)(smib->value)));
299 lbs_pr_debug(1, "SNMP_RESP: fragthsd =%u\n",
300 priv->adapter->fragthsd);
303 priv->adapter->rtsthsd =
305 ((unsigned short *)(smib->value)));
306 lbs_pr_debug(1, "SNMP_RESP: rtsthsd =%u\n",
307 priv->adapter->rtsthsd);
309 case short_retrylim_i:
310 priv->adapter->txretrycount =
312 ((unsigned short *)(smib->value)));
313 lbs_pr_debug(1, "SNMP_RESP: txretrycount =%u\n",
314 priv->adapter->rtsthsd);
325 static int wlan_ret_802_11_key_material(wlan_private * priv,
326 struct cmd_ds_command *resp)
328 struct cmd_ds_802_11_key_material *pkeymaterial =
329 &resp->params.keymaterial;
330 wlan_adapter *adapter = priv->adapter;
331 u16 action = le16_to_cpu(pkeymaterial->action);
335 /* Copy the returned key to driver private data */
336 if (action == cmd_act_get) {
337 u8 * buf_ptr = (u8 *) &pkeymaterial->keyParamSet;
338 u8 * resp_end = (u8 *) (resp + le16_to_cpu(resp->size));
340 while (buf_ptr < resp_end) {
341 struct MrvlIEtype_keyParamSet * pkeyparamset =
342 (struct MrvlIEtype_keyParamSet *) buf_ptr;
343 struct WLAN_802_11_KEY * pkey;
344 u16 key_info = le16_to_cpu(pkeyparamset->keyinfo);
345 u16 param_set_len = le16_to_cpu(pkeyparamset->length);
347 u16 key_len = le16_to_cpu(pkeyparamset->keylen);
349 end = (u8 *) pkeyparamset + sizeof (pkeyparamset->type)
350 + sizeof (pkeyparamset->length)
352 /* Make sure we don't access past the end of the IEs */
356 if (key_info & KEY_INFO_WPA_UNICAST)
357 pkey = &adapter->wpa_unicast_key;
358 else if (key_info & KEY_INFO_WPA_MCAST)
359 pkey = &adapter->wpa_mcast_key;
363 /* Copy returned key into driver */
364 memset(pkey, 0, sizeof(struct WLAN_802_11_KEY));
365 if (key_len > sizeof(pkey->key))
367 pkey->type = le16_to_cpu(pkeyparamset->keytypeid);
368 pkey->flags = le16_to_cpu(pkeyparamset->keyinfo);
369 pkey->len = le16_to_cpu(pkeyparamset->keylen);
370 memcpy(pkey->key, pkeyparamset->key, pkey->len);
380 static int wlan_ret_802_11_mac_address(wlan_private * priv,
381 struct cmd_ds_command *resp)
383 struct cmd_ds_802_11_mac_address *macadd = &resp->params.macadd;
384 wlan_adapter *adapter = priv->adapter;
388 memcpy(adapter->current_addr, macadd->macadd, ETH_ALEN);
394 static int wlan_ret_802_11_rf_tx_power(wlan_private * priv,
395 struct cmd_ds_command *resp)
397 struct cmd_ds_802_11_rf_tx_power *rtp = &resp->params.txp;
398 wlan_adapter *adapter = priv->adapter;
402 adapter->txpowerlevel = le16_to_cpu(rtp->currentlevel);
404 lbs_pr_debug(1, "Current TxPower Level = %d\n", adapter->txpowerlevel);
410 static int wlan_ret_802_11_rf_antenna(wlan_private * priv,
411 struct cmd_ds_command *resp)
413 struct cmd_ds_802_11_rf_antenna *pAntenna = &resp->params.rant;
414 wlan_adapter *adapter = priv->adapter;
415 u16 action = le16_to_cpu(pAntenna->action);
417 if (action == cmd_act_get_rx)
418 adapter->rxantennamode =
419 le16_to_cpu(pAntenna->antennamode);
421 if (action == cmd_act_get_tx)
422 adapter->txantennamode =
423 le16_to_cpu(pAntenna->antennamode);
425 lbs_pr_debug(1, "RF_ANT_RESP: action = 0x%x, mode = 0x%04x\n",
426 action, le16_to_cpu(pAntenna->antennamode));
431 static int wlan_ret_802_11_rate_adapt_rateset(wlan_private * priv,
432 struct cmd_ds_command *resp)
434 struct cmd_ds_802_11_rate_adapt_rateset *rates =
435 &resp->params.rateset;
436 wlan_adapter *adapter = priv->adapter;
440 if (rates->action == cmd_act_get) {
441 adapter->enablehwauto = rates->enablehwauto;
442 adapter->ratebitmap = rates->bitmap;
450 static int wlan_ret_802_11_data_rate(wlan_private * priv,
451 struct cmd_ds_command *resp)
453 struct cmd_ds_802_11_data_rate *pdatarate = &resp->params.drate;
454 wlan_adapter *adapter = priv->adapter;
459 lbs_dbg_hex("DATA_RATE_RESP: data_rate- ",
460 (u8 *) pdatarate, sizeof(struct cmd_ds_802_11_data_rate));
462 dot11datarate = pdatarate->datarate[0];
463 if (pdatarate->action == cmd_act_get_tx_rate) {
464 memcpy(adapter->libertas_supported_rates, pdatarate->datarate,
465 sizeof(adapter->libertas_supported_rates));
467 adapter->datarate = libertas_index_to_data_rate(dot11datarate);
473 static int wlan_ret_802_11_rf_channel(wlan_private * priv,
474 struct cmd_ds_command *resp)
476 struct cmd_ds_802_11_rf_channel *rfchannel =
477 &resp->params.rfchannel;
478 wlan_adapter *adapter = priv->adapter;
479 u16 action = le16_to_cpu(rfchannel->action);
480 u16 newchannel = le16_to_cpu(rfchannel->currentchannel);
484 if (action == cmd_opt_802_11_rf_channel_get
485 && adapter->curbssparams.channel != newchannel) {
486 lbs_pr_debug(1, "channel Switch: %d to %d\n",
487 adapter->curbssparams.channel, newchannel);
489 /* Update the channel again */
490 adapter->curbssparams.channel = newchannel;
497 static int wlan_ret_802_11_rssi(wlan_private * priv,
498 struct cmd_ds_command *resp)
500 struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp;
501 wlan_adapter *adapter = priv->adapter;
503 /* store the non average value */
504 adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR);
505 adapter->NF[TYPE_BEACON][TYPE_NOAVG] =
506 le16_to_cpu(rssirsp->noisefloor);
508 adapter->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR);
509 adapter->NF[TYPE_BEACON][TYPE_AVG] =
510 le16_to_cpu(rssirsp->avgnoisefloor);
512 adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] =
513 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
514 adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
516 adapter->RSSI[TYPE_BEACON][TYPE_AVG] =
517 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE,
518 adapter->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE);
520 lbs_pr_debug(1, "Beacon RSSI value = 0x%x\n",
521 adapter->RSSI[TYPE_BEACON][TYPE_AVG]);
526 static int wlan_ret_802_11_eeprom_access(wlan_private * priv,
527 struct cmd_ds_command *resp)
529 wlan_adapter *adapter = priv->adapter;
530 struct wlan_ioctl_regrdwr *pbuf;
531 pbuf = (struct wlan_ioctl_regrdwr *) adapter->prdeeprom;
533 lbs_pr_debug(1, "eeprom read len=%x\n",
534 le16_to_cpu(resp->params.rdeeprom.bytecount));
535 if (pbuf->NOB < le16_to_cpu(resp->params.rdeeprom.bytecount)) {
537 lbs_pr_debug(1, "eeprom read return length is too big\n");
540 pbuf->NOB = le16_to_cpu(resp->params.rdeeprom.bytecount);
543 memcpy(&pbuf->value, (u8 *) & resp->params.rdeeprom.value,
544 le16_to_cpu(resp->params.rdeeprom.bytecount));
545 lbs_dbg_hex("adapter", (char *)&pbuf->value,
546 le16_to_cpu(resp->params.rdeeprom.bytecount));
551 static int wlan_ret_get_log(wlan_private * priv,
552 struct cmd_ds_command *resp)
554 struct cmd_ds_802_11_get_log *logmessage =
555 (struct cmd_ds_802_11_get_log *)&resp->params.glog;
556 wlan_adapter *adapter = priv->adapter;
560 /* TODO Convert it to Big Endian before copy */
561 memcpy(&adapter->logmsg, logmessage,
562 sizeof(struct cmd_ds_802_11_get_log));
568 static inline int handle_cmd_response(u16 respcmd,
569 struct cmd_ds_command *resp,
574 wlan_adapter *adapter = priv->adapter;
577 case cmd_ret_mac_reg_access:
578 case cmd_ret_bbp_reg_access:
579 case cmd_ret_rf_reg_access:
580 ret = wlan_ret_reg_access(priv, respcmd, resp);
583 case cmd_ret_hw_spec_info:
584 ret = wlan_ret_get_hw_spec(priv, resp);
587 case cmd_ret_802_11_scan:
588 ret = libertas_ret_80211_scan(priv, resp);
591 case cmd_ret_802_11_get_log:
592 ret = wlan_ret_get_log(priv, resp);
595 case cmd_ret_802_11_associate:
596 case cmd_ret_802_11_reassociate:
597 ret = libertas_ret_80211_associate(priv, resp);
600 case cmd_ret_802_11_disassociate:
601 case cmd_ret_802_11_deauthenticate:
602 ret = libertas_ret_80211_disassociate(priv, resp);
605 case cmd_ret_802_11_ad_hoc_start:
606 case cmd_ret_802_11_ad_hoc_join:
607 ret = libertas_ret_80211_ad_hoc_start(priv, resp);
610 case cmd_ret_802_11_stat:
611 ret = wlan_ret_802_11_stat(priv, resp);
614 case cmd_ret_802_11_snmp_mib:
615 ret = wlan_ret_802_11_snmp_mib(priv, resp);
618 case cmd_ret_802_11_rf_tx_power:
619 ret = wlan_ret_802_11_rf_tx_power(priv, resp);
622 case cmd_ret_802_11_set_afc:
623 case cmd_ret_802_11_get_afc:
624 spin_lock_irqsave(&adapter->driver_lock, flags);
625 memmove(adapter->cur_cmd->pdata_buf,
627 sizeof(struct cmd_ds_802_11_afc));
628 spin_unlock_irqrestore(&adapter->driver_lock, flags);
631 case cmd_ret_802_11_rf_antenna:
632 ret = wlan_ret_802_11_rf_antenna(priv, resp);
635 case cmd_ret_mac_multicast_adr:
636 case cmd_ret_mac_control:
637 case cmd_ret_802_11_set_wep:
638 case cmd_ret_802_11_reset:
639 case cmd_ret_802_11_authenticate:
640 case cmd_ret_802_11_radio_control:
641 case cmd_ret_802_11_beacon_stop:
642 case cmd_ret_802_11_enable_rsn:
645 case cmd_ret_802_11_data_rate:
646 ret = wlan_ret_802_11_data_rate(priv, resp);
648 case cmd_ret_802_11_rate_adapt_rateset:
649 ret = wlan_ret_802_11_rate_adapt_rateset(priv, resp);
651 case cmd_ret_802_11_rf_channel:
652 ret = wlan_ret_802_11_rf_channel(priv, resp);
655 case cmd_ret_802_11_rssi:
656 ret = wlan_ret_802_11_rssi(priv, resp);
659 case cmd_ret_802_11_mac_address:
660 ret = wlan_ret_802_11_mac_address(priv, resp);
663 case cmd_ret_802_11_ad_hoc_stop:
664 ret = libertas_ret_80211_ad_hoc_stop(priv, resp);
667 case cmd_ret_802_11_key_material:
668 lbs_pr_debug(1, "CMD_RESP: KEY_MATERIAL command response\n");
669 ret = wlan_ret_802_11_key_material(priv, resp);
672 case cmd_ret_802_11_eeprom_access:
673 ret = wlan_ret_802_11_eeprom_access(priv, resp);
676 case cmd_ret_802_11d_domain_info:
677 ret = libertas_ret_802_11d_domain_info(priv, resp);
680 case cmd_ret_802_11_sleep_params:
681 ret = wlan_ret_802_11_sleep_params(priv, resp);
683 case cmd_ret_802_11_inactivity_timeout:
684 spin_lock_irqsave(&adapter->driver_lock, flags);
685 *((u16 *) adapter->cur_cmd->pdata_buf) =
686 le16_to_cpu(resp->params.inactivity_timeout.timeout);
687 spin_unlock_irqrestore(&adapter->driver_lock, flags);
690 case cmd_ret_802_11_tpc_cfg:
691 spin_lock_irqsave(&adapter->driver_lock, flags);
692 memmove(adapter->cur_cmd->pdata_buf,
693 &resp->params.tpccfg,
694 sizeof(struct cmd_ds_802_11_tpc_cfg));
695 spin_unlock_irqrestore(&adapter->driver_lock, flags);
697 case cmd_ret_802_11_led_gpio_ctrl:
698 spin_lock_irqsave(&adapter->driver_lock, flags);
699 memmove(adapter->cur_cmd->pdata_buf,
700 &resp->params.ledgpio,
701 sizeof(struct cmd_ds_802_11_led_ctrl));
702 spin_unlock_irqrestore(&adapter->driver_lock, flags);
704 case cmd_ret_802_11_pwr_cfg:
705 spin_lock_irqsave(&adapter->driver_lock, flags);
706 memmove(adapter->cur_cmd->pdata_buf,
707 &resp->params.pwrcfg,
708 sizeof(struct cmd_ds_802_11_pwr_cfg));
709 spin_unlock_irqrestore(&adapter->driver_lock, flags);
713 case cmd_ret_get_tsf:
714 spin_lock_irqsave(&adapter->driver_lock, flags);
715 memcpy(priv->adapter->cur_cmd->pdata_buf,
716 &resp->params.gettsf.tsfvalue, sizeof(u64));
717 spin_unlock_irqrestore(&adapter->driver_lock, flags);
719 case cmd_ret_bt_access:
720 spin_lock_irqsave(&adapter->driver_lock, flags);
721 if (adapter->cur_cmd->pdata_buf)
722 memcpy(adapter->cur_cmd->pdata_buf,
723 &resp->params.bt.addr1, 2 * ETH_ALEN);
724 spin_unlock_irqrestore(&adapter->driver_lock, flags);
726 case cmd_ret_fwt_access:
727 spin_lock_irqsave(&adapter->driver_lock, flags);
728 if (adapter->cur_cmd->pdata_buf)
729 memcpy(adapter->cur_cmd->pdata_buf,
731 sizeof(resp->params.fwt));
732 spin_unlock_irqrestore(&adapter->driver_lock, flags);
734 case cmd_ret_mesh_access:
735 if (adapter->cur_cmd->pdata_buf)
736 memcpy(adapter->cur_cmd->pdata_buf,
738 sizeof(resp->params.mesh));
740 case cmd_rte_802_11_tx_rate_query:
741 priv->adapter->txrate = resp->params.txrate.txrate;
744 lbs_pr_debug(1, "CMD_RESP: Unknown command response %#x\n",
751 int libertas_process_rx_command(wlan_private * priv)
754 struct cmd_ds_command *resp;
755 wlan_adapter *adapter = priv->adapter;
762 lbs_pr_debug(1, "CMD_RESP: @ %lu\n", jiffies);
764 /* Now we got response from FW, cancel the command timer */
765 del_timer(&adapter->command_timer);
767 mutex_lock(&adapter->lock);
768 spin_lock_irqsave(&adapter->driver_lock, flags);
770 if (!adapter->cur_cmd) {
771 lbs_pr_debug(1, "CMD_RESP: NULL cur_cmd=%p\n", adapter->cur_cmd);
773 spin_unlock_irqrestore(&adapter->driver_lock, flags);
776 resp = (struct cmd_ds_command *)(adapter->cur_cmd->bufvirtualaddr);
778 lbs_dbg_hex("CMD_RESP:", adapter->cur_cmd->bufvirtualaddr,
779 priv->wlan_dev.upld_len);
781 respcmd = le16_to_cpu(resp->command);
783 result = le16_to_cpu(resp->result);
785 lbs_pr_debug(1, "CMD_RESP: %x result: %d length: %d\n", respcmd,
786 result, priv->wlan_dev.upld_len);
788 if (!(respcmd & 0x8000)) {
789 lbs_pr_debug(1, "Invalid response to command!");
790 adapter->cur_cmd_retcode = -1;
791 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
792 adapter->nr_cmd_pending--;
793 adapter->cur_cmd = NULL;
794 spin_unlock_irqrestore(&adapter->driver_lock, flags);
799 /* Store the response code to cur_cmd_retcode. */
800 adapter->cur_cmd_retcode = le16_to_cpu(resp->result);
802 if (respcmd == cmd_ret_802_11_ps_mode) {
803 struct cmd_ds_802_11_ps_mode *psmode;
805 psmode = &resp->params.psmode;
807 "CMD_RESP: PS_MODE cmd reply result=%#x action=0x%X\n",
808 resp->result, psmode->action);
809 psmode->action = cpu_to_le16(psmode->action);
812 lbs_pr_debug(1, "CMD_RESP: PS command failed- %#x \n",
814 if (adapter->inframode == wlan802_11ibss) {
816 * We should not re-try enter-ps command in
817 * ad-hoc mode. It takes place in
818 * libertas_execute_next_command().
820 if (psmode->action == cmd_subcmd_enter_ps)
822 wlan802_11powermodecam;
824 } else if (psmode->action == cmd_subcmd_enter_ps) {
825 adapter->needtowakeup = 0;
826 adapter->psstate = PS_STATE_AWAKE;
828 lbs_pr_debug(1, "CMD_RESP: Enter_PS command response\n");
829 if (adapter->connect_status != libertas_connected) {
831 * When Deauth Event received before Enter_PS command
832 * response, We need to wake up the firmware.
835 "Disconnected, Going to invoke libertas_ps_wakeup\n");
837 mutex_unlock(&adapter->lock);
838 spin_unlock_irqrestore(&adapter->driver_lock, flags);
839 libertas_ps_wakeup(priv, 0);
840 mutex_lock(&adapter->lock);
841 spin_lock_irqsave(&adapter->driver_lock, flags);
843 } else if (psmode->action == cmd_subcmd_exit_ps) {
844 adapter->needtowakeup = 0;
845 adapter->psstate = PS_STATE_FULL_POWER;
846 lbs_pr_debug(1, "CMD_RESP: Exit_PS command response\n");
848 lbs_pr_debug(1, "CMD_RESP: PS- action=0x%X\n",
852 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
853 adapter->nr_cmd_pending--;
854 adapter->cur_cmd = NULL;
855 spin_unlock_irqrestore(&adapter->driver_lock, flags);
861 if (adapter->cur_cmd->cmdflags & CMD_F_HOSTCMD) {
862 /* Copy the response back to response buffer */
863 memcpy(adapter->cur_cmd->pdata_buf, resp, resp->size);
865 adapter->cur_cmd->cmdflags &= ~CMD_F_HOSTCMD;
868 /* If the command is not successful, cleanup and return failure */
869 if ((result != 0 || !(respcmd & 0x8000))) {
870 lbs_pr_debug(1, "CMD_RESP: command reply %#x result=%#x\n",
871 resp->command, resp->result);
873 * Handling errors here
876 case cmd_ret_hw_spec_info:
877 case cmd_ret_802_11_reset:
878 lbs_pr_debug(1, "CMD_RESP: Reset command failed\n");
883 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
884 adapter->nr_cmd_pending--;
885 adapter->cur_cmd = NULL;
886 spin_unlock_irqrestore(&adapter->driver_lock, flags);
892 spin_unlock_irqrestore(&adapter->driver_lock, flags);
894 ret = handle_cmd_response(respcmd, resp, priv);
896 spin_lock_irqsave(&adapter->driver_lock, flags);
897 if (adapter->cur_cmd) {
898 /* Clean up and Put current command back to cmdfreeq */
899 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
900 adapter->nr_cmd_pending--;
901 WARN_ON(adapter->nr_cmd_pending > 128);
902 adapter->cur_cmd = NULL;
904 spin_unlock_irqrestore(&adapter->driver_lock, flags);
907 mutex_unlock(&adapter->lock);
912 int libertas_process_event(wlan_private * priv)
915 wlan_adapter *adapter = priv->adapter;
918 spin_lock_irq(&adapter->driver_lock);
919 eventcause = adapter->eventcause;
920 spin_unlock_irq(&adapter->driver_lock);
924 lbs_pr_debug(1, "EVENT Cause %x\n", eventcause);
926 switch (eventcause >> SBI_EVENT_CAUSE_SHIFT) {
927 case MACREG_INT_CODE_LINK_SENSED:
928 lbs_pr_debug(1, "EVENT: MACREG_INT_CODE_LINK_SENSED\n");
931 case MACREG_INT_CODE_DEAUTHENTICATED:
932 lbs_pr_debug(1, "EVENT: Deauthenticated\n");
933 libertas_mac_event_disconnected(priv);
936 case MACREG_INT_CODE_DISASSOCIATED:
937 lbs_pr_debug(1, "EVENT: Disassociated\n");
938 libertas_mac_event_disconnected(priv);
941 case MACREG_INT_CODE_LINK_LOSE_NO_SCAN:
942 lbs_pr_debug(1, "EVENT: Link lost\n");
943 libertas_mac_event_disconnected(priv);
946 case MACREG_INT_CODE_PS_SLEEP:
947 lbs_pr_debug(1, "EVENT: SLEEP\n");
948 lbs_pr_debug(1, "_");
950 /* handle unexpected PS SLEEP event */
951 if (adapter->psstate == PS_STATE_FULL_POWER) {
953 "EVENT: In FULL POWER mode - ignore PS SLEEP\n");
956 adapter->psstate = PS_STATE_PRE_SLEEP;
958 libertas_ps_confirm_sleep(priv, (u16) adapter->psmode);
962 case MACREG_INT_CODE_PS_AWAKE:
963 lbs_pr_debug(1, "EVENT: AWAKE \n");
964 lbs_pr_debug(1, "|");
966 /* handle unexpected PS AWAKE event */
967 if (adapter->psstate == PS_STATE_FULL_POWER) {
969 "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
973 adapter->psstate = PS_STATE_AWAKE;
975 if (adapter->needtowakeup) {
977 * wait for the command processing to finish
978 * before resuming sending
979 * adapter->needtowakeup will be set to FALSE
980 * in libertas_ps_wakeup()
982 lbs_pr_debug(1, "Waking up...\n");
983 libertas_ps_wakeup(priv, 0);
987 case MACREG_INT_CODE_MIC_ERR_UNICAST:
988 lbs_pr_debug(1, "EVENT: UNICAST MIC ERROR\n");
989 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST);
992 case MACREG_INT_CODE_MIC_ERR_MULTICAST:
993 lbs_pr_debug(1, "EVENT: MULTICAST MIC ERROR\n");
994 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST);
996 case MACREG_INT_CODE_MIB_CHANGED:
997 case MACREG_INT_CODE_INIT_DONE:
1000 case MACREG_INT_CODE_ADHOC_BCN_LOST:
1001 lbs_pr_debug(1, "EVENT: HWAC - ADHOC BCN LOST\n");
1004 case MACREG_INT_CODE_RSSI_LOW:
1005 lbs_pr_alert( "EVENT: RSSI_LOW\n");
1007 case MACREG_INT_CODE_SNR_LOW:
1008 lbs_pr_alert( "EVENT: SNR_LOW\n");
1010 case MACREG_INT_CODE_MAX_FAIL:
1011 lbs_pr_alert( "EVENT: MAX_FAIL\n");
1013 case MACREG_INT_CODE_RSSI_HIGH:
1014 lbs_pr_alert( "EVENT: RSSI_HIGH\n");
1016 case MACREG_INT_CODE_SNR_HIGH:
1017 lbs_pr_alert( "EVENT: SNR_HIGH\n");
1021 lbs_pr_alert( "EVENT: unknown event id: %#x\n",
1022 eventcause >> SBI_EVENT_CAUSE_SHIFT);
1026 spin_lock_irq(&adapter->driver_lock);
1027 adapter->eventcause = 0;
1028 spin_unlock_irq(&adapter->driver_lock);