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