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