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_get_hw_spec(struct lbs_private *priv,
149 struct cmd_ds_command *resp)
152 struct cmd_ds_get_hw_spec *hwspec = &resp->params.hwspec;
154 DECLARE_MAC_BUF(mac);
156 lbs_deb_enter(LBS_DEB_CMD);
158 priv->fwcapinfo = le32_to_cpu(hwspec->fwcapinfo);
160 memcpy(priv->fwreleasenumber, hwspec->fwreleasenumber, 4);
162 lbs_deb_cmd("GET_HW_SPEC: firmware release %u.%u.%up%u\n",
163 priv->fwreleasenumber[2], priv->fwreleasenumber[1],
164 priv->fwreleasenumber[0], priv->fwreleasenumber[3]);
165 lbs_deb_cmd("GET_HW_SPEC: MAC addr %s\n",
166 print_mac(mac, hwspec->permanentaddr));
167 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
168 hwspec->hwifversion, hwspec->version);
170 /* Clamp region code to 8-bit since FW spec indicates that it should
171 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
172 * returns non-zero high 8 bits here.
174 priv->regioncode = le16_to_cpu(hwspec->regioncode) & 0xFF;
176 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
177 /* use the region code to search for the index */
178 if (priv->regioncode == lbs_region_code_to_index[i]) {
183 /* if it's unidentified region code, use the default (USA) */
184 if (i >= MRVDRV_MAX_REGION_CODE) {
185 priv->regioncode = 0x10;
186 lbs_pr_info("unidentified region code; using the default (USA)\n");
189 if (priv->current_addr[0] == 0xff)
190 memmove(priv->current_addr, hwspec->permanentaddr, ETH_ALEN);
192 memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
194 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
196 if (lbs_set_regiontable(priv, priv->regioncode, 0)) {
201 if (lbs_set_universaltable(priv, 0)) {
207 lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret);
211 static int lbs_ret_802_11_sleep_params(struct lbs_private *priv,
212 struct cmd_ds_command *resp)
214 struct cmd_ds_802_11_sleep_params *sp = &resp->params.sleep_params;
216 lbs_deb_enter(LBS_DEB_CMD);
218 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, calcontrol 0x%x "
219 "extsleepclk 0x%x\n", le16_to_cpu(sp->error),
220 le16_to_cpu(sp->offset), le16_to_cpu(sp->stabletime),
221 sp->calcontrol, sp->externalsleepclk);
223 priv->sp.sp_error = le16_to_cpu(sp->error);
224 priv->sp.sp_offset = le16_to_cpu(sp->offset);
225 priv->sp.sp_stabletime = le16_to_cpu(sp->stabletime);
226 priv->sp.sp_calcontrol = sp->calcontrol;
227 priv->sp.sp_extsleepclk = sp->externalsleepclk;
228 priv->sp.sp_reserved = le16_to_cpu(sp->reserved);
230 lbs_deb_enter(LBS_DEB_CMD);
234 static int lbs_ret_802_11_stat(struct lbs_private *priv,
235 struct cmd_ds_command *resp)
237 lbs_deb_enter(LBS_DEB_CMD);
238 /* currently priv->wlan802_11Stat is unused
240 struct cmd_ds_802_11_get_stat *p11Stat = &resp->params.gstat;
242 // TODO Convert it to Big endian befor copy
243 memcpy(&priv->wlan802_11Stat,
244 p11Stat, sizeof(struct cmd_ds_802_11_get_stat));
246 lbs_deb_leave(LBS_DEB_CMD);
250 static int lbs_ret_802_11_snmp_mib(struct lbs_private *priv,
251 struct cmd_ds_command *resp)
253 struct cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
254 u16 oid = le16_to_cpu(smib->oid);
255 u16 querytype = le16_to_cpu(smib->querytype);
257 lbs_deb_enter(LBS_DEB_CMD);
259 lbs_deb_cmd("SNMP_RESP: oid 0x%x, querytype 0x%x\n", oid,
261 lbs_deb_cmd("SNMP_RESP: Buf size %d\n", le16_to_cpu(smib->bufsize));
263 if (querytype == CMD_ACT_GET) {
267 le16_to_cpu(*((__le16 *)(smib->value)));
268 lbs_deb_cmd("SNMP_RESP: frag threshold %u\n",
273 le16_to_cpu(*((__le16 *)(smib->value)));
274 lbs_deb_cmd("SNMP_RESP: rts threshold %u\n",
277 case SHORT_RETRYLIM_I:
279 le16_to_cpu(*((__le16 *)(smib->value)));
280 lbs_deb_cmd("SNMP_RESP: tx retry count %u\n",
288 lbs_deb_enter(LBS_DEB_CMD);
292 static int lbs_ret_802_11_key_material(struct lbs_private *priv,
293 struct cmd_ds_command *resp)
295 struct cmd_ds_802_11_key_material *pkeymaterial =
296 &resp->params.keymaterial;
297 u16 action = le16_to_cpu(pkeymaterial->action);
299 lbs_deb_enter(LBS_DEB_CMD);
301 /* Copy the returned key to driver private data */
302 if (action == CMD_ACT_GET) {
303 u8 * buf_ptr = (u8 *) &pkeymaterial->keyParamSet;
304 u8 * resp_end = (u8 *) (resp + le16_to_cpu(resp->size));
306 while (buf_ptr < resp_end) {
307 struct MrvlIEtype_keyParamSet * pkeyparamset =
308 (struct MrvlIEtype_keyParamSet *) buf_ptr;
309 struct enc_key * pkey;
310 u16 param_set_len = le16_to_cpu(pkeyparamset->length);
311 u16 key_len = le16_to_cpu(pkeyparamset->keylen);
312 u16 key_flags = le16_to_cpu(pkeyparamset->keyinfo);
313 u16 key_type = le16_to_cpu(pkeyparamset->keytypeid);
316 end = (u8 *) pkeyparamset + sizeof (pkeyparamset->type)
317 + sizeof (pkeyparamset->length)
319 /* Make sure we don't access past the end of the IEs */
323 if (key_flags & KEY_INFO_WPA_UNICAST)
324 pkey = &priv->wpa_unicast_key;
325 else if (key_flags & KEY_INFO_WPA_MCAST)
326 pkey = &priv->wpa_mcast_key;
330 /* Copy returned key into driver */
331 memset(pkey, 0, sizeof(struct enc_key));
332 if (key_len > sizeof(pkey->key))
334 pkey->type = key_type;
335 pkey->flags = key_flags;
337 memcpy(pkey->key, pkeyparamset->key, pkey->len);
343 lbs_deb_enter(LBS_DEB_CMD);
347 static int lbs_ret_802_11_mac_address(struct lbs_private *priv,
348 struct cmd_ds_command *resp)
350 struct cmd_ds_802_11_mac_address *macadd = &resp->params.macadd;
352 lbs_deb_enter(LBS_DEB_CMD);
354 memcpy(priv->current_addr, macadd->macadd, ETH_ALEN);
356 lbs_deb_enter(LBS_DEB_CMD);
360 static int lbs_ret_802_11_rf_tx_power(struct lbs_private *priv,
361 struct cmd_ds_command *resp)
363 struct cmd_ds_802_11_rf_tx_power *rtp = &resp->params.txp;
365 lbs_deb_enter(LBS_DEB_CMD);
367 priv->txpowerlevel = le16_to_cpu(rtp->currentlevel);
369 lbs_deb_cmd("TX power currently %d\n", priv->txpowerlevel);
371 lbs_deb_leave(LBS_DEB_CMD);
375 static int lbs_ret_802_11_rate_adapt_rateset(struct lbs_private *priv,
376 struct cmd_ds_command *resp)
378 struct cmd_ds_802_11_rate_adapt_rateset *rates = &resp->params.rateset;
380 lbs_deb_enter(LBS_DEB_CMD);
382 if (rates->action == CMD_ACT_GET) {
383 priv->enablehwauto = le16_to_cpu(rates->enablehwauto);
384 priv->ratebitmap = le16_to_cpu(rates->bitmap);
387 lbs_deb_leave(LBS_DEB_CMD);
391 static int lbs_ret_802_11_data_rate(struct lbs_private *priv,
392 struct cmd_ds_command *resp)
394 struct cmd_ds_802_11_data_rate *pdatarate = &resp->params.drate;
396 lbs_deb_enter(LBS_DEB_CMD);
398 lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) pdatarate,
399 sizeof(struct cmd_ds_802_11_data_rate));
401 /* FIXME: get actual rates FW can do if this command actually returns
402 * all data rates supported.
404 priv->cur_rate = lbs_fw_index_to_data_rate(pdatarate->rates[0]);
405 lbs_deb_cmd("DATA_RATE: current rate 0x%02x\n", priv->cur_rate);
407 lbs_deb_leave(LBS_DEB_CMD);
411 static int lbs_ret_802_11_rf_channel(struct lbs_private *priv,
412 struct cmd_ds_command *resp)
414 struct cmd_ds_802_11_rf_channel *rfchannel = &resp->params.rfchannel;
415 u16 action = le16_to_cpu(rfchannel->action);
416 u16 newchannel = le16_to_cpu(rfchannel->currentchannel);
418 lbs_deb_enter(LBS_DEB_CMD);
420 if (action == CMD_OPT_802_11_RF_CHANNEL_GET
421 && priv->curbssparams.channel != newchannel) {
422 lbs_deb_cmd("channel switch from %d to %d\n",
423 priv->curbssparams.channel, newchannel);
425 /* Update the channel again */
426 priv->curbssparams.channel = newchannel;
429 lbs_deb_enter(LBS_DEB_CMD);
433 static int lbs_ret_802_11_rssi(struct lbs_private *priv,
434 struct cmd_ds_command *resp)
436 struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp;
438 lbs_deb_enter(LBS_DEB_CMD);
440 /* store the non average value */
441 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR);
442 priv->NF[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->noisefloor);
444 priv->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR);
445 priv->NF[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgnoisefloor);
447 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] =
448 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
449 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
451 priv->RSSI[TYPE_BEACON][TYPE_AVG] =
452 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE,
453 priv->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE);
455 lbs_deb_cmd("RSSI: beacon %d, avg %d\n",
456 priv->RSSI[TYPE_BEACON][TYPE_NOAVG],
457 priv->RSSI[TYPE_BEACON][TYPE_AVG]);
459 lbs_deb_leave(LBS_DEB_CMD);
463 static int lbs_ret_802_11_eeprom_access(struct lbs_private *priv,
464 struct cmd_ds_command *resp)
466 struct lbs_ioctl_regrdwr *pbuf;
467 pbuf = (struct lbs_ioctl_regrdwr *) priv->prdeeprom;
469 lbs_deb_enter_args(LBS_DEB_CMD, "len %d",
470 le16_to_cpu(resp->params.rdeeprom.bytecount));
471 if (pbuf->NOB < le16_to_cpu(resp->params.rdeeprom.bytecount)) {
473 lbs_deb_cmd("EEPROM read length too big\n");
476 pbuf->NOB = le16_to_cpu(resp->params.rdeeprom.bytecount);
479 memcpy(&pbuf->value, (u8 *) & resp->params.rdeeprom.value,
480 le16_to_cpu(resp->params.rdeeprom.bytecount));
481 lbs_deb_hex(LBS_DEB_CMD, "EEPROM", (char *)&pbuf->value,
482 le16_to_cpu(resp->params.rdeeprom.bytecount));
484 lbs_deb_leave(LBS_DEB_CMD);
488 static int lbs_ret_get_log(struct lbs_private *priv,
489 struct cmd_ds_command *resp)
491 struct cmd_ds_802_11_get_log *logmessage = &resp->params.glog;
493 lbs_deb_enter(LBS_DEB_CMD);
495 /* Stored little-endian */
496 memcpy(&priv->logmsg, logmessage, sizeof(struct cmd_ds_802_11_get_log));
498 lbs_deb_leave(LBS_DEB_CMD);
502 static int lbs_ret_802_11_enable_rsn(struct lbs_private *priv,
503 struct cmd_ds_command *resp)
505 struct cmd_ds_802_11_enable_rsn *enable_rsn = &resp->params.enbrsn;
506 u32 * pdata_buf = priv->cur_cmd->pdata_buf;
508 lbs_deb_enter(LBS_DEB_CMD);
510 if (enable_rsn->action == cpu_to_le16(CMD_ACT_GET)) {
512 *pdata_buf = (u32) le16_to_cpu(enable_rsn->enable);
515 lbs_deb_leave(LBS_DEB_CMD);
519 static int lbs_ret_802_11_bcn_ctrl(struct lbs_private * priv,
520 struct cmd_ds_command *resp)
522 struct cmd_ds_802_11_beacon_control *bcn_ctrl =
523 &resp->params.bcn_ctrl;
525 lbs_deb_enter(LBS_DEB_CMD);
527 if (bcn_ctrl->action == CMD_ACT_GET) {
528 priv->beacon_enable = (u8) le16_to_cpu(bcn_ctrl->beacon_enable);
529 priv->beacon_period = le16_to_cpu(bcn_ctrl->beacon_period);
532 lbs_deb_enter(LBS_DEB_CMD);
536 static int lbs_ret_802_11_subscribe_event(struct lbs_private *priv,
537 struct cmd_ds_command *resp)
539 struct cmd_ds_802_11_subscribe_event *cmd_event =
540 &resp->params.subscribe_event;
541 struct cmd_ds_802_11_subscribe_event *dst_event =
542 priv->cur_cmd->pdata_buf;
544 lbs_deb_enter(LBS_DEB_CMD);
546 if (dst_event->action == cpu_to_le16(CMD_ACT_GET)) {
547 dst_event->events = cmd_event->events;
548 memcpy(dst_event->tlv, cmd_event->tlv, sizeof(dst_event->tlv));
551 lbs_deb_leave(LBS_DEB_CMD);
555 static inline int handle_cmd_response(u16 respcmd,
556 struct cmd_ds_command *resp,
557 struct lbs_private *priv)
562 lbs_deb_enter(LBS_DEB_HOST);
565 case CMD_RET(CMD_MAC_REG_ACCESS):
566 case CMD_RET(CMD_BBP_REG_ACCESS):
567 case CMD_RET(CMD_RF_REG_ACCESS):
568 ret = lbs_ret_reg_access(priv, respcmd, resp);
571 case CMD_RET(CMD_GET_HW_SPEC):
572 ret = lbs_ret_get_hw_spec(priv, resp);
575 case CMD_RET(CMD_802_11_SCAN):
576 ret = lbs_ret_80211_scan(priv, resp);
579 case CMD_RET(CMD_802_11_GET_LOG):
580 ret = lbs_ret_get_log(priv, resp);
583 case CMD_RET_802_11_ASSOCIATE:
584 case CMD_RET(CMD_802_11_ASSOCIATE):
585 case CMD_RET(CMD_802_11_REASSOCIATE):
586 ret = lbs_ret_80211_associate(priv, resp);
589 case CMD_RET(CMD_802_11_DISASSOCIATE):
590 case CMD_RET(CMD_802_11_DEAUTHENTICATE):
591 ret = lbs_ret_80211_disassociate(priv, resp);
594 case CMD_RET(CMD_802_11_AD_HOC_START):
595 case CMD_RET(CMD_802_11_AD_HOC_JOIN):
596 ret = lbs_ret_80211_ad_hoc_start(priv, resp);
599 case CMD_RET(CMD_802_11_GET_STAT):
600 ret = lbs_ret_802_11_stat(priv, resp);
603 case CMD_RET(CMD_802_11_SNMP_MIB):
604 ret = lbs_ret_802_11_snmp_mib(priv, resp);
607 case CMD_RET(CMD_802_11_RF_TX_POWER):
608 ret = lbs_ret_802_11_rf_tx_power(priv, resp);
611 case CMD_RET(CMD_802_11_SET_AFC):
612 case CMD_RET(CMD_802_11_GET_AFC):
613 spin_lock_irqsave(&priv->driver_lock, flags);
614 memmove(priv->cur_cmd->pdata_buf, &resp->params.afc,
615 sizeof(struct cmd_ds_802_11_afc));
616 spin_unlock_irqrestore(&priv->driver_lock, flags);
620 case CMD_RET(CMD_MAC_MULTICAST_ADR):
621 case CMD_RET(CMD_MAC_CONTROL):
622 case CMD_RET(CMD_802_11_SET_WEP):
623 case CMD_RET(CMD_802_11_RESET):
624 case CMD_RET(CMD_802_11_AUTHENTICATE):
625 case CMD_RET(CMD_802_11_RADIO_CONTROL):
626 case CMD_RET(CMD_802_11_BEACON_STOP):
629 case CMD_RET(CMD_802_11_ENABLE_RSN):
630 ret = lbs_ret_802_11_enable_rsn(priv, resp);
633 case CMD_RET(CMD_802_11_DATA_RATE):
634 ret = lbs_ret_802_11_data_rate(priv, resp);
636 case CMD_RET(CMD_802_11_RATE_ADAPT_RATESET):
637 ret = lbs_ret_802_11_rate_adapt_rateset(priv, resp);
639 case CMD_RET(CMD_802_11_RF_CHANNEL):
640 ret = lbs_ret_802_11_rf_channel(priv, resp);
643 case CMD_RET(CMD_802_11_RSSI):
644 ret = lbs_ret_802_11_rssi(priv, resp);
647 case CMD_RET(CMD_802_11_MAC_ADDRESS):
648 ret = lbs_ret_802_11_mac_address(priv, resp);
651 case CMD_RET(CMD_802_11_AD_HOC_STOP):
652 ret = lbs_ret_80211_ad_hoc_stop(priv, resp);
655 case CMD_RET(CMD_802_11_KEY_MATERIAL):
656 ret = lbs_ret_802_11_key_material(priv, resp);
659 case CMD_RET(CMD_802_11_EEPROM_ACCESS):
660 ret = lbs_ret_802_11_eeprom_access(priv, resp);
663 case CMD_RET(CMD_802_11D_DOMAIN_INFO):
664 ret = lbs_ret_802_11d_domain_info(priv, resp);
667 case CMD_RET(CMD_802_11_SLEEP_PARAMS):
668 ret = lbs_ret_802_11_sleep_params(priv, resp);
670 case CMD_RET(CMD_802_11_INACTIVITY_TIMEOUT):
671 spin_lock_irqsave(&priv->driver_lock, flags);
672 *((u16 *) priv->cur_cmd->pdata_buf) =
673 le16_to_cpu(resp->params.inactivity_timeout.timeout);
674 spin_unlock_irqrestore(&priv->driver_lock, flags);
677 case CMD_RET(CMD_802_11_TPC_CFG):
678 spin_lock_irqsave(&priv->driver_lock, flags);
679 memmove(priv->cur_cmd->pdata_buf, &resp->params.tpccfg,
680 sizeof(struct cmd_ds_802_11_tpc_cfg));
681 spin_unlock_irqrestore(&priv->driver_lock, flags);
683 case CMD_RET(CMD_802_11_LED_GPIO_CTRL):
684 spin_lock_irqsave(&priv->driver_lock, flags);
685 memmove(priv->cur_cmd->pdata_buf, &resp->params.ledgpio,
686 sizeof(struct cmd_ds_802_11_led_ctrl));
687 spin_unlock_irqrestore(&priv->driver_lock, flags);
689 case CMD_RET(CMD_802_11_SUBSCRIBE_EVENT):
690 ret = lbs_ret_802_11_subscribe_event(priv, resp);
693 case CMD_RET(CMD_802_11_PWR_CFG):
694 spin_lock_irqsave(&priv->driver_lock, flags);
695 memmove(priv->cur_cmd->pdata_buf, &resp->params.pwrcfg,
696 sizeof(struct cmd_ds_802_11_pwr_cfg));
697 spin_unlock_irqrestore(&priv->driver_lock, flags);
701 case CMD_RET(CMD_GET_TSF):
702 spin_lock_irqsave(&priv->driver_lock, flags);
703 memcpy(priv->cur_cmd->pdata_buf,
704 &resp->params.gettsf.tsfvalue, sizeof(u64));
705 spin_unlock_irqrestore(&priv->driver_lock, flags);
707 case CMD_RET(CMD_BT_ACCESS):
708 spin_lock_irqsave(&priv->driver_lock, flags);
709 if (priv->cur_cmd->pdata_buf)
710 memcpy(priv->cur_cmd->pdata_buf,
711 &resp->params.bt.addr1, 2 * ETH_ALEN);
712 spin_unlock_irqrestore(&priv->driver_lock, flags);
714 case CMD_RET(CMD_FWT_ACCESS):
715 spin_lock_irqsave(&priv->driver_lock, flags);
716 if (priv->cur_cmd->pdata_buf)
717 memcpy(priv->cur_cmd->pdata_buf, &resp->params.fwt,
718 sizeof(resp->params.fwt));
719 spin_unlock_irqrestore(&priv->driver_lock, flags);
721 case CMD_RET(CMD_MESH_ACCESS):
722 if (priv->cur_cmd->pdata_buf)
723 memcpy(priv->cur_cmd->pdata_buf, &resp->params.mesh,
724 sizeof(resp->params.mesh));
726 case CMD_RET(CMD_802_11_BEACON_CTRL):
727 ret = lbs_ret_802_11_bcn_ctrl(priv, resp);
731 lbs_deb_host("CMD_RESP: unknown cmd response 0x%04x\n",
735 lbs_deb_leave(LBS_DEB_HOST);
739 int lbs_process_rx_command(struct lbs_private *priv)
742 struct cmd_ds_command *resp;
747 lbs_deb_enter(LBS_DEB_HOST);
749 /* Now we got response from FW, cancel the command timer */
750 del_timer(&priv->command_timer);
752 mutex_lock(&priv->lock);
753 spin_lock_irqsave(&priv->driver_lock, flags);
755 if (!priv->cur_cmd) {
756 lbs_deb_host("CMD_RESP: cur_cmd is NULL\n");
758 spin_unlock_irqrestore(&priv->driver_lock, flags);
761 resp = (struct cmd_ds_command *)(priv->cur_cmd->bufvirtualaddr);
763 respcmd = le16_to_cpu(resp->command);
764 result = le16_to_cpu(resp->result);
766 lbs_deb_host("CMD_RESP: response 0x%04x, size %d, jiffies %lu\n",
767 respcmd, priv->upld_len, jiffies);
768 lbs_deb_hex(LBS_DEB_HOST, "CMD_RESP", priv->cur_cmd->bufvirtualaddr,
771 if (!(respcmd & 0x8000)) {
772 lbs_deb_host("invalid response!\n");
773 priv->cur_cmd_retcode = -1;
774 __lbs_cleanup_and_insert_cmd(priv, priv->cur_cmd);
775 priv->cur_cmd = NULL;
776 spin_unlock_irqrestore(&priv->driver_lock, flags);
781 /* Store the response code to cur_cmd_retcode. */
782 priv->cur_cmd_retcode = result;
784 if (respcmd == CMD_RET(CMD_802_11_PS_MODE)) {
785 struct cmd_ds_802_11_ps_mode *psmode = &resp->params.psmode;
786 u16 action = le16_to_cpu(psmode->action);
789 "CMD_RESP: PS_MODE cmd reply result 0x%x, action 0x%x\n",
793 lbs_deb_host("CMD_RESP: PS command failed with 0x%x\n",
796 * We should not re-try enter-ps command in
797 * ad-hoc mode. It takes place in
798 * lbs_execute_next_command().
800 if (priv->mode == IW_MODE_ADHOC &&
801 action == CMD_SUBCMD_ENTER_PS)
802 priv->psmode = LBS802_11POWERMODECAM;
803 } else if (action == CMD_SUBCMD_ENTER_PS) {
804 priv->needtowakeup = 0;
805 priv->psstate = PS_STATE_AWAKE;
807 lbs_deb_host("CMD_RESP: ENTER_PS command response\n");
808 if (priv->connect_status != LBS_CONNECTED) {
810 * When Deauth Event received before Enter_PS command
811 * response, We need to wake up the firmware.
814 "disconnected, invoking lbs_ps_wakeup\n");
816 spin_unlock_irqrestore(&priv->driver_lock, flags);
817 mutex_unlock(&priv->lock);
818 lbs_ps_wakeup(priv, 0);
819 mutex_lock(&priv->lock);
820 spin_lock_irqsave(&priv->driver_lock, flags);
822 } else if (action == CMD_SUBCMD_EXIT_PS) {
823 priv->needtowakeup = 0;
824 priv->psstate = PS_STATE_FULL_POWER;
825 lbs_deb_host("CMD_RESP: EXIT_PS command response\n");
827 lbs_deb_host("CMD_RESP: PS action 0x%X\n", action);
830 __lbs_cleanup_and_insert_cmd(priv, priv->cur_cmd);
831 priv->cur_cmd = NULL;
832 spin_unlock_irqrestore(&priv->driver_lock, flags);
838 /* If the command is not successful, cleanup and return failure */
839 if ((result != 0 || !(respcmd & 0x8000))) {
840 lbs_deb_host("CMD_RESP: error 0x%04x in command reply 0x%04x\n",
843 * Handling errors here
846 case CMD_RET(CMD_GET_HW_SPEC):
847 case CMD_RET(CMD_802_11_RESET):
848 lbs_deb_host("CMD_RESP: reset failed\n");
853 __lbs_cleanup_and_insert_cmd(priv, priv->cur_cmd);
854 priv->cur_cmd = NULL;
855 spin_unlock_irqrestore(&priv->driver_lock, flags);
861 spin_unlock_irqrestore(&priv->driver_lock, flags);
863 if (priv->cur_cmd && priv->cur_cmd->callback)
864 ret = priv->cur_cmd->callback(respcmd, resp, priv);
866 ret = handle_cmd_response(respcmd, resp, priv);
868 spin_lock_irqsave(&priv->driver_lock, flags);
871 /* Clean up and Put current command back to cmdfreeq */
872 __lbs_cleanup_and_insert_cmd(priv, priv->cur_cmd);
873 priv->cur_cmd = NULL;
875 spin_unlock_irqrestore(&priv->driver_lock, flags);
878 mutex_unlock(&priv->lock);
879 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
883 int lbs_process_event(struct lbs_private *priv)
888 lbs_deb_enter(LBS_DEB_CMD);
890 spin_lock_irq(&priv->driver_lock);
891 eventcause = priv->eventcause >> SBI_EVENT_CAUSE_SHIFT;
892 spin_unlock_irq(&priv->driver_lock);
894 lbs_deb_cmd("event cause %d\n", eventcause);
896 switch (eventcause) {
897 case MACREG_INT_CODE_LINK_SENSED:
898 lbs_deb_cmd("EVENT: MACREG_INT_CODE_LINK_SENSED\n");
901 case MACREG_INT_CODE_DEAUTHENTICATED:
902 lbs_deb_cmd("EVENT: deauthenticated\n");
903 lbs_mac_event_disconnected(priv);
906 case MACREG_INT_CODE_DISASSOCIATED:
907 lbs_deb_cmd("EVENT: disassociated\n");
908 lbs_mac_event_disconnected(priv);
911 case MACREG_INT_CODE_LINK_LOST_NO_SCAN:
912 lbs_deb_cmd("EVENT: link lost\n");
913 lbs_mac_event_disconnected(priv);
916 case MACREG_INT_CODE_PS_SLEEP:
917 lbs_deb_cmd("EVENT: sleep\n");
919 /* handle unexpected PS SLEEP event */
920 if (priv->psstate == PS_STATE_FULL_POWER) {
922 "EVENT: in FULL POWER mode, ignoreing PS_SLEEP\n");
925 priv->psstate = PS_STATE_PRE_SLEEP;
927 lbs_ps_confirm_sleep(priv, (u16) priv->psmode);
931 case MACREG_INT_CODE_PS_AWAKE:
932 lbs_deb_cmd("EVENT: awake\n");
934 /* handle unexpected PS AWAKE event */
935 if (priv->psstate == PS_STATE_FULL_POWER) {
937 "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
941 priv->psstate = PS_STATE_AWAKE;
943 if (priv->needtowakeup) {
945 * wait for the command processing to finish
946 * before resuming sending
947 * priv->needtowakeup will be set to FALSE
950 lbs_deb_cmd("waking up ...\n");
951 lbs_ps_wakeup(priv, 0);
955 case MACREG_INT_CODE_MIC_ERR_UNICAST:
956 lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n");
957 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST);
960 case MACREG_INT_CODE_MIC_ERR_MULTICAST:
961 lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n");
962 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST);
964 case MACREG_INT_CODE_MIB_CHANGED:
965 case MACREG_INT_CODE_INIT_DONE:
968 case MACREG_INT_CODE_ADHOC_BCN_LOST:
969 lbs_deb_cmd("EVENT: ADHOC beacon lost\n");
972 case MACREG_INT_CODE_RSSI_LOW:
973 lbs_pr_alert("EVENT: rssi low\n");
975 case MACREG_INT_CODE_SNR_LOW:
976 lbs_pr_alert("EVENT: snr low\n");
978 case MACREG_INT_CODE_MAX_FAIL:
979 lbs_pr_alert("EVENT: max fail\n");
981 case MACREG_INT_CODE_RSSI_HIGH:
982 lbs_pr_alert("EVENT: rssi high\n");
984 case MACREG_INT_CODE_SNR_HIGH:
985 lbs_pr_alert("EVENT: snr high\n");
988 case MACREG_INT_CODE_MESH_AUTO_STARTED:
989 /* Ignore spurious autostart events if autostart is disabled */
990 if (!priv->mesh_autostart_enabled) {
991 lbs_pr_info("EVENT: MESH_AUTO_STARTED (ignoring)\n");
994 lbs_pr_info("EVENT: MESH_AUTO_STARTED\n");
995 priv->mesh_connect_status = LBS_CONNECTED;
996 if (priv->mesh_open == 1) {
997 netif_wake_queue(priv->mesh_dev);
998 netif_carrier_on(priv->mesh_dev);
1000 priv->mode = IW_MODE_ADHOC;
1001 schedule_work(&priv->sync_channel);
1005 lbs_pr_alert("EVENT: unknown event id %d\n", eventcause);
1009 spin_lock_irq(&priv->driver_lock);
1010 priv->eventcause = 0;
1011 spin_unlock_irq(&priv->driver_lock);
1013 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);