Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of wl1271 |
| 3 | * |
| 4 | * Copyright (C) 2009 Nokia Corporation |
| 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> |
| 29 | |
| 30 | #include "wl1271.h" |
| 31 | #include "wl1271_reg.h" |
| 32 | #include "wl1271_spi.h" |
| 33 | #include "wl1271_acx.h" |
| 34 | #include "wl12xx_80211.h" |
| 35 | #include "wl1271_cmd.h" |
| 36 | |
| 37 | /* |
| 38 | * send command to firmware |
| 39 | * |
| 40 | * @wl: wl struct |
| 41 | * @id: command id |
| 42 | * @buf: buffer containing the command, must work with dma |
| 43 | * @len: length of the buffer |
| 44 | */ |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 45 | int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len, |
| 46 | size_t res_len) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 47 | { |
| 48 | struct wl1271_cmd_header *cmd; |
| 49 | unsigned long timeout; |
| 50 | u32 intr; |
| 51 | int ret = 0; |
Juuso Oikarinen | ad150e9 | 2009-11-02 20:22:12 +0200 | [diff] [blame] | 52 | u16 status; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 53 | |
| 54 | cmd = buf; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 55 | cmd->id = cpu_to_le16(id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 56 | cmd->status = 0; |
| 57 | |
| 58 | WARN_ON(len % 4 != 0); |
| 59 | |
Juuso Oikarinen | 7462141 | 2009-10-12 15:08:54 +0300 | [diff] [blame] | 60 | wl1271_spi_write(wl, wl->cmd_box_addr, buf, len, false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 61 | |
Juuso Oikarinen | 7462141 | 2009-10-12 15:08:54 +0300 | [diff] [blame] | 62 | wl1271_spi_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 63 | |
| 64 | timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT); |
| 65 | |
Juuso Oikarinen | 7462141 | 2009-10-12 15:08:54 +0300 | [diff] [blame] | 66 | intr = wl1271_spi_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 67 | while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) { |
| 68 | if (time_after(jiffies, timeout)) { |
| 69 | wl1271_error("command complete timeout"); |
| 70 | ret = -ETIMEDOUT; |
| 71 | goto out; |
| 72 | } |
| 73 | |
| 74 | msleep(1); |
| 75 | |
Juuso Oikarinen | 7462141 | 2009-10-12 15:08:54 +0300 | [diff] [blame] | 76 | intr = wl1271_spi_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 77 | } |
| 78 | |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 79 | /* read back the status code of the command */ |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 80 | if (res_len == 0) |
| 81 | res_len = sizeof(struct wl1271_cmd_header); |
| 82 | wl1271_spi_read(wl, wl->cmd_box_addr, cmd, res_len, false); |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 83 | |
Juuso Oikarinen | ad150e9 | 2009-11-02 20:22:12 +0200 | [diff] [blame] | 84 | status = le16_to_cpu(cmd->status); |
| 85 | if (status != CMD_STATUS_SUCCESS) { |
| 86 | wl1271_error("command execute failure %d", status); |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 87 | ret = -EIO; |
| 88 | } |
| 89 | |
Juuso Oikarinen | 7462141 | 2009-10-12 15:08:54 +0300 | [diff] [blame] | 90 | wl1271_spi_write32(wl, ACX_REG_INTERRUPT_ACK, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 91 | WL1271_ACX_INTR_CMD_COMPLETE); |
| 92 | |
| 93 | out: |
| 94 | return ret; |
| 95 | } |
| 96 | |
Luciano Coelho | 938e30c | 2009-10-15 10:33:27 +0300 | [diff] [blame] | 97 | static int wl1271_cmd_cal_channel_tune(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 98 | { |
| 99 | struct wl1271_cmd_cal_channel_tune *cmd; |
| 100 | int ret = 0; |
| 101 | |
| 102 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 103 | if (!cmd) |
| 104 | return -ENOMEM; |
| 105 | |
| 106 | cmd->test.id = TEST_CMD_CHANNEL_TUNE; |
| 107 | |
| 108 | cmd->band = WL1271_CHANNEL_TUNE_BAND_2_4; |
| 109 | /* set up any channel, 7 is in the middle of the range */ |
| 110 | cmd->channel = 7; |
| 111 | |
| 112 | ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0); |
| 113 | if (ret < 0) |
| 114 | wl1271_warning("TEST_CMD_CHANNEL_TUNE failed"); |
| 115 | |
| 116 | kfree(cmd); |
| 117 | return ret; |
| 118 | } |
| 119 | |
Luciano Coelho | 938e30c | 2009-10-15 10:33:27 +0300 | [diff] [blame] | 120 | static int wl1271_cmd_cal_update_ref_point(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 121 | { |
| 122 | struct wl1271_cmd_cal_update_ref_point *cmd; |
| 123 | int ret = 0; |
| 124 | |
| 125 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 126 | if (!cmd) |
| 127 | return -ENOMEM; |
| 128 | |
| 129 | cmd->test.id = TEST_CMD_UPDATE_PD_REFERENCE_POINT; |
| 130 | |
| 131 | /* FIXME: still waiting for the correct values */ |
| 132 | cmd->ref_power = 0; |
| 133 | cmd->ref_detector = 0; |
| 134 | |
| 135 | cmd->sub_band = WL1271_PD_REFERENCE_POINT_BAND_B_G; |
| 136 | |
| 137 | ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0); |
| 138 | if (ret < 0) |
| 139 | wl1271_warning("TEST_CMD_UPDATE_PD_REFERENCE_POINT failed"); |
| 140 | |
| 141 | kfree(cmd); |
| 142 | return ret; |
| 143 | } |
| 144 | |
Luciano Coelho | 938e30c | 2009-10-15 10:33:27 +0300 | [diff] [blame] | 145 | static int wl1271_cmd_cal_p2g(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 146 | { |
| 147 | struct wl1271_cmd_cal_p2g *cmd; |
| 148 | int ret = 0; |
| 149 | |
| 150 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 151 | if (!cmd) |
| 152 | return -ENOMEM; |
| 153 | |
| 154 | cmd->test.id = TEST_CMD_P2G_CAL; |
| 155 | |
| 156 | cmd->sub_band_mask = WL1271_CAL_P2G_BAND_B_G; |
| 157 | |
| 158 | ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0); |
| 159 | if (ret < 0) |
| 160 | wl1271_warning("TEST_CMD_P2G_CAL failed"); |
| 161 | |
| 162 | kfree(cmd); |
| 163 | return ret; |
| 164 | } |
| 165 | |
Luciano Coelho | 938e30c | 2009-10-15 10:33:27 +0300 | [diff] [blame] | 166 | static int wl1271_cmd_cal(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 167 | { |
| 168 | /* |
| 169 | * FIXME: we must make sure that we're not sleeping when calibration |
| 170 | * is done |
| 171 | */ |
| 172 | int ret; |
| 173 | |
| 174 | wl1271_notice("performing tx calibration"); |
| 175 | |
| 176 | ret = wl1271_cmd_cal_channel_tune(wl); |
| 177 | if (ret < 0) |
| 178 | return ret; |
| 179 | |
| 180 | ret = wl1271_cmd_cal_update_ref_point(wl); |
| 181 | if (ret < 0) |
| 182 | return ret; |
| 183 | |
| 184 | ret = wl1271_cmd_cal_p2g(wl); |
| 185 | if (ret < 0) |
| 186 | return ret; |
| 187 | |
| 188 | return ret; |
| 189 | } |
| 190 | |
Juuso Oikarinen | d94cd29 | 2009-10-08 21:56:25 +0300 | [diff] [blame] | 191 | int wl1271_cmd_join(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 192 | { |
| 193 | static bool do_cal = true; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 194 | struct wl1271_cmd_join *join; |
| 195 | int ret, i; |
| 196 | u8 *bssid; |
| 197 | |
| 198 | /* FIXME: remove when we get calibration from the factory */ |
| 199 | if (do_cal) { |
| 200 | ret = wl1271_cmd_cal(wl); |
| 201 | if (ret < 0) |
| 202 | wl1271_warning("couldn't calibrate"); |
| 203 | else |
| 204 | do_cal = false; |
| 205 | } |
| 206 | |
Luciano Coelho | d6e19d13 | 2009-10-12 15:08:43 +0300 | [diff] [blame] | 207 | /* FIXME: This is a workaround, because with the current stack, we |
| 208 | * cannot know when we have disassociated. So, if we have already |
| 209 | * joined, we disconnect before joining again. */ |
| 210 | if (wl->joined) { |
| 211 | ret = wl1271_cmd_disconnect(wl); |
| 212 | if (ret < 0) { |
| 213 | wl1271_error("failed to disconnect before rejoining"); |
| 214 | goto out; |
| 215 | } |
| 216 | |
| 217 | wl->joined = false; |
| 218 | } |
| 219 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 220 | join = kzalloc(sizeof(*join), GFP_KERNEL); |
| 221 | if (!join) { |
| 222 | ret = -ENOMEM; |
| 223 | goto out; |
| 224 | } |
| 225 | |
| 226 | wl1271_debug(DEBUG_CMD, "cmd join"); |
| 227 | |
| 228 | /* Reverse order BSSID */ |
| 229 | bssid = (u8 *) &join->bssid_lsb; |
| 230 | for (i = 0; i < ETH_ALEN; i++) |
| 231 | bssid[i] = wl->bssid[ETH_ALEN - i - 1]; |
| 232 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 233 | join->rx_config_options = cpu_to_le32(wl->rx_config); |
| 234 | join->rx_filter_options = cpu_to_le32(wl->rx_filter); |
Teemu Paasikivi | a410264 | 2009-10-13 12:47:51 +0300 | [diff] [blame] | 235 | join->bss_type = wl->bss_type; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 236 | |
Luciano Coelho | 64a7f67 | 2009-10-08 21:56:28 +0300 | [diff] [blame] | 237 | /* |
| 238 | * FIXME: disable temporarily all filters because after commit |
| 239 | * 9cef8737 "mac80211: fix managed mode BSSID handling" broke |
| 240 | * association. The filter logic needs to be implemented properly |
| 241 | * and once that is done, this hack can be removed. |
| 242 | */ |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 243 | join->rx_config_options = cpu_to_le32(0); |
| 244 | join->rx_filter_options = cpu_to_le32(WL1271_DEFAULT_RX_FILTER); |
Luciano Coelho | 64a7f67 | 2009-10-08 21:56:28 +0300 | [diff] [blame] | 245 | |
Teemu Paasikivi | a410264 | 2009-10-13 12:47:51 +0300 | [diff] [blame] | 246 | if (wl->band == IEEE80211_BAND_2GHZ) |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 247 | join->basic_rate_set = cpu_to_le32(CONF_HW_BIT_RATE_1MBPS | |
| 248 | CONF_HW_BIT_RATE_2MBPS | |
| 249 | CONF_HW_BIT_RATE_5_5MBPS | |
| 250 | CONF_HW_BIT_RATE_11MBPS); |
Teemu Paasikivi | a410264 | 2009-10-13 12:47:51 +0300 | [diff] [blame] | 251 | else { |
| 252 | join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 253 | join->basic_rate_set = cpu_to_le32(CONF_HW_BIT_RATE_6MBPS | |
| 254 | CONF_HW_BIT_RATE_12MBPS | |
| 255 | CONF_HW_BIT_RATE_24MBPS); |
Teemu Paasikivi | a410264 | 2009-10-13 12:47:51 +0300 | [diff] [blame] | 256 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 257 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 258 | join->beacon_interval = cpu_to_le16(WL1271_DEFAULT_BEACON_INT); |
Luciano Coelho | ae751ba | 2009-10-12 15:08:57 +0300 | [diff] [blame] | 259 | join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD; |
Teemu Paasikivi | a410264 | 2009-10-13 12:47:51 +0300 | [diff] [blame] | 260 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 261 | join->channel = wl->channel; |
| 262 | join->ssid_len = wl->ssid_len; |
| 263 | memcpy(join->ssid, wl->ssid, wl->ssid_len); |
| 264 | join->ctrl = WL1271_JOIN_CMD_CTRL_TX_FLUSH; |
| 265 | |
| 266 | /* increment the session counter */ |
| 267 | wl->session_counter++; |
| 268 | if (wl->session_counter >= SESSION_COUNTER_MAX) |
| 269 | wl->session_counter = 0; |
| 270 | |
| 271 | join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET; |
| 272 | |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 273 | /* reset TX security counters */ |
| 274 | wl->tx_security_last_seq = 0; |
| 275 | wl->tx_security_seq_16 = 0; |
| 276 | wl->tx_security_seq_32 = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 277 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 278 | ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 279 | if (ret < 0) { |
| 280 | wl1271_error("failed to initiate cmd join"); |
| 281 | goto out_free; |
| 282 | } |
| 283 | |
Luciano Coelho | d6e19d13 | 2009-10-12 15:08:43 +0300 | [diff] [blame] | 284 | wl->joined = true; |
| 285 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 286 | /* |
| 287 | * ugly hack: we should wait for JOIN_EVENT_COMPLETE_ID but to |
| 288 | * simplify locking we just sleep instead, for now |
| 289 | */ |
Juuso Oikarinen | d94cd29 | 2009-10-08 21:56:25 +0300 | [diff] [blame] | 290 | msleep(10); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 291 | |
| 292 | out_free: |
| 293 | kfree(join); |
| 294 | |
| 295 | out: |
| 296 | return ret; |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * send test command to firmware |
| 301 | * |
| 302 | * @wl: wl struct |
| 303 | * @buf: buffer containing the command, with all headers, must work with dma |
| 304 | * @len: length of the buffer |
| 305 | * @answer: is answer needed |
| 306 | */ |
| 307 | int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer) |
| 308 | { |
| 309 | int ret; |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 310 | size_t res_len = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 311 | |
| 312 | wl1271_debug(DEBUG_CMD, "cmd test"); |
| 313 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 314 | if (answer) |
| 315 | res_len = buf_len; |
| 316 | |
| 317 | ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 318 | |
| 319 | if (ret < 0) { |
| 320 | wl1271_warning("TEST command failed"); |
| 321 | return ret; |
| 322 | } |
| 323 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 324 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | /** |
| 328 | * read acx from firmware |
| 329 | * |
| 330 | * @wl: wl struct |
| 331 | * @id: acx id |
| 332 | * @buf: buffer for the response, including all headers, must work with dma |
| 333 | * @len: lenght of buf |
| 334 | */ |
| 335 | int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len) |
| 336 | { |
| 337 | struct acx_header *acx = buf; |
| 338 | int ret; |
| 339 | |
| 340 | wl1271_debug(DEBUG_CMD, "cmd interrogate"); |
| 341 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 342 | acx->id = cpu_to_le16(id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 343 | |
| 344 | /* payload length, does not include any headers */ |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 345 | acx->len = cpu_to_le16(len - sizeof(*acx)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 346 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 347 | ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len); |
| 348 | if (ret < 0) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 349 | wl1271_error("INTERROGATE command failed"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 350 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 351 | return ret; |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * write acx value to firmware |
| 356 | * |
| 357 | * @wl: wl struct |
| 358 | * @id: acx id |
| 359 | * @buf: buffer containing acx, including all headers, must work with dma |
| 360 | * @len: length of buf |
| 361 | */ |
| 362 | int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len) |
| 363 | { |
| 364 | struct acx_header *acx = buf; |
| 365 | int ret; |
| 366 | |
| 367 | wl1271_debug(DEBUG_CMD, "cmd configure"); |
| 368 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 369 | acx->id = cpu_to_le16(id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 370 | |
| 371 | /* payload length, does not include any headers */ |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 372 | acx->len = cpu_to_le16(len - sizeof(*acx)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 373 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 374 | ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 375 | if (ret < 0) { |
| 376 | wl1271_warning("CONFIGURE command NOK"); |
| 377 | return ret; |
| 378 | } |
| 379 | |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | int wl1271_cmd_data_path(struct wl1271 *wl, u8 channel, bool enable) |
| 384 | { |
| 385 | struct cmd_enabledisable_path *cmd; |
| 386 | int ret; |
| 387 | u16 cmd_rx, cmd_tx; |
| 388 | |
| 389 | wl1271_debug(DEBUG_CMD, "cmd data path"); |
| 390 | |
| 391 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 392 | if (!cmd) { |
| 393 | ret = -ENOMEM; |
| 394 | goto out; |
| 395 | } |
| 396 | |
| 397 | cmd->channel = channel; |
| 398 | |
| 399 | if (enable) { |
| 400 | cmd_rx = CMD_ENABLE_RX; |
| 401 | cmd_tx = CMD_ENABLE_TX; |
| 402 | } else { |
| 403 | cmd_rx = CMD_DISABLE_RX; |
| 404 | cmd_tx = CMD_DISABLE_TX; |
| 405 | } |
| 406 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 407 | ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 408 | if (ret < 0) { |
| 409 | wl1271_error("rx %s cmd for channel %d failed", |
| 410 | enable ? "start" : "stop", channel); |
| 411 | goto out; |
| 412 | } |
| 413 | |
| 414 | wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d", |
| 415 | enable ? "start" : "stop", channel); |
| 416 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 417 | ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 418 | if (ret < 0) { |
| 419 | wl1271_error("tx %s cmd for channel %d failed", |
| 420 | enable ? "start" : "stop", channel); |
| 421 | return ret; |
| 422 | } |
| 423 | |
| 424 | wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d", |
| 425 | enable ? "start" : "stop", channel); |
| 426 | |
| 427 | out: |
| 428 | kfree(cmd); |
| 429 | return ret; |
| 430 | } |
| 431 | |
| 432 | int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode) |
| 433 | { |
| 434 | struct wl1271_cmd_ps_params *ps_params = NULL; |
| 435 | int ret = 0; |
| 436 | |
| 437 | /* FIXME: this should be in ps.c */ |
Juuso Oikarinen | 51f2be2 | 2009-10-13 12:47:42 +0300 | [diff] [blame] | 438 | ret = wl1271_acx_wake_up_conditions(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 439 | if (ret < 0) { |
| 440 | wl1271_error("couldn't set wake up conditions"); |
| 441 | goto out; |
| 442 | } |
| 443 | |
| 444 | wl1271_debug(DEBUG_CMD, "cmd set ps mode"); |
| 445 | |
| 446 | ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL); |
| 447 | if (!ps_params) { |
| 448 | ret = -ENOMEM; |
| 449 | goto out; |
| 450 | } |
| 451 | |
| 452 | ps_params->ps_mode = ps_mode; |
| 453 | ps_params->send_null_data = 1; |
| 454 | ps_params->retries = 5; |
| 455 | ps_params->hang_over_period = 128; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 456 | ps_params->null_data_rate = cpu_to_le32(1); /* 1 Mbps */ |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 457 | |
| 458 | ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params, |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 459 | sizeof(*ps_params), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 460 | if (ret < 0) { |
| 461 | wl1271_error("cmd set_ps_mode failed"); |
| 462 | goto out; |
| 463 | } |
| 464 | |
| 465 | out: |
| 466 | kfree(ps_params); |
| 467 | return ret; |
| 468 | } |
| 469 | |
| 470 | int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer, |
| 471 | size_t len) |
| 472 | { |
| 473 | struct cmd_read_write_memory *cmd; |
| 474 | int ret = 0; |
| 475 | |
| 476 | wl1271_debug(DEBUG_CMD, "cmd read memory"); |
| 477 | |
| 478 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 479 | if (!cmd) { |
| 480 | ret = -ENOMEM; |
| 481 | goto out; |
| 482 | } |
| 483 | |
| 484 | WARN_ON(len > MAX_READ_SIZE); |
| 485 | len = min_t(size_t, len, MAX_READ_SIZE); |
| 486 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 487 | cmd->addr = cpu_to_le32(addr); |
| 488 | cmd->size = cpu_to_le32(len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 489 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 490 | ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd), |
| 491 | sizeof(*cmd)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 492 | if (ret < 0) { |
| 493 | wl1271_error("read memory command failed: %d", ret); |
| 494 | goto out; |
| 495 | } |
| 496 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 497 | /* the read command got in */ |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 498 | memcpy(answer, cmd->value, len); |
| 499 | |
| 500 | out: |
| 501 | kfree(cmd); |
| 502 | return ret; |
| 503 | } |
| 504 | |
| 505 | int wl1271_cmd_scan(struct wl1271 *wl, u8 *ssid, size_t len, |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 506 | u8 active_scan, u8 high_prio, u8 band, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 507 | u8 probe_requests) |
| 508 | { |
| 509 | |
| 510 | struct wl1271_cmd_trigger_scan_to *trigger = NULL; |
| 511 | struct wl1271_cmd_scan *params = NULL; |
Teemu Paasikivi | 311494c | 2009-10-13 12:47:49 +0300 | [diff] [blame] | 512 | struct ieee80211_channel *channels; |
| 513 | int i, j, n_ch, ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 514 | u16 scan_options = 0; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 515 | u8 ieee_band; |
| 516 | |
| 517 | if (band == WL1271_SCAN_BAND_2_4_GHZ) |
| 518 | ieee_band = IEEE80211_BAND_2GHZ; |
| 519 | else if (band == WL1271_SCAN_BAND_DUAL && wl1271_11a_enabled()) |
| 520 | ieee_band = IEEE80211_BAND_2GHZ; |
| 521 | else if (band == WL1271_SCAN_BAND_5_GHZ && wl1271_11a_enabled()) |
| 522 | ieee_band = IEEE80211_BAND_5GHZ; |
| 523 | else |
| 524 | return -EINVAL; |
| 525 | |
| 526 | if (wl->hw->wiphy->bands[ieee_band]->channels == NULL) |
| 527 | return -EINVAL; |
| 528 | |
| 529 | channels = wl->hw->wiphy->bands[ieee_band]->channels; |
| 530 | n_ch = wl->hw->wiphy->bands[ieee_band]->n_channels; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 531 | |
| 532 | if (wl->scanning) |
| 533 | return -EINVAL; |
| 534 | |
| 535 | params = kzalloc(sizeof(*params), GFP_KERNEL); |
| 536 | if (!params) |
| 537 | return -ENOMEM; |
| 538 | |
| 539 | params->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD); |
| 540 | params->params.rx_filter_options = |
| 541 | cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN); |
| 542 | |
| 543 | if (!active_scan) |
| 544 | scan_options |= WL1271_SCAN_OPT_PASSIVE; |
| 545 | if (high_prio) |
| 546 | scan_options |= WL1271_SCAN_OPT_PRIORITY_HIGH; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 547 | params->params.scan_options = cpu_to_le16(scan_options); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 548 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 549 | params->params.num_probe_requests = probe_requests; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 550 | /* Let the fw autodetect suitable tx_rate for probes */ |
| 551 | params->params.tx_rate = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 552 | params->params.tid_trigger = 0; |
| 553 | params->params.scan_tag = WL1271_SCAN_DEFAULT_TAG; |
| 554 | |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 555 | if (band == WL1271_SCAN_BAND_DUAL) |
| 556 | params->params.band = WL1271_SCAN_BAND_2_4_GHZ; |
| 557 | else |
| 558 | params->params.band = band; |
| 559 | |
Teemu Paasikivi | 311494c | 2009-10-13 12:47:49 +0300 | [diff] [blame] | 560 | for (i = 0, j = 0; i < n_ch && i < WL1271_SCAN_MAX_CHANNELS; i++) { |
| 561 | if (!(channels[i].flags & IEEE80211_CHAN_DISABLED)) { |
| 562 | params->channels[j].min_duration = |
| 563 | cpu_to_le32(WL1271_SCAN_CHAN_MIN_DURATION); |
| 564 | params->channels[j].max_duration = |
| 565 | cpu_to_le32(WL1271_SCAN_CHAN_MAX_DURATION); |
| 566 | memset(¶ms->channels[j].bssid_lsb, 0xff, 4); |
| 567 | memset(¶ms->channels[j].bssid_msb, 0xff, 2); |
| 568 | params->channels[j].early_termination = 0; |
| 569 | params->channels[j].tx_power_att = |
| 570 | WL1271_SCAN_CURRENT_TX_PWR; |
| 571 | params->channels[j].channel = channels[i].hw_value; |
| 572 | j++; |
| 573 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 574 | } |
| 575 | |
Teemu Paasikivi | 311494c | 2009-10-13 12:47:49 +0300 | [diff] [blame] | 576 | params->params.num_channels = j; |
| 577 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 578 | if (len && ssid) { |
| 579 | params->params.ssid_len = len; |
| 580 | memcpy(params->params.ssid, ssid, len); |
| 581 | } |
| 582 | |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 583 | ret = wl1271_cmd_build_probe_req(wl, ssid, len, ieee_band); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 584 | if (ret < 0) { |
| 585 | wl1271_error("PROBE request template failed"); |
| 586 | goto out; |
| 587 | } |
| 588 | |
| 589 | trigger = kzalloc(sizeof(*trigger), GFP_KERNEL); |
| 590 | if (!trigger) { |
| 591 | ret = -ENOMEM; |
| 592 | goto out; |
| 593 | } |
| 594 | |
| 595 | /* disable the timeout */ |
| 596 | trigger->timeout = 0; |
| 597 | |
| 598 | ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger, |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 599 | sizeof(*trigger), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 600 | if (ret < 0) { |
| 601 | wl1271_error("trigger scan to failed for hw scan"); |
| 602 | goto out; |
| 603 | } |
| 604 | |
| 605 | wl1271_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params)); |
| 606 | |
| 607 | wl->scanning = true; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 608 | if (wl1271_11a_enabled()) { |
| 609 | wl->scan.state = band; |
| 610 | if (band == WL1271_SCAN_BAND_DUAL) { |
| 611 | wl->scan.active = active_scan; |
| 612 | wl->scan.high_prio = high_prio; |
| 613 | wl->scan.probe_requests = probe_requests; |
| 614 | if (len && ssid) { |
| 615 | wl->scan.ssid_len = len; |
| 616 | memcpy(wl->scan.ssid, ssid, len); |
| 617 | } else |
| 618 | wl->scan.ssid_len = 0; |
| 619 | } |
| 620 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 621 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 622 | ret = wl1271_cmd_send(wl, CMD_SCAN, params, sizeof(*params), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 623 | if (ret < 0) { |
| 624 | wl1271_error("SCAN failed"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 625 | wl->scanning = false; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 626 | goto out; |
| 627 | } |
| 628 | |
| 629 | out: |
| 630 | kfree(params); |
| 631 | return ret; |
| 632 | } |
| 633 | |
| 634 | int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id, |
| 635 | void *buf, size_t buf_len) |
| 636 | { |
| 637 | struct wl1271_cmd_template_set *cmd; |
| 638 | int ret = 0; |
| 639 | |
| 640 | wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id); |
| 641 | |
| 642 | WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE); |
| 643 | buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE); |
| 644 | |
| 645 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 646 | if (!cmd) { |
| 647 | ret = -ENOMEM; |
| 648 | goto out; |
| 649 | } |
| 650 | |
| 651 | cmd->len = cpu_to_le16(buf_len); |
| 652 | cmd->template_type = template_id; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 653 | cmd->enabled_rates = cpu_to_le32(wl->conf.tx.rc_conf.enabled_rates); |
Juuso Oikarinen | 45b531a | 2009-10-13 12:47:41 +0300 | [diff] [blame] | 654 | cmd->short_retry_limit = wl->conf.tx.rc_conf.short_retry_limit; |
| 655 | cmd->long_retry_limit = wl->conf.tx.rc_conf.long_retry_limit; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 656 | |
| 657 | if (buf) |
| 658 | memcpy(cmd->template_data, buf, buf_len); |
| 659 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 660 | ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 661 | if (ret < 0) { |
| 662 | wl1271_warning("cmd set_template failed: %d", ret); |
| 663 | goto out_free; |
| 664 | } |
| 665 | |
| 666 | out_free: |
| 667 | kfree(cmd); |
| 668 | |
| 669 | out: |
| 670 | return ret; |
| 671 | } |
| 672 | |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 673 | static int wl1271_build_basic_rates(char *rates, u8 band) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 674 | { |
| 675 | u8 index = 0; |
| 676 | |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 677 | if (band == IEEE80211_BAND_2GHZ) { |
| 678 | rates[index++] = |
| 679 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB; |
| 680 | rates[index++] = |
| 681 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB; |
| 682 | rates[index++] = |
| 683 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB; |
| 684 | rates[index++] = |
| 685 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB; |
| 686 | } else if (band == IEEE80211_BAND_5GHZ) { |
| 687 | rates[index++] = |
| 688 | IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB; |
| 689 | rates[index++] = |
| 690 | IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_12MB; |
| 691 | rates[index++] = |
| 692 | IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB; |
| 693 | } else { |
| 694 | wl1271_error("build_basic_rates invalid band: %d", band); |
| 695 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 696 | |
| 697 | return index; |
| 698 | } |
| 699 | |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 700 | static int wl1271_build_extended_rates(char *rates, u8 band) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 701 | { |
| 702 | u8 index = 0; |
| 703 | |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 704 | if (band == IEEE80211_BAND_2GHZ) { |
| 705 | rates[index++] = IEEE80211_OFDM_RATE_6MB; |
| 706 | rates[index++] = IEEE80211_OFDM_RATE_9MB; |
| 707 | rates[index++] = IEEE80211_OFDM_RATE_12MB; |
| 708 | rates[index++] = IEEE80211_OFDM_RATE_18MB; |
| 709 | rates[index++] = IEEE80211_OFDM_RATE_24MB; |
| 710 | rates[index++] = IEEE80211_OFDM_RATE_36MB; |
| 711 | rates[index++] = IEEE80211_OFDM_RATE_48MB; |
| 712 | rates[index++] = IEEE80211_OFDM_RATE_54MB; |
| 713 | } else if (band == IEEE80211_BAND_5GHZ) { |
| 714 | rates[index++] = |
| 715 | IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_9MB; |
| 716 | rates[index++] = |
| 717 | IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_18MB; |
| 718 | rates[index++] = |
| 719 | IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB; |
| 720 | rates[index++] = |
| 721 | IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB; |
| 722 | rates[index++] = |
| 723 | IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB; |
| 724 | rates[index++] = |
| 725 | IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB; |
| 726 | } else { |
| 727 | wl1271_error("build_basic_rates invalid band: %d", band); |
| 728 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 729 | |
| 730 | return index; |
| 731 | } |
| 732 | |
| 733 | int wl1271_cmd_build_null_data(struct wl1271 *wl) |
| 734 | { |
| 735 | struct wl12xx_null_data_template template; |
| 736 | |
| 737 | if (!is_zero_ether_addr(wl->bssid)) { |
| 738 | memcpy(template.header.da, wl->bssid, ETH_ALEN); |
| 739 | memcpy(template.header.bssid, wl->bssid, ETH_ALEN); |
| 740 | } else { |
| 741 | memset(template.header.da, 0xff, ETH_ALEN); |
| 742 | memset(template.header.bssid, 0xff, ETH_ALEN); |
| 743 | } |
| 744 | |
| 745 | memcpy(template.header.sa, wl->mac_addr, ETH_ALEN); |
| 746 | template.header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA | |
Juuso Oikarinen | 7a38079 | 2009-10-15 10:33:26 +0300 | [diff] [blame] | 747 | IEEE80211_STYPE_NULLFUNC | |
| 748 | IEEE80211_FCTL_TODS); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 749 | |
| 750 | return wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, &template, |
| 751 | sizeof(template)); |
| 752 | |
| 753 | } |
| 754 | |
| 755 | int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid) |
| 756 | { |
| 757 | struct wl12xx_ps_poll_template template; |
| 758 | |
| 759 | memcpy(template.bssid, wl->bssid, ETH_ALEN); |
| 760 | memcpy(template.ta, wl->mac_addr, ETH_ALEN); |
Juuso Oikarinen | c3fea19 | 2009-10-08 21:56:22 +0300 | [diff] [blame] | 761 | |
| 762 | /* aid in PS-Poll has its two MSBs each set to 1 */ |
| 763 | template.aid = cpu_to_le16(1 << 15 | 1 << 14 | aid); |
| 764 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 765 | template.fc = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL); |
| 766 | |
| 767 | return wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, &template, |
| 768 | sizeof(template)); |
| 769 | |
| 770 | } |
| 771 | |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 772 | int wl1271_cmd_build_probe_req(struct wl1271 *wl, u8 *ssid, size_t ssid_len, |
| 773 | u8 band) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 774 | { |
| 775 | struct wl12xx_probe_req_template template; |
| 776 | struct wl12xx_ie_rates *rates; |
| 777 | char *ptr; |
| 778 | u16 size; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 779 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 780 | |
| 781 | ptr = (char *)&template; |
| 782 | size = sizeof(struct ieee80211_header); |
| 783 | |
| 784 | memset(template.header.da, 0xff, ETH_ALEN); |
| 785 | memset(template.header.bssid, 0xff, ETH_ALEN); |
| 786 | memcpy(template.header.sa, wl->mac_addr, ETH_ALEN); |
| 787 | template.header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
| 788 | |
| 789 | /* IEs */ |
| 790 | /* SSID */ |
| 791 | template.ssid.header.id = WLAN_EID_SSID; |
| 792 | template.ssid.header.len = ssid_len; |
| 793 | if (ssid_len && ssid) |
| 794 | memcpy(template.ssid.ssid, ssid, ssid_len); |
| 795 | size += sizeof(struct wl12xx_ie_header) + ssid_len; |
| 796 | ptr += size; |
| 797 | |
| 798 | /* Basic Rates */ |
| 799 | rates = (struct wl12xx_ie_rates *)ptr; |
| 800 | rates->header.id = WLAN_EID_SUPP_RATES; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 801 | rates->header.len = wl1271_build_basic_rates(rates->rates, band); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 802 | size += sizeof(struct wl12xx_ie_header) + rates->header.len; |
| 803 | ptr += sizeof(struct wl12xx_ie_header) + rates->header.len; |
| 804 | |
| 805 | /* Extended rates */ |
| 806 | rates = (struct wl12xx_ie_rates *)ptr; |
| 807 | rates->header.id = WLAN_EID_EXT_SUPP_RATES; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 808 | rates->header.len = wl1271_build_extended_rates(rates->rates, band); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 809 | size += sizeof(struct wl12xx_ie_header) + rates->header.len; |
| 810 | |
| 811 | wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", &template, size); |
| 812 | |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 813 | if (band == IEEE80211_BAND_2GHZ) |
| 814 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, |
| 815 | &template, size); |
| 816 | else |
| 817 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5, |
| 818 | &template, size); |
| 819 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id) |
| 823 | { |
| 824 | struct wl1271_cmd_set_keys *cmd; |
| 825 | int ret = 0; |
| 826 | |
| 827 | wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id); |
| 828 | |
| 829 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 830 | if (!cmd) { |
| 831 | ret = -ENOMEM; |
| 832 | goto out; |
| 833 | } |
| 834 | |
| 835 | cmd->id = id; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 836 | cmd->key_action = cpu_to_le16(KEY_SET_ID); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 837 | cmd->key_type = KEY_WEP; |
| 838 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 839 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 840 | if (ret < 0) { |
| 841 | wl1271_warning("cmd set_default_wep_key failed: %d", ret); |
| 842 | goto out; |
| 843 | } |
| 844 | |
| 845 | out: |
| 846 | kfree(cmd); |
| 847 | |
| 848 | return ret; |
| 849 | } |
| 850 | |
| 851 | 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] | 852 | u8 key_size, const u8 *key, const u8 *addr, |
| 853 | u32 tx_seq_32, u16 tx_seq_16) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 854 | { |
| 855 | struct wl1271_cmd_set_keys *cmd; |
| 856 | int ret = 0; |
| 857 | |
| 858 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 859 | if (!cmd) { |
| 860 | ret = -ENOMEM; |
| 861 | goto out; |
| 862 | } |
| 863 | |
| 864 | if (key_type != KEY_WEP) |
| 865 | memcpy(cmd->addr, addr, ETH_ALEN); |
| 866 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 867 | cmd->key_action = cpu_to_le16(action); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 868 | cmd->key_size = key_size; |
| 869 | cmd->key_type = key_type; |
| 870 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 871 | cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16); |
| 872 | cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32); |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 873 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 874 | /* we have only one SSID profile */ |
| 875 | cmd->ssid_profile = 0; |
| 876 | |
| 877 | cmd->id = id; |
| 878 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 879 | if (key_type == KEY_TKIP) { |
| 880 | /* |
| 881 | * We get the key in the following form: |
| 882 | * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes) |
| 883 | * but the target is expecting: |
| 884 | * TKIP - RX MIC - TX MIC |
| 885 | */ |
| 886 | memcpy(cmd->key, key, 16); |
| 887 | memcpy(cmd->key + 16, key + 24, 8); |
| 888 | memcpy(cmd->key + 24, key + 16, 8); |
| 889 | |
| 890 | } else { |
| 891 | memcpy(cmd->key, key, key_size); |
| 892 | } |
| 893 | |
| 894 | wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd)); |
| 895 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 896 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 897 | if (ret < 0) { |
| 898 | wl1271_warning("could not set keys"); |
| 899 | goto out; |
| 900 | } |
| 901 | |
| 902 | out: |
| 903 | kfree(cmd); |
| 904 | |
| 905 | return ret; |
| 906 | } |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 907 | |
| 908 | int wl1271_cmd_disconnect(struct wl1271 *wl) |
| 909 | { |
| 910 | struct wl1271_cmd_disconnect *cmd; |
| 911 | int ret = 0; |
| 912 | |
| 913 | wl1271_debug(DEBUG_CMD, "cmd disconnect"); |
| 914 | |
| 915 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 916 | if (!cmd) { |
| 917 | ret = -ENOMEM; |
| 918 | goto out; |
| 919 | } |
| 920 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 921 | cmd->rx_config_options = cpu_to_le32(wl->rx_config); |
| 922 | cmd->rx_filter_options = cpu_to_le32(wl->rx_filter); |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 923 | /* disconnect reason is not used in immediate disconnections */ |
| 924 | cmd->type = DISCONNECT_IMMEDIATE; |
| 925 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame^] | 926 | ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0); |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 927 | if (ret < 0) { |
| 928 | wl1271_error("failed to send disconnect command"); |
| 929 | goto out_free; |
| 930 | } |
| 931 | |
| 932 | out_free: |
| 933 | kfree(cmd); |
| 934 | |
| 935 | out: |
| 936 | return ret; |
| 937 | } |