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);
66 WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
68 wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
70 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
72 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
74 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
75 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
76 if (time_after(jiffies, timeout)) {
77 wl1271_error("command complete timeout");
83 if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
88 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
91 /* read back the status code of the command */
93 res_len = sizeof(struct wl1271_cmd_header);
94 wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
96 status = le16_to_cpu(cmd->status);
97 if (status != CMD_STATUS_SUCCESS) {
98 wl1271_error("command execute failure %d", status);
99 ieee80211_queue_work(wl->hw, &wl->recovery_work);
103 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
104 WL1271_ACX_INTR_CMD_COMPLETE);
110 int wl1271_cmd_general_parms(struct wl1271 *wl)
112 struct wl1271_general_parms_cmd *gen_parms;
113 struct wl1271_ini_general_params *gp = &wl->nvs->general_params;
120 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
124 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
126 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
128 if (gp->tx_bip_fem_auto_detect)
131 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
133 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
137 gp->tx_bip_fem_manufacturer =
138 gen_parms->general_params.tx_bip_fem_manufacturer;
140 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
141 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
148 int wl1271_cmd_radio_parms(struct wl1271 *wl)
150 struct wl1271_radio_parms_cmd *radio_parms;
151 struct wl1271_ini_general_params *gp = &wl->nvs->general_params;
157 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
161 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
163 /* 2.4GHz parameters */
164 memcpy(&radio_parms->static_params_2, &wl->nvs->stat_radio_params_2,
165 sizeof(struct wl1271_ini_band_params_2));
166 memcpy(&radio_parms->dyn_params_2,
167 &wl->nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
168 sizeof(struct wl1271_ini_fem_params_2));
170 /* 5GHz parameters */
171 memcpy(&radio_parms->static_params_5,
172 &wl->nvs->stat_radio_params_5,
173 sizeof(struct wl1271_ini_band_params_5));
174 memcpy(&radio_parms->dyn_params_5,
175 &wl->nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
176 sizeof(struct wl1271_ini_fem_params_5));
178 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
179 radio_parms, sizeof(*radio_parms));
181 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
183 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
189 int wl1271_cmd_ext_radio_parms(struct wl1271 *wl)
191 struct wl1271_ext_radio_parms_cmd *ext_radio_parms;
192 struct conf_rf_settings *rf = &wl->conf.rf;
198 ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL);
199 if (!ext_radio_parms)
202 ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM;
204 memcpy(ext_radio_parms->tx_per_channel_power_compensation_2,
205 rf->tx_per_channel_power_compensation_2,
206 CONF_TX_PWR_COMPENSATION_LEN_2);
207 memcpy(ext_radio_parms->tx_per_channel_power_compensation_5,
208 rf->tx_per_channel_power_compensation_5,
209 CONF_TX_PWR_COMPENSATION_LEN_5);
211 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
212 ext_radio_parms, sizeof(*ext_radio_parms));
214 ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0);
216 wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
218 kfree(ext_radio_parms);
223 * Poll the mailbox event field until any of the bits in the mask is set or a
224 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
226 static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask)
228 u32 events_vector, event;
229 unsigned long timeout;
231 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
234 if (time_after(jiffies, timeout)) {
235 wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
242 /* read from both event fields */
243 wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
244 sizeof(events_vector), false);
245 event = events_vector & mask;
246 wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
247 sizeof(events_vector), false);
248 event |= events_vector & mask;
254 static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
258 ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask);
260 ieee80211_queue_work(wl->hw, &wl->recovery_work);
267 int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type)
269 struct wl1271_cmd_join *join;
273 join = kzalloc(sizeof(*join), GFP_KERNEL);
279 wl1271_debug(DEBUG_CMD, "cmd join");
281 /* Reverse order BSSID */
282 bssid = (u8 *) &join->bssid_lsb;
283 for (i = 0; i < ETH_ALEN; i++)
284 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
286 join->rx_config_options = cpu_to_le32(wl->rx_config);
287 join->rx_filter_options = cpu_to_le32(wl->rx_filter);
288 join->bss_type = bss_type;
289 join->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
290 join->supported_rate_set = cpu_to_le32(wl->rate_set);
292 if (wl->band == IEEE80211_BAND_5GHZ)
293 join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
295 join->beacon_interval = cpu_to_le16(wl->beacon_int);
296 join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD;
298 join->channel = wl->channel;
299 join->ssid_len = wl->ssid_len;
300 memcpy(join->ssid, wl->ssid, wl->ssid_len);
302 join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
304 /* reset TX security counters */
305 wl->tx_security_last_seq = 0;
306 wl->tx_security_seq = 0;
308 wl1271_debug(DEBUG_CMD, "cmd join: basic_rate_set=0x%x, rate_set=0x%x",
309 join->basic_rate_set, join->supported_rate_set);
311 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
313 wl1271_error("failed to initiate cmd join");
317 ret = wl1271_cmd_wait_for_event(wl, JOIN_EVENT_COMPLETE_ID);
319 wl1271_error("cmd join event completion error");
329 * send test command to firmware
332 * @buf: buffer containing the command, with all headers, must work with dma
333 * @len: length of the buffer
334 * @answer: is answer needed
336 int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
341 wl1271_debug(DEBUG_CMD, "cmd test");
346 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
349 wl1271_warning("TEST command failed");
357 * read acx from firmware
361 * @buf: buffer for the response, including all headers, must work with dma
362 * @len: length of buf
364 int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
366 struct acx_header *acx = buf;
369 wl1271_debug(DEBUG_CMD, "cmd interrogate");
371 acx->id = cpu_to_le16(id);
373 /* payload length, does not include any headers */
374 acx->len = cpu_to_le16(len - sizeof(*acx));
376 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
378 wl1271_error("INTERROGATE command failed");
384 * write acx value to firmware
388 * @buf: buffer containing acx, including all headers, must work with dma
389 * @len: length of buf
391 int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
393 struct acx_header *acx = buf;
396 wl1271_debug(DEBUG_CMD, "cmd configure");
398 acx->id = cpu_to_le16(id);
400 /* payload length, does not include any headers */
401 acx->len = cpu_to_le16(len - sizeof(*acx));
403 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
405 wl1271_warning("CONFIGURE command NOK");
412 int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
414 struct cmd_enabledisable_path *cmd;
418 wl1271_debug(DEBUG_CMD, "cmd data path");
420 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
426 /* the channel here is only used for calibration, so hardcoded to 1 */
430 cmd_rx = CMD_ENABLE_RX;
431 cmd_tx = CMD_ENABLE_TX;
433 cmd_rx = CMD_DISABLE_RX;
434 cmd_tx = CMD_DISABLE_TX;
437 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
439 wl1271_error("rx %s cmd for channel %d failed",
440 enable ? "start" : "stop", cmd->channel);
444 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
445 enable ? "start" : "stop", cmd->channel);
447 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
449 wl1271_error("tx %s cmd for channel %d failed",
450 enable ? "start" : "stop", cmd->channel);
454 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
455 enable ? "start" : "stop", cmd->channel);
462 int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode)
464 struct wl1271_cmd_ps_params *ps_params = NULL;
467 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
469 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
475 ps_params->ps_mode = ps_mode;
477 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
478 sizeof(*ps_params), 0);
480 wl1271_error("cmd set_ps_mode failed");
489 int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
490 void *buf, size_t buf_len, int index, u32 rates)
492 struct wl1271_cmd_template_set *cmd;
495 wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
497 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
498 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
500 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
506 cmd->len = cpu_to_le16(buf_len);
507 cmd->template_type = template_id;
508 cmd->enabled_rates = cpu_to_le32(rates);
509 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
510 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
514 memcpy(cmd->template_data, buf, buf_len);
516 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
518 wl1271_warning("cmd set_template failed: %d", ret);
529 int wl1271_cmd_build_null_data(struct wl1271 *wl)
531 struct sk_buff *skb = NULL;
537 if (wl->bss_type == BSS_TYPE_IBSS) {
538 size = sizeof(struct wl12xx_null_data_template);
541 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
548 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
554 wl1271_warning("cmd buld null data failed %d", ret);
560 int wl1271_cmd_build_klv_null_data(struct wl1271 *wl)
562 struct sk_buff *skb = NULL;
565 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
569 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
571 CMD_TEMPL_KLV_IDX_NULL_DATA,
577 wl1271_warning("cmd build klv null data failed %d", ret);
583 int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
588 skb = ieee80211_pspoll_get(wl->hw, wl->vif);
592 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
593 skb->len, 0, wl->basic_rate_set);
600 int wl1271_cmd_build_probe_req(struct wl1271 *wl,
601 const u8 *ssid, size_t ssid_len,
602 const u8 *ie, size_t ie_len, u8 band)
607 skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
614 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
616 if (band == IEEE80211_BAND_2GHZ)
617 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
618 skb->data, skb->len, 0,
619 wl->conf.tx.basic_rate);
621 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
622 skb->data, skb->len, 0,
623 wl->conf.tx.basic_rate_5);
630 struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
636 skb = ieee80211_ap_probereq_get(wl->hw, wl->vif);
640 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
642 if (wl->band == IEEE80211_BAND_2GHZ)
643 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
644 skb->data, skb->len, 0,
645 wl->conf.tx.basic_rate);
647 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
648 skb->data, skb->len, 0,
649 wl->conf.tx.basic_rate_5);
652 wl1271_error("Unable to set ap probe request template.");
658 int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr)
661 struct wl12xx_arp_rsp_template tmpl;
662 struct ieee80211_hdr_3addr *hdr;
663 struct arphdr *arp_hdr;
665 memset(&tmpl, 0, sizeof(tmpl));
667 /* mac80211 header */
669 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
670 IEEE80211_STYPE_DATA |
671 IEEE80211_FCTL_TODS);
672 memcpy(hdr->addr1, wl->vif->bss_conf.bssid, ETH_ALEN);
673 memcpy(hdr->addr2, wl->vif->addr, ETH_ALEN);
674 memset(hdr->addr3, 0xff, ETH_ALEN);
677 memcpy(tmpl.llc_hdr, rfc1042_header, sizeof(rfc1042_header));
678 tmpl.llc_type = cpu_to_be16(ETH_P_ARP);
681 arp_hdr = &tmpl.arp_hdr;
682 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
683 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
684 arp_hdr->ar_hln = ETH_ALEN;
686 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
689 memcpy(tmpl.sender_hw, wl->vif->addr, ETH_ALEN);
690 tmpl.sender_ip = ip_addr;
692 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP,
693 &tmpl, sizeof(tmpl), 0,
699 int wl1271_build_qos_null_data(struct wl1271 *wl)
701 struct ieee80211_qos_hdr template;
703 memset(&template, 0, sizeof(template));
705 memcpy(template.addr1, wl->bssid, ETH_ALEN);
706 memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
707 memcpy(template.addr3, wl->bssid, ETH_ALEN);
709 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
710 IEEE80211_STYPE_QOS_NULLFUNC |
711 IEEE80211_FCTL_TODS);
713 /* FIXME: not sure what priority to use here */
714 template.qos_ctrl = cpu_to_le16(0);
716 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
721 int wl1271_cmd_set_sta_default_wep_key(struct wl1271 *wl, u8 id)
723 struct wl1271_cmd_set_sta_keys *cmd;
726 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
728 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
735 cmd->key_action = cpu_to_le16(KEY_SET_ID);
736 cmd->key_type = KEY_WEP;
738 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
740 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
750 int wl1271_cmd_set_ap_default_wep_key(struct wl1271 *wl, u8 id)
752 struct wl1271_cmd_set_ap_keys *cmd;
755 wl1271_debug(DEBUG_CMD, "cmd set_ap_default_wep_key %d", id);
757 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
763 cmd->hlid = WL1271_AP_BROADCAST_HLID;
765 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
766 cmd->key_action = cpu_to_le16(KEY_SET_ID);
767 cmd->key_type = KEY_WEP;
769 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
771 wl1271_warning("cmd set_ap_default_wep_key failed: %d", ret);
781 int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
782 u8 key_size, const u8 *key, const u8 *addr,
783 u32 tx_seq_32, u16 tx_seq_16)
785 struct wl1271_cmd_set_sta_keys *cmd;
788 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
794 if (key_type != KEY_WEP)
795 memcpy(cmd->addr, addr, ETH_ALEN);
797 cmd->key_action = cpu_to_le16(action);
798 cmd->key_size = key_size;
799 cmd->key_type = key_type;
801 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
802 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
804 /* we have only one SSID profile */
805 cmd->ssid_profile = 0;
809 if (key_type == KEY_TKIP) {
811 * We get the key in the following form:
812 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
813 * but the target is expecting:
814 * TKIP - RX MIC - TX MIC
816 memcpy(cmd->key, key, 16);
817 memcpy(cmd->key + 16, key + 24, 8);
818 memcpy(cmd->key + 24, key + 16, 8);
821 memcpy(cmd->key, key, key_size);
824 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
826 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
828 wl1271_warning("could not set keys");
838 int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
839 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
842 struct wl1271_cmd_set_ap_keys *cmd;
846 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
850 if (hlid == WL1271_AP_BROADCAST_HLID) {
851 if (key_type == KEY_WEP)
852 lid_type = WEP_DEFAULT_LID_TYPE;
854 lid_type = BROADCAST_LID_TYPE;
856 lid_type = UNICAST_LID_TYPE;
859 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
860 " hlid: %d", (int)action, (int)id, (int)lid_type,
861 (int)key_type, (int)hlid);
863 cmd->lid_key_type = lid_type;
865 cmd->key_action = cpu_to_le16(action);
866 cmd->key_size = key_size;
867 cmd->key_type = key_type;
869 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
870 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
872 if (key_type == KEY_TKIP) {
874 * We get the key in the following form:
875 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
876 * but the target is expecting:
877 * TKIP - RX MIC - TX MIC
879 memcpy(cmd->key, key, 16);
880 memcpy(cmd->key + 16, key + 24, 8);
881 memcpy(cmd->key + 24, key + 16, 8);
883 memcpy(cmd->key, key, key_size);
886 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
888 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
890 wl1271_warning("could not set ap keys");
899 int wl1271_cmd_disconnect(struct wl1271 *wl)
901 struct wl1271_cmd_disconnect *cmd;
904 wl1271_debug(DEBUG_CMD, "cmd disconnect");
906 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
912 cmd->rx_config_options = cpu_to_le32(wl->rx_config);
913 cmd->rx_filter_options = cpu_to_le32(wl->rx_filter);
914 /* disconnect reason is not used in immediate disconnections */
915 cmd->type = DISCONNECT_IMMEDIATE;
917 ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
919 wl1271_error("failed to send disconnect command");
923 ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
925 wl1271_error("cmd disconnect event completion error");
934 int wl1271_cmd_set_sta_state(struct wl1271 *wl)
936 struct wl1271_cmd_set_sta_state *cmd;
939 wl1271_debug(DEBUG_CMD, "cmd set sta state");
941 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
947 cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
949 ret = wl1271_cmd_send(wl, CMD_SET_STA_STATE, cmd, sizeof(*cmd), 0);
951 wl1271_error("failed to send set STA state command");
962 int wl1271_cmd_start_bss(struct wl1271 *wl)
964 struct wl1271_cmd_bss_start *cmd;
965 struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf;
968 wl1271_debug(DEBUG_CMD, "cmd start bss");
971 * FIXME: We currently do not support hidden SSID. The real SSID
972 * should be fetched from mac80211 first.
974 if (wl->ssid_len == 0) {
975 wl1271_warning("Hidden SSID currently not supported for AP");
980 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
986 memcpy(cmd->bssid, bss_conf->bssid, ETH_ALEN);
988 cmd->aging_period = cpu_to_le16(WL1271_AP_DEF_INACTIV_SEC);
989 cmd->bss_index = WL1271_AP_BSS_INDEX;
990 cmd->global_hlid = WL1271_AP_GLOBAL_HLID;
991 cmd->broadcast_hlid = WL1271_AP_BROADCAST_HLID;
992 cmd->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
993 cmd->beacon_interval = cpu_to_le16(wl->beacon_int);
994 cmd->dtim_interval = bss_conf->dtim_period;
995 cmd->beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
996 cmd->channel = wl->channel;
997 cmd->ssid_len = wl->ssid_len;
998 cmd->ssid_type = SSID_TYPE_PUBLIC;
999 memcpy(cmd->ssid, wl->ssid, wl->ssid_len);
1002 case IEEE80211_BAND_2GHZ:
1003 cmd->band = RADIO_BAND_2_4GHZ;
1005 case IEEE80211_BAND_5GHZ:
1006 cmd->band = RADIO_BAND_5GHZ;
1009 wl1271_warning("bss start - unknown band: %d", (int)wl->band);
1010 cmd->band = RADIO_BAND_2_4GHZ;
1014 ret = wl1271_cmd_send(wl, CMD_BSS_START, cmd, sizeof(*cmd), 0);
1016 wl1271_error("failed to initiate cmd start bss");
1027 int wl1271_cmd_stop_bss(struct wl1271 *wl)
1029 struct wl1271_cmd_bss_start *cmd;
1032 wl1271_debug(DEBUG_CMD, "cmd stop bss");
1034 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1040 cmd->bss_index = WL1271_AP_BSS_INDEX;
1042 ret = wl1271_cmd_send(wl, CMD_BSS_STOP, cmd, sizeof(*cmd), 0);
1044 wl1271_error("failed to initiate cmd stop bss");
1055 int wl1271_cmd_add_sta(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid)
1057 struct wl1271_cmd_add_sta *cmd;
1060 wl1271_debug(DEBUG_CMD, "cmd add sta %d", (int)hlid);
1062 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1068 /* currently we don't support UAPSD */
1071 memcpy(cmd->addr, sta->addr, ETH_ALEN);
1072 cmd->bss_index = WL1271_AP_BSS_INDEX;
1073 cmd->aid = sta->aid;
1077 * FIXME: Does STA support QOS? We need to propagate this info from
1078 * hostapd. Currently not that important since this is only used for
1079 * sending the correct flavor of null-data packet in response to a
1084 cmd->supported_rates = cpu_to_le32(wl1271_tx_enabled_rates_get(wl,
1085 sta->supp_rates[wl->band]));
1087 wl1271_debug(DEBUG_CMD, "new sta rates: 0x%x", cmd->supported_rates);
1089 ret = wl1271_cmd_send(wl, CMD_ADD_STA, cmd, sizeof(*cmd), 0);
1091 wl1271_error("failed to initiate cmd add sta");
1102 int wl1271_cmd_remove_sta(struct wl1271 *wl, u8 hlid)
1104 struct wl1271_cmd_remove_sta *cmd;
1107 wl1271_debug(DEBUG_CMD, "cmd remove sta %d", (int)hlid);
1109 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1116 /* We never send a deauth, mac80211 is in charge of this */
1117 cmd->reason_opcode = 0;
1118 cmd->send_deauth_flag = 0;
1120 ret = wl1271_cmd_send(wl, CMD_REMOVE_STA, cmd, sizeof(*cmd), 0);
1122 wl1271_error("failed to initiate cmd remove sta");
1127 * We are ok with a timeout here. The event is sometimes not sent
1128 * due to a firmware bug.
1130 wl1271_cmd_wait_for_event_or_timeout(wl, STA_REMOVE_COMPLETE_EVENT_ID);