mac80211: Add the DS Params for mesh to every band
[deliverable/linux.git] / net / mac80211 / mesh.c
1 /*
2 * Copyright (c) 2008, 2009 open80211s Ltd.
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
11 #include <linux/slab.h>
12 #include <asm/unaligned.h>
13 #include "ieee80211_i.h"
14 #include "mesh.h"
15
16 #define TMR_RUNNING_HK 0
17 #define TMR_RUNNING_MP 1
18 #define TMR_RUNNING_MPR 2
19
20 int mesh_allocated;
21 static struct kmem_cache *rm_cache;
22
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 }
28
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
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
49 set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
50
51 if (local->quiescing) {
52 set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
53 return;
54 }
55
56 ieee80211_queue_work(&local->hw, &sdata->work);
57 }
58
59 /**
60 * mesh_matches_local - check if the config of a mesh point matches ours
61 *
62 * @sdata: local mesh subif
63 * @ie: information elements of a management frame from the mesh peer
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 */
68 bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
69 struct ieee802_11_elems *ie)
70 {
71 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
72 struct ieee80211_local *local = sdata->local;
73 u32 basic_rates = 0;
74 struct cfg80211_chan_def sta_chan_def;
75
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 */
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
95 ieee80211_sta_get_rates(local, ie, ieee80211_get_sdata_band(sdata),
96 &basic_rates);
97
98 if (sdata->vif.bss_conf.basic_rates != basic_rates)
99 goto mismatch;
100
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))
106 goto mismatch;
107
108 return true;
109 mismatch:
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
117 */
118 bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie)
119 {
120 return (ie->mesh_config->meshconf_cap &
121 IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS) != 0;
122 }
123
124 /**
125 * mesh_accept_plinks_update - update accepting_plink in local mesh beacons
126 *
127 * @sdata: mesh interface in which mesh beacons are going to be updated
128 *
129 * Returns: beacon changed flag if the beacon content changed.
130 */
131 u32 mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
132 {
133 bool free_plinks;
134 u32 changed = 0;
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
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
141 */
142 free_plinks = mesh_plink_availables(sdata);
143
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;
150 }
151
152 /*
153 * mesh_sta_cleanup - clean up any mesh sta state
154 *
155 * @sta: mesh sta to clean up.
156 */
157 void mesh_sta_cleanup(struct sta_info *sta)
158 {
159 struct ieee80211_sub_if_data *sdata = sta->sdata;
160 u32 changed;
161
162 /*
163 * maybe userspace handles peer allocation and peering, but in either
164 * case the beacon is still generated by the kernel and we might need
165 * an update.
166 */
167 changed = mesh_accept_plinks_update(sdata);
168 if (sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
169 changed |= mesh_plink_deactivate(sta);
170 del_timer_sync(&sta->plink_timer);
171 }
172
173 if (changed)
174 ieee80211_bss_info_change_notify(sdata, changed);
175 }
176
177 int mesh_rmc_init(struct ieee80211_sub_if_data *sdata)
178 {
179 int i;
180
181 sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL);
182 if (!sdata->u.mesh.rmc)
183 return -ENOMEM;
184 sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1;
185 for (i = 0; i < RMC_BUCKETS; i++)
186 INIT_LIST_HEAD(&sdata->u.mesh.rmc->bucket[i]);
187 return 0;
188 }
189
190 void mesh_rmc_free(struct ieee80211_sub_if_data *sdata)
191 {
192 struct mesh_rmc *rmc = sdata->u.mesh.rmc;
193 struct rmc_entry *p, *n;
194 int i;
195
196 if (!sdata->u.mesh.rmc)
197 return;
198
199 for (i = 0; i < RMC_BUCKETS; i++)
200 list_for_each_entry_safe(p, n, &rmc->bucket[i], list) {
201 list_del(&p->list);
202 kmem_cache_free(rm_cache, p);
203 }
204
205 kfree(rmc);
206 sdata->u.mesh.rmc = NULL;
207 }
208
209 /**
210 * mesh_rmc_check - Check frame in recent multicast cache and add if absent.
211 *
212 * @sa: source address
213 * @mesh_hdr: mesh_header
214 *
215 * Returns: 0 if the frame is not in the cache, nonzero otherwise.
216 *
217 * Checks using the source address and the mesh sequence number if we have
218 * received this frame lately. If the frame is not in the cache, it is added to
219 * it.
220 */
221 int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr,
222 struct ieee80211_sub_if_data *sdata)
223 {
224 struct mesh_rmc *rmc = sdata->u.mesh.rmc;
225 u32 seqnum = 0;
226 int entries = 0;
227 u8 idx;
228 struct rmc_entry *p, *n;
229
230 /* Don't care about endianness since only match matters */
231 memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum));
232 idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask;
233 list_for_each_entry_safe(p, n, &rmc->bucket[idx], list) {
234 ++entries;
235 if (time_after(jiffies, p->exp_time) ||
236 (entries == RMC_QUEUE_MAX_LEN)) {
237 list_del(&p->list);
238 kmem_cache_free(rm_cache, p);
239 --entries;
240 } else if ((seqnum == p->seqnum) &&
241 (ether_addr_equal(sa, p->sa)))
242 return -1;
243 }
244
245 p = kmem_cache_alloc(rm_cache, GFP_ATOMIC);
246 if (!p)
247 return 0;
248
249 p->seqnum = seqnum;
250 p->exp_time = jiffies + RMC_TIMEOUT;
251 memcpy(p->sa, sa, ETH_ALEN);
252 list_add(&p->list, &rmc->bucket[idx]);
253 return 0;
254 }
255
256 int
257 mesh_add_meshconf_ie(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
258 {
259 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
260 u8 *pos, neighbors;
261 u8 meshconf_len = sizeof(struct ieee80211_meshconf_ie);
262
263 if (skb_tailroom(skb) < 2 + meshconf_len)
264 return -ENOMEM;
265
266 pos = skb_put(skb, 2 + meshconf_len);
267 *pos++ = WLAN_EID_MESH_CONFIG;
268 *pos++ = meshconf_len;
269
270 /* Active path selection protocol ID */
271 *pos++ = ifmsh->mesh_pp_id;
272 /* Active path selection metric ID */
273 *pos++ = ifmsh->mesh_pm_id;
274 /* Congestion control mode identifier */
275 *pos++ = ifmsh->mesh_cc_id;
276 /* Synchronization protocol identifier */
277 *pos++ = ifmsh->mesh_sp_id;
278 /* Authentication Protocol identifier */
279 *pos++ = ifmsh->mesh_auth_id;
280 /* Mesh Formation Info - number of neighbors */
281 neighbors = atomic_read(&ifmsh->estab_plinks);
282 /* Number of neighbor mesh STAs or 15 whichever is smaller */
283 neighbors = (neighbors > 15) ? 15 : neighbors;
284 *pos++ = neighbors << 1;
285 /* Mesh capability */
286 *pos = IEEE80211_MESHCONF_CAPAB_FORWARDING;
287 *pos |= ifmsh->accepting_plinks ?
288 IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00;
289 /* Mesh PS mode. See IEEE802.11-2012 8.4.2.100.8 */
290 *pos |= ifmsh->ps_peers_deep_sleep ?
291 IEEE80211_MESHCONF_CAPAB_POWER_SAVE_LEVEL : 0x00;
292 *pos++ |= ifmsh->adjusting_tbtt ?
293 IEEE80211_MESHCONF_CAPAB_TBTT_ADJUSTING : 0x00;
294 *pos++ = 0x00;
295
296 return 0;
297 }
298
299 int
300 mesh_add_meshid_ie(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
301 {
302 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
303 u8 *pos;
304
305 if (skb_tailroom(skb) < 2 + ifmsh->mesh_id_len)
306 return -ENOMEM;
307
308 pos = skb_put(skb, 2 + ifmsh->mesh_id_len);
309 *pos++ = WLAN_EID_MESH_ID;
310 *pos++ = ifmsh->mesh_id_len;
311 if (ifmsh->mesh_id_len)
312 memcpy(pos, ifmsh->mesh_id, ifmsh->mesh_id_len);
313
314 return 0;
315 }
316
317 int mesh_add_awake_window_ie(struct sk_buff *skb,
318 struct ieee80211_sub_if_data *sdata)
319 {
320 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
321 u8 *pos;
322
323 /* see IEEE802.11-2012 13.14.6 */
324 if (ifmsh->ps_peers_light_sleep == 0 &&
325 ifmsh->ps_peers_deep_sleep == 0 &&
326 ifmsh->nonpeer_pm == NL80211_MESH_POWER_ACTIVE)
327 return 0;
328
329 if (skb_tailroom(skb) < 4)
330 return -ENOMEM;
331
332 pos = skb_put(skb, 2 + 2);
333 *pos++ = WLAN_EID_MESH_AWAKE_WINDOW;
334 *pos++ = 2;
335 put_unaligned_le16(ifmsh->mshcfg.dot11MeshAwakeWindowDuration, pos);
336
337 return 0;
338 }
339
340 int
341 mesh_add_vendor_ies(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
342 {
343 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
344 u8 offset, len;
345 const u8 *data;
346
347 if (!ifmsh->ie || !ifmsh->ie_len)
348 return 0;
349
350 /* fast-forward to vendor IEs */
351 offset = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0);
352
353 if (offset) {
354 len = ifmsh->ie_len - offset;
355 data = ifmsh->ie + offset;
356 if (skb_tailroom(skb) < len)
357 return -ENOMEM;
358 memcpy(skb_put(skb, len), data, len);
359 }
360
361 return 0;
362 }
363
364 int
365 mesh_add_rsn_ie(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
366 {
367 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
368 u8 len = 0;
369 const u8 *data;
370
371 if (!ifmsh->ie || !ifmsh->ie_len)
372 return 0;
373
374 /* find RSN IE */
375 data = ifmsh->ie;
376 while (data < ifmsh->ie + ifmsh->ie_len) {
377 if (*data == WLAN_EID_RSN) {
378 len = data[1] + 2;
379 break;
380 }
381 data++;
382 }
383
384 if (len) {
385 if (skb_tailroom(skb) < len)
386 return -ENOMEM;
387 memcpy(skb_put(skb, len), data, len);
388 }
389
390 return 0;
391 }
392
393 int mesh_add_ds_params_ie(struct sk_buff *skb,
394 struct ieee80211_sub_if_data *sdata)
395 {
396 struct ieee80211_chanctx_conf *chanctx_conf;
397 struct ieee80211_channel *chan;
398 u8 *pos;
399
400 if (skb_tailroom(skb) < 3)
401 return -ENOMEM;
402
403 rcu_read_lock();
404 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
405 if (WARN_ON(!chanctx_conf)) {
406 rcu_read_unlock();
407 return -EINVAL;
408 }
409 chan = chanctx_conf->def.chan;
410 rcu_read_unlock();
411
412 pos = skb_put(skb, 2 + 1);
413 *pos++ = WLAN_EID_DS_PARAMS;
414 *pos++ = 1;
415 *pos++ = ieee80211_frequency_to_channel(chan->center_freq);
416
417 return 0;
418 }
419
420 int mesh_add_ht_cap_ie(struct sk_buff *skb,
421 struct ieee80211_sub_if_data *sdata)
422 {
423 struct ieee80211_local *local = sdata->local;
424 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
425 struct ieee80211_supported_band *sband;
426 u8 *pos;
427
428 sband = local->hw.wiphy->bands[band];
429 if (!sband->ht_cap.ht_supported ||
430 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
431 return 0;
432
433 if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_cap))
434 return -ENOMEM;
435
436 pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_cap));
437 ieee80211_ie_build_ht_cap(pos, &sband->ht_cap, sband->ht_cap.cap);
438
439 return 0;
440 }
441
442 int mesh_add_ht_oper_ie(struct sk_buff *skb,
443 struct ieee80211_sub_if_data *sdata)
444 {
445 struct ieee80211_local *local = sdata->local;
446 struct ieee80211_chanctx_conf *chanctx_conf;
447 struct ieee80211_channel *channel;
448 enum nl80211_channel_type channel_type =
449 cfg80211_get_chandef_type(&sdata->vif.bss_conf.chandef);
450 struct ieee80211_supported_band *sband;
451 struct ieee80211_sta_ht_cap *ht_cap;
452 u8 *pos;
453
454 rcu_read_lock();
455 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
456 if (WARN_ON(!chanctx_conf)) {
457 rcu_read_unlock();
458 return -EINVAL;
459 }
460 channel = chanctx_conf->def.chan;
461 rcu_read_unlock();
462
463 sband = local->hw.wiphy->bands[channel->band];
464 ht_cap = &sband->ht_cap;
465
466 if (!ht_cap->ht_supported || channel_type == NL80211_CHAN_NO_HT)
467 return 0;
468
469 if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_operation))
470 return -ENOMEM;
471
472 pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_operation));
473 ieee80211_ie_build_ht_oper(pos, ht_cap, &sdata->vif.bss_conf.chandef,
474 sdata->vif.bss_conf.ht_operation_mode);
475
476 return 0;
477 }
478 static void ieee80211_mesh_path_timer(unsigned long data)
479 {
480 struct ieee80211_sub_if_data *sdata =
481 (struct ieee80211_sub_if_data *) data;
482 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
483 struct ieee80211_local *local = sdata->local;
484
485 if (local->quiescing) {
486 set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
487 return;
488 }
489
490 ieee80211_queue_work(&local->hw, &sdata->work);
491 }
492
493 static void ieee80211_mesh_path_root_timer(unsigned long data)
494 {
495 struct ieee80211_sub_if_data *sdata =
496 (struct ieee80211_sub_if_data *) data;
497 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
498 struct ieee80211_local *local = sdata->local;
499
500 set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
501
502 if (local->quiescing) {
503 set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
504 return;
505 }
506
507 ieee80211_queue_work(&local->hw, &sdata->work);
508 }
509
510 void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh)
511 {
512 if (ifmsh->mshcfg.dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)
513 set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
514 else {
515 clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
516 /* stop running timer */
517 del_timer_sync(&ifmsh->mesh_path_root_timer);
518 }
519 }
520
521 /**
522 * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
523 * @hdr: 802.11 frame header
524 * @fc: frame control field
525 * @meshda: destination address in the mesh
526 * @meshsa: source address address in the mesh. Same as TA, as frame is
527 * locally originated.
528 *
529 * Return the length of the 802.11 (does not include a mesh control header)
530 */
531 int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
532 const u8 *meshda, const u8 *meshsa)
533 {
534 if (is_multicast_ether_addr(meshda)) {
535 *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
536 /* DA TA SA */
537 memcpy(hdr->addr1, meshda, ETH_ALEN);
538 memcpy(hdr->addr2, meshsa, ETH_ALEN);
539 memcpy(hdr->addr3, meshsa, ETH_ALEN);
540 return 24;
541 } else {
542 *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
543 /* RA TA DA SA */
544 memset(hdr->addr1, 0, ETH_ALEN); /* RA is resolved later */
545 memcpy(hdr->addr2, meshsa, ETH_ALEN);
546 memcpy(hdr->addr3, meshda, ETH_ALEN);
547 memcpy(hdr->addr4, meshsa, ETH_ALEN);
548 return 30;
549 }
550 }
551
552 /**
553 * ieee80211_new_mesh_header - create a new mesh header
554 * @meshhdr: uninitialized mesh header
555 * @sdata: mesh interface to be used
556 * @addr4or5: 1st address in the ae header, which may correspond to address 4
557 * (if addr6 is NULL) or address 5 (if addr6 is present). It may
558 * be NULL.
559 * @addr6: 2nd address in the ae header, which corresponds to addr6 of the
560 * mesh frame
561 *
562 * Return the header length.
563 */
564 int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
565 struct ieee80211_sub_if_data *sdata, char *addr4or5,
566 char *addr6)
567 {
568 int aelen = 0;
569 BUG_ON(!addr4or5 && addr6);
570 memset(meshhdr, 0, sizeof(*meshhdr));
571 meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
572 put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
573 sdata->u.mesh.mesh_seqnum++;
574 if (addr4or5 && !addr6) {
575 meshhdr->flags |= MESH_FLAGS_AE_A4;
576 aelen += ETH_ALEN;
577 memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
578 } else if (addr4or5 && addr6) {
579 meshhdr->flags |= MESH_FLAGS_AE_A5_A6;
580 aelen += 2 * ETH_ALEN;
581 memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
582 memcpy(meshhdr->eaddr2, addr6, ETH_ALEN);
583 }
584 return 6 + aelen;
585 }
586
587 static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
588 struct ieee80211_if_mesh *ifmsh)
589 {
590 u32 changed;
591
592 ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
593 mesh_path_expire(sdata);
594
595 changed = mesh_accept_plinks_update(sdata);
596 ieee80211_bss_info_change_notify(sdata, changed);
597
598 mod_timer(&ifmsh->housekeeping_timer,
599 round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
600 }
601
602 static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata)
603 {
604 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
605 u32 interval;
606
607 mesh_path_tx_root_frame(sdata);
608
609 if (ifmsh->mshcfg.dot11MeshHWMPRootMode == IEEE80211_PROACTIVE_RANN)
610 interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval;
611 else
612 interval = ifmsh->mshcfg.dot11MeshHWMProotInterval;
613
614 mod_timer(&ifmsh->mesh_path_root_timer,
615 round_jiffies(TU_TO_EXP_TIME(interval)));
616 }
617
618 #ifdef CONFIG_PM
619 void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
620 {
621 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
622
623 /* use atomic bitops in case all timers fire at the same time */
624
625 if (del_timer_sync(&ifmsh->housekeeping_timer))
626 set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
627 if (del_timer_sync(&ifmsh->mesh_path_timer))
628 set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
629 if (del_timer_sync(&ifmsh->mesh_path_root_timer))
630 set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
631 }
632
633 void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
634 {
635 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
636
637 if (test_and_clear_bit(TMR_RUNNING_HK, &ifmsh->timers_running))
638 add_timer(&ifmsh->housekeeping_timer);
639 if (test_and_clear_bit(TMR_RUNNING_MP, &ifmsh->timers_running))
640 add_timer(&ifmsh->mesh_path_timer);
641 if (test_and_clear_bit(TMR_RUNNING_MPR, &ifmsh->timers_running))
642 add_timer(&ifmsh->mesh_path_root_timer);
643 ieee80211_mesh_root_setup(ifmsh);
644 }
645 #endif
646
647 void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
648 {
649 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
650 struct ieee80211_local *local = sdata->local;
651 u32 changed = BSS_CHANGED_BEACON |
652 BSS_CHANGED_BEACON_ENABLED |
653 BSS_CHANGED_HT |
654 BSS_CHANGED_BASIC_RATES |
655 BSS_CHANGED_BEACON_INT;
656 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
657
658 local->fif_other_bss++;
659 /* mesh ifaces must set allmulti to forward mcast traffic */
660 atomic_inc(&local->iff_allmultis);
661 ieee80211_configure_filter(local);
662
663 ifmsh->mesh_cc_id = 0; /* Disabled */
664 ifmsh->mesh_auth_id = 0; /* Disabled */
665 /* register sync ops from extensible synchronization framework */
666 ifmsh->sync_ops = ieee80211_mesh_sync_ops_get(ifmsh->mesh_sp_id);
667 ifmsh->adjusting_tbtt = false;
668 ifmsh->sync_offset_clockdrift_max = 0;
669 set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
670 ieee80211_mesh_root_setup(ifmsh);
671 ieee80211_queue_work(&local->hw, &sdata->work);
672 sdata->vif.bss_conf.ht_operation_mode =
673 ifmsh->mshcfg.ht_opmode;
674 sdata->vif.bss_conf.enable_beacon = true;
675 sdata->vif.bss_conf.basic_rates =
676 ieee80211_mandatory_rates(local, band);
677
678 ieee80211_mps_local_status_update(sdata);
679
680 ieee80211_bss_info_change_notify(sdata, changed);
681
682 netif_carrier_on(sdata->dev);
683 }
684
685 void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
686 {
687 struct ieee80211_local *local = sdata->local;
688 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
689
690 netif_carrier_off(sdata->dev);
691
692 /* stop the beacon */
693 ifmsh->mesh_id_len = 0;
694 sdata->vif.bss_conf.enable_beacon = false;
695 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
696 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
697
698 /* flush STAs and mpaths on this iface */
699 sta_info_flush(sdata);
700 mesh_path_flush_by_iface(sdata);
701
702 /* free all potentially still buffered group-addressed frames */
703 local->total_ps_buffered -= skb_queue_len(&ifmsh->ps.bc_buf);
704 skb_queue_purge(&ifmsh->ps.bc_buf);
705
706 del_timer_sync(&sdata->u.mesh.housekeeping_timer);
707 del_timer_sync(&sdata->u.mesh.mesh_path_root_timer);
708 del_timer_sync(&sdata->u.mesh.mesh_path_timer);
709 /*
710 * If the timer fired while we waited for it, it will have
711 * requeued the work. Now the work will be running again
712 * but will not rearm the timer again because it checks
713 * whether the interface is running, which, at this point,
714 * it no longer is.
715 */
716 cancel_work_sync(&sdata->work);
717
718 local->fif_other_bss--;
719 atomic_dec(&local->iff_allmultis);
720 ieee80211_configure_filter(local);
721
722 sdata->u.mesh.timers_running = 0;
723 }
724
725 static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
726 u16 stype,
727 struct ieee80211_mgmt *mgmt,
728 size_t len,
729 struct ieee80211_rx_status *rx_status)
730 {
731 struct ieee80211_local *local = sdata->local;
732 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
733 struct ieee802_11_elems elems;
734 struct ieee80211_channel *channel;
735 size_t baselen;
736 int freq;
737 enum ieee80211_band band = rx_status->band;
738
739 /* ignore ProbeResp to foreign address */
740 if (stype == IEEE80211_STYPE_PROBE_RESP &&
741 !ether_addr_equal(mgmt->da, sdata->vif.addr))
742 return;
743
744 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
745 if (baselen > len)
746 return;
747
748 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
749 &elems);
750
751 /* ignore non-mesh or secure / unsecure mismatch */
752 if ((!elems.mesh_id || !elems.mesh_config) ||
753 (elems.rsn && sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) ||
754 (!elems.rsn && sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE))
755 return;
756
757 if (elems.ds_params && elems.ds_params_len == 1)
758 freq = ieee80211_channel_to_frequency(elems.ds_params[0], band);
759 else
760 freq = rx_status->freq;
761
762 channel = ieee80211_get_channel(local->hw.wiphy, freq);
763
764 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
765 return;
766
767 if (mesh_matches_local(sdata, &elems))
768 mesh_neighbour_update(sdata, mgmt->sa, &elems);
769
770 if (ifmsh->sync_ops)
771 ifmsh->sync_ops->rx_bcn_presp(sdata,
772 stype, mgmt, &elems, rx_status);
773 }
774
775 static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
776 struct ieee80211_mgmt *mgmt,
777 size_t len,
778 struct ieee80211_rx_status *rx_status)
779 {
780 switch (mgmt->u.action.category) {
781 case WLAN_CATEGORY_SELF_PROTECTED:
782 switch (mgmt->u.action.u.self_prot.action_code) {
783 case WLAN_SP_MESH_PEERING_OPEN:
784 case WLAN_SP_MESH_PEERING_CLOSE:
785 case WLAN_SP_MESH_PEERING_CONFIRM:
786 mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
787 break;
788 }
789 break;
790 case WLAN_CATEGORY_MESH_ACTION:
791 if (mesh_action_is_path_sel(mgmt))
792 mesh_rx_path_sel_frame(sdata, mgmt, len);
793 break;
794 }
795 }
796
797 void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
798 struct sk_buff *skb)
799 {
800 struct ieee80211_rx_status *rx_status;
801 struct ieee80211_mgmt *mgmt;
802 u16 stype;
803
804 rx_status = IEEE80211_SKB_RXCB(skb);
805 mgmt = (struct ieee80211_mgmt *) skb->data;
806 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
807
808 switch (stype) {
809 case IEEE80211_STYPE_PROBE_RESP:
810 case IEEE80211_STYPE_BEACON:
811 ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
812 rx_status);
813 break;
814 case IEEE80211_STYPE_ACTION:
815 ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
816 break;
817 }
818 }
819
820 void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata)
821 {
822 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
823
824 if (ifmsh->preq_queue_len &&
825 time_after(jiffies,
826 ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
827 mesh_path_start_discovery(sdata);
828
829 if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
830 mesh_mpath_table_grow();
831
832 if (test_and_clear_bit(MESH_WORK_GROW_MPP_TABLE, &ifmsh->wrkq_flags))
833 mesh_mpp_table_grow();
834
835 if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
836 ieee80211_mesh_housekeeping(sdata, ifmsh);
837
838 if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags))
839 ieee80211_mesh_rootpath(sdata);
840
841 if (test_and_clear_bit(MESH_WORK_DRIFT_ADJUST, &ifmsh->wrkq_flags))
842 mesh_sync_adjust_tbtt(sdata);
843 }
844
845 void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
846 {
847 struct ieee80211_sub_if_data *sdata;
848
849 rcu_read_lock();
850 list_for_each_entry_rcu(sdata, &local->interfaces, list)
851 if (ieee80211_vif_is_mesh(&sdata->vif))
852 ieee80211_queue_work(&local->hw, &sdata->work);
853 rcu_read_unlock();
854 }
855
856 void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
857 {
858 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
859 static u8 zero_addr[ETH_ALEN] = {};
860
861 setup_timer(&ifmsh->housekeeping_timer,
862 ieee80211_mesh_housekeeping_timer,
863 (unsigned long) sdata);
864
865 ifmsh->accepting_plinks = true;
866 ifmsh->preq_id = 0;
867 ifmsh->sn = 0;
868 ifmsh->num_gates = 0;
869 atomic_set(&ifmsh->mpaths, 0);
870 mesh_rmc_init(sdata);
871 ifmsh->last_preq = jiffies;
872 ifmsh->next_perr = jiffies;
873 /* Allocate all mesh structures when creating the first mesh interface. */
874 if (!mesh_allocated)
875 ieee80211s_init();
876 setup_timer(&ifmsh->mesh_path_timer,
877 ieee80211_mesh_path_timer,
878 (unsigned long) sdata);
879 setup_timer(&ifmsh->mesh_path_root_timer,
880 ieee80211_mesh_path_root_timer,
881 (unsigned long) sdata);
882 INIT_LIST_HEAD(&ifmsh->preq_queue.list);
883 skb_queue_head_init(&ifmsh->ps.bc_buf);
884 spin_lock_init(&ifmsh->mesh_preq_queue_lock);
885 spin_lock_init(&ifmsh->sync_offset_lock);
886
887 sdata->vif.bss_conf.bssid = zero_addr;
888 }
This page took 0.205037 seconds and 5 git commands to generate.