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