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