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);
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);
102 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
103 WL1271_ACX_INTR_CMD_COMPLETE);
108 ieee80211_queue_work(wl->hw, &wl->recovery_work);
112 int wl1271_cmd_general_parms(struct wl1271 *wl)
114 struct wl1271_general_parms_cmd *gen_parms;
115 struct wl1271_ini_general_params *gp =
116 &((struct wl1271_nvs_file *)wl->nvs)->general_params;
123 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
127 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
129 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
131 if (gp->tx_bip_fem_auto_detect)
134 /* Override the REF CLK from the NVS with the one from platform data */
135 gen_parms->general_params.ref_clock = wl->ref_clock;
137 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
139 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
143 gp->tx_bip_fem_manufacturer =
144 gen_parms->general_params.tx_bip_fem_manufacturer;
146 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
147 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
154 int wl128x_cmd_general_parms(struct wl1271 *wl)
156 struct wl128x_general_parms_cmd *gen_parms;
157 struct wl128x_ini_general_params *gp =
158 &((struct wl128x_nvs_file *)wl->nvs)->general_params;
165 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
169 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
171 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
173 if (gp->tx_bip_fem_auto_detect)
176 /* Replace REF and TCXO CLKs with the ones from platform data */
177 gen_parms->general_params.ref_clock = wl->ref_clock;
178 gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock;
180 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
182 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
186 gp->tx_bip_fem_manufacturer =
187 gen_parms->general_params.tx_bip_fem_manufacturer;
189 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
190 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
197 int wl1271_cmd_radio_parms(struct wl1271 *wl)
199 struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs;
200 struct wl1271_radio_parms_cmd *radio_parms;
201 struct wl1271_ini_general_params *gp = &nvs->general_params;
207 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
211 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
213 /* 2.4GHz parameters */
214 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
215 sizeof(struct wl1271_ini_band_params_2));
216 memcpy(&radio_parms->dyn_params_2,
217 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
218 sizeof(struct wl1271_ini_fem_params_2));
220 /* 5GHz parameters */
221 memcpy(&radio_parms->static_params_5,
222 &nvs->stat_radio_params_5,
223 sizeof(struct wl1271_ini_band_params_5));
224 memcpy(&radio_parms->dyn_params_5,
225 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
226 sizeof(struct wl1271_ini_fem_params_5));
228 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
229 radio_parms, sizeof(*radio_parms));
231 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
233 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
239 int wl128x_cmd_radio_parms(struct wl1271 *wl)
241 struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
242 struct wl128x_radio_parms_cmd *radio_parms;
243 struct wl128x_ini_general_params *gp = &nvs->general_params;
249 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
253 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
255 /* 2.4GHz parameters */
256 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
257 sizeof(struct wl128x_ini_band_params_2));
258 memcpy(&radio_parms->dyn_params_2,
259 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
260 sizeof(struct wl128x_ini_fem_params_2));
262 /* 5GHz parameters */
263 memcpy(&radio_parms->static_params_5,
264 &nvs->stat_radio_params_5,
265 sizeof(struct wl128x_ini_band_params_5));
266 memcpy(&radio_parms->dyn_params_5,
267 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
268 sizeof(struct wl128x_ini_fem_params_5));
270 radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options;
272 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
273 radio_parms, sizeof(*radio_parms));
275 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
277 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
283 int wl1271_cmd_ext_radio_parms(struct wl1271 *wl)
285 struct wl1271_ext_radio_parms_cmd *ext_radio_parms;
286 struct conf_rf_settings *rf = &wl->conf.rf;
292 ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL);
293 if (!ext_radio_parms)
296 ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM;
298 memcpy(ext_radio_parms->tx_per_channel_power_compensation_2,
299 rf->tx_per_channel_power_compensation_2,
300 CONF_TX_PWR_COMPENSATION_LEN_2);
301 memcpy(ext_radio_parms->tx_per_channel_power_compensation_5,
302 rf->tx_per_channel_power_compensation_5,
303 CONF_TX_PWR_COMPENSATION_LEN_5);
305 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
306 ext_radio_parms, sizeof(*ext_radio_parms));
308 ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0);
310 wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
312 kfree(ext_radio_parms);
317 * Poll the mailbox event field until any of the bits in the mask is set or a
318 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
320 static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask)
322 u32 events_vector, event;
323 unsigned long timeout;
325 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
328 if (time_after(jiffies, timeout)) {
329 wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
336 /* read from both event fields */
337 wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
338 sizeof(events_vector), false);
339 event = events_vector & mask;
340 wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
341 sizeof(events_vector), false);
342 event |= events_vector & mask;
348 static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
352 ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask);
354 ieee80211_queue_work(wl->hw, &wl->recovery_work);
361 int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type)
363 struct wl1271_cmd_join *join;
367 join = kzalloc(sizeof(*join), GFP_KERNEL);
373 wl1271_debug(DEBUG_CMD, "cmd join");
375 /* Reverse order BSSID */
376 bssid = (u8 *) &join->bssid_lsb;
377 for (i = 0; i < ETH_ALEN; i++)
378 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
380 join->rx_config_options = cpu_to_le32(wl->rx_config);
381 join->rx_filter_options = cpu_to_le32(wl->rx_filter);
382 join->bss_type = bss_type;
383 join->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
384 join->supported_rate_set = cpu_to_le32(wl->rate_set);
386 if (wl->band == IEEE80211_BAND_5GHZ)
387 join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
389 join->beacon_interval = cpu_to_le16(wl->beacon_int);
390 join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD;
392 join->channel = wl->channel;
393 join->ssid_len = wl->ssid_len;
394 memcpy(join->ssid, wl->ssid, wl->ssid_len);
396 join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
398 /* reset TX security counters */
399 wl->tx_security_last_seq = 0;
400 wl->tx_security_seq = 0;
402 wl1271_debug(DEBUG_CMD, "cmd join: basic_rate_set=0x%x, rate_set=0x%x",
403 join->basic_rate_set, join->supported_rate_set);
405 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
407 wl1271_error("failed to initiate cmd join");
411 ret = wl1271_cmd_wait_for_event(wl, JOIN_EVENT_COMPLETE_ID);
413 wl1271_error("cmd join event completion error");
423 * send test command to firmware
426 * @buf: buffer containing the command, with all headers, must work with dma
427 * @len: length of the buffer
428 * @answer: is answer needed
430 int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
435 wl1271_debug(DEBUG_CMD, "cmd test");
440 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
443 wl1271_warning("TEST command failed");
451 * read acx from firmware
455 * @buf: buffer for the response, including all headers, must work with dma
456 * @len: length of buf
458 int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
460 struct acx_header *acx = buf;
463 wl1271_debug(DEBUG_CMD, "cmd interrogate");
465 acx->id = cpu_to_le16(id);
467 /* payload length, does not include any headers */
468 acx->len = cpu_to_le16(len - sizeof(*acx));
470 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
472 wl1271_error("INTERROGATE command failed");
478 * write acx value to firmware
482 * @buf: buffer containing acx, including all headers, must work with dma
483 * @len: length of buf
485 int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
487 struct acx_header *acx = buf;
490 wl1271_debug(DEBUG_CMD, "cmd configure");
492 acx->id = cpu_to_le16(id);
494 /* payload length, does not include any headers */
495 acx->len = cpu_to_le16(len - sizeof(*acx));
497 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
499 wl1271_warning("CONFIGURE command NOK");
506 int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
508 struct cmd_enabledisable_path *cmd;
512 wl1271_debug(DEBUG_CMD, "cmd data path");
514 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
520 /* the channel here is only used for calibration, so hardcoded to 1 */
524 cmd_rx = CMD_ENABLE_RX;
525 cmd_tx = CMD_ENABLE_TX;
527 cmd_rx = CMD_DISABLE_RX;
528 cmd_tx = CMD_DISABLE_TX;
531 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
533 wl1271_error("rx %s cmd for channel %d failed",
534 enable ? "start" : "stop", cmd->channel);
538 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
539 enable ? "start" : "stop", cmd->channel);
541 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
543 wl1271_error("tx %s cmd for channel %d failed",
544 enable ? "start" : "stop", cmd->channel);
548 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
549 enable ? "start" : "stop", cmd->channel);
556 int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode)
558 struct wl1271_cmd_ps_params *ps_params = NULL;
561 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
563 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
569 ps_params->ps_mode = ps_mode;
571 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
572 sizeof(*ps_params), 0);
574 wl1271_error("cmd set_ps_mode failed");
583 int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
584 void *buf, size_t buf_len, int index, u32 rates)
586 struct wl1271_cmd_template_set *cmd;
589 wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
591 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
592 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
594 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
600 cmd->len = cpu_to_le16(buf_len);
601 cmd->template_type = template_id;
602 cmd->enabled_rates = cpu_to_le32(rates);
603 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
604 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
608 memcpy(cmd->template_data, buf, buf_len);
610 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
612 wl1271_warning("cmd set_template failed: %d", ret);
623 int wl1271_cmd_build_null_data(struct wl1271 *wl)
625 struct sk_buff *skb = NULL;
631 if (wl->bss_type == BSS_TYPE_IBSS) {
632 size = sizeof(struct wl12xx_null_data_template);
635 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
642 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
648 wl1271_warning("cmd buld null data failed %d", ret);
654 int wl1271_cmd_build_klv_null_data(struct wl1271 *wl)
656 struct sk_buff *skb = NULL;
659 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
663 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
665 CMD_TEMPL_KLV_IDX_NULL_DATA,
671 wl1271_warning("cmd build klv null data failed %d", ret);
677 int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
682 skb = ieee80211_pspoll_get(wl->hw, wl->vif);
686 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
687 skb->len, 0, wl->basic_rate_set);
694 int wl1271_cmd_build_probe_req(struct wl1271 *wl,
695 const u8 *ssid, size_t ssid_len,
696 const u8 *ie, size_t ie_len, u8 band)
701 skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
708 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
710 if (band == IEEE80211_BAND_2GHZ)
711 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
712 skb->data, skb->len, 0,
713 wl->conf.tx.basic_rate);
715 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
716 skb->data, skb->len, 0,
717 wl->conf.tx.basic_rate_5);
724 struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
730 skb = ieee80211_ap_probereq_get(wl->hw, wl->vif);
734 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
736 if (wl->band == IEEE80211_BAND_2GHZ)
737 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
738 skb->data, skb->len, 0,
739 wl->conf.tx.basic_rate);
741 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
742 skb->data, skb->len, 0,
743 wl->conf.tx.basic_rate_5);
746 wl1271_error("Unable to set ap probe request template.");
752 int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr)
755 struct wl12xx_arp_rsp_template tmpl;
756 struct ieee80211_hdr_3addr *hdr;
757 struct arphdr *arp_hdr;
759 memset(&tmpl, 0, sizeof(tmpl));
761 /* mac80211 header */
763 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
764 IEEE80211_STYPE_DATA |
765 IEEE80211_FCTL_TODS);
766 memcpy(hdr->addr1, wl->vif->bss_conf.bssid, ETH_ALEN);
767 memcpy(hdr->addr2, wl->vif->addr, ETH_ALEN);
768 memset(hdr->addr3, 0xff, ETH_ALEN);
771 memcpy(tmpl.llc_hdr, rfc1042_header, sizeof(rfc1042_header));
772 tmpl.llc_type = cpu_to_be16(ETH_P_ARP);
775 arp_hdr = &tmpl.arp_hdr;
776 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
777 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
778 arp_hdr->ar_hln = ETH_ALEN;
780 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
783 memcpy(tmpl.sender_hw, wl->vif->addr, ETH_ALEN);
784 tmpl.sender_ip = ip_addr;
786 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP,
787 &tmpl, sizeof(tmpl), 0,
793 int wl1271_build_qos_null_data(struct wl1271 *wl)
795 struct ieee80211_qos_hdr template;
797 memset(&template, 0, sizeof(template));
799 memcpy(template.addr1, wl->bssid, ETH_ALEN);
800 memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
801 memcpy(template.addr3, wl->bssid, ETH_ALEN);
803 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
804 IEEE80211_STYPE_QOS_NULLFUNC |
805 IEEE80211_FCTL_TODS);
807 /* FIXME: not sure what priority to use here */
808 template.qos_ctrl = cpu_to_le16(0);
810 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
815 int wl1271_cmd_set_sta_default_wep_key(struct wl1271 *wl, u8 id)
817 struct wl1271_cmd_set_sta_keys *cmd;
820 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
822 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
829 cmd->key_action = cpu_to_le16(KEY_SET_ID);
830 cmd->key_type = KEY_WEP;
832 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
834 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
844 int wl1271_cmd_set_ap_default_wep_key(struct wl1271 *wl, u8 id)
846 struct wl1271_cmd_set_ap_keys *cmd;
849 wl1271_debug(DEBUG_CMD, "cmd set_ap_default_wep_key %d", id);
851 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
857 cmd->hlid = WL1271_AP_BROADCAST_HLID;
859 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
860 cmd->key_action = cpu_to_le16(KEY_SET_ID);
861 cmd->key_type = KEY_WEP;
863 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
865 wl1271_warning("cmd set_ap_default_wep_key failed: %d", ret);
875 int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
876 u8 key_size, const u8 *key, const u8 *addr,
877 u32 tx_seq_32, u16 tx_seq_16)
879 struct wl1271_cmd_set_sta_keys *cmd;
882 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
888 if (key_type != KEY_WEP)
889 memcpy(cmd->addr, addr, ETH_ALEN);
891 cmd->key_action = cpu_to_le16(action);
892 cmd->key_size = key_size;
893 cmd->key_type = key_type;
895 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
896 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
898 /* we have only one SSID profile */
899 cmd->ssid_profile = 0;
903 if (key_type == KEY_TKIP) {
905 * We get the key in the following form:
906 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
907 * but the target is expecting:
908 * TKIP - RX MIC - TX MIC
910 memcpy(cmd->key, key, 16);
911 memcpy(cmd->key + 16, key + 24, 8);
912 memcpy(cmd->key + 24, key + 16, 8);
915 memcpy(cmd->key, key, key_size);
918 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
920 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
922 wl1271_warning("could not set keys");
932 int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
933 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
936 struct wl1271_cmd_set_ap_keys *cmd;
940 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
944 if (hlid == WL1271_AP_BROADCAST_HLID) {
945 if (key_type == KEY_WEP)
946 lid_type = WEP_DEFAULT_LID_TYPE;
948 lid_type = BROADCAST_LID_TYPE;
950 lid_type = UNICAST_LID_TYPE;
953 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
954 " hlid: %d", (int)action, (int)id, (int)lid_type,
955 (int)key_type, (int)hlid);
957 cmd->lid_key_type = lid_type;
959 cmd->key_action = cpu_to_le16(action);
960 cmd->key_size = key_size;
961 cmd->key_type = key_type;
963 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
964 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
966 if (key_type == KEY_TKIP) {
968 * We get the key in the following form:
969 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
970 * but the target is expecting:
971 * TKIP - RX MIC - TX MIC
973 memcpy(cmd->key, key, 16);
974 memcpy(cmd->key + 16, key + 24, 8);
975 memcpy(cmd->key + 24, key + 16, 8);
977 memcpy(cmd->key, key, key_size);
980 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
982 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
984 wl1271_warning("could not set ap keys");
993 int wl1271_cmd_disconnect(struct wl1271 *wl)
995 struct wl1271_cmd_disconnect *cmd;
998 wl1271_debug(DEBUG_CMD, "cmd disconnect");
1000 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1006 cmd->rx_config_options = cpu_to_le32(wl->rx_config);
1007 cmd->rx_filter_options = cpu_to_le32(wl->rx_filter);
1008 /* disconnect reason is not used in immediate disconnections */
1009 cmd->type = DISCONNECT_IMMEDIATE;
1011 ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
1013 wl1271_error("failed to send disconnect command");
1017 ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
1019 wl1271_error("cmd disconnect event completion error");
1028 int wl1271_cmd_set_sta_state(struct wl1271 *wl)
1030 struct wl1271_cmd_set_sta_state *cmd;
1033 wl1271_debug(DEBUG_CMD, "cmd set sta state");
1035 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1041 cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
1043 ret = wl1271_cmd_send(wl, CMD_SET_STA_STATE, cmd, sizeof(*cmd), 0);
1045 wl1271_error("failed to send set STA state command");
1056 int wl1271_cmd_start_bss(struct wl1271 *wl)
1058 struct wl1271_cmd_bss_start *cmd;
1059 struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf;
1062 wl1271_debug(DEBUG_CMD, "cmd start bss");
1065 * FIXME: We currently do not support hidden SSID. The real SSID
1066 * should be fetched from mac80211 first.
1068 if (wl->ssid_len == 0) {
1069 wl1271_warning("Hidden SSID currently not supported for AP");
1074 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1080 memcpy(cmd->bssid, bss_conf->bssid, ETH_ALEN);
1082 cmd->aging_period = cpu_to_le16(WL1271_AP_DEF_INACTIV_SEC);
1083 cmd->bss_index = WL1271_AP_BSS_INDEX;
1084 cmd->global_hlid = WL1271_AP_GLOBAL_HLID;
1085 cmd->broadcast_hlid = WL1271_AP_BROADCAST_HLID;
1086 cmd->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
1087 cmd->beacon_interval = cpu_to_le16(wl->beacon_int);
1088 cmd->dtim_interval = bss_conf->dtim_period;
1089 cmd->beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
1090 cmd->channel = wl->channel;
1091 cmd->ssid_len = wl->ssid_len;
1092 cmd->ssid_type = SSID_TYPE_PUBLIC;
1093 memcpy(cmd->ssid, wl->ssid, wl->ssid_len);
1096 case IEEE80211_BAND_2GHZ:
1097 cmd->band = RADIO_BAND_2_4GHZ;
1099 case IEEE80211_BAND_5GHZ:
1100 cmd->band = RADIO_BAND_5GHZ;
1103 wl1271_warning("bss start - unknown band: %d", (int)wl->band);
1104 cmd->band = RADIO_BAND_2_4GHZ;
1108 ret = wl1271_cmd_send(wl, CMD_BSS_START, cmd, sizeof(*cmd), 0);
1110 wl1271_error("failed to initiate cmd start bss");
1121 int wl1271_cmd_stop_bss(struct wl1271 *wl)
1123 struct wl1271_cmd_bss_start *cmd;
1126 wl1271_debug(DEBUG_CMD, "cmd stop bss");
1128 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1134 cmd->bss_index = WL1271_AP_BSS_INDEX;
1136 ret = wl1271_cmd_send(wl, CMD_BSS_STOP, cmd, sizeof(*cmd), 0);
1138 wl1271_error("failed to initiate cmd stop bss");
1149 int wl1271_cmd_add_sta(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid)
1151 struct wl1271_cmd_add_sta *cmd;
1154 wl1271_debug(DEBUG_CMD, "cmd add sta %d", (int)hlid);
1156 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1162 /* currently we don't support UAPSD */
1165 memcpy(cmd->addr, sta->addr, ETH_ALEN);
1166 cmd->bss_index = WL1271_AP_BSS_INDEX;
1167 cmd->aid = sta->aid;
1171 * FIXME: Does STA support QOS? We need to propagate this info from
1172 * hostapd. Currently not that important since this is only used for
1173 * sending the correct flavor of null-data packet in response to a
1178 cmd->supported_rates = cpu_to_le32(wl1271_tx_enabled_rates_get(wl,
1179 sta->supp_rates[wl->band]));
1181 wl1271_debug(DEBUG_CMD, "new sta rates: 0x%x", cmd->supported_rates);
1183 ret = wl1271_cmd_send(wl, CMD_ADD_STA, cmd, sizeof(*cmd), 0);
1185 wl1271_error("failed to initiate cmd add sta");
1196 int wl1271_cmd_remove_sta(struct wl1271 *wl, u8 hlid)
1198 struct wl1271_cmd_remove_sta *cmd;
1201 wl1271_debug(DEBUG_CMD, "cmd remove sta %d", (int)hlid);
1203 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1210 /* We never send a deauth, mac80211 is in charge of this */
1211 cmd->reason_opcode = 0;
1212 cmd->send_deauth_flag = 0;
1214 ret = wl1271_cmd_send(wl, CMD_REMOVE_STA, cmd, sizeof(*cmd), 0);
1216 wl1271_error("failed to initiate cmd remove sta");
1221 * We are ok with a timeout here. The event is sometimes not sent
1222 * due to a firmware bug.
1224 wl1271_cmd_wait_for_event_or_timeout(wl, STA_REMOVE_COMPLETE_EVENT_ID);