blob: 24de3c3cf877e1da4bb13dfc48573847316fa559 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
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"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020012#include "decl.h"
13#include "defs.h"
14#include "dev.h"
Holger Schurig697900a2008-04-02 16:27:10 +020015#include "assoc.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020016#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 *
Holger Schurig69f90322007-11-23 15:43:44 +010023 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020024 * @return n/a
25 */
Holger Schurig69f90322007-11-23 15:43:44 +010026void lbs_mac_event_disconnected(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020027{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020028 union iwreq_data wrqu;
29
David Woodhouseaa21c002007-12-08 20:04:36 +000030 if (priv->connect_status != LBS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020031 return;
32
Holger Schurig91843462007-11-28 14:05:02 +010033 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020034
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);
Holger Schurig634b8f42007-05-25 13:05:16 -040044 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020045
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020046 /* report disconnect to upper layer */
Holger Schurig634b8f42007-05-25 13:05:16 -040047 netif_stop_queue(priv->dev);
48 netif_carrier_off(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020049
David Woodhousea27b9f92007-12-12 00:41:51 -050050 /* Free Tx and Rx packets */
51 kfree_skb(priv->currenttxskb);
52 priv->currenttxskb = NULL;
53 priv->tx_pending_len = 0;
54
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020055 /* reset SNR/NF/RSSI values */
David Woodhouseaa21c002007-12-08 20:04:36 +000056 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;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020064
Dan Williamse76850d2007-05-25 17:09:41 -040065 /* Clear out associated SSID and BSSID since connection is
66 * no longer valid.
67 */
David Woodhouseaa21c002007-12-08 20:04:36 +000068 memset(&priv->curbssparams.bssid, 0, ETH_ALEN);
69 memset(&priv->curbssparams.ssid, 0, IW_ESSID_MAX_SIZE);
70 priv->curbssparams.ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020071
David Woodhouseaa21c002007-12-08 20:04:36 +000072 if (priv->psstate != PS_STATE_FULL_POWER) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020073 /* make firmware to exit PS mode */
Holger Schuriga6c87002007-08-02 11:54:10 -040074 lbs_deb_cmd("disconnected, so exit PS mode\n");
Holger Schurig10078322007-11-15 18:05:47 -050075 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020076 }
Holger Schurig52507c22008-01-28 17:25:53 +010077 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020078}
79
80/**
81 * @brief This function handles MIC failure event.
82 *
Holger Schurig69f90322007-11-23 15:43:44 +010083 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020084 * @para event the event id
85 * @return n/a
86 */
Holger Schurig69f90322007-11-23 15:43:44 +010087static void handle_mic_failureevent(struct lbs_private *priv, u32 event)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020088{
89 char buf[50];
90
Holger Schuriga6c87002007-08-02 11:54:10 -040091 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020092 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
Holger Schurig10078322007-11-15 18:05:47 -0500102 lbs_send_iwevcustom_event(priv, buf);
Holger Schuriga6c87002007-08-02 11:54:10 -0400103 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200104}
105
Holger Schurig69f90322007-11-23 15:43:44 +0100106static int lbs_ret_reg_access(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200107 u16 type, struct cmd_ds_command *resp)
108{
Holger Schurig9012b282007-05-25 11:27:16 -0400109 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200110
Holger Schurig9012b282007-05-25 11:27:16 -0400111 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200112
113 switch (type) {
Holger Schurig6b63cd02007-08-02 11:53:36 -0400114 case CMD_RET(CMD_MAC_REG_ACCESS):
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200115 {
David Woodhouse981f1872007-05-25 23:36:54 -0400116 struct cmd_ds_mac_reg_access *reg = &resp->params.macreg;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200117
David Woodhouseaa21c002007-12-08 20:04:36 +0000118 priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
119 priv->offsetvalue.value = le32_to_cpu(reg->value);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200120 break;
121 }
122
Holger Schurig6b63cd02007-08-02 11:53:36 -0400123 case CMD_RET(CMD_BBP_REG_ACCESS):
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200124 {
David Woodhouse981f1872007-05-25 23:36:54 -0400125 struct cmd_ds_bbp_reg_access *reg = &resp->params.bbpreg;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200126
David Woodhouseaa21c002007-12-08 20:04:36 +0000127 priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
128 priv->offsetvalue.value = reg->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200129 break;
130 }
131
Holger Schurig6b63cd02007-08-02 11:53:36 -0400132 case CMD_RET(CMD_RF_REG_ACCESS):
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200133 {
David Woodhouse981f1872007-05-25 23:36:54 -0400134 struct cmd_ds_rf_reg_access *reg = &resp->params.rfreg;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200135
David Woodhouseaa21c002007-12-08 20:04:36 +0000136 priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
137 priv->offsetvalue.value = reg->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200138 break;
139 }
140
141 default:
Holger Schurig9012b282007-05-25 11:27:16 -0400142 ret = -1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200143 }
144
Holger Schurig8b17d722007-10-08 11:09:30 +0200145 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Holger Schurig9012b282007-05-25 11:27:16 -0400146 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200147}
148
Holger Schurig69f90322007-11-23 15:43:44 +0100149static int lbs_ret_802_11_snmp_mib(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200150 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
Holger Schurig9012b282007-05-25 11:27:16 -0400156 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200157
Holger Schuriga6c87002007-08-02 11:54:10 -0400158 lbs_deb_cmd("SNMP_RESP: oid 0x%x, querytype 0x%x\n", oid,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200159 querytype);
Holger Schuriga6c87002007-08-02 11:54:10 -0400160 lbs_deb_cmd("SNMP_RESP: Buf size %d\n", le16_to_cpu(smib->bufsize));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200161
Dan Williams0aef64d2007-08-02 11:31:18 -0400162 if (querytype == CMD_ACT_GET) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200163 switch (oid) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400164 case FRAGTHRESH_I:
David Woodhouseaa21c002007-12-08 20:04:36 +0000165 priv->fragthsd =
David Woodhouse981f1872007-05-25 23:36:54 -0400166 le16_to_cpu(*((__le16 *)(smib->value)));
Holger Schuriga6c87002007-08-02 11:54:10 -0400167 lbs_deb_cmd("SNMP_RESP: frag threshold %u\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000168 priv->fragthsd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200169 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400170 case RTSTHRESH_I:
David Woodhouseaa21c002007-12-08 20:04:36 +0000171 priv->rtsthsd =
David Woodhouse981f1872007-05-25 23:36:54 -0400172 le16_to_cpu(*((__le16 *)(smib->value)));
Holger Schuriga6c87002007-08-02 11:54:10 -0400173 lbs_deb_cmd("SNMP_RESP: rts threshold %u\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000174 priv->rtsthsd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200175 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400176 case SHORT_RETRYLIM_I:
David Woodhouseaa21c002007-12-08 20:04:36 +0000177 priv->txretrycount =
David Woodhouse981f1872007-05-25 23:36:54 -0400178 le16_to_cpu(*((__le16 *)(smib->value)));
Holger Schuriga6c87002007-08-02 11:54:10 -0400179 lbs_deb_cmd("SNMP_RESP: tx retry count %u\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000180 priv->rtsthsd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200181 break;
182 default:
183 break;
184 }
185 }
186
Holger Schurig9012b282007-05-25 11:27:16 -0400187 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200188 return 0;
189}
190
Holger Schurig69f90322007-11-23 15:43:44 +0100191static int lbs_ret_802_11_rf_tx_power(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200192 struct cmd_ds_command *resp)
193{
194 struct cmd_ds_802_11_rf_tx_power *rtp = &resp->params.txp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200195
Holger Schurig9012b282007-05-25 11:27:16 -0400196 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200197
David Woodhouseaa21c002007-12-08 20:04:36 +0000198 priv->txpowerlevel = le16_to_cpu(rtp->currentlevel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200199
David Woodhouseaa21c002007-12-08 20:04:36 +0000200 lbs_deb_cmd("TX power currently %d\n", priv->txpowerlevel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200201
Holger Schuriga6c87002007-08-02 11:54:10 -0400202 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200203 return 0;
204}
205
Holger Schurig69f90322007-11-23 15:43:44 +0100206static int lbs_ret_802_11_rssi(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200207 struct cmd_ds_command *resp)
208{
209 struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200210
Holger Schuriga6c87002007-08-02 11:54:10 -0400211 lbs_deb_enter(LBS_DEB_CMD);
212
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200213 /* store the non average value */
David Woodhouseaa21c002007-12-08 20:04:36 +0000214 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR);
215 priv->NF[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->noisefloor);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200216
David Woodhouseaa21c002007-12-08 20:04:36 +0000217 priv->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR);
218 priv->NF[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgnoisefloor);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200219
David Woodhouseaa21c002007-12-08 20:04:36 +0000220 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] =
221 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
222 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200223
David Woodhouseaa21c002007-12-08 20:04:36 +0000224 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);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200227
Holger Schuriga6c87002007-08-02 11:54:10 -0400228 lbs_deb_cmd("RSSI: beacon %d, avg %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000229 priv->RSSI[TYPE_BEACON][TYPE_NOAVG],
230 priv->RSSI[TYPE_BEACON][TYPE_AVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200231
Holger Schuriga6c87002007-08-02 11:54:10 -0400232 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200233 return 0;
234}
235
Brajesh Dave96287ac2007-11-20 17:44:28 -0500236static 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;
Brajesh Dave96287ac2007-11-20 17:44:28 -0500241
242 lbs_deb_enter(LBS_DEB_CMD);
243
244 if (bcn_ctrl->action == CMD_ACT_GET) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000245 priv->beacon_enable = (u8) le16_to_cpu(bcn_ctrl->beacon_enable);
246 priv->beacon_period = le16_to_cpu(bcn_ctrl->beacon_period);
Brajesh Dave96287ac2007-11-20 17:44:28 -0500247 }
248
249 lbs_deb_enter(LBS_DEB_CMD);
250 return 0;
251}
252
David Woodhouse1309b552007-12-10 13:36:10 -0500253static inline int handle_cmd_response(struct lbs_private *priv,
Dan Williamsddac4522007-12-11 13:49:39 -0500254 struct cmd_header *cmd_response)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200255{
Dan Williamsddac4522007-12-11 13:49:39 -0500256 struct cmd_ds_command *resp = (struct cmd_ds_command *) cmd_response;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200257 int ret = 0;
258 unsigned long flags;
David Woodhouse1309b552007-12-10 13:36:10 -0500259 uint16_t respcmd = le16_to_cpu(resp->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200260
Holger Schuriga6c87002007-08-02 11:54:10 -0400261 lbs_deb_enter(LBS_DEB_HOST);
262
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200263 switch (respcmd) {
Holger Schurig6b63cd02007-08-02 11:53:36 -0400264 case CMD_RET(CMD_MAC_REG_ACCESS):
265 case CMD_RET(CMD_BBP_REG_ACCESS):
266 case CMD_RET(CMD_RF_REG_ACCESS):
Holger Schurig10078322007-11-15 18:05:47 -0500267 ret = lbs_ret_reg_access(priv, respcmd, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200268 break;
269
Dan Williams0aef64d2007-08-02 11:31:18 -0400270 case CMD_RET_802_11_ASSOCIATE:
Holger Schurig6b63cd02007-08-02 11:53:36 -0400271 case CMD_RET(CMD_802_11_ASSOCIATE):
272 case CMD_RET(CMD_802_11_REASSOCIATE):
Holger Schurig10078322007-11-15 18:05:47 -0500273 ret = lbs_ret_80211_associate(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200274 break;
275
Holger Schurig6b63cd02007-08-02 11:53:36 -0400276 case CMD_RET(CMD_802_11_DISASSOCIATE):
277 case CMD_RET(CMD_802_11_DEAUTHENTICATE):
Holger Schurige98a88d2008-03-19 14:25:58 +0100278 ret = lbs_ret_80211_disassociate(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200279 break;
280
Holger Schurig6b63cd02007-08-02 11:53:36 -0400281 case CMD_RET(CMD_802_11_AD_HOC_START):
282 case CMD_RET(CMD_802_11_AD_HOC_JOIN):
Holger Schurig10078322007-11-15 18:05:47 -0500283 ret = lbs_ret_80211_ad_hoc_start(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200284 break;
285
Holger Schurig6b63cd02007-08-02 11:53:36 -0400286 case CMD_RET(CMD_802_11_SNMP_MIB):
Holger Schurig10078322007-11-15 18:05:47 -0500287 ret = lbs_ret_802_11_snmp_mib(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200288 break;
289
Holger Schurig6b63cd02007-08-02 11:53:36 -0400290 case CMD_RET(CMD_802_11_RF_TX_POWER):
Holger Schurig10078322007-11-15 18:05:47 -0500291 ret = lbs_ret_802_11_rf_tx_power(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200292 break;
293
Holger Schurig6b63cd02007-08-02 11:53:36 -0400294 case CMD_RET(CMD_802_11_SET_AFC):
295 case CMD_RET(CMD_802_11_GET_AFC):
David Woodhouseaa21c002007-12-08 20:04:36 +0000296 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse75567672007-12-15 02:38:17 -0500297 memmove((void *)priv->cur_cmd->callback_arg, &resp->params.afc,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200298 sizeof(struct cmd_ds_802_11_afc));
David Woodhouseaa21c002007-12-08 20:04:36 +0000299 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200300
301 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200302
Holger Schurig6b63cd02007-08-02 11:53:36 -0400303 case CMD_RET(CMD_802_11_RESET):
304 case CMD_RET(CMD_802_11_AUTHENTICATE):
Holger Schurig6b63cd02007-08-02 11:53:36 -0400305 case CMD_RET(CMD_802_11_BEACON_STOP):
Dan Williams18c96c342007-06-18 12:01:12 -0400306 break;
307
Holger Schurig6b63cd02007-08-02 11:53:36 -0400308 case CMD_RET(CMD_802_11_RSSI):
Holger Schurig10078322007-11-15 18:05:47 -0500309 ret = lbs_ret_802_11_rssi(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200310 break;
311
Holger Schurig6b63cd02007-08-02 11:53:36 -0400312 case CMD_RET(CMD_802_11_AD_HOC_STOP):
Holger Schurige98a88d2008-03-19 14:25:58 +0100313 ret = lbs_ret_80211_ad_hoc_stop(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200314 break;
315
Holger Schurig6b63cd02007-08-02 11:53:36 -0400316 case CMD_RET(CMD_802_11D_DOMAIN_INFO):
Holger Schurige98a88d2008-03-19 14:25:58 +0100317 ret = lbs_ret_802_11d_domain_info(resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200318 break;
319
Holger Schurig6b63cd02007-08-02 11:53:36 -0400320 case CMD_RET(CMD_802_11_TPC_CFG):
David Woodhouseaa21c002007-12-08 20:04:36 +0000321 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse75567672007-12-15 02:38:17 -0500322 memmove((void *)priv->cur_cmd->callback_arg, &resp->params.tpccfg,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200323 sizeof(struct cmd_ds_802_11_tpc_cfg));
David Woodhouseaa21c002007-12-08 20:04:36 +0000324 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200325 break;
Holger Schurig6b63cd02007-08-02 11:53:36 -0400326 case CMD_RET(CMD_802_11_LED_GPIO_CTRL):
David Woodhouseaa21c002007-12-08 20:04:36 +0000327 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse75567672007-12-15 02:38:17 -0500328 memmove((void *)priv->cur_cmd->callback_arg, &resp->params.ledgpio,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200329 sizeof(struct cmd_ds_802_11_led_ctrl));
David Woodhouseaa21c002007-12-08 20:04:36 +0000330 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200331 break;
Holger Schurig3a188642007-11-26 10:07:14 +0100332
Holger Schurig6b63cd02007-08-02 11:53:36 -0400333 case CMD_RET(CMD_GET_TSF):
David Woodhouseaa21c002007-12-08 20:04:36 +0000334 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse75567672007-12-15 02:38:17 -0500335 memcpy((void *)priv->cur_cmd->callback_arg,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200336 &resp->params.gettsf.tsfvalue, sizeof(u64));
David Woodhouseaa21c002007-12-08 20:04:36 +0000337 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200338 break;
Holger Schurig6b63cd02007-08-02 11:53:36 -0400339 case CMD_RET(CMD_BT_ACCESS):
David Woodhouseaa21c002007-12-08 20:04:36 +0000340 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse75567672007-12-15 02:38:17 -0500341 if (priv->cur_cmd->callback_arg)
342 memcpy((void *)priv->cur_cmd->callback_arg,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200343 &resp->params.bt.addr1, 2 * ETH_ALEN);
David Woodhouseaa21c002007-12-08 20:04:36 +0000344 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200345 break;
Holger Schurig6b63cd02007-08-02 11:53:36 -0400346 case CMD_RET(CMD_FWT_ACCESS):
David Woodhouseaa21c002007-12-08 20:04:36 +0000347 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse75567672007-12-15 02:38:17 -0500348 if (priv->cur_cmd->callback_arg)
349 memcpy((void *)priv->cur_cmd->callback_arg, &resp->params.fwt,
David Woodhouse981f1872007-05-25 23:36:54 -0400350 sizeof(resp->params.fwt));
David Woodhouseaa21c002007-12-08 20:04:36 +0000351 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200352 break;
Brajesh Dave96287ac2007-11-20 17:44:28 -0500353 case CMD_RET(CMD_802_11_BEACON_CTRL):
354 ret = lbs_ret_802_11_bcn_ctrl(priv, resp);
355 break;
356
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200357 default:
David Woodhousee37fc6e2008-05-20 11:47:16 +0100358 lbs_pr_err("CMD_RESP: unknown cmd response 0x%04x\n",
359 le16_to_cpu(resp->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200360 break;
361 }
Holger Schuriga6c87002007-08-02 11:54:10 -0400362 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200363 return ret;
364}
365
Holger Schurig7919b892008-04-01 14:50:43 +0200366int lbs_process_command_response(struct lbs_private *priv, u8 *data, u32 len)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200367{
David Woodhousee1258172007-12-11 23:42:49 -0500368 uint16_t respcmd, curcmd;
Dan Williamsddac4522007-12-11 13:49:39 -0500369 struct cmd_header *resp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200370 int ret = 0;
David Woodhousee1258172007-12-11 23:42:49 -0500371 unsigned long flags;
372 uint16_t result;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200373
Holger Schuriga6c87002007-08-02 11:54:10 -0400374 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200375
David Woodhouseaa21c002007-12-08 20:04:36 +0000376 mutex_lock(&priv->lock);
377 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200378
David Woodhouseaa21c002007-12-08 20:04:36 +0000379 if (!priv->cur_cmd) {
Holger Schuriga6c87002007-08-02 11:54:10 -0400380 lbs_deb_host("CMD_RESP: cur_cmd is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200381 ret = -1;
David Woodhouseaa21c002007-12-08 20:04:36 +0000382 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200383 goto done;
384 }
David Woodhousee1258172007-12-11 23:42:49 -0500385
Holger Schurig7919b892008-04-01 14:50:43 +0200386 resp = (void *)data;
Sebastian Siewior8a96df82008-03-04 18:22:27 +0100387 curcmd = le16_to_cpu(priv->cur_cmd->cmdbuf->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200388 respcmd = le16_to_cpu(resp->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200389 result = le16_to_cpu(resp->result);
390
Holger Schurige5225b32008-03-26 10:04:44 +0100391 lbs_deb_cmd("CMD_RESP: response 0x%04x, seq %d, size %d\n",
Holger Schurig7919b892008-04-01 14:50:43 +0200392 respcmd, le16_to_cpu(resp->seqnum), len);
393 lbs_deb_hex(LBS_DEB_CMD, "CMD_RESP", (void *) resp, len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200394
David Woodhouse6305f492008-03-03 12:20:12 +0100395 if (resp->seqnum != priv->cur_cmd->cmdbuf->seqnum) {
David Woodhousee1258172007-12-11 23:42:49 -0500396 lbs_pr_info("Received CMD_RESP with invalid sequence %d (expected %d)\n",
David Woodhouse6305f492008-03-03 12:20:12 +0100397 le16_to_cpu(resp->seqnum), le16_to_cpu(priv->cur_cmd->cmdbuf->seqnum));
David Woodhouseaa21c002007-12-08 20:04:36 +0000398 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200399 ret = -1;
400 goto done;
401 }
David Woodhousee1258172007-12-11 23:42:49 -0500402 if (respcmd != CMD_RET(curcmd) &&
Sebastian Siewior5f0547c22008-03-06 10:30:21 +0100403 respcmd != CMD_RET_802_11_ASSOCIATE && curcmd != CMD_802_11_ASSOCIATE) {
David Woodhousee1258172007-12-11 23:42:49 -0500404 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
David Woodhouse85388232007-12-17 15:41:30 -0500410 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
David Woodhousee1258172007-12-11 23:42:49 -0500420 /* Now we got response from FW, cancel the command timer */
421 del_timer(&priv->command_timer);
David Woodhouse2a345092007-12-15 19:33:43 -0500422 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 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200428
429 /* Store the response code to cur_cmd_retcode. */
David Woodhouseaa21c002007-12-08 20:04:36 +0000430 priv->cur_cmd_retcode = result;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200431
Holger Schurig6b63cd02007-08-02 11:53:36 -0400432 if (respcmd == CMD_RET(CMD_802_11_PS_MODE)) {
David Woodhouse38bfab12007-12-16 23:26:54 -0500433 struct cmd_ds_802_11_ps_mode *psmode = (void *) &resp[1];
David Woodhouse981f1872007-05-25 23:36:54 -0400434 u16 action = le16_to_cpu(psmode->action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200435
Holger Schuriga6c87002007-08-02 11:54:10 -0400436 lbs_deb_host(
437 "CMD_RESP: PS_MODE cmd reply result 0x%x, action 0x%x\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400438 result, action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200439
440 if (result) {
Holger Schuriga6c87002007-08-02 11:54:10 -0400441 lbs_deb_host("CMD_RESP: PS command failed with 0x%x\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400442 result);
443 /*
444 * We should not re-try enter-ps command in
445 * ad-hoc mode. It takes place in
Holger Schurig10078322007-11-15 18:05:47 -0500446 * lbs_execute_next_command().
David Woodhouse981f1872007-05-25 23:36:54 -0400447 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000448 if (priv->mode == IW_MODE_ADHOC &&
Dan Williams0aef64d2007-08-02 11:31:18 -0400449 action == CMD_SUBCMD_ENTER_PS)
David Woodhouseaa21c002007-12-08 20:04:36 +0000450 priv->psmode = LBS802_11POWERMODECAM;
Dan Williams0aef64d2007-08-02 11:31:18 -0400451 } else if (action == CMD_SUBCMD_ENTER_PS) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000452 priv->needtowakeup = 0;
453 priv->psstate = PS_STATE_AWAKE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200454
Holger Schuriga6c87002007-08-02 11:54:10 -0400455 lbs_deb_host("CMD_RESP: ENTER_PS command response\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000456 if (priv->connect_status != LBS_CONNECTED) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200457 /*
458 * When Deauth Event received before Enter_PS command
459 * response, We need to wake up the firmware.
460 */
Holger Schuriga6c87002007-08-02 11:54:10 -0400461 lbs_deb_host(
Holger Schurig10078322007-11-15 18:05:47 -0500462 "disconnected, invoking lbs_ps_wakeup\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200463
David Woodhouseaa21c002007-12-08 20:04:36 +0000464 spin_unlock_irqrestore(&priv->driver_lock, flags);
465 mutex_unlock(&priv->lock);
Holger Schurig10078322007-11-15 18:05:47 -0500466 lbs_ps_wakeup(priv, 0);
David Woodhouseaa21c002007-12-08 20:04:36 +0000467 mutex_lock(&priv->lock);
468 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200469 }
Dan Williams0aef64d2007-08-02 11:31:18 -0400470 } else if (action == CMD_SUBCMD_EXIT_PS) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000471 priv->needtowakeup = 0;
472 priv->psstate = PS_STATE_FULL_POWER;
Holger Schuriga6c87002007-08-02 11:54:10 -0400473 lbs_deb_host("CMD_RESP: EXIT_PS command response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200474 } else {
Holger Schuriga6c87002007-08-02 11:54:10 -0400475 lbs_deb_host("CMD_RESP: PS action 0x%X\n", action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476 }
477
David Woodhouse183aeac2007-12-15 01:52:54 -0500478 lbs_complete_command(priv, priv->cur_cmd, result);
David Woodhouseaa21c002007-12-08 20:04:36 +0000479 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200480
481 ret = 0;
482 goto done;
483 }
484
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200485 /* If the command is not successful, cleanup and return failure */
486 if ((result != 0 || !(respcmd & 0x8000))) {
Holger Schuriga6c87002007-08-02 11:54:10 -0400487 lbs_deb_host("CMD_RESP: error 0x%04x in command reply 0x%04x\n",
488 result, respcmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200489 /*
490 * Handling errors here
491 */
492 switch (respcmd) {
Holger Schurig6b63cd02007-08-02 11:53:36 -0400493 case CMD_RET(CMD_GET_HW_SPEC):
494 case CMD_RET(CMD_802_11_RESET):
Holger Schuriga6c87002007-08-02 11:54:10 -0400495 lbs_deb_host("CMD_RESP: reset failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200496 break;
497
498 }
David Woodhouse183aeac2007-12-15 01:52:54 -0500499 lbs_complete_command(priv, priv->cur_cmd, result);
David Woodhouseaa21c002007-12-08 20:04:36 +0000500 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200501
502 ret = -1;
503 goto done;
504 }
505
David Woodhouseaa21c002007-12-08 20:04:36 +0000506 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhouse17230472007-12-07 15:13:05 +0000507
Dan Williams7ad994d2007-12-11 12:33:30 -0500508 if (priv->cur_cmd && priv->cur_cmd->callback) {
509 ret = priv->cur_cmd->callback(priv, priv->cur_cmd->callback_arg,
Dan Williamsddac4522007-12-11 13:49:39 -0500510 resp);
Dan Williams7ad994d2007-12-11 12:33:30 -0500511 } else
Holger Schurige98a88d2008-03-19 14:25:58 +0100512 ret = handle_cmd_response(priv, resp);
David Woodhouse17230472007-12-07 15:13:05 +0000513
David Woodhouseaa21c002007-12-08 20:04:36 +0000514 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse17230472007-12-07 15:13:05 +0000515
David Woodhouseaa21c002007-12-08 20:04:36 +0000516 if (priv->cur_cmd) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200517 /* Clean up and Put current command back to cmdfreeq */
David Woodhouse183aeac2007-12-15 01:52:54 -0500518 lbs_complete_command(priv, priv->cur_cmd, result);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200519 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000520 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200521
522done:
David Woodhouseaa21c002007-12-08 20:04:36 +0000523 mutex_unlock(&priv->lock);
Holger Schuriga6c87002007-08-02 11:54:10 -0400524 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200525 return ret;
526}
527
David Woodhouseb47ef242007-12-17 13:26:42 -0500528static int lbs_send_confirmwake(struct lbs_private *priv)
529{
Holger Schurigf539f2e2008-03-26 13:22:11 +0100530 struct cmd_header cmd;
David Woodhouseb47ef242007-12-17 13:26:42 -0500531 int ret = 0;
532
533 lbs_deb_enter(LBS_DEB_HOST);
534
Holger Schurigf539f2e2008-03-26 13:22:11 +0100535 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;
David Woodhouseb47ef242007-12-17 13:26:42 -0500539
Holger Schurigf539f2e2008-03-26 13:22:11 +0100540 lbs_deb_hex(LBS_DEB_HOST, "wake confirm", (u8 *) &cmd,
541 sizeof(cmd));
David Woodhouseb47ef242007-12-17 13:26:42 -0500542
Holger Schurigf539f2e2008-03-26 13:22:11 +0100543 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &cmd, sizeof(cmd));
David Woodhouseb47ef242007-12-17 13:26:42 -0500544 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
Holger Schurig7919b892008-04-01 14:50:43 +0200551int lbs_process_event(struct lbs_private *priv, u32 event)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200552{
553 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200554
Holger Schurig9556d212007-08-02 13:14:07 -0400555 lbs_deb_enter(LBS_DEB_CMD);
556
Holger Schurig7919b892008-04-01 14:50:43 +0200557 switch (event) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200558 case MACREG_INT_CODE_LINK_SENSED:
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100559 lbs_deb_cmd("EVENT: link sensed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200560 break;
561
562 case MACREG_INT_CODE_DEAUTHENTICATED:
Holger Schuriga6c87002007-08-02 11:54:10 -0400563 lbs_deb_cmd("EVENT: deauthenticated\n");
Holger Schurig10078322007-11-15 18:05:47 -0500564 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200565 break;
566
567 case MACREG_INT_CODE_DISASSOCIATED:
Holger Schuriga6c87002007-08-02 11:54:10 -0400568 lbs_deb_cmd("EVENT: disassociated\n");
Holger Schurig10078322007-11-15 18:05:47 -0500569 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200570 break;
571
Holger Schurig0b3c07f2007-11-28 09:15:11 +0100572 case MACREG_INT_CODE_LINK_LOST_NO_SCAN:
Holger Schuriga6c87002007-08-02 11:54:10 -0400573 lbs_deb_cmd("EVENT: link lost\n");
Holger Schurig10078322007-11-15 18:05:47 -0500574 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200575 break;
576
577 case MACREG_INT_CODE_PS_SLEEP:
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100578 lbs_deb_cmd("EVENT: ps sleep\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200579
580 /* handle unexpected PS SLEEP event */
David Woodhouseaa21c002007-12-08 20:04:36 +0000581 if (priv->psstate == PS_STATE_FULL_POWER) {
Holger Schurig9012b282007-05-25 11:27:16 -0400582 lbs_deb_cmd(
Holger Schuriga6c87002007-08-02 11:54:10 -0400583 "EVENT: in FULL POWER mode, ignoreing PS_SLEEP\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200584 break;
585 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000586 priv->psstate = PS_STATE_PRE_SLEEP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200587
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100588 lbs_ps_confirm_sleep(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200589
590 break;
591
David Woodhouseb47ef242007-12-17 13:26:42 -0500592 case MACREG_INT_CODE_HOST_AWAKE:
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100593 lbs_deb_cmd("EVENT: host awake\n");
David Woodhouseb47ef242007-12-17 13:26:42 -0500594 lbs_send_confirmwake(priv);
595 break;
596
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200597 case MACREG_INT_CODE_PS_AWAKE:
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100598 lbs_deb_cmd("EVENT: ps awake\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200599 /* handle unexpected PS AWAKE event */
David Woodhouseaa21c002007-12-08 20:04:36 +0000600 if (priv->psstate == PS_STATE_FULL_POWER) {
Holger Schurig9012b282007-05-25 11:27:16 -0400601 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200602 "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
603 break;
604 }
605
David Woodhouseaa21c002007-12-08 20:04:36 +0000606 priv->psstate = PS_STATE_AWAKE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200607
David Woodhouseaa21c002007-12-08 20:04:36 +0000608 if (priv->needtowakeup) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200609 /*
610 * wait for the command processing to finish
611 * before resuming sending
David Woodhouseaa21c002007-12-08 20:04:36 +0000612 * priv->needtowakeup will be set to FALSE
Holger Schurig10078322007-11-15 18:05:47 -0500613 * in lbs_ps_wakeup()
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200614 */
Holger Schuriga6c87002007-08-02 11:54:10 -0400615 lbs_deb_cmd("waking up ...\n");
Holger Schurig10078322007-11-15 18:05:47 -0500616 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200617 }
618 break;
619
620 case MACREG_INT_CODE_MIC_ERR_UNICAST:
Holger Schurig9012b282007-05-25 11:27:16 -0400621 lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200622 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST);
623 break;
624
625 case MACREG_INT_CODE_MIC_ERR_MULTICAST:
Holger Schurig9012b282007-05-25 11:27:16 -0400626 lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200627 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST);
628 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200629
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100630 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;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200636 case MACREG_INT_CODE_ADHOC_BCN_LOST:
Holger Schuriga6c87002007-08-02 11:54:10 -0400637 lbs_deb_cmd("EVENT: ADHOC beacon lost\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200638 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200639 case MACREG_INT_CODE_RSSI_LOW:
Holger Schuriga6c87002007-08-02 11:54:10 -0400640 lbs_pr_alert("EVENT: rssi low\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200641 break;
642 case MACREG_INT_CODE_SNR_LOW:
Holger Schuriga6c87002007-08-02 11:54:10 -0400643 lbs_pr_alert("EVENT: snr low\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200644 break;
645 case MACREG_INT_CODE_MAX_FAIL:
Holger Schuriga6c87002007-08-02 11:54:10 -0400646 lbs_pr_alert("EVENT: max fail\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200647 break;
648 case MACREG_INT_CODE_RSSI_HIGH:
Holger Schuriga6c87002007-08-02 11:54:10 -0400649 lbs_pr_alert("EVENT: rssi high\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200650 break;
651 case MACREG_INT_CODE_SNR_HIGH:
Holger Schuriga6c87002007-08-02 11:54:10 -0400652 lbs_pr_alert("EVENT: snr high\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200653 break;
654
Luis Carlos Cobo Rus7d8d28b2007-05-25 23:12:19 -0400655 case MACREG_INT_CODE_MESH_AUTO_STARTED:
Dan Williams5612c012007-08-02 13:20:12 -0400656 /* 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 }
Luis Carlos Cobo9cdc6d22007-08-02 11:55:22 -0400661 lbs_pr_info("EVENT: MESH_AUTO_STARTED\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000662 priv->mesh_connect_status = LBS_CONNECTED;
David Woodhousea27b9f92007-12-12 00:41:51 -0500663 if (priv->mesh_open) {
Luis Carlos Cobo9cdc6d22007-08-02 11:55:22 -0400664 netif_carrier_on(priv->mesh_dev);
David Woodhousea27b9f92007-12-12 00:41:51 -0500665 if (!priv->tx_pending_len)
666 netif_wake_queue(priv->mesh_dev);
Luis Carlos Cobo Rus7d8d28b2007-05-25 23:12:19 -0400667 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000668 priv->mode = IW_MODE_ADHOC;
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400669 schedule_work(&priv->sync_channel);
Luis Carlos Cobo Rus7d8d28b2007-05-25 23:12:19 -0400670 break;
671
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200672 default:
Holger Schurig7919b892008-04-01 14:50:43 +0200673 lbs_pr_alert("EVENT: unknown event id %d\n", event);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200674 break;
675 }
676
Holger Schurig9556d212007-08-02 13:14:07 -0400677 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200678 return ret;
679}