diff options
Diffstat (limited to 'drivers/net/wireless/cw1200/sta.c')
-rw-r--r-- | drivers/net/wireless/cw1200/sta.c | 2406 |
1 files changed, 2406 insertions, 0 deletions
diff --git a/drivers/net/wireless/cw1200/sta.c b/drivers/net/wireless/cw1200/sta.c new file mode 100644 index 000000000000..679c55f15c67 --- /dev/null +++ b/drivers/net/wireless/cw1200/sta.c | |||
@@ -0,0 +1,2406 @@ | |||
1 | /* | ||
2 | * Mac80211 STA API for ST-Ericsson CW1200 drivers | ||
3 | * | ||
4 | * Copyright (c) 2010, ST-Ericsson | ||
5 | * Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/vmalloc.h> | ||
13 | #include <linux/sched.h> | ||
14 | #include <linux/firmware.h> | ||
15 | #include <linux/module.h> | ||
16 | |||
17 | #include "cw1200.h" | ||
18 | #include "sta.h" | ||
19 | #include "fwio.h" | ||
20 | #include "bh.h" | ||
21 | #include "debug.h" | ||
22 | |||
23 | #ifndef ERP_INFO_BYTE_OFFSET | ||
24 | #define ERP_INFO_BYTE_OFFSET 2 | ||
25 | #endif | ||
26 | |||
27 | static void cw1200_do_join(struct cw1200_common *priv); | ||
28 | static void cw1200_do_unjoin(struct cw1200_common *priv); | ||
29 | |||
30 | static int cw1200_upload_beacon(struct cw1200_common *priv); | ||
31 | static int cw1200_upload_pspoll(struct cw1200_common *priv); | ||
32 | static int cw1200_upload_null(struct cw1200_common *priv); | ||
33 | static int cw1200_upload_qosnull(struct cw1200_common *priv); | ||
34 | static int cw1200_start_ap(struct cw1200_common *priv); | ||
35 | static int cw1200_update_beaconing(struct cw1200_common *priv); | ||
36 | static int cw1200_enable_beaconing(struct cw1200_common *priv, | ||
37 | bool enable); | ||
38 | static void __cw1200_sta_notify(struct ieee80211_hw *dev, | ||
39 | struct ieee80211_vif *vif, | ||
40 | enum sta_notify_cmd notify_cmd, | ||
41 | int link_id); | ||
42 | static int __cw1200_flush(struct cw1200_common *priv, bool drop); | ||
43 | |||
44 | static inline void __cw1200_free_event_queue(struct list_head *list) | ||
45 | { | ||
46 | struct cw1200_wsm_event *event, *tmp; | ||
47 | list_for_each_entry_safe(event, tmp, list, link) { | ||
48 | list_del(&event->link); | ||
49 | kfree(event); | ||
50 | } | ||
51 | } | ||
52 | |||
53 | /* ******************************************************************** */ | ||
54 | /* STA API */ | ||
55 | |||
56 | int cw1200_start(struct ieee80211_hw *dev) | ||
57 | { | ||
58 | struct cw1200_common *priv = dev->priv; | ||
59 | int ret = 0; | ||
60 | |||
61 | cw1200_pm_stay_awake(&priv->pm_state, HZ); | ||
62 | |||
63 | mutex_lock(&priv->conf_mutex); | ||
64 | |||
65 | /* default EDCA */ | ||
66 | WSM_EDCA_SET(&priv->edca, 0, 0x0002, 0x0003, 0x0007, 47, 0xc8, false); | ||
67 | WSM_EDCA_SET(&priv->edca, 1, 0x0002, 0x0007, 0x000f, 94, 0xc8, false); | ||
68 | WSM_EDCA_SET(&priv->edca, 2, 0x0003, 0x000f, 0x03ff, 0, 0xc8, false); | ||
69 | WSM_EDCA_SET(&priv->edca, 3, 0x0007, 0x000f, 0x03ff, 0, 0xc8, false); | ||
70 | ret = wsm_set_edca_params(priv, &priv->edca); | ||
71 | if (ret) | ||
72 | goto out; | ||
73 | |||
74 | ret = cw1200_set_uapsd_param(priv, &priv->edca); | ||
75 | if (ret) | ||
76 | goto out; | ||
77 | |||
78 | priv->setbssparams_done = false; | ||
79 | |||
80 | memcpy(priv->mac_addr, dev->wiphy->perm_addr, ETH_ALEN); | ||
81 | priv->mode = NL80211_IFTYPE_MONITOR; | ||
82 | priv->wep_default_key_id = -1; | ||
83 | |||
84 | priv->cqm_beacon_loss_count = 10; | ||
85 | |||
86 | ret = cw1200_setup_mac(priv); | ||
87 | if (ret) | ||
88 | goto out; | ||
89 | |||
90 | out: | ||
91 | mutex_unlock(&priv->conf_mutex); | ||
92 | return ret; | ||
93 | } | ||
94 | |||
95 | void cw1200_stop(struct ieee80211_hw *dev) | ||
96 | { | ||
97 | struct cw1200_common *priv = dev->priv; | ||
98 | LIST_HEAD(list); | ||
99 | int i; | ||
100 | |||
101 | wsm_lock_tx(priv); | ||
102 | |||
103 | while (down_trylock(&priv->scan.lock)) { | ||
104 | /* Scan is in progress. Force it to stop. */ | ||
105 | priv->scan.req = NULL; | ||
106 | schedule(); | ||
107 | } | ||
108 | up(&priv->scan.lock); | ||
109 | |||
110 | cancel_delayed_work_sync(&priv->scan.probe_work); | ||
111 | cancel_delayed_work_sync(&priv->scan.timeout); | ||
112 | cancel_delayed_work_sync(&priv->clear_recent_scan_work); | ||
113 | cancel_delayed_work_sync(&priv->join_timeout); | ||
114 | cw1200_cqm_bssloss_sm(priv, 0, 0, 0); | ||
115 | cancel_work_sync(&priv->unjoin_work); | ||
116 | cancel_delayed_work_sync(&priv->link_id_gc_work); | ||
117 | flush_workqueue(priv->workqueue); | ||
118 | del_timer_sync(&priv->mcast_timeout); | ||
119 | mutex_lock(&priv->conf_mutex); | ||
120 | priv->mode = NL80211_IFTYPE_UNSPECIFIED; | ||
121 | priv->listening = false; | ||
122 | |||
123 | spin_lock(&priv->event_queue_lock); | ||
124 | list_splice_init(&priv->event_queue, &list); | ||
125 | spin_unlock(&priv->event_queue_lock); | ||
126 | __cw1200_free_event_queue(&list); | ||
127 | |||
128 | |||
129 | priv->join_status = CW1200_JOIN_STATUS_PASSIVE; | ||
130 | priv->join_pending = false; | ||
131 | |||
132 | for (i = 0; i < 4; i++) | ||
133 | cw1200_queue_clear(&priv->tx_queue[i]); | ||
134 | mutex_unlock(&priv->conf_mutex); | ||
135 | tx_policy_clean(priv); | ||
136 | |||
137 | /* HACK! */ | ||
138 | if (atomic_xchg(&priv->tx_lock, 1) != 1) | ||
139 | pr_debug("[STA] TX is force-unlocked due to stop request.\n"); | ||
140 | |||
141 | wsm_unlock_tx(priv); | ||
142 | atomic_xchg(&priv->tx_lock, 0); /* for recovery to work */ | ||
143 | } | ||
144 | |||
145 | static int cw1200_bssloss_mitigation = 1; | ||
146 | module_param(cw1200_bssloss_mitigation, int, 0644); | ||
147 | MODULE_PARM_DESC(cw1200_bssloss_mitigation, "BSS Loss mitigation. 0 == disabled, 1 == enabled (default)"); | ||
148 | |||
149 | |||
150 | void __cw1200_cqm_bssloss_sm(struct cw1200_common *priv, | ||
151 | int init, int good, int bad) | ||
152 | { | ||
153 | int tx = 0; | ||
154 | |||
155 | priv->delayed_link_loss = 0; | ||
156 | cancel_work_sync(&priv->bss_params_work); | ||
157 | |||
158 | pr_debug("[STA] CQM BSSLOSS_SM: state: %d init %d good %d bad: %d txlock: %d uj: %d\n", | ||
159 | priv->bss_loss_state, | ||
160 | init, good, bad, | ||
161 | atomic_read(&priv->tx_lock), | ||
162 | priv->delayed_unjoin); | ||
163 | |||
164 | /* If we have a pending unjoin */ | ||
165 | if (priv->delayed_unjoin) | ||
166 | return; | ||
167 | |||
168 | if (init) { | ||
169 | queue_delayed_work(priv->workqueue, | ||
170 | &priv->bss_loss_work, | ||
171 | HZ); | ||
172 | priv->bss_loss_state = 0; | ||
173 | |||
174 | /* Skip the confimration procedure in P2P case */ | ||
175 | if (!priv->vif->p2p && !atomic_read(&priv->tx_lock)) | ||
176 | tx = 1; | ||
177 | } else if (good) { | ||
178 | cancel_delayed_work_sync(&priv->bss_loss_work); | ||
179 | priv->bss_loss_state = 0; | ||
180 | queue_work(priv->workqueue, &priv->bss_params_work); | ||
181 | } else if (bad) { | ||
182 | /* XXX Should we just keep going until we time out? */ | ||
183 | if (priv->bss_loss_state < 3) | ||
184 | tx = 1; | ||
185 | } else { | ||
186 | cancel_delayed_work_sync(&priv->bss_loss_work); | ||
187 | priv->bss_loss_state = 0; | ||
188 | } | ||
189 | |||
190 | /* Bypass mitigation if it's disabled */ | ||
191 | if (!cw1200_bssloss_mitigation) | ||
192 | tx = 0; | ||
193 | |||
194 | /* Spit out a NULL packet to our AP if necessary */ | ||
195 | if (tx) { | ||
196 | struct sk_buff *skb; | ||
197 | |||
198 | priv->bss_loss_state++; | ||
199 | |||
200 | skb = ieee80211_nullfunc_get(priv->hw, priv->vif); | ||
201 | WARN_ON(!skb); | ||
202 | if (skb) | ||
203 | cw1200_tx(priv->hw, NULL, skb); | ||
204 | } | ||
205 | } | ||
206 | |||
207 | int cw1200_add_interface(struct ieee80211_hw *dev, | ||
208 | struct ieee80211_vif *vif) | ||
209 | { | ||
210 | int ret; | ||
211 | struct cw1200_common *priv = dev->priv; | ||
212 | /* __le32 auto_calibration_mode = __cpu_to_le32(1); */ | ||
213 | |||
214 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | | ||
215 | IEEE80211_VIF_SUPPORTS_CQM_RSSI; | ||
216 | |||
217 | mutex_lock(&priv->conf_mutex); | ||
218 | |||
219 | if (priv->mode != NL80211_IFTYPE_MONITOR) { | ||
220 | mutex_unlock(&priv->conf_mutex); | ||
221 | return -EOPNOTSUPP; | ||
222 | } | ||
223 | |||
224 | switch (vif->type) { | ||
225 | case NL80211_IFTYPE_STATION: | ||
226 | case NL80211_IFTYPE_ADHOC: | ||
227 | case NL80211_IFTYPE_MESH_POINT: | ||
228 | case NL80211_IFTYPE_AP: | ||
229 | priv->mode = vif->type; | ||
230 | break; | ||
231 | default: | ||
232 | mutex_unlock(&priv->conf_mutex); | ||
233 | return -EOPNOTSUPP; | ||
234 | } | ||
235 | |||
236 | priv->vif = vif; | ||
237 | memcpy(priv->mac_addr, vif->addr, ETH_ALEN); | ||
238 | ret = cw1200_setup_mac(priv); | ||
239 | /* Enable auto-calibration */ | ||
240 | /* Exception in subsequent channel switch; disabled. | ||
241 | * wsm_write_mib(priv, WSM_MIB_ID_SET_AUTO_CALIBRATION_MODE, | ||
242 | * &auto_calibration_mode, sizeof(auto_calibration_mode)); | ||
243 | */ | ||
244 | |||
245 | mutex_unlock(&priv->conf_mutex); | ||
246 | return ret; | ||
247 | } | ||
248 | |||
249 | void cw1200_remove_interface(struct ieee80211_hw *dev, | ||
250 | struct ieee80211_vif *vif) | ||
251 | { | ||
252 | struct cw1200_common *priv = dev->priv; | ||
253 | struct wsm_reset reset = { | ||
254 | .reset_statistics = true, | ||
255 | }; | ||
256 | int i; | ||
257 | |||
258 | mutex_lock(&priv->conf_mutex); | ||
259 | switch (priv->join_status) { | ||
260 | case CW1200_JOIN_STATUS_JOINING: | ||
261 | case CW1200_JOIN_STATUS_PRE_STA: | ||
262 | case CW1200_JOIN_STATUS_STA: | ||
263 | case CW1200_JOIN_STATUS_IBSS: | ||
264 | wsm_lock_tx(priv); | ||
265 | if (queue_work(priv->workqueue, &priv->unjoin_work) <= 0) | ||
266 | wsm_unlock_tx(priv); | ||
267 | break; | ||
268 | case CW1200_JOIN_STATUS_AP: | ||
269 | for (i = 0; priv->link_id_map; ++i) { | ||
270 | if (priv->link_id_map & BIT(i)) { | ||
271 | reset.link_id = i; | ||
272 | wsm_reset(priv, &reset); | ||
273 | priv->link_id_map &= ~BIT(i); | ||
274 | } | ||
275 | } | ||
276 | memset(priv->link_id_db, 0, sizeof(priv->link_id_db)); | ||
277 | priv->sta_asleep_mask = 0; | ||
278 | priv->enable_beacon = false; | ||
279 | priv->tx_multicast = false; | ||
280 | priv->aid0_bit_set = false; | ||
281 | priv->buffered_multicasts = false; | ||
282 | priv->pspoll_mask = 0; | ||
283 | reset.link_id = 0; | ||
284 | wsm_reset(priv, &reset); | ||
285 | break; | ||
286 | case CW1200_JOIN_STATUS_MONITOR: | ||
287 | cw1200_update_listening(priv, false); | ||
288 | break; | ||
289 | default: | ||
290 | break; | ||
291 | } | ||
292 | priv->vif = NULL; | ||
293 | priv->mode = NL80211_IFTYPE_MONITOR; | ||
294 | memset(priv->mac_addr, 0, ETH_ALEN); | ||
295 | memset(&priv->p2p_ps_modeinfo, 0, sizeof(priv->p2p_ps_modeinfo)); | ||
296 | cw1200_free_keys(priv); | ||
297 | cw1200_setup_mac(priv); | ||
298 | priv->listening = false; | ||
299 | priv->join_status = CW1200_JOIN_STATUS_PASSIVE; | ||
300 | if (!__cw1200_flush(priv, true)) | ||
301 | wsm_unlock_tx(priv); | ||
302 | |||
303 | mutex_unlock(&priv->conf_mutex); | ||
304 | } | ||
305 | |||
306 | int cw1200_change_interface(struct ieee80211_hw *dev, | ||
307 | struct ieee80211_vif *vif, | ||
308 | enum nl80211_iftype new_type, | ||
309 | bool p2p) | ||
310 | { | ||
311 | int ret = 0; | ||
312 | pr_debug("change_interface new: %d (%d), old: %d (%d)\n", new_type, | ||
313 | p2p, vif->type, vif->p2p); | ||
314 | |||
315 | if (new_type != vif->type || vif->p2p != p2p) { | ||
316 | cw1200_remove_interface(dev, vif); | ||
317 | vif->type = new_type; | ||
318 | vif->p2p = p2p; | ||
319 | ret = cw1200_add_interface(dev, vif); | ||
320 | } | ||
321 | |||
322 | return ret; | ||
323 | } | ||
324 | |||
325 | int cw1200_config(struct ieee80211_hw *dev, u32 changed) | ||
326 | { | ||
327 | int ret = 0; | ||
328 | struct cw1200_common *priv = dev->priv; | ||
329 | struct ieee80211_conf *conf = &dev->conf; | ||
330 | |||
331 | pr_debug("CONFIG CHANGED: %08x\n", changed); | ||
332 | |||
333 | down(&priv->scan.lock); | ||
334 | mutex_lock(&priv->conf_mutex); | ||
335 | /* TODO: IEEE80211_CONF_CHANGE_QOS */ | ||
336 | /* TODO: IEEE80211_CONF_CHANGE_LISTEN_INTERVAL */ | ||
337 | |||
338 | if (changed & IEEE80211_CONF_CHANGE_POWER) { | ||
339 | priv->output_power = conf->power_level; | ||
340 | pr_debug("[STA] TX power: %d\n", priv->output_power); | ||
341 | wsm_set_output_power(priv, priv->output_power * 10); | ||
342 | } | ||
343 | |||
344 | if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) && | ||
345 | (priv->channel != conf->chandef.chan)) { | ||
346 | struct ieee80211_channel *ch = conf->chandef.chan; | ||
347 | struct wsm_switch_channel channel = { | ||
348 | .channel_number = ch->hw_value, | ||
349 | }; | ||
350 | pr_debug("[STA] Freq %d (wsm ch: %d).\n", | ||
351 | ch->center_freq, ch->hw_value); | ||
352 | |||
353 | /* __cw1200_flush() implicitly locks tx, if successful */ | ||
354 | if (!__cw1200_flush(priv, false)) { | ||
355 | if (!wsm_switch_channel(priv, &channel)) { | ||
356 | ret = wait_event_timeout(priv->channel_switch_done, | ||
357 | !priv->channel_switch_in_progress, | ||
358 | 3 * HZ); | ||
359 | if (ret) { | ||
360 | /* Already unlocks if successful */ | ||
361 | priv->channel = ch; | ||
362 | ret = 0; | ||
363 | } else { | ||
364 | ret = -ETIMEDOUT; | ||
365 | } | ||
366 | } else { | ||
367 | /* Unlock if switch channel fails */ | ||
368 | wsm_unlock_tx(priv); | ||
369 | } | ||
370 | } | ||
371 | } | ||
372 | |||
373 | if (changed & IEEE80211_CONF_CHANGE_PS) { | ||
374 | if (!(conf->flags & IEEE80211_CONF_PS)) | ||
375 | priv->powersave_mode.mode = WSM_PSM_ACTIVE; | ||
376 | else if (conf->dynamic_ps_timeout <= 0) | ||
377 | priv->powersave_mode.mode = WSM_PSM_PS; | ||
378 | else | ||
379 | priv->powersave_mode.mode = WSM_PSM_FAST_PS; | ||
380 | |||
381 | /* Firmware requires that value for this 1-byte field must | ||
382 | * be specified in units of 500us. Values above the 128ms | ||
383 | * threshold are not supported. | ||
384 | */ | ||
385 | if (conf->dynamic_ps_timeout >= 0x80) | ||
386 | priv->powersave_mode.fast_psm_idle_period = 0xFF; | ||
387 | else | ||
388 | priv->powersave_mode.fast_psm_idle_period = | ||
389 | conf->dynamic_ps_timeout << 1; | ||
390 | |||
391 | if (priv->join_status == CW1200_JOIN_STATUS_STA && | ||
392 | priv->bss_params.aid) | ||
393 | cw1200_set_pm(priv, &priv->powersave_mode); | ||
394 | } | ||
395 | |||
396 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { | ||
397 | /* TBD: It looks like it's transparent | ||
398 | * there's a monitor interface present -- use this | ||
399 | * to determine for example whether to calculate | ||
400 | * timestamps for packets or not, do not use instead | ||
401 | * of filter flags! | ||
402 | */ | ||
403 | } | ||
404 | |||
405 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { | ||
406 | struct wsm_operational_mode mode = { | ||
407 | .power_mode = cw1200_power_mode, | ||
408 | .disable_more_flag_usage = true, | ||
409 | }; | ||
410 | |||
411 | wsm_lock_tx(priv); | ||
412 | /* Disable p2p-dev mode forced by TX request */ | ||
413 | if ((priv->join_status == CW1200_JOIN_STATUS_MONITOR) && | ||
414 | (conf->flags & IEEE80211_CONF_IDLE) && | ||
415 | !priv->listening) { | ||
416 | cw1200_disable_listening(priv); | ||
417 | priv->join_status = CW1200_JOIN_STATUS_PASSIVE; | ||
418 | } | ||
419 | wsm_set_operational_mode(priv, &mode); | ||
420 | wsm_unlock_tx(priv); | ||
421 | } | ||
422 | |||
423 | if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) { | ||
424 | pr_debug("[STA] Retry limits: %d (long), %d (short).\n", | ||
425 | conf->long_frame_max_tx_count, | ||
426 | conf->short_frame_max_tx_count); | ||
427 | spin_lock_bh(&priv->tx_policy_cache.lock); | ||
428 | priv->long_frame_max_tx_count = conf->long_frame_max_tx_count; | ||
429 | priv->short_frame_max_tx_count = | ||
430 | (conf->short_frame_max_tx_count < 0x0F) ? | ||
431 | conf->short_frame_max_tx_count : 0x0F; | ||
432 | priv->hw->max_rate_tries = priv->short_frame_max_tx_count; | ||
433 | spin_unlock_bh(&priv->tx_policy_cache.lock); | ||
434 | } | ||
435 | mutex_unlock(&priv->conf_mutex); | ||
436 | up(&priv->scan.lock); | ||
437 | return ret; | ||
438 | } | ||
439 | |||
440 | void cw1200_update_filtering(struct cw1200_common *priv) | ||
441 | { | ||
442 | int ret; | ||
443 | bool bssid_filtering = !priv->rx_filter.bssid; | ||
444 | bool is_p2p = priv->vif && priv->vif->p2p; | ||
445 | bool is_sta = priv->vif && NL80211_IFTYPE_STATION == priv->vif->type; | ||
446 | |||
447 | static struct wsm_beacon_filter_control bf_ctrl; | ||
448 | static struct wsm_mib_beacon_filter_table bf_tbl = { | ||
449 | .entry[0].ie_id = WLAN_EID_VENDOR_SPECIFIC, | ||
450 | .entry[0].flags = WSM_BEACON_FILTER_IE_HAS_CHANGED | | ||
451 | WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT | | ||
452 | WSM_BEACON_FILTER_IE_HAS_APPEARED, | ||
453 | .entry[0].oui[0] = 0x50, | ||
454 | .entry[0].oui[1] = 0x6F, | ||
455 | .entry[0].oui[2] = 0x9A, | ||
456 | .entry[1].ie_id = WLAN_EID_HT_OPERATION, | ||
457 | .entry[1].flags = WSM_BEACON_FILTER_IE_HAS_CHANGED | | ||
458 | WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT | | ||
459 | WSM_BEACON_FILTER_IE_HAS_APPEARED, | ||
460 | .entry[2].ie_id = WLAN_EID_ERP_INFO, | ||
461 | .entry[2].flags = WSM_BEACON_FILTER_IE_HAS_CHANGED | | ||
462 | WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT | | ||
463 | WSM_BEACON_FILTER_IE_HAS_APPEARED, | ||
464 | }; | ||
465 | |||
466 | if (priv->join_status == CW1200_JOIN_STATUS_PASSIVE) | ||
467 | return; | ||
468 | else if (priv->join_status == CW1200_JOIN_STATUS_MONITOR) | ||
469 | bssid_filtering = false; | ||
470 | |||
471 | if (priv->disable_beacon_filter) { | ||
472 | bf_ctrl.enabled = 0; | ||
473 | bf_ctrl.bcn_count = 1; | ||
474 | bf_tbl.num = __cpu_to_le32(0); | ||
475 | } else if (is_p2p || !is_sta) { | ||
476 | bf_ctrl.enabled = WSM_BEACON_FILTER_ENABLE | | ||
477 | WSM_BEACON_FILTER_AUTO_ERP; | ||
478 | bf_ctrl.bcn_count = 0; | ||
479 | bf_tbl.num = __cpu_to_le32(2); | ||
480 | } else { | ||
481 | bf_ctrl.enabled = WSM_BEACON_FILTER_ENABLE; | ||
482 | bf_ctrl.bcn_count = 0; | ||
483 | bf_tbl.num = __cpu_to_le32(3); | ||
484 | } | ||
485 | |||
486 | /* | ||
487 | * When acting as p2p client being connected to p2p GO, in order to | ||
488 | * receive frames from a different p2p device, turn off bssid filter. | ||
489 | * | ||
490 | * WARNING: FW dependency! | ||
491 | * This can only be used with FW WSM371 and its successors. | ||
492 | * In that FW version even with bssid filter turned off, | ||
493 | * device will block most of the unwanted frames. | ||
494 | */ | ||
495 | if (is_p2p) | ||
496 | bssid_filtering = false; | ||
497 | |||
498 | ret = wsm_set_rx_filter(priv, &priv->rx_filter); | ||
499 | if (!ret) | ||
500 | ret = wsm_set_beacon_filter_table(priv, &bf_tbl); | ||
501 | if (!ret) | ||
502 | ret = wsm_beacon_filter_control(priv, &bf_ctrl); | ||
503 | if (!ret) | ||
504 | ret = wsm_set_bssid_filtering(priv, bssid_filtering); | ||
505 | if (!ret) | ||
506 | ret = wsm_set_multicast_filter(priv, &priv->multicast_filter); | ||
507 | if (ret) | ||
508 | wiphy_err(priv->hw->wiphy, | ||
509 | "Update filtering failed: %d.\n", ret); | ||
510 | return; | ||
511 | } | ||
512 | |||
513 | void cw1200_update_filtering_work(struct work_struct *work) | ||
514 | { | ||
515 | struct cw1200_common *priv = | ||
516 | container_of(work, struct cw1200_common, | ||
517 | update_filtering_work); | ||
518 | |||
519 | cw1200_update_filtering(priv); | ||
520 | } | ||
521 | |||
522 | void cw1200_set_beacon_wakeup_period_work(struct work_struct *work) | ||
523 | { | ||
524 | struct cw1200_common *priv = | ||
525 | container_of(work, struct cw1200_common, | ||
526 | set_beacon_wakeup_period_work); | ||
527 | |||
528 | wsm_set_beacon_wakeup_period(priv, | ||
529 | priv->beacon_int * priv->join_dtim_period > | ||
530 | MAX_BEACON_SKIP_TIME_MS ? 1 : | ||
531 | priv->join_dtim_period, 0); | ||
532 | } | ||
533 | |||
534 | u64 cw1200_prepare_multicast(struct ieee80211_hw *hw, | ||
535 | struct netdev_hw_addr_list *mc_list) | ||
536 | { | ||
537 | static u8 broadcast_ipv6[ETH_ALEN] = { | ||
538 | 0x33, 0x33, 0x00, 0x00, 0x00, 0x01 | ||
539 | }; | ||
540 | static u8 broadcast_ipv4[ETH_ALEN] = { | ||
541 | 0x01, 0x00, 0x5e, 0x00, 0x00, 0x01 | ||
542 | }; | ||
543 | struct cw1200_common *priv = hw->priv; | ||
544 | struct netdev_hw_addr *ha; | ||
545 | int count = 0; | ||
546 | |||
547 | /* Disable multicast filtering */ | ||
548 | priv->has_multicast_subscription = false; | ||
549 | memset(&priv->multicast_filter, 0x00, sizeof(priv->multicast_filter)); | ||
550 | |||
551 | if (netdev_hw_addr_list_count(mc_list) > WSM_MAX_GRP_ADDRTABLE_ENTRIES) | ||
552 | return 0; | ||
553 | |||
554 | /* Enable if requested */ | ||
555 | netdev_hw_addr_list_for_each(ha, mc_list) { | ||
556 | pr_debug("[STA] multicast: %pM\n", ha->addr); | ||
557 | memcpy(&priv->multicast_filter.macaddrs[count], | ||
558 | ha->addr, ETH_ALEN); | ||
559 | if (memcmp(ha->addr, broadcast_ipv4, ETH_ALEN) && | ||
560 | memcmp(ha->addr, broadcast_ipv6, ETH_ALEN)) | ||
561 | priv->has_multicast_subscription = true; | ||
562 | count++; | ||
563 | } | ||
564 | |||
565 | if (count) { | ||
566 | priv->multicast_filter.enable = __cpu_to_le32(1); | ||
567 | priv->multicast_filter.num_addrs = __cpu_to_le32(count); | ||
568 | } | ||
569 | |||
570 | return netdev_hw_addr_list_count(mc_list); | ||
571 | } | ||
572 | |||
573 | void cw1200_configure_filter(struct ieee80211_hw *dev, | ||
574 | unsigned int changed_flags, | ||
575 | unsigned int *total_flags, | ||
576 | u64 multicast) | ||
577 | { | ||
578 | struct cw1200_common *priv = dev->priv; | ||
579 | bool listening = !!(*total_flags & | ||
580 | (FIF_PROMISC_IN_BSS | | ||
581 | FIF_OTHER_BSS | | ||
582 | FIF_BCN_PRBRESP_PROMISC | | ||
583 | FIF_PROBE_REQ)); | ||
584 | |||
585 | *total_flags &= FIF_PROMISC_IN_BSS | | ||
586 | FIF_OTHER_BSS | | ||
587 | FIF_FCSFAIL | | ||
588 | FIF_BCN_PRBRESP_PROMISC | | ||
589 | FIF_PROBE_REQ; | ||
590 | |||
591 | down(&priv->scan.lock); | ||
592 | mutex_lock(&priv->conf_mutex); | ||
593 | |||
594 | priv->rx_filter.promiscuous = (*total_flags & FIF_PROMISC_IN_BSS) | ||
595 | ? 1 : 0; | ||
596 | priv->rx_filter.bssid = (*total_flags & (FIF_OTHER_BSS | | ||
597 | FIF_PROBE_REQ)) ? 1 : 0; | ||
598 | priv->rx_filter.fcs = (*total_flags & FIF_FCSFAIL) ? 1 : 0; | ||
599 | priv->disable_beacon_filter = !(*total_flags & | ||
600 | (FIF_BCN_PRBRESP_PROMISC | | ||
601 | FIF_PROMISC_IN_BSS | | ||
602 | FIF_PROBE_REQ)); | ||
603 | if (priv->listening != listening) { | ||
604 | priv->listening = listening; | ||
605 | wsm_lock_tx(priv); | ||
606 | cw1200_update_listening(priv, listening); | ||
607 | wsm_unlock_tx(priv); | ||
608 | } | ||
609 | cw1200_update_filtering(priv); | ||
610 | mutex_unlock(&priv->conf_mutex); | ||
611 | up(&priv->scan.lock); | ||
612 | } | ||
613 | |||
614 | int cw1200_conf_tx(struct ieee80211_hw *dev, struct ieee80211_vif *vif, | ||
615 | u16 queue, const struct ieee80211_tx_queue_params *params) | ||
616 | { | ||
617 | struct cw1200_common *priv = dev->priv; | ||
618 | int ret = 0; | ||
619 | /* To prevent re-applying PM request OID again and again*/ | ||
620 | bool old_uapsd_flags; | ||
621 | |||
622 | mutex_lock(&priv->conf_mutex); | ||
623 | |||
624 | if (queue < dev->queues) { | ||
625 | old_uapsd_flags = priv->uapsd_info.uapsd_flags; | ||
626 | |||
627 | WSM_TX_QUEUE_SET(&priv->tx_queue_params, queue, 0, 0, 0); | ||
628 | ret = wsm_set_tx_queue_params(priv, | ||
629 | &priv->tx_queue_params.params[queue], queue); | ||
630 | if (ret) { | ||
631 | ret = -EINVAL; | ||
632 | goto out; | ||
633 | } | ||
634 | |||
635 | WSM_EDCA_SET(&priv->edca, queue, params->aifs, | ||
636 | params->cw_min, params->cw_max, | ||
637 | params->txop, 0xc8, | ||
638 | params->uapsd); | ||
639 | ret = wsm_set_edca_params(priv, &priv->edca); | ||
640 | if (ret) { | ||
641 | ret = -EINVAL; | ||
642 | goto out; | ||
643 | } | ||
644 | |||
645 | if (priv->mode == NL80211_IFTYPE_STATION) { | ||
646 | ret = cw1200_set_uapsd_param(priv, &priv->edca); | ||
647 | if (!ret && priv->setbssparams_done && | ||
648 | (priv->join_status == CW1200_JOIN_STATUS_STA) && | ||
649 | (old_uapsd_flags != priv->uapsd_info.uapsd_flags)) | ||
650 | ret = cw1200_set_pm(priv, &priv->powersave_mode); | ||
651 | } | ||
652 | } else { | ||
653 | ret = -EINVAL; | ||
654 | } | ||
655 | |||
656 | out: | ||
657 | mutex_unlock(&priv->conf_mutex); | ||
658 | return ret; | ||
659 | } | ||
660 | |||
661 | int cw1200_get_stats(struct ieee80211_hw *dev, | ||
662 | struct ieee80211_low_level_stats *stats) | ||
663 | { | ||
664 | struct cw1200_common *priv = dev->priv; | ||
665 | |||
666 | memcpy(stats, &priv->stats, sizeof(*stats)); | ||
667 | return 0; | ||
668 | } | ||
669 | |||
670 | int cw1200_set_pm(struct cw1200_common *priv, const struct wsm_set_pm *arg) | ||
671 | { | ||
672 | struct wsm_set_pm pm = *arg; | ||
673 | |||
674 | if (priv->uapsd_info.uapsd_flags != 0) | ||
675 | pm.mode &= ~WSM_PSM_FAST_PS_FLAG; | ||
676 | |||
677 | if (memcmp(&pm, &priv->firmware_ps_mode, | ||
678 | sizeof(struct wsm_set_pm))) { | ||
679 | priv->firmware_ps_mode = pm; | ||
680 | return wsm_set_pm(priv, &pm); | ||
681 | } else { | ||
682 | return 0; | ||
683 | } | ||
684 | } | ||
685 | |||
686 | int cw1200_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd, | ||
687 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, | ||
688 | struct ieee80211_key_conf *key) | ||
689 | { | ||
690 | int ret = -EOPNOTSUPP; | ||
691 | struct cw1200_common *priv = dev->priv; | ||
692 | struct ieee80211_key_seq seq; | ||
693 | |||
694 | mutex_lock(&priv->conf_mutex); | ||
695 | |||
696 | if (cmd == SET_KEY) { | ||
697 | u8 *peer_addr = NULL; | ||
698 | int pairwise = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) ? | ||
699 | 1 : 0; | ||
700 | int idx = cw1200_alloc_key(priv); | ||
701 | struct wsm_add_key *wsm_key = &priv->keys[idx]; | ||
702 | |||
703 | if (idx < 0) { | ||
704 | ret = -EINVAL; | ||
705 | goto finally; | ||
706 | } | ||
707 | |||
708 | if (sta) | ||
709 | peer_addr = sta->addr; | ||
710 | |||
711 | key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; | ||
712 | |||
713 | switch (key->cipher) { | ||
714 | case WLAN_CIPHER_SUITE_WEP40: | ||
715 | case WLAN_CIPHER_SUITE_WEP104: | ||
716 | if (key->keylen > 16) { | ||
717 | cw1200_free_key(priv, idx); | ||
718 | ret = -EINVAL; | ||
719 | goto finally; | ||
720 | } | ||
721 | |||
722 | if (pairwise) { | ||
723 | wsm_key->type = WSM_KEY_TYPE_WEP_PAIRWISE; | ||
724 | memcpy(wsm_key->wep_pairwise.peer, | ||
725 | peer_addr, ETH_ALEN); | ||
726 | memcpy(wsm_key->wep_pairwise.keydata, | ||
727 | &key->key[0], key->keylen); | ||
728 | wsm_key->wep_pairwise.keylen = key->keylen; | ||
729 | } else { | ||
730 | wsm_key->type = WSM_KEY_TYPE_WEP_DEFAULT; | ||
731 | memcpy(wsm_key->wep_group.keydata, | ||
732 | &key->key[0], key->keylen); | ||
733 | wsm_key->wep_group.keylen = key->keylen; | ||
734 | wsm_key->wep_group.keyid = key->keyidx; | ||
735 | } | ||
736 | break; | ||
737 | case WLAN_CIPHER_SUITE_TKIP: | ||
738 | ieee80211_get_key_rx_seq(key, 0, &seq); | ||
739 | if (pairwise) { | ||
740 | wsm_key->type = WSM_KEY_TYPE_TKIP_PAIRWISE; | ||
741 | memcpy(wsm_key->tkip_pairwise.peer, | ||
742 | peer_addr, ETH_ALEN); | ||
743 | memcpy(wsm_key->tkip_pairwise.keydata, | ||
744 | &key->key[0], 16); | ||
745 | memcpy(wsm_key->tkip_pairwise.tx_mic_key, | ||
746 | &key->key[16], 8); | ||
747 | memcpy(wsm_key->tkip_pairwise.rx_mic_key, | ||
748 | &key->key[24], 8); | ||
749 | } else { | ||
750 | size_t mic_offset = | ||
751 | (priv->mode == NL80211_IFTYPE_AP) ? | ||
752 | 16 : 24; | ||
753 | wsm_key->type = WSM_KEY_TYPE_TKIP_GROUP; | ||
754 | memcpy(wsm_key->tkip_group.keydata, | ||
755 | &key->key[0], 16); | ||
756 | memcpy(wsm_key->tkip_group.rx_mic_key, | ||
757 | &key->key[mic_offset], 8); | ||
758 | |||
759 | wsm_key->tkip_group.rx_seqnum[0] = seq.tkip.iv16 & 0xff; | ||
760 | wsm_key->tkip_group.rx_seqnum[1] = (seq.tkip.iv16 >> 8) & 0xff; | ||
761 | wsm_key->tkip_group.rx_seqnum[2] = seq.tkip.iv32 & 0xff; | ||
762 | wsm_key->tkip_group.rx_seqnum[3] = (seq.tkip.iv32 >> 8) & 0xff; | ||
763 | wsm_key->tkip_group.rx_seqnum[4] = (seq.tkip.iv32 >> 16) & 0xff; | ||
764 | wsm_key->tkip_group.rx_seqnum[5] = (seq.tkip.iv32 >> 24) & 0xff; | ||
765 | wsm_key->tkip_group.rx_seqnum[6] = 0; | ||
766 | wsm_key->tkip_group.rx_seqnum[7] = 0; | ||
767 | |||
768 | wsm_key->tkip_group.keyid = key->keyidx; | ||
769 | } | ||
770 | break; | ||
771 | case WLAN_CIPHER_SUITE_CCMP: | ||
772 | ieee80211_get_key_rx_seq(key, 0, &seq); | ||
773 | if (pairwise) { | ||
774 | wsm_key->type = WSM_KEY_TYPE_AES_PAIRWISE; | ||
775 | memcpy(wsm_key->aes_pairwise.peer, | ||
776 | peer_addr, ETH_ALEN); | ||
777 | memcpy(wsm_key->aes_pairwise.keydata, | ||
778 | &key->key[0], 16); | ||
779 | } else { | ||
780 | wsm_key->type = WSM_KEY_TYPE_AES_GROUP; | ||
781 | memcpy(wsm_key->aes_group.keydata, | ||
782 | &key->key[0], 16); | ||
783 | |||
784 | wsm_key->aes_group.rx_seqnum[0] = seq.ccmp.pn[5]; | ||
785 | wsm_key->aes_group.rx_seqnum[1] = seq.ccmp.pn[4]; | ||
786 | wsm_key->aes_group.rx_seqnum[2] = seq.ccmp.pn[3]; | ||
787 | wsm_key->aes_group.rx_seqnum[3] = seq.ccmp.pn[2]; | ||
788 | wsm_key->aes_group.rx_seqnum[4] = seq.ccmp.pn[1]; | ||
789 | wsm_key->aes_group.rx_seqnum[5] = seq.ccmp.pn[0]; | ||
790 | wsm_key->aes_group.rx_seqnum[6] = 0; | ||
791 | wsm_key->aes_group.rx_seqnum[7] = 0; | ||
792 | wsm_key->aes_group.keyid = key->keyidx; | ||
793 | } | ||
794 | break; | ||
795 | case WLAN_CIPHER_SUITE_SMS4: | ||
796 | if (pairwise) { | ||
797 | wsm_key->type = WSM_KEY_TYPE_WAPI_PAIRWISE; | ||
798 | memcpy(wsm_key->wapi_pairwise.peer, | ||
799 | peer_addr, ETH_ALEN); | ||
800 | memcpy(wsm_key->wapi_pairwise.keydata, | ||
801 | &key->key[0], 16); | ||
802 | memcpy(wsm_key->wapi_pairwise.mic_key, | ||
803 | &key->key[16], 16); | ||
804 | wsm_key->wapi_pairwise.keyid = key->keyidx; | ||
805 | } else { | ||
806 | wsm_key->type = WSM_KEY_TYPE_WAPI_GROUP; | ||
807 | memcpy(wsm_key->wapi_group.keydata, | ||
808 | &key->key[0], 16); | ||
809 | memcpy(wsm_key->wapi_group.mic_key, | ||
810 | &key->key[16], 16); | ||
811 | wsm_key->wapi_group.keyid = key->keyidx; | ||
812 | } | ||
813 | break; | ||
814 | default: | ||
815 | pr_warn("Unhandled key type %d\n", key->cipher); | ||
816 | cw1200_free_key(priv, idx); | ||
817 | ret = -EOPNOTSUPP; | ||
818 | goto finally; | ||
819 | } | ||
820 | ret = wsm_add_key(priv, wsm_key); | ||
821 | if (!ret) | ||
822 | key->hw_key_idx = idx; | ||
823 | else | ||
824 | cw1200_free_key(priv, idx); | ||
825 | } else if (cmd == DISABLE_KEY) { | ||
826 | struct wsm_remove_key wsm_key = { | ||
827 | .index = key->hw_key_idx, | ||
828 | }; | ||
829 | |||
830 | if (wsm_key.index > WSM_KEY_MAX_INDEX) { | ||
831 | ret = -EINVAL; | ||
832 | goto finally; | ||
833 | } | ||
834 | |||
835 | cw1200_free_key(priv, wsm_key.index); | ||
836 | ret = wsm_remove_key(priv, &wsm_key); | ||
837 | } else { | ||
838 | pr_warn("Unhandled key command %d\n", cmd); | ||
839 | } | ||
840 | |||
841 | finally: | ||
842 | mutex_unlock(&priv->conf_mutex); | ||
843 | return ret; | ||
844 | } | ||
845 | |||
846 | void cw1200_wep_key_work(struct work_struct *work) | ||
847 | { | ||
848 | struct cw1200_common *priv = | ||
849 | container_of(work, struct cw1200_common, wep_key_work); | ||
850 | u8 queue_id = cw1200_queue_get_queue_id(priv->pending_frame_id); | ||
851 | struct cw1200_queue *queue = &priv->tx_queue[queue_id]; | ||
852 | __le32 wep_default_key_id = __cpu_to_le32( | ||
853 | priv->wep_default_key_id); | ||
854 | |||
855 | pr_debug("[STA] Setting default WEP key: %d\n", | ||
856 | priv->wep_default_key_id); | ||
857 | wsm_flush_tx(priv); | ||
858 | wsm_write_mib(priv, WSM_MIB_ID_DOT11_WEP_DEFAULT_KEY_ID, | ||
859 | &wep_default_key_id, sizeof(wep_default_key_id)); | ||
860 | cw1200_queue_requeue(queue, priv->pending_frame_id); | ||
861 | wsm_unlock_tx(priv); | ||
862 | } | ||
863 | |||
864 | int cw1200_set_rts_threshold(struct ieee80211_hw *hw, u32 value) | ||
865 | { | ||
866 | int ret = 0; | ||
867 | __le32 val32; | ||
868 | struct cw1200_common *priv = hw->priv; | ||
869 | |||
870 | if (priv->mode == NL80211_IFTYPE_UNSPECIFIED) | ||
871 | return 0; | ||
872 | |||
873 | if (value != (u32) -1) | ||
874 | val32 = __cpu_to_le32(value); | ||
875 | else | ||
876 | val32 = 0; /* disabled */ | ||
877 | |||
878 | if (priv->mode == NL80211_IFTYPE_UNSPECIFIED) { | ||
879 | /* device is down, can _not_ set threshold */ | ||
880 | ret = -ENODEV; | ||
881 | goto out; | ||
882 | } | ||
883 | |||
884 | if (priv->rts_threshold == value) | ||
885 | goto out; | ||
886 | |||
887 | pr_debug("[STA] Setting RTS threshold: %d\n", | ||
888 | priv->rts_threshold); | ||
889 | |||
890 | /* mutex_lock(&priv->conf_mutex); */ | ||
891 | ret = wsm_write_mib(priv, WSM_MIB_ID_DOT11_RTS_THRESHOLD, | ||
892 | &val32, sizeof(val32)); | ||
893 | if (!ret) | ||
894 | priv->rts_threshold = value; | ||
895 | /* mutex_unlock(&priv->conf_mutex); */ | ||
896 | |||
897 | out: | ||
898 | return ret; | ||
899 | } | ||
900 | |||
901 | /* If successful, LOCKS the TX queue! */ | ||
902 | static int __cw1200_flush(struct cw1200_common *priv, bool drop) | ||
903 | { | ||
904 | int i, ret; | ||
905 | |||
906 | for (;;) { | ||
907 | /* TODO: correct flush handling is required when dev_stop. | ||
908 | * Temporary workaround: 2s | ||
909 | */ | ||
910 | if (drop) { | ||
911 | for (i = 0; i < 4; ++i) | ||
912 | cw1200_queue_clear(&priv->tx_queue[i]); | ||
913 | } else { | ||
914 | ret = wait_event_timeout( | ||
915 | priv->tx_queue_stats.wait_link_id_empty, | ||
916 | cw1200_queue_stats_is_empty( | ||
917 | &priv->tx_queue_stats, -1), | ||
918 | 2 * HZ); | ||
919 | } | ||
920 | |||
921 | if (!drop && ret <= 0) { | ||
922 | ret = -ETIMEDOUT; | ||
923 | break; | ||
924 | } else { | ||
925 | ret = 0; | ||
926 | } | ||
927 | |||
928 | wsm_lock_tx(priv); | ||
929 | if (!cw1200_queue_stats_is_empty(&priv->tx_queue_stats, -1)) { | ||
930 | /* Highly unlikely: WSM requeued frames. */ | ||
931 | wsm_unlock_tx(priv); | ||
932 | continue; | ||
933 | } | ||
934 | break; | ||
935 | } | ||
936 | return ret; | ||
937 | } | ||
938 | |||
939 | void cw1200_flush(struct ieee80211_hw *hw, u32 queues, bool drop) | ||
940 | { | ||
941 | struct cw1200_common *priv = hw->priv; | ||
942 | |||
943 | switch (priv->mode) { | ||
944 | case NL80211_IFTYPE_MONITOR: | ||
945 | drop = true; | ||
946 | break; | ||
947 | case NL80211_IFTYPE_AP: | ||
948 | if (!priv->enable_beacon) | ||
949 | drop = true; | ||
950 | break; | ||
951 | } | ||
952 | |||
953 | if (!__cw1200_flush(priv, drop)) | ||
954 | wsm_unlock_tx(priv); | ||
955 | |||
956 | return; | ||
957 | } | ||
958 | |||
959 | /* ******************************************************************** */ | ||
960 | /* WSM callbacks */ | ||
961 | |||
962 | void cw1200_free_event_queue(struct cw1200_common *priv) | ||
963 | { | ||
964 | LIST_HEAD(list); | ||
965 | |||
966 | spin_lock(&priv->event_queue_lock); | ||
967 | list_splice_init(&priv->event_queue, &list); | ||
968 | spin_unlock(&priv->event_queue_lock); | ||
969 | |||
970 | __cw1200_free_event_queue(&list); | ||
971 | } | ||
972 | |||
973 | void cw1200_event_handler(struct work_struct *work) | ||
974 | { | ||
975 | struct cw1200_common *priv = | ||
976 | container_of(work, struct cw1200_common, event_handler); | ||
977 | struct cw1200_wsm_event *event; | ||
978 | LIST_HEAD(list); | ||
979 | |||
980 | spin_lock(&priv->event_queue_lock); | ||
981 | list_splice_init(&priv->event_queue, &list); | ||
982 | spin_unlock(&priv->event_queue_lock); | ||
983 | |||
984 | list_for_each_entry(event, &list, link) { | ||
985 | switch (event->evt.id) { | ||
986 | case WSM_EVENT_ERROR: | ||
987 | pr_err("Unhandled WSM Error from LMAC\n"); | ||
988 | break; | ||
989 | case WSM_EVENT_BSS_LOST: | ||
990 | pr_debug("[CQM] BSS lost.\n"); | ||
991 | cancel_work_sync(&priv->unjoin_work); | ||
992 | if (!down_trylock(&priv->scan.lock)) { | ||
993 | cw1200_cqm_bssloss_sm(priv, 1, 0, 0); | ||
994 | up(&priv->scan.lock); | ||
995 | } else { | ||
996 | /* Scan is in progress. Delay reporting. | ||
997 | * Scan complete will trigger bss_loss_work | ||
998 | */ | ||
999 | priv->delayed_link_loss = 1; | ||
1000 | /* Also start a watchdog. */ | ||
1001 | queue_delayed_work(priv->workqueue, | ||
1002 | &priv->bss_loss_work, 5*HZ); | ||
1003 | } | ||
1004 | break; | ||
1005 | case WSM_EVENT_BSS_REGAINED: | ||
1006 | pr_debug("[CQM] BSS regained.\n"); | ||
1007 | cw1200_cqm_bssloss_sm(priv, 0, 0, 0); | ||
1008 | cancel_work_sync(&priv->unjoin_work); | ||
1009 | break; | ||
1010 | case WSM_EVENT_RADAR_DETECTED: | ||
1011 | wiphy_info(priv->hw->wiphy, "radar pulse detected\n"); | ||
1012 | break; | ||
1013 | case WSM_EVENT_RCPI_RSSI: | ||
1014 | { | ||
1015 | /* RSSI: signed Q8.0, RCPI: unsigned Q7.1 | ||
1016 | * RSSI = RCPI / 2 - 110 | ||
1017 | */ | ||
1018 | int rcpiRssi = (int)(event->evt.data & 0xFF); | ||
1019 | int cqm_evt; | ||
1020 | if (priv->cqm_use_rssi) | ||
1021 | rcpiRssi = (s8)rcpiRssi; | ||
1022 | else | ||
1023 | rcpiRssi = rcpiRssi / 2 - 110; | ||
1024 | |||
1025 | cqm_evt = (rcpiRssi <= priv->cqm_rssi_thold) ? | ||
1026 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW : | ||
1027 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH; | ||
1028 | pr_debug("[CQM] RSSI event: %d.\n", rcpiRssi); | ||
1029 | ieee80211_cqm_rssi_notify(priv->vif, cqm_evt, | ||
1030 | GFP_KERNEL); | ||
1031 | break; | ||
1032 | } | ||
1033 | case WSM_EVENT_BT_INACTIVE: | ||
1034 | pr_warn("Unhandled BT INACTIVE from LMAC\n"); | ||
1035 | break; | ||
1036 | case WSM_EVENT_BT_ACTIVE: | ||
1037 | pr_warn("Unhandled BT ACTIVE from LMAC\n"); | ||
1038 | break; | ||
1039 | } | ||
1040 | } | ||
1041 | __cw1200_free_event_queue(&list); | ||
1042 | } | ||
1043 | |||
1044 | void cw1200_bss_loss_work(struct work_struct *work) | ||
1045 | { | ||
1046 | struct cw1200_common *priv = | ||
1047 | container_of(work, struct cw1200_common, bss_loss_work.work); | ||
1048 | |||
1049 | pr_debug("[CQM] Reporting connection loss.\n"); | ||
1050 | wsm_lock_tx(priv); | ||
1051 | if (queue_work(priv->workqueue, &priv->unjoin_work) <= 0) | ||
1052 | wsm_unlock_tx(priv); | ||
1053 | } | ||
1054 | |||
1055 | void cw1200_bss_params_work(struct work_struct *work) | ||
1056 | { | ||
1057 | struct cw1200_common *priv = | ||
1058 | container_of(work, struct cw1200_common, bss_params_work); | ||
1059 | mutex_lock(&priv->conf_mutex); | ||
1060 | |||
1061 | priv->bss_params.reset_beacon_loss = 1; | ||
1062 | wsm_set_bss_params(priv, &priv->bss_params); | ||
1063 | priv->bss_params.reset_beacon_loss = 0; | ||
1064 | |||
1065 | mutex_unlock(&priv->conf_mutex); | ||
1066 | } | ||
1067 | |||
1068 | /* ******************************************************************** */ | ||
1069 | /* Internal API */ | ||
1070 | |||
1071 | /* | ||
1072 | * This function is called to Parse the SDD file | ||
1073 | * to extract listen_interval and PTA related information | ||
1074 | * sdd is a TLV: u8 id, u8 len, u8 data[] | ||
1075 | */ | ||
1076 | static int cw1200_parse_sdd_file(struct cw1200_common *priv) | ||
1077 | { | ||
1078 | const u8 *p = priv->sdd->data; | ||
1079 | int ret = 0; | ||
1080 | |||
1081 | while (p + 2 <= priv->sdd->data + priv->sdd->size) { | ||
1082 | if (p + p[1] + 2 > priv->sdd->data + priv->sdd->size) { | ||
1083 | pr_warn("Malformed sdd structure\n"); | ||
1084 | return -1; | ||
1085 | } | ||
1086 | switch (p[0]) { | ||
1087 | case SDD_PTA_CFG_ELT_ID: { | ||
1088 | u16 v; | ||
1089 | if (p[1] < 4) { | ||
1090 | pr_warn("SDD_PTA_CFG_ELT_ID malformed\n"); | ||
1091 | ret = -1; | ||
1092 | break; | ||
1093 | } | ||
1094 | v = le16_to_cpu(*((u16 *)(p + 2))); | ||
1095 | if (!v) /* non-zero means this is enabled */ | ||
1096 | break; | ||
1097 | |||
1098 | v = le16_to_cpu(*((u16 *)(p + 4))); | ||
1099 | priv->conf_listen_interval = (v >> 7) & 0x1F; | ||
1100 | pr_debug("PTA found; Listen Interval %d\n", | ||
1101 | priv->conf_listen_interval); | ||
1102 | break; | ||
1103 | } | ||
1104 | case SDD_REFERENCE_FREQUENCY_ELT_ID: { | ||
1105 | u16 clk = le16_to_cpu(*((u16 *)(p + 2))); | ||
1106 | if (clk != priv->hw_refclk) | ||
1107 | pr_warn("SDD file doesn't match configured refclk (%d vs %d)\n", | ||
1108 | clk, priv->hw_refclk); | ||
1109 | break; | ||
1110 | } | ||
1111 | default: | ||
1112 | break; | ||
1113 | } | ||
1114 | p += p[1] + 2; | ||
1115 | } | ||
1116 | |||
1117 | if (!priv->bt_present) { | ||
1118 | pr_debug("PTA element NOT found.\n"); | ||
1119 | priv->conf_listen_interval = 0; | ||
1120 | } | ||
1121 | return ret; | ||
1122 | } | ||
1123 | |||
1124 | int cw1200_setup_mac(struct cw1200_common *priv) | ||
1125 | { | ||
1126 | int ret = 0; | ||
1127 | |||
1128 | /* NOTE: There is a bug in FW: it reports signal | ||
1129 | * as RSSI if RSSI subscription is enabled. | ||
1130 | * It's not enough to set WSM_RCPI_RSSI_USE_RSSI. | ||
1131 | * | ||
1132 | * NOTE2: RSSI based reports have been switched to RCPI, since | ||
1133 | * FW has a bug and RSSI reported values are not stable, | ||
1134 | * what can leads to signal level oscilations in user-end applications | ||
1135 | */ | ||
1136 | struct wsm_rcpi_rssi_threshold threshold = { | ||
1137 | .rssiRcpiMode = WSM_RCPI_RSSI_THRESHOLD_ENABLE | | ||
1138 | WSM_RCPI_RSSI_DONT_USE_UPPER | | ||
1139 | WSM_RCPI_RSSI_DONT_USE_LOWER, | ||
1140 | .rollingAverageCount = 16, | ||
1141 | }; | ||
1142 | |||
1143 | struct wsm_configuration cfg = { | ||
1144 | .dot11StationId = &priv->mac_addr[0], | ||
1145 | }; | ||
1146 | |||
1147 | /* Remember the decission here to make sure, we will handle | ||
1148 | * the RCPI/RSSI value correctly on WSM_EVENT_RCPI_RSS | ||
1149 | */ | ||
1150 | if (threshold.rssiRcpiMode & WSM_RCPI_RSSI_USE_RSSI) | ||
1151 | priv->cqm_use_rssi = true; | ||
1152 | |||
1153 | if (!priv->sdd) { | ||
1154 | ret = request_firmware(&priv->sdd, priv->sdd_path, priv->pdev); | ||
1155 | if (ret) { | ||
1156 | pr_err("Can't load sdd file %s.\n", priv->sdd_path); | ||
1157 | return ret; | ||
1158 | } | ||
1159 | cw1200_parse_sdd_file(priv); | ||
1160 | } | ||
1161 | |||
1162 | cfg.dpdData = priv->sdd->data; | ||
1163 | cfg.dpdData_size = priv->sdd->size; | ||
1164 | ret = wsm_configuration(priv, &cfg); | ||
1165 | if (ret) | ||
1166 | return ret; | ||
1167 | |||
1168 | /* Configure RSSI/SCPI reporting as RSSI. */ | ||
1169 | wsm_set_rcpi_rssi_threshold(priv, &threshold); | ||
1170 | |||
1171 | return 0; | ||
1172 | } | ||
1173 | |||
1174 | static void cw1200_join_complete(struct cw1200_common *priv) | ||
1175 | { | ||
1176 | pr_debug("[STA] Join complete (%d)\n", priv->join_complete_status); | ||
1177 | |||
1178 | priv->join_pending = false; | ||
1179 | if (priv->join_complete_status) { | ||
1180 | priv->join_status = CW1200_JOIN_STATUS_PASSIVE; | ||
1181 | cw1200_update_listening(priv, priv->listening); | ||
1182 | cw1200_do_unjoin(priv); | ||
1183 | ieee80211_connection_loss(priv->vif); | ||
1184 | } else { | ||
1185 | if (priv->mode == NL80211_IFTYPE_ADHOC) | ||
1186 | priv->join_status = CW1200_JOIN_STATUS_IBSS; | ||
1187 | else | ||
1188 | priv->join_status = CW1200_JOIN_STATUS_PRE_STA; | ||
1189 | } | ||
1190 | wsm_unlock_tx(priv); /* Clearing the lock held before do_join() */ | ||
1191 | } | ||
1192 | |||
1193 | void cw1200_join_complete_work(struct work_struct *work) | ||
1194 | { | ||
1195 | struct cw1200_common *priv = | ||
1196 | container_of(work, struct cw1200_common, join_complete_work); | ||
1197 | mutex_lock(&priv->conf_mutex); | ||
1198 | cw1200_join_complete(priv); | ||
1199 | mutex_unlock(&priv->conf_mutex); | ||
1200 | } | ||
1201 | |||
1202 | void cw1200_join_complete_cb(struct cw1200_common *priv, | ||
1203 | struct wsm_join_complete *arg) | ||
1204 | { | ||
1205 | pr_debug("[STA] cw1200_join_complete_cb called, status=%d.\n", | ||
1206 | arg->status); | ||
1207 | |||
1208 | if (cancel_delayed_work(&priv->join_timeout)) { | ||
1209 | priv->join_complete_status = arg->status; | ||
1210 | queue_work(priv->workqueue, &priv->join_complete_work); | ||
1211 | } | ||
1212 | } | ||
1213 | |||
1214 | /* MUST be called with tx_lock held! It will be unlocked for us. */ | ||
1215 | static void cw1200_do_join(struct cw1200_common *priv) | ||
1216 | { | ||
1217 | const u8 *bssid; | ||
1218 | struct ieee80211_bss_conf *conf = &priv->vif->bss_conf; | ||
1219 | struct cfg80211_bss *bss = NULL; | ||
1220 | struct wsm_protected_mgmt_policy mgmt_policy; | ||
1221 | struct wsm_join join = { | ||
1222 | .mode = conf->ibss_joined ? | ||
1223 | WSM_JOIN_MODE_IBSS : WSM_JOIN_MODE_BSS, | ||
1224 | .preamble_type = WSM_JOIN_PREAMBLE_LONG, | ||
1225 | .probe_for_join = 1, | ||
1226 | .atim_window = 0, | ||
1227 | .basic_rate_set = cw1200_rate_mask_to_wsm(priv, | ||
1228 | conf->basic_rates), | ||
1229 | }; | ||
1230 | if (delayed_work_pending(&priv->join_timeout)) { | ||
1231 | pr_warn("[STA] - Join request already pending, skipping..\n"); | ||
1232 | wsm_unlock_tx(priv); | ||
1233 | return; | ||
1234 | } | ||
1235 | |||
1236 | if (priv->join_status) | ||
1237 | cw1200_do_unjoin(priv); | ||
1238 | |||
1239 | bssid = priv->vif->bss_conf.bssid; | ||
1240 | |||
1241 | bss = cfg80211_get_bss(priv->hw->wiphy, priv->channel, | ||
1242 | bssid, NULL, 0, 0, 0); | ||
1243 | |||
1244 | if (!bss && !conf->ibss_joined) { | ||
1245 | wsm_unlock_tx(priv); | ||
1246 | return; | ||
1247 | } | ||
1248 | |||
1249 | mutex_lock(&priv->conf_mutex); | ||
1250 | |||
1251 | /* Under the conf lock: check scan status and | ||
1252 | * bail out if it is in progress. | ||
1253 | */ | ||
1254 | if (atomic_read(&priv->scan.in_progress)) { | ||
1255 | wsm_unlock_tx(priv); | ||
1256 | goto done_put; | ||
1257 | } | ||
1258 | |||
1259 | priv->join_pending = true; | ||
1260 | |||
1261 | /* Sanity check basic rates */ | ||
1262 | if (!join.basic_rate_set) | ||
1263 | join.basic_rate_set = 7; | ||
1264 | |||
1265 | /* Sanity check beacon interval */ | ||
1266 | if (!priv->beacon_int) | ||
1267 | priv->beacon_int = 1; | ||
1268 | |||
1269 | join.beacon_interval = priv->beacon_int; | ||
1270 | |||
1271 | /* BT Coex related changes */ | ||
1272 | if (priv->bt_present) { | ||
1273 | if (((priv->conf_listen_interval * 100) % | ||
1274 | priv->beacon_int) == 0) | ||
1275 | priv->listen_interval = | ||
1276 | ((priv->conf_listen_interval * 100) / | ||
1277 | priv->beacon_int); | ||
1278 | else | ||
1279 | priv->listen_interval = | ||
1280 | ((priv->conf_listen_interval * 100) / | ||
1281 | priv->beacon_int + 1); | ||
1282 | } | ||
1283 | |||
1284 | if (priv->hw->conf.ps_dtim_period) | ||
1285 | priv->join_dtim_period = priv->hw->conf.ps_dtim_period; | ||
1286 | join.dtim_period = priv->join_dtim_period; | ||
1287 | |||
1288 | join.channel_number = priv->channel->hw_value; | ||
1289 | join.band = (priv->channel->band == IEEE80211_BAND_5GHZ) ? | ||
1290 | WSM_PHY_BAND_5G : WSM_PHY_BAND_2_4G; | ||
1291 | |||
1292 | memcpy(join.bssid, bssid, sizeof(join.bssid)); | ||
1293 | |||
1294 | pr_debug("[STA] Join BSSID: %pM DTIM: %d, interval: %d\n", | ||
1295 | join.bssid, | ||
1296 | join.dtim_period, priv->beacon_int); | ||
1297 | |||
1298 | if (!conf->ibss_joined) { | ||
1299 | const u8 *ssidie; | ||
1300 | rcu_read_lock(); | ||
1301 | ssidie = ieee80211_bss_get_ie(bss, WLAN_EID_SSID); | ||
1302 | if (ssidie) { | ||
1303 | join.ssid_len = ssidie[1]; | ||
1304 | memcpy(join.ssid, &ssidie[2], join.ssid_len); | ||
1305 | } | ||
1306 | rcu_read_unlock(); | ||
1307 | } | ||
1308 | |||
1309 | if (priv->vif->p2p) { | ||
1310 | join.flags |= WSM_JOIN_FLAGS_P2P_GO; | ||
1311 | join.basic_rate_set = | ||
1312 | cw1200_rate_mask_to_wsm(priv, 0xFF0); | ||
1313 | } | ||
1314 | |||
1315 | /* Enable asynchronous join calls */ | ||
1316 | if (!conf->ibss_joined) { | ||
1317 | join.flags |= WSM_JOIN_FLAGS_FORCE; | ||
1318 | join.flags |= WSM_JOIN_FLAGS_FORCE_WITH_COMPLETE_IND; | ||
1319 | } | ||
1320 | |||
1321 | wsm_flush_tx(priv); | ||
1322 | |||
1323 | /* Stay Awake for Join and Auth Timeouts and a bit more */ | ||
1324 | cw1200_pm_stay_awake(&priv->pm_state, | ||
1325 | CW1200_JOIN_TIMEOUT + CW1200_AUTH_TIMEOUT); | ||
1326 | |||
1327 | cw1200_update_listening(priv, false); | ||
1328 | |||
1329 | /* Turn on Block ACKs */ | ||
1330 | wsm_set_block_ack_policy(priv, priv->ba_tx_tid_mask, | ||
1331 | priv->ba_rx_tid_mask); | ||
1332 | |||
1333 | /* Set up timeout */ | ||
1334 | if (join.flags & WSM_JOIN_FLAGS_FORCE_WITH_COMPLETE_IND) { | ||
1335 | priv->join_status = CW1200_JOIN_STATUS_JOINING; | ||
1336 | queue_delayed_work(priv->workqueue, | ||
1337 | &priv->join_timeout, | ||
1338 | CW1200_JOIN_TIMEOUT); | ||
1339 | } | ||
1340 | |||
1341 | /* 802.11w protected mgmt frames */ | ||
1342 | mgmt_policy.protectedMgmtEnable = 0; | ||
1343 | mgmt_policy.unprotectedMgmtFramesAllowed = 1; | ||
1344 | mgmt_policy.encryptionForAuthFrame = 1; | ||
1345 | wsm_set_protected_mgmt_policy(priv, &mgmt_policy); | ||
1346 | |||
1347 | /* Perform actual join */ | ||
1348 | if (wsm_join(priv, &join)) { | ||
1349 | pr_err("[STA] cw1200_join_work: wsm_join failed!\n"); | ||
1350 | cancel_delayed_work_sync(&priv->join_timeout); | ||
1351 | cw1200_update_listening(priv, priv->listening); | ||
1352 | /* Tx lock still held, unjoin will clear it. */ | ||
1353 | if (queue_work(priv->workqueue, &priv->unjoin_work) <= 0) | ||
1354 | wsm_unlock_tx(priv); | ||
1355 | } else { | ||
1356 | if (!(join.flags & WSM_JOIN_FLAGS_FORCE_WITH_COMPLETE_IND)) | ||
1357 | cw1200_join_complete(priv); /* Will clear tx_lock */ | ||
1358 | |||
1359 | /* Upload keys */ | ||
1360 | cw1200_upload_keys(priv); | ||
1361 | |||
1362 | /* Due to beacon filtering it is possible that the | ||
1363 | * AP's beacon is not known for the mac80211 stack. | ||
1364 | * Disable filtering temporary to make sure the stack | ||
1365 | * receives at least one | ||
1366 | */ | ||
1367 | priv->disable_beacon_filter = true; | ||
1368 | } | ||
1369 | cw1200_update_filtering(priv); | ||
1370 | |||
1371 | done_put: | ||
1372 | mutex_unlock(&priv->conf_mutex); | ||
1373 | if (bss) | ||
1374 | cfg80211_put_bss(priv->hw->wiphy, bss); | ||
1375 | } | ||
1376 | |||
1377 | void cw1200_join_timeout(struct work_struct *work) | ||
1378 | { | ||
1379 | struct cw1200_common *priv = | ||
1380 | container_of(work, struct cw1200_common, join_timeout.work); | ||
1381 | pr_debug("[WSM] Join timed out.\n"); | ||
1382 | wsm_lock_tx(priv); | ||
1383 | if (queue_work(priv->workqueue, &priv->unjoin_work) <= 0) | ||
1384 | wsm_unlock_tx(priv); | ||
1385 | } | ||
1386 | |||
1387 | static void cw1200_do_unjoin(struct cw1200_common *priv) | ||
1388 | { | ||
1389 | struct wsm_reset reset = { | ||
1390 | .reset_statistics = true, | ||
1391 | }; | ||
1392 | |||
1393 | cancel_delayed_work_sync(&priv->join_timeout); | ||
1394 | |||
1395 | mutex_lock(&priv->conf_mutex); | ||
1396 | priv->join_pending = false; | ||
1397 | |||
1398 | if (atomic_read(&priv->scan.in_progress)) { | ||
1399 | if (priv->delayed_unjoin) | ||
1400 | wiphy_dbg(priv->hw->wiphy, "Delayed unjoin is already scheduled.\n"); | ||
1401 | else | ||
1402 | priv->delayed_unjoin = true; | ||
1403 | goto done; | ||
1404 | } | ||
1405 | |||
1406 | priv->delayed_link_loss = false; | ||
1407 | |||
1408 | if (!priv->join_status) | ||
1409 | goto done; | ||
1410 | |||
1411 | if (priv->join_status > CW1200_JOIN_STATUS_IBSS) { | ||
1412 | wiphy_err(priv->hw->wiphy, "Unexpected: join status: %d\n", | ||
1413 | priv->join_status); | ||
1414 | BUG_ON(1); | ||
1415 | } | ||
1416 | |||
1417 | cancel_work_sync(&priv->update_filtering_work); | ||
1418 | cancel_work_sync(&priv->set_beacon_wakeup_period_work); | ||
1419 | priv->join_status = CW1200_JOIN_STATUS_PASSIVE; | ||
1420 | |||
1421 | /* Unjoin is a reset. */ | ||
1422 | wsm_flush_tx(priv); | ||
1423 | wsm_keep_alive_period(priv, 0); | ||
1424 | wsm_reset(priv, &reset); | ||
1425 | wsm_set_output_power(priv, priv->output_power * 10); | ||
1426 | priv->join_dtim_period = 0; | ||
1427 | cw1200_setup_mac(priv); | ||
1428 | cw1200_free_event_queue(priv); | ||
1429 | cancel_work_sync(&priv->event_handler); | ||
1430 | cw1200_update_listening(priv, priv->listening); | ||
1431 | cw1200_cqm_bssloss_sm(priv, 0, 0, 0); | ||
1432 | |||
1433 | /* Disable Block ACKs */ | ||
1434 | wsm_set_block_ack_policy(priv, 0, 0); | ||
1435 | |||
1436 | priv->disable_beacon_filter = false; | ||
1437 | cw1200_update_filtering(priv); | ||
1438 | memset(&priv->association_mode, 0, | ||
1439 | sizeof(priv->association_mode)); | ||
1440 | memset(&priv->bss_params, 0, sizeof(priv->bss_params)); | ||
1441 | priv->setbssparams_done = false; | ||
1442 | memset(&priv->firmware_ps_mode, 0, | ||
1443 | sizeof(priv->firmware_ps_mode)); | ||
1444 | |||
1445 | pr_debug("[STA] Unjoin completed.\n"); | ||
1446 | |||
1447 | done: | ||
1448 | mutex_unlock(&priv->conf_mutex); | ||
1449 | } | ||
1450 | |||
1451 | void cw1200_unjoin_work(struct work_struct *work) | ||
1452 | { | ||
1453 | struct cw1200_common *priv = | ||
1454 | container_of(work, struct cw1200_common, unjoin_work); | ||
1455 | |||
1456 | cw1200_do_unjoin(priv); | ||
1457 | |||
1458 | /* Tell the stack we're dead */ | ||
1459 | ieee80211_connection_loss(priv->vif); | ||
1460 | |||
1461 | wsm_unlock_tx(priv); | ||
1462 | } | ||
1463 | |||
1464 | int cw1200_enable_listening(struct cw1200_common *priv) | ||
1465 | { | ||
1466 | struct wsm_start start = { | ||
1467 | .mode = WSM_START_MODE_P2P_DEV, | ||
1468 | .band = WSM_PHY_BAND_2_4G, | ||
1469 | .beacon_interval = 100, | ||
1470 | .dtim_period = 1, | ||
1471 | .probe_delay = 0, | ||
1472 | .basic_rate_set = 0x0F, | ||
1473 | }; | ||
1474 | |||
1475 | if (priv->channel) { | ||
1476 | start.band = priv->channel->band == IEEE80211_BAND_5GHZ ? | ||
1477 | WSM_PHY_BAND_5G : WSM_PHY_BAND_2_4G; | ||
1478 | start.channel_number = priv->channel->hw_value; | ||
1479 | } else { | ||
1480 | start.band = WSM_PHY_BAND_2_4G; | ||
1481 | start.channel_number = 1; | ||
1482 | } | ||
1483 | |||
1484 | return wsm_start(priv, &start); | ||
1485 | } | ||
1486 | |||
1487 | int cw1200_disable_listening(struct cw1200_common *priv) | ||
1488 | { | ||
1489 | int ret; | ||
1490 | struct wsm_reset reset = { | ||
1491 | .reset_statistics = true, | ||
1492 | }; | ||
1493 | ret = wsm_reset(priv, &reset); | ||
1494 | return ret; | ||
1495 | } | ||
1496 | |||
1497 | void cw1200_update_listening(struct cw1200_common *priv, bool enabled) | ||
1498 | { | ||
1499 | if (enabled) { | ||
1500 | if (priv->join_status == CW1200_JOIN_STATUS_PASSIVE) { | ||
1501 | if (!cw1200_enable_listening(priv)) | ||
1502 | priv->join_status = CW1200_JOIN_STATUS_MONITOR; | ||
1503 | wsm_set_probe_responder(priv, true); | ||
1504 | } | ||
1505 | } else { | ||
1506 | if (priv->join_status == CW1200_JOIN_STATUS_MONITOR) { | ||
1507 | if (!cw1200_disable_listening(priv)) | ||
1508 | priv->join_status = CW1200_JOIN_STATUS_PASSIVE; | ||
1509 | wsm_set_probe_responder(priv, false); | ||
1510 | } | ||
1511 | } | ||
1512 | } | ||
1513 | |||
1514 | int cw1200_set_uapsd_param(struct cw1200_common *priv, | ||
1515 | const struct wsm_edca_params *arg) | ||
1516 | { | ||
1517 | int ret; | ||
1518 | u16 uapsd_flags = 0; | ||
1519 | |||
1520 | /* Here's the mapping AC [queue, bit] | ||
1521 | * VO [0,3], VI [1, 2], BE [2, 1], BK [3, 0] | ||
1522 | */ | ||
1523 | |||
1524 | if (arg->uapsd_enable[0]) | ||
1525 | uapsd_flags |= 1 << 3; | ||
1526 | |||
1527 | if (arg->uapsd_enable[1]) | ||
1528 | uapsd_flags |= 1 << 2; | ||
1529 | |||
1530 | if (arg->uapsd_enable[2]) | ||
1531 | uapsd_flags |= 1 << 1; | ||
1532 | |||
1533 | if (arg->uapsd_enable[3]) | ||
1534 | uapsd_flags |= 1; | ||
1535 | |||
1536 | /* Currently pseudo U-APSD operation is not supported, so setting | ||
1537 | * MinAutoTriggerInterval, MaxAutoTriggerInterval and | ||
1538 | * AutoTriggerStep to 0 | ||
1539 | */ | ||
1540 | |||
1541 | priv->uapsd_info.uapsd_flags = cpu_to_le16(uapsd_flags); | ||
1542 | priv->uapsd_info.min_auto_trigger_interval = 0; | ||
1543 | priv->uapsd_info.max_auto_trigger_interval = 0; | ||
1544 | priv->uapsd_info.auto_trigger_step = 0; | ||
1545 | |||
1546 | ret = wsm_set_uapsd_info(priv, &priv->uapsd_info); | ||
1547 | return ret; | ||
1548 | } | ||
1549 | |||
1550 | /* ******************************************************************** */ | ||
1551 | /* AP API */ | ||
1552 | |||
1553 | int cw1200_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, | ||
1554 | struct ieee80211_sta *sta) | ||
1555 | { | ||
1556 | struct cw1200_common *priv = hw->priv; | ||
1557 | struct cw1200_sta_priv *sta_priv = | ||
1558 | (struct cw1200_sta_priv *)&sta->drv_priv; | ||
1559 | struct cw1200_link_entry *entry; | ||
1560 | struct sk_buff *skb; | ||
1561 | |||
1562 | if (priv->mode != NL80211_IFTYPE_AP) | ||
1563 | return 0; | ||
1564 | |||
1565 | sta_priv->link_id = cw1200_find_link_id(priv, sta->addr); | ||
1566 | if (WARN_ON(!sta_priv->link_id)) { | ||
1567 | wiphy_info(priv->hw->wiphy, | ||
1568 | "[AP] No more link IDs available.\n"); | ||
1569 | return -ENOENT; | ||
1570 | } | ||
1571 | |||
1572 | entry = &priv->link_id_db[sta_priv->link_id - 1]; | ||
1573 | spin_lock_bh(&priv->ps_state_lock); | ||
1574 | if ((sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) == | ||
1575 | IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | ||
1576 | priv->sta_asleep_mask |= BIT(sta_priv->link_id); | ||
1577 | entry->status = CW1200_LINK_HARD; | ||
1578 | while ((skb = skb_dequeue(&entry->rx_queue))) | ||
1579 | ieee80211_rx_irqsafe(priv->hw, skb); | ||
1580 | spin_unlock_bh(&priv->ps_state_lock); | ||
1581 | return 0; | ||
1582 | } | ||
1583 | |||
1584 | int cw1200_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, | ||
1585 | struct ieee80211_sta *sta) | ||
1586 | { | ||
1587 | struct cw1200_common *priv = hw->priv; | ||
1588 | struct cw1200_sta_priv *sta_priv = | ||
1589 | (struct cw1200_sta_priv *)&sta->drv_priv; | ||
1590 | struct cw1200_link_entry *entry; | ||
1591 | |||
1592 | if (priv->mode != NL80211_IFTYPE_AP || !sta_priv->link_id) | ||
1593 | return 0; | ||
1594 | |||
1595 | entry = &priv->link_id_db[sta_priv->link_id - 1]; | ||
1596 | spin_lock_bh(&priv->ps_state_lock); | ||
1597 | entry->status = CW1200_LINK_RESERVE; | ||
1598 | entry->timestamp = jiffies; | ||
1599 | wsm_lock_tx_async(priv); | ||
1600 | if (queue_work(priv->workqueue, &priv->link_id_work) <= 0) | ||
1601 | wsm_unlock_tx(priv); | ||
1602 | spin_unlock_bh(&priv->ps_state_lock); | ||
1603 | flush_workqueue(priv->workqueue); | ||
1604 | return 0; | ||
1605 | } | ||
1606 | |||
1607 | static void __cw1200_sta_notify(struct ieee80211_hw *dev, | ||
1608 | struct ieee80211_vif *vif, | ||
1609 | enum sta_notify_cmd notify_cmd, | ||
1610 | int link_id) | ||
1611 | { | ||
1612 | struct cw1200_common *priv = dev->priv; | ||
1613 | u32 bit, prev; | ||
1614 | |||
1615 | /* Zero link id means "for all link IDs" */ | ||
1616 | if (link_id) | ||
1617 | bit = BIT(link_id); | ||
1618 | else if (WARN_ON_ONCE(notify_cmd != STA_NOTIFY_AWAKE)) | ||
1619 | bit = 0; | ||
1620 | else | ||
1621 | bit = priv->link_id_map; | ||
1622 | prev = priv->sta_asleep_mask & bit; | ||
1623 | |||
1624 | switch (notify_cmd) { | ||
1625 | case STA_NOTIFY_SLEEP: | ||
1626 | if (!prev) { | ||
1627 | if (priv->buffered_multicasts && | ||
1628 | !priv->sta_asleep_mask) | ||
1629 | queue_work(priv->workqueue, | ||
1630 | &priv->multicast_start_work); | ||
1631 | priv->sta_asleep_mask |= bit; | ||
1632 | } | ||
1633 | break; | ||
1634 | case STA_NOTIFY_AWAKE: | ||
1635 | if (prev) { | ||
1636 | priv->sta_asleep_mask &= ~bit; | ||
1637 | priv->pspoll_mask &= ~bit; | ||
1638 | if (priv->tx_multicast && link_id && | ||
1639 | !priv->sta_asleep_mask) | ||
1640 | queue_work(priv->workqueue, | ||
1641 | &priv->multicast_stop_work); | ||
1642 | cw1200_bh_wakeup(priv); | ||
1643 | } | ||
1644 | break; | ||
1645 | } | ||
1646 | } | ||
1647 | |||
1648 | void cw1200_sta_notify(struct ieee80211_hw *dev, | ||
1649 | struct ieee80211_vif *vif, | ||
1650 | enum sta_notify_cmd notify_cmd, | ||
1651 | struct ieee80211_sta *sta) | ||
1652 | { | ||
1653 | struct cw1200_common *priv = dev->priv; | ||
1654 | struct cw1200_sta_priv *sta_priv = | ||
1655 | (struct cw1200_sta_priv *)&sta->drv_priv; | ||
1656 | |||
1657 | spin_lock_bh(&priv->ps_state_lock); | ||
1658 | __cw1200_sta_notify(dev, vif, notify_cmd, sta_priv->link_id); | ||
1659 | spin_unlock_bh(&priv->ps_state_lock); | ||
1660 | } | ||
1661 | |||
1662 | static void cw1200_ps_notify(struct cw1200_common *priv, | ||
1663 | int link_id, bool ps) | ||
1664 | { | ||
1665 | if (link_id > CW1200_MAX_STA_IN_AP_MODE) | ||
1666 | return; | ||
1667 | |||
1668 | pr_debug("%s for LinkId: %d. STAs asleep: %.8X\n", | ||
1669 | ps ? "Stop" : "Start", | ||
1670 | link_id, priv->sta_asleep_mask); | ||
1671 | |||
1672 | __cw1200_sta_notify(priv->hw, priv->vif, | ||
1673 | ps ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE, link_id); | ||
1674 | } | ||
1675 | |||
1676 | static int cw1200_set_tim_impl(struct cw1200_common *priv, bool aid0_bit_set) | ||
1677 | { | ||
1678 | struct sk_buff *skb; | ||
1679 | struct wsm_update_ie update_ie = { | ||
1680 | .what = WSM_UPDATE_IE_BEACON, | ||
1681 | .count = 1, | ||
1682 | }; | ||
1683 | u16 tim_offset, tim_length; | ||
1684 | |||
1685 | pr_debug("[AP] mcast: %s.\n", aid0_bit_set ? "ena" : "dis"); | ||
1686 | |||
1687 | skb = ieee80211_beacon_get_tim(priv->hw, priv->vif, | ||
1688 | &tim_offset, &tim_length); | ||
1689 | if (!skb) { | ||
1690 | if (!__cw1200_flush(priv, true)) | ||
1691 | wsm_unlock_tx(priv); | ||
1692 | return -ENOENT; | ||
1693 | } | ||
1694 | |||
1695 | if (tim_offset && tim_length >= 6) { | ||
1696 | /* Ignore DTIM count from mac80211: | ||
1697 | * firmware handles DTIM internally. | ||
1698 | */ | ||
1699 | skb->data[tim_offset + 2] = 0; | ||
1700 | |||
1701 | /* Set/reset aid0 bit */ | ||
1702 | if (aid0_bit_set) | ||
1703 | skb->data[tim_offset + 4] |= 1; | ||
1704 | else | ||
1705 | skb->data[tim_offset + 4] &= ~1; | ||
1706 | } | ||
1707 | |||
1708 | update_ie.ies = &skb->data[tim_offset]; | ||
1709 | update_ie.length = tim_length; | ||
1710 | wsm_update_ie(priv, &update_ie); | ||
1711 | |||
1712 | dev_kfree_skb(skb); | ||
1713 | |||
1714 | return 0; | ||
1715 | } | ||
1716 | |||
1717 | void cw1200_set_tim_work(struct work_struct *work) | ||
1718 | { | ||
1719 | struct cw1200_common *priv = | ||
1720 | container_of(work, struct cw1200_common, set_tim_work); | ||
1721 | (void)cw1200_set_tim_impl(priv, priv->aid0_bit_set); | ||
1722 | } | ||
1723 | |||
1724 | int cw1200_set_tim(struct ieee80211_hw *dev, struct ieee80211_sta *sta, | ||
1725 | bool set) | ||
1726 | { | ||
1727 | struct cw1200_common *priv = dev->priv; | ||
1728 | queue_work(priv->workqueue, &priv->set_tim_work); | ||
1729 | return 0; | ||
1730 | } | ||
1731 | |||
1732 | void cw1200_set_cts_work(struct work_struct *work) | ||
1733 | { | ||
1734 | struct cw1200_common *priv = | ||
1735 | container_of(work, struct cw1200_common, set_cts_work); | ||
1736 | |||
1737 | u8 erp_ie[3] = {WLAN_EID_ERP_INFO, 0x1, 0}; | ||
1738 | struct wsm_update_ie update_ie = { | ||
1739 | .what = WSM_UPDATE_IE_BEACON, | ||
1740 | .count = 1, | ||
1741 | .ies = erp_ie, | ||
1742 | .length = 3, | ||
1743 | }; | ||
1744 | u32 erp_info; | ||
1745 | __le32 use_cts_prot; | ||
1746 | mutex_lock(&priv->conf_mutex); | ||
1747 | erp_info = priv->erp_info; | ||
1748 | mutex_unlock(&priv->conf_mutex); | ||
1749 | use_cts_prot = | ||
1750 | erp_info & WLAN_ERP_USE_PROTECTION ? | ||
1751 | __cpu_to_le32(1) : 0; | ||
1752 | |||
1753 | erp_ie[ERP_INFO_BYTE_OFFSET] = erp_info; | ||
1754 | |||
1755 | pr_debug("[STA] ERP information 0x%x\n", erp_info); | ||
1756 | |||
1757 | wsm_write_mib(priv, WSM_MIB_ID_NON_ERP_PROTECTION, | ||
1758 | &use_cts_prot, sizeof(use_cts_prot)); | ||
1759 | wsm_update_ie(priv, &update_ie); | ||
1760 | |||
1761 | return; | ||
1762 | } | ||
1763 | |||
1764 | static int cw1200_set_btcoexinfo(struct cw1200_common *priv) | ||
1765 | { | ||
1766 | struct wsm_override_internal_txrate arg; | ||
1767 | int ret = 0; | ||
1768 | |||
1769 | if (priv->mode == NL80211_IFTYPE_STATION) { | ||
1770 | /* Plumb PSPOLL and NULL template */ | ||
1771 | cw1200_upload_pspoll(priv); | ||
1772 | cw1200_upload_null(priv); | ||
1773 | cw1200_upload_qosnull(priv); | ||
1774 | } else { | ||
1775 | return 0; | ||
1776 | } | ||
1777 | |||
1778 | memset(&arg, 0, sizeof(struct wsm_override_internal_txrate)); | ||
1779 | |||
1780 | if (!priv->vif->p2p) { | ||
1781 | /* STATION mode */ | ||
1782 | if (priv->bss_params.operational_rate_set & ~0xF) { | ||
1783 | pr_debug("[STA] STA has ERP rates\n"); | ||
1784 | /* G or BG mode */ | ||
1785 | arg.internalTxRate = (__ffs( | ||
1786 | priv->bss_params.operational_rate_set & ~0xF)); | ||
1787 | } else { | ||
1788 | pr_debug("[STA] STA has non ERP rates\n"); | ||
1789 | /* B only mode */ | ||
1790 | arg.internalTxRate = (__ffs(priv->association_mode.basic_rate_set)); | ||
1791 | } | ||
1792 | arg.nonErpInternalTxRate = (__ffs(priv->association_mode.basic_rate_set)); | ||
1793 | } else { | ||
1794 | /* P2P mode */ | ||
1795 | arg.internalTxRate = (__ffs(priv->bss_params.operational_rate_set & ~0xF)); | ||
1796 | arg.nonErpInternalTxRate = (__ffs(priv->bss_params.operational_rate_set & ~0xF)); | ||
1797 | } | ||
1798 | |||
1799 | pr_debug("[STA] BTCOEX_INFO MODE %d, internalTxRate : %x, nonErpInternalTxRate: %x\n", | ||
1800 | priv->mode, | ||
1801 | arg.internalTxRate, | ||
1802 | arg.nonErpInternalTxRate); | ||
1803 | |||
1804 | ret = wsm_write_mib(priv, WSM_MIB_ID_OVERRIDE_INTERNAL_TX_RATE, | ||
1805 | &arg, sizeof(arg)); | ||
1806 | |||
1807 | return ret; | ||
1808 | } | ||
1809 | |||
1810 | void cw1200_bss_info_changed(struct ieee80211_hw *dev, | ||
1811 | struct ieee80211_vif *vif, | ||
1812 | struct ieee80211_bss_conf *info, | ||
1813 | u32 changed) | ||
1814 | { | ||
1815 | struct cw1200_common *priv = dev->priv; | ||
1816 | bool do_join = false; | ||
1817 | |||
1818 | mutex_lock(&priv->conf_mutex); | ||
1819 | |||
1820 | pr_debug("BSS CHANGED: %08x\n", changed); | ||
1821 | |||
1822 | /* TODO: BSS_CHANGED_QOS */ | ||
1823 | /* TODO: BSS_CHANGED_TXPOWER */ | ||
1824 | |||
1825 | if (changed & BSS_CHANGED_ARP_FILTER) { | ||
1826 | struct wsm_mib_arp_ipv4_filter filter = {0}; | ||
1827 | int i; | ||
1828 | |||
1829 | pr_debug("[STA] BSS_CHANGED_ARP_FILTER cnt: %d\n", | ||
1830 | info->arp_addr_cnt); | ||
1831 | |||
1832 | /* Currently only one IP address is supported by firmware. | ||
1833 | * In case of more IPs arp filtering will be disabled. | ||
1834 | */ | ||
1835 | if (info->arp_addr_cnt > 0 && | ||
1836 | info->arp_addr_cnt <= WSM_MAX_ARP_IP_ADDRTABLE_ENTRIES) { | ||
1837 | for (i = 0; i < info->arp_addr_cnt; i++) { | ||
1838 | filter.ipv4addrs[i] = info->arp_addr_list[i]; | ||
1839 | pr_debug("[STA] addr[%d]: 0x%X\n", | ||
1840 | i, filter.ipv4addrs[i]); | ||
1841 | } | ||
1842 | filter.enable = __cpu_to_le32(1); | ||
1843 | } | ||
1844 | |||
1845 | pr_debug("[STA] arp ip filter enable: %d\n", | ||
1846 | __le32_to_cpu(filter.enable)); | ||
1847 | |||
1848 | wsm_set_arp_ipv4_filter(priv, &filter); | ||
1849 | } | ||
1850 | |||
1851 | if (changed & | ||
1852 | (BSS_CHANGED_BEACON | | ||
1853 | BSS_CHANGED_AP_PROBE_RESP | | ||
1854 | BSS_CHANGED_BSSID | | ||
1855 | BSS_CHANGED_SSID | | ||
1856 | BSS_CHANGED_IBSS)) { | ||
1857 | pr_debug("BSS_CHANGED_BEACON\n"); | ||
1858 | priv->beacon_int = info->beacon_int; | ||
1859 | cw1200_update_beaconing(priv); | ||
1860 | cw1200_upload_beacon(priv); | ||
1861 | } | ||
1862 | |||
1863 | if (changed & BSS_CHANGED_BEACON_ENABLED) { | ||
1864 | pr_debug("BSS_CHANGED_BEACON_ENABLED (%d)\n", info->enable_beacon); | ||
1865 | |||
1866 | if (priv->enable_beacon != info->enable_beacon) { | ||
1867 | cw1200_enable_beaconing(priv, info->enable_beacon); | ||
1868 | priv->enable_beacon = info->enable_beacon; | ||
1869 | } | ||
1870 | } | ||
1871 | |||
1872 | if (changed & BSS_CHANGED_BEACON_INT) { | ||
1873 | pr_debug("CHANGED_BEACON_INT\n"); | ||
1874 | if (info->ibss_joined) | ||
1875 | do_join = true; | ||
1876 | else if (priv->join_status == CW1200_JOIN_STATUS_AP) | ||
1877 | cw1200_update_beaconing(priv); | ||
1878 | } | ||
1879 | |||
1880 | /* assoc/disassoc, or maybe AID changed */ | ||
1881 | if (changed & BSS_CHANGED_ASSOC) { | ||
1882 | wsm_lock_tx(priv); | ||
1883 | priv->wep_default_key_id = -1; | ||
1884 | wsm_unlock_tx(priv); | ||
1885 | } | ||
1886 | |||
1887 | if (changed & BSS_CHANGED_BSSID) { | ||
1888 | pr_debug("BSS_CHANGED_BSSID\n"); | ||
1889 | do_join = true; | ||
1890 | } | ||
1891 | |||
1892 | if (changed & | ||
1893 | (BSS_CHANGED_ASSOC | | ||
1894 | BSS_CHANGED_BSSID | | ||
1895 | BSS_CHANGED_IBSS | | ||
1896 | BSS_CHANGED_BASIC_RATES | | ||
1897 | BSS_CHANGED_HT)) { | ||
1898 | pr_debug("BSS_CHANGED_ASSOC\n"); | ||
1899 | if (info->assoc) { | ||
1900 | if (priv->join_status < CW1200_JOIN_STATUS_PRE_STA) { | ||
1901 | ieee80211_connection_loss(vif); | ||
1902 | mutex_unlock(&priv->conf_mutex); | ||
1903 | return; | ||
1904 | } else if (priv->join_status == CW1200_JOIN_STATUS_PRE_STA) { | ||
1905 | priv->join_status = CW1200_JOIN_STATUS_STA; | ||
1906 | } | ||
1907 | } else { | ||
1908 | do_join = true; | ||
1909 | } | ||
1910 | |||
1911 | if (info->assoc || info->ibss_joined) { | ||
1912 | struct ieee80211_sta *sta = NULL; | ||
1913 | u32 val = 0; | ||
1914 | |||
1915 | if (info->dtim_period) | ||
1916 | priv->join_dtim_period = info->dtim_period; | ||
1917 | priv->beacon_int = info->beacon_int; | ||
1918 | |||
1919 | rcu_read_lock(); | ||
1920 | |||
1921 | if (info->bssid && !info->ibss_joined) | ||
1922 | sta = ieee80211_find_sta(vif, info->bssid); | ||
1923 | if (sta) { | ||
1924 | priv->ht_info.ht_cap = sta->ht_cap; | ||
1925 | priv->bss_params.operational_rate_set = | ||
1926 | cw1200_rate_mask_to_wsm(priv, | ||
1927 | sta->supp_rates[priv->channel->band]); | ||
1928 | priv->ht_info.channel_type = cfg80211_get_chandef_type(&dev->conf.chandef); | ||
1929 | priv->ht_info.operation_mode = info->ht_operation_mode; | ||
1930 | } else { | ||
1931 | memset(&priv->ht_info, 0, | ||
1932 | sizeof(priv->ht_info)); | ||
1933 | priv->bss_params.operational_rate_set = -1; | ||
1934 | } | ||
1935 | rcu_read_unlock(); | ||
1936 | |||
1937 | /* Non Greenfield stations present */ | ||
1938 | if (priv->ht_info.operation_mode & | ||
1939 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) | ||
1940 | val |= WSM_NON_GREENFIELD_STA_PRESENT; | ||
1941 | |||
1942 | /* Set HT protection method */ | ||
1943 | val |= (priv->ht_info.operation_mode & IEEE80211_HT_OP_MODE_PROTECTION) << 2; | ||
1944 | |||
1945 | /* TODO: | ||
1946 | * STBC_param.dual_cts | ||
1947 | * STBC_param.LSIG_TXOP_FILL | ||
1948 | */ | ||
1949 | |||
1950 | val = cpu_to_le32(val); | ||
1951 | wsm_write_mib(priv, WSM_MIB_ID_SET_HT_PROTECTION, | ||
1952 | &val, sizeof(val)); | ||
1953 | |||
1954 | priv->association_mode.greenfield = | ||
1955 | cw1200_ht_greenfield(&priv->ht_info); | ||
1956 | priv->association_mode.flags = | ||
1957 | WSM_ASSOCIATION_MODE_SNOOP_ASSOC_FRAMES | | ||
1958 | WSM_ASSOCIATION_MODE_USE_PREAMBLE_TYPE | | ||
1959 | WSM_ASSOCIATION_MODE_USE_HT_MODE | | ||
1960 | WSM_ASSOCIATION_MODE_USE_BASIC_RATE_SET | | ||
1961 | WSM_ASSOCIATION_MODE_USE_MPDU_START_SPACING; | ||
1962 | priv->association_mode.preamble = | ||
1963 | info->use_short_preamble ? | ||
1964 | WSM_JOIN_PREAMBLE_SHORT : | ||
1965 | WSM_JOIN_PREAMBLE_LONG; | ||
1966 | priv->association_mode.basic_rate_set = __cpu_to_le32( | ||
1967 | cw1200_rate_mask_to_wsm(priv, | ||
1968 | info->basic_rates)); | ||
1969 | priv->association_mode.mpdu_start_spacing = | ||
1970 | cw1200_ht_ampdu_density(&priv->ht_info); | ||
1971 | |||
1972 | cw1200_cqm_bssloss_sm(priv, 0, 0, 0); | ||
1973 | cancel_work_sync(&priv->unjoin_work); | ||
1974 | |||
1975 | priv->bss_params.beacon_lost_count = priv->cqm_beacon_loss_count; | ||
1976 | priv->bss_params.aid = info->aid; | ||
1977 | |||
1978 | if (priv->join_dtim_period < 1) | ||
1979 | priv->join_dtim_period = 1; | ||
1980 | |||
1981 | pr_debug("[STA] DTIM %d, interval: %d\n", | ||
1982 | priv->join_dtim_period, priv->beacon_int); | ||
1983 | pr_debug("[STA] Preamble: %d, Greenfield: %d, Aid: %d, Rates: 0x%.8X, Basic: 0x%.8X\n", | ||
1984 | priv->association_mode.preamble, | ||
1985 | priv->association_mode.greenfield, | ||
1986 | priv->bss_params.aid, | ||
1987 | priv->bss_params.operational_rate_set, | ||
1988 | priv->association_mode.basic_rate_set); | ||
1989 | wsm_set_association_mode(priv, &priv->association_mode); | ||
1990 | |||
1991 | if (!info->ibss_joined) { | ||
1992 | wsm_keep_alive_period(priv, 30 /* sec */); | ||
1993 | wsm_set_bss_params(priv, &priv->bss_params); | ||
1994 | priv->setbssparams_done = true; | ||
1995 | cw1200_set_beacon_wakeup_period_work(&priv->set_beacon_wakeup_period_work); | ||
1996 | cw1200_set_pm(priv, &priv->powersave_mode); | ||
1997 | } | ||
1998 | if (priv->vif->p2p) { | ||
1999 | pr_debug("[STA] Setting p2p powersave configuration.\n"); | ||
2000 | wsm_set_p2p_ps_modeinfo(priv, | ||
2001 | &priv->p2p_ps_modeinfo); | ||
2002 | } | ||
2003 | if (priv->bt_present) | ||
2004 | cw1200_set_btcoexinfo(priv); | ||
2005 | } else { | ||
2006 | memset(&priv->association_mode, 0, | ||
2007 | sizeof(priv->association_mode)); | ||
2008 | memset(&priv->bss_params, 0, sizeof(priv->bss_params)); | ||
2009 | } | ||
2010 | } | ||
2011 | |||
2012 | /* ERP Protection */ | ||
2013 | if (changed & (BSS_CHANGED_ASSOC | | ||
2014 | BSS_CHANGED_ERP_CTS_PROT | | ||
2015 | BSS_CHANGED_ERP_PREAMBLE)) { | ||
2016 | u32 prev_erp_info = priv->erp_info; | ||
2017 | if (info->use_cts_prot) | ||
2018 | priv->erp_info |= WLAN_ERP_USE_PROTECTION; | ||
2019 | else if (!(prev_erp_info & WLAN_ERP_NON_ERP_PRESENT)) | ||
2020 | priv->erp_info &= ~WLAN_ERP_USE_PROTECTION; | ||
2021 | |||
2022 | if (info->use_short_preamble) | ||
2023 | priv->erp_info |= WLAN_ERP_BARKER_PREAMBLE; | ||
2024 | else | ||
2025 | priv->erp_info &= ~WLAN_ERP_BARKER_PREAMBLE; | ||
2026 | |||
2027 | pr_debug("[STA] ERP Protection: %x\n", priv->erp_info); | ||
2028 | |||
2029 | if (prev_erp_info != priv->erp_info) | ||
2030 | queue_work(priv->workqueue, &priv->set_cts_work); | ||
2031 | } | ||
2032 | |||
2033 | /* ERP Slottime */ | ||
2034 | if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_SLOT)) { | ||
2035 | __le32 slot_time = info->use_short_slot ? | ||
2036 | __cpu_to_le32(9) : __cpu_to_le32(20); | ||
2037 | pr_debug("[STA] Slot time: %d us.\n", | ||
2038 | __le32_to_cpu(slot_time)); | ||
2039 | wsm_write_mib(priv, WSM_MIB_ID_DOT11_SLOT_TIME, | ||
2040 | &slot_time, sizeof(slot_time)); | ||
2041 | } | ||
2042 | |||
2043 | if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_CQM)) { | ||
2044 | struct wsm_rcpi_rssi_threshold threshold = { | ||
2045 | .rollingAverageCount = 8, | ||
2046 | }; | ||
2047 | pr_debug("[CQM] RSSI threshold subscribe: %d +- %d\n", | ||
2048 | info->cqm_rssi_thold, info->cqm_rssi_hyst); | ||
2049 | priv->cqm_rssi_thold = info->cqm_rssi_thold; | ||
2050 | priv->cqm_rssi_hyst = info->cqm_rssi_hyst; | ||
2051 | |||
2052 | if (info->cqm_rssi_thold || info->cqm_rssi_hyst) { | ||
2053 | /* RSSI subscription enabled */ | ||
2054 | /* TODO: It's not a correct way of setting threshold. | ||
2055 | * Upper and lower must be set equal here and adjusted | ||
2056 | * in callback. However current implementation is much | ||
2057 | * more relaible and stable. | ||
2058 | */ | ||
2059 | |||
2060 | /* RSSI: signed Q8.0, RCPI: unsigned Q7.1 | ||
2061 | * RSSI = RCPI / 2 - 110 | ||
2062 | */ | ||
2063 | if (priv->cqm_use_rssi) { | ||
2064 | threshold.upperThreshold = | ||
2065 | info->cqm_rssi_thold + info->cqm_rssi_hyst; | ||
2066 | threshold.lowerThreshold = | ||
2067 | info->cqm_rssi_thold; | ||
2068 | threshold.rssiRcpiMode |= WSM_RCPI_RSSI_USE_RSSI; | ||
2069 | } else { | ||
2070 | threshold.upperThreshold = (info->cqm_rssi_thold + info->cqm_rssi_hyst + 110) * 2; | ||
2071 | threshold.lowerThreshold = (info->cqm_rssi_thold + 110) * 2; | ||
2072 | } | ||
2073 | threshold.rssiRcpiMode |= WSM_RCPI_RSSI_THRESHOLD_ENABLE; | ||
2074 | } else { | ||
2075 | /* There is a bug in FW, see sta.c. We have to enable | ||
2076 | * dummy subscription to get correct RSSI values. | ||
2077 | */ | ||
2078 | threshold.rssiRcpiMode |= | ||
2079 | WSM_RCPI_RSSI_THRESHOLD_ENABLE | | ||
2080 | WSM_RCPI_RSSI_DONT_USE_UPPER | | ||
2081 | WSM_RCPI_RSSI_DONT_USE_LOWER; | ||
2082 | if (priv->cqm_use_rssi) | ||
2083 | threshold.rssiRcpiMode |= WSM_RCPI_RSSI_USE_RSSI; | ||
2084 | } | ||
2085 | wsm_set_rcpi_rssi_threshold(priv, &threshold); | ||
2086 | } | ||
2087 | mutex_unlock(&priv->conf_mutex); | ||
2088 | |||
2089 | if (do_join) { | ||
2090 | wsm_lock_tx(priv); | ||
2091 | cw1200_do_join(priv); /* Will unlock it for us */ | ||
2092 | } | ||
2093 | } | ||
2094 | |||
2095 | void cw1200_multicast_start_work(struct work_struct *work) | ||
2096 | { | ||
2097 | struct cw1200_common *priv = | ||
2098 | container_of(work, struct cw1200_common, multicast_start_work); | ||
2099 | long tmo = priv->join_dtim_period * | ||
2100 | (priv->beacon_int + 20) * HZ / 1024; | ||
2101 | |||
2102 | cancel_work_sync(&priv->multicast_stop_work); | ||
2103 | |||
2104 | if (!priv->aid0_bit_set) { | ||
2105 | wsm_lock_tx(priv); | ||
2106 | cw1200_set_tim_impl(priv, true); | ||
2107 | priv->aid0_bit_set = true; | ||
2108 | mod_timer(&priv->mcast_timeout, jiffies + tmo); | ||
2109 | wsm_unlock_tx(priv); | ||
2110 | } | ||
2111 | } | ||
2112 | |||
2113 | void cw1200_multicast_stop_work(struct work_struct *work) | ||
2114 | { | ||
2115 | struct cw1200_common *priv = | ||
2116 | container_of(work, struct cw1200_common, multicast_stop_work); | ||
2117 | |||
2118 | if (priv->aid0_bit_set) { | ||
2119 | del_timer_sync(&priv->mcast_timeout); | ||
2120 | wsm_lock_tx(priv); | ||
2121 | priv->aid0_bit_set = false; | ||
2122 | cw1200_set_tim_impl(priv, false); | ||
2123 | wsm_unlock_tx(priv); | ||
2124 | } | ||
2125 | } | ||
2126 | |||
2127 | void cw1200_mcast_timeout(unsigned long arg) | ||
2128 | { | ||
2129 | struct cw1200_common *priv = | ||
2130 | (struct cw1200_common *)arg; | ||
2131 | |||
2132 | wiphy_warn(priv->hw->wiphy, | ||
2133 | "Multicast delivery timeout.\n"); | ||
2134 | spin_lock_bh(&priv->ps_state_lock); | ||
2135 | priv->tx_multicast = priv->aid0_bit_set && | ||
2136 | priv->buffered_multicasts; | ||
2137 | if (priv->tx_multicast) | ||
2138 | cw1200_bh_wakeup(priv); | ||
2139 | spin_unlock_bh(&priv->ps_state_lock); | ||
2140 | } | ||
2141 | |||
2142 | int cw1200_ampdu_action(struct ieee80211_hw *hw, | ||
2143 | struct ieee80211_vif *vif, | ||
2144 | enum ieee80211_ampdu_mlme_action action, | ||
2145 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, | ||
2146 | u8 buf_size) | ||
2147 | { | ||
2148 | /* Aggregation is implemented fully in firmware, | ||
2149 | * including block ack negotiation. Do not allow | ||
2150 | * mac80211 stack to do anything: it interferes with | ||
2151 | * the firmware. | ||
2152 | */ | ||
2153 | |||
2154 | /* Note that we still need this function stubbed. */ | ||
2155 | return -ENOTSUPP; | ||
2156 | } | ||
2157 | |||
2158 | /* ******************************************************************** */ | ||
2159 | /* WSM callback */ | ||
2160 | void cw1200_suspend_resume(struct cw1200_common *priv, | ||
2161 | struct wsm_suspend_resume *arg) | ||
2162 | { | ||
2163 | pr_debug("[AP] %s: %s\n", | ||
2164 | arg->stop ? "stop" : "start", | ||
2165 | arg->multicast ? "broadcast" : "unicast"); | ||
2166 | |||
2167 | if (arg->multicast) { | ||
2168 | bool cancel_tmo = false; | ||
2169 | spin_lock_bh(&priv->ps_state_lock); | ||
2170 | if (arg->stop) { | ||
2171 | priv->tx_multicast = false; | ||
2172 | } else { | ||
2173 | /* Firmware sends this indication every DTIM if there | ||
2174 | * is a STA in powersave connected. There is no reason | ||
2175 | * to suspend, following wakeup will consume much more | ||
2176 | * power than it could be saved. | ||
2177 | */ | ||
2178 | cw1200_pm_stay_awake(&priv->pm_state, | ||
2179 | priv->join_dtim_period * | ||
2180 | (priv->beacon_int + 20) * HZ / 1024); | ||
2181 | priv->tx_multicast = (priv->aid0_bit_set && | ||
2182 | priv->buffered_multicasts); | ||
2183 | if (priv->tx_multicast) { | ||
2184 | cancel_tmo = true; | ||
2185 | cw1200_bh_wakeup(priv); | ||
2186 | } | ||
2187 | } | ||
2188 | spin_unlock_bh(&priv->ps_state_lock); | ||
2189 | if (cancel_tmo) | ||
2190 | del_timer_sync(&priv->mcast_timeout); | ||
2191 | } else { | ||
2192 | spin_lock_bh(&priv->ps_state_lock); | ||
2193 | cw1200_ps_notify(priv, arg->link_id, arg->stop); | ||
2194 | spin_unlock_bh(&priv->ps_state_lock); | ||
2195 | if (!arg->stop) | ||
2196 | cw1200_bh_wakeup(priv); | ||
2197 | } | ||
2198 | return; | ||
2199 | } | ||
2200 | |||
2201 | /* ******************************************************************** */ | ||
2202 | /* AP privates */ | ||
2203 | |||
2204 | static int cw1200_upload_beacon(struct cw1200_common *priv) | ||
2205 | { | ||
2206 | int ret = 0; | ||
2207 | struct ieee80211_mgmt *mgmt; | ||
2208 | struct wsm_template_frame frame = { | ||
2209 | .frame_type = WSM_FRAME_TYPE_BEACON, | ||
2210 | }; | ||
2211 | |||
2212 | u16 tim_offset; | ||
2213 | u16 tim_len; | ||
2214 | |||
2215 | if (priv->mode == NL80211_IFTYPE_STATION || | ||
2216 | priv->mode == NL80211_IFTYPE_MONITOR || | ||
2217 | priv->mode == NL80211_IFTYPE_UNSPECIFIED) | ||
2218 | goto done; | ||
2219 | |||
2220 | if (priv->vif->p2p) | ||
2221 | frame.rate = WSM_TRANSMIT_RATE_6; | ||
2222 | |||
2223 | frame.skb = ieee80211_beacon_get_tim(priv->hw, priv->vif, | ||
2224 | &tim_offset, &tim_len); | ||
2225 | if (!frame.skb) | ||
2226 | return -ENOMEM; | ||
2227 | |||
2228 | ret = wsm_set_template_frame(priv, &frame); | ||
2229 | |||
2230 | if (ret) | ||
2231 | goto done; | ||
2232 | |||
2233 | /* TODO: Distill probe resp; remove TIM | ||
2234 | * and any other beacon-specific IEs | ||
2235 | */ | ||
2236 | mgmt = (void *)frame.skb->data; | ||
2237 | mgmt->frame_control = | ||
2238 | __cpu_to_le16(IEEE80211_FTYPE_MGMT | | ||
2239 | IEEE80211_STYPE_PROBE_RESP); | ||
2240 | |||
2241 | frame.frame_type = WSM_FRAME_TYPE_PROBE_RESPONSE; | ||
2242 | if (priv->vif->p2p) { | ||
2243 | ret = wsm_set_probe_responder(priv, true); | ||
2244 | } else { | ||
2245 | ret = wsm_set_template_frame(priv, &frame); | ||
2246 | wsm_set_probe_responder(priv, false); | ||
2247 | } | ||
2248 | |||
2249 | done: | ||
2250 | dev_kfree_skb(frame.skb); | ||
2251 | |||
2252 | return ret; | ||
2253 | } | ||
2254 | |||
2255 | static int cw1200_upload_pspoll(struct cw1200_common *priv) | ||
2256 | { | ||
2257 | int ret = 0; | ||
2258 | struct wsm_template_frame frame = { | ||
2259 | .frame_type = WSM_FRAME_TYPE_PS_POLL, | ||
2260 | .rate = 0xFF, | ||
2261 | }; | ||
2262 | |||
2263 | |||
2264 | frame.skb = ieee80211_pspoll_get(priv->hw, priv->vif); | ||
2265 | if (!frame.skb) | ||
2266 | return -ENOMEM; | ||
2267 | |||
2268 | ret = wsm_set_template_frame(priv, &frame); | ||
2269 | |||
2270 | dev_kfree_skb(frame.skb); | ||
2271 | |||
2272 | return ret; | ||
2273 | } | ||
2274 | |||
2275 | static int cw1200_upload_null(struct cw1200_common *priv) | ||
2276 | { | ||
2277 | int ret = 0; | ||
2278 | struct wsm_template_frame frame = { | ||
2279 | .frame_type = WSM_FRAME_TYPE_NULL, | ||
2280 | .rate = 0xFF, | ||
2281 | }; | ||
2282 | |||
2283 | frame.skb = ieee80211_nullfunc_get(priv->hw, priv->vif); | ||
2284 | if (!frame.skb) | ||
2285 | return -ENOMEM; | ||
2286 | |||
2287 | ret = wsm_set_template_frame(priv, &frame); | ||
2288 | |||
2289 | dev_kfree_skb(frame.skb); | ||
2290 | |||
2291 | return ret; | ||
2292 | } | ||
2293 | |||
2294 | static int cw1200_upload_qosnull(struct cw1200_common *priv) | ||
2295 | { | ||
2296 | int ret = 0; | ||
2297 | /* TODO: This needs to be implemented | ||
2298 | |||
2299 | struct wsm_template_frame frame = { | ||
2300 | .frame_type = WSM_FRAME_TYPE_QOS_NULL, | ||
2301 | .rate = 0xFF, | ||
2302 | }; | ||
2303 | |||
2304 | frame.skb = ieee80211_qosnullfunc_get(priv->hw, priv->vif); | ||
2305 | if (!frame.skb) | ||
2306 | return -ENOMEM; | ||
2307 | |||
2308 | ret = wsm_set_template_frame(priv, &frame); | ||
2309 | |||
2310 | dev_kfree_skb(frame.skb); | ||
2311 | |||
2312 | */ | ||
2313 | return ret; | ||
2314 | } | ||
2315 | |||
2316 | static int cw1200_enable_beaconing(struct cw1200_common *priv, | ||
2317 | bool enable) | ||
2318 | { | ||
2319 | struct wsm_beacon_transmit transmit = { | ||
2320 | .enable_beaconing = enable, | ||
2321 | }; | ||
2322 | |||
2323 | return wsm_beacon_transmit(priv, &transmit); | ||
2324 | } | ||
2325 | |||
2326 | static int cw1200_start_ap(struct cw1200_common *priv) | ||
2327 | { | ||
2328 | int ret; | ||
2329 | struct ieee80211_bss_conf *conf = &priv->vif->bss_conf; | ||
2330 | struct wsm_start start = { | ||
2331 | .mode = priv->vif->p2p ? | ||
2332 | WSM_START_MODE_P2P_GO : WSM_START_MODE_AP, | ||
2333 | .band = (priv->channel->band == IEEE80211_BAND_5GHZ) ? | ||
2334 | WSM_PHY_BAND_5G : WSM_PHY_BAND_2_4G, | ||
2335 | .channel_number = priv->channel->hw_value, | ||
2336 | .beacon_interval = conf->beacon_int, | ||
2337 | .dtim_period = conf->dtim_period, | ||
2338 | .preamble = conf->use_short_preamble ? | ||
2339 | WSM_JOIN_PREAMBLE_SHORT : | ||
2340 | WSM_JOIN_PREAMBLE_LONG, | ||
2341 | .probe_delay = 100, | ||
2342 | .basic_rate_set = cw1200_rate_mask_to_wsm(priv, | ||
2343 | conf->basic_rates), | ||
2344 | }; | ||
2345 | struct wsm_operational_mode mode = { | ||
2346 | .power_mode = cw1200_power_mode, | ||
2347 | .disable_more_flag_usage = true, | ||
2348 | }; | ||
2349 | |||
2350 | memset(start.ssid, 0, sizeof(start.ssid)); | ||
2351 | if (!conf->hidden_ssid) { | ||
2352 | start.ssid_len = conf->ssid_len; | ||
2353 | memcpy(start.ssid, conf->ssid, start.ssid_len); | ||
2354 | } | ||
2355 | |||
2356 | priv->beacon_int = conf->beacon_int; | ||
2357 | priv->join_dtim_period = conf->dtim_period; | ||
2358 | |||
2359 | memset(&priv->link_id_db, 0, sizeof(priv->link_id_db)); | ||
2360 | |||
2361 | pr_debug("[AP] ch: %d(%d), bcn: %d(%d), brt: 0x%.8X, ssid: %.*s.\n", | ||
2362 | start.channel_number, start.band, | ||
2363 | start.beacon_interval, start.dtim_period, | ||
2364 | start.basic_rate_set, | ||
2365 | start.ssid_len, start.ssid); | ||
2366 | ret = wsm_start(priv, &start); | ||
2367 | if (!ret) | ||
2368 | ret = cw1200_upload_keys(priv); | ||
2369 | if (!ret && priv->vif->p2p) { | ||
2370 | pr_debug("[AP] Setting p2p powersave configuration.\n"); | ||
2371 | wsm_set_p2p_ps_modeinfo(priv, &priv->p2p_ps_modeinfo); | ||
2372 | } | ||
2373 | if (!ret) { | ||
2374 | wsm_set_block_ack_policy(priv, 0, 0); | ||
2375 | priv->join_status = CW1200_JOIN_STATUS_AP; | ||
2376 | cw1200_update_filtering(priv); | ||
2377 | } | ||
2378 | wsm_set_operational_mode(priv, &mode); | ||
2379 | return ret; | ||
2380 | } | ||
2381 | |||
2382 | static int cw1200_update_beaconing(struct cw1200_common *priv) | ||
2383 | { | ||
2384 | struct ieee80211_bss_conf *conf = &priv->vif->bss_conf; | ||
2385 | struct wsm_reset reset = { | ||
2386 | .link_id = 0, | ||
2387 | .reset_statistics = true, | ||
2388 | }; | ||
2389 | |||
2390 | if (priv->mode == NL80211_IFTYPE_AP) { | ||
2391 | /* TODO: check if changed channel, band */ | ||
2392 | if (priv->join_status != CW1200_JOIN_STATUS_AP || | ||
2393 | priv->beacon_int != conf->beacon_int) { | ||
2394 | pr_debug("ap restarting\n"); | ||
2395 | wsm_lock_tx(priv); | ||
2396 | if (priv->join_status != CW1200_JOIN_STATUS_PASSIVE) | ||
2397 | wsm_reset(priv, &reset); | ||
2398 | priv->join_status = CW1200_JOIN_STATUS_PASSIVE; | ||
2399 | cw1200_start_ap(priv); | ||
2400 | wsm_unlock_tx(priv); | ||
2401 | } else | ||
2402 | pr_debug("ap started join_status: %d\n", | ||
2403 | priv->join_status); | ||
2404 | } | ||
2405 | return 0; | ||
2406 | } | ||