blob: 89f83165e04ff07bb57c57dc2c78350ec0294947 [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"
15#include "join.h"
16#include "wext.h"
17
18/**
19 * @brief This function handles disconnect event. it
20 * reports disconnect to upper layer, clean tx/rx packets,
21 * reset link state etc.
22 *
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 Schuriga6c87002007-08-02 11:54:10 -040077 lbs_deb_leave(LBS_DEB_CMD);
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_sleep_params(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200150 struct cmd_ds_command *resp)
151{
152 struct cmd_ds_802_11_sleep_params *sp = &resp->params.sleep_params;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200153
Holger Schurig9012b282007-05-25 11:27:16 -0400154 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200155
Holger Schuriga6c87002007-08-02 11:54:10 -0400156 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, calcontrol 0x%x "
157 "extsleepclk 0x%x\n", le16_to_cpu(sp->error),
David Woodhouse981f1872007-05-25 23:36:54 -0400158 le16_to_cpu(sp->offset), le16_to_cpu(sp->stabletime),
159 sp->calcontrol, sp->externalsleepclk);
160
David Woodhouseaa21c002007-12-08 20:04:36 +0000161 priv->sp.sp_error = le16_to_cpu(sp->error);
162 priv->sp.sp_offset = le16_to_cpu(sp->offset);
163 priv->sp.sp_stabletime = le16_to_cpu(sp->stabletime);
164 priv->sp.sp_calcontrol = sp->calcontrol;
165 priv->sp.sp_extsleepclk = sp->externalsleepclk;
166 priv->sp.sp_reserved = le16_to_cpu(sp->reserved);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200167
Holger Schurig9012b282007-05-25 11:27:16 -0400168 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200169 return 0;
170}
171
Holger Schurig69f90322007-11-23 15:43:44 +0100172static int lbs_ret_802_11_stat(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200173 struct cmd_ds_command *resp)
174{
Holger Schuriga6c87002007-08-02 11:54:10 -0400175 lbs_deb_enter(LBS_DEB_CMD);
David Woodhouseaa21c002007-12-08 20:04:36 +0000176/* currently priv->wlan802_11Stat is unused
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200177
178 struct cmd_ds_802_11_get_stat *p11Stat = &resp->params.gstat;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200179
180 // TODO Convert it to Big endian befor copy
David Woodhouseaa21c002007-12-08 20:04:36 +0000181 memcpy(&priv->wlan802_11Stat,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200182 p11Stat, sizeof(struct cmd_ds_802_11_get_stat));
183*/
Holger Schuriga6c87002007-08-02 11:54:10 -0400184 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200185 return 0;
186}
187
Holger Schurig69f90322007-11-23 15:43:44 +0100188static int lbs_ret_802_11_snmp_mib(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200189 struct cmd_ds_command *resp)
190{
191 struct cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
192 u16 oid = le16_to_cpu(smib->oid);
193 u16 querytype = le16_to_cpu(smib->querytype);
194
Holger Schurig9012b282007-05-25 11:27:16 -0400195 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200196
Holger Schuriga6c87002007-08-02 11:54:10 -0400197 lbs_deb_cmd("SNMP_RESP: oid 0x%x, querytype 0x%x\n", oid,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200198 querytype);
Holger Schuriga6c87002007-08-02 11:54:10 -0400199 lbs_deb_cmd("SNMP_RESP: Buf size %d\n", le16_to_cpu(smib->bufsize));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200200
Dan Williams0aef64d2007-08-02 11:31:18 -0400201 if (querytype == CMD_ACT_GET) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200202 switch (oid) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400203 case FRAGTHRESH_I:
David Woodhouseaa21c002007-12-08 20:04:36 +0000204 priv->fragthsd =
David Woodhouse981f1872007-05-25 23:36:54 -0400205 le16_to_cpu(*((__le16 *)(smib->value)));
Holger Schuriga6c87002007-08-02 11:54:10 -0400206 lbs_deb_cmd("SNMP_RESP: frag threshold %u\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000207 priv->fragthsd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200208 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400209 case RTSTHRESH_I:
David Woodhouseaa21c002007-12-08 20:04:36 +0000210 priv->rtsthsd =
David Woodhouse981f1872007-05-25 23:36:54 -0400211 le16_to_cpu(*((__le16 *)(smib->value)));
Holger Schuriga6c87002007-08-02 11:54:10 -0400212 lbs_deb_cmd("SNMP_RESP: rts threshold %u\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000213 priv->rtsthsd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200214 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400215 case SHORT_RETRYLIM_I:
David Woodhouseaa21c002007-12-08 20:04:36 +0000216 priv->txretrycount =
David Woodhouse981f1872007-05-25 23:36:54 -0400217 le16_to_cpu(*((__le16 *)(smib->value)));
Holger Schuriga6c87002007-08-02 11:54:10 -0400218 lbs_deb_cmd("SNMP_RESP: tx retry count %u\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000219 priv->rtsthsd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200220 break;
221 default:
222 break;
223 }
224 }
225
Holger Schurig9012b282007-05-25 11:27:16 -0400226 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200227 return 0;
228}
229
Holger Schurig69f90322007-11-23 15:43:44 +0100230static int lbs_ret_802_11_key_material(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200231 struct cmd_ds_command *resp)
232{
233 struct cmd_ds_802_11_key_material *pkeymaterial =
234 &resp->params.keymaterial;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200235 u16 action = le16_to_cpu(pkeymaterial->action);
236
Holger Schurig9012b282007-05-25 11:27:16 -0400237 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200238
239 /* Copy the returned key to driver private data */
Dan Williams0aef64d2007-08-02 11:31:18 -0400240 if (action == CMD_ACT_GET) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200241 u8 * buf_ptr = (u8 *) &pkeymaterial->keyParamSet;
242 u8 * resp_end = (u8 *) (resp + le16_to_cpu(resp->size));
243
244 while (buf_ptr < resp_end) {
245 struct MrvlIEtype_keyParamSet * pkeyparamset =
246 (struct MrvlIEtype_keyParamSet *) buf_ptr;
Dan Williams1443b652007-08-02 10:45:55 -0400247 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200248 u16 param_set_len = le16_to_cpu(pkeyparamset->length);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200249 u16 key_len = le16_to_cpu(pkeyparamset->keylen);
Dan Williams1443b652007-08-02 10:45:55 -0400250 u16 key_flags = le16_to_cpu(pkeyparamset->keyinfo);
251 u16 key_type = le16_to_cpu(pkeyparamset->keytypeid);
252 u8 * end;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200253
254 end = (u8 *) pkeyparamset + sizeof (pkeyparamset->type)
255 + sizeof (pkeyparamset->length)
256 + param_set_len;
257 /* Make sure we don't access past the end of the IEs */
258 if (end > resp_end)
259 break;
260
Dan Williams1443b652007-08-02 10:45:55 -0400261 if (key_flags & KEY_INFO_WPA_UNICAST)
David Woodhouseaa21c002007-12-08 20:04:36 +0000262 pkey = &priv->wpa_unicast_key;
Dan Williams1443b652007-08-02 10:45:55 -0400263 else if (key_flags & KEY_INFO_WPA_MCAST)
David Woodhouseaa21c002007-12-08 20:04:36 +0000264 pkey = &priv->wpa_mcast_key;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200265 else
266 break;
267
268 /* Copy returned key into driver */
Dan Williams1443b652007-08-02 10:45:55 -0400269 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200270 if (key_len > sizeof(pkey->key))
271 break;
Dan Williams1443b652007-08-02 10:45:55 -0400272 pkey->type = key_type;
273 pkey->flags = key_flags;
274 pkey->len = key_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200275 memcpy(pkey->key, pkeyparamset->key, pkey->len);
276
277 buf_ptr = end + 1;
278 }
279 }
280
Holger Schurig9012b282007-05-25 11:27:16 -0400281 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200282 return 0;
283}
284
Holger Schurig69f90322007-11-23 15:43:44 +0100285static int lbs_ret_802_11_mac_address(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200286 struct cmd_ds_command *resp)
287{
288 struct cmd_ds_802_11_mac_address *macadd = &resp->params.macadd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200289
Holger Schurig9012b282007-05-25 11:27:16 -0400290 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200291
David Woodhouseaa21c002007-12-08 20:04:36 +0000292 memcpy(priv->current_addr, macadd->macadd, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200293
Holger Schurig9012b282007-05-25 11:27:16 -0400294 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200295 return 0;
296}
297
Holger Schurig69f90322007-11-23 15:43:44 +0100298static int lbs_ret_802_11_rf_tx_power(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200299 struct cmd_ds_command *resp)
300{
301 struct cmd_ds_802_11_rf_tx_power *rtp = &resp->params.txp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200302
Holger Schurig9012b282007-05-25 11:27:16 -0400303 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200304
David Woodhouseaa21c002007-12-08 20:04:36 +0000305 priv->txpowerlevel = le16_to_cpu(rtp->currentlevel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200306
David Woodhouseaa21c002007-12-08 20:04:36 +0000307 lbs_deb_cmd("TX power currently %d\n", priv->txpowerlevel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200308
Holger Schuriga6c87002007-08-02 11:54:10 -0400309 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200310 return 0;
311}
312
Holger Schurig69f90322007-11-23 15:43:44 +0100313static int lbs_ret_802_11_rate_adapt_rateset(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200314 struct cmd_ds_command *resp)
315{
David Woodhouse981f1872007-05-25 23:36:54 -0400316 struct cmd_ds_802_11_rate_adapt_rateset *rates = &resp->params.rateset;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200317
Holger Schurig9012b282007-05-25 11:27:16 -0400318 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200319
Dan Williams0aef64d2007-08-02 11:31:18 -0400320 if (rates->action == CMD_ACT_GET) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000321 priv->enablehwauto = le16_to_cpu(rates->enablehwauto);
322 priv->ratebitmap = le16_to_cpu(rates->bitmap);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200323 }
324
Holger Schuriga6c87002007-08-02 11:54:10 -0400325 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200326 return 0;
327}
328
Holger Schurig69f90322007-11-23 15:43:44 +0100329static int lbs_ret_802_11_rssi(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200330 struct cmd_ds_command *resp)
331{
332 struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200333
Holger Schuriga6c87002007-08-02 11:54:10 -0400334 lbs_deb_enter(LBS_DEB_CMD);
335
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200336 /* store the non average value */
David Woodhouseaa21c002007-12-08 20:04:36 +0000337 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR);
338 priv->NF[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->noisefloor);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200339
David Woodhouseaa21c002007-12-08 20:04:36 +0000340 priv->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR);
341 priv->NF[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgnoisefloor);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200342
David Woodhouseaa21c002007-12-08 20:04:36 +0000343 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] =
344 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
345 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200346
David Woodhouseaa21c002007-12-08 20:04:36 +0000347 priv->RSSI[TYPE_BEACON][TYPE_AVG] =
348 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE,
349 priv->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200350
Holger Schuriga6c87002007-08-02 11:54:10 -0400351 lbs_deb_cmd("RSSI: beacon %d, avg %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000352 priv->RSSI[TYPE_BEACON][TYPE_NOAVG],
353 priv->RSSI[TYPE_BEACON][TYPE_AVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200354
Holger Schuriga6c87002007-08-02 11:54:10 -0400355 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200356 return 0;
357}
358
Holger Schurig69f90322007-11-23 15:43:44 +0100359static int lbs_ret_802_11_eeprom_access(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200360 struct cmd_ds_command *resp)
361{
Holger Schurig10078322007-11-15 18:05:47 -0500362 struct lbs_ioctl_regrdwr *pbuf;
David Woodhouseaa21c002007-12-08 20:04:36 +0000363 pbuf = (struct lbs_ioctl_regrdwr *) priv->prdeeprom;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200364
Holger Schuriga6c87002007-08-02 11:54:10 -0400365 lbs_deb_enter_args(LBS_DEB_CMD, "len %d",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200366 le16_to_cpu(resp->params.rdeeprom.bytecount));
367 if (pbuf->NOB < le16_to_cpu(resp->params.rdeeprom.bytecount)) {
368 pbuf->NOB = 0;
Holger Schuriga6c87002007-08-02 11:54:10 -0400369 lbs_deb_cmd("EEPROM read length too big\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200370 return -1;
371 }
372 pbuf->NOB = le16_to_cpu(resp->params.rdeeprom.bytecount);
373 if (pbuf->NOB > 0) {
374
375 memcpy(&pbuf->value, (u8 *) & resp->params.rdeeprom.value,
376 le16_to_cpu(resp->params.rdeeprom.bytecount));
Holger Schuriga6c87002007-08-02 11:54:10 -0400377 lbs_deb_hex(LBS_DEB_CMD, "EEPROM", (char *)&pbuf->value,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200378 le16_to_cpu(resp->params.rdeeprom.bytecount));
379 }
Holger Schuriga6c87002007-08-02 11:54:10 -0400380 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200381 return 0;
382}
383
Holger Schurig69f90322007-11-23 15:43:44 +0100384static int lbs_ret_get_log(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200385 struct cmd_ds_command *resp)
386{
David Woodhouse981f1872007-05-25 23:36:54 -0400387 struct cmd_ds_802_11_get_log *logmessage = &resp->params.glog;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200388
Holger Schurig9012b282007-05-25 11:27:16 -0400389 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200390
David Woodhouse981f1872007-05-25 23:36:54 -0400391 /* Stored little-endian */
David Woodhouseaa21c002007-12-08 20:04:36 +0000392 memcpy(&priv->logmsg, logmessage, sizeof(struct cmd_ds_802_11_get_log));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200393
Holger Schuriga6c87002007-08-02 11:54:10 -0400394 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200395 return 0;
396}
397
Holger Schurig69f90322007-11-23 15:43:44 +0100398static int lbs_ret_802_11_enable_rsn(struct lbs_private *priv,
Dan Williams18c96c342007-06-18 12:01:12 -0400399 struct cmd_ds_command *resp)
400{
401 struct cmd_ds_802_11_enable_rsn *enable_rsn = &resp->params.enbrsn;
David Woodhouseaa21c002007-12-08 20:04:36 +0000402 u32 * pdata_buf = priv->cur_cmd->pdata_buf;
Dan Williams18c96c342007-06-18 12:01:12 -0400403
404 lbs_deb_enter(LBS_DEB_CMD);
405
Dan Williams0aef64d2007-08-02 11:31:18 -0400406 if (enable_rsn->action == cpu_to_le16(CMD_ACT_GET)) {
Dan Williams18c96c342007-06-18 12:01:12 -0400407 if (pdata_buf)
408 *pdata_buf = (u32) le16_to_cpu(enable_rsn->enable);
409 }
410
Holger Schuriga6c87002007-08-02 11:54:10 -0400411 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams18c96c342007-06-18 12:01:12 -0400412 return 0;
413}
414
Brajesh Dave96287ac2007-11-20 17:44:28 -0500415static int lbs_ret_802_11_bcn_ctrl(struct lbs_private * priv,
416 struct cmd_ds_command *resp)
417{
418 struct cmd_ds_802_11_beacon_control *bcn_ctrl =
419 &resp->params.bcn_ctrl;
Brajesh Dave96287ac2007-11-20 17:44:28 -0500420
421 lbs_deb_enter(LBS_DEB_CMD);
422
423 if (bcn_ctrl->action == CMD_ACT_GET) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000424 priv->beacon_enable = (u8) le16_to_cpu(bcn_ctrl->beacon_enable);
425 priv->beacon_period = le16_to_cpu(bcn_ctrl->beacon_period);
Brajesh Dave96287ac2007-11-20 17:44:28 -0500426 }
427
428 lbs_deb_enter(LBS_DEB_CMD);
429 return 0;
430}
431
Holger Schurig3a188642007-11-26 10:07:14 +0100432static int lbs_ret_802_11_subscribe_event(struct lbs_private *priv,
433 struct cmd_ds_command *resp)
434{
Holger Schurig3a188642007-11-26 10:07:14 +0100435 struct cmd_ds_802_11_subscribe_event *cmd_event =
436 &resp->params.subscribe_event;
437 struct cmd_ds_802_11_subscribe_event *dst_event =
David Woodhouseaa21c002007-12-08 20:04:36 +0000438 priv->cur_cmd->pdata_buf;
Holger Schurig3a188642007-11-26 10:07:14 +0100439
440 lbs_deb_enter(LBS_DEB_CMD);
441
442 if (dst_event->action == cpu_to_le16(CMD_ACT_GET)) {
Holger Schurigc2df2ef2007-12-07 15:30:44 +0000443 dst_event->events = cmd_event->events;
Holger Schurig3a188642007-11-26 10:07:14 +0100444 memcpy(dst_event->tlv, cmd_event->tlv, sizeof(dst_event->tlv));
445 }
446
447 lbs_deb_leave(LBS_DEB_CMD);
448 return 0;
449}
450
David Woodhouse1309b552007-12-10 13:36:10 -0500451static inline int handle_cmd_response(struct lbs_private *priv,
452 unsigned long dummy,
Dan Williamsddac4522007-12-11 13:49:39 -0500453 struct cmd_header *cmd_response)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200454{
Dan Williamsddac4522007-12-11 13:49:39 -0500455 struct cmd_ds_command *resp = (struct cmd_ds_command *) cmd_response;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200456 int ret = 0;
457 unsigned long flags;
David Woodhouse1309b552007-12-10 13:36:10 -0500458 uint16_t respcmd = le16_to_cpu(resp->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200459
Holger Schuriga6c87002007-08-02 11:54:10 -0400460 lbs_deb_enter(LBS_DEB_HOST);
461
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200462 switch (respcmd) {
Holger Schurig6b63cd02007-08-02 11:53:36 -0400463 case CMD_RET(CMD_MAC_REG_ACCESS):
464 case CMD_RET(CMD_BBP_REG_ACCESS):
465 case CMD_RET(CMD_RF_REG_ACCESS):
Holger Schurig10078322007-11-15 18:05:47 -0500466 ret = lbs_ret_reg_access(priv, respcmd, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200467 break;
468
Holger Schurig6b63cd02007-08-02 11:53:36 -0400469 case CMD_RET(CMD_802_11_SCAN):
Holger Schurig10078322007-11-15 18:05:47 -0500470 ret = lbs_ret_80211_scan(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200471 break;
472
Holger Schurig6b63cd02007-08-02 11:53:36 -0400473 case CMD_RET(CMD_802_11_GET_LOG):
Holger Schurig10078322007-11-15 18:05:47 -0500474 ret = lbs_ret_get_log(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200475 break;
476
Dan Williams0aef64d2007-08-02 11:31:18 -0400477 case CMD_RET_802_11_ASSOCIATE:
Holger Schurig6b63cd02007-08-02 11:53:36 -0400478 case CMD_RET(CMD_802_11_ASSOCIATE):
479 case CMD_RET(CMD_802_11_REASSOCIATE):
Holger Schurig10078322007-11-15 18:05:47 -0500480 ret = lbs_ret_80211_associate(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481 break;
482
Holger Schurig6b63cd02007-08-02 11:53:36 -0400483 case CMD_RET(CMD_802_11_DISASSOCIATE):
484 case CMD_RET(CMD_802_11_DEAUTHENTICATE):
Holger Schurig10078322007-11-15 18:05:47 -0500485 ret = lbs_ret_80211_disassociate(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200486 break;
487
Holger Schurig6b63cd02007-08-02 11:53:36 -0400488 case CMD_RET(CMD_802_11_AD_HOC_START):
489 case CMD_RET(CMD_802_11_AD_HOC_JOIN):
Holger Schurig10078322007-11-15 18:05:47 -0500490 ret = lbs_ret_80211_ad_hoc_start(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200491 break;
492
Holger Schurig6b63cd02007-08-02 11:53:36 -0400493 case CMD_RET(CMD_802_11_GET_STAT):
Holger Schurig10078322007-11-15 18:05:47 -0500494 ret = lbs_ret_802_11_stat(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200495 break;
496
Holger Schurig6b63cd02007-08-02 11:53:36 -0400497 case CMD_RET(CMD_802_11_SNMP_MIB):
Holger Schurig10078322007-11-15 18:05:47 -0500498 ret = lbs_ret_802_11_snmp_mib(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200499 break;
500
Holger Schurig6b63cd02007-08-02 11:53:36 -0400501 case CMD_RET(CMD_802_11_RF_TX_POWER):
Holger Schurig10078322007-11-15 18:05:47 -0500502 ret = lbs_ret_802_11_rf_tx_power(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200503 break;
504
Holger Schurig6b63cd02007-08-02 11:53:36 -0400505 case CMD_RET(CMD_802_11_SET_AFC):
506 case CMD_RET(CMD_802_11_GET_AFC):
David Woodhouseaa21c002007-12-08 20:04:36 +0000507 spin_lock_irqsave(&priv->driver_lock, flags);
508 memmove(priv->cur_cmd->pdata_buf, &resp->params.afc,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200509 sizeof(struct cmd_ds_802_11_afc));
David Woodhouseaa21c002007-12-08 20:04:36 +0000510 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200511
512 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200513
Holger Schurig6b63cd02007-08-02 11:53:36 -0400514 case CMD_RET(CMD_MAC_MULTICAST_ADR):
515 case CMD_RET(CMD_MAC_CONTROL):
516 case CMD_RET(CMD_802_11_SET_WEP):
517 case CMD_RET(CMD_802_11_RESET):
518 case CMD_RET(CMD_802_11_AUTHENTICATE):
519 case CMD_RET(CMD_802_11_RADIO_CONTROL):
520 case CMD_RET(CMD_802_11_BEACON_STOP):
Dan Williams18c96c342007-06-18 12:01:12 -0400521 break;
522
Holger Schurig6b63cd02007-08-02 11:53:36 -0400523 case CMD_RET(CMD_802_11_ENABLE_RSN):
Holger Schurig10078322007-11-15 18:05:47 -0500524 ret = lbs_ret_802_11_enable_rsn(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200525 break;
526
Holger Schurig6b63cd02007-08-02 11:53:36 -0400527 case CMD_RET(CMD_802_11_RATE_ADAPT_RATESET):
Holger Schurig10078322007-11-15 18:05:47 -0500528 ret = lbs_ret_802_11_rate_adapt_rateset(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200529 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200530
Holger Schurig6b63cd02007-08-02 11:53:36 -0400531 case CMD_RET(CMD_802_11_RSSI):
Holger Schurig10078322007-11-15 18:05:47 -0500532 ret = lbs_ret_802_11_rssi(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200533 break;
534
Holger Schurig6b63cd02007-08-02 11:53:36 -0400535 case CMD_RET(CMD_802_11_MAC_ADDRESS):
Holger Schurig10078322007-11-15 18:05:47 -0500536 ret = lbs_ret_802_11_mac_address(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200537 break;
538
Holger Schurig6b63cd02007-08-02 11:53:36 -0400539 case CMD_RET(CMD_802_11_AD_HOC_STOP):
Holger Schurig10078322007-11-15 18:05:47 -0500540 ret = lbs_ret_80211_ad_hoc_stop(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200541 break;
542
Holger Schurig6b63cd02007-08-02 11:53:36 -0400543 case CMD_RET(CMD_802_11_KEY_MATERIAL):
Holger Schurig10078322007-11-15 18:05:47 -0500544 ret = lbs_ret_802_11_key_material(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200545 break;
546
Holger Schurig6b63cd02007-08-02 11:53:36 -0400547 case CMD_RET(CMD_802_11_EEPROM_ACCESS):
Holger Schurig10078322007-11-15 18:05:47 -0500548 ret = lbs_ret_802_11_eeprom_access(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200549 break;
550
Holger Schurig6b63cd02007-08-02 11:53:36 -0400551 case CMD_RET(CMD_802_11D_DOMAIN_INFO):
Holger Schurig10078322007-11-15 18:05:47 -0500552 ret = lbs_ret_802_11d_domain_info(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200553 break;
554
Holger Schurig6b63cd02007-08-02 11:53:36 -0400555 case CMD_RET(CMD_802_11_SLEEP_PARAMS):
Holger Schurig10078322007-11-15 18:05:47 -0500556 ret = lbs_ret_802_11_sleep_params(priv, resp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200557 break;
Holger Schurig6b63cd02007-08-02 11:53:36 -0400558 case CMD_RET(CMD_802_11_INACTIVITY_TIMEOUT):
David Woodhouseaa21c002007-12-08 20:04:36 +0000559 spin_lock_irqsave(&priv->driver_lock, flags);
560 *((u16 *) priv->cur_cmd->pdata_buf) =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200561 le16_to_cpu(resp->params.inactivity_timeout.timeout);
David Woodhouseaa21c002007-12-08 20:04:36 +0000562 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200563 break;
564
Holger Schurig6b63cd02007-08-02 11:53:36 -0400565 case CMD_RET(CMD_802_11_TPC_CFG):
David Woodhouseaa21c002007-12-08 20:04:36 +0000566 spin_lock_irqsave(&priv->driver_lock, flags);
567 memmove(priv->cur_cmd->pdata_buf, &resp->params.tpccfg,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200568 sizeof(struct cmd_ds_802_11_tpc_cfg));
David Woodhouseaa21c002007-12-08 20:04:36 +0000569 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200570 break;
Holger Schurig6b63cd02007-08-02 11:53:36 -0400571 case CMD_RET(CMD_802_11_LED_GPIO_CTRL):
David Woodhouseaa21c002007-12-08 20:04:36 +0000572 spin_lock_irqsave(&priv->driver_lock, flags);
573 memmove(priv->cur_cmd->pdata_buf, &resp->params.ledgpio,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200574 sizeof(struct cmd_ds_802_11_led_ctrl));
David Woodhouseaa21c002007-12-08 20:04:36 +0000575 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200576 break;
Holger Schurig3a188642007-11-26 10:07:14 +0100577 case CMD_RET(CMD_802_11_SUBSCRIBE_EVENT):
578 ret = lbs_ret_802_11_subscribe_event(priv, resp);
579 break;
580
Holger Schurig6b63cd02007-08-02 11:53:36 -0400581 case CMD_RET(CMD_802_11_PWR_CFG):
David Woodhouseaa21c002007-12-08 20:04:36 +0000582 spin_lock_irqsave(&priv->driver_lock, flags);
583 memmove(priv->cur_cmd->pdata_buf, &resp->params.pwrcfg,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200584 sizeof(struct cmd_ds_802_11_pwr_cfg));
David Woodhouseaa21c002007-12-08 20:04:36 +0000585 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200586
587 break;
588
Holger Schurig6b63cd02007-08-02 11:53:36 -0400589 case CMD_RET(CMD_GET_TSF):
David Woodhouseaa21c002007-12-08 20:04:36 +0000590 spin_lock_irqsave(&priv->driver_lock, flags);
591 memcpy(priv->cur_cmd->pdata_buf,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200592 &resp->params.gettsf.tsfvalue, sizeof(u64));
David Woodhouseaa21c002007-12-08 20:04:36 +0000593 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200594 break;
Holger Schurig6b63cd02007-08-02 11:53:36 -0400595 case CMD_RET(CMD_BT_ACCESS):
David Woodhouseaa21c002007-12-08 20:04:36 +0000596 spin_lock_irqsave(&priv->driver_lock, flags);
597 if (priv->cur_cmd->pdata_buf)
598 memcpy(priv->cur_cmd->pdata_buf,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200599 &resp->params.bt.addr1, 2 * ETH_ALEN);
David Woodhouseaa21c002007-12-08 20:04:36 +0000600 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200601 break;
Holger Schurig6b63cd02007-08-02 11:53:36 -0400602 case CMD_RET(CMD_FWT_ACCESS):
David Woodhouseaa21c002007-12-08 20:04:36 +0000603 spin_lock_irqsave(&priv->driver_lock, flags);
604 if (priv->cur_cmd->pdata_buf)
605 memcpy(priv->cur_cmd->pdata_buf, &resp->params.fwt,
David Woodhouse981f1872007-05-25 23:36:54 -0400606 sizeof(resp->params.fwt));
David Woodhouseaa21c002007-12-08 20:04:36 +0000607 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200608 break;
Brajesh Dave96287ac2007-11-20 17:44:28 -0500609 case CMD_RET(CMD_802_11_BEACON_CTRL):
610 ret = lbs_ret_802_11_bcn_ctrl(priv, resp);
611 break;
612
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200613 default:
Holger Schuriga6c87002007-08-02 11:54:10 -0400614 lbs_deb_host("CMD_RESP: unknown cmd response 0x%04x\n",
David Woodhousee1258172007-12-11 23:42:49 -0500615 le16_to_cpu(resp->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200616 break;
617 }
Holger Schuriga6c87002007-08-02 11:54:10 -0400618 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200619 return ret;
620}
621
Holger Schurig69f90322007-11-23 15:43:44 +0100622int lbs_process_rx_command(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200623{
David Woodhousee1258172007-12-11 23:42:49 -0500624 uint16_t respcmd, curcmd;
Dan Williamsddac4522007-12-11 13:49:39 -0500625 struct cmd_header *resp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200626 int ret = 0;
David Woodhousee1258172007-12-11 23:42:49 -0500627 unsigned long flags;
628 uint16_t result;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200629
Holger Schuriga6c87002007-08-02 11:54:10 -0400630 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200631
David Woodhouseaa21c002007-12-08 20:04:36 +0000632 mutex_lock(&priv->lock);
633 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200634
David Woodhouseaa21c002007-12-08 20:04:36 +0000635 if (!priv->cur_cmd) {
Holger Schuriga6c87002007-08-02 11:54:10 -0400636 lbs_deb_host("CMD_RESP: cur_cmd is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200637 ret = -1;
David Woodhouseaa21c002007-12-08 20:04:36 +0000638 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200639 goto done;
640 }
David Woodhousee1258172007-12-11 23:42:49 -0500641
642 curcmd = le16_to_cpu(priv->cur_cmd->cmdbuf->command);
643
Dan Williamsddac4522007-12-11 13:49:39 -0500644 resp = priv->cur_cmd->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200645
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200646 respcmd = le16_to_cpu(resp->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200647 result = le16_to_cpu(resp->result);
648
David Woodhousee1258172007-12-11 23:42:49 -0500649 lbs_deb_host("CMD_RESP: response 0x%04x, seq %d, size %d, jiffies %lu\n",
650 respcmd, le16_to_cpu(resp->seqnum), priv->upld_len, jiffies);
Dan Williamsddac4522007-12-11 13:49:39 -0500651 lbs_deb_hex(LBS_DEB_HOST, "CMD_RESP", (void *) resp, priv->upld_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200652
David Woodhousee1258172007-12-11 23:42:49 -0500653 if (resp->seqnum != priv->cur_cmd->cmdbuf->seqnum) {
654 lbs_pr_info("Received CMD_RESP with invalid sequence %d (expected %d)\n",
655 le16_to_cpu(resp->seqnum), le16_to_cpu(priv->cur_cmd->cmdbuf->seqnum));
David Woodhouseaa21c002007-12-08 20:04:36 +0000656 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200657 ret = -1;
658 goto done;
659 }
David Woodhousee1258172007-12-11 23:42:49 -0500660 if (respcmd != CMD_RET(curcmd) &&
661 respcmd != CMD_802_11_ASSOCIATE && curcmd != CMD_RET_802_11_ASSOCIATE) {
662 lbs_pr_info("Invalid CMD_RESP %x to command %x!\n", respcmd, curcmd);
663 spin_unlock_irqrestore(&priv->driver_lock, flags);
664 ret = -1;
665 goto done;
666 }
667
668 /* Now we got response from FW, cancel the command timer */
669 del_timer(&priv->command_timer);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200670
671 /* Store the response code to cur_cmd_retcode. */
David Woodhouseaa21c002007-12-08 20:04:36 +0000672 priv->cur_cmd_retcode = result;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200673
Holger Schurig6b63cd02007-08-02 11:53:36 -0400674 if (respcmd == CMD_RET(CMD_802_11_PS_MODE)) {
Dan Williamsddac4522007-12-11 13:49:39 -0500675 struct cmd_ds_802_11_ps_mode *psmode = (void *) resp;
David Woodhouse981f1872007-05-25 23:36:54 -0400676 u16 action = le16_to_cpu(psmode->action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200677
Holger Schuriga6c87002007-08-02 11:54:10 -0400678 lbs_deb_host(
679 "CMD_RESP: PS_MODE cmd reply result 0x%x, action 0x%x\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400680 result, action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200681
682 if (result) {
Holger Schuriga6c87002007-08-02 11:54:10 -0400683 lbs_deb_host("CMD_RESP: PS command failed with 0x%x\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400684 result);
685 /*
686 * We should not re-try enter-ps command in
687 * ad-hoc mode. It takes place in
Holger Schurig10078322007-11-15 18:05:47 -0500688 * lbs_execute_next_command().
David Woodhouse981f1872007-05-25 23:36:54 -0400689 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000690 if (priv->mode == IW_MODE_ADHOC &&
Dan Williams0aef64d2007-08-02 11:31:18 -0400691 action == CMD_SUBCMD_ENTER_PS)
David Woodhouseaa21c002007-12-08 20:04:36 +0000692 priv->psmode = LBS802_11POWERMODECAM;
Dan Williams0aef64d2007-08-02 11:31:18 -0400693 } else if (action == CMD_SUBCMD_ENTER_PS) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000694 priv->needtowakeup = 0;
695 priv->psstate = PS_STATE_AWAKE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200696
Holger Schuriga6c87002007-08-02 11:54:10 -0400697 lbs_deb_host("CMD_RESP: ENTER_PS command response\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000698 if (priv->connect_status != LBS_CONNECTED) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200699 /*
700 * When Deauth Event received before Enter_PS command
701 * response, We need to wake up the firmware.
702 */
Holger Schuriga6c87002007-08-02 11:54:10 -0400703 lbs_deb_host(
Holger Schurig10078322007-11-15 18:05:47 -0500704 "disconnected, invoking lbs_ps_wakeup\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200705
David Woodhouseaa21c002007-12-08 20:04:36 +0000706 spin_unlock_irqrestore(&priv->driver_lock, flags);
707 mutex_unlock(&priv->lock);
Holger Schurig10078322007-11-15 18:05:47 -0500708 lbs_ps_wakeup(priv, 0);
David Woodhouseaa21c002007-12-08 20:04:36 +0000709 mutex_lock(&priv->lock);
710 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200711 }
Dan Williams0aef64d2007-08-02 11:31:18 -0400712 } else if (action == CMD_SUBCMD_EXIT_PS) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000713 priv->needtowakeup = 0;
714 priv->psstate = PS_STATE_FULL_POWER;
Holger Schuriga6c87002007-08-02 11:54:10 -0400715 lbs_deb_host("CMD_RESP: EXIT_PS command response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200716 } else {
Holger Schuriga6c87002007-08-02 11:54:10 -0400717 lbs_deb_host("CMD_RESP: PS action 0x%X\n", action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200718 }
719
David Woodhouse183aeac2007-12-15 01:52:54 -0500720 lbs_complete_command(priv, priv->cur_cmd, result);
David Woodhouseaa21c002007-12-08 20:04:36 +0000721 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200722
723 ret = 0;
724 goto done;
725 }
726
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200727 /* If the command is not successful, cleanup and return failure */
728 if ((result != 0 || !(respcmd & 0x8000))) {
Holger Schuriga6c87002007-08-02 11:54:10 -0400729 lbs_deb_host("CMD_RESP: error 0x%04x in command reply 0x%04x\n",
730 result, respcmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200731 /*
732 * Handling errors here
733 */
734 switch (respcmd) {
Holger Schurig6b63cd02007-08-02 11:53:36 -0400735 case CMD_RET(CMD_GET_HW_SPEC):
736 case CMD_RET(CMD_802_11_RESET):
Holger Schuriga6c87002007-08-02 11:54:10 -0400737 lbs_deb_host("CMD_RESP: reset failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200738 break;
739
740 }
David Woodhouse183aeac2007-12-15 01:52:54 -0500741 lbs_complete_command(priv, priv->cur_cmd, result);
David Woodhouseaa21c002007-12-08 20:04:36 +0000742 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200743
744 ret = -1;
745 goto done;
746 }
747
David Woodhouseaa21c002007-12-08 20:04:36 +0000748 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhouse17230472007-12-07 15:13:05 +0000749
Dan Williams7ad994d2007-12-11 12:33:30 -0500750 if (priv->cur_cmd && priv->cur_cmd->callback) {
751 ret = priv->cur_cmd->callback(priv, priv->cur_cmd->callback_arg,
Dan Williamsddac4522007-12-11 13:49:39 -0500752 resp);
Dan Williams7ad994d2007-12-11 12:33:30 -0500753 } else
David Woodhouse1309b552007-12-10 13:36:10 -0500754 ret = handle_cmd_response(priv, 0, resp);
David Woodhouse17230472007-12-07 15:13:05 +0000755
David Woodhouseaa21c002007-12-08 20:04:36 +0000756 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse17230472007-12-07 15:13:05 +0000757
David Woodhouseaa21c002007-12-08 20:04:36 +0000758 if (priv->cur_cmd) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200759 /* Clean up and Put current command back to cmdfreeq */
David Woodhouse183aeac2007-12-15 01:52:54 -0500760 lbs_complete_command(priv, priv->cur_cmd, result);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200761 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000762 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200763
764done:
David Woodhouseaa21c002007-12-08 20:04:36 +0000765 mutex_unlock(&priv->lock);
Holger Schuriga6c87002007-08-02 11:54:10 -0400766 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200767 return ret;
768}
769
Holger Schurig69f90322007-11-23 15:43:44 +0100770int lbs_process_event(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200771{
772 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200773 u32 eventcause;
774
Holger Schurig9556d212007-08-02 13:14:07 -0400775 lbs_deb_enter(LBS_DEB_CMD);
776
David Woodhouseaa21c002007-12-08 20:04:36 +0000777 spin_lock_irq(&priv->driver_lock);
778 eventcause = priv->eventcause >> SBI_EVENT_CAUSE_SHIFT;
779 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200780
Holger Schurig0b3c07f2007-11-28 09:15:11 +0100781 lbs_deb_cmd("event cause %d\n", eventcause);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200782
Holger Schurig0b3c07f2007-11-28 09:15:11 +0100783 switch (eventcause) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200784 case MACREG_INT_CODE_LINK_SENSED:
Holger Schurig9012b282007-05-25 11:27:16 -0400785 lbs_deb_cmd("EVENT: MACREG_INT_CODE_LINK_SENSED\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200786 break;
787
788 case MACREG_INT_CODE_DEAUTHENTICATED:
Holger Schuriga6c87002007-08-02 11:54:10 -0400789 lbs_deb_cmd("EVENT: deauthenticated\n");
Holger Schurig10078322007-11-15 18:05:47 -0500790 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200791 break;
792
793 case MACREG_INT_CODE_DISASSOCIATED:
Holger Schuriga6c87002007-08-02 11:54:10 -0400794 lbs_deb_cmd("EVENT: disassociated\n");
Holger Schurig10078322007-11-15 18:05:47 -0500795 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200796 break;
797
Holger Schurig0b3c07f2007-11-28 09:15:11 +0100798 case MACREG_INT_CODE_LINK_LOST_NO_SCAN:
Holger Schuriga6c87002007-08-02 11:54:10 -0400799 lbs_deb_cmd("EVENT: link lost\n");
Holger Schurig10078322007-11-15 18:05:47 -0500800 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200801 break;
802
803 case MACREG_INT_CODE_PS_SLEEP:
Holger Schuriga6c87002007-08-02 11:54:10 -0400804 lbs_deb_cmd("EVENT: sleep\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200805
806 /* handle unexpected PS SLEEP event */
David Woodhouseaa21c002007-12-08 20:04:36 +0000807 if (priv->psstate == PS_STATE_FULL_POWER) {
Holger Schurig9012b282007-05-25 11:27:16 -0400808 lbs_deb_cmd(
Holger Schuriga6c87002007-08-02 11:54:10 -0400809 "EVENT: in FULL POWER mode, ignoreing PS_SLEEP\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200810 break;
811 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000812 priv->psstate = PS_STATE_PRE_SLEEP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200813
David Woodhouseaa21c002007-12-08 20:04:36 +0000814 lbs_ps_confirm_sleep(priv, (u16) priv->psmode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200815
816 break;
817
818 case MACREG_INT_CODE_PS_AWAKE:
Holger Schuriga6c87002007-08-02 11:54:10 -0400819 lbs_deb_cmd("EVENT: awake\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200820
821 /* handle unexpected PS AWAKE event */
David Woodhouseaa21c002007-12-08 20:04:36 +0000822 if (priv->psstate == PS_STATE_FULL_POWER) {
Holger Schurig9012b282007-05-25 11:27:16 -0400823 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200824 "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
825 break;
826 }
827
David Woodhouseaa21c002007-12-08 20:04:36 +0000828 priv->psstate = PS_STATE_AWAKE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200829
David Woodhouseaa21c002007-12-08 20:04:36 +0000830 if (priv->needtowakeup) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200831 /*
832 * wait for the command processing to finish
833 * before resuming sending
David Woodhouseaa21c002007-12-08 20:04:36 +0000834 * priv->needtowakeup will be set to FALSE
Holger Schurig10078322007-11-15 18:05:47 -0500835 * in lbs_ps_wakeup()
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200836 */
Holger Schuriga6c87002007-08-02 11:54:10 -0400837 lbs_deb_cmd("waking up ...\n");
Holger Schurig10078322007-11-15 18:05:47 -0500838 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200839 }
840 break;
841
842 case MACREG_INT_CODE_MIC_ERR_UNICAST:
Holger Schurig9012b282007-05-25 11:27:16 -0400843 lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200844 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST);
845 break;
846
847 case MACREG_INT_CODE_MIC_ERR_MULTICAST:
Holger Schurig9012b282007-05-25 11:27:16 -0400848 lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200849 handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST);
850 break;
851 case MACREG_INT_CODE_MIB_CHANGED:
852 case MACREG_INT_CODE_INIT_DONE:
853 break;
854
855 case MACREG_INT_CODE_ADHOC_BCN_LOST:
Holger Schuriga6c87002007-08-02 11:54:10 -0400856 lbs_deb_cmd("EVENT: ADHOC beacon lost\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200857 break;
858
859 case MACREG_INT_CODE_RSSI_LOW:
Holger Schuriga6c87002007-08-02 11:54:10 -0400860 lbs_pr_alert("EVENT: rssi low\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200861 break;
862 case MACREG_INT_CODE_SNR_LOW:
Holger Schuriga6c87002007-08-02 11:54:10 -0400863 lbs_pr_alert("EVENT: snr low\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200864 break;
865 case MACREG_INT_CODE_MAX_FAIL:
Holger Schuriga6c87002007-08-02 11:54:10 -0400866 lbs_pr_alert("EVENT: max fail\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200867 break;
868 case MACREG_INT_CODE_RSSI_HIGH:
Holger Schuriga6c87002007-08-02 11:54:10 -0400869 lbs_pr_alert("EVENT: rssi high\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200870 break;
871 case MACREG_INT_CODE_SNR_HIGH:
Holger Schuriga6c87002007-08-02 11:54:10 -0400872 lbs_pr_alert("EVENT: snr high\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200873 break;
874
Luis Carlos Cobo Rus7d8d28b2007-05-25 23:12:19 -0400875 case MACREG_INT_CODE_MESH_AUTO_STARTED:
Dan Williams5612c012007-08-02 13:20:12 -0400876 /* Ignore spurious autostart events if autostart is disabled */
877 if (!priv->mesh_autostart_enabled) {
878 lbs_pr_info("EVENT: MESH_AUTO_STARTED (ignoring)\n");
879 break;
880 }
Luis Carlos Cobo9cdc6d22007-08-02 11:55:22 -0400881 lbs_pr_info("EVENT: MESH_AUTO_STARTED\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000882 priv->mesh_connect_status = LBS_CONNECTED;
David Woodhousea27b9f92007-12-12 00:41:51 -0500883 if (priv->mesh_open) {
Luis Carlos Cobo9cdc6d22007-08-02 11:55:22 -0400884 netif_carrier_on(priv->mesh_dev);
David Woodhousea27b9f92007-12-12 00:41:51 -0500885 if (!priv->tx_pending_len)
886 netif_wake_queue(priv->mesh_dev);
Luis Carlos Cobo Rus7d8d28b2007-05-25 23:12:19 -0400887 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000888 priv->mode = IW_MODE_ADHOC;
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400889 schedule_work(&priv->sync_channel);
Luis Carlos Cobo Rus7d8d28b2007-05-25 23:12:19 -0400890 break;
891
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200892 default:
Holger Schurig0b3c07f2007-11-28 09:15:11 +0100893 lbs_pr_alert("EVENT: unknown event id %d\n", eventcause);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200894 break;
895 }
896
David Woodhouseaa21c002007-12-08 20:04:36 +0000897 spin_lock_irq(&priv->driver_lock);
898 priv->eventcause = 0;
899 spin_unlock_irq(&priv->driver_lock);
Holger Schurig9012b282007-05-25 11:27:16 -0400900
Holger Schurig9556d212007-08-02 13:14:07 -0400901 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200902 return ret;
903}