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 | |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 32 | #include "wl12xx.h" |
| 33 | #include "reg.h" |
| 34 | #include "io.h" |
| 35 | #include "acx.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 36 | #include "wl12xx_80211.h" |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 37 | #include "cmd.h" |
| 38 | #include "event.h" |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 39 | #include "tx.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 40 | |
Juuso Oikarinen | 16092b5 | 2010-04-28 09:49:59 +0300 | [diff] [blame] | 41 | #define WL1271_CMD_FAST_POLL_COUNT 50 |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * send command to firmware |
| 45 | * |
| 46 | * @wl: wl struct |
| 47 | * @id: command id |
| 48 | * @buf: buffer containing the command, must work with dma |
| 49 | * @len: length of the buffer |
| 50 | */ |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 51 | int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len, |
| 52 | size_t res_len) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 53 | { |
| 54 | struct wl1271_cmd_header *cmd; |
| 55 | unsigned long timeout; |
| 56 | u32 intr; |
| 57 | int ret = 0; |
Juuso Oikarinen | ad150e9 | 2009-11-02 20:22:12 +0200 | [diff] [blame] | 58 | u16 status; |
Saravanan Dhanabal | bc0f03e | 2010-03-26 12:53:33 +0200 | [diff] [blame] | 59 | u16 poll_count = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 60 | |
| 61 | cmd = buf; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 62 | cmd->id = cpu_to_le16(id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 63 | cmd->status = 0; |
| 64 | |
| 65 | WARN_ON(len % 4 != 0); |
Arik Nemtsov | 24225b3 | 2011-03-01 12:27:26 +0200 | [diff] [blame] | 66 | WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags)); |
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_write(wl, wl->cmd_box_addr, buf, len, false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 69 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 70 | wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 71 | |
| 72 | timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT); |
| 73 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 74 | intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 75 | while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) { |
| 76 | if (time_after(jiffies, timeout)) { |
| 77 | wl1271_error("command complete timeout"); |
| 78 | ret = -ETIMEDOUT; |
Arik Nemtsov | f482b76 | 2011-04-18 14:15:23 +0300 | [diff] [blame] | 79 | goto fail; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 80 | } |
| 81 | |
Saravanan Dhanabal | bc0f03e | 2010-03-26 12:53:33 +0200 | [diff] [blame] | 82 | poll_count++; |
Juuso Oikarinen | 16092b5 | 2010-04-28 09:49:59 +0300 | [diff] [blame] | 83 | if (poll_count < WL1271_CMD_FAST_POLL_COUNT) |
| 84 | udelay(10); |
| 85 | else |
| 86 | msleep(1); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 87 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 88 | intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 89 | } |
| 90 | |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 91 | /* read back the status code of the command */ |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 92 | if (res_len == 0) |
| 93 | res_len = sizeof(struct wl1271_cmd_header); |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 94 | wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false); |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 95 | |
Juuso Oikarinen | ad150e9 | 2009-11-02 20:22:12 +0200 | [diff] [blame] | 96 | status = le16_to_cpu(cmd->status); |
| 97 | if (status != CMD_STATUS_SUCCESS) { |
| 98 | wl1271_error("command execute failure %d", status); |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 99 | ret = -EIO; |
Arik Nemtsov | f482b76 | 2011-04-18 14:15:23 +0300 | [diff] [blame] | 100 | goto fail; |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 101 | } |
| 102 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 103 | wl1271_write32(wl, ACX_REG_INTERRUPT_ACK, |
| 104 | WL1271_ACX_INTR_CMD_COMPLETE); |
Arik Nemtsov | f482b76 | 2011-04-18 14:15:23 +0300 | [diff] [blame] | 105 | return 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 106 | |
Arik Nemtsov | f482b76 | 2011-04-18 14:15:23 +0300 | [diff] [blame] | 107 | fail: |
| 108 | WARN_ON(1); |
| 109 | ieee80211_queue_work(wl->hw, &wl->recovery_work); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 110 | return ret; |
| 111 | } |
| 112 | |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 113 | int wl1271_cmd_general_parms(struct wl1271 *wl) |
| 114 | { |
| 115 | struct wl1271_general_parms_cmd *gen_parms; |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 116 | struct wl1271_ini_general_params *gp = |
| 117 | &((struct wl1271_nvs_file *)wl->nvs)->general_params; |
| 118 | bool answer = false; |
| 119 | int ret; |
| 120 | |
| 121 | if (!wl->nvs) |
| 122 | return -ENODEV; |
| 123 | |
Pontus Fuchs | 4b2bb3c | 2011-10-18 09:23:41 +0200 | [diff] [blame^] | 124 | if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) { |
| 125 | wl1271_warning("FEM index from INI out of bounds"); |
| 126 | return -EINVAL; |
| 127 | } |
| 128 | |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 129 | gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL); |
| 130 | if (!gen_parms) |
| 131 | return -ENOMEM; |
| 132 | |
| 133 | gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM; |
| 134 | |
| 135 | memcpy(&gen_parms->general_params, gp, sizeof(*gp)); |
| 136 | |
| 137 | if (gp->tx_bip_fem_auto_detect) |
| 138 | answer = true; |
| 139 | |
Shahar Levi | b03acad | 2011-04-03 13:54:54 +0300 | [diff] [blame] | 140 | /* Override the REF CLK from the NVS with the one from platform data */ |
| 141 | gen_parms->general_params.ref_clock = wl->ref_clock; |
| 142 | |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 143 | ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer); |
| 144 | if (ret < 0) { |
| 145 | wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed"); |
| 146 | goto out; |
| 147 | } |
| 148 | |
| 149 | gp->tx_bip_fem_manufacturer = |
| 150 | gen_parms->general_params.tx_bip_fem_manufacturer; |
| 151 | |
Pontus Fuchs | 4b2bb3c | 2011-10-18 09:23:41 +0200 | [diff] [blame^] | 152 | if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) { |
| 153 | wl1271_warning("FEM index from FW out of bounds"); |
| 154 | ret = -EINVAL; |
| 155 | goto out; |
| 156 | } |
| 157 | |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 158 | wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n", |
| 159 | answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer); |
| 160 | |
| 161 | out: |
| 162 | kfree(gen_parms); |
| 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | int wl128x_cmd_general_parms(struct wl1271 *wl) |
| 167 | { |
| 168 | struct wl128x_general_parms_cmd *gen_parms; |
| 169 | struct wl128x_ini_general_params *gp = |
| 170 | &((struct wl128x_nvs_file *)wl->nvs)->general_params; |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 171 | bool answer = false; |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 172 | int ret; |
| 173 | |
Juuso Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 174 | if (!wl->nvs) |
| 175 | return -ENODEV; |
| 176 | |
Pontus Fuchs | 4b2bb3c | 2011-10-18 09:23:41 +0200 | [diff] [blame^] | 177 | if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) { |
| 178 | wl1271_warning("FEM index from ini out of bounds"); |
| 179 | return -EINVAL; |
| 180 | } |
| 181 | |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 182 | gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL); |
| 183 | if (!gen_parms) |
| 184 | return -ENOMEM; |
| 185 | |
| 186 | gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM; |
| 187 | |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 188 | memcpy(&gen_parms->general_params, gp, sizeof(*gp)); |
Luciano Coelho | 76c0f8d | 2009-12-11 15:40:41 +0200 | [diff] [blame] | 189 | |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 190 | if (gp->tx_bip_fem_auto_detect) |
| 191 | answer = true; |
| 192 | |
Shahar Levi | b03acad | 2011-04-03 13:54:54 +0300 | [diff] [blame] | 193 | /* Replace REF and TCXO CLKs with the ones from platform data */ |
| 194 | gen_parms->general_params.ref_clock = wl->ref_clock; |
| 195 | gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock; |
| 196 | |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 197 | ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer); |
| 198 | if (ret < 0) { |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 199 | wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed"); |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 200 | goto out; |
| 201 | } |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 202 | |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 203 | gp->tx_bip_fem_manufacturer = |
| 204 | gen_parms->general_params.tx_bip_fem_manufacturer; |
| 205 | |
Pontus Fuchs | 4b2bb3c | 2011-10-18 09:23:41 +0200 | [diff] [blame^] | 206 | if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) { |
| 207 | wl1271_warning("FEM index from FW out of bounds"); |
| 208 | ret = -EINVAL; |
| 209 | goto out; |
| 210 | } |
| 211 | |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 212 | wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n", |
| 213 | answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer); |
| 214 | |
| 215 | out: |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 216 | kfree(gen_parms); |
| 217 | return ret; |
| 218 | } |
| 219 | |
| 220 | int wl1271_cmd_radio_parms(struct wl1271 *wl) |
| 221 | { |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 222 | struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs; |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 223 | struct wl1271_radio_parms_cmd *radio_parms; |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 224 | struct wl1271_ini_general_params *gp = &nvs->general_params; |
Juuso Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 225 | int ret; |
| 226 | |
| 227 | if (!wl->nvs) |
| 228 | return -ENODEV; |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 229 | |
| 230 | radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL); |
| 231 | if (!radio_parms) |
| 232 | return -ENOMEM; |
| 233 | |
| 234 | radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM; |
| 235 | |
Juuso Oikarinen | a7da74f | 2010-05-14 10:46:23 +0300 | [diff] [blame] | 236 | /* 2.4GHz parameters */ |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 237 | memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2, |
Juuso Oikarinen | eb70eb7 | 2010-05-14 10:46:22 +0300 | [diff] [blame] | 238 | sizeof(struct wl1271_ini_band_params_2)); |
| 239 | memcpy(&radio_parms->dyn_params_2, |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 240 | &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params, |
Juuso Oikarinen | eb70eb7 | 2010-05-14 10:46:22 +0300 | [diff] [blame] | 241 | sizeof(struct wl1271_ini_fem_params_2)); |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 242 | |
Juuso Oikarinen | a7da74f | 2010-05-14 10:46:23 +0300 | [diff] [blame] | 243 | /* 5GHz parameters */ |
| 244 | memcpy(&radio_parms->static_params_5, |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 245 | &nvs->stat_radio_params_5, |
Juuso Oikarinen | a7da74f | 2010-05-14 10:46:23 +0300 | [diff] [blame] | 246 | sizeof(struct wl1271_ini_band_params_5)); |
| 247 | memcpy(&radio_parms->dyn_params_5, |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 248 | &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params, |
Juuso Oikarinen | a7da74f | 2010-05-14 10:46:23 +0300 | [diff] [blame] | 249 | sizeof(struct wl1271_ini_fem_params_5)); |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 250 | |
| 251 | wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ", |
| 252 | radio_parms, sizeof(*radio_parms)); |
| 253 | |
| 254 | ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0); |
| 255 | if (ret < 0) |
| 256 | wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed"); |
| 257 | |
| 258 | kfree(radio_parms); |
| 259 | return ret; |
| 260 | } |
| 261 | |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 262 | int wl128x_cmd_radio_parms(struct wl1271 *wl) |
| 263 | { |
| 264 | struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs; |
| 265 | struct wl128x_radio_parms_cmd *radio_parms; |
| 266 | struct wl128x_ini_general_params *gp = &nvs->general_params; |
| 267 | int ret; |
| 268 | |
| 269 | if (!wl->nvs) |
| 270 | return -ENODEV; |
| 271 | |
| 272 | radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL); |
| 273 | if (!radio_parms) |
| 274 | return -ENOMEM; |
| 275 | |
| 276 | radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM; |
| 277 | |
| 278 | /* 2.4GHz parameters */ |
| 279 | memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2, |
| 280 | sizeof(struct wl128x_ini_band_params_2)); |
| 281 | memcpy(&radio_parms->dyn_params_2, |
| 282 | &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params, |
| 283 | sizeof(struct wl128x_ini_fem_params_2)); |
| 284 | |
| 285 | /* 5GHz parameters */ |
| 286 | memcpy(&radio_parms->static_params_5, |
| 287 | &nvs->stat_radio_params_5, |
| 288 | sizeof(struct wl128x_ini_band_params_5)); |
| 289 | memcpy(&radio_parms->dyn_params_5, |
| 290 | &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params, |
| 291 | sizeof(struct wl128x_ini_fem_params_5)); |
| 292 | |
| 293 | radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options; |
| 294 | |
| 295 | wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ", |
| 296 | radio_parms, sizeof(*radio_parms)); |
| 297 | |
| 298 | ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0); |
| 299 | if (ret < 0) |
| 300 | wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed"); |
| 301 | |
| 302 | kfree(radio_parms); |
| 303 | return ret; |
| 304 | } |
| 305 | |
Juuso Oikarinen | 644a486 | 2010-10-05 13:11:56 +0200 | [diff] [blame] | 306 | int wl1271_cmd_ext_radio_parms(struct wl1271 *wl) |
| 307 | { |
| 308 | struct wl1271_ext_radio_parms_cmd *ext_radio_parms; |
| 309 | struct conf_rf_settings *rf = &wl->conf.rf; |
| 310 | int ret; |
| 311 | |
| 312 | if (!wl->nvs) |
| 313 | return -ENODEV; |
| 314 | |
| 315 | ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL); |
| 316 | if (!ext_radio_parms) |
| 317 | return -ENOMEM; |
| 318 | |
| 319 | ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM; |
| 320 | |
| 321 | memcpy(ext_radio_parms->tx_per_channel_power_compensation_2, |
| 322 | rf->tx_per_channel_power_compensation_2, |
| 323 | CONF_TX_PWR_COMPENSATION_LEN_2); |
| 324 | memcpy(ext_radio_parms->tx_per_channel_power_compensation_5, |
| 325 | rf->tx_per_channel_power_compensation_5, |
| 326 | CONF_TX_PWR_COMPENSATION_LEN_5); |
| 327 | |
| 328 | wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ", |
| 329 | ext_radio_parms, sizeof(*ext_radio_parms)); |
| 330 | |
| 331 | ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0); |
| 332 | if (ret < 0) |
| 333 | wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed"); |
| 334 | |
| 335 | kfree(ext_radio_parms); |
| 336 | return ret; |
| 337 | } |
| 338 | |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 339 | /* |
| 340 | * Poll the mailbox event field until any of the bits in the mask is set or a |
| 341 | * timeout occurs (WL1271_EVENT_TIMEOUT in msecs) |
| 342 | */ |
Arik Nemtsov | 05285cf | 2010-11-12 17:15:03 +0200 | [diff] [blame] | 343 | static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask) |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 344 | { |
| 345 | u32 events_vector, event; |
| 346 | unsigned long timeout; |
| 347 | |
| 348 | timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT); |
| 349 | |
| 350 | do { |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 351 | if (time_after(jiffies, timeout)) { |
Arik Nemtsov | 05285cf | 2010-11-12 17:15:03 +0200 | [diff] [blame] | 352 | wl1271_debug(DEBUG_CMD, "timeout waiting for event %d", |
| 353 | (int)mask); |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 354 | return -ETIMEDOUT; |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 355 | } |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 356 | |
| 357 | msleep(1); |
| 358 | |
| 359 | /* read from both event fields */ |
| 360 | wl1271_read(wl, wl->mbox_ptr[0], &events_vector, |
| 361 | sizeof(events_vector), false); |
| 362 | event = events_vector & mask; |
| 363 | wl1271_read(wl, wl->mbox_ptr[1], &events_vector, |
| 364 | sizeof(events_vector), false); |
| 365 | event |= events_vector & mask; |
| 366 | } while (!event); |
| 367 | |
| 368 | return 0; |
| 369 | } |
| 370 | |
Arik Nemtsov | 05285cf | 2010-11-12 17:15:03 +0200 | [diff] [blame] | 371 | static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask) |
| 372 | { |
| 373 | int ret; |
| 374 | |
| 375 | ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask); |
| 376 | if (ret != 0) { |
| 377 | ieee80211_queue_work(wl->hw, &wl->recovery_work); |
| 378 | return ret; |
| 379 | } |
| 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
Juuso Oikarinen | 1530549 | 2010-02-22 08:38:32 +0200 | [diff] [blame] | 384 | int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type) |
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 | struct wl1271_cmd_join *join; |
| 387 | int ret, i; |
| 388 | u8 *bssid; |
| 389 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 390 | join = kzalloc(sizeof(*join), GFP_KERNEL); |
| 391 | if (!join) { |
| 392 | ret = -ENOMEM; |
| 393 | goto out; |
| 394 | } |
| 395 | |
| 396 | wl1271_debug(DEBUG_CMD, "cmd join"); |
| 397 | |
| 398 | /* Reverse order BSSID */ |
| 399 | bssid = (u8 *) &join->bssid_lsb; |
| 400 | for (i = 0; i < ETH_ALEN; i++) |
| 401 | bssid[i] = wl->bssid[ETH_ALEN - i - 1]; |
| 402 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 403 | join->rx_config_options = cpu_to_le32(wl->rx_config); |
| 404 | join->rx_filter_options = cpu_to_le32(wl->rx_filter); |
Juuso Oikarinen | 1530549 | 2010-02-22 08:38:32 +0200 | [diff] [blame] | 405 | join->bss_type = bss_type; |
Luciano Coelho | 23a7a51 | 2010-04-28 09:50:02 +0300 | [diff] [blame] | 406 | join->basic_rate_set = cpu_to_le32(wl->basic_rate_set); |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 407 | join->supported_rate_set = cpu_to_le32(wl->rate_set); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 408 | |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 409 | if (wl->band == IEEE80211_BAND_5GHZ) |
Teemu Paasikivi | a410264 | 2009-10-13 12:47:51 +0300 | [diff] [blame] | 410 | join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 411 | |
Juuso Oikarinen | 60e84c2 | 2010-03-26 12:53:25 +0200 | [diff] [blame] | 412 | join->beacon_interval = cpu_to_le16(wl->beacon_int); |
Luciano Coelho | ae751ba | 2009-10-12 15:08:57 +0300 | [diff] [blame] | 413 | join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD; |
Teemu Paasikivi | a410264 | 2009-10-13 12:47:51 +0300 | [diff] [blame] | 414 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 415 | join->channel = wl->channel; |
| 416 | join->ssid_len = wl->ssid_len; |
| 417 | memcpy(join->ssid, wl->ssid, wl->ssid_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 418 | |
| 419 | join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET; |
| 420 | |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 421 | /* reset TX security counters */ |
| 422 | wl->tx_security_last_seq = 0; |
Juuso Oikarinen | 04e36fc | 2010-02-22 08:38:40 +0200 | [diff] [blame] | 423 | wl->tx_security_seq = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 424 | |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 425 | wl1271_debug(DEBUG_CMD, "cmd join: basic_rate_set=0x%x, rate_set=0x%x", |
| 426 | join->basic_rate_set, join->supported_rate_set); |
| 427 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 428 | ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 429 | if (ret < 0) { |
| 430 | wl1271_error("failed to initiate cmd join"); |
| 431 | goto out_free; |
| 432 | } |
| 433 | |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 434 | ret = wl1271_cmd_wait_for_event(wl, JOIN_EVENT_COMPLETE_ID); |
| 435 | if (ret < 0) |
| 436 | wl1271_error("cmd join event completion error"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 437 | |
| 438 | out_free: |
| 439 | kfree(join); |
| 440 | |
| 441 | out: |
| 442 | return ret; |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * send test command to firmware |
| 447 | * |
| 448 | * @wl: wl struct |
| 449 | * @buf: buffer containing the command, with all headers, must work with dma |
| 450 | * @len: length of the buffer |
| 451 | * @answer: is answer needed |
| 452 | */ |
| 453 | int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer) |
| 454 | { |
| 455 | int ret; |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 456 | size_t res_len = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 457 | |
| 458 | wl1271_debug(DEBUG_CMD, "cmd test"); |
| 459 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 460 | if (answer) |
| 461 | res_len = buf_len; |
| 462 | |
| 463 | ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 464 | |
| 465 | if (ret < 0) { |
| 466 | wl1271_warning("TEST command failed"); |
| 467 | return ret; |
| 468 | } |
| 469 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 470 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | /** |
| 474 | * read acx from firmware |
| 475 | * |
| 476 | * @wl: wl struct |
| 477 | * @id: acx id |
| 478 | * @buf: buffer for the response, including all headers, must work with dma |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 479 | * @len: length of buf |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 480 | */ |
| 481 | int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len) |
| 482 | { |
| 483 | struct acx_header *acx = buf; |
| 484 | int ret; |
| 485 | |
| 486 | wl1271_debug(DEBUG_CMD, "cmd interrogate"); |
| 487 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 488 | acx->id = cpu_to_le16(id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 489 | |
| 490 | /* payload length, does not include any headers */ |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 491 | acx->len = cpu_to_le16(len - sizeof(*acx)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 492 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 493 | ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len); |
| 494 | if (ret < 0) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 495 | wl1271_error("INTERROGATE command failed"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 496 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 497 | return ret; |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * write acx value to firmware |
| 502 | * |
| 503 | * @wl: wl struct |
| 504 | * @id: acx id |
| 505 | * @buf: buffer containing acx, including all headers, must work with dma |
| 506 | * @len: length of buf |
| 507 | */ |
| 508 | int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len) |
| 509 | { |
| 510 | struct acx_header *acx = buf; |
| 511 | int ret; |
| 512 | |
| 513 | wl1271_debug(DEBUG_CMD, "cmd configure"); |
| 514 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 515 | acx->id = cpu_to_le16(id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 516 | |
| 517 | /* payload length, does not include any headers */ |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 518 | acx->len = cpu_to_le16(len - sizeof(*acx)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 519 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 520 | ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 521 | if (ret < 0) { |
| 522 | wl1271_warning("CONFIGURE command NOK"); |
| 523 | return ret; |
| 524 | } |
| 525 | |
| 526 | return 0; |
| 527 | } |
| 528 | |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 529 | int wl1271_cmd_data_path(struct wl1271 *wl, bool enable) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 530 | { |
| 531 | struct cmd_enabledisable_path *cmd; |
| 532 | int ret; |
| 533 | u16 cmd_rx, cmd_tx; |
| 534 | |
| 535 | wl1271_debug(DEBUG_CMD, "cmd data path"); |
| 536 | |
| 537 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 538 | if (!cmd) { |
| 539 | ret = -ENOMEM; |
| 540 | goto out; |
| 541 | } |
| 542 | |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 543 | /* the channel here is only used for calibration, so hardcoded to 1 */ |
| 544 | cmd->channel = 1; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 545 | |
| 546 | if (enable) { |
| 547 | cmd_rx = CMD_ENABLE_RX; |
| 548 | cmd_tx = CMD_ENABLE_TX; |
| 549 | } else { |
| 550 | cmd_rx = CMD_DISABLE_RX; |
| 551 | cmd_tx = CMD_DISABLE_TX; |
| 552 | } |
| 553 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 554 | ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 555 | if (ret < 0) { |
| 556 | wl1271_error("rx %s cmd for channel %d failed", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 557 | enable ? "start" : "stop", cmd->channel); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 558 | goto out; |
| 559 | } |
| 560 | |
| 561 | wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 562 | enable ? "start" : "stop", cmd->channel); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 563 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 564 | ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 565 | if (ret < 0) { |
| 566 | wl1271_error("tx %s cmd for channel %d failed", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 567 | enable ? "start" : "stop", cmd->channel); |
Juuso Oikarinen | 1b00f2b | 2010-03-26 12:53:17 +0200 | [diff] [blame] | 568 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 572 | enable ? "start" : "stop", cmd->channel); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 573 | |
| 574 | out: |
| 575 | kfree(cmd); |
| 576 | return ret; |
| 577 | } |
| 578 | |
Eliad Peller | c8bde24 | 2011-02-02 09:59:35 +0200 | [diff] [blame] | 579 | int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 580 | { |
| 581 | struct wl1271_cmd_ps_params *ps_params = NULL; |
| 582 | int ret = 0; |
| 583 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 584 | wl1271_debug(DEBUG_CMD, "cmd set ps mode"); |
| 585 | |
| 586 | ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL); |
| 587 | if (!ps_params) { |
| 588 | ret = -ENOMEM; |
| 589 | goto out; |
| 590 | } |
| 591 | |
| 592 | ps_params->ps_mode = ps_mode; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 593 | |
| 594 | ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params, |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 595 | sizeof(*ps_params), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 596 | if (ret < 0) { |
| 597 | wl1271_error("cmd set_ps_mode failed"); |
| 598 | goto out; |
| 599 | } |
| 600 | |
| 601 | out: |
| 602 | kfree(ps_params); |
| 603 | return ret; |
| 604 | } |
| 605 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 606 | int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 607 | void *buf, size_t buf_len, int index, u32 rates) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 608 | { |
| 609 | struct wl1271_cmd_template_set *cmd; |
| 610 | int ret = 0; |
| 611 | |
| 612 | wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id); |
| 613 | |
| 614 | WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE); |
| 615 | buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE); |
| 616 | |
| 617 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 618 | if (!cmd) { |
| 619 | ret = -ENOMEM; |
| 620 | goto out; |
| 621 | } |
| 622 | |
| 623 | cmd->len = cpu_to_le16(buf_len); |
| 624 | cmd->template_type = template_id; |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 625 | cmd->enabled_rates = cpu_to_le32(rates); |
Arik Nemtsov | 1e05a81 | 2010-10-16 17:44:51 +0200 | [diff] [blame] | 626 | cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit; |
| 627 | cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit; |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 628 | cmd->index = index; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 629 | |
| 630 | if (buf) |
| 631 | memcpy(cmd->template_data, buf, buf_len); |
| 632 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 633 | ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 634 | if (ret < 0) { |
| 635 | wl1271_warning("cmd set_template failed: %d", ret); |
| 636 | goto out_free; |
| 637 | } |
| 638 | |
| 639 | out_free: |
| 640 | kfree(cmd); |
| 641 | |
| 642 | out: |
| 643 | return ret; |
| 644 | } |
| 645 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 646 | int wl1271_cmd_build_null_data(struct wl1271 *wl) |
| 647 | { |
Juuso Oikarinen | a0cb7be | 2010-03-18 12:26:44 +0200 | [diff] [blame] | 648 | struct sk_buff *skb = NULL; |
| 649 | int size; |
| 650 | void *ptr; |
| 651 | int ret = -ENOMEM; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 652 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 653 | |
Juuso Oikarinen | a0cb7be | 2010-03-18 12:26:44 +0200 | [diff] [blame] | 654 | if (wl->bss_type == BSS_TYPE_IBSS) { |
| 655 | size = sizeof(struct wl12xx_null_data_template); |
| 656 | ptr = NULL; |
| 657 | } else { |
| 658 | skb = ieee80211_nullfunc_get(wl->hw, wl->vif); |
| 659 | if (!skb) |
| 660 | goto out; |
| 661 | size = skb->len; |
| 662 | ptr = skb->data; |
| 663 | } |
| 664 | |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 665 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0, |
Juuso Oikarinen | 8eab7b4 | 2010-09-24 03:10:11 +0200 | [diff] [blame] | 666 | wl->basic_rate); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 667 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 668 | out: |
| 669 | dev_kfree_skb(skb); |
Juuso Oikarinen | a0cb7be | 2010-03-18 12:26:44 +0200 | [diff] [blame] | 670 | if (ret) |
| 671 | wl1271_warning("cmd buld null data failed %d", ret); |
| 672 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 673 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 674 | |
| 675 | } |
| 676 | |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 677 | int wl1271_cmd_build_klv_null_data(struct wl1271 *wl) |
| 678 | { |
| 679 | struct sk_buff *skb = NULL; |
| 680 | int ret = -ENOMEM; |
| 681 | |
| 682 | skb = ieee80211_nullfunc_get(wl->hw, wl->vif); |
| 683 | if (!skb) |
| 684 | goto out; |
| 685 | |
| 686 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, |
| 687 | skb->data, skb->len, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 688 | CMD_TEMPL_KLV_IDX_NULL_DATA, |
Juuso Oikarinen | 8eab7b4 | 2010-09-24 03:10:11 +0200 | [diff] [blame] | 689 | wl->basic_rate); |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 690 | |
| 691 | out: |
| 692 | dev_kfree_skb(skb); |
| 693 | if (ret) |
| 694 | wl1271_warning("cmd build klv null data failed %d", ret); |
| 695 | |
| 696 | return ret; |
| 697 | |
| 698 | } |
| 699 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 700 | int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid) |
| 701 | { |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 702 | struct sk_buff *skb; |
| 703 | int ret = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 704 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 705 | skb = ieee80211_pspoll_get(wl->hw, wl->vif); |
| 706 | if (!skb) |
| 707 | goto out; |
Juuso Oikarinen | c3fea19 | 2009-10-08 21:56:22 +0300 | [diff] [blame] | 708 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 709 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data, |
Juuso Oikarinen | 849923f | 2010-07-08 17:49:59 +0300 | [diff] [blame] | 710 | skb->len, 0, wl->basic_rate_set); |
Juuso Oikarinen | c3fea19 | 2009-10-08 21:56:22 +0300 | [diff] [blame] | 711 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 712 | out: |
| 713 | dev_kfree_skb(skb); |
| 714 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 715 | } |
| 716 | |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 717 | int wl1271_cmd_build_probe_req(struct wl1271 *wl, |
| 718 | const u8 *ssid, size_t ssid_len, |
| 719 | const u8 *ie, size_t ie_len, u8 band) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 720 | { |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 721 | struct sk_buff *skb; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 722 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 723 | |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 724 | skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len, |
| 725 | ie, ie_len); |
| 726 | if (!skb) { |
| 727 | ret = -ENOMEM; |
| 728 | goto out; |
| 729 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 730 | |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 731 | wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 732 | |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 733 | if (band == IEEE80211_BAND_2GHZ) |
| 734 | 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] | 735 | skb->data, skb->len, 0, |
| 736 | wl->conf.tx.basic_rate); |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 737 | else |
| 738 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 739 | skb->data, skb->len, 0, |
| 740 | wl->conf.tx.basic_rate_5); |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 741 | |
| 742 | out: |
| 743 | dev_kfree_skb(skb); |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 744 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 745 | } |
| 746 | |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 747 | struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl, |
| 748 | struct sk_buff *skb) |
| 749 | { |
| 750 | int ret; |
| 751 | |
| 752 | if (!skb) |
| 753 | skb = ieee80211_ap_probereq_get(wl->hw, wl->vif); |
| 754 | if (!skb) |
| 755 | goto out; |
| 756 | |
| 757 | wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len); |
| 758 | |
| 759 | if (wl->band == IEEE80211_BAND_2GHZ) |
| 760 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, |
| 761 | skb->data, skb->len, 0, |
| 762 | wl->conf.tx.basic_rate); |
| 763 | else |
| 764 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5, |
| 765 | skb->data, skb->len, 0, |
| 766 | wl->conf.tx.basic_rate_5); |
| 767 | |
| 768 | if (ret < 0) |
| 769 | wl1271_error("Unable to set ap probe request template."); |
| 770 | |
| 771 | out: |
| 772 | return skb; |
| 773 | } |
| 774 | |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 775 | int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr) |
| 776 | { |
| 777 | int ret; |
| 778 | struct wl12xx_arp_rsp_template tmpl; |
| 779 | struct ieee80211_hdr_3addr *hdr; |
| 780 | struct arphdr *arp_hdr; |
| 781 | |
| 782 | memset(&tmpl, 0, sizeof(tmpl)); |
| 783 | |
| 784 | /* mac80211 header */ |
| 785 | hdr = &tmpl.hdr; |
| 786 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 787 | IEEE80211_STYPE_DATA | |
| 788 | IEEE80211_FCTL_TODS); |
| 789 | memcpy(hdr->addr1, wl->vif->bss_conf.bssid, ETH_ALEN); |
| 790 | memcpy(hdr->addr2, wl->vif->addr, ETH_ALEN); |
| 791 | memset(hdr->addr3, 0xff, ETH_ALEN); |
| 792 | |
| 793 | /* llc layer */ |
| 794 | memcpy(tmpl.llc_hdr, rfc1042_header, sizeof(rfc1042_header)); |
Eliad Peller | 6177eae | 2010-12-22 12:38:52 +0100 | [diff] [blame] | 795 | tmpl.llc_type = cpu_to_be16(ETH_P_ARP); |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 796 | |
| 797 | /* arp header */ |
| 798 | arp_hdr = &tmpl.arp_hdr; |
Eliad Peller | 6177eae | 2010-12-22 12:38:52 +0100 | [diff] [blame] | 799 | arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER); |
| 800 | arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP); |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 801 | arp_hdr->ar_hln = ETH_ALEN; |
| 802 | arp_hdr->ar_pln = 4; |
Eliad Peller | 6177eae | 2010-12-22 12:38:52 +0100 | [diff] [blame] | 803 | arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY); |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 804 | |
| 805 | /* arp payload */ |
| 806 | memcpy(tmpl.sender_hw, wl->vif->addr, ETH_ALEN); |
| 807 | tmpl.sender_ip = ip_addr; |
| 808 | |
| 809 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, |
| 810 | &tmpl, sizeof(tmpl), 0, |
| 811 | wl->basic_rate); |
| 812 | |
| 813 | return ret; |
| 814 | } |
| 815 | |
Kalle Valo | 023e082 | 2010-03-18 12:26:36 +0200 | [diff] [blame] | 816 | int wl1271_build_qos_null_data(struct wl1271 *wl) |
| 817 | { |
| 818 | struct ieee80211_qos_hdr template; |
| 819 | |
| 820 | memset(&template, 0, sizeof(template)); |
| 821 | |
| 822 | memcpy(template.addr1, wl->bssid, ETH_ALEN); |
| 823 | memcpy(template.addr2, wl->mac_addr, ETH_ALEN); |
| 824 | memcpy(template.addr3, wl->bssid, ETH_ALEN); |
| 825 | |
| 826 | template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 827 | IEEE80211_STYPE_QOS_NULLFUNC | |
| 828 | IEEE80211_FCTL_TODS); |
| 829 | |
| 830 | /* FIXME: not sure what priority to use here */ |
| 831 | template.qos_ctrl = cpu_to_le16(0); |
| 832 | |
| 833 | return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 834 | sizeof(template), 0, |
Juuso Oikarinen | 8eab7b4 | 2010-09-24 03:10:11 +0200 | [diff] [blame] | 835 | wl->basic_rate); |
Kalle Valo | 023e082 | 2010-03-18 12:26:36 +0200 | [diff] [blame] | 836 | } |
| 837 | |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 838 | int wl1271_cmd_set_sta_default_wep_key(struct wl1271 *wl, u8 id) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 839 | { |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 840 | struct wl1271_cmd_set_sta_keys *cmd; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 841 | int ret = 0; |
| 842 | |
| 843 | wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id); |
| 844 | |
| 845 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 846 | if (!cmd) { |
| 847 | ret = -ENOMEM; |
| 848 | goto out; |
| 849 | } |
| 850 | |
| 851 | cmd->id = id; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 852 | cmd->key_action = cpu_to_le16(KEY_SET_ID); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 853 | cmd->key_type = KEY_WEP; |
| 854 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 855 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 856 | if (ret < 0) { |
| 857 | wl1271_warning("cmd set_default_wep_key failed: %d", ret); |
| 858 | goto out; |
| 859 | } |
| 860 | |
| 861 | out: |
| 862 | kfree(cmd); |
| 863 | |
| 864 | return ret; |
| 865 | } |
| 866 | |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 867 | int wl1271_cmd_set_ap_default_wep_key(struct wl1271 *wl, u8 id) |
| 868 | { |
| 869 | struct wl1271_cmd_set_ap_keys *cmd; |
| 870 | int ret = 0; |
| 871 | |
| 872 | wl1271_debug(DEBUG_CMD, "cmd set_ap_default_wep_key %d", id); |
| 873 | |
| 874 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 875 | if (!cmd) { |
| 876 | ret = -ENOMEM; |
| 877 | goto out; |
| 878 | } |
| 879 | |
| 880 | cmd->hlid = WL1271_AP_BROADCAST_HLID; |
| 881 | cmd->key_id = id; |
| 882 | cmd->lid_key_type = WEP_DEFAULT_LID_TYPE; |
| 883 | cmd->key_action = cpu_to_le16(KEY_SET_ID); |
| 884 | cmd->key_type = KEY_WEP; |
| 885 | |
| 886 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); |
| 887 | if (ret < 0) { |
| 888 | wl1271_warning("cmd set_ap_default_wep_key failed: %d", ret); |
| 889 | goto out; |
| 890 | } |
| 891 | |
| 892 | out: |
| 893 | kfree(cmd); |
| 894 | |
| 895 | return ret; |
| 896 | } |
| 897 | |
| 898 | int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 899 | u8 key_size, const u8 *key, const u8 *addr, |
| 900 | u32 tx_seq_32, u16 tx_seq_16) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 901 | { |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 902 | struct wl1271_cmd_set_sta_keys *cmd; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 903 | int ret = 0; |
| 904 | |
| 905 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 906 | if (!cmd) { |
| 907 | ret = -ENOMEM; |
| 908 | goto out; |
| 909 | } |
| 910 | |
| 911 | if (key_type != KEY_WEP) |
| 912 | memcpy(cmd->addr, addr, ETH_ALEN); |
| 913 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 914 | cmd->key_action = cpu_to_le16(action); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 915 | cmd->key_size = key_size; |
| 916 | cmd->key_type = key_type; |
| 917 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 918 | cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16); |
| 919 | cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32); |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 920 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 921 | /* we have only one SSID profile */ |
| 922 | cmd->ssid_profile = 0; |
| 923 | |
| 924 | cmd->id = id; |
| 925 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 926 | if (key_type == KEY_TKIP) { |
| 927 | /* |
| 928 | * We get the key in the following form: |
| 929 | * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes) |
| 930 | * but the target is expecting: |
| 931 | * TKIP - RX MIC - TX MIC |
| 932 | */ |
| 933 | memcpy(cmd->key, key, 16); |
| 934 | memcpy(cmd->key + 16, key + 24, 8); |
| 935 | memcpy(cmd->key + 24, key + 16, 8); |
| 936 | |
| 937 | } else { |
| 938 | memcpy(cmd->key, key, key_size); |
| 939 | } |
| 940 | |
| 941 | wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd)); |
| 942 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 943 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 944 | if (ret < 0) { |
| 945 | wl1271_warning("could not set keys"); |
Juuso Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 946 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | out: |
| 950 | kfree(cmd); |
| 951 | |
| 952 | return ret; |
| 953 | } |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 954 | |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 955 | int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, |
| 956 | u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32, |
| 957 | u16 tx_seq_16) |
| 958 | { |
| 959 | struct wl1271_cmd_set_ap_keys *cmd; |
| 960 | int ret = 0; |
| 961 | u8 lid_type; |
| 962 | |
| 963 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 964 | if (!cmd) |
| 965 | return -ENOMEM; |
| 966 | |
| 967 | if (hlid == WL1271_AP_BROADCAST_HLID) { |
| 968 | if (key_type == KEY_WEP) |
| 969 | lid_type = WEP_DEFAULT_LID_TYPE; |
| 970 | else |
| 971 | lid_type = BROADCAST_LID_TYPE; |
| 972 | } else { |
| 973 | lid_type = UNICAST_LID_TYPE; |
| 974 | } |
| 975 | |
| 976 | wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d" |
| 977 | " hlid: %d", (int)action, (int)id, (int)lid_type, |
| 978 | (int)key_type, (int)hlid); |
| 979 | |
| 980 | cmd->lid_key_type = lid_type; |
| 981 | cmd->hlid = hlid; |
| 982 | cmd->key_action = cpu_to_le16(action); |
| 983 | cmd->key_size = key_size; |
| 984 | cmd->key_type = key_type; |
| 985 | cmd->key_id = id; |
| 986 | cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16); |
| 987 | cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32); |
| 988 | |
| 989 | if (key_type == KEY_TKIP) { |
| 990 | /* |
| 991 | * We get the key in the following form: |
| 992 | * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes) |
| 993 | * but the target is expecting: |
| 994 | * TKIP - RX MIC - TX MIC |
| 995 | */ |
| 996 | memcpy(cmd->key, key, 16); |
| 997 | memcpy(cmd->key + 16, key + 24, 8); |
| 998 | memcpy(cmd->key + 24, key + 16, 8); |
| 999 | } else { |
| 1000 | memcpy(cmd->key, key, key_size); |
| 1001 | } |
| 1002 | |
| 1003 | wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd)); |
| 1004 | |
| 1005 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); |
| 1006 | if (ret < 0) { |
| 1007 | wl1271_warning("could not set ap keys"); |
| 1008 | goto out; |
| 1009 | } |
| 1010 | |
| 1011 | out: |
| 1012 | kfree(cmd); |
| 1013 | return ret; |
| 1014 | } |
| 1015 | |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 1016 | int wl1271_cmd_disconnect(struct wl1271 *wl) |
| 1017 | { |
| 1018 | struct wl1271_cmd_disconnect *cmd; |
| 1019 | int ret = 0; |
| 1020 | |
| 1021 | wl1271_debug(DEBUG_CMD, "cmd disconnect"); |
| 1022 | |
| 1023 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1024 | if (!cmd) { |
| 1025 | ret = -ENOMEM; |
| 1026 | goto out; |
| 1027 | } |
| 1028 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 1029 | cmd->rx_config_options = cpu_to_le32(wl->rx_config); |
| 1030 | cmd->rx_filter_options = cpu_to_le32(wl->rx_filter); |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 1031 | /* disconnect reason is not used in immediate disconnections */ |
| 1032 | cmd->type = DISCONNECT_IMMEDIATE; |
| 1033 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 1034 | ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0); |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 1035 | if (ret < 0) { |
| 1036 | wl1271_error("failed to send disconnect command"); |
| 1037 | goto out_free; |
| 1038 | } |
| 1039 | |
Luciano Coelho | 2f826f5 | 2010-03-26 12:53:21 +0200 | [diff] [blame] | 1040 | ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID); |
| 1041 | if (ret < 0) |
| 1042 | wl1271_error("cmd disconnect event completion error"); |
| 1043 | |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 1044 | out_free: |
| 1045 | kfree(cmd); |
| 1046 | |
| 1047 | out: |
| 1048 | return ret; |
| 1049 | } |
Juuso Oikarinen | be86cbe | 2010-05-27 12:53:01 +0300 | [diff] [blame] | 1050 | |
| 1051 | int wl1271_cmd_set_sta_state(struct wl1271 *wl) |
| 1052 | { |
| 1053 | struct wl1271_cmd_set_sta_state *cmd; |
| 1054 | int ret = 0; |
| 1055 | |
| 1056 | wl1271_debug(DEBUG_CMD, "cmd set sta state"); |
| 1057 | |
| 1058 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1059 | if (!cmd) { |
| 1060 | ret = -ENOMEM; |
| 1061 | goto out; |
| 1062 | } |
| 1063 | |
| 1064 | cmd->state = WL1271_CMD_STA_STATE_CONNECTED; |
| 1065 | |
| 1066 | ret = wl1271_cmd_send(wl, CMD_SET_STA_STATE, cmd, sizeof(*cmd), 0); |
| 1067 | if (ret < 0) { |
| 1068 | wl1271_error("failed to send set STA state command"); |
| 1069 | goto out_free; |
| 1070 | } |
| 1071 | |
| 1072 | out_free: |
| 1073 | kfree(cmd); |
| 1074 | |
| 1075 | out: |
| 1076 | return ret; |
| 1077 | } |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1078 | |
| 1079 | int wl1271_cmd_start_bss(struct wl1271 *wl) |
| 1080 | { |
| 1081 | struct wl1271_cmd_bss_start *cmd; |
| 1082 | struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf; |
| 1083 | int ret; |
| 1084 | |
| 1085 | wl1271_debug(DEBUG_CMD, "cmd start bss"); |
| 1086 | |
| 1087 | /* |
| 1088 | * FIXME: We currently do not support hidden SSID. The real SSID |
| 1089 | * should be fetched from mac80211 first. |
| 1090 | */ |
| 1091 | if (wl->ssid_len == 0) { |
| 1092 | wl1271_warning("Hidden SSID currently not supported for AP"); |
| 1093 | ret = -EINVAL; |
| 1094 | goto out; |
| 1095 | } |
| 1096 | |
| 1097 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1098 | if (!cmd) { |
| 1099 | ret = -ENOMEM; |
| 1100 | goto out; |
| 1101 | } |
| 1102 | |
| 1103 | memcpy(cmd->bssid, bss_conf->bssid, ETH_ALEN); |
| 1104 | |
Luciano Coelho | 25eaea30 | 2011-05-02 12:37:33 +0300 | [diff] [blame] | 1105 | cmd->aging_period = cpu_to_le16(WL1271_AP_DEF_INACTIV_SEC); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1106 | cmd->bss_index = WL1271_AP_BSS_INDEX; |
| 1107 | cmd->global_hlid = WL1271_AP_GLOBAL_HLID; |
| 1108 | cmd->broadcast_hlid = WL1271_AP_BROADCAST_HLID; |
| 1109 | cmd->basic_rate_set = cpu_to_le32(wl->basic_rate_set); |
| 1110 | cmd->beacon_interval = cpu_to_le16(wl->beacon_int); |
| 1111 | cmd->dtim_interval = bss_conf->dtim_period; |
| 1112 | cmd->beacon_expiry = WL1271_AP_DEF_BEACON_EXP; |
| 1113 | cmd->channel = wl->channel; |
| 1114 | cmd->ssid_len = wl->ssid_len; |
| 1115 | cmd->ssid_type = SSID_TYPE_PUBLIC; |
| 1116 | memcpy(cmd->ssid, wl->ssid, wl->ssid_len); |
| 1117 | |
| 1118 | switch (wl->band) { |
| 1119 | case IEEE80211_BAND_2GHZ: |
| 1120 | cmd->band = RADIO_BAND_2_4GHZ; |
| 1121 | break; |
| 1122 | case IEEE80211_BAND_5GHZ: |
| 1123 | cmd->band = RADIO_BAND_5GHZ; |
| 1124 | break; |
| 1125 | default: |
| 1126 | wl1271_warning("bss start - unknown band: %d", (int)wl->band); |
| 1127 | cmd->band = RADIO_BAND_2_4GHZ; |
| 1128 | break; |
| 1129 | } |
| 1130 | |
| 1131 | ret = wl1271_cmd_send(wl, CMD_BSS_START, cmd, sizeof(*cmd), 0); |
| 1132 | if (ret < 0) { |
| 1133 | wl1271_error("failed to initiate cmd start bss"); |
| 1134 | goto out_free; |
| 1135 | } |
| 1136 | |
| 1137 | out_free: |
| 1138 | kfree(cmd); |
| 1139 | |
| 1140 | out: |
| 1141 | return ret; |
| 1142 | } |
| 1143 | |
| 1144 | int wl1271_cmd_stop_bss(struct wl1271 *wl) |
| 1145 | { |
| 1146 | struct wl1271_cmd_bss_start *cmd; |
| 1147 | int ret; |
| 1148 | |
| 1149 | wl1271_debug(DEBUG_CMD, "cmd stop bss"); |
| 1150 | |
| 1151 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1152 | if (!cmd) { |
| 1153 | ret = -ENOMEM; |
| 1154 | goto out; |
| 1155 | } |
| 1156 | |
| 1157 | cmd->bss_index = WL1271_AP_BSS_INDEX; |
| 1158 | |
| 1159 | ret = wl1271_cmd_send(wl, CMD_BSS_STOP, cmd, sizeof(*cmd), 0); |
| 1160 | if (ret < 0) { |
| 1161 | wl1271_error("failed to initiate cmd stop bss"); |
| 1162 | goto out_free; |
| 1163 | } |
| 1164 | |
| 1165 | out_free: |
| 1166 | kfree(cmd); |
| 1167 | |
| 1168 | out: |
| 1169 | return ret; |
| 1170 | } |
| 1171 | |
| 1172 | int wl1271_cmd_add_sta(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid) |
| 1173 | { |
| 1174 | struct wl1271_cmd_add_sta *cmd; |
| 1175 | int ret; |
| 1176 | |
| 1177 | wl1271_debug(DEBUG_CMD, "cmd add sta %d", (int)hlid); |
| 1178 | |
| 1179 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1180 | if (!cmd) { |
| 1181 | ret = -ENOMEM; |
| 1182 | goto out; |
| 1183 | } |
| 1184 | |
| 1185 | /* currently we don't support UAPSD */ |
| 1186 | cmd->sp_len = 0; |
| 1187 | |
| 1188 | memcpy(cmd->addr, sta->addr, ETH_ALEN); |
| 1189 | cmd->bss_index = WL1271_AP_BSS_INDEX; |
| 1190 | cmd->aid = sta->aid; |
| 1191 | cmd->hlid = hlid; |
| 1192 | |
| 1193 | /* |
| 1194 | * FIXME: Does STA support QOS? We need to propagate this info from |
| 1195 | * hostapd. Currently not that important since this is only used for |
| 1196 | * sending the correct flavor of null-data packet in response to a |
| 1197 | * trigger. |
| 1198 | */ |
| 1199 | cmd->wmm = 0; |
| 1200 | |
| 1201 | cmd->supported_rates = cpu_to_le32(wl1271_tx_enabled_rates_get(wl, |
| 1202 | sta->supp_rates[wl->band])); |
| 1203 | |
| 1204 | wl1271_debug(DEBUG_CMD, "new sta rates: 0x%x", cmd->supported_rates); |
| 1205 | |
| 1206 | ret = wl1271_cmd_send(wl, CMD_ADD_STA, cmd, sizeof(*cmd), 0); |
| 1207 | if (ret < 0) { |
| 1208 | wl1271_error("failed to initiate cmd add sta"); |
| 1209 | goto out_free; |
| 1210 | } |
| 1211 | |
| 1212 | out_free: |
| 1213 | kfree(cmd); |
| 1214 | |
| 1215 | out: |
| 1216 | return ret; |
| 1217 | } |
| 1218 | |
| 1219 | int wl1271_cmd_remove_sta(struct wl1271 *wl, u8 hlid) |
| 1220 | { |
| 1221 | struct wl1271_cmd_remove_sta *cmd; |
| 1222 | int ret; |
| 1223 | |
| 1224 | wl1271_debug(DEBUG_CMD, "cmd remove sta %d", (int)hlid); |
| 1225 | |
| 1226 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1227 | if (!cmd) { |
| 1228 | ret = -ENOMEM; |
| 1229 | goto out; |
| 1230 | } |
| 1231 | |
| 1232 | cmd->hlid = hlid; |
| 1233 | /* We never send a deauth, mac80211 is in charge of this */ |
| 1234 | cmd->reason_opcode = 0; |
| 1235 | cmd->send_deauth_flag = 0; |
| 1236 | |
| 1237 | ret = wl1271_cmd_send(wl, CMD_REMOVE_STA, cmd, sizeof(*cmd), 0); |
| 1238 | if (ret < 0) { |
| 1239 | wl1271_error("failed to initiate cmd remove sta"); |
| 1240 | goto out_free; |
| 1241 | } |
| 1242 | |
Arik Nemtsov | 05285cf | 2010-11-12 17:15:03 +0200 | [diff] [blame] | 1243 | /* |
| 1244 | * We are ok with a timeout here. The event is sometimes not sent |
| 1245 | * due to a firmware bug. |
| 1246 | */ |
| 1247 | wl1271_cmd_wait_for_event_or_timeout(wl, STA_REMOVE_COMPLETE_EVENT_ID); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1248 | |
| 1249 | out_free: |
| 1250 | kfree(cmd); |
| 1251 | |
| 1252 | out: |
| 1253 | return ret; |
| 1254 | } |