blob: 13f6528abb00d22370eff0626b1927bcedca79aa [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[] = {
18 cmd_802_11_rssi,
19};
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
40static int wlan_cmd_hw_spec(wlan_private * priv, struct cmd_ds_command *cmd)
41{
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
46 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
54static int wlan_cmd_802_11_ps_mode(wlan_private * priv,
55 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 wlan_adapter *adapter = priv->adapter;
60
Holger Schurig9012b282007-05-25 11:27:16 -040061 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020062
63 cmd->command = cpu_to_le16(cmd_802_11_ps_mode);
David Woodhouse981f1872007-05-25 23:36:54 -040064 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
65 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020066 psm->action = cpu_to_le16(cmd_action);
67 psm->multipledtim = 0;
David Woodhouse981f1872007-05-25 23:36:54 -040068 switch (cmd_action) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020069 case cmd_subcmd_enter_ps:
Holger Schurig9012b282007-05-25 11:27:16 -040070 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
71 lbs_deb_cmd("locallisteninterval = %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020072 adapter->locallisteninterval);
73
74 psm->locallisteninterval =
75 cpu_to_le16(adapter->locallisteninterval);
76 psm->nullpktinterval =
77 cpu_to_le16(adapter->nullpktinterval);
78 psm->multipledtim =
79 cpu_to_le16(priv->adapter->multipledtim);
80 break;
81
82 case cmd_subcmd_exit_ps:
Holger Schurig9012b282007-05-25 11:27:16 -040083 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020084 break;
85
86 case cmd_subcmd_sleep_confirmed:
Holger Schurig9012b282007-05-25 11:27:16 -040087 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020088 break;
89
90 default:
91 break;
92 }
93
Holger Schurig9012b282007-05-25 11:27:16 -040094 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020095 return 0;
96}
97
98static int wlan_cmd_802_11_inactivity_timeout(wlan_private * priv,
99 struct cmd_ds_command *cmd,
100 u16 cmd_action, void *pdata_buf)
101{
102 u16 *timeout = pdata_buf;
103
104 cmd->command = cpu_to_le16(cmd_802_11_inactivity_timeout);
105 cmd->size =
106 cpu_to_le16(sizeof(struct cmd_ds_802_11_inactivity_timeout)
107 + S_DS_GEN);
108
109 cmd->params.inactivity_timeout.action = cpu_to_le16(cmd_action);
110
111 if (cmd_action)
David Woodhouse981f1872007-05-25 23:36:54 -0400112 cmd->params.inactivity_timeout.timeout = cpu_to_le16(*timeout);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200113 else
114 cmd->params.inactivity_timeout.timeout = 0;
115
116 return 0;
117}
118
119static int wlan_cmd_802_11_sleep_params(wlan_private * priv,
120 struct cmd_ds_command *cmd,
121 u16 cmd_action)
122{
123 wlan_adapter *adapter = priv->adapter;
124 struct cmd_ds_802_11_sleep_params *sp = &cmd->params.sleep_params;
125
Holger Schurig9012b282007-05-25 11:27:16 -0400126 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200127
David Woodhouse981f1872007-05-25 23:36:54 -0400128 cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
129 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200130 cmd->command = cpu_to_le16(cmd_802_11_sleep_params);
131
132 if (cmd_action == cmd_act_get) {
133 memset(&adapter->sp, 0, sizeof(struct sleep_params));
134 memset(sp, 0, sizeof(struct cmd_ds_802_11_sleep_params));
135 sp->action = cpu_to_le16(cmd_action);
136 } else if (cmd_action == cmd_act_set) {
137 sp->action = cpu_to_le16(cmd_action);
138 sp->error = cpu_to_le16(adapter->sp.sp_error);
139 sp->offset = cpu_to_le16(adapter->sp.sp_offset);
140 sp->stabletime = cpu_to_le16(adapter->sp.sp_stabletime);
141 sp->calcontrol = (u8) adapter->sp.sp_calcontrol;
142 sp->externalsleepclk = (u8) adapter->sp.sp_extsleepclk;
143 sp->reserved = cpu_to_le16(adapter->sp.sp_reserved);
144 }
145
Holger Schurig9012b282007-05-25 11:27:16 -0400146 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200147 return 0;
148}
149
150static int wlan_cmd_802_11_set_wep(wlan_private * priv,
151 struct cmd_ds_command *cmd,
152 u32 cmd_act,
153 void * pdata_buf)
154{
155 struct cmd_ds_802_11_set_wep *wep = &cmd->params.wep;
156 wlan_adapter *adapter = priv->adapter;
157 int ret = 0;
158 struct assoc_request * assoc_req = pdata_buf;
159
Holger Schurig9012b282007-05-25 11:27:16 -0400160 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200161
162 cmd->command = cpu_to_le16(cmd_802_11_set_wep);
David Woodhouse981f1872007-05-25 23:36:54 -0400163 cmd->size = cpu_to_le16(sizeof(*wep) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200164
165 if (cmd_act == cmd_act_add) {
166 int i;
167
168 if (!assoc_req) {
Holger Schurig9012b282007-05-25 11:27:16 -0400169 lbs_deb_cmd("Invalid association request!");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200170 ret = -1;
171 goto done;
172 }
173
174 wep->action = cpu_to_le16(cmd_act_add);
175
176 /* default tx key index */
David Woodhouse981f1872007-05-25 23:36:54 -0400177 wep->keyindex = cpu_to_le16((u16)(assoc_req->wep_tx_keyidx &
178 (u32)cmd_WEP_KEY_INDEX_MASK));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200179
David Woodhouse981f1872007-05-25 23:36:54 -0400180 lbs_deb_cmd("Tx key Index: %u\n", le16_to_cpu(wep->keyindex));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200181
182 /* Copy key types and material to host command structure */
183 for (i = 0; i < 4; i++) {
184 struct WLAN_802_11_KEY * pkey = &assoc_req->wep_keys[i];
185
186 switch (pkey->len) {
187 case KEY_LEN_WEP_40:
David Woodhouse981f1872007-05-25 23:36:54 -0400188 wep->keytype[i] =
189 cpu_to_le16(cmd_type_wep_40_bit);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200190 memmove(&wep->keymaterial[i], pkey->key,
191 pkey->len);
192 break;
193 case KEY_LEN_WEP_104:
David Woodhouse981f1872007-05-25 23:36:54 -0400194 wep->keytype[i] =
195 cpu_to_le16(cmd_type_wep_104_bit);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200196 memmove(&wep->keymaterial[i], pkey->key,
197 pkey->len);
198 break;
199 case 0:
200 break;
201 default:
Holger Schurig9012b282007-05-25 11:27:16 -0400202 lbs_deb_cmd("Invalid WEP key %d length of %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200203 i, pkey->len);
204 ret = -1;
205 goto done;
206 break;
207 }
208 }
209 } else if (cmd_act == cmd_act_remove) {
210 /* ACT_REMOVE clears _all_ WEP keys */
211 wep->action = cpu_to_le16(cmd_act_remove);
212
213 /* default tx key index */
David Woodhouse981f1872007-05-25 23:36:54 -0400214 wep->keyindex = cpu_to_le16((u16)(adapter->wep_tx_keyidx &
215 (u32)cmd_WEP_KEY_INDEX_MASK));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200216 }
217
218 ret = 0;
219
220done:
Holger Schurig9012b282007-05-25 11:27:16 -0400221 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200222 return ret;
223}
224
225static int wlan_cmd_802_11_enable_rsn(wlan_private * priv,
226 struct cmd_ds_command *cmd,
Dan Williams90a42212007-05-25 23:01:24 -0400227 u16 cmd_action,
228 void * pdata_buf)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200229{
230 struct cmd_ds_802_11_enable_rsn *penableRSN = &cmd->params.enbrsn;
Dan Williams18c96c342007-06-18 12:01:12 -0400231 u32 * enable = pdata_buf;
Dan Williams90a42212007-05-25 23:01:24 -0400232
233 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234
235 cmd->command = cpu_to_le16(cmd_802_11_enable_rsn);
David Woodhouse981f1872007-05-25 23:36:54 -0400236 cmd->size = cpu_to_le16(sizeof(*penableRSN) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200237 penableRSN->action = cpu_to_le16(cmd_action);
Dan Williams18c96c342007-06-18 12:01:12 -0400238
239 if (cmd_action == cmd_act_set) {
240 if (*enable)
241 penableRSN->enable = cpu_to_le16(cmd_enable_rsn);
242 else
243 penableRSN->enable = cpu_to_le16(cmd_enable_rsn);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200244 }
245
Dan Williams90a42212007-05-25 23:01:24 -0400246 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200247 return 0;
248}
249
250
251static void set_one_wpa_key(struct MrvlIEtype_keyParamSet * pkeyparamset,
252 struct WLAN_802_11_KEY * pkey)
253{
254 pkeyparamset->keytypeid = cpu_to_le16(pkey->type);
255
256 if (pkey->flags & KEY_INFO_WPA_ENABLED) {
Dan Williams90a42212007-05-25 23:01:24 -0400257 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200258 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200259 if (pkey->flags & KEY_INFO_WPA_UNICAST) {
260 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
Dan Williams90a42212007-05-25 23:01:24 -0400261 }
262 if (pkey->flags & KEY_INFO_WPA_MCAST) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200263 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
264 }
265
266 pkeyparamset->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
267 pkeyparamset->keylen = cpu_to_le16(pkey->len);
268 memcpy(pkeyparamset->key, pkey->key, pkey->len);
269 pkeyparamset->length = cpu_to_le16( sizeof(pkeyparamset->keytypeid)
270 + sizeof(pkeyparamset->keyinfo)
271 + sizeof(pkeyparamset->keylen)
272 + sizeof(pkeyparamset->key));
273}
274
275static int wlan_cmd_802_11_key_material(wlan_private * priv,
276 struct cmd_ds_command *cmd,
277 u16 cmd_action,
278 u32 cmd_oid, void *pdata_buf)
279{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200280 struct cmd_ds_802_11_key_material *pkeymaterial =
281 &cmd->params.keymaterial;
Dan Williams90a42212007-05-25 23:01:24 -0400282 struct assoc_request * assoc_req = pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200283 int ret = 0;
284 int index = 0;
285
Holger Schurig9012b282007-05-25 11:27:16 -0400286 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200287
288 cmd->command = cpu_to_le16(cmd_802_11_key_material);
289 pkeymaterial->action = cpu_to_le16(cmd_action);
290
291 if (cmd_action == cmd_act_get) {
Dan Williams90a42212007-05-25 23:01:24 -0400292 cmd->size = cpu_to_le16(S_DS_GEN + sizeof (pkeymaterial->action));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200293 ret = 0;
294 goto done;
295 }
296
297 memset(&pkeymaterial->keyParamSet, 0, sizeof(pkeymaterial->keyParamSet));
298
Dan Williams90a42212007-05-25 23:01:24 -0400299 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200300 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
Dan Williams90a42212007-05-25 23:01:24 -0400301 &assoc_req->wpa_unicast_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200302 index++;
303 }
304
Dan Williams90a42212007-05-25 23:01:24 -0400305 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200306 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
Dan Williams90a42212007-05-25 23:01:24 -0400307 &assoc_req->wpa_mcast_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200308 index++;
309 }
310
311 cmd->size = cpu_to_le16( S_DS_GEN
Dan Williams90a42212007-05-25 23:01:24 -0400312 + sizeof (pkeymaterial->action)
313 + (index * sizeof(struct MrvlIEtype_keyParamSet)));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200314
315 ret = 0;
316
317done:
Holger Schurig9012b282007-05-25 11:27:16 -0400318 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200319 return ret;
320}
321
322static int wlan_cmd_802_11_reset(wlan_private * priv,
323 struct cmd_ds_command *cmd, int cmd_action)
324{
325 struct cmd_ds_802_11_reset *reset = &cmd->params.reset;
326
327 cmd->command = cpu_to_le16(cmd_802_11_reset);
328 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
329 reset->action = cpu_to_le16(cmd_action);
330
331 return 0;
332}
333
334static int wlan_cmd_802_11_get_log(wlan_private * priv,
335 struct cmd_ds_command *cmd)
336{
337 cmd->command = cpu_to_le16(cmd_802_11_get_log);
338 cmd->size =
339 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_log) + S_DS_GEN);
340
341 return 0;
342}
343
344static int wlan_cmd_802_11_get_stat(wlan_private * priv,
345 struct cmd_ds_command *cmd)
346{
347 cmd->command = cpu_to_le16(cmd_802_11_get_stat);
348 cmd->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400349 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200350
351 return 0;
352}
353
354static int wlan_cmd_802_11_snmp_mib(wlan_private * priv,
355 struct cmd_ds_command *cmd,
356 int cmd_action,
357 int cmd_oid, void *pdata_buf)
358{
359 struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib;
360 wlan_adapter *adapter = priv->adapter;
361 u8 ucTemp;
362
Holger Schurig9012b282007-05-25 11:27:16 -0400363 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200364
Holger Schurig9012b282007-05-25 11:27:16 -0400365 lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200366
367 cmd->command = cpu_to_le16(cmd_802_11_snmp_mib);
David Woodhouse981f1872007-05-25 23:36:54 -0400368 cmd->size = cpu_to_le16(sizeof(*pSNMPMIB) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200369
370 switch (cmd_oid) {
371 case OID_802_11_INFRASTRUCTURE_MODE:
372 {
Dan Williams0dc5a292007-05-10 22:58:02 -0400373 u8 mode = (u8) (size_t) pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200374 pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
375 pSNMPMIB->oid = cpu_to_le16((u16) desired_bsstype_i);
376 pSNMPMIB->bufsize = sizeof(u8);
Dan Williams0dc5a292007-05-10 22:58:02 -0400377 if (mode == IW_MODE_ADHOC) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200378 ucTemp = SNMP_MIB_VALUE_ADHOC;
Dan Williams0dc5a292007-05-10 22:58:02 -0400379 } else {
380 /* Infra and Auto modes */
381 ucTemp = SNMP_MIB_VALUE_INFRA;
382 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200383
384 memmove(pSNMPMIB->value, &ucTemp, sizeof(u8));
385
386 break;
387 }
388
389 case OID_802_11D_ENABLE:
390 {
391 u32 ulTemp;
392
393 pSNMPMIB->oid = cpu_to_le16((u16) dot11d_i);
394
395 if (cmd_action == cmd_act_set) {
396 pSNMPMIB->querytype = cmd_act_set;
397 pSNMPMIB->bufsize = sizeof(u16);
398 ulTemp = *(u32 *)pdata_buf;
David Woodhouse981f1872007-05-25 23:36:54 -0400399 *((__le16 *)(pSNMPMIB->value)) =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200400 cpu_to_le16((u16) ulTemp);
401 }
402 break;
403 }
404
405 case OID_802_11_FRAGMENTATION_THRESHOLD:
406 {
407 u32 ulTemp;
408
409 pSNMPMIB->oid = cpu_to_le16((u16) fragthresh_i);
410
411 if (cmd_action == cmd_act_get) {
David Woodhouse981f1872007-05-25 23:36:54 -0400412 pSNMPMIB->querytype = cpu_to_le16(cmd_act_get);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200413 } else if (cmd_action == cmd_act_set) {
David Woodhouse981f1872007-05-25 23:36:54 -0400414 pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
415 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200416 ulTemp = *((u32 *) pdata_buf);
David Woodhouse981f1872007-05-25 23:36:54 -0400417 *((__le16 *)(pSNMPMIB->value)) =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200418 cpu_to_le16((u16) ulTemp);
419
420 }
421
422 break;
423 }
424
425 case OID_802_11_RTS_THRESHOLD:
426 {
427
428 u32 ulTemp;
429 pSNMPMIB->oid = le16_to_cpu((u16) rtsthresh_i);
430
431 if (cmd_action == cmd_act_get) {
David Woodhouse981f1872007-05-25 23:36:54 -0400432 pSNMPMIB->querytype = cpu_to_le16(cmd_act_get);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200433 } else if (cmd_action == cmd_act_set) {
David Woodhouse981f1872007-05-25 23:36:54 -0400434 pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
435 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
436 ulTemp = *((u32 *)pdata_buf);
437 *(__le16 *)(pSNMPMIB->value) =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200438 cpu_to_le16((u16) ulTemp);
439
440 }
441 break;
442 }
443 case OID_802_11_TX_RETRYCOUNT:
444 pSNMPMIB->oid = cpu_to_le16((u16) short_retrylim_i);
445
446 if (cmd_action == cmd_act_get) {
David Woodhouse981f1872007-05-25 23:36:54 -0400447 pSNMPMIB->querytype = cpu_to_le16(cmd_act_get);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200448 } else if (cmd_action == cmd_act_set) {
David Woodhouse981f1872007-05-25 23:36:54 -0400449 pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200450 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
David Woodhouse981f1872007-05-25 23:36:54 -0400451 *((__le16 *)(pSNMPMIB->value)) =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200452 cpu_to_le16((u16) adapter->txretrycount);
453 }
454
455 break;
456 default:
457 break;
458 }
459
Holger Schurig9012b282007-05-25 11:27:16 -0400460 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200461 "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400462 le16_to_cpu(cmd->command), le16_to_cpu(cmd->size),
463 le16_to_cpu(cmd->seqnum), le16_to_cpu(cmd->result));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200464
Holger Schurig9012b282007-05-25 11:27:16 -0400465 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200466 "SNMP_CMD: action=0x%x, oid=0x%x, oidsize=0x%x, value=0x%x\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400467 le16_to_cpu(pSNMPMIB->querytype), le16_to_cpu(pSNMPMIB->oid),
468 le16_to_cpu(pSNMPMIB->bufsize),
469 le16_to_cpu(*(__le16 *) pSNMPMIB->value));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200470
Holger Schurig9012b282007-05-25 11:27:16 -0400471 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200472 return 0;
473}
474
475static int wlan_cmd_802_11_radio_control(wlan_private * priv,
476 struct cmd_ds_command *cmd,
477 int cmd_action)
478{
479 wlan_adapter *adapter = priv->adapter;
David Woodhouse981f1872007-05-25 23:36:54 -0400480 struct cmd_ds_802_11_radio_control *pradiocontrol = &cmd->params.radio;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481
Holger Schurig9012b282007-05-25 11:27:16 -0400482 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200483
484 cmd->size =
485 cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control)) +
486 S_DS_GEN);
487 cmd->command = cpu_to_le16(cmd_802_11_radio_control);
488
489 pradiocontrol->action = cpu_to_le16(cmd_action);
490
491 switch (adapter->preamble) {
492 case cmd_type_short_preamble:
493 pradiocontrol->control = cpu_to_le16(SET_SHORT_PREAMBLE);
494 break;
495
496 case cmd_type_long_preamble:
497 pradiocontrol->control = cpu_to_le16(SET_LONG_PREAMBLE);
498 break;
499
500 case cmd_type_auto_preamble:
501 default:
502 pradiocontrol->control = cpu_to_le16(SET_AUTO_PREAMBLE);
503 break;
504 }
505
506 if (adapter->radioon)
507 pradiocontrol->control |= cpu_to_le16(TURN_ON_RF);
508 else
509 pradiocontrol->control &= cpu_to_le16(~TURN_ON_RF);
510
Holger Schurig9012b282007-05-25 11:27:16 -0400511 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200512 return 0;
513}
514
515static int wlan_cmd_802_11_rf_tx_power(wlan_private * priv,
516 struct cmd_ds_command *cmd,
517 u16 cmd_action, void *pdata_buf)
518{
519
520 struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
521
Holger Schurig9012b282007-05-25 11:27:16 -0400522 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200523
524 cmd->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400525 cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200526 cmd->command = cpu_to_le16(cmd_802_11_rf_tx_power);
David Woodhouse981f1872007-05-25 23:36:54 -0400527 prtp->action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200528
David Woodhouse981f1872007-05-25 23:36:54 -0400529 lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
530 le16_to_cpu(cmd->size), le16_to_cpu(cmd->command),
531 le16_to_cpu(prtp->action));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200532
533 switch (cmd_action) {
534 case cmd_act_tx_power_opt_get:
535 prtp->action = cpu_to_le16(cmd_act_get);
536 prtp->currentlevel = 0;
537 break;
538
539 case cmd_act_tx_power_opt_set_high:
540 prtp->action = cpu_to_le16(cmd_act_set);
David Woodhouse981f1872007-05-25 23:36:54 -0400541 prtp->currentlevel = cpu_to_le16(cmd_act_tx_power_index_high);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200542 break;
543
544 case cmd_act_tx_power_opt_set_mid:
545 prtp->action = cpu_to_le16(cmd_act_set);
David Woodhouse981f1872007-05-25 23:36:54 -0400546 prtp->currentlevel = cpu_to_le16(cmd_act_tx_power_index_mid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200547 break;
548
549 case cmd_act_tx_power_opt_set_low:
550 prtp->action = cpu_to_le16(cmd_act_set);
551 prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
552 break;
553 }
Holger Schurig9012b282007-05-25 11:27:16 -0400554
555 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200556 return 0;
557}
558
559static int wlan_cmd_802_11_rf_antenna(wlan_private * priv,
560 struct cmd_ds_command *cmd,
561 u16 cmd_action, void *pdata_buf)
562{
563 struct cmd_ds_802_11_rf_antenna *rant = &cmd->params.rant;
564
565 cmd->command = cpu_to_le16(cmd_802_11_rf_antenna);
David Woodhouse981f1872007-05-25 23:36:54 -0400566 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_antenna) +
567 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200568
569 rant->action = cpu_to_le16(cmd_action);
David Woodhouse981f1872007-05-25 23:36:54 -0400570 if ((cmd_action == cmd_act_set_rx) || (cmd_action == cmd_act_set_tx)) {
571 rant->antennamode = cpu_to_le16((u16) (*(u32 *) pdata_buf));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200572 }
573
574 return 0;
575}
576
577static int wlan_cmd_802_11_rate_adapt_rateset(wlan_private * priv,
578 struct cmd_ds_command *cmd,
579 u16 cmd_action)
580{
581 struct cmd_ds_802_11_rate_adapt_rateset
582 *rateadapt = &cmd->params.rateset;
583 wlan_adapter *adapter = priv->adapter;
584
585 cmd->size =
586 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
587 + S_DS_GEN);
588 cmd->command = cpu_to_le16(cmd_802_11_rate_adapt_rateset);
589
Holger Schurig9012b282007-05-25 11:27:16 -0400590 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200591
David Woodhouse981f1872007-05-25 23:36:54 -0400592 rateadapt->action = cpu_to_le16(cmd_action);
593 rateadapt->enablehwauto = cpu_to_le16(adapter->enablehwauto);
594 rateadapt->bitmap = cpu_to_le16(adapter->ratebitmap);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200595
Holger Schurig9012b282007-05-25 11:27:16 -0400596 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200597 return 0;
598}
599
600static int wlan_cmd_802_11_data_rate(wlan_private * priv,
601 struct cmd_ds_command *cmd,
602 u16 cmd_action)
603{
604 struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
605 wlan_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200606
Holger Schurig9012b282007-05-25 11:27:16 -0400607 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200608
David Woodhouse981f1872007-05-25 23:36:54 -0400609 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200610 S_DS_GEN);
611
612 cmd->command = cpu_to_le16(cmd_802_11_data_rate);
613
614 memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate));
615
616 pdatarate->action = cpu_to_le16(cmd_action);
617
David Woodhouse981f1872007-05-25 23:36:54 -0400618 if (cmd_action == cmd_act_set_tx_fix_rate) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200619 pdatarate->datarate[0] = libertas_data_rate_to_index(adapter->datarate);
Holger Schurig9012b282007-05-25 11:27:16 -0400620 lbs_deb_cmd("Setting FW for fixed rate 0x%02X\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200621 adapter->datarate);
David Woodhouse981f1872007-05-25 23:36:54 -0400622 } else if (cmd_action == cmd_act_set_tx_auto) {
Holger Schurig9012b282007-05-25 11:27:16 -0400623 lbs_deb_cmd("Setting FW for AUTO rate\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200624 }
625
Holger Schurig9012b282007-05-25 11:27:16 -0400626 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200627 return 0;
628}
629
630static int wlan_cmd_mac_multicast_adr(wlan_private * priv,
631 struct cmd_ds_command *cmd,
632 u16 cmd_action)
633{
634 struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
635 wlan_adapter *adapter = priv->adapter;
636
David Woodhouse981f1872007-05-25 23:36:54 -0400637 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200638 S_DS_GEN);
639 cmd->command = cpu_to_le16(cmd_mac_multicast_adr);
640
641 pMCastAdr->action = cpu_to_le16(cmd_action);
642 pMCastAdr->nr_of_adrs =
643 cpu_to_le16((u16) adapter->nr_of_multicastmacaddr);
644 memcpy(pMCastAdr->maclist, adapter->multicastlist,
645 adapter->nr_of_multicastmacaddr * ETH_ALEN);
646
647 return 0;
648}
649
650static int wlan_cmd_802_11_rf_channel(wlan_private * priv,
651 struct cmd_ds_command *cmd,
652 int option, void *pdata_buf)
653{
654 struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel;
655
656 cmd->command = cpu_to_le16(cmd_802_11_rf_channel);
David Woodhouse981f1872007-05-25 23:36:54 -0400657 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel) +
658 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200659
660 if (option == cmd_opt_802_11_rf_channel_set) {
661 rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf));
662 }
663
664 rfchan->action = cpu_to_le16(option);
665
666 return 0;
667}
668
669static int wlan_cmd_802_11_rssi(wlan_private * priv,
670 struct cmd_ds_command *cmd)
671{
672 wlan_adapter *adapter = priv->adapter;
673
674 cmd->command = cpu_to_le16(cmd_802_11_rssi);
David Woodhouse981f1872007-05-25 23:36:54 -0400675 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
676 cmd->params.rssi.N = cpu_to_le16(priv->adapter->bcn_avg_factor);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200677
678 /* reset Beacon SNR/NF/RSSI values */
679 adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
680 adapter->SNR[TYPE_BEACON][TYPE_AVG] = 0;
681 adapter->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
682 adapter->NF[TYPE_BEACON][TYPE_AVG] = 0;
683 adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
684 adapter->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
685
686 return 0;
687}
688
689static int wlan_cmd_reg_access(wlan_private * priv,
690 struct cmd_ds_command *cmdptr,
691 u8 cmd_action, void *pdata_buf)
692{
693 struct wlan_offset_value *offval;
694
Holger Schurig9012b282007-05-25 11:27:16 -0400695 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200696
697 offval = (struct wlan_offset_value *)pdata_buf;
698
699 switch (cmdptr->command) {
700 case cmd_mac_reg_access:
701 {
702 struct cmd_ds_mac_reg_access *macreg;
703
704 cmdptr->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400705 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
706 + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200707 macreg =
708 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
709 macreg;
710
711 macreg->action = cpu_to_le16(cmd_action);
712 macreg->offset = cpu_to_le16((u16) offval->offset);
713 macreg->value = cpu_to_le32(offval->value);
714
715 break;
716 }
717
718 case cmd_bbp_reg_access:
719 {
720 struct cmd_ds_bbp_reg_access *bbpreg;
721
722 cmdptr->size =
723 cpu_to_le16(sizeof
724 (struct cmd_ds_bbp_reg_access)
725 + S_DS_GEN);
726 bbpreg =
727 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
728 bbpreg;
729
730 bbpreg->action = cpu_to_le16(cmd_action);
731 bbpreg->offset = cpu_to_le16((u16) offval->offset);
732 bbpreg->value = (u8) offval->value;
733
734 break;
735 }
736
737 case cmd_rf_reg_access:
738 {
739 struct cmd_ds_rf_reg_access *rfreg;
740
741 cmdptr->size =
742 cpu_to_le16(sizeof
743 (struct cmd_ds_rf_reg_access) +
744 S_DS_GEN);
745 rfreg =
746 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
747 rfreg;
748
749 rfreg->action = cpu_to_le16(cmd_action);
750 rfreg->offset = cpu_to_le16((u16) offval->offset);
751 rfreg->value = (u8) offval->value;
752
753 break;
754 }
755
756 default:
757 break;
758 }
759
Holger Schurig9012b282007-05-25 11:27:16 -0400760 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200761 return 0;
762}
763
764static int wlan_cmd_802_11_mac_address(wlan_private * priv,
765 struct cmd_ds_command *cmd,
766 u16 cmd_action)
767{
768 wlan_adapter *adapter = priv->adapter;
769
770 cmd->command = cpu_to_le16(cmd_802_11_mac_address);
David Woodhouse981f1872007-05-25 23:36:54 -0400771 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200772 S_DS_GEN);
773 cmd->result = 0;
774
775 cmd->params.macadd.action = cpu_to_le16(cmd_action);
776
777 if (cmd_action == cmd_act_set) {
778 memcpy(cmd->params.macadd.macadd,
779 adapter->current_addr, ETH_ALEN);
780 lbs_dbg_hex("SET_CMD: MAC ADDRESS-", adapter->current_addr, 6);
781 }
782
783 return 0;
784}
785
786static int wlan_cmd_802_11_eeprom_access(wlan_private * priv,
787 struct cmd_ds_command *cmd,
788 int cmd_action, void *pdata_buf)
789{
790 struct wlan_ioctl_regrdwr *ea = pdata_buf;
791
Holger Schurig9012b282007-05-25 11:27:16 -0400792 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200793
794 cmd->command = cpu_to_le16(cmd_802_11_eeprom_access);
David Woodhouse981f1872007-05-25 23:36:54 -0400795 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
796 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200797 cmd->result = 0;
798
799 cmd->params.rdeeprom.action = cpu_to_le16(ea->action);
800 cmd->params.rdeeprom.offset = cpu_to_le16(ea->offset);
801 cmd->params.rdeeprom.bytecount = cpu_to_le16(ea->NOB);
802 cmd->params.rdeeprom.value = 0;
803
804 return 0;
805}
806
807static int wlan_cmd_bt_access(wlan_private * priv,
808 struct cmd_ds_command *cmd,
809 u16 cmd_action, void *pdata_buf)
810{
811 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
Holger Schurig9012b282007-05-25 11:27:16 -0400812 lbs_deb_cmd("BT CMD(%d)\n", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200813
814 cmd->command = cpu_to_le16(cmd_bt_access);
David Woodhouse981f1872007-05-25 23:36:54 -0400815 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200816 cmd->result = 0;
817 bt_access->action = cpu_to_le16(cmd_action);
818
819 switch (cmd_action) {
820 case cmd_act_bt_access_add:
821 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
822 lbs_dbg_hex("BT_ADD: blinded mac address-", bt_access->addr1, 6);
823 break;
824 case cmd_act_bt_access_del:
825 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
826 lbs_dbg_hex("BT_DEL: blinded mac address-", bt_access->addr1, 6);
827 break;
828 case cmd_act_bt_access_list:
829 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
830 break;
831 case cmd_act_bt_access_reset:
832 break;
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -0400833 case cmd_act_bt_access_set_invert:
834 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
835 break;
836 case cmd_act_bt_access_get_invert:
837 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200838 default:
839 break;
840 }
841 return 0;
842}
843
844static int wlan_cmd_fwt_access(wlan_private * priv,
845 struct cmd_ds_command *cmd,
846 u16 cmd_action, void *pdata_buf)
847{
848 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
Holger Schurig9012b282007-05-25 11:27:16 -0400849 lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200850
851 cmd->command = cpu_to_le16(cmd_fwt_access);
David Woodhouse981f1872007-05-25 23:36:54 -0400852 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200853 cmd->result = 0;
854
855 if (pdata_buf)
856 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
857 else
858 memset(fwt_access, 0, sizeof(*fwt_access));
859
860 fwt_access->action = cpu_to_le16(cmd_action);
861
862 return 0;
863}
864
865static int wlan_cmd_mesh_access(wlan_private * priv,
866 struct cmd_ds_command *cmd,
867 u16 cmd_action, void *pdata_buf)
868{
869 struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
Holger Schurig9012b282007-05-25 11:27:16 -0400870 lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200871
872 cmd->command = cpu_to_le16(cmd_mesh_access);
David Woodhouse981f1872007-05-25 23:36:54 -0400873 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200874 cmd->result = 0;
875
876 if (pdata_buf)
877 memcpy(mesh_access, pdata_buf, sizeof(*mesh_access));
878 else
879 memset(mesh_access, 0, sizeof(*mesh_access));
880
881 mesh_access->action = cpu_to_le16(cmd_action);
882
883 return 0;
884}
885
886void libertas_queue_cmd(wlan_adapter * adapter, struct cmd_ctrl_node *cmdnode, u8 addtail)
887{
888 unsigned long flags;
889 struct cmd_ds_command *cmdptr;
890
Holger Schurig9012b282007-05-25 11:27:16 -0400891 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200892
893 if (!cmdnode) {
Holger Schurig9012b282007-05-25 11:27:16 -0400894 lbs_deb_cmd("QUEUE_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200895 goto done;
896 }
897
898 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
899 if (!cmdptr) {
Holger Schurig9012b282007-05-25 11:27:16 -0400900 lbs_deb_cmd("QUEUE_CMD: cmdptr is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200901 goto done;
902 }
903
904 /* Exit_PS command needs to be queued in the header always. */
905 if (cmdptr->command == cmd_802_11_ps_mode) {
906 struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
David Woodhouse981f1872007-05-25 23:36:54 -0400907 if (psm->action == cpu_to_le16(cmd_subcmd_exit_ps)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200908 if (adapter->psstate != PS_STATE_FULL_POWER)
909 addtail = 0;
910 }
911 }
912
913 spin_lock_irqsave(&adapter->driver_lock, flags);
914
915 if (addtail)
916 list_add_tail((struct list_head *)cmdnode,
917 &adapter->cmdpendingq);
918 else
919 list_add((struct list_head *)cmdnode, &adapter->cmdpendingq);
920
921 spin_unlock_irqrestore(&adapter->driver_lock, flags);
922
Holger Schurig9012b282007-05-25 11:27:16 -0400923 lbs_deb_cmd("QUEUE_CMD: Inserted node=%p, cmd=0x%x in cmdpendingq\n",
Dan Williams4269e2a2007-05-10 23:10:18 -0400924 cmdnode,
David Woodhouse981f1872007-05-25 23:36:54 -0400925 le16_to_cpu(((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200926
927done:
Holger Schurig9012b282007-05-25 11:27:16 -0400928 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200929}
930
931/*
932 * TODO: Fix the issue when DownloadcommandToStation is being called the
933 * second time when the command timesout. All the cmdptr->xxx are in little
934 * endian and therefore all the comparissions will fail.
935 * For now - we are not performing the endian conversion the second time - but
936 * for PS and DEEP_SLEEP we need to worry
937 */
938static int DownloadcommandToStation(wlan_private * priv,
939 struct cmd_ctrl_node *cmdnode)
940{
941 unsigned long flags;
942 struct cmd_ds_command *cmdptr;
943 wlan_adapter *adapter = priv->adapter;
944 int ret = 0;
945 u16 cmdsize;
946 u16 command;
947
Holger Schurig9012b282007-05-25 11:27:16 -0400948 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200949
950 if (!adapter || !cmdnode) {
Holger Schurig9012b282007-05-25 11:27:16 -0400951 lbs_deb_cmd("DNLD_CMD: adapter = %p, cmdnode = %p\n",
Dan Williams4269e2a2007-05-10 23:10:18 -0400952 adapter, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200953 if (cmdnode) {
954 spin_lock_irqsave(&adapter->driver_lock, flags);
955 __libertas_cleanup_and_insert_cmd(priv, cmdnode);
956 spin_unlock_irqrestore(&adapter->driver_lock, flags);
957 }
958 ret = -1;
959 goto done;
960 }
961
962 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
963
964
965 spin_lock_irqsave(&adapter->driver_lock, flags);
966 if (!cmdptr || !cmdptr->size) {
Holger Schurig9012b282007-05-25 11:27:16 -0400967 lbs_deb_cmd("DNLD_CMD: cmdptr is Null or cmd size is Zero, "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200968 "Not sending\n");
969 __libertas_cleanup_and_insert_cmd(priv, cmdnode);
970 spin_unlock_irqrestore(&adapter->driver_lock, flags);
971 ret = -1;
972 goto done;
973 }
974
975 adapter->cur_cmd = cmdnode;
976 adapter->cur_cmd_retcode = 0;
977 spin_unlock_irqrestore(&adapter->driver_lock, flags);
Holger Schurig9012b282007-05-25 11:27:16 -0400978 lbs_deb_cmd("DNLD_CMD:: Before download, size of cmd = %d\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400979 le16_to_cpu(cmdptr->size));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200980
981 cmdsize = cmdptr->size;
982
983 command = cpu_to_le16(cmdptr->command);
984
985 cmdnode->cmdwaitqwoken = 0;
986 cmdsize = cpu_to_le16(cmdsize);
987
Holger Schurig208fdd22007-05-25 12:17:06 -0400988 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200989
990 if (ret != 0) {
Holger Schurig9012b282007-05-25 11:27:16 -0400991 lbs_deb_cmd("DNLD_CMD: Host to Card failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200992 spin_lock_irqsave(&adapter->driver_lock, flags);
993 __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
994 adapter->cur_cmd = NULL;
995 spin_unlock_irqrestore(&adapter->driver_lock, flags);
996 ret = -1;
997 goto done;
998 }
999
Holger Schurig9012b282007-05-25 11:27:16 -04001000 lbs_deb_cmd("DNLD_CMD: Sent command 0x%x @ %lu\n", command, jiffies);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001001 lbs_dbg_hex("DNLD_CMD: command", cmdnode->bufvirtualaddr, cmdsize);
1002
1003 /* Setup the timer after transmit command */
David Woodhouse981f1872007-05-25 23:36:54 -04001004 if (command == cmd_802_11_scan || command == cmd_802_11_authenticate
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001005 || command == cmd_802_11_associate)
1006 mod_timer(&adapter->command_timer, jiffies + (10*HZ));
1007 else
1008 mod_timer(&adapter->command_timer, jiffies + (5*HZ));
1009
1010 ret = 0;
1011
Holger Schurig9012b282007-05-25 11:27:16 -04001012done:
1013 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001014 return ret;
1015}
1016
1017static int wlan_cmd_mac_control(wlan_private * priv,
1018 struct cmd_ds_command *cmd)
1019{
1020 struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
1021
Holger Schurig9012b282007-05-25 11:27:16 -04001022 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001023
1024 cmd->command = cpu_to_le16(cmd_mac_control);
David Woodhouse981f1872007-05-25 23:36:54 -04001025 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001026 mac->action = cpu_to_le16(priv->adapter->currentpacketfilter);
1027
Holger Schurig9012b282007-05-25 11:27:16 -04001028 lbs_deb_cmd("wlan_cmd_mac_control(): action=0x%X size=%d\n",
David Woodhouse981f1872007-05-25 23:36:54 -04001029 le16_to_cpu(mac->action), le16_to_cpu(cmd->size));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001030
Holger Schurig9012b282007-05-25 11:27:16 -04001031 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001032 return 0;
1033}
1034
1035/**
1036 * This function inserts command node to cmdfreeq
1037 * after cleans it. Requires adapter->driver_lock held.
1038 */
1039void __libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
1040{
1041 wlan_adapter *adapter = priv->adapter;
1042
1043 if (!ptempcmd)
1044 goto done;
1045
1046 cleanup_cmdnode(ptempcmd);
1047 list_add_tail((struct list_head *)ptempcmd, &adapter->cmdfreeq);
1048done:
1049 return;
1050}
1051
1052void libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
1053{
1054 unsigned long flags;
1055
1056 spin_lock_irqsave(&priv->adapter->driver_lock, flags);
1057 __libertas_cleanup_and_insert_cmd(priv, ptempcmd);
1058 spin_unlock_irqrestore(&priv->adapter->driver_lock, flags);
1059}
1060
1061int libertas_set_radio_control(wlan_private * priv)
1062{
1063 int ret = 0;
1064
Holger Schurig9012b282007-05-25 11:27:16 -04001065 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001066
1067 ret = libertas_prepare_and_send_command(priv,
1068 cmd_802_11_radio_control,
1069 cmd_act_set,
1070 cmd_option_waitforrsp, 0, NULL);
1071
Holger Schurig9012b282007-05-25 11:27:16 -04001072 lbs_deb_cmd("RADIO_SET: on or off: 0x%X, preamble = 0x%X\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001073 priv->adapter->radioon, priv->adapter->preamble);
1074
Holger Schurig9012b282007-05-25 11:27:16 -04001075 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001076 return ret;
1077}
1078
1079int libertas_set_mac_packet_filter(wlan_private * priv)
1080{
1081 int ret = 0;
1082
Holger Schurig9012b282007-05-25 11:27:16 -04001083 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001084
Holger Schurig9012b282007-05-25 11:27:16 -04001085 lbs_deb_cmd("libertas_set_mac_packet_filter value = %x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001086 priv->adapter->currentpacketfilter);
1087
1088 /* Send MAC control command to station */
1089 ret = libertas_prepare_and_send_command(priv,
1090 cmd_mac_control, 0, 0, 0, NULL);
1091
Holger Schurig9012b282007-05-25 11:27:16 -04001092 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001093 return ret;
1094}
1095
1096/**
1097 * @brief This function prepare the command before send to firmware.
1098 *
1099 * @param priv A pointer to wlan_private structure
1100 * @param cmd_no command number
1101 * @param cmd_action command action: GET or SET
1102 * @param wait_option wait option: wait response or not
1103 * @param cmd_oid cmd oid: treated as sub command
1104 * @param pdata_buf A pointer to informaion buffer
1105 * @return 0 or -1
1106 */
1107int libertas_prepare_and_send_command(wlan_private * priv,
1108 u16 cmd_no,
1109 u16 cmd_action,
1110 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1111{
1112 int ret = 0;
1113 wlan_adapter *adapter = priv->adapter;
1114 struct cmd_ctrl_node *cmdnode;
1115 struct cmd_ds_command *cmdptr;
1116 unsigned long flags;
1117
Holger Schurig9012b282007-05-25 11:27:16 -04001118 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001119
1120 if (!adapter) {
Holger Schurig9012b282007-05-25 11:27:16 -04001121 lbs_deb_cmd("PREP_CMD: adapter is Null\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001122 ret = -1;
1123 goto done;
1124 }
1125
1126 if (adapter->surpriseremoved) {
Holger Schurig9012b282007-05-25 11:27:16 -04001127 lbs_deb_cmd("PREP_CMD: Card is Removed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001128 ret = -1;
1129 goto done;
1130 }
1131
1132 cmdnode = libertas_get_free_cmd_ctrl_node(priv);
1133
1134 if (cmdnode == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -04001135 lbs_deb_cmd("PREP_CMD: No free cmdnode\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001136
1137 /* Wake up main thread to execute next command */
1138 wake_up_interruptible(&priv->mainthread.waitq);
1139 ret = -1;
1140 goto done;
1141 }
1142
1143 libertas_set_cmd_ctrl_node(priv, cmdnode, cmd_oid, wait_option, pdata_buf);
1144
1145 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1146
Holger Schurig9012b282007-05-25 11:27:16 -04001147 lbs_deb_cmd("PREP_CMD: Val of cmd ptr=%p, command=0x%X\n",
Dan Williams4269e2a2007-05-10 23:10:18 -04001148 cmdptr, cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001149
1150 if (!cmdptr) {
Holger Schurig9012b282007-05-25 11:27:16 -04001151 lbs_deb_cmd("PREP_CMD: bufvirtualaddr of cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001152 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1153 ret = -1;
1154 goto done;
1155 }
1156
1157 /* Set sequence number, command and INT option */
1158 adapter->seqnum++;
1159 cmdptr->seqnum = cpu_to_le16(adapter->seqnum);
1160
David Woodhouse981f1872007-05-25 23:36:54 -04001161 cmdptr->command = cpu_to_le16(cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001162 cmdptr->result = 0;
1163
1164 switch (cmd_no) {
1165 case cmd_get_hw_spec:
1166 ret = wlan_cmd_hw_spec(priv, cmdptr);
1167 break;
1168 case cmd_802_11_ps_mode:
1169 ret = wlan_cmd_802_11_ps_mode(priv, cmdptr, cmd_action);
1170 break;
1171
1172 case cmd_802_11_scan:
1173 ret = libertas_cmd_80211_scan(priv, cmdptr, pdata_buf);
1174 break;
1175
1176 case cmd_mac_control:
1177 ret = wlan_cmd_mac_control(priv, cmdptr);
1178 break;
1179
1180 case cmd_802_11_associate:
1181 case cmd_802_11_reassociate:
1182 ret = libertas_cmd_80211_associate(priv, cmdptr, pdata_buf);
1183 break;
1184
1185 case cmd_802_11_deauthenticate:
1186 ret = libertas_cmd_80211_deauthenticate(priv, cmdptr);
1187 break;
1188
1189 case cmd_802_11_set_wep:
1190 ret = wlan_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf);
1191 break;
1192
1193 case cmd_802_11_ad_hoc_start:
1194 ret = libertas_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
1195 break;
1196 case cmd_code_dnld:
1197 break;
1198
1199 case cmd_802_11_reset:
1200 ret = wlan_cmd_802_11_reset(priv, cmdptr, cmd_action);
1201 break;
1202
1203 case cmd_802_11_get_log:
1204 ret = wlan_cmd_802_11_get_log(priv, cmdptr);
1205 break;
1206
1207 case cmd_802_11_authenticate:
1208 ret = libertas_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
1209 break;
1210
1211 case cmd_802_11_get_stat:
1212 ret = wlan_cmd_802_11_get_stat(priv, cmdptr);
1213 break;
1214
1215 case cmd_802_11_snmp_mib:
1216 ret = wlan_cmd_802_11_snmp_mib(priv, cmdptr,
1217 cmd_action, cmd_oid, pdata_buf);
1218 break;
1219
1220 case cmd_mac_reg_access:
1221 case cmd_bbp_reg_access:
1222 case cmd_rf_reg_access:
1223 ret = wlan_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf);
1224 break;
1225
1226 case cmd_802_11_rf_channel:
1227 ret = wlan_cmd_802_11_rf_channel(priv, cmdptr,
1228 cmd_action, pdata_buf);
1229 break;
1230
1231 case cmd_802_11_rf_tx_power:
1232 ret = wlan_cmd_802_11_rf_tx_power(priv, cmdptr,
1233 cmd_action, pdata_buf);
1234 break;
1235
1236 case cmd_802_11_radio_control:
1237 ret = wlan_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
1238 break;
1239
1240 case cmd_802_11_rf_antenna:
1241 ret = wlan_cmd_802_11_rf_antenna(priv, cmdptr,
1242 cmd_action, pdata_buf);
1243 break;
1244
1245 case cmd_802_11_data_rate:
1246 ret = wlan_cmd_802_11_data_rate(priv, cmdptr, cmd_action);
1247 break;
1248 case cmd_802_11_rate_adapt_rateset:
1249 ret = wlan_cmd_802_11_rate_adapt_rateset(priv,
1250 cmdptr, cmd_action);
1251 break;
1252
1253 case cmd_mac_multicast_adr:
1254 ret = wlan_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
1255 break;
1256
1257 case cmd_802_11_ad_hoc_join:
1258 ret = libertas_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
1259 break;
1260
1261 case cmd_802_11_rssi:
1262 ret = wlan_cmd_802_11_rssi(priv, cmdptr);
1263 break;
1264
1265 case cmd_802_11_ad_hoc_stop:
1266 ret = libertas_cmd_80211_ad_hoc_stop(priv, cmdptr);
1267 break;
1268
1269 case cmd_802_11_enable_rsn:
Dan Williams90a42212007-05-25 23:01:24 -04001270 ret = wlan_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action,
1271 pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001272 break;
1273
1274 case cmd_802_11_key_material:
Dan Williams90a42212007-05-25 23:01:24 -04001275 ret = wlan_cmd_802_11_key_material(priv, cmdptr, cmd_action,
1276 cmd_oid, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001277 break;
1278
1279 case cmd_802_11_pairwise_tsc:
1280 break;
1281 case cmd_802_11_group_tsc:
1282 break;
1283
1284 case cmd_802_11_mac_address:
1285 ret = wlan_cmd_802_11_mac_address(priv, cmdptr, cmd_action);
1286 break;
1287
1288 case cmd_802_11_eeprom_access:
1289 ret = wlan_cmd_802_11_eeprom_access(priv, cmdptr,
1290 cmd_action, pdata_buf);
1291 break;
1292
1293 case cmd_802_11_set_afc:
1294 case cmd_802_11_get_afc:
1295
1296 cmdptr->command = cpu_to_le16(cmd_no);
David Woodhouse981f1872007-05-25 23:36:54 -04001297 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1298 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001299
1300 memmove(&cmdptr->params.afc,
1301 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1302
1303 ret = 0;
1304 goto done;
1305
1306 case cmd_802_11d_domain_info:
1307 ret = libertas_cmd_802_11d_domain_info(priv, cmdptr,
1308 cmd_no, cmd_action);
1309 break;
1310
1311 case cmd_802_11_sleep_params:
1312 ret = wlan_cmd_802_11_sleep_params(priv, cmdptr, cmd_action);
1313 break;
1314 case cmd_802_11_inactivity_timeout:
1315 ret = wlan_cmd_802_11_inactivity_timeout(priv, cmdptr,
1316 cmd_action, pdata_buf);
1317 libertas_set_cmd_ctrl_node(priv, cmdnode, 0, 0, pdata_buf);
1318 break;
1319
1320 case cmd_802_11_tpc_cfg:
1321 cmdptr->command = cpu_to_le16(cmd_802_11_tpc_cfg);
1322 cmdptr->size =
1323 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1324 S_DS_GEN);
1325
1326 memmove(&cmdptr->params.tpccfg,
1327 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1328
1329 ret = 0;
1330 break;
1331 case cmd_802_11_led_gpio_ctrl:
1332 {
1333 struct mrvlietypes_ledgpio *gpio =
1334 (struct mrvlietypes_ledgpio*)
1335 cmdptr->params.ledgpio.data;
1336
1337 memmove(&cmdptr->params.ledgpio,
1338 pdata_buf,
1339 sizeof(struct cmd_ds_802_11_led_ctrl));
1340
1341 cmdptr->command =
1342 cpu_to_le16(cmd_802_11_led_gpio_ctrl);
1343
1344#define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1345 cmdptr->size =
1346 cpu_to_le16(gpio->header.len + S_DS_GEN +
1347 ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1348 gpio->header.len = cpu_to_le16(gpio->header.len);
1349
1350 ret = 0;
1351 break;
1352 }
1353 case cmd_802_11_pwr_cfg:
1354 cmdptr->command = cpu_to_le16(cmd_802_11_pwr_cfg);
1355 cmdptr->size =
1356 cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) +
1357 S_DS_GEN);
1358 memmove(&cmdptr->params.pwrcfg, pdata_buf,
1359 sizeof(struct cmd_ds_802_11_pwr_cfg));
1360
1361 ret = 0;
1362 break;
1363 case cmd_bt_access:
1364 ret = wlan_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf);
1365 break;
1366
1367 case cmd_fwt_access:
1368 ret = wlan_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf);
1369 break;
1370
1371 case cmd_mesh_access:
1372 ret = wlan_cmd_mesh_access(priv, cmdptr, cmd_action, pdata_buf);
1373 break;
1374
1375 case cmd_get_tsf:
1376 cmdptr->command = cpu_to_le16(cmd_get_tsf);
David Woodhouse981f1872007-05-25 23:36:54 -04001377 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1378 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001379 ret = 0;
1380 break;
1381 case cmd_802_11_tx_rate_query:
David Woodhouse981f1872007-05-25 23:36:54 -04001382 cmdptr->command = cpu_to_le16(cmd_802_11_tx_rate_query);
1383 cmdptr->size = cpu_to_le16(sizeof(struct cmd_tx_rate_query) +
1384 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001385 adapter->txrate = 0;
1386 ret = 0;
1387 break;
1388 default:
Holger Schurig9012b282007-05-25 11:27:16 -04001389 lbs_deb_cmd("PREP_CMD: unknown command- %#x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001390 ret = -1;
1391 break;
1392 }
1393
1394 /* return error, since the command preparation failed */
1395 if (ret != 0) {
Holger Schurig9012b282007-05-25 11:27:16 -04001396 lbs_deb_cmd("PREP_CMD: command preparation failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001397 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1398 ret = -1;
1399 goto done;
1400 }
1401
1402 cmdnode->cmdwaitqwoken = 0;
1403
1404 libertas_queue_cmd(adapter, cmdnode, 1);
1405 adapter->nr_cmd_pending++;
1406 wake_up_interruptible(&priv->mainthread.waitq);
1407
1408 if (wait_option & cmd_option_waitforrsp) {
Holger Schurig9012b282007-05-25 11:27:16 -04001409 lbs_deb_cmd("PREP_CMD: Wait for CMD response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001410 might_sleep();
1411 wait_event_interruptible(cmdnode->cmdwait_q,
1412 cmdnode->cmdwaitqwoken);
1413 }
1414
1415 spin_lock_irqsave(&adapter->driver_lock, flags);
1416 if (adapter->cur_cmd_retcode) {
Holger Schurig9012b282007-05-25 11:27:16 -04001417 lbs_deb_cmd("PREP_CMD: command failed with return code=%d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001418 adapter->cur_cmd_retcode);
1419 adapter->cur_cmd_retcode = 0;
1420 ret = -1;
1421 }
1422 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1423
1424done:
Holger Schurig9012b282007-05-25 11:27:16 -04001425 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001426 return ret;
1427}
Holger Schurig084708b2007-05-25 12:37:58 -04001428EXPORT_SYMBOL_GPL(libertas_prepare_and_send_command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001429
1430/**
1431 * @brief This function allocates the command buffer and link
1432 * it to command free queue.
1433 *
1434 * @param priv A pointer to wlan_private structure
1435 * @return 0 or -1
1436 */
1437int libertas_allocate_cmd_buffer(wlan_private * priv)
1438{
1439 int ret = 0;
1440 u32 ulbufsize;
1441 u32 i;
1442 struct cmd_ctrl_node *tempcmd_array;
1443 u8 *ptempvirtualaddr;
1444 wlan_adapter *adapter = priv->adapter;
1445
Holger Schurig9012b282007-05-25 11:27:16 -04001446 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001447
1448 /* Allocate and initialize cmdCtrlNode */
1449 ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
1450
Holger Schurigfb3dddf2007-05-25 11:58:22 -04001451 if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) {
Holger Schurig9012b282007-05-25 11:27:16 -04001452 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001453 "ALLOC_CMD_BUF: failed to allocate tempcmd_array\n");
1454 ret = -1;
1455 goto done;
1456 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001457 adapter->cmd_array = tempcmd_array;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001458
1459 /* Allocate and initialize command buffers */
1460 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1461 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
Holger Schurigfb3dddf2007-05-25 11:58:22 -04001462 if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) {
Holger Schurig9012b282007-05-25 11:27:16 -04001463 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001464 "ALLOC_CMD_BUF: ptempvirtualaddr: out of memory\n");
1465 ret = -1;
1466 goto done;
1467 }
1468
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001469 /* Update command buffer virtual */
1470 tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
1471 }
1472
1473 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1474 init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
1475 libertas_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
1476 }
1477
1478 ret = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001479
1480done:
1481 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001482 return ret;
1483}
1484
1485/**
1486 * @brief This function frees the command buffer.
1487 *
1488 * @param priv A pointer to wlan_private structure
1489 * @return 0 or -1
1490 */
1491int libertas_free_cmd_buffer(wlan_private * priv)
1492{
David Woodhouse981f1872007-05-25 23:36:54 -04001493 u32 ulbufsize; /* Someone needs to die for this. Slowly and painfully */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001494 unsigned int i;
1495 struct cmd_ctrl_node *tempcmd_array;
1496 wlan_adapter *adapter = priv->adapter;
1497
Holger Schurig9012b282007-05-25 11:27:16 -04001498 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001499
1500 /* need to check if cmd array is allocated or not */
1501 if (adapter->cmd_array == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -04001502 lbs_deb_cmd("FREE_CMD_BUF: cmd_array is Null\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001503 goto done;
1504 }
1505
1506 tempcmd_array = adapter->cmd_array;
1507
1508 /* Release shared memory buffers */
1509 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1510 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1511 if (tempcmd_array[i].bufvirtualaddr) {
Holger Schurig9012b282007-05-25 11:27:16 -04001512 lbs_deb_cmd("Free all the array\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001513 kfree(tempcmd_array[i].bufvirtualaddr);
1514 tempcmd_array[i].bufvirtualaddr = NULL;
1515 }
1516 }
1517
1518 /* Release cmd_ctrl_node */
1519 if (adapter->cmd_array) {
Holger Schurig9012b282007-05-25 11:27:16 -04001520 lbs_deb_cmd("Free cmd_array\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001521 kfree(adapter->cmd_array);
1522 adapter->cmd_array = NULL;
1523 }
1524
1525done:
Holger Schurig9012b282007-05-25 11:27:16 -04001526 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001527 return 0;
1528}
1529
1530/**
1531 * @brief This function gets a free command node if available in
1532 * command free queue.
1533 *
1534 * @param priv A pointer to wlan_private structure
1535 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1536 */
1537struct cmd_ctrl_node *libertas_get_free_cmd_ctrl_node(wlan_private * priv)
1538{
1539 struct cmd_ctrl_node *tempnode;
1540 wlan_adapter *adapter = priv->adapter;
1541 unsigned long flags;
1542
1543 if (!adapter)
1544 return NULL;
1545
1546 spin_lock_irqsave(&adapter->driver_lock, flags);
1547
1548 if (!list_empty(&adapter->cmdfreeq)) {
1549 tempnode = (struct cmd_ctrl_node *)adapter->cmdfreeq.next;
1550 list_del((struct list_head *)tempnode);
1551 } else {
Holger Schurig9012b282007-05-25 11:27:16 -04001552 lbs_deb_cmd("GET_CMD_NODE: cmd_ctrl_node is not available\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001553 tempnode = NULL;
1554 }
1555
1556 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1557
1558 if (tempnode) {
Holger Schurig9012b282007-05-25 11:27:16 -04001559 /*
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001560 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode available\n");
1561 lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode Address = %p\n",
1562 tempnode);
Holger Schurig9012b282007-05-25 11:27:16 -04001563 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001564 cleanup_cmdnode(tempnode);
1565 }
1566
1567 return tempnode;
1568}
1569
1570/**
1571 * @brief This function cleans command node.
1572 *
1573 * @param ptempnode A pointer to cmdCtrlNode structure
1574 * @return n/a
1575 */
1576static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
1577{
1578 if (!ptempnode)
1579 return;
1580 ptempnode->cmdwaitqwoken = 1;
1581 wake_up_interruptible(&ptempnode->cmdwait_q);
1582 ptempnode->status = 0;
1583 ptempnode->cmd_oid = (u32) 0;
1584 ptempnode->wait_option = 0;
1585 ptempnode->pdata_buf = NULL;
1586
1587 if (ptempnode->bufvirtualaddr != NULL)
1588 memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
1589 return;
1590}
1591
1592/**
1593 * @brief This function initializes the command node.
1594 *
1595 * @param priv A pointer to wlan_private structure
1596 * @param ptempnode A pointer to cmd_ctrl_node structure
1597 * @param cmd_oid cmd oid: treated as sub command
1598 * @param wait_option wait option: wait response or not
1599 * @param pdata_buf A pointer to informaion buffer
1600 * @return 0 or -1
1601 */
1602void libertas_set_cmd_ctrl_node(wlan_private * priv,
1603 struct cmd_ctrl_node *ptempnode,
1604 u32 cmd_oid, u16 wait_option, void *pdata_buf)
1605{
Holger Schurig9012b282007-05-25 11:27:16 -04001606 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001607
1608 if (!ptempnode)
1609 return;
1610
1611 ptempnode->cmd_oid = cmd_oid;
1612 ptempnode->wait_option = wait_option;
1613 ptempnode->pdata_buf = pdata_buf;
1614
Holger Schurig9012b282007-05-25 11:27:16 -04001615 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001616}
1617
1618/**
1619 * @brief This function executes next command in command
1620 * pending queue. It will put fimware back to PS mode
1621 * if applicable.
1622 *
1623 * @param priv A pointer to wlan_private structure
1624 * @return 0 or -1
1625 */
1626int libertas_execute_next_command(wlan_private * priv)
1627{
1628 wlan_adapter *adapter = priv->adapter;
1629 struct cmd_ctrl_node *cmdnode = NULL;
1630 struct cmd_ds_command *cmdptr;
1631 unsigned long flags;
1632 int ret = 0;
1633
Dan Williams24d443b2007-05-25 17:29:34 -04001634 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001635
1636 spin_lock_irqsave(&adapter->driver_lock, flags);
1637
1638 if (adapter->cur_cmd) {
1639 lbs_pr_alert( "EXEC_NEXT_CMD: there is command in processing!\n");
1640 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1641 ret = -1;
1642 goto done;
1643 }
1644
1645 if (!list_empty(&adapter->cmdpendingq)) {
1646 cmdnode = (struct cmd_ctrl_node *)
1647 adapter->cmdpendingq.next;
1648 }
1649
1650 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1651
1652 if (cmdnode) {
Holger Schurig9012b282007-05-25 11:27:16 -04001653 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001654 "EXEC_NEXT_CMD: Got next command from cmdpendingq\n");
1655 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1656
1657 if (is_command_allowed_in_ps(cmdptr->command)) {
David Woodhouse981f1872007-05-25 23:36:54 -04001658 if ((adapter->psstate == PS_STATE_SLEEP) ||
1659 (adapter->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001660 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001661 "EXEC_NEXT_CMD: Cannot send cmd 0x%x in psstate %d\n",
David Woodhouse981f1872007-05-25 23:36:54 -04001662 le16_to_cpu(cmdptr->command),
1663 adapter->psstate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001664 ret = -1;
1665 goto done;
1666 }
Holger Schurig9012b282007-05-25 11:27:16 -04001667 lbs_deb_cmd("EXEC_NEXT_CMD: OK to send command "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001668 "0x%x in psstate %d\n",
David Woodhouse981f1872007-05-25 23:36:54 -04001669 le16_to_cpu(cmdptr->command),
1670 adapter->psstate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001671 } else if (adapter->psstate != PS_STATE_FULL_POWER) {
1672 /*
1673 * 1. Non-PS command:
1674 * Queue it. set needtowakeup to TRUE if current state
1675 * is SLEEP, otherwise call libertas_ps_wakeup to send Exit_PS.
1676 * 2. PS command but not Exit_PS:
1677 * Ignore it.
1678 * 3. PS command Exit_PS:
1679 * Set needtowakeup to TRUE if current state is SLEEP,
1680 * otherwise send this command down to firmware
1681 * immediately.
1682 */
1683 if (cmdptr->command !=
1684 cpu_to_le16(cmd_802_11_ps_mode)) {
1685 /* Prepare to send Exit PS,
1686 * this non PS command will be sent later */
1687 if ((adapter->psstate == PS_STATE_SLEEP)
1688 || (adapter->psstate == PS_STATE_PRE_SLEEP)
1689 ) {
1690 /* w/ new scheme, it will not reach here.
1691 since it is blocked in main_thread. */
1692 adapter->needtowakeup = 1;
1693 } else
1694 libertas_ps_wakeup(priv, 0);
1695
1696 ret = 0;
1697 goto done;
1698 } else {
1699 /*
1700 * PS command. Ignore it if it is not Exit_PS.
1701 * otherwise send it down immediately.
1702 */
1703 struct cmd_ds_802_11_ps_mode *psm =
1704 &cmdptr->params.psmode;
1705
Holger Schurig9012b282007-05-25 11:27:16 -04001706 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001707 "EXEC_NEXT_CMD: PS cmd- action=0x%x\n",
1708 psm->action);
1709 if (psm->action !=
1710 cpu_to_le16(cmd_subcmd_exit_ps)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001711 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001712 "EXEC_NEXT_CMD: Ignore Enter PS cmd\n");
1713 list_del((struct list_head *)cmdnode);
1714 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1715
1716 ret = 0;
1717 goto done;
1718 }
1719
David Woodhouse981f1872007-05-25 23:36:54 -04001720 if ((adapter->psstate == PS_STATE_SLEEP) ||
1721 (adapter->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001722 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001723 "EXEC_NEXT_CMD: Ignore ExitPS cmd in sleep\n");
1724 list_del((struct list_head *)cmdnode);
1725 libertas_cleanup_and_insert_cmd(priv, cmdnode);
1726 adapter->needtowakeup = 1;
1727
1728 ret = 0;
1729 goto done;
1730 }
1731
Holger Schurig9012b282007-05-25 11:27:16 -04001732 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001733 "EXEC_NEXT_CMD: Sending Exit_PS down...\n");
1734 }
1735 }
1736 list_del((struct list_head *)cmdnode);
Holger Schurig9012b282007-05-25 11:27:16 -04001737 lbs_deb_cmd("EXEC_NEXT_CMD: Sending 0x%04X command\n",
David Woodhouse981f1872007-05-25 23:36:54 -04001738 le16_to_cpu(cmdptr->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001739 DownloadcommandToStation(priv, cmdnode);
1740 } else {
1741 /*
1742 * check if in power save mode, if yes, put the device back
1743 * to PS mode
1744 */
1745 if ((adapter->psmode != wlan802_11powermodecam) &&
1746 (adapter->psstate == PS_STATE_FULL_POWER) &&
1747 (adapter->connect_status == libertas_connected)) {
David Woodhouse981f1872007-05-25 23:36:54 -04001748 if (adapter->secinfo.WPAenabled ||
1749 adapter->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001750 /* check for valid WPA group keys */
David Woodhouse981f1872007-05-25 23:36:54 -04001751 if (adapter->wpa_mcast_key.len ||
1752 adapter->wpa_unicast_key.len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001753 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001754 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1755 " go back to PS_SLEEP");
1756 libertas_ps_sleep(priv, 0);
1757 }
1758 } else {
Holger Schurig9012b282007-05-25 11:27:16 -04001759 lbs_deb_cmd(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001760 "EXEC_NEXT_CMD: command PendQ is empty,"
1761 " go back to PS_SLEEP");
1762 libertas_ps_sleep(priv, 0);
1763 }
1764 }
1765 }
1766
1767 ret = 0;
1768done:
Dan Williams24d443b2007-05-25 17:29:34 -04001769 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001770 return ret;
1771}
1772
1773void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str)
1774{
1775 union iwreq_data iwrq;
1776 u8 buf[50];
1777
Holger Schurig9012b282007-05-25 11:27:16 -04001778 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001779
1780 memset(&iwrq, 0, sizeof(union iwreq_data));
1781 memset(buf, 0, sizeof(buf));
1782
1783 snprintf(buf, sizeof(buf) - 1, "%s", str);
1784
1785 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1786
1787 /* Send Event to upper layer */
David Woodhouse981f1872007-05-25 23:36:54 -04001788 lbs_deb_cmd("Event Indication string = %s\n", (char *)buf);
Holger Schurig9012b282007-05-25 11:27:16 -04001789 lbs_deb_cmd("Event Indication String length = %d\n", iwrq.data.length);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001790
Holger Schurig9012b282007-05-25 11:27:16 -04001791 lbs_deb_cmd("Sending wireless event IWEVCUSTOM for %s\n", str);
Holger Schurig634b8f42007-05-25 13:05:16 -04001792 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001793
Holger Schurig9012b282007-05-25 11:27:16 -04001794 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001795}
1796
1797static int sendconfirmsleep(wlan_private * priv, u8 * cmdptr, u16 size)
1798{
1799 unsigned long flags;
1800 wlan_adapter *adapter = priv->adapter;
1801 int ret = 0;
1802
Holger Schurig9012b282007-05-25 11:27:16 -04001803 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001804
Holger Schurig9012b282007-05-25 11:27:16 -04001805 lbs_deb_cmd("SEND_SLEEPC_CMD: Before download, size of cmd = %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001806 size);
1807
1808 lbs_dbg_hex("SEND_SLEEPC_CMD: Sleep confirm command", cmdptr, size);
1809
Holger Schurig208fdd22007-05-25 12:17:06 -04001810 ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
Holger Schurig634b8f42007-05-25 13:05:16 -04001811 priv->dnld_sent = DNLD_RES_RECEIVED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001812
1813 spin_lock_irqsave(&adapter->driver_lock, flags);
1814 if (adapter->intcounter || adapter->currenttxskb)
Holger Schurig9012b282007-05-25 11:27:16 -04001815 lbs_deb_cmd("SEND_SLEEPC_CMD: intcounter=%d currenttxskb=%p\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001816 adapter->intcounter, adapter->currenttxskb);
1817 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1818
1819 if (ret) {
1820 lbs_pr_alert(
1821 "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
1822 } else {
1823 spin_lock_irqsave(&adapter->driver_lock, flags);
1824 if (!adapter->intcounter) {
1825 adapter->psstate = PS_STATE_SLEEP;
1826 } else {
Holger Schurig9012b282007-05-25 11:27:16 -04001827 lbs_deb_cmd("SEND_SLEEPC_CMD: After sent,IntC=%d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001828 adapter->intcounter);
1829 }
1830 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1831
Holger Schurig9012b282007-05-25 11:27:16 -04001832 lbs_deb_cmd("SEND_SLEEPC_CMD: Sent Confirm Sleep command\n");
1833 lbs_deb_cmd("+");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001834 }
1835
Holger Schurig9012b282007-05-25 11:27:16 -04001836 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001837 return ret;
1838}
1839
1840void libertas_ps_sleep(wlan_private * priv, int wait_option)
1841{
Holger Schurig9012b282007-05-25 11:27:16 -04001842 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001843
1844 /*
1845 * PS is currently supported only in Infrastructure mode
1846 * Remove this check if it is to be supported in IBSS mode also
1847 */
1848
1849 libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
1850 cmd_subcmd_enter_ps, wait_option, 0, NULL);
1851
Holger Schurig9012b282007-05-25 11:27:16 -04001852 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001853}
1854
1855/**
1856 * @brief This function sends Eixt_PS command to firmware.
1857 *
1858 * @param priv A pointer to wlan_private structure
1859 * @param wait_option wait response or not
1860 * @return n/a
1861 */
1862void libertas_ps_wakeup(wlan_private * priv, int wait_option)
1863{
David Woodhouse981f1872007-05-25 23:36:54 -04001864 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001865
Holger Schurig9012b282007-05-25 11:27:16 -04001866 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001867
David Woodhouse981f1872007-05-25 23:36:54 -04001868 Localpsmode = cpu_to_le32(wlan802_11powermodecam);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001869
David Woodhouse981f1872007-05-25 23:36:54 -04001870 lbs_deb_cmd("Exit_PS: Localpsmode = %d\n", wlan802_11powermodecam);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001871
1872 libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
1873 cmd_subcmd_exit_ps,
1874 wait_option, 0, &Localpsmode);
1875
Holger Schurig9012b282007-05-25 11:27:16 -04001876 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001877}
1878
1879/**
1880 * @brief This function checks condition and prepares to
1881 * send sleep confirm command to firmware if ok.
1882 *
1883 * @param priv A pointer to wlan_private structure
1884 * @param psmode Power Saving mode
1885 * @return n/a
1886 */
1887void libertas_ps_confirm_sleep(wlan_private * priv, u16 psmode)
1888{
1889 unsigned long flags =0;
1890 wlan_adapter *adapter = priv->adapter;
1891 u8 allowed = 1;
1892
Holger Schurig9012b282007-05-25 11:27:16 -04001893 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001894
Holger Schurig634b8f42007-05-25 13:05:16 -04001895 if (priv->dnld_sent) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001896 allowed = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001897 lbs_deb_cmd("D");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001898 }
1899
1900 spin_lock_irqsave(&adapter->driver_lock, flags);
1901 if (adapter->cur_cmd) {
1902 allowed = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001903 lbs_deb_cmd("C");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001904 }
1905 if (adapter->intcounter > 0) {
1906 allowed = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001907 lbs_deb_cmd("I%d", adapter->intcounter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001908 }
1909 spin_unlock_irqrestore(&adapter->driver_lock, flags);
1910
1911 if (allowed) {
Holger Schurig9012b282007-05-25 11:27:16 -04001912 lbs_deb_cmd("Sending libertas_ps_confirm_sleep\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001913 sendconfirmsleep(priv, (u8 *) & adapter->libertas_ps_confirm_sleep,
1914 sizeof(struct PS_CMD_ConfirmSleep));
1915 } else {
Holger Schurig9012b282007-05-25 11:27:16 -04001916 lbs_deb_cmd("Sleep Confirm has been delayed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001917 }
1918
Holger Schurig9012b282007-05-25 11:27:16 -04001919 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001920}