Commit | Line | Data |
---|---|---|
2e3c8736 | 1 | /* |
264d9b7d | 2 | * Copyright (c) 2008, 2009 open80211s Ltd. |
2e3c8736 LCC |
3 | * Authors: Luis Carlos Cobo <luisca@cozybit.com> |
4 | * Javier Cardona <javier@cozybit.com> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | */ | |
10 | ||
5a0e3ad6 | 11 | #include <linux/slab.h> |
51ceddad | 12 | #include <asm/unaligned.h> |
2e3c8736 LCC |
13 | #include "ieee80211_i.h" |
14 | #include "mesh.h" | |
15 | ||
5bb644a0 JB |
16 | #define TMR_RUNNING_HK 0 |
17 | #define TMR_RUNNING_MP 1 | |
e304bfd3 | 18 | #define TMR_RUNNING_MPR 2 |
5bb644a0 | 19 | |
2e3c8736 LCC |
20 | int mesh_allocated; |
21 | static struct kmem_cache *rm_cache; | |
22 | ||
25d49e4d TP |
23 | bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt) |
24 | { | |
25 | return (mgmt->u.action.u.mesh_action.action_code == | |
26 | WLAN_MESH_ACTION_HWMP_PATH_SELECTION); | |
27 | } | |
25d49e4d | 28 | |
2e3c8736 LCC |
29 | void ieee80211s_init(void) |
30 | { | |
31 | mesh_pathtbl_init(); | |
32 | mesh_allocated = 1; | |
33 | rm_cache = kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry), | |
34 | 0, 0, NULL); | |
35 | } | |
36 | ||
37 | void ieee80211s_stop(void) | |
38 | { | |
39 | mesh_pathtbl_unregister(); | |
40 | kmem_cache_destroy(rm_cache); | |
41 | } | |
42 | ||
472dbc45 JB |
43 | static void ieee80211_mesh_housekeeping_timer(unsigned long data) |
44 | { | |
45 | struct ieee80211_sub_if_data *sdata = (void *) data; | |
46 | struct ieee80211_local *local = sdata->local; | |
47 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
48 | ||
6b9ac442 | 49 | set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags); |
5bb644a0 JB |
50 | |
51 | if (local->quiescing) { | |
52 | set_bit(TMR_RUNNING_HK, &ifmsh->timers_running); | |
53 | return; | |
54 | } | |
55 | ||
64592c8f | 56 | ieee80211_queue_work(&local->hw, &sdata->work); |
472dbc45 JB |
57 | } |
58 | ||
2e3c8736 LCC |
59 | /** |
60 | * mesh_matches_local - check if the config of a mesh point matches ours | |
61 | * | |
f698d856 | 62 | * @sdata: local mesh subif |
f743ff49 | 63 | * @ie: information elements of a management frame from the mesh peer |
2e3c8736 LCC |
64 | * |
65 | * This function checks if the mesh configuration of a mesh point matches the | |
66 | * local mesh configuration, i.e. if both nodes belong to the same mesh network. | |
67 | */ | |
f743ff49 TP |
68 | bool mesh_matches_local(struct ieee80211_sub_if_data *sdata, |
69 | struct ieee802_11_elems *ie) | |
2e3c8736 | 70 | { |
472dbc45 | 71 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
739522ba | 72 | struct ieee80211_local *local = sdata->local; |
f743ff49 | 73 | u32 basic_rates = 0; |
4bf88530 | 74 | struct cfg80211_chan_def sta_chan_def; |
2e3c8736 | 75 | |
2e3c8736 LCC |
76 | /* |
77 | * As support for each feature is added, check for matching | |
78 | * - On mesh config capabilities | |
79 | * - Power Save Support En | |
80 | * - Sync support enabled | |
81 | * - Sync support active | |
82 | * - Sync support required from peer | |
83 | * - MDA enabled | |
84 | * - Power management control on fc | |
85 | */ | |
739522ba TP |
86 | if (!(ifmsh->mesh_id_len == ie->mesh_id_len && |
87 | memcmp(ifmsh->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 && | |
88 | (ifmsh->mesh_pp_id == ie->mesh_config->meshconf_psel) && | |
89 | (ifmsh->mesh_pm_id == ie->mesh_config->meshconf_pmetric) && | |
90 | (ifmsh->mesh_cc_id == ie->mesh_config->meshconf_congest) && | |
91 | (ifmsh->mesh_sp_id == ie->mesh_config->meshconf_synch) && | |
92 | (ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth))) | |
93 | goto mismatch; | |
94 | ||
55de908a | 95 | ieee80211_sta_get_rates(local, ie, ieee80211_get_sdata_band(sdata), |
f743ff49 TP |
96 | &basic_rates); |
97 | ||
fe40cb62 AN |
98 | if (sdata->vif.bss_conf.basic_rates != basic_rates) |
99 | goto mismatch; | |
100 | ||
4bf88530 JB |
101 | ieee80211_ht_oper_to_chandef(sdata->vif.bss_conf.chandef.chan, |
102 | ie->ht_operation, &sta_chan_def); | |
103 | ||
104 | if (!cfg80211_chandef_compatible(&sdata->vif.bss_conf.chandef, | |
105 | &sta_chan_def)) | |
739522ba | 106 | goto mismatch; |
2e3c8736 | 107 | |
739522ba TP |
108 | return true; |
109 | mismatch: | |
2e3c8736 LCC |
110 | return false; |
111 | } | |
112 | ||
113 | /** | |
114 | * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links | |
115 | * | |
116 | * @ie: information elements of a management frame from the mesh peer | |
2e3c8736 | 117 | */ |
f698d856 | 118 | bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie) |
2e3c8736 | 119 | { |
136cfa28 | 120 | return (ie->mesh_config->meshconf_cap & |
65821635 | 121 | IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS) != 0; |
2e3c8736 LCC |
122 | } |
123 | ||
124 | /** | |
2c53040f | 125 | * mesh_accept_plinks_update - update accepting_plink in local mesh beacons |
2e3c8736 | 126 | * |
d0709a65 | 127 | * @sdata: mesh interface in which mesh beacons are going to be updated |
df323818 MP |
128 | * |
129 | * Returns: beacon changed flag if the beacon content changed. | |
2e3c8736 | 130 | */ |
df323818 | 131 | u32 mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata) |
2e3c8736 | 132 | { |
2e3c8736 | 133 | bool free_plinks; |
df323818 | 134 | u32 changed = 0; |
2e3c8736 LCC |
135 | |
136 | /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0, | |
137 | * the mesh interface might be able to establish plinks with peers that | |
b4e08ea1 LCC |
138 | * are already on the table but are not on PLINK_ESTAB state. However, |
139 | * in general the mesh interface is not accepting peer link requests | |
140 | * from new peers, and that must be reflected in the beacon | |
2e3c8736 LCC |
141 | */ |
142 | free_plinks = mesh_plink_availables(sdata); | |
143 | ||
df323818 MP |
144 | if (free_plinks != sdata->u.mesh.accepting_plinks) { |
145 | sdata->u.mesh.accepting_plinks = free_plinks; | |
146 | changed = BSS_CHANGED_BEACON; | |
147 | } | |
148 | ||
149 | return changed; | |
2e3c8736 LCC |
150 | } |
151 | ||
f698d856 | 152 | int mesh_rmc_init(struct ieee80211_sub_if_data *sdata) |
2e3c8736 | 153 | { |
2e3c8736 LCC |
154 | int i; |
155 | ||
472dbc45 JB |
156 | sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL); |
157 | if (!sdata->u.mesh.rmc) | |
2e3c8736 | 158 | return -ENOMEM; |
472dbc45 | 159 | sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1; |
2e3c8736 | 160 | for (i = 0; i < RMC_BUCKETS; i++) |
b7cfcd11 | 161 | INIT_LIST_HEAD(&sdata->u.mesh.rmc->bucket[i]); |
2e3c8736 LCC |
162 | return 0; |
163 | } | |
164 | ||
f698d856 | 165 | void mesh_rmc_free(struct ieee80211_sub_if_data *sdata) |
2e3c8736 | 166 | { |
472dbc45 | 167 | struct mesh_rmc *rmc = sdata->u.mesh.rmc; |
2e3c8736 LCC |
168 | struct rmc_entry *p, *n; |
169 | int i; | |
170 | ||
472dbc45 | 171 | if (!sdata->u.mesh.rmc) |
2e3c8736 LCC |
172 | return; |
173 | ||
174 | for (i = 0; i < RMC_BUCKETS; i++) | |
b7cfcd11 | 175 | list_for_each_entry_safe(p, n, &rmc->bucket[i], list) { |
2e3c8736 LCC |
176 | list_del(&p->list); |
177 | kmem_cache_free(rm_cache, p); | |
178 | } | |
179 | ||
180 | kfree(rmc); | |
472dbc45 | 181 | sdata->u.mesh.rmc = NULL; |
2e3c8736 LCC |
182 | } |
183 | ||
184 | /** | |
185 | * mesh_rmc_check - Check frame in recent multicast cache and add if absent. | |
186 | * | |
187 | * @sa: source address | |
188 | * @mesh_hdr: mesh_header | |
189 | * | |
190 | * Returns: 0 if the frame is not in the cache, nonzero otherwise. | |
191 | * | |
192 | * Checks using the source address and the mesh sequence number if we have | |
193 | * received this frame lately. If the frame is not in the cache, it is added to | |
194 | * it. | |
195 | */ | |
196 | int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr, | |
f698d856 | 197 | struct ieee80211_sub_if_data *sdata) |
2e3c8736 | 198 | { |
472dbc45 | 199 | struct mesh_rmc *rmc = sdata->u.mesh.rmc; |
2e3c8736 LCC |
200 | u32 seqnum = 0; |
201 | int entries = 0; | |
202 | u8 idx; | |
203 | struct rmc_entry *p, *n; | |
204 | ||
205 | /* Don't care about endianness since only match matters */ | |
51ceddad LCC |
206 | memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum)); |
207 | idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask; | |
b7cfcd11 | 208 | list_for_each_entry_safe(p, n, &rmc->bucket[idx], list) { |
2e3c8736 LCC |
209 | ++entries; |
210 | if (time_after(jiffies, p->exp_time) || | |
211 | (entries == RMC_QUEUE_MAX_LEN)) { | |
212 | list_del(&p->list); | |
213 | kmem_cache_free(rm_cache, p); | |
214 | --entries; | |
f64f9e71 | 215 | } else if ((seqnum == p->seqnum) && |
b203ca39 | 216 | (ether_addr_equal(sa, p->sa))) |
2e3c8736 LCC |
217 | return -1; |
218 | } | |
219 | ||
220 | p = kmem_cache_alloc(rm_cache, GFP_ATOMIC); | |
d15b8459 | 221 | if (!p) |
2e3c8736 | 222 | return 0; |
d15b8459 | 223 | |
2e3c8736 LCC |
224 | p->seqnum = seqnum; |
225 | p->exp_time = jiffies + RMC_TIMEOUT; | |
226 | memcpy(p->sa, sa, ETH_ALEN); | |
b7cfcd11 | 227 | list_add(&p->list, &rmc->bucket[idx]); |
2e3c8736 LCC |
228 | return 0; |
229 | } | |
230 | ||
082ebb0c TP |
231 | int |
232 | mesh_add_meshconf_ie(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata) | |
233 | { | |
234 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
235 | u8 *pos, neighbors; | |
236 | u8 meshconf_len = sizeof(struct ieee80211_meshconf_ie); | |
237 | ||
238 | if (skb_tailroom(skb) < 2 + meshconf_len) | |
239 | return -ENOMEM; | |
240 | ||
241 | pos = skb_put(skb, 2 + meshconf_len); | |
242 | *pos++ = WLAN_EID_MESH_CONFIG; | |
243 | *pos++ = meshconf_len; | |
244 | ||
245 | /* Active path selection protocol ID */ | |
246 | *pos++ = ifmsh->mesh_pp_id; | |
247 | /* Active path selection metric ID */ | |
248 | *pos++ = ifmsh->mesh_pm_id; | |
249 | /* Congestion control mode identifier */ | |
250 | *pos++ = ifmsh->mesh_cc_id; | |
251 | /* Synchronization protocol identifier */ | |
252 | *pos++ = ifmsh->mesh_sp_id; | |
253 | /* Authentication Protocol identifier */ | |
254 | *pos++ = ifmsh->mesh_auth_id; | |
255 | /* Mesh Formation Info - number of neighbors */ | |
1258d976 | 256 | neighbors = atomic_read(&ifmsh->estab_plinks); |
082ebb0c TP |
257 | /* Number of neighbor mesh STAs or 15 whichever is smaller */ |
258 | neighbors = (neighbors > 15) ? 15 : neighbors; | |
259 | *pos++ = neighbors << 1; | |
260 | /* Mesh capability */ | |
65821635 | 261 | *pos = IEEE80211_MESHCONF_CAPAB_FORWARDING; |
dbf498fb | 262 | *pos |= ifmsh->accepting_plinks ? |
65821635 | 263 | IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00; |
dbf498fb | 264 | *pos++ |= ifmsh->adjusting_tbtt ? |
65821635 | 265 | IEEE80211_MESHCONF_CAPAB_TBTT_ADJUSTING : 0x00; |
082ebb0c TP |
266 | *pos++ = 0x00; |
267 | ||
268 | return 0; | |
269 | } | |
270 | ||
271 | int | |
272 | mesh_add_meshid_ie(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata) | |
273 | { | |
274 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
275 | u8 *pos; | |
276 | ||
277 | if (skb_tailroom(skb) < 2 + ifmsh->mesh_id_len) | |
278 | return -ENOMEM; | |
279 | ||
280 | pos = skb_put(skb, 2 + ifmsh->mesh_id_len); | |
281 | *pos++ = WLAN_EID_MESH_ID; | |
282 | *pos++ = ifmsh->mesh_id_len; | |
283 | if (ifmsh->mesh_id_len) | |
284 | memcpy(pos, ifmsh->mesh_id, ifmsh->mesh_id_len); | |
285 | ||
286 | return 0; | |
287 | } | |
288 | ||
289 | int | |
290 | mesh_add_vendor_ies(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata) | |
291 | { | |
292 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
293 | u8 offset, len; | |
294 | const u8 *data; | |
295 | ||
296 | if (!ifmsh->ie || !ifmsh->ie_len) | |
297 | return 0; | |
298 | ||
299 | /* fast-forward to vendor IEs */ | |
300 | offset = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0); | |
301 | ||
302 | if (offset) { | |
303 | len = ifmsh->ie_len - offset; | |
304 | data = ifmsh->ie + offset; | |
305 | if (skb_tailroom(skb) < len) | |
306 | return -ENOMEM; | |
307 | memcpy(skb_put(skb, len), data, len); | |
308 | } | |
309 | ||
310 | return 0; | |
311 | } | |
312 | ||
313 | int | |
314 | mesh_add_rsn_ie(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata) | |
315 | { | |
316 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
317 | u8 len = 0; | |
318 | const u8 *data; | |
319 | ||
320 | if (!ifmsh->ie || !ifmsh->ie_len) | |
321 | return 0; | |
322 | ||
323 | /* find RSN IE */ | |
324 | data = ifmsh->ie; | |
325 | while (data < ifmsh->ie + ifmsh->ie_len) { | |
326 | if (*data == WLAN_EID_RSN) { | |
327 | len = data[1] + 2; | |
328 | break; | |
329 | } | |
330 | data++; | |
331 | } | |
332 | ||
333 | if (len) { | |
334 | if (skb_tailroom(skb) < len) | |
335 | return -ENOMEM; | |
336 | memcpy(skb_put(skb, len), data, len); | |
337 | } | |
338 | ||
339 | return 0; | |
340 | } | |
341 | ||
082ebb0c TP |
342 | int mesh_add_ds_params_ie(struct sk_buff *skb, |
343 | struct ieee80211_sub_if_data *sdata) | |
344 | { | |
345 | struct ieee80211_local *local = sdata->local; | |
346 | struct ieee80211_supported_band *sband; | |
55de908a JB |
347 | struct ieee80211_chanctx_conf *chanctx_conf; |
348 | struct ieee80211_channel *chan; | |
082ebb0c | 349 | u8 *pos; |
2e3c8736 | 350 | |
082ebb0c TP |
351 | if (skb_tailroom(skb) < 3) |
352 | return -ENOMEM; | |
353 | ||
55de908a JB |
354 | rcu_read_lock(); |
355 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); | |
356 | if (WARN_ON(!chanctx_conf)) { | |
357 | rcu_read_unlock(); | |
358 | return -EINVAL; | |
359 | } | |
4bf88530 | 360 | chan = chanctx_conf->def.chan; |
55de908a JB |
361 | rcu_read_unlock(); |
362 | ||
6962d602 | 363 | sband = local->hw.wiphy->bands[chan->band]; |
be125c60 RP |
364 | if (sband->band == IEEE80211_BAND_2GHZ) { |
365 | pos = skb_put(skb, 2 + 1); | |
366 | *pos++ = WLAN_EID_DS_PARAMS; | |
367 | *pos++ = 1; | |
6962d602 | 368 | *pos++ = ieee80211_frequency_to_channel(chan->center_freq); |
be125c60 RP |
369 | } |
370 | ||
082ebb0c | 371 | return 0; |
2e3c8736 LCC |
372 | } |
373 | ||
176f3608 TP |
374 | int mesh_add_ht_cap_ie(struct sk_buff *skb, |
375 | struct ieee80211_sub_if_data *sdata) | |
376 | { | |
377 | struct ieee80211_local *local = sdata->local; | |
55de908a | 378 | enum ieee80211_band band = ieee80211_get_sdata_band(sdata); |
176f3608 TP |
379 | struct ieee80211_supported_band *sband; |
380 | u8 *pos; | |
381 | ||
55de908a | 382 | sband = local->hw.wiphy->bands[band]; |
176f3608 | 383 | if (!sband->ht_cap.ht_supported || |
4bf88530 | 384 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT) |
176f3608 TP |
385 | return 0; |
386 | ||
387 | if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_cap)) | |
388 | return -ENOMEM; | |
389 | ||
390 | pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_cap)); | |
ef96a842 | 391 | ieee80211_ie_build_ht_cap(pos, &sband->ht_cap, sband->ht_cap.cap); |
176f3608 TP |
392 | |
393 | return 0; | |
394 | } | |
395 | ||
074d46d1 | 396 | int mesh_add_ht_oper_ie(struct sk_buff *skb, |
176f3608 TP |
397 | struct ieee80211_sub_if_data *sdata) |
398 | { | |
399 | struct ieee80211_local *local = sdata->local; | |
55de908a JB |
400 | struct ieee80211_chanctx_conf *chanctx_conf; |
401 | struct ieee80211_channel *channel; | |
466f310d | 402 | enum nl80211_channel_type channel_type = |
4bf88530 | 403 | cfg80211_get_chandef_type(&sdata->vif.bss_conf.chandef); |
55de908a JB |
404 | struct ieee80211_supported_band *sband; |
405 | struct ieee80211_sta_ht_cap *ht_cap; | |
176f3608 TP |
406 | u8 *pos; |
407 | ||
55de908a JB |
408 | rcu_read_lock(); |
409 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); | |
410 | if (WARN_ON(!chanctx_conf)) { | |
411 | rcu_read_unlock(); | |
412 | return -EINVAL; | |
413 | } | |
4bf88530 | 414 | channel = chanctx_conf->def.chan; |
55de908a JB |
415 | rcu_read_unlock(); |
416 | ||
417 | sband = local->hw.wiphy->bands[channel->band]; | |
418 | ht_cap = &sband->ht_cap; | |
419 | ||
176f3608 TP |
420 | if (!ht_cap->ht_supported || channel_type == NL80211_CHAN_NO_HT) |
421 | return 0; | |
422 | ||
074d46d1 | 423 | if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_operation)) |
176f3608 TP |
424 | return -ENOMEM; |
425 | ||
074d46d1 | 426 | pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_operation)); |
4bf88530 | 427 | ieee80211_ie_build_ht_oper(pos, ht_cap, &sdata->vif.bss_conf.chandef, |
431e3154 | 428 | sdata->vif.bss_conf.ht_operation_mode); |
176f3608 TP |
429 | |
430 | return 0; | |
431 | } | |
2e3c8736 LCC |
432 | static void ieee80211_mesh_path_timer(unsigned long data) |
433 | { | |
434 | struct ieee80211_sub_if_data *sdata = | |
435 | (struct ieee80211_sub_if_data *) data; | |
472dbc45 | 436 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
133b8226 | 437 | struct ieee80211_local *local = sdata->local; |
2e3c8736 | 438 | |
5bb644a0 JB |
439 | if (local->quiescing) { |
440 | set_bit(TMR_RUNNING_MP, &ifmsh->timers_running); | |
441 | return; | |
442 | } | |
443 | ||
64592c8f | 444 | ieee80211_queue_work(&local->hw, &sdata->work); |
2e3c8736 LCC |
445 | } |
446 | ||
e304bfd3 RP |
447 | static void ieee80211_mesh_path_root_timer(unsigned long data) |
448 | { | |
449 | struct ieee80211_sub_if_data *sdata = | |
450 | (struct ieee80211_sub_if_data *) data; | |
451 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
452 | struct ieee80211_local *local = sdata->local; | |
453 | ||
454 | set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags); | |
455 | ||
456 | if (local->quiescing) { | |
457 | set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running); | |
458 | return; | |
459 | } | |
460 | ||
64592c8f | 461 | ieee80211_queue_work(&local->hw, &sdata->work); |
e304bfd3 RP |
462 | } |
463 | ||
63c5723b RP |
464 | void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh) |
465 | { | |
dbb912cd | 466 | if (ifmsh->mshcfg.dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT) |
63c5723b RP |
467 | set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags); |
468 | else { | |
469 | clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags); | |
470 | /* stop running timer */ | |
471 | del_timer_sync(&ifmsh->mesh_path_root_timer); | |
472 | } | |
473 | } | |
474 | ||
3c5772a5 JC |
475 | /** |
476 | * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame | |
477 | * @hdr: 802.11 frame header | |
478 | * @fc: frame control field | |
479 | * @meshda: destination address in the mesh | |
480 | * @meshsa: source address address in the mesh. Same as TA, as frame is | |
481 | * locally originated. | |
482 | * | |
483 | * Return the length of the 802.11 (does not include a mesh control header) | |
484 | */ | |
15ff6365 JB |
485 | int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc, |
486 | const u8 *meshda, const u8 *meshsa) | |
487 | { | |
3c5772a5 JC |
488 | if (is_multicast_ether_addr(meshda)) { |
489 | *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); | |
490 | /* DA TA SA */ | |
491 | memcpy(hdr->addr1, meshda, ETH_ALEN); | |
492 | memcpy(hdr->addr2, meshsa, ETH_ALEN); | |
493 | memcpy(hdr->addr3, meshsa, ETH_ALEN); | |
494 | return 24; | |
495 | } else { | |
2154c81c | 496 | *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); |
3c5772a5 JC |
497 | /* RA TA DA SA */ |
498 | memset(hdr->addr1, 0, ETH_ALEN); /* RA is resolved later */ | |
499 | memcpy(hdr->addr2, meshsa, ETH_ALEN); | |
500 | memcpy(hdr->addr3, meshda, ETH_ALEN); | |
501 | memcpy(hdr->addr4, meshsa, ETH_ALEN); | |
502 | return 30; | |
503 | } | |
504 | } | |
505 | ||
902acc78 JB |
506 | /** |
507 | * ieee80211_new_mesh_header - create a new mesh header | |
508 | * @meshhdr: uninitialized mesh header | |
509 | * @sdata: mesh interface to be used | |
61ad5394 JC |
510 | * @addr4or5: 1st address in the ae header, which may correspond to address 4 |
511 | * (if addr6 is NULL) or address 5 (if addr6 is present). It may | |
512 | * be NULL. | |
513 | * @addr6: 2nd address in the ae header, which corresponds to addr6 of the | |
514 | * mesh frame | |
902acc78 JB |
515 | * |
516 | * Return the header length. | |
517 | */ | |
518 | int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr, | |
61ad5394 JC |
519 | struct ieee80211_sub_if_data *sdata, char *addr4or5, |
520 | char *addr6) | |
902acc78 | 521 | { |
3c5772a5 | 522 | int aelen = 0; |
61ad5394 | 523 | BUG_ON(!addr4or5 && addr6); |
0c3cee72 | 524 | memset(meshhdr, 0, sizeof(*meshhdr)); |
472dbc45 JB |
525 | meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL; |
526 | put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum); | |
527 | sdata->u.mesh.mesh_seqnum++; | |
61ad5394 | 528 | if (addr4or5 && !addr6) { |
3c5772a5 JC |
529 | meshhdr->flags |= MESH_FLAGS_AE_A4; |
530 | aelen += ETH_ALEN; | |
61ad5394 JC |
531 | memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN); |
532 | } else if (addr4or5 && addr6) { | |
3c5772a5 JC |
533 | meshhdr->flags |= MESH_FLAGS_AE_A5_A6; |
534 | aelen += 2 * ETH_ALEN; | |
61ad5394 JC |
535 | memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN); |
536 | memcpy(meshhdr->eaddr2, addr6, ETH_ALEN); | |
3c5772a5 JC |
537 | } |
538 | return 6 + aelen; | |
902acc78 JB |
539 | } |
540 | ||
472dbc45 JB |
541 | static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata, |
542 | struct ieee80211_if_mesh *ifmsh) | |
543 | { | |
df323818 | 544 | u32 changed; |
472dbc45 | 545 | |
472dbc45 JB |
546 | ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT); |
547 | mesh_path_expire(sdata); | |
548 | ||
df323818 MP |
549 | changed = mesh_accept_plinks_update(sdata); |
550 | ieee80211_bss_info_change_notify(sdata, changed); | |
472dbc45 | 551 | |
472dbc45 JB |
552 | mod_timer(&ifmsh->housekeeping_timer, |
553 | round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL)); | |
554 | } | |
555 | ||
e304bfd3 RP |
556 | static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata) |
557 | { | |
558 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
a69cc44f | 559 | u32 interval; |
e304bfd3 RP |
560 | |
561 | mesh_path_tx_root_frame(sdata); | |
a69cc44f CYY |
562 | |
563 | if (ifmsh->mshcfg.dot11MeshHWMPRootMode == IEEE80211_PROACTIVE_RANN) | |
564 | interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval; | |
565 | else | |
566 | interval = ifmsh->mshcfg.dot11MeshHWMProotInterval; | |
567 | ||
e304bfd3 | 568 | mod_timer(&ifmsh->mesh_path_root_timer, |
a69cc44f | 569 | round_jiffies(TU_TO_EXP_TIME(interval))); |
e304bfd3 RP |
570 | } |
571 | ||
5bb644a0 JB |
572 | #ifdef CONFIG_PM |
573 | void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata) | |
574 | { | |
575 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
576 | ||
5ee68e5b | 577 | /* use atomic bitops in case all timers fire at the same time */ |
5bb644a0 JB |
578 | |
579 | if (del_timer_sync(&ifmsh->housekeeping_timer)) | |
580 | set_bit(TMR_RUNNING_HK, &ifmsh->timers_running); | |
581 | if (del_timer_sync(&ifmsh->mesh_path_timer)) | |
582 | set_bit(TMR_RUNNING_MP, &ifmsh->timers_running); | |
e304bfd3 RP |
583 | if (del_timer_sync(&ifmsh->mesh_path_root_timer)) |
584 | set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running); | |
5bb644a0 JB |
585 | } |
586 | ||
587 | void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata) | |
588 | { | |
589 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
590 | ||
591 | if (test_and_clear_bit(TMR_RUNNING_HK, &ifmsh->timers_running)) | |
592 | add_timer(&ifmsh->housekeeping_timer); | |
593 | if (test_and_clear_bit(TMR_RUNNING_MP, &ifmsh->timers_running)) | |
594 | add_timer(&ifmsh->mesh_path_timer); | |
e304bfd3 RP |
595 | if (test_and_clear_bit(TMR_RUNNING_MPR, &ifmsh->timers_running)) |
596 | add_timer(&ifmsh->mesh_path_root_timer); | |
63c5723b | 597 | ieee80211_mesh_root_setup(ifmsh); |
5bb644a0 JB |
598 | } |
599 | #endif | |
472dbc45 JB |
600 | |
601 | void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata) | |
602 | { | |
603 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
604 | struct ieee80211_local *local = sdata->local; | |
f4eabc91 CYY |
605 | u32 changed = BSS_CHANGED_BEACON | |
606 | BSS_CHANGED_BEACON_ENABLED | | |
607 | BSS_CHANGED_HT | | |
608 | BSS_CHANGED_BASIC_RATES | | |
609 | BSS_CHANGED_BEACON_INT; | |
610 | enum ieee80211_band band = ieee80211_get_sdata_band(sdata); | |
472dbc45 | 611 | |
09b17470 JB |
612 | local->fif_other_bss++; |
613 | /* mesh ifaces must set allmulti to forward mcast traffic */ | |
614 | atomic_inc(&local->iff_allmultis); | |
615 | ieee80211_configure_filter(local); | |
616 | ||
c7108a71 | 617 | ifmsh->mesh_cc_id = 0; /* Disabled */ |
c7108a71 | 618 | ifmsh->mesh_auth_id = 0; /* Disabled */ |
dbf498fb JC |
619 | /* register sync ops from extensible synchronization framework */ |
620 | ifmsh->sync_ops = ieee80211_mesh_sync_ops_get(ifmsh->mesh_sp_id); | |
621 | ifmsh->adjusting_tbtt = false; | |
622 | ifmsh->sync_offset_clockdrift_max = 0; | |
6b9ac442 | 623 | set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags); |
63c5723b | 624 | ieee80211_mesh_root_setup(ifmsh); |
64592c8f | 625 | ieee80211_queue_work(&local->hw, &sdata->work); |
70c33eaa AN |
626 | sdata->vif.bss_conf.ht_operation_mode = |
627 | ifmsh->mshcfg.ht_opmode; | |
d6a83228 | 628 | sdata->vif.bss_conf.enable_beacon = true; |
d934f7d0 | 629 | sdata->vif.bss_conf.basic_rates = |
f4eabc91 CYY |
630 | ieee80211_mandatory_rates(local, band); |
631 | ||
632 | if (band == IEEE80211_BAND_5GHZ) { | |
633 | sdata->vif.bss_conf.use_short_slot = true; | |
634 | changed |= BSS_CHANGED_ERP_SLOT; | |
635 | } | |
636 | ||
637 | ieee80211_bss_info_change_notify(sdata, changed); | |
c405c629 JB |
638 | |
639 | netif_carrier_on(sdata->dev); | |
472dbc45 JB |
640 | } |
641 | ||
642 | void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata) | |
643 | { | |
09b17470 | 644 | struct ieee80211_local *local = sdata->local; |
29cbe68c JB |
645 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
646 | ||
c405c629 JB |
647 | netif_carrier_off(sdata->dev); |
648 | ||
0d466b9c | 649 | /* stop the beacon */ |
29cbe68c | 650 | ifmsh->mesh_id_len = 0; |
d6a83228 JB |
651 | sdata->vif.bss_conf.enable_beacon = false; |
652 | clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state); | |
29cbe68c | 653 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED); |
0d466b9c TP |
654 | |
655 | /* flush STAs and mpaths on this iface */ | |
b998e8bb | 656 | sta_info_flush(sdata); |
0d466b9c | 657 | mesh_path_flush_by_iface(sdata); |
09b17470 | 658 | |
472dbc45 | 659 | del_timer_sync(&sdata->u.mesh.housekeeping_timer); |
e304bfd3 | 660 | del_timer_sync(&sdata->u.mesh.mesh_path_root_timer); |
dd4c9260 | 661 | del_timer_sync(&sdata->u.mesh.mesh_path_timer); |
b7413430 JB |
662 | /* |
663 | * If the timer fired while we waited for it, it will have | |
664 | * requeued the work. Now the work will be running again | |
665 | * but will not rearm the timer again because it checks | |
666 | * whether the interface is running, which, at this point, | |
667 | * it no longer is. | |
668 | */ | |
64592c8f | 669 | cancel_work_sync(&sdata->work); |
09b17470 JB |
670 | |
671 | local->fif_other_bss--; | |
672 | atomic_dec(&local->iff_allmultis); | |
673 | ieee80211_configure_filter(local); | |
2d9957cc JB |
674 | |
675 | sdata->u.mesh.timers_running = 0; | |
472dbc45 JB |
676 | } |
677 | ||
678 | static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata, | |
679 | u16 stype, | |
680 | struct ieee80211_mgmt *mgmt, | |
681 | size_t len, | |
682 | struct ieee80211_rx_status *rx_status) | |
683 | { | |
c6a1fa12 | 684 | struct ieee80211_local *local = sdata->local; |
dbf498fb | 685 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
472dbc45 JB |
686 | struct ieee802_11_elems elems; |
687 | struct ieee80211_channel *channel; | |
472dbc45 JB |
688 | size_t baselen; |
689 | int freq; | |
690 | enum ieee80211_band band = rx_status->band; | |
691 | ||
692 | /* ignore ProbeResp to foreign address */ | |
693 | if (stype == IEEE80211_STYPE_PROBE_RESP && | |
b203ca39 | 694 | !ether_addr_equal(mgmt->da, sdata->vif.addr)) |
472dbc45 JB |
695 | return; |
696 | ||
697 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; | |
698 | if (baselen > len) | |
699 | return; | |
700 | ||
701 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, | |
702 | &elems); | |
703 | ||
9a90bc81 TP |
704 | /* ignore non-mesh or secure / unsecure mismatch */ |
705 | if ((!elems.mesh_id || !elems.mesh_config) || | |
706 | (elems.rsn && sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) || | |
707 | (!elems.rsn && sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)) | |
5cff5e01 JC |
708 | return; |
709 | ||
472dbc45 | 710 | if (elems.ds_params && elems.ds_params_len == 1) |
59eb21a6 | 711 | freq = ieee80211_channel_to_frequency(elems.ds_params[0], band); |
472dbc45 JB |
712 | else |
713 | freq = rx_status->freq; | |
714 | ||
715 | channel = ieee80211_get_channel(local->hw.wiphy, freq); | |
716 | ||
717 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) | |
718 | return; | |
719 | ||
9a90bc81 | 720 | if (mesh_matches_local(sdata, &elems)) |
f743ff49 | 721 | mesh_neighbour_update(sdata, mgmt->sa, &elems); |
dbf498fb JC |
722 | |
723 | if (ifmsh->sync_ops) | |
724 | ifmsh->sync_ops->rx_bcn_presp(sdata, | |
725 | stype, mgmt, &elems, rx_status); | |
472dbc45 JB |
726 | } |
727 | ||
728 | static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata, | |
729 | struct ieee80211_mgmt *mgmt, | |
730 | size_t len, | |
731 | struct ieee80211_rx_status *rx_status) | |
732 | { | |
733 | switch (mgmt->u.action.category) { | |
8db09850 TP |
734 | case WLAN_CATEGORY_SELF_PROTECTED: |
735 | switch (mgmt->u.action.u.self_prot.action_code) { | |
736 | case WLAN_SP_MESH_PEERING_OPEN: | |
737 | case WLAN_SP_MESH_PEERING_CLOSE: | |
738 | case WLAN_SP_MESH_PEERING_CONFIRM: | |
739 | mesh_rx_plink_frame(sdata, mgmt, len, rx_status); | |
740 | break; | |
741 | } | |
472dbc45 | 742 | break; |
25d49e4d TP |
743 | case WLAN_CATEGORY_MESH_ACTION: |
744 | if (mesh_action_is_path_sel(mgmt)) | |
745 | mesh_rx_path_sel_frame(sdata, mgmt, len); | |
472dbc45 JB |
746 | break; |
747 | } | |
748 | } | |
749 | ||
1fa57d01 JB |
750 | void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
751 | struct sk_buff *skb) | |
472dbc45 JB |
752 | { |
753 | struct ieee80211_rx_status *rx_status; | |
472dbc45 JB |
754 | struct ieee80211_mgmt *mgmt; |
755 | u16 stype; | |
756 | ||
f1d58c25 | 757 | rx_status = IEEE80211_SKB_RXCB(skb); |
472dbc45 JB |
758 | mgmt = (struct ieee80211_mgmt *) skb->data; |
759 | stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE; | |
760 | ||
761 | switch (stype) { | |
762 | case IEEE80211_STYPE_PROBE_RESP: | |
763 | case IEEE80211_STYPE_BEACON: | |
764 | ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len, | |
765 | rx_status); | |
766 | break; | |
767 | case IEEE80211_STYPE_ACTION: | |
768 | ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status); | |
769 | break; | |
770 | } | |
472dbc45 JB |
771 | } |
772 | ||
1fa57d01 | 773 | void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata) |
472dbc45 | 774 | { |
472dbc45 | 775 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
472dbc45 JB |
776 | |
777 | if (ifmsh->preq_queue_len && | |
778 | time_after(jiffies, | |
779 | ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval))) | |
780 | mesh_path_start_discovery(sdata); | |
781 | ||
18889231 JC |
782 | if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags)) |
783 | mesh_mpath_table_grow(); | |
784 | ||
dcac908b | 785 | if (test_and_clear_bit(MESH_WORK_GROW_MPP_TABLE, &ifmsh->wrkq_flags)) |
18889231 JC |
786 | mesh_mpp_table_grow(); |
787 | ||
788 | if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags)) | |
472dbc45 | 789 | ieee80211_mesh_housekeeping(sdata, ifmsh); |
e304bfd3 RP |
790 | |
791 | if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags)) | |
792 | ieee80211_mesh_rootpath(sdata); | |
dbf498fb JC |
793 | |
794 | if (test_and_clear_bit(MESH_WORK_DRIFT_ADJUST, &ifmsh->wrkq_flags)) | |
795 | mesh_sync_adjust_tbtt(sdata); | |
472dbc45 JB |
796 | } |
797 | ||
798 | void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local) | |
799 | { | |
800 | struct ieee80211_sub_if_data *sdata; | |
801 | ||
802 | rcu_read_lock(); | |
803 | list_for_each_entry_rcu(sdata, &local->interfaces, list) | |
804 | if (ieee80211_vif_is_mesh(&sdata->vif)) | |
64592c8f | 805 | ieee80211_queue_work(&local->hw, &sdata->work); |
472dbc45 JB |
806 | rcu_read_unlock(); |
807 | } | |
808 | ||
902acc78 JB |
809 | void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata) |
810 | { | |
472dbc45 | 811 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
ad2d223a | 812 | static u8 zero_addr[ETH_ALEN] = {}; |
472dbc45 | 813 | |
472dbc45 JB |
814 | setup_timer(&ifmsh->housekeeping_timer, |
815 | ieee80211_mesh_housekeeping_timer, | |
816 | (unsigned long) sdata); | |
472dbc45 | 817 | |
472dbc45 JB |
818 | ifmsh->accepting_plinks = true; |
819 | ifmsh->preq_id = 0; | |
d19b3bf6 | 820 | ifmsh->sn = 0; |
5ee68e5b | 821 | ifmsh->num_gates = 0; |
472dbc45 | 822 | atomic_set(&ifmsh->mpaths, 0); |
f698d856 | 823 | mesh_rmc_init(sdata); |
472dbc45 | 824 | ifmsh->last_preq = jiffies; |
dca7e943 | 825 | ifmsh->next_perr = jiffies; |
902acc78 JB |
826 | /* Allocate all mesh structures when creating the first mesh interface. */ |
827 | if (!mesh_allocated) | |
828 | ieee80211s_init(); | |
472dbc45 | 829 | setup_timer(&ifmsh->mesh_path_timer, |
902acc78 JB |
830 | ieee80211_mesh_path_timer, |
831 | (unsigned long) sdata); | |
e304bfd3 RP |
832 | setup_timer(&ifmsh->mesh_path_root_timer, |
833 | ieee80211_mesh_path_root_timer, | |
834 | (unsigned long) sdata); | |
472dbc45 JB |
835 | INIT_LIST_HEAD(&ifmsh->preq_queue.list); |
836 | spin_lock_init(&ifmsh->mesh_preq_queue_lock); | |
dbf498fb | 837 | spin_lock_init(&ifmsh->sync_offset_lock); |
ad2d223a JB |
838 | |
839 | sdata->vif.bss_conf.bssid = zero_addr; | |
472dbc45 | 840 | } |