blob: abd20ea92553a384d6a9256e35a960d42b88dec7 [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>
Alan Cox767e3662009-10-12 05:27:48 +00006#include <linux/sched.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02007#include <linux/if_arp.h>
8#include <linux/netdevice.h>
Cliff Cai2c5b9e512009-05-27 14:03:09 -04009#include <asm/unaligned.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020010#include <net/iw_handler.h>
11
12#include "host.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020013#include "decl.h"
Holger Schurigbca61f82009-10-16 17:33:23 +020014#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020015#include "defs.h"
16#include "dev.h"
Holger Schurig697900a2008-04-02 16:27:10 +020017#include "assoc.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020018#include "wext.h"
19
20/**
21 * @brief This function handles disconnect event. it
22 * reports disconnect to upper layer, clean tx/rx packets,
23 * reset link state etc.
24 *
Holger Schurig69f90322007-11-23 15:43:44 +010025 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020026 * @return n/a
27 */
Holger Schurig69f90322007-11-23 15:43:44 +010028void lbs_mac_event_disconnected(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020029{
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
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020035 /*
36 * Cisco AP sends EAP failure and de-auth in less than 0.5 ms.
37 * It causes problem in the Supplicant
38 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020039 msleep_interruptible(1000);
Holger Schurigfea2b8e2009-10-22 15:30:56 +020040 lbs_send_disconnect_notification(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020041
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020042 /* report disconnect to upper layer */
Holger Schurig634b8f492007-05-25 13:05:16 -040043 netif_stop_queue(priv->dev);
44 netif_carrier_off(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020045
David Woodhousea27b9f92007-12-12 00:41:51 -050046 /* Free Tx and Rx packets */
47 kfree_skb(priv->currenttxskb);
48 priv->currenttxskb = NULL;
49 priv->tx_pending_len = 0;
50
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020051 /* reset SNR/NF/RSSI values */
David Woodhouseaa21c002007-12-08 20:04:36 +000052 memset(priv->SNR, 0x00, sizeof(priv->SNR));
53 memset(priv->NF, 0x00, sizeof(priv->NF));
54 memset(priv->RSSI, 0x00, sizeof(priv->RSSI));
55 memset(priv->rawSNR, 0x00, sizeof(priv->rawSNR));
56 memset(priv->rawNF, 0x00, sizeof(priv->rawNF));
57 priv->nextSNRNF = 0;
58 priv->numSNRNF = 0;
59 priv->connect_status = LBS_DISCONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020060
Dan Williamse76850d2007-05-25 17:09:41 -040061 /* Clear out associated SSID and BSSID since connection is
62 * no longer valid.
63 */
David Woodhouseaa21c002007-12-08 20:04:36 +000064 memset(&priv->curbssparams.bssid, 0, ETH_ALEN);
Holger Schurig243e84e2009-10-22 15:30:47 +020065 memset(&priv->curbssparams.ssid, 0, IEEE80211_MAX_SSID_LEN);
David Woodhouseaa21c002007-12-08 20:04:36 +000066 priv->curbssparams.ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020067
David Woodhouseaa21c002007-12-08 20:04:36 +000068 if (priv->psstate != PS_STATE_FULL_POWER) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020069 /* make firmware to exit PS mode */
Holger Schuriga6c87002007-08-02 11:54:10 -040070 lbs_deb_cmd("disconnected, so exit PS mode\n");
Holger Schurig10078322007-11-15 18:05:47 -050071 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020072 }
Holger Schurig52507c22008-01-28 17:25:53 +010073 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020074}
75
76/**
77 * @brief This function handles MIC failure event.
78 *
Holger Schurig69f90322007-11-23 15:43:44 +010079 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020080 * @para event the event id
81 * @return n/a
82 */
Holger Schurig69f90322007-11-23 15:43:44 +010083static void handle_mic_failureevent(struct lbs_private *priv, u32 event)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020084{
85 char buf[50];
86
Holger Schuriga6c87002007-08-02 11:54:10 -040087 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020088 memset(buf, 0, sizeof(buf));
89
90 sprintf(buf, "%s", "MLME-MICHAELMICFAILURE.indication ");
91
92 if (event == MACREG_INT_CODE_MIC_ERR_UNICAST) {
93 strcat(buf, "unicast ");
94 } else {
95 strcat(buf, "multicast ");
96 }
97
Holger Schurig10078322007-11-15 18:05:47 -050098 lbs_send_iwevcustom_event(priv, buf);
Holger Schuriga6c87002007-08-02 11:54:10 -040099 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200100}
101
Holger Schurig69f90322007-11-23 15:43:44 +0100102static int lbs_ret_reg_access(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200103 u16 type, struct cmd_ds_command *resp)
104{
Holger Schurig9012b282007-05-25 11:27:16 -0400105 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200106
Holger Schurig9012b282007-05-25 11:27:16 -0400107 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200108
109 switch (type) {
Holger Schurig6b63cd02007-08-02 11:53:36 -0400110 case CMD_RET(CMD_MAC_REG_ACCESS):
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200111 {
David Woodhouse981f1872007-05-25 23:36:54 -0400112 struct cmd_ds_mac_reg_access *reg = &resp->params.macreg;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200113
David Woodhouseaa21c002007-12-08 20:04:36 +0000114 priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
115 priv->offsetvalue.value = le32_to_cpu(reg->value);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200116 break;
117 }
118
Holger Schurig6b63cd02007-08-02 11:53:36 -0400119 case CMD_RET(CMD_BBP_REG_ACCESS):
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200120 {
David Woodhouse981f1872007-05-25 23:36:54 -0400121 struct cmd_ds_bbp_reg_access *reg = &resp->params.bbpreg;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200122
David Woodhouseaa21c002007-12-08 20:04:36 +0000123 priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
124 priv->offsetvalue.value = reg->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200125 break;
126 }
127
Holger Schurig6b63cd02007-08-02 11:53:36 -0400128 case CMD_RET(CMD_RF_REG_ACCESS):
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200129 {
David Woodhouse981f1872007-05-25 23:36:54 -0400130 struct cmd_ds_rf_reg_access *reg = &resp->params.rfreg;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200131
David Woodhouseaa21c002007-12-08 20:04:36 +0000132 priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
133 priv->offsetvalue.value = reg->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200134 break;
135 }
136
137 default:
Holger Schurig9012b282007-05-25 11:27:16 -0400138 ret = -1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200139 }
140
Holger Schurig8b17d722007-10-08 11:09:30 +0200141 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Holger Schurig9012b282007-05-25 11:27:16 -0400142 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200143}
144
David Woodhouse1309b552007-12-10 13:36:10 -0500145static inline int handle_cmd_response(struct lbs_private *priv,
Dan Williamsddac4522007-12-11 13:49:39 -0500146 struct cmd_header *cmd_response)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200147{
Dan Williamsddac4522007-12-11 13:49:39 -0500148 struct cmd_ds_command *resp = (struct cmd_ds_command *) cmd_response;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200149 int ret = 0;
150 unsigned long flags;
David Woodhouse1309b552007-12-10 13:36:10 -0500151 uint16_t respcmd = le16_to_cpu(resp->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200152
Holger Schuriga6c87002007-08-02 11:54:10 -0400153 lbs_deb_enter(LBS_DEB_HOST);
154
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200155 switch (respcmd) {
Holger Schurig6b63cd02007-08-02 11:53:36 -0400156 case CMD_RET(CMD_MAC_REG_ACCESS):
157 case CMD_RET(CMD_BBP_REG_ACCESS):
158 case CMD_RET(CMD_RF_REG_ACCESS):
Holger Schurig10078322007-11-15 18:05:47 -0500159 ret = lbs_ret_reg_access(priv, respcmd, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200160 break;
161
Holger Schurig6b63cd02007-08-02 11:53:36 -0400162 case CMD_RET(CMD_802_11_SET_AFC):
163 case CMD_RET(CMD_802_11_GET_AFC):
David Woodhouseaa21c002007-12-08 20:04:36 +0000164 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse75567672007-12-15 02:38:17 -0500165 memmove((void *)priv->cur_cmd->callback_arg, &resp->params.afc,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200166 sizeof(struct cmd_ds_802_11_afc));
David Woodhouseaa21c002007-12-08 20:04:36 +0000167 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200168
169 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200170
Holger Schurig6b63cd02007-08-02 11:53:36 -0400171 case CMD_RET(CMD_802_11_BEACON_STOP):
Dan Williams18c96c342007-06-18 12:01:12 -0400172 break;
173
Holger Schurig6b63cd02007-08-02 11:53:36 -0400174 case CMD_RET(CMD_802_11_RSSI):
Holger Schurig10078322007-11-15 18:05:47 -0500175 ret = lbs_ret_802_11_rssi(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200176 break;
177
Holger Schurig6b63cd02007-08-02 11:53:36 -0400178 case CMD_RET(CMD_802_11_TPC_CFG):
David Woodhouseaa21c002007-12-08 20:04:36 +0000179 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse75567672007-12-15 02:38:17 -0500180 memmove((void *)priv->cur_cmd->callback_arg, &resp->params.tpccfg,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200181 sizeof(struct cmd_ds_802_11_tpc_cfg));
David Woodhouseaa21c002007-12-08 20:04:36 +0000182 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200183 break;
Holger Schurig3a188642007-11-26 10:07:14 +0100184
Holger Schurig6b63cd02007-08-02 11:53:36 -0400185 case CMD_RET(CMD_BT_ACCESS):
David Woodhouseaa21c002007-12-08 20:04:36 +0000186 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse75567672007-12-15 02:38:17 -0500187 if (priv->cur_cmd->callback_arg)
188 memcpy((void *)priv->cur_cmd->callback_arg,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200189 &resp->params.bt.addr1, 2 * ETH_ALEN);
David Woodhouseaa21c002007-12-08 20:04:36 +0000190 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200191 break;
Holger Schurig6b63cd02007-08-02 11:53:36 -0400192 case CMD_RET(CMD_FWT_ACCESS):
David Woodhouseaa21c002007-12-08 20:04:36 +0000193 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse75567672007-12-15 02:38:17 -0500194 if (priv->cur_cmd->callback_arg)
195 memcpy((void *)priv->cur_cmd->callback_arg, &resp->params.fwt,
David Woodhouse981f1872007-05-25 23:36:54 -0400196 sizeof(resp->params.fwt));
David Woodhouseaa21c002007-12-08 20:04:36 +0000197 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200198 break;
Brajesh Dave96287ac2007-11-20 17:44:28 -0500199 case CMD_RET(CMD_802_11_BEACON_CTRL):
200 ret = lbs_ret_802_11_bcn_ctrl(priv, resp);
201 break;
202
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200203 default:
David Woodhousee37fc6e2008-05-20 11:47:16 +0100204 lbs_pr_err("CMD_RESP: unknown cmd response 0x%04x\n",
205 le16_to_cpu(resp->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200206 break;
207 }
Holger Schuriga6c87002007-08-02 11:54:10 -0400208 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200209 return ret;
210}
211
Holger Schurig7919b892008-04-01 14:50:43 +0200212int lbs_process_command_response(struct lbs_private *priv, u8 *data, u32 len)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200213{
David Woodhousee1258172007-12-11 23:42:49 -0500214 uint16_t respcmd, curcmd;
Dan Williamsddac4522007-12-11 13:49:39 -0500215 struct cmd_header *resp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200216 int ret = 0;
David Woodhousee1258172007-12-11 23:42:49 -0500217 unsigned long flags;
218 uint16_t result;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200219
Holger Schuriga6c87002007-08-02 11:54:10 -0400220 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200221
David Woodhouseaa21c002007-12-08 20:04:36 +0000222 mutex_lock(&priv->lock);
223 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200224
David Woodhouseaa21c002007-12-08 20:04:36 +0000225 if (!priv->cur_cmd) {
Holger Schuriga6c87002007-08-02 11:54:10 -0400226 lbs_deb_host("CMD_RESP: cur_cmd is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200227 ret = -1;
David Woodhouseaa21c002007-12-08 20:04:36 +0000228 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200229 goto done;
230 }
David Woodhousee1258172007-12-11 23:42:49 -0500231
Holger Schurig7919b892008-04-01 14:50:43 +0200232 resp = (void *)data;
Sebastian Siewior8a96df82008-03-04 18:22:27 +0100233 curcmd = le16_to_cpu(priv->cur_cmd->cmdbuf->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234 respcmd = le16_to_cpu(resp->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200235 result = le16_to_cpu(resp->result);
236
Holger Schurige5225b32008-03-26 10:04:44 +0100237 lbs_deb_cmd("CMD_RESP: response 0x%04x, seq %d, size %d\n",
Holger Schurig7919b892008-04-01 14:50:43 +0200238 respcmd, le16_to_cpu(resp->seqnum), len);
239 lbs_deb_hex(LBS_DEB_CMD, "CMD_RESP", (void *) resp, len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200240
David Woodhouse6305f492008-03-03 12:20:12 +0100241 if (resp->seqnum != priv->cur_cmd->cmdbuf->seqnum) {
David Woodhousee1258172007-12-11 23:42:49 -0500242 lbs_pr_info("Received CMD_RESP with invalid sequence %d (expected %d)\n",
David Woodhouse6305f492008-03-03 12:20:12 +0100243 le16_to_cpu(resp->seqnum), le16_to_cpu(priv->cur_cmd->cmdbuf->seqnum));
David Woodhouseaa21c002007-12-08 20:04:36 +0000244 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200245 ret = -1;
246 goto done;
247 }
David Woodhousee1258172007-12-11 23:42:49 -0500248 if (respcmd != CMD_RET(curcmd) &&
Sebastian Siewior5f0547c22008-03-06 10:30:21 +0100249 respcmd != CMD_RET_802_11_ASSOCIATE && curcmd != CMD_802_11_ASSOCIATE) {
David Woodhousee1258172007-12-11 23:42:49 -0500250 lbs_pr_info("Invalid CMD_RESP %x to command %x!\n", respcmd, curcmd);
251 spin_unlock_irqrestore(&priv->driver_lock, flags);
252 ret = -1;
253 goto done;
254 }
255
David Woodhouse85388232007-12-17 15:41:30 -0500256 if (resp->result == cpu_to_le16(0x0004)) {
257 /* 0x0004 means -EAGAIN. Drop the response, let it time out
258 and be resubmitted */
259 lbs_pr_info("Firmware returns DEFER to command %x. Will let it time out...\n",
260 le16_to_cpu(resp->command));
261 spin_unlock_irqrestore(&priv->driver_lock, flags);
262 ret = -1;
263 goto done;
264 }
265
David Woodhousee1258172007-12-11 23:42:49 -0500266 /* Now we got response from FW, cancel the command timer */
267 del_timer(&priv->command_timer);
David Woodhouse2a345092007-12-15 19:33:43 -0500268 priv->cmd_timed_out = 0;
269 if (priv->nr_retries) {
270 lbs_pr_info("Received result %x to command %x after %d retries\n",
271 result, curcmd, priv->nr_retries);
272 priv->nr_retries = 0;
273 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200274
275 /* Store the response code to cur_cmd_retcode. */
David Woodhouseaa21c002007-12-08 20:04:36 +0000276 priv->cur_cmd_retcode = result;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200277
Holger Schurig6b63cd02007-08-02 11:53:36 -0400278 if (respcmd == CMD_RET(CMD_802_11_PS_MODE)) {
David Woodhouse38bfab12007-12-16 23:26:54 -0500279 struct cmd_ds_802_11_ps_mode *psmode = (void *) &resp[1];
David Woodhouse981f1872007-05-25 23:36:54 -0400280 u16 action = le16_to_cpu(psmode->action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200281
Holger Schuriga6c87002007-08-02 11:54:10 -0400282 lbs_deb_host(
283 "CMD_RESP: PS_MODE cmd reply result 0x%x, action 0x%x\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400284 result, action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200285
286 if (result) {
Holger Schuriga6c87002007-08-02 11:54:10 -0400287 lbs_deb_host("CMD_RESP: PS command failed with 0x%x\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400288 result);
289 /*
290 * We should not re-try enter-ps command in
291 * ad-hoc mode. It takes place in
Holger Schurig10078322007-11-15 18:05:47 -0500292 * lbs_execute_next_command().
David Woodhouse981f1872007-05-25 23:36:54 -0400293 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000294 if (priv->mode == IW_MODE_ADHOC &&
Dan Williams0aef64d2007-08-02 11:31:18 -0400295 action == CMD_SUBCMD_ENTER_PS)
David Woodhouseaa21c002007-12-08 20:04:36 +0000296 priv->psmode = LBS802_11POWERMODECAM;
Dan Williams0aef64d2007-08-02 11:31:18 -0400297 } else if (action == CMD_SUBCMD_ENTER_PS) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000298 priv->needtowakeup = 0;
299 priv->psstate = PS_STATE_AWAKE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200300
Holger Schuriga6c87002007-08-02 11:54:10 -0400301 lbs_deb_host("CMD_RESP: ENTER_PS command response\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000302 if (priv->connect_status != LBS_CONNECTED) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200303 /*
304 * When Deauth Event received before Enter_PS command
305 * response, We need to wake up the firmware.
306 */
Holger Schuriga6c87002007-08-02 11:54:10 -0400307 lbs_deb_host(
Holger Schurig10078322007-11-15 18:05:47 -0500308 "disconnected, invoking lbs_ps_wakeup\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200309
David Woodhouseaa21c002007-12-08 20:04:36 +0000310 spin_unlock_irqrestore(&priv->driver_lock, flags);
311 mutex_unlock(&priv->lock);
Holger Schurig10078322007-11-15 18:05:47 -0500312 lbs_ps_wakeup(priv, 0);
David Woodhouseaa21c002007-12-08 20:04:36 +0000313 mutex_lock(&priv->lock);
314 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200315 }
Dan Williams0aef64d2007-08-02 11:31:18 -0400316 } else if (action == CMD_SUBCMD_EXIT_PS) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000317 priv->needtowakeup = 0;
318 priv->psstate = PS_STATE_FULL_POWER;
Holger Schuriga6c87002007-08-02 11:54:10 -0400319 lbs_deb_host("CMD_RESP: EXIT_PS command response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200320 } else {
Holger Schuriga6c87002007-08-02 11:54:10 -0400321 lbs_deb_host("CMD_RESP: PS action 0x%X\n", action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200322 }
323
David Woodhouse183aeac2007-12-15 01:52:54 -0500324 lbs_complete_command(priv, priv->cur_cmd, result);
David Woodhouseaa21c002007-12-08 20:04:36 +0000325 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200326
327 ret = 0;
328 goto done;
329 }
330
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200331 /* If the command is not successful, cleanup and return failure */
332 if ((result != 0 || !(respcmd & 0x8000))) {
Holger Schuriga6c87002007-08-02 11:54:10 -0400333 lbs_deb_host("CMD_RESP: error 0x%04x in command reply 0x%04x\n",
334 result, respcmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200335 /*
336 * Handling errors here
337 */
338 switch (respcmd) {
Holger Schurig6b63cd02007-08-02 11:53:36 -0400339 case CMD_RET(CMD_GET_HW_SPEC):
340 case CMD_RET(CMD_802_11_RESET):
Holger Schuriga6c87002007-08-02 11:54:10 -0400341 lbs_deb_host("CMD_RESP: reset failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200342 break;
343
344 }
David Woodhouse183aeac2007-12-15 01:52:54 -0500345 lbs_complete_command(priv, priv->cur_cmd, result);
David Woodhouseaa21c002007-12-08 20:04:36 +0000346 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200347
348 ret = -1;
349 goto done;
350 }
351
David Woodhouseaa21c002007-12-08 20:04:36 +0000352 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhouse17230472007-12-07 15:13:05 +0000353
Dan Williams7ad994d2007-12-11 12:33:30 -0500354 if (priv->cur_cmd && priv->cur_cmd->callback) {
355 ret = priv->cur_cmd->callback(priv, priv->cur_cmd->callback_arg,
Dan Williamsddac4522007-12-11 13:49:39 -0500356 resp);
Dan Williams7ad994d2007-12-11 12:33:30 -0500357 } else
Holger Schurige98a88d2008-03-19 14:25:58 +0100358 ret = handle_cmd_response(priv, resp);
David Woodhouse17230472007-12-07 15:13:05 +0000359
David Woodhouseaa21c002007-12-08 20:04:36 +0000360 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse17230472007-12-07 15:13:05 +0000361
David Woodhouseaa21c002007-12-08 20:04:36 +0000362 if (priv->cur_cmd) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200363 /* Clean up and Put current command back to cmdfreeq */
David Woodhouse183aeac2007-12-15 01:52:54 -0500364 lbs_complete_command(priv, priv->cur_cmd, result);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200365 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000366 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200367
368done:
David Woodhouseaa21c002007-12-08 20:04:36 +0000369 mutex_unlock(&priv->lock);
Holger Schuriga6c87002007-08-02 11:54:10 -0400370 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200371 return ret;
372}
373
David Woodhouseb47ef242007-12-17 13:26:42 -0500374static int lbs_send_confirmwake(struct lbs_private *priv)
375{
Holger Schurigf539f2e2008-03-26 13:22:11 +0100376 struct cmd_header cmd;
David Woodhouseb47ef242007-12-17 13:26:42 -0500377 int ret = 0;
378
379 lbs_deb_enter(LBS_DEB_HOST);
380
Holger Schurigf539f2e2008-03-26 13:22:11 +0100381 cmd.command = cpu_to_le16(CMD_802_11_WAKEUP_CONFIRM);
382 cmd.size = cpu_to_le16(sizeof(cmd));
383 cmd.seqnum = cpu_to_le16(++priv->seqnum);
384 cmd.result = 0;
David Woodhouseb47ef242007-12-17 13:26:42 -0500385
Holger Schurigf539f2e2008-03-26 13:22:11 +0100386 lbs_deb_hex(LBS_DEB_HOST, "wake confirm", (u8 *) &cmd,
387 sizeof(cmd));
David Woodhouseb47ef242007-12-17 13:26:42 -0500388
Holger Schurigf539f2e2008-03-26 13:22:11 +0100389 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &cmd, sizeof(cmd));
David Woodhouseb47ef242007-12-17 13:26:42 -0500390 if (ret)
391 lbs_pr_alert("SEND_WAKEC_CMD: Host to Card failed for Confirm Wake\n");
392
393 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
394 return ret;
395}
396
Holger Schurig7919b892008-04-01 14:50:43 +0200397int lbs_process_event(struct lbs_private *priv, u32 event)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200398{
399 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200400
Holger Schurig9556d212007-08-02 13:14:07 -0400401 lbs_deb_enter(LBS_DEB_CMD);
402
Holger Schurig7919b892008-04-01 14:50:43 +0200403 switch (event) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200404 case MACREG_INT_CODE_LINK_SENSED:
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100405 lbs_deb_cmd("EVENT: link sensed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200406 break;
407
408 case MACREG_INT_CODE_DEAUTHENTICATED:
Holger Schuriga6c87002007-08-02 11:54:10 -0400409 lbs_deb_cmd("EVENT: deauthenticated\n");
Holger Schurig10078322007-11-15 18:05:47 -0500410 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200411 break;
412
413 case MACREG_INT_CODE_DISASSOCIATED:
Holger Schuriga6c87002007-08-02 11:54:10 -0400414 lbs_deb_cmd("EVENT: disassociated\n");
Holger Schurig10078322007-11-15 18:05:47 -0500415 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200416 break;
417
Holger Schurig0b3c07f2007-11-28 09:15:11 +0100418 case MACREG_INT_CODE_LINK_LOST_NO_SCAN:
Holger Schuriga6c87002007-08-02 11:54:10 -0400419 lbs_deb_cmd("EVENT: link lost\n");
Holger Schurig10078322007-11-15 18:05:47 -0500420 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200421 break;
422
423 case MACREG_INT_CODE_PS_SLEEP:
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100424 lbs_deb_cmd("EVENT: ps sleep\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200425
426 /* handle unexpected PS SLEEP event */
David Woodhouseaa21c002007-12-08 20:04:36 +0000427 if (priv->psstate == PS_STATE_FULL_POWER) {
Holger Schurig9012b282007-05-25 11:27:16 -0400428 lbs_deb_cmd(
Holger Schuriga6c87002007-08-02 11:54:10 -0400429 "EVENT: in FULL POWER mode, ignoreing PS_SLEEP\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200430 break;
431 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000432 priv->psstate = PS_STATE_PRE_SLEEP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200433
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100434 lbs_ps_confirm_sleep(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200435
436 break;
437
David Woodhouseb47ef242007-12-17 13:26:42 -0500438 case MACREG_INT_CODE_HOST_AWAKE:
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100439 lbs_deb_cmd("EVENT: host awake\n");
Amitkumar Karwar49125452009-09-30 20:04:38 -0700440 if (priv->reset_deep_sleep_wakeup)
441 priv->reset_deep_sleep_wakeup(priv);
442 priv->is_deep_sleep = 0;
David Woodhouseb47ef242007-12-17 13:26:42 -0500443 lbs_send_confirmwake(priv);
444 break;
445
Amitkumar Karwar49125452009-09-30 20:04:38 -0700446 case MACREG_INT_CODE_DEEP_SLEEP_AWAKE:
447 if (priv->reset_deep_sleep_wakeup)
448 priv->reset_deep_sleep_wakeup(priv);
449 lbs_deb_cmd("EVENT: ds awake\n");
450 priv->is_deep_sleep = 0;
451 priv->wakeup_dev_required = 0;
452 wake_up_interruptible(&priv->ds_awake_q);
453 break;
454
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200455 case MACREG_INT_CODE_PS_AWAKE:
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100456 lbs_deb_cmd("EVENT: ps awake\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200457 /* handle unexpected PS AWAKE event */
David Woodhouseaa21c002007-12-08 20:04:36 +0000458 if (priv->psstate == PS_STATE_FULL_POWER) {
Holger Schurig9012b282007-05-25 11:27:16 -0400459 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200460 "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
461 break;
462 }
463
David Woodhouseaa21c002007-12-08 20:04:36 +0000464 priv->psstate = PS_STATE_AWAKE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200465
David Woodhouseaa21c002007-12-08 20:04:36 +0000466 if (priv->needtowakeup) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200467 /*
468 * wait for the command processing to finish
469 * before resuming sending
David Woodhouseaa21c002007-12-08 20:04:36 +0000470 * priv->needtowakeup will be set to FALSE
Holger Schurig10078322007-11-15 18:05:47 -0500471 * in lbs_ps_wakeup()
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200472 */
Holger Schuriga6c87002007-08-02 11:54:10 -0400473 lbs_deb_cmd("waking up ...\n");
Holger Schurig10078322007-11-15 18:05:47 -0500474 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200475 }
476 break;
477
478 case MACREG_INT_CODE_MIC_ERR_UNICAST:
Holger Schurig9012b282007-05-25 11:27:16 -0400479 lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200480 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST);
481 break;
482
483 case MACREG_INT_CODE_MIC_ERR_MULTICAST:
Holger Schurig9012b282007-05-25 11:27:16 -0400484 lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200485 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST);
486 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200487
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100488 case MACREG_INT_CODE_MIB_CHANGED:
489 lbs_deb_cmd("EVENT: MIB CHANGED\n");
490 break;
491 case MACREG_INT_CODE_INIT_DONE:
492 lbs_deb_cmd("EVENT: INIT DONE\n");
493 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200494 case MACREG_INT_CODE_ADHOC_BCN_LOST:
Holger Schuriga6c87002007-08-02 11:54:10 -0400495 lbs_deb_cmd("EVENT: ADHOC beacon lost\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200496 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200497 case MACREG_INT_CODE_RSSI_LOW:
Holger Schuriga6c87002007-08-02 11:54:10 -0400498 lbs_pr_alert("EVENT: rssi low\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200499 break;
500 case MACREG_INT_CODE_SNR_LOW:
Holger Schuriga6c87002007-08-02 11:54:10 -0400501 lbs_pr_alert("EVENT: snr low\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200502 break;
503 case MACREG_INT_CODE_MAX_FAIL:
Holger Schuriga6c87002007-08-02 11:54:10 -0400504 lbs_pr_alert("EVENT: max fail\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200505 break;
506 case MACREG_INT_CODE_RSSI_HIGH:
Holger Schuriga6c87002007-08-02 11:54:10 -0400507 lbs_pr_alert("EVENT: rssi high\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200508 break;
509 case MACREG_INT_CODE_SNR_HIGH:
Holger Schuriga6c87002007-08-02 11:54:10 -0400510 lbs_pr_alert("EVENT: snr high\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200511 break;
512
Luis Carlos Cobo Rus7d8d28b2007-05-25 23:12:19 -0400513 case MACREG_INT_CODE_MESH_AUTO_STARTED:
Dan Williams5612c012007-08-02 13:20:12 -0400514 /* Ignore spurious autostart events if autostart is disabled */
515 if (!priv->mesh_autostart_enabled) {
516 lbs_pr_info("EVENT: MESH_AUTO_STARTED (ignoring)\n");
517 break;
518 }
Luis Carlos Cobo9cdc6d22007-08-02 11:55:22 -0400519 lbs_pr_info("EVENT: MESH_AUTO_STARTED\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000520 priv->mesh_connect_status = LBS_CONNECTED;
David Woodhousea27b9f92007-12-12 00:41:51 -0500521 if (priv->mesh_open) {
Luis Carlos Cobo9cdc6d22007-08-02 11:55:22 -0400522 netif_carrier_on(priv->mesh_dev);
David Woodhousea27b9f92007-12-12 00:41:51 -0500523 if (!priv->tx_pending_len)
524 netif_wake_queue(priv->mesh_dev);
Luis Carlos Cobo Rus7d8d28b2007-05-25 23:12:19 -0400525 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000526 priv->mode = IW_MODE_ADHOC;
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400527 schedule_work(&priv->sync_channel);
Luis Carlos Cobo Rus7d8d28b2007-05-25 23:12:19 -0400528 break;
529
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200530 default:
Holger Schurig7919b892008-04-01 14:50:43 +0200531 lbs_pr_alert("EVENT: unknown event id %d\n", event);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200532 break;
533 }
534
Holger Schurig9556d212007-08-02 13:14:07 -0400535 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200536 return ret;
537}