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/spi/spi.h>
27 #include <linux/etherdevice.h>
28 #include <linux/ieee80211.h>
29 #include <linux/slab.h>
35 #include "wl12xx_80211.h"
40 #define WL1271_CMD_FAST_POLL_COUNT 50
43 * send command to firmware
47 * @buf: buffer containing the command, must work with dma
48 * @len: length of the buffer
50 int wl1271_cmd_send(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
,
53 struct wl1271_cmd_header
*cmd
;
54 unsigned long timeout
;
61 cmd
->id
= cpu_to_le16(id
);
64 WARN_ON(len
% 4 != 0);
65 WARN_ON(test_bit(WL1271_FLAG_IN_ELP
, &wl
->flags
));
67 wl1271_write(wl
, wl
->cmd_box_addr
, buf
, len
, false);
70 * TODO: we just need this because one bit is in a different
71 * place. Is there any better way?
73 wl
->ops
->trigger_cmd(wl
);
75 timeout
= jiffies
+ msecs_to_jiffies(WL1271_COMMAND_TIMEOUT
);
77 intr
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
);
78 while (!(intr
& WL1271_ACX_INTR_CMD_COMPLETE
)) {
79 if (time_after(jiffies
, timeout
)) {
80 wl1271_error("command complete timeout");
86 if (poll_count
< WL1271_CMD_FAST_POLL_COUNT
)
91 intr
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
);
94 /* read back the status code of the command */
96 res_len
= sizeof(struct wl1271_cmd_header
);
97 wl1271_read(wl
, wl
->cmd_box_addr
, cmd
, res_len
, false);
99 status
= le16_to_cpu(cmd
->status
);
100 if (status
!= CMD_STATUS_SUCCESS
) {
101 wl1271_error("command execute failure %d", status
);
106 wlcore_write_reg(wl
, REG_INTERRUPT_ACK
, WL1271_ACX_INTR_CMD_COMPLETE
);
111 wl12xx_queue_recovery_work(wl
);
115 int wl1271_cmd_general_parms(struct wl1271
*wl
)
117 struct wl1271_general_parms_cmd
*gen_parms
;
118 struct wl1271_ini_general_params
*gp
=
119 &((struct wl1271_nvs_file
*)wl
->nvs
)->general_params
;
126 if (gp
->tx_bip_fem_manufacturer
>= WL1271_INI_FEM_MODULE_COUNT
) {
127 wl1271_warning("FEM index from INI out of bounds");
131 gen_parms
= kzalloc(sizeof(*gen_parms
), GFP_KERNEL
);
135 gen_parms
->test
.id
= TEST_CMD_INI_FILE_GENERAL_PARAM
;
137 memcpy(&gen_parms
->general_params
, gp
, sizeof(*gp
));
139 if (gp
->tx_bip_fem_auto_detect
)
142 /* Override the REF CLK from the NVS with the one from platform data */
143 gen_parms
->general_params
.ref_clock
= wl
->ref_clock
;
145 ret
= wl1271_cmd_test(wl
, gen_parms
, sizeof(*gen_parms
), answer
);
147 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
151 gp
->tx_bip_fem_manufacturer
=
152 gen_parms
->general_params
.tx_bip_fem_manufacturer
;
154 if (gp
->tx_bip_fem_manufacturer
>= WL1271_INI_FEM_MODULE_COUNT
) {
155 wl1271_warning("FEM index from FW out of bounds");
160 wl1271_debug(DEBUG_CMD
, "FEM autodetect: %s, manufacturer: %d\n",
161 answer
? "auto" : "manual", gp
->tx_bip_fem_manufacturer
);
168 int wl128x_cmd_general_parms(struct wl1271
*wl
)
170 struct wl128x_general_parms_cmd
*gen_parms
;
171 struct wl128x_ini_general_params
*gp
=
172 &((struct wl128x_nvs_file
*)wl
->nvs
)->general_params
;
179 if (gp
->tx_bip_fem_manufacturer
>= WL1271_INI_FEM_MODULE_COUNT
) {
180 wl1271_warning("FEM index from ini out of bounds");
184 gen_parms
= kzalloc(sizeof(*gen_parms
), GFP_KERNEL
);
188 gen_parms
->test
.id
= TEST_CMD_INI_FILE_GENERAL_PARAM
;
190 memcpy(&gen_parms
->general_params
, gp
, sizeof(*gp
));
192 if (gp
->tx_bip_fem_auto_detect
)
195 /* Replace REF and TCXO CLKs with the ones from platform data */
196 gen_parms
->general_params
.ref_clock
= wl
->ref_clock
;
197 gen_parms
->general_params
.tcxo_ref_clock
= wl
->tcxo_clock
;
199 ret
= wl1271_cmd_test(wl
, gen_parms
, sizeof(*gen_parms
), answer
);
201 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
205 gp
->tx_bip_fem_manufacturer
=
206 gen_parms
->general_params
.tx_bip_fem_manufacturer
;
208 if (gp
->tx_bip_fem_manufacturer
>= WL1271_INI_FEM_MODULE_COUNT
) {
209 wl1271_warning("FEM index from FW out of bounds");
214 wl1271_debug(DEBUG_CMD
, "FEM autodetect: %s, manufacturer: %d\n",
215 answer
? "auto" : "manual", gp
->tx_bip_fem_manufacturer
);
222 int wl1271_cmd_radio_parms(struct wl1271
*wl
)
224 struct wl1271_nvs_file
*nvs
= (struct wl1271_nvs_file
*)wl
->nvs
;
225 struct wl1271_radio_parms_cmd
*radio_parms
;
226 struct wl1271_ini_general_params
*gp
= &nvs
->general_params
;
232 radio_parms
= kzalloc(sizeof(*radio_parms
), GFP_KERNEL
);
236 radio_parms
->test
.id
= TEST_CMD_INI_FILE_RADIO_PARAM
;
238 /* 2.4GHz parameters */
239 memcpy(&radio_parms
->static_params_2
, &nvs
->stat_radio_params_2
,
240 sizeof(struct wl1271_ini_band_params_2
));
241 memcpy(&radio_parms
->dyn_params_2
,
242 &nvs
->dyn_radio_params_2
[gp
->tx_bip_fem_manufacturer
].params
,
243 sizeof(struct wl1271_ini_fem_params_2
));
245 /* 5GHz parameters */
246 memcpy(&radio_parms
->static_params_5
,
247 &nvs
->stat_radio_params_5
,
248 sizeof(struct wl1271_ini_band_params_5
));
249 memcpy(&radio_parms
->dyn_params_5
,
250 &nvs
->dyn_radio_params_5
[gp
->tx_bip_fem_manufacturer
].params
,
251 sizeof(struct wl1271_ini_fem_params_5
));
253 wl1271_dump(DEBUG_CMD
, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
254 radio_parms
, sizeof(*radio_parms
));
256 ret
= wl1271_cmd_test(wl
, radio_parms
, sizeof(*radio_parms
), 0);
258 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
264 int wl128x_cmd_radio_parms(struct wl1271
*wl
)
266 struct wl128x_nvs_file
*nvs
= (struct wl128x_nvs_file
*)wl
->nvs
;
267 struct wl128x_radio_parms_cmd
*radio_parms
;
268 struct wl128x_ini_general_params
*gp
= &nvs
->general_params
;
274 radio_parms
= kzalloc(sizeof(*radio_parms
), GFP_KERNEL
);
278 radio_parms
->test
.id
= TEST_CMD_INI_FILE_RADIO_PARAM
;
280 /* 2.4GHz parameters */
281 memcpy(&radio_parms
->static_params_2
, &nvs
->stat_radio_params_2
,
282 sizeof(struct wl128x_ini_band_params_2
));
283 memcpy(&radio_parms
->dyn_params_2
,
284 &nvs
->dyn_radio_params_2
[gp
->tx_bip_fem_manufacturer
].params
,
285 sizeof(struct wl128x_ini_fem_params_2
));
287 /* 5GHz parameters */
288 memcpy(&radio_parms
->static_params_5
,
289 &nvs
->stat_radio_params_5
,
290 sizeof(struct wl128x_ini_band_params_5
));
291 memcpy(&radio_parms
->dyn_params_5
,
292 &nvs
->dyn_radio_params_5
[gp
->tx_bip_fem_manufacturer
].params
,
293 sizeof(struct wl128x_ini_fem_params_5
));
295 radio_parms
->fem_vendor_and_options
= nvs
->fem_vendor_and_options
;
297 wl1271_dump(DEBUG_CMD
, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
298 radio_parms
, sizeof(*radio_parms
));
300 ret
= wl1271_cmd_test(wl
, radio_parms
, sizeof(*radio_parms
), 0);
302 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
308 int wl1271_cmd_ext_radio_parms(struct wl1271
*wl
)
310 struct wl1271_ext_radio_parms_cmd
*ext_radio_parms
;
311 struct conf_rf_settings
*rf
= &wl
->conf
.rf
;
317 ext_radio_parms
= kzalloc(sizeof(*ext_radio_parms
), GFP_KERNEL
);
318 if (!ext_radio_parms
)
321 ext_radio_parms
->test
.id
= TEST_CMD_INI_FILE_RF_EXTENDED_PARAM
;
323 memcpy(ext_radio_parms
->tx_per_channel_power_compensation_2
,
324 rf
->tx_per_channel_power_compensation_2
,
325 CONF_TX_PWR_COMPENSATION_LEN_2
);
326 memcpy(ext_radio_parms
->tx_per_channel_power_compensation_5
,
327 rf
->tx_per_channel_power_compensation_5
,
328 CONF_TX_PWR_COMPENSATION_LEN_5
);
330 wl1271_dump(DEBUG_CMD
, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
331 ext_radio_parms
, sizeof(*ext_radio_parms
));
333 ret
= wl1271_cmd_test(wl
, ext_radio_parms
, sizeof(*ext_radio_parms
), 0);
335 wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
337 kfree(ext_radio_parms
);
342 * Poll the mailbox event field until any of the bits in the mask is set or a
343 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
345 static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271
*wl
, u32 mask
)
349 unsigned long timeout
;
352 events_vector
= kmalloc(sizeof(*events_vector
), GFP_DMA
);
354 timeout
= jiffies
+ msecs_to_jiffies(WL1271_EVENT_TIMEOUT
);
357 if (time_after(jiffies
, timeout
)) {
358 wl1271_debug(DEBUG_CMD
, "timeout waiting for event %d",
366 /* read from both event fields */
367 wl1271_read(wl
, wl
->mbox_ptr
[0], events_vector
,
368 sizeof(*events_vector
), false);
369 event
= *events_vector
& mask
;
370 wl1271_read(wl
, wl
->mbox_ptr
[1], events_vector
,
371 sizeof(*events_vector
), false);
372 event
|= *events_vector
& mask
;
376 kfree(events_vector
);
380 static int wl1271_cmd_wait_for_event(struct wl1271
*wl
, u32 mask
)
384 ret
= wl1271_cmd_wait_for_event_or_timeout(wl
, mask
);
386 wl12xx_queue_recovery_work(wl
);
393 int wl12xx_cmd_role_enable(struct wl1271
*wl
, u8
*addr
, u8 role_type
,
396 struct wl12xx_cmd_role_enable
*cmd
;
399 wl1271_debug(DEBUG_CMD
, "cmd role enable");
401 if (WARN_ON(*role_id
!= WL12XX_INVALID_ROLE_ID
))
404 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
411 cmd
->role_id
= find_first_zero_bit(wl
->roles_map
, WL12XX_MAX_ROLES
);
412 if (cmd
->role_id
>= WL12XX_MAX_ROLES
) {
417 memcpy(cmd
->mac_address
, addr
, ETH_ALEN
);
418 cmd
->role_type
= role_type
;
420 ret
= wl1271_cmd_send(wl
, CMD_ROLE_ENABLE
, cmd
, sizeof(*cmd
), 0);
422 wl1271_error("failed to initiate cmd role enable");
426 __set_bit(cmd
->role_id
, wl
->roles_map
);
427 *role_id
= cmd
->role_id
;
436 int wl12xx_cmd_role_disable(struct wl1271
*wl
, u8
*role_id
)
438 struct wl12xx_cmd_role_disable
*cmd
;
441 wl1271_debug(DEBUG_CMD
, "cmd role disable");
443 if (WARN_ON(*role_id
== WL12XX_INVALID_ROLE_ID
))
446 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
451 cmd
->role_id
= *role_id
;
453 ret
= wl1271_cmd_send(wl
, CMD_ROLE_DISABLE
, cmd
, sizeof(*cmd
), 0);
455 wl1271_error("failed to initiate cmd role disable");
459 __clear_bit(*role_id
, wl
->roles_map
);
460 *role_id
= WL12XX_INVALID_ROLE_ID
;
469 int wl12xx_allocate_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
472 u8 link
= find_first_zero_bit(wl
->links_map
, WL12XX_MAX_LINKS
);
473 if (link
>= WL12XX_MAX_LINKS
)
476 /* these bits are used by op_tx */
477 spin_lock_irqsave(&wl
->wl_lock
, flags
);
478 __set_bit(link
, wl
->links_map
);
479 __set_bit(link
, wlvif
->links_map
);
480 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
485 void wl12xx_free_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
489 if (*hlid
== WL12XX_INVALID_LINK_ID
)
492 /* these bits are used by op_tx */
493 spin_lock_irqsave(&wl
->wl_lock
, flags
);
494 __clear_bit(*hlid
, wl
->links_map
);
495 __clear_bit(*hlid
, wlvif
->links_map
);
496 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
499 * At this point op_tx() will not add more packets to the queues. We
502 wl1271_tx_reset_link_queues(wl
, *hlid
);
504 *hlid
= WL12XX_INVALID_LINK_ID
;
507 static int wl12xx_get_new_session_id(struct wl1271
*wl
,
508 struct wl12xx_vif
*wlvif
)
510 if (wlvif
->session_counter
>= SESSION_COUNTER_MAX
)
511 wlvif
->session_counter
= 0;
513 wlvif
->session_counter
++;
515 return wlvif
->session_counter
;
518 static int wl12xx_cmd_role_start_dev(struct wl1271
*wl
,
519 struct wl12xx_vif
*wlvif
)
521 struct wl12xx_cmd_role_start
*cmd
;
524 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
530 wl1271_debug(DEBUG_CMD
, "cmd role start dev %d", wlvif
->dev_role_id
);
532 cmd
->role_id
= wlvif
->dev_role_id
;
533 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
534 cmd
->band
= WLCORE_BAND_5GHZ
;
535 cmd
->channel
= wlvif
->channel
;
537 if (wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
) {
538 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->dev_hlid
);
542 cmd
->device
.hlid
= wlvif
->dev_hlid
;
543 cmd
->device
.session
= wl12xx_get_new_session_id(wl
, wlvif
);
545 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d",
546 cmd
->role_id
, cmd
->device
.hlid
, cmd
->device
.session
);
548 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
550 wl1271_error("failed to initiate cmd role enable");
557 /* clear links on error */
558 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
567 static int wl12xx_cmd_role_stop_dev(struct wl1271
*wl
,
568 struct wl12xx_vif
*wlvif
)
570 struct wl12xx_cmd_role_stop
*cmd
;
573 if (WARN_ON(wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
))
576 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
582 wl1271_debug(DEBUG_CMD
, "cmd role stop dev");
584 cmd
->role_id
= wlvif
->dev_role_id
;
585 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
586 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
588 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
590 wl1271_error("failed to initiate cmd role stop");
594 ret
= wl1271_cmd_wait_for_event(wl
, ROLE_STOP_COMPLETE_EVENT_ID
);
596 wl1271_error("cmd role stop dev event completion error");
600 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
609 int wl12xx_cmd_role_start_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
611 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
612 struct wl12xx_cmd_role_start
*cmd
;
615 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
621 wl1271_debug(DEBUG_CMD
, "cmd role start sta %d", wlvif
->role_id
);
623 cmd
->role_id
= wlvif
->role_id
;
624 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
625 cmd
->band
= WLCORE_BAND_5GHZ
;
626 cmd
->channel
= wlvif
->channel
;
627 cmd
->sta
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
628 cmd
->sta
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
629 cmd
->sta
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
630 cmd
->sta
.ssid_len
= wlvif
->ssid_len
;
631 memcpy(cmd
->sta
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
632 memcpy(cmd
->sta
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
633 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
635 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
636 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
640 cmd
->sta
.hlid
= wlvif
->sta
.hlid
;
641 cmd
->sta
.session
= wl12xx_get_new_session_id(wl
, wlvif
);
642 cmd
->sta
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
644 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
645 "basic_rate_set: 0x%x, remote_rates: 0x%x",
646 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
647 wlvif
->basic_rate_set
, wlvif
->rate_set
);
649 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
651 wl1271_error("failed to initiate cmd role start sta");
658 /* clear links on error. */
659 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
668 /* use this function to stop ibss as well */
669 int wl12xx_cmd_role_stop_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
671 struct wl12xx_cmd_role_stop
*cmd
;
674 if (WARN_ON(wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
))
677 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
683 wl1271_debug(DEBUG_CMD
, "cmd role stop sta %d", wlvif
->role_id
);
685 cmd
->role_id
= wlvif
->role_id
;
686 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
687 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
689 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
691 wl1271_error("failed to initiate cmd role stop sta");
695 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
704 int wl12xx_cmd_role_start_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
706 struct wl12xx_cmd_role_start
*cmd
;
707 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
708 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
711 wl1271_debug(DEBUG_CMD
, "cmd role start ap %d", wlvif
->role_id
);
713 /* trying to use hidden SSID with an old hostapd version */
714 if (wlvif
->ssid_len
== 0 && !bss_conf
->hidden_ssid
) {
715 wl1271_error("got a null SSID from beacon/bss");
720 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
726 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
730 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
732 goto out_free_global
;
734 cmd
->role_id
= wlvif
->role_id
;
735 cmd
->ap
.aging_period
= cpu_to_le16(wl
->conf
.tx
.ap_aging_period
);
736 cmd
->ap
.bss_index
= WL1271_AP_BSS_INDEX
;
737 cmd
->ap
.global_hlid
= wlvif
->ap
.global_hlid
;
738 cmd
->ap
.broadcast_hlid
= wlvif
->ap
.bcast_hlid
;
739 cmd
->ap
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
740 cmd
->ap
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
741 cmd
->ap
.dtim_interval
= bss_conf
->dtim_period
;
742 cmd
->ap
.beacon_expiry
= WL1271_AP_DEF_BEACON_EXP
;
743 /* FIXME: Change when adding DFS */
744 cmd
->ap
.reset_tsf
= 1; /* By default reset AP TSF */
745 cmd
->channel
= wlvif
->channel
;
747 if (!bss_conf
->hidden_ssid
) {
748 /* take the SSID from the beacon for backward compatibility */
749 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_PUBLIC
;
750 cmd
->ap
.ssid_len
= wlvif
->ssid_len
;
751 memcpy(cmd
->ap
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
753 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_HIDDEN
;
754 cmd
->ap
.ssid_len
= bss_conf
->ssid_len
;
755 memcpy(cmd
->ap
.ssid
, bss_conf
->ssid
, bss_conf
->ssid_len
);
758 cmd
->ap
.local_rates
= cpu_to_le32(0xffffffff);
760 switch (wlvif
->band
) {
761 case IEEE80211_BAND_2GHZ
:
762 cmd
->band
= WLCORE_BAND_2_4GHZ
;
764 case IEEE80211_BAND_5GHZ
:
765 cmd
->band
= WLCORE_BAND_5GHZ
;
768 wl1271_warning("ap start - unknown band: %d", (int)wlvif
->band
);
769 cmd
->band
= WLCORE_BAND_2_4GHZ
;
773 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
775 wl1271_error("failed to initiate cmd role start ap");
782 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
785 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
794 int wl12xx_cmd_role_stop_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
796 struct wl12xx_cmd_role_stop
*cmd
;
799 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
805 wl1271_debug(DEBUG_CMD
, "cmd role stop ap %d", wlvif
->role_id
);
807 cmd
->role_id
= wlvif
->role_id
;
809 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
811 wl1271_error("failed to initiate cmd role stop ap");
815 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
816 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
825 int wl12xx_cmd_role_start_ibss(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
827 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
828 struct wl12xx_cmd_role_start
*cmd
;
829 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
832 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
838 wl1271_debug(DEBUG_CMD
, "cmd role start ibss %d", wlvif
->role_id
);
840 cmd
->role_id
= wlvif
->role_id
;
841 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
842 cmd
->band
= WLCORE_BAND_5GHZ
;
843 cmd
->channel
= wlvif
->channel
;
844 cmd
->ibss
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
845 cmd
->ibss
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
846 cmd
->ibss
.dtim_interval
= bss_conf
->dtim_period
;
847 cmd
->ibss
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
848 cmd
->ibss
.ssid_len
= wlvif
->ssid_len
;
849 memcpy(cmd
->ibss
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
850 memcpy(cmd
->ibss
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
851 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
853 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
854 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
858 cmd
->ibss
.hlid
= wlvif
->sta
.hlid
;
859 cmd
->ibss
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
861 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
862 "basic_rate_set: 0x%x, remote_rates: 0x%x",
863 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
864 wlvif
->basic_rate_set
, wlvif
->rate_set
);
866 wl1271_debug(DEBUG_CMD
, "vif->bss_conf.bssid = %pM",
867 vif
->bss_conf
.bssid
);
869 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
871 wl1271_error("failed to initiate cmd role enable");
878 /* clear links on error. */
879 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
890 * send test command to firmware
893 * @buf: buffer containing the command, with all headers, must work with dma
894 * @len: length of the buffer
895 * @answer: is answer needed
897 int wl1271_cmd_test(struct wl1271
*wl
, void *buf
, size_t buf_len
, u8 answer
)
902 wl1271_debug(DEBUG_CMD
, "cmd test");
907 ret
= wl1271_cmd_send(wl
, CMD_TEST
, buf
, buf_len
, res_len
);
910 wl1271_warning("TEST command failed");
918 * read acx from firmware
922 * @buf: buffer for the response, including all headers, must work with dma
923 * @len: length of buf
925 int wl1271_cmd_interrogate(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
927 struct acx_header
*acx
= buf
;
930 wl1271_debug(DEBUG_CMD
, "cmd interrogate");
932 acx
->id
= cpu_to_le16(id
);
934 /* payload length, does not include any headers */
935 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
937 ret
= wl1271_cmd_send(wl
, CMD_INTERROGATE
, acx
, sizeof(*acx
), len
);
939 wl1271_error("INTERROGATE command failed");
945 * write acx value to firmware
949 * @buf: buffer containing acx, including all headers, must work with dma
950 * @len: length of buf
952 int wl1271_cmd_configure(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
954 struct acx_header
*acx
= buf
;
957 wl1271_debug(DEBUG_CMD
, "cmd configure (%d)", id
);
959 acx
->id
= cpu_to_le16(id
);
961 /* payload length, does not include any headers */
962 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
964 ret
= wl1271_cmd_send(wl
, CMD_CONFIGURE
, acx
, len
, 0);
966 wl1271_warning("CONFIGURE command NOK");
973 int wl1271_cmd_data_path(struct wl1271
*wl
, bool enable
)
975 struct cmd_enabledisable_path
*cmd
;
979 wl1271_debug(DEBUG_CMD
, "cmd data path");
981 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
987 /* the channel here is only used for calibration, so hardcoded to 1 */
991 cmd_rx
= CMD_ENABLE_RX
;
992 cmd_tx
= CMD_ENABLE_TX
;
994 cmd_rx
= CMD_DISABLE_RX
;
995 cmd_tx
= CMD_DISABLE_TX
;
998 ret
= wl1271_cmd_send(wl
, cmd_rx
, cmd
, sizeof(*cmd
), 0);
1000 wl1271_error("rx %s cmd for channel %d failed",
1001 enable
? "start" : "stop", cmd
->channel
);
1005 wl1271_debug(DEBUG_BOOT
, "rx %s cmd channel %d",
1006 enable
? "start" : "stop", cmd
->channel
);
1008 ret
= wl1271_cmd_send(wl
, cmd_tx
, cmd
, sizeof(*cmd
), 0);
1010 wl1271_error("tx %s cmd for channel %d failed",
1011 enable
? "start" : "stop", cmd
->channel
);
1015 wl1271_debug(DEBUG_BOOT
, "tx %s cmd channel %d",
1016 enable
? "start" : "stop", cmd
->channel
);
1023 int wl1271_cmd_ps_mode(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1024 u8 ps_mode
, u16 auto_ps_timeout
)
1026 struct wl1271_cmd_ps_params
*ps_params
= NULL
;
1029 wl1271_debug(DEBUG_CMD
, "cmd set ps mode");
1031 ps_params
= kzalloc(sizeof(*ps_params
), GFP_KERNEL
);
1037 ps_params
->role_id
= wlvif
->role_id
;
1038 ps_params
->ps_mode
= ps_mode
;
1039 ps_params
->auto_ps_timeout
= auto_ps_timeout
;
1041 ret
= wl1271_cmd_send(wl
, CMD_SET_PS_MODE
, ps_params
,
1042 sizeof(*ps_params
), 0);
1044 wl1271_error("cmd set_ps_mode failed");
1053 int wl1271_cmd_template_set(struct wl1271
*wl
, u8 role_id
,
1054 u16 template_id
, void *buf
, size_t buf_len
,
1055 int index
, u32 rates
)
1057 struct wl1271_cmd_template_set
*cmd
;
1060 wl1271_debug(DEBUG_CMD
, "cmd template_set %d (role %d)",
1061 template_id
, role_id
);
1063 WARN_ON(buf_len
> WL1271_CMD_TEMPL_MAX_SIZE
);
1064 buf_len
= min_t(size_t, buf_len
, WL1271_CMD_TEMPL_MAX_SIZE
);
1066 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1072 /* during initialization wlvif is NULL */
1073 cmd
->role_id
= role_id
;
1074 cmd
->len
= cpu_to_le16(buf_len
);
1075 cmd
->template_type
= template_id
;
1076 cmd
->enabled_rates
= cpu_to_le32(rates
);
1077 cmd
->short_retry_limit
= wl
->conf
.tx
.tmpl_short_retry_limit
;
1078 cmd
->long_retry_limit
= wl
->conf
.tx
.tmpl_long_retry_limit
;
1082 memcpy(cmd
->template_data
, buf
, buf_len
);
1084 ret
= wl1271_cmd_send(wl
, CMD_SET_TEMPLATE
, cmd
, sizeof(*cmd
), 0);
1086 wl1271_warning("cmd set_template failed: %d", ret
);
1097 int wl12xx_cmd_build_null_data(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1099 struct sk_buff
*skb
= NULL
;
1105 if (wlvif
->bss_type
== BSS_TYPE_IBSS
) {
1106 size
= sizeof(struct wl12xx_null_data_template
);
1109 skb
= ieee80211_nullfunc_get(wl
->hw
,
1110 wl12xx_wlvif_to_vif(wlvif
));
1117 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1118 CMD_TEMPL_NULL_DATA
, ptr
, size
, 0,
1124 wl1271_warning("cmd buld null data failed %d", ret
);
1130 int wl12xx_cmd_build_klv_null_data(struct wl1271
*wl
,
1131 struct wl12xx_vif
*wlvif
)
1133 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1134 struct sk_buff
*skb
= NULL
;
1137 skb
= ieee80211_nullfunc_get(wl
->hw
, vif
);
1141 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_KLV
,
1142 skb
->data
, skb
->len
,
1143 CMD_TEMPL_KLV_IDX_NULL_DATA
,
1149 wl1271_warning("cmd build klv null data failed %d", ret
);
1155 int wl1271_cmd_build_ps_poll(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1158 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1159 struct sk_buff
*skb
;
1162 skb
= ieee80211_pspoll_get(wl
->hw
, vif
);
1166 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1167 CMD_TEMPL_PS_POLL
, skb
->data
,
1168 skb
->len
, 0, wlvif
->basic_rate_set
);
1175 int wl12xx_cmd_build_probe_req(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1176 u8 role_id
, u8 band
,
1177 const u8
*ssid
, size_t ssid_len
,
1178 const u8
*ie
, size_t ie_len
)
1180 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1181 struct sk_buff
*skb
;
1185 skb
= ieee80211_probereq_get(wl
->hw
, vif
, ssid
, ssid_len
,
1192 wl1271_dump(DEBUG_SCAN
, "PROBE REQ: ", skb
->data
, skb
->len
);
1194 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[band
]);
1195 if (band
== IEEE80211_BAND_2GHZ
)
1196 ret
= wl1271_cmd_template_set(wl
, role_id
,
1197 CMD_TEMPL_CFG_PROBE_REQ_2_4
,
1198 skb
->data
, skb
->len
, 0, rate
);
1200 ret
= wl1271_cmd_template_set(wl
, role_id
,
1201 CMD_TEMPL_CFG_PROBE_REQ_5
,
1202 skb
->data
, skb
->len
, 0, rate
);
1209 struct sk_buff
*wl1271_cmd_build_ap_probe_req(struct wl1271
*wl
,
1210 struct wl12xx_vif
*wlvif
,
1211 struct sk_buff
*skb
)
1213 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1218 skb
= ieee80211_ap_probereq_get(wl
->hw
, vif
);
1222 wl1271_dump(DEBUG_SCAN
, "AP PROBE REQ: ", skb
->data
, skb
->len
);
1224 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[wlvif
->band
]);
1225 if (wlvif
->band
== IEEE80211_BAND_2GHZ
)
1226 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1227 CMD_TEMPL_CFG_PROBE_REQ_2_4
,
1228 skb
->data
, skb
->len
, 0, rate
);
1230 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1231 CMD_TEMPL_CFG_PROBE_REQ_5
,
1232 skb
->data
, skb
->len
, 0, rate
);
1235 wl1271_error("Unable to set ap probe request template.");
1241 int wl1271_cmd_build_arp_rsp(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1245 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1246 struct sk_buff
*skb
;
1247 struct wl12xx_arp_rsp_template
*tmpl
;
1248 struct ieee80211_hdr_3addr
*hdr
;
1249 struct arphdr
*arp_hdr
;
1251 skb
= dev_alloc_skb(sizeof(*hdr
) + sizeof(__le16
) + sizeof(*tmpl
) +
1252 WL1271_EXTRA_SPACE_MAX
);
1254 wl1271_error("failed to allocate buffer for arp rsp template");
1258 skb_reserve(skb
, sizeof(*hdr
) + WL1271_EXTRA_SPACE_MAX
);
1260 tmpl
= (struct wl12xx_arp_rsp_template
*)skb_put(skb
, sizeof(*tmpl
));
1261 memset(tmpl
, 0, sizeof(tmpl
));
1264 memcpy(tmpl
->llc_hdr
, rfc1042_header
, sizeof(rfc1042_header
));
1265 tmpl
->llc_type
= cpu_to_be16(ETH_P_ARP
);
1268 arp_hdr
= &tmpl
->arp_hdr
;
1269 arp_hdr
->ar_hrd
= cpu_to_be16(ARPHRD_ETHER
);
1270 arp_hdr
->ar_pro
= cpu_to_be16(ETH_P_IP
);
1271 arp_hdr
->ar_hln
= ETH_ALEN
;
1272 arp_hdr
->ar_pln
= 4;
1273 arp_hdr
->ar_op
= cpu_to_be16(ARPOP_REPLY
);
1276 memcpy(tmpl
->sender_hw
, vif
->addr
, ETH_ALEN
);
1277 tmpl
->sender_ip
= wlvif
->ip_addr
;
1279 /* encryption space */
1280 switch (wlvif
->encryption_type
) {
1282 extra
= WL1271_EXTRA_SPACE_TKIP
;
1285 extra
= WL1271_EXTRA_SPACE_AES
;
1293 wl1271_warning("Unknown encryption type: %d",
1294 wlvif
->encryption_type
);
1300 u8
*space
= skb_push(skb
, extra
);
1301 memset(space
, 0, extra
);
1304 /* QoS header - BE */
1306 memset(skb_push(skb
, sizeof(__le16
)), 0, sizeof(__le16
));
1308 /* mac80211 header */
1309 hdr
= (struct ieee80211_hdr_3addr
*)skb_push(skb
, sizeof(*hdr
));
1310 memset(hdr
, 0, sizeof(hdr
));
1311 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_FCTL_TODS
;
1313 fc
|= IEEE80211_STYPE_QOS_DATA
;
1315 fc
|= IEEE80211_STYPE_DATA
;
1316 if (wlvif
->encryption_type
!= KEY_NONE
)
1317 fc
|= IEEE80211_FCTL_PROTECTED
;
1319 hdr
->frame_control
= cpu_to_le16(fc
);
1320 memcpy(hdr
->addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1321 memcpy(hdr
->addr2
, vif
->addr
, ETH_ALEN
);
1322 memset(hdr
->addr3
, 0xff, ETH_ALEN
);
1324 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_ARP_RSP
,
1325 skb
->data
, skb
->len
, 0,
1332 int wl1271_build_qos_null_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
1334 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
1335 struct ieee80211_qos_hdr
template;
1337 memset(&template, 0, sizeof(template));
1339 memcpy(template.addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1340 memcpy(template.addr2
, vif
->addr
, ETH_ALEN
);
1341 memcpy(template.addr3
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1343 template.frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1344 IEEE80211_STYPE_QOS_NULLFUNC
|
1345 IEEE80211_FCTL_TODS
);
1347 /* FIXME: not sure what priority to use here */
1348 template.qos_ctrl
= cpu_to_le16(0);
1350 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1351 CMD_TEMPL_QOS_NULL_DATA
, &template,
1352 sizeof(template), 0,
1356 int wl12xx_cmd_set_default_wep_key(struct wl1271
*wl
, u8 id
, u8 hlid
)
1358 struct wl1271_cmd_set_keys
*cmd
;
1361 wl1271_debug(DEBUG_CMD
, "cmd set_default_wep_key %d", id
);
1363 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1371 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1372 cmd
->key_action
= cpu_to_le16(KEY_SET_ID
);
1373 cmd
->key_type
= KEY_WEP
;
1375 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1377 wl1271_warning("cmd set_default_wep_key failed: %d", ret
);
1387 int wl1271_cmd_set_sta_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1388 u16 action
, u8 id
, u8 key_type
,
1389 u8 key_size
, const u8
*key
, const u8
*addr
,
1390 u32 tx_seq_32
, u16 tx_seq_16
)
1392 struct wl1271_cmd_set_keys
*cmd
;
1395 /* hlid might have already been deleted */
1396 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
1399 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1405 cmd
->hlid
= wlvif
->sta
.hlid
;
1407 if (key_type
== KEY_WEP
)
1408 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1409 else if (is_broadcast_ether_addr(addr
))
1410 cmd
->lid_key_type
= BROADCAST_LID_TYPE
;
1412 cmd
->lid_key_type
= UNICAST_LID_TYPE
;
1414 cmd
->key_action
= cpu_to_le16(action
);
1415 cmd
->key_size
= key_size
;
1416 cmd
->key_type
= key_type
;
1418 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1419 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1423 if (key_type
== KEY_TKIP
) {
1425 * We get the key in the following form:
1426 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1427 * but the target is expecting:
1428 * TKIP - RX MIC - TX MIC
1430 memcpy(cmd
->key
, key
, 16);
1431 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1432 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1435 memcpy(cmd
->key
, key
, key_size
);
1438 wl1271_dump(DEBUG_CRYPT
, "TARGET KEY: ", cmd
, sizeof(*cmd
));
1440 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1442 wl1271_warning("could not set keys");
1453 * TODO: merge with sta/ibss into 1 set_key function.
1454 * note there are slight diffs
1456 int wl1271_cmd_set_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1457 u16 action
, u8 id
, u8 key_type
,
1458 u8 key_size
, const u8
*key
, u8 hlid
, u32 tx_seq_32
,
1461 struct wl1271_cmd_set_keys
*cmd
;
1465 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1469 if (hlid
== wlvif
->ap
.bcast_hlid
) {
1470 if (key_type
== KEY_WEP
)
1471 lid_type
= WEP_DEFAULT_LID_TYPE
;
1473 lid_type
= BROADCAST_LID_TYPE
;
1475 lid_type
= UNICAST_LID_TYPE
;
1478 wl1271_debug(DEBUG_CRYPT
, "ap key action: %d id: %d lid: %d type: %d"
1479 " hlid: %d", (int)action
, (int)id
, (int)lid_type
,
1480 (int)key_type
, (int)hlid
);
1482 cmd
->lid_key_type
= lid_type
;
1484 cmd
->key_action
= cpu_to_le16(action
);
1485 cmd
->key_size
= key_size
;
1486 cmd
->key_type
= key_type
;
1488 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1489 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1491 if (key_type
== KEY_TKIP
) {
1493 * We get the key in the following form:
1494 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1495 * but the target is expecting:
1496 * TKIP - RX MIC - TX MIC
1498 memcpy(cmd
->key
, key
, 16);
1499 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1500 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1502 memcpy(cmd
->key
, key
, key_size
);
1505 wl1271_dump(DEBUG_CRYPT
, "TARGET AP KEY: ", cmd
, sizeof(*cmd
));
1507 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1509 wl1271_warning("could not set ap keys");
1518 int wl12xx_cmd_set_peer_state(struct wl1271
*wl
, u8 hlid
)
1520 struct wl12xx_cmd_set_peer_state
*cmd
;
1523 wl1271_debug(DEBUG_CMD
, "cmd set peer state (hlid=%d)", hlid
);
1525 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1532 cmd
->state
= WL1271_CMD_STA_STATE_CONNECTED
;
1534 ret
= wl1271_cmd_send(wl
, CMD_SET_PEER_STATE
, cmd
, sizeof(*cmd
), 0);
1536 wl1271_error("failed to send set peer state command");
1547 int wl12xx_cmd_add_peer(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1548 struct ieee80211_sta
*sta
, u8 hlid
)
1550 struct wl12xx_cmd_add_peer
*cmd
;
1554 wl1271_debug(DEBUG_CMD
, "cmd add peer %d", (int)hlid
);
1556 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1562 memcpy(cmd
->addr
, sta
->addr
, ETH_ALEN
);
1563 cmd
->bss_index
= WL1271_AP_BSS_INDEX
;
1564 cmd
->aid
= sta
->aid
;
1566 cmd
->sp_len
= sta
->max_sp
;
1567 cmd
->wmm
= sta
->wme
? 1 : 0;
1569 for (i
= 0; i
< NUM_ACCESS_CATEGORIES_COPY
; i
++)
1570 if (sta
->wme
&& (sta
->uapsd_queues
& BIT(i
)))
1571 cmd
->psd_type
[i
] = WL1271_PSD_UPSD_TRIGGER
;
1573 cmd
->psd_type
[i
] = WL1271_PSD_LEGACY
;
1575 sta_rates
= sta
->supp_rates
[wlvif
->band
];
1576 if (sta
->ht_cap
.ht_supported
)
1577 sta_rates
|= sta
->ht_cap
.mcs
.rx_mask
[0] << HW_HT_RATES_OFFSET
;
1579 cmd
->supported_rates
=
1580 cpu_to_le32(wl1271_tx_enabled_rates_get(wl
, sta_rates
,
1583 wl1271_debug(DEBUG_CMD
, "new peer rates=0x%x queues=0x%x",
1584 cmd
->supported_rates
, sta
->uapsd_queues
);
1586 ret
= wl1271_cmd_send(wl
, CMD_ADD_PEER
, cmd
, sizeof(*cmd
), 0);
1588 wl1271_error("failed to initiate cmd add peer");
1599 int wl12xx_cmd_remove_peer(struct wl1271
*wl
, u8 hlid
)
1601 struct wl12xx_cmd_remove_peer
*cmd
;
1604 wl1271_debug(DEBUG_CMD
, "cmd remove peer %d", (int)hlid
);
1606 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1613 /* We never send a deauth, mac80211 is in charge of this */
1614 cmd
->reason_opcode
= 0;
1615 cmd
->send_deauth_flag
= 0;
1617 ret
= wl1271_cmd_send(wl
, CMD_REMOVE_PEER
, cmd
, sizeof(*cmd
), 0);
1619 wl1271_error("failed to initiate cmd remove peer");
1624 * We are ok with a timeout here. The event is sometimes not sent
1625 * due to a firmware bug.
1627 wl1271_cmd_wait_for_event_or_timeout(wl
,
1628 PEER_REMOVE_COMPLETE_EVENT_ID
);
1637 int wl12xx_cmd_config_fwlog(struct wl1271
*wl
)
1639 struct wl12xx_cmd_config_fwlog
*cmd
;
1642 wl1271_debug(DEBUG_CMD
, "cmd config firmware logger");
1644 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1650 cmd
->logger_mode
= wl
->conf
.fwlog
.mode
;
1651 cmd
->log_severity
= wl
->conf
.fwlog
.severity
;
1652 cmd
->timestamp
= wl
->conf
.fwlog
.timestamp
;
1653 cmd
->output
= wl
->conf
.fwlog
.output
;
1654 cmd
->threshold
= wl
->conf
.fwlog
.threshold
;
1656 ret
= wl1271_cmd_send(wl
, CMD_CONFIG_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1658 wl1271_error("failed to send config firmware logger command");
1669 int wl12xx_cmd_start_fwlog(struct wl1271
*wl
)
1671 struct wl12xx_cmd_start_fwlog
*cmd
;
1674 wl1271_debug(DEBUG_CMD
, "cmd start firmware logger");
1676 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1682 ret
= wl1271_cmd_send(wl
, CMD_START_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1684 wl1271_error("failed to send start firmware logger command");
1695 int wl12xx_cmd_stop_fwlog(struct wl1271
*wl
)
1697 struct wl12xx_cmd_stop_fwlog
*cmd
;
1700 wl1271_debug(DEBUG_CMD
, "cmd stop firmware logger");
1702 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1708 ret
= wl1271_cmd_send(wl
, CMD_STOP_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1710 wl1271_error("failed to send stop firmware logger command");
1721 static int wl12xx_cmd_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1724 struct wl12xx_cmd_roc
*cmd
;
1727 wl1271_debug(DEBUG_CMD
, "cmd roc %d (%d)", wlvif
->channel
, role_id
);
1729 if (WARN_ON(role_id
== WL12XX_INVALID_ROLE_ID
))
1732 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1738 cmd
->role_id
= role_id
;
1739 cmd
->channel
= wlvif
->channel
;
1740 switch (wlvif
->band
) {
1741 case IEEE80211_BAND_2GHZ
:
1742 cmd
->band
= WLCORE_BAND_2_4GHZ
;
1744 case IEEE80211_BAND_5GHZ
:
1745 cmd
->band
= WLCORE_BAND_5GHZ
;
1748 wl1271_error("roc - unknown band: %d", (int)wlvif
->band
);
1754 ret
= wl1271_cmd_send(wl
, CMD_REMAIN_ON_CHANNEL
, cmd
, sizeof(*cmd
), 0);
1756 wl1271_error("failed to send ROC command");
1767 static int wl12xx_cmd_croc(struct wl1271
*wl
, u8 role_id
)
1769 struct wl12xx_cmd_croc
*cmd
;
1772 wl1271_debug(DEBUG_CMD
, "cmd croc (%d)", role_id
);
1774 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1779 cmd
->role_id
= role_id
;
1781 ret
= wl1271_cmd_send(wl
, CMD_CANCEL_REMAIN_ON_CHANNEL
, cmd
,
1784 wl1271_error("failed to send ROC command");
1795 int wl12xx_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 role_id
)
1799 if (WARN_ON(test_bit(role_id
, wl
->roc_map
)))
1802 ret
= wl12xx_cmd_roc(wl
, wlvif
, role_id
);
1806 ret
= wl1271_cmd_wait_for_event(wl
,
1807 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID
);
1809 wl1271_error("cmd roc event completion error");
1813 __set_bit(role_id
, wl
->roc_map
);
1818 int wl12xx_croc(struct wl1271
*wl
, u8 role_id
)
1822 if (WARN_ON(!test_bit(role_id
, wl
->roc_map
)))
1825 ret
= wl12xx_cmd_croc(wl
, role_id
);
1829 __clear_bit(role_id
, wl
->roc_map
);
1832 * Rearm the tx watchdog when removing the last ROC. This prevents
1833 * recoveries due to just finished ROCs - when Tx hasn't yet had
1834 * a chance to get out.
1836 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) >= WL12XX_MAX_ROLES
)
1837 wl12xx_rearm_tx_watchdog_locked(wl
);
1842 int wl12xx_cmd_channel_switch(struct wl1271
*wl
,
1843 struct wl12xx_vif
*wlvif
,
1844 struct ieee80211_channel_switch
*ch_switch
)
1846 struct wl12xx_cmd_channel_switch
*cmd
;
1849 wl1271_debug(DEBUG_ACX
, "cmd channel switch");
1851 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1857 cmd
->role_id
= wlvif
->role_id
;
1858 cmd
->channel
= ch_switch
->channel
->hw_value
;
1859 cmd
->switch_time
= ch_switch
->count
;
1860 cmd
->stop_tx
= ch_switch
->block_tx
;
1862 /* FIXME: control from mac80211 in the future */
1863 cmd
->post_switch_tx_disable
= 0; /* Enable TX on the target channel */
1865 ret
= wl1271_cmd_send(wl
, CMD_CHANNEL_SWITCH
, cmd
, sizeof(*cmd
), 0);
1867 wl1271_error("failed to send channel switch command");
1878 int wl12xx_cmd_stop_channel_switch(struct wl1271
*wl
)
1880 struct wl12xx_cmd_stop_channel_switch
*cmd
;
1883 wl1271_debug(DEBUG_ACX
, "cmd stop channel switch");
1885 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1891 ret
= wl1271_cmd_send(wl
, CMD_STOP_CHANNEL_SWICTH
, cmd
, sizeof(*cmd
), 0);
1893 wl1271_error("failed to stop channel switch command");
1904 /* start dev role and roc on its channel */
1905 int wl12xx_start_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1909 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1910 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
1913 ret
= wl12xx_cmd_role_start_dev(wl
, wlvif
);
1917 ret
= wl12xx_roc(wl
, wlvif
, wlvif
->dev_role_id
);
1924 wl12xx_cmd_role_stop_dev(wl
, wlvif
);
1929 /* croc dev hlid, and stop the role */
1930 int wl12xx_stop_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1934 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1935 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
1938 /* flush all pending packets */
1939 wl1271_tx_work_locked(wl
);
1941 if (test_bit(wlvif
->dev_role_id
, wl
->roc_map
)) {
1942 ret
= wl12xx_croc(wl
, wlvif
->dev_role_id
);
1947 ret
= wl12xx_cmd_role_stop_dev(wl
, wlvif
);