Merge branch 'for-rmk' of git://git.kernel.org/pub/scm/linux/kernel/git/ycmiao/pxa...
[linux-2.6] / drivers / net / wireless / libertas / cmdresp.c
1 /**
2   * This file contains the handling of command
3   * responses as well as events generated by firmware.
4   */
5 #include <linux/delay.h>
6 #include <linux/if_arp.h>
7 #include <linux/netdevice.h>
8
9 #include <net/iw_handler.h>
10
11 #include "host.h"
12 #include "decl.h"
13 #include "defs.h"
14 #include "dev.h"
15 #include "assoc.h"
16 #include "wext.h"
17
18 /**
19  *  @brief This function handles disconnect event. it
20  *  reports disconnect to upper layer, clean tx/rx packets,
21  *  reset link state etc.
22  *
23  *  @param priv    A pointer to struct lbs_private structure
24  *  @return        n/a
25  */
26 void lbs_mac_event_disconnected(struct lbs_private *priv)
27 {
28         union iwreq_data wrqu;
29
30         if (priv->connect_status != LBS_CONNECTED)
31                 return;
32
33         lbs_deb_enter(LBS_DEB_ASSOC);
34
35         memset(wrqu.ap_addr.sa_data, 0x00, ETH_ALEN);
36         wrqu.ap_addr.sa_family = ARPHRD_ETHER;
37
38         /*
39          * Cisco AP sends EAP failure and de-auth in less than 0.5 ms.
40          * It causes problem in the Supplicant
41          */
42
43         msleep_interruptible(1000);
44         wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
45
46         /* report disconnect to upper layer */
47         netif_stop_queue(priv->dev);
48         netif_carrier_off(priv->dev);
49
50         /* Free Tx and Rx packets */
51         kfree_skb(priv->currenttxskb);
52         priv->currenttxskb = NULL;
53         priv->tx_pending_len = 0;
54
55         /* reset SNR/NF/RSSI values */
56         memset(priv->SNR, 0x00, sizeof(priv->SNR));
57         memset(priv->NF, 0x00, sizeof(priv->NF));
58         memset(priv->RSSI, 0x00, sizeof(priv->RSSI));
59         memset(priv->rawSNR, 0x00, sizeof(priv->rawSNR));
60         memset(priv->rawNF, 0x00, sizeof(priv->rawNF));
61         priv->nextSNRNF = 0;
62         priv->numSNRNF = 0;
63         priv->connect_status = LBS_DISCONNECTED;
64
65         /* Clear out associated SSID and BSSID since connection is
66          * no longer valid.
67          */
68         memset(&priv->curbssparams.bssid, 0, ETH_ALEN);
69         memset(&priv->curbssparams.ssid, 0, IW_ESSID_MAX_SIZE);
70         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  *  @brief This function handles MIC failure event.
82  *
83  *  @param priv    A pointer to struct lbs_private structure
84  *  @para  event   the event id
85  *  @return        n/a
86  */
87 static void handle_mic_failureevent(struct lbs_private *priv, u32 event)
88 {
89         char buf[50];
90
91         lbs_deb_enter(LBS_DEB_CMD);
92         memset(buf, 0, sizeof(buf));
93
94         sprintf(buf, "%s", "MLME-MICHAELMICFAILURE.indication ");
95
96         if (event == MACREG_INT_CODE_MIC_ERR_UNICAST) {
97                 strcat(buf, "unicast ");
98         } else {
99                 strcat(buf, "multicast ");
100         }
101
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                                u16 type, struct cmd_ds_command *resp)
108 {
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                         priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
119                         priv->offsetvalue.value = le32_to_cpu(reg->value);
120                         break;
121                 }
122
123         case CMD_RET(CMD_BBP_REG_ACCESS):
124                 {
125                         struct cmd_ds_bbp_reg_access *reg = &resp->params.bbpreg;
126
127                         priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
128                         priv->offsetvalue.value = reg->value;
129                         break;
130                 }
131
132         case CMD_RET(CMD_RF_REG_ACCESS):
133                 {
134                         struct cmd_ds_rf_reg_access *reg = &resp->params.rfreg;
135
136                         priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
137                         priv->offsetvalue.value = reg->value;
138                         break;
139                 }
140
141         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                                     struct cmd_ds_command *resp)
151 {
152         struct cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
153         u16 oid = le16_to_cpu(smib->oid);
154         u16 querytype = le16_to_cpu(smib->querytype);
155
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                         break;
182                 default:
183                         break;
184                 }
185         }
186
187         lbs_deb_enter(LBS_DEB_CMD);
188         return 0;
189 }
190
191 static int lbs_ret_802_11_rf_tx_power(struct lbs_private *priv,
192                                        struct cmd_ds_command *resp)
193 {
194         struct cmd_ds_802_11_rf_tx_power *rtp = &resp->params.txp;
195
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         return 0;
204 }
205
206 static int lbs_ret_802_11_rssi(struct lbs_private *priv,
207                                 struct cmd_ds_command *resp)
208 {
209         struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp;
210
211         lbs_deb_enter(LBS_DEB_CMD);
212
213         /* store the non average value */
214         priv->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR);
215         priv->NF[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->noisefloor);
216
217         priv->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR);
218         priv->NF[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgnoisefloor);
219
220         priv->RSSI[TYPE_BEACON][TYPE_NOAVG] =
221             CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
222                      priv->NF[TYPE_BEACON][TYPE_NOAVG]);
223
224         priv->RSSI[TYPE_BEACON][TYPE_AVG] =
225             CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE,
226                      priv->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE);
227
228         lbs_deb_cmd("RSSI: beacon %d, avg %d\n",
229                priv->RSSI[TYPE_BEACON][TYPE_NOAVG],
230                priv->RSSI[TYPE_BEACON][TYPE_AVG]);
231
232         lbs_deb_leave(LBS_DEB_CMD);
233         return 0;
234 }
235
236 static int lbs_ret_802_11_bcn_ctrl(struct lbs_private * priv,
237                                         struct cmd_ds_command *resp)
238 {
239         struct cmd_ds_802_11_beacon_control *bcn_ctrl =
240             &resp->params.bcn_ctrl;
241
242         lbs_deb_enter(LBS_DEB_CMD);
243
244         if (bcn_ctrl->action == CMD_ACT_GET) {
245                 priv->beacon_enable = (u8) le16_to_cpu(bcn_ctrl->beacon_enable);
246                 priv->beacon_period = le16_to_cpu(bcn_ctrl->beacon_period);
247         }
248
249         lbs_deb_enter(LBS_DEB_CMD);
250         return 0;
251 }
252
253 static inline int handle_cmd_response(struct lbs_private *priv,
254                                       struct cmd_header *cmd_response)
255 {
256         struct cmd_ds_command *resp = (struct cmd_ds_command *) cmd_response;
257         int ret = 0;
258         unsigned long flags;
259         uint16_t respcmd = le16_to_cpu(resp->command);
260
261         lbs_deb_enter(LBS_DEB_HOST);
262
263         switch (respcmd) {
264         case CMD_RET(CMD_MAC_REG_ACCESS):
265         case CMD_RET(CMD_BBP_REG_ACCESS):
266         case CMD_RET(CMD_RF_REG_ACCESS):
267                 ret = lbs_ret_reg_access(priv, respcmd, resp);
268                 break;
269
270         case CMD_RET_802_11_ASSOCIATE:
271         case CMD_RET(CMD_802_11_ASSOCIATE):
272         case CMD_RET(CMD_802_11_REASSOCIATE):
273                 ret = lbs_ret_80211_associate(priv, resp);
274                 break;
275
276         case CMD_RET(CMD_802_11_DISASSOCIATE):
277         case CMD_RET(CMD_802_11_DEAUTHENTICATE):
278                 ret = lbs_ret_80211_disassociate(priv);
279                 break;
280
281         case CMD_RET(CMD_802_11_AD_HOC_START):
282         case CMD_RET(CMD_802_11_AD_HOC_JOIN):
283                 ret = lbs_ret_80211_ad_hoc_start(priv, resp);
284                 break;
285
286         case CMD_RET(CMD_802_11_SNMP_MIB):
287                 ret = lbs_ret_802_11_snmp_mib(priv, resp);
288                 break;
289
290         case CMD_RET(CMD_802_11_RF_TX_POWER):
291                 ret = lbs_ret_802_11_rf_tx_power(priv, resp);
292                 break;
293
294         case CMD_RET(CMD_802_11_SET_AFC):
295         case CMD_RET(CMD_802_11_GET_AFC):
296                 spin_lock_irqsave(&priv->driver_lock, flags);
297                 memmove((void *)priv->cur_cmd->callback_arg, &resp->params.afc,
298                         sizeof(struct cmd_ds_802_11_afc));
299                 spin_unlock_irqrestore(&priv->driver_lock, flags);
300
301                 break;
302
303         case CMD_RET(CMD_802_11_RESET):
304         case CMD_RET(CMD_802_11_AUTHENTICATE):
305         case CMD_RET(CMD_802_11_BEACON_STOP):
306                 break;
307
308         case CMD_RET(CMD_802_11_RSSI):
309                 ret = lbs_ret_802_11_rssi(priv, resp);
310                 break;
311
312         case CMD_RET(CMD_802_11_AD_HOC_STOP):
313                 ret = lbs_ret_80211_ad_hoc_stop(priv);
314                 break;
315
316         case CMD_RET(CMD_802_11D_DOMAIN_INFO):
317                 ret = lbs_ret_802_11d_domain_info(resp);
318                 break;
319
320         case CMD_RET(CMD_802_11_TPC_CFG):
321                 spin_lock_irqsave(&priv->driver_lock, flags);
322                 memmove((void *)priv->cur_cmd->callback_arg, &resp->params.tpccfg,
323                         sizeof(struct cmd_ds_802_11_tpc_cfg));
324                 spin_unlock_irqrestore(&priv->driver_lock, flags);
325                 break;
326         case CMD_RET(CMD_802_11_LED_GPIO_CTRL):
327                 spin_lock_irqsave(&priv->driver_lock, flags);
328                 memmove((void *)priv->cur_cmd->callback_arg, &resp->params.ledgpio,
329                         sizeof(struct cmd_ds_802_11_led_ctrl));
330                 spin_unlock_irqrestore(&priv->driver_lock, flags);
331                 break;
332
333         case CMD_RET(CMD_GET_TSF):
334                 spin_lock_irqsave(&priv->driver_lock, flags);
335                 memcpy((void *)priv->cur_cmd->callback_arg,
336                        &resp->params.gettsf.tsfvalue, sizeof(u64));
337                 spin_unlock_irqrestore(&priv->driver_lock, flags);
338                 break;
339         case CMD_RET(CMD_BT_ACCESS):
340                 spin_lock_irqsave(&priv->driver_lock, flags);
341                 if (priv->cur_cmd->callback_arg)
342                         memcpy((void *)priv->cur_cmd->callback_arg,
343                                &resp->params.bt.addr1, 2 * ETH_ALEN);
344                 spin_unlock_irqrestore(&priv->driver_lock, flags);
345                 break;
346         case CMD_RET(CMD_FWT_ACCESS):
347                 spin_lock_irqsave(&priv->driver_lock, flags);
348                 if (priv->cur_cmd->callback_arg)
349                         memcpy((void *)priv->cur_cmd->callback_arg, &resp->params.fwt,
350                                sizeof(resp->params.fwt));
351                 spin_unlock_irqrestore(&priv->driver_lock, flags);
352                 break;
353         case CMD_RET(CMD_802_11_BEACON_CTRL):
354                 ret = lbs_ret_802_11_bcn_ctrl(priv, resp);
355                 break;
356
357         default:
358                 lbs_pr_err("CMD_RESP: unknown cmd response 0x%04x\n",
359                            le16_to_cpu(resp->command));
360                 break;
361         }
362         lbs_deb_leave(LBS_DEB_HOST);
363         return ret;
364 }
365
366 int lbs_process_command_response(struct lbs_private *priv, u8 *data, u32 len)
367 {
368         uint16_t respcmd, curcmd;
369         struct cmd_header *resp;
370         int ret = 0;
371         unsigned long flags;
372         uint16_t result;
373
374         lbs_deb_enter(LBS_DEB_HOST);
375
376         mutex_lock(&priv->lock);
377         spin_lock_irqsave(&priv->driver_lock, flags);
378
379         if (!priv->cur_cmd) {
380                 lbs_deb_host("CMD_RESP: cur_cmd is NULL\n");
381                 ret = -1;
382                 spin_unlock_irqrestore(&priv->driver_lock, flags);
383                 goto done;
384         }
385
386         resp = (void *)data;
387         curcmd = le16_to_cpu(priv->cur_cmd->cmdbuf->command);
388         respcmd = le16_to_cpu(resp->command);
389         result = le16_to_cpu(resp->result);
390
391         lbs_deb_cmd("CMD_RESP: response 0x%04x, seq %d, size %d\n",
392                      respcmd, le16_to_cpu(resp->seqnum), len);
393         lbs_deb_hex(LBS_DEB_CMD, "CMD_RESP", (void *) resp, len);
394
395         if (resp->seqnum != priv->cur_cmd->cmdbuf->seqnum) {
396                 lbs_pr_info("Received CMD_RESP with invalid sequence %d (expected %d)\n",
397                             le16_to_cpu(resp->seqnum), le16_to_cpu(priv->cur_cmd->cmdbuf->seqnum));
398                 spin_unlock_irqrestore(&priv->driver_lock, flags);
399                 ret = -1;
400                 goto done;
401         }
402         if (respcmd != CMD_RET(curcmd) &&
403             respcmd != CMD_RET_802_11_ASSOCIATE && curcmd != CMD_802_11_ASSOCIATE) {
404                 lbs_pr_info("Invalid CMD_RESP %x to command %x!\n", respcmd, curcmd);
405                 spin_unlock_irqrestore(&priv->driver_lock, flags);
406                 ret = -1;
407                 goto done;
408         }
409
410         if (resp->result == cpu_to_le16(0x0004)) {
411                 /* 0x0004 means -EAGAIN. Drop the response, let it time out
412                    and be resubmitted */
413                 lbs_pr_info("Firmware returns DEFER to command %x. Will let it time out...\n",
414                             le16_to_cpu(resp->command));
415                 spin_unlock_irqrestore(&priv->driver_lock, flags);
416                 ret = -1;
417                 goto done;
418         }
419
420         /* Now we got response from FW, cancel the command timer */
421         del_timer(&priv->command_timer);
422         priv->cmd_timed_out = 0;
423         if (priv->nr_retries) {
424                 lbs_pr_info("Received result %x to command %x after %d retries\n",
425                             result, curcmd, priv->nr_retries);
426                 priv->nr_retries = 0;
427         }
428
429         /* Store the response code to cur_cmd_retcode. */
430         priv->cur_cmd_retcode = result;
431
432         if (respcmd == CMD_RET(CMD_802_11_PS_MODE)) {
433                 struct cmd_ds_802_11_ps_mode *psmode = (void *) &resp[1];
434                 u16 action = le16_to_cpu(psmode->action);
435
436                 lbs_deb_host(
437                        "CMD_RESP: PS_MODE cmd reply result 0x%x, action 0x%x\n",
438                        result, action);
439
440                 if (result) {
441                         lbs_deb_host("CMD_RESP: PS command failed with 0x%x\n",
442                                     result);
443                         /*
444                          * We should not re-try enter-ps command in
445                          * ad-hoc mode. It takes place in
446                          * lbs_execute_next_command().
447                          */
448                         if (priv->mode == IW_MODE_ADHOC &&
449                             action == CMD_SUBCMD_ENTER_PS)
450                                 priv->psmode = LBS802_11POWERMODECAM;
451                 } else if (action == CMD_SUBCMD_ENTER_PS) {
452                         priv->needtowakeup = 0;
453                         priv->psstate = PS_STATE_AWAKE;
454
455                         lbs_deb_host("CMD_RESP: ENTER_PS command response\n");
456                         if (priv->connect_status != LBS_CONNECTED) {
457                                 /*
458                                  * When Deauth Event received before Enter_PS command
459                                  * response, We need to wake up the firmware.
460                                  */
461                                 lbs_deb_host(
462                                        "disconnected, invoking lbs_ps_wakeup\n");
463
464                                 spin_unlock_irqrestore(&priv->driver_lock, flags);
465                                 mutex_unlock(&priv->lock);
466                                 lbs_ps_wakeup(priv, 0);
467                                 mutex_lock(&priv->lock);
468                                 spin_lock_irqsave(&priv->driver_lock, flags);
469                         }
470                 } else if (action == CMD_SUBCMD_EXIT_PS) {
471                         priv->needtowakeup = 0;
472                         priv->psstate = PS_STATE_FULL_POWER;
473                         lbs_deb_host("CMD_RESP: EXIT_PS command response\n");
474                 } else {
475                         lbs_deb_host("CMD_RESP: PS action 0x%X\n", action);
476                 }
477
478                 lbs_complete_command(priv, priv->cur_cmd, result);
479                 spin_unlock_irqrestore(&priv->driver_lock, flags);
480
481                 ret = 0;
482                 goto done;
483         }
484
485         /* If the command is not successful, cleanup and return failure */
486         if ((result != 0 || !(respcmd & 0x8000))) {
487                 lbs_deb_host("CMD_RESP: error 0x%04x in command reply 0x%04x\n",
488                        result, respcmd);
489                 /*
490                  * Handling errors here
491                  */
492                 switch (respcmd) {
493                 case CMD_RET(CMD_GET_HW_SPEC):
494                 case CMD_RET(CMD_802_11_RESET):
495                         lbs_deb_host("CMD_RESP: reset failed\n");
496                         break;
497
498                 }
499                 lbs_complete_command(priv, priv->cur_cmd, result);
500                 spin_unlock_irqrestore(&priv->driver_lock, flags);
501
502                 ret = -1;
503                 goto done;
504         }
505
506         spin_unlock_irqrestore(&priv->driver_lock, flags);
507
508         if (priv->cur_cmd && priv->cur_cmd->callback) {
509                 ret = priv->cur_cmd->callback(priv, priv->cur_cmd->callback_arg,
510                                 resp);
511         } else
512                 ret = handle_cmd_response(priv, resp);
513
514         spin_lock_irqsave(&priv->driver_lock, flags);
515
516         if (priv->cur_cmd) {
517                 /* Clean up and Put current command back to cmdfreeq */
518                 lbs_complete_command(priv, priv->cur_cmd, result);
519         }
520         spin_unlock_irqrestore(&priv->driver_lock, flags);
521
522 done:
523         mutex_unlock(&priv->lock);
524         lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
525         return ret;
526 }
527
528 static int lbs_send_confirmwake(struct lbs_private *priv)
529 {
530         struct cmd_header cmd;
531         int ret = 0;
532
533         lbs_deb_enter(LBS_DEB_HOST);
534
535         cmd.command = cpu_to_le16(CMD_802_11_WAKEUP_CONFIRM);
536         cmd.size = cpu_to_le16(sizeof(cmd));
537         cmd.seqnum = cpu_to_le16(++priv->seqnum);
538         cmd.result = 0;
539
540         lbs_deb_hex(LBS_DEB_HOST, "wake confirm", (u8 *) &cmd,
541                 sizeof(cmd));
542
543         ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &cmd, sizeof(cmd));
544         if (ret)
545                 lbs_pr_alert("SEND_WAKEC_CMD: Host to Card failed for Confirm Wake\n");
546
547         lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
548         return ret;
549 }
550
551 int lbs_process_event(struct lbs_private *priv, u32 event)
552 {
553         int ret = 0;
554
555         lbs_deb_enter(LBS_DEB_CMD);
556
557         switch (event) {
558         case MACREG_INT_CODE_LINK_SENSED:
559                 lbs_deb_cmd("EVENT: link sensed\n");
560                 break;
561
562         case MACREG_INT_CODE_DEAUTHENTICATED:
563                 lbs_deb_cmd("EVENT: deauthenticated\n");
564                 lbs_mac_event_disconnected(priv);
565                 break;
566
567         case MACREG_INT_CODE_DISASSOCIATED:
568                 lbs_deb_cmd("EVENT: disassociated\n");
569                 lbs_mac_event_disconnected(priv);
570                 break;
571
572         case MACREG_INT_CODE_LINK_LOST_NO_SCAN:
573                 lbs_deb_cmd("EVENT: link lost\n");
574                 lbs_mac_event_disconnected(priv);
575                 break;
576
577         case MACREG_INT_CODE_PS_SLEEP:
578                 lbs_deb_cmd("EVENT: ps sleep\n");
579
580                 /* handle unexpected PS SLEEP event */
581                 if (priv->psstate == PS_STATE_FULL_POWER) {
582                         lbs_deb_cmd(
583                                "EVENT: in FULL POWER mode, ignoreing PS_SLEEP\n");
584                         break;
585                 }
586                 priv->psstate = PS_STATE_PRE_SLEEP;
587
588                 lbs_ps_confirm_sleep(priv);
589
590                 break;
591
592         case MACREG_INT_CODE_HOST_AWAKE:
593                 lbs_deb_cmd("EVENT: host awake\n");
594                 lbs_send_confirmwake(priv);
595                 break;
596
597         case MACREG_INT_CODE_PS_AWAKE:
598                 lbs_deb_cmd("EVENT: ps awake\n");
599                 /* handle unexpected PS AWAKE event */
600                 if (priv->psstate == PS_STATE_FULL_POWER) {
601                         lbs_deb_cmd(
602                                "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
603                         break;
604                 }
605
606                 priv->psstate = PS_STATE_AWAKE;
607
608                 if (priv->needtowakeup) {
609                         /*
610                          * wait for the command processing to finish
611                          * before resuming sending
612                          * priv->needtowakeup will be set to FALSE
613                          * in lbs_ps_wakeup()
614                          */
615                         lbs_deb_cmd("waking up ...\n");
616                         lbs_ps_wakeup(priv, 0);
617                 }
618                 break;
619
620         case MACREG_INT_CODE_MIC_ERR_UNICAST:
621                 lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n");
622                 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST);
623                 break;
624
625         case MACREG_INT_CODE_MIC_ERR_MULTICAST:
626                 lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n");
627                 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST);
628                 break;
629
630         case MACREG_INT_CODE_MIB_CHANGED:
631                 lbs_deb_cmd("EVENT: MIB CHANGED\n");
632                 break;
633         case MACREG_INT_CODE_INIT_DONE:
634                 lbs_deb_cmd("EVENT: INIT DONE\n");
635                 break;
636         case MACREG_INT_CODE_ADHOC_BCN_LOST:
637                 lbs_deb_cmd("EVENT: ADHOC beacon lost\n");
638                 break;
639         case MACREG_INT_CODE_RSSI_LOW:
640                 lbs_pr_alert("EVENT: rssi low\n");
641                 break;
642         case MACREG_INT_CODE_SNR_LOW:
643                 lbs_pr_alert("EVENT: snr low\n");
644                 break;
645         case MACREG_INT_CODE_MAX_FAIL:
646                 lbs_pr_alert("EVENT: max fail\n");
647                 break;
648         case MACREG_INT_CODE_RSSI_HIGH:
649                 lbs_pr_alert("EVENT: rssi high\n");
650                 break;
651         case MACREG_INT_CODE_SNR_HIGH:
652                 lbs_pr_alert("EVENT: snr high\n");
653                 break;
654
655         case MACREG_INT_CODE_MESH_AUTO_STARTED:
656                 /* Ignore spurious autostart events if autostart is disabled */
657                 if (!priv->mesh_autostart_enabled) {
658                         lbs_pr_info("EVENT: MESH_AUTO_STARTED (ignoring)\n");
659                         break;
660                 }
661                 lbs_pr_info("EVENT: MESH_AUTO_STARTED\n");
662                 priv->mesh_connect_status = LBS_CONNECTED;
663                 if (priv->mesh_open) {
664                         netif_carrier_on(priv->mesh_dev);
665                         if (!priv->tx_pending_len)
666                                 netif_wake_queue(priv->mesh_dev);
667                 }
668                 priv->mode = IW_MODE_ADHOC;
669                 schedule_work(&priv->sync_channel);
670                 break;
671
672         default:
673                 lbs_pr_alert("EVENT: unknown event id %d\n", event);
674                 break;
675         }
676
677         lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
678         return ret;
679 }