2 * This file is part of wl1271
4 * Copyright (C) 2009-2010 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>
29 #include <linux/ieee80211.h>
32 #include "wl1271_reg.h"
33 #include "wl1271_io.h"
34 #include "wl1271_acx.h"
35 #include "wl12xx_80211.h"
36 #include "wl1271_cmd.h"
37 #include "wl1271_event.h"
39 #define WL1271_CMD_FAST_POLL_COUNT 50
42 * send command to firmware
46 * @buf: buffer containing the command, must work with dma
47 * @len: length of the buffer
49 int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
52 struct wl1271_cmd_header *cmd;
53 unsigned long timeout;
60 cmd->id = cpu_to_le16(id);
63 WARN_ON(len % 4 != 0);
65 wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
67 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
69 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
71 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
72 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
73 if (time_after(jiffies, timeout)) {
74 wl1271_error("command complete timeout");
80 if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
85 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
88 /* read back the status code of the command */
90 res_len = sizeof(struct wl1271_cmd_header);
91 wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
93 status = le16_to_cpu(cmd->status);
94 if (status != CMD_STATUS_SUCCESS) {
95 wl1271_error("command execute failure %d", status);
99 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
100 WL1271_ACX_INTR_CMD_COMPLETE);
106 static int wl1271_cmd_cal_channel_tune(struct wl1271 *wl)
108 struct wl1271_cmd_cal_channel_tune *cmd;
111 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
115 cmd->test.id = TEST_CMD_CHANNEL_TUNE;
117 cmd->band = WL1271_CHANNEL_TUNE_BAND_2_4;
118 /* set up any channel, 7 is in the middle of the range */
121 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
123 wl1271_warning("TEST_CMD_CHANNEL_TUNE failed");
129 static int wl1271_cmd_cal_update_ref_point(struct wl1271 *wl)
131 struct wl1271_cmd_cal_update_ref_point *cmd;
134 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
138 cmd->test.id = TEST_CMD_UPDATE_PD_REFERENCE_POINT;
140 /* FIXME: still waiting for the correct values */
142 cmd->ref_detector = 0;
144 cmd->sub_band = WL1271_PD_REFERENCE_POINT_BAND_B_G;
146 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
148 wl1271_warning("TEST_CMD_UPDATE_PD_REFERENCE_POINT failed");
154 static int wl1271_cmd_cal_p2g(struct wl1271 *wl)
156 struct wl1271_cmd_cal_p2g *cmd;
159 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
163 cmd->test.id = TEST_CMD_P2G_CAL;
165 cmd->sub_band_mask = WL1271_CAL_P2G_BAND_B_G;
167 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
169 wl1271_warning("TEST_CMD_P2G_CAL failed");
175 static int wl1271_cmd_cal(struct wl1271 *wl)
178 * FIXME: we must make sure that we're not sleeping when calibration
183 wl1271_notice("performing tx calibration");
185 ret = wl1271_cmd_cal_channel_tune(wl);
189 ret = wl1271_cmd_cal_update_ref_point(wl);
193 ret = wl1271_cmd_cal_p2g(wl);
200 int wl1271_cmd_general_parms(struct wl1271 *wl)
202 struct wl1271_general_parms_cmd *gen_parms;
208 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
212 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
214 memcpy(gen_parms->params, wl->nvs->general_params,
215 WL1271_NVS_GENERAL_PARAMS_SIZE);
217 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
219 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
225 int wl1271_cmd_radio_parms(struct wl1271 *wl)
227 struct wl1271_radio_parms_cmd *radio_parms;
228 struct conf_radio_parms *rparam = &wl->conf.init.radioparam;
234 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
238 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
240 memcpy(radio_parms->stat_radio_params, wl->nvs->stat_radio_params,
241 WL1271_NVS_STAT_RADIO_PARAMS_SIZE);
242 memcpy(radio_parms->dyn_radio_params,
243 wl->nvs->dyn_radio_params[rparam->fem],
244 WL1271_NVS_DYN_RADIO_PARAMS_SIZE);
246 /* FIXME: current NVS is missing 5GHz parameters */
248 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
249 radio_parms, sizeof(*radio_parms));
251 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
253 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
260 * Poll the mailbox event field until any of the bits in the mask is set or a
261 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
263 static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
265 u32 events_vector, event;
266 unsigned long timeout;
268 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
271 if (time_after(jiffies, timeout))
276 /* read from both event fields */
277 wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
278 sizeof(events_vector), false);
279 event = events_vector & mask;
280 wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
281 sizeof(events_vector), false);
282 event |= events_vector & mask;
288 int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type)
290 static bool do_cal = true;
291 struct wl1271_cmd_join *join;
295 /* FIXME: remove when we get calibration from the factory */
297 ret = wl1271_cmd_cal(wl);
299 wl1271_warning("couldn't calibrate");
304 join = kzalloc(sizeof(*join), GFP_KERNEL);
310 wl1271_debug(DEBUG_CMD, "cmd join");
312 /* Reverse order BSSID */
313 bssid = (u8 *) &join->bssid_lsb;
314 for (i = 0; i < ETH_ALEN; i++)
315 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
317 join->rx_config_options = cpu_to_le32(wl->rx_config);
318 join->rx_filter_options = cpu_to_le32(wl->rx_filter);
319 join->bss_type = bss_type;
320 join->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
322 if (wl->band == IEEE80211_BAND_5GHZ)
323 join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
325 join->beacon_interval = cpu_to_le16(wl->beacon_int);
326 join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD;
328 join->channel = wl->channel;
329 join->ssid_len = wl->ssid_len;
330 memcpy(join->ssid, wl->ssid, wl->ssid_len);
331 join->ctrl = WL1271_JOIN_CMD_CTRL_TX_FLUSH;
333 /* increment the session counter */
334 wl->session_counter++;
335 if (wl->session_counter >= SESSION_COUNTER_MAX)
336 wl->session_counter = 0;
338 join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
340 /* reset TX security counters */
341 wl->tx_security_last_seq = 0;
342 wl->tx_security_seq = 0;
344 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
346 wl1271_error("failed to initiate cmd join");
350 ret = wl1271_cmd_wait_for_event(wl, JOIN_EVENT_COMPLETE_ID);
352 wl1271_error("cmd join event completion error");
362 * send test command to firmware
365 * @buf: buffer containing the command, with all headers, must work with dma
366 * @len: length of the buffer
367 * @answer: is answer needed
369 int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
374 wl1271_debug(DEBUG_CMD, "cmd test");
379 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
382 wl1271_warning("TEST command failed");
390 * read acx from firmware
394 * @buf: buffer for the response, including all headers, must work with dma
395 * @len: lenght of buf
397 int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
399 struct acx_header *acx = buf;
402 wl1271_debug(DEBUG_CMD, "cmd interrogate");
404 acx->id = cpu_to_le16(id);
406 /* payload length, does not include any headers */
407 acx->len = cpu_to_le16(len - sizeof(*acx));
409 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
411 wl1271_error("INTERROGATE command failed");
417 * write acx value to firmware
421 * @buf: buffer containing acx, including all headers, must work with dma
422 * @len: length of buf
424 int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
426 struct acx_header *acx = buf;
429 wl1271_debug(DEBUG_CMD, "cmd configure");
431 acx->id = cpu_to_le16(id);
433 /* payload length, does not include any headers */
434 acx->len = cpu_to_le16(len - sizeof(*acx));
436 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
438 wl1271_warning("CONFIGURE command NOK");
445 int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
447 struct cmd_enabledisable_path *cmd;
451 wl1271_debug(DEBUG_CMD, "cmd data path");
453 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
459 /* the channel here is only used for calibration, so hardcoded to 1 */
463 cmd_rx = CMD_ENABLE_RX;
464 cmd_tx = CMD_ENABLE_TX;
466 cmd_rx = CMD_DISABLE_RX;
467 cmd_tx = CMD_DISABLE_TX;
470 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
472 wl1271_error("rx %s cmd for channel %d failed",
473 enable ? "start" : "stop", cmd->channel);
477 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
478 enable ? "start" : "stop", cmd->channel);
480 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
482 wl1271_error("tx %s cmd for channel %d failed",
483 enable ? "start" : "stop", cmd->channel);
487 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
488 enable ? "start" : "stop", cmd->channel);
495 int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode, bool send)
497 struct wl1271_cmd_ps_params *ps_params = NULL;
500 /* FIXME: this should be in ps.c */
501 ret = wl1271_acx_wake_up_conditions(wl);
503 wl1271_error("couldn't set wake up conditions");
507 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
509 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
515 ps_params->ps_mode = ps_mode;
516 ps_params->send_null_data = send;
517 ps_params->retries = 5;
518 ps_params->hang_over_period = 128;
519 ps_params->null_data_rate = cpu_to_le32(1); /* 1 Mbps */
521 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
522 sizeof(*ps_params), 0);
524 wl1271_error("cmd set_ps_mode failed");
533 int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
536 struct cmd_read_write_memory *cmd;
539 wl1271_debug(DEBUG_CMD, "cmd read memory");
541 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
547 WARN_ON(len > MAX_READ_SIZE);
548 len = min_t(size_t, len, MAX_READ_SIZE);
550 cmd->addr = cpu_to_le32(addr);
551 cmd->size = cpu_to_le32(len);
553 ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd),
556 wl1271_error("read memory command failed: %d", ret);
560 /* the read command got in */
561 memcpy(answer, cmd->value, len);
568 int wl1271_cmd_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len,
569 const u8 *ie, size_t ie_len, u8 active_scan,
570 u8 high_prio, u8 band, u8 probe_requests)
573 struct wl1271_cmd_trigger_scan_to *trigger = NULL;
574 struct wl1271_cmd_scan *params = NULL;
575 struct ieee80211_channel *channels;
578 u16 scan_options = 0;
581 if (band == WL1271_SCAN_BAND_2_4_GHZ) {
582 ieee_band = IEEE80211_BAND_2GHZ;
583 rate = wl->conf.tx.basic_rate;
584 } else if (band == WL1271_SCAN_BAND_DUAL && wl1271_11a_enabled()) {
585 ieee_band = IEEE80211_BAND_2GHZ;
586 rate = wl->conf.tx.basic_rate;
587 } else if (band == WL1271_SCAN_BAND_5_GHZ && wl1271_11a_enabled()) {
588 ieee_band = IEEE80211_BAND_5GHZ;
589 rate = wl->conf.tx.basic_rate_5;
593 if (wl->hw->wiphy->bands[ieee_band]->channels == NULL)
596 channels = wl->hw->wiphy->bands[ieee_band]->channels;
597 n_ch = wl->hw->wiphy->bands[ieee_band]->n_channels;
599 if (test_bit(WL1271_FLAG_SCANNING, &wl->flags))
602 params = kzalloc(sizeof(*params), GFP_KERNEL);
606 params->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
607 params->params.rx_filter_options =
608 cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
611 scan_options |= WL1271_SCAN_OPT_PASSIVE;
613 scan_options |= WL1271_SCAN_OPT_PRIORITY_HIGH;
614 params->params.scan_options = cpu_to_le16(scan_options);
616 params->params.num_probe_requests = probe_requests;
617 params->params.tx_rate = cpu_to_le32(rate);
618 params->params.tid_trigger = 0;
619 params->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
621 if (band == WL1271_SCAN_BAND_DUAL)
622 params->params.band = WL1271_SCAN_BAND_2_4_GHZ;
624 params->params.band = band;
626 for (i = 0, j = 0; i < n_ch && i < WL1271_SCAN_MAX_CHANNELS; i++) {
627 if (!(channels[i].flags & IEEE80211_CHAN_DISABLED)) {
628 params->channels[j].min_duration =
629 cpu_to_le32(WL1271_SCAN_CHAN_MIN_DURATION);
630 params->channels[j].max_duration =
631 cpu_to_le32(WL1271_SCAN_CHAN_MAX_DURATION);
632 memset(¶ms->channels[j].bssid_lsb, 0xff, 4);
633 memset(¶ms->channels[j].bssid_msb, 0xff, 2);
634 params->channels[j].early_termination = 0;
635 params->channels[j].tx_power_att =
636 WL1271_SCAN_CURRENT_TX_PWR;
637 params->channels[j].channel = channels[i].hw_value;
642 params->params.num_channels = j;
644 if (ssid_len && ssid) {
645 params->params.ssid_len = ssid_len;
646 memcpy(params->params.ssid, ssid, ssid_len);
649 ret = wl1271_cmd_build_probe_req(wl, ssid, ssid_len,
650 ie, ie_len, ieee_band);
652 wl1271_error("PROBE request template failed");
656 trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
662 /* disable the timeout */
663 trigger->timeout = 0;
665 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
666 sizeof(*trigger), 0);
668 wl1271_error("trigger scan to failed for hw scan");
672 wl1271_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params));
674 set_bit(WL1271_FLAG_SCANNING, &wl->flags);
675 if (wl1271_11a_enabled()) {
676 wl->scan.state = band;
677 if (band == WL1271_SCAN_BAND_DUAL) {
678 wl->scan.active = active_scan;
679 wl->scan.high_prio = high_prio;
680 wl->scan.probe_requests = probe_requests;
681 if (ssid_len && ssid) {
682 wl->scan.ssid_len = ssid_len;
683 memcpy(wl->scan.ssid, ssid, ssid_len);
685 wl->scan.ssid_len = 0;
689 ret = wl1271_cmd_send(wl, CMD_SCAN, params, sizeof(*params), 0);
691 wl1271_error("SCAN failed");
692 clear_bit(WL1271_FLAG_SCANNING, &wl->flags);
702 int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
703 void *buf, size_t buf_len, int index, u32 rates)
705 struct wl1271_cmd_template_set *cmd;
708 wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
710 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
711 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
713 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
719 cmd->len = cpu_to_le16(buf_len);
720 cmd->template_type = template_id;
721 cmd->enabled_rates = cpu_to_le32(rates);
722 cmd->short_retry_limit = wl->conf.tx.rc_conf.short_retry_limit;
723 cmd->long_retry_limit = wl->conf.tx.rc_conf.long_retry_limit;
727 memcpy(cmd->template_data, buf, buf_len);
729 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
731 wl1271_warning("cmd set_template failed: %d", ret);
742 int wl1271_cmd_build_null_data(struct wl1271 *wl)
744 struct sk_buff *skb = NULL;
750 if (wl->bss_type == BSS_TYPE_IBSS) {
751 size = sizeof(struct wl12xx_null_data_template);
754 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
761 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
762 WL1271_RATE_AUTOMATIC);
767 wl1271_warning("cmd buld null data failed %d", ret);
773 int wl1271_cmd_build_klv_null_data(struct wl1271 *wl)
775 struct sk_buff *skb = NULL;
778 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
782 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
784 CMD_TEMPL_KLV_IDX_NULL_DATA,
785 WL1271_RATE_AUTOMATIC);
790 wl1271_warning("cmd build klv null data failed %d", ret);
796 int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
801 skb = ieee80211_pspoll_get(wl->hw, wl->vif);
805 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
806 skb->len, 0, wl->basic_rate);
813 int wl1271_cmd_build_probe_req(struct wl1271 *wl,
814 const u8 *ssid, size_t ssid_len,
815 const u8 *ie, size_t ie_len, u8 band)
820 skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
827 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
829 if (band == IEEE80211_BAND_2GHZ)
830 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
831 skb->data, skb->len, 0,
832 wl->conf.tx.basic_rate);
834 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
835 skb->data, skb->len, 0,
836 wl->conf.tx.basic_rate_5);
843 int wl1271_build_qos_null_data(struct wl1271 *wl)
845 struct ieee80211_qos_hdr template;
847 memset(&template, 0, sizeof(template));
849 memcpy(template.addr1, wl->bssid, ETH_ALEN);
850 memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
851 memcpy(template.addr3, wl->bssid, ETH_ALEN);
853 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
854 IEEE80211_STYPE_QOS_NULLFUNC |
855 IEEE80211_FCTL_TODS);
857 /* FIXME: not sure what priority to use here */
858 template.qos_ctrl = cpu_to_le16(0);
860 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
862 WL1271_RATE_AUTOMATIC);
865 int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id)
867 struct wl1271_cmd_set_keys *cmd;
870 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
872 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
879 cmd->key_action = cpu_to_le16(KEY_SET_ID);
880 cmd->key_type = KEY_WEP;
882 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
884 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
894 int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
895 u8 key_size, const u8 *key, const u8 *addr,
896 u32 tx_seq_32, u16 tx_seq_16)
898 struct wl1271_cmd_set_keys *cmd;
901 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
907 if (key_type != KEY_WEP)
908 memcpy(cmd->addr, addr, ETH_ALEN);
910 cmd->key_action = cpu_to_le16(action);
911 cmd->key_size = key_size;
912 cmd->key_type = key_type;
914 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
915 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
917 /* we have only one SSID profile */
918 cmd->ssid_profile = 0;
922 if (key_type == KEY_TKIP) {
924 * We get the key in the following form:
925 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
926 * but the target is expecting:
927 * TKIP - RX MIC - TX MIC
929 memcpy(cmd->key, key, 16);
930 memcpy(cmd->key + 16, key + 24, 8);
931 memcpy(cmd->key + 24, key + 16, 8);
934 memcpy(cmd->key, key, key_size);
937 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
939 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
941 wl1271_warning("could not set keys");
951 int wl1271_cmd_disconnect(struct wl1271 *wl)
953 struct wl1271_cmd_disconnect *cmd;
956 wl1271_debug(DEBUG_CMD, "cmd disconnect");
958 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
964 cmd->rx_config_options = cpu_to_le32(wl->rx_config);
965 cmd->rx_filter_options = cpu_to_le32(wl->rx_filter);
966 /* disconnect reason is not used in immediate disconnections */
967 cmd->type = DISCONNECT_IMMEDIATE;
969 ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
971 wl1271_error("failed to send disconnect command");
975 ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
977 wl1271_error("cmd disconnect event completion error");