libertas: fix multicast filtering on eth and msh interfaces
[linux-3.10.git] / 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_rate_adapt_rateset(struct lbs_private *priv,
207                                               struct cmd_ds_command *resp)
208 {
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                 priv->enablehwauto = le16_to_cpu(rates->enablehwauto);
215                 priv->ratebitmap = le16_to_cpu(rates->bitmap);
216         }
217
218         lbs_deb_leave(LBS_DEB_CMD);
219         return 0;
220 }
221
222 static int lbs_ret_802_11_rssi(struct lbs_private *priv,
223                                 struct cmd_ds_command *resp)
224 {
225         struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp;
226
227         lbs_deb_enter(LBS_DEB_CMD);
228
229         /* store the non average value */
230         priv->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR);
231         priv->NF[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->noisefloor);
232
233         priv->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR);
234         priv->NF[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgnoisefloor);
235
236         priv->RSSI[TYPE_BEACON][TYPE_NOAVG] =
237             CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
238                      priv->NF[TYPE_BEACON][TYPE_NOAVG]);
239
240         priv->RSSI[TYPE_BEACON][TYPE_AVG] =
241             CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE,
242                      priv->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE);
243
244         lbs_deb_cmd("RSSI: beacon %d, avg %d\n",
245                priv->RSSI[TYPE_BEACON][TYPE_NOAVG],
246                priv->RSSI[TYPE_BEACON][TYPE_AVG]);
247
248         lbs_deb_leave(LBS_DEB_CMD);
249         return 0;
250 }
251
252 static int lbs_ret_802_11_bcn_ctrl(struct lbs_private * priv,
253                                         struct cmd_ds_command *resp)
254 {
255         struct cmd_ds_802_11_beacon_control *bcn_ctrl =
256             &resp->params.bcn_ctrl;
257
258         lbs_deb_enter(LBS_DEB_CMD);
259
260         if (bcn_ctrl->action == CMD_ACT_GET) {
261                 priv->beacon_enable = (u8) le16_to_cpu(bcn_ctrl->beacon_enable);
262                 priv->beacon_period = le16_to_cpu(bcn_ctrl->beacon_period);
263         }
264
265         lbs_deb_enter(LBS_DEB_CMD);
266         return 0;
267 }
268
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         int ret = 0;
274         unsigned long flags;
275         uint16_t respcmd = le16_to_cpu(resp->command);
276
277         lbs_deb_enter(LBS_DEB_HOST);
278
279         switch (respcmd) {
280         case CMD_RET(CMD_MAC_REG_ACCESS):
281         case CMD_RET(CMD_BBP_REG_ACCESS):
282         case CMD_RET(CMD_RF_REG_ACCESS):
283                 ret = lbs_ret_reg_access(priv, respcmd, resp);
284                 break;
285
286         case CMD_RET_802_11_ASSOCIATE:
287         case CMD_RET(CMD_802_11_ASSOCIATE):
288         case CMD_RET(CMD_802_11_REASSOCIATE):
289                 ret = lbs_ret_80211_associate(priv, resp);
290                 break;
291
292         case CMD_RET(CMD_802_11_DISASSOCIATE):
293         case CMD_RET(CMD_802_11_DEAUTHENTICATE):
294                 ret = lbs_ret_80211_disassociate(priv);
295                 break;
296
297         case CMD_RET(CMD_802_11_AD_HOC_START):
298         case CMD_RET(CMD_802_11_AD_HOC_JOIN):
299                 ret = lbs_ret_80211_ad_hoc_start(priv, resp);
300                 break;
301
302         case CMD_RET(CMD_802_11_SNMP_MIB):
303                 ret = lbs_ret_802_11_snmp_mib(priv, resp);
304                 break;
305
306         case CMD_RET(CMD_802_11_RF_TX_POWER):
307                 ret = lbs_ret_802_11_rf_tx_power(priv, resp);
308                 break;
309
310         case CMD_RET(CMD_802_11_SET_AFC):
311         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                 break;
318
319         case CMD_RET(CMD_802_11_RESET):
320         case CMD_RET(CMD_802_11_AUTHENTICATE):
321         case CMD_RET(CMD_802_11_BEACON_STOP):
322                 break;
323
324         case CMD_RET(CMD_802_11_RATE_ADAPT_RATESET):
325                 ret = lbs_ret_802_11_rate_adapt_rateset(priv, resp);
326                 break;
327
328         case CMD_RET(CMD_802_11_RSSI):
329                 ret = lbs_ret_802_11_rssi(priv, resp);
330                 break;
331
332         case CMD_RET(CMD_802_11_AD_HOC_STOP):
333                 ret = lbs_ret_80211_ad_hoc_stop(priv);
334                 break;
335
336         case CMD_RET(CMD_802_11D_DOMAIN_INFO):
337                 ret = lbs_ret_802_11d_domain_info(resp);
338                 break;
339
340         case CMD_RET(CMD_802_11_TPC_CFG):
341                 spin_lock_irqsave(&priv->driver_lock, flags);
342                 memmove((void *)priv->cur_cmd->callback_arg, &resp->params.tpccfg,
343                         sizeof(struct cmd_ds_802_11_tpc_cfg));
344                 spin_unlock_irqrestore(&priv->driver_lock, flags);
345                 break;
346         case CMD_RET(CMD_802_11_LED_GPIO_CTRL):
347                 spin_lock_irqsave(&priv->driver_lock, flags);
348                 memmove((void *)priv->cur_cmd->callback_arg, &resp->params.ledgpio,
349                         sizeof(struct cmd_ds_802_11_led_ctrl));
350                 spin_unlock_irqrestore(&priv->driver_lock, flags);
351                 break;
352
353         case CMD_RET(CMD_GET_TSF):
354                 spin_lock_irqsave(&priv->driver_lock, flags);
355                 memcpy((void *)priv->cur_cmd->callback_arg,
356                        &resp->params.gettsf.tsfvalue, sizeof(u64));
357                 spin_unlock_irqrestore(&priv->driver_lock, flags);
358                 break;
359         case CMD_RET(CMD_BT_ACCESS):
360                 spin_lock_irqsave(&priv->driver_lock, flags);
361                 if (priv->cur_cmd->callback_arg)
362                         memcpy((void *)priv->cur_cmd->callback_arg,
363                                &resp->params.bt.addr1, 2 * ETH_ALEN);
364                 spin_unlock_irqrestore(&priv->driver_lock, flags);
365                 break;
366         case CMD_RET(CMD_FWT_ACCESS):
367                 spin_lock_irqsave(&priv->driver_lock, flags);
368                 if (priv->cur_cmd->callback_arg)
369                         memcpy((void *)priv->cur_cmd->callback_arg, &resp->params.fwt,
370                                sizeof(resp->params.fwt));
371                 spin_unlock_irqrestore(&priv->driver_lock, flags);
372                 break;
373         case CMD_RET(CMD_802_11_BEACON_CTRL):
374                 ret = lbs_ret_802_11_bcn_ctrl(priv, resp);
375                 break;
376
377         default:
378                 lbs_pr_err("CMD_RESP: unknown cmd response 0x%04x\n",
379                            le16_to_cpu(resp->command));
380                 break;
381         }
382         lbs_deb_leave(LBS_DEB_HOST);
383         return ret;
384 }
385
386 int lbs_process_command_response(struct lbs_private *priv, u8 *data, u32 len)
387 {
388         uint16_t respcmd, curcmd;
389         struct cmd_header *resp;
390         int ret = 0;
391         unsigned long flags;
392         uint16_t result;
393
394         lbs_deb_enter(LBS_DEB_HOST);
395
396         mutex_lock(&priv->lock);
397         spin_lock_irqsave(&priv->driver_lock, flags);
398
399         if (!priv->cur_cmd) {
400                 lbs_deb_host("CMD_RESP: cur_cmd is NULL\n");
401                 ret = -1;
402                 spin_unlock_irqrestore(&priv->driver_lock, flags);
403                 goto done;
404         }
405
406         resp = (void *)data;
407         curcmd = le16_to_cpu(priv->cur_cmd->cmdbuf->command);
408         respcmd = le16_to_cpu(resp->command);
409         result = le16_to_cpu(resp->result);
410
411         lbs_deb_cmd("CMD_RESP: response 0x%04x, seq %d, size %d\n",
412                      respcmd, le16_to_cpu(resp->seqnum), len);
413         lbs_deb_hex(LBS_DEB_CMD, "CMD_RESP", (void *) resp, len);
414
415         if (resp->seqnum != priv->cur_cmd->cmdbuf->seqnum) {
416                 lbs_pr_info("Received CMD_RESP with invalid sequence %d (expected %d)\n",
417                             le16_to_cpu(resp->seqnum), le16_to_cpu(priv->cur_cmd->cmdbuf->seqnum));
418                 spin_unlock_irqrestore(&priv->driver_lock, flags);
419                 ret = -1;
420                 goto done;
421         }
422         if (respcmd != CMD_RET(curcmd) &&
423             respcmd != CMD_RET_802_11_ASSOCIATE && curcmd != CMD_802_11_ASSOCIATE) {
424                 lbs_pr_info("Invalid CMD_RESP %x to command %x!\n", respcmd, curcmd);
425                 spin_unlock_irqrestore(&priv->driver_lock, flags);
426                 ret = -1;
427                 goto done;
428         }
429
430         if (resp->result == cpu_to_le16(0x0004)) {
431                 /* 0x0004 means -EAGAIN. Drop the response, let it time out
432                    and be resubmitted */
433                 lbs_pr_info("Firmware returns DEFER to command %x. Will let it time out...\n",
434                             le16_to_cpu(resp->command));
435                 spin_unlock_irqrestore(&priv->driver_lock, flags);
436                 ret = -1;
437                 goto done;
438         }
439
440         /* Now we got response from FW, cancel the command timer */
441         del_timer(&priv->command_timer);
442         priv->cmd_timed_out = 0;
443         if (priv->nr_retries) {
444                 lbs_pr_info("Received result %x to command %x after %d retries\n",
445                             result, curcmd, priv->nr_retries);
446                 priv->nr_retries = 0;
447         }
448
449         /* Store the response code to cur_cmd_retcode. */
450         priv->cur_cmd_retcode = result;
451
452         if (respcmd == CMD_RET(CMD_802_11_PS_MODE)) {
453                 struct cmd_ds_802_11_ps_mode *psmode = (void *) &resp[1];
454                 u16 action = le16_to_cpu(psmode->action);
455
456                 lbs_deb_host(
457                        "CMD_RESP: PS_MODE cmd reply result 0x%x, action 0x%x\n",
458                        result, action);
459
460                 if (result) {
461                         lbs_deb_host("CMD_RESP: PS command failed with 0x%x\n",
462                                     result);
463                         /*
464                          * We should not re-try enter-ps command in
465                          * ad-hoc mode. It takes place in
466                          * lbs_execute_next_command().
467                          */
468                         if (priv->mode == IW_MODE_ADHOC &&
469                             action == CMD_SUBCMD_ENTER_PS)
470                                 priv->psmode = LBS802_11POWERMODECAM;
471                 } else if (action == CMD_SUBCMD_ENTER_PS) {
472                         priv->needtowakeup = 0;
473                         priv->psstate = PS_STATE_AWAKE;
474
475                         lbs_deb_host("CMD_RESP: ENTER_PS command response\n");
476                         if (priv->connect_status != LBS_CONNECTED) {
477                                 /*
478                                  * When Deauth Event received before Enter_PS command
479                                  * response, We need to wake up the firmware.
480                                  */
481                                 lbs_deb_host(
482                                        "disconnected, invoking lbs_ps_wakeup\n");
483
484                                 spin_unlock_irqrestore(&priv->driver_lock, flags);
485                                 mutex_unlock(&priv->lock);
486                                 lbs_ps_wakeup(priv, 0);
487                                 mutex_lock(&priv->lock);
488                                 spin_lock_irqsave(&priv->driver_lock, flags);
489                         }
490                 } else if (action == CMD_SUBCMD_EXIT_PS) {
491                         priv->needtowakeup = 0;
492                         priv->psstate = PS_STATE_FULL_POWER;
493                         lbs_deb_host("CMD_RESP: EXIT_PS command response\n");
494                 } else {
495                         lbs_deb_host("CMD_RESP: PS action 0x%X\n", action);
496                 }
497
498                 lbs_complete_command(priv, priv->cur_cmd, result);
499                 spin_unlock_irqrestore(&priv->driver_lock, flags);
500
501                 ret = 0;
502                 goto done;
503         }
504
505         /* If the command is not successful, cleanup and return failure */
506         if ((result != 0 || !(respcmd & 0x8000))) {
507                 lbs_deb_host("CMD_RESP: error 0x%04x in command reply 0x%04x\n",
508                        result, respcmd);
509                 /*
510                  * Handling errors here
511                  */
512                 switch (respcmd) {
513                 case CMD_RET(CMD_GET_HW_SPEC):
514                 case CMD_RET(CMD_802_11_RESET):
515                         lbs_deb_host("CMD_RESP: reset failed\n");
516                         break;
517
518                 }
519                 lbs_complete_command(priv, priv->cur_cmd, result);
520                 spin_unlock_irqrestore(&priv->driver_lock, flags);
521
522                 ret = -1;
523                 goto done;
524         }
525
526         spin_unlock_irqrestore(&priv->driver_lock, flags);
527
528         if (priv->cur_cmd && priv->cur_cmd->callback) {
529                 ret = priv->cur_cmd->callback(priv, priv->cur_cmd->callback_arg,
530                                 resp);
531         } else
532                 ret = handle_cmd_response(priv, resp);
533
534         spin_lock_irqsave(&priv->driver_lock, flags);
535
536         if (priv->cur_cmd) {
537                 /* Clean up and Put current command back to cmdfreeq */
538                 lbs_complete_command(priv, priv->cur_cmd, result);
539         }
540         spin_unlock_irqrestore(&priv->driver_lock, flags);
541
542 done:
543         mutex_unlock(&priv->lock);
544         lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
545         return ret;
546 }
547
548 static int lbs_send_confirmwake(struct lbs_private *priv)
549 {
550         struct cmd_header cmd;
551         int ret = 0;
552
553         lbs_deb_enter(LBS_DEB_HOST);
554
555         cmd.command = cpu_to_le16(CMD_802_11_WAKEUP_CONFIRM);
556         cmd.size = cpu_to_le16(sizeof(cmd));
557         cmd.seqnum = cpu_to_le16(++priv->seqnum);
558         cmd.result = 0;
559
560         lbs_deb_hex(LBS_DEB_HOST, "wake confirm", (u8 *) &cmd,
561                 sizeof(cmd));
562
563         ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &cmd, sizeof(cmd));
564         if (ret)
565                 lbs_pr_alert("SEND_WAKEC_CMD: Host to Card failed for Confirm Wake\n");
566
567         lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
568         return ret;
569 }
570
571 int lbs_process_event(struct lbs_private *priv, u32 event)
572 {
573         int ret = 0;
574
575         lbs_deb_enter(LBS_DEB_CMD);
576
577         switch (event) {
578         case MACREG_INT_CODE_LINK_SENSED:
579                 lbs_deb_cmd("EVENT: link sensed\n");
580                 break;
581
582         case MACREG_INT_CODE_DEAUTHENTICATED:
583                 lbs_deb_cmd("EVENT: deauthenticated\n");
584                 lbs_mac_event_disconnected(priv);
585                 break;
586
587         case MACREG_INT_CODE_DISASSOCIATED:
588                 lbs_deb_cmd("EVENT: disassociated\n");
589                 lbs_mac_event_disconnected(priv);
590                 break;
591
592         case MACREG_INT_CODE_LINK_LOST_NO_SCAN:
593                 lbs_deb_cmd("EVENT: link lost\n");
594                 lbs_mac_event_disconnected(priv);
595                 break;
596
597         case MACREG_INT_CODE_PS_SLEEP:
598                 lbs_deb_cmd("EVENT: ps sleep\n");
599
600                 /* handle unexpected PS SLEEP event */
601                 if (priv->psstate == PS_STATE_FULL_POWER) {
602                         lbs_deb_cmd(
603                                "EVENT: in FULL POWER mode, ignoreing PS_SLEEP\n");
604                         break;
605                 }
606                 priv->psstate = PS_STATE_PRE_SLEEP;
607
608                 lbs_ps_confirm_sleep(priv);
609
610                 break;
611
612         case MACREG_INT_CODE_HOST_AWAKE:
613                 lbs_deb_cmd("EVENT: host awake\n");
614                 lbs_send_confirmwake(priv);
615                 break;
616
617         case MACREG_INT_CODE_PS_AWAKE:
618                 lbs_deb_cmd("EVENT: ps awake\n");
619                 /* handle unexpected PS AWAKE event */
620                 if (priv->psstate == PS_STATE_FULL_POWER) {
621                         lbs_deb_cmd(
622                                "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
623                         break;
624                 }
625
626                 priv->psstate = PS_STATE_AWAKE;
627
628                 if (priv->needtowakeup) {
629                         /*
630                          * wait for the command processing to finish
631                          * before resuming sending
632                          * priv->needtowakeup will be set to FALSE
633                          * in lbs_ps_wakeup()
634                          */
635                         lbs_deb_cmd("waking up ...\n");
636                         lbs_ps_wakeup(priv, 0);
637                 }
638                 break;
639
640         case MACREG_INT_CODE_MIC_ERR_UNICAST:
641                 lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n");
642                 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST);
643                 break;
644
645         case MACREG_INT_CODE_MIC_ERR_MULTICAST:
646                 lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n");
647                 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST);
648                 break;
649
650         case MACREG_INT_CODE_MIB_CHANGED:
651                 lbs_deb_cmd("EVENT: MIB CHANGED\n");
652                 break;
653         case MACREG_INT_CODE_INIT_DONE:
654                 lbs_deb_cmd("EVENT: INIT DONE\n");
655                 break;
656         case MACREG_INT_CODE_ADHOC_BCN_LOST:
657                 lbs_deb_cmd("EVENT: ADHOC beacon lost\n");
658                 break;
659         case MACREG_INT_CODE_RSSI_LOW:
660                 lbs_pr_alert("EVENT: rssi low\n");
661                 break;
662         case MACREG_INT_CODE_SNR_LOW:
663                 lbs_pr_alert("EVENT: snr low\n");
664                 break;
665         case MACREG_INT_CODE_MAX_FAIL:
666                 lbs_pr_alert("EVENT: max fail\n");
667                 break;
668         case MACREG_INT_CODE_RSSI_HIGH:
669                 lbs_pr_alert("EVENT: rssi high\n");
670                 break;
671         case MACREG_INT_CODE_SNR_HIGH:
672                 lbs_pr_alert("EVENT: snr high\n");
673                 break;
674
675         case MACREG_INT_CODE_MESH_AUTO_STARTED:
676                 /* Ignore spurious autostart events if autostart is disabled */
677                 if (!priv->mesh_autostart_enabled) {
678                         lbs_pr_info("EVENT: MESH_AUTO_STARTED (ignoring)\n");
679                         break;
680                 }
681                 lbs_pr_info("EVENT: MESH_AUTO_STARTED\n");
682                 priv->mesh_connect_status = LBS_CONNECTED;
683                 if (priv->mesh_open) {
684                         netif_carrier_on(priv->mesh_dev);
685                         if (!priv->tx_pending_len)
686                                 netif_wake_queue(priv->mesh_dev);
687                 }
688                 priv->mode = IW_MODE_ADHOC;
689                 schedule_work(&priv->sync_channel);
690                 break;
691
692         default:
693                 lbs_pr_alert("EVENT: unknown event id %d\n", event);
694                 break;
695         }
696
697         lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
698         return ret;
699 }