2 * This file is part of wl1271
4 * Copyright (C) 2009 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
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.
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.
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
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>
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"
38 * send command to firmware
42 * @buf: buffer containing the command, must work with dma
43 * @len: length of the buffer
45 int wl1271_cmd_send(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
,
48 struct wl1271_cmd_header
*cmd
;
49 unsigned long timeout
;
55 cmd
->id
= cpu_to_le16(id
);
58 WARN_ON(len
% 4 != 0);
60 wl1271_spi_write(wl
, wl
->cmd_box_addr
, buf
, len
, false);
62 wl1271_spi_write32(wl
, ACX_REG_INTERRUPT_TRIG
, INTR_TRIG_CMD
);
64 timeout
= jiffies
+ msecs_to_jiffies(WL1271_COMMAND_TIMEOUT
);
66 intr
= wl1271_spi_read32(wl
, ACX_REG_INTERRUPT_NO_CLEAR
);
67 while (!(intr
& WL1271_ACX_INTR_CMD_COMPLETE
)) {
68 if (time_after(jiffies
, timeout
)) {
69 wl1271_error("command complete timeout");
76 intr
= wl1271_spi_read32(wl
, ACX_REG_INTERRUPT_NO_CLEAR
);
79 /* read back the status code of the command */
81 res_len
= sizeof(struct wl1271_cmd_header
);
82 wl1271_spi_read(wl
, wl
->cmd_box_addr
, cmd
, res_len
, false);
84 status
= le16_to_cpu(cmd
->status
);
85 if (status
!= CMD_STATUS_SUCCESS
) {
86 wl1271_error("command execute failure %d", status
);
90 wl1271_spi_write32(wl
, ACX_REG_INTERRUPT_ACK
,
91 WL1271_ACX_INTR_CMD_COMPLETE
);
97 static int wl1271_cmd_cal_channel_tune(struct wl1271
*wl
)
99 struct wl1271_cmd_cal_channel_tune
*cmd
;
102 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
106 cmd
->test
.id
= TEST_CMD_CHANNEL_TUNE
;
108 cmd
->band
= WL1271_CHANNEL_TUNE_BAND_2_4
;
109 /* set up any channel, 7 is in the middle of the range */
112 ret
= wl1271_cmd_test(wl
, cmd
, sizeof(*cmd
), 0);
114 wl1271_warning("TEST_CMD_CHANNEL_TUNE failed");
120 static int wl1271_cmd_cal_update_ref_point(struct wl1271
*wl
)
122 struct wl1271_cmd_cal_update_ref_point
*cmd
;
125 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
129 cmd
->test
.id
= TEST_CMD_UPDATE_PD_REFERENCE_POINT
;
131 /* FIXME: still waiting for the correct values */
133 cmd
->ref_detector
= 0;
135 cmd
->sub_band
= WL1271_PD_REFERENCE_POINT_BAND_B_G
;
137 ret
= wl1271_cmd_test(wl
, cmd
, sizeof(*cmd
), 0);
139 wl1271_warning("TEST_CMD_UPDATE_PD_REFERENCE_POINT failed");
145 static int wl1271_cmd_cal_p2g(struct wl1271
*wl
)
147 struct wl1271_cmd_cal_p2g
*cmd
;
150 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
154 cmd
->test
.id
= TEST_CMD_P2G_CAL
;
156 cmd
->sub_band_mask
= WL1271_CAL_P2G_BAND_B_G
;
158 ret
= wl1271_cmd_test(wl
, cmd
, sizeof(*cmd
), 0);
160 wl1271_warning("TEST_CMD_P2G_CAL failed");
166 static int wl1271_cmd_cal(struct wl1271
*wl
)
169 * FIXME: we must make sure that we're not sleeping when calibration
174 wl1271_notice("performing tx calibration");
176 ret
= wl1271_cmd_cal_channel_tune(wl
);
180 ret
= wl1271_cmd_cal_update_ref_point(wl
);
184 ret
= wl1271_cmd_cal_p2g(wl
);
191 int wl1271_cmd_general_parms(struct wl1271
*wl
)
193 struct wl1271_general_parms_cmd
*gen_parms
;
194 struct conf_general_parms
*g
= &wl
->conf
.init
.genparam
;
197 gen_parms
= kzalloc(sizeof(*gen_parms
), GFP_KERNEL
);
201 gen_parms
->test
.id
= TEST_CMD_INI_FILE_GENERAL_PARAM
;
203 gen_parms
->ref_clk
= g
->ref_clk
;
204 gen_parms
->settling_time
= g
->settling_time
;
205 gen_parms
->clk_valid_on_wakeup
= g
->clk_valid_on_wakeup
;
206 gen_parms
->dc2dcmode
= g
->dc2dcmode
;
207 gen_parms
->single_dual_band
= g
->single_dual_band
;
208 gen_parms
->tx_bip_fem_autodetect
= g
->tx_bip_fem_autodetect
;
209 gen_parms
->tx_bip_fem_manufacturer
= g
->tx_bip_fem_manufacturer
;
210 gen_parms
->settings
= g
->settings
;
212 ret
= wl1271_cmd_test(wl
, gen_parms
, sizeof(*gen_parms
), 0);
214 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
220 int wl1271_cmd_radio_parms(struct wl1271
*wl
)
222 struct wl1271_radio_parms_cmd
*radio_parms
;
223 struct conf_radio_parms
*r
= &wl
->conf
.init
.radioparam
;
226 radio_parms
= kzalloc(sizeof(*radio_parms
), GFP_KERNEL
);
230 radio_parms
->test
.id
= TEST_CMD_INI_FILE_RADIO_PARAM
;
232 /* Static radio parameters */
233 radio_parms
->rx_trace_loss
= r
->rx_trace_loss
;
234 radio_parms
->tx_trace_loss
= r
->tx_trace_loss
;
235 memcpy(radio_parms
->rx_rssi_and_proc_compens
,
236 r
->rx_rssi_and_proc_compens
,
237 CONF_RSSI_AND_PROCESS_COMPENSATION_SIZE
);
239 memcpy(radio_parms
->rx_trace_loss_5
, r
->rx_trace_loss_5
,
240 CONF_NUMBER_OF_SUB_BANDS_5
);
241 memcpy(radio_parms
->tx_trace_loss_5
, r
->tx_trace_loss_5
,
242 CONF_NUMBER_OF_SUB_BANDS_5
);
243 memcpy(radio_parms
->rx_rssi_and_proc_compens_5
,
244 r
->rx_rssi_and_proc_compens_5
,
245 CONF_RSSI_AND_PROCESS_COMPENSATION_SIZE
);
247 /* Dynamic radio parameters */
248 radio_parms
->tx_ref_pd_voltage
= cpu_to_le16(r
->tx_ref_pd_voltage
);
249 radio_parms
->tx_ref_power
= r
->tx_ref_power
;
250 radio_parms
->tx_offset_db
= r
->tx_offset_db
;
252 memcpy(radio_parms
->tx_rate_limits_normal
, r
->tx_rate_limits_normal
,
253 CONF_NUMBER_OF_RATE_GROUPS
);
254 memcpy(radio_parms
->tx_rate_limits_degraded
, r
->tx_rate_limits_degraded
,
255 CONF_NUMBER_OF_RATE_GROUPS
);
257 memcpy(radio_parms
->tx_channel_limits_11b
, r
->tx_channel_limits_11b
,
258 CONF_NUMBER_OF_CHANNELS_2_4
);
259 memcpy(radio_parms
->tx_channel_limits_ofdm
, r
->tx_channel_limits_ofdm
,
260 CONF_NUMBER_OF_CHANNELS_2_4
);
261 memcpy(radio_parms
->tx_pdv_rate_offsets
, r
->tx_pdv_rate_offsets
,
262 CONF_NUMBER_OF_RATE_GROUPS
);
263 memcpy(radio_parms
->tx_ibias
, r
->tx_ibias
, CONF_NUMBER_OF_RATE_GROUPS
);
265 radio_parms
->rx_fem_insertion_loss
= r
->rx_fem_insertion_loss
;
267 for (i
= 0; i
< CONF_NUMBER_OF_SUB_BANDS_5
; i
++)
268 radio_parms
->tx_ref_pd_voltage_5
[i
] =
269 cpu_to_le16(r
->tx_ref_pd_voltage_5
[i
]);
270 memcpy(radio_parms
->tx_ref_power_5
, r
->tx_ref_power_5
,
271 CONF_NUMBER_OF_SUB_BANDS_5
);
272 memcpy(radio_parms
->tx_offset_db_5
, r
->tx_offset_db_5
,
273 CONF_NUMBER_OF_SUB_BANDS_5
);
274 memcpy(radio_parms
->tx_rate_limits_normal_5
,
275 r
->tx_rate_limits_normal_5
, CONF_NUMBER_OF_RATE_GROUPS
);
276 memcpy(radio_parms
->tx_rate_limits_degraded_5
,
277 r
->tx_rate_limits_degraded_5
, CONF_NUMBER_OF_RATE_GROUPS
);
278 memcpy(radio_parms
->tx_channel_limits_ofdm_5
,
279 r
->tx_channel_limits_ofdm_5
, CONF_NUMBER_OF_CHANNELS_5
);
280 memcpy(radio_parms
->tx_pdv_rate_offsets_5
, r
->tx_pdv_rate_offsets_5
,
281 CONF_NUMBER_OF_RATE_GROUPS
);
282 memcpy(radio_parms
->tx_ibias_5
, r
->tx_ibias_5
,
283 CONF_NUMBER_OF_RATE_GROUPS
);
284 memcpy(radio_parms
->rx_fem_insertion_loss_5
,
285 r
->rx_fem_insertion_loss_5
, CONF_NUMBER_OF_SUB_BANDS_5
);
287 wl1271_dump(DEBUG_CMD
, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
288 radio_parms
, sizeof(*radio_parms
));
290 ret
= wl1271_cmd_test(wl
, radio_parms
, sizeof(*radio_parms
), 0);
292 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
298 int wl1271_cmd_join(struct wl1271
*wl
)
300 static bool do_cal
= true;
301 struct wl1271_cmd_join
*join
;
305 /* FIXME: remove when we get calibration from the factory */
307 ret
= wl1271_cmd_cal(wl
);
309 wl1271_warning("couldn't calibrate");
314 /* FIXME: This is a workaround, because with the current stack, we
315 * cannot know when we have disassociated. So, if we have already
316 * joined, we disconnect before joining again. */
318 ret
= wl1271_cmd_disconnect(wl
);
320 wl1271_error("failed to disconnect before rejoining");
327 join
= kzalloc(sizeof(*join
), GFP_KERNEL
);
333 wl1271_debug(DEBUG_CMD
, "cmd join");
335 /* Reverse order BSSID */
336 bssid
= (u8
*) &join
->bssid_lsb
;
337 for (i
= 0; i
< ETH_ALEN
; i
++)
338 bssid
[i
] = wl
->bssid
[ETH_ALEN
- i
- 1];
340 join
->rx_config_options
= cpu_to_le32(wl
->rx_config
);
341 join
->rx_filter_options
= cpu_to_le32(wl
->rx_filter
);
342 join
->bss_type
= wl
->bss_type
;
345 * FIXME: disable temporarily all filters because after commit
346 * 9cef8737 "mac80211: fix managed mode BSSID handling" broke
347 * association. The filter logic needs to be implemented properly
348 * and once that is done, this hack can be removed.
350 join
->rx_config_options
= cpu_to_le32(0);
351 join
->rx_filter_options
= cpu_to_le32(WL1271_DEFAULT_RX_FILTER
);
353 if (wl
->band
== IEEE80211_BAND_2GHZ
)
354 join
->basic_rate_set
= cpu_to_le32(CONF_HW_BIT_RATE_1MBPS
|
355 CONF_HW_BIT_RATE_2MBPS
|
356 CONF_HW_BIT_RATE_5_5MBPS
|
357 CONF_HW_BIT_RATE_11MBPS
);
359 join
->bss_type
|= WL1271_JOIN_CMD_BSS_TYPE_5GHZ
;
360 join
->basic_rate_set
= cpu_to_le32(CONF_HW_BIT_RATE_6MBPS
|
361 CONF_HW_BIT_RATE_12MBPS
|
362 CONF_HW_BIT_RATE_24MBPS
);
365 join
->beacon_interval
= cpu_to_le16(WL1271_DEFAULT_BEACON_INT
);
366 join
->dtim_interval
= WL1271_DEFAULT_DTIM_PERIOD
;
368 join
->channel
= wl
->channel
;
369 join
->ssid_len
= wl
->ssid_len
;
370 memcpy(join
->ssid
, wl
->ssid
, wl
->ssid_len
);
371 join
->ctrl
= WL1271_JOIN_CMD_CTRL_TX_FLUSH
;
373 /* increment the session counter */
374 wl
->session_counter
++;
375 if (wl
->session_counter
>= SESSION_COUNTER_MAX
)
376 wl
->session_counter
= 0;
378 join
->ctrl
|= wl
->session_counter
<< WL1271_JOIN_CMD_TX_SESSION_OFFSET
;
380 /* reset TX security counters */
381 wl
->tx_security_last_seq
= 0;
382 wl
->tx_security_seq_16
= 0;
383 wl
->tx_security_seq_32
= 0;
385 ret
= wl1271_cmd_send(wl
, CMD_START_JOIN
, join
, sizeof(*join
), 0);
387 wl1271_error("failed to initiate cmd join");
394 * ugly hack: we should wait for JOIN_EVENT_COMPLETE_ID but to
395 * simplify locking we just sleep instead, for now
407 * send test command to firmware
410 * @buf: buffer containing the command, with all headers, must work with dma
411 * @len: length of the buffer
412 * @answer: is answer needed
414 int wl1271_cmd_test(struct wl1271
*wl
, void *buf
, size_t buf_len
, u8 answer
)
419 wl1271_debug(DEBUG_CMD
, "cmd test");
424 ret
= wl1271_cmd_send(wl
, CMD_TEST
, buf
, buf_len
, res_len
);
427 wl1271_warning("TEST command failed");
435 * read acx from firmware
439 * @buf: buffer for the response, including all headers, must work with dma
440 * @len: lenght of buf
442 int wl1271_cmd_interrogate(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
444 struct acx_header
*acx
= buf
;
447 wl1271_debug(DEBUG_CMD
, "cmd interrogate");
449 acx
->id
= cpu_to_le16(id
);
451 /* payload length, does not include any headers */
452 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
454 ret
= wl1271_cmd_send(wl
, CMD_INTERROGATE
, acx
, sizeof(*acx
), len
);
456 wl1271_error("INTERROGATE command failed");
462 * write acx value to firmware
466 * @buf: buffer containing acx, including all headers, must work with dma
467 * @len: length of buf
469 int wl1271_cmd_configure(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
471 struct acx_header
*acx
= buf
;
474 wl1271_debug(DEBUG_CMD
, "cmd configure");
476 acx
->id
= cpu_to_le16(id
);
478 /* payload length, does not include any headers */
479 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
481 ret
= wl1271_cmd_send(wl
, CMD_CONFIGURE
, acx
, len
, 0);
483 wl1271_warning("CONFIGURE command NOK");
490 int wl1271_cmd_data_path(struct wl1271
*wl
, u8 channel
, bool enable
)
492 struct cmd_enabledisable_path
*cmd
;
496 wl1271_debug(DEBUG_CMD
, "cmd data path");
498 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
504 cmd
->channel
= channel
;
507 cmd_rx
= CMD_ENABLE_RX
;
508 cmd_tx
= CMD_ENABLE_TX
;
510 cmd_rx
= CMD_DISABLE_RX
;
511 cmd_tx
= CMD_DISABLE_TX
;
514 ret
= wl1271_cmd_send(wl
, cmd_rx
, cmd
, sizeof(*cmd
), 0);
516 wl1271_error("rx %s cmd for channel %d failed",
517 enable
? "start" : "stop", channel
);
521 wl1271_debug(DEBUG_BOOT
, "rx %s cmd channel %d",
522 enable
? "start" : "stop", channel
);
524 ret
= wl1271_cmd_send(wl
, cmd_tx
, cmd
, sizeof(*cmd
), 0);
526 wl1271_error("tx %s cmd for channel %d failed",
527 enable
? "start" : "stop", channel
);
531 wl1271_debug(DEBUG_BOOT
, "tx %s cmd channel %d",
532 enable
? "start" : "stop", channel
);
539 int wl1271_cmd_ps_mode(struct wl1271
*wl
, u8 ps_mode
)
541 struct wl1271_cmd_ps_params
*ps_params
= NULL
;
544 /* FIXME: this should be in ps.c */
545 ret
= wl1271_acx_wake_up_conditions(wl
);
547 wl1271_error("couldn't set wake up conditions");
551 wl1271_debug(DEBUG_CMD
, "cmd set ps mode");
553 ps_params
= kzalloc(sizeof(*ps_params
), GFP_KERNEL
);
559 ps_params
->ps_mode
= ps_mode
;
560 ps_params
->send_null_data
= 1;
561 ps_params
->retries
= 5;
562 ps_params
->hang_over_period
= 128;
563 ps_params
->null_data_rate
= cpu_to_le32(1); /* 1 Mbps */
565 ret
= wl1271_cmd_send(wl
, CMD_SET_PS_MODE
, ps_params
,
566 sizeof(*ps_params
), 0);
568 wl1271_error("cmd set_ps_mode failed");
577 int wl1271_cmd_read_memory(struct wl1271
*wl
, u32 addr
, void *answer
,
580 struct cmd_read_write_memory
*cmd
;
583 wl1271_debug(DEBUG_CMD
, "cmd read memory");
585 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
591 WARN_ON(len
> MAX_READ_SIZE
);
592 len
= min_t(size_t, len
, MAX_READ_SIZE
);
594 cmd
->addr
= cpu_to_le32(addr
);
595 cmd
->size
= cpu_to_le32(len
);
597 ret
= wl1271_cmd_send(wl
, CMD_READ_MEMORY
, cmd
, sizeof(*cmd
),
600 wl1271_error("read memory command failed: %d", ret
);
604 /* the read command got in */
605 memcpy(answer
, cmd
->value
, len
);
612 int wl1271_cmd_scan(struct wl1271
*wl
, u8
*ssid
, size_t len
,
613 u8 active_scan
, u8 high_prio
, u8 band
,
617 struct wl1271_cmd_trigger_scan_to
*trigger
= NULL
;
618 struct wl1271_cmd_scan
*params
= NULL
;
619 struct ieee80211_channel
*channels
;
621 u16 scan_options
= 0;
624 if (band
== WL1271_SCAN_BAND_2_4_GHZ
)
625 ieee_band
= IEEE80211_BAND_2GHZ
;
626 else if (band
== WL1271_SCAN_BAND_DUAL
&& wl1271_11a_enabled())
627 ieee_band
= IEEE80211_BAND_2GHZ
;
628 else if (band
== WL1271_SCAN_BAND_5_GHZ
&& wl1271_11a_enabled())
629 ieee_band
= IEEE80211_BAND_5GHZ
;
633 if (wl
->hw
->wiphy
->bands
[ieee_band
]->channels
== NULL
)
636 channels
= wl
->hw
->wiphy
->bands
[ieee_band
]->channels
;
637 n_ch
= wl
->hw
->wiphy
->bands
[ieee_band
]->n_channels
;
642 params
= kzalloc(sizeof(*params
), GFP_KERNEL
);
646 params
->params
.rx_config_options
= cpu_to_le32(CFG_RX_ALL_GOOD
);
647 params
->params
.rx_filter_options
=
648 cpu_to_le32(CFG_RX_PRSP_EN
| CFG_RX_MGMT_EN
| CFG_RX_BCN_EN
);
651 scan_options
|= WL1271_SCAN_OPT_PASSIVE
;
653 scan_options
|= WL1271_SCAN_OPT_PRIORITY_HIGH
;
654 params
->params
.scan_options
= cpu_to_le16(scan_options
);
656 params
->params
.num_probe_requests
= probe_requests
;
657 /* Let the fw autodetect suitable tx_rate for probes */
658 params
->params
.tx_rate
= 0;
659 params
->params
.tid_trigger
= 0;
660 params
->params
.scan_tag
= WL1271_SCAN_DEFAULT_TAG
;
662 if (band
== WL1271_SCAN_BAND_DUAL
)
663 params
->params
.band
= WL1271_SCAN_BAND_2_4_GHZ
;
665 params
->params
.band
= band
;
667 for (i
= 0, j
= 0; i
< n_ch
&& i
< WL1271_SCAN_MAX_CHANNELS
; i
++) {
668 if (!(channels
[i
].flags
& IEEE80211_CHAN_DISABLED
)) {
669 params
->channels
[j
].min_duration
=
670 cpu_to_le32(WL1271_SCAN_CHAN_MIN_DURATION
);
671 params
->channels
[j
].max_duration
=
672 cpu_to_le32(WL1271_SCAN_CHAN_MAX_DURATION
);
673 memset(¶ms
->channels
[j
].bssid_lsb
, 0xff, 4);
674 memset(¶ms
->channels
[j
].bssid_msb
, 0xff, 2);
675 params
->channels
[j
].early_termination
= 0;
676 params
->channels
[j
].tx_power_att
=
677 WL1271_SCAN_CURRENT_TX_PWR
;
678 params
->channels
[j
].channel
= channels
[i
].hw_value
;
683 params
->params
.num_channels
= j
;
686 params
->params
.ssid_len
= len
;
687 memcpy(params
->params
.ssid
, ssid
, len
);
690 ret
= wl1271_cmd_build_probe_req(wl
, ssid
, len
, ieee_band
);
692 wl1271_error("PROBE request template failed");
696 trigger
= kzalloc(sizeof(*trigger
), GFP_KERNEL
);
702 /* disable the timeout */
703 trigger
->timeout
= 0;
705 ret
= wl1271_cmd_send(wl
, CMD_TRIGGER_SCAN_TO
, trigger
,
706 sizeof(*trigger
), 0);
708 wl1271_error("trigger scan to failed for hw scan");
712 wl1271_dump(DEBUG_SCAN
, "SCAN: ", params
, sizeof(*params
));
715 if (wl1271_11a_enabled()) {
716 wl
->scan
.state
= band
;
717 if (band
== WL1271_SCAN_BAND_DUAL
) {
718 wl
->scan
.active
= active_scan
;
719 wl
->scan
.high_prio
= high_prio
;
720 wl
->scan
.probe_requests
= probe_requests
;
722 wl
->scan
.ssid_len
= len
;
723 memcpy(wl
->scan
.ssid
, ssid
, len
);
725 wl
->scan
.ssid_len
= 0;
729 ret
= wl1271_cmd_send(wl
, CMD_SCAN
, params
, sizeof(*params
), 0);
731 wl1271_error("SCAN failed");
732 wl
->scanning
= false;
741 int wl1271_cmd_template_set(struct wl1271
*wl
, u16 template_id
,
742 void *buf
, size_t buf_len
)
744 struct wl1271_cmd_template_set
*cmd
;
747 wl1271_debug(DEBUG_CMD
, "cmd template_set %d", template_id
);
749 WARN_ON(buf_len
> WL1271_CMD_TEMPL_MAX_SIZE
);
750 buf_len
= min_t(size_t, buf_len
, WL1271_CMD_TEMPL_MAX_SIZE
);
752 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
758 cmd
->len
= cpu_to_le16(buf_len
);
759 cmd
->template_type
= template_id
;
760 cmd
->enabled_rates
= cpu_to_le32(wl
->conf
.tx
.rc_conf
.enabled_rates
);
761 cmd
->short_retry_limit
= wl
->conf
.tx
.rc_conf
.short_retry_limit
;
762 cmd
->long_retry_limit
= wl
->conf
.tx
.rc_conf
.long_retry_limit
;
765 memcpy(cmd
->template_data
, buf
, buf_len
);
767 ret
= wl1271_cmd_send(wl
, CMD_SET_TEMPLATE
, cmd
, sizeof(*cmd
), 0);
769 wl1271_warning("cmd set_template failed: %d", ret
);
780 static int wl1271_build_basic_rates(u8
*rates
, u8 band
)
784 if (band
== IEEE80211_BAND_2GHZ
) {
786 IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_1MB
;
788 IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_2MB
;
790 IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_5MB
;
792 IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_11MB
;
793 } else if (band
== IEEE80211_BAND_5GHZ
) {
795 IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_6MB
;
797 IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_12MB
;
799 IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_24MB
;
801 wl1271_error("build_basic_rates invalid band: %d", band
);
807 static int wl1271_build_extended_rates(u8
*rates
, u8 band
)
811 if (band
== IEEE80211_BAND_2GHZ
) {
812 rates
[index
++] = IEEE80211_OFDM_RATE_6MB
;
813 rates
[index
++] = IEEE80211_OFDM_RATE_9MB
;
814 rates
[index
++] = IEEE80211_OFDM_RATE_12MB
;
815 rates
[index
++] = IEEE80211_OFDM_RATE_18MB
;
816 rates
[index
++] = IEEE80211_OFDM_RATE_24MB
;
817 rates
[index
++] = IEEE80211_OFDM_RATE_36MB
;
818 rates
[index
++] = IEEE80211_OFDM_RATE_48MB
;
819 rates
[index
++] = IEEE80211_OFDM_RATE_54MB
;
820 } else if (band
== IEEE80211_BAND_5GHZ
) {
822 IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_9MB
;
824 IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_18MB
;
826 IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_24MB
;
828 IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_36MB
;
830 IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_48MB
;
832 IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_54MB
;
834 wl1271_error("build_basic_rates invalid band: %d", band
);
840 int wl1271_cmd_build_null_data(struct wl1271
*wl
)
842 struct wl12xx_null_data_template
template;
844 if (!is_zero_ether_addr(wl
->bssid
)) {
845 memcpy(template.header
.da
, wl
->bssid
, ETH_ALEN
);
846 memcpy(template.header
.bssid
, wl
->bssid
, ETH_ALEN
);
848 memset(template.header
.da
, 0xff, ETH_ALEN
);
849 memset(template.header
.bssid
, 0xff, ETH_ALEN
);
852 memcpy(template.header
.sa
, wl
->mac_addr
, ETH_ALEN
);
853 template.header
.frame_ctl
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
854 IEEE80211_STYPE_NULLFUNC
|
855 IEEE80211_FCTL_TODS
);
857 return wl1271_cmd_template_set(wl
, CMD_TEMPL_NULL_DATA
, &template,
862 int wl1271_cmd_build_ps_poll(struct wl1271
*wl
, u16 aid
)
864 struct wl12xx_ps_poll_template
template;
866 memcpy(template.bssid
, wl
->bssid
, ETH_ALEN
);
867 memcpy(template.ta
, wl
->mac_addr
, ETH_ALEN
);
869 /* aid in PS-Poll has its two MSBs each set to 1 */
870 template.aid
= cpu_to_le16(1 << 15 | 1 << 14 | aid
);
872 template.fc
= cpu_to_le16(IEEE80211_FTYPE_CTL
| IEEE80211_STYPE_PSPOLL
);
874 return wl1271_cmd_template_set(wl
, CMD_TEMPL_PS_POLL
, &template,
879 int wl1271_cmd_build_probe_req(struct wl1271
*wl
, u8
*ssid
, size_t ssid_len
,
882 struct wl12xx_probe_req_template
template;
883 struct wl12xx_ie_rates
*rates
;
888 ptr
= (char *)&template;
889 size
= sizeof(struct ieee80211_header
);
891 memset(template.header
.da
, 0xff, ETH_ALEN
);
892 memset(template.header
.bssid
, 0xff, ETH_ALEN
);
893 memcpy(template.header
.sa
, wl
->mac_addr
, ETH_ALEN
);
894 template.header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
898 template.ssid
.header
.id
= WLAN_EID_SSID
;
899 template.ssid
.header
.len
= ssid_len
;
900 if (ssid_len
&& ssid
)
901 memcpy(template.ssid
.ssid
, ssid
, ssid_len
);
902 size
+= sizeof(struct wl12xx_ie_header
) + ssid_len
;
906 rates
= (struct wl12xx_ie_rates
*)ptr
;
907 rates
->header
.id
= WLAN_EID_SUPP_RATES
;
908 rates
->header
.len
= wl1271_build_basic_rates(rates
->rates
, band
);
909 size
+= sizeof(struct wl12xx_ie_header
) + rates
->header
.len
;
910 ptr
+= sizeof(struct wl12xx_ie_header
) + rates
->header
.len
;
913 rates
= (struct wl12xx_ie_rates
*)ptr
;
914 rates
->header
.id
= WLAN_EID_EXT_SUPP_RATES
;
915 rates
->header
.len
= wl1271_build_extended_rates(rates
->rates
, band
);
916 size
+= sizeof(struct wl12xx_ie_header
) + rates
->header
.len
;
918 wl1271_dump(DEBUG_SCAN
, "PROBE REQ: ", &template, size
);
920 if (band
== IEEE80211_BAND_2GHZ
)
921 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_CFG_PROBE_REQ_2_4
,
924 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_CFG_PROBE_REQ_5
,
929 int wl1271_cmd_set_default_wep_key(struct wl1271
*wl
, u8 id
)
931 struct wl1271_cmd_set_keys
*cmd
;
934 wl1271_debug(DEBUG_CMD
, "cmd set_default_wep_key %d", id
);
936 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
943 cmd
->key_action
= cpu_to_le16(KEY_SET_ID
);
944 cmd
->key_type
= KEY_WEP
;
946 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
948 wl1271_warning("cmd set_default_wep_key failed: %d", ret
);
958 int wl1271_cmd_set_key(struct wl1271
*wl
, u16 action
, u8 id
, u8 key_type
,
959 u8 key_size
, const u8
*key
, const u8
*addr
,
960 u32 tx_seq_32
, u16 tx_seq_16
)
962 struct wl1271_cmd_set_keys
*cmd
;
965 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
971 if (key_type
!= KEY_WEP
)
972 memcpy(cmd
->addr
, addr
, ETH_ALEN
);
974 cmd
->key_action
= cpu_to_le16(action
);
975 cmd
->key_size
= key_size
;
976 cmd
->key_type
= key_type
;
978 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
979 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
981 /* we have only one SSID profile */
982 cmd
->ssid_profile
= 0;
986 if (key_type
== KEY_TKIP
) {
988 * We get the key in the following form:
989 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
990 * but the target is expecting:
991 * TKIP - RX MIC - TX MIC
993 memcpy(cmd
->key
, key
, 16);
994 memcpy(cmd
->key
+ 16, key
+ 24, 8);
995 memcpy(cmd
->key
+ 24, key
+ 16, 8);
998 memcpy(cmd
->key
, key
, key_size
);
1001 wl1271_dump(DEBUG_CRYPT
, "TARGET KEY: ", cmd
, sizeof(*cmd
));
1003 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1005 wl1271_warning("could not set keys");
1015 int wl1271_cmd_disconnect(struct wl1271
*wl
)
1017 struct wl1271_cmd_disconnect
*cmd
;
1020 wl1271_debug(DEBUG_CMD
, "cmd disconnect");
1022 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1028 cmd
->rx_config_options
= cpu_to_le32(wl
->rx_config
);
1029 cmd
->rx_filter_options
= cpu_to_le32(wl
->rx_filter
);
1030 /* disconnect reason is not used in immediate disconnections */
1031 cmd
->type
= DISCONNECT_IMMEDIATE
;
1033 ret
= wl1271_cmd_send(wl
, CMD_DISCONNECT
, cmd
, sizeof(*cmd
), 0);
1035 wl1271_error("failed to send disconnect command");