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>
30 #include <linux/slab.h>
36 #include "wl12xx_80211.h"
41 #define WL1271_CMD_FAST_POLL_COUNT 50
44 * send command to firmware
48 * @buf: buffer containing the command, must work with dma
49 * @len: length of the buffer
51 int wl1271_cmd_send(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
,
54 struct wl1271_cmd_header
*cmd
;
55 unsigned long timeout
;
62 cmd
->id
= cpu_to_le16(id
);
65 WARN_ON(len
% 4 != 0);
67 wl1271_write(wl
, wl
->cmd_box_addr
, buf
, len
, false);
69 wl1271_write32(wl
, ACX_REG_INTERRUPT_TRIG
, INTR_TRIG_CMD
);
71 timeout
= jiffies
+ msecs_to_jiffies(WL1271_COMMAND_TIMEOUT
);
73 intr
= wl1271_read32(wl
, ACX_REG_INTERRUPT_NO_CLEAR
);
74 while (!(intr
& WL1271_ACX_INTR_CMD_COMPLETE
)) {
75 if (time_after(jiffies
, timeout
)) {
76 wl1271_error("command complete timeout");
82 if (poll_count
< WL1271_CMD_FAST_POLL_COUNT
)
87 intr
= wl1271_read32(wl
, ACX_REG_INTERRUPT_NO_CLEAR
);
90 /* read back the status code of the command */
92 res_len
= sizeof(struct wl1271_cmd_header
);
93 wl1271_read(wl
, wl
->cmd_box_addr
, cmd
, res_len
, false);
95 status
= le16_to_cpu(cmd
->status
);
96 if (status
!= CMD_STATUS_SUCCESS
) {
97 wl1271_error("command execute failure %d", status
);
98 ieee80211_queue_work(wl
->hw
, &wl
->recovery_work
);
102 wl1271_write32(wl
, ACX_REG_INTERRUPT_ACK
,
103 WL1271_ACX_INTR_CMD_COMPLETE
);
109 int wl1271_cmd_general_parms(struct wl1271
*wl
)
111 struct wl1271_general_parms_cmd
*gen_parms
;
112 struct wl1271_ini_general_params
*gp
= &wl
->nvs
->general_params
;
119 gen_parms
= kzalloc(sizeof(*gen_parms
), GFP_KERNEL
);
123 gen_parms
->test
.id
= TEST_CMD_INI_FILE_GENERAL_PARAM
;
125 memcpy(&gen_parms
->general_params
, gp
, sizeof(*gp
));
127 if (gp
->tx_bip_fem_auto_detect
)
130 ret
= wl1271_cmd_test(wl
, gen_parms
, sizeof(*gen_parms
), answer
);
132 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
136 gp
->tx_bip_fem_manufacturer
=
137 gen_parms
->general_params
.tx_bip_fem_manufacturer
;
139 wl1271_debug(DEBUG_CMD
, "FEM autodetect: %s, manufacturer: %d\n",
140 answer
? "auto" : "manual", gp
->tx_bip_fem_manufacturer
);
147 int wl1271_cmd_radio_parms(struct wl1271
*wl
)
149 struct wl1271_radio_parms_cmd
*radio_parms
;
150 struct wl1271_ini_general_params
*gp
= &wl
->nvs
->general_params
;
156 radio_parms
= kzalloc(sizeof(*radio_parms
), GFP_KERNEL
);
160 radio_parms
->test
.id
= TEST_CMD_INI_FILE_RADIO_PARAM
;
162 /* 2.4GHz parameters */
163 memcpy(&radio_parms
->static_params_2
, &wl
->nvs
->stat_radio_params_2
,
164 sizeof(struct wl1271_ini_band_params_2
));
165 memcpy(&radio_parms
->dyn_params_2
,
166 &wl
->nvs
->dyn_radio_params_2
[gp
->tx_bip_fem_manufacturer
].params
,
167 sizeof(struct wl1271_ini_fem_params_2
));
169 /* 5GHz parameters */
170 memcpy(&radio_parms
->static_params_5
,
171 &wl
->nvs
->stat_radio_params_5
,
172 sizeof(struct wl1271_ini_band_params_5
));
173 memcpy(&radio_parms
->dyn_params_5
,
174 &wl
->nvs
->dyn_radio_params_5
[gp
->tx_bip_fem_manufacturer
].params
,
175 sizeof(struct wl1271_ini_fem_params_5
));
177 wl1271_dump(DEBUG_CMD
, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
178 radio_parms
, sizeof(*radio_parms
));
180 ret
= wl1271_cmd_test(wl
, radio_parms
, sizeof(*radio_parms
), 0);
182 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
188 int wl1271_cmd_ext_radio_parms(struct wl1271
*wl
)
190 struct wl1271_ext_radio_parms_cmd
*ext_radio_parms
;
191 struct conf_rf_settings
*rf
= &wl
->conf
.rf
;
197 ext_radio_parms
= kzalloc(sizeof(*ext_radio_parms
), GFP_KERNEL
);
198 if (!ext_radio_parms
)
201 ext_radio_parms
->test
.id
= TEST_CMD_INI_FILE_RF_EXTENDED_PARAM
;
203 memcpy(ext_radio_parms
->tx_per_channel_power_compensation_2
,
204 rf
->tx_per_channel_power_compensation_2
,
205 CONF_TX_PWR_COMPENSATION_LEN_2
);
206 memcpy(ext_radio_parms
->tx_per_channel_power_compensation_5
,
207 rf
->tx_per_channel_power_compensation_5
,
208 CONF_TX_PWR_COMPENSATION_LEN_5
);
210 wl1271_dump(DEBUG_CMD
, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
211 ext_radio_parms
, sizeof(*ext_radio_parms
));
213 ret
= wl1271_cmd_test(wl
, ext_radio_parms
, sizeof(*ext_radio_parms
), 0);
215 wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
217 kfree(ext_radio_parms
);
222 * Poll the mailbox event field until any of the bits in the mask is set or a
223 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
225 static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271
*wl
, u32 mask
)
227 u32 events_vector
, event
;
228 unsigned long timeout
;
230 timeout
= jiffies
+ msecs_to_jiffies(WL1271_EVENT_TIMEOUT
);
233 if (time_after(jiffies
, timeout
)) {
234 wl1271_debug(DEBUG_CMD
, "timeout waiting for event %d",
241 /* read from both event fields */
242 wl1271_read(wl
, wl
->mbox_ptr
[0], &events_vector
,
243 sizeof(events_vector
), false);
244 event
= events_vector
& mask
;
245 wl1271_read(wl
, wl
->mbox_ptr
[1], &events_vector
,
246 sizeof(events_vector
), false);
247 event
|= events_vector
& mask
;
253 static int wl1271_cmd_wait_for_event(struct wl1271
*wl
, u32 mask
)
257 ret
= wl1271_cmd_wait_for_event_or_timeout(wl
, mask
);
259 ieee80211_queue_work(wl
->hw
, &wl
->recovery_work
);
266 int wl1271_cmd_join(struct wl1271
*wl
, u8 bss_type
)
268 struct wl1271_cmd_join
*join
;
272 join
= kzalloc(sizeof(*join
), GFP_KERNEL
);
278 wl1271_debug(DEBUG_CMD
, "cmd join");
280 /* Reverse order BSSID */
281 bssid
= (u8
*) &join
->bssid_lsb
;
282 for (i
= 0; i
< ETH_ALEN
; i
++)
283 bssid
[i
] = wl
->bssid
[ETH_ALEN
- i
- 1];
285 join
->rx_config_options
= cpu_to_le32(wl
->rx_config
);
286 join
->rx_filter_options
= cpu_to_le32(wl
->rx_filter
);
287 join
->bss_type
= bss_type
;
288 join
->basic_rate_set
= cpu_to_le32(wl
->basic_rate_set
);
289 join
->supported_rate_set
= cpu_to_le32(wl
->rate_set
);
291 if (wl
->band
== IEEE80211_BAND_5GHZ
)
292 join
->bss_type
|= WL1271_JOIN_CMD_BSS_TYPE_5GHZ
;
294 join
->beacon_interval
= cpu_to_le16(wl
->beacon_int
);
295 join
->dtim_interval
= WL1271_DEFAULT_DTIM_PERIOD
;
297 join
->channel
= wl
->channel
;
298 join
->ssid_len
= wl
->ssid_len
;
299 memcpy(join
->ssid
, wl
->ssid
, wl
->ssid_len
);
301 join
->ctrl
|= wl
->session_counter
<< WL1271_JOIN_CMD_TX_SESSION_OFFSET
;
303 /* reset TX security counters */
304 wl
->tx_security_last_seq
= 0;
305 wl
->tx_security_seq
= 0;
307 wl1271_debug(DEBUG_CMD
, "cmd join: basic_rate_set=0x%x, rate_set=0x%x",
308 join
->basic_rate_set
, join
->supported_rate_set
);
310 ret
= wl1271_cmd_send(wl
, CMD_START_JOIN
, join
, sizeof(*join
), 0);
312 wl1271_error("failed to initiate cmd join");
316 ret
= wl1271_cmd_wait_for_event(wl
, JOIN_EVENT_COMPLETE_ID
);
318 wl1271_error("cmd join event completion error");
328 * send test command to firmware
331 * @buf: buffer containing the command, with all headers, must work with dma
332 * @len: length of the buffer
333 * @answer: is answer needed
335 int wl1271_cmd_test(struct wl1271
*wl
, void *buf
, size_t buf_len
, u8 answer
)
340 wl1271_debug(DEBUG_CMD
, "cmd test");
345 ret
= wl1271_cmd_send(wl
, CMD_TEST
, buf
, buf_len
, res_len
);
348 wl1271_warning("TEST command failed");
356 * read acx from firmware
360 * @buf: buffer for the response, including all headers, must work with dma
361 * @len: lenght of buf
363 int wl1271_cmd_interrogate(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
365 struct acx_header
*acx
= buf
;
368 wl1271_debug(DEBUG_CMD
, "cmd interrogate");
370 acx
->id
= cpu_to_le16(id
);
372 /* payload length, does not include any headers */
373 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
375 ret
= wl1271_cmd_send(wl
, CMD_INTERROGATE
, acx
, sizeof(*acx
), len
);
377 wl1271_error("INTERROGATE command failed");
383 * write acx value to firmware
387 * @buf: buffer containing acx, including all headers, must work with dma
388 * @len: length of buf
390 int wl1271_cmd_configure(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
392 struct acx_header
*acx
= buf
;
395 wl1271_debug(DEBUG_CMD
, "cmd configure");
397 acx
->id
= cpu_to_le16(id
);
399 /* payload length, does not include any headers */
400 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
402 ret
= wl1271_cmd_send(wl
, CMD_CONFIGURE
, acx
, len
, 0);
404 wl1271_warning("CONFIGURE command NOK");
411 int wl1271_cmd_data_path(struct wl1271
*wl
, bool enable
)
413 struct cmd_enabledisable_path
*cmd
;
417 wl1271_debug(DEBUG_CMD
, "cmd data path");
419 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
425 /* the channel here is only used for calibration, so hardcoded to 1 */
429 cmd_rx
= CMD_ENABLE_RX
;
430 cmd_tx
= CMD_ENABLE_TX
;
432 cmd_rx
= CMD_DISABLE_RX
;
433 cmd_tx
= CMD_DISABLE_TX
;
436 ret
= wl1271_cmd_send(wl
, cmd_rx
, cmd
, sizeof(*cmd
), 0);
438 wl1271_error("rx %s cmd for channel %d failed",
439 enable
? "start" : "stop", cmd
->channel
);
443 wl1271_debug(DEBUG_BOOT
, "rx %s cmd channel %d",
444 enable
? "start" : "stop", cmd
->channel
);
446 ret
= wl1271_cmd_send(wl
, cmd_tx
, cmd
, sizeof(*cmd
), 0);
448 wl1271_error("tx %s cmd for channel %d failed",
449 enable
? "start" : "stop", cmd
->channel
);
453 wl1271_debug(DEBUG_BOOT
, "tx %s cmd channel %d",
454 enable
? "start" : "stop", cmd
->channel
);
461 int wl1271_cmd_ps_mode(struct wl1271
*wl
, u8 ps_mode
)
463 struct wl1271_cmd_ps_params
*ps_params
= NULL
;
466 wl1271_debug(DEBUG_CMD
, "cmd set ps mode");
468 ps_params
= kzalloc(sizeof(*ps_params
), GFP_KERNEL
);
474 ps_params
->ps_mode
= ps_mode
;
476 ret
= wl1271_cmd_send(wl
, CMD_SET_PS_MODE
, ps_params
,
477 sizeof(*ps_params
), 0);
479 wl1271_error("cmd set_ps_mode failed");
488 int wl1271_cmd_template_set(struct wl1271
*wl
, u16 template_id
,
489 void *buf
, size_t buf_len
, int index
, u32 rates
)
491 struct wl1271_cmd_template_set
*cmd
;
494 wl1271_debug(DEBUG_CMD
, "cmd template_set %d", template_id
);
496 WARN_ON(buf_len
> WL1271_CMD_TEMPL_MAX_SIZE
);
497 buf_len
= min_t(size_t, buf_len
, WL1271_CMD_TEMPL_MAX_SIZE
);
499 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
505 cmd
->len
= cpu_to_le16(buf_len
);
506 cmd
->template_type
= template_id
;
507 cmd
->enabled_rates
= cpu_to_le32(rates
);
508 cmd
->short_retry_limit
= wl
->conf
.tx
.tmpl_short_retry_limit
;
509 cmd
->long_retry_limit
= wl
->conf
.tx
.tmpl_long_retry_limit
;
513 memcpy(cmd
->template_data
, buf
, buf_len
);
515 ret
= wl1271_cmd_send(wl
, CMD_SET_TEMPLATE
, cmd
, sizeof(*cmd
), 0);
517 wl1271_warning("cmd set_template failed: %d", ret
);
528 int wl1271_cmd_build_null_data(struct wl1271
*wl
)
530 struct sk_buff
*skb
= NULL
;
536 if (wl
->bss_type
== BSS_TYPE_IBSS
) {
537 size
= sizeof(struct wl12xx_null_data_template
);
540 skb
= ieee80211_nullfunc_get(wl
->hw
, wl
->vif
);
547 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_NULL_DATA
, ptr
, size
, 0,
553 wl1271_warning("cmd buld null data failed %d", ret
);
559 int wl1271_cmd_build_klv_null_data(struct wl1271
*wl
)
561 struct sk_buff
*skb
= NULL
;
564 skb
= ieee80211_nullfunc_get(wl
->hw
, wl
->vif
);
568 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_KLV
,
570 CMD_TEMPL_KLV_IDX_NULL_DATA
,
576 wl1271_warning("cmd build klv null data failed %d", ret
);
582 int wl1271_cmd_build_ps_poll(struct wl1271
*wl
, u16 aid
)
587 skb
= ieee80211_pspoll_get(wl
->hw
, wl
->vif
);
591 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_PS_POLL
, skb
->data
,
592 skb
->len
, 0, wl
->basic_rate_set
);
599 int wl1271_cmd_build_probe_req(struct wl1271
*wl
,
600 const u8
*ssid
, size_t ssid_len
,
601 const u8
*ie
, size_t ie_len
, u8 band
)
606 skb
= ieee80211_probereq_get(wl
->hw
, wl
->vif
, ssid
, ssid_len
,
613 wl1271_dump(DEBUG_SCAN
, "PROBE REQ: ", skb
->data
, skb
->len
);
615 if (band
== IEEE80211_BAND_2GHZ
)
616 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_CFG_PROBE_REQ_2_4
,
617 skb
->data
, skb
->len
, 0,
618 wl
->conf
.tx
.basic_rate
);
620 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_CFG_PROBE_REQ_5
,
621 skb
->data
, skb
->len
, 0,
622 wl
->conf
.tx
.basic_rate_5
);
629 struct sk_buff
*wl1271_cmd_build_ap_probe_req(struct wl1271
*wl
,
635 skb
= ieee80211_ap_probereq_get(wl
->hw
, wl
->vif
);
639 wl1271_dump(DEBUG_SCAN
, "AP PROBE REQ: ", skb
->data
, skb
->len
);
641 if (wl
->band
== IEEE80211_BAND_2GHZ
)
642 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_CFG_PROBE_REQ_2_4
,
643 skb
->data
, skb
->len
, 0,
644 wl
->conf
.tx
.basic_rate
);
646 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_CFG_PROBE_REQ_5
,
647 skb
->data
, skb
->len
, 0,
648 wl
->conf
.tx
.basic_rate_5
);
651 wl1271_error("Unable to set ap probe request template.");
657 int wl1271_cmd_build_arp_rsp(struct wl1271
*wl
, __be32 ip_addr
)
660 struct wl12xx_arp_rsp_template tmpl
;
661 struct ieee80211_hdr_3addr
*hdr
;
662 struct arphdr
*arp_hdr
;
664 memset(&tmpl
, 0, sizeof(tmpl
));
666 /* mac80211 header */
668 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
669 IEEE80211_STYPE_DATA
|
670 IEEE80211_FCTL_TODS
);
671 memcpy(hdr
->addr1
, wl
->vif
->bss_conf
.bssid
, ETH_ALEN
);
672 memcpy(hdr
->addr2
, wl
->vif
->addr
, ETH_ALEN
);
673 memset(hdr
->addr3
, 0xff, ETH_ALEN
);
676 memcpy(tmpl
.llc_hdr
, rfc1042_header
, sizeof(rfc1042_header
));
677 tmpl
.llc_type
= cpu_to_be16(ETH_P_ARP
);
680 arp_hdr
= &tmpl
.arp_hdr
;
681 arp_hdr
->ar_hrd
= cpu_to_be16(ARPHRD_ETHER
);
682 arp_hdr
->ar_pro
= cpu_to_be16(ETH_P_IP
);
683 arp_hdr
->ar_hln
= ETH_ALEN
;
685 arp_hdr
->ar_op
= cpu_to_be16(ARPOP_REPLY
);
688 memcpy(tmpl
.sender_hw
, wl
->vif
->addr
, ETH_ALEN
);
689 tmpl
.sender_ip
= ip_addr
;
691 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_ARP_RSP
,
692 &tmpl
, sizeof(tmpl
), 0,
698 int wl1271_build_qos_null_data(struct wl1271
*wl
)
700 struct ieee80211_qos_hdr
template;
702 memset(&template, 0, sizeof(template));
704 memcpy(template.addr1
, wl
->bssid
, ETH_ALEN
);
705 memcpy(template.addr2
, wl
->mac_addr
, ETH_ALEN
);
706 memcpy(template.addr3
, wl
->bssid
, ETH_ALEN
);
708 template.frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
709 IEEE80211_STYPE_QOS_NULLFUNC
|
710 IEEE80211_FCTL_TODS
);
712 /* FIXME: not sure what priority to use here */
713 template.qos_ctrl
= cpu_to_le16(0);
715 return wl1271_cmd_template_set(wl
, CMD_TEMPL_QOS_NULL_DATA
, &template,
720 int wl1271_cmd_set_sta_default_wep_key(struct wl1271
*wl
, u8 id
)
722 struct wl1271_cmd_set_sta_keys
*cmd
;
725 wl1271_debug(DEBUG_CMD
, "cmd set_default_wep_key %d", id
);
727 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
734 cmd
->key_action
= cpu_to_le16(KEY_SET_ID
);
735 cmd
->key_type
= KEY_WEP
;
737 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
739 wl1271_warning("cmd set_default_wep_key failed: %d", ret
);
749 int wl1271_cmd_set_ap_default_wep_key(struct wl1271
*wl
, u8 id
)
751 struct wl1271_cmd_set_ap_keys
*cmd
;
754 wl1271_debug(DEBUG_CMD
, "cmd set_ap_default_wep_key %d", id
);
756 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
762 cmd
->hlid
= WL1271_AP_BROADCAST_HLID
;
764 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
765 cmd
->key_action
= cpu_to_le16(KEY_SET_ID
);
766 cmd
->key_type
= KEY_WEP
;
768 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
770 wl1271_warning("cmd set_ap_default_wep_key failed: %d", ret
);
780 int wl1271_cmd_set_sta_key(struct wl1271
*wl
, u16 action
, u8 id
, u8 key_type
,
781 u8 key_size
, const u8
*key
, const u8
*addr
,
782 u32 tx_seq_32
, u16 tx_seq_16
)
784 struct wl1271_cmd_set_sta_keys
*cmd
;
787 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
793 if (key_type
!= KEY_WEP
)
794 memcpy(cmd
->addr
, addr
, ETH_ALEN
);
796 cmd
->key_action
= cpu_to_le16(action
);
797 cmd
->key_size
= key_size
;
798 cmd
->key_type
= key_type
;
800 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
801 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
803 /* we have only one SSID profile */
804 cmd
->ssid_profile
= 0;
808 if (key_type
== KEY_TKIP
) {
810 * We get the key in the following form:
811 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
812 * but the target is expecting:
813 * TKIP - RX MIC - TX MIC
815 memcpy(cmd
->key
, key
, 16);
816 memcpy(cmd
->key
+ 16, key
+ 24, 8);
817 memcpy(cmd
->key
+ 24, key
+ 16, 8);
820 memcpy(cmd
->key
, key
, key_size
);
823 wl1271_dump(DEBUG_CRYPT
, "TARGET KEY: ", cmd
, sizeof(*cmd
));
825 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
827 wl1271_warning("could not set keys");
837 int wl1271_cmd_set_ap_key(struct wl1271
*wl
, u16 action
, u8 id
, u8 key_type
,
838 u8 key_size
, const u8
*key
, u8 hlid
, u32 tx_seq_32
,
841 struct wl1271_cmd_set_ap_keys
*cmd
;
845 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
849 if (hlid
== WL1271_AP_BROADCAST_HLID
) {
850 if (key_type
== KEY_WEP
)
851 lid_type
= WEP_DEFAULT_LID_TYPE
;
853 lid_type
= BROADCAST_LID_TYPE
;
855 lid_type
= UNICAST_LID_TYPE
;
858 wl1271_debug(DEBUG_CRYPT
, "ap key action: %d id: %d lid: %d type: %d"
859 " hlid: %d", (int)action
, (int)id
, (int)lid_type
,
860 (int)key_type
, (int)hlid
);
862 cmd
->lid_key_type
= lid_type
;
864 cmd
->key_action
= cpu_to_le16(action
);
865 cmd
->key_size
= key_size
;
866 cmd
->key_type
= key_type
;
868 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
869 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
871 if (key_type
== KEY_TKIP
) {
873 * We get the key in the following form:
874 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
875 * but the target is expecting:
876 * TKIP - RX MIC - TX MIC
878 memcpy(cmd
->key
, key
, 16);
879 memcpy(cmd
->key
+ 16, key
+ 24, 8);
880 memcpy(cmd
->key
+ 24, key
+ 16, 8);
882 memcpy(cmd
->key
, key
, key_size
);
885 wl1271_dump(DEBUG_CRYPT
, "TARGET AP KEY: ", cmd
, sizeof(*cmd
));
887 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
889 wl1271_warning("could not set ap keys");
898 int wl1271_cmd_disconnect(struct wl1271
*wl
)
900 struct wl1271_cmd_disconnect
*cmd
;
903 wl1271_debug(DEBUG_CMD
, "cmd disconnect");
905 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
911 cmd
->rx_config_options
= cpu_to_le32(wl
->rx_config
);
912 cmd
->rx_filter_options
= cpu_to_le32(wl
->rx_filter
);
913 /* disconnect reason is not used in immediate disconnections */
914 cmd
->type
= DISCONNECT_IMMEDIATE
;
916 ret
= wl1271_cmd_send(wl
, CMD_DISCONNECT
, cmd
, sizeof(*cmd
), 0);
918 wl1271_error("failed to send disconnect command");
922 ret
= wl1271_cmd_wait_for_event(wl
, DISCONNECT_EVENT_COMPLETE_ID
);
924 wl1271_error("cmd disconnect event completion error");
933 int wl1271_cmd_set_sta_state(struct wl1271
*wl
)
935 struct wl1271_cmd_set_sta_state
*cmd
;
938 wl1271_debug(DEBUG_CMD
, "cmd set sta state");
940 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
946 cmd
->state
= WL1271_CMD_STA_STATE_CONNECTED
;
948 ret
= wl1271_cmd_send(wl
, CMD_SET_STA_STATE
, cmd
, sizeof(*cmd
), 0);
950 wl1271_error("failed to send set STA state command");
961 int wl1271_cmd_start_bss(struct wl1271
*wl
)
963 struct wl1271_cmd_bss_start
*cmd
;
964 struct ieee80211_bss_conf
*bss_conf
= &wl
->vif
->bss_conf
;
967 wl1271_debug(DEBUG_CMD
, "cmd start bss");
970 * FIXME: We currently do not support hidden SSID. The real SSID
971 * should be fetched from mac80211 first.
973 if (wl
->ssid_len
== 0) {
974 wl1271_warning("Hidden SSID currently not supported for AP");
979 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
985 memcpy(cmd
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
987 cmd
->aging_period
= cpu_to_le16(WL1271_AP_DEF_INACTIV_SEC
);
988 cmd
->bss_index
= WL1271_AP_BSS_INDEX
;
989 cmd
->global_hlid
= WL1271_AP_GLOBAL_HLID
;
990 cmd
->broadcast_hlid
= WL1271_AP_BROADCAST_HLID
;
991 cmd
->basic_rate_set
= cpu_to_le32(wl
->basic_rate_set
);
992 cmd
->beacon_interval
= cpu_to_le16(wl
->beacon_int
);
993 cmd
->dtim_interval
= bss_conf
->dtim_period
;
994 cmd
->beacon_expiry
= WL1271_AP_DEF_BEACON_EXP
;
995 cmd
->channel
= wl
->channel
;
996 cmd
->ssid_len
= wl
->ssid_len
;
997 cmd
->ssid_type
= SSID_TYPE_PUBLIC
;
998 memcpy(cmd
->ssid
, wl
->ssid
, wl
->ssid_len
);
1001 case IEEE80211_BAND_2GHZ
:
1002 cmd
->band
= RADIO_BAND_2_4GHZ
;
1004 case IEEE80211_BAND_5GHZ
:
1005 cmd
->band
= RADIO_BAND_5GHZ
;
1008 wl1271_warning("bss start - unknown band: %d", (int)wl
->band
);
1009 cmd
->band
= RADIO_BAND_2_4GHZ
;
1013 ret
= wl1271_cmd_send(wl
, CMD_BSS_START
, cmd
, sizeof(*cmd
), 0);
1015 wl1271_error("failed to initiate cmd start bss");
1026 int wl1271_cmd_stop_bss(struct wl1271
*wl
)
1028 struct wl1271_cmd_bss_start
*cmd
;
1031 wl1271_debug(DEBUG_CMD
, "cmd stop bss");
1033 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1039 cmd
->bss_index
= WL1271_AP_BSS_INDEX
;
1041 ret
= wl1271_cmd_send(wl
, CMD_BSS_STOP
, cmd
, sizeof(*cmd
), 0);
1043 wl1271_error("failed to initiate cmd stop bss");
1054 int wl1271_cmd_add_sta(struct wl1271
*wl
, struct ieee80211_sta
*sta
, u8 hlid
)
1056 struct wl1271_cmd_add_sta
*cmd
;
1059 wl1271_debug(DEBUG_CMD
, "cmd add sta %d", (int)hlid
);
1061 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1067 /* currently we don't support UAPSD */
1070 memcpy(cmd
->addr
, sta
->addr
, ETH_ALEN
);
1071 cmd
->bss_index
= WL1271_AP_BSS_INDEX
;
1072 cmd
->aid
= sta
->aid
;
1076 * FIXME: Does STA support QOS? We need to propagate this info from
1077 * hostapd. Currently not that important since this is only used for
1078 * sending the correct flavor of null-data packet in response to a
1083 cmd
->supported_rates
= cpu_to_le32(wl1271_tx_enabled_rates_get(wl
,
1084 sta
->supp_rates
[wl
->band
]));
1086 wl1271_debug(DEBUG_CMD
, "new sta rates: 0x%x", cmd
->supported_rates
);
1088 ret
= wl1271_cmd_send(wl
, CMD_ADD_STA
, cmd
, sizeof(*cmd
), 0);
1090 wl1271_error("failed to initiate cmd add sta");
1101 int wl1271_cmd_remove_sta(struct wl1271
*wl
, u8 hlid
)
1103 struct wl1271_cmd_remove_sta
*cmd
;
1106 wl1271_debug(DEBUG_CMD
, "cmd remove sta %d", (int)hlid
);
1108 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1115 /* We never send a deauth, mac80211 is in charge of this */
1116 cmd
->reason_opcode
= 0;
1117 cmd
->send_deauth_flag
= 0;
1119 ret
= wl1271_cmd_send(wl
, CMD_REMOVE_STA
, cmd
, sizeof(*cmd
), 0);
1121 wl1271_error("failed to initiate cmd remove sta");
1126 * We are ok with a timeout here. The event is sometimes not sent
1127 * due to a firmware bug.
1129 wl1271_cmd_wait_for_event_or_timeout(wl
, STA_REMOVE_COMPLETE_EVENT_ID
);