blob: bd65b38eb1d9b6c952deb02f7730af294d01dee4 [file] [log] [blame]
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009 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/crc7.h>
27#include <linux/spi/spi.h>
28#include <linux/etherdevice.h>
29
30#include "wl1271.h"
31#include "wl1271_reg.h"
32#include "wl1271_spi.h"
33#include "wl1271_acx.h"
34#include "wl12xx_80211.h"
35#include "wl1271_cmd.h"
36
37/*
38 * send command to firmware
39 *
40 * @wl: wl struct
41 * @id: command id
42 * @buf: buffer containing the command, must work with dma
43 * @len: length of the buffer
44 */
45int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len)
46{
47 struct wl1271_cmd_header *cmd;
48 unsigned long timeout;
49 u32 intr;
50 int ret = 0;
51
52 cmd = buf;
53 cmd->id = id;
54 cmd->status = 0;
55
56 WARN_ON(len % 4 != 0);
57
58 wl1271_spi_mem_write(wl, wl->cmd_box_addr, buf, len);
59
60 wl1271_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
61
62 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
63
64 intr = wl1271_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
65 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
66 if (time_after(jiffies, timeout)) {
67 wl1271_error("command complete timeout");
68 ret = -ETIMEDOUT;
69 goto out;
70 }
71
72 msleep(1);
73
74 intr = wl1271_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
75 }
76
77 wl1271_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
78 WL1271_ACX_INTR_CMD_COMPLETE);
79
80out:
81 return ret;
82}
83
84int wl1271_cmd_cal_channel_tune(struct wl1271 *wl)
85{
86 struct wl1271_cmd_cal_channel_tune *cmd;
87 int ret = 0;
88
89 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
90 if (!cmd)
91 return -ENOMEM;
92
93 cmd->test.id = TEST_CMD_CHANNEL_TUNE;
94
95 cmd->band = WL1271_CHANNEL_TUNE_BAND_2_4;
96 /* set up any channel, 7 is in the middle of the range */
97 cmd->channel = 7;
98
99 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
100 if (ret < 0)
101 wl1271_warning("TEST_CMD_CHANNEL_TUNE failed");
102
103 kfree(cmd);
104 return ret;
105}
106
107int wl1271_cmd_cal_update_ref_point(struct wl1271 *wl)
108{
109 struct wl1271_cmd_cal_update_ref_point *cmd;
110 int ret = 0;
111
112 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
113 if (!cmd)
114 return -ENOMEM;
115
116 cmd->test.id = TEST_CMD_UPDATE_PD_REFERENCE_POINT;
117
118 /* FIXME: still waiting for the correct values */
119 cmd->ref_power = 0;
120 cmd->ref_detector = 0;
121
122 cmd->sub_band = WL1271_PD_REFERENCE_POINT_BAND_B_G;
123
124 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
125 if (ret < 0)
126 wl1271_warning("TEST_CMD_UPDATE_PD_REFERENCE_POINT failed");
127
128 kfree(cmd);
129 return ret;
130}
131
132int wl1271_cmd_cal_p2g(struct wl1271 *wl)
133{
134 struct wl1271_cmd_cal_p2g *cmd;
135 int ret = 0;
136
137 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
138 if (!cmd)
139 return -ENOMEM;
140
141 cmd->test.id = TEST_CMD_P2G_CAL;
142
143 cmd->sub_band_mask = WL1271_CAL_P2G_BAND_B_G;
144
145 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
146 if (ret < 0)
147 wl1271_warning("TEST_CMD_P2G_CAL failed");
148
149 kfree(cmd);
150 return ret;
151}
152
153int wl1271_cmd_cal(struct wl1271 *wl)
154{
155 /*
156 * FIXME: we must make sure that we're not sleeping when calibration
157 * is done
158 */
159 int ret;
160
161 wl1271_notice("performing tx calibration");
162
163 ret = wl1271_cmd_cal_channel_tune(wl);
164 if (ret < 0)
165 return ret;
166
167 ret = wl1271_cmd_cal_update_ref_point(wl);
168 if (ret < 0)
169 return ret;
170
171 ret = wl1271_cmd_cal_p2g(wl);
172 if (ret < 0)
173 return ret;
174
175 return ret;
176}
177
178int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type, u8 dtim_interval,
179 u16 beacon_interval, u8 wait)
180{
181 static bool do_cal = true;
182 unsigned long timeout;
183 struct wl1271_cmd_join *join;
184 int ret, i;
185 u8 *bssid;
186
187 /* FIXME: remove when we get calibration from the factory */
188 if (do_cal) {
189 ret = wl1271_cmd_cal(wl);
190 if (ret < 0)
191 wl1271_warning("couldn't calibrate");
192 else
193 do_cal = false;
194 }
195
196
197 join = kzalloc(sizeof(*join), GFP_KERNEL);
198 if (!join) {
199 ret = -ENOMEM;
200 goto out;
201 }
202
203 wl1271_debug(DEBUG_CMD, "cmd join");
204
205 /* Reverse order BSSID */
206 bssid = (u8 *) &join->bssid_lsb;
207 for (i = 0; i < ETH_ALEN; i++)
208 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
209
210 join->rx_config_options = wl->rx_config;
211 join->rx_filter_options = wl->rx_filter;
212
213 join->basic_rate_set = RATE_MASK_1MBPS | RATE_MASK_2MBPS |
214 RATE_MASK_5_5MBPS | RATE_MASK_11MBPS;
215
216 join->beacon_interval = beacon_interval;
217 join->dtim_interval = dtim_interval;
218 join->bss_type = bss_type;
219 join->channel = wl->channel;
220 join->ssid_len = wl->ssid_len;
221 memcpy(join->ssid, wl->ssid, wl->ssid_len);
222 join->ctrl = WL1271_JOIN_CMD_CTRL_TX_FLUSH;
223
224 /* increment the session counter */
225 wl->session_counter++;
226 if (wl->session_counter >= SESSION_COUNTER_MAX)
227 wl->session_counter = 0;
228
229 join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
230
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300231 /* reset TX security counters */
232 wl->tx_security_last_seq = 0;
233 wl->tx_security_seq_16 = 0;
234 wl->tx_security_seq_32 = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300235
236 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join));
237 if (ret < 0) {
238 wl1271_error("failed to initiate cmd join");
239 goto out_free;
240 }
241
242 timeout = msecs_to_jiffies(JOIN_TIMEOUT);
243
244 /*
245 * ugly hack: we should wait for JOIN_EVENT_COMPLETE_ID but to
246 * simplify locking we just sleep instead, for now
247 */
248 if (wait)
249 msleep(10);
250
251out_free:
252 kfree(join);
253
254out:
255 return ret;
256}
257
258/**
259 * send test command to firmware
260 *
261 * @wl: wl struct
262 * @buf: buffer containing the command, with all headers, must work with dma
263 * @len: length of the buffer
264 * @answer: is answer needed
265 */
266int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
267{
268 int ret;
269
270 wl1271_debug(DEBUG_CMD, "cmd test");
271
272 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len);
273
274 if (ret < 0) {
275 wl1271_warning("TEST command failed");
276 return ret;
277 }
278
279 if (answer) {
280 struct wl1271_command *cmd_answer;
281
282 /*
283 * The test command got in, we can read the answer.
284 * The answer would be a wl1271_command, where the
285 * parameter array contains the actual answer.
286 */
287 wl1271_spi_mem_read(wl, wl->cmd_box_addr, buf, buf_len);
288
289 cmd_answer = buf;
290
291 if (cmd_answer->header.status != CMD_STATUS_SUCCESS)
292 wl1271_error("TEST command answer error: %d",
293 cmd_answer->header.status);
294 }
295
296 return 0;
297}
298
299/**
300 * read acx from firmware
301 *
302 * @wl: wl struct
303 * @id: acx id
304 * @buf: buffer for the response, including all headers, must work with dma
305 * @len: lenght of buf
306 */
307int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
308{
309 struct acx_header *acx = buf;
310 int ret;
311
312 wl1271_debug(DEBUG_CMD, "cmd interrogate");
313
314 acx->id = id;
315
316 /* payload length, does not include any headers */
317 acx->len = len - sizeof(*acx);
318
319 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx));
320 if (ret < 0) {
321 wl1271_error("INTERROGATE command failed");
322 goto out;
323 }
324
325 /* the interrogate command got in, we can read the answer */
326 wl1271_spi_mem_read(wl, wl->cmd_box_addr, buf, len);
327
328 acx = buf;
329 if (acx->cmd.status != CMD_STATUS_SUCCESS)
330 wl1271_error("INTERROGATE command error: %d",
331 acx->cmd.status);
332
333out:
334 return ret;
335}
336
337/**
338 * write acx value to firmware
339 *
340 * @wl: wl struct
341 * @id: acx id
342 * @buf: buffer containing acx, including all headers, must work with dma
343 * @len: length of buf
344 */
345int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
346{
347 struct acx_header *acx = buf;
348 int ret;
349
350 wl1271_debug(DEBUG_CMD, "cmd configure");
351
352 acx->id = id;
353
354 /* payload length, does not include any headers */
355 acx->len = len - sizeof(*acx);
356
357 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len);
358 if (ret < 0) {
359 wl1271_warning("CONFIGURE command NOK");
360 return ret;
361 }
362
363 return 0;
364}
365
366int wl1271_cmd_data_path(struct wl1271 *wl, u8 channel, bool enable)
367{
368 struct cmd_enabledisable_path *cmd;
369 int ret;
370 u16 cmd_rx, cmd_tx;
371
372 wl1271_debug(DEBUG_CMD, "cmd data path");
373
374 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
375 if (!cmd) {
376 ret = -ENOMEM;
377 goto out;
378 }
379
380 cmd->channel = channel;
381
382 if (enable) {
383 cmd_rx = CMD_ENABLE_RX;
384 cmd_tx = CMD_ENABLE_TX;
385 } else {
386 cmd_rx = CMD_DISABLE_RX;
387 cmd_tx = CMD_DISABLE_TX;
388 }
389
390 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd));
391 if (ret < 0) {
392 wl1271_error("rx %s cmd for channel %d failed",
393 enable ? "start" : "stop", channel);
394 goto out;
395 }
396
397 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
398 enable ? "start" : "stop", channel);
399
400 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd));
401 if (ret < 0) {
402 wl1271_error("tx %s cmd for channel %d failed",
403 enable ? "start" : "stop", channel);
404 return ret;
405 }
406
407 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
408 enable ? "start" : "stop", channel);
409
410out:
411 kfree(cmd);
412 return ret;
413}
414
415int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode)
416{
417 struct wl1271_cmd_ps_params *ps_params = NULL;
418 int ret = 0;
419
420 /* FIXME: this should be in ps.c */
421 ret = wl1271_acx_wake_up_conditions(wl, WAKE_UP_EVENT_DTIM_BITMAP,
422 wl->listen_int);
423 if (ret < 0) {
424 wl1271_error("couldn't set wake up conditions");
425 goto out;
426 }
427
428 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
429
430 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
431 if (!ps_params) {
432 ret = -ENOMEM;
433 goto out;
434 }
435
436 ps_params->ps_mode = ps_mode;
437 ps_params->send_null_data = 1;
438 ps_params->retries = 5;
439 ps_params->hang_over_period = 128;
440 ps_params->null_data_rate = 1; /* 1 Mbps */
441
442 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
443 sizeof(*ps_params));
444 if (ret < 0) {
445 wl1271_error("cmd set_ps_mode failed");
446 goto out;
447 }
448
449out:
450 kfree(ps_params);
451 return ret;
452}
453
454int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
455 size_t len)
456{
457 struct cmd_read_write_memory *cmd;
458 int ret = 0;
459
460 wl1271_debug(DEBUG_CMD, "cmd read memory");
461
462 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
463 if (!cmd) {
464 ret = -ENOMEM;
465 goto out;
466 }
467
468 WARN_ON(len > MAX_READ_SIZE);
469 len = min_t(size_t, len, MAX_READ_SIZE);
470
471 cmd->addr = addr;
472 cmd->size = len;
473
474 ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd));
475 if (ret < 0) {
476 wl1271_error("read memory command failed: %d", ret);
477 goto out;
478 }
479
480 /* the read command got in, we can now read the answer */
481 wl1271_spi_mem_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd));
482
483 if (cmd->header.status != CMD_STATUS_SUCCESS)
484 wl1271_error("error in read command result: %d",
485 cmd->header.status);
486
487 memcpy(answer, cmd->value, len);
488
489out:
490 kfree(cmd);
491 return ret;
492}
493
494int wl1271_cmd_scan(struct wl1271 *wl, u8 *ssid, size_t len,
495 u8 active_scan, u8 high_prio, u8 num_channels,
496 u8 probe_requests)
497{
498
499 struct wl1271_cmd_trigger_scan_to *trigger = NULL;
500 struct wl1271_cmd_scan *params = NULL;
501 int i, ret;
502 u16 scan_options = 0;
503
504 if (wl->scanning)
505 return -EINVAL;
506
507 params = kzalloc(sizeof(*params), GFP_KERNEL);
508 if (!params)
509 return -ENOMEM;
510
511 params->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
512 params->params.rx_filter_options =
513 cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
514
515 if (!active_scan)
516 scan_options |= WL1271_SCAN_OPT_PASSIVE;
517 if (high_prio)
518 scan_options |= WL1271_SCAN_OPT_PRIORITY_HIGH;
519 params->params.scan_options = scan_options;
520
521 params->params.num_channels = num_channels;
522 params->params.num_probe_requests = probe_requests;
523 params->params.tx_rate = cpu_to_le32(RATE_MASK_2MBPS);
524 params->params.tid_trigger = 0;
525 params->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
526
527 for (i = 0; i < num_channels; i++) {
528 params->channels[i].min_duration =
529 cpu_to_le32(WL1271_SCAN_CHAN_MIN_DURATION);
530 params->channels[i].max_duration =
531 cpu_to_le32(WL1271_SCAN_CHAN_MAX_DURATION);
532 memset(&params->channels[i].bssid_lsb, 0xff, 4);
533 memset(&params->channels[i].bssid_msb, 0xff, 2);
534 params->channels[i].early_termination = 0;
535 params->channels[i].tx_power_att = WL1271_SCAN_CURRENT_TX_PWR;
536 params->channels[i].channel = i + 1;
537 }
538
539 if (len && ssid) {
540 params->params.ssid_len = len;
541 memcpy(params->params.ssid, ssid, len);
542 }
543
544 ret = wl1271_cmd_build_probe_req(wl, ssid, len);
545 if (ret < 0) {
546 wl1271_error("PROBE request template failed");
547 goto out;
548 }
549
550 trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
551 if (!trigger) {
552 ret = -ENOMEM;
553 goto out;
554 }
555
556 /* disable the timeout */
557 trigger->timeout = 0;
558
559 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
560 sizeof(*trigger));
561 if (ret < 0) {
562 wl1271_error("trigger scan to failed for hw scan");
563 goto out;
564 }
565
566 wl1271_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params));
567
568 wl->scanning = true;
569
570 ret = wl1271_cmd_send(wl, CMD_SCAN, params, sizeof(*params));
571 if (ret < 0) {
572 wl1271_error("SCAN failed");
573 goto out;
574 }
575
576 wl1271_spi_mem_read(wl, wl->cmd_box_addr, params, sizeof(*params));
577
578 if (params->header.status != CMD_STATUS_SUCCESS) {
579 wl1271_error("Scan command error: %d",
580 params->header.status);
581 wl->scanning = false;
582 ret = -EIO;
583 goto out;
584 }
585
586out:
587 kfree(params);
588 return ret;
589}
590
591int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
592 void *buf, size_t buf_len)
593{
594 struct wl1271_cmd_template_set *cmd;
595 int ret = 0;
596
597 wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
598
599 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
600 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
601
602 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
603 if (!cmd) {
604 ret = -ENOMEM;
605 goto out;
606 }
607
608 cmd->len = cpu_to_le16(buf_len);
609 cmd->template_type = template_id;
610 cmd->enabled_rates = ACX_RATE_MASK_UNSPECIFIED;
611 cmd->short_retry_limit = ACX_RATE_RETRY_LIMIT;
612 cmd->long_retry_limit = ACX_RATE_RETRY_LIMIT;
613
614 if (buf)
615 memcpy(cmd->template_data, buf, buf_len);
616
617 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd));
618 if (ret < 0) {
619 wl1271_warning("cmd set_template failed: %d", ret);
620 goto out_free;
621 }
622
623out_free:
624 kfree(cmd);
625
626out:
627 return ret;
628}
629
630static int wl1271_build_basic_rates(char *rates)
631{
632 u8 index = 0;
633
634 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
635 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
636 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
637 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
638
639 return index;
640}
641
642static int wl1271_build_extended_rates(char *rates)
643{
644 u8 index = 0;
645
646 rates[index++] = IEEE80211_OFDM_RATE_6MB;
647 rates[index++] = IEEE80211_OFDM_RATE_9MB;
648 rates[index++] = IEEE80211_OFDM_RATE_12MB;
649 rates[index++] = IEEE80211_OFDM_RATE_18MB;
650 rates[index++] = IEEE80211_OFDM_RATE_24MB;
651 rates[index++] = IEEE80211_OFDM_RATE_36MB;
652 rates[index++] = IEEE80211_OFDM_RATE_48MB;
653 rates[index++] = IEEE80211_OFDM_RATE_54MB;
654
655 return index;
656}
657
658int wl1271_cmd_build_null_data(struct wl1271 *wl)
659{
660 struct wl12xx_null_data_template template;
661
662 if (!is_zero_ether_addr(wl->bssid)) {
663 memcpy(template.header.da, wl->bssid, ETH_ALEN);
664 memcpy(template.header.bssid, wl->bssid, ETH_ALEN);
665 } else {
666 memset(template.header.da, 0xff, ETH_ALEN);
667 memset(template.header.bssid, 0xff, ETH_ALEN);
668 }
669
670 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
671 template.header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
672 IEEE80211_STYPE_NULLFUNC);
673
674 return wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, &template,
675 sizeof(template));
676
677}
678
679int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
680{
681 struct wl12xx_ps_poll_template template;
682
683 memcpy(template.bssid, wl->bssid, ETH_ALEN);
684 memcpy(template.ta, wl->mac_addr, ETH_ALEN);
Juuso Oikarinenc3fea192009-10-08 21:56:22 +0300685
686 /* aid in PS-Poll has its two MSBs each set to 1 */
687 template.aid = cpu_to_le16(1 << 15 | 1 << 14 | aid);
688
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300689 template.fc = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
690
691 return wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, &template,
692 sizeof(template));
693
694}
695
696int wl1271_cmd_build_probe_req(struct wl1271 *wl, u8 *ssid, size_t ssid_len)
697{
698 struct wl12xx_probe_req_template template;
699 struct wl12xx_ie_rates *rates;
700 char *ptr;
701 u16 size;
702
703 ptr = (char *)&template;
704 size = sizeof(struct ieee80211_header);
705
706 memset(template.header.da, 0xff, ETH_ALEN);
707 memset(template.header.bssid, 0xff, ETH_ALEN);
708 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
709 template.header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
710
711 /* IEs */
712 /* SSID */
713 template.ssid.header.id = WLAN_EID_SSID;
714 template.ssid.header.len = ssid_len;
715 if (ssid_len && ssid)
716 memcpy(template.ssid.ssid, ssid, ssid_len);
717 size += sizeof(struct wl12xx_ie_header) + ssid_len;
718 ptr += size;
719
720 /* Basic Rates */
721 rates = (struct wl12xx_ie_rates *)ptr;
722 rates->header.id = WLAN_EID_SUPP_RATES;
723 rates->header.len = wl1271_build_basic_rates(rates->rates);
724 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
725 ptr += sizeof(struct wl12xx_ie_header) + rates->header.len;
726
727 /* Extended rates */
728 rates = (struct wl12xx_ie_rates *)ptr;
729 rates->header.id = WLAN_EID_EXT_SUPP_RATES;
730 rates->header.len = wl1271_build_extended_rates(rates->rates);
731 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
732
733 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", &template, size);
734
735 return wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
736 &template, size);
737}
738
739int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id)
740{
741 struct wl1271_cmd_set_keys *cmd;
742 int ret = 0;
743
744 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
745
746 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
747 if (!cmd) {
748 ret = -ENOMEM;
749 goto out;
750 }
751
752 cmd->id = id;
753 cmd->key_action = KEY_SET_ID;
754 cmd->key_type = KEY_WEP;
755
756 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd));
757 if (ret < 0) {
758 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
759 goto out;
760 }
761
762out:
763 kfree(cmd);
764
765 return ret;
766}
767
768int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300769 u8 key_size, const u8 *key, const u8 *addr,
770 u32 tx_seq_32, u16 tx_seq_16)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300771{
772 struct wl1271_cmd_set_keys *cmd;
773 int ret = 0;
774
775 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
776 if (!cmd) {
777 ret = -ENOMEM;
778 goto out;
779 }
780
781 if (key_type != KEY_WEP)
782 memcpy(cmd->addr, addr, ETH_ALEN);
783
784 cmd->key_action = action;
785 cmd->key_size = key_size;
786 cmd->key_type = key_type;
787
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300788 cmd->ac_seq_num16[0] = tx_seq_16;
789 cmd->ac_seq_num32[0] = tx_seq_32;
790
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300791 /* we have only one SSID profile */
792 cmd->ssid_profile = 0;
793
794 cmd->id = id;
795
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300796 if (key_type == KEY_TKIP) {
797 /*
798 * We get the key in the following form:
799 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
800 * but the target is expecting:
801 * TKIP - RX MIC - TX MIC
802 */
803 memcpy(cmd->key, key, 16);
804 memcpy(cmd->key + 16, key + 24, 8);
805 memcpy(cmd->key + 24, key + 16, 8);
806
807 } else {
808 memcpy(cmd->key, key, key_size);
809 }
810
811 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
812
813 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd));
814 if (ret < 0) {
815 wl1271_warning("could not set keys");
816 goto out;
817 }
818
819out:
820 kfree(cmd);
821
822 return ret;
823}