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