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 struct lbs_private structure
26 void lbs_mac_event_disconnected(struct lbs_private *priv)
28 union iwreq_data wrqu;
30 if (priv->connect_status != LBS_CONNECTED)
33 lbs_deb_enter(LBS_DEB_ASSOC);
35 memset(wrqu.ap_addr.sa_data, 0x00, ETH_ALEN);
36 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
39 * Cisco AP sends EAP failure and de-auth in less than 0.5 ms.
40 * It causes problem in the Supplicant
43 msleep_interruptible(1000);
44 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
46 /* Free Tx and Rx packets */
47 kfree_skb(priv->currenttxskb);
48 priv->currenttxskb = NULL;
50 /* report disconnect to upper layer */
51 netif_stop_queue(priv->dev);
52 netif_carrier_off(priv->dev);
54 /* reset SNR/NF/RSSI values */
55 memset(priv->SNR, 0x00, sizeof(priv->SNR));
56 memset(priv->NF, 0x00, sizeof(priv->NF));
57 memset(priv->RSSI, 0x00, sizeof(priv->RSSI));
58 memset(priv->rawSNR, 0x00, sizeof(priv->rawSNR));
59 memset(priv->rawNF, 0x00, sizeof(priv->rawNF));
62 priv->connect_status = LBS_DISCONNECTED;
64 /* Clear out associated SSID and BSSID since connection is
67 memset(&priv->curbssparams.bssid, 0, ETH_ALEN);
68 memset(&priv->curbssparams.ssid, 0, IW_ESSID_MAX_SIZE);
69 priv->curbssparams.ssid_len = 0;
71 if (priv->psstate != PS_STATE_FULL_POWER) {
72 /* make firmware to exit PS mode */
73 lbs_deb_cmd("disconnected, so exit PS mode\n");
74 lbs_ps_wakeup(priv, 0);
76 lbs_deb_leave(LBS_DEB_CMD);
80 * @brief This function handles MIC failure event.
82 * @param priv A pointer to struct lbs_private structure
83 * @para event the event id
86 static void handle_mic_failureevent(struct lbs_private *priv, u32 event)
90 lbs_deb_enter(LBS_DEB_CMD);
91 memset(buf, 0, sizeof(buf));
93 sprintf(buf, "%s", "MLME-MICHAELMICFAILURE.indication ");
95 if (event == MACREG_INT_CODE_MIC_ERR_UNICAST) {
96 strcat(buf, "unicast ");
98 strcat(buf, "multicast ");
101 lbs_send_iwevcustom_event(priv, buf);
102 lbs_deb_leave(LBS_DEB_CMD);
105 static int lbs_ret_reg_access(struct lbs_private *priv,
106 u16 type, struct cmd_ds_command *resp)
110 lbs_deb_enter(LBS_DEB_CMD);
113 case CMD_RET(CMD_MAC_REG_ACCESS):
115 struct cmd_ds_mac_reg_access *reg = &resp->params.macreg;
117 priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
118 priv->offsetvalue.value = le32_to_cpu(reg->value);
122 case CMD_RET(CMD_BBP_REG_ACCESS):
124 struct cmd_ds_bbp_reg_access *reg = &resp->params.bbpreg;
126 priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
127 priv->offsetvalue.value = reg->value;
131 case CMD_RET(CMD_RF_REG_ACCESS):
133 struct cmd_ds_rf_reg_access *reg = &resp->params.rfreg;
135 priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
136 priv->offsetvalue.value = reg->value;
144 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
148 static int lbs_ret_802_11_sleep_params(struct lbs_private *priv,
149 struct cmd_ds_command *resp)
151 struct cmd_ds_802_11_sleep_params *sp = &resp->params.sleep_params;
153 lbs_deb_enter(LBS_DEB_CMD);
155 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, calcontrol 0x%x "
156 "extsleepclk 0x%x\n", le16_to_cpu(sp->error),
157 le16_to_cpu(sp->offset), le16_to_cpu(sp->stabletime),
158 sp->calcontrol, sp->externalsleepclk);
160 priv->sp.sp_error = le16_to_cpu(sp->error);
161 priv->sp.sp_offset = le16_to_cpu(sp->offset);
162 priv->sp.sp_stabletime = le16_to_cpu(sp->stabletime);
163 priv->sp.sp_calcontrol = sp->calcontrol;
164 priv->sp.sp_extsleepclk = sp->externalsleepclk;
165 priv->sp.sp_reserved = le16_to_cpu(sp->reserved);
167 lbs_deb_enter(LBS_DEB_CMD);
171 static int lbs_ret_802_11_stat(struct lbs_private *priv,
172 struct cmd_ds_command *resp)
174 lbs_deb_enter(LBS_DEB_CMD);
175 /* currently priv->wlan802_11Stat is unused
177 struct cmd_ds_802_11_get_stat *p11Stat = &resp->params.gstat;
179 // TODO Convert it to Big endian befor copy
180 memcpy(&priv->wlan802_11Stat,
181 p11Stat, sizeof(struct cmd_ds_802_11_get_stat));
183 lbs_deb_leave(LBS_DEB_CMD);
187 static int lbs_ret_802_11_snmp_mib(struct lbs_private *priv,
188 struct cmd_ds_command *resp)
190 struct cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
191 u16 oid = le16_to_cpu(smib->oid);
192 u16 querytype = le16_to_cpu(smib->querytype);
194 lbs_deb_enter(LBS_DEB_CMD);
196 lbs_deb_cmd("SNMP_RESP: oid 0x%x, querytype 0x%x\n", oid,
198 lbs_deb_cmd("SNMP_RESP: Buf size %d\n", le16_to_cpu(smib->bufsize));
200 if (querytype == CMD_ACT_GET) {
204 le16_to_cpu(*((__le16 *)(smib->value)));
205 lbs_deb_cmd("SNMP_RESP: frag threshold %u\n",
210 le16_to_cpu(*((__le16 *)(smib->value)));
211 lbs_deb_cmd("SNMP_RESP: rts threshold %u\n",
214 case SHORT_RETRYLIM_I:
216 le16_to_cpu(*((__le16 *)(smib->value)));
217 lbs_deb_cmd("SNMP_RESP: tx retry count %u\n",
225 lbs_deb_enter(LBS_DEB_CMD);
229 static int lbs_ret_802_11_key_material(struct lbs_private *priv,
230 struct cmd_ds_command *resp)
232 struct cmd_ds_802_11_key_material *pkeymaterial =
233 &resp->params.keymaterial;
234 u16 action = le16_to_cpu(pkeymaterial->action);
236 lbs_deb_enter(LBS_DEB_CMD);
238 /* Copy the returned key to driver private data */
239 if (action == CMD_ACT_GET) {
240 u8 * buf_ptr = (u8 *) &pkeymaterial->keyParamSet;
241 u8 * resp_end = (u8 *) (resp + le16_to_cpu(resp->size));
243 while (buf_ptr < resp_end) {
244 struct MrvlIEtype_keyParamSet * pkeyparamset =
245 (struct MrvlIEtype_keyParamSet *) buf_ptr;
246 struct enc_key * pkey;
247 u16 param_set_len = le16_to_cpu(pkeyparamset->length);
248 u16 key_len = le16_to_cpu(pkeyparamset->keylen);
249 u16 key_flags = le16_to_cpu(pkeyparamset->keyinfo);
250 u16 key_type = le16_to_cpu(pkeyparamset->keytypeid);
253 end = (u8 *) pkeyparamset + sizeof (pkeyparamset->type)
254 + sizeof (pkeyparamset->length)
256 /* Make sure we don't access past the end of the IEs */
260 if (key_flags & KEY_INFO_WPA_UNICAST)
261 pkey = &priv->wpa_unicast_key;
262 else if (key_flags & KEY_INFO_WPA_MCAST)
263 pkey = &priv->wpa_mcast_key;
267 /* Copy returned key into driver */
268 memset(pkey, 0, sizeof(struct enc_key));
269 if (key_len > sizeof(pkey->key))
271 pkey->type = key_type;
272 pkey->flags = key_flags;
274 memcpy(pkey->key, pkeyparamset->key, pkey->len);
280 lbs_deb_enter(LBS_DEB_CMD);
284 static int lbs_ret_802_11_mac_address(struct lbs_private *priv,
285 struct cmd_ds_command *resp)
287 struct cmd_ds_802_11_mac_address *macadd = &resp->params.macadd;
289 lbs_deb_enter(LBS_DEB_CMD);
291 memcpy(priv->current_addr, macadd->macadd, ETH_ALEN);
293 lbs_deb_enter(LBS_DEB_CMD);
297 static int lbs_ret_802_11_rf_tx_power(struct lbs_private *priv,
298 struct cmd_ds_command *resp)
300 struct cmd_ds_802_11_rf_tx_power *rtp = &resp->params.txp;
302 lbs_deb_enter(LBS_DEB_CMD);
304 priv->txpowerlevel = le16_to_cpu(rtp->currentlevel);
306 lbs_deb_cmd("TX power currently %d\n", priv->txpowerlevel);
308 lbs_deb_leave(LBS_DEB_CMD);
312 static int lbs_ret_802_11_rate_adapt_rateset(struct lbs_private *priv,
313 struct cmd_ds_command *resp)
315 struct cmd_ds_802_11_rate_adapt_rateset *rates = &resp->params.rateset;
317 lbs_deb_enter(LBS_DEB_CMD);
319 if (rates->action == CMD_ACT_GET) {
320 priv->enablehwauto = le16_to_cpu(rates->enablehwauto);
321 priv->ratebitmap = le16_to_cpu(rates->bitmap);
324 lbs_deb_leave(LBS_DEB_CMD);
328 static int lbs_ret_802_11_rf_channel(struct lbs_private *priv,
329 struct cmd_ds_command *resp)
331 struct cmd_ds_802_11_rf_channel *rfchannel = &resp->params.rfchannel;
332 u16 action = le16_to_cpu(rfchannel->action);
333 u16 newchannel = le16_to_cpu(rfchannel->currentchannel);
335 lbs_deb_enter(LBS_DEB_CMD);
337 if (action == CMD_OPT_802_11_RF_CHANNEL_GET
338 && priv->curbssparams.channel != newchannel) {
339 lbs_deb_cmd("channel switch from %d to %d\n",
340 priv->curbssparams.channel, newchannel);
342 /* Update the channel again */
343 priv->curbssparams.channel = newchannel;
346 lbs_deb_enter(LBS_DEB_CMD);
350 static int lbs_ret_802_11_rssi(struct lbs_private *priv,
351 struct cmd_ds_command *resp)
353 struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp;
355 lbs_deb_enter(LBS_DEB_CMD);
357 /* store the non average value */
358 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR);
359 priv->NF[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->noisefloor);
361 priv->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR);
362 priv->NF[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgnoisefloor);
364 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] =
365 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
366 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
368 priv->RSSI[TYPE_BEACON][TYPE_AVG] =
369 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE,
370 priv->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE);
372 lbs_deb_cmd("RSSI: beacon %d, avg %d\n",
373 priv->RSSI[TYPE_BEACON][TYPE_NOAVG],
374 priv->RSSI[TYPE_BEACON][TYPE_AVG]);
376 lbs_deb_leave(LBS_DEB_CMD);
380 static int lbs_ret_802_11_eeprom_access(struct lbs_private *priv,
381 struct cmd_ds_command *resp)
383 struct lbs_ioctl_regrdwr *pbuf;
384 pbuf = (struct lbs_ioctl_regrdwr *) priv->prdeeprom;
386 lbs_deb_enter_args(LBS_DEB_CMD, "len %d",
387 le16_to_cpu(resp->params.rdeeprom.bytecount));
388 if (pbuf->NOB < le16_to_cpu(resp->params.rdeeprom.bytecount)) {
390 lbs_deb_cmd("EEPROM read length too big\n");
393 pbuf->NOB = le16_to_cpu(resp->params.rdeeprom.bytecount);
396 memcpy(&pbuf->value, (u8 *) & resp->params.rdeeprom.value,
397 le16_to_cpu(resp->params.rdeeprom.bytecount));
398 lbs_deb_hex(LBS_DEB_CMD, "EEPROM", (char *)&pbuf->value,
399 le16_to_cpu(resp->params.rdeeprom.bytecount));
401 lbs_deb_leave(LBS_DEB_CMD);
405 static int lbs_ret_get_log(struct lbs_private *priv,
406 struct cmd_ds_command *resp)
408 struct cmd_ds_802_11_get_log *logmessage = &resp->params.glog;
410 lbs_deb_enter(LBS_DEB_CMD);
412 /* Stored little-endian */
413 memcpy(&priv->logmsg, logmessage, sizeof(struct cmd_ds_802_11_get_log));
415 lbs_deb_leave(LBS_DEB_CMD);
419 static int lbs_ret_802_11_enable_rsn(struct lbs_private *priv,
420 struct cmd_ds_command *resp)
422 struct cmd_ds_802_11_enable_rsn *enable_rsn = &resp->params.enbrsn;
423 u32 * pdata_buf = priv->cur_cmd->pdata_buf;
425 lbs_deb_enter(LBS_DEB_CMD);
427 if (enable_rsn->action == cpu_to_le16(CMD_ACT_GET)) {
429 *pdata_buf = (u32) le16_to_cpu(enable_rsn->enable);
432 lbs_deb_leave(LBS_DEB_CMD);
436 static int lbs_ret_802_11_bcn_ctrl(struct lbs_private * priv,
437 struct cmd_ds_command *resp)
439 struct cmd_ds_802_11_beacon_control *bcn_ctrl =
440 &resp->params.bcn_ctrl;
442 lbs_deb_enter(LBS_DEB_CMD);
444 if (bcn_ctrl->action == CMD_ACT_GET) {
445 priv->beacon_enable = (u8) le16_to_cpu(bcn_ctrl->beacon_enable);
446 priv->beacon_period = le16_to_cpu(bcn_ctrl->beacon_period);
449 lbs_deb_enter(LBS_DEB_CMD);
453 static int lbs_ret_802_11_subscribe_event(struct lbs_private *priv,
454 struct cmd_ds_command *resp)
456 struct cmd_ds_802_11_subscribe_event *cmd_event =
457 &resp->params.subscribe_event;
458 struct cmd_ds_802_11_subscribe_event *dst_event =
459 priv->cur_cmd->pdata_buf;
461 lbs_deb_enter(LBS_DEB_CMD);
463 if (dst_event->action == cpu_to_le16(CMD_ACT_GET)) {
464 dst_event->events = cmd_event->events;
465 memcpy(dst_event->tlv, cmd_event->tlv, sizeof(dst_event->tlv));
468 lbs_deb_leave(LBS_DEB_CMD);
472 static inline int handle_cmd_response(struct lbs_private *priv,
474 struct cmd_header *cmd_response)
476 struct cmd_ds_command *resp = (struct cmd_ds_command *) cmd_response;
479 uint16_t respcmd = le16_to_cpu(resp->command);
481 lbs_deb_enter(LBS_DEB_HOST);
484 case CMD_RET(CMD_MAC_REG_ACCESS):
485 case CMD_RET(CMD_BBP_REG_ACCESS):
486 case CMD_RET(CMD_RF_REG_ACCESS):
487 ret = lbs_ret_reg_access(priv, respcmd, resp);
490 case CMD_RET(CMD_802_11_SCAN):
491 ret = lbs_ret_80211_scan(priv, resp);
494 case CMD_RET(CMD_802_11_GET_LOG):
495 ret = lbs_ret_get_log(priv, resp);
498 case CMD_RET_802_11_ASSOCIATE:
499 case CMD_RET(CMD_802_11_ASSOCIATE):
500 case CMD_RET(CMD_802_11_REASSOCIATE):
501 ret = lbs_ret_80211_associate(priv, resp);
504 case CMD_RET(CMD_802_11_DISASSOCIATE):
505 case CMD_RET(CMD_802_11_DEAUTHENTICATE):
506 ret = lbs_ret_80211_disassociate(priv, resp);
509 case CMD_RET(CMD_802_11_AD_HOC_START):
510 case CMD_RET(CMD_802_11_AD_HOC_JOIN):
511 ret = lbs_ret_80211_ad_hoc_start(priv, resp);
514 case CMD_RET(CMD_802_11_GET_STAT):
515 ret = lbs_ret_802_11_stat(priv, resp);
518 case CMD_RET(CMD_802_11_SNMP_MIB):
519 ret = lbs_ret_802_11_snmp_mib(priv, resp);
522 case CMD_RET(CMD_802_11_RF_TX_POWER):
523 ret = lbs_ret_802_11_rf_tx_power(priv, resp);
526 case CMD_RET(CMD_802_11_SET_AFC):
527 case CMD_RET(CMD_802_11_GET_AFC):
528 spin_lock_irqsave(&priv->driver_lock, flags);
529 memmove(priv->cur_cmd->pdata_buf, &resp->params.afc,
530 sizeof(struct cmd_ds_802_11_afc));
531 spin_unlock_irqrestore(&priv->driver_lock, flags);
535 case CMD_RET(CMD_MAC_MULTICAST_ADR):
536 case CMD_RET(CMD_MAC_CONTROL):
537 case CMD_RET(CMD_802_11_SET_WEP):
538 case CMD_RET(CMD_802_11_RESET):
539 case CMD_RET(CMD_802_11_AUTHENTICATE):
540 case CMD_RET(CMD_802_11_RADIO_CONTROL):
541 case CMD_RET(CMD_802_11_BEACON_STOP):
544 case CMD_RET(CMD_802_11_ENABLE_RSN):
545 ret = lbs_ret_802_11_enable_rsn(priv, resp);
548 case CMD_RET(CMD_802_11_RATE_ADAPT_RATESET):
549 ret = lbs_ret_802_11_rate_adapt_rateset(priv, resp);
551 case CMD_RET(CMD_802_11_RF_CHANNEL):
552 ret = lbs_ret_802_11_rf_channel(priv, resp);
555 case CMD_RET(CMD_802_11_RSSI):
556 ret = lbs_ret_802_11_rssi(priv, resp);
559 case CMD_RET(CMD_802_11_MAC_ADDRESS):
560 ret = lbs_ret_802_11_mac_address(priv, resp);
563 case CMD_RET(CMD_802_11_AD_HOC_STOP):
564 ret = lbs_ret_80211_ad_hoc_stop(priv, resp);
567 case CMD_RET(CMD_802_11_KEY_MATERIAL):
568 ret = lbs_ret_802_11_key_material(priv, resp);
571 case CMD_RET(CMD_802_11_EEPROM_ACCESS):
572 ret = lbs_ret_802_11_eeprom_access(priv, resp);
575 case CMD_RET(CMD_802_11D_DOMAIN_INFO):
576 ret = lbs_ret_802_11d_domain_info(priv, resp);
579 case CMD_RET(CMD_802_11_SLEEP_PARAMS):
580 ret = lbs_ret_802_11_sleep_params(priv, resp);
582 case CMD_RET(CMD_802_11_INACTIVITY_TIMEOUT):
583 spin_lock_irqsave(&priv->driver_lock, flags);
584 *((u16 *) priv->cur_cmd->pdata_buf) =
585 le16_to_cpu(resp->params.inactivity_timeout.timeout);
586 spin_unlock_irqrestore(&priv->driver_lock, flags);
589 case CMD_RET(CMD_802_11_TPC_CFG):
590 spin_lock_irqsave(&priv->driver_lock, flags);
591 memmove(priv->cur_cmd->pdata_buf, &resp->params.tpccfg,
592 sizeof(struct cmd_ds_802_11_tpc_cfg));
593 spin_unlock_irqrestore(&priv->driver_lock, flags);
595 case CMD_RET(CMD_802_11_LED_GPIO_CTRL):
596 spin_lock_irqsave(&priv->driver_lock, flags);
597 memmove(priv->cur_cmd->pdata_buf, &resp->params.ledgpio,
598 sizeof(struct cmd_ds_802_11_led_ctrl));
599 spin_unlock_irqrestore(&priv->driver_lock, flags);
601 case CMD_RET(CMD_802_11_SUBSCRIBE_EVENT):
602 ret = lbs_ret_802_11_subscribe_event(priv, resp);
605 case CMD_RET(CMD_802_11_PWR_CFG):
606 spin_lock_irqsave(&priv->driver_lock, flags);
607 memmove(priv->cur_cmd->pdata_buf, &resp->params.pwrcfg,
608 sizeof(struct cmd_ds_802_11_pwr_cfg));
609 spin_unlock_irqrestore(&priv->driver_lock, flags);
613 case CMD_RET(CMD_GET_TSF):
614 spin_lock_irqsave(&priv->driver_lock, flags);
615 memcpy(priv->cur_cmd->pdata_buf,
616 &resp->params.gettsf.tsfvalue, sizeof(u64));
617 spin_unlock_irqrestore(&priv->driver_lock, flags);
619 case CMD_RET(CMD_BT_ACCESS):
620 spin_lock_irqsave(&priv->driver_lock, flags);
621 if (priv->cur_cmd->pdata_buf)
622 memcpy(priv->cur_cmd->pdata_buf,
623 &resp->params.bt.addr1, 2 * ETH_ALEN);
624 spin_unlock_irqrestore(&priv->driver_lock, flags);
626 case CMD_RET(CMD_FWT_ACCESS):
627 spin_lock_irqsave(&priv->driver_lock, flags);
628 if (priv->cur_cmd->pdata_buf)
629 memcpy(priv->cur_cmd->pdata_buf, &resp->params.fwt,
630 sizeof(resp->params.fwt));
631 spin_unlock_irqrestore(&priv->driver_lock, flags);
633 case CMD_RET(CMD_802_11_BEACON_CTRL):
634 ret = lbs_ret_802_11_bcn_ctrl(priv, resp);
638 lbs_deb_host("CMD_RESP: unknown cmd response 0x%04x\n",
642 lbs_deb_leave(LBS_DEB_HOST);
646 int lbs_process_rx_command(struct lbs_private *priv)
649 struct cmd_header *resp;
654 lbs_deb_enter(LBS_DEB_HOST);
656 /* Now we got response from FW, cancel the command timer */
657 del_timer(&priv->command_timer);
659 mutex_lock(&priv->lock);
660 spin_lock_irqsave(&priv->driver_lock, flags);
662 if (!priv->cur_cmd) {
663 lbs_deb_host("CMD_RESP: cur_cmd is NULL\n");
665 spin_unlock_irqrestore(&priv->driver_lock, flags);
668 resp = priv->cur_cmd->cmdbuf;
670 respcmd = le16_to_cpu(resp->command);
671 result = le16_to_cpu(resp->result);
673 lbs_deb_host("CMD_RESP: response 0x%04x, size %d, jiffies %lu\n",
674 respcmd, priv->upld_len, jiffies);
675 lbs_deb_hex(LBS_DEB_HOST, "CMD_RESP", (void *) resp, priv->upld_len);
677 if (!(respcmd & 0x8000)) {
678 lbs_deb_host("invalid response!\n");
679 priv->cur_cmd_retcode = -1;
680 __lbs_cleanup_and_insert_cmd(priv, priv->cur_cmd);
681 priv->cur_cmd = NULL;
682 spin_unlock_irqrestore(&priv->driver_lock, flags);
687 /* Store the response code to cur_cmd_retcode. */
688 priv->cur_cmd_retcode = result;
690 if (respcmd == CMD_RET(CMD_802_11_PS_MODE)) {
691 struct cmd_ds_802_11_ps_mode *psmode = (void *) resp;
692 u16 action = le16_to_cpu(psmode->action);
695 "CMD_RESP: PS_MODE cmd reply result 0x%x, action 0x%x\n",
699 lbs_deb_host("CMD_RESP: PS command failed with 0x%x\n",
702 * We should not re-try enter-ps command in
703 * ad-hoc mode. It takes place in
704 * lbs_execute_next_command().
706 if (priv->mode == IW_MODE_ADHOC &&
707 action == CMD_SUBCMD_ENTER_PS)
708 priv->psmode = LBS802_11POWERMODECAM;
709 } else if (action == CMD_SUBCMD_ENTER_PS) {
710 priv->needtowakeup = 0;
711 priv->psstate = PS_STATE_AWAKE;
713 lbs_deb_host("CMD_RESP: ENTER_PS command response\n");
714 if (priv->connect_status != LBS_CONNECTED) {
716 * When Deauth Event received before Enter_PS command
717 * response, We need to wake up the firmware.
720 "disconnected, invoking lbs_ps_wakeup\n");
722 spin_unlock_irqrestore(&priv->driver_lock, flags);
723 mutex_unlock(&priv->lock);
724 lbs_ps_wakeup(priv, 0);
725 mutex_lock(&priv->lock);
726 spin_lock_irqsave(&priv->driver_lock, flags);
728 } else if (action == CMD_SUBCMD_EXIT_PS) {
729 priv->needtowakeup = 0;
730 priv->psstate = PS_STATE_FULL_POWER;
731 lbs_deb_host("CMD_RESP: EXIT_PS command response\n");
733 lbs_deb_host("CMD_RESP: PS action 0x%X\n", action);
736 __lbs_cleanup_and_insert_cmd(priv, priv->cur_cmd);
737 priv->cur_cmd = NULL;
738 spin_unlock_irqrestore(&priv->driver_lock, flags);
744 /* If the command is not successful, cleanup and return failure */
745 if ((result != 0 || !(respcmd & 0x8000))) {
746 lbs_deb_host("CMD_RESP: error 0x%04x in command reply 0x%04x\n",
749 * Handling errors here
752 case CMD_RET(CMD_GET_HW_SPEC):
753 case CMD_RET(CMD_802_11_RESET):
754 lbs_deb_host("CMD_RESP: reset failed\n");
759 __lbs_cleanup_and_insert_cmd(priv, priv->cur_cmd);
760 priv->cur_cmd = NULL;
761 spin_unlock_irqrestore(&priv->driver_lock, flags);
767 spin_unlock_irqrestore(&priv->driver_lock, flags);
769 if (priv->cur_cmd && priv->cur_cmd->callback) {
770 ret = priv->cur_cmd->callback(priv, priv->cur_cmd->callback_arg,
773 ret = handle_cmd_response(priv, 0, resp);
775 spin_lock_irqsave(&priv->driver_lock, flags);
778 /* Clean up and Put current command back to cmdfreeq */
779 __lbs_cleanup_and_insert_cmd(priv, priv->cur_cmd);
780 priv->cur_cmd = NULL;
782 spin_unlock_irqrestore(&priv->driver_lock, flags);
785 mutex_unlock(&priv->lock);
786 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
790 int lbs_process_event(struct lbs_private *priv)
795 lbs_deb_enter(LBS_DEB_CMD);
797 spin_lock_irq(&priv->driver_lock);
798 eventcause = priv->eventcause >> SBI_EVENT_CAUSE_SHIFT;
799 spin_unlock_irq(&priv->driver_lock);
801 lbs_deb_cmd("event cause %d\n", eventcause);
803 switch (eventcause) {
804 case MACREG_INT_CODE_LINK_SENSED:
805 lbs_deb_cmd("EVENT: MACREG_INT_CODE_LINK_SENSED\n");
808 case MACREG_INT_CODE_DEAUTHENTICATED:
809 lbs_deb_cmd("EVENT: deauthenticated\n");
810 lbs_mac_event_disconnected(priv);
813 case MACREG_INT_CODE_DISASSOCIATED:
814 lbs_deb_cmd("EVENT: disassociated\n");
815 lbs_mac_event_disconnected(priv);
818 case MACREG_INT_CODE_LINK_LOST_NO_SCAN:
819 lbs_deb_cmd("EVENT: link lost\n");
820 lbs_mac_event_disconnected(priv);
823 case MACREG_INT_CODE_PS_SLEEP:
824 lbs_deb_cmd("EVENT: sleep\n");
826 /* handle unexpected PS SLEEP event */
827 if (priv->psstate == PS_STATE_FULL_POWER) {
829 "EVENT: in FULL POWER mode, ignoreing PS_SLEEP\n");
832 priv->psstate = PS_STATE_PRE_SLEEP;
834 lbs_ps_confirm_sleep(priv, (u16) priv->psmode);
838 case MACREG_INT_CODE_PS_AWAKE:
839 lbs_deb_cmd("EVENT: awake\n");
841 /* handle unexpected PS AWAKE event */
842 if (priv->psstate == PS_STATE_FULL_POWER) {
844 "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
848 priv->psstate = PS_STATE_AWAKE;
850 if (priv->needtowakeup) {
852 * wait for the command processing to finish
853 * before resuming sending
854 * priv->needtowakeup will be set to FALSE
857 lbs_deb_cmd("waking up ...\n");
858 lbs_ps_wakeup(priv, 0);
862 case MACREG_INT_CODE_MIC_ERR_UNICAST:
863 lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n");
864 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST);
867 case MACREG_INT_CODE_MIC_ERR_MULTICAST:
868 lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n");
869 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST);
871 case MACREG_INT_CODE_MIB_CHANGED:
872 case MACREG_INT_CODE_INIT_DONE:
875 case MACREG_INT_CODE_ADHOC_BCN_LOST:
876 lbs_deb_cmd("EVENT: ADHOC beacon lost\n");
879 case MACREG_INT_CODE_RSSI_LOW:
880 lbs_pr_alert("EVENT: rssi low\n");
882 case MACREG_INT_CODE_SNR_LOW:
883 lbs_pr_alert("EVENT: snr low\n");
885 case MACREG_INT_CODE_MAX_FAIL:
886 lbs_pr_alert("EVENT: max fail\n");
888 case MACREG_INT_CODE_RSSI_HIGH:
889 lbs_pr_alert("EVENT: rssi high\n");
891 case MACREG_INT_CODE_SNR_HIGH:
892 lbs_pr_alert("EVENT: snr high\n");
895 case MACREG_INT_CODE_MESH_AUTO_STARTED:
896 /* Ignore spurious autostart events if autostart is disabled */
897 if (!priv->mesh_autostart_enabled) {
898 lbs_pr_info("EVENT: MESH_AUTO_STARTED (ignoring)\n");
901 lbs_pr_info("EVENT: MESH_AUTO_STARTED\n");
902 priv->mesh_connect_status = LBS_CONNECTED;
903 if (priv->mesh_open == 1) {
904 netif_wake_queue(priv->mesh_dev);
905 netif_carrier_on(priv->mesh_dev);
907 priv->mode = IW_MODE_ADHOC;
908 schedule_work(&priv->sync_channel);
912 lbs_pr_alert("EVENT: unknown event id %d\n", eventcause);
916 spin_lock_irq(&priv->driver_lock);
917 priv->eventcause = 0;
918 spin_unlock_irq(&priv->driver_lock);
920 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);