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