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