blob: 96324336f936bcdd047062bca63b041c5694db46 [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
Shahar Levi00d20102010-11-08 11:20:10 +000032#include "wl12xx.h"
33#include "reg.h"
34#include "io.h"
35#include "acx.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030036#include "wl12xx_80211.h"
Shahar Levi00d20102010-11-08 11:20:10 +000037#include "cmd.h"
38#include "event.h"
Arik Nemtsov98bdaab2010-10-16 18:08:58 +020039#include "tx.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030040
Juuso Oikarinen16092b52010-04-28 09:49:59 +030041#define WL1271_CMD_FAST_POLL_COUNT 50
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030042
43/*
44 * send command to firmware
45 *
46 * @wl: wl struct
47 * @id: command id
48 * @buf: buffer containing the command, must work with dma
49 * @len: length of the buffer
50 */
Juuso Oikarinenfa867e72009-11-02 20:22:13 +020051int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
52 size_t res_len)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030053{
54 struct wl1271_cmd_header *cmd;
55 unsigned long timeout;
56 u32 intr;
57 int ret = 0;
Juuso Oikarinenad150e92009-11-02 20:22:12 +020058 u16 status;
Saravanan Dhanabalbc0f03e2010-03-26 12:53:33 +020059 u16 poll_count = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030060
61 cmd = buf;
Luciano Coelhod0f63b22009-10-15 10:33:29 +030062 cmd->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030063 cmd->status = 0;
64
65 WARN_ON(len % 4 != 0);
Arik Nemtsov24225b32011-03-01 12:27:26 +020066 WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030067
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020068 wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030069
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020070 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030071
72 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
73
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020074 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030075 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
76 if (time_after(jiffies, timeout)) {
77 wl1271_error("command complete timeout");
78 ret = -ETIMEDOUT;
79 goto out;
80 }
81
Saravanan Dhanabalbc0f03e2010-03-26 12:53:33 +020082 poll_count++;
Juuso Oikarinen16092b52010-04-28 09:49:59 +030083 if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
84 udelay(10);
85 else
86 msleep(1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030087
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020088 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030089 }
90
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020091 /* read back the status code of the command */
Juuso Oikarinenfa867e72009-11-02 20:22:13 +020092 if (res_len == 0)
93 res_len = sizeof(struct wl1271_cmd_header);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020094 wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020095
Juuso Oikarinenad150e92009-11-02 20:22:12 +020096 status = le16_to_cpu(cmd->status);
97 if (status != CMD_STATUS_SUCCESS) {
98 wl1271_error("command execute failure %d", status);
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +020099 ieee80211_queue_work(wl->hw, &wl->recovery_work);
Juuso Oikarinen3b775b42009-11-02 20:22:10 +0200100 ret = -EIO;
101 }
102
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200103 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
104 WL1271_ACX_INTR_CMD_COMPLETE);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300105
106out:
107 return ret;
108}
109
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200110int wl1271_cmd_general_parms(struct wl1271 *wl)
111{
112 struct wl1271_general_parms_cmd *gen_parms;
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300113 struct wl1271_ini_general_params *gp = &wl->nvs->general_params;
114 bool answer = false;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200115 int ret;
116
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200117 if (!wl->nvs)
118 return -ENODEV;
119
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200120 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
121 if (!gen_parms)
122 return -ENOMEM;
123
124 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
125
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300126 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
Luciano Coelho76c0f8d2009-12-11 15:40:41 +0200127
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300128 if (gp->tx_bip_fem_auto_detect)
129 answer = true;
130
131 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
132 if (ret < 0) {
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200133 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300134 goto out;
135 }
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200136
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300137 gp->tx_bip_fem_manufacturer =
138 gen_parms->general_params.tx_bip_fem_manufacturer;
139
140 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
141 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
142
143out:
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200144 kfree(gen_parms);
145 return ret;
146}
147
148int wl1271_cmd_radio_parms(struct wl1271 *wl)
149{
150 struct wl1271_radio_parms_cmd *radio_parms;
Luciano Coelhoe6b190f2010-07-08 17:50:01 +0300151 struct wl1271_ini_general_params *gp = &wl->nvs->general_params;
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200152 int ret;
153
154 if (!wl->nvs)
155 return -ENODEV;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200156
157 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
158 if (!radio_parms)
159 return -ENOMEM;
160
161 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
162
Juuso Oikarinena7da74f2010-05-14 10:46:23 +0300163 /* 2.4GHz parameters */
Juuso Oikarineneb70eb72010-05-14 10:46:22 +0300164 memcpy(&radio_parms->static_params_2, &wl->nvs->stat_radio_params_2,
165 sizeof(struct wl1271_ini_band_params_2));
166 memcpy(&radio_parms->dyn_params_2,
Luciano Coelhoe6b190f2010-07-08 17:50:01 +0300167 &wl->nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
Juuso Oikarineneb70eb72010-05-14 10:46:22 +0300168 sizeof(struct wl1271_ini_fem_params_2));
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200169
Juuso Oikarinena7da74f2010-05-14 10:46:23 +0300170 /* 5GHz parameters */
171 memcpy(&radio_parms->static_params_5,
172 &wl->nvs->stat_radio_params_5,
173 sizeof(struct wl1271_ini_band_params_5));
174 memcpy(&radio_parms->dyn_params_5,
Luciano Coelhoe6b190f2010-07-08 17:50:01 +0300175 &wl->nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
Juuso Oikarinena7da74f2010-05-14 10:46:23 +0300176 sizeof(struct wl1271_ini_fem_params_5));
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200177
178 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
179 radio_parms, sizeof(*radio_parms));
180
181 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
182 if (ret < 0)
183 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
184
185 kfree(radio_parms);
186 return ret;
187}
188
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200189int wl1271_cmd_ext_radio_parms(struct wl1271 *wl)
190{
191 struct wl1271_ext_radio_parms_cmd *ext_radio_parms;
192 struct conf_rf_settings *rf = &wl->conf.rf;
193 int ret;
194
195 if (!wl->nvs)
196 return -ENODEV;
197
198 ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL);
199 if (!ext_radio_parms)
200 return -ENOMEM;
201
202 ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM;
203
204 memcpy(ext_radio_parms->tx_per_channel_power_compensation_2,
205 rf->tx_per_channel_power_compensation_2,
206 CONF_TX_PWR_COMPENSATION_LEN_2);
207 memcpy(ext_radio_parms->tx_per_channel_power_compensation_5,
208 rf->tx_per_channel_power_compensation_5,
209 CONF_TX_PWR_COMPENSATION_LEN_5);
210
211 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
212 ext_radio_parms, sizeof(*ext_radio_parms));
213
214 ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0);
215 if (ret < 0)
216 wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
217
218 kfree(ext_radio_parms);
219 return ret;
220}
221
Luciano Coelho99d84c12010-03-26 12:53:20 +0200222/*
223 * Poll the mailbox event field until any of the bits in the mask is set or a
224 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
225 */
Arik Nemtsov05285cf2010-11-12 17:15:03 +0200226static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask)
Luciano Coelho99d84c12010-03-26 12:53:20 +0200227{
228 u32 events_vector, event;
229 unsigned long timeout;
230
231 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
232
233 do {
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +0200234 if (time_after(jiffies, timeout)) {
Arik Nemtsov05285cf2010-11-12 17:15:03 +0200235 wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
236 (int)mask);
Luciano Coelho99d84c12010-03-26 12:53:20 +0200237 return -ETIMEDOUT;
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +0200238 }
Luciano Coelho99d84c12010-03-26 12:53:20 +0200239
240 msleep(1);
241
242 /* read from both event fields */
243 wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
244 sizeof(events_vector), false);
245 event = events_vector & mask;
246 wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
247 sizeof(events_vector), false);
248 event |= events_vector & mask;
249 } while (!event);
250
251 return 0;
252}
253
Arik Nemtsov05285cf2010-11-12 17:15:03 +0200254static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
255{
256 int ret;
257
258 ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask);
259 if (ret != 0) {
260 ieee80211_queue_work(wl->hw, &wl->recovery_work);
261 return ret;
262 }
263
264 return 0;
265}
266
Juuso Oikarinen15305492010-02-22 08:38:32 +0200267int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300268{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300269 struct wl1271_cmd_join *join;
270 int ret, i;
271 u8 *bssid;
272
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300273 join = kzalloc(sizeof(*join), GFP_KERNEL);
274 if (!join) {
275 ret = -ENOMEM;
276 goto out;
277 }
278
279 wl1271_debug(DEBUG_CMD, "cmd join");
280
281 /* Reverse order BSSID */
282 bssid = (u8 *) &join->bssid_lsb;
283 for (i = 0; i < ETH_ALEN; i++)
284 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
285
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300286 join->rx_config_options = cpu_to_le32(wl->rx_config);
287 join->rx_filter_options = cpu_to_le32(wl->rx_filter);
Juuso Oikarinen15305492010-02-22 08:38:32 +0200288 join->bss_type = bss_type;
Luciano Coelho23a7a512010-04-28 09:50:02 +0300289 join->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
Eliad Peller72c2d9e2011-02-02 09:59:37 +0200290 join->supported_rate_set = cpu_to_le32(wl->rate_set);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300291
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300292 if (wl->band == IEEE80211_BAND_5GHZ)
Teemu Paasikivia4102642009-10-13 12:47:51 +0300293 join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300294
Juuso Oikarinen60e84c22010-03-26 12:53:25 +0200295 join->beacon_interval = cpu_to_le16(wl->beacon_int);
Luciano Coelhoae751ba2009-10-12 15:08:57 +0300296 join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD;
Teemu Paasikivia4102642009-10-13 12:47:51 +0300297
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300298 join->channel = wl->channel;
299 join->ssid_len = wl->ssid_len;
300 memcpy(join->ssid, wl->ssid, wl->ssid_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300301
302 join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
303
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300304 /* reset TX security counters */
305 wl->tx_security_last_seq = 0;
Juuso Oikarinen04e36fc2010-02-22 08:38:40 +0200306 wl->tx_security_seq = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300307
Eliad Peller72c2d9e2011-02-02 09:59:37 +0200308 wl1271_debug(DEBUG_CMD, "cmd join: basic_rate_set=0x%x, rate_set=0x%x",
309 join->basic_rate_set, join->supported_rate_set);
310
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200311 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300312 if (ret < 0) {
313 wl1271_error("failed to initiate cmd join");
314 goto out_free;
315 }
316
Luciano Coelho99d84c12010-03-26 12:53:20 +0200317 ret = wl1271_cmd_wait_for_event(wl, JOIN_EVENT_COMPLETE_ID);
318 if (ret < 0)
319 wl1271_error("cmd join event completion error");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300320
321out_free:
322 kfree(join);
323
324out:
325 return ret;
326}
327
328/**
329 * send test command to firmware
330 *
331 * @wl: wl struct
332 * @buf: buffer containing the command, with all headers, must work with dma
333 * @len: length of the buffer
334 * @answer: is answer needed
335 */
336int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
337{
338 int ret;
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200339 size_t res_len = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300340
341 wl1271_debug(DEBUG_CMD, "cmd test");
342
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200343 if (answer)
344 res_len = buf_len;
345
346 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300347
348 if (ret < 0) {
349 wl1271_warning("TEST command failed");
350 return ret;
351 }
352
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200353 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300354}
355
356/**
357 * read acx from firmware
358 *
359 * @wl: wl struct
360 * @id: acx id
361 * @buf: buffer for the response, including all headers, must work with dma
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300362 * @len: length of buf
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300363 */
364int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
365{
366 struct acx_header *acx = buf;
367 int ret;
368
369 wl1271_debug(DEBUG_CMD, "cmd interrogate");
370
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300371 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300372
373 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300374 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300375
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200376 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
377 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300378 wl1271_error("INTERROGATE command failed");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300379
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300380 return ret;
381}
382
383/**
384 * write acx value to firmware
385 *
386 * @wl: wl struct
387 * @id: acx id
388 * @buf: buffer containing acx, including all headers, must work with dma
389 * @len: length of buf
390 */
391int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
392{
393 struct acx_header *acx = buf;
394 int ret;
395
396 wl1271_debug(DEBUG_CMD, "cmd configure");
397
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300398 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300399
400 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300401 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300402
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200403 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300404 if (ret < 0) {
405 wl1271_warning("CONFIGURE command NOK");
406 return ret;
407 }
408
409 return 0;
410}
411
Luciano Coelho94210892009-12-11 15:40:55 +0200412int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300413{
414 struct cmd_enabledisable_path *cmd;
415 int ret;
416 u16 cmd_rx, cmd_tx;
417
418 wl1271_debug(DEBUG_CMD, "cmd data path");
419
420 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
421 if (!cmd) {
422 ret = -ENOMEM;
423 goto out;
424 }
425
Luciano Coelho94210892009-12-11 15:40:55 +0200426 /* the channel here is only used for calibration, so hardcoded to 1 */
427 cmd->channel = 1;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300428
429 if (enable) {
430 cmd_rx = CMD_ENABLE_RX;
431 cmd_tx = CMD_ENABLE_TX;
432 } else {
433 cmd_rx = CMD_DISABLE_RX;
434 cmd_tx = CMD_DISABLE_TX;
435 }
436
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200437 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300438 if (ret < 0) {
439 wl1271_error("rx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200440 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300441 goto out;
442 }
443
444 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200445 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300446
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200447 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300448 if (ret < 0) {
449 wl1271_error("tx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200450 enable ? "start" : "stop", cmd->channel);
Juuso Oikarinen1b00f2b2010-03-26 12:53:17 +0200451 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300452 }
453
454 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200455 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300456
457out:
458 kfree(cmd);
459 return ret;
460}
461
Eliad Pellerc8bde242011-02-02 09:59:35 +0200462int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300463{
464 struct wl1271_cmd_ps_params *ps_params = NULL;
465 int ret = 0;
466
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300467 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
468
469 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
470 if (!ps_params) {
471 ret = -ENOMEM;
472 goto out;
473 }
474
475 ps_params->ps_mode = ps_mode;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300476
477 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200478 sizeof(*ps_params), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300479 if (ret < 0) {
480 wl1271_error("cmd set_ps_mode failed");
481 goto out;
482 }
483
484out:
485 kfree(ps_params);
486 return ret;
487}
488
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300489int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300490 void *buf, size_t buf_len, int index, u32 rates)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300491{
492 struct wl1271_cmd_template_set *cmd;
493 int ret = 0;
494
495 wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
496
497 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
498 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
499
500 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
501 if (!cmd) {
502 ret = -ENOMEM;
503 goto out;
504 }
505
506 cmd->len = cpu_to_le16(buf_len);
507 cmd->template_type = template_id;
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300508 cmd->enabled_rates = cpu_to_le32(rates);
Arik Nemtsov1e05a812010-10-16 17:44:51 +0200509 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
510 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200511 cmd->index = index;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300512
513 if (buf)
514 memcpy(cmd->template_data, buf, buf_len);
515
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200516 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300517 if (ret < 0) {
518 wl1271_warning("cmd set_template failed: %d", ret);
519 goto out_free;
520 }
521
522out_free:
523 kfree(cmd);
524
525out:
526 return ret;
527}
528
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300529int wl1271_cmd_build_null_data(struct wl1271 *wl)
530{
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200531 struct sk_buff *skb = NULL;
532 int size;
533 void *ptr;
534 int ret = -ENOMEM;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300535
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300536
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200537 if (wl->bss_type == BSS_TYPE_IBSS) {
538 size = sizeof(struct wl12xx_null_data_template);
539 ptr = NULL;
540 } else {
541 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
542 if (!skb)
543 goto out;
544 size = skb->len;
545 ptr = skb->data;
546 }
547
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300548 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
Juuso Oikarinen8eab7b42010-09-24 03:10:11 +0200549 wl->basic_rate);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300550
Kalle Valo899e6e62010-03-18 12:26:34 +0200551out:
552 dev_kfree_skb(skb);
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200553 if (ret)
554 wl1271_warning("cmd buld null data failed %d", ret);
555
Kalle Valo899e6e62010-03-18 12:26:34 +0200556 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300557
558}
559
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200560int wl1271_cmd_build_klv_null_data(struct wl1271 *wl)
561{
562 struct sk_buff *skb = NULL;
563 int ret = -ENOMEM;
564
565 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
566 if (!skb)
567 goto out;
568
569 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
570 skb->data, skb->len,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300571 CMD_TEMPL_KLV_IDX_NULL_DATA,
Juuso Oikarinen8eab7b42010-09-24 03:10:11 +0200572 wl->basic_rate);
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200573
574out:
575 dev_kfree_skb(skb);
576 if (ret)
577 wl1271_warning("cmd build klv null data failed %d", ret);
578
579 return ret;
580
581}
582
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300583int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
584{
Kalle Valo899e6e62010-03-18 12:26:34 +0200585 struct sk_buff *skb;
586 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300587
Kalle Valo899e6e62010-03-18 12:26:34 +0200588 skb = ieee80211_pspoll_get(wl->hw, wl->vif);
589 if (!skb)
590 goto out;
Juuso Oikarinenc3fea192009-10-08 21:56:22 +0300591
Kalle Valo899e6e62010-03-18 12:26:34 +0200592 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
Juuso Oikarinen849923f2010-07-08 17:49:59 +0300593 skb->len, 0, wl->basic_rate_set);
Juuso Oikarinenc3fea192009-10-08 21:56:22 +0300594
Kalle Valo899e6e62010-03-18 12:26:34 +0200595out:
596 dev_kfree_skb(skb);
597 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300598}
599
Kalle Valo818e3062010-03-18 12:26:35 +0200600int wl1271_cmd_build_probe_req(struct wl1271 *wl,
601 const u8 *ssid, size_t ssid_len,
602 const u8 *ie, size_t ie_len, u8 band)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300603{
Kalle Valo818e3062010-03-18 12:26:35 +0200604 struct sk_buff *skb;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300605 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300606
Kalle Valo818e3062010-03-18 12:26:35 +0200607 skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
608 ie, ie_len);
609 if (!skb) {
610 ret = -ENOMEM;
611 goto out;
612 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300613
Kalle Valo818e3062010-03-18 12:26:35 +0200614 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300615
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300616 if (band == IEEE80211_BAND_2GHZ)
617 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300618 skb->data, skb->len, 0,
619 wl->conf.tx.basic_rate);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300620 else
621 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300622 skb->data, skb->len, 0,
623 wl->conf.tx.basic_rate_5);
Kalle Valo818e3062010-03-18 12:26:35 +0200624
625out:
626 dev_kfree_skb(skb);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300627 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300628}
629
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +0200630struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
631 struct sk_buff *skb)
632{
633 int ret;
634
635 if (!skb)
636 skb = ieee80211_ap_probereq_get(wl->hw, wl->vif);
637 if (!skb)
638 goto out;
639
640 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
641
642 if (wl->band == IEEE80211_BAND_2GHZ)
643 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
644 skb->data, skb->len, 0,
645 wl->conf.tx.basic_rate);
646 else
647 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
648 skb->data, skb->len, 0,
649 wl->conf.tx.basic_rate_5);
650
651 if (ret < 0)
652 wl1271_error("Unable to set ap probe request template.");
653
654out:
655 return skb;
656}
657
Eliad Pellerc5312772010-12-09 11:31:27 +0200658int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr)
659{
660 int ret;
661 struct wl12xx_arp_rsp_template tmpl;
662 struct ieee80211_hdr_3addr *hdr;
663 struct arphdr *arp_hdr;
664
665 memset(&tmpl, 0, sizeof(tmpl));
666
667 /* mac80211 header */
668 hdr = &tmpl.hdr;
669 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
670 IEEE80211_STYPE_DATA |
671 IEEE80211_FCTL_TODS);
672 memcpy(hdr->addr1, wl->vif->bss_conf.bssid, ETH_ALEN);
673 memcpy(hdr->addr2, wl->vif->addr, ETH_ALEN);
674 memset(hdr->addr3, 0xff, ETH_ALEN);
675
676 /* llc layer */
677 memcpy(tmpl.llc_hdr, rfc1042_header, sizeof(rfc1042_header));
Eliad Peller6177eae2010-12-22 12:38:52 +0100678 tmpl.llc_type = cpu_to_be16(ETH_P_ARP);
Eliad Pellerc5312772010-12-09 11:31:27 +0200679
680 /* arp header */
681 arp_hdr = &tmpl.arp_hdr;
Eliad Peller6177eae2010-12-22 12:38:52 +0100682 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
683 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
Eliad Pellerc5312772010-12-09 11:31:27 +0200684 arp_hdr->ar_hln = ETH_ALEN;
685 arp_hdr->ar_pln = 4;
Eliad Peller6177eae2010-12-22 12:38:52 +0100686 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
Eliad Pellerc5312772010-12-09 11:31:27 +0200687
688 /* arp payload */
689 memcpy(tmpl.sender_hw, wl->vif->addr, ETH_ALEN);
690 tmpl.sender_ip = ip_addr;
691
692 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP,
693 &tmpl, sizeof(tmpl), 0,
694 wl->basic_rate);
695
696 return ret;
697}
698
Kalle Valo023e0822010-03-18 12:26:36 +0200699int wl1271_build_qos_null_data(struct wl1271 *wl)
700{
701 struct ieee80211_qos_hdr template;
702
703 memset(&template, 0, sizeof(template));
704
705 memcpy(template.addr1, wl->bssid, ETH_ALEN);
706 memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
707 memcpy(template.addr3, wl->bssid, ETH_ALEN);
708
709 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
710 IEEE80211_STYPE_QOS_NULLFUNC |
711 IEEE80211_FCTL_TODS);
712
713 /* FIXME: not sure what priority to use here */
714 template.qos_ctrl = cpu_to_le16(0);
715
716 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300717 sizeof(template), 0,
Juuso Oikarinen8eab7b42010-09-24 03:10:11 +0200718 wl->basic_rate);
Kalle Valo023e0822010-03-18 12:26:36 +0200719}
720
Arik Nemtsov98bdaab2010-10-16 18:08:58 +0200721int wl1271_cmd_set_sta_default_wep_key(struct wl1271 *wl, u8 id)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300722{
Arik Nemtsov98bdaab2010-10-16 18:08:58 +0200723 struct wl1271_cmd_set_sta_keys *cmd;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300724 int ret = 0;
725
726 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
727
728 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
729 if (!cmd) {
730 ret = -ENOMEM;
731 goto out;
732 }
733
734 cmd->id = id;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300735 cmd->key_action = cpu_to_le16(KEY_SET_ID);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300736 cmd->key_type = KEY_WEP;
737
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200738 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300739 if (ret < 0) {
740 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
741 goto out;
742 }
743
744out:
745 kfree(cmd);
746
747 return ret;
748}
749
Arik Nemtsov98bdaab2010-10-16 18:08:58 +0200750int wl1271_cmd_set_ap_default_wep_key(struct wl1271 *wl, u8 id)
751{
752 struct wl1271_cmd_set_ap_keys *cmd;
753 int ret = 0;
754
755 wl1271_debug(DEBUG_CMD, "cmd set_ap_default_wep_key %d", id);
756
757 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
758 if (!cmd) {
759 ret = -ENOMEM;
760 goto out;
761 }
762
763 cmd->hlid = WL1271_AP_BROADCAST_HLID;
764 cmd->key_id = id;
765 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
766 cmd->key_action = cpu_to_le16(KEY_SET_ID);
767 cmd->key_type = KEY_WEP;
768
769 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
770 if (ret < 0) {
771 wl1271_warning("cmd set_ap_default_wep_key failed: %d", ret);
772 goto out;
773 }
774
775out:
776 kfree(cmd);
777
778 return ret;
779}
780
781int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300782 u8 key_size, const u8 *key, const u8 *addr,
783 u32 tx_seq_32, u16 tx_seq_16)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300784{
Arik Nemtsov98bdaab2010-10-16 18:08:58 +0200785 struct wl1271_cmd_set_sta_keys *cmd;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300786 int ret = 0;
787
788 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
789 if (!cmd) {
790 ret = -ENOMEM;
791 goto out;
792 }
793
794 if (key_type != KEY_WEP)
795 memcpy(cmd->addr, addr, ETH_ALEN);
796
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300797 cmd->key_action = cpu_to_le16(action);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300798 cmd->key_size = key_size;
799 cmd->key_type = key_type;
800
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300801 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
802 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300803
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300804 /* we have only one SSID profile */
805 cmd->ssid_profile = 0;
806
807 cmd->id = id;
808
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300809 if (key_type == KEY_TKIP) {
810 /*
811 * We get the key in the following form:
812 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
813 * but the target is expecting:
814 * TKIP - RX MIC - TX MIC
815 */
816 memcpy(cmd->key, key, 16);
817 memcpy(cmd->key + 16, key + 24, 8);
818 memcpy(cmd->key + 24, key + 16, 8);
819
820 } else {
821 memcpy(cmd->key, key, key_size);
822 }
823
824 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
825
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200826 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300827 if (ret < 0) {
828 wl1271_warning("could not set keys");
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200829 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300830 }
831
832out:
833 kfree(cmd);
834
835 return ret;
836}
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300837
Arik Nemtsov98bdaab2010-10-16 18:08:58 +0200838int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
839 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
840 u16 tx_seq_16)
841{
842 struct wl1271_cmd_set_ap_keys *cmd;
843 int ret = 0;
844 u8 lid_type;
845
846 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
847 if (!cmd)
848 return -ENOMEM;
849
850 if (hlid == WL1271_AP_BROADCAST_HLID) {
851 if (key_type == KEY_WEP)
852 lid_type = WEP_DEFAULT_LID_TYPE;
853 else
854 lid_type = BROADCAST_LID_TYPE;
855 } else {
856 lid_type = UNICAST_LID_TYPE;
857 }
858
859 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
860 " hlid: %d", (int)action, (int)id, (int)lid_type,
861 (int)key_type, (int)hlid);
862
863 cmd->lid_key_type = lid_type;
864 cmd->hlid = hlid;
865 cmd->key_action = cpu_to_le16(action);
866 cmd->key_size = key_size;
867 cmd->key_type = key_type;
868 cmd->key_id = id;
869 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
870 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
871
872 if (key_type == KEY_TKIP) {
873 /*
874 * We get the key in the following form:
875 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
876 * but the target is expecting:
877 * TKIP - RX MIC - TX MIC
878 */
879 memcpy(cmd->key, key, 16);
880 memcpy(cmd->key + 16, key + 24, 8);
881 memcpy(cmd->key + 24, key + 16, 8);
882 } else {
883 memcpy(cmd->key, key, key_size);
884 }
885
886 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
887
888 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
889 if (ret < 0) {
890 wl1271_warning("could not set ap keys");
891 goto out;
892 }
893
894out:
895 kfree(cmd);
896 return ret;
897}
898
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300899int wl1271_cmd_disconnect(struct wl1271 *wl)
900{
901 struct wl1271_cmd_disconnect *cmd;
902 int ret = 0;
903
904 wl1271_debug(DEBUG_CMD, "cmd disconnect");
905
906 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
907 if (!cmd) {
908 ret = -ENOMEM;
909 goto out;
910 }
911
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300912 cmd->rx_config_options = cpu_to_le32(wl->rx_config);
913 cmd->rx_filter_options = cpu_to_le32(wl->rx_filter);
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300914 /* disconnect reason is not used in immediate disconnections */
915 cmd->type = DISCONNECT_IMMEDIATE;
916
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200917 ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300918 if (ret < 0) {
919 wl1271_error("failed to send disconnect command");
920 goto out_free;
921 }
922
Luciano Coelho2f826f52010-03-26 12:53:21 +0200923 ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
924 if (ret < 0)
925 wl1271_error("cmd disconnect event completion error");
926
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300927out_free:
928 kfree(cmd);
929
930out:
931 return ret;
932}
Juuso Oikarinenbe86cbe2010-05-27 12:53:01 +0300933
934int wl1271_cmd_set_sta_state(struct wl1271 *wl)
935{
936 struct wl1271_cmd_set_sta_state *cmd;
937 int ret = 0;
938
939 wl1271_debug(DEBUG_CMD, "cmd set sta state");
940
941 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
942 if (!cmd) {
943 ret = -ENOMEM;
944 goto out;
945 }
946
947 cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
948
949 ret = wl1271_cmd_send(wl, CMD_SET_STA_STATE, cmd, sizeof(*cmd), 0);
950 if (ret < 0) {
951 wl1271_error("failed to send set STA state command");
952 goto out_free;
953 }
954
955out_free:
956 kfree(cmd);
957
958out:
959 return ret;
960}
Arik Nemtsov98bdaab2010-10-16 18:08:58 +0200961
962int wl1271_cmd_start_bss(struct wl1271 *wl)
963{
964 struct wl1271_cmd_bss_start *cmd;
965 struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf;
966 int ret;
967
968 wl1271_debug(DEBUG_CMD, "cmd start bss");
969
970 /*
971 * FIXME: We currently do not support hidden SSID. The real SSID
972 * should be fetched from mac80211 first.
973 */
974 if (wl->ssid_len == 0) {
975 wl1271_warning("Hidden SSID currently not supported for AP");
976 ret = -EINVAL;
977 goto out;
978 }
979
980 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
981 if (!cmd) {
982 ret = -ENOMEM;
983 goto out;
984 }
985
986 memcpy(cmd->bssid, bss_conf->bssid, ETH_ALEN);
987
Eliad Peller1d4801f2011-01-16 10:07:10 +0100988 cmd->aging_period = cpu_to_le16(WL1271_AP_DEF_INACTIV_SEC);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +0200989 cmd->bss_index = WL1271_AP_BSS_INDEX;
990 cmd->global_hlid = WL1271_AP_GLOBAL_HLID;
991 cmd->broadcast_hlid = WL1271_AP_BROADCAST_HLID;
992 cmd->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
993 cmd->beacon_interval = cpu_to_le16(wl->beacon_int);
994 cmd->dtim_interval = bss_conf->dtim_period;
995 cmd->beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
996 cmd->channel = wl->channel;
997 cmd->ssid_len = wl->ssid_len;
998 cmd->ssid_type = SSID_TYPE_PUBLIC;
999 memcpy(cmd->ssid, wl->ssid, wl->ssid_len);
1000
1001 switch (wl->band) {
1002 case IEEE80211_BAND_2GHZ:
1003 cmd->band = RADIO_BAND_2_4GHZ;
1004 break;
1005 case IEEE80211_BAND_5GHZ:
1006 cmd->band = RADIO_BAND_5GHZ;
1007 break;
1008 default:
1009 wl1271_warning("bss start - unknown band: %d", (int)wl->band);
1010 cmd->band = RADIO_BAND_2_4GHZ;
1011 break;
1012 }
1013
1014 ret = wl1271_cmd_send(wl, CMD_BSS_START, cmd, sizeof(*cmd), 0);
1015 if (ret < 0) {
1016 wl1271_error("failed to initiate cmd start bss");
1017 goto out_free;
1018 }
1019
1020out_free:
1021 kfree(cmd);
1022
1023out:
1024 return ret;
1025}
1026
1027int wl1271_cmd_stop_bss(struct wl1271 *wl)
1028{
1029 struct wl1271_cmd_bss_start *cmd;
1030 int ret;
1031
1032 wl1271_debug(DEBUG_CMD, "cmd stop bss");
1033
1034 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1035 if (!cmd) {
1036 ret = -ENOMEM;
1037 goto out;
1038 }
1039
1040 cmd->bss_index = WL1271_AP_BSS_INDEX;
1041
1042 ret = wl1271_cmd_send(wl, CMD_BSS_STOP, cmd, sizeof(*cmd), 0);
1043 if (ret < 0) {
1044 wl1271_error("failed to initiate cmd stop bss");
1045 goto out_free;
1046 }
1047
1048out_free:
1049 kfree(cmd);
1050
1051out:
1052 return ret;
1053}
1054
1055int wl1271_cmd_add_sta(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid)
1056{
1057 struct wl1271_cmd_add_sta *cmd;
1058 int ret;
1059
1060 wl1271_debug(DEBUG_CMD, "cmd add sta %d", (int)hlid);
1061
1062 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1063 if (!cmd) {
1064 ret = -ENOMEM;
1065 goto out;
1066 }
1067
1068 /* currently we don't support UAPSD */
1069 cmd->sp_len = 0;
1070
1071 memcpy(cmd->addr, sta->addr, ETH_ALEN);
1072 cmd->bss_index = WL1271_AP_BSS_INDEX;
1073 cmd->aid = sta->aid;
1074 cmd->hlid = hlid;
1075
1076 /*
1077 * FIXME: Does STA support QOS? We need to propagate this info from
1078 * hostapd. Currently not that important since this is only used for
1079 * sending the correct flavor of null-data packet in response to a
1080 * trigger.
1081 */
1082 cmd->wmm = 0;
1083
1084 cmd->supported_rates = cpu_to_le32(wl1271_tx_enabled_rates_get(wl,
1085 sta->supp_rates[wl->band]));
1086
1087 wl1271_debug(DEBUG_CMD, "new sta rates: 0x%x", cmd->supported_rates);
1088
1089 ret = wl1271_cmd_send(wl, CMD_ADD_STA, cmd, sizeof(*cmd), 0);
1090 if (ret < 0) {
1091 wl1271_error("failed to initiate cmd add sta");
1092 goto out_free;
1093 }
1094
1095out_free:
1096 kfree(cmd);
1097
1098out:
1099 return ret;
1100}
1101
1102int wl1271_cmd_remove_sta(struct wl1271 *wl, u8 hlid)
1103{
1104 struct wl1271_cmd_remove_sta *cmd;
1105 int ret;
1106
1107 wl1271_debug(DEBUG_CMD, "cmd remove sta %d", (int)hlid);
1108
1109 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1110 if (!cmd) {
1111 ret = -ENOMEM;
1112 goto out;
1113 }
1114
1115 cmd->hlid = hlid;
1116 /* We never send a deauth, mac80211 is in charge of this */
1117 cmd->reason_opcode = 0;
1118 cmd->send_deauth_flag = 0;
1119
1120 ret = wl1271_cmd_send(wl, CMD_REMOVE_STA, cmd, sizeof(*cmd), 0);
1121 if (ret < 0) {
1122 wl1271_error("failed to initiate cmd remove sta");
1123 goto out_free;
1124 }
1125
Arik Nemtsov05285cf2010-11-12 17:15:03 +02001126 /*
1127 * We are ok with a timeout here. The event is sometimes not sent
1128 * due to a firmware bug.
1129 */
1130 wl1271_cmd_wait_for_event_or_timeout(wl, STA_REMOVE_COMPLETE_EVENT_ID);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001131
1132out_free:
1133 kfree(cmd);
1134
1135out:
1136 return ret;
1137}