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