Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of wl1271 |
| 3 | * |
Luciano Coelho | 2f826f5 | 2010-03-26 12:53:21 +0200 | [diff] [blame] | 4 | * Copyright (C) 2009-2010 Nokia Corporation |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5 | * |
| 6 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> |
| 7 | * |
| 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. |
| 11 | * |
| 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. |
| 16 | * |
| 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 |
| 20 | * 02110-1301 USA |
| 21 | * |
| 22 | */ |
| 23 | |
| 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> |
Kalle Valo | 023e082 | 2010-03-18 12:26:36 +0200 | [diff] [blame] | 29 | #include <linux/ieee80211.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 31 | |
| 32 | #include "wl1271.h" |
| 33 | #include "wl1271_reg.h" |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 34 | #include "wl1271_io.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 35 | #include "wl1271_acx.h" |
| 36 | #include "wl12xx_80211.h" |
| 37 | #include "wl1271_cmd.h" |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 38 | #include "wl1271_event.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 39 | |
Juuso Oikarinen | 16092b5 | 2010-04-28 09:49:59 +0300 | [diff] [blame] | 40 | #define WL1271_CMD_FAST_POLL_COUNT 50 |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * send command to firmware |
| 44 | * |
| 45 | * @wl: wl struct |
| 46 | * @id: command id |
| 47 | * @buf: buffer containing the command, must work with dma |
| 48 | * @len: length of the buffer |
| 49 | */ |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 50 | int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len, |
| 51 | size_t res_len) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 52 | { |
| 53 | struct wl1271_cmd_header *cmd; |
| 54 | unsigned long timeout; |
| 55 | u32 intr; |
| 56 | int ret = 0; |
Juuso Oikarinen | ad150e9 | 2009-11-02 20:22:12 +0200 | [diff] [blame] | 57 | u16 status; |
Saravanan Dhanabal | bc0f03e | 2010-03-26 12:53:33 +0200 | [diff] [blame] | 58 | u16 poll_count = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 59 | |
| 60 | cmd = buf; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 61 | cmd->id = cpu_to_le16(id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 62 | cmd->status = 0; |
| 63 | |
| 64 | WARN_ON(len % 4 != 0); |
| 65 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 66 | wl1271_write(wl, wl->cmd_box_addr, buf, len, false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 67 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 68 | wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 69 | |
| 70 | timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT); |
| 71 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 72 | intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 73 | while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) { |
| 74 | if (time_after(jiffies, timeout)) { |
| 75 | wl1271_error("command complete timeout"); |
| 76 | ret = -ETIMEDOUT; |
| 77 | goto out; |
| 78 | } |
| 79 | |
Saravanan Dhanabal | bc0f03e | 2010-03-26 12:53:33 +0200 | [diff] [blame] | 80 | poll_count++; |
Juuso Oikarinen | 16092b5 | 2010-04-28 09:49:59 +0300 | [diff] [blame] | 81 | if (poll_count < WL1271_CMD_FAST_POLL_COUNT) |
| 82 | udelay(10); |
| 83 | else |
| 84 | msleep(1); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 85 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 86 | intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 87 | } |
| 88 | |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 89 | /* read back the status code of the command */ |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 90 | if (res_len == 0) |
| 91 | res_len = sizeof(struct wl1271_cmd_header); |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 92 | wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false); |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 93 | |
Juuso Oikarinen | ad150e9 | 2009-11-02 20:22:12 +0200 | [diff] [blame] | 94 | status = le16_to_cpu(cmd->status); |
| 95 | if (status != CMD_STATUS_SUCCESS) { |
| 96 | wl1271_error("command execute failure %d", status); |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 97 | ieee80211_queue_work(wl->hw, &wl->recovery_work); |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 98 | ret = -EIO; |
| 99 | } |
| 100 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 101 | wl1271_write32(wl, ACX_REG_INTERRUPT_ACK, |
| 102 | WL1271_ACX_INTR_CMD_COMPLETE); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 103 | |
| 104 | out: |
| 105 | return ret; |
| 106 | } |
| 107 | |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 108 | int wl1271_cmd_general_parms(struct wl1271 *wl) |
| 109 | { |
| 110 | struct wl1271_general_parms_cmd *gen_parms; |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 111 | struct wl1271_ini_general_params *gp = &wl->nvs->general_params; |
| 112 | bool answer = false; |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 113 | int ret; |
| 114 | |
Juuso Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 115 | if (!wl->nvs) |
| 116 | return -ENODEV; |
| 117 | |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 118 | gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL); |
| 119 | if (!gen_parms) |
| 120 | return -ENOMEM; |
| 121 | |
| 122 | gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM; |
| 123 | |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 124 | memcpy(&gen_parms->general_params, gp, sizeof(*gp)); |
Luciano Coelho | 76c0f8d | 2009-12-11 15:40:41 +0200 | [diff] [blame] | 125 | |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 126 | if (gp->tx_bip_fem_auto_detect) |
| 127 | answer = true; |
| 128 | |
| 129 | ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer); |
| 130 | if (ret < 0) { |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 131 | wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed"); |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 132 | goto out; |
| 133 | } |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 134 | |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 135 | gp->tx_bip_fem_manufacturer = |
| 136 | gen_parms->general_params.tx_bip_fem_manufacturer; |
| 137 | |
| 138 | wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n", |
| 139 | answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer); |
| 140 | |
| 141 | out: |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 142 | kfree(gen_parms); |
| 143 | return ret; |
| 144 | } |
| 145 | |
| 146 | int wl1271_cmd_radio_parms(struct wl1271 *wl) |
| 147 | { |
| 148 | struct wl1271_radio_parms_cmd *radio_parms; |
Luciano Coelho | e6b190f | 2010-07-08 17:50:01 +0300 | [diff] [blame] | 149 | struct wl1271_ini_general_params *gp = &wl->nvs->general_params; |
Juuso Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 150 | int ret; |
| 151 | |
| 152 | if (!wl->nvs) |
| 153 | return -ENODEV; |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 154 | |
| 155 | radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL); |
| 156 | if (!radio_parms) |
| 157 | return -ENOMEM; |
| 158 | |
| 159 | radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM; |
| 160 | |
Juuso Oikarinen | a7da74f | 2010-05-14 10:46:23 +0300 | [diff] [blame] | 161 | /* 2.4GHz parameters */ |
Juuso Oikarinen | eb70eb7 | 2010-05-14 10:46:22 +0300 | [diff] [blame] | 162 | memcpy(&radio_parms->static_params_2, &wl->nvs->stat_radio_params_2, |
| 163 | sizeof(struct wl1271_ini_band_params_2)); |
| 164 | memcpy(&radio_parms->dyn_params_2, |
Luciano Coelho | e6b190f | 2010-07-08 17:50:01 +0300 | [diff] [blame] | 165 | &wl->nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params, |
Juuso Oikarinen | eb70eb7 | 2010-05-14 10:46:22 +0300 | [diff] [blame] | 166 | sizeof(struct wl1271_ini_fem_params_2)); |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 167 | |
Juuso Oikarinen | a7da74f | 2010-05-14 10:46:23 +0300 | [diff] [blame] | 168 | /* 5GHz parameters */ |
| 169 | memcpy(&radio_parms->static_params_5, |
| 170 | &wl->nvs->stat_radio_params_5, |
| 171 | sizeof(struct wl1271_ini_band_params_5)); |
| 172 | memcpy(&radio_parms->dyn_params_5, |
Luciano Coelho | e6b190f | 2010-07-08 17:50:01 +0300 | [diff] [blame] | 173 | &wl->nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params, |
Juuso Oikarinen | a7da74f | 2010-05-14 10:46:23 +0300 | [diff] [blame] | 174 | sizeof(struct wl1271_ini_fem_params_5)); |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 175 | |
| 176 | wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ", |
| 177 | radio_parms, sizeof(*radio_parms)); |
| 178 | |
| 179 | ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0); |
| 180 | if (ret < 0) |
| 181 | wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed"); |
| 182 | |
| 183 | kfree(radio_parms); |
| 184 | return ret; |
| 185 | } |
| 186 | |
Juuso Oikarinen | 644a486 | 2010-10-05 13:11:56 +0200 | [diff] [blame] | 187 | int wl1271_cmd_ext_radio_parms(struct wl1271 *wl) |
| 188 | { |
| 189 | struct wl1271_ext_radio_parms_cmd *ext_radio_parms; |
| 190 | struct conf_rf_settings *rf = &wl->conf.rf; |
| 191 | int ret; |
| 192 | |
| 193 | if (!wl->nvs) |
| 194 | return -ENODEV; |
| 195 | |
| 196 | ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL); |
| 197 | if (!ext_radio_parms) |
| 198 | return -ENOMEM; |
| 199 | |
| 200 | ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM; |
| 201 | |
| 202 | memcpy(ext_radio_parms->tx_per_channel_power_compensation_2, |
| 203 | rf->tx_per_channel_power_compensation_2, |
| 204 | CONF_TX_PWR_COMPENSATION_LEN_2); |
| 205 | memcpy(ext_radio_parms->tx_per_channel_power_compensation_5, |
| 206 | rf->tx_per_channel_power_compensation_5, |
| 207 | CONF_TX_PWR_COMPENSATION_LEN_5); |
| 208 | |
| 209 | wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ", |
| 210 | ext_radio_parms, sizeof(*ext_radio_parms)); |
| 211 | |
| 212 | ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0); |
| 213 | if (ret < 0) |
| 214 | wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed"); |
| 215 | |
| 216 | kfree(ext_radio_parms); |
| 217 | return ret; |
| 218 | } |
| 219 | |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 220 | /* |
| 221 | * Poll the mailbox event field until any of the bits in the mask is set or a |
| 222 | * timeout occurs (WL1271_EVENT_TIMEOUT in msecs) |
| 223 | */ |
| 224 | static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask) |
| 225 | { |
| 226 | u32 events_vector, event; |
| 227 | unsigned long timeout; |
| 228 | |
| 229 | timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT); |
| 230 | |
| 231 | do { |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 232 | if (time_after(jiffies, timeout)) { |
| 233 | ieee80211_queue_work(wl->hw, &wl->recovery_work); |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 234 | return -ETIMEDOUT; |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 235 | } |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 236 | |
| 237 | msleep(1); |
| 238 | |
| 239 | /* read from both event fields */ |
| 240 | wl1271_read(wl, wl->mbox_ptr[0], &events_vector, |
| 241 | sizeof(events_vector), false); |
| 242 | event = events_vector & mask; |
| 243 | wl1271_read(wl, wl->mbox_ptr[1], &events_vector, |
| 244 | sizeof(events_vector), false); |
| 245 | event |= events_vector & mask; |
| 246 | } while (!event); |
| 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
Juuso Oikarinen | 1530549 | 2010-02-22 08:38:32 +0200 | [diff] [blame] | 251 | int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 252 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 253 | struct wl1271_cmd_join *join; |
| 254 | int ret, i; |
| 255 | u8 *bssid; |
| 256 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 257 | join = kzalloc(sizeof(*join), GFP_KERNEL); |
| 258 | if (!join) { |
| 259 | ret = -ENOMEM; |
| 260 | goto out; |
| 261 | } |
| 262 | |
| 263 | wl1271_debug(DEBUG_CMD, "cmd join"); |
| 264 | |
| 265 | /* Reverse order BSSID */ |
| 266 | bssid = (u8 *) &join->bssid_lsb; |
| 267 | for (i = 0; i < ETH_ALEN; i++) |
| 268 | bssid[i] = wl->bssid[ETH_ALEN - i - 1]; |
| 269 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 270 | join->rx_config_options = cpu_to_le32(wl->rx_config); |
| 271 | join->rx_filter_options = cpu_to_le32(wl->rx_filter); |
Juuso Oikarinen | 1530549 | 2010-02-22 08:38:32 +0200 | [diff] [blame] | 272 | join->bss_type = bss_type; |
Luciano Coelho | 23a7a51 | 2010-04-28 09:50:02 +0300 | [diff] [blame] | 273 | join->basic_rate_set = cpu_to_le32(wl->basic_rate_set); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 274 | |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 275 | if (wl->band == IEEE80211_BAND_5GHZ) |
Teemu Paasikivi | a410264 | 2009-10-13 12:47:51 +0300 | [diff] [blame] | 276 | join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 277 | |
Juuso Oikarinen | 60e84c2 | 2010-03-26 12:53:25 +0200 | [diff] [blame] | 278 | join->beacon_interval = cpu_to_le16(wl->beacon_int); |
Luciano Coelho | ae751ba | 2009-10-12 15:08:57 +0300 | [diff] [blame] | 279 | join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD; |
Teemu Paasikivi | a410264 | 2009-10-13 12:47:51 +0300 | [diff] [blame] | 280 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 281 | join->channel = wl->channel; |
| 282 | join->ssid_len = wl->ssid_len; |
| 283 | memcpy(join->ssid, wl->ssid, wl->ssid_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 284 | |
| 285 | join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET; |
| 286 | |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 287 | /* reset TX security counters */ |
| 288 | wl->tx_security_last_seq = 0; |
Juuso Oikarinen | 04e36fc | 2010-02-22 08:38:40 +0200 | [diff] [blame] | 289 | wl->tx_security_seq = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 290 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 291 | ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 292 | if (ret < 0) { |
| 293 | wl1271_error("failed to initiate cmd join"); |
| 294 | goto out_free; |
| 295 | } |
| 296 | |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 297 | ret = wl1271_cmd_wait_for_event(wl, JOIN_EVENT_COMPLETE_ID); |
| 298 | if (ret < 0) |
| 299 | wl1271_error("cmd join event completion error"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 300 | |
| 301 | out_free: |
| 302 | kfree(join); |
| 303 | |
| 304 | out: |
| 305 | return ret; |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * send test command to firmware |
| 310 | * |
| 311 | * @wl: wl struct |
| 312 | * @buf: buffer containing the command, with all headers, must work with dma |
| 313 | * @len: length of the buffer |
| 314 | * @answer: is answer needed |
| 315 | */ |
| 316 | int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer) |
| 317 | { |
| 318 | int ret; |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 319 | size_t res_len = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 320 | |
| 321 | wl1271_debug(DEBUG_CMD, "cmd test"); |
| 322 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 323 | if (answer) |
| 324 | res_len = buf_len; |
| 325 | |
| 326 | ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 327 | |
| 328 | if (ret < 0) { |
| 329 | wl1271_warning("TEST command failed"); |
| 330 | return ret; |
| 331 | } |
| 332 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 333 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | /** |
| 337 | * read acx from firmware |
| 338 | * |
| 339 | * @wl: wl struct |
| 340 | * @id: acx id |
| 341 | * @buf: buffer for the response, including all headers, must work with dma |
| 342 | * @len: lenght of buf |
| 343 | */ |
| 344 | int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len) |
| 345 | { |
| 346 | struct acx_header *acx = buf; |
| 347 | int ret; |
| 348 | |
| 349 | wl1271_debug(DEBUG_CMD, "cmd interrogate"); |
| 350 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 351 | acx->id = cpu_to_le16(id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 352 | |
| 353 | /* payload length, does not include any headers */ |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 354 | acx->len = cpu_to_le16(len - sizeof(*acx)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 355 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 356 | ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len); |
| 357 | if (ret < 0) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 358 | wl1271_error("INTERROGATE command failed"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 359 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 360 | return ret; |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * write acx value to firmware |
| 365 | * |
| 366 | * @wl: wl struct |
| 367 | * @id: acx id |
| 368 | * @buf: buffer containing acx, including all headers, must work with dma |
| 369 | * @len: length of buf |
| 370 | */ |
| 371 | int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len) |
| 372 | { |
| 373 | struct acx_header *acx = buf; |
| 374 | int ret; |
| 375 | |
| 376 | wl1271_debug(DEBUG_CMD, "cmd configure"); |
| 377 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 378 | acx->id = cpu_to_le16(id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 379 | |
| 380 | /* payload length, does not include any headers */ |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 381 | acx->len = cpu_to_le16(len - sizeof(*acx)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 382 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 383 | ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 384 | if (ret < 0) { |
| 385 | wl1271_warning("CONFIGURE command NOK"); |
| 386 | return ret; |
| 387 | } |
| 388 | |
| 389 | return 0; |
| 390 | } |
| 391 | |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 392 | int wl1271_cmd_data_path(struct wl1271 *wl, bool enable) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 393 | { |
| 394 | struct cmd_enabledisable_path *cmd; |
| 395 | int ret; |
| 396 | u16 cmd_rx, cmd_tx; |
| 397 | |
| 398 | wl1271_debug(DEBUG_CMD, "cmd data path"); |
| 399 | |
| 400 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 401 | if (!cmd) { |
| 402 | ret = -ENOMEM; |
| 403 | goto out; |
| 404 | } |
| 405 | |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 406 | /* the channel here is only used for calibration, so hardcoded to 1 */ |
| 407 | cmd->channel = 1; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 408 | |
| 409 | if (enable) { |
| 410 | cmd_rx = CMD_ENABLE_RX; |
| 411 | cmd_tx = CMD_ENABLE_TX; |
| 412 | } else { |
| 413 | cmd_rx = CMD_DISABLE_RX; |
| 414 | cmd_tx = CMD_DISABLE_TX; |
| 415 | } |
| 416 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 417 | ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 418 | if (ret < 0) { |
| 419 | wl1271_error("rx %s cmd for channel %d failed", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 420 | enable ? "start" : "stop", cmd->channel); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 421 | goto out; |
| 422 | } |
| 423 | |
| 424 | wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 425 | enable ? "start" : "stop", cmd->channel); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 426 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 427 | ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 428 | if (ret < 0) { |
| 429 | wl1271_error("tx %s cmd for channel %d failed", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 430 | enable ? "start" : "stop", cmd->channel); |
Juuso Oikarinen | 1b00f2b | 2010-03-26 12:53:17 +0200 | [diff] [blame] | 431 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 435 | enable ? "start" : "stop", cmd->channel); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 436 | |
| 437 | out: |
| 438 | kfree(cmd); |
| 439 | return ret; |
| 440 | } |
| 441 | |
Juuso Oikarinen | 65cddbf1 | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 442 | int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode, u32 rates, bool send) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 443 | { |
| 444 | struct wl1271_cmd_ps_params *ps_params = NULL; |
| 445 | int ret = 0; |
| 446 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 447 | wl1271_debug(DEBUG_CMD, "cmd set ps mode"); |
| 448 | |
| 449 | ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL); |
| 450 | if (!ps_params) { |
| 451 | ret = -ENOMEM; |
| 452 | goto out; |
| 453 | } |
| 454 | |
| 455 | ps_params->ps_mode = ps_mode; |
Juuso Oikarinen | d8c42c0 | 2010-02-18 13:25:36 +0200 | [diff] [blame] | 456 | ps_params->send_null_data = send; |
Juuso Oikarinen | 8eab7b4 | 2010-09-24 03:10:11 +0200 | [diff] [blame] | 457 | ps_params->retries = wl->conf.conn.psm_entry_nullfunc_retries; |
| 458 | ps_params->hang_over_period = wl->conf.conn.psm_entry_hangover_period; |
Juuso Oikarinen | 65cddbf1 | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 459 | ps_params->null_data_rate = cpu_to_le32(rates); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 460 | |
| 461 | ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params, |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 462 | sizeof(*ps_params), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 463 | if (ret < 0) { |
| 464 | wl1271_error("cmd set_ps_mode failed"); |
| 465 | goto out; |
| 466 | } |
| 467 | |
| 468 | out: |
| 469 | kfree(ps_params); |
| 470 | return ret; |
| 471 | } |
| 472 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 473 | int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 474 | void *buf, size_t buf_len, int index, u32 rates) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 475 | { |
| 476 | struct wl1271_cmd_template_set *cmd; |
| 477 | int ret = 0; |
| 478 | |
| 479 | wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id); |
| 480 | |
| 481 | WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE); |
| 482 | buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE); |
| 483 | |
| 484 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 485 | if (!cmd) { |
| 486 | ret = -ENOMEM; |
| 487 | goto out; |
| 488 | } |
| 489 | |
| 490 | cmd->len = cpu_to_le16(buf_len); |
| 491 | cmd->template_type = template_id; |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 492 | cmd->enabled_rates = cpu_to_le32(rates); |
Juuso Oikarinen | 45b531a | 2009-10-13 12:47:41 +0300 | [diff] [blame] | 493 | cmd->short_retry_limit = wl->conf.tx.rc_conf.short_retry_limit; |
| 494 | cmd->long_retry_limit = wl->conf.tx.rc_conf.long_retry_limit; |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 495 | cmd->index = index; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 496 | |
| 497 | if (buf) |
| 498 | memcpy(cmd->template_data, buf, buf_len); |
| 499 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 500 | ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 501 | if (ret < 0) { |
| 502 | wl1271_warning("cmd set_template failed: %d", ret); |
| 503 | goto out_free; |
| 504 | } |
| 505 | |
| 506 | out_free: |
| 507 | kfree(cmd); |
| 508 | |
| 509 | out: |
| 510 | return ret; |
| 511 | } |
| 512 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 513 | int wl1271_cmd_build_null_data(struct wl1271 *wl) |
| 514 | { |
Juuso Oikarinen | a0cb7be | 2010-03-18 12:26:44 +0200 | [diff] [blame] | 515 | struct sk_buff *skb = NULL; |
| 516 | int size; |
| 517 | void *ptr; |
| 518 | int ret = -ENOMEM; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 519 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 520 | |
Juuso Oikarinen | a0cb7be | 2010-03-18 12:26:44 +0200 | [diff] [blame] | 521 | if (wl->bss_type == BSS_TYPE_IBSS) { |
| 522 | size = sizeof(struct wl12xx_null_data_template); |
| 523 | ptr = NULL; |
| 524 | } else { |
| 525 | skb = ieee80211_nullfunc_get(wl->hw, wl->vif); |
| 526 | if (!skb) |
| 527 | goto out; |
| 528 | size = skb->len; |
| 529 | ptr = skb->data; |
| 530 | } |
| 531 | |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 532 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0, |
Juuso Oikarinen | 8eab7b4 | 2010-09-24 03:10:11 +0200 | [diff] [blame] | 533 | wl->basic_rate); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 534 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 535 | out: |
| 536 | dev_kfree_skb(skb); |
Juuso Oikarinen | a0cb7be | 2010-03-18 12:26:44 +0200 | [diff] [blame] | 537 | if (ret) |
| 538 | wl1271_warning("cmd buld null data failed %d", ret); |
| 539 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 540 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 541 | |
| 542 | } |
| 543 | |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 544 | int wl1271_cmd_build_klv_null_data(struct wl1271 *wl) |
| 545 | { |
| 546 | struct sk_buff *skb = NULL; |
| 547 | int ret = -ENOMEM; |
| 548 | |
| 549 | skb = ieee80211_nullfunc_get(wl->hw, wl->vif); |
| 550 | if (!skb) |
| 551 | goto out; |
| 552 | |
| 553 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, |
| 554 | skb->data, skb->len, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 555 | CMD_TEMPL_KLV_IDX_NULL_DATA, |
Juuso Oikarinen | 8eab7b4 | 2010-09-24 03:10:11 +0200 | [diff] [blame] | 556 | wl->basic_rate); |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 557 | |
| 558 | out: |
| 559 | dev_kfree_skb(skb); |
| 560 | if (ret) |
| 561 | wl1271_warning("cmd build klv null data failed %d", ret); |
| 562 | |
| 563 | return ret; |
| 564 | |
| 565 | } |
| 566 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 567 | int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid) |
| 568 | { |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 569 | struct sk_buff *skb; |
| 570 | int ret = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 571 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 572 | skb = ieee80211_pspoll_get(wl->hw, wl->vif); |
| 573 | if (!skb) |
| 574 | goto out; |
Juuso Oikarinen | c3fea19 | 2009-10-08 21:56:22 +0300 | [diff] [blame] | 575 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 576 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data, |
Juuso Oikarinen | 849923f | 2010-07-08 17:49:59 +0300 | [diff] [blame] | 577 | skb->len, 0, wl->basic_rate_set); |
Juuso Oikarinen | c3fea19 | 2009-10-08 21:56:22 +0300 | [diff] [blame] | 578 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 579 | out: |
| 580 | dev_kfree_skb(skb); |
| 581 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 582 | } |
| 583 | |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 584 | int wl1271_cmd_build_probe_req(struct wl1271 *wl, |
| 585 | const u8 *ssid, size_t ssid_len, |
| 586 | const u8 *ie, size_t ie_len, u8 band) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 587 | { |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 588 | struct sk_buff *skb; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 589 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 590 | |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 591 | skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len, |
| 592 | ie, ie_len); |
| 593 | if (!skb) { |
| 594 | ret = -ENOMEM; |
| 595 | goto out; |
| 596 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 597 | |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 598 | wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 599 | |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 600 | if (band == IEEE80211_BAND_2GHZ) |
| 601 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 602 | skb->data, skb->len, 0, |
| 603 | wl->conf.tx.basic_rate); |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 604 | else |
| 605 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 606 | skb->data, skb->len, 0, |
| 607 | wl->conf.tx.basic_rate_5); |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 608 | |
| 609 | out: |
| 610 | dev_kfree_skb(skb); |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 611 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 612 | } |
| 613 | |
Kalle Valo | 023e082 | 2010-03-18 12:26:36 +0200 | [diff] [blame] | 614 | int wl1271_build_qos_null_data(struct wl1271 *wl) |
| 615 | { |
| 616 | struct ieee80211_qos_hdr template; |
| 617 | |
| 618 | memset(&template, 0, sizeof(template)); |
| 619 | |
| 620 | memcpy(template.addr1, wl->bssid, ETH_ALEN); |
| 621 | memcpy(template.addr2, wl->mac_addr, ETH_ALEN); |
| 622 | memcpy(template.addr3, wl->bssid, ETH_ALEN); |
| 623 | |
| 624 | template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 625 | IEEE80211_STYPE_QOS_NULLFUNC | |
| 626 | IEEE80211_FCTL_TODS); |
| 627 | |
| 628 | /* FIXME: not sure what priority to use here */ |
| 629 | template.qos_ctrl = cpu_to_le16(0); |
| 630 | |
| 631 | return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 632 | sizeof(template), 0, |
Juuso Oikarinen | 8eab7b4 | 2010-09-24 03:10:11 +0200 | [diff] [blame] | 633 | wl->basic_rate); |
Kalle Valo | 023e082 | 2010-03-18 12:26:36 +0200 | [diff] [blame] | 634 | } |
| 635 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 636 | int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id) |
| 637 | { |
| 638 | struct wl1271_cmd_set_keys *cmd; |
| 639 | int ret = 0; |
| 640 | |
| 641 | wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id); |
| 642 | |
| 643 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 644 | if (!cmd) { |
| 645 | ret = -ENOMEM; |
| 646 | goto out; |
| 647 | } |
| 648 | |
| 649 | cmd->id = id; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 650 | cmd->key_action = cpu_to_le16(KEY_SET_ID); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 651 | cmd->key_type = KEY_WEP; |
| 652 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 653 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 654 | if (ret < 0) { |
| 655 | wl1271_warning("cmd set_default_wep_key failed: %d", ret); |
| 656 | goto out; |
| 657 | } |
| 658 | |
| 659 | out: |
| 660 | kfree(cmd); |
| 661 | |
| 662 | return ret; |
| 663 | } |
| 664 | |
| 665 | int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 666 | u8 key_size, const u8 *key, const u8 *addr, |
| 667 | u32 tx_seq_32, u16 tx_seq_16) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 668 | { |
| 669 | struct wl1271_cmd_set_keys *cmd; |
| 670 | int ret = 0; |
| 671 | |
| 672 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 673 | if (!cmd) { |
| 674 | ret = -ENOMEM; |
| 675 | goto out; |
| 676 | } |
| 677 | |
| 678 | if (key_type != KEY_WEP) |
| 679 | memcpy(cmd->addr, addr, ETH_ALEN); |
| 680 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 681 | cmd->key_action = cpu_to_le16(action); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 682 | cmd->key_size = key_size; |
| 683 | cmd->key_type = key_type; |
| 684 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 685 | cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16); |
| 686 | cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32); |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 687 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 688 | /* we have only one SSID profile */ |
| 689 | cmd->ssid_profile = 0; |
| 690 | |
| 691 | cmd->id = id; |
| 692 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 693 | if (key_type == KEY_TKIP) { |
| 694 | /* |
| 695 | * We get the key in the following form: |
| 696 | * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes) |
| 697 | * but the target is expecting: |
| 698 | * TKIP - RX MIC - TX MIC |
| 699 | */ |
| 700 | memcpy(cmd->key, key, 16); |
| 701 | memcpy(cmd->key + 16, key + 24, 8); |
| 702 | memcpy(cmd->key + 24, key + 16, 8); |
| 703 | |
| 704 | } else { |
| 705 | memcpy(cmd->key, key, key_size); |
| 706 | } |
| 707 | |
| 708 | wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd)); |
| 709 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 710 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 711 | if (ret < 0) { |
| 712 | wl1271_warning("could not set keys"); |
Juuso Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 713 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | out: |
| 717 | kfree(cmd); |
| 718 | |
| 719 | return ret; |
| 720 | } |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 721 | |
| 722 | int wl1271_cmd_disconnect(struct wl1271 *wl) |
| 723 | { |
| 724 | struct wl1271_cmd_disconnect *cmd; |
| 725 | int ret = 0; |
| 726 | |
| 727 | wl1271_debug(DEBUG_CMD, "cmd disconnect"); |
| 728 | |
| 729 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 730 | if (!cmd) { |
| 731 | ret = -ENOMEM; |
| 732 | goto out; |
| 733 | } |
| 734 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 735 | cmd->rx_config_options = cpu_to_le32(wl->rx_config); |
| 736 | cmd->rx_filter_options = cpu_to_le32(wl->rx_filter); |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 737 | /* disconnect reason is not used in immediate disconnections */ |
| 738 | cmd->type = DISCONNECT_IMMEDIATE; |
| 739 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 740 | ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0); |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 741 | if (ret < 0) { |
| 742 | wl1271_error("failed to send disconnect command"); |
| 743 | goto out_free; |
| 744 | } |
| 745 | |
Luciano Coelho | 2f826f5 | 2010-03-26 12:53:21 +0200 | [diff] [blame] | 746 | ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID); |
| 747 | if (ret < 0) |
| 748 | wl1271_error("cmd disconnect event completion error"); |
| 749 | |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 750 | out_free: |
| 751 | kfree(cmd); |
| 752 | |
| 753 | out: |
| 754 | return ret; |
| 755 | } |
Juuso Oikarinen | be86cbe | 2010-05-27 12:53:01 +0300 | [diff] [blame] | 756 | |
| 757 | int wl1271_cmd_set_sta_state(struct wl1271 *wl) |
| 758 | { |
| 759 | struct wl1271_cmd_set_sta_state *cmd; |
| 760 | int ret = 0; |
| 761 | |
| 762 | wl1271_debug(DEBUG_CMD, "cmd set sta state"); |
| 763 | |
| 764 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 765 | if (!cmd) { |
| 766 | ret = -ENOMEM; |
| 767 | goto out; |
| 768 | } |
| 769 | |
| 770 | cmd->state = WL1271_CMD_STA_STATE_CONNECTED; |
| 771 | |
| 772 | ret = wl1271_cmd_send(wl, CMD_SET_STA_STATE, cmd, sizeof(*cmd), 0); |
| 773 | if (ret < 0) { |
| 774 | wl1271_error("failed to send set STA state command"); |
| 775 | goto out_free; |
| 776 | } |
| 777 | |
| 778 | out_free: |
| 779 | kfree(cmd); |
| 780 | |
| 781 | out: |
| 782 | return ret; |
| 783 | } |