wl12xx: move debugging definitions to a separate file
[deliverable/linux.git] / drivers / net / wireless / wl12xx / cmd.c
1 /*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009-2010 Nokia Corporation
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>
26 #include <linux/spi/spi.h>
27 #include <linux/etherdevice.h>
28 #include <linux/ieee80211.h>
29 #include <linux/slab.h>
30
31 #include "wl12xx.h"
32 #include "debug.h"
33 #include "reg.h"
34 #include "io.h"
35 #include "acx.h"
36 #include "wl12xx_80211.h"
37 #include "cmd.h"
38 #include "event.h"
39 #include "tx.h"
40
41 #define WL1271_CMD_FAST_POLL_COUNT 50
42
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 */
51 int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
52 size_t res_len)
53 {
54 struct wl1271_cmd_header *cmd;
55 unsigned long timeout;
56 u32 intr;
57 int ret = 0;
58 u16 status;
59 u16 poll_count = 0;
60
61 cmd = buf;
62 cmd->id = cpu_to_le16(id);
63 cmd->status = 0;
64
65 WARN_ON(len % 4 != 0);
66 WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
67
68 wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
69
70 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
71
72 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
73
74 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
75 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
76 if (time_after(jiffies, timeout)) {
77 wl1271_error("command complete timeout");
78 ret = -ETIMEDOUT;
79 goto fail;
80 }
81
82 poll_count++;
83 if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
84 udelay(10);
85 else
86 msleep(1);
87
88 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
89 }
90
91 /* read back the status code of the command */
92 if (res_len == 0)
93 res_len = sizeof(struct wl1271_cmd_header);
94 wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
95
96 status = le16_to_cpu(cmd->status);
97 if (status != CMD_STATUS_SUCCESS) {
98 wl1271_error("command execute failure %d", status);
99 ret = -EIO;
100 goto fail;
101 }
102
103 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
104 WL1271_ACX_INTR_CMD_COMPLETE);
105 return 0;
106
107 fail:
108 WARN_ON(1);
109 wl12xx_queue_recovery_work(wl);
110 return ret;
111 }
112
113 int wl1271_cmd_general_parms(struct wl1271 *wl)
114 {
115 struct wl1271_general_parms_cmd *gen_parms;
116 struct wl1271_ini_general_params *gp =
117 &((struct wl1271_nvs_file *)wl->nvs)->general_params;
118 bool answer = false;
119 int ret;
120
121 if (!wl->nvs)
122 return -ENODEV;
123
124 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
125 if (!gen_parms)
126 return -ENOMEM;
127
128 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
129
130 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
131
132 if (gp->tx_bip_fem_auto_detect)
133 answer = true;
134
135 /* Override the REF CLK from the NVS with the one from platform data */
136 gen_parms->general_params.ref_clock = wl->ref_clock;
137
138 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
139 if (ret < 0) {
140 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
141 goto out;
142 }
143
144 gp->tx_bip_fem_manufacturer =
145 gen_parms->general_params.tx_bip_fem_manufacturer;
146
147 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
148 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
149
150 out:
151 kfree(gen_parms);
152 return ret;
153 }
154
155 int wl128x_cmd_general_parms(struct wl1271 *wl)
156 {
157 struct wl128x_general_parms_cmd *gen_parms;
158 struct wl128x_ini_general_params *gp =
159 &((struct wl128x_nvs_file *)wl->nvs)->general_params;
160 bool answer = false;
161 int ret;
162
163 if (!wl->nvs)
164 return -ENODEV;
165
166 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
167 if (!gen_parms)
168 return -ENOMEM;
169
170 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
171
172 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
173
174 if (gp->tx_bip_fem_auto_detect)
175 answer = true;
176
177 /* Replace REF and TCXO CLKs with the ones from platform data */
178 gen_parms->general_params.ref_clock = wl->ref_clock;
179 gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock;
180
181 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
182 if (ret < 0) {
183 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
184 goto out;
185 }
186
187 gp->tx_bip_fem_manufacturer =
188 gen_parms->general_params.tx_bip_fem_manufacturer;
189
190 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
191 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
192
193 out:
194 kfree(gen_parms);
195 return ret;
196 }
197
198 int wl1271_cmd_radio_parms(struct wl1271 *wl)
199 {
200 struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs;
201 struct wl1271_radio_parms_cmd *radio_parms;
202 struct wl1271_ini_general_params *gp = &nvs->general_params;
203 int ret;
204
205 if (!wl->nvs)
206 return -ENODEV;
207
208 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
209 if (!radio_parms)
210 return -ENOMEM;
211
212 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
213
214 /* 2.4GHz parameters */
215 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
216 sizeof(struct wl1271_ini_band_params_2));
217 memcpy(&radio_parms->dyn_params_2,
218 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
219 sizeof(struct wl1271_ini_fem_params_2));
220
221 /* 5GHz parameters */
222 memcpy(&radio_parms->static_params_5,
223 &nvs->stat_radio_params_5,
224 sizeof(struct wl1271_ini_band_params_5));
225 memcpy(&radio_parms->dyn_params_5,
226 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
227 sizeof(struct wl1271_ini_fem_params_5));
228
229 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
230 radio_parms, sizeof(*radio_parms));
231
232 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
233 if (ret < 0)
234 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
235
236 kfree(radio_parms);
237 return ret;
238 }
239
240 int wl128x_cmd_radio_parms(struct wl1271 *wl)
241 {
242 struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
243 struct wl128x_radio_parms_cmd *radio_parms;
244 struct wl128x_ini_general_params *gp = &nvs->general_params;
245 int ret;
246
247 if (!wl->nvs)
248 return -ENODEV;
249
250 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
251 if (!radio_parms)
252 return -ENOMEM;
253
254 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
255
256 /* 2.4GHz parameters */
257 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
258 sizeof(struct wl128x_ini_band_params_2));
259 memcpy(&radio_parms->dyn_params_2,
260 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
261 sizeof(struct wl128x_ini_fem_params_2));
262
263 /* 5GHz parameters */
264 memcpy(&radio_parms->static_params_5,
265 &nvs->stat_radio_params_5,
266 sizeof(struct wl128x_ini_band_params_5));
267 memcpy(&radio_parms->dyn_params_5,
268 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
269 sizeof(struct wl128x_ini_fem_params_5));
270
271 radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options;
272
273 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
274 radio_parms, sizeof(*radio_parms));
275
276 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
277 if (ret < 0)
278 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
279
280 kfree(radio_parms);
281 return ret;
282 }
283
284 int wl1271_cmd_ext_radio_parms(struct wl1271 *wl)
285 {
286 struct wl1271_ext_radio_parms_cmd *ext_radio_parms;
287 struct conf_rf_settings *rf = &wl->conf.rf;
288 int ret;
289
290 if (!wl->nvs)
291 return -ENODEV;
292
293 ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL);
294 if (!ext_radio_parms)
295 return -ENOMEM;
296
297 ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM;
298
299 memcpy(ext_radio_parms->tx_per_channel_power_compensation_2,
300 rf->tx_per_channel_power_compensation_2,
301 CONF_TX_PWR_COMPENSATION_LEN_2);
302 memcpy(ext_radio_parms->tx_per_channel_power_compensation_5,
303 rf->tx_per_channel_power_compensation_5,
304 CONF_TX_PWR_COMPENSATION_LEN_5);
305
306 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
307 ext_radio_parms, sizeof(*ext_radio_parms));
308
309 ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0);
310 if (ret < 0)
311 wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
312
313 kfree(ext_radio_parms);
314 return ret;
315 }
316
317 /*
318 * Poll the mailbox event field until any of the bits in the mask is set or a
319 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
320 */
321 static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask)
322 {
323 u32 events_vector, event;
324 unsigned long timeout;
325
326 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
327
328 do {
329 if (time_after(jiffies, timeout)) {
330 wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
331 (int)mask);
332 return -ETIMEDOUT;
333 }
334
335 msleep(1);
336
337 /* read from both event fields */
338 wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
339 sizeof(events_vector), false);
340 event = events_vector & mask;
341 wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
342 sizeof(events_vector), false);
343 event |= events_vector & mask;
344 } while (!event);
345
346 return 0;
347 }
348
349 static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
350 {
351 int ret;
352
353 ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask);
354 if (ret != 0) {
355 wl12xx_queue_recovery_work(wl);
356 return ret;
357 }
358
359 return 0;
360 }
361
362 int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
363 u8 *role_id)
364 {
365 struct wl12xx_cmd_role_enable *cmd;
366 int ret;
367
368 wl1271_debug(DEBUG_CMD, "cmd role enable");
369
370 if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID))
371 return -EBUSY;
372
373 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
374 if (!cmd) {
375 ret = -ENOMEM;
376 goto out;
377 }
378
379 /* get role id */
380 cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES);
381 if (cmd->role_id >= WL12XX_MAX_ROLES) {
382 ret = -EBUSY;
383 goto out_free;
384 }
385
386 memcpy(cmd->mac_address, addr, ETH_ALEN);
387 cmd->role_type = role_type;
388
389 ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0);
390 if (ret < 0) {
391 wl1271_error("failed to initiate cmd role enable");
392 goto out_free;
393 }
394
395 __set_bit(cmd->role_id, wl->roles_map);
396 *role_id = cmd->role_id;
397
398 out_free:
399 kfree(cmd);
400
401 out:
402 return ret;
403 }
404
405 int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id)
406 {
407 struct wl12xx_cmd_role_disable *cmd;
408 int ret;
409
410 wl1271_debug(DEBUG_CMD, "cmd role disable");
411
412 if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID))
413 return -ENOENT;
414
415 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
416 if (!cmd) {
417 ret = -ENOMEM;
418 goto out;
419 }
420 cmd->role_id = *role_id;
421
422 ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0);
423 if (ret < 0) {
424 wl1271_error("failed to initiate cmd role disable");
425 goto out_free;
426 }
427
428 __clear_bit(*role_id, wl->roles_map);
429 *role_id = WL12XX_INVALID_ROLE_ID;
430
431 out_free:
432 kfree(cmd);
433
434 out:
435 return ret;
436 }
437
438 int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
439 {
440 u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
441 if (link >= WL12XX_MAX_LINKS)
442 return -EBUSY;
443
444 __set_bit(link, wl->links_map);
445 __set_bit(link, wlvif->links_map);
446 *hlid = link;
447 return 0;
448 }
449
450 void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
451 {
452 if (*hlid == WL12XX_INVALID_LINK_ID)
453 return;
454
455 __clear_bit(*hlid, wl->links_map);
456 __clear_bit(*hlid, wlvif->links_map);
457 *hlid = WL12XX_INVALID_LINK_ID;
458 }
459
460 static int wl12xx_get_new_session_id(struct wl1271 *wl,
461 struct wl12xx_vif *wlvif)
462 {
463 if (wlvif->session_counter >= SESSION_COUNTER_MAX)
464 wlvif->session_counter = 0;
465
466 wlvif->session_counter++;
467
468 return wlvif->session_counter;
469 }
470
471 int wl12xx_cmd_role_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
472 {
473 struct wl12xx_cmd_role_start *cmd;
474 int ret;
475
476 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
477 if (!cmd) {
478 ret = -ENOMEM;
479 goto out;
480 }
481
482 wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id);
483
484 cmd->role_id = wlvif->dev_role_id;
485 if (wlvif->band == IEEE80211_BAND_5GHZ)
486 cmd->band = WL12XX_BAND_5GHZ;
487 cmd->channel = wlvif->channel;
488
489 if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) {
490 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid);
491 if (ret)
492 goto out_free;
493 }
494 cmd->device.hlid = wlvif->dev_hlid;
495 cmd->device.session = wlvif->session_counter;
496
497 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
498 cmd->role_id, cmd->device.hlid, cmd->device.session);
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 enable");
503 goto err_hlid;
504 }
505
506 goto out_free;
507
508 err_hlid:
509 /* clear links on error */
510 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
511
512 out_free:
513 kfree(cmd);
514
515 out:
516 return ret;
517 }
518
519 int wl12xx_cmd_role_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
520 {
521 struct wl12xx_cmd_role_stop *cmd;
522 int ret;
523
524 if (WARN_ON(wlvif->dev_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 }
532
533 wl1271_debug(DEBUG_CMD, "cmd role stop dev");
534
535 cmd->role_id = wlvif->dev_role_id;
536 cmd->disc_type = DISCONNECT_IMMEDIATE;
537 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
538
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");
542 goto out_free;
543 }
544
545 ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
546 if (ret < 0) {
547 wl1271_error("cmd role stop dev event completion error");
548 goto out_free;
549 }
550
551 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
552
553 out_free:
554 kfree(cmd);
555
556 out:
557 return ret;
558 }
559
560 int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
561 {
562 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
563 struct wl12xx_cmd_role_start *cmd;
564 int ret;
565
566 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
567 if (!cmd) {
568 ret = -ENOMEM;
569 goto out;
570 }
571
572 wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id);
573
574 cmd->role_id = wlvif->role_id;
575 if (wlvif->band == IEEE80211_BAND_5GHZ)
576 cmd->band = WL12XX_BAND_5GHZ;
577 cmd->channel = wlvif->channel;
578 cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
579 cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
580 cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
581 cmd->sta.ssid_len = wlvif->ssid_len;
582 memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
583 memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
584 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
585
586 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
587 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
588 if (ret)
589 goto out_free;
590 }
591 cmd->sta.hlid = wlvif->sta.hlid;
592 cmd->sta.session = wl12xx_get_new_session_id(wl, wlvif);
593 cmd->sta.remote_rates = cpu_to_le32(wlvif->rate_set);
594
595 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
596 "basic_rate_set: 0x%x, remote_rates: 0x%x",
597 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
598 wlvif->basic_rate_set, wlvif->rate_set);
599
600 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
601 if (ret < 0) {
602 wl1271_error("failed to initiate cmd role start sta");
603 goto err_hlid;
604 }
605
606 goto out_free;
607
608 err_hlid:
609 /* clear links on error. */
610 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
611
612 out_free:
613 kfree(cmd);
614
615 out:
616 return ret;
617 }
618
619 /* use this function to stop ibss as well */
620 int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
621 {
622 struct wl12xx_cmd_role_stop *cmd;
623 int ret;
624
625 if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID))
626 return -EINVAL;
627
628 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
629 if (!cmd) {
630 ret = -ENOMEM;
631 goto out;
632 }
633
634 wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id);
635
636 cmd->role_id = wlvif->role_id;
637 cmd->disc_type = DISCONNECT_IMMEDIATE;
638 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
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 sta");
643 goto out_free;
644 }
645
646 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
647
648 out_free:
649 kfree(cmd);
650
651 out:
652 return ret;
653 }
654
655 int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
656 {
657 struct wl12xx_cmd_role_start *cmd;
658 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
659 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
660 int ret;
661
662 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
663
664 /* trying to use hidden SSID with an old hostapd version */
665 if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
666 wl1271_error("got a null SSID from beacon/bss");
667 ret = -EINVAL;
668 goto out;
669 }
670
671 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
672 if (!cmd) {
673 ret = -ENOMEM;
674 goto out;
675 }
676
677 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid);
678 if (ret < 0)
679 goto out_free;
680
681 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid);
682 if (ret < 0)
683 goto out_free_global;
684
685 cmd->role_id = wlvif->role_id;
686 cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
687 cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
688 cmd->ap.global_hlid = wlvif->ap.global_hlid;
689 cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid;
690 cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
691 cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
692 cmd->ap.dtim_interval = bss_conf->dtim_period;
693 cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
694 cmd->channel = wlvif->channel;
695
696 if (!bss_conf->hidden_ssid) {
697 /* take the SSID from the beacon for backward compatibility */
698 cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
699 cmd->ap.ssid_len = wlvif->ssid_len;
700 memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len);
701 } else {
702 cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN;
703 cmd->ap.ssid_len = bss_conf->ssid_len;
704 memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len);
705 }
706
707 cmd->ap.local_rates = cpu_to_le32(0xffffffff);
708
709 switch (wlvif->band) {
710 case IEEE80211_BAND_2GHZ:
711 cmd->band = RADIO_BAND_2_4GHZ;
712 break;
713 case IEEE80211_BAND_5GHZ:
714 cmd->band = RADIO_BAND_5GHZ;
715 break;
716 default:
717 wl1271_warning("ap start - unknown band: %d", (int)wlvif->band);
718 cmd->band = RADIO_BAND_2_4GHZ;
719 break;
720 }
721
722 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
723 if (ret < 0) {
724 wl1271_error("failed to initiate cmd role start ap");
725 goto out_free_bcast;
726 }
727
728 goto out_free;
729
730 out_free_bcast:
731 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
732
733 out_free_global:
734 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
735
736 out_free:
737 kfree(cmd);
738
739 out:
740 return ret;
741 }
742
743 int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
744 {
745 struct wl12xx_cmd_role_stop *cmd;
746 int ret;
747
748 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
749 if (!cmd) {
750 ret = -ENOMEM;
751 goto out;
752 }
753
754 wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id);
755
756 cmd->role_id = wlvif->role_id;
757
758 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
759 if (ret < 0) {
760 wl1271_error("failed to initiate cmd role stop ap");
761 goto out_free;
762 }
763
764 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
765 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
766
767 out_free:
768 kfree(cmd);
769
770 out:
771 return ret;
772 }
773
774 int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif)
775 {
776 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
777 struct wl12xx_cmd_role_start *cmd;
778 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
779 int ret;
780
781 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
782 if (!cmd) {
783 ret = -ENOMEM;
784 goto out;
785 }
786
787 wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id);
788
789 cmd->role_id = wlvif->role_id;
790 if (wlvif->band == IEEE80211_BAND_5GHZ)
791 cmd->band = WL12XX_BAND_5GHZ;
792 cmd->channel = wlvif->channel;
793 cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
794 cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int);
795 cmd->ibss.dtim_interval = bss_conf->dtim_period;
796 cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY;
797 cmd->ibss.ssid_len = wlvif->ssid_len;
798 memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len);
799 memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN);
800 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
801
802 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
803 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
804 if (ret)
805 goto out_free;
806 }
807 cmd->ibss.hlid = wlvif->sta.hlid;
808 cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set);
809
810 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
811 "basic_rate_set: 0x%x, remote_rates: 0x%x",
812 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
813 wlvif->basic_rate_set, wlvif->rate_set);
814
815 wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM",
816 vif->bss_conf.bssid);
817
818 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
819 if (ret < 0) {
820 wl1271_error("failed to initiate cmd role enable");
821 goto err_hlid;
822 }
823
824 goto out_free;
825
826 err_hlid:
827 /* clear links on error. */
828 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
829
830 out_free:
831 kfree(cmd);
832
833 out:
834 return ret;
835 }
836
837
838 /**
839 * send test command to firmware
840 *
841 * @wl: wl struct
842 * @buf: buffer containing the command, with all headers, must work with dma
843 * @len: length of the buffer
844 * @answer: is answer needed
845 */
846 int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
847 {
848 int ret;
849 size_t res_len = 0;
850
851 wl1271_debug(DEBUG_CMD, "cmd test");
852
853 if (answer)
854 res_len = buf_len;
855
856 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
857
858 if (ret < 0) {
859 wl1271_warning("TEST command failed");
860 return ret;
861 }
862
863 return ret;
864 }
865
866 /**
867 * read acx from firmware
868 *
869 * @wl: wl struct
870 * @id: acx id
871 * @buf: buffer for the response, including all headers, must work with dma
872 * @len: length of buf
873 */
874 int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
875 {
876 struct acx_header *acx = buf;
877 int ret;
878
879 wl1271_debug(DEBUG_CMD, "cmd interrogate");
880
881 acx->id = cpu_to_le16(id);
882
883 /* payload length, does not include any headers */
884 acx->len = cpu_to_le16(len - sizeof(*acx));
885
886 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
887 if (ret < 0)
888 wl1271_error("INTERROGATE command failed");
889
890 return ret;
891 }
892
893 /**
894 * write acx value to firmware
895 *
896 * @wl: wl struct
897 * @id: acx id
898 * @buf: buffer containing acx, including all headers, must work with dma
899 * @len: length of buf
900 */
901 int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
902 {
903 struct acx_header *acx = buf;
904 int ret;
905
906 wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
907
908 acx->id = cpu_to_le16(id);
909
910 /* payload length, does not include any headers */
911 acx->len = cpu_to_le16(len - sizeof(*acx));
912
913 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
914 if (ret < 0) {
915 wl1271_warning("CONFIGURE command NOK");
916 return ret;
917 }
918
919 return 0;
920 }
921
922 int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
923 {
924 struct cmd_enabledisable_path *cmd;
925 int ret;
926 u16 cmd_rx, cmd_tx;
927
928 wl1271_debug(DEBUG_CMD, "cmd data path");
929
930 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
931 if (!cmd) {
932 ret = -ENOMEM;
933 goto out;
934 }
935
936 /* the channel here is only used for calibration, so hardcoded to 1 */
937 cmd->channel = 1;
938
939 if (enable) {
940 cmd_rx = CMD_ENABLE_RX;
941 cmd_tx = CMD_ENABLE_TX;
942 } else {
943 cmd_rx = CMD_DISABLE_RX;
944 cmd_tx = CMD_DISABLE_TX;
945 }
946
947 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
948 if (ret < 0) {
949 wl1271_error("rx %s cmd for channel %d failed",
950 enable ? "start" : "stop", cmd->channel);
951 goto out;
952 }
953
954 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
955 enable ? "start" : "stop", cmd->channel);
956
957 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
958 if (ret < 0) {
959 wl1271_error("tx %s cmd for channel %d failed",
960 enable ? "start" : "stop", cmd->channel);
961 goto out;
962 }
963
964 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
965 enable ? "start" : "stop", cmd->channel);
966
967 out:
968 kfree(cmd);
969 return ret;
970 }
971
972 int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
973 u8 ps_mode)
974 {
975 struct wl1271_cmd_ps_params *ps_params = NULL;
976 int ret = 0;
977
978 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
979
980 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
981 if (!ps_params) {
982 ret = -ENOMEM;
983 goto out;
984 }
985
986 ps_params->role_id = wlvif->role_id;
987 ps_params->ps_mode = ps_mode;
988
989 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
990 sizeof(*ps_params), 0);
991 if (ret < 0) {
992 wl1271_error("cmd set_ps_mode failed");
993 goto out;
994 }
995
996 out:
997 kfree(ps_params);
998 return ret;
999 }
1000
1001 int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
1002 void *buf, size_t buf_len, int index, u32 rates)
1003 {
1004 struct wl1271_cmd_template_set *cmd;
1005 int ret = 0;
1006
1007 wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
1008
1009 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
1010 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
1011
1012 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1013 if (!cmd) {
1014 ret = -ENOMEM;
1015 goto out;
1016 }
1017
1018 cmd->len = cpu_to_le16(buf_len);
1019 cmd->template_type = template_id;
1020 cmd->enabled_rates = cpu_to_le32(rates);
1021 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
1022 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
1023 cmd->index = index;
1024
1025 if (buf)
1026 memcpy(cmd->template_data, buf, buf_len);
1027
1028 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
1029 if (ret < 0) {
1030 wl1271_warning("cmd set_template failed: %d", ret);
1031 goto out_free;
1032 }
1033
1034 out_free:
1035 kfree(cmd);
1036
1037 out:
1038 return ret;
1039 }
1040
1041 int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1042 {
1043 struct sk_buff *skb = NULL;
1044 int size;
1045 void *ptr;
1046 int ret = -ENOMEM;
1047
1048
1049 if (wlvif->bss_type == BSS_TYPE_IBSS) {
1050 size = sizeof(struct wl12xx_null_data_template);
1051 ptr = NULL;
1052 } else {
1053 skb = ieee80211_nullfunc_get(wl->hw,
1054 wl12xx_wlvif_to_vif(wlvif));
1055 if (!skb)
1056 goto out;
1057 size = skb->len;
1058 ptr = skb->data;
1059 }
1060
1061 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
1062 wlvif->basic_rate);
1063
1064 out:
1065 dev_kfree_skb(skb);
1066 if (ret)
1067 wl1271_warning("cmd buld null data failed %d", ret);
1068
1069 return ret;
1070
1071 }
1072
1073 int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
1074 struct wl12xx_vif *wlvif)
1075 {
1076 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1077 struct sk_buff *skb = NULL;
1078 int ret = -ENOMEM;
1079
1080 skb = ieee80211_nullfunc_get(wl->hw, vif);
1081 if (!skb)
1082 goto out;
1083
1084 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
1085 skb->data, skb->len,
1086 CMD_TEMPL_KLV_IDX_NULL_DATA,
1087 wlvif->basic_rate);
1088
1089 out:
1090 dev_kfree_skb(skb);
1091 if (ret)
1092 wl1271_warning("cmd build klv null data failed %d", ret);
1093
1094 return ret;
1095
1096 }
1097
1098 int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1099 u16 aid)
1100 {
1101 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1102 struct sk_buff *skb;
1103 int ret = 0;
1104
1105 skb = ieee80211_pspoll_get(wl->hw, vif);
1106 if (!skb)
1107 goto out;
1108
1109 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
1110 skb->len, 0, wlvif->basic_rate_set);
1111
1112 out:
1113 dev_kfree_skb(skb);
1114 return ret;
1115 }
1116
1117 int wl1271_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1118 const u8 *ssid, size_t ssid_len,
1119 const u8 *ie, size_t ie_len, u8 band)
1120 {
1121 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1122 struct sk_buff *skb;
1123 int ret;
1124 u32 rate;
1125
1126 skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len,
1127 ie, ie_len);
1128 if (!skb) {
1129 ret = -ENOMEM;
1130 goto out;
1131 }
1132
1133 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
1134
1135 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
1136 if (band == IEEE80211_BAND_2GHZ)
1137 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
1138 skb->data, skb->len, 0, rate);
1139 else
1140 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
1141 skb->data, skb->len, 0, rate);
1142
1143 out:
1144 dev_kfree_skb(skb);
1145 return ret;
1146 }
1147
1148 struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
1149 struct wl12xx_vif *wlvif,
1150 struct sk_buff *skb)
1151 {
1152 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1153 int ret;
1154 u32 rate;
1155
1156 if (!skb)
1157 skb = ieee80211_ap_probereq_get(wl->hw, vif);
1158 if (!skb)
1159 goto out;
1160
1161 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
1162
1163 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
1164 if (wlvif->band == IEEE80211_BAND_2GHZ)
1165 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
1166 skb->data, skb->len, 0, rate);
1167 else
1168 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
1169 skb->data, skb->len, 0, rate);
1170
1171 if (ret < 0)
1172 wl1271_error("Unable to set ap probe request template.");
1173
1174 out:
1175 return skb;
1176 }
1177
1178 int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1179 __be32 ip_addr)
1180 {
1181 int ret;
1182 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1183 struct wl12xx_arp_rsp_template tmpl;
1184 struct ieee80211_hdr_3addr *hdr;
1185 struct arphdr *arp_hdr;
1186
1187 memset(&tmpl, 0, sizeof(tmpl));
1188
1189 /* mac80211 header */
1190 hdr = &tmpl.hdr;
1191 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1192 IEEE80211_STYPE_DATA |
1193 IEEE80211_FCTL_TODS);
1194 memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN);
1195 memcpy(hdr->addr2, vif->addr, ETH_ALEN);
1196 memset(hdr->addr3, 0xff, ETH_ALEN);
1197
1198 /* llc layer */
1199 memcpy(tmpl.llc_hdr, rfc1042_header, sizeof(rfc1042_header));
1200 tmpl.llc_type = cpu_to_be16(ETH_P_ARP);
1201
1202 /* arp header */
1203 arp_hdr = &tmpl.arp_hdr;
1204 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
1205 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
1206 arp_hdr->ar_hln = ETH_ALEN;
1207 arp_hdr->ar_pln = 4;
1208 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
1209
1210 /* arp payload */
1211 memcpy(tmpl.sender_hw, vif->addr, ETH_ALEN);
1212 tmpl.sender_ip = ip_addr;
1213
1214 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP,
1215 &tmpl, sizeof(tmpl), 0,
1216 wlvif->basic_rate);
1217
1218 return ret;
1219 }
1220
1221 int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1222 {
1223 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
1224 struct ieee80211_qos_hdr template;
1225
1226 memset(&template, 0, sizeof(template));
1227
1228 memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN);
1229 memcpy(template.addr2, vif->addr, ETH_ALEN);
1230 memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN);
1231
1232 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1233 IEEE80211_STYPE_QOS_NULLFUNC |
1234 IEEE80211_FCTL_TODS);
1235
1236 /* FIXME: not sure what priority to use here */
1237 template.qos_ctrl = cpu_to_le16(0);
1238
1239 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
1240 sizeof(template), 0,
1241 wlvif->basic_rate);
1242 }
1243
1244 int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
1245 {
1246 struct wl1271_cmd_set_keys *cmd;
1247 int ret = 0;
1248
1249 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
1250
1251 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1252 if (!cmd) {
1253 ret = -ENOMEM;
1254 goto out;
1255 }
1256
1257 cmd->hlid = hlid;
1258 cmd->key_id = id;
1259 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1260 cmd->key_action = cpu_to_le16(KEY_SET_ID);
1261 cmd->key_type = KEY_WEP;
1262
1263 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1264 if (ret < 0) {
1265 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
1266 goto out;
1267 }
1268
1269 out:
1270 kfree(cmd);
1271
1272 return ret;
1273 }
1274
1275 int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1276 u16 action, u8 id, u8 key_type,
1277 u8 key_size, const u8 *key, const u8 *addr,
1278 u32 tx_seq_32, u16 tx_seq_16)
1279 {
1280 struct wl1271_cmd_set_keys *cmd;
1281 int ret = 0;
1282
1283 /* hlid might have already been deleted */
1284 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
1285 return 0;
1286
1287 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1288 if (!cmd) {
1289 ret = -ENOMEM;
1290 goto out;
1291 }
1292
1293 cmd->hlid = wlvif->sta.hlid;
1294
1295 if (key_type == KEY_WEP)
1296 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1297 else if (is_broadcast_ether_addr(addr))
1298 cmd->lid_key_type = BROADCAST_LID_TYPE;
1299 else
1300 cmd->lid_key_type = UNICAST_LID_TYPE;
1301
1302 cmd->key_action = cpu_to_le16(action);
1303 cmd->key_size = key_size;
1304 cmd->key_type = key_type;
1305
1306 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1307 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1308
1309 cmd->key_id = id;
1310
1311 if (key_type == KEY_TKIP) {
1312 /*
1313 * We get the key in the following form:
1314 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1315 * but the target is expecting:
1316 * TKIP - RX MIC - TX MIC
1317 */
1318 memcpy(cmd->key, key, 16);
1319 memcpy(cmd->key + 16, key + 24, 8);
1320 memcpy(cmd->key + 24, key + 16, 8);
1321
1322 } else {
1323 memcpy(cmd->key, key, key_size);
1324 }
1325
1326 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
1327
1328 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1329 if (ret < 0) {
1330 wl1271_warning("could not set keys");
1331 goto out;
1332 }
1333
1334 out:
1335 kfree(cmd);
1336
1337 return ret;
1338 }
1339
1340 /*
1341 * TODO: merge with sta/ibss into 1 set_key function.
1342 * note there are slight diffs
1343 */
1344 int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1345 u16 action, u8 id, u8 key_type,
1346 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
1347 u16 tx_seq_16)
1348 {
1349 struct wl1271_cmd_set_keys *cmd;
1350 int ret = 0;
1351 u8 lid_type;
1352
1353 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1354 if (!cmd)
1355 return -ENOMEM;
1356
1357 if (hlid == wlvif->ap.bcast_hlid) {
1358 if (key_type == KEY_WEP)
1359 lid_type = WEP_DEFAULT_LID_TYPE;
1360 else
1361 lid_type = BROADCAST_LID_TYPE;
1362 } else {
1363 lid_type = UNICAST_LID_TYPE;
1364 }
1365
1366 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
1367 " hlid: %d", (int)action, (int)id, (int)lid_type,
1368 (int)key_type, (int)hlid);
1369
1370 cmd->lid_key_type = lid_type;
1371 cmd->hlid = hlid;
1372 cmd->key_action = cpu_to_le16(action);
1373 cmd->key_size = key_size;
1374 cmd->key_type = key_type;
1375 cmd->key_id = id;
1376 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1377 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1378
1379 if (key_type == KEY_TKIP) {
1380 /*
1381 * We get the key in the following form:
1382 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1383 * but the target is expecting:
1384 * TKIP - RX MIC - TX MIC
1385 */
1386 memcpy(cmd->key, key, 16);
1387 memcpy(cmd->key + 16, key + 24, 8);
1388 memcpy(cmd->key + 24, key + 16, 8);
1389 } else {
1390 memcpy(cmd->key, key, key_size);
1391 }
1392
1393 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
1394
1395 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1396 if (ret < 0) {
1397 wl1271_warning("could not set ap keys");
1398 goto out;
1399 }
1400
1401 out:
1402 kfree(cmd);
1403 return ret;
1404 }
1405
1406 int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid)
1407 {
1408 struct wl12xx_cmd_set_peer_state *cmd;
1409 int ret = 0;
1410
1411 wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid);
1412
1413 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1414 if (!cmd) {
1415 ret = -ENOMEM;
1416 goto out;
1417 }
1418
1419 cmd->hlid = hlid;
1420 cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
1421
1422 ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0);
1423 if (ret < 0) {
1424 wl1271_error("failed to send set peer state command");
1425 goto out_free;
1426 }
1427
1428 out_free:
1429 kfree(cmd);
1430
1431 out:
1432 return ret;
1433 }
1434
1435 int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1436 struct ieee80211_sta *sta, u8 hlid)
1437 {
1438 struct wl12xx_cmd_add_peer *cmd;
1439 int i, ret;
1440 u32 sta_rates;
1441
1442 wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid);
1443
1444 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1445 if (!cmd) {
1446 ret = -ENOMEM;
1447 goto out;
1448 }
1449
1450 memcpy(cmd->addr, sta->addr, ETH_ALEN);
1451 cmd->bss_index = WL1271_AP_BSS_INDEX;
1452 cmd->aid = sta->aid;
1453 cmd->hlid = hlid;
1454 cmd->sp_len = sta->max_sp;
1455 cmd->wmm = sta->wme ? 1 : 0;
1456
1457 for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++)
1458 if (sta->wme && (sta->uapsd_queues & BIT(i)))
1459 cmd->psd_type[i] = WL1271_PSD_UPSD_TRIGGER;
1460 else
1461 cmd->psd_type[i] = WL1271_PSD_LEGACY;
1462
1463 sta_rates = sta->supp_rates[wlvif->band];
1464 if (sta->ht_cap.ht_supported)
1465 sta_rates |= sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET;
1466
1467 cmd->supported_rates =
1468 cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
1469 wlvif->band));
1470
1471 wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x",
1472 cmd->supported_rates, sta->uapsd_queues);
1473
1474 ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0);
1475 if (ret < 0) {
1476 wl1271_error("failed to initiate cmd add peer");
1477 goto out_free;
1478 }
1479
1480 out_free:
1481 kfree(cmd);
1482
1483 out:
1484 return ret;
1485 }
1486
1487 int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid)
1488 {
1489 struct wl12xx_cmd_remove_peer *cmd;
1490 int ret;
1491
1492 wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid);
1493
1494 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1495 if (!cmd) {
1496 ret = -ENOMEM;
1497 goto out;
1498 }
1499
1500 cmd->hlid = hlid;
1501 /* We never send a deauth, mac80211 is in charge of this */
1502 cmd->reason_opcode = 0;
1503 cmd->send_deauth_flag = 0;
1504
1505 ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
1506 if (ret < 0) {
1507 wl1271_error("failed to initiate cmd remove peer");
1508 goto out_free;
1509 }
1510
1511 /*
1512 * We are ok with a timeout here. The event is sometimes not sent
1513 * due to a firmware bug.
1514 */
1515 wl1271_cmd_wait_for_event_or_timeout(wl,
1516 PEER_REMOVE_COMPLETE_EVENT_ID);
1517
1518 out_free:
1519 kfree(cmd);
1520
1521 out:
1522 return ret;
1523 }
1524
1525 int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
1526 {
1527 struct wl12xx_cmd_config_fwlog *cmd;
1528 int ret = 0;
1529
1530 wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
1531
1532 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1533 if (!cmd) {
1534 ret = -ENOMEM;
1535 goto out;
1536 }
1537
1538 cmd->logger_mode = wl->conf.fwlog.mode;
1539 cmd->log_severity = wl->conf.fwlog.severity;
1540 cmd->timestamp = wl->conf.fwlog.timestamp;
1541 cmd->output = wl->conf.fwlog.output;
1542 cmd->threshold = wl->conf.fwlog.threshold;
1543
1544 ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
1545 if (ret < 0) {
1546 wl1271_error("failed to send config firmware logger command");
1547 goto out_free;
1548 }
1549
1550 out_free:
1551 kfree(cmd);
1552
1553 out:
1554 return ret;
1555 }
1556
1557 int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
1558 {
1559 struct wl12xx_cmd_start_fwlog *cmd;
1560 int ret = 0;
1561
1562 wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
1563
1564 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1565 if (!cmd) {
1566 ret = -ENOMEM;
1567 goto out;
1568 }
1569
1570 ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
1571 if (ret < 0) {
1572 wl1271_error("failed to send start firmware logger command");
1573 goto out_free;
1574 }
1575
1576 out_free:
1577 kfree(cmd);
1578
1579 out:
1580 return ret;
1581 }
1582
1583 int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
1584 {
1585 struct wl12xx_cmd_stop_fwlog *cmd;
1586 int ret = 0;
1587
1588 wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
1589
1590 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1591 if (!cmd) {
1592 ret = -ENOMEM;
1593 goto out;
1594 }
1595
1596 ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
1597 if (ret < 0) {
1598 wl1271_error("failed to send stop firmware logger command");
1599 goto out_free;
1600 }
1601
1602 out_free:
1603 kfree(cmd);
1604
1605 out:
1606 return ret;
1607 }
1608
1609 static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1610 u8 role_id)
1611 {
1612 struct wl12xx_cmd_roc *cmd;
1613 int ret = 0;
1614
1615 wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wlvif->channel, role_id);
1616
1617 if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
1618 return -EINVAL;
1619
1620 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1621 if (!cmd) {
1622 ret = -ENOMEM;
1623 goto out;
1624 }
1625
1626 cmd->role_id = role_id;
1627 cmd->channel = wlvif->channel;
1628 switch (wlvif->band) {
1629 case IEEE80211_BAND_2GHZ:
1630 cmd->band = RADIO_BAND_2_4GHZ;
1631 break;
1632 case IEEE80211_BAND_5GHZ:
1633 cmd->band = RADIO_BAND_5GHZ;
1634 break;
1635 default:
1636 wl1271_error("roc - unknown band: %d", (int)wlvif->band);
1637 ret = -EINVAL;
1638 goto out_free;
1639 }
1640
1641
1642 ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0);
1643 if (ret < 0) {
1644 wl1271_error("failed to send ROC command");
1645 goto out_free;
1646 }
1647
1648 out_free:
1649 kfree(cmd);
1650
1651 out:
1652 return ret;
1653 }
1654
1655 static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id)
1656 {
1657 struct wl12xx_cmd_croc *cmd;
1658 int ret = 0;
1659
1660 wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id);
1661
1662 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1663 if (!cmd) {
1664 ret = -ENOMEM;
1665 goto out;
1666 }
1667 cmd->role_id = role_id;
1668
1669 ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd,
1670 sizeof(*cmd), 0);
1671 if (ret < 0) {
1672 wl1271_error("failed to send ROC command");
1673 goto out_free;
1674 }
1675
1676 out_free:
1677 kfree(cmd);
1678
1679 out:
1680 return ret;
1681 }
1682
1683 int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id)
1684 {
1685 int ret = 0;
1686
1687 if (WARN_ON(test_bit(role_id, wl->roc_map)))
1688 return 0;
1689
1690 ret = wl12xx_cmd_roc(wl, wlvif, role_id);
1691 if (ret < 0)
1692 goto out;
1693
1694 ret = wl1271_cmd_wait_for_event(wl,
1695 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID);
1696 if (ret < 0) {
1697 wl1271_error("cmd roc event completion error");
1698 goto out;
1699 }
1700
1701 __set_bit(role_id, wl->roc_map);
1702 out:
1703 return ret;
1704 }
1705
1706 int wl12xx_croc(struct wl1271 *wl, u8 role_id)
1707 {
1708 int ret = 0;
1709
1710 if (WARN_ON(!test_bit(role_id, wl->roc_map)))
1711 return 0;
1712
1713 ret = wl12xx_cmd_croc(wl, role_id);
1714 if (ret < 0)
1715 goto out;
1716
1717 __clear_bit(role_id, wl->roc_map);
1718 out:
1719 return ret;
1720 }
1721
1722 int wl12xx_cmd_channel_switch(struct wl1271 *wl,
1723 struct ieee80211_channel_switch *ch_switch)
1724 {
1725 struct wl12xx_cmd_channel_switch *cmd;
1726 int ret;
1727
1728 wl1271_debug(DEBUG_ACX, "cmd channel switch");
1729
1730 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1731 if (!cmd) {
1732 ret = -ENOMEM;
1733 goto out;
1734 }
1735
1736 cmd->channel = ch_switch->channel->hw_value;
1737 cmd->switch_time = ch_switch->count;
1738 cmd->tx_suspend = ch_switch->block_tx;
1739 cmd->flush = 0; /* this value is ignored by the FW */
1740
1741 ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
1742 if (ret < 0) {
1743 wl1271_error("failed to send channel switch command");
1744 goto out_free;
1745 }
1746
1747 out_free:
1748 kfree(cmd);
1749
1750 out:
1751 return ret;
1752 }
1753
1754 int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl)
1755 {
1756 struct wl12xx_cmd_stop_channel_switch *cmd;
1757 int ret;
1758
1759 wl1271_debug(DEBUG_ACX, "cmd stop channel switch");
1760
1761 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1762 if (!cmd) {
1763 ret = -ENOMEM;
1764 goto out;
1765 }
1766
1767 ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0);
1768 if (ret < 0) {
1769 wl1271_error("failed to stop channel switch command");
1770 goto out_free;
1771 }
1772
1773 out_free:
1774 kfree(cmd);
1775
1776 out:
1777 return ret;
1778 }
This page took 0.63156 seconds and 5 git commands to generate.