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 int libertas_ret_802_11_enable_rsn(wlan_private * priv,
541 struct cmd_ds_command *resp)
543 struct cmd_ds_802_11_enable_rsn *enable_rsn = &resp->params.enbrsn;
544 wlan_adapter *adapter = priv->adapter;
545 u32 * pdata_buf = adapter->cur_cmd->pdata_buf;
547 lbs_deb_enter(LBS_DEB_CMD);
549 if (enable_rsn->action == cpu_to_le16(cmd_act_get)) {
551 *pdata_buf = (u32) le16_to_cpu(enable_rsn->enable);
554 lbs_deb_enter(LBS_DEB_CMD);
558 static inline int handle_cmd_response(u16 respcmd,
559 struct cmd_ds_command *resp,
564 wlan_adapter *adapter = priv->adapter;
567 case cmd_ret_mac_reg_access:
568 case cmd_ret_bbp_reg_access:
569 case cmd_ret_rf_reg_access:
570 ret = wlan_ret_reg_access(priv, respcmd, resp);
573 case cmd_ret_hw_spec_info:
574 ret = wlan_ret_get_hw_spec(priv, resp);
577 case cmd_ret_802_11_scan:
578 ret = libertas_ret_80211_scan(priv, resp);
581 case cmd_ret_802_11_get_log:
582 ret = wlan_ret_get_log(priv, resp);
585 case cmd_ret_802_11_associate:
586 case cmd_ret_802_11_reassociate:
587 ret = libertas_ret_80211_associate(priv, resp);
590 case cmd_ret_802_11_disassociate:
591 case cmd_ret_802_11_deauthenticate:
592 ret = libertas_ret_80211_disassociate(priv, resp);
595 case cmd_ret_802_11_ad_hoc_start:
596 case cmd_ret_802_11_ad_hoc_join:
597 ret = libertas_ret_80211_ad_hoc_start(priv, resp);
600 case cmd_ret_802_11_stat:
601 ret = wlan_ret_802_11_stat(priv, resp);
604 case cmd_ret_802_11_snmp_mib:
605 ret = wlan_ret_802_11_snmp_mib(priv, resp);
608 case cmd_ret_802_11_rf_tx_power:
609 ret = wlan_ret_802_11_rf_tx_power(priv, resp);
612 case cmd_ret_802_11_set_afc:
613 case cmd_ret_802_11_get_afc:
614 spin_lock_irqsave(&adapter->driver_lock, flags);
615 memmove(adapter->cur_cmd->pdata_buf, &resp->params.afc,
616 sizeof(struct cmd_ds_802_11_afc));
617 spin_unlock_irqrestore(&adapter->driver_lock, flags);
620 case cmd_ret_802_11_rf_antenna:
621 ret = wlan_ret_802_11_rf_antenna(priv, resp);
624 case cmd_ret_mac_multicast_adr:
625 case cmd_ret_mac_control:
626 case cmd_ret_802_11_set_wep:
627 case cmd_ret_802_11_reset:
628 case cmd_ret_802_11_authenticate:
629 case cmd_ret_802_11_radio_control:
630 case cmd_ret_802_11_beacon_stop:
633 case cmd_ret_802_11_enable_rsn:
634 ret = libertas_ret_802_11_enable_rsn(priv, resp);
637 case cmd_ret_802_11_data_rate:
638 ret = wlan_ret_802_11_data_rate(priv, resp);
640 case cmd_ret_802_11_rate_adapt_rateset:
641 ret = wlan_ret_802_11_rate_adapt_rateset(priv, resp);
643 case cmd_ret_802_11_rf_channel:
644 ret = wlan_ret_802_11_rf_channel(priv, resp);
647 case cmd_ret_802_11_rssi:
648 ret = wlan_ret_802_11_rssi(priv, resp);
651 case cmd_ret_802_11_mac_address:
652 ret = wlan_ret_802_11_mac_address(priv, resp);
655 case cmd_ret_802_11_ad_hoc_stop:
656 ret = libertas_ret_80211_ad_hoc_stop(priv, resp);
659 case cmd_ret_802_11_key_material:
660 lbs_deb_cmd("CMD_RESP: KEY_MATERIAL command response\n");
661 ret = wlan_ret_802_11_key_material(priv, resp);
664 case cmd_ret_802_11_eeprom_access:
665 ret = wlan_ret_802_11_eeprom_access(priv, resp);
668 case cmd_ret_802_11d_domain_info:
669 ret = libertas_ret_802_11d_domain_info(priv, resp);
672 case cmd_ret_802_11_sleep_params:
673 ret = wlan_ret_802_11_sleep_params(priv, resp);
675 case cmd_ret_802_11_inactivity_timeout:
676 spin_lock_irqsave(&adapter->driver_lock, flags);
677 *((u16 *) adapter->cur_cmd->pdata_buf) =
678 le16_to_cpu(resp->params.inactivity_timeout.timeout);
679 spin_unlock_irqrestore(&adapter->driver_lock, flags);
682 case cmd_ret_802_11_tpc_cfg:
683 spin_lock_irqsave(&adapter->driver_lock, flags);
684 memmove(adapter->cur_cmd->pdata_buf, &resp->params.tpccfg,
685 sizeof(struct cmd_ds_802_11_tpc_cfg));
686 spin_unlock_irqrestore(&adapter->driver_lock, flags);
688 case cmd_ret_802_11_led_gpio_ctrl:
689 spin_lock_irqsave(&adapter->driver_lock, flags);
690 memmove(adapter->cur_cmd->pdata_buf, &resp->params.ledgpio,
691 sizeof(struct cmd_ds_802_11_led_ctrl));
692 spin_unlock_irqrestore(&adapter->driver_lock, flags);
694 case cmd_ret_802_11_pwr_cfg:
695 spin_lock_irqsave(&adapter->driver_lock, flags);
696 memmove(adapter->cur_cmd->pdata_buf, &resp->params.pwrcfg,
697 sizeof(struct cmd_ds_802_11_pwr_cfg));
698 spin_unlock_irqrestore(&adapter->driver_lock, flags);
702 case cmd_ret_get_tsf:
703 spin_lock_irqsave(&adapter->driver_lock, flags);
704 memcpy(priv->adapter->cur_cmd->pdata_buf,
705 &resp->params.gettsf.tsfvalue, sizeof(u64));
706 spin_unlock_irqrestore(&adapter->driver_lock, flags);
708 case cmd_ret_bt_access:
709 spin_lock_irqsave(&adapter->driver_lock, flags);
710 if (adapter->cur_cmd->pdata_buf)
711 memcpy(adapter->cur_cmd->pdata_buf,
712 &resp->params.bt.addr1, 2 * ETH_ALEN);
713 spin_unlock_irqrestore(&adapter->driver_lock, flags);
715 case cmd_ret_fwt_access:
716 spin_lock_irqsave(&adapter->driver_lock, flags);
717 if (adapter->cur_cmd->pdata_buf)
718 memcpy(adapter->cur_cmd->pdata_buf, &resp->params.fwt,
719 sizeof(resp->params.fwt));
720 spin_unlock_irqrestore(&adapter->driver_lock, flags);
722 case cmd_ret_mesh_access:
723 if (adapter->cur_cmd->pdata_buf)
724 memcpy(adapter->cur_cmd->pdata_buf, &resp->params.mesh,
725 sizeof(resp->params.mesh));
727 case cmd_rte_802_11_tx_rate_query:
728 priv->adapter->txrate = resp->params.txrate.txrate;
731 lbs_deb_cmd("CMD_RESP: Unknown command response %#x\n",
738 int libertas_process_rx_command(wlan_private * priv)
741 struct cmd_ds_command *resp;
742 wlan_adapter *adapter = priv->adapter;
747 lbs_deb_enter(LBS_DEB_CMD);
749 lbs_deb_cmd("CMD_RESP: @ %lu\n", jiffies);
751 /* Now we got response from FW, cancel the command timer */
752 del_timer(&adapter->command_timer);
754 mutex_lock(&adapter->lock);
755 spin_lock_irqsave(&adapter->driver_lock, flags);
757 if (!adapter->cur_cmd) {
758 lbs_deb_cmd("CMD_RESP: NULL cur_cmd=%p\n", adapter->cur_cmd);
760 spin_unlock_irqrestore(&adapter->driver_lock, flags);
763 resp = (struct cmd_ds_command *)(adapter->cur_cmd->bufvirtualaddr);
765 lbs_dbg_hex("CMD_RESP:", adapter->cur_cmd->bufvirtualaddr,
768 respcmd = le16_to_cpu(resp->command);
770 result = le16_to_cpu(resp->result);
772 lbs_deb_cmd("CMD_RESP: %x result: %d length: %d\n", respcmd,
773 result, priv->upld_len);
775 if (!(respcmd & 0x8000)) {
776 lbs_deb_cmd("Invalid response to command!");
777 adapter->cur_cmd_retcode = -1;
778 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
779 adapter->nr_cmd_pending--;
780 adapter->cur_cmd = NULL;
781 spin_unlock_irqrestore(&adapter->driver_lock, flags);
786 /* Store the response code to cur_cmd_retcode. */
787 adapter->cur_cmd_retcode = result;;
789 if (respcmd == cmd_ret_802_11_ps_mode) {
790 struct cmd_ds_802_11_ps_mode *psmode = &resp->params.psmode;
791 u16 action = le16_to_cpu(psmode->action);
794 "CMD_RESP: PS_MODE cmd reply result=%#x action=0x%X\n",
798 lbs_deb_cmd("CMD_RESP: PS command failed- %#x \n",
801 * We should not re-try enter-ps command in
802 * ad-hoc mode. It takes place in
803 * libertas_execute_next_command().
805 if (adapter->mode == IW_MODE_ADHOC &&
806 action == cmd_subcmd_enter_ps)
807 adapter->psmode = wlan802_11powermodecam;
808 } else if (action == cmd_subcmd_enter_ps) {
809 adapter->needtowakeup = 0;
810 adapter->psstate = PS_STATE_AWAKE;
812 lbs_deb_cmd("CMD_RESP: Enter_PS command response\n");
813 if (adapter->connect_status != libertas_connected) {
815 * When Deauth Event received before Enter_PS command
816 * response, We need to wake up the firmware.
819 "Disconnected, Going to invoke libertas_ps_wakeup\n");
821 spin_unlock_irqrestore(&adapter->driver_lock, flags);
822 mutex_unlock(&adapter->lock);
823 libertas_ps_wakeup(priv, 0);
824 mutex_lock(&adapter->lock);
825 spin_lock_irqsave(&adapter->driver_lock, flags);
827 } else if (action == cmd_subcmd_exit_ps) {
828 adapter->needtowakeup = 0;
829 adapter->psstate = PS_STATE_FULL_POWER;
830 lbs_deb_cmd("CMD_RESP: Exit_PS command response\n");
832 lbs_deb_cmd("CMD_RESP: PS- action=0x%X\n", action);
835 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
836 adapter->nr_cmd_pending--;
837 adapter->cur_cmd = NULL;
838 spin_unlock_irqrestore(&adapter->driver_lock, flags);
844 if (adapter->cur_cmd->cmdflags & CMD_F_HOSTCMD) {
845 /* Copy the response back to response buffer */
846 memcpy(adapter->cur_cmd->pdata_buf, resp, resp->size);
848 adapter->cur_cmd->cmdflags &= ~CMD_F_HOSTCMD;
851 /* If the command is not successful, cleanup and return failure */
852 if ((result != 0 || !(respcmd & 0x8000))) {
853 lbs_deb_cmd("CMD_RESP: command reply %#x result=%#x\n",
856 * Handling errors here
859 case cmd_ret_hw_spec_info:
860 case cmd_ret_802_11_reset:
861 lbs_deb_cmd("CMD_RESP: Reset command failed\n");
866 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
867 adapter->nr_cmd_pending--;
868 adapter->cur_cmd = NULL;
869 spin_unlock_irqrestore(&adapter->driver_lock, flags);
875 spin_unlock_irqrestore(&adapter->driver_lock, flags);
877 ret = handle_cmd_response(respcmd, resp, priv);
879 spin_lock_irqsave(&adapter->driver_lock, flags);
880 if (adapter->cur_cmd) {
881 /* Clean up and Put current command back to cmdfreeq */
882 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
883 adapter->nr_cmd_pending--;
884 WARN_ON(adapter->nr_cmd_pending > 128);
885 adapter->cur_cmd = NULL;
887 spin_unlock_irqrestore(&adapter->driver_lock, flags);
890 mutex_unlock(&adapter->lock);
891 lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret);
895 int libertas_process_event(wlan_private * priv)
898 wlan_adapter *adapter = priv->adapter;
901 spin_lock_irq(&adapter->driver_lock);
902 eventcause = adapter->eventcause;
903 spin_unlock_irq(&adapter->driver_lock);
905 lbs_deb_enter(LBS_DEB_CMD);
907 lbs_deb_cmd("EVENT Cause %x\n", eventcause);
909 switch (eventcause >> SBI_EVENT_CAUSE_SHIFT) {
910 case MACREG_INT_CODE_LINK_SENSED:
911 lbs_deb_cmd("EVENT: MACREG_INT_CODE_LINK_SENSED\n");
914 case MACREG_INT_CODE_DEAUTHENTICATED:
915 lbs_deb_cmd("EVENT: Deauthenticated\n");
916 libertas_mac_event_disconnected(priv);
919 case MACREG_INT_CODE_DISASSOCIATED:
920 lbs_deb_cmd("EVENT: Disassociated\n");
921 libertas_mac_event_disconnected(priv);
924 case MACREG_INT_CODE_LINK_LOSE_NO_SCAN:
925 lbs_deb_cmd("EVENT: Link lost\n");
926 libertas_mac_event_disconnected(priv);
929 case MACREG_INT_CODE_PS_SLEEP:
930 lbs_deb_cmd("EVENT: SLEEP\n");
933 /* handle unexpected PS SLEEP event */
934 if (adapter->psstate == PS_STATE_FULL_POWER) {
936 "EVENT: In FULL POWER mode - ignore PS SLEEP\n");
939 adapter->psstate = PS_STATE_PRE_SLEEP;
941 libertas_ps_confirm_sleep(priv, (u16) adapter->psmode);
945 case MACREG_INT_CODE_PS_AWAKE:
946 lbs_deb_cmd("EVENT: AWAKE \n");
949 /* handle unexpected PS AWAKE event */
950 if (adapter->psstate == PS_STATE_FULL_POWER) {
952 "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
956 adapter->psstate = PS_STATE_AWAKE;
958 if (adapter->needtowakeup) {
960 * wait for the command processing to finish
961 * before resuming sending
962 * adapter->needtowakeup will be set to FALSE
963 * in libertas_ps_wakeup()
965 lbs_deb_cmd("Waking up...\n");
966 libertas_ps_wakeup(priv, 0);
970 case MACREG_INT_CODE_MIC_ERR_UNICAST:
971 lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n");
972 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST);
975 case MACREG_INT_CODE_MIC_ERR_MULTICAST:
976 lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n");
977 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST);
979 case MACREG_INT_CODE_MIB_CHANGED:
980 case MACREG_INT_CODE_INIT_DONE:
983 case MACREG_INT_CODE_ADHOC_BCN_LOST:
984 lbs_deb_cmd("EVENT: HWAC - ADHOC BCN LOST\n");
987 case MACREG_INT_CODE_RSSI_LOW:
988 lbs_pr_alert( "EVENT: RSSI_LOW\n");
990 case MACREG_INT_CODE_SNR_LOW:
991 lbs_pr_alert( "EVENT: SNR_LOW\n");
993 case MACREG_INT_CODE_MAX_FAIL:
994 lbs_pr_alert( "EVENT: MAX_FAIL\n");
996 case MACREG_INT_CODE_RSSI_HIGH:
997 lbs_pr_alert( "EVENT: RSSI_HIGH\n");
999 case MACREG_INT_CODE_SNR_HIGH:
1000 lbs_pr_alert( "EVENT: SNR_HIGH\n");
1003 case MACREG_INT_CODE_MESH_AUTO_STARTED:
1004 lbs_pr_alert( "EVENT: MESH_AUTO_STARTED\n");
1005 adapter->connect_status = libertas_connected ;
1006 if (priv->mesh_open == 1) {
1007 netif_wake_queue(priv->mesh_dev) ;
1008 netif_carrier_on(priv->mesh_dev) ;
1010 adapter->mode = IW_MODE_ADHOC ;
1011 schedule_work(&priv->sync_channel);
1015 lbs_pr_alert( "EVENT: unknown event id: %#x\n",
1016 eventcause >> SBI_EVENT_CAUSE_SHIFT);
1020 spin_lock_irq(&adapter->driver_lock);
1021 adapter->eventcause = 0;
1022 spin_unlock_irq(&adapter->driver_lock);
1024 lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret);