wl12xx: update commands & events
[deliverable/linux.git] / drivers / net / wireless / wl12xx / cmd.c
CommitLineData
f5fc0f86
LC
1/*
2 * This file is part of wl1271
3 *
2f826f55 4 * Copyright (C) 2009-2010 Nokia Corporation
f5fc0f86
LC
5 *
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>
f5fc0f86
LC
26#include <linux/spi/spi.h>
27#include <linux/etherdevice.h>
023e0826 28#include <linux/ieee80211.h>
5a0e3ad6 29#include <linux/slab.h>
f5fc0f86 30
00d20100
SL
31#include "wl12xx.h"
32#include "reg.h"
33#include "io.h"
34#include "acx.h"
f5fc0f86 35#include "wl12xx_80211.h"
00d20100
SL
36#include "cmd.h"
37#include "event.h"
98bdaabb 38#include "tx.h"
f5fc0f86 39
16092b5c 40#define WL1271_CMD_FAST_POLL_COUNT 50
f5fc0f86
LC
41
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 */
fa867e73
JO
50int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
51 size_t res_len)
f5fc0f86
LC
52{
53 struct wl1271_cmd_header *cmd;
54 unsigned long timeout;
55 u32 intr;
56 int ret = 0;
ad150e96 57 u16 status;
bc0f03ea 58 u16 poll_count = 0;
f5fc0f86
LC
59
60 cmd = buf;
d0f63b20 61 cmd->id = cpu_to_le16(id);
f5fc0f86
LC
62 cmd->status = 0;
63
64 WARN_ON(len % 4 != 0);
24225b37 65 WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
f5fc0f86 66
7b048c52 67 wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
f5fc0f86 68
7b048c52 69 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
f5fc0f86
LC
70
71 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
72
7b048c52 73 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
f5fc0f86
LC
74 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
75 if (time_after(jiffies, timeout)) {
76 wl1271_error("command complete timeout");
77 ret = -ETIMEDOUT;
f482b762 78 goto fail;
f5fc0f86
LC
79 }
80
bc0f03ea 81 poll_count++;
16092b5c
JO
82 if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
83 udelay(10);
84 else
85 msleep(1);
f5fc0f86 86
7b048c52 87 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
f5fc0f86
LC
88 }
89
3b775b4b 90 /* read back the status code of the command */
fa867e73
JO
91 if (res_len == 0)
92 res_len = sizeof(struct wl1271_cmd_header);
7b048c52 93 wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
3b775b4b 94
ad150e96
JO
95 status = le16_to_cpu(cmd->status);
96 if (status != CMD_STATUS_SUCCESS) {
97 wl1271_error("command execute failure %d", status);
3b775b4b 98 ret = -EIO;
f482b762 99 goto fail;
3b775b4b
JO
100 }
101
7b048c52
TP
102 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
103 WL1271_ACX_INTR_CMD_COMPLETE);
f482b762 104 return 0;
f5fc0f86 105
f482b762
AN
106fail:
107 WARN_ON(1);
baacb9ae 108 wl12xx_queue_recovery_work(wl);
f5fc0f86
LC
109 return ret;
110}
111
98b5dd5d
LC
112int wl1271_cmd_general_parms(struct wl1271 *wl)
113{
114 struct wl1271_general_parms_cmd *gen_parms;
49d750ca
SL
115 struct wl1271_ini_general_params *gp =
116 &((struct wl1271_nvs_file *)wl->nvs)->general_params;
117 bool answer = false;
118 int ret;
119
120 if (!wl->nvs)
121 return -ENODEV;
122
123 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
124 if (!gen_parms)
125 return -ENOMEM;
126
127 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
128
129 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
130
131 if (gp->tx_bip_fem_auto_detect)
132 answer = true;
133
b03acade
SL
134 /* Override the REF CLK from the NVS with the one from platform data */
135 gen_parms->general_params.ref_clock = wl->ref_clock;
136
0c005048
SL
137 /* LPD mode enable (bits 6-7) in WL1271 AP mode only */
138 if (wl->quirks & WL12XX_QUIRK_LPD_MODE)
139 gen_parms->general_params.general_settings |=
140 GENERAL_SETTINGS_DRPW_LPD;
141
49d750ca
SL
142 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
143 if (ret < 0) {
144 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
145 goto out;
146 }
147
148 gp->tx_bip_fem_manufacturer =
149 gen_parms->general_params.tx_bip_fem_manufacturer;
150
151 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
152 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
153
154out:
155 kfree(gen_parms);
156 return ret;
157}
158
159int wl128x_cmd_general_parms(struct wl1271 *wl)
160{
161 struct wl128x_general_parms_cmd *gen_parms;
162 struct wl128x_ini_general_params *gp =
163 &((struct wl128x_nvs_file *)wl->nvs)->general_params;
4b34d432 164 bool answer = false;
98b5dd5d
LC
165 int ret;
166
152ee6e0
JO
167 if (!wl->nvs)
168 return -ENODEV;
169
98b5dd5d
LC
170 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
171 if (!gen_parms)
172 return -ENOMEM;
173
174 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
175
4b34d432
JO
176 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
177
178 if (gp->tx_bip_fem_auto_detect)
179 answer = true;
76c0f8d3 180
b03acade
SL
181 /* Replace REF and TCXO CLKs with the ones from platform data */
182 gen_parms->general_params.ref_clock = wl->ref_clock;
183 gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock;
184
4b34d432
JO
185 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
186 if (ret < 0) {
98b5dd5d 187 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
4b34d432
JO
188 goto out;
189 }
98b5dd5d 190
4b34d432
JO
191 gp->tx_bip_fem_manufacturer =
192 gen_parms->general_params.tx_bip_fem_manufacturer;
193
194 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
195 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
196
197out:
98b5dd5d
LC
198 kfree(gen_parms);
199 return ret;
200}
201
202int wl1271_cmd_radio_parms(struct wl1271 *wl)
203{
bc765bf3 204 struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs;
98b5dd5d 205 struct wl1271_radio_parms_cmd *radio_parms;
bc765bf3 206 struct wl1271_ini_general_params *gp = &nvs->general_params;
152ee6e0
JO
207 int ret;
208
209 if (!wl->nvs)
210 return -ENODEV;
98b5dd5d
LC
211
212 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
213 if (!radio_parms)
214 return -ENOMEM;
215
216 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
217
a7da74fc 218 /* 2.4GHz parameters */
bc765bf3 219 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
eb70eb72
JO
220 sizeof(struct wl1271_ini_band_params_2));
221 memcpy(&radio_parms->dyn_params_2,
bc765bf3 222 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
eb70eb72 223 sizeof(struct wl1271_ini_fem_params_2));
152ee6e0 224
a7da74fc
JO
225 /* 5GHz parameters */
226 memcpy(&radio_parms->static_params_5,
bc765bf3 227 &nvs->stat_radio_params_5,
a7da74fc
JO
228 sizeof(struct wl1271_ini_band_params_5));
229 memcpy(&radio_parms->dyn_params_5,
bc765bf3 230 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
a7da74fc 231 sizeof(struct wl1271_ini_fem_params_5));
98b5dd5d
LC
232
233 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
234 radio_parms, sizeof(*radio_parms));
235
236 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
237 if (ret < 0)
238 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
239
240 kfree(radio_parms);
241 return ret;
242}
243
49d750ca
SL
244int wl128x_cmd_radio_parms(struct wl1271 *wl)
245{
246 struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
247 struct wl128x_radio_parms_cmd *radio_parms;
248 struct wl128x_ini_general_params *gp = &nvs->general_params;
249 int ret;
250
251 if (!wl->nvs)
252 return -ENODEV;
253
254 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
255 if (!radio_parms)
256 return -ENOMEM;
257
258 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
259
260 /* 2.4GHz parameters */
261 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
262 sizeof(struct wl128x_ini_band_params_2));
263 memcpy(&radio_parms->dyn_params_2,
264 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
265 sizeof(struct wl128x_ini_fem_params_2));
266
267 /* 5GHz parameters */
268 memcpy(&radio_parms->static_params_5,
269 &nvs->stat_radio_params_5,
270 sizeof(struct wl128x_ini_band_params_5));
271 memcpy(&radio_parms->dyn_params_5,
272 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
273 sizeof(struct wl128x_ini_fem_params_5));
274
275 radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options;
276
277 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
278 radio_parms, sizeof(*radio_parms));
279
280 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
98b5dd5d
LC
281 if (ret < 0)
282 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
283
284 kfree(radio_parms);
285 return ret;
286}
287
644a4860
JO
288int wl1271_cmd_ext_radio_parms(struct wl1271 *wl)
289{
290 struct wl1271_ext_radio_parms_cmd *ext_radio_parms;
291 struct conf_rf_settings *rf = &wl->conf.rf;
292 int ret;
293
294 if (!wl->nvs)
295 return -ENODEV;
296
297 ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL);
298 if (!ext_radio_parms)
299 return -ENOMEM;
300
301 ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM;
302
303 memcpy(ext_radio_parms->tx_per_channel_power_compensation_2,
304 rf->tx_per_channel_power_compensation_2,
305 CONF_TX_PWR_COMPENSATION_LEN_2);
306 memcpy(ext_radio_parms->tx_per_channel_power_compensation_5,
307 rf->tx_per_channel_power_compensation_5,
308 CONF_TX_PWR_COMPENSATION_LEN_5);
309
310 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
311 ext_radio_parms, sizeof(*ext_radio_parms));
312
313 ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0);
314 if (ret < 0)
315 wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
316
317 kfree(ext_radio_parms);
318 return ret;
319}
320
99d84c1d
LC
321/*
322 * Poll the mailbox event field until any of the bits in the mask is set or a
323 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
324 */
05285cf9 325static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask)
99d84c1d
LC
326{
327 u32 events_vector, event;
328 unsigned long timeout;
329
330 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
331
332 do {
52b0e7a6 333 if (time_after(jiffies, timeout)) {
05285cf9
AN
334 wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
335 (int)mask);
99d84c1d 336 return -ETIMEDOUT;
52b0e7a6 337 }
99d84c1d
LC
338
339 msleep(1);
340
341 /* read from both event fields */
342 wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
343 sizeof(events_vector), false);
344 event = events_vector & mask;
345 wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
346 sizeof(events_vector), false);
347 event |= events_vector & mask;
348 } while (!event);
349
350 return 0;
351}
352
05285cf9
AN
353static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
354{
355 int ret;
356
357 ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask);
358 if (ret != 0) {
baacb9ae 359 wl12xx_queue_recovery_work(wl);
05285cf9
AN
360 return ret;
361 }
362
363 return 0;
364}
365
c690ec81 366int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 role_type, u8 *role_id)
f5fc0f86 367{
c690ec81
EP
368 struct wl12xx_cmd_role_enable *cmd;
369 int ret;
370
371 wl1271_debug(DEBUG_CMD, "cmd role enable");
372
373 if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID))
374 return -EBUSY;
375
376 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
377 if (!cmd) {
378 ret = -ENOMEM;
379 goto out;
380 }
381
382 /* get role id */
383 cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES);
384 if (cmd->role_id >= WL12XX_MAX_ROLES) {
385 ret = -EBUSY;
386 goto out_free;
387 }
388
389 memcpy(cmd->mac_address, wl->mac_addr, ETH_ALEN);
390 cmd->role_type = role_type;
391
392 ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0);
393 if (ret < 0) {
394 wl1271_error("failed to initiate cmd role enable");
395 goto out_free;
396 }
397
398 __set_bit(cmd->role_id, wl->roles_map);
399 *role_id = cmd->role_id;
f5fc0f86 400
c690ec81
EP
401out_free:
402 kfree(cmd);
403
404out:
405 return ret;
406}
407
408int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id)
409{
410 struct wl12xx_cmd_role_disable *cmd;
411 int ret;
412
413 wl1271_debug(DEBUG_CMD, "cmd role disable");
414
415 if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID))
416 return -ENOENT;
417
418 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
419 if (!cmd) {
f5fc0f86
LC
420 ret = -ENOMEM;
421 goto out;
422 }
c690ec81
EP
423 cmd->role_id = *role_id;
424
425 ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0);
426 if (ret < 0) {
427 wl1271_error("failed to initiate cmd role disable");
428 goto out_free;
429 }
f5fc0f86 430
c690ec81
EP
431 __clear_bit(*role_id, wl->roles_map);
432 *role_id = WL12XX_INVALID_ROLE_ID;
f5fc0f86 433
c690ec81
EP
434out_free:
435 kfree(cmd);
436
437out:
438 return ret;
439}
440
441static int wl12xx_allocate_link(struct wl1271 *wl, u8 *hlid)
442{
443 u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
444 if (link >= WL12XX_MAX_LINKS)
445 return -EBUSY;
446
447 __set_bit(link, wl->links_map);
448 *hlid = link;
449 return 0;
450}
451
452static void wl12xx_free_link(struct wl1271 *wl, u8 *hlid)
453{
454 if (*hlid == WL12XX_INVALID_LINK_ID)
455 return;
456
457 __clear_bit(*hlid, wl->links_map);
458 *hlid = WL12XX_INVALID_LINK_ID;
459}
460
461int wl12xx_cmd_role_start_sta(struct wl1271 *wl)
462{
463 struct wl12xx_cmd_role_start *cmd;
464 int ret;
f5fc0f86 465
c690ec81
EP
466 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
467 if (!cmd) {
468 ret = -ENOMEM;
469 goto out;
470 }
f5fc0f86 471
c690ec81
EP
472 wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wl->role_id);
473
474 cmd->role_id = wl->role_id;
ebba60c6 475 if (wl->band == IEEE80211_BAND_5GHZ)
c690ec81
EP
476 cmd->band = WL12XX_BAND_5GHZ;
477 cmd->channel = wl->channel;
478 cmd->sta.basic_rate_set = cpu_to_le32(wl->basic_rate_set);
479 cmd->sta.beacon_interval = cpu_to_le16(wl->beacon_int);
480 cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
481 cmd->sta.ssid_len = wl->ssid_len;
482 memcpy(cmd->sta.ssid, wl->ssid, wl->ssid_len);
483 memcpy(cmd->sta.bssid, wl->bssid, ETH_ALEN);
484 cmd->sta.local_rates = cpu_to_le32(wl->rate_set);
485
486 if (wl->sta_hlid == WL12XX_INVALID_LINK_ID) {
487 ret = wl12xx_allocate_link(wl, &wl->sta_hlid);
488 if (ret)
489 goto out_free;
490 }
491 cmd->sta.hlid = wl->sta_hlid;
492 cmd->sta.session = wl->session_counter;
493 cmd->sta.remote_rates = cpu_to_le32(wl->rate_set);
494
495 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
496 "basic_rate_set: 0x%x, remote_rates: 0x%x",
497 wl->role_id, cmd->sta.hlid, cmd->sta.session,
498 wl->basic_rate_set, wl->rate_set);
499
500 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
501 if (ret < 0) {
502 wl1271_error("failed to initiate cmd role start sta");
503 goto err_hlid;
504 }
505
506 goto out_free;
507
508err_hlid:
509 /* clear links on error. */
510 wl12xx_free_link(wl, &wl->sta_hlid);
511
512out_free:
513 kfree(cmd);
514
515out:
516 return ret;
517}
f5fc0f86 518
c690ec81
EP
519int wl12xx_cmd_role_stop_sta(struct wl1271 *wl)
520{
521 struct wl12xx_cmd_role_stop *cmd;
522 int ret;
523
524 if (WARN_ON(wl->sta_hlid == WL12XX_INVALID_LINK_ID))
525 return -EINVAL;
526
527 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
528 if (!cmd) {
529 ret = -ENOMEM;
530 goto out;
531 }
a4102645 532
c690ec81 533 wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wl->role_id);
f5fc0f86 534
c690ec81
EP
535 cmd->role_id = wl->role_id;
536 cmd->disc_type = DISCONNECT_IMMEDIATE;
537 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
f5fc0f86 538
c690ec81
EP
539 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
540 if (ret < 0) {
541 wl1271_error("failed to initiate cmd role stop sta");
542 goto out_free;
543 }
72c2d9e5 544
c690ec81 545 ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
f5fc0f86 546 if (ret < 0) {
c690ec81 547 wl1271_error("cmd role stop sta event completion error");
f5fc0f86
LC
548 goto out_free;
549 }
550
c690ec81
EP
551 wl12xx_free_link(wl, &wl->sta_hlid);
552
553out_free:
554 kfree(cmd);
555
556out:
557 return ret;
558}
559
560int wl12xx_cmd_role_start_ap(struct wl1271 *wl)
561{
562 struct wl12xx_cmd_role_start *cmd;
563 struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf;
564 int ret;
565
566 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wl->role_id);
567
568 /*
569 * We currently do not support hidden SSID. The real SSID
570 * should be fetched from mac80211 first.
571 */
572 if (wl->ssid_len == 0) {
573 wl1271_warning("Hidden SSID currently not supported for AP");
574 ret = -EINVAL;
575 goto out;
576 }
577
578 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
579 if (!cmd) {
580 ret = -ENOMEM;
581 goto out;
582 }
583
584 cmd->role_id = wl->role_id;
585 cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
586 cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
587 cmd->ap.global_hlid = WL1271_AP_GLOBAL_HLID;
588 cmd->ap.broadcast_hlid = WL1271_AP_BROADCAST_HLID;
589 cmd->ap.basic_rate_set = cpu_to_le32(wl->basic_rate_set);
590 cmd->ap.beacon_interval = cpu_to_le16(wl->beacon_int);
591 cmd->ap.dtim_interval = bss_conf->dtim_period;
592 cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
593 cmd->channel = wl->channel;
594 cmd->ap.ssid_len = wl->ssid_len;
595 cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
596 memcpy(cmd->ap.ssid, wl->ssid, wl->ssid_len);
597 cmd->ap.local_rates = cpu_to_le32(0xffffffff);
598
599 switch (wl->band) {
600 case IEEE80211_BAND_2GHZ:
601 cmd->band = RADIO_BAND_2_4GHZ;
602 break;
603 case IEEE80211_BAND_5GHZ:
604 cmd->band = RADIO_BAND_5GHZ;
605 break;
606 default:
607 wl1271_warning("ap start - unknown band: %d", (int)wl->band);
608 cmd->band = RADIO_BAND_2_4GHZ;
609 break;
610 }
611
612 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
613 if (ret < 0) {
614 wl1271_error("failed to initiate cmd role start ap");
615 goto out_free;
616 }
f5fc0f86
LC
617
618out_free:
c690ec81 619 kfree(cmd);
f5fc0f86
LC
620
621out:
622 return ret;
623}
624
c690ec81
EP
625int wl12xx_cmd_role_stop_ap(struct wl1271 *wl)
626{
627 struct wl12xx_cmd_role_stop *cmd;
628 int ret;
629
630 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
631 if (!cmd) {
632 ret = -ENOMEM;
633 goto out;
634 }
635
636 wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wl->role_id);
637
638 cmd->role_id = wl->role_id;
639
640 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
641 if (ret < 0) {
642 wl1271_error("failed to initiate cmd role stop ap");
643 goto out_free;
644 }
645
646out_free:
647 kfree(cmd);
648
649out:
650 return ret;
651}
652
653
f5fc0f86
LC
654/**
655 * send test command to firmware
656 *
657 * @wl: wl struct
658 * @buf: buffer containing the command, with all headers, must work with dma
659 * @len: length of the buffer
660 * @answer: is answer needed
661 */
662int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
663{
664 int ret;
fa867e73 665 size_t res_len = 0;
f5fc0f86
LC
666
667 wl1271_debug(DEBUG_CMD, "cmd test");
668
fa867e73
JO
669 if (answer)
670 res_len = buf_len;
671
672 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
f5fc0f86
LC
673
674 if (ret < 0) {
675 wl1271_warning("TEST command failed");
676 return ret;
677 }
678
fa867e73 679 return ret;
f5fc0f86
LC
680}
681
682/**
683 * read acx from firmware
684 *
685 * @wl: wl struct
686 * @id: acx id
687 * @buf: buffer for the response, including all headers, must work with dma
25985edc 688 * @len: length of buf
f5fc0f86
LC
689 */
690int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
691{
692 struct acx_header *acx = buf;
693 int ret;
694
695 wl1271_debug(DEBUG_CMD, "cmd interrogate");
696
d0f63b20 697 acx->id = cpu_to_le16(id);
f5fc0f86
LC
698
699 /* payload length, does not include any headers */
d0f63b20 700 acx->len = cpu_to_le16(len - sizeof(*acx));
f5fc0f86 701
fa867e73
JO
702 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
703 if (ret < 0)
f5fc0f86 704 wl1271_error("INTERROGATE command failed");
f5fc0f86 705
f5fc0f86
LC
706 return ret;
707}
708
709/**
710 * write acx value to firmware
711 *
712 * @wl: wl struct
713 * @id: acx id
714 * @buf: buffer containing acx, including all headers, must work with dma
715 * @len: length of buf
716 */
717int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
718{
719 struct acx_header *acx = buf;
720 int ret;
721
722 wl1271_debug(DEBUG_CMD, "cmd configure");
723
d0f63b20 724 acx->id = cpu_to_le16(id);
f5fc0f86
LC
725
726 /* payload length, does not include any headers */
d0f63b20 727 acx->len = cpu_to_le16(len - sizeof(*acx));
f5fc0f86 728
fa867e73 729 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
f5fc0f86
LC
730 if (ret < 0) {
731 wl1271_warning("CONFIGURE command NOK");
732 return ret;
733 }
734
735 return 0;
736}
737
94210897 738int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
f5fc0f86
LC
739{
740 struct cmd_enabledisable_path *cmd;
741 int ret;
742 u16 cmd_rx, cmd_tx;
743
744 wl1271_debug(DEBUG_CMD, "cmd data path");
745
746 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
747 if (!cmd) {
748 ret = -ENOMEM;
749 goto out;
750 }
751
94210897
LC
752 /* the channel here is only used for calibration, so hardcoded to 1 */
753 cmd->channel = 1;
f5fc0f86
LC
754
755 if (enable) {
756 cmd_rx = CMD_ENABLE_RX;
757 cmd_tx = CMD_ENABLE_TX;
758 } else {
759 cmd_rx = CMD_DISABLE_RX;
760 cmd_tx = CMD_DISABLE_TX;
761 }
762
fa867e73 763 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
f5fc0f86
LC
764 if (ret < 0) {
765 wl1271_error("rx %s cmd for channel %d failed",
94210897 766 enable ? "start" : "stop", cmd->channel);
f5fc0f86
LC
767 goto out;
768 }
769
770 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
94210897 771 enable ? "start" : "stop", cmd->channel);
f5fc0f86 772
fa867e73 773 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
f5fc0f86
LC
774 if (ret < 0) {
775 wl1271_error("tx %s cmd for channel %d failed",
94210897 776 enable ? "start" : "stop", cmd->channel);
1b00f2b5 777 goto out;
f5fc0f86
LC
778 }
779
780 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
94210897 781 enable ? "start" : "stop", cmd->channel);
f5fc0f86
LC
782
783out:
784 kfree(cmd);
785 return ret;
786}
787
c8bde243 788int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode)
f5fc0f86
LC
789{
790 struct wl1271_cmd_ps_params *ps_params = NULL;
791 int ret = 0;
792
f5fc0f86
LC
793 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
794
795 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
796 if (!ps_params) {
797 ret = -ENOMEM;
798 goto out;
799 }
800
c690ec81 801 ps_params->role_id = wl->role_id;
f5fc0f86 802 ps_params->ps_mode = ps_mode;
f5fc0f86
LC
803
804 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
fa867e73 805 sizeof(*ps_params), 0);
f5fc0f86
LC
806 if (ret < 0) {
807 wl1271_error("cmd set_ps_mode failed");
808 goto out;
809 }
810
811out:
812 kfree(ps_params);
813 return ret;
814}
815
f5fc0f86 816int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
606c1487 817 void *buf, size_t buf_len, int index, u32 rates)
f5fc0f86
LC
818{
819 struct wl1271_cmd_template_set *cmd;
820 int ret = 0;
821
822 wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
823
824 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
825 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
826
827 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
828 if (!cmd) {
829 ret = -ENOMEM;
830 goto out;
831 }
832
833 cmd->len = cpu_to_le16(buf_len);
834 cmd->template_type = template_id;
606c1487 835 cmd->enabled_rates = cpu_to_le32(rates);
1e05a818
AN
836 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
837 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
bfb24c9e 838 cmd->index = index;
f5fc0f86
LC
839
840 if (buf)
841 memcpy(cmd->template_data, buf, buf_len);
842
fa867e73 843 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
f5fc0f86
LC
844 if (ret < 0) {
845 wl1271_warning("cmd set_template failed: %d", ret);
846 goto out_free;
847 }
848
849out_free:
850 kfree(cmd);
851
852out:
853 return ret;
854}
855
f5fc0f86
LC
856int wl1271_cmd_build_null_data(struct wl1271 *wl)
857{
a0cb7be4
JO
858 struct sk_buff *skb = NULL;
859 int size;
860 void *ptr;
861 int ret = -ENOMEM;
f5fc0f86 862
f5fc0f86 863
a0cb7be4
JO
864 if (wl->bss_type == BSS_TYPE_IBSS) {
865 size = sizeof(struct wl12xx_null_data_template);
866 ptr = NULL;
867 } else {
868 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
869 if (!skb)
870 goto out;
871 size = skb->len;
872 ptr = skb->data;
873 }
874
606c1487 875 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
8eab7b47 876 wl->basic_rate);
f5fc0f86 877
899e6e65
KV
878out:
879 dev_kfree_skb(skb);
a0cb7be4
JO
880 if (ret)
881 wl1271_warning("cmd buld null data failed %d", ret);
882
899e6e65 883 return ret;
f5fc0f86
LC
884
885}
886
bfb24c9e
JO
887int wl1271_cmd_build_klv_null_data(struct wl1271 *wl)
888{
889 struct sk_buff *skb = NULL;
890 int ret = -ENOMEM;
891
892 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
893 if (!skb)
894 goto out;
895
896 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
897 skb->data, skb->len,
606c1487 898 CMD_TEMPL_KLV_IDX_NULL_DATA,
8eab7b47 899 wl->basic_rate);
bfb24c9e
JO
900
901out:
902 dev_kfree_skb(skb);
903 if (ret)
904 wl1271_warning("cmd build klv null data failed %d", ret);
905
906 return ret;
907
908}
909
f5fc0f86
LC
910int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
911{
899e6e65
KV
912 struct sk_buff *skb;
913 int ret = 0;
c3fea199 914
899e6e65
KV
915 skb = ieee80211_pspoll_get(wl->hw, wl->vif);
916 if (!skb)
917 goto out;
f5fc0f86 918
899e6e65 919 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
849923f4 920 skb->len, 0, wl->basic_rate_set);
f5fc0f86 921
899e6e65
KV
922out:
923 dev_kfree_skb(skb);
924 return ret;
f5fc0f86
LC
925}
926
818e3063
KV
927int wl1271_cmd_build_probe_req(struct wl1271 *wl,
928 const u8 *ssid, size_t ssid_len,
929 const u8 *ie, size_t ie_len, u8 band)
f5fc0f86 930{
818e3063 931 struct sk_buff *skb;
abb0b3bf 932 int ret;
f5fc0f86 933
818e3063
KV
934 skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
935 ie, ie_len);
936 if (!skb) {
937 ret = -ENOMEM;
938 goto out;
939 }
940
941 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
f5fc0f86 942
abb0b3bf
TP
943 if (band == IEEE80211_BAND_2GHZ)
944 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
606c1487
JO
945 skb->data, skb->len, 0,
946 wl->conf.tx.basic_rate);
abb0b3bf
TP
947 else
948 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
606c1487
JO
949 skb->data, skb->len, 0,
950 wl->conf.tx.basic_rate_5);
818e3063
KV
951
952out:
953 dev_kfree_skb(skb);
abb0b3bf 954 return ret;
f5fc0f86
LC
955}
956
2f6724b2
JO
957struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
958 struct sk_buff *skb)
959{
960 int ret;
961
962 if (!skb)
963 skb = ieee80211_ap_probereq_get(wl->hw, wl->vif);
964 if (!skb)
965 goto out;
966
967 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
968
969 if (wl->band == IEEE80211_BAND_2GHZ)
970 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
971 skb->data, skb->len, 0,
972 wl->conf.tx.basic_rate);
973 else
974 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
975 skb->data, skb->len, 0,
976 wl->conf.tx.basic_rate_5);
977
978 if (ret < 0)
979 wl1271_error("Unable to set ap probe request template.");
980
981out:
982 return skb;
983}
984
c5312772
EP
985int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr)
986{
987 int ret;
988 struct wl12xx_arp_rsp_template tmpl;
989 struct ieee80211_hdr_3addr *hdr;
990 struct arphdr *arp_hdr;
991
992 memset(&tmpl, 0, sizeof(tmpl));
993
994 /* mac80211 header */
995 hdr = &tmpl.hdr;
996 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
997 IEEE80211_STYPE_DATA |
998 IEEE80211_FCTL_TODS);
999 memcpy(hdr->addr1, wl->vif->bss_conf.bssid, ETH_ALEN);
1000 memcpy(hdr->addr2, wl->vif->addr, ETH_ALEN);
1001 memset(hdr->addr3, 0xff, ETH_ALEN);
1002
1003 /* llc layer */
1004 memcpy(tmpl.llc_hdr, rfc1042_header, sizeof(rfc1042_header));
6177eaea 1005 tmpl.llc_type = cpu_to_be16(ETH_P_ARP);
c5312772
EP
1006
1007 /* arp header */
1008 arp_hdr = &tmpl.arp_hdr;
6177eaea
EP
1009 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
1010 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
c5312772
EP
1011 arp_hdr->ar_hln = ETH_ALEN;
1012 arp_hdr->ar_pln = 4;
6177eaea 1013 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
c5312772
EP
1014
1015 /* arp payload */
1016 memcpy(tmpl.sender_hw, wl->vif->addr, ETH_ALEN);
1017 tmpl.sender_ip = ip_addr;
1018
1019 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP,
1020 &tmpl, sizeof(tmpl), 0,
1021 wl->basic_rate);
1022
1023 return ret;
1024}
1025
023e0826
KV
1026int wl1271_build_qos_null_data(struct wl1271 *wl)
1027{
1028 struct ieee80211_qos_hdr template;
1029
1030 memset(&template, 0, sizeof(template));
1031
1032 memcpy(template.addr1, wl->bssid, ETH_ALEN);
1033 memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
1034 memcpy(template.addr3, wl->bssid, ETH_ALEN);
1035
1036 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1037 IEEE80211_STYPE_QOS_NULLFUNC |
1038 IEEE80211_FCTL_TODS);
1039
1040 /* FIXME: not sure what priority to use here */
1041 template.qos_ctrl = cpu_to_le16(0);
1042
1043 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
606c1487 1044 sizeof(template), 0,
8eab7b47 1045 wl->basic_rate);
023e0826
KV
1046}
1047
c690ec81 1048int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
f5fc0f86 1049{
c690ec81 1050 struct wl1271_cmd_set_keys *cmd;
f5fc0f86
LC
1051 int ret = 0;
1052
1053 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
1054
1055 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1056 if (!cmd) {
1057 ret = -ENOMEM;
1058 goto out;
1059 }
1060
c690ec81 1061 cmd->hlid = hlid;
98bdaabb
AN
1062 cmd->key_id = id;
1063 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1064 cmd->key_action = cpu_to_le16(KEY_SET_ID);
1065 cmd->key_type = KEY_WEP;
1066
1067 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1068 if (ret < 0) {
c690ec81 1069 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
98bdaabb
AN
1070 goto out;
1071 }
1072
1073out:
1074 kfree(cmd);
1075
1076 return ret;
1077}
1078
1079int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
ac4e4ce5
JO
1080 u8 key_size, const u8 *key, const u8 *addr,
1081 u32 tx_seq_32, u16 tx_seq_16)
f5fc0f86 1082{
c690ec81 1083 struct wl1271_cmd_set_keys *cmd;
f5fc0f86
LC
1084 int ret = 0;
1085
1086 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1087 if (!cmd) {
1088 ret = -ENOMEM;
1089 goto out;
1090 }
1091
c690ec81
EP
1092 cmd->hlid = wl->sta_hlid;
1093
1094 if (key_type == KEY_WEP)
1095 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1096 else if (is_broadcast_ether_addr(addr))
1097 cmd->lid_key_type = BROADCAST_LID_TYPE;
1098 else
1099 cmd->lid_key_type = UNICAST_LID_TYPE;
f5fc0f86 1100
d0f63b20 1101 cmd->key_action = cpu_to_le16(action);
f5fc0f86
LC
1102 cmd->key_size = key_size;
1103 cmd->key_type = key_type;
1104
d0f63b20
LC
1105 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1106 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
ac4e4ce5 1107
c690ec81 1108 cmd->key_id = id;
f5fc0f86 1109
f5fc0f86
LC
1110 if (key_type == KEY_TKIP) {
1111 /*
1112 * We get the key in the following form:
1113 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1114 * but the target is expecting:
1115 * TKIP - RX MIC - TX MIC
1116 */
1117 memcpy(cmd->key, key, 16);
1118 memcpy(cmd->key + 16, key + 24, 8);
1119 memcpy(cmd->key + 24, key + 16, 8);
1120
1121 } else {
1122 memcpy(cmd->key, key, key_size);
1123 }
1124
1125 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
1126
fa867e73 1127 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
f5fc0f86
LC
1128 if (ret < 0) {
1129 wl1271_warning("could not set keys");
152ee6e0 1130 goto out;
f5fc0f86
LC
1131 }
1132
1133out:
1134 kfree(cmd);
1135
1136 return ret;
1137}
25a7dc6d 1138
c690ec81
EP
1139/*
1140 * TODO: merge with sta/ibss into 1 set_key function.
1141 * note there are slight diffs
1142 */
98bdaabb
AN
1143int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
1144 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
1145 u16 tx_seq_16)
1146{
c690ec81 1147 struct wl1271_cmd_set_keys *cmd;
98bdaabb
AN
1148 int ret = 0;
1149 u8 lid_type;
1150
1151 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1152 if (!cmd)
1153 return -ENOMEM;
1154
1155 if (hlid == WL1271_AP_BROADCAST_HLID) {
1156 if (key_type == KEY_WEP)
1157 lid_type = WEP_DEFAULT_LID_TYPE;
1158 else
1159 lid_type = BROADCAST_LID_TYPE;
1160 } else {
1161 lid_type = UNICAST_LID_TYPE;
1162 }
1163
1164 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
1165 " hlid: %d", (int)action, (int)id, (int)lid_type,
1166 (int)key_type, (int)hlid);
1167
1168 cmd->lid_key_type = lid_type;
1169 cmd->hlid = hlid;
1170 cmd->key_action = cpu_to_le16(action);
1171 cmd->key_size = key_size;
1172 cmd->key_type = key_type;
1173 cmd->key_id = id;
1174 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1175 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1176
1177 if (key_type == KEY_TKIP) {
1178 /*
1179 * We get the key in the following form:
1180 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1181 * but the target is expecting:
1182 * TKIP - RX MIC - TX MIC
1183 */
1184 memcpy(cmd->key, key, 16);
1185 memcpy(cmd->key + 16, key + 24, 8);
1186 memcpy(cmd->key + 24, key + 16, 8);
1187 } else {
1188 memcpy(cmd->key, key, key_size);
1189 }
1190
1191 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
1192
1193 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1194 if (ret < 0) {
1195 wl1271_warning("could not set ap keys");
1196 goto out;
1197 }
1198
1199out:
1200 kfree(cmd);
1201 return ret;
1202}
1203
c690ec81 1204int wl12xx_cmd_set_peer_state(struct wl1271 *wl)
be86cbea 1205{
c690ec81 1206 struct wl12xx_cmd_set_peer_state *cmd;
be86cbea
JO
1207 int ret = 0;
1208
c690ec81 1209 wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", wl->sta_hlid);
be86cbea
JO
1210
1211 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1212 if (!cmd) {
1213 ret = -ENOMEM;
1214 goto out;
1215 }
1216
c690ec81 1217 cmd->hlid = wl->sta_hlid;
be86cbea
JO
1218 cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
1219
c690ec81 1220 ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0);
be86cbea 1221 if (ret < 0) {
c690ec81 1222 wl1271_error("failed to send set peer state command");
be86cbea
JO
1223 goto out_free;
1224 }
1225
1226out_free:
1227 kfree(cmd);
1228
1229out:
1230 return ret;
1231}
c690ec81 1232int wl12xx_cmd_add_peer(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid)
98bdaabb 1233{
c690ec81 1234 struct wl12xx_cmd_add_peer *cmd;
98bdaabb
AN
1235 int ret;
1236
c690ec81 1237 wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid);
98bdaabb
AN
1238
1239 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1240 if (!cmd) {
1241 ret = -ENOMEM;
1242 goto out;
1243 }
1244
1245 /* currently we don't support UAPSD */
1246 cmd->sp_len = 0;
1247
1248 memcpy(cmd->addr, sta->addr, ETH_ALEN);
1249 cmd->bss_index = WL1271_AP_BSS_INDEX;
1250 cmd->aid = sta->aid;
1251 cmd->hlid = hlid;
b4d38db1 1252 cmd->wmm = sta->wme ? 1 : 0;
98bdaabb
AN
1253
1254 cmd->supported_rates = cpu_to_le32(wl1271_tx_enabled_rates_get(wl,
1255 sta->supp_rates[wl->band]));
1256
c690ec81 1257 wl1271_debug(DEBUG_CMD, "new peer rates: 0x%x", cmd->supported_rates);
98bdaabb 1258
c690ec81 1259 ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0);
98bdaabb 1260 if (ret < 0) {
c690ec81 1261 wl1271_error("failed to initiate cmd add peer");
98bdaabb
AN
1262 goto out_free;
1263 }
1264
1265out_free:
1266 kfree(cmd);
1267
1268out:
1269 return ret;
1270}
1271
c690ec81 1272int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid)
98bdaabb 1273{
c690ec81 1274 struct wl12xx_cmd_remove_peer *cmd;
98bdaabb
AN
1275 int ret;
1276
c690ec81 1277 wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid);
98bdaabb
AN
1278
1279 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1280 if (!cmd) {
1281 ret = -ENOMEM;
1282 goto out;
1283 }
1284
1285 cmd->hlid = hlid;
1286 /* We never send a deauth, mac80211 is in charge of this */
1287 cmd->reason_opcode = 0;
1288 cmd->send_deauth_flag = 0;
1289
c690ec81 1290 ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
98bdaabb 1291 if (ret < 0) {
c690ec81 1292 wl1271_error("failed to initiate cmd remove peer");
98bdaabb
AN
1293 goto out_free;
1294 }
1295
05285cf9
AN
1296 /*
1297 * We are ok with a timeout here. The event is sometimes not sent
1298 * due to a firmware bug.
1299 */
c690ec81
EP
1300 wl1271_cmd_wait_for_event_or_timeout(wl,
1301 PEER_REMOVE_COMPLETE_EVENT_ID);
98bdaabb
AN
1302
1303out_free:
1304 kfree(cmd);
1305
1306out:
1307 return ret;
1308}
95dac04f
IY
1309
1310int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
1311{
1312 struct wl12xx_cmd_config_fwlog *cmd;
1313 int ret = 0;
1314
1315 wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
1316
1317 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1318 if (!cmd) {
1319 ret = -ENOMEM;
1320 goto out;
1321 }
1322
1323 cmd->logger_mode = wl->conf.fwlog.mode;
1324 cmd->log_severity = wl->conf.fwlog.severity;
1325 cmd->timestamp = wl->conf.fwlog.timestamp;
1326 cmd->output = wl->conf.fwlog.output;
1327 cmd->threshold = wl->conf.fwlog.threshold;
1328
1329 ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
1330 if (ret < 0) {
1331 wl1271_error("failed to send config firmware logger command");
1332 goto out_free;
1333 }
1334
1335out_free:
1336 kfree(cmd);
1337
1338out:
1339 return ret;
1340}
1341
1342int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
1343{
1344 struct wl12xx_cmd_start_fwlog *cmd;
1345 int ret = 0;
1346
1347 wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
1348
1349 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1350 if (!cmd) {
1351 ret = -ENOMEM;
1352 goto out;
1353 }
1354
1355 ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
1356 if (ret < 0) {
1357 wl1271_error("failed to send start firmware logger command");
1358 goto out_free;
1359 }
1360
1361out_free:
1362 kfree(cmd);
1363
1364out:
1365 return ret;
1366}
1367
1368int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
1369{
1370 struct wl12xx_cmd_stop_fwlog *cmd;
1371 int ret = 0;
1372
1373 wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
1374
1375 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1376 if (!cmd) {
1377 ret = -ENOMEM;
1378 goto out;
1379 }
1380
1381 ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
1382 if (ret < 0) {
1383 wl1271_error("failed to send stop firmware logger command");
1384 goto out_free;
1385 }
1386
1387out_free:
1388 kfree(cmd);
1389
1390out:
1391 return ret;
1392}
This page took 0.393637 seconds and 5 git commands to generate.