blob: 52b543c52a93717a8cebe8f0d3d57745609a3467 [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 */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09005#include <linux/slab.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02006#include <linux/delay.h>
Alan Cox767e3662009-10-12 05:27:48 +00007#include <linux/sched.h>
Cliff Cai2c5b9e512009-05-27 14:03:09 -04008#include <asm/unaligned.h>
Kiran Divekare86dc1c2010-06-14 22:01:26 +05309#include <net/cfg80211.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020010
Kiran Divekare86dc1c2010-06-14 22:01:26 +053011#include "cfg.h"
Amitkumar Karwar66fceb62010-05-19 03:24:38 -070012#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020013
14/**
15 * @brief This function handles disconnect event. it
16 * reports disconnect to upper layer, clean tx/rx packets,
17 * reset link state etc.
18 *
Holger Schurig69f90322007-11-23 15:43:44 +010019 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020020 * @return n/a
21 */
Holger Schurig69f90322007-11-23 15:43:44 +010022void lbs_mac_event_disconnected(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020023{
David Woodhouseaa21c002007-12-08 20:04:36 +000024 if (priv->connect_status != LBS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020025 return;
26
Holger Schurig91843462007-11-28 14:05:02 +010027 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020028
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020029 /*
30 * Cisco AP sends EAP failure and de-auth in less than 0.5 ms.
31 * It causes problem in the Supplicant
32 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020033 msleep_interruptible(1000);
Kiran Divekare4fe4ea2010-06-04 23:20:37 -070034
35 if (priv->wdev->iftype == NL80211_IFTYPE_STATION)
36 lbs_send_disconnect_notification(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020037
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020038 /* report disconnect to upper layer */
Holger Schurig634b8f492007-05-25 13:05:16 -040039 netif_stop_queue(priv->dev);
40 netif_carrier_off(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020041
David Woodhousea27b9f92007-12-12 00:41:51 -050042 /* Free Tx and Rx packets */
43 kfree_skb(priv->currenttxskb);
44 priv->currenttxskb = NULL;
45 priv->tx_pending_len = 0;
46
David Woodhouseaa21c002007-12-08 20:04:36 +000047 priv->connect_status = LBS_DISCONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020048
David Woodhouseaa21c002007-12-08 20:04:36 +000049 if (priv->psstate != PS_STATE_FULL_POWER) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020050 /* make firmware to exit PS mode */
Holger Schuriga6c87002007-08-02 11:54:10 -040051 lbs_deb_cmd("disconnected, so exit PS mode\n");
Holger Schurig10078322007-11-15 18:05:47 -050052 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020053 }
Holger Schurig52507c22008-01-28 17:25:53 +010054 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020055}
56
Holger Schurig69f90322007-11-23 15:43:44 +010057static int lbs_ret_reg_access(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020058 u16 type, struct cmd_ds_command *resp)
59{
Holger Schurig9012b282007-05-25 11:27:16 -040060 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020061
Holger Schurig9012b282007-05-25 11:27:16 -040062 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020063
64 switch (type) {
Holger Schurig6b63cd02007-08-02 11:53:36 -040065 case CMD_RET(CMD_MAC_REG_ACCESS):
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020066 {
David Woodhouse981f1872007-05-25 23:36:54 -040067 struct cmd_ds_mac_reg_access *reg = &resp->params.macreg;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020068
David Woodhouseaa21c002007-12-08 20:04:36 +000069 priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
70 priv->offsetvalue.value = le32_to_cpu(reg->value);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020071 break;
72 }
73
Holger Schurig6b63cd02007-08-02 11:53:36 -040074 case CMD_RET(CMD_BBP_REG_ACCESS):
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020075 {
David Woodhouse981f1872007-05-25 23:36:54 -040076 struct cmd_ds_bbp_reg_access *reg = &resp->params.bbpreg;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020077
David Woodhouseaa21c002007-12-08 20:04:36 +000078 priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
79 priv->offsetvalue.value = reg->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020080 break;
81 }
82
Holger Schurig6b63cd02007-08-02 11:53:36 -040083 case CMD_RET(CMD_RF_REG_ACCESS):
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020084 {
David Woodhouse981f1872007-05-25 23:36:54 -040085 struct cmd_ds_rf_reg_access *reg = &resp->params.rfreg;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020086
David Woodhouseaa21c002007-12-08 20:04:36 +000087 priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
88 priv->offsetvalue.value = reg->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020089 break;
90 }
91
92 default:
Holger Schurig9012b282007-05-25 11:27:16 -040093 ret = -1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020094 }
95
Holger Schurig8b17d722007-10-08 11:09:30 +020096 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Holger Schurig9012b282007-05-25 11:27:16 -040097 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020098}
99
David Woodhouse1309b552007-12-10 13:36:10 -0500100static inline int handle_cmd_response(struct lbs_private *priv,
Dan Williamsddac4522007-12-11 13:49:39 -0500101 struct cmd_header *cmd_response)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200102{
Dan Williamsddac4522007-12-11 13:49:39 -0500103 struct cmd_ds_command *resp = (struct cmd_ds_command *) cmd_response;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200104 int ret = 0;
105 unsigned long flags;
David Woodhouse1309b552007-12-10 13:36:10 -0500106 uint16_t respcmd = le16_to_cpu(resp->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200107
Holger Schuriga6c87002007-08-02 11:54:10 -0400108 lbs_deb_enter(LBS_DEB_HOST);
109
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200110 switch (respcmd) {
Holger Schurig6b63cd02007-08-02 11:53:36 -0400111 case CMD_RET(CMD_MAC_REG_ACCESS):
112 case CMD_RET(CMD_BBP_REG_ACCESS):
113 case CMD_RET(CMD_RF_REG_ACCESS):
Holger Schurig10078322007-11-15 18:05:47 -0500114 ret = lbs_ret_reg_access(priv, respcmd, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200115 break;
116
Holger Schurig6b63cd02007-08-02 11:53:36 -0400117 case CMD_RET(CMD_802_11_SET_AFC):
118 case CMD_RET(CMD_802_11_GET_AFC):
David Woodhouseaa21c002007-12-08 20:04:36 +0000119 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse75567672007-12-15 02:38:17 -0500120 memmove((void *)priv->cur_cmd->callback_arg, &resp->params.afc,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200121 sizeof(struct cmd_ds_802_11_afc));
David Woodhouseaa21c002007-12-08 20:04:36 +0000122 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200123
124 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200125
Holger Schurig6b63cd02007-08-02 11:53:36 -0400126 case CMD_RET(CMD_802_11_BEACON_STOP):
Dan Williams18c96c342007-06-18 12:01:12 -0400127 break;
128
Holger Schurig6b63cd02007-08-02 11:53:36 -0400129 case CMD_RET(CMD_802_11_RSSI):
Holger Schurig10078322007-11-15 18:05:47 -0500130 ret = lbs_ret_802_11_rssi(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200131 break;
132
Holger Schurig6b63cd02007-08-02 11:53:36 -0400133 case CMD_RET(CMD_802_11_TPC_CFG):
David Woodhouseaa21c002007-12-08 20:04:36 +0000134 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse75567672007-12-15 02:38:17 -0500135 memmove((void *)priv->cur_cmd->callback_arg, &resp->params.tpccfg,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200136 sizeof(struct cmd_ds_802_11_tpc_cfg));
David Woodhouseaa21c002007-12-08 20:04:36 +0000137 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200138 break;
Holger Schurig3a188642007-11-26 10:07:14 +0100139
Holger Schurig6b63cd02007-08-02 11:53:36 -0400140 case CMD_RET(CMD_BT_ACCESS):
David Woodhouseaa21c002007-12-08 20:04:36 +0000141 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse75567672007-12-15 02:38:17 -0500142 if (priv->cur_cmd->callback_arg)
143 memcpy((void *)priv->cur_cmd->callback_arg,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200144 &resp->params.bt.addr1, 2 * ETH_ALEN);
David Woodhouseaa21c002007-12-08 20:04:36 +0000145 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200146 break;
Holger Schurig6b63cd02007-08-02 11:53:36 -0400147 case CMD_RET(CMD_FWT_ACCESS):
David Woodhouseaa21c002007-12-08 20:04:36 +0000148 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse75567672007-12-15 02:38:17 -0500149 if (priv->cur_cmd->callback_arg)
150 memcpy((void *)priv->cur_cmd->callback_arg, &resp->params.fwt,
David Woodhouse981f1872007-05-25 23:36:54 -0400151 sizeof(resp->params.fwt));
David Woodhouseaa21c002007-12-08 20:04:36 +0000152 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200153 break;
Brajesh Dave96287ac2007-11-20 17:44:28 -0500154 case CMD_RET(CMD_802_11_BEACON_CTRL):
155 ret = lbs_ret_802_11_bcn_ctrl(priv, resp);
156 break;
157
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200158 default:
David Woodhousee37fc6e2008-05-20 11:47:16 +0100159 lbs_pr_err("CMD_RESP: unknown cmd response 0x%04x\n",
160 le16_to_cpu(resp->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200161 break;
162 }
Holger Schuriga6c87002007-08-02 11:54:10 -0400163 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200164 return ret;
165}
166
Holger Schurig7919b892008-04-01 14:50:43 +0200167int lbs_process_command_response(struct lbs_private *priv, u8 *data, u32 len)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200168{
David Woodhousee1258172007-12-11 23:42:49 -0500169 uint16_t respcmd, curcmd;
Dan Williamsddac4522007-12-11 13:49:39 -0500170 struct cmd_header *resp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200171 int ret = 0;
David Woodhousee1258172007-12-11 23:42:49 -0500172 unsigned long flags;
173 uint16_t result;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200174
Holger Schuriga6c87002007-08-02 11:54:10 -0400175 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200176
David Woodhouseaa21c002007-12-08 20:04:36 +0000177 mutex_lock(&priv->lock);
178 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200179
David Woodhouseaa21c002007-12-08 20:04:36 +0000180 if (!priv->cur_cmd) {
Holger Schuriga6c87002007-08-02 11:54:10 -0400181 lbs_deb_host("CMD_RESP: cur_cmd is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200182 ret = -1;
David Woodhouseaa21c002007-12-08 20:04:36 +0000183 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200184 goto done;
185 }
David Woodhousee1258172007-12-11 23:42:49 -0500186
Holger Schurig7919b892008-04-01 14:50:43 +0200187 resp = (void *)data;
Sebastian Siewior8a96df82008-03-04 18:22:27 +0100188 curcmd = le16_to_cpu(priv->cur_cmd->cmdbuf->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200189 respcmd = le16_to_cpu(resp->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200190 result = le16_to_cpu(resp->result);
191
Holger Schurige5225b32008-03-26 10:04:44 +0100192 lbs_deb_cmd("CMD_RESP: response 0x%04x, seq %d, size %d\n",
Holger Schurig7919b892008-04-01 14:50:43 +0200193 respcmd, le16_to_cpu(resp->seqnum), len);
194 lbs_deb_hex(LBS_DEB_CMD, "CMD_RESP", (void *) resp, len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200195
David Woodhouse6305f492008-03-03 12:20:12 +0100196 if (resp->seqnum != priv->cur_cmd->cmdbuf->seqnum) {
David Woodhousee1258172007-12-11 23:42:49 -0500197 lbs_pr_info("Received CMD_RESP with invalid sequence %d (expected %d)\n",
David Woodhouse6305f492008-03-03 12:20:12 +0100198 le16_to_cpu(resp->seqnum), le16_to_cpu(priv->cur_cmd->cmdbuf->seqnum));
David Woodhouseaa21c002007-12-08 20:04:36 +0000199 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200200 ret = -1;
201 goto done;
202 }
David Woodhousee1258172007-12-11 23:42:49 -0500203 if (respcmd != CMD_RET(curcmd) &&
Sebastian Siewior5f0547c22008-03-06 10:30:21 +0100204 respcmd != CMD_RET_802_11_ASSOCIATE && curcmd != CMD_802_11_ASSOCIATE) {
David Woodhousee1258172007-12-11 23:42:49 -0500205 lbs_pr_info("Invalid CMD_RESP %x to command %x!\n", respcmd, curcmd);
206 spin_unlock_irqrestore(&priv->driver_lock, flags);
207 ret = -1;
208 goto done;
209 }
210
David Woodhouse85388232007-12-17 15:41:30 -0500211 if (resp->result == cpu_to_le16(0x0004)) {
212 /* 0x0004 means -EAGAIN. Drop the response, let it time out
213 and be resubmitted */
214 lbs_pr_info("Firmware returns DEFER to command %x. Will let it time out...\n",
215 le16_to_cpu(resp->command));
216 spin_unlock_irqrestore(&priv->driver_lock, flags);
217 ret = -1;
218 goto done;
219 }
220
David Woodhousee1258172007-12-11 23:42:49 -0500221 /* Now we got response from FW, cancel the command timer */
222 del_timer(&priv->command_timer);
David Woodhouse2a345092007-12-15 19:33:43 -0500223 priv->cmd_timed_out = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200224
225 /* Store the response code to cur_cmd_retcode. */
David Woodhouseaa21c002007-12-08 20:04:36 +0000226 priv->cur_cmd_retcode = result;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200227
Holger Schurig6b63cd02007-08-02 11:53:36 -0400228 if (respcmd == CMD_RET(CMD_802_11_PS_MODE)) {
David Woodhouse38bfab12007-12-16 23:26:54 -0500229 struct cmd_ds_802_11_ps_mode *psmode = (void *) &resp[1];
David Woodhouse981f1872007-05-25 23:36:54 -0400230 u16 action = le16_to_cpu(psmode->action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200231
Holger Schuriga6c87002007-08-02 11:54:10 -0400232 lbs_deb_host(
233 "CMD_RESP: PS_MODE cmd reply result 0x%x, action 0x%x\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400234 result, action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200235
236 if (result) {
Holger Schuriga6c87002007-08-02 11:54:10 -0400237 lbs_deb_host("CMD_RESP: PS command failed with 0x%x\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400238 result);
239 /*
240 * We should not re-try enter-ps command in
241 * ad-hoc mode. It takes place in
Holger Schurig10078322007-11-15 18:05:47 -0500242 * lbs_execute_next_command().
David Woodhouse981f1872007-05-25 23:36:54 -0400243 */
Kiran Divekare86dc1c2010-06-14 22:01:26 +0530244 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR &&
Dan Williams0aef64d2007-08-02 11:31:18 -0400245 action == CMD_SUBCMD_ENTER_PS)
David Woodhouseaa21c002007-12-08 20:04:36 +0000246 priv->psmode = LBS802_11POWERMODECAM;
Dan Williams0aef64d2007-08-02 11:31:18 -0400247 } else if (action == CMD_SUBCMD_ENTER_PS) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000248 priv->needtowakeup = 0;
249 priv->psstate = PS_STATE_AWAKE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200250
Holger Schuriga6c87002007-08-02 11:54:10 -0400251 lbs_deb_host("CMD_RESP: ENTER_PS command response\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000252 if (priv->connect_status != LBS_CONNECTED) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200253 /*
254 * When Deauth Event received before Enter_PS command
255 * response, We need to wake up the firmware.
256 */
Holger Schuriga6c87002007-08-02 11:54:10 -0400257 lbs_deb_host(
Holger Schurig10078322007-11-15 18:05:47 -0500258 "disconnected, invoking lbs_ps_wakeup\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200259
David Woodhouseaa21c002007-12-08 20:04:36 +0000260 spin_unlock_irqrestore(&priv->driver_lock, flags);
261 mutex_unlock(&priv->lock);
Holger Schurig10078322007-11-15 18:05:47 -0500262 lbs_ps_wakeup(priv, 0);
David Woodhouseaa21c002007-12-08 20:04:36 +0000263 mutex_lock(&priv->lock);
264 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200265 }
Dan Williams0aef64d2007-08-02 11:31:18 -0400266 } else if (action == CMD_SUBCMD_EXIT_PS) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000267 priv->needtowakeup = 0;
268 priv->psstate = PS_STATE_FULL_POWER;
Holger Schuriga6c87002007-08-02 11:54:10 -0400269 lbs_deb_host("CMD_RESP: EXIT_PS command response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200270 } else {
Holger Schuriga6c87002007-08-02 11:54:10 -0400271 lbs_deb_host("CMD_RESP: PS action 0x%X\n", action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200272 }
273
David Woodhouse183aeac2007-12-15 01:52:54 -0500274 lbs_complete_command(priv, priv->cur_cmd, result);
David Woodhouseaa21c002007-12-08 20:04:36 +0000275 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200276
277 ret = 0;
278 goto done;
279 }
280
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200281 /* If the command is not successful, cleanup and return failure */
282 if ((result != 0 || !(respcmd & 0x8000))) {
Holger Schuriga6c87002007-08-02 11:54:10 -0400283 lbs_deb_host("CMD_RESP: error 0x%04x in command reply 0x%04x\n",
284 result, respcmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200285 /*
286 * Handling errors here
287 */
288 switch (respcmd) {
Holger Schurig6b63cd02007-08-02 11:53:36 -0400289 case CMD_RET(CMD_GET_HW_SPEC):
290 case CMD_RET(CMD_802_11_RESET):
Holger Schuriga6c87002007-08-02 11:54:10 -0400291 lbs_deb_host("CMD_RESP: reset failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200292 break;
293
294 }
David Woodhouse183aeac2007-12-15 01:52:54 -0500295 lbs_complete_command(priv, priv->cur_cmd, result);
David Woodhouseaa21c002007-12-08 20:04:36 +0000296 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200297
298 ret = -1;
299 goto done;
300 }
301
David Woodhouseaa21c002007-12-08 20:04:36 +0000302 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhouse17230472007-12-07 15:13:05 +0000303
Dan Williams7ad994d2007-12-11 12:33:30 -0500304 if (priv->cur_cmd && priv->cur_cmd->callback) {
305 ret = priv->cur_cmd->callback(priv, priv->cur_cmd->callback_arg,
Dan Williamsddac4522007-12-11 13:49:39 -0500306 resp);
Dan Williams7ad994d2007-12-11 12:33:30 -0500307 } else
Holger Schurige98a88d2008-03-19 14:25:58 +0100308 ret = handle_cmd_response(priv, resp);
David Woodhouse17230472007-12-07 15:13:05 +0000309
David Woodhouseaa21c002007-12-08 20:04:36 +0000310 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse17230472007-12-07 15:13:05 +0000311
David Woodhouseaa21c002007-12-08 20:04:36 +0000312 if (priv->cur_cmd) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200313 /* Clean up and Put current command back to cmdfreeq */
David Woodhouse183aeac2007-12-15 01:52:54 -0500314 lbs_complete_command(priv, priv->cur_cmd, result);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200315 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000316 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200317
318done:
David Woodhouseaa21c002007-12-08 20:04:36 +0000319 mutex_unlock(&priv->lock);
Holger Schuriga6c87002007-08-02 11:54:10 -0400320 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200321 return ret;
322}
323
Holger Schurig7919b892008-04-01 14:50:43 +0200324int lbs_process_event(struct lbs_private *priv, u32 event)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200325{
326 int ret = 0;
Amitkumar Karwar66fceb62010-05-19 03:24:38 -0700327 struct cmd_header cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200328
Holger Schurig9556d212007-08-02 13:14:07 -0400329 lbs_deb_enter(LBS_DEB_CMD);
330
Holger Schurig7919b892008-04-01 14:50:43 +0200331 switch (event) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200332 case MACREG_INT_CODE_LINK_SENSED:
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100333 lbs_deb_cmd("EVENT: link sensed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200334 break;
335
336 case MACREG_INT_CODE_DEAUTHENTICATED:
Holger Schuriga6c87002007-08-02 11:54:10 -0400337 lbs_deb_cmd("EVENT: deauthenticated\n");
Holger Schurig10078322007-11-15 18:05:47 -0500338 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200339 break;
340
341 case MACREG_INT_CODE_DISASSOCIATED:
Holger Schuriga6c87002007-08-02 11:54:10 -0400342 lbs_deb_cmd("EVENT: disassociated\n");
Holger Schurig10078322007-11-15 18:05:47 -0500343 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200344 break;
345
Holger Schurig0b3c07f2007-11-28 09:15:11 +0100346 case MACREG_INT_CODE_LINK_LOST_NO_SCAN:
Holger Schuriga6c87002007-08-02 11:54:10 -0400347 lbs_deb_cmd("EVENT: link lost\n");
Holger Schurig10078322007-11-15 18:05:47 -0500348 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200349 break;
350
351 case MACREG_INT_CODE_PS_SLEEP:
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100352 lbs_deb_cmd("EVENT: ps sleep\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200353
354 /* handle unexpected PS SLEEP event */
David Woodhouseaa21c002007-12-08 20:04:36 +0000355 if (priv->psstate == PS_STATE_FULL_POWER) {
Holger Schurig9012b282007-05-25 11:27:16 -0400356 lbs_deb_cmd(
Holger Schuriga6c87002007-08-02 11:54:10 -0400357 "EVENT: in FULL POWER mode, ignoreing PS_SLEEP\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200358 break;
359 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000360 priv->psstate = PS_STATE_PRE_SLEEP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200361
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100362 lbs_ps_confirm_sleep(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200363
364 break;
365
David Woodhouseb47ef242007-12-17 13:26:42 -0500366 case MACREG_INT_CODE_HOST_AWAKE:
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100367 lbs_deb_cmd("EVENT: host awake\n");
Amitkumar Karwar49125452009-09-30 20:04:38 -0700368 if (priv->reset_deep_sleep_wakeup)
369 priv->reset_deep_sleep_wakeup(priv);
370 priv->is_deep_sleep = 0;
Amitkumar Karwar66fceb62010-05-19 03:24:38 -0700371 lbs_cmd_async(priv, CMD_802_11_WAKEUP_CONFIRM, &cmd,
372 sizeof(cmd));
373 priv->is_host_sleep_activated = 0;
374 wake_up_interruptible(&priv->host_sleep_q);
David Woodhouseb47ef242007-12-17 13:26:42 -0500375 break;
376
Amitkumar Karwar49125452009-09-30 20:04:38 -0700377 case MACREG_INT_CODE_DEEP_SLEEP_AWAKE:
378 if (priv->reset_deep_sleep_wakeup)
379 priv->reset_deep_sleep_wakeup(priv);
380 lbs_deb_cmd("EVENT: ds awake\n");
381 priv->is_deep_sleep = 0;
382 priv->wakeup_dev_required = 0;
383 wake_up_interruptible(&priv->ds_awake_q);
384 break;
385
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200386 case MACREG_INT_CODE_PS_AWAKE:
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100387 lbs_deb_cmd("EVENT: ps awake\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200388 /* handle unexpected PS AWAKE event */
David Woodhouseaa21c002007-12-08 20:04:36 +0000389 if (priv->psstate == PS_STATE_FULL_POWER) {
Holger Schurig9012b282007-05-25 11:27:16 -0400390 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200391 "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
392 break;
393 }
394
David Woodhouseaa21c002007-12-08 20:04:36 +0000395 priv->psstate = PS_STATE_AWAKE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200396
David Woodhouseaa21c002007-12-08 20:04:36 +0000397 if (priv->needtowakeup) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200398 /*
399 * wait for the command processing to finish
400 * before resuming sending
David Woodhouseaa21c002007-12-08 20:04:36 +0000401 * priv->needtowakeup will be set to FALSE
Holger Schurig10078322007-11-15 18:05:47 -0500402 * in lbs_ps_wakeup()
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200403 */
Holger Schuriga6c87002007-08-02 11:54:10 -0400404 lbs_deb_cmd("waking up ...\n");
Holger Schurig10078322007-11-15 18:05:47 -0500405 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200406 }
407 break;
408
409 case MACREG_INT_CODE_MIC_ERR_UNICAST:
Holger Schurig9012b282007-05-25 11:27:16 -0400410 lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n");
Holger Schurig560c6332009-10-22 15:30:57 +0200411 lbs_send_mic_failureevent(priv, event);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200412 break;
413
414 case MACREG_INT_CODE_MIC_ERR_MULTICAST:
Holger Schurig9012b282007-05-25 11:27:16 -0400415 lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n");
Holger Schurig560c6332009-10-22 15:30:57 +0200416 lbs_send_mic_failureevent(priv, event);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200417 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200418
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100419 case MACREG_INT_CODE_MIB_CHANGED:
420 lbs_deb_cmd("EVENT: MIB CHANGED\n");
421 break;
422 case MACREG_INT_CODE_INIT_DONE:
423 lbs_deb_cmd("EVENT: INIT DONE\n");
424 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200425 case MACREG_INT_CODE_ADHOC_BCN_LOST:
Holger Schuriga6c87002007-08-02 11:54:10 -0400426 lbs_deb_cmd("EVENT: ADHOC beacon lost\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200427 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200428 case MACREG_INT_CODE_RSSI_LOW:
Holger Schuriga6c87002007-08-02 11:54:10 -0400429 lbs_pr_alert("EVENT: rssi low\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200430 break;
431 case MACREG_INT_CODE_SNR_LOW:
Holger Schuriga6c87002007-08-02 11:54:10 -0400432 lbs_pr_alert("EVENT: snr low\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200433 break;
434 case MACREG_INT_CODE_MAX_FAIL:
Holger Schuriga6c87002007-08-02 11:54:10 -0400435 lbs_pr_alert("EVENT: max fail\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200436 break;
437 case MACREG_INT_CODE_RSSI_HIGH:
Holger Schuriga6c87002007-08-02 11:54:10 -0400438 lbs_pr_alert("EVENT: rssi high\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200439 break;
440 case MACREG_INT_CODE_SNR_HIGH:
Holger Schuriga6c87002007-08-02 11:54:10 -0400441 lbs_pr_alert("EVENT: snr high\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200442 break;
443
Luis Carlos Cobo Rus7d8d28b2007-05-25 23:12:19 -0400444 case MACREG_INT_CODE_MESH_AUTO_STARTED:
Holger Schurigd6ede672009-12-02 15:25:57 +0100445 /* Ignore spurious autostart events */
446 lbs_pr_info("EVENT: MESH_AUTO_STARTED (ignoring)\n");
Luis Carlos Cobo Rus7d8d28b2007-05-25 23:12:19 -0400447 break;
448
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200449 default:
Holger Schurig7919b892008-04-01 14:50:43 +0200450 lbs_pr_alert("EVENT: unknown event id %d\n", event);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200451 break;
452 }
453
Holger Schurig9556d212007-08-02 13:14:07 -0400454 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200455 return ret;
456}