blob: d7bcce887c4138a604f734dc0ed21367e1dfef34 [file] [log] [blame]
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001/*
2 * This file is part of wl1271
3 *
Luciano Coelho2f826f52010-03-26 12:53:21 +02004 * Copyright (C) 2009-2010 Nokia Corporation
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/module.h>
25#include <linux/platform_device.h>
26#include <linux/crc7.h>
27#include <linux/spi/spi.h>
28#include <linux/etherdevice.h>
Kalle Valo023e0822010-03-18 12:26:36 +020029#include <linux/ieee80211.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030031
32#include "wl1271.h"
33#include "wl1271_reg.h"
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020034#include "wl1271_io.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030035#include "wl1271_acx.h"
36#include "wl12xx_80211.h"
37#include "wl1271_cmd.h"
Luciano Coelho99d84c12010-03-26 12:53:20 +020038#include "wl1271_event.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030039
Juuso Oikarinen16092b52010-04-28 09:49:59 +030040#define WL1271_CMD_FAST_POLL_COUNT 50
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030041
42/*
43 * send command to firmware
44 *
45 * @wl: wl struct
46 * @id: command id
47 * @buf: buffer containing the command, must work with dma
48 * @len: length of the buffer
49 */
Juuso Oikarinenfa867e72009-11-02 20:22:13 +020050int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
51 size_t res_len)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030052{
53 struct wl1271_cmd_header *cmd;
54 unsigned long timeout;
55 u32 intr;
56 int ret = 0;
Juuso Oikarinenad150e92009-11-02 20:22:12 +020057 u16 status;
Saravanan Dhanabalbc0f03e2010-03-26 12:53:33 +020058 u16 poll_count = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030059
60 cmd = buf;
Luciano Coelhod0f63b22009-10-15 10:33:29 +030061 cmd->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030062 cmd->status = 0;
63
64 WARN_ON(len % 4 != 0);
65
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020066 wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030067
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020068 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030069
70 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
71
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020072 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030073 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
74 if (time_after(jiffies, timeout)) {
75 wl1271_error("command complete timeout");
76 ret = -ETIMEDOUT;
77 goto out;
78 }
79
Saravanan Dhanabalbc0f03e2010-03-26 12:53:33 +020080 poll_count++;
Juuso Oikarinen16092b52010-04-28 09:49:59 +030081 if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
82 udelay(10);
83 else
84 msleep(1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030085
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020086 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030087 }
88
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020089 /* read back the status code of the command */
Juuso Oikarinenfa867e72009-11-02 20:22:13 +020090 if (res_len == 0)
91 res_len = sizeof(struct wl1271_cmd_header);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020092 wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020093
Juuso Oikarinenad150e92009-11-02 20:22:12 +020094 status = le16_to_cpu(cmd->status);
95 if (status != CMD_STATUS_SUCCESS) {
96 wl1271_error("command execute failure %d", status);
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020097 ret = -EIO;
98 }
99
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200100 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
101 WL1271_ACX_INTR_CMD_COMPLETE);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300102
103out:
104 return ret;
105}
106
Luciano Coelho938e30c2009-10-15 10:33:27 +0300107static int wl1271_cmd_cal_channel_tune(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300108{
109 struct wl1271_cmd_cal_channel_tune *cmd;
110 int ret = 0;
111
112 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
113 if (!cmd)
114 return -ENOMEM;
115
116 cmd->test.id = TEST_CMD_CHANNEL_TUNE;
117
118 cmd->band = WL1271_CHANNEL_TUNE_BAND_2_4;
119 /* set up any channel, 7 is in the middle of the range */
120 cmd->channel = 7;
121
122 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
123 if (ret < 0)
124 wl1271_warning("TEST_CMD_CHANNEL_TUNE failed");
125
126 kfree(cmd);
127 return ret;
128}
129
Luciano Coelho938e30c2009-10-15 10:33:27 +0300130static int wl1271_cmd_cal_update_ref_point(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300131{
132 struct wl1271_cmd_cal_update_ref_point *cmd;
133 int ret = 0;
134
135 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
136 if (!cmd)
137 return -ENOMEM;
138
139 cmd->test.id = TEST_CMD_UPDATE_PD_REFERENCE_POINT;
140
141 /* FIXME: still waiting for the correct values */
142 cmd->ref_power = 0;
143 cmd->ref_detector = 0;
144
145 cmd->sub_band = WL1271_PD_REFERENCE_POINT_BAND_B_G;
146
147 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
148 if (ret < 0)
149 wl1271_warning("TEST_CMD_UPDATE_PD_REFERENCE_POINT failed");
150
151 kfree(cmd);
152 return ret;
153}
154
Luciano Coelho938e30c2009-10-15 10:33:27 +0300155static int wl1271_cmd_cal_p2g(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300156{
157 struct wl1271_cmd_cal_p2g *cmd;
158 int ret = 0;
159
160 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
161 if (!cmd)
162 return -ENOMEM;
163
164 cmd->test.id = TEST_CMD_P2G_CAL;
165
166 cmd->sub_band_mask = WL1271_CAL_P2G_BAND_B_G;
167
168 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
169 if (ret < 0)
170 wl1271_warning("TEST_CMD_P2G_CAL failed");
171
172 kfree(cmd);
173 return ret;
174}
175
Luciano Coelho938e30c2009-10-15 10:33:27 +0300176static int wl1271_cmd_cal(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300177{
178 /*
179 * FIXME: we must make sure that we're not sleeping when calibration
180 * is done
181 */
182 int ret;
183
184 wl1271_notice("performing tx calibration");
185
186 ret = wl1271_cmd_cal_channel_tune(wl);
187 if (ret < 0)
188 return ret;
189
190 ret = wl1271_cmd_cal_update_ref_point(wl);
191 if (ret < 0)
192 return ret;
193
194 ret = wl1271_cmd_cal_p2g(wl);
195 if (ret < 0)
196 return ret;
197
198 return ret;
199}
200
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200201int wl1271_cmd_general_parms(struct wl1271 *wl)
202{
203 struct wl1271_general_parms_cmd *gen_parms;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200204 int ret;
205
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200206 if (!wl->nvs)
207 return -ENODEV;
208
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200209 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
210 if (!gen_parms)
211 return -ENOMEM;
212
213 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
214
Juuso Oikarineneb70eb72010-05-14 10:46:22 +0300215 memcpy(&gen_parms->general_params, &wl->nvs->general_params,
216 sizeof(struct wl1271_ini_general_params));
Luciano Coelho76c0f8d2009-12-11 15:40:41 +0200217
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200218 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
219 if (ret < 0)
220 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
221
222 kfree(gen_parms);
223 return ret;
224}
225
226int wl1271_cmd_radio_parms(struct wl1271 *wl)
227{
228 struct wl1271_radio_parms_cmd *radio_parms;
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200229 struct conf_radio_parms *rparam = &wl->conf.init.radioparam;
230 int ret;
231
232 if (!wl->nvs)
233 return -ENODEV;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200234
235 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
236 if (!radio_parms)
237 return -ENOMEM;
238
239 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
240
Juuso Oikarinena7da74f2010-05-14 10:46:23 +0300241 /* 2.4GHz parameters */
Juuso Oikarineneb70eb72010-05-14 10:46:22 +0300242 memcpy(&radio_parms->static_params_2, &wl->nvs->stat_radio_params_2,
243 sizeof(struct wl1271_ini_band_params_2));
244 memcpy(&radio_parms->dyn_params_2,
245 &wl->nvs->dyn_radio_params_2[rparam->fem].params,
246 sizeof(struct wl1271_ini_fem_params_2));
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200247
Juuso Oikarinena7da74f2010-05-14 10:46:23 +0300248 /* 5GHz parameters */
249 memcpy(&radio_parms->static_params_5,
250 &wl->nvs->stat_radio_params_5,
251 sizeof(struct wl1271_ini_band_params_5));
252 memcpy(&radio_parms->dyn_params_5,
253 &wl->nvs->dyn_radio_params_5[rparam->fem].params,
254 sizeof(struct wl1271_ini_fem_params_5));
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200255
256 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
257 radio_parms, sizeof(*radio_parms));
258
259 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
260 if (ret < 0)
261 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
262
263 kfree(radio_parms);
264 return ret;
265}
266
Luciano Coelho99d84c12010-03-26 12:53:20 +0200267/*
268 * Poll the mailbox event field until any of the bits in the mask is set or a
269 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
270 */
271static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
272{
273 u32 events_vector, event;
274 unsigned long timeout;
275
276 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
277
278 do {
279 if (time_after(jiffies, timeout))
280 return -ETIMEDOUT;
281
282 msleep(1);
283
284 /* read from both event fields */
285 wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
286 sizeof(events_vector), false);
287 event = events_vector & mask;
288 wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
289 sizeof(events_vector), false);
290 event |= events_vector & mask;
291 } while (!event);
292
293 return 0;
294}
295
Juuso Oikarinen15305492010-02-22 08:38:32 +0200296int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300297{
298 static bool do_cal = true;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300299 struct wl1271_cmd_join *join;
300 int ret, i;
301 u8 *bssid;
302
303 /* FIXME: remove when we get calibration from the factory */
304 if (do_cal) {
305 ret = wl1271_cmd_cal(wl);
306 if (ret < 0)
307 wl1271_warning("couldn't calibrate");
308 else
309 do_cal = false;
310 }
311
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300312 join = kzalloc(sizeof(*join), GFP_KERNEL);
313 if (!join) {
314 ret = -ENOMEM;
315 goto out;
316 }
317
318 wl1271_debug(DEBUG_CMD, "cmd join");
319
320 /* Reverse order BSSID */
321 bssid = (u8 *) &join->bssid_lsb;
322 for (i = 0; i < ETH_ALEN; i++)
323 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
324
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300325 join->rx_config_options = cpu_to_le32(wl->rx_config);
326 join->rx_filter_options = cpu_to_le32(wl->rx_filter);
Juuso Oikarinen15305492010-02-22 08:38:32 +0200327 join->bss_type = bss_type;
Luciano Coelho23a7a512010-04-28 09:50:02 +0300328 join->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300329
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300330 if (wl->band == IEEE80211_BAND_5GHZ)
Teemu Paasikivia4102642009-10-13 12:47:51 +0300331 join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300332
Juuso Oikarinen60e84c22010-03-26 12:53:25 +0200333 join->beacon_interval = cpu_to_le16(wl->beacon_int);
Luciano Coelhoae751ba2009-10-12 15:08:57 +0300334 join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD;
Teemu Paasikivia4102642009-10-13 12:47:51 +0300335
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300336 join->channel = wl->channel;
337 join->ssid_len = wl->ssid_len;
338 memcpy(join->ssid, wl->ssid, wl->ssid_len);
339 join->ctrl = WL1271_JOIN_CMD_CTRL_TX_FLUSH;
340
341 /* increment the session counter */
342 wl->session_counter++;
343 if (wl->session_counter >= SESSION_COUNTER_MAX)
344 wl->session_counter = 0;
345
346 join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
347
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300348 /* reset TX security counters */
349 wl->tx_security_last_seq = 0;
Juuso Oikarinen04e36fc2010-02-22 08:38:40 +0200350 wl->tx_security_seq = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300351
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200352 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300353 if (ret < 0) {
354 wl1271_error("failed to initiate cmd join");
355 goto out_free;
356 }
357
Luciano Coelho99d84c12010-03-26 12:53:20 +0200358 ret = wl1271_cmd_wait_for_event(wl, JOIN_EVENT_COMPLETE_ID);
359 if (ret < 0)
360 wl1271_error("cmd join event completion error");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300361
362out_free:
363 kfree(join);
364
365out:
366 return ret;
367}
368
369/**
370 * send test command to firmware
371 *
372 * @wl: wl struct
373 * @buf: buffer containing the command, with all headers, must work with dma
374 * @len: length of the buffer
375 * @answer: is answer needed
376 */
377int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
378{
379 int ret;
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200380 size_t res_len = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300381
382 wl1271_debug(DEBUG_CMD, "cmd test");
383
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200384 if (answer)
385 res_len = buf_len;
386
387 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300388
389 if (ret < 0) {
390 wl1271_warning("TEST command failed");
391 return ret;
392 }
393
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200394 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300395}
396
397/**
398 * read acx from firmware
399 *
400 * @wl: wl struct
401 * @id: acx id
402 * @buf: buffer for the response, including all headers, must work with dma
403 * @len: lenght of buf
404 */
405int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
406{
407 struct acx_header *acx = buf;
408 int ret;
409
410 wl1271_debug(DEBUG_CMD, "cmd interrogate");
411
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300412 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300413
414 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300415 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300416
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200417 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
418 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300419 wl1271_error("INTERROGATE command failed");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300420
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300421 return ret;
422}
423
424/**
425 * write acx value to firmware
426 *
427 * @wl: wl struct
428 * @id: acx id
429 * @buf: buffer containing acx, including all headers, must work with dma
430 * @len: length of buf
431 */
432int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
433{
434 struct acx_header *acx = buf;
435 int ret;
436
437 wl1271_debug(DEBUG_CMD, "cmd configure");
438
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300439 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300440
441 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300442 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300443
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200444 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300445 if (ret < 0) {
446 wl1271_warning("CONFIGURE command NOK");
447 return ret;
448 }
449
450 return 0;
451}
452
Luciano Coelho94210892009-12-11 15:40:55 +0200453int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300454{
455 struct cmd_enabledisable_path *cmd;
456 int ret;
457 u16 cmd_rx, cmd_tx;
458
459 wl1271_debug(DEBUG_CMD, "cmd data path");
460
461 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
462 if (!cmd) {
463 ret = -ENOMEM;
464 goto out;
465 }
466
Luciano Coelho94210892009-12-11 15:40:55 +0200467 /* the channel here is only used for calibration, so hardcoded to 1 */
468 cmd->channel = 1;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300469
470 if (enable) {
471 cmd_rx = CMD_ENABLE_RX;
472 cmd_tx = CMD_ENABLE_TX;
473 } else {
474 cmd_rx = CMD_DISABLE_RX;
475 cmd_tx = CMD_DISABLE_TX;
476 }
477
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200478 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300479 if (ret < 0) {
480 wl1271_error("rx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200481 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300482 goto out;
483 }
484
485 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200486 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300487
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200488 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300489 if (ret < 0) {
490 wl1271_error("tx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200491 enable ? "start" : "stop", cmd->channel);
Juuso Oikarinen1b00f2b2010-03-26 12:53:17 +0200492 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300493 }
494
495 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200496 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300497
498out:
499 kfree(cmd);
500 return ret;
501}
502
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200503int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode, bool send)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300504{
505 struct wl1271_cmd_ps_params *ps_params = NULL;
506 int ret = 0;
507
508 /* FIXME: this should be in ps.c */
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300509 ret = wl1271_acx_wake_up_conditions(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300510 if (ret < 0) {
511 wl1271_error("couldn't set wake up conditions");
512 goto out;
513 }
514
515 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
516
517 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
518 if (!ps_params) {
519 ret = -ENOMEM;
520 goto out;
521 }
522
523 ps_params->ps_mode = ps_mode;
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200524 ps_params->send_null_data = send;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300525 ps_params->retries = 5;
Juuso Oikarinencbd1ea82010-05-07 11:39:02 +0300526 ps_params->hang_over_period = 1;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300527 ps_params->null_data_rate = cpu_to_le32(1); /* 1 Mbps */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300528
529 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200530 sizeof(*ps_params), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300531 if (ret < 0) {
532 wl1271_error("cmd set_ps_mode failed");
533 goto out;
534 }
535
536out:
537 kfree(ps_params);
538 return ret;
539}
540
541int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
542 size_t len)
543{
544 struct cmd_read_write_memory *cmd;
545 int ret = 0;
546
547 wl1271_debug(DEBUG_CMD, "cmd read memory");
548
549 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
550 if (!cmd) {
551 ret = -ENOMEM;
552 goto out;
553 }
554
555 WARN_ON(len > MAX_READ_SIZE);
556 len = min_t(size_t, len, MAX_READ_SIZE);
557
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300558 cmd->addr = cpu_to_le32(addr);
559 cmd->size = cpu_to_le32(len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300560
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200561 ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd),
562 sizeof(*cmd));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300563 if (ret < 0) {
564 wl1271_error("read memory command failed: %d", ret);
565 goto out;
566 }
567
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200568 /* the read command got in */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300569 memcpy(answer, cmd->value, len);
570
571out:
572 kfree(cmd);
573 return ret;
574}
575
Kalle Valo818e3062010-03-18 12:26:35 +0200576int wl1271_cmd_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len,
577 const u8 *ie, size_t ie_len, u8 active_scan,
578 u8 high_prio, u8 band, u8 probe_requests)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300579{
580
581 struct wl1271_cmd_trigger_scan_to *trigger = NULL;
582 struct wl1271_cmd_scan *params = NULL;
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300583 struct ieee80211_channel *channels;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300584 u32 rate;
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300585 int i, j, n_ch, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300586 u16 scan_options = 0;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300587 u8 ieee_band;
588
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300589 if (band == WL1271_SCAN_BAND_2_4_GHZ) {
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300590 ieee_band = IEEE80211_BAND_2GHZ;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300591 rate = wl->conf.tx.basic_rate;
592 } else if (band == WL1271_SCAN_BAND_DUAL && wl1271_11a_enabled()) {
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300593 ieee_band = IEEE80211_BAND_2GHZ;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300594 rate = wl->conf.tx.basic_rate;
595 } else if (band == WL1271_SCAN_BAND_5_GHZ && wl1271_11a_enabled()) {
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300596 ieee_band = IEEE80211_BAND_5GHZ;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300597 rate = wl->conf.tx.basic_rate_5;
598 } else
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300599 return -EINVAL;
600
601 if (wl->hw->wiphy->bands[ieee_band]->channels == NULL)
602 return -EINVAL;
603
604 channels = wl->hw->wiphy->bands[ieee_band]->channels;
605 n_ch = wl->hw->wiphy->bands[ieee_band]->n_channels;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300606
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200607 if (test_bit(WL1271_FLAG_SCANNING, &wl->flags))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300608 return -EINVAL;
609
610 params = kzalloc(sizeof(*params), GFP_KERNEL);
611 if (!params)
612 return -ENOMEM;
613
614 params->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
615 params->params.rx_filter_options =
616 cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
617
618 if (!active_scan)
619 scan_options |= WL1271_SCAN_OPT_PASSIVE;
620 if (high_prio)
621 scan_options |= WL1271_SCAN_OPT_PRIORITY_HIGH;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300622 params->params.scan_options = cpu_to_le16(scan_options);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300623
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300624 params->params.num_probe_requests = probe_requests;
Luciano Coelho23a7a512010-04-28 09:50:02 +0300625 params->params.tx_rate = cpu_to_le32(rate);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300626 params->params.tid_trigger = 0;
627 params->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
628
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300629 if (band == WL1271_SCAN_BAND_DUAL)
630 params->params.band = WL1271_SCAN_BAND_2_4_GHZ;
631 else
632 params->params.band = band;
633
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300634 for (i = 0, j = 0; i < n_ch && i < WL1271_SCAN_MAX_CHANNELS; i++) {
635 if (!(channels[i].flags & IEEE80211_CHAN_DISABLED)) {
636 params->channels[j].min_duration =
637 cpu_to_le32(WL1271_SCAN_CHAN_MIN_DURATION);
638 params->channels[j].max_duration =
639 cpu_to_le32(WL1271_SCAN_CHAN_MAX_DURATION);
640 memset(&params->channels[j].bssid_lsb, 0xff, 4);
641 memset(&params->channels[j].bssid_msb, 0xff, 2);
642 params->channels[j].early_termination = 0;
643 params->channels[j].tx_power_att =
644 WL1271_SCAN_CURRENT_TX_PWR;
645 params->channels[j].channel = channels[i].hw_value;
646 j++;
647 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300648 }
649
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300650 params->params.num_channels = j;
651
Kalle Valo818e3062010-03-18 12:26:35 +0200652 if (ssid_len && ssid) {
653 params->params.ssid_len = ssid_len;
654 memcpy(params->params.ssid, ssid, ssid_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300655 }
656
Kalle Valo818e3062010-03-18 12:26:35 +0200657 ret = wl1271_cmd_build_probe_req(wl, ssid, ssid_len,
658 ie, ie_len, ieee_band);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300659 if (ret < 0) {
660 wl1271_error("PROBE request template failed");
661 goto out;
662 }
663
664 trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
665 if (!trigger) {
666 ret = -ENOMEM;
667 goto out;
668 }
669
670 /* disable the timeout */
671 trigger->timeout = 0;
672
673 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200674 sizeof(*trigger), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300675 if (ret < 0) {
676 wl1271_error("trigger scan to failed for hw scan");
677 goto out;
678 }
679
680 wl1271_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params));
681
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200682 set_bit(WL1271_FLAG_SCANNING, &wl->flags);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300683 if (wl1271_11a_enabled()) {
684 wl->scan.state = band;
685 if (band == WL1271_SCAN_BAND_DUAL) {
686 wl->scan.active = active_scan;
687 wl->scan.high_prio = high_prio;
688 wl->scan.probe_requests = probe_requests;
Kalle Valo818e3062010-03-18 12:26:35 +0200689 if (ssid_len && ssid) {
690 wl->scan.ssid_len = ssid_len;
691 memcpy(wl->scan.ssid, ssid, ssid_len);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300692 } else
693 wl->scan.ssid_len = 0;
694 }
695 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300696
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200697 ret = wl1271_cmd_send(wl, CMD_SCAN, params, sizeof(*params), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300698 if (ret < 0) {
699 wl1271_error("SCAN failed");
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200700 clear_bit(WL1271_FLAG_SCANNING, &wl->flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300701 goto out;
702 }
703
704out:
705 kfree(params);
Juuso Oikarinen9cea4612010-03-26 12:53:14 +0200706 kfree(trigger);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300707 return ret;
708}
709
710int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300711 void *buf, size_t buf_len, int index, u32 rates)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300712{
713 struct wl1271_cmd_template_set *cmd;
714 int ret = 0;
715
716 wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
717
718 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
719 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
720
721 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
722 if (!cmd) {
723 ret = -ENOMEM;
724 goto out;
725 }
726
727 cmd->len = cpu_to_le16(buf_len);
728 cmd->template_type = template_id;
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300729 cmd->enabled_rates = cpu_to_le32(rates);
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300730 cmd->short_retry_limit = wl->conf.tx.rc_conf.short_retry_limit;
731 cmd->long_retry_limit = wl->conf.tx.rc_conf.long_retry_limit;
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200732 cmd->index = index;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300733
734 if (buf)
735 memcpy(cmd->template_data, buf, buf_len);
736
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200737 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300738 if (ret < 0) {
739 wl1271_warning("cmd set_template failed: %d", ret);
740 goto out_free;
741 }
742
743out_free:
744 kfree(cmd);
745
746out:
747 return ret;
748}
749
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300750int wl1271_cmd_build_null_data(struct wl1271 *wl)
751{
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200752 struct sk_buff *skb = NULL;
753 int size;
754 void *ptr;
755 int ret = -ENOMEM;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300756
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300757
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200758 if (wl->bss_type == BSS_TYPE_IBSS) {
759 size = sizeof(struct wl12xx_null_data_template);
760 ptr = NULL;
761 } else {
762 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
763 if (!skb)
764 goto out;
765 size = skb->len;
766 ptr = skb->data;
767 }
768
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300769 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
770 WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300771
Kalle Valo899e6e62010-03-18 12:26:34 +0200772out:
773 dev_kfree_skb(skb);
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200774 if (ret)
775 wl1271_warning("cmd buld null data failed %d", ret);
776
Kalle Valo899e6e62010-03-18 12:26:34 +0200777 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300778
779}
780
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200781int wl1271_cmd_build_klv_null_data(struct wl1271 *wl)
782{
783 struct sk_buff *skb = NULL;
784 int ret = -ENOMEM;
785
786 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
787 if (!skb)
788 goto out;
789
790 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
791 skb->data, skb->len,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300792 CMD_TEMPL_KLV_IDX_NULL_DATA,
793 WL1271_RATE_AUTOMATIC);
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200794
795out:
796 dev_kfree_skb(skb);
797 if (ret)
798 wl1271_warning("cmd build klv null data failed %d", ret);
799
800 return ret;
801
802}
803
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300804int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
805{
Kalle Valo899e6e62010-03-18 12:26:34 +0200806 struct sk_buff *skb;
807 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300808
Kalle Valo899e6e62010-03-18 12:26:34 +0200809 skb = ieee80211_pspoll_get(wl->hw, wl->vif);
810 if (!skb)
811 goto out;
Juuso Oikarinenc3fea192009-10-08 21:56:22 +0300812
Kalle Valo899e6e62010-03-18 12:26:34 +0200813 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300814 skb->len, 0, wl->basic_rate);
Juuso Oikarinenc3fea192009-10-08 21:56:22 +0300815
Kalle Valo899e6e62010-03-18 12:26:34 +0200816out:
817 dev_kfree_skb(skb);
818 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300819}
820
Kalle Valo818e3062010-03-18 12:26:35 +0200821int wl1271_cmd_build_probe_req(struct wl1271 *wl,
822 const u8 *ssid, size_t ssid_len,
823 const u8 *ie, size_t ie_len, u8 band)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300824{
Kalle Valo818e3062010-03-18 12:26:35 +0200825 struct sk_buff *skb;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300826 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300827
Kalle Valo818e3062010-03-18 12:26:35 +0200828 skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
829 ie, ie_len);
830 if (!skb) {
831 ret = -ENOMEM;
832 goto out;
833 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300834
Kalle Valo818e3062010-03-18 12:26:35 +0200835 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300836
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300837 if (band == IEEE80211_BAND_2GHZ)
838 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300839 skb->data, skb->len, 0,
840 wl->conf.tx.basic_rate);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300841 else
842 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300843 skb->data, skb->len, 0,
844 wl->conf.tx.basic_rate_5);
Kalle Valo818e3062010-03-18 12:26:35 +0200845
846out:
847 dev_kfree_skb(skb);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300848 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300849}
850
Kalle Valo023e0822010-03-18 12:26:36 +0200851int wl1271_build_qos_null_data(struct wl1271 *wl)
852{
853 struct ieee80211_qos_hdr template;
854
855 memset(&template, 0, sizeof(template));
856
857 memcpy(template.addr1, wl->bssid, ETH_ALEN);
858 memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
859 memcpy(template.addr3, wl->bssid, ETH_ALEN);
860
861 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
862 IEEE80211_STYPE_QOS_NULLFUNC |
863 IEEE80211_FCTL_TODS);
864
865 /* FIXME: not sure what priority to use here */
866 template.qos_ctrl = cpu_to_le16(0);
867
868 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300869 sizeof(template), 0,
870 WL1271_RATE_AUTOMATIC);
Kalle Valo023e0822010-03-18 12:26:36 +0200871}
872
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300873int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id)
874{
875 struct wl1271_cmd_set_keys *cmd;
876 int ret = 0;
877
878 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
879
880 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
881 if (!cmd) {
882 ret = -ENOMEM;
883 goto out;
884 }
885
886 cmd->id = id;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300887 cmd->key_action = cpu_to_le16(KEY_SET_ID);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300888 cmd->key_type = KEY_WEP;
889
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200890 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300891 if (ret < 0) {
892 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
893 goto out;
894 }
895
896out:
897 kfree(cmd);
898
899 return ret;
900}
901
902int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300903 u8 key_size, const u8 *key, const u8 *addr,
904 u32 tx_seq_32, u16 tx_seq_16)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300905{
906 struct wl1271_cmd_set_keys *cmd;
907 int ret = 0;
908
909 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
910 if (!cmd) {
911 ret = -ENOMEM;
912 goto out;
913 }
914
915 if (key_type != KEY_WEP)
916 memcpy(cmd->addr, addr, ETH_ALEN);
917
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300918 cmd->key_action = cpu_to_le16(action);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300919 cmd->key_size = key_size;
920 cmd->key_type = key_type;
921
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300922 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
923 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300924
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300925 /* we have only one SSID profile */
926 cmd->ssid_profile = 0;
927
928 cmd->id = id;
929
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300930 if (key_type == KEY_TKIP) {
931 /*
932 * We get the key in the following form:
933 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
934 * but the target is expecting:
935 * TKIP - RX MIC - TX MIC
936 */
937 memcpy(cmd->key, key, 16);
938 memcpy(cmd->key + 16, key + 24, 8);
939 memcpy(cmd->key + 24, key + 16, 8);
940
941 } else {
942 memcpy(cmd->key, key, key_size);
943 }
944
945 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
946
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200947 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300948 if (ret < 0) {
949 wl1271_warning("could not set keys");
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200950 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300951 }
952
953out:
954 kfree(cmd);
955
956 return ret;
957}
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300958
959int wl1271_cmd_disconnect(struct wl1271 *wl)
960{
961 struct wl1271_cmd_disconnect *cmd;
962 int ret = 0;
963
964 wl1271_debug(DEBUG_CMD, "cmd disconnect");
965
966 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
967 if (!cmd) {
968 ret = -ENOMEM;
969 goto out;
970 }
971
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300972 cmd->rx_config_options = cpu_to_le32(wl->rx_config);
973 cmd->rx_filter_options = cpu_to_le32(wl->rx_filter);
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300974 /* disconnect reason is not used in immediate disconnections */
975 cmd->type = DISCONNECT_IMMEDIATE;
976
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200977 ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300978 if (ret < 0) {
979 wl1271_error("failed to send disconnect command");
980 goto out_free;
981 }
982
Luciano Coelho2f826f52010-03-26 12:53:21 +0200983 ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
984 if (ret < 0)
985 wl1271_error("cmd disconnect event completion error");
986
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300987out_free:
988 kfree(cmd);
989
990out:
991 return ret;
992}