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>
19 * @brief This function handles disconnect event. it
20 * reports disconnect to upper layer, clean tx/rx packets,
21 * reset link state etc.
23 * @param priv A pointer to wlan_private structure
26 void libertas_mac_event_disconnected(wlan_private * priv)
28 wlan_adapter *adapter = priv->adapter;
29 union iwreq_data wrqu;
31 if (adapter->connect_status != libertas_connected)
34 lbs_deb_cmd("Handles disconnect event.\n");
36 memset(wrqu.ap_addr.sa_data, 0x00, ETH_ALEN);
37 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
40 * Cisco AP sends EAP failure and de-auth in less than 0.5 ms.
41 * It causes problem in the Supplicant
44 msleep_interruptible(1000);
45 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
47 /* Free Tx and Rx packets */
48 kfree_skb(priv->adapter->currenttxskb);
49 priv->adapter->currenttxskb = NULL;
51 /* report disconnect to upper layer */
52 netif_stop_queue(priv->dev);
53 netif_carrier_off(priv->dev);
55 /* reset SNR/NF/RSSI values */
56 memset(adapter->SNR, 0x00, sizeof(adapter->SNR));
57 memset(adapter->NF, 0x00, sizeof(adapter->NF));
58 memset(adapter->RSSI, 0x00, sizeof(adapter->RSSI));
59 memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR));
60 memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF));
61 adapter->nextSNRNF = 0;
62 adapter->numSNRNF = 0;
63 adapter->rxpd_rate = 0;
64 lbs_deb_cmd("Current SSID='%s', ssid length=%u\n",
65 escape_essid(adapter->curbssparams.ssid,
66 adapter->curbssparams.ssid_len),
67 adapter->curbssparams.ssid_len);
68 lbs_deb_cmd("Previous SSID='%s', ssid length=%u\n",
69 escape_essid(adapter->prev_ssid, adapter->prev_ssid_len),
70 adapter->prev_ssid_len);
72 adapter->connect_status = libertas_disconnected;
74 /* Save previous SSID and BSSID for possible reassociation */
75 memcpy(&adapter->prev_ssid, &adapter->curbssparams.ssid,
77 adapter->prev_ssid_len = adapter->curbssparams.ssid_len;
78 memcpy(adapter->prev_bssid, adapter->curbssparams.bssid, ETH_ALEN);
80 /* Clear out associated SSID and BSSID since connection is
83 memset(&adapter->curbssparams.bssid, 0, ETH_ALEN);
84 memset(&adapter->curbssparams.ssid, 0, IW_ESSID_MAX_SIZE);
85 adapter->curbssparams.ssid_len = 0;
87 if (adapter->psstate != PS_STATE_FULL_POWER) {
88 /* make firmware to exit PS mode */
89 lbs_deb_cmd("Disconnected, so exit PS mode.\n");
90 libertas_ps_wakeup(priv, 0);
95 * @brief This function handles MIC failure event.
97 * @param priv A pointer to wlan_private structure
98 * @para event the event id
101 static void handle_mic_failureevent(wlan_private * priv, u32 event)
105 memset(buf, 0, sizeof(buf));
107 sprintf(buf, "%s", "MLME-MICHAELMICFAILURE.indication ");
109 if (event == MACREG_INT_CODE_MIC_ERR_UNICAST) {
110 strcat(buf, "unicast ");
112 strcat(buf, "multicast ");
115 libertas_send_iwevcustom_event(priv, buf);
118 static int wlan_ret_reg_access(wlan_private * priv,
119 u16 type, struct cmd_ds_command *resp)
122 wlan_adapter *adapter = priv->adapter;
124 lbs_deb_enter(LBS_DEB_CMD);
127 case cmd_ret_mac_reg_access:
129 struct cmd_ds_mac_reg_access *reg = &resp->params.macreg;
131 adapter->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
132 adapter->offsetvalue.value = le32_to_cpu(reg->value);
136 case cmd_ret_bbp_reg_access:
138 struct cmd_ds_bbp_reg_access *reg = &resp->params.bbpreg;
140 adapter->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
141 adapter->offsetvalue.value = reg->value;
145 case cmd_ret_rf_reg_access:
147 struct cmd_ds_rf_reg_access *reg = &resp->params.rfreg;
149 adapter->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
150 adapter->offsetvalue.value = reg->value;
158 lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret);
162 static int wlan_ret_get_hw_spec(wlan_private * priv,
163 struct cmd_ds_command *resp)
166 struct cmd_ds_get_hw_spec *hwspec = &resp->params.hwspec;
167 wlan_adapter *adapter = priv->adapter;
170 lbs_deb_enter(LBS_DEB_CMD);
172 adapter->fwcapinfo = le32_to_cpu(hwspec->fwcapinfo);
174 memcpy(adapter->fwreleasenumber, hwspec->fwreleasenumber, 4);
176 lbs_deb_cmd("GET_HW_SPEC: FWReleaseVersion- %u.%u.%u.p%u\n",
177 adapter->fwreleasenumber[2], adapter->fwreleasenumber[1],
178 adapter->fwreleasenumber[0], adapter->fwreleasenumber[3]);
179 lbs_deb_cmd("GET_HW_SPEC: Permanent addr- %2x:%2x:%2x:%2x:%2x:%2x\n",
180 hwspec->permanentaddr[0], hwspec->permanentaddr[1],
181 hwspec->permanentaddr[2], hwspec->permanentaddr[3],
182 hwspec->permanentaddr[4], hwspec->permanentaddr[5]);
183 lbs_deb_cmd("GET_HW_SPEC: hwifversion=0x%X version=0x%X\n",
184 hwspec->hwifversion, hwspec->version);
186 adapter->regioncode = le16_to_cpu(hwspec->regioncode);
188 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
189 /* use the region code to search for the index */
190 if (adapter->regioncode == libertas_region_code_to_index[i]) {
191 adapter->regiontableindex = (u16) i;
196 /* if it's unidentified region code, use the default (USA) */
197 if (i >= MRVDRV_MAX_REGION_CODE) {
198 adapter->regioncode = 0x10;
199 adapter->regiontableindex = 0;
200 lbs_pr_info("unidentified region code; using the default (USA)\n");
203 if (adapter->current_addr[0] == 0xff)
204 memmove(adapter->current_addr, hwspec->permanentaddr, ETH_ALEN);
206 memcpy(priv->dev->dev_addr, adapter->current_addr, ETH_ALEN);
208 memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN);
210 if (libertas_set_regiontable(priv, adapter->regioncode, 0)) {
215 if (libertas_set_universaltable(priv, 0)) {
221 lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret);
225 static int wlan_ret_802_11_sleep_params(wlan_private * priv,
226 struct cmd_ds_command *resp)
228 struct cmd_ds_802_11_sleep_params *sp = &resp->params.sleep_params;
229 wlan_adapter *adapter = priv->adapter;
231 lbs_deb_enter(LBS_DEB_CMD);
233 lbs_deb_cmd("error=%x offset=%x stabletime=%x calcontrol=%x\n"
234 " extsleepclk=%x\n", le16_to_cpu(sp->error),
235 le16_to_cpu(sp->offset), le16_to_cpu(sp->stabletime),
236 sp->calcontrol, sp->externalsleepclk);
238 adapter->sp.sp_error = le16_to_cpu(sp->error);
239 adapter->sp.sp_offset = le16_to_cpu(sp->offset);
240 adapter->sp.sp_stabletime = le16_to_cpu(sp->stabletime);
241 adapter->sp.sp_calcontrol = sp->calcontrol;
242 adapter->sp.sp_extsleepclk = sp->externalsleepclk;
243 adapter->sp.sp_reserved = le16_to_cpu(sp->reserved);
245 lbs_deb_enter(LBS_DEB_CMD);
249 static int wlan_ret_802_11_stat(wlan_private * priv,
250 struct cmd_ds_command *resp)
252 /* currently adapter->wlan802_11Stat is unused
254 struct cmd_ds_802_11_get_stat *p11Stat = &resp->params.gstat;
255 wlan_adapter *adapter = priv->adapter;
257 // TODO Convert it to Big endian befor copy
258 memcpy(&adapter->wlan802_11Stat,
259 p11Stat, sizeof(struct cmd_ds_802_11_get_stat));
264 static int wlan_ret_802_11_snmp_mib(wlan_private * priv,
265 struct cmd_ds_command *resp)
267 struct cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
268 u16 oid = le16_to_cpu(smib->oid);
269 u16 querytype = le16_to_cpu(smib->querytype);
271 lbs_deb_enter(LBS_DEB_CMD);
273 lbs_deb_cmd("SNMP_RESP: value of the oid = %x, querytype=%x\n", oid,
275 lbs_deb_cmd("SNMP_RESP: Buf size = %x\n", le16_to_cpu(smib->bufsize));
277 if (querytype == cmd_act_get) {
280 priv->adapter->fragthsd =
281 le16_to_cpu(*((__le16 *)(smib->value)));
282 lbs_deb_cmd("SNMP_RESP: fragthsd =%u\n",
283 priv->adapter->fragthsd);
286 priv->adapter->rtsthsd =
287 le16_to_cpu(*((__le16 *)(smib->value)));
288 lbs_deb_cmd("SNMP_RESP: rtsthsd =%u\n",
289 priv->adapter->rtsthsd);
291 case short_retrylim_i:
292 priv->adapter->txretrycount =
293 le16_to_cpu(*((__le16 *)(smib->value)));
294 lbs_deb_cmd("SNMP_RESP: txretrycount =%u\n",
295 priv->adapter->rtsthsd);
302 lbs_deb_enter(LBS_DEB_CMD);
306 static int wlan_ret_802_11_key_material(wlan_private * priv,
307 struct cmd_ds_command *resp)
309 struct cmd_ds_802_11_key_material *pkeymaterial =
310 &resp->params.keymaterial;
311 wlan_adapter *adapter = priv->adapter;
312 u16 action = le16_to_cpu(pkeymaterial->action);
314 lbs_deb_enter(LBS_DEB_CMD);
316 /* Copy the returned key to driver private data */
317 if (action == cmd_act_get) {
318 u8 * buf_ptr = (u8 *) &pkeymaterial->keyParamSet;
319 u8 * resp_end = (u8 *) (resp + le16_to_cpu(resp->size));
321 while (buf_ptr < resp_end) {
322 struct MrvlIEtype_keyParamSet * pkeyparamset =
323 (struct MrvlIEtype_keyParamSet *) buf_ptr;
324 struct WLAN_802_11_KEY * pkey;
325 u16 key_info = le16_to_cpu(pkeyparamset->keyinfo);
326 u16 param_set_len = le16_to_cpu(pkeyparamset->length);
328 u16 key_len = le16_to_cpu(pkeyparamset->keylen);
330 end = (u8 *) pkeyparamset + sizeof (pkeyparamset->type)
331 + sizeof (pkeyparamset->length)
333 /* Make sure we don't access past the end of the IEs */
337 if (key_info & KEY_INFO_WPA_UNICAST)
338 pkey = &adapter->wpa_unicast_key;
339 else if (key_info & KEY_INFO_WPA_MCAST)
340 pkey = &adapter->wpa_mcast_key;
344 /* Copy returned key into driver */
345 memset(pkey, 0, sizeof(struct WLAN_802_11_KEY));
346 if (key_len > sizeof(pkey->key))
348 pkey->type = le16_to_cpu(pkeyparamset->keytypeid);
349 pkey->flags = le16_to_cpu(pkeyparamset->keyinfo);
350 pkey->len = le16_to_cpu(pkeyparamset->keylen);
351 memcpy(pkey->key, pkeyparamset->key, pkey->len);
357 lbs_deb_enter(LBS_DEB_CMD);
361 static int wlan_ret_802_11_mac_address(wlan_private * priv,
362 struct cmd_ds_command *resp)
364 struct cmd_ds_802_11_mac_address *macadd = &resp->params.macadd;
365 wlan_adapter *adapter = priv->adapter;
367 lbs_deb_enter(LBS_DEB_CMD);
369 memcpy(adapter->current_addr, macadd->macadd, ETH_ALEN);
371 lbs_deb_enter(LBS_DEB_CMD);
375 static int wlan_ret_802_11_rf_tx_power(wlan_private * priv,
376 struct cmd_ds_command *resp)
378 struct cmd_ds_802_11_rf_tx_power *rtp = &resp->params.txp;
379 wlan_adapter *adapter = priv->adapter;
381 lbs_deb_enter(LBS_DEB_CMD);
383 adapter->txpowerlevel = le16_to_cpu(rtp->currentlevel);
385 lbs_deb_cmd("Current TxPower Level = %d\n", adapter->txpowerlevel);
387 lbs_deb_enter(LBS_DEB_CMD);
391 static int wlan_ret_802_11_rf_antenna(wlan_private * priv,
392 struct cmd_ds_command *resp)
394 struct cmd_ds_802_11_rf_antenna *pAntenna = &resp->params.rant;
395 wlan_adapter *adapter = priv->adapter;
396 u16 action = le16_to_cpu(pAntenna->action);
398 if (action == cmd_act_get_rx)
399 adapter->rxantennamode = le16_to_cpu(pAntenna->antennamode);
401 if (action == cmd_act_get_tx)
402 adapter->txantennamode = le16_to_cpu(pAntenna->antennamode);
404 lbs_deb_cmd("RF_ANT_RESP: action = 0x%x, mode = 0x%04x\n",
405 action, le16_to_cpu(pAntenna->antennamode));
410 static int wlan_ret_802_11_rate_adapt_rateset(wlan_private * priv,
411 struct cmd_ds_command *resp)
413 struct cmd_ds_802_11_rate_adapt_rateset *rates = &resp->params.rateset;
414 wlan_adapter *adapter = priv->adapter;
416 lbs_deb_enter(LBS_DEB_CMD);
418 if (rates->action == cmd_act_get) {
419 adapter->enablehwauto = le16_to_cpu(rates->enablehwauto);
420 adapter->ratebitmap = le16_to_cpu(rates->bitmap);
423 lbs_deb_enter(LBS_DEB_CMD);
427 static int wlan_ret_802_11_data_rate(wlan_private * priv,
428 struct cmd_ds_command *resp)
430 struct cmd_ds_802_11_data_rate *pdatarate = &resp->params.drate;
431 wlan_adapter *adapter = priv->adapter;
434 lbs_deb_enter(LBS_DEB_CMD);
436 lbs_dbg_hex("DATA_RATE_RESP: data_rate- ",
437 (u8 *) pdatarate, sizeof(struct cmd_ds_802_11_data_rate));
439 dot11datarate = pdatarate->datarate[0];
440 if (pdatarate->action == cpu_to_le16(cmd_act_get_tx_rate)) {
441 memcpy(adapter->libertas_supported_rates, pdatarate->datarate,
442 sizeof(adapter->libertas_supported_rates));
444 adapter->datarate = libertas_index_to_data_rate(dot11datarate);
446 lbs_deb_enter(LBS_DEB_CMD);
450 static int wlan_ret_802_11_rf_channel(wlan_private * priv,
451 struct cmd_ds_command *resp)
453 struct cmd_ds_802_11_rf_channel *rfchannel = &resp->params.rfchannel;
454 wlan_adapter *adapter = priv->adapter;
455 u16 action = le16_to_cpu(rfchannel->action);
456 u16 newchannel = le16_to_cpu(rfchannel->currentchannel);
458 lbs_deb_enter(LBS_DEB_CMD);
460 if (action == cmd_opt_802_11_rf_channel_get
461 && adapter->curbssparams.channel != newchannel) {
462 lbs_deb_cmd("channel Switch: %d to %d\n",
463 adapter->curbssparams.channel, newchannel);
465 /* Update the channel again */
466 adapter->curbssparams.channel = newchannel;
469 lbs_deb_enter(LBS_DEB_CMD);
473 static int wlan_ret_802_11_rssi(wlan_private * priv,
474 struct cmd_ds_command *resp)
476 struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp;
477 wlan_adapter *adapter = priv->adapter;
479 /* store the non average value */
480 adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR);
481 adapter->NF[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->noisefloor);
483 adapter->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR);
484 adapter->NF[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgnoisefloor);
486 adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] =
487 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
488 adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
490 adapter->RSSI[TYPE_BEACON][TYPE_AVG] =
491 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE,
492 adapter->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE);
494 lbs_deb_cmd("Beacon RSSI value = 0x%x\n",
495 adapter->RSSI[TYPE_BEACON][TYPE_AVG]);
500 static int wlan_ret_802_11_eeprom_access(wlan_private * priv,
501 struct cmd_ds_command *resp)
503 wlan_adapter *adapter = priv->adapter;
504 struct wlan_ioctl_regrdwr *pbuf;
505 pbuf = (struct wlan_ioctl_regrdwr *) adapter->prdeeprom;
507 lbs_deb_cmd("eeprom read len=%x\n",
508 le16_to_cpu(resp->params.rdeeprom.bytecount));
509 if (pbuf->NOB < le16_to_cpu(resp->params.rdeeprom.bytecount)) {
511 lbs_deb_cmd("eeprom read return length is too big\n");
514 pbuf->NOB = le16_to_cpu(resp->params.rdeeprom.bytecount);
517 memcpy(&pbuf->value, (u8 *) & resp->params.rdeeprom.value,
518 le16_to_cpu(resp->params.rdeeprom.bytecount));
519 lbs_dbg_hex("adapter", (char *)&pbuf->value,
520 le16_to_cpu(resp->params.rdeeprom.bytecount));
525 static int wlan_ret_get_log(wlan_private * priv,
526 struct cmd_ds_command *resp)
528 struct cmd_ds_802_11_get_log *logmessage = &resp->params.glog;
529 wlan_adapter *adapter = priv->adapter;
531 lbs_deb_enter(LBS_DEB_CMD);
533 /* Stored little-endian */
534 memcpy(&adapter->logmsg, logmessage, sizeof(struct cmd_ds_802_11_get_log));
536 lbs_deb_enter(LBS_DEB_CMD);
540 static inline int handle_cmd_response(u16 respcmd,
541 struct cmd_ds_command *resp,
546 wlan_adapter *adapter = priv->adapter;
549 case cmd_ret_mac_reg_access:
550 case cmd_ret_bbp_reg_access:
551 case cmd_ret_rf_reg_access:
552 ret = wlan_ret_reg_access(priv, respcmd, resp);
555 case cmd_ret_hw_spec_info:
556 ret = wlan_ret_get_hw_spec(priv, resp);
559 case cmd_ret_802_11_scan:
560 ret = libertas_ret_80211_scan(priv, resp);
563 case cmd_ret_802_11_get_log:
564 ret = wlan_ret_get_log(priv, resp);
567 case cmd_ret_802_11_associate:
568 case cmd_ret_802_11_reassociate:
569 ret = libertas_ret_80211_associate(priv, resp);
572 case cmd_ret_802_11_disassociate:
573 case cmd_ret_802_11_deauthenticate:
574 ret = libertas_ret_80211_disassociate(priv, resp);
577 case cmd_ret_802_11_ad_hoc_start:
578 case cmd_ret_802_11_ad_hoc_join:
579 ret = libertas_ret_80211_ad_hoc_start(priv, resp);
582 case cmd_ret_802_11_stat:
583 ret = wlan_ret_802_11_stat(priv, resp);
586 case cmd_ret_802_11_snmp_mib:
587 ret = wlan_ret_802_11_snmp_mib(priv, resp);
590 case cmd_ret_802_11_rf_tx_power:
591 ret = wlan_ret_802_11_rf_tx_power(priv, resp);
594 case cmd_ret_802_11_set_afc:
595 case cmd_ret_802_11_get_afc:
596 spin_lock_irqsave(&adapter->driver_lock, flags);
597 memmove(adapter->cur_cmd->pdata_buf, &resp->params.afc,
598 sizeof(struct cmd_ds_802_11_afc));
599 spin_unlock_irqrestore(&adapter->driver_lock, flags);
602 case cmd_ret_802_11_rf_antenna:
603 ret = wlan_ret_802_11_rf_antenna(priv, resp);
606 case cmd_ret_mac_multicast_adr:
607 case cmd_ret_mac_control:
608 case cmd_ret_802_11_set_wep:
609 case cmd_ret_802_11_reset:
610 case cmd_ret_802_11_authenticate:
611 case cmd_ret_802_11_radio_control:
612 case cmd_ret_802_11_beacon_stop:
613 case cmd_ret_802_11_enable_rsn:
616 case cmd_ret_802_11_data_rate:
617 ret = wlan_ret_802_11_data_rate(priv, resp);
619 case cmd_ret_802_11_rate_adapt_rateset:
620 ret = wlan_ret_802_11_rate_adapt_rateset(priv, resp);
622 case cmd_ret_802_11_rf_channel:
623 ret = wlan_ret_802_11_rf_channel(priv, resp);
626 case cmd_ret_802_11_rssi:
627 ret = wlan_ret_802_11_rssi(priv, resp);
630 case cmd_ret_802_11_mac_address:
631 ret = wlan_ret_802_11_mac_address(priv, resp);
634 case cmd_ret_802_11_ad_hoc_stop:
635 ret = libertas_ret_80211_ad_hoc_stop(priv, resp);
638 case cmd_ret_802_11_key_material:
639 lbs_deb_cmd("CMD_RESP: KEY_MATERIAL command response\n");
640 ret = wlan_ret_802_11_key_material(priv, resp);
643 case cmd_ret_802_11_eeprom_access:
644 ret = wlan_ret_802_11_eeprom_access(priv, resp);
647 case cmd_ret_802_11d_domain_info:
648 ret = libertas_ret_802_11d_domain_info(priv, resp);
651 case cmd_ret_802_11_sleep_params:
652 ret = wlan_ret_802_11_sleep_params(priv, resp);
654 case cmd_ret_802_11_inactivity_timeout:
655 spin_lock_irqsave(&adapter->driver_lock, flags);
656 *((u16 *) adapter->cur_cmd->pdata_buf) =
657 le16_to_cpu(resp->params.inactivity_timeout.timeout);
658 spin_unlock_irqrestore(&adapter->driver_lock, flags);
661 case cmd_ret_802_11_tpc_cfg:
662 spin_lock_irqsave(&adapter->driver_lock, flags);
663 memmove(adapter->cur_cmd->pdata_buf, &resp->params.tpccfg,
664 sizeof(struct cmd_ds_802_11_tpc_cfg));
665 spin_unlock_irqrestore(&adapter->driver_lock, flags);
667 case cmd_ret_802_11_led_gpio_ctrl:
668 spin_lock_irqsave(&adapter->driver_lock, flags);
669 memmove(adapter->cur_cmd->pdata_buf, &resp->params.ledgpio,
670 sizeof(struct cmd_ds_802_11_led_ctrl));
671 spin_unlock_irqrestore(&adapter->driver_lock, flags);
673 case cmd_ret_802_11_pwr_cfg:
674 spin_lock_irqsave(&adapter->driver_lock, flags);
675 memmove(adapter->cur_cmd->pdata_buf, &resp->params.pwrcfg,
676 sizeof(struct cmd_ds_802_11_pwr_cfg));
677 spin_unlock_irqrestore(&adapter->driver_lock, flags);
681 case cmd_ret_get_tsf:
682 spin_lock_irqsave(&adapter->driver_lock, flags);
683 memcpy(priv->adapter->cur_cmd->pdata_buf,
684 &resp->params.gettsf.tsfvalue, sizeof(u64));
685 spin_unlock_irqrestore(&adapter->driver_lock, flags);
687 case cmd_ret_bt_access:
688 spin_lock_irqsave(&adapter->driver_lock, flags);
689 if (adapter->cur_cmd->pdata_buf)
690 memcpy(adapter->cur_cmd->pdata_buf,
691 &resp->params.bt.addr1, 2 * ETH_ALEN);
692 spin_unlock_irqrestore(&adapter->driver_lock, flags);
694 case cmd_ret_fwt_access:
695 spin_lock_irqsave(&adapter->driver_lock, flags);
696 if (adapter->cur_cmd->pdata_buf)
697 memcpy(adapter->cur_cmd->pdata_buf, &resp->params.fwt,
698 sizeof(resp->params.fwt));
699 spin_unlock_irqrestore(&adapter->driver_lock, flags);
701 case cmd_ret_mesh_access:
702 if (adapter->cur_cmd->pdata_buf)
703 memcpy(adapter->cur_cmd->pdata_buf, &resp->params.mesh,
704 sizeof(resp->params.mesh));
706 case cmd_rte_802_11_tx_rate_query:
707 priv->adapter->txrate = resp->params.txrate.txrate;
710 lbs_deb_cmd("CMD_RESP: Unknown command response %#x\n",
717 int libertas_process_rx_command(wlan_private * priv)
720 struct cmd_ds_command *resp;
721 wlan_adapter *adapter = priv->adapter;
726 lbs_deb_enter(LBS_DEB_CMD);
728 lbs_deb_cmd("CMD_RESP: @ %lu\n", jiffies);
730 /* Now we got response from FW, cancel the command timer */
731 del_timer(&adapter->command_timer);
733 mutex_lock(&adapter->lock);
734 spin_lock_irqsave(&adapter->driver_lock, flags);
736 if (!adapter->cur_cmd) {
737 lbs_deb_cmd("CMD_RESP: NULL cur_cmd=%p\n", adapter->cur_cmd);
739 spin_unlock_irqrestore(&adapter->driver_lock, flags);
742 resp = (struct cmd_ds_command *)(adapter->cur_cmd->bufvirtualaddr);
744 lbs_dbg_hex("CMD_RESP:", adapter->cur_cmd->bufvirtualaddr,
747 respcmd = le16_to_cpu(resp->command);
749 result = le16_to_cpu(resp->result);
751 lbs_deb_cmd("CMD_RESP: %x result: %d length: %d\n", respcmd,
752 result, priv->upld_len);
754 if (!(respcmd & 0x8000)) {
755 lbs_deb_cmd("Invalid response to command!");
756 adapter->cur_cmd_retcode = -1;
757 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
758 adapter->nr_cmd_pending--;
759 adapter->cur_cmd = NULL;
760 spin_unlock_irqrestore(&adapter->driver_lock, flags);
765 /* Store the response code to cur_cmd_retcode. */
766 adapter->cur_cmd_retcode = result;;
768 if (respcmd == cmd_ret_802_11_ps_mode) {
769 struct cmd_ds_802_11_ps_mode *psmode = &resp->params.psmode;
770 u16 action = le16_to_cpu(psmode->action);
773 "CMD_RESP: PS_MODE cmd reply result=%#x action=0x%X\n",
777 lbs_deb_cmd("CMD_RESP: PS command failed- %#x \n",
780 * We should not re-try enter-ps command in
781 * ad-hoc mode. It takes place in
782 * libertas_execute_next_command().
784 if (adapter->mode == IW_MODE_ADHOC &&
785 action == cmd_subcmd_enter_ps)
786 adapter->psmode = wlan802_11powermodecam;
787 } else if (action == cmd_subcmd_enter_ps) {
788 adapter->needtowakeup = 0;
789 adapter->psstate = PS_STATE_AWAKE;
791 lbs_deb_cmd("CMD_RESP: Enter_PS command response\n");
792 if (adapter->connect_status != libertas_connected) {
794 * When Deauth Event received before Enter_PS command
795 * response, We need to wake up the firmware.
798 "Disconnected, Going to invoke libertas_ps_wakeup\n");
800 spin_unlock_irqrestore(&adapter->driver_lock, flags);
801 mutex_unlock(&adapter->lock);
802 libertas_ps_wakeup(priv, 0);
803 mutex_lock(&adapter->lock);
804 spin_lock_irqsave(&adapter->driver_lock, flags);
806 } else if (action == cmd_subcmd_exit_ps) {
807 adapter->needtowakeup = 0;
808 adapter->psstate = PS_STATE_FULL_POWER;
809 lbs_deb_cmd("CMD_RESP: Exit_PS command response\n");
811 lbs_deb_cmd("CMD_RESP: PS- action=0x%X\n", action);
814 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
815 adapter->nr_cmd_pending--;
816 adapter->cur_cmd = NULL;
817 spin_unlock_irqrestore(&adapter->driver_lock, flags);
823 if (adapter->cur_cmd->cmdflags & CMD_F_HOSTCMD) {
824 /* Copy the response back to response buffer */
825 memcpy(adapter->cur_cmd->pdata_buf, resp, resp->size);
827 adapter->cur_cmd->cmdflags &= ~CMD_F_HOSTCMD;
830 /* If the command is not successful, cleanup and return failure */
831 if ((result != 0 || !(respcmd & 0x8000))) {
832 lbs_deb_cmd("CMD_RESP: command reply %#x result=%#x\n",
835 * Handling errors here
838 case cmd_ret_hw_spec_info:
839 case cmd_ret_802_11_reset:
840 lbs_deb_cmd("CMD_RESP: Reset command failed\n");
845 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
846 adapter->nr_cmd_pending--;
847 adapter->cur_cmd = NULL;
848 spin_unlock_irqrestore(&adapter->driver_lock, flags);
854 spin_unlock_irqrestore(&adapter->driver_lock, flags);
856 ret = handle_cmd_response(respcmd, resp, priv);
858 spin_lock_irqsave(&adapter->driver_lock, flags);
859 if (adapter->cur_cmd) {
860 /* Clean up and Put current command back to cmdfreeq */
861 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
862 adapter->nr_cmd_pending--;
863 WARN_ON(adapter->nr_cmd_pending > 128);
864 adapter->cur_cmd = NULL;
866 spin_unlock_irqrestore(&adapter->driver_lock, flags);
869 mutex_unlock(&adapter->lock);
870 lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret);
874 int libertas_process_event(wlan_private * priv)
877 wlan_adapter *adapter = priv->adapter;
880 spin_lock_irq(&adapter->driver_lock);
881 eventcause = adapter->eventcause;
882 spin_unlock_irq(&adapter->driver_lock);
884 lbs_deb_enter(LBS_DEB_CMD);
886 lbs_deb_cmd("EVENT Cause %x\n", eventcause);
888 switch (eventcause >> SBI_EVENT_CAUSE_SHIFT) {
889 case MACREG_INT_CODE_LINK_SENSED:
890 lbs_deb_cmd("EVENT: MACREG_INT_CODE_LINK_SENSED\n");
893 case MACREG_INT_CODE_DEAUTHENTICATED:
894 lbs_deb_cmd("EVENT: Deauthenticated\n");
895 libertas_mac_event_disconnected(priv);
898 case MACREG_INT_CODE_DISASSOCIATED:
899 lbs_deb_cmd("EVENT: Disassociated\n");
900 libertas_mac_event_disconnected(priv);
903 case MACREG_INT_CODE_LINK_LOSE_NO_SCAN:
904 lbs_deb_cmd("EVENT: Link lost\n");
905 libertas_mac_event_disconnected(priv);
908 case MACREG_INT_CODE_PS_SLEEP:
909 lbs_deb_cmd("EVENT: SLEEP\n");
912 /* handle unexpected PS SLEEP event */
913 if (adapter->psstate == PS_STATE_FULL_POWER) {
915 "EVENT: In FULL POWER mode - ignore PS SLEEP\n");
918 adapter->psstate = PS_STATE_PRE_SLEEP;
920 libertas_ps_confirm_sleep(priv, (u16) adapter->psmode);
924 case MACREG_INT_CODE_PS_AWAKE:
925 lbs_deb_cmd("EVENT: AWAKE \n");
928 /* handle unexpected PS AWAKE event */
929 if (adapter->psstate == PS_STATE_FULL_POWER) {
931 "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
935 adapter->psstate = PS_STATE_AWAKE;
937 if (adapter->needtowakeup) {
939 * wait for the command processing to finish
940 * before resuming sending
941 * adapter->needtowakeup will be set to FALSE
942 * in libertas_ps_wakeup()
944 lbs_deb_cmd("Waking up...\n");
945 libertas_ps_wakeup(priv, 0);
949 case MACREG_INT_CODE_MIC_ERR_UNICAST:
950 lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n");
951 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST);
954 case MACREG_INT_CODE_MIC_ERR_MULTICAST:
955 lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n");
956 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST);
958 case MACREG_INT_CODE_MIB_CHANGED:
959 case MACREG_INT_CODE_INIT_DONE:
962 case MACREG_INT_CODE_ADHOC_BCN_LOST:
963 lbs_deb_cmd("EVENT: HWAC - ADHOC BCN LOST\n");
966 case MACREG_INT_CODE_RSSI_LOW:
967 lbs_pr_alert( "EVENT: RSSI_LOW\n");
969 case MACREG_INT_CODE_SNR_LOW:
970 lbs_pr_alert( "EVENT: SNR_LOW\n");
972 case MACREG_INT_CODE_MAX_FAIL:
973 lbs_pr_alert( "EVENT: MAX_FAIL\n");
975 case MACREG_INT_CODE_RSSI_HIGH:
976 lbs_pr_alert( "EVENT: RSSI_HIGH\n");
978 case MACREG_INT_CODE_SNR_HIGH:
979 lbs_pr_alert( "EVENT: SNR_HIGH\n");
982 case MACREG_INT_CODE_MESH_AUTO_STARTED:
983 lbs_pr_alert( "EVENT: MESH_AUTO_STARTED\n");
984 adapter->connect_status = libertas_connected ;
985 if (priv->mesh_open == 1) {
986 netif_wake_queue(priv->mesh_dev) ;
987 netif_carrier_on(priv->mesh_dev) ;
989 adapter->mode = IW_MODE_ADHOC ;
990 schedule_work(&priv->sync_channel);
994 lbs_pr_alert( "EVENT: unknown event id: %#x\n",
995 eventcause >> SBI_EVENT_CAUSE_SHIFT);
999 spin_lock_irq(&adapter->driver_lock);
1000 adapter->eventcause = 0;
1001 spin_unlock_irq(&adapter->driver_lock);
1003 lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret);