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" |
Luciano Coelho | 0f4e312 | 2011-10-07 11:02:42 +0300 | [diff] [blame] | 32 | #include "debug.h" |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 33 | #include "reg.h" |
| 34 | #include "io.h" |
| 35 | #include "acx.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 36 | #include "wl12xx_80211.h" |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 37 | #include "cmd.h" |
| 38 | #include "event.h" |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 39 | #include "tx.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 40 | |
Juuso Oikarinen | 16092b5 | 2010-04-28 09:49:59 +0300 | [diff] [blame] | 41 | #define WL1271_CMD_FAST_POLL_COUNT 50 |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * send command to firmware |
| 45 | * |
| 46 | * @wl: wl struct |
| 47 | * @id: command id |
| 48 | * @buf: buffer containing the command, must work with dma |
| 49 | * @len: length of the buffer |
| 50 | */ |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 51 | int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len, |
| 52 | size_t res_len) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 53 | { |
| 54 | struct wl1271_cmd_header *cmd; |
| 55 | unsigned long timeout; |
| 56 | u32 intr; |
| 57 | int ret = 0; |
Juuso Oikarinen | ad150e9 | 2009-11-02 20:22:12 +0200 | [diff] [blame] | 58 | u16 status; |
Saravanan Dhanabal | bc0f03e | 2010-03-26 12:53:33 +0200 | [diff] [blame] | 59 | u16 poll_count = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 60 | |
| 61 | cmd = buf; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 62 | cmd->id = cpu_to_le16(id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 63 | cmd->status = 0; |
| 64 | |
| 65 | WARN_ON(len % 4 != 0); |
Arik Nemtsov | 24225b3 | 2011-03-01 12:27:26 +0200 | [diff] [blame] | 66 | WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 67 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 68 | wl1271_write(wl, wl->cmd_box_addr, buf, len, false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 69 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 70 | wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 71 | |
| 72 | timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT); |
| 73 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 74 | intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 75 | while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) { |
| 76 | if (time_after(jiffies, timeout)) { |
| 77 | wl1271_error("command complete timeout"); |
| 78 | ret = -ETIMEDOUT; |
Arik Nemtsov | f482b76 | 2011-04-18 14:15:23 +0300 | [diff] [blame] | 79 | goto fail; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 80 | } |
| 81 | |
Saravanan Dhanabal | bc0f03e | 2010-03-26 12:53:33 +0200 | [diff] [blame] | 82 | poll_count++; |
Juuso Oikarinen | 16092b5 | 2010-04-28 09:49:59 +0300 | [diff] [blame] | 83 | if (poll_count < WL1271_CMD_FAST_POLL_COUNT) |
| 84 | udelay(10); |
| 85 | else |
| 86 | msleep(1); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 87 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 88 | intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 89 | } |
| 90 | |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 91 | /* read back the status code of the command */ |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 92 | if (res_len == 0) |
| 93 | res_len = sizeof(struct wl1271_cmd_header); |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 94 | wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false); |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 95 | |
Juuso Oikarinen | ad150e9 | 2009-11-02 20:22:12 +0200 | [diff] [blame] | 96 | status = le16_to_cpu(cmd->status); |
| 97 | if (status != CMD_STATUS_SUCCESS) { |
| 98 | wl1271_error("command execute failure %d", status); |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 99 | ret = -EIO; |
Arik Nemtsov | f482b76 | 2011-04-18 14:15:23 +0300 | [diff] [blame] | 100 | goto fail; |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 101 | } |
| 102 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 103 | wl1271_write32(wl, ACX_REG_INTERRUPT_ACK, |
| 104 | WL1271_ACX_INTR_CMD_COMPLETE); |
Arik Nemtsov | f482b76 | 2011-04-18 14:15:23 +0300 | [diff] [blame] | 105 | return 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 106 | |
Arik Nemtsov | f482b76 | 2011-04-18 14:15:23 +0300 | [diff] [blame] | 107 | fail: |
| 108 | WARN_ON(1); |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 109 | wl12xx_queue_recovery_work(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 110 | return ret; |
| 111 | } |
| 112 | |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 113 | int wl1271_cmd_general_parms(struct wl1271 *wl) |
| 114 | { |
| 115 | struct wl1271_general_parms_cmd *gen_parms; |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 116 | struct wl1271_ini_general_params *gp = |
| 117 | &((struct wl1271_nvs_file *)wl->nvs)->general_params; |
| 118 | bool answer = false; |
| 119 | int ret; |
| 120 | |
| 121 | if (!wl->nvs) |
| 122 | return -ENODEV; |
| 123 | |
Pontus Fuchs | 2131d3c | 2011-10-18 09:23:41 +0200 | [diff] [blame] | 124 | if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) { |
| 125 | wl1271_warning("FEM index from INI out of bounds"); |
| 126 | return -EINVAL; |
| 127 | } |
| 128 | |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 129 | gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL); |
| 130 | if (!gen_parms) |
| 131 | return -ENOMEM; |
| 132 | |
| 133 | gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM; |
| 134 | |
| 135 | memcpy(&gen_parms->general_params, gp, sizeof(*gp)); |
| 136 | |
| 137 | if (gp->tx_bip_fem_auto_detect) |
| 138 | answer = true; |
| 139 | |
Shahar Levi | b03acad | 2011-04-03 13:54:54 +0300 | [diff] [blame] | 140 | /* Override the REF CLK from the NVS with the one from platform data */ |
| 141 | gen_parms->general_params.ref_clock = wl->ref_clock; |
| 142 | |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 143 | ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer); |
| 144 | if (ret < 0) { |
| 145 | wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed"); |
| 146 | goto out; |
| 147 | } |
| 148 | |
| 149 | gp->tx_bip_fem_manufacturer = |
| 150 | gen_parms->general_params.tx_bip_fem_manufacturer; |
| 151 | |
Pontus Fuchs | 2131d3c | 2011-10-18 09:23:41 +0200 | [diff] [blame] | 152 | if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) { |
| 153 | wl1271_warning("FEM index from FW out of bounds"); |
| 154 | ret = -EINVAL; |
| 155 | goto out; |
| 156 | } |
| 157 | |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 158 | wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n", |
| 159 | answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer); |
| 160 | |
| 161 | out: |
| 162 | kfree(gen_parms); |
| 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | int wl128x_cmd_general_parms(struct wl1271 *wl) |
| 167 | { |
| 168 | struct wl128x_general_parms_cmd *gen_parms; |
| 169 | struct wl128x_ini_general_params *gp = |
| 170 | &((struct wl128x_nvs_file *)wl->nvs)->general_params; |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 171 | bool answer = false; |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 172 | int ret; |
| 173 | |
Juuso Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 174 | if (!wl->nvs) |
| 175 | return -ENODEV; |
| 176 | |
Pontus Fuchs | 2131d3c | 2011-10-18 09:23:41 +0200 | [diff] [blame] | 177 | if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) { |
| 178 | wl1271_warning("FEM index from ini out of bounds"); |
| 179 | return -EINVAL; |
| 180 | } |
| 181 | |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 182 | gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL); |
| 183 | if (!gen_parms) |
| 184 | return -ENOMEM; |
| 185 | |
| 186 | gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM; |
| 187 | |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 188 | memcpy(&gen_parms->general_params, gp, sizeof(*gp)); |
Luciano Coelho | 76c0f8d | 2009-12-11 15:40:41 +0200 | [diff] [blame] | 189 | |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 190 | if (gp->tx_bip_fem_auto_detect) |
| 191 | answer = true; |
| 192 | |
Shahar Levi | b03acad | 2011-04-03 13:54:54 +0300 | [diff] [blame] | 193 | /* Replace REF and TCXO CLKs with the ones from platform data */ |
| 194 | gen_parms->general_params.ref_clock = wl->ref_clock; |
| 195 | gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock; |
| 196 | |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 197 | ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer); |
| 198 | if (ret < 0) { |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 199 | wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed"); |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 200 | goto out; |
| 201 | } |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 202 | |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 203 | gp->tx_bip_fem_manufacturer = |
| 204 | gen_parms->general_params.tx_bip_fem_manufacturer; |
| 205 | |
Pontus Fuchs | 2131d3c | 2011-10-18 09:23:41 +0200 | [diff] [blame] | 206 | if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) { |
| 207 | wl1271_warning("FEM index from FW out of bounds"); |
| 208 | ret = -EINVAL; |
| 209 | goto out; |
| 210 | } |
| 211 | |
Juuso Oikarinen | 4b34d43 | 2010-10-07 10:16:42 +0300 | [diff] [blame] | 212 | wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n", |
| 213 | answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer); |
| 214 | |
| 215 | out: |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 216 | kfree(gen_parms); |
| 217 | return ret; |
| 218 | } |
| 219 | |
| 220 | int wl1271_cmd_radio_parms(struct wl1271 *wl) |
| 221 | { |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 222 | struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs; |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 223 | struct wl1271_radio_parms_cmd *radio_parms; |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 224 | struct wl1271_ini_general_params *gp = &nvs->general_params; |
Juuso Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 225 | int ret; |
| 226 | |
| 227 | if (!wl->nvs) |
| 228 | return -ENODEV; |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 229 | |
| 230 | radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL); |
| 231 | if (!radio_parms) |
| 232 | return -ENOMEM; |
| 233 | |
| 234 | radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM; |
| 235 | |
Juuso Oikarinen | a7da74f | 2010-05-14 10:46:23 +0300 | [diff] [blame] | 236 | /* 2.4GHz parameters */ |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 237 | memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2, |
Juuso Oikarinen | eb70eb7 | 2010-05-14 10:46:22 +0300 | [diff] [blame] | 238 | sizeof(struct wl1271_ini_band_params_2)); |
| 239 | memcpy(&radio_parms->dyn_params_2, |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 240 | &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params, |
Juuso Oikarinen | eb70eb7 | 2010-05-14 10:46:22 +0300 | [diff] [blame] | 241 | sizeof(struct wl1271_ini_fem_params_2)); |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 242 | |
Juuso Oikarinen | a7da74f | 2010-05-14 10:46:23 +0300 | [diff] [blame] | 243 | /* 5GHz parameters */ |
| 244 | memcpy(&radio_parms->static_params_5, |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 245 | &nvs->stat_radio_params_5, |
Juuso Oikarinen | a7da74f | 2010-05-14 10:46:23 +0300 | [diff] [blame] | 246 | sizeof(struct wl1271_ini_band_params_5)); |
| 247 | memcpy(&radio_parms->dyn_params_5, |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 248 | &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params, |
Juuso Oikarinen | a7da74f | 2010-05-14 10:46:23 +0300 | [diff] [blame] | 249 | sizeof(struct wl1271_ini_fem_params_5)); |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 250 | |
| 251 | wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ", |
| 252 | radio_parms, sizeof(*radio_parms)); |
| 253 | |
| 254 | ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0); |
| 255 | if (ret < 0) |
| 256 | wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed"); |
| 257 | |
| 258 | kfree(radio_parms); |
| 259 | return ret; |
| 260 | } |
| 261 | |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 262 | int wl128x_cmd_radio_parms(struct wl1271 *wl) |
| 263 | { |
| 264 | struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs; |
| 265 | struct wl128x_radio_parms_cmd *radio_parms; |
| 266 | struct wl128x_ini_general_params *gp = &nvs->general_params; |
| 267 | int ret; |
| 268 | |
| 269 | if (!wl->nvs) |
| 270 | return -ENODEV; |
| 271 | |
| 272 | radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL); |
| 273 | if (!radio_parms) |
| 274 | return -ENOMEM; |
| 275 | |
| 276 | radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM; |
| 277 | |
| 278 | /* 2.4GHz parameters */ |
| 279 | memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2, |
| 280 | sizeof(struct wl128x_ini_band_params_2)); |
| 281 | memcpy(&radio_parms->dyn_params_2, |
| 282 | &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params, |
| 283 | sizeof(struct wl128x_ini_fem_params_2)); |
| 284 | |
| 285 | /* 5GHz parameters */ |
| 286 | memcpy(&radio_parms->static_params_5, |
| 287 | &nvs->stat_radio_params_5, |
| 288 | sizeof(struct wl128x_ini_band_params_5)); |
| 289 | memcpy(&radio_parms->dyn_params_5, |
| 290 | &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params, |
| 291 | sizeof(struct wl128x_ini_fem_params_5)); |
| 292 | |
| 293 | radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options; |
| 294 | |
| 295 | wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ", |
| 296 | radio_parms, sizeof(*radio_parms)); |
| 297 | |
| 298 | ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0); |
| 299 | if (ret < 0) |
| 300 | wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed"); |
| 301 | |
| 302 | kfree(radio_parms); |
| 303 | return ret; |
| 304 | } |
| 305 | |
Juuso Oikarinen | 644a486 | 2010-10-05 13:11:56 +0200 | [diff] [blame] | 306 | int wl1271_cmd_ext_radio_parms(struct wl1271 *wl) |
| 307 | { |
| 308 | struct wl1271_ext_radio_parms_cmd *ext_radio_parms; |
| 309 | struct conf_rf_settings *rf = &wl->conf.rf; |
| 310 | int ret; |
| 311 | |
| 312 | if (!wl->nvs) |
| 313 | return -ENODEV; |
| 314 | |
| 315 | ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL); |
| 316 | if (!ext_radio_parms) |
| 317 | return -ENOMEM; |
| 318 | |
| 319 | ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM; |
| 320 | |
| 321 | memcpy(ext_radio_parms->tx_per_channel_power_compensation_2, |
| 322 | rf->tx_per_channel_power_compensation_2, |
| 323 | CONF_TX_PWR_COMPENSATION_LEN_2); |
| 324 | memcpy(ext_radio_parms->tx_per_channel_power_compensation_5, |
| 325 | rf->tx_per_channel_power_compensation_5, |
| 326 | CONF_TX_PWR_COMPENSATION_LEN_5); |
| 327 | |
| 328 | wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ", |
| 329 | ext_radio_parms, sizeof(*ext_radio_parms)); |
| 330 | |
| 331 | ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0); |
| 332 | if (ret < 0) |
| 333 | wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed"); |
| 334 | |
| 335 | kfree(ext_radio_parms); |
| 336 | return ret; |
| 337 | } |
| 338 | |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 339 | /* |
| 340 | * Poll the mailbox event field until any of the bits in the mask is set or a |
| 341 | * timeout occurs (WL1271_EVENT_TIMEOUT in msecs) |
| 342 | */ |
Arik Nemtsov | 05285cf | 2010-11-12 17:15:03 +0200 | [diff] [blame] | 343 | static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask) |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 344 | { |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 345 | u32 *events_vector; |
| 346 | u32 event; |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 347 | unsigned long timeout; |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 348 | int ret = 0; |
| 349 | |
| 350 | events_vector = kmalloc(sizeof(*events_vector), GFP_DMA); |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 351 | |
| 352 | timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT); |
| 353 | |
| 354 | do { |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 355 | if (time_after(jiffies, timeout)) { |
Arik Nemtsov | 05285cf | 2010-11-12 17:15:03 +0200 | [diff] [blame] | 356 | wl1271_debug(DEBUG_CMD, "timeout waiting for event %d", |
| 357 | (int)mask); |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 358 | ret = -ETIMEDOUT; |
| 359 | goto out; |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 360 | } |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 361 | |
| 362 | msleep(1); |
| 363 | |
| 364 | /* read from both event fields */ |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 365 | wl1271_read(wl, wl->mbox_ptr[0], events_vector, |
| 366 | sizeof(*events_vector), false); |
| 367 | event = *events_vector & mask; |
| 368 | wl1271_read(wl, wl->mbox_ptr[1], events_vector, |
| 369 | sizeof(*events_vector), false); |
| 370 | event |= *events_vector & mask; |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 371 | } while (!event); |
| 372 | |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 373 | out: |
| 374 | kfree(events_vector); |
| 375 | return ret; |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 376 | } |
| 377 | |
Arik Nemtsov | 05285cf | 2010-11-12 17:15:03 +0200 | [diff] [blame] | 378 | static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask) |
| 379 | { |
| 380 | int ret; |
| 381 | |
| 382 | ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask); |
| 383 | if (ret != 0) { |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 384 | wl12xx_queue_recovery_work(wl); |
Arik Nemtsov | 05285cf | 2010-11-12 17:15:03 +0200 | [diff] [blame] | 385 | return ret; |
| 386 | } |
| 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 391 | int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type, |
| 392 | u8 *role_id) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 393 | { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 394 | struct wl12xx_cmd_role_enable *cmd; |
| 395 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 396 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 397 | wl1271_debug(DEBUG_CMD, "cmd role enable"); |
| 398 | |
| 399 | if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID)) |
| 400 | return -EBUSY; |
| 401 | |
| 402 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 403 | if (!cmd) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 404 | ret = -ENOMEM; |
| 405 | goto out; |
| 406 | } |
| 407 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 408 | /* get role id */ |
| 409 | cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES); |
| 410 | if (cmd->role_id >= WL12XX_MAX_ROLES) { |
| 411 | ret = -EBUSY; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 412 | goto out_free; |
| 413 | } |
| 414 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 415 | memcpy(cmd->mac_address, addr, ETH_ALEN); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 416 | cmd->role_type = role_type; |
| 417 | |
| 418 | ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0); |
| 419 | if (ret < 0) { |
| 420 | wl1271_error("failed to initiate cmd role enable"); |
| 421 | goto out_free; |
| 422 | } |
| 423 | |
| 424 | __set_bit(cmd->role_id, wl->roles_map); |
| 425 | *role_id = cmd->role_id; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 426 | |
| 427 | out_free: |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 428 | kfree(cmd); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 429 | |
| 430 | out: |
| 431 | return ret; |
| 432 | } |
| 433 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 434 | int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id) |
| 435 | { |
| 436 | struct wl12xx_cmd_role_disable *cmd; |
| 437 | int ret; |
| 438 | |
| 439 | wl1271_debug(DEBUG_CMD, "cmd role disable"); |
| 440 | |
| 441 | if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID)) |
| 442 | return -ENOENT; |
| 443 | |
| 444 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 445 | if (!cmd) { |
| 446 | ret = -ENOMEM; |
| 447 | goto out; |
| 448 | } |
| 449 | cmd->role_id = *role_id; |
| 450 | |
| 451 | ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0); |
| 452 | if (ret < 0) { |
| 453 | wl1271_error("failed to initiate cmd role disable"); |
| 454 | goto out_free; |
| 455 | } |
| 456 | |
| 457 | __clear_bit(*role_id, wl->roles_map); |
| 458 | *role_id = WL12XX_INVALID_ROLE_ID; |
| 459 | |
| 460 | out_free: |
| 461 | kfree(cmd); |
| 462 | |
| 463 | out: |
| 464 | return ret; |
| 465 | } |
| 466 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 467 | int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 468 | { |
Arik Nemtsov | 0b0e32b | 2012-02-28 00:41:29 +0200 | [diff] [blame] | 469 | unsigned long flags; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 470 | u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS); |
| 471 | if (link >= WL12XX_MAX_LINKS) |
| 472 | return -EBUSY; |
| 473 | |
Arik Nemtsov | 0b0e32b | 2012-02-28 00:41:29 +0200 | [diff] [blame] | 474 | /* these bits are used by op_tx */ |
| 475 | spin_lock_irqsave(&wl->wl_lock, flags); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 476 | __set_bit(link, wl->links_map); |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 477 | __set_bit(link, wlvif->links_map); |
Arik Nemtsov | 0b0e32b | 2012-02-28 00:41:29 +0200 | [diff] [blame] | 478 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 479 | *hlid = link; |
| 480 | return 0; |
| 481 | } |
| 482 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 483 | void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 484 | { |
Arik Nemtsov | 0b0e32b | 2012-02-28 00:41:29 +0200 | [diff] [blame] | 485 | unsigned long flags; |
| 486 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 487 | if (*hlid == WL12XX_INVALID_LINK_ID) |
| 488 | return; |
| 489 | |
Arik Nemtsov | 0b0e32b | 2012-02-28 00:41:29 +0200 | [diff] [blame] | 490 | /* these bits are used by op_tx */ |
| 491 | spin_lock_irqsave(&wl->wl_lock, flags); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 492 | __clear_bit(*hlid, wl->links_map); |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 493 | __clear_bit(*hlid, wlvif->links_map); |
Arik Nemtsov | 0b0e32b | 2012-02-28 00:41:29 +0200 | [diff] [blame] | 494 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Arik Nemtsov | 6246ca0 | 2012-02-28 00:41:30 +0200 | [diff] [blame] | 495 | |
| 496 | /* |
| 497 | * At this point op_tx() will not add more packets to the queues. We |
| 498 | * can purge them. |
| 499 | */ |
| 500 | wl1271_tx_reset_link_queues(wl, *hlid); |
| 501 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 502 | *hlid = WL12XX_INVALID_LINK_ID; |
| 503 | } |
| 504 | |
Eliad Peller | 98b862530 | 2011-10-05 11:55:55 +0200 | [diff] [blame] | 505 | static int wl12xx_get_new_session_id(struct wl1271 *wl, |
| 506 | struct wl12xx_vif *wlvif) |
Arik Nemtsov | 712e9bf | 2011-08-14 13:17:20 +0300 | [diff] [blame] | 507 | { |
Eliad Peller | 98b862530 | 2011-10-05 11:55:55 +0200 | [diff] [blame] | 508 | if (wlvif->session_counter >= SESSION_COUNTER_MAX) |
| 509 | wlvif->session_counter = 0; |
Arik Nemtsov | 712e9bf | 2011-08-14 13:17:20 +0300 | [diff] [blame] | 510 | |
Eliad Peller | 98b862530 | 2011-10-05 11:55:55 +0200 | [diff] [blame] | 511 | wlvif->session_counter++; |
Arik Nemtsov | 712e9bf | 2011-08-14 13:17:20 +0300 | [diff] [blame] | 512 | |
Eliad Peller | 98b862530 | 2011-10-05 11:55:55 +0200 | [diff] [blame] | 513 | return wlvif->session_counter; |
Arik Nemtsov | 712e9bf | 2011-08-14 13:17:20 +0300 | [diff] [blame] | 514 | } |
| 515 | |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 516 | static int wl12xx_cmd_role_start_dev(struct wl1271 *wl, |
| 517 | struct wl12xx_vif *wlvif) |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 518 | { |
| 519 | struct wl12xx_cmd_role_start *cmd; |
| 520 | int ret; |
| 521 | |
| 522 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 523 | if (!cmd) { |
| 524 | ret = -ENOMEM; |
| 525 | goto out; |
| 526 | } |
| 527 | |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 528 | wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id); |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 529 | |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 530 | cmd->role_id = wlvif->dev_role_id; |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 531 | if (wlvif->band == IEEE80211_BAND_5GHZ) |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 532 | cmd->band = WL12XX_BAND_5GHZ; |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 533 | cmd->channel = wlvif->channel; |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 534 | |
Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 535 | if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) { |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 536 | ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid); |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 537 | if (ret) |
| 538 | goto out_free; |
| 539 | } |
Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 540 | cmd->device.hlid = wlvif->dev_hlid; |
Eliad Peller | b32b2b0 | 2012-03-04 10:55:49 +0200 | [diff] [blame] | 541 | cmd->device.session = wl12xx_get_new_session_id(wl, wlvif); |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 542 | |
| 543 | wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d", |
| 544 | cmd->role_id, cmd->device.hlid, cmd->device.session); |
| 545 | |
| 546 | ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); |
| 547 | if (ret < 0) { |
| 548 | wl1271_error("failed to initiate cmd role enable"); |
| 549 | goto err_hlid; |
| 550 | } |
| 551 | |
| 552 | goto out_free; |
| 553 | |
| 554 | err_hlid: |
| 555 | /* clear links on error */ |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 556 | wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid); |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 557 | |
| 558 | out_free: |
| 559 | kfree(cmd); |
| 560 | |
| 561 | out: |
| 562 | return ret; |
| 563 | } |
| 564 | |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 565 | static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl, |
| 566 | struct wl12xx_vif *wlvif) |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 567 | { |
| 568 | struct wl12xx_cmd_role_stop *cmd; |
| 569 | int ret; |
| 570 | |
Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 571 | if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID)) |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 572 | return -EINVAL; |
| 573 | |
| 574 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 575 | if (!cmd) { |
| 576 | ret = -ENOMEM; |
| 577 | goto out; |
| 578 | } |
| 579 | |
| 580 | wl1271_debug(DEBUG_CMD, "cmd role stop dev"); |
| 581 | |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 582 | cmd->role_id = wlvif->dev_role_id; |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 583 | cmd->disc_type = DISCONNECT_IMMEDIATE; |
| 584 | cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED); |
| 585 | |
| 586 | ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0); |
| 587 | if (ret < 0) { |
| 588 | wl1271_error("failed to initiate cmd role stop"); |
| 589 | goto out_free; |
| 590 | } |
| 591 | |
Eliad Peller | 8332f0f | 2012-01-31 11:57:19 +0200 | [diff] [blame] | 592 | ret = wl1271_cmd_wait_for_event(wl, ROLE_STOP_COMPLETE_EVENT_ID); |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 593 | if (ret < 0) { |
| 594 | wl1271_error("cmd role stop dev event completion error"); |
| 595 | goto out_free; |
| 596 | } |
| 597 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 598 | wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid); |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 599 | |
| 600 | out_free: |
| 601 | kfree(cmd); |
| 602 | |
| 603 | out: |
| 604 | return ret; |
| 605 | } |
| 606 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 607 | int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 608 | { |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 609 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 610 | struct wl12xx_cmd_role_start *cmd; |
| 611 | int ret; |
| 612 | |
| 613 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 614 | if (!cmd) { |
| 615 | ret = -ENOMEM; |
| 616 | goto out; |
| 617 | } |
| 618 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 619 | wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 620 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 621 | cmd->role_id = wlvif->role_id; |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 622 | if (wlvif->band == IEEE80211_BAND_5GHZ) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 623 | cmd->band = WL12XX_BAND_5GHZ; |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 624 | cmd->channel = wlvif->channel; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 625 | cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set); |
Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 626 | cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 627 | cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY; |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 628 | cmd->sta.ssid_len = wlvif->ssid_len; |
| 629 | memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len); |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 630 | memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN); |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 631 | cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 632 | |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 633 | if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) { |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 634 | ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 635 | if (ret) |
| 636 | goto out_free; |
| 637 | } |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 638 | cmd->sta.hlid = wlvif->sta.hlid; |
Eliad Peller | 98b862530 | 2011-10-05 11:55:55 +0200 | [diff] [blame] | 639 | cmd->sta.session = wl12xx_get_new_session_id(wl, wlvif); |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 640 | cmd->sta.remote_rates = cpu_to_le32(wlvif->rate_set); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 641 | |
| 642 | wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d " |
| 643 | "basic_rate_set: 0x%x, remote_rates: 0x%x", |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 644 | wlvif->role_id, cmd->sta.hlid, cmd->sta.session, |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 645 | wlvif->basic_rate_set, wlvif->rate_set); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 646 | |
| 647 | ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); |
| 648 | if (ret < 0) { |
| 649 | wl1271_error("failed to initiate cmd role start sta"); |
| 650 | goto err_hlid; |
| 651 | } |
| 652 | |
| 653 | goto out_free; |
| 654 | |
| 655 | err_hlid: |
| 656 | /* clear links on error. */ |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 657 | wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 658 | |
| 659 | out_free: |
| 660 | kfree(cmd); |
| 661 | |
| 662 | out: |
| 663 | return ret; |
| 664 | } |
| 665 | |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 666 | /* use this function to stop ibss as well */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 667 | int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 668 | { |
| 669 | struct wl12xx_cmd_role_stop *cmd; |
| 670 | int ret; |
| 671 | |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 672 | if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 673 | return -EINVAL; |
| 674 | |
| 675 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 676 | if (!cmd) { |
| 677 | ret = -ENOMEM; |
| 678 | goto out; |
| 679 | } |
| 680 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 681 | wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 682 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 683 | cmd->role_id = wlvif->role_id; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 684 | cmd->disc_type = DISCONNECT_IMMEDIATE; |
| 685 | cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED); |
| 686 | |
| 687 | ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0); |
| 688 | if (ret < 0) { |
| 689 | wl1271_error("failed to initiate cmd role stop sta"); |
| 690 | goto out_free; |
| 691 | } |
| 692 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 693 | wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 694 | |
| 695 | out_free: |
| 696 | kfree(cmd); |
| 697 | |
| 698 | out: |
| 699 | return ret; |
| 700 | } |
| 701 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 702 | int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 703 | { |
| 704 | struct wl12xx_cmd_role_start *cmd; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 705 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 706 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 707 | int ret; |
| 708 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 709 | wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 710 | |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 711 | /* trying to use hidden SSID with an old hostapd version */ |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 712 | if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) { |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 713 | wl1271_error("got a null SSID from beacon/bss"); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 714 | ret = -EINVAL; |
| 715 | goto out; |
| 716 | } |
| 717 | |
| 718 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 719 | if (!cmd) { |
| 720 | ret = -ENOMEM; |
| 721 | goto out; |
| 722 | } |
| 723 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 724 | ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid); |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 725 | if (ret < 0) |
| 726 | goto out_free; |
| 727 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 728 | ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid); |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 729 | if (ret < 0) |
| 730 | goto out_free_global; |
| 731 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 732 | cmd->role_id = wlvif->role_id; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 733 | cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period); |
| 734 | cmd->ap.bss_index = WL1271_AP_BSS_INDEX; |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 735 | cmd->ap.global_hlid = wlvif->ap.global_hlid; |
| 736 | cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 737 | cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set); |
Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 738 | cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 739 | cmd->ap.dtim_interval = bss_conf->dtim_period; |
| 740 | cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP; |
Eliad Peller | 8332f0f | 2012-01-31 11:57:19 +0200 | [diff] [blame] | 741 | /* FIXME: Change when adding DFS */ |
| 742 | cmd->ap.reset_tsf = 1; /* By default reset AP TSF */ |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 743 | cmd->channel = wlvif->channel; |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 744 | |
| 745 | if (!bss_conf->hidden_ssid) { |
| 746 | /* take the SSID from the beacon for backward compatibility */ |
| 747 | cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC; |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 748 | cmd->ap.ssid_len = wlvif->ssid_len; |
| 749 | memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len); |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 750 | } else { |
| 751 | cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN; |
| 752 | cmd->ap.ssid_len = bss_conf->ssid_len; |
| 753 | memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len); |
| 754 | } |
| 755 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 756 | cmd->ap.local_rates = cpu_to_le32(0xffffffff); |
| 757 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 758 | switch (wlvif->band) { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 759 | case IEEE80211_BAND_2GHZ: |
| 760 | cmd->band = RADIO_BAND_2_4GHZ; |
| 761 | break; |
| 762 | case IEEE80211_BAND_5GHZ: |
| 763 | cmd->band = RADIO_BAND_5GHZ; |
| 764 | break; |
| 765 | default: |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 766 | wl1271_warning("ap start - unknown band: %d", (int)wlvif->band); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 767 | cmd->band = RADIO_BAND_2_4GHZ; |
| 768 | break; |
| 769 | } |
| 770 | |
| 771 | ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); |
| 772 | if (ret < 0) { |
| 773 | wl1271_error("failed to initiate cmd role start ap"); |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 774 | goto out_free_bcast; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 775 | } |
| 776 | |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 777 | goto out_free; |
| 778 | |
| 779 | out_free_bcast: |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 780 | wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid); |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 781 | |
| 782 | out_free_global: |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 783 | wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid); |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 784 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 785 | out_free: |
| 786 | kfree(cmd); |
| 787 | |
| 788 | out: |
| 789 | return ret; |
| 790 | } |
| 791 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 792 | int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 793 | { |
| 794 | struct wl12xx_cmd_role_stop *cmd; |
| 795 | int ret; |
| 796 | |
| 797 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 798 | if (!cmd) { |
| 799 | ret = -ENOMEM; |
| 800 | goto out; |
| 801 | } |
| 802 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 803 | wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 804 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 805 | cmd->role_id = wlvif->role_id; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 806 | |
| 807 | ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0); |
| 808 | if (ret < 0) { |
| 809 | wl1271_error("failed to initiate cmd role stop ap"); |
| 810 | goto out_free; |
| 811 | } |
| 812 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 813 | wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid); |
| 814 | wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid); |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 815 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 816 | out_free: |
| 817 | kfree(cmd); |
| 818 | |
| 819 | out: |
| 820 | return ret; |
| 821 | } |
| 822 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 823 | int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 824 | { |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 825 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 826 | struct wl12xx_cmd_role_start *cmd; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 827 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 828 | int ret; |
| 829 | |
| 830 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 831 | if (!cmd) { |
| 832 | ret = -ENOMEM; |
| 833 | goto out; |
| 834 | } |
| 835 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 836 | wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 837 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 838 | cmd->role_id = wlvif->role_id; |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 839 | if (wlvif->band == IEEE80211_BAND_5GHZ) |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 840 | cmd->band = WL12XX_BAND_5GHZ; |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 841 | cmd->channel = wlvif->channel; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 842 | cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set); |
Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 843 | cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 844 | cmd->ibss.dtim_interval = bss_conf->dtim_period; |
| 845 | cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY; |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 846 | cmd->ibss.ssid_len = wlvif->ssid_len; |
| 847 | memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len); |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 848 | memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN); |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 849 | cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 850 | |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 851 | if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) { |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 852 | ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 853 | if (ret) |
| 854 | goto out_free; |
| 855 | } |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 856 | cmd->ibss.hlid = wlvif->sta.hlid; |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 857 | cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 858 | |
| 859 | wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d " |
| 860 | "basic_rate_set: 0x%x, remote_rates: 0x%x", |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 861 | wlvif->role_id, cmd->sta.hlid, cmd->sta.session, |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 862 | wlvif->basic_rate_set, wlvif->rate_set); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 863 | |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 864 | wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM", |
| 865 | vif->bss_conf.bssid); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 866 | |
| 867 | ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); |
| 868 | if (ret < 0) { |
| 869 | wl1271_error("failed to initiate cmd role enable"); |
| 870 | goto err_hlid; |
| 871 | } |
| 872 | |
| 873 | goto out_free; |
| 874 | |
| 875 | err_hlid: |
| 876 | /* clear links on error. */ |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 877 | wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 878 | |
| 879 | out_free: |
| 880 | kfree(cmd); |
| 881 | |
| 882 | out: |
| 883 | return ret; |
| 884 | } |
| 885 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 886 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 887 | /** |
| 888 | * send test command to firmware |
| 889 | * |
| 890 | * @wl: wl struct |
| 891 | * @buf: buffer containing the command, with all headers, must work with dma |
| 892 | * @len: length of the buffer |
| 893 | * @answer: is answer needed |
| 894 | */ |
| 895 | int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer) |
| 896 | { |
| 897 | int ret; |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 898 | size_t res_len = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 899 | |
| 900 | wl1271_debug(DEBUG_CMD, "cmd test"); |
| 901 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 902 | if (answer) |
| 903 | res_len = buf_len; |
| 904 | |
| 905 | ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 906 | |
| 907 | if (ret < 0) { |
| 908 | wl1271_warning("TEST command failed"); |
| 909 | return ret; |
| 910 | } |
| 911 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 912 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | /** |
| 916 | * read acx from firmware |
| 917 | * |
| 918 | * @wl: wl struct |
| 919 | * @id: acx id |
| 920 | * @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] | 921 | * @len: length of buf |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 922 | */ |
| 923 | int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len) |
| 924 | { |
| 925 | struct acx_header *acx = buf; |
| 926 | int ret; |
| 927 | |
| 928 | wl1271_debug(DEBUG_CMD, "cmd interrogate"); |
| 929 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 930 | acx->id = cpu_to_le16(id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 931 | |
| 932 | /* payload length, does not include any headers */ |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 933 | acx->len = cpu_to_le16(len - sizeof(*acx)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 934 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 935 | ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len); |
| 936 | if (ret < 0) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 937 | wl1271_error("INTERROGATE command failed"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 938 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 939 | return ret; |
| 940 | } |
| 941 | |
| 942 | /** |
| 943 | * write acx value to firmware |
| 944 | * |
| 945 | * @wl: wl struct |
| 946 | * @id: acx id |
| 947 | * @buf: buffer containing acx, including all headers, must work with dma |
| 948 | * @len: length of buf |
| 949 | */ |
| 950 | int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len) |
| 951 | { |
| 952 | struct acx_header *acx = buf; |
| 953 | int ret; |
| 954 | |
Eliad Peller | c91d060 | 2011-08-25 18:10:57 +0300 | [diff] [blame] | 955 | wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 956 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 957 | acx->id = cpu_to_le16(id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 958 | |
| 959 | /* payload length, does not include any headers */ |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 960 | acx->len = cpu_to_le16(len - sizeof(*acx)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 961 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 962 | ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 963 | if (ret < 0) { |
| 964 | wl1271_warning("CONFIGURE command NOK"); |
| 965 | return ret; |
| 966 | } |
| 967 | |
| 968 | return 0; |
| 969 | } |
| 970 | |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 971 | int wl1271_cmd_data_path(struct wl1271 *wl, bool enable) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 972 | { |
| 973 | struct cmd_enabledisable_path *cmd; |
| 974 | int ret; |
| 975 | u16 cmd_rx, cmd_tx; |
| 976 | |
| 977 | wl1271_debug(DEBUG_CMD, "cmd data path"); |
| 978 | |
| 979 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 980 | if (!cmd) { |
| 981 | ret = -ENOMEM; |
| 982 | goto out; |
| 983 | } |
| 984 | |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 985 | /* the channel here is only used for calibration, so hardcoded to 1 */ |
| 986 | cmd->channel = 1; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 987 | |
| 988 | if (enable) { |
| 989 | cmd_rx = CMD_ENABLE_RX; |
| 990 | cmd_tx = CMD_ENABLE_TX; |
| 991 | } else { |
| 992 | cmd_rx = CMD_DISABLE_RX; |
| 993 | cmd_tx = CMD_DISABLE_TX; |
| 994 | } |
| 995 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 996 | ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 997 | if (ret < 0) { |
| 998 | wl1271_error("rx %s cmd for channel %d failed", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 999 | enable ? "start" : "stop", cmd->channel); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1000 | goto out; |
| 1001 | } |
| 1002 | |
| 1003 | wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 1004 | enable ? "start" : "stop", cmd->channel); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1005 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 1006 | ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1007 | if (ret < 0) { |
| 1008 | wl1271_error("tx %s cmd for channel %d failed", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 1009 | enable ? "start" : "stop", cmd->channel); |
Juuso Oikarinen | 1b00f2b | 2010-03-26 12:53:17 +0200 | [diff] [blame] | 1010 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 1014 | enable ? "start" : "stop", cmd->channel); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1015 | |
| 1016 | out: |
| 1017 | kfree(cmd); |
| 1018 | return ret; |
| 1019 | } |
| 1020 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1021 | int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
Eyal Shapira | f1d63a5 | 2012-01-31 11:57:21 +0200 | [diff] [blame] | 1022 | u8 ps_mode, u16 auto_ps_timeout) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1023 | { |
| 1024 | struct wl1271_cmd_ps_params *ps_params = NULL; |
| 1025 | int ret = 0; |
| 1026 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1027 | wl1271_debug(DEBUG_CMD, "cmd set ps mode"); |
| 1028 | |
| 1029 | ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL); |
| 1030 | if (!ps_params) { |
| 1031 | ret = -ENOMEM; |
| 1032 | goto out; |
| 1033 | } |
| 1034 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1035 | ps_params->role_id = wlvif->role_id; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1036 | ps_params->ps_mode = ps_mode; |
Eyal Shapira | f1d63a5 | 2012-01-31 11:57:21 +0200 | [diff] [blame] | 1037 | ps_params->auto_ps_timeout = auto_ps_timeout; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1038 | |
| 1039 | ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params, |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 1040 | sizeof(*ps_params), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1041 | if (ret < 0) { |
| 1042 | wl1271_error("cmd set_ps_mode failed"); |
| 1043 | goto out; |
| 1044 | } |
| 1045 | |
| 1046 | out: |
| 1047 | kfree(ps_params); |
| 1048 | return ret; |
| 1049 | } |
| 1050 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1051 | int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id, |
| 1052 | u16 template_id, void *buf, size_t buf_len, |
| 1053 | int index, u32 rates) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1054 | { |
| 1055 | struct wl1271_cmd_template_set *cmd; |
| 1056 | int ret = 0; |
| 1057 | |
Eliad Peller | c059beb | 2012-01-31 11:57:17 +0200 | [diff] [blame] | 1058 | wl1271_debug(DEBUG_CMD, "cmd template_set %d (role %d)", |
| 1059 | template_id, role_id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1060 | |
| 1061 | WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE); |
| 1062 | buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE); |
| 1063 | |
| 1064 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1065 | if (!cmd) { |
| 1066 | ret = -ENOMEM; |
| 1067 | goto out; |
| 1068 | } |
| 1069 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1070 | /* during initialization wlvif is NULL */ |
| 1071 | cmd->role_id = role_id; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1072 | cmd->len = cpu_to_le16(buf_len); |
| 1073 | cmd->template_type = template_id; |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 1074 | cmd->enabled_rates = cpu_to_le32(rates); |
Arik Nemtsov | 1e05a81 | 2010-10-16 17:44:51 +0200 | [diff] [blame] | 1075 | cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit; |
| 1076 | cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit; |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 1077 | cmd->index = index; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1078 | |
| 1079 | if (buf) |
| 1080 | memcpy(cmd->template_data, buf, buf_len); |
| 1081 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 1082 | ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1083 | if (ret < 0) { |
| 1084 | wl1271_warning("cmd set_template failed: %d", ret); |
| 1085 | goto out_free; |
| 1086 | } |
| 1087 | |
| 1088 | out_free: |
| 1089 | kfree(cmd); |
| 1090 | |
| 1091 | out: |
| 1092 | return ret; |
| 1093 | } |
| 1094 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1095 | int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1096 | { |
Juuso Oikarinen | a0cb7be | 2010-03-18 12:26:44 +0200 | [diff] [blame] | 1097 | struct sk_buff *skb = NULL; |
| 1098 | int size; |
| 1099 | void *ptr; |
| 1100 | int ret = -ENOMEM; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1101 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1102 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1103 | if (wlvif->bss_type == BSS_TYPE_IBSS) { |
Juuso Oikarinen | a0cb7be | 2010-03-18 12:26:44 +0200 | [diff] [blame] | 1104 | size = sizeof(struct wl12xx_null_data_template); |
| 1105 | ptr = NULL; |
| 1106 | } else { |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1107 | skb = ieee80211_nullfunc_get(wl->hw, |
| 1108 | wl12xx_wlvif_to_vif(wlvif)); |
Juuso Oikarinen | a0cb7be | 2010-03-18 12:26:44 +0200 | [diff] [blame] | 1109 | if (!skb) |
| 1110 | goto out; |
| 1111 | size = skb->len; |
| 1112 | ptr = skb->data; |
| 1113 | } |
| 1114 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1115 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
| 1116 | CMD_TEMPL_NULL_DATA, ptr, size, 0, |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1117 | wlvif->basic_rate); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1118 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 1119 | out: |
| 1120 | dev_kfree_skb(skb); |
Juuso Oikarinen | a0cb7be | 2010-03-18 12:26:44 +0200 | [diff] [blame] | 1121 | if (ret) |
| 1122 | wl1271_warning("cmd buld null data failed %d", ret); |
| 1123 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 1124 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1125 | |
| 1126 | } |
| 1127 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1128 | int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl, |
| 1129 | struct wl12xx_vif *wlvif) |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 1130 | { |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1131 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 1132 | struct sk_buff *skb = NULL; |
| 1133 | int ret = -ENOMEM; |
| 1134 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1135 | skb = ieee80211_nullfunc_get(wl->hw, vif); |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 1136 | if (!skb) |
| 1137 | goto out; |
| 1138 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1139 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_KLV, |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 1140 | skb->data, skb->len, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 1141 | CMD_TEMPL_KLV_IDX_NULL_DATA, |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1142 | wlvif->basic_rate); |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 1143 | |
| 1144 | out: |
| 1145 | dev_kfree_skb(skb); |
| 1146 | if (ret) |
| 1147 | wl1271_warning("cmd build klv null data failed %d", ret); |
| 1148 | |
| 1149 | return ret; |
| 1150 | |
| 1151 | } |
| 1152 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 1153 | int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 1154 | u16 aid) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1155 | { |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1156 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 1157 | struct sk_buff *skb; |
| 1158 | int ret = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1159 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1160 | skb = ieee80211_pspoll_get(wl->hw, vif); |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 1161 | if (!skb) |
| 1162 | goto out; |
Juuso Oikarinen | c3fea19 | 2009-10-08 21:56:22 +0300 | [diff] [blame] | 1163 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1164 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
| 1165 | CMD_TEMPL_PS_POLL, skb->data, |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 1166 | skb->len, 0, wlvif->basic_rate_set); |
Juuso Oikarinen | c3fea19 | 2009-10-08 21:56:22 +0300 | [diff] [blame] | 1167 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 1168 | out: |
| 1169 | dev_kfree_skb(skb); |
| 1170 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1171 | } |
| 1172 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1173 | int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 1174 | u8 role_id, u8 band, |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 1175 | const u8 *ssid, size_t ssid_len, |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1176 | const u8 *ie, size_t ie_len) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1177 | { |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 1178 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 1179 | struct sk_buff *skb; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 1180 | int ret; |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 1181 | u32 rate; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1182 | |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 1183 | skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len, |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 1184 | ie, ie_len); |
| 1185 | if (!skb) { |
| 1186 | ret = -ENOMEM; |
| 1187 | goto out; |
| 1188 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1189 | |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 1190 | wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1191 | |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 1192 | rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]); |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 1193 | if (band == IEEE80211_BAND_2GHZ) |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1194 | ret = wl1271_cmd_template_set(wl, role_id, |
| 1195 | CMD_TEMPL_CFG_PROBE_REQ_2_4, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 1196 | skb->data, skb->len, 0, rate); |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 1197 | else |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1198 | ret = wl1271_cmd_template_set(wl, role_id, |
| 1199 | CMD_TEMPL_CFG_PROBE_REQ_5, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 1200 | skb->data, skb->len, 0, rate); |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 1201 | |
| 1202 | out: |
| 1203 | dev_kfree_skb(skb); |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 1204 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1205 | } |
| 1206 | |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 1207 | struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl, |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 1208 | struct wl12xx_vif *wlvif, |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 1209 | struct sk_buff *skb) |
| 1210 | { |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 1211 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 1212 | int ret; |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 1213 | u32 rate; |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 1214 | |
| 1215 | if (!skb) |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 1216 | skb = ieee80211_ap_probereq_get(wl->hw, vif); |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 1217 | if (!skb) |
| 1218 | goto out; |
| 1219 | |
| 1220 | wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len); |
| 1221 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1222 | rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]); |
| 1223 | if (wlvif->band == IEEE80211_BAND_2GHZ) |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1224 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
| 1225 | CMD_TEMPL_CFG_PROBE_REQ_2_4, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 1226 | skb->data, skb->len, 0, rate); |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 1227 | else |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1228 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
| 1229 | CMD_TEMPL_CFG_PROBE_REQ_5, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 1230 | skb->data, skb->len, 0, rate); |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 1231 | |
| 1232 | if (ret < 0) |
| 1233 | wl1271_error("Unable to set ap probe request template."); |
| 1234 | |
| 1235 | out: |
| 1236 | return skb; |
| 1237 | } |
| 1238 | |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1239 | int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1240 | { |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1241 | int ret, extra; |
| 1242 | u16 fc; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1243 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1244 | struct sk_buff *skb; |
| 1245 | struct wl12xx_arp_rsp_template *tmpl; |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1246 | struct ieee80211_hdr_3addr *hdr; |
| 1247 | struct arphdr *arp_hdr; |
| 1248 | |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1249 | skb = dev_alloc_skb(sizeof(*hdr) + sizeof(__le16) + sizeof(*tmpl) + |
| 1250 | WL1271_EXTRA_SPACE_MAX); |
| 1251 | if (!skb) { |
| 1252 | wl1271_error("failed to allocate buffer for arp rsp template"); |
| 1253 | return -ENOMEM; |
| 1254 | } |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1255 | |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1256 | skb_reserve(skb, sizeof(*hdr) + WL1271_EXTRA_SPACE_MAX); |
| 1257 | |
| 1258 | tmpl = (struct wl12xx_arp_rsp_template *)skb_put(skb, sizeof(*tmpl)); |
| 1259 | memset(tmpl, 0, sizeof(tmpl)); |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1260 | |
| 1261 | /* llc layer */ |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1262 | memcpy(tmpl->llc_hdr, rfc1042_header, sizeof(rfc1042_header)); |
| 1263 | tmpl->llc_type = cpu_to_be16(ETH_P_ARP); |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1264 | |
| 1265 | /* arp header */ |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1266 | arp_hdr = &tmpl->arp_hdr; |
Eliad Peller | 6177eae | 2010-12-22 12:38:52 +0100 | [diff] [blame] | 1267 | arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER); |
| 1268 | arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP); |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1269 | arp_hdr->ar_hln = ETH_ALEN; |
| 1270 | arp_hdr->ar_pln = 4; |
Eliad Peller | 6177eae | 2010-12-22 12:38:52 +0100 | [diff] [blame] | 1271 | arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY); |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1272 | |
| 1273 | /* arp payload */ |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1274 | memcpy(tmpl->sender_hw, vif->addr, ETH_ALEN); |
| 1275 | tmpl->sender_ip = wlvif->ip_addr; |
| 1276 | |
| 1277 | /* encryption space */ |
| 1278 | switch (wlvif->encryption_type) { |
| 1279 | case KEY_TKIP: |
| 1280 | extra = WL1271_EXTRA_SPACE_TKIP; |
| 1281 | break; |
| 1282 | case KEY_AES: |
| 1283 | extra = WL1271_EXTRA_SPACE_AES; |
| 1284 | break; |
| 1285 | case KEY_NONE: |
| 1286 | case KEY_WEP: |
| 1287 | case KEY_GEM: |
| 1288 | extra = 0; |
| 1289 | break; |
| 1290 | default: |
| 1291 | wl1271_warning("Unknown encryption type: %d", |
| 1292 | wlvif->encryption_type); |
| 1293 | ret = -EINVAL; |
| 1294 | goto out; |
| 1295 | } |
| 1296 | |
| 1297 | if (extra) { |
| 1298 | u8 *space = skb_push(skb, extra); |
| 1299 | memset(space, 0, extra); |
| 1300 | } |
| 1301 | |
| 1302 | /* QoS header - BE */ |
| 1303 | if (wlvif->sta.qos) |
| 1304 | memset(skb_push(skb, sizeof(__le16)), 0, sizeof(__le16)); |
| 1305 | |
| 1306 | /* mac80211 header */ |
| 1307 | hdr = (struct ieee80211_hdr_3addr *)skb_push(skb, sizeof(*hdr)); |
| 1308 | memset(hdr, 0, sizeof(hdr)); |
| 1309 | fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_TODS; |
| 1310 | if (wlvif->sta.qos) |
| 1311 | fc |= IEEE80211_STYPE_QOS_DATA; |
| 1312 | else |
| 1313 | fc |= IEEE80211_STYPE_DATA; |
| 1314 | if (wlvif->encryption_type != KEY_NONE) |
| 1315 | fc |= IEEE80211_FCTL_PROTECTED; |
| 1316 | |
| 1317 | hdr->frame_control = cpu_to_le16(fc); |
| 1318 | memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN); |
| 1319 | memcpy(hdr->addr2, vif->addr, ETH_ALEN); |
| 1320 | memset(hdr->addr3, 0xff, ETH_ALEN); |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1321 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1322 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_ARP_RSP, |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1323 | skb->data, skb->len, 0, |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1324 | wlvif->basic_rate); |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1325 | out: |
| 1326 | dev_kfree_skb(skb); |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1327 | return ret; |
| 1328 | } |
| 1329 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 1330 | int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif) |
Kalle Valo | 023e082 | 2010-03-18 12:26:36 +0200 | [diff] [blame] | 1331 | { |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1332 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Kalle Valo | 023e082 | 2010-03-18 12:26:36 +0200 | [diff] [blame] | 1333 | struct ieee80211_qos_hdr template; |
| 1334 | |
| 1335 | memset(&template, 0, sizeof(template)); |
| 1336 | |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 1337 | memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN); |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 1338 | memcpy(template.addr2, vif->addr, ETH_ALEN); |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 1339 | memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN); |
Kalle Valo | 023e082 | 2010-03-18 12:26:36 +0200 | [diff] [blame] | 1340 | |
| 1341 | template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 1342 | IEEE80211_STYPE_QOS_NULLFUNC | |
| 1343 | IEEE80211_FCTL_TODS); |
| 1344 | |
| 1345 | /* FIXME: not sure what priority to use here */ |
| 1346 | template.qos_ctrl = cpu_to_le16(0); |
| 1347 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1348 | return wl1271_cmd_template_set(wl, wlvif->role_id, |
| 1349 | CMD_TEMPL_QOS_NULL_DATA, &template, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 1350 | sizeof(template), 0, |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1351 | wlvif->basic_rate); |
Kalle Valo | 023e082 | 2010-03-18 12:26:36 +0200 | [diff] [blame] | 1352 | } |
| 1353 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1354 | int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1355 | { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1356 | struct wl1271_cmd_set_keys *cmd; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1357 | int ret = 0; |
| 1358 | |
| 1359 | wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id); |
| 1360 | |
| 1361 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1362 | if (!cmd) { |
| 1363 | ret = -ENOMEM; |
| 1364 | goto out; |
| 1365 | } |
| 1366 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1367 | cmd->hlid = hlid; |
| 1368 | cmd->key_id = id; |
| 1369 | cmd->lid_key_type = WEP_DEFAULT_LID_TYPE; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 1370 | cmd->key_action = cpu_to_le16(KEY_SET_ID); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1371 | cmd->key_type = KEY_WEP; |
| 1372 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 1373 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1374 | if (ret < 0) { |
| 1375 | wl1271_warning("cmd set_default_wep_key failed: %d", ret); |
| 1376 | goto out; |
| 1377 | } |
| 1378 | |
| 1379 | out: |
| 1380 | kfree(cmd); |
| 1381 | |
| 1382 | return ret; |
| 1383 | } |
| 1384 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 1385 | int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 1386 | u16 action, u8 id, u8 key_type, |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 1387 | u8 key_size, const u8 *key, const u8 *addr, |
| 1388 | u32 tx_seq_32, u16 tx_seq_16) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1389 | { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1390 | struct wl1271_cmd_set_keys *cmd; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1391 | int ret = 0; |
| 1392 | |
Eliad Peller | b42f068 | 2011-08-14 13:17:24 +0300 | [diff] [blame] | 1393 | /* hlid might have already been deleted */ |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 1394 | if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) |
Eliad Peller | b42f068 | 2011-08-14 13:17:24 +0300 | [diff] [blame] | 1395 | return 0; |
| 1396 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1397 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1398 | if (!cmd) { |
| 1399 | ret = -ENOMEM; |
| 1400 | goto out; |
| 1401 | } |
| 1402 | |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 1403 | cmd->hlid = wlvif->sta.hlid; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1404 | |
| 1405 | if (key_type == KEY_WEP) |
| 1406 | cmd->lid_key_type = WEP_DEFAULT_LID_TYPE; |
| 1407 | else if (is_broadcast_ether_addr(addr)) |
| 1408 | cmd->lid_key_type = BROADCAST_LID_TYPE; |
| 1409 | else |
| 1410 | cmd->lid_key_type = UNICAST_LID_TYPE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1411 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 1412 | cmd->key_action = cpu_to_le16(action); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1413 | cmd->key_size = key_size; |
| 1414 | cmd->key_type = key_type; |
| 1415 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 1416 | cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16); |
| 1417 | cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32); |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 1418 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1419 | cmd->key_id = id; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1420 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1421 | if (key_type == KEY_TKIP) { |
| 1422 | /* |
| 1423 | * We get the key in the following form: |
| 1424 | * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes) |
| 1425 | * but the target is expecting: |
| 1426 | * TKIP - RX MIC - TX MIC |
| 1427 | */ |
| 1428 | memcpy(cmd->key, key, 16); |
| 1429 | memcpy(cmd->key + 16, key + 24, 8); |
| 1430 | memcpy(cmd->key + 24, key + 16, 8); |
| 1431 | |
| 1432 | } else { |
| 1433 | memcpy(cmd->key, key, key_size); |
| 1434 | } |
| 1435 | |
| 1436 | wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd)); |
| 1437 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 1438 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1439 | if (ret < 0) { |
| 1440 | wl1271_warning("could not set keys"); |
Juuso Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 1441 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | out: |
| 1445 | kfree(cmd); |
| 1446 | |
| 1447 | return ret; |
| 1448 | } |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 1449 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1450 | /* |
| 1451 | * TODO: merge with sta/ibss into 1 set_key function. |
| 1452 | * note there are slight diffs |
| 1453 | */ |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 1454 | int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 1455 | u16 action, u8 id, u8 key_type, |
| 1456 | u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32, |
| 1457 | u16 tx_seq_16) |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1458 | { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1459 | struct wl1271_cmd_set_keys *cmd; |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1460 | int ret = 0; |
| 1461 | u8 lid_type; |
| 1462 | |
| 1463 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1464 | if (!cmd) |
| 1465 | return -ENOMEM; |
| 1466 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 1467 | if (hlid == wlvif->ap.bcast_hlid) { |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1468 | if (key_type == KEY_WEP) |
| 1469 | lid_type = WEP_DEFAULT_LID_TYPE; |
| 1470 | else |
| 1471 | lid_type = BROADCAST_LID_TYPE; |
| 1472 | } else { |
| 1473 | lid_type = UNICAST_LID_TYPE; |
| 1474 | } |
| 1475 | |
| 1476 | wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d" |
| 1477 | " hlid: %d", (int)action, (int)id, (int)lid_type, |
| 1478 | (int)key_type, (int)hlid); |
| 1479 | |
| 1480 | cmd->lid_key_type = lid_type; |
| 1481 | cmd->hlid = hlid; |
| 1482 | cmd->key_action = cpu_to_le16(action); |
| 1483 | cmd->key_size = key_size; |
| 1484 | cmd->key_type = key_type; |
| 1485 | cmd->key_id = id; |
| 1486 | cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16); |
| 1487 | cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32); |
| 1488 | |
| 1489 | if (key_type == KEY_TKIP) { |
| 1490 | /* |
| 1491 | * We get the key in the following form: |
| 1492 | * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes) |
| 1493 | * but the target is expecting: |
| 1494 | * TKIP - RX MIC - TX MIC |
| 1495 | */ |
| 1496 | memcpy(cmd->key, key, 16); |
| 1497 | memcpy(cmd->key + 16, key + 24, 8); |
| 1498 | memcpy(cmd->key + 24, key + 16, 8); |
| 1499 | } else { |
| 1500 | memcpy(cmd->key, key, key_size); |
| 1501 | } |
| 1502 | |
| 1503 | wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd)); |
| 1504 | |
| 1505 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); |
| 1506 | if (ret < 0) { |
| 1507 | wl1271_warning("could not set ap keys"); |
| 1508 | goto out; |
| 1509 | } |
| 1510 | |
| 1511 | out: |
| 1512 | kfree(cmd); |
| 1513 | return ret; |
| 1514 | } |
| 1515 | |
Eliad Peller | b67476e | 2011-08-14 13:17:23 +0300 | [diff] [blame] | 1516 | int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid) |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 1517 | { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1518 | struct wl12xx_cmd_set_peer_state *cmd; |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 1519 | int ret = 0; |
| 1520 | |
Eliad Peller | b67476e | 2011-08-14 13:17:23 +0300 | [diff] [blame] | 1521 | wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid); |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 1522 | |
| 1523 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1524 | if (!cmd) { |
| 1525 | ret = -ENOMEM; |
| 1526 | goto out; |
| 1527 | } |
| 1528 | |
Eliad Peller | b67476e | 2011-08-14 13:17:23 +0300 | [diff] [blame] | 1529 | cmd->hlid = hlid; |
Juuso Oikarinen | be86cbe | 2010-05-27 12:53:01 +0300 | [diff] [blame] | 1530 | cmd->state = WL1271_CMD_STA_STATE_CONNECTED; |
| 1531 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1532 | ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0); |
Juuso Oikarinen | be86cbe | 2010-05-27 12:53:01 +0300 | [diff] [blame] | 1533 | if (ret < 0) { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1534 | wl1271_error("failed to send set peer state command"); |
Juuso Oikarinen | be86cbe | 2010-05-27 12:53:01 +0300 | [diff] [blame] | 1535 | goto out_free; |
| 1536 | } |
| 1537 | |
| 1538 | out_free: |
| 1539 | kfree(cmd); |
| 1540 | |
| 1541 | out: |
| 1542 | return ret; |
| 1543 | } |
Arik Nemtsov | 99d5ad7 | 2011-08-14 13:17:28 +0300 | [diff] [blame] | 1544 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1545 | int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 1546 | struct ieee80211_sta *sta, u8 hlid) |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1547 | { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1548 | struct wl12xx_cmd_add_peer *cmd; |
Eliad Peller | 1ec23f7 | 2011-08-25 14:26:54 +0300 | [diff] [blame] | 1549 | int i, ret; |
Arik Nemtsov | 99d5ad7 | 2011-08-14 13:17:28 +0300 | [diff] [blame] | 1550 | u32 sta_rates; |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1551 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1552 | wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1553 | |
| 1554 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1555 | if (!cmd) { |
| 1556 | ret = -ENOMEM; |
| 1557 | goto out; |
| 1558 | } |
| 1559 | |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1560 | memcpy(cmd->addr, sta->addr, ETH_ALEN); |
| 1561 | cmd->bss_index = WL1271_AP_BSS_INDEX; |
| 1562 | cmd->aid = sta->aid; |
| 1563 | cmd->hlid = hlid; |
Eliad Peller | 1ec23f7 | 2011-08-25 14:26:54 +0300 | [diff] [blame] | 1564 | cmd->sp_len = sta->max_sp; |
Arik Nemtsov | b4d38db | 2011-06-27 23:58:46 +0300 | [diff] [blame] | 1565 | cmd->wmm = sta->wme ? 1 : 0; |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1566 | |
Eliad Peller | 1ec23f7 | 2011-08-25 14:26:54 +0300 | [diff] [blame] | 1567 | for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++) |
| 1568 | if (sta->wme && (sta->uapsd_queues & BIT(i))) |
| 1569 | cmd->psd_type[i] = WL1271_PSD_UPSD_TRIGGER; |
| 1570 | else |
| 1571 | cmd->psd_type[i] = WL1271_PSD_LEGACY; |
| 1572 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1573 | sta_rates = sta->supp_rates[wlvif->band]; |
Arik Nemtsov | 99d5ad7 | 2011-08-14 13:17:28 +0300 | [diff] [blame] | 1574 | if (sta->ht_cap.ht_supported) |
| 1575 | sta_rates |= sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET; |
| 1576 | |
| 1577 | cmd->supported_rates = |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 1578 | cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates, |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1579 | wlvif->band)); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1580 | |
Eliad Peller | 1ec23f7 | 2011-08-25 14:26:54 +0300 | [diff] [blame] | 1581 | wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x", |
| 1582 | cmd->supported_rates, sta->uapsd_queues); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1583 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1584 | ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1585 | if (ret < 0) { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1586 | wl1271_error("failed to initiate cmd add peer"); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1587 | goto out_free; |
| 1588 | } |
| 1589 | |
| 1590 | out_free: |
| 1591 | kfree(cmd); |
| 1592 | |
| 1593 | out: |
| 1594 | return ret; |
| 1595 | } |
| 1596 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1597 | int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid) |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1598 | { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1599 | struct wl12xx_cmd_remove_peer *cmd; |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1600 | int ret; |
| 1601 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1602 | wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1603 | |
| 1604 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1605 | if (!cmd) { |
| 1606 | ret = -ENOMEM; |
| 1607 | goto out; |
| 1608 | } |
| 1609 | |
| 1610 | cmd->hlid = hlid; |
| 1611 | /* We never send a deauth, mac80211 is in charge of this */ |
| 1612 | cmd->reason_opcode = 0; |
| 1613 | cmd->send_deauth_flag = 0; |
| 1614 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1615 | ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1616 | if (ret < 0) { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1617 | wl1271_error("failed to initiate cmd remove peer"); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1618 | goto out_free; |
| 1619 | } |
| 1620 | |
Arik Nemtsov | 05285cf | 2010-11-12 17:15:03 +0200 | [diff] [blame] | 1621 | /* |
| 1622 | * We are ok with a timeout here. The event is sometimes not sent |
| 1623 | * due to a firmware bug. |
| 1624 | */ |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1625 | wl1271_cmd_wait_for_event_or_timeout(wl, |
| 1626 | PEER_REMOVE_COMPLETE_EVENT_ID); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1627 | |
| 1628 | out_free: |
| 1629 | kfree(cmd); |
| 1630 | |
| 1631 | out: |
| 1632 | return ret; |
| 1633 | } |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 1634 | |
| 1635 | int wl12xx_cmd_config_fwlog(struct wl1271 *wl) |
| 1636 | { |
| 1637 | struct wl12xx_cmd_config_fwlog *cmd; |
| 1638 | int ret = 0; |
| 1639 | |
| 1640 | wl1271_debug(DEBUG_CMD, "cmd config firmware logger"); |
| 1641 | |
| 1642 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1643 | if (!cmd) { |
| 1644 | ret = -ENOMEM; |
| 1645 | goto out; |
| 1646 | } |
| 1647 | |
| 1648 | cmd->logger_mode = wl->conf.fwlog.mode; |
| 1649 | cmd->log_severity = wl->conf.fwlog.severity; |
| 1650 | cmd->timestamp = wl->conf.fwlog.timestamp; |
| 1651 | cmd->output = wl->conf.fwlog.output; |
| 1652 | cmd->threshold = wl->conf.fwlog.threshold; |
| 1653 | |
| 1654 | ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0); |
| 1655 | if (ret < 0) { |
| 1656 | wl1271_error("failed to send config firmware logger command"); |
| 1657 | goto out_free; |
| 1658 | } |
| 1659 | |
| 1660 | out_free: |
| 1661 | kfree(cmd); |
| 1662 | |
| 1663 | out: |
| 1664 | return ret; |
| 1665 | } |
| 1666 | |
| 1667 | int wl12xx_cmd_start_fwlog(struct wl1271 *wl) |
| 1668 | { |
| 1669 | struct wl12xx_cmd_start_fwlog *cmd; |
| 1670 | int ret = 0; |
| 1671 | |
| 1672 | wl1271_debug(DEBUG_CMD, "cmd start firmware logger"); |
| 1673 | |
| 1674 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1675 | if (!cmd) { |
| 1676 | ret = -ENOMEM; |
| 1677 | goto out; |
| 1678 | } |
| 1679 | |
| 1680 | ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0); |
| 1681 | if (ret < 0) { |
| 1682 | wl1271_error("failed to send start firmware logger command"); |
| 1683 | goto out_free; |
| 1684 | } |
| 1685 | |
| 1686 | out_free: |
| 1687 | kfree(cmd); |
| 1688 | |
| 1689 | out: |
| 1690 | return ret; |
| 1691 | } |
| 1692 | |
| 1693 | int wl12xx_cmd_stop_fwlog(struct wl1271 *wl) |
| 1694 | { |
| 1695 | struct wl12xx_cmd_stop_fwlog *cmd; |
| 1696 | int ret = 0; |
| 1697 | |
| 1698 | wl1271_debug(DEBUG_CMD, "cmd stop firmware logger"); |
| 1699 | |
| 1700 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1701 | if (!cmd) { |
| 1702 | ret = -ENOMEM; |
| 1703 | goto out; |
| 1704 | } |
| 1705 | |
| 1706 | ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0); |
| 1707 | if (ret < 0) { |
| 1708 | wl1271_error("failed to send stop firmware logger command"); |
| 1709 | goto out_free; |
| 1710 | } |
| 1711 | |
| 1712 | out_free: |
| 1713 | kfree(cmd); |
| 1714 | |
| 1715 | out: |
| 1716 | return ret; |
| 1717 | } |
Eliad Peller | a7cba38 | 2011-08-14 13:17:16 +0300 | [diff] [blame] | 1718 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1719 | static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 1720 | u8 role_id) |
Eliad Peller | a7cba38 | 2011-08-14 13:17:16 +0300 | [diff] [blame] | 1721 | { |
| 1722 | struct wl12xx_cmd_roc *cmd; |
| 1723 | int ret = 0; |
| 1724 | |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 1725 | wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wlvif->channel, role_id); |
Eliad Peller | a7cba38 | 2011-08-14 13:17:16 +0300 | [diff] [blame] | 1726 | |
| 1727 | if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID)) |
| 1728 | return -EINVAL; |
| 1729 | |
| 1730 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1731 | if (!cmd) { |
| 1732 | ret = -ENOMEM; |
| 1733 | goto out; |
| 1734 | } |
| 1735 | |
| 1736 | cmd->role_id = role_id; |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 1737 | cmd->channel = wlvif->channel; |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1738 | switch (wlvif->band) { |
Eliad Peller | a7cba38 | 2011-08-14 13:17:16 +0300 | [diff] [blame] | 1739 | case IEEE80211_BAND_2GHZ: |
| 1740 | cmd->band = RADIO_BAND_2_4GHZ; |
| 1741 | break; |
| 1742 | case IEEE80211_BAND_5GHZ: |
| 1743 | cmd->band = RADIO_BAND_5GHZ; |
| 1744 | break; |
| 1745 | default: |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1746 | wl1271_error("roc - unknown band: %d", (int)wlvif->band); |
Eliad Peller | a7cba38 | 2011-08-14 13:17:16 +0300 | [diff] [blame] | 1747 | ret = -EINVAL; |
| 1748 | goto out_free; |
| 1749 | } |
| 1750 | |
| 1751 | |
| 1752 | ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0); |
| 1753 | if (ret < 0) { |
| 1754 | wl1271_error("failed to send ROC command"); |
| 1755 | goto out_free; |
| 1756 | } |
| 1757 | |
| 1758 | out_free: |
| 1759 | kfree(cmd); |
| 1760 | |
| 1761 | out: |
| 1762 | return ret; |
| 1763 | } |
| 1764 | |
| 1765 | static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id) |
| 1766 | { |
| 1767 | struct wl12xx_cmd_croc *cmd; |
| 1768 | int ret = 0; |
| 1769 | |
| 1770 | wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id); |
| 1771 | |
| 1772 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1773 | if (!cmd) { |
| 1774 | ret = -ENOMEM; |
| 1775 | goto out; |
| 1776 | } |
| 1777 | cmd->role_id = role_id; |
| 1778 | |
| 1779 | ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd, |
| 1780 | sizeof(*cmd), 0); |
| 1781 | if (ret < 0) { |
| 1782 | wl1271_error("failed to send ROC command"); |
| 1783 | goto out_free; |
| 1784 | } |
| 1785 | |
| 1786 | out_free: |
| 1787 | kfree(cmd); |
| 1788 | |
| 1789 | out: |
| 1790 | return ret; |
| 1791 | } |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 1792 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1793 | int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id) |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 1794 | { |
| 1795 | int ret = 0; |
| 1796 | |
| 1797 | if (WARN_ON(test_bit(role_id, wl->roc_map))) |
| 1798 | return 0; |
| 1799 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1800 | ret = wl12xx_cmd_roc(wl, wlvif, role_id); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 1801 | if (ret < 0) |
| 1802 | goto out; |
| 1803 | |
| 1804 | ret = wl1271_cmd_wait_for_event(wl, |
| 1805 | REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID); |
| 1806 | if (ret < 0) { |
| 1807 | wl1271_error("cmd roc event completion error"); |
| 1808 | goto out; |
| 1809 | } |
| 1810 | |
| 1811 | __set_bit(role_id, wl->roc_map); |
| 1812 | out: |
| 1813 | return ret; |
| 1814 | } |
| 1815 | |
| 1816 | int wl12xx_croc(struct wl1271 *wl, u8 role_id) |
| 1817 | { |
| 1818 | int ret = 0; |
| 1819 | |
| 1820 | if (WARN_ON(!test_bit(role_id, wl->roc_map))) |
| 1821 | return 0; |
| 1822 | |
| 1823 | ret = wl12xx_cmd_croc(wl, role_id); |
| 1824 | if (ret < 0) |
| 1825 | goto out; |
| 1826 | |
| 1827 | __clear_bit(role_id, wl->roc_map); |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 1828 | |
| 1829 | /* |
| 1830 | * Rearm the tx watchdog when removing the last ROC. This prevents |
| 1831 | * recoveries due to just finished ROCs - when Tx hasn't yet had |
| 1832 | * a chance to get out. |
| 1833 | */ |
| 1834 | if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES) |
| 1835 | wl12xx_rearm_tx_watchdog_locked(wl); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 1836 | out: |
| 1837 | return ret; |
| 1838 | } |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 1839 | |
| 1840 | int wl12xx_cmd_channel_switch(struct wl1271 *wl, |
Eliad Peller | 8332f0f | 2012-01-31 11:57:19 +0200 | [diff] [blame] | 1841 | struct wl12xx_vif *wlvif, |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 1842 | struct ieee80211_channel_switch *ch_switch) |
| 1843 | { |
| 1844 | struct wl12xx_cmd_channel_switch *cmd; |
| 1845 | int ret; |
| 1846 | |
| 1847 | wl1271_debug(DEBUG_ACX, "cmd channel switch"); |
| 1848 | |
| 1849 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1850 | if (!cmd) { |
| 1851 | ret = -ENOMEM; |
| 1852 | goto out; |
| 1853 | } |
| 1854 | |
Eliad Peller | 8332f0f | 2012-01-31 11:57:19 +0200 | [diff] [blame] | 1855 | cmd->role_id = wlvif->role_id; |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 1856 | cmd->channel = ch_switch->channel->hw_value; |
| 1857 | cmd->switch_time = ch_switch->count; |
Eliad Peller | 8332f0f | 2012-01-31 11:57:19 +0200 | [diff] [blame] | 1858 | cmd->stop_tx = ch_switch->block_tx; |
| 1859 | |
| 1860 | /* FIXME: control from mac80211 in the future */ |
| 1861 | cmd->post_switch_tx_disable = 0; /* Enable TX on the target channel */ |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 1862 | |
| 1863 | ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0); |
| 1864 | if (ret < 0) { |
| 1865 | wl1271_error("failed to send channel switch command"); |
| 1866 | goto out_free; |
| 1867 | } |
| 1868 | |
| 1869 | out_free: |
| 1870 | kfree(cmd); |
| 1871 | |
| 1872 | out: |
| 1873 | return ret; |
| 1874 | } |
| 1875 | |
| 1876 | int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl) |
| 1877 | { |
| 1878 | struct wl12xx_cmd_stop_channel_switch *cmd; |
| 1879 | int ret; |
| 1880 | |
| 1881 | wl1271_debug(DEBUG_ACX, "cmd stop channel switch"); |
| 1882 | |
| 1883 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1884 | if (!cmd) { |
| 1885 | ret = -ENOMEM; |
| 1886 | goto out; |
| 1887 | } |
| 1888 | |
| 1889 | ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0); |
| 1890 | if (ret < 0) { |
| 1891 | wl1271_error("failed to stop channel switch command"); |
| 1892 | goto out_free; |
| 1893 | } |
| 1894 | |
| 1895 | out_free: |
| 1896 | kfree(cmd); |
| 1897 | |
| 1898 | out: |
| 1899 | return ret; |
| 1900 | } |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 1901 | |
| 1902 | /* start dev role and roc on its channel */ |
| 1903 | int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
| 1904 | { |
| 1905 | int ret; |
| 1906 | |
| 1907 | if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 1908 | wlvif->bss_type == BSS_TYPE_IBSS))) |
| 1909 | return -EINVAL; |
| 1910 | |
| 1911 | ret = wl12xx_cmd_role_start_dev(wl, wlvif); |
| 1912 | if (ret < 0) |
| 1913 | goto out; |
| 1914 | |
| 1915 | ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id); |
| 1916 | if (ret < 0) |
| 1917 | goto out_stop; |
| 1918 | |
| 1919 | return 0; |
| 1920 | |
| 1921 | out_stop: |
| 1922 | wl12xx_cmd_role_stop_dev(wl, wlvif); |
| 1923 | out: |
| 1924 | return ret; |
| 1925 | } |
| 1926 | |
| 1927 | /* croc dev hlid, and stop the role */ |
| 1928 | int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
| 1929 | { |
| 1930 | int ret; |
| 1931 | |
| 1932 | if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 1933 | wlvif->bss_type == BSS_TYPE_IBSS))) |
| 1934 | return -EINVAL; |
| 1935 | |
Eliad Peller | 8aefffe | 2011-12-18 20:25:42 +0200 | [diff] [blame] | 1936 | /* flush all pending packets */ |
| 1937 | wl1271_tx_work_locked(wl); |
| 1938 | |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 1939 | if (test_bit(wlvif->dev_role_id, wl->roc_map)) { |
| 1940 | ret = wl12xx_croc(wl, wlvif->dev_role_id); |
| 1941 | if (ret < 0) |
| 1942 | goto out; |
| 1943 | } |
| 1944 | |
| 1945 | ret = wl12xx_cmd_role_stop_dev(wl, wlvif); |
| 1946 | if (ret < 0) |
| 1947 | goto out; |
| 1948 | out: |
| 1949 | return ret; |
| 1950 | } |