blob: 245885841c8dd40b9eb493f3276943296c4d6ab0 [file] [log] [blame]
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +01001/*
Rui Paulo264d9b72009-11-09 23:46:58 +00002 * Copyright (c) 2008, 2009 open80211s Ltd.
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +01003 * 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
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Luis Carlos Cobo51cedda2008-04-23 12:15:29 -070012#include <asm/unaligned.h>
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +010013#include "ieee80211_i.h"
14#include "mesh.h"
15
Johannes Berg5bb644a2009-05-17 11:40:42 +020016#define TMR_RUNNING_HK 0
17#define TMR_RUNNING_MP 1
Rui Pauloe304bfd2009-11-09 23:46:56 +000018#define TMR_RUNNING_MPR 2
Johannes Berg5bb644a2009-05-17 11:40:42 +020019
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +010020int mesh_allocated;
21static struct kmem_cache *rm_cache;
22
Thomas Pedersen25d49e42011-08-11 19:35:15 -070023bool 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}
Thomas Pedersen25d49e42011-08-11 19:35:15 -070028
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +010029void 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
37void ieee80211s_stop(void)
38{
39 mesh_pathtbl_unregister();
40 kmem_cache_destroy(rm_cache);
41}
42
Johannes Berg472dbc42008-09-11 00:01:49 +020043static 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
Rui Paulo6b9ac442009-10-20 21:21:48 +010049 set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
Johannes Berg5bb644a2009-05-17 11:40:42 +020050
51 if (local->quiescing) {
52 set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
53 return;
54 }
55
Johannes Berg64592c82010-06-10 10:21:31 +020056 ieee80211_queue_work(&local->hw, &sdata->work);
Johannes Berg472dbc42008-09-11 00:01:49 +020057}
58
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +010059/**
60 * mesh_matches_local - check if the config of a mesh point matches ours
61 *
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120062 * @sdata: local mesh subif
Thomas Pedersenf743ff42012-04-18 19:23:43 -070063 * @ie: information elements of a management frame from the mesh peer
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +010064 *
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 */
Thomas Pedersenf743ff42012-04-18 19:23:43 -070068bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
69 struct ieee802_11_elems *ie)
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +010070{
Johannes Berg472dbc42008-09-11 00:01:49 +020071 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Thomas Pedersen739522b2011-10-26 14:47:28 -070072 struct ieee80211_local *local = sdata->local;
Thomas Pedersenf743ff42012-04-18 19:23:43 -070073 u32 basic_rates = 0;
Johannes Berg4bf88532012-11-09 11:39:59 +010074 struct cfg80211_chan_def sta_chan_def;
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +010075
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +010076 /*
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 */
Thomas Pedersen739522b2011-10-26 14:47:28 -070086 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;
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +010094
Johannes Berg55de9082012-07-26 17:24:39 +020095 ieee80211_sta_get_rates(local, ie, ieee80211_get_sdata_band(sdata),
Thomas Pedersenf743ff42012-04-18 19:23:43 -070096 &basic_rates);
97
Ashok Nagarajanfe40cb62012-04-02 21:21:22 -070098 if (sdata->vif.bss_conf.basic_rates != basic_rates)
99 goto mismatch;
100
Johannes Berg4bf88532012-11-09 11:39:59 +0100101 ieee80211_ht_oper_to_chandef(sdata->vif.bss_conf.chandef.chan,
102 ie->ht_operation, &sta_chan_def);
Ashok Nagarajanb91e64a2012-04-30 14:20:31 -0700103
Johannes Berg4bf88532012-11-09 11:39:59 +0100104 if (!cfg80211_chandef_compatible(&sdata->vif.bss_conf.chandef,
105 &sta_chan_def))
Thomas Pedersen739522b2011-10-26 14:47:28 -0700106 goto mismatch;
107
108 return true;
109mismatch:
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100110 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
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100117 */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200118bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie)
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100119{
Rui Paulo136cfa22009-11-18 18:40:00 +0000120 return (ie->mesh_config->meshconf_cap &
Marco Porsch65821632012-11-21 18:40:30 -0800121 IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS) != 0;
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100122}
123
124/**
Ben Hutchings2c530402012-07-10 10:55:09 +0000125 * mesh_accept_plinks_update - update accepting_plink in local mesh beacons
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100126 *
Johannes Bergd0709a62008-02-25 16:27:46 +0100127 * @sdata: mesh interface in which mesh beacons are going to be updated
Marco Porschdf323812012-08-08 07:58:43 +0200128 *
129 * Returns: beacon changed flag if the beacon content changed.
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100130 */
Marco Porschdf323812012-08-08 07:58:43 +0200131u32 mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100132{
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100133 bool free_plinks;
Marco Porschdf323812012-08-08 07:58:43 +0200134 u32 changed = 0;
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100135
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
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800138 * 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
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100141 */
142 free_plinks = mesh_plink_availables(sdata);
143
Marco Porschdf323812012-08-08 07:58:43 +0200144 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;
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100150}
151
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200152int mesh_rmc_init(struct ieee80211_sub_if_data *sdata)
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100153{
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100154 int i;
155
Johannes Berg472dbc42008-09-11 00:01:49 +0200156 sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL);
157 if (!sdata->u.mesh.rmc)
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100158 return -ENOMEM;
Johannes Berg472dbc42008-09-11 00:01:49 +0200159 sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1;
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100160 for (i = 0; i < RMC_BUCKETS; i++)
Thomas Pedersenb7cfcd12012-12-17 18:41:57 -0800161 INIT_LIST_HEAD(&sdata->u.mesh.rmc->bucket[i]);
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100162 return 0;
163}
164
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200165void mesh_rmc_free(struct ieee80211_sub_if_data *sdata)
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100166{
Johannes Berg472dbc42008-09-11 00:01:49 +0200167 struct mesh_rmc *rmc = sdata->u.mesh.rmc;
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100168 struct rmc_entry *p, *n;
169 int i;
170
Johannes Berg472dbc42008-09-11 00:01:49 +0200171 if (!sdata->u.mesh.rmc)
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100172 return;
173
174 for (i = 0; i < RMC_BUCKETS; i++)
Thomas Pedersenb7cfcd12012-12-17 18:41:57 -0800175 list_for_each_entry_safe(p, n, &rmc->bucket[i], list) {
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100176 list_del(&p->list);
177 kmem_cache_free(rm_cache, p);
178 }
179
180 kfree(rmc);
Johannes Berg472dbc42008-09-11 00:01:49 +0200181 sdata->u.mesh.rmc = NULL;
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100182}
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 */
196int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr,
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200197 struct ieee80211_sub_if_data *sdata)
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100198{
Johannes Berg472dbc42008-09-11 00:01:49 +0200199 struct mesh_rmc *rmc = sdata->u.mesh.rmc;
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100200 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 */
Luis Carlos Cobo51cedda2008-04-23 12:15:29 -0700206 memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum));
207 idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask;
Thomas Pedersenb7cfcd12012-12-17 18:41:57 -0800208 list_for_each_entry_safe(p, n, &rmc->bucket[idx], list) {
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100209 ++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;
Joe Perchesf64f9e72009-11-29 16:55:45 -0800215 } else if ((seqnum == p->seqnum) &&
Joe Perchesb203ca32012-05-08 18:56:52 +0000216 (ether_addr_equal(sa, p->sa)))
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100217 return -1;
218 }
219
220 p = kmem_cache_alloc(rm_cache, GFP_ATOMIC);
Joe Perchesd15b8452011-08-29 14:17:31 -0700221 if (!p)
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100222 return 0;
Joe Perchesd15b8452011-08-29 14:17:31 -0700223
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100224 p->seqnum = seqnum;
225 p->exp_time = jiffies + RMC_TIMEOUT;
226 memcpy(p->sa, sa, ETH_ALEN);
Thomas Pedersenb7cfcd12012-12-17 18:41:57 -0800227 list_add(&p->list, &rmc->bucket[idx]);
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100228 return 0;
229}
230
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700231int
232mesh_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 */
Ashok Nagarajan1258d972012-10-09 13:27:47 -0700256 neighbors = atomic_read(&ifmsh->estab_plinks);
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700257 /* Number of neighbor mesh STAs or 15 whichever is smaller */
258 neighbors = (neighbors > 15) ? 15 : neighbors;
259 *pos++ = neighbors << 1;
260 /* Mesh capability */
Marco Porsch65821632012-11-21 18:40:30 -0800261 *pos = IEEE80211_MESHCONF_CAPAB_FORWARDING;
Javier Cardonadbf498f2012-03-31 11:31:32 -0700262 *pos |= ifmsh->accepting_plinks ?
Marco Porsch65821632012-11-21 18:40:30 -0800263 IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00;
Javier Cardonadbf498f2012-03-31 11:31:32 -0700264 *pos++ |= ifmsh->adjusting_tbtt ?
Marco Porsch65821632012-11-21 18:40:30 -0800265 IEEE80211_MESHCONF_CAPAB_TBTT_ADJUSTING : 0x00;
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700266 *pos++ = 0x00;
267
268 return 0;
269}
270
271int
272mesh_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
289int
290mesh_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
313int
314mesh_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
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700342int 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;
Johannes Berg55de9082012-07-26 17:24:39 +0200347 struct ieee80211_chanctx_conf *chanctx_conf;
348 struct ieee80211_channel *chan;
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700349 u8 *pos;
350
351 if (skb_tailroom(skb) < 3)
352 return -ENOMEM;
353
Johannes Berg55de9082012-07-26 17:24:39 +0200354 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 }
Johannes Berg4bf88532012-11-09 11:39:59 +0100360 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200361 rcu_read_unlock();
362
Johannes Berg6962d602012-07-23 14:29:21 +0200363 sband = local->hw.wiphy->bands[chan->band];
Rui Paulobe125c62009-11-09 23:46:54 +0000364 if (sband->band == IEEE80211_BAND_2GHZ) {
365 pos = skb_put(skb, 2 + 1);
366 *pos++ = WLAN_EID_DS_PARAMS;
367 *pos++ = 1;
Johannes Berg6962d602012-07-23 14:29:21 +0200368 *pos++ = ieee80211_frequency_to_channel(chan->center_freq);
Rui Paulobe125c62009-11-09 23:46:54 +0000369 }
370
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700371 return 0;
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100372}
373
Thomas Pedersen176f3602011-10-26 14:47:27 -0700374int mesh_add_ht_cap_ie(struct sk_buff *skb,
375 struct ieee80211_sub_if_data *sdata)
376{
377 struct ieee80211_local *local = sdata->local;
Johannes Berg55de9082012-07-26 17:24:39 +0200378 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Thomas Pedersen176f3602011-10-26 14:47:27 -0700379 struct ieee80211_supported_band *sband;
380 u8 *pos;
381
Johannes Berg55de9082012-07-26 17:24:39 +0200382 sband = local->hw.wiphy->bands[band];
Thomas Pedersen176f3602011-10-26 14:47:27 -0700383 if (!sband->ht_cap.ht_supported ||
Johannes Berg4bf88532012-11-09 11:39:59 +0100384 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Thomas Pedersen176f3602011-10-26 14:47:27 -0700385 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));
Ben Greearef96a8422011-11-18 11:32:00 -0800391 ieee80211_ie_build_ht_cap(pos, &sband->ht_cap, sband->ht_cap.cap);
Thomas Pedersen176f3602011-10-26 14:47:27 -0700392
393 return 0;
394}
395
Johannes Berg074d46d2012-03-15 19:45:16 +0100396int mesh_add_ht_oper_ie(struct sk_buff *skb,
Thomas Pedersen176f3602011-10-26 14:47:27 -0700397 struct ieee80211_sub_if_data *sdata)
398{
399 struct ieee80211_local *local = sdata->local;
Johannes Berg55de9082012-07-26 17:24:39 +0200400 struct ieee80211_chanctx_conf *chanctx_conf;
401 struct ieee80211_channel *channel;
Johannes Berg466f3102012-07-25 13:51:49 +0200402 enum nl80211_channel_type channel_type =
Johannes Berg4bf88532012-11-09 11:39:59 +0100403 cfg80211_get_chandef_type(&sdata->vif.bss_conf.chandef);
Johannes Berg55de9082012-07-26 17:24:39 +0200404 struct ieee80211_supported_band *sband;
405 struct ieee80211_sta_ht_cap *ht_cap;
Thomas Pedersen176f3602011-10-26 14:47:27 -0700406 u8 *pos;
407
Johannes Berg55de9082012-07-26 17:24:39 +0200408 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 }
Johannes Berg4bf88532012-11-09 11:39:59 +0100414 channel = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200415 rcu_read_unlock();
416
417 sband = local->hw.wiphy->bands[channel->band];
418 ht_cap = &sband->ht_cap;
419
Thomas Pedersen176f3602011-10-26 14:47:27 -0700420 if (!ht_cap->ht_supported || channel_type == NL80211_CHAN_NO_HT)
421 return 0;
422
Johannes Berg074d46d2012-03-15 19:45:16 +0100423 if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_operation))
Thomas Pedersen176f3602011-10-26 14:47:27 -0700424 return -ENOMEM;
425
Johannes Berg074d46d2012-03-15 19:45:16 +0100426 pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_operation));
Johannes Berg4bf88532012-11-09 11:39:59 +0100427 ieee80211_ie_build_ht_oper(pos, ht_cap, &sdata->vif.bss_conf.chandef,
Ashok Nagarajan431e3152012-04-30 14:20:29 -0700428 sdata->vif.bss_conf.ht_operation_mode);
Thomas Pedersen176f3602011-10-26 14:47:27 -0700429
430 return 0;
431}
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100432static void ieee80211_mesh_path_timer(unsigned long data)
433{
434 struct ieee80211_sub_if_data *sdata =
435 (struct ieee80211_sub_if_data *) data;
Johannes Berg472dbc42008-09-11 00:01:49 +0200436 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Johannes Berg133b8222008-09-16 14:18:59 +0200437 struct ieee80211_local *local = sdata->local;
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100438
Johannes Berg5bb644a2009-05-17 11:40:42 +0200439 if (local->quiescing) {
440 set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
441 return;
442 }
443
Johannes Berg64592c82010-06-10 10:21:31 +0200444 ieee80211_queue_work(&local->hw, &sdata->work);
Luis Carlos Cobo2e3c8732008-02-23 15:17:09 +0100445}
446
Rui Pauloe304bfd2009-11-09 23:46:56 +0000447static 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
Johannes Berg64592c82010-06-10 10:21:31 +0200461 ieee80211_queue_work(&local->hw, &sdata->work);
Rui Pauloe304bfd2009-11-09 23:46:56 +0000462}
463
Rui Paulo63c57232009-11-09 23:46:57 +0000464void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh)
465{
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +0800466 if (ifmsh->mshcfg.dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)
Rui Paulo63c57232009-11-09 23:46:57 +0000467 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
Johannes Berg902acc72008-02-23 15:17:19 +0100475/**
Javier Cardona3c5772a2009-08-10 12:15:48 -0700476 * 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 */
Johannes Berg15ff6362009-11-17 13:34:04 +0100485int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
486 const u8 *meshda, const u8 *meshsa)
487{
Javier Cardona3c5772a2009-08-10 12:15:48 -0700488 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 {
Javier Cardona2154c812011-09-07 17:49:53 -0700496 *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
Javier Cardona3c5772a2009-08-10 12:15:48 -0700497 /* 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
506/**
Johannes Berg902acc72008-02-23 15:17:19 +0100507 * ieee80211_new_mesh_header - create a new mesh header
508 * @meshhdr: uninitialized mesh header
509 * @sdata: mesh interface to be used
Javier Cardona61ad5392010-12-16 17:23:34 -0800510 * @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
Johannes Berg902acc72008-02-23 15:17:19 +0100515 *
516 * Return the header length.
517 */
518int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
Javier Cardona61ad5392010-12-16 17:23:34 -0800519 struct ieee80211_sub_if_data *sdata, char *addr4or5,
520 char *addr6)
Johannes Berg902acc72008-02-23 15:17:19 +0100521{
Javier Cardona3c5772a2009-08-10 12:15:48 -0700522 int aelen = 0;
Javier Cardona61ad5392010-12-16 17:23:34 -0800523 BUG_ON(!addr4or5 && addr6);
Julia Lawall0c3cee72009-12-09 20:25:59 +0100524 memset(meshhdr, 0, sizeof(*meshhdr));
Johannes Berg472dbc42008-09-11 00:01:49 +0200525 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++;
Javier Cardona61ad5392010-12-16 17:23:34 -0800528 if (addr4or5 && !addr6) {
Javier Cardona3c5772a2009-08-10 12:15:48 -0700529 meshhdr->flags |= MESH_FLAGS_AE_A4;
530 aelen += ETH_ALEN;
Javier Cardona61ad5392010-12-16 17:23:34 -0800531 memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
532 } else if (addr4or5 && addr6) {
Javier Cardona3c5772a2009-08-10 12:15:48 -0700533 meshhdr->flags |= MESH_FLAGS_AE_A5_A6;
534 aelen += 2 * ETH_ALEN;
Javier Cardona61ad5392010-12-16 17:23:34 -0800535 memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
536 memcpy(meshhdr->eaddr2, addr6, ETH_ALEN);
Javier Cardona3c5772a2009-08-10 12:15:48 -0700537 }
538 return 6 + aelen;
Johannes Berg902acc72008-02-23 15:17:19 +0100539}
540
Johannes Berg472dbc42008-09-11 00:01:49 +0200541static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
542 struct ieee80211_if_mesh *ifmsh)
543{
Marco Porschdf323812012-08-08 07:58:43 +0200544 u32 changed;
Johannes Berg472dbc42008-09-11 00:01:49 +0200545
Johannes Berg472dbc42008-09-11 00:01:49 +0200546 ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
547 mesh_path_expire(sdata);
548
Marco Porschdf323812012-08-08 07:58:43 +0200549 changed = mesh_accept_plinks_update(sdata);
550 ieee80211_bss_info_change_notify(sdata, changed);
Johannes Berg472dbc42008-09-11 00:01:49 +0200551
Johannes Berg472dbc42008-09-11 00:01:49 +0200552 mod_timer(&ifmsh->housekeeping_timer,
553 round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
554}
555
Rui Pauloe304bfd2009-11-09 23:46:56 +0000556static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata)
557{
558 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Chun-Yeow Yeoha69cc442012-06-14 02:06:07 +0800559 u32 interval;
Rui Pauloe304bfd2009-11-09 23:46:56 +0000560
561 mesh_path_tx_root_frame(sdata);
Chun-Yeow Yeoha69cc442012-06-14 02:06:07 +0800562
563 if (ifmsh->mshcfg.dot11MeshHWMPRootMode == IEEE80211_PROACTIVE_RANN)
564 interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval;
565 else
566 interval = ifmsh->mshcfg.dot11MeshHWMProotInterval;
567
Rui Pauloe304bfd2009-11-09 23:46:56 +0000568 mod_timer(&ifmsh->mesh_path_root_timer,
Chun-Yeow Yeoha69cc442012-06-14 02:06:07 +0800569 round_jiffies(TU_TO_EXP_TIME(interval)));
Rui Pauloe304bfd2009-11-09 23:46:56 +0000570}
571
Johannes Berg5bb644a2009-05-17 11:40:42 +0200572#ifdef CONFIG_PM
573void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
574{
575 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
576
Javier Cardona5ee68e52011-08-09 16:45:08 -0700577 /* use atomic bitops in case all timers fire at the same time */
Johannes Berg5bb644a2009-05-17 11:40:42 +0200578
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);
Rui Pauloe304bfd2009-11-09 23:46:56 +0000583 if (del_timer_sync(&ifmsh->mesh_path_root_timer))
584 set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
Johannes Berg5bb644a2009-05-17 11:40:42 +0200585}
586
587void 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);
Rui Pauloe304bfd2009-11-09 23:46:56 +0000595 if (test_and_clear_bit(TMR_RUNNING_MPR, &ifmsh->timers_running))
596 add_timer(&ifmsh->mesh_path_root_timer);
Rui Paulo63c57232009-11-09 23:46:57 +0000597 ieee80211_mesh_root_setup(ifmsh);
Johannes Berg5bb644a2009-05-17 11:40:42 +0200598}
599#endif
Johannes Berg472dbc42008-09-11 00:01:49 +0200600
601void 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;
Chun-Yeow Yeohf4eabc92012-12-13 18:59:57 +0800605 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);
Johannes Berg472dbc42008-09-11 00:01:49 +0200611
Johannes Berg09b17472010-12-03 09:20:41 +0100612 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
Javier Cardonac7108a72010-12-16 17:37:50 -0800617 ifmsh->mesh_cc_id = 0; /* Disabled */
Javier Cardonac7108a72010-12-16 17:37:50 -0800618 ifmsh->mesh_auth_id = 0; /* Disabled */
Javier Cardonadbf498f2012-03-31 11:31:32 -0700619 /* 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;
Rui Paulo6b9ac442009-10-20 21:21:48 +0100623 set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
Rui Paulo63c57232009-11-09 23:46:57 +0000624 ieee80211_mesh_root_setup(ifmsh);
Johannes Berg64592c82010-06-10 10:21:31 +0200625 ieee80211_queue_work(&local->hw, &sdata->work);
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -0700626 sdata->vif.bss_conf.ht_operation_mode =
627 ifmsh->mshcfg.ht_opmode;
Javier Cardona5b365832009-08-10 12:15:51 -0700628 sdata->vif.bss_conf.beacon_int = MESH_DEFAULT_BEACON_INTERVAL;
Johannes Bergd6a83222012-12-14 14:06:28 +0100629 sdata->vif.bss_conf.enable_beacon = true;
Ashok Nagarajand934f7d2012-04-02 21:21:19 -0700630 sdata->vif.bss_conf.basic_rates =
Chun-Yeow Yeohf4eabc92012-12-13 18:59:57 +0800631 ieee80211_mandatory_rates(local, band);
632
633 if (band == IEEE80211_BAND_5GHZ) {
634 sdata->vif.bss_conf.use_short_slot = true;
635 changed |= BSS_CHANGED_ERP_SLOT;
636 }
637
638 ieee80211_bss_info_change_notify(sdata, changed);
Johannes Bergc405c622012-07-30 19:44:12 +0200639
640 netif_carrier_on(sdata->dev);
Johannes Berg472dbc42008-09-11 00:01:49 +0200641}
642
643void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
644{
Johannes Berg09b17472010-12-03 09:20:41 +0100645 struct ieee80211_local *local = sdata->local;
Johannes Berg29cbe682010-12-03 09:20:44 +0100646 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
647
Johannes Bergc405c622012-07-30 19:44:12 +0200648 netif_carrier_off(sdata->dev);
649
Thomas Pedersen0d466b9c2012-08-03 12:21:32 -0700650 /* stop the beacon */
Johannes Berg29cbe682010-12-03 09:20:44 +0100651 ifmsh->mesh_id_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +0100652 sdata->vif.bss_conf.enable_beacon = false;
653 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg29cbe682010-12-03 09:20:44 +0100654 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Thomas Pedersen0d466b9c2012-08-03 12:21:32 -0700655
656 /* flush STAs and mpaths on this iface */
Johannes Bergb998e8b2012-12-13 23:07:46 +0100657 sta_info_flush(sdata);
Thomas Pedersen0d466b9c2012-08-03 12:21:32 -0700658 mesh_path_flush_by_iface(sdata);
Johannes Berg09b17472010-12-03 09:20:41 +0100659
Johannes Berg472dbc42008-09-11 00:01:49 +0200660 del_timer_sync(&sdata->u.mesh.housekeeping_timer);
Rui Pauloe304bfd2009-11-09 23:46:56 +0000661 del_timer_sync(&sdata->u.mesh.mesh_path_root_timer);
Johannes Bergdd4c9262012-08-01 21:03:21 +0200662 del_timer_sync(&sdata->u.mesh.mesh_path_timer);
Johannes Berg472dbc42008-09-11 00:01:49 +0200663 /*
Johannes Bergb7413432008-09-11 00:01:50 +0200664 * If the timer fired while we waited for it, it will have
665 * requeued the work. Now the work will be running again
666 * but will not rearm the timer again because it checks
667 * whether the interface is running, which, at this point,
668 * it no longer is.
669 */
Johannes Berg64592c82010-06-10 10:21:31 +0200670 cancel_work_sync(&sdata->work);
Johannes Berg09b17472010-12-03 09:20:41 +0100671
672 local->fif_other_bss--;
673 atomic_dec(&local->iff_allmultis);
674 ieee80211_configure_filter(local);
Johannes Berg2d9957c2012-08-01 20:54:52 +0200675
676 sdata->u.mesh.timers_running = 0;
Johannes Berg472dbc42008-09-11 00:01:49 +0200677}
678
679static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
680 u16 stype,
681 struct ieee80211_mgmt *mgmt,
682 size_t len,
683 struct ieee80211_rx_status *rx_status)
684{
Johannes Bergc6a1fa12008-10-07 12:04:32 +0200685 struct ieee80211_local *local = sdata->local;
Javier Cardonadbf498f2012-03-31 11:31:32 -0700686 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Johannes Berg472dbc42008-09-11 00:01:49 +0200687 struct ieee802_11_elems elems;
688 struct ieee80211_channel *channel;
Johannes Berg472dbc42008-09-11 00:01:49 +0200689 size_t baselen;
690 int freq;
691 enum ieee80211_band band = rx_status->band;
692
693 /* ignore ProbeResp to foreign address */
694 if (stype == IEEE80211_STYPE_PROBE_RESP &&
Joe Perchesb203ca32012-05-08 18:56:52 +0000695 !ether_addr_equal(mgmt->da, sdata->vif.addr))
Johannes Berg472dbc42008-09-11 00:01:49 +0200696 return;
697
698 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
699 if (baselen > len)
700 return;
701
702 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
703 &elems);
704
Thomas Pedersen9a90bc82012-10-20 19:03:10 -0700705 /* ignore non-mesh or secure / unsecure mismatch */
706 if ((!elems.mesh_id || !elems.mesh_config) ||
707 (elems.rsn && sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) ||
708 (!elems.rsn && sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE))
Javier Cardona5cff5e02011-04-07 15:08:29 -0700709 return;
710
Johannes Berg472dbc42008-09-11 00:01:49 +0200711 if (elems.ds_params && elems.ds_params_len == 1)
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900712 freq = ieee80211_channel_to_frequency(elems.ds_params[0], band);
Johannes Berg472dbc42008-09-11 00:01:49 +0200713 else
714 freq = rx_status->freq;
715
716 channel = ieee80211_get_channel(local->hw.wiphy, freq);
717
718 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
719 return;
720
Thomas Pedersen9a90bc82012-10-20 19:03:10 -0700721 if (mesh_matches_local(sdata, &elems))
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700722 mesh_neighbour_update(sdata, mgmt->sa, &elems);
Javier Cardonadbf498f2012-03-31 11:31:32 -0700723
724 if (ifmsh->sync_ops)
725 ifmsh->sync_ops->rx_bcn_presp(sdata,
726 stype, mgmt, &elems, rx_status);
Johannes Berg472dbc42008-09-11 00:01:49 +0200727}
728
729static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
730 struct ieee80211_mgmt *mgmt,
731 size_t len,
732 struct ieee80211_rx_status *rx_status)
733{
734 switch (mgmt->u.action.category) {
Thomas Pedersen8db09852011-08-12 20:01:00 -0700735 case WLAN_CATEGORY_SELF_PROTECTED:
736 switch (mgmt->u.action.u.self_prot.action_code) {
737 case WLAN_SP_MESH_PEERING_OPEN:
738 case WLAN_SP_MESH_PEERING_CLOSE:
739 case WLAN_SP_MESH_PEERING_CONFIRM:
740 mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
741 break;
742 }
Johannes Berg472dbc42008-09-11 00:01:49 +0200743 break;
Thomas Pedersen25d49e42011-08-11 19:35:15 -0700744 case WLAN_CATEGORY_MESH_ACTION:
745 if (mesh_action_is_path_sel(mgmt))
746 mesh_rx_path_sel_frame(sdata, mgmt, len);
Johannes Berg472dbc42008-09-11 00:01:49 +0200747 break;
748 }
749}
750
Johannes Berg1fa57d02010-06-10 10:21:32 +0200751void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
752 struct sk_buff *skb)
Johannes Berg472dbc42008-09-11 00:01:49 +0200753{
754 struct ieee80211_rx_status *rx_status;
Johannes Berg472dbc42008-09-11 00:01:49 +0200755 struct ieee80211_mgmt *mgmt;
756 u16 stype;
757
Johannes Bergf1d58c22009-06-17 13:13:00 +0200758 rx_status = IEEE80211_SKB_RXCB(skb);
Johannes Berg472dbc42008-09-11 00:01:49 +0200759 mgmt = (struct ieee80211_mgmt *) skb->data;
760 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
761
762 switch (stype) {
763 case IEEE80211_STYPE_PROBE_RESP:
764 case IEEE80211_STYPE_BEACON:
765 ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
766 rx_status);
767 break;
768 case IEEE80211_STYPE_ACTION:
769 ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
770 break;
771 }
Johannes Berg472dbc42008-09-11 00:01:49 +0200772}
773
Johannes Berg1fa57d02010-06-10 10:21:32 +0200774void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg472dbc42008-09-11 00:01:49 +0200775{
Johannes Berg472dbc42008-09-11 00:01:49 +0200776 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Johannes Berg472dbc42008-09-11 00:01:49 +0200777
778 if (ifmsh->preq_queue_len &&
779 time_after(jiffies,
780 ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
781 mesh_path_start_discovery(sdata);
782
Javier Cardona18889232009-08-10 12:15:52 -0700783 if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
784 mesh_mpath_table_grow();
785
Nick Ledovskikhdcac9082011-01-11 14:35:12 +0000786 if (test_and_clear_bit(MESH_WORK_GROW_MPP_TABLE, &ifmsh->wrkq_flags))
Javier Cardona18889232009-08-10 12:15:52 -0700787 mesh_mpp_table_grow();
788
789 if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
Johannes Berg472dbc42008-09-11 00:01:49 +0200790 ieee80211_mesh_housekeeping(sdata, ifmsh);
Rui Pauloe304bfd2009-11-09 23:46:56 +0000791
792 if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags))
793 ieee80211_mesh_rootpath(sdata);
Javier Cardonadbf498f2012-03-31 11:31:32 -0700794
795 if (test_and_clear_bit(MESH_WORK_DRIFT_ADJUST, &ifmsh->wrkq_flags))
796 mesh_sync_adjust_tbtt(sdata);
Johannes Berg472dbc42008-09-11 00:01:49 +0200797}
798
799void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
800{
801 struct ieee80211_sub_if_data *sdata;
802
803 rcu_read_lock();
804 list_for_each_entry_rcu(sdata, &local->interfaces, list)
805 if (ieee80211_vif_is_mesh(&sdata->vif))
Johannes Berg64592c82010-06-10 10:21:31 +0200806 ieee80211_queue_work(&local->hw, &sdata->work);
Johannes Berg472dbc42008-09-11 00:01:49 +0200807 rcu_read_unlock();
808}
809
Johannes Berg902acc72008-02-23 15:17:19 +0100810void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
811{
Johannes Berg472dbc42008-09-11 00:01:49 +0200812 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Johannes Bergad2d2232012-12-14 14:34:25 +0100813 static u8 zero_addr[ETH_ALEN] = {};
Johannes Berg902acc72008-02-23 15:17:19 +0100814
Johannes Berg472dbc42008-09-11 00:01:49 +0200815 setup_timer(&ifmsh->housekeeping_timer,
816 ieee80211_mesh_housekeeping_timer,
817 (unsigned long) sdata);
Johannes Berg472dbc42008-09-11 00:01:49 +0200818
Johannes Berg472dbc42008-09-11 00:01:49 +0200819 ifmsh->accepting_plinks = true;
820 ifmsh->preq_id = 0;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000821 ifmsh->sn = 0;
Javier Cardona5ee68e52011-08-09 16:45:08 -0700822 ifmsh->num_gates = 0;
Johannes Berg472dbc42008-09-11 00:01:49 +0200823 atomic_set(&ifmsh->mpaths, 0);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200824 mesh_rmc_init(sdata);
Johannes Berg472dbc42008-09-11 00:01:49 +0200825 ifmsh->last_preq = jiffies;
Thomas Pedersendca7e942011-11-24 17:15:24 -0800826 ifmsh->next_perr = jiffies;
Johannes Berg902acc72008-02-23 15:17:19 +0100827 /* Allocate all mesh structures when creating the first mesh interface. */
828 if (!mesh_allocated)
829 ieee80211s_init();
Johannes Berg472dbc42008-09-11 00:01:49 +0200830 setup_timer(&ifmsh->mesh_path_timer,
Johannes Berg902acc72008-02-23 15:17:19 +0100831 ieee80211_mesh_path_timer,
832 (unsigned long) sdata);
Rui Pauloe304bfd2009-11-09 23:46:56 +0000833 setup_timer(&ifmsh->mesh_path_root_timer,
834 ieee80211_mesh_path_root_timer,
835 (unsigned long) sdata);
Johannes Berg472dbc42008-09-11 00:01:49 +0200836 INIT_LIST_HEAD(&ifmsh->preq_queue.list);
837 spin_lock_init(&ifmsh->mesh_preq_queue_lock);
Javier Cardonadbf498f2012-03-31 11:31:32 -0700838 spin_lock_init(&ifmsh->sync_offset_lock);
Johannes Bergad2d2232012-12-14 14:34:25 +0100839
840 sdata->vif.bss_conf.bssid = zero_addr;
Johannes Berg472dbc42008-09-11 00:01:49 +0200841}