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