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