blob: 49267ed7cea30899be850fde711b0b08baf513f8 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains the handling of command.
3 * It prepares command and sends it to firmware when it is ready.
4 */
5
6#include <net/iw_handler.h>
Holger Schurig7919b892008-04-01 14:50:43 +02007#include <linux/kfifo.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02008#include "host.h"
9#include "hostcmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020010#include "decl.h"
11#include "defs.h"
12#include "dev.h"
Holger Schurig697900a2008-04-02 16:27:10 +020013#include "assoc.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020014#include "wext.h"
Dan Williams6e66f032007-12-11 12:42:16 -050015#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020016
David Woodhouse2fd6cfe2007-12-11 17:44:10 -050017static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
Holger Schurig0d61d042007-12-05 17:58:06 +010018
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020019
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020020/**
Holger Schurig8db4a2b2008-03-19 10:11:00 +010021 * @brief Simple callback that copies response back into command
22 *
23 * @param priv A pointer to struct lbs_private structure
24 * @param extra A pointer to the original command structure for which
25 * 'resp' is a response
26 * @param resp A pointer to the command response
27 *
28 * @return 0 on success, error on failure
29 */
30int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
31 struct cmd_header *resp)
32{
33 struct cmd_header *buf = (void *)extra;
34 uint16_t copy_len;
35
36 copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
37 memcpy(buf, resp, copy_len);
38 return 0;
39}
40EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
41
42/**
43 * @brief Simple callback that ignores the result. Use this if
44 * you just want to send a command to the hardware, but don't
45 * care for the result.
46 *
47 * @param priv ignored
48 * @param extra ignored
49 * @param resp ignored
50 *
51 * @return 0 for success
52 */
53static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
54 struct cmd_header *resp)
55{
56 return 0;
57}
58
59
60/**
Dan Williams852e1f22007-12-10 15:24:47 -050061 * @brief Checks whether a command is allowed in Power Save mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020062 *
63 * @param command the command ID
Dan Williams852e1f22007-12-10 15:24:47 -050064 * @return 1 if allowed, 0 if not allowed
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020065 */
Dan Williams852e1f22007-12-10 15:24:47 -050066static u8 is_command_allowed_in_ps(u16 cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020067{
Dan Williams852e1f22007-12-10 15:24:47 -050068 switch (cmd) {
69 case CMD_802_11_RSSI:
70 return 1;
71 default:
72 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020073 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020074 return 0;
75}
76
Dan Williams6e66f032007-12-11 12:42:16 -050077/**
78 * @brief Updates the hardware details like MAC address and regulatory region
79 *
80 * @param priv A pointer to struct lbs_private structure
81 *
82 * @return 0 on success, error on failure
83 */
84int lbs_update_hw_spec(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020085{
Dan Williams6e66f032007-12-11 12:42:16 -050086 struct cmd_ds_get_hw_spec cmd;
87 int ret = -1;
88 u32 i;
89 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020090
Holger Schurig9012b282007-05-25 11:27:16 -040091 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020092
Dan Williams6e66f032007-12-11 12:42:16 -050093 memset(&cmd, 0, sizeof(cmd));
94 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
95 memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
David Woodhouse689442d2007-12-12 16:00:42 -050096 ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
Dan Williams6e66f032007-12-11 12:42:16 -050097 if (ret)
98 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020099
Dan Williams6e66f032007-12-11 12:42:16 -0500100 priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500101
Holger Schurigdac10a92008-01-16 15:55:22 +0100102 /* The firmware release is in an interesting format: the patch
103 * level is in the most significant nibble ... so fix that: */
104 priv->fwrelease = le32_to_cpu(cmd.fwrelease);
105 priv->fwrelease = (priv->fwrelease << 8) |
106 (priv->fwrelease >> 24 & 0xff);
107
108 /* Some firmware capabilities:
109 * CF card firmware 5.0.16p0: cap 0x00000303
110 * USB dongle firmware 5.110.17p2: cap 0x00000303
111 */
112 printk("libertas: %s, fw %u.%u.%up%u, cap 0x%08x\n",
113 print_mac(mac, cmd.permanentaddr),
114 priv->fwrelease >> 24 & 0xff,
115 priv->fwrelease >> 16 & 0xff,
116 priv->fwrelease >> 8 & 0xff,
117 priv->fwrelease & 0xff,
118 priv->fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500119 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
120 cmd.hwifversion, cmd.version);
121
122 /* Clamp region code to 8-bit since FW spec indicates that it should
123 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
124 * returns non-zero high 8 bits here.
125 */
126 priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
127
128 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
129 /* use the region code to search for the index */
130 if (priv->regioncode == lbs_region_code_to_index[i])
131 break;
132 }
133
134 /* if it's unidentified region code, use the default (USA) */
135 if (i >= MRVDRV_MAX_REGION_CODE) {
136 priv->regioncode = 0x10;
137 lbs_pr_info("unidentified region code; using the default (USA)\n");
138 }
139
140 if (priv->current_addr[0] == 0xff)
141 memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
142
143 memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
144 if (priv->mesh_dev)
145 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
146
147 if (lbs_set_regiontable(priv, priv->regioncode, 0)) {
148 ret = -1;
149 goto out;
150 }
151
152 if (lbs_set_universaltable(priv, 0)) {
153 ret = -1;
154 goto out;
155 }
156
157out:
Holger Schurig9012b282007-05-25 11:27:16 -0400158 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams6e66f032007-12-11 12:42:16 -0500159 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200160}
161
David Woodhouse506e9022007-12-12 20:06:06 -0500162int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria)
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500163{
164 struct cmd_ds_host_sleep cmd_config;
165 int ret;
166
David Woodhouse9fae8992007-12-15 03:46:44 -0500167 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500168 cmd_config.criteria = cpu_to_le32(criteria);
David Woodhouse506e9022007-12-12 20:06:06 -0500169 cmd_config.gpio = priv->wol_gpio;
170 cmd_config.gap = priv->wol_gap;
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500171
David Woodhouse689442d2007-12-12 16:00:42 -0500172 ret = lbs_cmd_with_response(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config);
David Woodhouse506e9022007-12-12 20:06:06 -0500173 if (!ret) {
174 lbs_deb_cmd("Set WOL criteria to %x\n", criteria);
175 priv->wol_criteria = criteria;
176 } else {
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500177 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500178 }
David Woodhouse506e9022007-12-12 20:06:06 -0500179
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500180 return ret;
181}
182EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
183
Holger Schurige98a88d2008-03-19 14:25:58 +0100184static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200185 u16 cmd_action)
186{
187 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200188
Holger Schurig9012b282007-05-25 11:27:16 -0400189 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200190
Dan Williams0aef64d2007-08-02 11:31:18 -0400191 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
David Woodhouse981f1872007-05-25 23:36:54 -0400192 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
193 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200194 psm->action = cpu_to_le16(cmd_action);
195 psm->multipledtim = 0;
David Woodhouse981f1872007-05-25 23:36:54 -0400196 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400197 case CMD_SUBCMD_ENTER_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400198 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200199
Holger Schurig252cf0d2007-08-02 13:09:34 -0400200 psm->locallisteninterval = 0;
Holger Schurig97605c32007-08-02 13:09:15 -0400201 psm->nullpktinterval = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200202 psm->multipledtim =
Holger Schurig56c46562007-08-02 13:09:49 -0400203 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200204 break;
205
Dan Williams0aef64d2007-08-02 11:31:18 -0400206 case CMD_SUBCMD_EXIT_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400207 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200208 break;
209
Dan Williams0aef64d2007-08-02 11:31:18 -0400210 case CMD_SUBCMD_SLEEP_CONFIRMED:
Holger Schurig9012b282007-05-25 11:27:16 -0400211 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200212 break;
213
214 default:
215 break;
216 }
217
Holger Schurig9012b282007-05-25 11:27:16 -0400218 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200219 return 0;
220}
221
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500222int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv,
223 uint16_t cmd_action, uint16_t *timeout)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200224{
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500225 struct cmd_ds_802_11_inactivity_timeout cmd;
226 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200227
Holger Schurig8ff12da2007-08-02 11:54:31 -0400228 lbs_deb_enter(LBS_DEB_CMD);
229
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500230 cmd.hdr.command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
231 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200232
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500233 cmd.action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500235 if (cmd_action == CMD_ACT_SET)
236 cmd.timeout = cpu_to_le16(*timeout);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200237 else
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500238 cmd.timeout = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200239
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500240 ret = lbs_cmd_with_response(priv, CMD_802_11_INACTIVITY_TIMEOUT, &cmd);
241
242 if (!ret)
243 *timeout = le16_to_cpu(cmd.timeout);
244
245 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200246 return 0;
247}
248
David Woodhouse3fbe1042007-12-17 23:48:31 -0500249int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
250 struct sleep_params *sp)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200251{
David Woodhouse3fbe1042007-12-17 23:48:31 -0500252 struct cmd_ds_802_11_sleep_params cmd;
253 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200254
Holger Schurig9012b282007-05-25 11:27:16 -0400255 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200256
Dan Williams0aef64d2007-08-02 11:31:18 -0400257 if (cmd_action == CMD_ACT_GET) {
David Woodhouse3fbe1042007-12-17 23:48:31 -0500258 memset(&cmd, 0, sizeof(cmd));
259 } else {
260 cmd.error = cpu_to_le16(sp->sp_error);
261 cmd.offset = cpu_to_le16(sp->sp_offset);
262 cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
263 cmd.calcontrol = sp->sp_calcontrol;
264 cmd.externalsleepclk = sp->sp_extsleepclk;
265 cmd.reserved = cpu_to_le16(sp->sp_reserved);
266 }
267 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
268 cmd.action = cpu_to_le16(cmd_action);
269
270 ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
271
272 if (!ret) {
273 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
274 "calcontrol 0x%x extsleepclk 0x%x\n",
275 le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
276 le16_to_cpu(cmd.stabletime), cmd.calcontrol,
277 cmd.externalsleepclk);
278
279 sp->sp_error = le16_to_cpu(cmd.error);
280 sp->sp_offset = le16_to_cpu(cmd.offset);
281 sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
282 sp->sp_calcontrol = cmd.calcontrol;
283 sp->sp_extsleepclk = cmd.externalsleepclk;
284 sp->sp_reserved = le16_to_cpu(cmd.reserved);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200285 }
286
David Woodhouse3fbe1042007-12-17 23:48:31 -0500287 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200288 return 0;
289}
290
David Woodhousef70dd452007-12-18 00:18:05 -0500291int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action,
292 struct assoc_request *assoc)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200293{
David Woodhousef70dd452007-12-18 00:18:05 -0500294 struct cmd_ds_802_11_set_wep cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200295 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200296
Holger Schurig9012b282007-05-25 11:27:16 -0400297 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200298
David Woodhousef70dd452007-12-18 00:18:05 -0500299 cmd.hdr.command = cpu_to_le16(CMD_802_11_SET_WEP);
300 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200301
David Woodhousef70dd452007-12-18 00:18:05 -0500302 cmd.action = cpu_to_le16(cmd_action);
303
304 if (cmd_action == CMD_ACT_ADD) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200305 int i;
306
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200307 /* default tx key index */
David Woodhousef70dd452007-12-18 00:18:05 -0500308 cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx &
309 CMD_WEP_KEY_INDEX_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200310
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200311 /* Copy key types and material to host command structure */
312 for (i = 0; i < 4; i++) {
David Woodhousef70dd452007-12-18 00:18:05 -0500313 struct enc_key *pkey = &assoc->wep_keys[i];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200314
315 switch (pkey->len) {
316 case KEY_LEN_WEP_40:
David Woodhousef70dd452007-12-18 00:18:05 -0500317 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
318 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400319 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200320 break;
321 case KEY_LEN_WEP_104:
David Woodhousef70dd452007-12-18 00:18:05 -0500322 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
323 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400324 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200325 break;
326 case 0:
327 break;
328 default:
Holger Schurig8ff12da2007-08-02 11:54:31 -0400329 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
David Woodhousef70dd452007-12-18 00:18:05 -0500330 i, pkey->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200331 ret = -1;
332 goto done;
333 break;
334 }
335 }
David Woodhousef70dd452007-12-18 00:18:05 -0500336 } else if (cmd_action == CMD_ACT_REMOVE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200337 /* ACT_REMOVE clears _all_ WEP keys */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200338
339 /* default tx key index */
David Woodhousef70dd452007-12-18 00:18:05 -0500340 cmd.keyindex = cpu_to_le16(priv->wep_tx_keyidx &
341 CMD_WEP_KEY_INDEX_MASK);
David Woodhouseaa21c002007-12-08 20:04:36 +0000342 lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200343 }
344
David Woodhousef70dd452007-12-18 00:18:05 -0500345 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200346done:
Holger Schurig9012b282007-05-25 11:27:16 -0400347 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200348 return ret;
349}
350
David Woodhouse4f59abf2007-12-18 00:47:17 -0500351int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action,
352 uint16_t *enable)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200353{
David Woodhouse4f59abf2007-12-18 00:47:17 -0500354 struct cmd_ds_802_11_enable_rsn cmd;
355 int ret;
Dan Williams90a42212007-05-25 23:01:24 -0400356
357 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200358
David Woodhouse4f59abf2007-12-18 00:47:17 -0500359 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
360 cmd.action = cpu_to_le16(cmd_action);
Dan Williams18c96c342007-06-18 12:01:12 -0400361
Dan Williams0aef64d2007-08-02 11:31:18 -0400362 if (cmd_action == CMD_ACT_SET) {
Dan Williams18c96c342007-06-18 12:01:12 -0400363 if (*enable)
David Woodhouse4f59abf2007-12-18 00:47:17 -0500364 cmd.enable = cpu_to_le16(CMD_ENABLE_RSN);
Dan Williams18c96c342007-06-18 12:01:12 -0400365 else
David Woodhouse4f59abf2007-12-18 00:47:17 -0500366 cmd.enable = cpu_to_le16(CMD_DISABLE_RSN);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400367 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200368 }
369
David Woodhouse4f59abf2007-12-18 00:47:17 -0500370 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
371 if (!ret && cmd_action == CMD_ACT_GET)
372 *enable = le16_to_cpu(cmd.enable);
373
374 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
375 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200376}
377
David Woodhouse9e1228d2008-03-03 12:15:39 +0100378static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam,
379 struct enc_key *key)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200380{
Holger Schurig8ff12da2007-08-02 11:54:31 -0400381 lbs_deb_enter(LBS_DEB_CMD);
382
David Woodhouse9e1228d2008-03-03 12:15:39 +0100383 if (key->flags & KEY_INFO_WPA_ENABLED)
384 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
385 if (key->flags & KEY_INFO_WPA_UNICAST)
386 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
387 if (key->flags & KEY_INFO_WPA_MCAST)
388 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200389
David Woodhouse9e1228d2008-03-03 12:15:39 +0100390 keyparam->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
391 keyparam->keytypeid = cpu_to_le16(key->type);
392 keyparam->keylen = cpu_to_le16(key->len);
393 memcpy(keyparam->key, key->key, key->len);
394
395 /* Length field doesn't include the {type,length} header */
396 keyparam->length = cpu_to_le16(sizeof(*keyparam) - 4);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400397 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200398}
399
David Woodhouse9e1228d2008-03-03 12:15:39 +0100400int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action,
401 struct assoc_request *assoc)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200402{
David Woodhouse9e1228d2008-03-03 12:15:39 +0100403 struct cmd_ds_802_11_key_material cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200404 int ret = 0;
405 int index = 0;
406
Holger Schurig9012b282007-05-25 11:27:16 -0400407 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200408
David Woodhouse9e1228d2008-03-03 12:15:39 +0100409 cmd.action = cpu_to_le16(cmd_action);
410 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200411
Dan Williams0aef64d2007-08-02 11:31:18 -0400412 if (cmd_action == CMD_ACT_GET) {
David Woodhouse9e1228d2008-03-03 12:15:39 +0100413 cmd.hdr.size = cpu_to_le16(S_DS_GEN + 2);
414 } else {
415 memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet));
416
417 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) {
418 set_one_wpa_key(&cmd.keyParamSet[index],
419 &assoc->wpa_unicast_key);
420 index++;
421 }
422
423 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) {
424 set_one_wpa_key(&cmd.keyParamSet[index],
425 &assoc->wpa_mcast_key);
426 index++;
427 }
428
429 /* The common header and as many keys as we included */
430 cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd),
431 keyParamSet[index]));
432 }
433 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
434 /* Copy the returned key to driver private data */
435 if (!ret && cmd_action == CMD_ACT_GET) {
436 void *buf_ptr = cmd.keyParamSet;
437 void *resp_end = &(&cmd)[1];
438
439 while (buf_ptr < resp_end) {
440 struct MrvlIEtype_keyParamSet *keyparam = buf_ptr;
441 struct enc_key *key;
442 uint16_t param_set_len = le16_to_cpu(keyparam->length);
443 uint16_t key_len = le16_to_cpu(keyparam->keylen);
444 uint16_t key_flags = le16_to_cpu(keyparam->keyinfo);
445 uint16_t key_type = le16_to_cpu(keyparam->keytypeid);
446 void *end;
447
448 end = (void *)keyparam + sizeof(keyparam->type)
449 + sizeof(keyparam->length) + param_set_len;
450
451 /* Make sure we don't access past the end of the IEs */
452 if (end > resp_end)
453 break;
454
455 if (key_flags & KEY_INFO_WPA_UNICAST)
456 key = &priv->wpa_unicast_key;
457 else if (key_flags & KEY_INFO_WPA_MCAST)
458 key = &priv->wpa_mcast_key;
459 else
460 break;
461
462 /* Copy returned key into driver */
463 memset(key, 0, sizeof(struct enc_key));
464 if (key_len > sizeof(key->key))
465 break;
466 key->type = key_type;
467 key->flags = key_flags;
468 key->len = key_len;
469 memcpy(key->key, keyparam->key, key->len);
470
471 buf_ptr = end + 1;
472 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200473 }
474
Holger Schurig9012b282007-05-25 11:27:16 -0400475 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476 return ret;
477}
478
Holger Schurige98a88d2008-03-19 14:25:58 +0100479static int lbs_cmd_802_11_reset(struct cmd_ds_command *cmd, int cmd_action)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200480{
481 struct cmd_ds_802_11_reset *reset = &cmd->params.reset;
482
Holger Schurig8ff12da2007-08-02 11:54:31 -0400483 lbs_deb_enter(LBS_DEB_CMD);
484
Dan Williams0aef64d2007-08-02 11:31:18 -0400485 cmd->command = cpu_to_le16(CMD_802_11_RESET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200486 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
487 reset->action = cpu_to_le16(cmd_action);
488
Holger Schurig8ff12da2007-08-02 11:54:31 -0400489 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200490 return 0;
491}
492
Holger Schurig69f90322007-11-23 15:43:44 +0100493static int lbs_cmd_802_11_snmp_mib(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200494 struct cmd_ds_command *cmd,
495 int cmd_action,
496 int cmd_oid, void *pdata_buf)
497{
498 struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200499 u8 ucTemp;
500
Holger Schurig9012b282007-05-25 11:27:16 -0400501 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200502
Holger Schurig9012b282007-05-25 11:27:16 -0400503 lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200504
Dan Williams0aef64d2007-08-02 11:31:18 -0400505 cmd->command = cpu_to_le16(CMD_802_11_SNMP_MIB);
David Woodhouse981f1872007-05-25 23:36:54 -0400506 cmd->size = cpu_to_le16(sizeof(*pSNMPMIB) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200507
508 switch (cmd_oid) {
509 case OID_802_11_INFRASTRUCTURE_MODE:
510 {
Dan Williams0dc5a292007-05-10 22:58:02 -0400511 u8 mode = (u8) (size_t) pdata_buf;
Dan Williams0aef64d2007-08-02 11:31:18 -0400512 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
513 pSNMPMIB->oid = cpu_to_le16((u16) DESIRED_BSSTYPE_I);
Holger Schurigc2df2ef2007-12-07 15:30:44 +0000514 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u8));
Dan Williams0dc5a292007-05-10 22:58:02 -0400515 if (mode == IW_MODE_ADHOC) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200516 ucTemp = SNMP_MIB_VALUE_ADHOC;
Dan Williams0dc5a292007-05-10 22:58:02 -0400517 } else {
518 /* Infra and Auto modes */
519 ucTemp = SNMP_MIB_VALUE_INFRA;
520 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200521
522 memmove(pSNMPMIB->value, &ucTemp, sizeof(u8));
523
524 break;
525 }
526
527 case OID_802_11D_ENABLE:
528 {
529 u32 ulTemp;
530
Dan Williams0aef64d2007-08-02 11:31:18 -0400531 pSNMPMIB->oid = cpu_to_le16((u16) DOT11D_I);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200532
Dan Williams0aef64d2007-08-02 11:31:18 -0400533 if (cmd_action == CMD_ACT_SET) {
Holger Schurigc2df2ef2007-12-07 15:30:44 +0000534 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
535 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200536 ulTemp = *(u32 *)pdata_buf;
David Woodhouse981f1872007-05-25 23:36:54 -0400537 *((__le16 *)(pSNMPMIB->value)) =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200538 cpu_to_le16((u16) ulTemp);
539 }
540 break;
541 }
542
543 case OID_802_11_FRAGMENTATION_THRESHOLD:
544 {
545 u32 ulTemp;
546
Dan Williams0aef64d2007-08-02 11:31:18 -0400547 pSNMPMIB->oid = cpu_to_le16((u16) FRAGTHRESH_I);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200548
Dan Williams0aef64d2007-08-02 11:31:18 -0400549 if (cmd_action == CMD_ACT_GET) {
550 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
551 } else if (cmd_action == CMD_ACT_SET) {
552 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
David Woodhouse981f1872007-05-25 23:36:54 -0400553 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200554 ulTemp = *((u32 *) pdata_buf);
David Woodhouse981f1872007-05-25 23:36:54 -0400555 *((__le16 *)(pSNMPMIB->value)) =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200556 cpu_to_le16((u16) ulTemp);
557
558 }
559
560 break;
561 }
562
563 case OID_802_11_RTS_THRESHOLD:
564 {
565
566 u32 ulTemp;
Holger Schurigc2df2ef2007-12-07 15:30:44 +0000567 pSNMPMIB->oid = cpu_to_le16(RTSTHRESH_I);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200568
Dan Williams0aef64d2007-08-02 11:31:18 -0400569 if (cmd_action == CMD_ACT_GET) {
570 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
571 } else if (cmd_action == CMD_ACT_SET) {
572 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
David Woodhouse981f1872007-05-25 23:36:54 -0400573 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
574 ulTemp = *((u32 *)pdata_buf);
575 *(__le16 *)(pSNMPMIB->value) =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200576 cpu_to_le16((u16) ulTemp);
577
578 }
579 break;
580 }
581 case OID_802_11_TX_RETRYCOUNT:
Dan Williams0aef64d2007-08-02 11:31:18 -0400582 pSNMPMIB->oid = cpu_to_le16((u16) SHORT_RETRYLIM_I);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200583
Dan Williams0aef64d2007-08-02 11:31:18 -0400584 if (cmd_action == CMD_ACT_GET) {
585 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
586 } else if (cmd_action == CMD_ACT_SET) {
587 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200588 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
David Woodhouse981f1872007-05-25 23:36:54 -0400589 *((__le16 *)(pSNMPMIB->value)) =
David Woodhouseaa21c002007-12-08 20:04:36 +0000590 cpu_to_le16((u16) priv->txretrycount);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200591 }
592
593 break;
594 default:
595 break;
596 }
597
Holger Schurig9012b282007-05-25 11:27:16 -0400598 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200599 "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400600 le16_to_cpu(cmd->command), le16_to_cpu(cmd->size),
601 le16_to_cpu(cmd->seqnum), le16_to_cpu(cmd->result));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200602
Holger Schurig9012b282007-05-25 11:27:16 -0400603 lbs_deb_cmd(
Holger Schurig8ff12da2007-08-02 11:54:31 -0400604 "SNMP_CMD: action 0x%x, oid 0x%x, oidsize 0x%x, value 0x%x\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400605 le16_to_cpu(pSNMPMIB->querytype), le16_to_cpu(pSNMPMIB->oid),
606 le16_to_cpu(pSNMPMIB->bufsize),
607 le16_to_cpu(*(__le16 *) pSNMPMIB->value));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200608
Holger Schurig9012b282007-05-25 11:27:16 -0400609 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200610 return 0;
611}
612
Holger Schurige98a88d2008-03-19 14:25:58 +0100613static int lbs_cmd_802_11_rf_tx_power(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200614 u16 cmd_action, void *pdata_buf)
615{
616
617 struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
618
Holger Schurig9012b282007-05-25 11:27:16 -0400619 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200620
621 cmd->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400622 cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN);
Dan Williams0aef64d2007-08-02 11:31:18 -0400623 cmd->command = cpu_to_le16(CMD_802_11_RF_TX_POWER);
David Woodhouse981f1872007-05-25 23:36:54 -0400624 prtp->action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200625
David Woodhouse981f1872007-05-25 23:36:54 -0400626 lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
627 le16_to_cpu(cmd->size), le16_to_cpu(cmd->command),
628 le16_to_cpu(prtp->action));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200629
630 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400631 case CMD_ACT_TX_POWER_OPT_GET:
632 prtp->action = cpu_to_le16(CMD_ACT_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200633 prtp->currentlevel = 0;
634 break;
635
Dan Williams0aef64d2007-08-02 11:31:18 -0400636 case CMD_ACT_TX_POWER_OPT_SET_HIGH:
637 prtp->action = cpu_to_le16(CMD_ACT_SET);
638 prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_HIGH);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200639 break;
640
Dan Williams0aef64d2007-08-02 11:31:18 -0400641 case CMD_ACT_TX_POWER_OPT_SET_MID:
642 prtp->action = cpu_to_le16(CMD_ACT_SET);
643 prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_MID);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200644 break;
645
Dan Williams0aef64d2007-08-02 11:31:18 -0400646 case CMD_ACT_TX_POWER_OPT_SET_LOW:
647 prtp->action = cpu_to_le16(CMD_ACT_SET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200648 prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
649 break;
650 }
Holger Schurig9012b282007-05-25 11:27:16 -0400651
652 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200653 return 0;
654}
655
Holger Schurige98a88d2008-03-19 14:25:58 +0100656static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400657 u16 cmd_action, void *pdata_buf)
658{
659 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
660
661 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
662 cmd->size =
663 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
664 S_DS_GEN);
665
666 monitor->action = cpu_to_le16(cmd_action);
667 if (cmd_action == CMD_ACT_SET) {
668 monitor->mode =
669 cpu_to_le16((u16) (*(u32 *) pdata_buf));
670 }
671
672 return 0;
673}
674
Holger Schurig69f90322007-11-23 15:43:44 +0100675static int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200676 struct cmd_ds_command *cmd,
677 u16 cmd_action)
678{
679 struct cmd_ds_802_11_rate_adapt_rateset
680 *rateadapt = &cmd->params.rateset;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200681
Holger Schurig8ff12da2007-08-02 11:54:31 -0400682 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200683 cmd->size =
684 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
685 + S_DS_GEN);
Dan Williams0aef64d2007-08-02 11:31:18 -0400686 cmd->command = cpu_to_le16(CMD_802_11_RATE_ADAPT_RATESET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200687
David Woodhouse981f1872007-05-25 23:36:54 -0400688 rateadapt->action = cpu_to_le16(cmd_action);
David Woodhouseaa21c002007-12-08 20:04:36 +0000689 rateadapt->enablehwauto = cpu_to_le16(priv->enablehwauto);
690 rateadapt->bitmap = cpu_to_le16(priv->ratebitmap);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200691
Holger Schurig9012b282007-05-25 11:27:16 -0400692 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200693 return 0;
694}
695
Dan Williams8e3c91b2007-12-11 15:50:59 -0500696/**
697 * @brief Get the current data rate
698 *
699 * @param priv A pointer to struct lbs_private structure
700 *
701 * @return The data rate on success, error on failure
702 */
703int lbs_get_data_rate(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200704{
Dan Williams8e3c91b2007-12-11 15:50:59 -0500705 struct cmd_ds_802_11_data_rate cmd;
706 int ret = -1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200707
Holger Schurig9012b282007-05-25 11:27:16 -0400708 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200709
Dan Williams8e3c91b2007-12-11 15:50:59 -0500710 memset(&cmd, 0, sizeof(cmd));
711 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
712 cmd.action = cpu_to_le16(CMD_ACT_GET_TX_RATE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200713
David Woodhouse689442d2007-12-12 16:00:42 -0500714 ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
Dan Williams8e3c91b2007-12-11 15:50:59 -0500715 if (ret)
716 goto out;
717
718 lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
719
720 ret = (int) lbs_fw_index_to_data_rate(cmd.rates[0]);
721 lbs_deb_cmd("DATA_RATE: current rate 0x%02x\n", ret);
722
723out:
724 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
725 return ret;
726}
727
728/**
729 * @brief Set the data rate
730 *
731 * @param priv A pointer to struct lbs_private structure
732 * @param rate The desired data rate, or 0 to clear a locked rate
733 *
734 * @return 0 on success, error on failure
735 */
736int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
737{
738 struct cmd_ds_802_11_data_rate cmd;
739 int ret = 0;
740
741 lbs_deb_enter(LBS_DEB_CMD);
742
743 memset(&cmd, 0, sizeof(cmd));
744 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
745
746 if (rate > 0) {
747 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
748 cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
749 if (cmd.rates[0] == 0) {
750 lbs_deb_cmd("DATA_RATE: invalid requested rate of"
751 " 0x%02X\n", rate);
752 ret = 0;
753 goto out;
754 }
755 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
756 } else {
757 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400758 lbs_deb_cmd("DATA_RATE: setting auto\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200759 }
760
David Woodhouse689442d2007-12-12 16:00:42 -0500761 ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
Dan Williams8e3c91b2007-12-11 15:50:59 -0500762 if (ret)
763 goto out;
764
765 lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
766
767 /* FIXME: get actual rates FW can do if this command actually returns
768 * all data rates supported.
769 */
770 priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
771 lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
772
773out:
774 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
775 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200776}
777
Holger Schurig69f90322007-11-23 15:43:44 +0100778static int lbs_cmd_mac_multicast_adr(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200779 struct cmd_ds_command *cmd,
780 u16 cmd_action)
781{
782 struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200783
Holger Schurig8ff12da2007-08-02 11:54:31 -0400784 lbs_deb_enter(LBS_DEB_CMD);
David Woodhouse981f1872007-05-25 23:36:54 -0400785 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200786 S_DS_GEN);
Dan Williams0aef64d2007-08-02 11:31:18 -0400787 cmd->command = cpu_to_le16(CMD_MAC_MULTICAST_ADR);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200788
Holger Schurig8ff12da2007-08-02 11:54:31 -0400789 lbs_deb_cmd("MULTICAST_ADR: setting %d addresses\n", pMCastAdr->nr_of_adrs);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200790 pMCastAdr->action = cpu_to_le16(cmd_action);
791 pMCastAdr->nr_of_adrs =
David Woodhouseaa21c002007-12-08 20:04:36 +0000792 cpu_to_le16((u16) priv->nr_of_multicastmacaddr);
793 memcpy(pMCastAdr->maclist, priv->multicastlist,
794 priv->nr_of_multicastmacaddr * ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200795
Holger Schurig8ff12da2007-08-02 11:54:31 -0400796 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200797 return 0;
798}
799
Dan Williams2dd4b262007-12-11 16:54:15 -0500800/**
801 * @brief Get the radio channel
802 *
803 * @param priv A pointer to struct lbs_private structure
804 *
805 * @return The channel on success, error on failure
806 */
807int lbs_get_channel(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200808{
Dan Williams2dd4b262007-12-11 16:54:15 -0500809 struct cmd_ds_802_11_rf_channel cmd;
810 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200811
Holger Schurig8ff12da2007-08-02 11:54:31 -0400812 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200813
Dan Williams2dd4b262007-12-11 16:54:15 -0500814 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
815 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200816
David Woodhouse689442d2007-12-12 16:00:42 -0500817 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500818 if (ret)
819 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200820
Dan Williamscb182a62007-12-11 17:35:51 -0500821 ret = le16_to_cpu(cmd.channel);
822 lbs_deb_cmd("current radio channel is %d\n", ret);
Dan Williams2dd4b262007-12-11 16:54:15 -0500823
824out:
825 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
826 return ret;
827}
828
Holger Schurig73ab1f22008-04-02 16:52:19 +0200829int lbs_update_channel(struct lbs_private *priv)
830{
831 int ret;
832
833 /* the channel in f/w could be out of sync; get the current channel */
834 lbs_deb_enter(LBS_DEB_ASSOC);
835
836 ret = lbs_get_channel(priv);
837 if (ret > 0) {
838 priv->curbssparams.channel = ret;
839 ret = 0;
840 }
841 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
842 return ret;
843}
844
Dan Williams2dd4b262007-12-11 16:54:15 -0500845/**
846 * @brief Set the radio channel
847 *
848 * @param priv A pointer to struct lbs_private structure
849 * @param channel The desired channel, or 0 to clear a locked channel
850 *
851 * @return 0 on success, error on failure
852 */
853int lbs_set_channel(struct lbs_private *priv, u8 channel)
854{
855 struct cmd_ds_802_11_rf_channel cmd;
856 u8 old_channel = priv->curbssparams.channel;
857 int ret = 0;
858
859 lbs_deb_enter(LBS_DEB_CMD);
860
861 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
862 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
863 cmd.channel = cpu_to_le16(channel);
864
David Woodhouse689442d2007-12-12 16:00:42 -0500865 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500866 if (ret)
867 goto out;
868
Dan Williamscb182a62007-12-11 17:35:51 -0500869 priv->curbssparams.channel = (uint8_t) le16_to_cpu(cmd.channel);
870 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
871 priv->curbssparams.channel);
Dan Williams2dd4b262007-12-11 16:54:15 -0500872
873out:
874 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
875 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200876}
877
Holger Schurig69f90322007-11-23 15:43:44 +0100878static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200879 struct cmd_ds_command *cmd)
880{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200881
Holger Schurig8ff12da2007-08-02 11:54:31 -0400882 lbs_deb_enter(LBS_DEB_CMD);
Dan Williams0aef64d2007-08-02 11:31:18 -0400883 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
David Woodhouse981f1872007-05-25 23:36:54 -0400884 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
Holger Schuriga783f1e2007-08-02 13:08:24 -0400885 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200886
887 /* reset Beacon SNR/NF/RSSI values */
David Woodhouseaa21c002007-12-08 20:04:36 +0000888 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
889 priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
890 priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
891 priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
892 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
893 priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200894
Holger Schurig8ff12da2007-08-02 11:54:31 -0400895 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200896 return 0;
897}
898
Holger Schurige98a88d2008-03-19 14:25:58 +0100899static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200900 u8 cmd_action, void *pdata_buf)
901{
Holger Schurig10078322007-11-15 18:05:47 -0500902 struct lbs_offset_value *offval;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200903
Holger Schurig9012b282007-05-25 11:27:16 -0400904 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200905
Holger Schurig10078322007-11-15 18:05:47 -0500906 offval = (struct lbs_offset_value *)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200907
Holger Schurigc2df2ef2007-12-07 15:30:44 +0000908 switch (le16_to_cpu(cmdptr->command)) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400909 case CMD_MAC_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200910 {
911 struct cmd_ds_mac_reg_access *macreg;
912
913 cmdptr->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400914 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
915 + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200916 macreg =
917 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
918 macreg;
919
920 macreg->action = cpu_to_le16(cmd_action);
921 macreg->offset = cpu_to_le16((u16) offval->offset);
922 macreg->value = cpu_to_le32(offval->value);
923
924 break;
925 }
926
Dan Williams0aef64d2007-08-02 11:31:18 -0400927 case CMD_BBP_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200928 {
929 struct cmd_ds_bbp_reg_access *bbpreg;
930
931 cmdptr->size =
932 cpu_to_le16(sizeof
933 (struct cmd_ds_bbp_reg_access)
934 + S_DS_GEN);
935 bbpreg =
936 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
937 bbpreg;
938
939 bbpreg->action = cpu_to_le16(cmd_action);
940 bbpreg->offset = cpu_to_le16((u16) offval->offset);
941 bbpreg->value = (u8) offval->value;
942
943 break;
944 }
945
Dan Williams0aef64d2007-08-02 11:31:18 -0400946 case CMD_RF_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200947 {
948 struct cmd_ds_rf_reg_access *rfreg;
949
950 cmdptr->size =
951 cpu_to_le16(sizeof
952 (struct cmd_ds_rf_reg_access) +
953 S_DS_GEN);
954 rfreg =
955 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
956 rfreg;
957
958 rfreg->action = cpu_to_le16(cmd_action);
959 rfreg->offset = cpu_to_le16((u16) offval->offset);
960 rfreg->value = (u8) offval->value;
961
962 break;
963 }
964
965 default:
966 break;
967 }
968
Holger Schurig9012b282007-05-25 11:27:16 -0400969 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200970 return 0;
971}
972
Holger Schurige98a88d2008-03-19 14:25:58 +0100973static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200974 u16 cmd_action, void *pdata_buf)
975{
976 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
Holger Schurig8ff12da2007-08-02 11:54:31 -0400977 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200978
Dan Williams0aef64d2007-08-02 11:31:18 -0400979 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -0400980 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200981 cmd->result = 0;
982 bt_access->action = cpu_to_le16(cmd_action);
983
984 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400985 case CMD_ACT_BT_ACCESS_ADD:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200986 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400987 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200988 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400989 case CMD_ACT_BT_ACCESS_DEL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200990 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400991 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200992 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400993 case CMD_ACT_BT_ACCESS_LIST:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200994 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
995 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400996 case CMD_ACT_BT_ACCESS_RESET:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200997 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400998 case CMD_ACT_BT_ACCESS_SET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -0400999 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
1000 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001001 case CMD_ACT_BT_ACCESS_GET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -04001002 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001003 default:
1004 break;
1005 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001006 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001007 return 0;
1008}
1009
Holger Schurige98a88d2008-03-19 14:25:58 +01001010static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001011 u16 cmd_action, void *pdata_buf)
1012{
1013 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
Holger Schurig8ff12da2007-08-02 11:54:31 -04001014 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001015
Dan Williams0aef64d2007-08-02 11:31:18 -04001016 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -04001017 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001018 cmd->result = 0;
1019
1020 if (pdata_buf)
1021 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
1022 else
1023 memset(fwt_access, 0, sizeof(*fwt_access));
1024
1025 fwt_access->action = cpu_to_le16(cmd_action);
1026
Holger Schurig8ff12da2007-08-02 11:54:31 -04001027 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001028 return 0;
1029}
1030
David Woodhouse301eacb2007-12-11 15:23:59 -05001031int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
1032 struct cmd_ds_mesh_access *cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001033{
David Woodhouse301eacb2007-12-11 15:23:59 -05001034 int ret;
1035
Holger Schurig8ff12da2007-08-02 11:54:31 -04001036 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001037
David Woodhouse301eacb2007-12-11 15:23:59 -05001038 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
David Woodhouse9fae8992007-12-15 03:46:44 -05001039 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
David Woodhouse301eacb2007-12-11 15:23:59 -05001040 cmd->hdr.result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001041
David Woodhouse301eacb2007-12-11 15:23:59 -05001042 cmd->action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001043
David Woodhouse689442d2007-12-12 16:00:42 -05001044 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001045
Holger Schurig8ff12da2007-08-02 11:54:31 -04001046 lbs_deb_leave(LBS_DEB_CMD);
David Woodhouse301eacb2007-12-11 15:23:59 -05001047 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001048}
1049
David Woodhouse86062132007-12-13 00:32:36 -05001050int lbs_mesh_config(struct lbs_private *priv, uint16_t enable, uint16_t chan)
David Woodhouse23a397a2007-12-11 18:56:42 -05001051{
1052 struct cmd_ds_mesh_config cmd;
1053
1054 memset(&cmd, 0, sizeof(cmd));
1055 cmd.action = cpu_to_le16(enable);
David Woodhouse86062132007-12-13 00:32:36 -05001056 cmd.channel = cpu_to_le16(chan);
David Woodhouse020f3d02007-12-12 23:29:13 -05001057 cmd.type = cpu_to_le16(priv->mesh_tlv);
David Woodhouse9fae8992007-12-15 03:46:44 -05001058 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
David Woodhouse7e226272007-12-14 22:53:41 -05001059
David Woodhouse23a397a2007-12-11 18:56:42 -05001060 if (enable) {
1061 cmd.length = cpu_to_le16(priv->mesh_ssid_len);
1062 memcpy(cmd.data, priv->mesh_ssid, priv->mesh_ssid_len);
1063 }
David Woodhouse020f3d02007-12-12 23:29:13 -05001064 lbs_deb_cmd("mesh config enable %d TLV %x channel %d SSID %s\n",
David Woodhouse86062132007-12-13 00:32:36 -05001065 enable, priv->mesh_tlv, chan,
David Woodhouse06113c12007-12-11 22:52:03 -05001066 escape_essid(priv->mesh_ssid, priv->mesh_ssid_len));
David Woodhouse689442d2007-12-12 16:00:42 -05001067 return lbs_cmd_with_response(priv, CMD_MESH_CONFIG, &cmd);
David Woodhouse23a397a2007-12-11 18:56:42 -05001068}
1069
Brajesh Dave96287ac2007-11-20 17:44:28 -05001070static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
1071 struct cmd_ds_command *cmd,
1072 u16 cmd_action)
1073{
1074 struct cmd_ds_802_11_beacon_control
1075 *bcn_ctrl = &cmd->params.bcn_ctrl;
Brajesh Dave96287ac2007-11-20 17:44:28 -05001076
1077 lbs_deb_enter(LBS_DEB_CMD);
1078 cmd->size =
1079 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
1080 + S_DS_GEN);
1081 cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
1082
1083 bcn_ctrl->action = cpu_to_le16(cmd_action);
David Woodhouseaa21c002007-12-08 20:04:36 +00001084 bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
1085 bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
Brajesh Dave96287ac2007-11-20 17:44:28 -05001086
1087 lbs_deb_leave(LBS_DEB_CMD);
1088 return 0;
1089}
1090
David Woodhouse681ffbb2007-12-15 20:04:54 -05001091static void lbs_queue_cmd(struct lbs_private *priv,
1092 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001093{
1094 unsigned long flags;
David Woodhouse681ffbb2007-12-15 20:04:54 -05001095 int addtail = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001096
Holger Schurig8ff12da2007-08-02 11:54:31 -04001097 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001098
David Woodhousec4ab4122007-12-15 00:41:51 -05001099 if (!cmdnode) {
1100 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001101 goto done;
1102 }
David Woodhoused9896ee2007-12-15 00:09:25 -05001103 if (!cmdnode->cmdbuf->size) {
1104 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
1105 goto done;
1106 }
David Woodhouseae125bf2007-12-15 04:22:52 -05001107 cmdnode->result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001108
1109 /* Exit_PS command needs to be queued in the header always. */
Dan Williamsddac4522007-12-11 13:49:39 -05001110 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
David Woodhouse38bfab12007-12-16 23:26:54 -05001111 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
Dan Williamsddac4522007-12-11 13:49:39 -05001112
Dan Williams0aef64d2007-08-02 11:31:18 -04001113 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001114 if (priv->psstate != PS_STATE_FULL_POWER)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001115 addtail = 0;
1116 }
1117 }
1118
David Woodhouseaa21c002007-12-08 20:04:36 +00001119 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001120
David Woodhouseac472462007-12-08 00:35:00 +00001121 if (addtail)
David Woodhouseaa21c002007-12-08 20:04:36 +00001122 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
David Woodhouseac472462007-12-08 00:35:00 +00001123 else
David Woodhouseaa21c002007-12-08 20:04:36 +00001124 list_add(&cmdnode->list, &priv->cmdpendingq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001125
David Woodhouseaa21c002007-12-08 20:04:36 +00001126 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001127
Holger Schurig8ff12da2007-08-02 11:54:31 -04001128 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
David Woodhousec4ab4122007-12-15 00:41:51 -05001129 le16_to_cpu(cmdnode->cmdbuf->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001130
1131done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001132 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001133}
1134
David Woodhouse18c52e72007-12-17 16:03:58 -05001135static void lbs_submit_command(struct lbs_private *priv,
1136 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001137{
1138 unsigned long flags;
Dan Williamsddac4522007-12-11 13:49:39 -05001139 struct cmd_header *cmd;
David Woodhouse18c52e72007-12-17 16:03:58 -05001140 uint16_t cmdsize;
1141 uint16_t command;
1142 int timeo = 5 * HZ;
1143 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001144
Holger Schurig8ff12da2007-08-02 11:54:31 -04001145 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001146
Dan Williamsddac4522007-12-11 13:49:39 -05001147 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001148
David Woodhouseaa21c002007-12-08 20:04:36 +00001149 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001150 priv->cur_cmd = cmdnode;
1151 priv->cur_cmd_retcode = 0;
1152 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001153
Dan Williamsddac4522007-12-11 13:49:39 -05001154 cmdsize = le16_to_cpu(cmd->size);
1155 command = le16_to_cpu(cmd->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001156
David Woodhouse18c52e72007-12-17 16:03:58 -05001157 /* These commands take longer */
1158 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE ||
1159 command == CMD_802_11_AUTHENTICATE)
1160 timeo = 10 * HZ;
1161
Holger Schurige5225b32008-03-26 10:04:44 +01001162 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
1163 command, le16_to_cpu(cmd->seqnum), cmdsize);
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001164 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001165
Dan Williamsddac4522007-12-11 13:49:39 -05001166 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
David Woodhouse18c52e72007-12-17 16:03:58 -05001167
David Woodhoused9896ee2007-12-15 00:09:25 -05001168 if (ret) {
1169 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
David Woodhouse18c52e72007-12-17 16:03:58 -05001170 /* Let the timer kick in and retry, and potentially reset
1171 the whole thing if the condition persists */
1172 timeo = HZ;
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001173 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001174
1175 /* Setup the timer after transmit command */
David Woodhouse18c52e72007-12-17 16:03:58 -05001176 mod_timer(&priv->command_timer, jiffies + timeo);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001177
David Woodhouse18c52e72007-12-17 16:03:58 -05001178 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001179}
1180
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001181/**
1182 * This function inserts command node to cmdfreeq
David Woodhouseaa21c002007-12-08 20:04:36 +00001183 * after cleans it. Requires priv->driver_lock held.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001184 */
David Woodhouse183aeac2007-12-15 01:52:54 -05001185static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001186 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001187{
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001188 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001189
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001190 if (!cmdnode)
1191 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001192
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001193 cmdnode->callback = NULL;
1194 cmdnode->callback_arg = 0;
1195
1196 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
1197
1198 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
1199 out:
1200 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001201}
1202
Holger Schurig69f90322007-11-23 15:43:44 +01001203static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1204 struct cmd_ctrl_node *ptempcmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001205{
1206 unsigned long flags;
1207
David Woodhouseaa21c002007-12-08 20:04:36 +00001208 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig10078322007-11-15 18:05:47 -05001209 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
David Woodhouseaa21c002007-12-08 20:04:36 +00001210 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001211}
1212
David Woodhouse183aeac2007-12-15 01:52:54 -05001213void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1214 int result)
1215{
1216 if (cmd == priv->cur_cmd)
1217 priv->cur_cmd_retcode = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001218
David Woodhouseae125bf2007-12-15 04:22:52 -05001219 cmd->result = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001220 cmd->cmdwaitqwoken = 1;
1221 wake_up_interruptible(&cmd->cmdwait_q);
1222
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001223 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
David Woodhousead12d0f2007-12-15 02:06:16 -05001224 __lbs_cleanup_and_insert_cmd(priv, cmd);
David Woodhouse183aeac2007-12-15 01:52:54 -05001225 priv->cur_cmd = NULL;
1226}
1227
Holger Schurig69f90322007-11-23 15:43:44 +01001228int lbs_set_radio_control(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001229{
1230 int ret = 0;
David Woodhousea7c45892007-12-17 22:43:48 -05001231 struct cmd_ds_802_11_radio_control cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001232
Holger Schurig9012b282007-05-25 11:27:16 -04001233 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001234
David Woodhousea7c45892007-12-17 22:43:48 -05001235 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1236 cmd.action = cpu_to_le16(CMD_ACT_SET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001237
David Woodhousea7c45892007-12-17 22:43:48 -05001238 switch (priv->preamble) {
1239 case CMD_TYPE_SHORT_PREAMBLE:
1240 cmd.control = cpu_to_le16(SET_SHORT_PREAMBLE);
1241 break;
1242
1243 case CMD_TYPE_LONG_PREAMBLE:
1244 cmd.control = cpu_to_le16(SET_LONG_PREAMBLE);
1245 break;
1246
1247 case CMD_TYPE_AUTO_PREAMBLE:
1248 default:
1249 cmd.control = cpu_to_le16(SET_AUTO_PREAMBLE);
1250 break;
1251 }
1252
1253 if (priv->radioon)
1254 cmd.control |= cpu_to_le16(TURN_ON_RF);
1255 else
1256 cmd.control &= cpu_to_le16(~TURN_ON_RF);
1257
1258 lbs_deb_cmd("RADIO_SET: radio %d, preamble %d\n", priv->radioon,
1259 priv->preamble);
1260
1261 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001262
Holger Schurig9012b282007-05-25 11:27:16 -04001263 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001264 return ret;
1265}
1266
Holger Schurigc97329e2008-03-18 11:20:21 +01001267void lbs_set_mac_control(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001268{
Holger Schurig835d3ac2008-03-12 16:05:40 +01001269 struct cmd_ds_mac_control cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001270
Holger Schurig9012b282007-05-25 11:27:16 -04001271 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001272
Holger Schurig835d3ac2008-03-12 16:05:40 +01001273 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Holger Schurigd9e97782008-03-12 16:06:43 +01001274 cmd.action = cpu_to_le16(priv->mac_control);
Holger Schurig835d3ac2008-03-12 16:05:40 +01001275 cmd.reserved = 0;
1276
Holger Schurigc97329e2008-03-18 11:20:21 +01001277 lbs_cmd_async(priv, CMD_MAC_CONTROL,
1278 &cmd.hdr, sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001279
Holger Schurigc97329e2008-03-18 11:20:21 +01001280 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001281}
1282
1283/**
1284 * @brief This function prepare the command before send to firmware.
1285 *
Holger Schurig69f90322007-11-23 15:43:44 +01001286 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001287 * @param cmd_no command number
1288 * @param cmd_action command action: GET or SET
1289 * @param wait_option wait option: wait response or not
1290 * @param cmd_oid cmd oid: treated as sub command
1291 * @param pdata_buf A pointer to informaion buffer
1292 * @return 0 or -1
1293 */
Holger Schurig69f90322007-11-23 15:43:44 +01001294int lbs_prepare_and_send_command(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001295 u16 cmd_no,
1296 u16 cmd_action,
1297 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1298{
1299 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001300 struct cmd_ctrl_node *cmdnode;
1301 struct cmd_ds_command *cmdptr;
1302 unsigned long flags;
1303
Holger Schurig8ff12da2007-08-02 11:54:31 -04001304 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001305
David Woodhouseaa21c002007-12-08 20:04:36 +00001306 if (!priv) {
1307 lbs_deb_host("PREP_CMD: priv is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001308 ret = -1;
1309 goto done;
1310 }
1311
David Woodhouseaa21c002007-12-08 20:04:36 +00001312 if (priv->surpriseremoved) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001313 lbs_deb_host("PREP_CMD: card removed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001314 ret = -1;
1315 goto done;
1316 }
1317
Holger Schurig0d61d042007-12-05 17:58:06 +01001318 cmdnode = lbs_get_cmd_ctrl_node(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001319
1320 if (cmdnode == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001321 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001322
1323 /* Wake up main thread to execute next command */
Dan Williamsfe336152007-08-02 11:32:25 -04001324 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001325 ret = -1;
1326 goto done;
1327 }
1328
Holger Schurige98a88d2008-03-19 14:25:58 +01001329 cmdnode->callback = NULL;
1330 cmdnode->callback_arg = (unsigned long)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001331
Dan Williamsddac4522007-12-11 13:49:39 -05001332 cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001333
Holger Schurig8ff12da2007-08-02 11:54:31 -04001334 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001335
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001336 /* Set sequence number, command and INT option */
David Woodhouseaa21c002007-12-08 20:04:36 +00001337 priv->seqnum++;
1338 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001339
David Woodhouse981f1872007-05-25 23:36:54 -04001340 cmdptr->command = cpu_to_le16(cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001341 cmdptr->result = 0;
1342
1343 switch (cmd_no) {
Dan Williams0aef64d2007-08-02 11:31:18 -04001344 case CMD_802_11_PS_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001345 ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001346 break;
1347
Dan Williams0aef64d2007-08-02 11:31:18 -04001348 case CMD_802_11_ASSOCIATE:
1349 case CMD_802_11_REASSOCIATE:
Holger Schurig10078322007-11-15 18:05:47 -05001350 ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001351 break;
1352
Dan Williams0aef64d2007-08-02 11:31:18 -04001353 case CMD_802_11_DEAUTHENTICATE:
Holger Schurig10078322007-11-15 18:05:47 -05001354 ret = lbs_cmd_80211_deauthenticate(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001355 break;
1356
Dan Williams0aef64d2007-08-02 11:31:18 -04001357 case CMD_802_11_AD_HOC_START:
Holger Schurig10078322007-11-15 18:05:47 -05001358 ret = lbs_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001359 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001360
Dan Williams0aef64d2007-08-02 11:31:18 -04001361 case CMD_802_11_RESET:
Holger Schurige98a88d2008-03-19 14:25:58 +01001362 ret = lbs_cmd_802_11_reset(cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001363 break;
1364
Dan Williams0aef64d2007-08-02 11:31:18 -04001365 case CMD_802_11_AUTHENTICATE:
Holger Schurig10078322007-11-15 18:05:47 -05001366 ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001367 break;
1368
Dan Williams0aef64d2007-08-02 11:31:18 -04001369 case CMD_802_11_SNMP_MIB:
Holger Schurig10078322007-11-15 18:05:47 -05001370 ret = lbs_cmd_802_11_snmp_mib(priv, cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001371 cmd_action, cmd_oid, pdata_buf);
1372 break;
1373
Dan Williams0aef64d2007-08-02 11:31:18 -04001374 case CMD_MAC_REG_ACCESS:
1375 case CMD_BBP_REG_ACCESS:
1376 case CMD_RF_REG_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001377 ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001378 break;
1379
Dan Williams0aef64d2007-08-02 11:31:18 -04001380 case CMD_802_11_RF_TX_POWER:
Holger Schurige98a88d2008-03-19 14:25:58 +01001381 ret = lbs_cmd_802_11_rf_tx_power(cmdptr,
1382 cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001383 break;
1384
Dan Williams0aef64d2007-08-02 11:31:18 -04001385 case CMD_802_11_RATE_ADAPT_RATESET:
Holger Schurig10078322007-11-15 18:05:47 -05001386 ret = lbs_cmd_802_11_rate_adapt_rateset(priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001387 cmdptr, cmd_action);
1388 break;
1389
Dan Williams0aef64d2007-08-02 11:31:18 -04001390 case CMD_MAC_MULTICAST_ADR:
Holger Schurig10078322007-11-15 18:05:47 -05001391 ret = lbs_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001392 break;
1393
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001394 case CMD_802_11_MONITOR_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001395 ret = lbs_cmd_802_11_monitor_mode(cmdptr,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001396 cmd_action, pdata_buf);
1397 break;
1398
Dan Williams0aef64d2007-08-02 11:31:18 -04001399 case CMD_802_11_AD_HOC_JOIN:
Holger Schurig10078322007-11-15 18:05:47 -05001400 ret = lbs_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001401 break;
1402
Dan Williams0aef64d2007-08-02 11:31:18 -04001403 case CMD_802_11_RSSI:
Holger Schurig10078322007-11-15 18:05:47 -05001404 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001405 break;
1406
Dan Williams0aef64d2007-08-02 11:31:18 -04001407 case CMD_802_11_AD_HOC_STOP:
Holger Schurige98a88d2008-03-19 14:25:58 +01001408 ret = lbs_cmd_80211_ad_hoc_stop(cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001409 break;
1410
Dan Williams0aef64d2007-08-02 11:31:18 -04001411 case CMD_802_11_SET_AFC:
1412 case CMD_802_11_GET_AFC:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001413
1414 cmdptr->command = cpu_to_le16(cmd_no);
David Woodhouse981f1872007-05-25 23:36:54 -04001415 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1416 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001417
1418 memmove(&cmdptr->params.afc,
1419 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1420
1421 ret = 0;
1422 goto done;
1423
Dan Williams0aef64d2007-08-02 11:31:18 -04001424 case CMD_802_11D_DOMAIN_INFO:
Holger Schurig10078322007-11-15 18:05:47 -05001425 ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001426 cmd_no, cmd_action);
1427 break;
1428
Dan Williams0aef64d2007-08-02 11:31:18 -04001429 case CMD_802_11_TPC_CFG:
1430 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001431 cmdptr->size =
1432 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1433 S_DS_GEN);
1434
1435 memmove(&cmdptr->params.tpccfg,
1436 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1437
1438 ret = 0;
1439 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001440 case CMD_802_11_LED_GPIO_CTRL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001441 {
1442 struct mrvlietypes_ledgpio *gpio =
1443 (struct mrvlietypes_ledgpio*)
1444 cmdptr->params.ledgpio.data;
1445
1446 memmove(&cmdptr->params.ledgpio,
1447 pdata_buf,
1448 sizeof(struct cmd_ds_802_11_led_ctrl));
1449
1450 cmdptr->command =
Dan Williams0aef64d2007-08-02 11:31:18 -04001451 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001452
1453#define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1454 cmdptr->size =
Holger Schurigc2df2ef2007-12-07 15:30:44 +00001455 cpu_to_le16(le16_to_cpu(gpio->header.len)
1456 + S_DS_GEN
1457 + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1458 gpio->header.len = gpio->header.len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001459
1460 ret = 0;
1461 break;
1462 }
David Woodhouse5844d122007-12-18 02:01:37 -05001463
Dan Williams0aef64d2007-08-02 11:31:18 -04001464 case CMD_BT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001465 ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001466 break;
1467
Dan Williams0aef64d2007-08-02 11:31:18 -04001468 case CMD_FWT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001469 ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001470 break;
1471
Dan Williams0aef64d2007-08-02 11:31:18 -04001472 case CMD_GET_TSF:
1473 cmdptr->command = cpu_to_le16(CMD_GET_TSF);
David Woodhouse981f1872007-05-25 23:36:54 -04001474 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1475 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001476 ret = 0;
1477 break;
Brajesh Dave96287ac2007-11-20 17:44:28 -05001478 case CMD_802_11_BEACON_CTRL:
1479 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1480 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001481 default:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001482 lbs_deb_host("PREP_CMD: unknown command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001483 ret = -1;
1484 break;
1485 }
1486
1487 /* return error, since the command preparation failed */
1488 if (ret != 0) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001489 lbs_deb_host("PREP_CMD: command preparation failed\n");
Holger Schurig10078322007-11-15 18:05:47 -05001490 lbs_cleanup_and_insert_cmd(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001491 ret = -1;
1492 goto done;
1493 }
1494
1495 cmdnode->cmdwaitqwoken = 0;
1496
David Woodhouse681ffbb2007-12-15 20:04:54 -05001497 lbs_queue_cmd(priv, cmdnode);
Dan Williamsfe336152007-08-02 11:32:25 -04001498 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001499
Dan Williams0aef64d2007-08-02 11:31:18 -04001500 if (wait_option & CMD_OPTION_WAITFORRSP) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001501 lbs_deb_host("PREP_CMD: wait for response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001502 might_sleep();
1503 wait_event_interruptible(cmdnode->cmdwait_q,
1504 cmdnode->cmdwaitqwoken);
1505 }
1506
David Woodhouseaa21c002007-12-08 20:04:36 +00001507 spin_lock_irqsave(&priv->driver_lock, flags);
1508 if (priv->cur_cmd_retcode) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001509 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001510 priv->cur_cmd_retcode);
1511 priv->cur_cmd_retcode = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001512 ret = -1;
1513 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001514 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001515
1516done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001517 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001518 return ret;
1519}
1520
1521/**
1522 * @brief This function allocates the command buffer and link
1523 * it to command free queue.
1524 *
Holger Schurig69f90322007-11-23 15:43:44 +01001525 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001526 * @return 0 or -1
1527 */
Holger Schurig69f90322007-11-23 15:43:44 +01001528int lbs_allocate_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001529{
1530 int ret = 0;
Dan Williamsddac4522007-12-11 13:49:39 -05001531 u32 bufsize;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001532 u32 i;
Dan Williamsddac4522007-12-11 13:49:39 -05001533 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001534
Holger Schurig8ff12da2007-08-02 11:54:31 -04001535 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001536
Dan Williamsddac4522007-12-11 13:49:39 -05001537 /* Allocate and initialize the command array */
1538 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1539 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001540 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001541 ret = -1;
1542 goto done;
1543 }
Dan Williamsddac4522007-12-11 13:49:39 -05001544 priv->cmd_array = cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001545
Dan Williamsddac4522007-12-11 13:49:39 -05001546 /* Allocate and initialize each command buffer in the command array */
1547 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1548 cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
1549 if (!cmdarray[i].cmdbuf) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001550 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001551 ret = -1;
1552 goto done;
1553 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001554 }
1555
Dan Williamsddac4522007-12-11 13:49:39 -05001556 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1557 init_waitqueue_head(&cmdarray[i].cmdwait_q);
1558 lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001559 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001560 ret = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001561
1562done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001563 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001564 return ret;
1565}
1566
1567/**
1568 * @brief This function frees the command buffer.
1569 *
Holger Schurig69f90322007-11-23 15:43:44 +01001570 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001571 * @return 0 or -1
1572 */
Holger Schurig69f90322007-11-23 15:43:44 +01001573int lbs_free_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001574{
Dan Williamsddac4522007-12-11 13:49:39 -05001575 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001576 unsigned int i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001577
Holger Schurig8ff12da2007-08-02 11:54:31 -04001578 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001579
1580 /* need to check if cmd array is allocated or not */
David Woodhouseaa21c002007-12-08 20:04:36 +00001581 if (priv->cmd_array == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001582 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001583 goto done;
1584 }
1585
Dan Williamsddac4522007-12-11 13:49:39 -05001586 cmdarray = priv->cmd_array;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001587
1588 /* Release shared memory buffers */
Dan Williamsddac4522007-12-11 13:49:39 -05001589 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1590 if (cmdarray[i].cmdbuf) {
1591 kfree(cmdarray[i].cmdbuf);
1592 cmdarray[i].cmdbuf = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001593 }
1594 }
1595
1596 /* Release cmd_ctrl_node */
David Woodhouseaa21c002007-12-08 20:04:36 +00001597 if (priv->cmd_array) {
1598 kfree(priv->cmd_array);
1599 priv->cmd_array = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001600 }
1601
1602done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001603 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001604 return 0;
1605}
1606
1607/**
1608 * @brief This function gets a free command node if available in
1609 * command free queue.
1610 *
Holger Schurig69f90322007-11-23 15:43:44 +01001611 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001612 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1613 */
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001614static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001615{
1616 struct cmd_ctrl_node *tempnode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001617 unsigned long flags;
1618
Holger Schurig8ff12da2007-08-02 11:54:31 -04001619 lbs_deb_enter(LBS_DEB_HOST);
1620
David Woodhouseaa21c002007-12-08 20:04:36 +00001621 if (!priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001622 return NULL;
1623
David Woodhouseaa21c002007-12-08 20:04:36 +00001624 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001625
David Woodhouseaa21c002007-12-08 20:04:36 +00001626 if (!list_empty(&priv->cmdfreeq)) {
1627 tempnode = list_first_entry(&priv->cmdfreeq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001628 struct cmd_ctrl_node, list);
1629 list_del(&tempnode->list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001630 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001631 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001632 tempnode = NULL;
1633 }
1634
David Woodhouseaa21c002007-12-08 20:04:36 +00001635 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001636
Holger Schurig8ff12da2007-08-02 11:54:31 -04001637 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001638 return tempnode;
1639}
1640
1641/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001642 * @brief This function executes next command in command
1643 * pending queue. It will put fimware back to PS mode
1644 * if applicable.
1645 *
Holger Schurig69f90322007-11-23 15:43:44 +01001646 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001647 * @return 0 or -1
1648 */
Holger Schurig69f90322007-11-23 15:43:44 +01001649int lbs_execute_next_command(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001650{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001651 struct cmd_ctrl_node *cmdnode = NULL;
Dan Williamsddac4522007-12-11 13:49:39 -05001652 struct cmd_header *cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001653 unsigned long flags;
1654 int ret = 0;
1655
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001656 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1657 * only caller to us is lbs_thread() and we get even when a
1658 * data packet is received */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001659 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001660
David Woodhouseaa21c002007-12-08 20:04:36 +00001661 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001662
David Woodhouseaa21c002007-12-08 20:04:36 +00001663 if (priv->cur_cmd) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001664 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001665 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001666 ret = -1;
1667 goto done;
1668 }
1669
David Woodhouseaa21c002007-12-08 20:04:36 +00001670 if (!list_empty(&priv->cmdpendingq)) {
1671 cmdnode = list_first_entry(&priv->cmdpendingq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001672 struct cmd_ctrl_node, list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001673 }
1674
David Woodhouseaa21c002007-12-08 20:04:36 +00001675 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001676
1677 if (cmdnode) {
Dan Williamsddac4522007-12-11 13:49:39 -05001678 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001679
Dan Williamsddac4522007-12-11 13:49:39 -05001680 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001681 if ((priv->psstate == PS_STATE_SLEEP) ||
1682 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001683 lbs_deb_host(
1684 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001685 le16_to_cpu(cmd->command),
David Woodhouseaa21c002007-12-08 20:04:36 +00001686 priv->psstate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001687 ret = -1;
1688 goto done;
1689 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001690 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
Dan Williamsddac4522007-12-11 13:49:39 -05001691 "0x%04x in psstate %d\n",
1692 le16_to_cpu(cmd->command), priv->psstate);
David Woodhouseaa21c002007-12-08 20:04:36 +00001693 } else if (priv->psstate != PS_STATE_FULL_POWER) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001694 /*
1695 * 1. Non-PS command:
1696 * Queue it. set needtowakeup to TRUE if current state
Holger Schurig10078322007-11-15 18:05:47 -05001697 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001698 * 2. PS command but not Exit_PS:
1699 * Ignore it.
1700 * 3. PS command Exit_PS:
1701 * Set needtowakeup to TRUE if current state is SLEEP,
1702 * otherwise send this command down to firmware
1703 * immediately.
1704 */
Dan Williamsddac4522007-12-11 13:49:39 -05001705 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001706 /* Prepare to send Exit PS,
1707 * this non PS command will be sent later */
David Woodhouseaa21c002007-12-08 20:04:36 +00001708 if ((priv->psstate == PS_STATE_SLEEP)
1709 || (priv->psstate == PS_STATE_PRE_SLEEP)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001710 ) {
1711 /* w/ new scheme, it will not reach here.
1712 since it is blocked in main_thread. */
David Woodhouseaa21c002007-12-08 20:04:36 +00001713 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001714 } else
Holger Schurig10078322007-11-15 18:05:47 -05001715 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001716
1717 ret = 0;
1718 goto done;
1719 } else {
1720 /*
1721 * PS command. Ignore it if it is not Exit_PS.
1722 * otherwise send it down immediately.
1723 */
David Woodhouse38bfab12007-12-16 23:26:54 -05001724 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001725
Holger Schurig8ff12da2007-08-02 11:54:31 -04001726 lbs_deb_host(
1727 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001728 psm->action);
1729 if (psm->action !=
Dan Williams0aef64d2007-08-02 11:31:18 -04001730 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001731 lbs_deb_host(
1732 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001733 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001734 spin_lock_irqsave(&priv->driver_lock, flags);
1735 lbs_complete_command(priv, cmdnode, 0);
1736 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001737
1738 ret = 0;
1739 goto done;
1740 }
1741
David Woodhouseaa21c002007-12-08 20:04:36 +00001742 if ((priv->psstate == PS_STATE_SLEEP) ||
1743 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001744 lbs_deb_host(
1745 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001746 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001747 spin_lock_irqsave(&priv->driver_lock, flags);
1748 lbs_complete_command(priv, cmdnode, 0);
1749 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001750 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001751
1752 ret = 0;
1753 goto done;
1754 }
1755
Holger Schurig8ff12da2007-08-02 11:54:31 -04001756 lbs_deb_host(
1757 "EXEC_NEXT_CMD: sending EXIT_PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001758 }
1759 }
Li Zefanabe3ed12007-12-06 13:01:21 +01001760 list_del(&cmdnode->list);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001761 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001762 le16_to_cpu(cmd->command));
David Woodhoused9896ee2007-12-15 00:09:25 -05001763 lbs_submit_command(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001764 } else {
1765 /*
1766 * check if in power save mode, if yes, put the device back
1767 * to PS mode
1768 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001769 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1770 (priv->psstate == PS_STATE_FULL_POWER) &&
1771 ((priv->connect_status == LBS_CONNECTED) ||
1772 (priv->mesh_connect_status == LBS_CONNECTED))) {
1773 if (priv->secinfo.WPAenabled ||
1774 priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001775 /* check for valid WPA group keys */
David Woodhouseaa21c002007-12-08 20:04:36 +00001776 if (priv->wpa_mcast_key.len ||
1777 priv->wpa_unicast_key.len) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001778 lbs_deb_host(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001779 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1780 " go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001781 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001782 }
1783 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001784 lbs_deb_host(
1785 "EXEC_NEXT_CMD: cmdpendingq empty, "
1786 "go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001787 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001788 }
1789 }
1790 }
1791
1792 ret = 0;
1793done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001794 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001795 return ret;
1796}
1797
Holger Schurig69f90322007-11-23 15:43:44 +01001798void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001799{
1800 union iwreq_data iwrq;
1801 u8 buf[50];
1802
Holger Schurig8ff12da2007-08-02 11:54:31 -04001803 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001804
1805 memset(&iwrq, 0, sizeof(union iwreq_data));
1806 memset(buf, 0, sizeof(buf));
1807
1808 snprintf(buf, sizeof(buf) - 1, "%s", str);
1809
1810 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1811
1812 /* Send Event to upper layer */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001813 lbs_deb_wext("event indication string %s\n", (char *)buf);
1814 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
1815 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001816
Holger Schurig634b8f42007-05-25 13:05:16 -04001817 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001818
Holger Schurig8ff12da2007-08-02 11:54:31 -04001819 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001820}
1821
Holger Schurigf539f2e2008-03-26 13:22:11 +01001822static void lbs_send_confirmsleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001823{
1824 unsigned long flags;
Holger Schurigf539f2e2008-03-26 13:22:11 +01001825 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001826
Holger Schurig8ff12da2007-08-02 11:54:31 -04001827 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurigf539f2e2008-03-26 13:22:11 +01001828 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1829 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001830
Holger Schurigf539f2e2008-03-26 13:22:11 +01001831 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1832 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001833 if (ret) {
Holger Schurigf539f2e2008-03-26 13:22:11 +01001834 lbs_pr_alert("confirm_sleep failed\n");
Holger Schurig7919b892008-04-01 14:50:43 +02001835 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001836 }
Holger Schurig7919b892008-04-01 14:50:43 +02001837
1838 spin_lock_irqsave(&priv->driver_lock, flags);
1839
1840 /* If nothing to do, go back to sleep (?) */
1841 if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
1842 priv->psstate = PS_STATE_SLEEP;
1843
1844 spin_unlock_irqrestore(&priv->driver_lock, flags);
1845
1846out:
Holger Schurigf539f2e2008-03-26 13:22:11 +01001847 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001848}
1849
Holger Schurig69f90322007-11-23 15:43:44 +01001850void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001851{
Holger Schurig8ff12da2007-08-02 11:54:31 -04001852 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001853
1854 /*
1855 * PS is currently supported only in Infrastructure mode
1856 * Remove this check if it is to be supported in IBSS mode also
1857 */
1858
Holger Schurig10078322007-11-15 18:05:47 -05001859 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001860 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001861
Holger Schurig8ff12da2007-08-02 11:54:31 -04001862 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001863}
1864
1865/**
Holger Schurig8ff12da2007-08-02 11:54:31 -04001866 * @brief This function sends Exit_PS command to firmware.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001867 *
Holger Schurig69f90322007-11-23 15:43:44 +01001868 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001869 * @param wait_option wait response or not
1870 * @return n/a
1871 */
Holger Schurig69f90322007-11-23 15:43:44 +01001872void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001873{
David Woodhouse981f1872007-05-25 23:36:54 -04001874 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001875
Holger Schurig8ff12da2007-08-02 11:54:31 -04001876 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001877
Holger Schurig10078322007-11-15 18:05:47 -05001878 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001879
Holger Schurig10078322007-11-15 18:05:47 -05001880 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001881 CMD_SUBCMD_EXIT_PS,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001882 wait_option, 0, &Localpsmode);
1883
Holger Schurig8ff12da2007-08-02 11:54:31 -04001884 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001885}
1886
1887/**
1888 * @brief This function checks condition and prepares to
1889 * send sleep confirm command to firmware if ok.
1890 *
Holger Schurig69f90322007-11-23 15:43:44 +01001891 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001892 * @param psmode Power Saving mode
1893 * @return n/a
1894 */
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001895void lbs_ps_confirm_sleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001896{
1897 unsigned long flags =0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001898 int allowed = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001899
Holger Schurig8ff12da2007-08-02 11:54:31 -04001900 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001901
Holger Schurig634b8f42007-05-25 13:05:16 -04001902 if (priv->dnld_sent) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001903 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001904 lbs_deb_host("dnld_sent was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001905 }
1906
David Woodhouseaa21c002007-12-08 20:04:36 +00001907 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig7919b892008-04-01 14:50:43 +02001908 /* In-progress command? */
David Woodhouseaa21c002007-12-08 20:04:36 +00001909 if (priv->cur_cmd) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001910 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001911 lbs_deb_host("cur_cmd was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001912 }
Holger Schurig7919b892008-04-01 14:50:43 +02001913
1914 /* Pending events or command responses? */
1915 if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001916 allowed = 0;
Holger Schurig7919b892008-04-01 14:50:43 +02001917 lbs_deb_host("pending events or command responses\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001918 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001919 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001920
1921 if (allowed) {
Holger Schurig10078322007-11-15 18:05:47 -05001922 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
Holger Schurigf539f2e2008-03-26 13:22:11 +01001923 lbs_send_confirmsleep(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001924 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001925 lbs_deb_host("sleep confirm has been delayed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001926 }
1927
Holger Schurig8ff12da2007-08-02 11:54:31 -04001928 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001929}
Holger Schurig675787e2007-12-05 17:58:11 +01001930
1931
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001932static struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
1933 uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
1934 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1935 unsigned long callback_arg)
Holger Schurig675787e2007-12-05 17:58:11 +01001936{
Holger Schurig675787e2007-12-05 17:58:11 +01001937 struct cmd_ctrl_node *cmdnode;
Holger Schurig675787e2007-12-05 17:58:11 +01001938
1939 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurig675787e2007-12-05 17:58:11 +01001940
David Woodhouseaa21c002007-12-08 20:04:36 +00001941 if (priv->surpriseremoved) {
Holger Schurig675787e2007-12-05 17:58:11 +01001942 lbs_deb_host("PREP_CMD: card removed\n");
David Woodhouse3399ea52007-12-15 03:09:33 -05001943 cmdnode = ERR_PTR(-ENOENT);
Holger Schurig675787e2007-12-05 17:58:11 +01001944 goto done;
1945 }
1946
1947 cmdnode = lbs_get_cmd_ctrl_node(priv);
Holger Schurig675787e2007-12-05 17:58:11 +01001948 if (cmdnode == NULL) {
1949 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1950
1951 /* Wake up main thread to execute next command */
1952 wake_up_interruptible(&priv->waitq);
David Woodhouse3399ea52007-12-15 03:09:33 -05001953 cmdnode = ERR_PTR(-ENOBUFS);
Holger Schurig675787e2007-12-05 17:58:11 +01001954 goto done;
1955 }
1956
David Woodhouse448a51a2007-12-08 00:59:54 +00001957 cmdnode->callback = callback;
David Woodhouse1309b552007-12-10 13:36:10 -05001958 cmdnode->callback_arg = callback_arg;
Holger Schurig675787e2007-12-05 17:58:11 +01001959
Dan Williams7ad994d2007-12-11 12:33:30 -05001960 /* Copy the incoming command to the buffer */
Dan Williamsddac4522007-12-11 13:49:39 -05001961 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
Dan Williams7ad994d2007-12-11 12:33:30 -05001962
Holger Schurig675787e2007-12-05 17:58:11 +01001963 /* Set sequence number, clean result, move to buffer */
David Woodhouseaa21c002007-12-08 20:04:36 +00001964 priv->seqnum++;
Dan Williamsddac4522007-12-11 13:49:39 -05001965 cmdnode->cmdbuf->command = cpu_to_le16(command);
1966 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
1967 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
1968 cmdnode->cmdbuf->result = 0;
Holger Schurig675787e2007-12-05 17:58:11 +01001969
1970 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
1971
Holger Schurig675787e2007-12-05 17:58:11 +01001972 cmdnode->cmdwaitqwoken = 0;
David Woodhouse681ffbb2007-12-15 20:04:54 -05001973 lbs_queue_cmd(priv, cmdnode);
Holger Schurig675787e2007-12-05 17:58:11 +01001974 wake_up_interruptible(&priv->waitq);
1975
David Woodhouse3399ea52007-12-15 03:09:33 -05001976 done:
1977 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
1978 return cmdnode;
1979}
1980
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001981void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
1982 struct cmd_header *in_cmd, int in_cmd_size)
1983{
1984 lbs_deb_enter(LBS_DEB_CMD);
1985 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1986 lbs_cmd_async_callback, 0);
1987 lbs_deb_leave(LBS_DEB_CMD);
1988}
1989
David Woodhouse3399ea52007-12-15 03:09:33 -05001990int __lbs_cmd(struct lbs_private *priv, uint16_t command,
1991 struct cmd_header *in_cmd, int in_cmd_size,
1992 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1993 unsigned long callback_arg)
1994{
1995 struct cmd_ctrl_node *cmdnode;
1996 unsigned long flags;
1997 int ret = 0;
1998
1999 lbs_deb_enter(LBS_DEB_HOST);
2000
2001 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2002 callback, callback_arg);
2003 if (IS_ERR(cmdnode)) {
2004 ret = PTR_ERR(cmdnode);
2005 goto done;
2006 }
2007
Holger Schurig675787e2007-12-05 17:58:11 +01002008 might_sleep();
2009 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
2010
David Woodhouseaa21c002007-12-08 20:04:36 +00002011 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseae125bf2007-12-15 04:22:52 -05002012 ret = cmdnode->result;
2013 if (ret)
2014 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
2015 command, ret);
David Woodhouse3399ea52007-12-15 03:09:33 -05002016
David Woodhousead12d0f2007-12-15 02:06:16 -05002017 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
David Woodhouseaa21c002007-12-08 20:04:36 +00002018 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig675787e2007-12-05 17:58:11 +01002019
2020done:
2021 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
2022 return ret;
2023}
Dan Williams14e865b2007-12-10 15:11:23 -05002024EXPORT_SYMBOL_GPL(__lbs_cmd);
Holger Schurig675787e2007-12-05 17:58:11 +01002025
2026