cmdresp.c 18.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/**
  * This file contains the handling of command
  * responses as well as events generated by firmware.
  */
#include <linux/delay.h>
#include <linux/if_arp.h>
#include <linux/netdevice.h>

#include <net/iw_handler.h>

#include "host.h"
#include "decl.h"
#include "defs.h"
#include "dev.h"
15
#include "assoc.h"
16 17 18 19 20 21 22
#include "wext.h"

/**
 *  @brief This function handles disconnect event. it
 *  reports disconnect to upper layer, clean tx/rx packets,
 *  reset link state etc.
 *
23
 *  @param priv    A pointer to struct lbs_private structure
24 25
 *  @return 	   n/a
 */
26
void lbs_mac_event_disconnected(struct lbs_private *priv)
27 28 29
{
	union iwreq_data wrqu;

30
	if (priv->connect_status != LBS_CONNECTED)
31 32
		return;

33
	lbs_deb_enter(LBS_DEB_ASSOC);
34 35 36 37 38 39 40 41 42 43

	memset(wrqu.ap_addr.sa_data, 0x00, ETH_ALEN);
	wrqu.ap_addr.sa_family = ARPHRD_ETHER;

	/*
	 * Cisco AP sends EAP failure and de-auth in less than 0.5 ms.
	 * It causes problem in the Supplicant
	 */

	msleep_interruptible(1000);
44
	wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
45 46

	/* report disconnect to upper layer */
47 48
	netif_stop_queue(priv->dev);
	netif_carrier_off(priv->dev);
49

50 51 52 53 54
	/* Free Tx and Rx packets */
	kfree_skb(priv->currenttxskb);
	priv->currenttxskb = NULL;
	priv->tx_pending_len = 0;

55
	/* reset SNR/NF/RSSI values */
56 57 58 59 60 61 62 63
	memset(priv->SNR, 0x00, sizeof(priv->SNR));
	memset(priv->NF, 0x00, sizeof(priv->NF));
	memset(priv->RSSI, 0x00, sizeof(priv->RSSI));
	memset(priv->rawSNR, 0x00, sizeof(priv->rawSNR));
	memset(priv->rawNF, 0x00, sizeof(priv->rawNF));
	priv->nextSNRNF = 0;
	priv->numSNRNF = 0;
	priv->connect_status = LBS_DISCONNECTED;
64

65 66 67
	/* Clear out associated SSID and BSSID since connection is
	 * no longer valid.
	 */
68 69 70
	memset(&priv->curbssparams.bssid, 0, ETH_ALEN);
	memset(&priv->curbssparams.ssid, 0, IW_ESSID_MAX_SIZE);
	priv->curbssparams.ssid_len = 0;
71

72
	if (priv->psstate != PS_STATE_FULL_POWER) {
73
		/* make firmware to exit PS mode */
74
		lbs_deb_cmd("disconnected, so exit PS mode\n");
75
		lbs_ps_wakeup(priv, 0);
76
	}
77
	lbs_deb_leave(LBS_DEB_ASSOC);
78 79 80 81 82
}

/**
 *  @brief This function handles MIC failure event.
 *
83
 *  @param priv    A pointer to struct lbs_private structure
84 85 86
 *  @para  event   the event id
 *  @return 	   n/a
 */
87
static void handle_mic_failureevent(struct lbs_private *priv, u32 event)
88 89 90
{
	char buf[50];

91
	lbs_deb_enter(LBS_DEB_CMD);
92 93 94 95 96 97 98 99 100 101
	memset(buf, 0, sizeof(buf));

	sprintf(buf, "%s", "MLME-MICHAELMICFAILURE.indication ");

	if (event == MACREG_INT_CODE_MIC_ERR_UNICAST) {
		strcat(buf, "unicast ");
	} else {
		strcat(buf, "multicast ");
	}

102
	lbs_send_iwevcustom_event(priv, buf);
103
	lbs_deb_leave(LBS_DEB_CMD);
104 105
}

106
static int lbs_ret_reg_access(struct lbs_private *priv,
107 108
			       u16 type, struct cmd_ds_command *resp)
{
109
	int ret = 0;
110

111
	lbs_deb_enter(LBS_DEB_CMD);
112 113

	switch (type) {
114
	case CMD_RET(CMD_MAC_REG_ACCESS):
115
		{
116
			struct cmd_ds_mac_reg_access *reg = &resp->params.macreg;
117

118 119
			priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
			priv->offsetvalue.value = le32_to_cpu(reg->value);
120 121 122
			break;
		}

123
	case CMD_RET(CMD_BBP_REG_ACCESS):
124
		{
125
			struct cmd_ds_bbp_reg_access *reg = &resp->params.bbpreg;
126

127 128
			priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
			priv->offsetvalue.value = reg->value;
129 130 131
			break;
		}

132
	case CMD_RET(CMD_RF_REG_ACCESS):
133
		{
134
			struct cmd_ds_rf_reg_access *reg = &resp->params.rfreg;
135

136 137
			priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
			priv->offsetvalue.value = reg->value;
138 139 140 141
			break;
		}

	default:
142
		ret = -1;
143 144
	}

145
	lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
146
	return ret;
147 148
}

149
static int lbs_ret_802_11_snmp_mib(struct lbs_private *priv,
150 151 152 153 154 155
				    struct cmd_ds_command *resp)
{
	struct cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
	u16 oid = le16_to_cpu(smib->oid);
	u16 querytype = le16_to_cpu(smib->querytype);

156
	lbs_deb_enter(LBS_DEB_CMD);
157

158
	lbs_deb_cmd("SNMP_RESP: oid 0x%x, querytype 0x%x\n", oid,
159
	       querytype);
160
	lbs_deb_cmd("SNMP_RESP: Buf size %d\n", le16_to_cpu(smib->bufsize));
161

162
	if (querytype == CMD_ACT_GET) {
163
		switch (oid) {
164
		case FRAGTHRESH_I:
165
			priv->fragthsd =
166
				le16_to_cpu(*((__le16 *)(smib->value)));
167
			lbs_deb_cmd("SNMP_RESP: frag threshold %u\n",
168
				    priv->fragthsd);
169
			break;
170
		case RTSTHRESH_I:
171
			priv->rtsthsd =
172
				le16_to_cpu(*((__le16 *)(smib->value)));
173
			lbs_deb_cmd("SNMP_RESP: rts threshold %u\n",
174
				    priv->rtsthsd);
175
			break;
176
		case SHORT_RETRYLIM_I:
177
			priv->txretrycount =
178
				le16_to_cpu(*((__le16 *)(smib->value)));
179
			lbs_deb_cmd("SNMP_RESP: tx retry count %u\n",
180
				    priv->rtsthsd);
181 182 183 184 185 186
			break;
		default:
			break;
		}
	}

187
	lbs_deb_enter(LBS_DEB_CMD);
188 189 190
	return 0;
}

191
static int lbs_ret_802_11_rf_tx_power(struct lbs_private *priv,
192 193 194 195
				       struct cmd_ds_command *resp)
{
	struct cmd_ds_802_11_rf_tx_power *rtp = &resp->params.txp;

196
	lbs_deb_enter(LBS_DEB_CMD);
197

198
	priv->txpowerlevel = le16_to_cpu(rtp->currentlevel);
199

200
	lbs_deb_cmd("TX power currently %d\n", priv->txpowerlevel);
201

202
	lbs_deb_leave(LBS_DEB_CMD);
203 204 205
	return 0;
}

206
static int lbs_ret_802_11_rate_adapt_rateset(struct lbs_private *priv,
207 208
					      struct cmd_ds_command *resp)
{
209
	struct cmd_ds_802_11_rate_adapt_rateset *rates = &resp->params.rateset;
210

211
	lbs_deb_enter(LBS_DEB_CMD);
212

213
	if (rates->action == CMD_ACT_GET) {
214 215
		priv->enablehwauto = le16_to_cpu(rates->enablehwauto);
		priv->ratebitmap = le16_to_cpu(rates->bitmap);
216 217
	}

218
	lbs_deb_leave(LBS_DEB_CMD);
219 220 221
	return 0;
}

222
static int lbs_ret_802_11_rssi(struct lbs_private *priv,
223 224 225 226
				struct cmd_ds_command *resp)
{
	struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp;

227 228
	lbs_deb_enter(LBS_DEB_CMD);

229
	/* store the non average value */
230 231
	priv->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR);
	priv->NF[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->noisefloor);
232

233 234
	priv->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR);
	priv->NF[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgnoisefloor);
235

236 237 238
	priv->RSSI[TYPE_BEACON][TYPE_NOAVG] =
	    CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
		     priv->NF[TYPE_BEACON][TYPE_NOAVG]);
239

240 241 242
	priv->RSSI[TYPE_BEACON][TYPE_AVG] =
	    CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE,
		     priv->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE);
243

244
	lbs_deb_cmd("RSSI: beacon %d, avg %d\n",
245 246
	       priv->RSSI[TYPE_BEACON][TYPE_NOAVG],
	       priv->RSSI[TYPE_BEACON][TYPE_AVG]);
247

248
	lbs_deb_leave(LBS_DEB_CMD);
249 250 251
	return 0;
}

252 253 254 255 256 257 258 259 260
static int lbs_ret_802_11_bcn_ctrl(struct lbs_private * priv,
					struct cmd_ds_command *resp)
{
	struct cmd_ds_802_11_beacon_control *bcn_ctrl =
	    &resp->params.bcn_ctrl;

	lbs_deb_enter(LBS_DEB_CMD);

	if (bcn_ctrl->action == CMD_ACT_GET) {
261 262
		priv->beacon_enable = (u8) le16_to_cpu(bcn_ctrl->beacon_enable);
		priv->beacon_period = le16_to_cpu(bcn_ctrl->beacon_period);
263 264 265 266 267 268
	}

	lbs_deb_enter(LBS_DEB_CMD);
	return 0;
}

269
static inline int handle_cmd_response(struct lbs_private *priv,
270
				      struct cmd_header *cmd_response)
271
{
272
	struct cmd_ds_command *resp = (struct cmd_ds_command *) cmd_response;
273 274
	int ret = 0;
	unsigned long flags;
275
	uint16_t respcmd = le16_to_cpu(resp->command);
276

277 278
	lbs_deb_enter(LBS_DEB_HOST);

279
	switch (respcmd) {
280 281 282
	case CMD_RET(CMD_MAC_REG_ACCESS):
	case CMD_RET(CMD_BBP_REG_ACCESS):
	case CMD_RET(CMD_RF_REG_ACCESS):
283
		ret = lbs_ret_reg_access(priv, respcmd, resp);
284 285
		break;

286
	case CMD_RET_802_11_ASSOCIATE:
287 288
	case CMD_RET(CMD_802_11_ASSOCIATE):
	case CMD_RET(CMD_802_11_REASSOCIATE):
289
		ret = lbs_ret_80211_associate(priv, resp);
290 291
		break;

292 293
	case CMD_RET(CMD_802_11_DISASSOCIATE):
	case CMD_RET(CMD_802_11_DEAUTHENTICATE):
294
		ret = lbs_ret_80211_disassociate(priv);
295 296
		break;

297 298
	case CMD_RET(CMD_802_11_AD_HOC_START):
	case CMD_RET(CMD_802_11_AD_HOC_JOIN):
299
		ret = lbs_ret_80211_ad_hoc_start(priv, resp);
300 301
		break;

302
	case CMD_RET(CMD_802_11_SNMP_MIB):
303
		ret = lbs_ret_802_11_snmp_mib(priv, resp);
304 305
		break;

306
	case CMD_RET(CMD_802_11_RF_TX_POWER):
307
		ret = lbs_ret_802_11_rf_tx_power(priv, resp);
308 309
		break;

310 311
	case CMD_RET(CMD_802_11_SET_AFC):
	case CMD_RET(CMD_802_11_GET_AFC):
312
		spin_lock_irqsave(&priv->driver_lock, flags);
313
		memmove((void *)priv->cur_cmd->callback_arg, &resp->params.afc,
314
			sizeof(struct cmd_ds_802_11_afc));
315
		spin_unlock_irqrestore(&priv->driver_lock, flags);
316 317 318

		break;

319 320 321 322
	case CMD_RET(CMD_MAC_MULTICAST_ADR):
	case CMD_RET(CMD_802_11_RESET):
	case CMD_RET(CMD_802_11_AUTHENTICATE):
	case CMD_RET(CMD_802_11_BEACON_STOP):
323 324
		break;

325
	case CMD_RET(CMD_802_11_RATE_ADAPT_RATESET):
326
		ret = lbs_ret_802_11_rate_adapt_rateset(priv, resp);
327 328
		break;

329
	case CMD_RET(CMD_802_11_RSSI):
330
		ret = lbs_ret_802_11_rssi(priv, resp);
331 332
		break;

333
	case CMD_RET(CMD_802_11_AD_HOC_STOP):
334
		ret = lbs_ret_80211_ad_hoc_stop(priv);
335 336
		break;

337
	case CMD_RET(CMD_802_11D_DOMAIN_INFO):
338
		ret = lbs_ret_802_11d_domain_info(resp);
339 340
		break;

341
	case CMD_RET(CMD_802_11_TPC_CFG):
342
		spin_lock_irqsave(&priv->driver_lock, flags);
343
		memmove((void *)priv->cur_cmd->callback_arg, &resp->params.tpccfg,
344
			sizeof(struct cmd_ds_802_11_tpc_cfg));
345
		spin_unlock_irqrestore(&priv->driver_lock, flags);
346
		break;
347
	case CMD_RET(CMD_802_11_LED_GPIO_CTRL):
348
		spin_lock_irqsave(&priv->driver_lock, flags);
349
		memmove((void *)priv->cur_cmd->callback_arg, &resp->params.ledgpio,
350
			sizeof(struct cmd_ds_802_11_led_ctrl));
351
		spin_unlock_irqrestore(&priv->driver_lock, flags);
352
		break;
353

354
	case CMD_RET(CMD_GET_TSF):
355
		spin_lock_irqsave(&priv->driver_lock, flags);
356
		memcpy((void *)priv->cur_cmd->callback_arg,
357
		       &resp->params.gettsf.tsfvalue, sizeof(u64));
358
		spin_unlock_irqrestore(&priv->driver_lock, flags);
359
		break;
360
	case CMD_RET(CMD_BT_ACCESS):
361
		spin_lock_irqsave(&priv->driver_lock, flags);
362 363
		if (priv->cur_cmd->callback_arg)
			memcpy((void *)priv->cur_cmd->callback_arg,
364
			       &resp->params.bt.addr1, 2 * ETH_ALEN);
365
		spin_unlock_irqrestore(&priv->driver_lock, flags);
366
		break;
367
	case CMD_RET(CMD_FWT_ACCESS):
368
		spin_lock_irqsave(&priv->driver_lock, flags);
369 370
		if (priv->cur_cmd->callback_arg)
			memcpy((void *)priv->cur_cmd->callback_arg, &resp->params.fwt,
371
			       sizeof(resp->params.fwt));
372
		spin_unlock_irqrestore(&priv->driver_lock, flags);
373
		break;
374 375 376 377
	case CMD_RET(CMD_802_11_BEACON_CTRL):
		ret = lbs_ret_802_11_bcn_ctrl(priv, resp);
		break;

378
	default:
379
		lbs_deb_host("CMD_RESP: unknown cmd response 0x%04x\n",
380
			     le16_to_cpu(resp->command));
381 382
		break;
	}
383
	lbs_deb_leave(LBS_DEB_HOST);
384 385 386
	return ret;
}

387
int lbs_process_command_response(struct lbs_private *priv, u8 *data, u32 len)
388
{
389
	uint16_t respcmd, curcmd;
390
	struct cmd_header *resp;
391
	int ret = 0;
392 393
	unsigned long flags;
	uint16_t result;
394

395
	lbs_deb_enter(LBS_DEB_HOST);
396

397 398
	mutex_lock(&priv->lock);
	spin_lock_irqsave(&priv->driver_lock, flags);
399

400
	if (!priv->cur_cmd) {
401
		lbs_deb_host("CMD_RESP: cur_cmd is NULL\n");
402
		ret = -1;
403
		spin_unlock_irqrestore(&priv->driver_lock, flags);
404 405
		goto done;
	}
406

407
	resp = (void *)data;
408
	curcmd = le16_to_cpu(priv->cur_cmd->cmdbuf->command);
409 410 411
	respcmd = le16_to_cpu(resp->command);
	result = le16_to_cpu(resp->result);

H
Holger Schurig 已提交
412
	lbs_deb_cmd("CMD_RESP: response 0x%04x, seq %d, size %d\n",
413 414
		     respcmd, le16_to_cpu(resp->seqnum), len);
	lbs_deb_hex(LBS_DEB_CMD, "CMD_RESP", (void *) resp, len);
415

416
	if (resp->seqnum != priv->cur_cmd->cmdbuf->seqnum) {
417
		lbs_pr_info("Received CMD_RESP with invalid sequence %d (expected %d)\n",
418
			    le16_to_cpu(resp->seqnum), le16_to_cpu(priv->cur_cmd->cmdbuf->seqnum));
419
		spin_unlock_irqrestore(&priv->driver_lock, flags);
420 421 422
		ret = -1;
		goto done;
	}
423
	if (respcmd != CMD_RET(curcmd) &&
424
	    respcmd != CMD_RET_802_11_ASSOCIATE && curcmd != CMD_802_11_ASSOCIATE) {
425 426 427 428 429 430
		lbs_pr_info("Invalid CMD_RESP %x to command %x!\n", respcmd, curcmd);
		spin_unlock_irqrestore(&priv->driver_lock, flags);
		ret = -1;
		goto done;
	}

431 432 433 434 435 436 437 438 439 440
	if (resp->result == cpu_to_le16(0x0004)) {
		/* 0x0004 means -EAGAIN. Drop the response, let it time out
		   and be resubmitted */
		lbs_pr_info("Firmware returns DEFER to command %x. Will let it time out...\n",
			    le16_to_cpu(resp->command));
		spin_unlock_irqrestore(&priv->driver_lock, flags);
		ret = -1;
		goto done;
	}

441 442
	/* Now we got response from FW, cancel the command timer */
	del_timer(&priv->command_timer);
443 444 445 446 447 448
	priv->cmd_timed_out = 0;
	if (priv->nr_retries) {
		lbs_pr_info("Received result %x to command %x after %d retries\n",
			    result, curcmd, priv->nr_retries);
		priv->nr_retries = 0;
	}
449 450

	/* Store the response code to cur_cmd_retcode. */
451
	priv->cur_cmd_retcode = result;
452

453
	if (respcmd == CMD_RET(CMD_802_11_PS_MODE)) {
454
		struct cmd_ds_802_11_ps_mode *psmode = (void *) &resp[1];
455
		u16 action = le16_to_cpu(psmode->action);
456

457 458
		lbs_deb_host(
		       "CMD_RESP: PS_MODE cmd reply result 0x%x, action 0x%x\n",
459
		       result, action);
460 461

		if (result) {
462
			lbs_deb_host("CMD_RESP: PS command failed with 0x%x\n",
463 464 465 466
				    result);
			/*
			 * We should not re-try enter-ps command in
			 * ad-hoc mode. It takes place in
467
			 * lbs_execute_next_command().
468
			 */
469
			if (priv->mode == IW_MODE_ADHOC &&
470
			    action == CMD_SUBCMD_ENTER_PS)
471
				priv->psmode = LBS802_11POWERMODECAM;
472
		} else if (action == CMD_SUBCMD_ENTER_PS) {
473 474
			priv->needtowakeup = 0;
			priv->psstate = PS_STATE_AWAKE;
475

476
			lbs_deb_host("CMD_RESP: ENTER_PS command response\n");
477
			if (priv->connect_status != LBS_CONNECTED) {
478 479 480 481
				/*
				 * When Deauth Event received before Enter_PS command
				 * response, We need to wake up the firmware.
				 */
482
				lbs_deb_host(
483
				       "disconnected, invoking lbs_ps_wakeup\n");
484

485 486
				spin_unlock_irqrestore(&priv->driver_lock, flags);
				mutex_unlock(&priv->lock);
487
				lbs_ps_wakeup(priv, 0);
488 489
				mutex_lock(&priv->lock);
				spin_lock_irqsave(&priv->driver_lock, flags);
490
			}
491
		} else if (action == CMD_SUBCMD_EXIT_PS) {
492 493
			priv->needtowakeup = 0;
			priv->psstate = PS_STATE_FULL_POWER;
494
			lbs_deb_host("CMD_RESP: EXIT_PS command response\n");
495
		} else {
496
			lbs_deb_host("CMD_RESP: PS action 0x%X\n", action);
497 498
		}

499
		lbs_complete_command(priv, priv->cur_cmd, result);
500
		spin_unlock_irqrestore(&priv->driver_lock, flags);
501 502 503 504 505 506 507

		ret = 0;
		goto done;
	}

	/* If the command is not successful, cleanup and return failure */
	if ((result != 0 || !(respcmd & 0x8000))) {
508 509
		lbs_deb_host("CMD_RESP: error 0x%04x in command reply 0x%04x\n",
		       result, respcmd);
510 511 512 513
		/*
		 * Handling errors here
		 */
		switch (respcmd) {
514 515
		case CMD_RET(CMD_GET_HW_SPEC):
		case CMD_RET(CMD_802_11_RESET):
516
			lbs_deb_host("CMD_RESP: reset failed\n");
517 518 519
			break;

		}
520
		lbs_complete_command(priv, priv->cur_cmd, result);
521
		spin_unlock_irqrestore(&priv->driver_lock, flags);
522 523 524 525 526

		ret = -1;
		goto done;
	}

527
	spin_unlock_irqrestore(&priv->driver_lock, flags);
528

529 530
	if (priv->cur_cmd && priv->cur_cmd->callback) {
		ret = priv->cur_cmd->callback(priv, priv->cur_cmd->callback_arg,
531
				resp);
532
	} else
533
		ret = handle_cmd_response(priv, resp);
534

535
	spin_lock_irqsave(&priv->driver_lock, flags);
536

537
	if (priv->cur_cmd) {
538
		/* Clean up and Put current command back to cmdfreeq */
539
		lbs_complete_command(priv, priv->cur_cmd, result);
540
	}
541
	spin_unlock_irqrestore(&priv->driver_lock, flags);
542 543

done:
544
	mutex_unlock(&priv->lock);
545
	lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
546 547 548
	return ret;
}

549 550
static int lbs_send_confirmwake(struct lbs_private *priv)
{
551
	struct cmd_header cmd;
552 553 554 555
	int ret = 0;

	lbs_deb_enter(LBS_DEB_HOST);

556 557 558 559
	cmd.command = cpu_to_le16(CMD_802_11_WAKEUP_CONFIRM);
	cmd.size = cpu_to_le16(sizeof(cmd));
	cmd.seqnum = cpu_to_le16(++priv->seqnum);
	cmd.result = 0;
560

561 562
	lbs_deb_hex(LBS_DEB_HOST, "wake confirm", (u8 *) &cmd,
		sizeof(cmd));
563

564
	ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &cmd, sizeof(cmd));
565 566 567 568 569 570 571
	if (ret)
		lbs_pr_alert("SEND_WAKEC_CMD: Host to Card failed for Confirm Wake\n");

	lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
	return ret;
}

572
int lbs_process_event(struct lbs_private *priv, u32 event)
573 574 575
{
	int ret = 0;

576 577
	lbs_deb_enter(LBS_DEB_CMD);

578
	switch (event) {
579
	case MACREG_INT_CODE_LINK_SENSED:
580
		lbs_deb_cmd("EVENT: link sensed\n");
581 582 583
		break;

	case MACREG_INT_CODE_DEAUTHENTICATED:
584
		lbs_deb_cmd("EVENT: deauthenticated\n");
585
		lbs_mac_event_disconnected(priv);
586 587 588
		break;

	case MACREG_INT_CODE_DISASSOCIATED:
589
		lbs_deb_cmd("EVENT: disassociated\n");
590
		lbs_mac_event_disconnected(priv);
591 592
		break;

593
	case MACREG_INT_CODE_LINK_LOST_NO_SCAN:
594
		lbs_deb_cmd("EVENT: link lost\n");
595
		lbs_mac_event_disconnected(priv);
596 597 598
		break;

	case MACREG_INT_CODE_PS_SLEEP:
599
		lbs_deb_cmd("EVENT: ps sleep\n");
600 601

		/* handle unexpected PS SLEEP event */
602
		if (priv->psstate == PS_STATE_FULL_POWER) {
603
			lbs_deb_cmd(
604
			       "EVENT: in FULL POWER mode, ignoreing PS_SLEEP\n");
605 606
			break;
		}
607
		priv->psstate = PS_STATE_PRE_SLEEP;
608

609
		lbs_ps_confirm_sleep(priv);
610 611 612

		break;

613
	case MACREG_INT_CODE_HOST_AWAKE:
614
		lbs_deb_cmd("EVENT: host awake\n");
615 616 617
		lbs_send_confirmwake(priv);
		break;

618
	case MACREG_INT_CODE_PS_AWAKE:
619
		lbs_deb_cmd("EVENT: ps awake\n");
620
		/* handle unexpected PS AWAKE event */
621
		if (priv->psstate == PS_STATE_FULL_POWER) {
622
			lbs_deb_cmd(
623 624 625 626
			       "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
			break;
		}

627
		priv->psstate = PS_STATE_AWAKE;
628

629
		if (priv->needtowakeup) {
630 631 632
			/*
			 * wait for the command processing to finish
			 * before resuming sending
633
			 * priv->needtowakeup will be set to FALSE
634
			 * in lbs_ps_wakeup()
635
			 */
636
			lbs_deb_cmd("waking up ...\n");
637
			lbs_ps_wakeup(priv, 0);
638 639 640 641
		}
		break;

	case MACREG_INT_CODE_MIC_ERR_UNICAST:
642
		lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n");
643 644 645 646
		handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST);
		break;

	case MACREG_INT_CODE_MIC_ERR_MULTICAST:
647
		lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n");
648 649
		handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST);
		break;
650

651
	case MACREG_INT_CODE_MIB_CHANGED:
652 653
		lbs_deb_cmd("EVENT: MIB CHANGED\n");
		break;
654
	case MACREG_INT_CODE_INIT_DONE:
655
		lbs_deb_cmd("EVENT: INIT DONE\n");
656 657
		break;
	case MACREG_INT_CODE_ADHOC_BCN_LOST:
658
		lbs_deb_cmd("EVENT: ADHOC beacon lost\n");
659 660
		break;
	case MACREG_INT_CODE_RSSI_LOW:
661
		lbs_pr_alert("EVENT: rssi low\n");
662 663
		break;
	case MACREG_INT_CODE_SNR_LOW:
664
		lbs_pr_alert("EVENT: snr low\n");
665 666
		break;
	case MACREG_INT_CODE_MAX_FAIL:
667
		lbs_pr_alert("EVENT: max fail\n");
668 669
		break;
	case MACREG_INT_CODE_RSSI_HIGH:
670
		lbs_pr_alert("EVENT: rssi high\n");
671 672
		break;
	case MACREG_INT_CODE_SNR_HIGH:
673
		lbs_pr_alert("EVENT: snr high\n");
674 675
		break;

676
	case MACREG_INT_CODE_MESH_AUTO_STARTED:
677 678 679 680 681
		/* Ignore spurious autostart events if autostart is disabled */
		if (!priv->mesh_autostart_enabled) {
			lbs_pr_info("EVENT: MESH_AUTO_STARTED (ignoring)\n");
			break;
		}
682
		lbs_pr_info("EVENT: MESH_AUTO_STARTED\n");
683
		priv->mesh_connect_status = LBS_CONNECTED;
684
		if (priv->mesh_open) {
685
			netif_carrier_on(priv->mesh_dev);
686 687
			if (!priv->tx_pending_len)
				netif_wake_queue(priv->mesh_dev);
688
		}
689
		priv->mode = IW_MODE_ADHOC;
690
		schedule_work(&priv->sync_channel);
691 692
		break;

693
	default:
694
		lbs_pr_alert("EVENT: unknown event id %d\n", event);
695 696 697
		break;
	}

698
	lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
699 700
	return ret;
}