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