blob: 6658590ca6e3f7c277776c5dcdb1e444c29efd72 [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>
7#include "host.h"
8#include "hostcmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02009#include "decl.h"
10#include "defs.h"
11#include "dev.h"
12#include "join.h"
13#include "wext.h"
14
15static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode);
16
17static u16 commands_allowed_in_ps[] = {
Dan Williams0aef64d2007-08-02 11:31:18 -040018 CMD_802_11_RSSI,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020019};
20
21/**
22 * @brief This function checks if the commans is allowed
23 * in PS mode not.
24 *
25 * @param command the command ID
26 * @return TRUE or FALSE
27 */
David Woodhouse981f1872007-05-25 23:36:54 -040028static u8 is_command_allowed_in_ps(__le16 command)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020029{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020030 int i;
31
David Woodhouse981f1872007-05-25 23:36:54 -040032 for (i = 0; i < ARRAY_SIZE(commands_allowed_in_ps); i++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020033 if (command == cpu_to_le16(commands_allowed_in_ps[i]))
34 return 1;
35 }
36
37 return 0;
38}
39
Holger Schurig69f90322007-11-23 15:43:44 +010040static int lbs_cmd_hw_spec(struct lbs_private *priv, struct cmd_ds_command *cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020041{
42 struct cmd_ds_get_hw_spec *hwspec = &cmd->params.hwspec;
43
Holger Schurig9012b282007-05-25 11:27:16 -040044 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020045
Dan Williams0aef64d2007-08-02 11:31:18 -040046 cmd->command = cpu_to_le16(CMD_GET_HW_SPEC);
David Woodhouse981f1872007-05-25 23:36:54 -040047 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_get_hw_spec) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020048 memcpy(hwspec->permanentaddr, priv->adapter->current_addr, ETH_ALEN);
49
Holger Schurig9012b282007-05-25 11:27:16 -040050 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020051 return 0;
52}
53
Holger Schurig69f90322007-11-23 15:43:44 +010054static int lbs_cmd_802_11_ps_mode(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020055 struct cmd_ds_command *cmd,
56 u16 cmd_action)
57{
58 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020059
Holger Schurig9012b282007-05-25 11:27:16 -040060 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020061
Dan Williams0aef64d2007-08-02 11:31:18 -040062 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
David Woodhouse981f1872007-05-25 23:36:54 -040063 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
64 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020065 psm->action = cpu_to_le16(cmd_action);
66 psm->multipledtim = 0;
David Woodhouse981f1872007-05-25 23:36:54 -040067 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -040068 case CMD_SUBCMD_ENTER_PS:
Holger Schurig9012b282007-05-25 11:27:16 -040069 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020070
Holger Schurig252cf0d2007-08-02 13:09:34 -040071 psm->locallisteninterval = 0;
Holger Schurig97605c32007-08-02 13:09:15 -040072 psm->nullpktinterval = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020073 psm->multipledtim =
Holger Schurig56c46562007-08-02 13:09:49 -040074 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020075 break;
76
Dan Williams0aef64d2007-08-02 11:31:18 -040077 case CMD_SUBCMD_EXIT_PS:
Holger Schurig9012b282007-05-25 11:27:16 -040078 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020079 break;
80
Dan Williams0aef64d2007-08-02 11:31:18 -040081 case CMD_SUBCMD_SLEEP_CONFIRMED:
Holger Schurig9012b282007-05-25 11:27:16 -040082 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020083 break;
84
85 default:
86 break;
87 }
88
Holger Schurig9012b282007-05-25 11:27:16 -040089 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020090 return 0;
91}
92
Holger Schurig69f90322007-11-23 15:43:44 +010093static int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020094 struct cmd_ds_command *cmd,
95 u16 cmd_action, void *pdata_buf)
96{
97 u16 *timeout = pdata_buf;
98
Holger Schurig8ff12da2007-08-02 11:54:31 -040099 lbs_deb_enter(LBS_DEB_CMD);
100
Dan Williams0aef64d2007-08-02 11:31:18 -0400101 cmd->command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200102 cmd->size =
103 cpu_to_le16(sizeof(struct cmd_ds_802_11_inactivity_timeout)
104 + S_DS_GEN);
105
106 cmd->params.inactivity_timeout.action = cpu_to_le16(cmd_action);
107
108 if (cmd_action)
David Woodhouse981f1872007-05-25 23:36:54 -0400109 cmd->params.inactivity_timeout.timeout = cpu_to_le16(*timeout);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200110 else
111 cmd->params.inactivity_timeout.timeout = 0;
112
Holger Schurig8ff12da2007-08-02 11:54:31 -0400113 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200114 return 0;
115}
116
Holger Schurig69f90322007-11-23 15:43:44 +0100117static int lbs_cmd_802_11_sleep_params(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200118 struct cmd_ds_command *cmd,
119 u16 cmd_action)
120{
Holger Schurig69f90322007-11-23 15:43:44 +0100121 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200122 struct cmd_ds_802_11_sleep_params *sp = &cmd->params.sleep_params;
123
Holger Schurig9012b282007-05-25 11:27:16 -0400124 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200125
David Woodhouse981f1872007-05-25 23:36:54 -0400126 cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
127 S_DS_GEN);
Dan Williams0aef64d2007-08-02 11:31:18 -0400128 cmd->command = cpu_to_le16(CMD_802_11_SLEEP_PARAMS);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200129
Dan Williams0aef64d2007-08-02 11:31:18 -0400130 if (cmd_action == CMD_ACT_GET) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200131 memset(&adapter->sp, 0, sizeof(struct sleep_params));
132 memset(sp, 0, sizeof(struct cmd_ds_802_11_sleep_params));
133 sp->action = cpu_to_le16(cmd_action);
Dan Williams0aef64d2007-08-02 11:31:18 -0400134 } else if (cmd_action == CMD_ACT_SET) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200135 sp->action = cpu_to_le16(cmd_action);
136 sp->error = cpu_to_le16(adapter->sp.sp_error);
137 sp->offset = cpu_to_le16(adapter->sp.sp_offset);
138 sp->stabletime = cpu_to_le16(adapter->sp.sp_stabletime);
139 sp->calcontrol = (u8) adapter->sp.sp_calcontrol;
140 sp->externalsleepclk = (u8) adapter->sp.sp_extsleepclk;
141 sp->reserved = cpu_to_le16(adapter->sp.sp_reserved);
142 }
143
Holger Schurig9012b282007-05-25 11:27:16 -0400144 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200145 return 0;
146}
147
Holger Schurig69f90322007-11-23 15:43:44 +0100148static int lbs_cmd_802_11_set_wep(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200149 struct cmd_ds_command *cmd,
150 u32 cmd_act,
151 void * pdata_buf)
152{
153 struct cmd_ds_802_11_set_wep *wep = &cmd->params.wep;
Holger Schurig69f90322007-11-23 15:43:44 +0100154 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200155 int ret = 0;
156 struct assoc_request * assoc_req = pdata_buf;
157
Holger Schurig9012b282007-05-25 11:27:16 -0400158 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200159
Dan Williams0aef64d2007-08-02 11:31:18 -0400160 cmd->command = cpu_to_le16(CMD_802_11_SET_WEP);
David Woodhouse981f1872007-05-25 23:36:54 -0400161 cmd->size = cpu_to_le16(sizeof(*wep) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200162
Dan Williams0aef64d2007-08-02 11:31:18 -0400163 if (cmd_act == CMD_ACT_ADD) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200164 int i;
165
166 if (!assoc_req) {
Holger Schurig9012b282007-05-25 11:27:16 -0400167 lbs_deb_cmd("Invalid association request!");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200168 ret = -1;
169 goto done;
170 }
171
Dan Williams0aef64d2007-08-02 11:31:18 -0400172 wep->action = cpu_to_le16(CMD_ACT_ADD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200173
174 /* default tx key index */
David Woodhouse981f1872007-05-25 23:36:54 -0400175 wep->keyindex = cpu_to_le16((u16)(assoc_req->wep_tx_keyidx &
Dan Williams0aef64d2007-08-02 11:31:18 -0400176 (u32)CMD_WEP_KEY_INDEX_MASK));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200177
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200178 /* Copy key types and material to host command structure */
179 for (i = 0; i < 4; i++) {
Dan Williams1443b652007-08-02 10:45:55 -0400180 struct enc_key * pkey = &assoc_req->wep_keys[i];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200181
182 switch (pkey->len) {
183 case KEY_LEN_WEP_40:
Holger Schurig6470a892007-10-08 11:07:27 +0200184 wep->keytype[i] = CMD_TYPE_WEP_40_BIT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200185 memmove(&wep->keymaterial[i], pkey->key,
186 pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400187 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200188 break;
189 case KEY_LEN_WEP_104:
Holger Schurig6470a892007-10-08 11:07:27 +0200190 wep->keytype[i] = CMD_TYPE_WEP_104_BIT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200191 memmove(&wep->keymaterial[i], pkey->key,
192 pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400193 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200194 break;
195 case 0:
196 break;
197 default:
Holger Schurig8ff12da2007-08-02 11:54:31 -0400198 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200199 i, pkey->len);
200 ret = -1;
201 goto done;
202 break;
203 }
204 }
Dan Williams0aef64d2007-08-02 11:31:18 -0400205 } else if (cmd_act == CMD_ACT_REMOVE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200206 /* ACT_REMOVE clears _all_ WEP keys */
Dan Williams0aef64d2007-08-02 11:31:18 -0400207 wep->action = cpu_to_le16(CMD_ACT_REMOVE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200208
209 /* default tx key index */
David Woodhouse981f1872007-05-25 23:36:54 -0400210 wep->keyindex = cpu_to_le16((u16)(adapter->wep_tx_keyidx &
Dan Williams0aef64d2007-08-02 11:31:18 -0400211 (u32)CMD_WEP_KEY_INDEX_MASK));
Holger Schurig8ff12da2007-08-02 11:54:31 -0400212 lbs_deb_cmd("SET_WEP: remove key %d\n", adapter->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200213 }
214
215 ret = 0;
216
217done:
Holger Schurig9012b282007-05-25 11:27:16 -0400218 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200219 return ret;
220}
221
Holger Schurig69f90322007-11-23 15:43:44 +0100222static int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200223 struct cmd_ds_command *cmd,
Dan Williams90a42212007-05-25 23:01:24 -0400224 u16 cmd_action,
225 void * pdata_buf)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200226{
227 struct cmd_ds_802_11_enable_rsn *penableRSN = &cmd->params.enbrsn;
Dan Williams18c96c342007-06-18 12:01:12 -0400228 u32 * enable = pdata_buf;
Dan Williams90a42212007-05-25 23:01:24 -0400229
230 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200231
Dan Williams0aef64d2007-08-02 11:31:18 -0400232 cmd->command = cpu_to_le16(CMD_802_11_ENABLE_RSN);
David Woodhouse981f1872007-05-25 23:36:54 -0400233 cmd->size = cpu_to_le16(sizeof(*penableRSN) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234 penableRSN->action = cpu_to_le16(cmd_action);
Dan Williams18c96c342007-06-18 12:01:12 -0400235
Dan Williams0aef64d2007-08-02 11:31:18 -0400236 if (cmd_action == CMD_ACT_SET) {
Dan Williams18c96c342007-06-18 12:01:12 -0400237 if (*enable)
Dan Williams0aef64d2007-08-02 11:31:18 -0400238 penableRSN->enable = cpu_to_le16(CMD_ENABLE_RSN);
Dan Williams18c96c342007-06-18 12:01:12 -0400239 else
Dan Williams0aef64d2007-08-02 11:31:18 -0400240 penableRSN->enable = cpu_to_le16(CMD_DISABLE_RSN);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400241 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200242 }
243
Dan Williams90a42212007-05-25 23:01:24 -0400244 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200245 return 0;
246}
247
248
Holger Schurig3a188642007-11-26 10:07:14 +0100249static ssize_t lbs_tlv_size(const u8 *tlv, u16 size)
250{
251 ssize_t pos = 0;
252 struct mrvlietypesheader *tlv_h;
253 while (pos < size) {
254 u16 length;
255 tlv_h = (struct mrvlietypesheader *) tlv;
256 if (tlv_h->len == 0)
257 return pos;
258 length = le16_to_cpu(tlv_h->len) +
259 sizeof(struct mrvlietypesheader);
260 pos += length;
261 tlv += length;
262 }
263 return pos;
264}
265
266
267static void lbs_cmd_802_11_subscribe_event(struct lbs_private *priv,
268 struct cmd_ds_command *cmd, u16 cmd_action,
269 void *pdata_buf)
270{
271 struct cmd_ds_802_11_subscribe_event *events =
272 (struct cmd_ds_802_11_subscribe_event *) pdata_buf;
273
274 /* pdata_buf points to a struct cmd_ds_802_11_subscribe_event and room
275 * for various Marvell TLVs */
276
277 lbs_deb_enter(LBS_DEB_CMD);
278
279 cmd->size = cpu_to_le16(sizeof(*events)
280 - sizeof(events->tlv)
281 + S_DS_GEN);
282 cmd->params.subscribe_event.action = cpu_to_le16(cmd_action);
283 if (cmd_action == CMD_ACT_GET) {
284 cmd->params.subscribe_event.events = 0;
285 } else {
286 ssize_t sz = lbs_tlv_size(events->tlv, sizeof(events->tlv));
287 cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) + sz);
288 cmd->params.subscribe_event.events = events->events;
289 memcpy(cmd->params.subscribe_event.tlv, events->tlv, sz);
290 }
291
292 lbs_deb_leave(LBS_DEB_CMD);
293}
294
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200295static void set_one_wpa_key(struct MrvlIEtype_keyParamSet * pkeyparamset,
Dan Williams1443b652007-08-02 10:45:55 -0400296 struct enc_key * pkey)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200297{
Holger Schurig8ff12da2007-08-02 11:54:31 -0400298 lbs_deb_enter(LBS_DEB_CMD);
299
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200300 if (pkey->flags & KEY_INFO_WPA_ENABLED) {
Dan Williams90a42212007-05-25 23:01:24 -0400301 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200302 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200303 if (pkey->flags & KEY_INFO_WPA_UNICAST) {
304 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
Dan Williams90a42212007-05-25 23:01:24 -0400305 }
306 if (pkey->flags & KEY_INFO_WPA_MCAST) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200307 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
308 }
309
310 pkeyparamset->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
Dan Williams1443b652007-08-02 10:45:55 -0400311 pkeyparamset->keytypeid = cpu_to_le16(pkey->type);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200312 pkeyparamset->keylen = cpu_to_le16(pkey->len);
313 memcpy(pkeyparamset->key, pkey->key, pkey->len);
314 pkeyparamset->length = cpu_to_le16( sizeof(pkeyparamset->keytypeid)
315 + sizeof(pkeyparamset->keyinfo)
316 + sizeof(pkeyparamset->keylen)
317 + sizeof(pkeyparamset->key));
Holger Schurig8ff12da2007-08-02 11:54:31 -0400318 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200319}
320
Holger Schurig69f90322007-11-23 15:43:44 +0100321static int lbs_cmd_802_11_key_material(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200322 struct cmd_ds_command *cmd,
323 u16 cmd_action,
324 u32 cmd_oid, void *pdata_buf)
325{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200326 struct cmd_ds_802_11_key_material *pkeymaterial =
327 &cmd->params.keymaterial;
Dan Williams90a42212007-05-25 23:01:24 -0400328 struct assoc_request * assoc_req = pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200329 int ret = 0;
330 int index = 0;
331
Holger Schurig9012b282007-05-25 11:27:16 -0400332 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200333
Dan Williams0aef64d2007-08-02 11:31:18 -0400334 cmd->command = cpu_to_le16(CMD_802_11_KEY_MATERIAL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200335 pkeymaterial->action = cpu_to_le16(cmd_action);
336
Dan Williams0aef64d2007-08-02 11:31:18 -0400337 if (cmd_action == CMD_ACT_GET) {
Dan Williams90a42212007-05-25 23:01:24 -0400338 cmd->size = cpu_to_le16(S_DS_GEN + sizeof (pkeymaterial->action));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200339 ret = 0;
340 goto done;
341 }
342
343 memset(&pkeymaterial->keyParamSet, 0, sizeof(pkeymaterial->keyParamSet));
344
Dan Williams90a42212007-05-25 23:01:24 -0400345 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200346 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
Dan Williams90a42212007-05-25 23:01:24 -0400347 &assoc_req->wpa_unicast_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200348 index++;
349 }
350
Dan Williams90a42212007-05-25 23:01:24 -0400351 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200352 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
Dan Williams90a42212007-05-25 23:01:24 -0400353 &assoc_req->wpa_mcast_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200354 index++;
355 }
356
357 cmd->size = cpu_to_le16( S_DS_GEN
Dan Williams90a42212007-05-25 23:01:24 -0400358 + sizeof (pkeymaterial->action)
359 + (index * sizeof(struct MrvlIEtype_keyParamSet)));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200360
361 ret = 0;
362
363done:
Holger Schurig9012b282007-05-25 11:27:16 -0400364 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200365 return ret;
366}
367
Holger Schurig69f90322007-11-23 15:43:44 +0100368static int lbs_cmd_802_11_reset(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200369 struct cmd_ds_command *cmd, int cmd_action)
370{
371 struct cmd_ds_802_11_reset *reset = &cmd->params.reset;
372
Holger Schurig8ff12da2007-08-02 11:54:31 -0400373 lbs_deb_enter(LBS_DEB_CMD);
374
Dan Williams0aef64d2007-08-02 11:31:18 -0400375 cmd->command = cpu_to_le16(CMD_802_11_RESET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200376 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
377 reset->action = cpu_to_le16(cmd_action);
378
Holger Schurig8ff12da2007-08-02 11:54:31 -0400379 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200380 return 0;
381}
382
Holger Schurig69f90322007-11-23 15:43:44 +0100383static int lbs_cmd_802_11_get_log(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200384 struct cmd_ds_command *cmd)
385{
Holger Schurig8ff12da2007-08-02 11:54:31 -0400386 lbs_deb_enter(LBS_DEB_CMD);
Dan Williams0aef64d2007-08-02 11:31:18 -0400387 cmd->command = cpu_to_le16(CMD_802_11_GET_LOG);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200388 cmd->size =
389 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_log) + S_DS_GEN);
390
Holger Schurig8ff12da2007-08-02 11:54:31 -0400391 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200392 return 0;
393}
394
Holger Schurig69f90322007-11-23 15:43:44 +0100395static int lbs_cmd_802_11_get_stat(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200396 struct cmd_ds_command *cmd)
397{
Holger Schurig8ff12da2007-08-02 11:54:31 -0400398 lbs_deb_enter(LBS_DEB_CMD);
Dan Williams0aef64d2007-08-02 11:31:18 -0400399 cmd->command = cpu_to_le16(CMD_802_11_GET_STAT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200400 cmd->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400401 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200402
Holger Schurig8ff12da2007-08-02 11:54:31 -0400403 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200404 return 0;
405}
406
Holger Schurig69f90322007-11-23 15:43:44 +0100407static int lbs_cmd_802_11_snmp_mib(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200408 struct cmd_ds_command *cmd,
409 int cmd_action,
410 int cmd_oid, void *pdata_buf)
411{
412 struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib;
Holger Schurig69f90322007-11-23 15:43:44 +0100413 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200414 u8 ucTemp;
415
Holger Schurig9012b282007-05-25 11:27:16 -0400416 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200417
Holger Schurig9012b282007-05-25 11:27:16 -0400418 lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200419
Dan Williams0aef64d2007-08-02 11:31:18 -0400420 cmd->command = cpu_to_le16(CMD_802_11_SNMP_MIB);
David Woodhouse981f1872007-05-25 23:36:54 -0400421 cmd->size = cpu_to_le16(sizeof(*pSNMPMIB) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200422
423 switch (cmd_oid) {
424 case OID_802_11_INFRASTRUCTURE_MODE:
425 {
Dan Williams0dc5a292007-05-10 22:58:02 -0400426 u8 mode = (u8) (size_t) pdata_buf;
Dan Williams0aef64d2007-08-02 11:31:18 -0400427 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
428 pSNMPMIB->oid = cpu_to_le16((u16) DESIRED_BSSTYPE_I);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200429 pSNMPMIB->bufsize = sizeof(u8);
Dan Williams0dc5a292007-05-10 22:58:02 -0400430 if (mode == IW_MODE_ADHOC) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200431 ucTemp = SNMP_MIB_VALUE_ADHOC;
Dan Williams0dc5a292007-05-10 22:58:02 -0400432 } else {
433 /* Infra and Auto modes */
434 ucTemp = SNMP_MIB_VALUE_INFRA;
435 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200436
437 memmove(pSNMPMIB->value, &ucTemp, sizeof(u8));
438
439 break;
440 }
441
442 case OID_802_11D_ENABLE:
443 {
444 u32 ulTemp;
445
Dan Williams0aef64d2007-08-02 11:31:18 -0400446 pSNMPMIB->oid = cpu_to_le16((u16) DOT11D_I);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200447
Dan Williams0aef64d2007-08-02 11:31:18 -0400448 if (cmd_action == CMD_ACT_SET) {
449 pSNMPMIB->querytype = CMD_ACT_SET;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200450 pSNMPMIB->bufsize = sizeof(u16);
451 ulTemp = *(u32 *)pdata_buf;
David Woodhouse981f1872007-05-25 23:36:54 -0400452 *((__le16 *)(pSNMPMIB->value)) =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200453 cpu_to_le16((u16) ulTemp);
454 }
455 break;
456 }
457
458 case OID_802_11_FRAGMENTATION_THRESHOLD:
459 {
460 u32 ulTemp;
461
Dan Williams0aef64d2007-08-02 11:31:18 -0400462 pSNMPMIB->oid = cpu_to_le16((u16) FRAGTHRESH_I);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200463
Dan Williams0aef64d2007-08-02 11:31:18 -0400464 if (cmd_action == CMD_ACT_GET) {
465 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
466 } else if (cmd_action == CMD_ACT_SET) {
467 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
David Woodhouse981f1872007-05-25 23:36:54 -0400468 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200469 ulTemp = *((u32 *) pdata_buf);
David Woodhouse981f1872007-05-25 23:36:54 -0400470 *((__le16 *)(pSNMPMIB->value)) =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200471 cpu_to_le16((u16) ulTemp);
472
473 }
474
475 break;
476 }
477
478 case OID_802_11_RTS_THRESHOLD:
479 {
480
481 u32 ulTemp;
Dan Williams0aef64d2007-08-02 11:31:18 -0400482 pSNMPMIB->oid = le16_to_cpu((u16) RTSTHRESH_I);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200483
Dan Williams0aef64d2007-08-02 11:31:18 -0400484 if (cmd_action == CMD_ACT_GET) {
485 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
486 } else if (cmd_action == CMD_ACT_SET) {
487 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
David Woodhouse981f1872007-05-25 23:36:54 -0400488 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
489 ulTemp = *((u32 *)pdata_buf);
490 *(__le16 *)(pSNMPMIB->value) =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200491 cpu_to_le16((u16) ulTemp);
492
493 }
494 break;
495 }
496 case OID_802_11_TX_RETRYCOUNT:
Dan Williams0aef64d2007-08-02 11:31:18 -0400497 pSNMPMIB->oid = cpu_to_le16((u16) SHORT_RETRYLIM_I);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200498
Dan Williams0aef64d2007-08-02 11:31:18 -0400499 if (cmd_action == CMD_ACT_GET) {
500 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
501 } else if (cmd_action == CMD_ACT_SET) {
502 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200503 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
David Woodhouse981f1872007-05-25 23:36:54 -0400504 *((__le16 *)(pSNMPMIB->value)) =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200505 cpu_to_le16((u16) adapter->txretrycount);
506 }
507
508 break;
509 default:
510 break;
511 }
512
Holger Schurig9012b282007-05-25 11:27:16 -0400513 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200514 "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400515 le16_to_cpu(cmd->command), le16_to_cpu(cmd->size),
516 le16_to_cpu(cmd->seqnum), le16_to_cpu(cmd->result));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200517
Holger Schurig9012b282007-05-25 11:27:16 -0400518 lbs_deb_cmd(
Holger Schurig8ff12da2007-08-02 11:54:31 -0400519 "SNMP_CMD: action 0x%x, oid 0x%x, oidsize 0x%x, value 0x%x\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400520 le16_to_cpu(pSNMPMIB->querytype), le16_to_cpu(pSNMPMIB->oid),
521 le16_to_cpu(pSNMPMIB->bufsize),
522 le16_to_cpu(*(__le16 *) pSNMPMIB->value));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200523
Holger Schurig9012b282007-05-25 11:27:16 -0400524 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200525 return 0;
526}
527
Holger Schurig69f90322007-11-23 15:43:44 +0100528static int lbs_cmd_802_11_radio_control(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200529 struct cmd_ds_command *cmd,
530 int cmd_action)
531{
Holger Schurig69f90322007-11-23 15:43:44 +0100532 struct lbs_adapter *adapter = priv->adapter;
David Woodhouse981f1872007-05-25 23:36:54 -0400533 struct cmd_ds_802_11_radio_control *pradiocontrol = &cmd->params.radio;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200534
Holger Schurig9012b282007-05-25 11:27:16 -0400535 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200536
537 cmd->size =
538 cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control)) +
539 S_DS_GEN);
Dan Williams0aef64d2007-08-02 11:31:18 -0400540 cmd->command = cpu_to_le16(CMD_802_11_RADIO_CONTROL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200541
542 pradiocontrol->action = cpu_to_le16(cmd_action);
543
544 switch (adapter->preamble) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400545 case CMD_TYPE_SHORT_PREAMBLE:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200546 pradiocontrol->control = cpu_to_le16(SET_SHORT_PREAMBLE);
547 break;
548
Dan Williams0aef64d2007-08-02 11:31:18 -0400549 case CMD_TYPE_LONG_PREAMBLE:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200550 pradiocontrol->control = cpu_to_le16(SET_LONG_PREAMBLE);
551 break;
552
Dan Williams0aef64d2007-08-02 11:31:18 -0400553 case CMD_TYPE_AUTO_PREAMBLE:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200554 default:
555 pradiocontrol->control = cpu_to_le16(SET_AUTO_PREAMBLE);
556 break;
557 }
558
559 if (adapter->radioon)
560 pradiocontrol->control |= cpu_to_le16(TURN_ON_RF);
561 else
562 pradiocontrol->control &= cpu_to_le16(~TURN_ON_RF);
563
Holger Schurig9012b282007-05-25 11:27:16 -0400564 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200565 return 0;
566}
567
Holger Schurig69f90322007-11-23 15:43:44 +0100568static int lbs_cmd_802_11_rf_tx_power(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200569 struct cmd_ds_command *cmd,
570 u16 cmd_action, void *pdata_buf)
571{
572
573 struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
574
Holger Schurig9012b282007-05-25 11:27:16 -0400575 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200576
577 cmd->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400578 cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN);
Dan Williams0aef64d2007-08-02 11:31:18 -0400579 cmd->command = cpu_to_le16(CMD_802_11_RF_TX_POWER);
David Woodhouse981f1872007-05-25 23:36:54 -0400580 prtp->action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200581
David Woodhouse981f1872007-05-25 23:36:54 -0400582 lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
583 le16_to_cpu(cmd->size), le16_to_cpu(cmd->command),
584 le16_to_cpu(prtp->action));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200585
586 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400587 case CMD_ACT_TX_POWER_OPT_GET:
588 prtp->action = cpu_to_le16(CMD_ACT_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200589 prtp->currentlevel = 0;
590 break;
591
Dan Williams0aef64d2007-08-02 11:31:18 -0400592 case CMD_ACT_TX_POWER_OPT_SET_HIGH:
593 prtp->action = cpu_to_le16(CMD_ACT_SET);
594 prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_HIGH);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200595 break;
596
Dan Williams0aef64d2007-08-02 11:31:18 -0400597 case CMD_ACT_TX_POWER_OPT_SET_MID:
598 prtp->action = cpu_to_le16(CMD_ACT_SET);
599 prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_MID);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200600 break;
601
Dan Williams0aef64d2007-08-02 11:31:18 -0400602 case CMD_ACT_TX_POWER_OPT_SET_LOW:
603 prtp->action = cpu_to_le16(CMD_ACT_SET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200604 prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
605 break;
606 }
Holger Schurig9012b282007-05-25 11:27:16 -0400607
608 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200609 return 0;
610}
611
Holger Schurig69f90322007-11-23 15:43:44 +0100612static int lbs_cmd_802_11_monitor_mode(struct lbs_private *priv,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400613 struct cmd_ds_command *cmd,
614 u16 cmd_action, void *pdata_buf)
615{
616 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
617
618 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
619 cmd->size =
620 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
621 S_DS_GEN);
622
623 monitor->action = cpu_to_le16(cmd_action);
624 if (cmd_action == CMD_ACT_SET) {
625 monitor->mode =
626 cpu_to_le16((u16) (*(u32 *) pdata_buf));
627 }
628
629 return 0;
630}
631
Holger Schurig69f90322007-11-23 15:43:44 +0100632static int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200633 struct cmd_ds_command *cmd,
634 u16 cmd_action)
635{
636 struct cmd_ds_802_11_rate_adapt_rateset
637 *rateadapt = &cmd->params.rateset;
Holger Schurig69f90322007-11-23 15:43:44 +0100638 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200639
Holger Schurig8ff12da2007-08-02 11:54:31 -0400640 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200641 cmd->size =
642 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
643 + S_DS_GEN);
Dan Williams0aef64d2007-08-02 11:31:18 -0400644 cmd->command = cpu_to_le16(CMD_802_11_RATE_ADAPT_RATESET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200645
David Woodhouse981f1872007-05-25 23:36:54 -0400646 rateadapt->action = cpu_to_le16(cmd_action);
647 rateadapt->enablehwauto = cpu_to_le16(adapter->enablehwauto);
648 rateadapt->bitmap = cpu_to_le16(adapter->ratebitmap);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200649
Holger Schurig9012b282007-05-25 11:27:16 -0400650 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200651 return 0;
652}
653
Holger Schurig69f90322007-11-23 15:43:44 +0100654static int lbs_cmd_802_11_data_rate(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200655 struct cmd_ds_command *cmd,
656 u16 cmd_action)
657{
658 struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
Holger Schurig69f90322007-11-23 15:43:44 +0100659 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200660
Holger Schurig9012b282007-05-25 11:27:16 -0400661 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200662
David Woodhouse981f1872007-05-25 23:36:54 -0400663 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200664 S_DS_GEN);
Dan Williams0aef64d2007-08-02 11:31:18 -0400665 cmd->command = cpu_to_le16(CMD_802_11_DATA_RATE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200666 memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200667 pdatarate->action = cpu_to_le16(cmd_action);
668
Dan Williamsffcae952007-08-02 11:35:46 -0400669 if (cmd_action == CMD_ACT_SET_TX_FIX_RATE) {
Holger Schurig10078322007-11-15 18:05:47 -0500670 pdatarate->rates[0] = lbs_data_rate_to_fw_index(adapter->cur_rate);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400671 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n",
Dan Williams8c512762007-08-02 11:40:45 -0400672 adapter->cur_rate);
Dan Williamsffcae952007-08-02 11:35:46 -0400673 } else if (cmd_action == CMD_ACT_SET_TX_AUTO) {
Holger Schurig8ff12da2007-08-02 11:54:31 -0400674 lbs_deb_cmd("DATA_RATE: setting auto\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200675 }
676
Holger Schurig9012b282007-05-25 11:27:16 -0400677 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200678 return 0;
679}
680
Holger Schurig69f90322007-11-23 15:43:44 +0100681static int lbs_cmd_mac_multicast_adr(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200682 struct cmd_ds_command *cmd,
683 u16 cmd_action)
684{
685 struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
Holger Schurig69f90322007-11-23 15:43:44 +0100686 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200687
Holger Schurig8ff12da2007-08-02 11:54:31 -0400688 lbs_deb_enter(LBS_DEB_CMD);
David Woodhouse981f1872007-05-25 23:36:54 -0400689 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200690 S_DS_GEN);
Dan Williams0aef64d2007-08-02 11:31:18 -0400691 cmd->command = cpu_to_le16(CMD_MAC_MULTICAST_ADR);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200692
Holger Schurig8ff12da2007-08-02 11:54:31 -0400693 lbs_deb_cmd("MULTICAST_ADR: setting %d addresses\n", pMCastAdr->nr_of_adrs);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200694 pMCastAdr->action = cpu_to_le16(cmd_action);
695 pMCastAdr->nr_of_adrs =
696 cpu_to_le16((u16) adapter->nr_of_multicastmacaddr);
697 memcpy(pMCastAdr->maclist, adapter->multicastlist,
698 adapter->nr_of_multicastmacaddr * ETH_ALEN);
699
Holger Schurig8ff12da2007-08-02 11:54:31 -0400700 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200701 return 0;
702}
703
Holger Schurig69f90322007-11-23 15:43:44 +0100704static int lbs_cmd_802_11_rf_channel(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200705 struct cmd_ds_command *cmd,
706 int option, void *pdata_buf)
707{
708 struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel;
709
Holger Schurig8ff12da2007-08-02 11:54:31 -0400710 lbs_deb_enter(LBS_DEB_CMD);
Dan Williams0aef64d2007-08-02 11:31:18 -0400711 cmd->command = cpu_to_le16(CMD_802_11_RF_CHANNEL);
David Woodhouse981f1872007-05-25 23:36:54 -0400712 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel) +
713 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200714
Dan Williams0aef64d2007-08-02 11:31:18 -0400715 if (option == CMD_OPT_802_11_RF_CHANNEL_SET) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200716 rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf));
717 }
718
719 rfchan->action = cpu_to_le16(option);
720
Holger Schurig8ff12da2007-08-02 11:54:31 -0400721 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200722 return 0;
723}
724
Holger Schurig69f90322007-11-23 15:43:44 +0100725static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200726 struct cmd_ds_command *cmd)
727{
Holger Schurig69f90322007-11-23 15:43:44 +0100728 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200729
Holger Schurig8ff12da2007-08-02 11:54:31 -0400730 lbs_deb_enter(LBS_DEB_CMD);
Dan Williams0aef64d2007-08-02 11:31:18 -0400731 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
David Woodhouse981f1872007-05-25 23:36:54 -0400732 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
Holger Schuriga783f1e2007-08-02 13:08:24 -0400733 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200734
735 /* reset Beacon SNR/NF/RSSI values */
736 adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
737 adapter->SNR[TYPE_BEACON][TYPE_AVG] = 0;
738 adapter->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
739 adapter->NF[TYPE_BEACON][TYPE_AVG] = 0;
740 adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
741 adapter->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
742
Holger Schurig8ff12da2007-08-02 11:54:31 -0400743 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200744 return 0;
745}
746
Holger Schurig69f90322007-11-23 15:43:44 +0100747static int lbs_cmd_reg_access(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200748 struct cmd_ds_command *cmdptr,
749 u8 cmd_action, void *pdata_buf)
750{
Holger Schurig10078322007-11-15 18:05:47 -0500751 struct lbs_offset_value *offval;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200752
Holger Schurig9012b282007-05-25 11:27:16 -0400753 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200754
Holger Schurig10078322007-11-15 18:05:47 -0500755 offval = (struct lbs_offset_value *)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200756
757 switch (cmdptr->command) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400758 case CMD_MAC_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200759 {
760 struct cmd_ds_mac_reg_access *macreg;
761
762 cmdptr->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400763 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
764 + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200765 macreg =
766 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
767 macreg;
768
769 macreg->action = cpu_to_le16(cmd_action);
770 macreg->offset = cpu_to_le16((u16) offval->offset);
771 macreg->value = cpu_to_le32(offval->value);
772
773 break;
774 }
775
Dan Williams0aef64d2007-08-02 11:31:18 -0400776 case CMD_BBP_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200777 {
778 struct cmd_ds_bbp_reg_access *bbpreg;
779
780 cmdptr->size =
781 cpu_to_le16(sizeof
782 (struct cmd_ds_bbp_reg_access)
783 + S_DS_GEN);
784 bbpreg =
785 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
786 bbpreg;
787
788 bbpreg->action = cpu_to_le16(cmd_action);
789 bbpreg->offset = cpu_to_le16((u16) offval->offset);
790 bbpreg->value = (u8) offval->value;
791
792 break;
793 }
794
Dan Williams0aef64d2007-08-02 11:31:18 -0400795 case CMD_RF_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200796 {
797 struct cmd_ds_rf_reg_access *rfreg;
798
799 cmdptr->size =
800 cpu_to_le16(sizeof
801 (struct cmd_ds_rf_reg_access) +
802 S_DS_GEN);
803 rfreg =
804 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
805 rfreg;
806
807 rfreg->action = cpu_to_le16(cmd_action);
808 rfreg->offset = cpu_to_le16((u16) offval->offset);
809 rfreg->value = (u8) offval->value;
810
811 break;
812 }
813
814 default:
815 break;
816 }
817
Holger Schurig9012b282007-05-25 11:27:16 -0400818 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200819 return 0;
820}
821
Holger Schurig69f90322007-11-23 15:43:44 +0100822static int lbs_cmd_802_11_mac_address(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200823 struct cmd_ds_command *cmd,
824 u16 cmd_action)
825{
Holger Schurig69f90322007-11-23 15:43:44 +0100826 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200827
Holger Schurig8ff12da2007-08-02 11:54:31 -0400828 lbs_deb_enter(LBS_DEB_CMD);
Dan Williams0aef64d2007-08-02 11:31:18 -0400829 cmd->command = cpu_to_le16(CMD_802_11_MAC_ADDRESS);
David Woodhouse981f1872007-05-25 23:36:54 -0400830 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200831 S_DS_GEN);
832 cmd->result = 0;
833
834 cmd->params.macadd.action = cpu_to_le16(cmd_action);
835
Dan Williams0aef64d2007-08-02 11:31:18 -0400836 if (cmd_action == CMD_ACT_SET) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200837 memcpy(cmd->params.macadd.macadd,
838 adapter->current_addr, ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400839 lbs_deb_hex(LBS_DEB_CMD, "SET_CMD: MAC addr", adapter->current_addr, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200840 }
841
Holger Schurig8ff12da2007-08-02 11:54:31 -0400842 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200843 return 0;
844}
845
Holger Schurig69f90322007-11-23 15:43:44 +0100846static int lbs_cmd_802_11_eeprom_access(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200847 struct cmd_ds_command *cmd,
848 int cmd_action, void *pdata_buf)
849{
Holger Schurig10078322007-11-15 18:05:47 -0500850 struct lbs_ioctl_regrdwr *ea = pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200851
Holger Schurig9012b282007-05-25 11:27:16 -0400852 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200853
Dan Williams0aef64d2007-08-02 11:31:18 -0400854 cmd->command = cpu_to_le16(CMD_802_11_EEPROM_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -0400855 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
856 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200857 cmd->result = 0;
858
859 cmd->params.rdeeprom.action = cpu_to_le16(ea->action);
860 cmd->params.rdeeprom.offset = cpu_to_le16(ea->offset);
861 cmd->params.rdeeprom.bytecount = cpu_to_le16(ea->NOB);
862 cmd->params.rdeeprom.value = 0;
863
Holger Schurig8ff12da2007-08-02 11:54:31 -0400864 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200865 return 0;
866}
867
Holger Schurig69f90322007-11-23 15:43:44 +0100868static int lbs_cmd_bt_access(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200869 struct cmd_ds_command *cmd,
870 u16 cmd_action, void *pdata_buf)
871{
872 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
Holger Schurig8ff12da2007-08-02 11:54:31 -0400873 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200874
Dan Williams0aef64d2007-08-02 11:31:18 -0400875 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -0400876 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200877 cmd->result = 0;
878 bt_access->action = cpu_to_le16(cmd_action);
879
880 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400881 case CMD_ACT_BT_ACCESS_ADD:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200882 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400883 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200884 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400885 case CMD_ACT_BT_ACCESS_DEL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200886 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400887 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200888 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400889 case CMD_ACT_BT_ACCESS_LIST:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200890 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
891 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400892 case CMD_ACT_BT_ACCESS_RESET:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200893 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400894 case CMD_ACT_BT_ACCESS_SET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -0400895 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
896 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400897 case CMD_ACT_BT_ACCESS_GET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -0400898 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200899 default:
900 break;
901 }
Holger Schurig8ff12da2007-08-02 11:54:31 -0400902 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200903 return 0;
904}
905
Holger Schurig69f90322007-11-23 15:43:44 +0100906static int lbs_cmd_fwt_access(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200907 struct cmd_ds_command *cmd,
908 u16 cmd_action, void *pdata_buf)
909{
910 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
Holger Schurig8ff12da2007-08-02 11:54:31 -0400911 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200912
Dan Williams0aef64d2007-08-02 11:31:18 -0400913 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -0400914 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200915 cmd->result = 0;
916
917 if (pdata_buf)
918 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
919 else
920 memset(fwt_access, 0, sizeof(*fwt_access));
921
922 fwt_access->action = cpu_to_le16(cmd_action);
923
Holger Schurig8ff12da2007-08-02 11:54:31 -0400924 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200925 return 0;
926}
927
Holger Schurig69f90322007-11-23 15:43:44 +0100928static int lbs_cmd_mesh_access(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200929 struct cmd_ds_command *cmd,
930 u16 cmd_action, void *pdata_buf)
931{
932 struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
Holger Schurig8ff12da2007-08-02 11:54:31 -0400933 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200934
Dan Williams0aef64d2007-08-02 11:31:18 -0400935 cmd->command = cpu_to_le16(CMD_MESH_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -0400936 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200937 cmd->result = 0;
938
939 if (pdata_buf)
940 memcpy(mesh_access, pdata_buf, sizeof(*mesh_access));
941 else
942 memset(mesh_access, 0, sizeof(*mesh_access));
943
944 mesh_access->action = cpu_to_le16(cmd_action);
945
Holger Schurig8ff12da2007-08-02 11:54:31 -0400946 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200947 return 0;
948}
949
Brajesh Dave96287ac2007-11-20 17:44:28 -0500950static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
951 struct cmd_ds_command *cmd,
952 u16 cmd_action)
953{
954 struct cmd_ds_802_11_beacon_control
955 *bcn_ctrl = &cmd->params.bcn_ctrl;
956 struct lbs_adapter *adapter = priv->adapter;
957
958 lbs_deb_enter(LBS_DEB_CMD);
959 cmd->size =
960 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
961 + S_DS_GEN);
962 cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
963
964 bcn_ctrl->action = cpu_to_le16(cmd_action);
965 bcn_ctrl->beacon_enable = cpu_to_le16(adapter->beacon_enable);
966 bcn_ctrl->beacon_period = cpu_to_le16(adapter->beacon_period);
967
968 lbs_deb_leave(LBS_DEB_CMD);
969 return 0;
970}
971
Holger Schurig69f90322007-11-23 15:43:44 +0100972static int lbs_cmd_set_boot2_ver(struct lbs_private *priv,
Luis Carlos Cobo63f00232007-08-02 13:19:24 -0400973 struct cmd_ds_command *cmd,
974 u16 cmd_action, void *pdata_buf)
975{
976 struct cmd_ds_set_boot2_ver *boot2_ver = &cmd->params.boot2_ver;
977 cmd->command = cpu_to_le16(CMD_SET_BOOT2_VER);
978 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_set_boot2_ver) + S_DS_GEN);
979 boot2_ver->version = priv->boot2_version;
980 return 0;
981}
982
Marcelo Tosatti29f5f2a2007-10-30 10:52:46 -0400983/*
Holger Schurig10078322007-11-15 18:05:47 -0500984 * Note: NEVER use lbs_queue_cmd() with addtail==0 other than for
Marcelo Tosatti29f5f2a2007-10-30 10:52:46 -0400985 * the command timer, because it does not account for queued commands.
986 */
Holger Schurig69f90322007-11-23 15:43:44 +0100987void lbs_queue_cmd(struct lbs_adapter *adapter,
988 struct cmd_ctrl_node *cmdnode,
989 u8 addtail)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200990{
991 unsigned long flags;
992 struct cmd_ds_command *cmdptr;
993
Holger Schurig8ff12da2007-08-02 11:54:31 -0400994 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200995
996 if (!cmdnode) {
Holger Schurig8ff12da2007-08-02 11:54:31 -0400997 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200998 goto done;
999 }
1000
1001 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1002 if (!cmdptr) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001003 lbs_deb_host("QUEUE_CMD: cmdptr is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001004 goto done;
1005 }
1006
1007 /* Exit_PS command needs to be queued in the header always. */
Dan Williams0aef64d2007-08-02 11:31:18 -04001008 if (cmdptr->command == CMD_802_11_PS_MODE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001009 struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
Dan Williams0aef64d2007-08-02 11:31:18 -04001010 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001011 if (adapter->psstate != PS_STATE_FULL_POWER)
1012 addtail = 0;
1013 }
1014 }
1015
1016 spin_lock_irqsave(&adapter->driver_lock, flags);
1017
Marcelo Tosatti29f5f2a2007-10-30 10:52:46 -04001018 if (addtail) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001019 list_add_tail((struct list_head *)cmdnode,
1020 &adapter->cmdpendingq);
Marcelo Tosatti29f5f2a2007-10-30 10:52:46 -04001021 adapter->nr_cmd_pending++;
1022 } else
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001023 list_add((struct list_head *)cmdnode, &adapter->cmdpendingq);
1024
1025 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1026
Holger Schurig8ff12da2007-08-02 11:54:31 -04001027 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
David Woodhouse981f1872007-05-25 23:36:54 -04001028 le16_to_cpu(((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001029
1030done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001031 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001032}
1033
1034/*
1035 * TODO: Fix the issue when DownloadcommandToStation is being called the
Holger Schurig8ff12da2007-08-02 11:54:31 -04001036 * second time when the command times out. All the cmdptr->xxx are in little
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001037 * endian and therefore all the comparissions will fail.
1038 * For now - we are not performing the endian conversion the second time - but
1039 * for PS and DEEP_SLEEP we need to worry
1040 */
Holger Schurig69f90322007-11-23 15:43:44 +01001041static int DownloadcommandToStation(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001042 struct cmd_ctrl_node *cmdnode)
1043{
1044 unsigned long flags;
1045 struct cmd_ds_command *cmdptr;
Holger Schurig69f90322007-11-23 15:43:44 +01001046 struct lbs_adapter *adapter = priv->adapter;
Eugene Teob031ac12007-08-02 13:18:07 -04001047 int ret = -1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001048 u16 cmdsize;
1049 u16 command;
1050
Holger Schurig8ff12da2007-08-02 11:54:31 -04001051 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001052
1053 if (!adapter || !cmdnode) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001054 lbs_deb_host("DNLD_CMD: adapter or cmdmode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001055 goto done;
1056 }
1057
1058 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1059
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001060 spin_lock_irqsave(&adapter->driver_lock, flags);
1061 if (!cmdptr || !cmdptr->size) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001062 lbs_deb_host("DNLD_CMD: cmdptr is NULL or zero\n");
Holger Schurig10078322007-11-15 18:05:47 -05001063 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001064 spin_unlock_irqrestore(&adapter->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001065 goto done;
1066 }
1067
1068 adapter->cur_cmd = cmdnode;
1069 adapter->cur_cmd_retcode = 0;
1070 spin_unlock_irqrestore(&adapter->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001071
1072 cmdsize = cmdptr->size;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001073 command = cpu_to_le16(cmdptr->command);
1074
Holger Schurig8ff12da2007-08-02 11:54:31 -04001075 lbs_deb_host("DNLD_CMD: command 0x%04x, size %d, jiffies %lu\n",
1076 command, le16_to_cpu(cmdptr->size), jiffies);
1077 lbs_deb_hex(LBS_DEB_HOST, "DNLD_CMD", cmdnode->bufvirtualaddr, cmdsize);
1078
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001079 cmdnode->cmdwaitqwoken = 0;
1080 cmdsize = cpu_to_le16(cmdsize);
1081
Holger Schurig208fdd22007-05-25 12:17:06 -04001082 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001083
1084 if (ret != 0) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001085 lbs_deb_host("DNLD_CMD: hw_host_to_card failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001086 spin_lock_irqsave(&adapter->driver_lock, flags);
Pierre Ossman794760f2007-08-20 12:24:42 -04001087 adapter->cur_cmd_retcode = ret;
Holger Schurig10078322007-11-15 18:05:47 -05001088 __lbs_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
Pierre Ossman794760f2007-08-20 12:24:42 -04001089 adapter->nr_cmd_pending--;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001090 adapter->cur_cmd = NULL;
1091 spin_unlock_irqrestore(&adapter->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001092 goto done;
1093 }
1094
Holger Schurig8ff12da2007-08-02 11:54:31 -04001095 lbs_deb_cmd("DNLD_CMD: sent command 0x%04x, jiffies %lu\n", command, jiffies);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001096
1097 /* Setup the timer after transmit command */
Dan Williams0aef64d2007-08-02 11:31:18 -04001098 if (command == CMD_802_11_SCAN || command == CMD_802_11_AUTHENTICATE
1099 || command == CMD_802_11_ASSOCIATE)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001100 mod_timer(&adapter->command_timer, jiffies + (10*HZ));
1101 else
1102 mod_timer(&adapter->command_timer, jiffies + (5*HZ));
1103
1104 ret = 0;
1105
Holger Schurig9012b282007-05-25 11:27:16 -04001106done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001107 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001108 return ret;
1109}
1110
Holger Schurig69f90322007-11-23 15:43:44 +01001111static int lbs_cmd_mac_control(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001112 struct cmd_ds_command *cmd)
1113{
1114 struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
1115
Holger Schurig9012b282007-05-25 11:27:16 -04001116 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001117
Dan Williams0aef64d2007-08-02 11:31:18 -04001118 cmd->command = cpu_to_le16(CMD_MAC_CONTROL);
David Woodhouse981f1872007-05-25 23:36:54 -04001119 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001120 mac->action = cpu_to_le16(priv->adapter->currentpacketfilter);
1121
Holger Schurig8ff12da2007-08-02 11:54:31 -04001122 lbs_deb_cmd("MAC_CONTROL: action 0x%x, size %d\n",
David Woodhouse981f1872007-05-25 23:36:54 -04001123 le16_to_cpu(mac->action), le16_to_cpu(cmd->size));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001124
Holger Schurig9012b282007-05-25 11:27:16 -04001125 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001126 return 0;
1127}
1128
1129/**
1130 * This function inserts command node to cmdfreeq
1131 * after cleans it. Requires adapter->driver_lock held.
1132 */
Holger Schurig69f90322007-11-23 15:43:44 +01001133void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1134 struct cmd_ctrl_node *ptempcmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001135{
Holger Schurig69f90322007-11-23 15:43:44 +01001136 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001137
1138 if (!ptempcmd)
Holger Schurig8ff12da2007-08-02 11:54:31 -04001139 return;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001140
1141 cleanup_cmdnode(ptempcmd);
1142 list_add_tail((struct list_head *)ptempcmd, &adapter->cmdfreeq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001143}
1144
Holger Schurig69f90322007-11-23 15:43:44 +01001145static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1146 struct cmd_ctrl_node *ptempcmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001147{
1148 unsigned long flags;
1149
1150 spin_lock_irqsave(&priv->adapter->driver_lock, flags);
Holger Schurig10078322007-11-15 18:05:47 -05001151 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001152 spin_unlock_irqrestore(&priv->adapter->driver_lock, flags);
1153}
1154
Holger Schurig69f90322007-11-23 15:43:44 +01001155int lbs_set_radio_control(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001156{
1157 int ret = 0;
1158
Holger Schurig9012b282007-05-25 11:27:16 -04001159 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001160
Holger Schurig10078322007-11-15 18:05:47 -05001161 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -04001162 CMD_802_11_RADIO_CONTROL,
1163 CMD_ACT_SET,
1164 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001165
Holger Schurig8ff12da2007-08-02 11:54:31 -04001166 lbs_deb_cmd("RADIO_SET: radio %d, preamble %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001167 priv->adapter->radioon, priv->adapter->preamble);
1168
Holger Schurig9012b282007-05-25 11:27:16 -04001169 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001170 return ret;
1171}
1172
Holger Schurig69f90322007-11-23 15:43:44 +01001173int lbs_set_mac_packet_filter(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001174{
1175 int ret = 0;
1176
Holger Schurig9012b282007-05-25 11:27:16 -04001177 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001178
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001179 /* Send MAC control command to station */
Holger Schurig10078322007-11-15 18:05:47 -05001180 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -04001181 CMD_MAC_CONTROL, 0, 0, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001182
Holger Schurig9012b282007-05-25 11:27:16 -04001183 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001184 return ret;
1185}
1186
1187/**
1188 * @brief This function prepare the command before send to firmware.
1189 *
Holger Schurig69f90322007-11-23 15:43:44 +01001190 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001191 * @param cmd_no command number
1192 * @param cmd_action command action: GET or SET
1193 * @param wait_option wait option: wait response or not
1194 * @param cmd_oid cmd oid: treated as sub command
1195 * @param pdata_buf A pointer to informaion buffer
1196 * @return 0 or -1
1197 */
Holger Schurig69f90322007-11-23 15:43:44 +01001198int lbs_prepare_and_send_command(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001199 u16 cmd_no,
1200 u16 cmd_action,
1201 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1202{
1203 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001204 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001205 struct cmd_ctrl_node *cmdnode;
1206 struct cmd_ds_command *cmdptr;
1207 unsigned long flags;
1208
Holger Schurig8ff12da2007-08-02 11:54:31 -04001209 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001210
1211 if (!adapter) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001212 lbs_deb_host("PREP_CMD: adapter is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001213 ret = -1;
1214 goto done;
1215 }
1216
1217 if (adapter->surpriseremoved) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001218 lbs_deb_host("PREP_CMD: card removed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001219 ret = -1;
1220 goto done;
1221 }
1222
Holger Schurig10078322007-11-15 18:05:47 -05001223 cmdnode = lbs_get_free_cmd_ctrl_node(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001224
1225 if (cmdnode == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001226 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001227
1228 /* Wake up main thread to execute next command */
Dan Williamsfe336152007-08-02 11:32:25 -04001229 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001230 ret = -1;
1231 goto done;
1232 }
1233
David Woodhousef5ece8f2007-12-01 15:15:41 +00001234 lbs_set_cmd_ctrl_node(priv, cmdnode, wait_option, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001235
1236 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1237
Holger Schurig8ff12da2007-08-02 11:54:31 -04001238 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001239
1240 if (!cmdptr) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001241 lbs_deb_host("PREP_CMD: cmdptr is NULL\n");
Holger Schurig10078322007-11-15 18:05:47 -05001242 lbs_cleanup_and_insert_cmd(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001243 ret = -1;
1244 goto done;
1245 }
1246
1247 /* Set sequence number, command and INT option */
1248 adapter->seqnum++;
1249 cmdptr->seqnum = cpu_to_le16(adapter->seqnum);
1250
David Woodhouse981f1872007-05-25 23:36:54 -04001251 cmdptr->command = cpu_to_le16(cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001252 cmdptr->result = 0;
1253
1254 switch (cmd_no) {
Dan Williams0aef64d2007-08-02 11:31:18 -04001255 case CMD_GET_HW_SPEC:
Holger Schurig10078322007-11-15 18:05:47 -05001256 ret = lbs_cmd_hw_spec(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001257 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001258 case CMD_802_11_PS_MODE:
Holger Schurig10078322007-11-15 18:05:47 -05001259 ret = lbs_cmd_802_11_ps_mode(priv, cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001260 break;
1261
Dan Williams0aef64d2007-08-02 11:31:18 -04001262 case CMD_802_11_SCAN:
Holger Schurig10078322007-11-15 18:05:47 -05001263 ret = lbs_cmd_80211_scan(priv, cmdptr, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001264 break;
1265
Dan Williams0aef64d2007-08-02 11:31:18 -04001266 case CMD_MAC_CONTROL:
Holger Schurig10078322007-11-15 18:05:47 -05001267 ret = lbs_cmd_mac_control(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001268 break;
1269
Dan Williams0aef64d2007-08-02 11:31:18 -04001270 case CMD_802_11_ASSOCIATE:
1271 case CMD_802_11_REASSOCIATE:
Holger Schurig10078322007-11-15 18:05:47 -05001272 ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001273 break;
1274
Dan Williams0aef64d2007-08-02 11:31:18 -04001275 case CMD_802_11_DEAUTHENTICATE:
Holger Schurig10078322007-11-15 18:05:47 -05001276 ret = lbs_cmd_80211_deauthenticate(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001277 break;
1278
Dan Williams0aef64d2007-08-02 11:31:18 -04001279 case CMD_802_11_SET_WEP:
Holger Schurig10078322007-11-15 18:05:47 -05001280 ret = lbs_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001281 break;
1282
Dan Williams0aef64d2007-08-02 11:31:18 -04001283 case CMD_802_11_AD_HOC_START:
Holger Schurig10078322007-11-15 18:05:47 -05001284 ret = lbs_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001285 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001286 case CMD_CODE_DNLD:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001287 break;
1288
Dan Williams0aef64d2007-08-02 11:31:18 -04001289 case CMD_802_11_RESET:
Holger Schurig10078322007-11-15 18:05:47 -05001290 ret = lbs_cmd_802_11_reset(priv, cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001291 break;
1292
Dan Williams0aef64d2007-08-02 11:31:18 -04001293 case CMD_802_11_GET_LOG:
Holger Schurig10078322007-11-15 18:05:47 -05001294 ret = lbs_cmd_802_11_get_log(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001295 break;
1296
Dan Williams0aef64d2007-08-02 11:31:18 -04001297 case CMD_802_11_AUTHENTICATE:
Holger Schurig10078322007-11-15 18:05:47 -05001298 ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001299 break;
1300
Dan Williams0aef64d2007-08-02 11:31:18 -04001301 case CMD_802_11_GET_STAT:
Holger Schurig10078322007-11-15 18:05:47 -05001302 ret = lbs_cmd_802_11_get_stat(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001303 break;
1304
Dan Williams0aef64d2007-08-02 11:31:18 -04001305 case CMD_802_11_SNMP_MIB:
Holger Schurig10078322007-11-15 18:05:47 -05001306 ret = lbs_cmd_802_11_snmp_mib(priv, cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001307 cmd_action, cmd_oid, pdata_buf);
1308 break;
1309
Dan Williams0aef64d2007-08-02 11:31:18 -04001310 case CMD_MAC_REG_ACCESS:
1311 case CMD_BBP_REG_ACCESS:
1312 case CMD_RF_REG_ACCESS:
Holger Schurig10078322007-11-15 18:05:47 -05001313 ret = lbs_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001314 break;
1315
Dan Williams0aef64d2007-08-02 11:31:18 -04001316 case CMD_802_11_RF_CHANNEL:
Holger Schurig10078322007-11-15 18:05:47 -05001317 ret = lbs_cmd_802_11_rf_channel(priv, cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001318 cmd_action, pdata_buf);
1319 break;
1320
Dan Williams0aef64d2007-08-02 11:31:18 -04001321 case CMD_802_11_RF_TX_POWER:
Holger Schurig10078322007-11-15 18:05:47 -05001322 ret = lbs_cmd_802_11_rf_tx_power(priv, cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001323 cmd_action, pdata_buf);
1324 break;
1325
Dan Williams0aef64d2007-08-02 11:31:18 -04001326 case CMD_802_11_RADIO_CONTROL:
Holger Schurig10078322007-11-15 18:05:47 -05001327 ret = lbs_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001328 break;
1329
Dan Williams0aef64d2007-08-02 11:31:18 -04001330 case CMD_802_11_DATA_RATE:
Holger Schurig10078322007-11-15 18:05:47 -05001331 ret = lbs_cmd_802_11_data_rate(priv, cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001332 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001333 case CMD_802_11_RATE_ADAPT_RATESET:
Holger Schurig10078322007-11-15 18:05:47 -05001334 ret = lbs_cmd_802_11_rate_adapt_rateset(priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001335 cmdptr, cmd_action);
1336 break;
1337
Dan Williams0aef64d2007-08-02 11:31:18 -04001338 case CMD_MAC_MULTICAST_ADR:
Holger Schurig10078322007-11-15 18:05:47 -05001339 ret = lbs_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001340 break;
1341
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001342 case CMD_802_11_MONITOR_MODE:
Holger Schurig10078322007-11-15 18:05:47 -05001343 ret = lbs_cmd_802_11_monitor_mode(priv, cmdptr,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001344 cmd_action, pdata_buf);
1345 break;
1346
Dan Williams0aef64d2007-08-02 11:31:18 -04001347 case CMD_802_11_AD_HOC_JOIN:
Holger Schurig10078322007-11-15 18:05:47 -05001348 ret = lbs_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001349 break;
1350
Dan Williams0aef64d2007-08-02 11:31:18 -04001351 case CMD_802_11_RSSI:
Holger Schurig10078322007-11-15 18:05:47 -05001352 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001353 break;
1354
Dan Williams0aef64d2007-08-02 11:31:18 -04001355 case CMD_802_11_AD_HOC_STOP:
Holger Schurig10078322007-11-15 18:05:47 -05001356 ret = lbs_cmd_80211_ad_hoc_stop(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001357 break;
1358
Dan Williams0aef64d2007-08-02 11:31:18 -04001359 case CMD_802_11_ENABLE_RSN:
Holger Schurig10078322007-11-15 18:05:47 -05001360 ret = lbs_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action,
Dan Williams90a42212007-05-25 23:01:24 -04001361 pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001362 break;
1363
Dan Williams0aef64d2007-08-02 11:31:18 -04001364 case CMD_802_11_KEY_MATERIAL:
Holger Schurig10078322007-11-15 18:05:47 -05001365 ret = lbs_cmd_802_11_key_material(priv, cmdptr, cmd_action,
Dan Williams90a42212007-05-25 23:01:24 -04001366 cmd_oid, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001367 break;
1368
Dan Williams0aef64d2007-08-02 11:31:18 -04001369 case CMD_802_11_PAIRWISE_TSC:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001370 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001371 case CMD_802_11_GROUP_TSC:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001372 break;
1373
Dan Williams0aef64d2007-08-02 11:31:18 -04001374 case CMD_802_11_MAC_ADDRESS:
Holger Schurig10078322007-11-15 18:05:47 -05001375 ret = lbs_cmd_802_11_mac_address(priv, cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001376 break;
1377
Dan Williams0aef64d2007-08-02 11:31:18 -04001378 case CMD_802_11_EEPROM_ACCESS:
Holger Schurig10078322007-11-15 18:05:47 -05001379 ret = lbs_cmd_802_11_eeprom_access(priv, cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001380 cmd_action, pdata_buf);
1381 break;
1382
Dan Williams0aef64d2007-08-02 11:31:18 -04001383 case CMD_802_11_SET_AFC:
1384 case CMD_802_11_GET_AFC:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001385
1386 cmdptr->command = cpu_to_le16(cmd_no);
David Woodhouse981f1872007-05-25 23:36:54 -04001387 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1388 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001389
1390 memmove(&cmdptr->params.afc,
1391 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1392
1393 ret = 0;
1394 goto done;
1395
Dan Williams0aef64d2007-08-02 11:31:18 -04001396 case CMD_802_11D_DOMAIN_INFO:
Holger Schurig10078322007-11-15 18:05:47 -05001397 ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001398 cmd_no, cmd_action);
1399 break;
1400
Dan Williams0aef64d2007-08-02 11:31:18 -04001401 case CMD_802_11_SLEEP_PARAMS:
Holger Schurig10078322007-11-15 18:05:47 -05001402 ret = lbs_cmd_802_11_sleep_params(priv, cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001403 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001404 case CMD_802_11_INACTIVITY_TIMEOUT:
Holger Schurig10078322007-11-15 18:05:47 -05001405 ret = lbs_cmd_802_11_inactivity_timeout(priv, cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001406 cmd_action, pdata_buf);
David Woodhousef5ece8f2007-12-01 15:15:41 +00001407 lbs_set_cmd_ctrl_node(priv, cmdnode, 0, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001408 break;
1409
Dan Williams0aef64d2007-08-02 11:31:18 -04001410 case CMD_802_11_TPC_CFG:
1411 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001412 cmdptr->size =
1413 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1414 S_DS_GEN);
1415
1416 memmove(&cmdptr->params.tpccfg,
1417 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1418
1419 ret = 0;
1420 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001421 case CMD_802_11_LED_GPIO_CTRL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001422 {
1423 struct mrvlietypes_ledgpio *gpio =
1424 (struct mrvlietypes_ledgpio*)
1425 cmdptr->params.ledgpio.data;
1426
1427 memmove(&cmdptr->params.ledgpio,
1428 pdata_buf,
1429 sizeof(struct cmd_ds_802_11_led_ctrl));
1430
1431 cmdptr->command =
Dan Williams0aef64d2007-08-02 11:31:18 -04001432 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001433
1434#define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1435 cmdptr->size =
1436 cpu_to_le16(gpio->header.len + S_DS_GEN +
1437 ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1438 gpio->header.len = cpu_to_le16(gpio->header.len);
1439
1440 ret = 0;
1441 break;
1442 }
Holger Schurig3a188642007-11-26 10:07:14 +01001443 case CMD_802_11_SUBSCRIBE_EVENT:
1444 lbs_cmd_802_11_subscribe_event(priv, cmdptr,
1445 cmd_action, pdata_buf);
1446 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001447 case CMD_802_11_PWR_CFG:
1448 cmdptr->command = cpu_to_le16(CMD_802_11_PWR_CFG);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001449 cmdptr->size =
1450 cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) +
1451 S_DS_GEN);
1452 memmove(&cmdptr->params.pwrcfg, pdata_buf,
1453 sizeof(struct cmd_ds_802_11_pwr_cfg));
1454
1455 ret = 0;
1456 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001457 case CMD_BT_ACCESS:
Holger Schurig10078322007-11-15 18:05:47 -05001458 ret = lbs_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001459 break;
1460
Dan Williams0aef64d2007-08-02 11:31:18 -04001461 case CMD_FWT_ACCESS:
Holger Schurig10078322007-11-15 18:05:47 -05001462 ret = lbs_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001463 break;
1464
Dan Williams0aef64d2007-08-02 11:31:18 -04001465 case CMD_MESH_ACCESS:
Holger Schurig10078322007-11-15 18:05:47 -05001466 ret = lbs_cmd_mesh_access(priv, cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001467 break;
1468
Luis Carlos Cobo63f00232007-08-02 13:19:24 -04001469 case CMD_SET_BOOT2_VER:
Holger Schurig10078322007-11-15 18:05:47 -05001470 ret = lbs_cmd_set_boot2_ver(priv, cmdptr, cmd_action, pdata_buf);
Luis Carlos Cobo63f00232007-08-02 13:19:24 -04001471 break;
1472
Dan Williams0aef64d2007-08-02 11:31:18 -04001473 case CMD_GET_TSF:
1474 cmdptr->command = cpu_to_le16(CMD_GET_TSF);
David Woodhouse981f1872007-05-25 23:36:54 -04001475 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1476 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001477 ret = 0;
1478 break;
Brajesh Dave96287ac2007-11-20 17:44:28 -05001479 case CMD_802_11_BEACON_CTRL:
1480 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1481 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001482 default:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001483 lbs_deb_host("PREP_CMD: unknown command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001484 ret = -1;
1485 break;
1486 }
1487
1488 /* return error, since the command preparation failed */
1489 if (ret != 0) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001490 lbs_deb_host("PREP_CMD: command preparation failed\n");
Holger Schurig10078322007-11-15 18:05:47 -05001491 lbs_cleanup_and_insert_cmd(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001492 ret = -1;
1493 goto done;
1494 }
1495
1496 cmdnode->cmdwaitqwoken = 0;
1497
Holger Schurig10078322007-11-15 18:05:47 -05001498 lbs_queue_cmd(adapter, cmdnode, 1);
Dan Williamsfe336152007-08-02 11:32:25 -04001499 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001500
Dan Williams0aef64d2007-08-02 11:31:18 -04001501 if (wait_option & CMD_OPTION_WAITFORRSP) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001502 lbs_deb_host("PREP_CMD: wait for response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001503 might_sleep();
1504 wait_event_interruptible(cmdnode->cmdwait_q,
1505 cmdnode->cmdwaitqwoken);
1506 }
1507
1508 spin_lock_irqsave(&adapter->driver_lock, flags);
1509 if (adapter->cur_cmd_retcode) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001510 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001511 adapter->cur_cmd_retcode);
1512 adapter->cur_cmd_retcode = 0;
1513 ret = -1;
1514 }
1515 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1516
1517done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001518 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001519 return ret;
1520}
Holger Schurig10078322007-11-15 18:05:47 -05001521EXPORT_SYMBOL_GPL(lbs_prepare_and_send_command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001522
1523/**
1524 * @brief This function allocates the command buffer and link
1525 * it to command free queue.
1526 *
Holger Schurig69f90322007-11-23 15:43:44 +01001527 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001528 * @return 0 or -1
1529 */
Holger Schurig69f90322007-11-23 15:43:44 +01001530int lbs_allocate_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001531{
1532 int ret = 0;
1533 u32 ulbufsize;
1534 u32 i;
1535 struct cmd_ctrl_node *tempcmd_array;
1536 u8 *ptempvirtualaddr;
Holger Schurig69f90322007-11-23 15:43:44 +01001537 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001538
Holger Schurig8ff12da2007-08-02 11:54:31 -04001539 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001540
1541 /* Allocate and initialize cmdCtrlNode */
1542 ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
1543
Holger Schurigfb3dddf2007-05-25 11:58:22 -04001544 if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001545 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001546 ret = -1;
1547 goto done;
1548 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001549 adapter->cmd_array = tempcmd_array;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001550
1551 /* Allocate and initialize command buffers */
1552 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1553 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
Holger Schurigfb3dddf2007-05-25 11:58:22 -04001554 if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001555 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001556 ret = -1;
1557 goto done;
1558 }
1559
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001560 /* Update command buffer virtual */
1561 tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
1562 }
1563
1564 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1565 init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
Holger Schurig10078322007-11-15 18:05:47 -05001566 lbs_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001567 }
1568
1569 ret = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001570
1571done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001572 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001573 return ret;
1574}
1575
1576/**
1577 * @brief This function frees the command buffer.
1578 *
Holger Schurig69f90322007-11-23 15:43:44 +01001579 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001580 * @return 0 or -1
1581 */
Holger Schurig69f90322007-11-23 15:43:44 +01001582int lbs_free_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001583{
David Woodhouse981f1872007-05-25 23:36:54 -04001584 u32 ulbufsize; /* Someone needs to die for this. Slowly and painfully */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001585 unsigned int i;
1586 struct cmd_ctrl_node *tempcmd_array;
Holger Schurig69f90322007-11-23 15:43:44 +01001587 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001588
Holger Schurig8ff12da2007-08-02 11:54:31 -04001589 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001590
1591 /* need to check if cmd array is allocated or not */
1592 if (adapter->cmd_array == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001593 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001594 goto done;
1595 }
1596
1597 tempcmd_array = adapter->cmd_array;
1598
1599 /* Release shared memory buffers */
1600 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1601 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1602 if (tempcmd_array[i].bufvirtualaddr) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001603 kfree(tempcmd_array[i].bufvirtualaddr);
1604 tempcmd_array[i].bufvirtualaddr = NULL;
1605 }
1606 }
1607
1608 /* Release cmd_ctrl_node */
1609 if (adapter->cmd_array) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001610 kfree(adapter->cmd_array);
1611 adapter->cmd_array = NULL;
1612 }
1613
1614done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001615 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001616 return 0;
1617}
1618
1619/**
1620 * @brief This function gets a free command node if available in
1621 * command free queue.
1622 *
Holger Schurig69f90322007-11-23 15:43:44 +01001623 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001624 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1625 */
Holger Schurig69f90322007-11-23 15:43:44 +01001626struct cmd_ctrl_node *lbs_get_free_cmd_ctrl_node(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001627{
1628 struct cmd_ctrl_node *tempnode;
Holger Schurig69f90322007-11-23 15:43:44 +01001629 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001630 unsigned long flags;
1631
Holger Schurig8ff12da2007-08-02 11:54:31 -04001632 lbs_deb_enter(LBS_DEB_HOST);
1633
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001634 if (!adapter)
1635 return NULL;
1636
1637 spin_lock_irqsave(&adapter->driver_lock, flags);
1638
1639 if (!list_empty(&adapter->cmdfreeq)) {
1640 tempnode = (struct cmd_ctrl_node *)adapter->cmdfreeq.next;
1641 list_del((struct list_head *)tempnode);
1642 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001643 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001644 tempnode = NULL;
1645 }
1646
1647 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1648
Holger Schurig8ff12da2007-08-02 11:54:31 -04001649 if (tempnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001650 cleanup_cmdnode(tempnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001651
Holger Schurig8ff12da2007-08-02 11:54:31 -04001652 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001653 return tempnode;
1654}
1655
1656/**
1657 * @brief This function cleans command node.
1658 *
1659 * @param ptempnode A pointer to cmdCtrlNode structure
1660 * @return n/a
1661 */
1662static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
1663{
Holger Schurig8ff12da2007-08-02 11:54:31 -04001664 lbs_deb_enter(LBS_DEB_HOST);
1665
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001666 if (!ptempnode)
1667 return;
1668 ptempnode->cmdwaitqwoken = 1;
1669 wake_up_interruptible(&ptempnode->cmdwait_q);
1670 ptempnode->status = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001671 ptempnode->wait_option = 0;
1672 ptempnode->pdata_buf = NULL;
1673
1674 if (ptempnode->bufvirtualaddr != NULL)
1675 memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001676
1677 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001678}
1679
1680/**
1681 * @brief This function initializes the command node.
1682 *
Holger Schurig69f90322007-11-23 15:43:44 +01001683 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001684 * @param ptempnode A pointer to cmd_ctrl_node structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001685 * @param wait_option wait option: wait response or not
1686 * @param pdata_buf A pointer to informaion buffer
1687 * @return 0 or -1
1688 */
Holger Schurig69f90322007-11-23 15:43:44 +01001689void lbs_set_cmd_ctrl_node(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001690 struct cmd_ctrl_node *ptempnode,
David Woodhousef5ece8f2007-12-01 15:15:41 +00001691 u16 wait_option, void *pdata_buf)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001692{
Holger Schurig8ff12da2007-08-02 11:54:31 -04001693 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001694
1695 if (!ptempnode)
1696 return;
1697
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001698 ptempnode->wait_option = wait_option;
1699 ptempnode->pdata_buf = pdata_buf;
1700
Holger Schurig8ff12da2007-08-02 11:54:31 -04001701 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001702}
1703
1704/**
1705 * @brief This function executes next command in command
1706 * pending queue. It will put fimware back to PS mode
1707 * if applicable.
1708 *
Holger Schurig69f90322007-11-23 15:43:44 +01001709 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001710 * @return 0 or -1
1711 */
Holger Schurig69f90322007-11-23 15:43:44 +01001712int lbs_execute_next_command(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001713{
Holger Schurig69f90322007-11-23 15:43:44 +01001714 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001715 struct cmd_ctrl_node *cmdnode = NULL;
1716 struct cmd_ds_command *cmdptr;
1717 unsigned long flags;
1718 int ret = 0;
1719
Holger Schurig8ff12da2007-08-02 11:54:31 -04001720 // Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
Holger Schurig10078322007-11-15 18:05:47 -05001721 // only caller to us is lbs_thread() and we get even when a
Holger Schurig8ff12da2007-08-02 11:54:31 -04001722 // data packet is received
1723 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001724
1725 spin_lock_irqsave(&adapter->driver_lock, flags);
1726
1727 if (adapter->cur_cmd) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001728 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001729 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1730 ret = -1;
1731 goto done;
1732 }
1733
1734 if (!list_empty(&adapter->cmdpendingq)) {
1735 cmdnode = (struct cmd_ctrl_node *)
1736 adapter->cmdpendingq.next;
1737 }
1738
1739 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1740
1741 if (cmdnode) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001742 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1743
1744 if (is_command_allowed_in_ps(cmdptr->command)) {
David Woodhouse981f1872007-05-25 23:36:54 -04001745 if ((adapter->psstate == PS_STATE_SLEEP) ||
1746 (adapter->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001747 lbs_deb_host(
1748 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
David Woodhouse981f1872007-05-25 23:36:54 -04001749 le16_to_cpu(cmdptr->command),
1750 adapter->psstate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001751 ret = -1;
1752 goto done;
1753 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001754 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
1755 "0x%04x in psstate %d\n",
David Woodhouse981f1872007-05-25 23:36:54 -04001756 le16_to_cpu(cmdptr->command),
1757 adapter->psstate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001758 } else if (adapter->psstate != PS_STATE_FULL_POWER) {
1759 /*
1760 * 1. Non-PS command:
1761 * Queue it. set needtowakeup to TRUE if current state
Holger Schurig10078322007-11-15 18:05:47 -05001762 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001763 * 2. PS command but not Exit_PS:
1764 * Ignore it.
1765 * 3. PS command Exit_PS:
1766 * Set needtowakeup to TRUE if current state is SLEEP,
1767 * otherwise send this command down to firmware
1768 * immediately.
1769 */
1770 if (cmdptr->command !=
Dan Williams0aef64d2007-08-02 11:31:18 -04001771 cpu_to_le16(CMD_802_11_PS_MODE)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001772 /* Prepare to send Exit PS,
1773 * this non PS command will be sent later */
1774 if ((adapter->psstate == PS_STATE_SLEEP)
1775 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1776 ) {
1777 /* w/ new scheme, it will not reach here.
1778 since it is blocked in main_thread. */
1779 adapter->needtowakeup = 1;
1780 } else
Holger Schurig10078322007-11-15 18:05:47 -05001781 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001782
1783 ret = 0;
1784 goto done;
1785 } else {
1786 /*
1787 * PS command. Ignore it if it is not Exit_PS.
1788 * otherwise send it down immediately.
1789 */
1790 struct cmd_ds_802_11_ps_mode *psm =
1791 &cmdptr->params.psmode;
1792
Holger Schurig8ff12da2007-08-02 11:54:31 -04001793 lbs_deb_host(
1794 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001795 psm->action);
1796 if (psm->action !=
Dan Williams0aef64d2007-08-02 11:31:18 -04001797 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001798 lbs_deb_host(
1799 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001800 list_del((struct list_head *)cmdnode);
Holger Schurig10078322007-11-15 18:05:47 -05001801 lbs_cleanup_and_insert_cmd(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001802
1803 ret = 0;
1804 goto done;
1805 }
1806
David Woodhouse981f1872007-05-25 23:36:54 -04001807 if ((adapter->psstate == PS_STATE_SLEEP) ||
1808 (adapter->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001809 lbs_deb_host(
1810 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001811 list_del((struct list_head *)cmdnode);
Holger Schurig10078322007-11-15 18:05:47 -05001812 lbs_cleanup_and_insert_cmd(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001813 adapter->needtowakeup = 1;
1814
1815 ret = 0;
1816 goto done;
1817 }
1818
Holger Schurig8ff12da2007-08-02 11:54:31 -04001819 lbs_deb_host(
1820 "EXEC_NEXT_CMD: sending EXIT_PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001821 }
1822 }
1823 list_del((struct list_head *)cmdnode);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001824 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
David Woodhouse981f1872007-05-25 23:36:54 -04001825 le16_to_cpu(cmdptr->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001826 DownloadcommandToStation(priv, cmdnode);
1827 } else {
1828 /*
1829 * check if in power save mode, if yes, put the device back
1830 * to PS mode
1831 */
Holger Schurig10078322007-11-15 18:05:47 -05001832 if ((adapter->psmode != LBS802_11POWERMODECAM) &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001833 (adapter->psstate == PS_STATE_FULL_POWER) &&
Brajesh Dave01d77d82007-11-20 17:44:14 -05001834 ((adapter->connect_status == LBS_CONNECTED) ||
1835 (adapter->mesh_connect_status == LBS_CONNECTED))) {
David Woodhouse981f1872007-05-25 23:36:54 -04001836 if (adapter->secinfo.WPAenabled ||
1837 adapter->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001838 /* check for valid WPA group keys */
David Woodhouse981f1872007-05-25 23:36:54 -04001839 if (adapter->wpa_mcast_key.len ||
1840 adapter->wpa_unicast_key.len) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001841 lbs_deb_host(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001842 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1843 " go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001844 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001845 }
1846 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001847 lbs_deb_host(
1848 "EXEC_NEXT_CMD: cmdpendingq empty, "
1849 "go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001850 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001851 }
1852 }
1853 }
1854
1855 ret = 0;
1856done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001857 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001858 return ret;
1859}
1860
Holger Schurig69f90322007-11-23 15:43:44 +01001861void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001862{
1863 union iwreq_data iwrq;
1864 u8 buf[50];
1865
Holger Schurig8ff12da2007-08-02 11:54:31 -04001866 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001867
1868 memset(&iwrq, 0, sizeof(union iwreq_data));
1869 memset(buf, 0, sizeof(buf));
1870
1871 snprintf(buf, sizeof(buf) - 1, "%s", str);
1872
1873 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1874
1875 /* Send Event to upper layer */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001876 lbs_deb_wext("event indication string %s\n", (char *)buf);
1877 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
1878 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001879
Holger Schurig634b8f42007-05-25 13:05:16 -04001880 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001881
Holger Schurig8ff12da2007-08-02 11:54:31 -04001882 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001883}
1884
Holger Schurig69f90322007-11-23 15:43:44 +01001885static int sendconfirmsleep(struct lbs_private *priv, u8 *cmdptr, u16 size)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001886{
1887 unsigned long flags;
Holger Schurig69f90322007-11-23 15:43:44 +01001888 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001889 int ret = 0;
1890
Holger Schurig8ff12da2007-08-02 11:54:31 -04001891 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001892
Holger Schurig8ff12da2007-08-02 11:54:31 -04001893 lbs_deb_host("SEND_SLEEPC_CMD: before download, cmd size %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001894 size);
1895
Holger Schurig8ff12da2007-08-02 11:54:31 -04001896 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm command", cmdptr, size);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001897
Holger Schurig208fdd22007-05-25 12:17:06 -04001898 ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
Holger Schurig634b8f42007-05-25 13:05:16 -04001899 priv->dnld_sent = DNLD_RES_RECEIVED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001900
1901 spin_lock_irqsave(&adapter->driver_lock, flags);
1902 if (adapter->intcounter || adapter->currenttxskb)
Holger Schurig8ff12da2007-08-02 11:54:31 -04001903 lbs_deb_host("SEND_SLEEPC_CMD: intcounter %d, currenttxskb %p\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001904 adapter->intcounter, adapter->currenttxskb);
1905 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1906
1907 if (ret) {
1908 lbs_pr_alert(
1909 "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
1910 } else {
1911 spin_lock_irqsave(&adapter->driver_lock, flags);
1912 if (!adapter->intcounter) {
1913 adapter->psstate = PS_STATE_SLEEP;
1914 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001915 lbs_deb_host("SEND_SLEEPC_CMD: after sent, intcounter %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001916 adapter->intcounter);
1917 }
1918 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1919
Holger Schurig8ff12da2007-08-02 11:54:31 -04001920 lbs_deb_host("SEND_SLEEPC_CMD: sent confirm sleep\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001921 }
1922
Holger Schurig8ff12da2007-08-02 11:54:31 -04001923 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001924 return ret;
1925}
1926
Holger Schurig69f90322007-11-23 15:43:44 +01001927void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001928{
Holger Schurig8ff12da2007-08-02 11:54:31 -04001929 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001930
1931 /*
1932 * PS is currently supported only in Infrastructure mode
1933 * Remove this check if it is to be supported in IBSS mode also
1934 */
1935
Holger Schurig10078322007-11-15 18:05:47 -05001936 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001937 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001938
Holger Schurig8ff12da2007-08-02 11:54:31 -04001939 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001940}
1941
1942/**
Holger Schurig8ff12da2007-08-02 11:54:31 -04001943 * @brief This function sends Exit_PS command to firmware.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001944 *
Holger Schurig69f90322007-11-23 15:43:44 +01001945 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001946 * @param wait_option wait response or not
1947 * @return n/a
1948 */
Holger Schurig69f90322007-11-23 15:43:44 +01001949void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001950{
David Woodhouse981f1872007-05-25 23:36:54 -04001951 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001952
Holger Schurig8ff12da2007-08-02 11:54:31 -04001953 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001954
Holger Schurig10078322007-11-15 18:05:47 -05001955 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001956
Holger Schurig10078322007-11-15 18:05:47 -05001957 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001958 CMD_SUBCMD_EXIT_PS,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001959 wait_option, 0, &Localpsmode);
1960
Holger Schurig8ff12da2007-08-02 11:54:31 -04001961 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001962}
1963
1964/**
1965 * @brief This function checks condition and prepares to
1966 * send sleep confirm command to firmware if ok.
1967 *
Holger Schurig69f90322007-11-23 15:43:44 +01001968 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001969 * @param psmode Power Saving mode
1970 * @return n/a
1971 */
Holger Schurig69f90322007-11-23 15:43:44 +01001972void lbs_ps_confirm_sleep(struct lbs_private *priv, u16 psmode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001973{
1974 unsigned long flags =0;
Holger Schurig69f90322007-11-23 15:43:44 +01001975 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001976 u8 allowed = 1;
1977
Holger Schurig8ff12da2007-08-02 11:54:31 -04001978 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001979
Holger Schurig634b8f42007-05-25 13:05:16 -04001980 if (priv->dnld_sent) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001981 allowed = 0;
Holger Schurig8ff12da2007-08-02 11:54:31 -04001982 lbs_deb_host("dnld_sent was set");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001983 }
1984
1985 spin_lock_irqsave(&adapter->driver_lock, flags);
1986 if (adapter->cur_cmd) {
1987 allowed = 0;
Holger Schurig8ff12da2007-08-02 11:54:31 -04001988 lbs_deb_host("cur_cmd was set");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001989 }
1990 if (adapter->intcounter > 0) {
1991 allowed = 0;
Holger Schurig8ff12da2007-08-02 11:54:31 -04001992 lbs_deb_host("intcounter %d", adapter->intcounter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001993 }
1994 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1995
1996 if (allowed) {
Holger Schurig10078322007-11-15 18:05:47 -05001997 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
1998 sendconfirmsleep(priv, (u8 *) & adapter->lbs_ps_confirm_sleep,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001999 sizeof(struct PS_CMD_ConfirmSleep));
2000 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04002001 lbs_deb_host("sleep confirm has been delayed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002002 }
2003
Holger Schurig8ff12da2007-08-02 11:54:31 -04002004 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002005}