blob: 2468044285172ad4905b6102ac729bd2119a3873 [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;
Shahar Levi49d750ca2011-03-06 16:32:09 +0200113 struct wl1271_ini_general_params *gp =
114 &((struct wl1271_nvs_file *)wl->nvs)->general_params;
115 bool answer = false;
116 int ret;
117
118 if (!wl->nvs)
119 return -ENODEV;
120
121 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
122 if (!gen_parms)
123 return -ENOMEM;
124
125 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
126
127 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
128
129 if (gp->tx_bip_fem_auto_detect)
130 answer = true;
131
132 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
133 if (ret < 0) {
134 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
135 goto out;
136 }
137
138 gp->tx_bip_fem_manufacturer =
139 gen_parms->general_params.tx_bip_fem_manufacturer;
140
141 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
142 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
143
144out:
145 kfree(gen_parms);
146 return ret;
147}
148
149int wl128x_cmd_general_parms(struct wl1271 *wl)
150{
151 struct wl128x_general_parms_cmd *gen_parms;
152 struct wl128x_ini_general_params *gp =
153 &((struct wl128x_nvs_file *)wl->nvs)->general_params;
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300154 bool answer = false;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200155 int ret;
156
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200157 if (!wl->nvs)
158 return -ENODEV;
159
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200160 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
161 if (!gen_parms)
162 return -ENOMEM;
163
164 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
165
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300166 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
Luciano Coelho76c0f8d2009-12-11 15:40:41 +0200167
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300168 if (gp->tx_bip_fem_auto_detect)
169 answer = true;
170
171 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
172 if (ret < 0) {
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200173 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300174 goto out;
175 }
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200176
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300177 gp->tx_bip_fem_manufacturer =
178 gen_parms->general_params.tx_bip_fem_manufacturer;
179
180 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
181 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
182
183out:
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200184 kfree(gen_parms);
185 return ret;
186}
187
188int wl1271_cmd_radio_parms(struct wl1271 *wl)
189{
Shahar Levibc765bf2011-03-06 16:32:10 +0200190 struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200191 struct wl1271_radio_parms_cmd *radio_parms;
Shahar Levibc765bf2011-03-06 16:32:10 +0200192 struct wl1271_ini_general_params *gp = &nvs->general_params;
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200193 int ret;
194
195 if (!wl->nvs)
196 return -ENODEV;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200197
198 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
199 if (!radio_parms)
200 return -ENOMEM;
201
202 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
203
Juuso Oikarinena7da74f2010-05-14 10:46:23 +0300204 /* 2.4GHz parameters */
Shahar Levibc765bf2011-03-06 16:32:10 +0200205 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
Juuso Oikarineneb70eb72010-05-14 10:46:22 +0300206 sizeof(struct wl1271_ini_band_params_2));
207 memcpy(&radio_parms->dyn_params_2,
Shahar Levibc765bf2011-03-06 16:32:10 +0200208 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
Juuso Oikarineneb70eb72010-05-14 10:46:22 +0300209 sizeof(struct wl1271_ini_fem_params_2));
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200210
Juuso Oikarinena7da74f2010-05-14 10:46:23 +0300211 /* 5GHz parameters */
212 memcpy(&radio_parms->static_params_5,
Shahar Levibc765bf2011-03-06 16:32:10 +0200213 &nvs->stat_radio_params_5,
Juuso Oikarinena7da74f2010-05-14 10:46:23 +0300214 sizeof(struct wl1271_ini_band_params_5));
215 memcpy(&radio_parms->dyn_params_5,
Shahar Levibc765bf2011-03-06 16:32:10 +0200216 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
Juuso Oikarinena7da74f2010-05-14 10:46:23 +0300217 sizeof(struct wl1271_ini_fem_params_5));
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200218
219 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
220 radio_parms, sizeof(*radio_parms));
221
222 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
223 if (ret < 0)
224 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
225
226 kfree(radio_parms);
227 return ret;
228}
229
Shahar Levi49d750ca2011-03-06 16:32:09 +0200230int wl128x_cmd_radio_parms(struct wl1271 *wl)
231{
232 struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
233 struct wl128x_radio_parms_cmd *radio_parms;
234 struct wl128x_ini_general_params *gp = &nvs->general_params;
235 int ret;
236
237 if (!wl->nvs)
238 return -ENODEV;
239
240 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
241 if (!radio_parms)
242 return -ENOMEM;
243
244 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
245
246 /* 2.4GHz parameters */
247 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
248 sizeof(struct wl128x_ini_band_params_2));
249 memcpy(&radio_parms->dyn_params_2,
250 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
251 sizeof(struct wl128x_ini_fem_params_2));
252
253 /* 5GHz parameters */
254 memcpy(&radio_parms->static_params_5,
255 &nvs->stat_radio_params_5,
256 sizeof(struct wl128x_ini_band_params_5));
257 memcpy(&radio_parms->dyn_params_5,
258 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
259 sizeof(struct wl128x_ini_fem_params_5));
260
261 radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options;
262
263 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
264 radio_parms, sizeof(*radio_parms));
265
266 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
267 if (ret < 0)
268 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
269
270 kfree(radio_parms);
271 return ret;
272}
273
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200274int wl1271_cmd_ext_radio_parms(struct wl1271 *wl)
275{
276 struct wl1271_ext_radio_parms_cmd *ext_radio_parms;
277 struct conf_rf_settings *rf = &wl->conf.rf;
278 int ret;
279
280 if (!wl->nvs)
281 return -ENODEV;
282
283 ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL);
284 if (!ext_radio_parms)
285 return -ENOMEM;
286
287 ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM;
288
289 memcpy(ext_radio_parms->tx_per_channel_power_compensation_2,
290 rf->tx_per_channel_power_compensation_2,
291 CONF_TX_PWR_COMPENSATION_LEN_2);
292 memcpy(ext_radio_parms->tx_per_channel_power_compensation_5,
293 rf->tx_per_channel_power_compensation_5,
294 CONF_TX_PWR_COMPENSATION_LEN_5);
295
296 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
297 ext_radio_parms, sizeof(*ext_radio_parms));
298
299 ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0);
300 if (ret < 0)
301 wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
302
303 kfree(ext_radio_parms);
304 return ret;
305}
306
Luciano Coelho99d84c12010-03-26 12:53:20 +0200307/*
308 * Poll the mailbox event field until any of the bits in the mask is set or a
309 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
310 */
Arik Nemtsov05285cf2010-11-12 17:15:03 +0200311static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask)
Luciano Coelho99d84c12010-03-26 12:53:20 +0200312{
313 u32 events_vector, event;
314 unsigned long timeout;
315
316 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
317
318 do {
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +0200319 if (time_after(jiffies, timeout)) {
Arik Nemtsov05285cf2010-11-12 17:15:03 +0200320 wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
321 (int)mask);
Luciano Coelho99d84c12010-03-26 12:53:20 +0200322 return -ETIMEDOUT;
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +0200323 }
Luciano Coelho99d84c12010-03-26 12:53:20 +0200324
325 msleep(1);
326
327 /* read from both event fields */
328 wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
329 sizeof(events_vector), false);
330 event = events_vector & mask;
331 wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
332 sizeof(events_vector), false);
333 event |= events_vector & mask;
334 } while (!event);
335
336 return 0;
337}
338
Arik Nemtsov05285cf2010-11-12 17:15:03 +0200339static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
340{
341 int ret;
342
343 ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask);
344 if (ret != 0) {
345 ieee80211_queue_work(wl->hw, &wl->recovery_work);
346 return ret;
347 }
348
349 return 0;
350}
351
Juuso Oikarinen15305492010-02-22 08:38:32 +0200352int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300353{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300354 struct wl1271_cmd_join *join;
355 int ret, i;
356 u8 *bssid;
357
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300358 join = kzalloc(sizeof(*join), GFP_KERNEL);
359 if (!join) {
360 ret = -ENOMEM;
361 goto out;
362 }
363
364 wl1271_debug(DEBUG_CMD, "cmd join");
365
366 /* Reverse order BSSID */
367 bssid = (u8 *) &join->bssid_lsb;
368 for (i = 0; i < ETH_ALEN; i++)
369 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
370
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300371 join->rx_config_options = cpu_to_le32(wl->rx_config);
372 join->rx_filter_options = cpu_to_le32(wl->rx_filter);
Juuso Oikarinen15305492010-02-22 08:38:32 +0200373 join->bss_type = bss_type;
Luciano Coelho23a7a512010-04-28 09:50:02 +0300374 join->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
Eliad Peller72c2d9e2011-02-02 09:59:37 +0200375 join->supported_rate_set = cpu_to_le32(wl->rate_set);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300376
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300377 if (wl->band == IEEE80211_BAND_5GHZ)
Teemu Paasikivia4102642009-10-13 12:47:51 +0300378 join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300379
Juuso Oikarinen60e84c22010-03-26 12:53:25 +0200380 join->beacon_interval = cpu_to_le16(wl->beacon_int);
Luciano Coelhoae751ba2009-10-12 15:08:57 +0300381 join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD;
Teemu Paasikivia4102642009-10-13 12:47:51 +0300382
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300383 join->channel = wl->channel;
384 join->ssid_len = wl->ssid_len;
385 memcpy(join->ssid, wl->ssid, wl->ssid_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300386
387 join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
388
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300389 /* reset TX security counters */
390 wl->tx_security_last_seq = 0;
Juuso Oikarinen04e36fc2010-02-22 08:38:40 +0200391 wl->tx_security_seq = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300392
Eliad Peller72c2d9e2011-02-02 09:59:37 +0200393 wl1271_debug(DEBUG_CMD, "cmd join: basic_rate_set=0x%x, rate_set=0x%x",
394 join->basic_rate_set, join->supported_rate_set);
395
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200396 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300397 if (ret < 0) {
398 wl1271_error("failed to initiate cmd join");
399 goto out_free;
400 }
401
Luciano Coelho99d84c12010-03-26 12:53:20 +0200402 ret = wl1271_cmd_wait_for_event(wl, JOIN_EVENT_COMPLETE_ID);
403 if (ret < 0)
404 wl1271_error("cmd join event completion error");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300405
406out_free:
407 kfree(join);
408
409out:
410 return ret;
411}
412
413/**
414 * send test command to firmware
415 *
416 * @wl: wl struct
417 * @buf: buffer containing the command, with all headers, must work with dma
418 * @len: length of the buffer
419 * @answer: is answer needed
420 */
421int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
422{
423 int ret;
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200424 size_t res_len = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300425
426 wl1271_debug(DEBUG_CMD, "cmd test");
427
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200428 if (answer)
429 res_len = buf_len;
430
431 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300432
433 if (ret < 0) {
434 wl1271_warning("TEST command failed");
435 return ret;
436 }
437
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200438 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300439}
440
441/**
442 * read acx from firmware
443 *
444 * @wl: wl struct
445 * @id: acx id
446 * @buf: buffer for the response, including all headers, must work with dma
447 * @len: lenght of buf
448 */
449int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
450{
451 struct acx_header *acx = buf;
452 int ret;
453
454 wl1271_debug(DEBUG_CMD, "cmd interrogate");
455
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300456 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300457
458 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300459 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300460
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200461 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
462 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300463 wl1271_error("INTERROGATE command failed");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300464
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300465 return ret;
466}
467
468/**
469 * write acx value to firmware
470 *
471 * @wl: wl struct
472 * @id: acx id
473 * @buf: buffer containing acx, including all headers, must work with dma
474 * @len: length of buf
475 */
476int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
477{
478 struct acx_header *acx = buf;
479 int ret;
480
481 wl1271_debug(DEBUG_CMD, "cmd configure");
482
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300483 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300484
485 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300486 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300487
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200488 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300489 if (ret < 0) {
490 wl1271_warning("CONFIGURE command NOK");
491 return ret;
492 }
493
494 return 0;
495}
496
Luciano Coelho94210892009-12-11 15:40:55 +0200497int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300498{
499 struct cmd_enabledisable_path *cmd;
500 int ret;
501 u16 cmd_rx, cmd_tx;
502
503 wl1271_debug(DEBUG_CMD, "cmd data path");
504
505 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
506 if (!cmd) {
507 ret = -ENOMEM;
508 goto out;
509 }
510
Luciano Coelho94210892009-12-11 15:40:55 +0200511 /* the channel here is only used for calibration, so hardcoded to 1 */
512 cmd->channel = 1;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300513
514 if (enable) {
515 cmd_rx = CMD_ENABLE_RX;
516 cmd_tx = CMD_ENABLE_TX;
517 } else {
518 cmd_rx = CMD_DISABLE_RX;
519 cmd_tx = CMD_DISABLE_TX;
520 }
521
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200522 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300523 if (ret < 0) {
524 wl1271_error("rx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200525 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300526 goto out;
527 }
528
529 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200530 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300531
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200532 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300533 if (ret < 0) {
534 wl1271_error("tx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200535 enable ? "start" : "stop", cmd->channel);
Juuso Oikarinen1b00f2b2010-03-26 12:53:17 +0200536 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300537 }
538
539 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200540 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300541
542out:
543 kfree(cmd);
544 return ret;
545}
546
Eliad Pellerc8bde242011-02-02 09:59:35 +0200547int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300548{
549 struct wl1271_cmd_ps_params *ps_params = NULL;
550 int ret = 0;
551
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300552 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
553
554 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
555 if (!ps_params) {
556 ret = -ENOMEM;
557 goto out;
558 }
559
560 ps_params->ps_mode = ps_mode;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300561
562 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200563 sizeof(*ps_params), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300564 if (ret < 0) {
565 wl1271_error("cmd set_ps_mode failed");
566 goto out;
567 }
568
569out:
570 kfree(ps_params);
571 return ret;
572}
573
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300574int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300575 void *buf, size_t buf_len, int index, u32 rates)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300576{
577 struct wl1271_cmd_template_set *cmd;
578 int ret = 0;
579
580 wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
581
582 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
583 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
584
585 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
586 if (!cmd) {
587 ret = -ENOMEM;
588 goto out;
589 }
590
591 cmd->len = cpu_to_le16(buf_len);
592 cmd->template_type = template_id;
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300593 cmd->enabled_rates = cpu_to_le32(rates);
Arik Nemtsov1e05a812010-10-16 17:44:51 +0200594 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
595 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200596 cmd->index = index;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300597
598 if (buf)
599 memcpy(cmd->template_data, buf, buf_len);
600
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200601 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300602 if (ret < 0) {
603 wl1271_warning("cmd set_template failed: %d", ret);
604 goto out_free;
605 }
606
607out_free:
608 kfree(cmd);
609
610out:
611 return ret;
612}
613
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300614int wl1271_cmd_build_null_data(struct wl1271 *wl)
615{
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200616 struct sk_buff *skb = NULL;
617 int size;
618 void *ptr;
619 int ret = -ENOMEM;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300620
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300621
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200622 if (wl->bss_type == BSS_TYPE_IBSS) {
623 size = sizeof(struct wl12xx_null_data_template);
624 ptr = NULL;
625 } else {
626 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
627 if (!skb)
628 goto out;
629 size = skb->len;
630 ptr = skb->data;
631 }
632
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300633 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
Juuso Oikarinen8eab7b42010-09-24 03:10:11 +0200634 wl->basic_rate);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300635
Kalle Valo899e6e62010-03-18 12:26:34 +0200636out:
637 dev_kfree_skb(skb);
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200638 if (ret)
639 wl1271_warning("cmd buld null data failed %d", ret);
640
Kalle Valo899e6e62010-03-18 12:26:34 +0200641 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300642
643}
644
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200645int wl1271_cmd_build_klv_null_data(struct wl1271 *wl)
646{
647 struct sk_buff *skb = NULL;
648 int ret = -ENOMEM;
649
650 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
651 if (!skb)
652 goto out;
653
654 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
655 skb->data, skb->len,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300656 CMD_TEMPL_KLV_IDX_NULL_DATA,
Juuso Oikarinen8eab7b42010-09-24 03:10:11 +0200657 wl->basic_rate);
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200658
659out:
660 dev_kfree_skb(skb);
661 if (ret)
662 wl1271_warning("cmd build klv null data failed %d", ret);
663
664 return ret;
665
666}
667
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300668int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
669{
Kalle Valo899e6e62010-03-18 12:26:34 +0200670 struct sk_buff *skb;
671 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300672
Kalle Valo899e6e62010-03-18 12:26:34 +0200673 skb = ieee80211_pspoll_get(wl->hw, wl->vif);
674 if (!skb)
675 goto out;
Juuso Oikarinenc3fea192009-10-08 21:56:22 +0300676
Kalle Valo899e6e62010-03-18 12:26:34 +0200677 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
Juuso Oikarinen849923f2010-07-08 17:49:59 +0300678 skb->len, 0, wl->basic_rate_set);
Juuso Oikarinenc3fea192009-10-08 21:56:22 +0300679
Kalle Valo899e6e62010-03-18 12:26:34 +0200680out:
681 dev_kfree_skb(skb);
682 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300683}
684
Kalle Valo818e3062010-03-18 12:26:35 +0200685int wl1271_cmd_build_probe_req(struct wl1271 *wl,
686 const u8 *ssid, size_t ssid_len,
687 const u8 *ie, size_t ie_len, u8 band)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300688{
Kalle Valo818e3062010-03-18 12:26:35 +0200689 struct sk_buff *skb;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300690 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300691
Kalle Valo818e3062010-03-18 12:26:35 +0200692 skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
693 ie, ie_len);
694 if (!skb) {
695 ret = -ENOMEM;
696 goto out;
697 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300698
Kalle Valo818e3062010-03-18 12:26:35 +0200699 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300700
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300701 if (band == IEEE80211_BAND_2GHZ)
702 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300703 skb->data, skb->len, 0,
704 wl->conf.tx.basic_rate);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300705 else
706 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300707 skb->data, skb->len, 0,
708 wl->conf.tx.basic_rate_5);
Kalle Valo818e3062010-03-18 12:26:35 +0200709
710out:
711 dev_kfree_skb(skb);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300712 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300713}
714
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +0200715struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
716 struct sk_buff *skb)
717{
718 int ret;
719
720 if (!skb)
721 skb = ieee80211_ap_probereq_get(wl->hw, wl->vif);
722 if (!skb)
723 goto out;
724
725 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
726
727 if (wl->band == IEEE80211_BAND_2GHZ)
728 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
729 skb->data, skb->len, 0,
730 wl->conf.tx.basic_rate);
731 else
732 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
733 skb->data, skb->len, 0,
734 wl->conf.tx.basic_rate_5);
735
736 if (ret < 0)
737 wl1271_error("Unable to set ap probe request template.");
738
739out:
740 return skb;
741}
742
Eliad Pellerc5312772010-12-09 11:31:27 +0200743int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr)
744{
745 int ret;
746 struct wl12xx_arp_rsp_template tmpl;
747 struct ieee80211_hdr_3addr *hdr;
748 struct arphdr *arp_hdr;
749
750 memset(&tmpl, 0, sizeof(tmpl));
751
752 /* mac80211 header */
753 hdr = &tmpl.hdr;
754 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
755 IEEE80211_STYPE_DATA |
756 IEEE80211_FCTL_TODS);
757 memcpy(hdr->addr1, wl->vif->bss_conf.bssid, ETH_ALEN);
758 memcpy(hdr->addr2, wl->vif->addr, ETH_ALEN);
759 memset(hdr->addr3, 0xff, ETH_ALEN);
760
761 /* llc layer */
762 memcpy(tmpl.llc_hdr, rfc1042_header, sizeof(rfc1042_header));
Eliad Peller6177eae2010-12-22 12:38:52 +0100763 tmpl.llc_type = cpu_to_be16(ETH_P_ARP);
Eliad Pellerc5312772010-12-09 11:31:27 +0200764
765 /* arp header */
766 arp_hdr = &tmpl.arp_hdr;
Eliad Peller6177eae2010-12-22 12:38:52 +0100767 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
768 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
Eliad Pellerc5312772010-12-09 11:31:27 +0200769 arp_hdr->ar_hln = ETH_ALEN;
770 arp_hdr->ar_pln = 4;
Eliad Peller6177eae2010-12-22 12:38:52 +0100771 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
Eliad Pellerc5312772010-12-09 11:31:27 +0200772
773 /* arp payload */
774 memcpy(tmpl.sender_hw, wl->vif->addr, ETH_ALEN);
775 tmpl.sender_ip = ip_addr;
776
777 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP,
778 &tmpl, sizeof(tmpl), 0,
779 wl->basic_rate);
780
781 return ret;
782}
783
Kalle Valo023e0822010-03-18 12:26:36 +0200784int wl1271_build_qos_null_data(struct wl1271 *wl)
785{
786 struct ieee80211_qos_hdr template;
787
788 memset(&template, 0, sizeof(template));
789
790 memcpy(template.addr1, wl->bssid, ETH_ALEN);
791 memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
792 memcpy(template.addr3, wl->bssid, ETH_ALEN);
793
794 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
795 IEEE80211_STYPE_QOS_NULLFUNC |
796 IEEE80211_FCTL_TODS);
797
798 /* FIXME: not sure what priority to use here */
799 template.qos_ctrl = cpu_to_le16(0);
800
801 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300802 sizeof(template), 0,
Juuso Oikarinen8eab7b42010-09-24 03:10:11 +0200803 wl->basic_rate);
Kalle Valo023e0822010-03-18 12:26:36 +0200804}
805
Arik Nemtsov98bdaab2010-10-16 18:08:58 +0200806int wl1271_cmd_set_sta_default_wep_key(struct wl1271 *wl, u8 id)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300807{
Arik Nemtsov98bdaab2010-10-16 18:08:58 +0200808 struct wl1271_cmd_set_sta_keys *cmd;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300809 int ret = 0;
810
811 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
812
813 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
814 if (!cmd) {
815 ret = -ENOMEM;
816 goto out;
817 }
818
819 cmd->id = id;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300820 cmd->key_action = cpu_to_le16(KEY_SET_ID);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300821 cmd->key_type = KEY_WEP;
822
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200823 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300824 if (ret < 0) {
825 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
826 goto out;
827 }
828
829out:
830 kfree(cmd);
831
832 return ret;
833}
834
Arik Nemtsov98bdaab2010-10-16 18:08:58 +0200835int wl1271_cmd_set_ap_default_wep_key(struct wl1271 *wl, u8 id)
836{
837 struct wl1271_cmd_set_ap_keys *cmd;
838 int ret = 0;
839
840 wl1271_debug(DEBUG_CMD, "cmd set_ap_default_wep_key %d", id);
841
842 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
843 if (!cmd) {
844 ret = -ENOMEM;
845 goto out;
846 }
847
848 cmd->hlid = WL1271_AP_BROADCAST_HLID;
849 cmd->key_id = id;
850 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
851 cmd->key_action = cpu_to_le16(KEY_SET_ID);
852 cmd->key_type = KEY_WEP;
853
854 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
855 if (ret < 0) {
856 wl1271_warning("cmd set_ap_default_wep_key failed: %d", ret);
857 goto out;
858 }
859
860out:
861 kfree(cmd);
862
863 return ret;
864}
865
866int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300867 u8 key_size, const u8 *key, const u8 *addr,
868 u32 tx_seq_32, u16 tx_seq_16)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300869{
Arik Nemtsov98bdaab2010-10-16 18:08:58 +0200870 struct wl1271_cmd_set_sta_keys *cmd;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300871 int ret = 0;
872
873 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
874 if (!cmd) {
875 ret = -ENOMEM;
876 goto out;
877 }
878
879 if (key_type != KEY_WEP)
880 memcpy(cmd->addr, addr, ETH_ALEN);
881
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300882 cmd->key_action = cpu_to_le16(action);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300883 cmd->key_size = key_size;
884 cmd->key_type = key_type;
885
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300886 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
887 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300888
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300889 /* we have only one SSID profile */
890 cmd->ssid_profile = 0;
891
892 cmd->id = id;
893
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300894 if (key_type == KEY_TKIP) {
895 /*
896 * We get the key in the following form:
897 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
898 * but the target is expecting:
899 * TKIP - RX MIC - TX MIC
900 */
901 memcpy(cmd->key, key, 16);
902 memcpy(cmd->key + 16, key + 24, 8);
903 memcpy(cmd->key + 24, key + 16, 8);
904
905 } else {
906 memcpy(cmd->key, key, key_size);
907 }
908
909 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
910
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200911 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300912 if (ret < 0) {
913 wl1271_warning("could not set keys");
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200914 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300915 }
916
917out:
918 kfree(cmd);
919
920 return ret;
921}
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300922
Arik Nemtsov98bdaab2010-10-16 18:08:58 +0200923int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
924 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
925 u16 tx_seq_16)
926{
927 struct wl1271_cmd_set_ap_keys *cmd;
928 int ret = 0;
929 u8 lid_type;
930
931 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
932 if (!cmd)
933 return -ENOMEM;
934
935 if (hlid == WL1271_AP_BROADCAST_HLID) {
936 if (key_type == KEY_WEP)
937 lid_type = WEP_DEFAULT_LID_TYPE;
938 else
939 lid_type = BROADCAST_LID_TYPE;
940 } else {
941 lid_type = UNICAST_LID_TYPE;
942 }
943
944 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
945 " hlid: %d", (int)action, (int)id, (int)lid_type,
946 (int)key_type, (int)hlid);
947
948 cmd->lid_key_type = lid_type;
949 cmd->hlid = hlid;
950 cmd->key_action = cpu_to_le16(action);
951 cmd->key_size = key_size;
952 cmd->key_type = key_type;
953 cmd->key_id = id;
954 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
955 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
956
957 if (key_type == KEY_TKIP) {
958 /*
959 * We get the key in the following form:
960 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
961 * but the target is expecting:
962 * TKIP - RX MIC - TX MIC
963 */
964 memcpy(cmd->key, key, 16);
965 memcpy(cmd->key + 16, key + 24, 8);
966 memcpy(cmd->key + 24, key + 16, 8);
967 } else {
968 memcpy(cmd->key, key, key_size);
969 }
970
971 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
972
973 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
974 if (ret < 0) {
975 wl1271_warning("could not set ap keys");
976 goto out;
977 }
978
979out:
980 kfree(cmd);
981 return ret;
982}
983
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300984int wl1271_cmd_disconnect(struct wl1271 *wl)
985{
986 struct wl1271_cmd_disconnect *cmd;
987 int ret = 0;
988
989 wl1271_debug(DEBUG_CMD, "cmd disconnect");
990
991 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
992 if (!cmd) {
993 ret = -ENOMEM;
994 goto out;
995 }
996
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300997 cmd->rx_config_options = cpu_to_le32(wl->rx_config);
998 cmd->rx_filter_options = cpu_to_le32(wl->rx_filter);
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300999 /* disconnect reason is not used in immediate disconnections */
1000 cmd->type = DISCONNECT_IMMEDIATE;
1001
Juuso Oikarinenfa867e72009-11-02 20:22:13 +02001002 ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
Luciano Coelho25a7dc62009-10-12 15:08:42 +03001003 if (ret < 0) {
1004 wl1271_error("failed to send disconnect command");
1005 goto out_free;
1006 }
1007
Luciano Coelho2f826f52010-03-26 12:53:21 +02001008 ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
1009 if (ret < 0)
1010 wl1271_error("cmd disconnect event completion error");
1011
Luciano Coelho25a7dc62009-10-12 15:08:42 +03001012out_free:
1013 kfree(cmd);
1014
1015out:
1016 return ret;
1017}
Juuso Oikarinenbe86cbe2010-05-27 12:53:01 +03001018
1019int wl1271_cmd_set_sta_state(struct wl1271 *wl)
1020{
1021 struct wl1271_cmd_set_sta_state *cmd;
1022 int ret = 0;
1023
1024 wl1271_debug(DEBUG_CMD, "cmd set sta state");
1025
1026 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1027 if (!cmd) {
1028 ret = -ENOMEM;
1029 goto out;
1030 }
1031
1032 cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
1033
1034 ret = wl1271_cmd_send(wl, CMD_SET_STA_STATE, cmd, sizeof(*cmd), 0);
1035 if (ret < 0) {
1036 wl1271_error("failed to send set STA state command");
1037 goto out_free;
1038 }
1039
1040out_free:
1041 kfree(cmd);
1042
1043out:
1044 return ret;
1045}
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001046
1047int wl1271_cmd_start_bss(struct wl1271 *wl)
1048{
1049 struct wl1271_cmd_bss_start *cmd;
1050 struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf;
1051 int ret;
1052
1053 wl1271_debug(DEBUG_CMD, "cmd start bss");
1054
1055 /*
1056 * FIXME: We currently do not support hidden SSID. The real SSID
1057 * should be fetched from mac80211 first.
1058 */
1059 if (wl->ssid_len == 0) {
1060 wl1271_warning("Hidden SSID currently not supported for AP");
1061 ret = -EINVAL;
1062 goto out;
1063 }
1064
1065 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1066 if (!cmd) {
1067 ret = -ENOMEM;
1068 goto out;
1069 }
1070
1071 memcpy(cmd->bssid, bss_conf->bssid, ETH_ALEN);
1072
Eliad Peller1d4801f2011-01-16 10:07:10 +01001073 cmd->aging_period = cpu_to_le16(WL1271_AP_DEF_INACTIV_SEC);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001074 cmd->bss_index = WL1271_AP_BSS_INDEX;
1075 cmd->global_hlid = WL1271_AP_GLOBAL_HLID;
1076 cmd->broadcast_hlid = WL1271_AP_BROADCAST_HLID;
1077 cmd->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
1078 cmd->beacon_interval = cpu_to_le16(wl->beacon_int);
1079 cmd->dtim_interval = bss_conf->dtim_period;
1080 cmd->beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
1081 cmd->channel = wl->channel;
1082 cmd->ssid_len = wl->ssid_len;
1083 cmd->ssid_type = SSID_TYPE_PUBLIC;
1084 memcpy(cmd->ssid, wl->ssid, wl->ssid_len);
1085
1086 switch (wl->band) {
1087 case IEEE80211_BAND_2GHZ:
1088 cmd->band = RADIO_BAND_2_4GHZ;
1089 break;
1090 case IEEE80211_BAND_5GHZ:
1091 cmd->band = RADIO_BAND_5GHZ;
1092 break;
1093 default:
1094 wl1271_warning("bss start - unknown band: %d", (int)wl->band);
1095 cmd->band = RADIO_BAND_2_4GHZ;
1096 break;
1097 }
1098
1099 ret = wl1271_cmd_send(wl, CMD_BSS_START, cmd, sizeof(*cmd), 0);
1100 if (ret < 0) {
1101 wl1271_error("failed to initiate cmd start bss");
1102 goto out_free;
1103 }
1104
1105out_free:
1106 kfree(cmd);
1107
1108out:
1109 return ret;
1110}
1111
1112int wl1271_cmd_stop_bss(struct wl1271 *wl)
1113{
1114 struct wl1271_cmd_bss_start *cmd;
1115 int ret;
1116
1117 wl1271_debug(DEBUG_CMD, "cmd stop bss");
1118
1119 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1120 if (!cmd) {
1121 ret = -ENOMEM;
1122 goto out;
1123 }
1124
1125 cmd->bss_index = WL1271_AP_BSS_INDEX;
1126
1127 ret = wl1271_cmd_send(wl, CMD_BSS_STOP, cmd, sizeof(*cmd), 0);
1128 if (ret < 0) {
1129 wl1271_error("failed to initiate cmd stop bss");
1130 goto out_free;
1131 }
1132
1133out_free:
1134 kfree(cmd);
1135
1136out:
1137 return ret;
1138}
1139
1140int wl1271_cmd_add_sta(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid)
1141{
1142 struct wl1271_cmd_add_sta *cmd;
1143 int ret;
1144
1145 wl1271_debug(DEBUG_CMD, "cmd add sta %d", (int)hlid);
1146
1147 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1148 if (!cmd) {
1149 ret = -ENOMEM;
1150 goto out;
1151 }
1152
1153 /* currently we don't support UAPSD */
1154 cmd->sp_len = 0;
1155
1156 memcpy(cmd->addr, sta->addr, ETH_ALEN);
1157 cmd->bss_index = WL1271_AP_BSS_INDEX;
1158 cmd->aid = sta->aid;
1159 cmd->hlid = hlid;
1160
1161 /*
1162 * FIXME: Does STA support QOS? We need to propagate this info from
1163 * hostapd. Currently not that important since this is only used for
1164 * sending the correct flavor of null-data packet in response to a
1165 * trigger.
1166 */
1167 cmd->wmm = 0;
1168
1169 cmd->supported_rates = cpu_to_le32(wl1271_tx_enabled_rates_get(wl,
1170 sta->supp_rates[wl->band]));
1171
1172 wl1271_debug(DEBUG_CMD, "new sta rates: 0x%x", cmd->supported_rates);
1173
1174 ret = wl1271_cmd_send(wl, CMD_ADD_STA, cmd, sizeof(*cmd), 0);
1175 if (ret < 0) {
1176 wl1271_error("failed to initiate cmd add sta");
1177 goto out_free;
1178 }
1179
1180out_free:
1181 kfree(cmd);
1182
1183out:
1184 return ret;
1185}
1186
1187int wl1271_cmd_remove_sta(struct wl1271 *wl, u8 hlid)
1188{
1189 struct wl1271_cmd_remove_sta *cmd;
1190 int ret;
1191
1192 wl1271_debug(DEBUG_CMD, "cmd remove sta %d", (int)hlid);
1193
1194 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1195 if (!cmd) {
1196 ret = -ENOMEM;
1197 goto out;
1198 }
1199
1200 cmd->hlid = hlid;
1201 /* We never send a deauth, mac80211 is in charge of this */
1202 cmd->reason_opcode = 0;
1203 cmd->send_deauth_flag = 0;
1204
1205 ret = wl1271_cmd_send(wl, CMD_REMOVE_STA, cmd, sizeof(*cmd), 0);
1206 if (ret < 0) {
1207 wl1271_error("failed to initiate cmd remove sta");
1208 goto out_free;
1209 }
1210
Arik Nemtsov05285cf2010-11-12 17:15:03 +02001211 /*
1212 * We are ok with a timeout here. The event is sometimes not sent
1213 * due to a firmware bug.
1214 */
1215 wl1271_cmd_wait_for_event_or_timeout(wl, STA_REMOVE_COMPLETE_EVENT_ID);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001216
1217out_free:
1218 kfree(cmd);
1219
1220out:
1221 return ret;
1222}