xref: /linux/net/mac80211/mesh.h (revision f81a9dedaff434604c7fc3d9c299d277b76db0a8)
1ccf80ddfSLuis Carlos Cobo /*
2264d9b7dSRui Paulo  * Copyright (c) 2008, 2009 open80211s Ltd.
3ccf80ddfSLuis Carlos Cobo  * Authors:    Luis Carlos Cobo <luisca@cozybit.com>
4ccf80ddfSLuis Carlos Cobo  *             Javier Cardona <javier@cozybit.com>
5ccf80ddfSLuis Carlos Cobo  *
6ccf80ddfSLuis Carlos Cobo  * This program is free software; you can redistribute it and/or modify
7ccf80ddfSLuis Carlos Cobo  * it under the terms of the GNU General Public License version 2 as
8ccf80ddfSLuis Carlos Cobo  * published by the Free Software Foundation.
9ccf80ddfSLuis Carlos Cobo  */
10ccf80ddfSLuis Carlos Cobo 
11ccf80ddfSLuis Carlos Cobo #ifndef IEEE80211S_H
12ccf80ddfSLuis Carlos Cobo #define IEEE80211S_H
13ccf80ddfSLuis Carlos Cobo 
14902acc78SJohannes Berg #include <linux/types.h>
15ccf80ddfSLuis Carlos Cobo #include <linux/jhash.h>
16902acc78SJohannes Berg #include "ieee80211_i.h"
17ccf80ddfSLuis Carlos Cobo 
18ccf80ddfSLuis Carlos Cobo 
19ccf80ddfSLuis Carlos Cobo /* Data structures */
20ccf80ddfSLuis Carlos Cobo 
21ccf80ddfSLuis Carlos Cobo /**
22ccf80ddfSLuis Carlos Cobo  * enum mesh_path_flags - mac80211 mesh path flags
23ccf80ddfSLuis Carlos Cobo  *
24ccf80ddfSLuis Carlos Cobo  *
25ccf80ddfSLuis Carlos Cobo  *
26eb80ed8dSRami Rosen  * @MESH_PATH_ACTIVE: the mesh path can be used for forwarding
27eb80ed8dSRami Rosen  * @MESH_PATH_RESOLVING: the discovery process is running for this mesh path
28d19b3bf6SRui Paulo  * @MESH_PATH_SN_VALID: the mesh path contains a valid destination sequence
29ccf80ddfSLuis Carlos Cobo  *	number
30ccf80ddfSLuis Carlos Cobo  * @MESH_PATH_FIXED: the mesh path has been manually set and should not be
31ccf80ddfSLuis Carlos Cobo  *	modified
32ccf80ddfSLuis Carlos Cobo  * @MESH_PATH_RESOLVED: the mesh path can has been resolved
33f3011cf9SJavier Cardona  * @MESH_PATH_REQ_QUEUED: there is an unsent path request for this destination
34f3011cf9SJavier Cardona  *	already queued up, waiting for the discovery process to start.
35ccf80ddfSLuis Carlos Cobo  *
36eb80ed8dSRami Rosen  * MESH_PATH_RESOLVED is used by the mesh path timer to
37ccf80ddfSLuis Carlos Cobo  * decide when to stop or cancel the mesh path discovery.
38ccf80ddfSLuis Carlos Cobo  */
39ccf80ddfSLuis Carlos Cobo enum mesh_path_flags {
40ccf80ddfSLuis Carlos Cobo 	MESH_PATH_ACTIVE =	BIT(0),
41ccf80ddfSLuis Carlos Cobo 	MESH_PATH_RESOLVING =	BIT(1),
42d19b3bf6SRui Paulo 	MESH_PATH_SN_VALID =	BIT(2),
43ccf80ddfSLuis Carlos Cobo 	MESH_PATH_FIXED	=	BIT(3),
44ccf80ddfSLuis Carlos Cobo 	MESH_PATH_RESOLVED =	BIT(4),
45f3011cf9SJavier Cardona 	MESH_PATH_REQ_QUEUED =	BIT(5),
46ccf80ddfSLuis Carlos Cobo };
47ccf80ddfSLuis Carlos Cobo 
48ccf80ddfSLuis Carlos Cobo /**
4918889231SJavier Cardona  * enum mesh_deferred_task_flags - mac80211 mesh deferred tasks
5018889231SJavier Cardona  *
5118889231SJavier Cardona  *
5218889231SJavier Cardona  *
5318889231SJavier Cardona  * @MESH_WORK_HOUSEKEEPING: run the periodic mesh housekeeping tasks
5418889231SJavier Cardona  * @MESH_WORK_GROW_MPATH_TABLE: the mesh path table is full and needs
5518889231SJavier Cardona  * to grow.
5618889231SJavier Cardona  * @MESH_WORK_GROW_MPP_TABLE: the mesh portals table is full and needs to
5718889231SJavier Cardona  * grow
58e304bfd3SRui Paulo  * @MESH_WORK_ROOT: the mesh root station needs to send a frame
59dbf498fbSJavier Cardona  * @MESH_WORK_DRIFT_ADJUST: time to compensate for clock drift relative to other
60dbf498fbSJavier Cardona  * mesh nodes
61*f81a9dedSThomas Pedersen  * @MESH_WORK_MBSS_CHANGED: rebuild beacon and notify driver of BSS changes
6218889231SJavier Cardona  */
6318889231SJavier Cardona enum mesh_deferred_task_flags {
6418889231SJavier Cardona 	MESH_WORK_HOUSEKEEPING,
6518889231SJavier Cardona 	MESH_WORK_GROW_MPATH_TABLE,
6618889231SJavier Cardona 	MESH_WORK_GROW_MPP_TABLE,
67e304bfd3SRui Paulo 	MESH_WORK_ROOT,
68dbf498fbSJavier Cardona 	MESH_WORK_DRIFT_ADJUST,
69*f81a9dedSThomas Pedersen 	MESH_WORK_MBSS_CHANGED,
7018889231SJavier Cardona };
7118889231SJavier Cardona 
7218889231SJavier Cardona /**
73ccf80ddfSLuis Carlos Cobo  * struct mesh_path - mac80211 mesh path structure
74ccf80ddfSLuis Carlos Cobo  *
75ccf80ddfSLuis Carlos Cobo  * @dst: mesh path destination mac address
76f698d856SJasper Bryant-Greene  * @sdata: mesh subif
77ccf80ddfSLuis Carlos Cobo  * @next_hop: mesh neighbor to which frames for this destination will be
78ccf80ddfSLuis Carlos Cobo  *	forwarded
79ccf80ddfSLuis Carlos Cobo  * @timer: mesh path discovery timer
80ccf80ddfSLuis Carlos Cobo  * @frame_queue: pending queue for frames sent to this destination while the
81ccf80ddfSLuis Carlos Cobo  *	path is unresolved
82d19b3bf6SRui Paulo  * @sn: target sequence number
83ccf80ddfSLuis Carlos Cobo  * @metric: current metric to this destination
84ccf80ddfSLuis Carlos Cobo  * @hop_count: hops to destination
85ccf80ddfSLuis Carlos Cobo  * @exp_time: in jiffies, when the path will expire or when it expired
86ccf80ddfSLuis Carlos Cobo  * @discovery_timeout: timeout (lapse in jiffies) used for the last discovery
87ccf80ddfSLuis Carlos Cobo  *	retry
88ccf80ddfSLuis Carlos Cobo  * @discovery_retries: number of discovery retries
89ccf80ddfSLuis Carlos Cobo  * @flags: mesh path flags, as specified on &enum mesh_path_flags
90f5e50cd0SJavier Cardona  * @state_lock: mesh path state lock used to protect changes to the
91f5e50cd0SJavier Cardona  * mpath itself.  No need to take this lock when adding or removing
92f5e50cd0SJavier Cardona  * an mpath to a hash bucket on a path table.
933d045a54SChun-Yeow Yeoh  * @rann_snd_addr: the RANN sender address
94d2a079fdSChun-Yeow Yeoh  * @rann_metric: the aggregated path metric towards the root node
95728b19e5SChun-Yeow Yeoh  * @last_preq_to_root: Timestamp of last PREQ sent to root
963d045a54SChun-Yeow Yeoh  * @is_root: the destination station of this path is a root node
975ee68e5bSJavier Cardona  * @is_gate: the destination station of this path is a mesh gate
98ccf80ddfSLuis Carlos Cobo  *
99ccf80ddfSLuis Carlos Cobo  *
100f698d856SJasper Bryant-Greene  * The combination of dst and sdata is unique in the mesh path table. Since the
101d0709a65SJohannes Berg  * next_hop STA is only protected by RCU as well, deleting the STA must also
102d0709a65SJohannes Berg  * remove/substitute the mesh_path structure and wait until that is no longer
103d0709a65SJohannes Berg  * reachable before destroying the STA completely.
104ccf80ddfSLuis Carlos Cobo  */
105ccf80ddfSLuis Carlos Cobo struct mesh_path {
106ccf80ddfSLuis Carlos Cobo 	u8 dst[ETH_ALEN];
10779617deeSYanBo 	u8 mpp[ETH_ALEN];	/* used for MPP or MAP */
108f698d856SJasper Bryant-Greene 	struct ieee80211_sub_if_data *sdata;
10940b275b6SJohannes Berg 	struct sta_info __rcu *next_hop;
110ccf80ddfSLuis Carlos Cobo 	struct timer_list timer;
111ccf80ddfSLuis Carlos Cobo 	struct sk_buff_head frame_queue;
112ccf80ddfSLuis Carlos Cobo 	struct rcu_head rcu;
113d19b3bf6SRui Paulo 	u32 sn;
114ccf80ddfSLuis Carlos Cobo 	u32 metric;
115ccf80ddfSLuis Carlos Cobo 	u8 hop_count;
116ccf80ddfSLuis Carlos Cobo 	unsigned long exp_time;
117ccf80ddfSLuis Carlos Cobo 	u32 discovery_timeout;
118ccf80ddfSLuis Carlos Cobo 	u8 discovery_retries;
119ccf80ddfSLuis Carlos Cobo 	enum mesh_path_flags flags;
120ccf80ddfSLuis Carlos Cobo 	spinlock_t state_lock;
1213d045a54SChun-Yeow Yeoh 	u8 rann_snd_addr[ETH_ALEN];
122d2a079fdSChun-Yeow Yeoh 	u32 rann_metric;
123728b19e5SChun-Yeow Yeoh 	unsigned long last_preq_to_root;
1243d045a54SChun-Yeow Yeoh 	bool is_root;
1255ee68e5bSJavier Cardona 	bool is_gate;
126ccf80ddfSLuis Carlos Cobo };
127ccf80ddfSLuis Carlos Cobo 
128ccf80ddfSLuis Carlos Cobo /**
129ccf80ddfSLuis Carlos Cobo  * struct mesh_table
130ccf80ddfSLuis Carlos Cobo  *
131ccf80ddfSLuis Carlos Cobo  * @hash_buckets: array of hash buckets of the table
132ccf80ddfSLuis Carlos Cobo  * @hashwlock: array of locks to protect write operations, one per bucket
133ccf80ddfSLuis Carlos Cobo  * @hash_mask: 2^size_order - 1, used to compute hash idx
134ccf80ddfSLuis Carlos Cobo  * @hash_rnd: random value used for hash computations
135ccf80ddfSLuis Carlos Cobo  * @entries: number of entries in the table
136ccf80ddfSLuis Carlos Cobo  * @free_node: function to free nodes of the table
137eef35c2dSStefan Weil  * @copy_node: function to copy nodes of the table
138ccf80ddfSLuis Carlos Cobo  * @size_order: determines size of the table, there will be 2^size_order hash
139ccf80ddfSLuis Carlos Cobo  *	buckets
140ccf80ddfSLuis Carlos Cobo  * @mean_chain_len: maximum average length for the hash buckets' list, if it is
141ccf80ddfSLuis Carlos Cobo  *	reached, the table will grow
1425ee68e5bSJavier Cardona  * @known_gates: list of known mesh gates and their mpaths by the station. The
1435ee68e5bSJavier Cardona  * gate's mpath may or may not be resolved and active.
1445ee68e5bSJavier Cardona  *
1451928ecabSJohannes Berg  * rcu_head: RCU head to free the table
146ccf80ddfSLuis Carlos Cobo  */
147ccf80ddfSLuis Carlos Cobo struct mesh_table {
148ccf80ddfSLuis Carlos Cobo 	/* Number of buckets will be 2^N */
149ccf80ddfSLuis Carlos Cobo 	struct hlist_head *hash_buckets;
150ccf80ddfSLuis Carlos Cobo 	spinlock_t *hashwlock;		/* One per bucket, for add/del */
151ccf80ddfSLuis Carlos Cobo 	unsigned int hash_mask;		/* (2^size_order) - 1 */
152ccf80ddfSLuis Carlos Cobo 	__u32 hash_rnd;			/* Used for hash generation */
153ccf80ddfSLuis Carlos Cobo 	atomic_t entries;		/* Up to MAX_MESH_NEIGHBOURS */
154ccf80ddfSLuis Carlos Cobo 	void (*free_node) (struct hlist_node *p, bool free_leafs);
1554caf86c6SPavel Emelyanov 	int (*copy_node) (struct hlist_node *p, struct mesh_table *newtbl);
156ccf80ddfSLuis Carlos Cobo 	int size_order;
157ccf80ddfSLuis Carlos Cobo 	int mean_chain_len;
1585ee68e5bSJavier Cardona 	struct hlist_head *known_gates;
1595ee68e5bSJavier Cardona 	spinlock_t gates_lock;
1601928ecabSJohannes Berg 
1611928ecabSJohannes Berg 	struct rcu_head rcu_head;
162ccf80ddfSLuis Carlos Cobo };
163ccf80ddfSLuis Carlos Cobo 
164ccf80ddfSLuis Carlos Cobo /* Recent multicast cache */
165ccf80ddfSLuis Carlos Cobo /* RMC_BUCKETS must be a power of 2, maximum 256 */
166ccf80ddfSLuis Carlos Cobo #define RMC_BUCKETS		256
167ccf80ddfSLuis Carlos Cobo #define RMC_QUEUE_MAX_LEN	4
168ccf80ddfSLuis Carlos Cobo #define RMC_TIMEOUT		(3 * HZ)
169ccf80ddfSLuis Carlos Cobo 
170ccf80ddfSLuis Carlos Cobo /**
171ccf80ddfSLuis Carlos Cobo  * struct rmc_entry - entry in the Recent Multicast Cache
172ccf80ddfSLuis Carlos Cobo  *
173ccf80ddfSLuis Carlos Cobo  * @seqnum: mesh sequence number of the frame
174ccf80ddfSLuis Carlos Cobo  * @exp_time: expiration time of the entry, in jiffies
175ccf80ddfSLuis Carlos Cobo  * @sa: source address of the frame
176ccf80ddfSLuis Carlos Cobo  *
177ccf80ddfSLuis Carlos Cobo  * The Recent Multicast Cache keeps track of the latest multicast frames that
178ccf80ddfSLuis Carlos Cobo  * have been received by a mesh interface and discards received multicast frames
179ccf80ddfSLuis Carlos Cobo  * that are found in the cache.
180ccf80ddfSLuis Carlos Cobo  */
181ccf80ddfSLuis Carlos Cobo struct rmc_entry {
182ccf80ddfSLuis Carlos Cobo 	struct list_head list;
183ccf80ddfSLuis Carlos Cobo 	u32 seqnum;
184ccf80ddfSLuis Carlos Cobo 	unsigned long exp_time;
185ccf80ddfSLuis Carlos Cobo 	u8 sa[ETH_ALEN];
186ccf80ddfSLuis Carlos Cobo };
187ccf80ddfSLuis Carlos Cobo 
188ccf80ddfSLuis Carlos Cobo struct mesh_rmc {
189b7cfcd11SThomas Pedersen 	struct list_head bucket[RMC_BUCKETS];
19051ceddadSLuis Carlos Cobo 	u32 idx_mask;
191ccf80ddfSLuis Carlos Cobo };
192ccf80ddfSLuis Carlos Cobo 
19325d49e4dSThomas Pedersen #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
194ccf80ddfSLuis Carlos Cobo 
195ccf80ddfSLuis Carlos Cobo #define MESH_PATH_EXPIRE (600 * HZ)
196ccf80ddfSLuis Carlos Cobo 
197ccf80ddfSLuis Carlos Cobo /* Default maximum number of plinks per interface */
198ccf80ddfSLuis Carlos Cobo #define MESH_MAX_PLINKS		256
199ccf80ddfSLuis Carlos Cobo 
200ccf80ddfSLuis Carlos Cobo /* Maximum number of paths per interface */
201ccf80ddfSLuis Carlos Cobo #define MESH_MAX_MPATHS		1024
202ccf80ddfSLuis Carlos Cobo 
2034bd4c2ddSThomas Pedersen /* Number of frames buffered per destination for unresolved destinations */
2044bd4c2ddSThomas Pedersen #define MESH_FRAME_QUEUE_LEN	10
2054bd4c2ddSThomas Pedersen 
206ccf80ddfSLuis Carlos Cobo /* Public interfaces */
207ccf80ddfSLuis Carlos Cobo /* Various */
2083c5772a5SJavier Cardona int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
20915ff6365SJohannes Berg 				  const u8 *da, const u8 *sa);
210bf7cd94dSJohannes Berg int ieee80211_new_mesh_header(struct ieee80211_sub_if_data *sdata,
211bf7cd94dSJohannes Berg 			      struct ieee80211s_hdr *meshhdr,
212bf7cd94dSJohannes Berg 			      const char *addr4or5, const char *addr6);
213bf7cd94dSJohannes Berg int mesh_rmc_check(struct ieee80211_sub_if_data *sdata,
214bf7cd94dSJohannes Berg 		   const u8 *addr, struct ieee80211s_hdr *mesh_hdr);
215f743ff49SThomas Pedersen bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
216f743ff49SThomas Pedersen 			struct ieee802_11_elems *ie);
217472dbc45SJohannes Berg void mesh_ids_set_default(struct ieee80211_if_mesh *mesh);
218bf7cd94dSJohannes Berg void mesh_mgmt_ies_add(struct ieee80211_sub_if_data *sdata,
219bf7cd94dSJohannes Berg 		       struct sk_buff *skb);
220bf7cd94dSJohannes Berg int mesh_add_meshconf_ie(struct ieee80211_sub_if_data *sdata,
221bf7cd94dSJohannes Berg 			 struct sk_buff *skb);
222bf7cd94dSJohannes Berg int mesh_add_meshid_ie(struct ieee80211_sub_if_data *sdata,
223bf7cd94dSJohannes Berg 		       struct sk_buff *skb);
224bf7cd94dSJohannes Berg int mesh_add_rsn_ie(struct ieee80211_sub_if_data *sdata,
225bf7cd94dSJohannes Berg 		    struct sk_buff *skb);
226bf7cd94dSJohannes Berg int mesh_add_vendor_ies(struct ieee80211_sub_if_data *sdata,
227bf7cd94dSJohannes Berg 			struct sk_buff *skb);
228bf7cd94dSJohannes Berg int mesh_add_ht_cap_ie(struct ieee80211_sub_if_data *sdata,
229bf7cd94dSJohannes Berg 		       struct sk_buff *skb);
230bf7cd94dSJohannes Berg int mesh_add_ht_oper_ie(struct ieee80211_sub_if_data *sdata,
231bf7cd94dSJohannes Berg 			struct sk_buff *skb);
232f698d856SJasper Bryant-Greene void mesh_rmc_free(struct ieee80211_sub_if_data *sdata);
233f698d856SJasper Bryant-Greene int mesh_rmc_init(struct ieee80211_sub_if_data *sdata);
234ccf80ddfSLuis Carlos Cobo void ieee80211s_init(void);
235bfc32e6aSJavier Cardona void ieee80211s_update_metric(struct ieee80211_local *local,
23635b3fe1cSJavier Cardona 			      struct sta_info *sta, struct sk_buff *skb);
237902acc78SJohannes Berg void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata);
2382b5e1967SThomas Pedersen int ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata);
239472dbc45SJohannes Berg void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata);
24063c5723bSRui Paulo void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh);
2418ba7acf3SJohannes Berg const struct ieee80211_mesh_sync_ops *ieee80211_mesh_sync_ops_get(u8 method);
2422b5e1967SThomas Pedersen /* wrapper for ieee80211_bss_info_change_notify() */
2432b5e1967SThomas Pedersen void ieee80211_mbss_info_change_notify(struct ieee80211_sub_if_data *sdata,
2442b5e1967SThomas Pedersen 				       u32 changed);
245902acc78SJohannes Berg 
2463f52b7e3SMarco Porsch /* mesh power save */
24739886b61SThomas Pedersen u32 ieee80211_mps_local_status_update(struct ieee80211_sub_if_data *sdata);
24839886b61SThomas Pedersen u32 ieee80211_mps_set_sta_local_pm(struct sta_info *sta,
2493f52b7e3SMarco Porsch 				   enum nl80211_mesh_power_mode pm);
2503f52b7e3SMarco Porsch void ieee80211_mps_set_frame_flags(struct ieee80211_sub_if_data *sdata,
2513f52b7e3SMarco Porsch 				   struct sta_info *sta,
2523f52b7e3SMarco Porsch 				   struct ieee80211_hdr *hdr);
2533f52b7e3SMarco Porsch void ieee80211_mps_sta_status_update(struct sta_info *sta);
2543f52b7e3SMarco Porsch void ieee80211_mps_rx_h_sta_process(struct sta_info *sta,
2553f52b7e3SMarco Porsch 				    struct ieee80211_hdr *hdr);
2563f52b7e3SMarco Porsch void ieee80211_mpsp_trigger_process(u8 *qc, struct sta_info *sta,
2573f52b7e3SMarco Porsch 				    bool tx, bool acked);
2583f52b7e3SMarco Porsch void ieee80211_mps_frame_release(struct sta_info *sta,
2593f52b7e3SMarco Porsch 				 struct ieee802_11_elems *elems);
2603f52b7e3SMarco Porsch 
261ccf80ddfSLuis Carlos Cobo /* Mesh paths */
262bf7cd94dSJohannes Berg int mesh_nexthop_lookup(struct ieee80211_sub_if_data *sdata,
263bf7cd94dSJohannes Berg 			struct sk_buff *skb);
264bf7cd94dSJohannes Berg int mesh_nexthop_resolve(struct ieee80211_sub_if_data *sdata,
265bf7cd94dSJohannes Berg 			 struct sk_buff *skb);
266f698d856SJasper Bryant-Greene void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata);
267bf7cd94dSJohannes Berg struct mesh_path *mesh_path_lookup(struct ieee80211_sub_if_data *sdata,
268bf7cd94dSJohannes Berg 				   const u8 *dst);
269bf7cd94dSJohannes Berg struct mesh_path *mpp_path_lookup(struct ieee80211_sub_if_data *sdata,
270bf7cd94dSJohannes Berg 				  const u8 *dst);
271bf7cd94dSJohannes Berg int mpp_path_add(struct ieee80211_sub_if_data *sdata,
272bf7cd94dSJohannes Berg 		 const u8 *dst, const u8 *mpp);
273bf7cd94dSJohannes Berg struct mesh_path *
274bf7cd94dSJohannes Berg mesh_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx);
275ccf80ddfSLuis Carlos Cobo void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop);
276f698d856SJasper Bryant-Greene void mesh_path_expire(struct ieee80211_sub_if_data *sdata);
277f698d856SJasper Bryant-Greene void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata,
278f698d856SJasper Bryant-Greene 			    struct ieee80211_mgmt *mgmt, size_t len);
279ae76eef0SBob Copeland struct mesh_path *
280ae76eef0SBob Copeland mesh_path_add(struct ieee80211_sub_if_data *sdata, const u8 *dst);
2815ee68e5bSJavier Cardona 
2825ee68e5bSJavier Cardona int mesh_path_add_gate(struct mesh_path *mpath);
2835ee68e5bSJavier Cardona int mesh_path_send_to_gates(struct mesh_path *mpath);
2845ee68e5bSJavier Cardona int mesh_gate_num(struct ieee80211_sub_if_data *sdata);
285bf7cd94dSJohannes Berg 
286ccf80ddfSLuis Carlos Cobo /* Mesh plinks */
287f743ff49SThomas Pedersen void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
288bf7cd94dSJohannes Berg 			   u8 *hw_addr, struct ieee802_11_elems *ie);
289f698d856SJasper Bryant-Greene bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie);
290df323818SMarco Porsch u32 mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata);
291ccf80ddfSLuis Carlos Cobo void mesh_plink_broken(struct sta_info *sta);
29245b5028eSThomas Pedersen u32 mesh_plink_deactivate(struct sta_info *sta);
29339886b61SThomas Pedersen u32 mesh_plink_open(struct sta_info *sta);
29439886b61SThomas Pedersen u32 mesh_plink_block(struct sta_info *sta);
295f698d856SJasper Bryant-Greene void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata,
296f698d856SJasper Bryant-Greene 			 struct ieee80211_mgmt *mgmt, size_t len,
297f698d856SJasper Bryant-Greene 			 struct ieee80211_rx_status *rx_status);
29845b5028eSThomas Pedersen void mesh_sta_cleanup(struct sta_info *sta);
299ccf80ddfSLuis Carlos Cobo 
300ccf80ddfSLuis Carlos Cobo /* Private interfaces */
301ccf80ddfSLuis Carlos Cobo /* Mesh tables */
30218889231SJavier Cardona void mesh_mpath_table_grow(void);
30318889231SJavier Cardona void mesh_mpp_table_grow(void);
304ccf80ddfSLuis Carlos Cobo /* Mesh paths */
305bf7cd94dSJohannes Berg int mesh_path_error_tx(struct ieee80211_sub_if_data *sdata,
306bf7cd94dSJohannes Berg 		       u8 ttl, const u8 *target, __le32 target_sn,
307bf7cd94dSJohannes Berg 		       __le16 target_rcode, const u8 *ra);
308ccf80ddfSLuis Carlos Cobo void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta);
309ccf80ddfSLuis Carlos Cobo void mesh_path_flush_pending(struct mesh_path *mpath);
310ccf80ddfSLuis Carlos Cobo void mesh_path_tx_pending(struct mesh_path *mpath);
311ccf80ddfSLuis Carlos Cobo int mesh_pathtbl_init(void);
312ccf80ddfSLuis Carlos Cobo void mesh_pathtbl_unregister(void);
313bf7cd94dSJohannes Berg int mesh_path_del(struct ieee80211_sub_if_data *sdata, const u8 *addr);
314ccf80ddfSLuis Carlos Cobo void mesh_path_timer(unsigned long data);
315ccf80ddfSLuis Carlos Cobo void mesh_path_flush_by_nexthop(struct sta_info *sta);
316bf7cd94dSJohannes Berg void mesh_path_discard_frame(struct ieee80211_sub_if_data *sdata,
317bf7cd94dSJohannes Berg 			     struct sk_buff *skb);
318e304bfd3SRui Paulo void mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata);
319ccf80ddfSLuis Carlos Cobo 
32025d49e4dSThomas Pedersen bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt);
321f5ea9120SJohannes Berg extern int mesh_paths_generation;
322f5ea9120SJohannes Berg 
323902acc78SJohannes Berg #ifdef CONFIG_MAC80211_MESH
3241617bab8SMarco Porsch static inline
3251617bab8SMarco Porsch u32 mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
3261617bab8SMarco Porsch {
3271617bab8SMarco Porsch 	atomic_inc(&sdata->u.mesh.estab_plinks);
328e05ecccdSJacob Minshall 	return mesh_accept_plinks_update(sdata) | BSS_CHANGED_BEACON;
3291617bab8SMarco Porsch }
3301617bab8SMarco Porsch 
3311617bab8SMarco Porsch static inline
3321617bab8SMarco Porsch u32 mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
3331617bab8SMarco Porsch {
3341617bab8SMarco Porsch 	atomic_dec(&sdata->u.mesh.estab_plinks);
335e05ecccdSJacob Minshall 	return mesh_accept_plinks_update(sdata) | BSS_CHANGED_BEACON;
3361617bab8SMarco Porsch }
3371617bab8SMarco Porsch 
338ccf80ddfSLuis Carlos Cobo static inline int mesh_plink_free_count(struct ieee80211_sub_if_data *sdata)
339ccf80ddfSLuis Carlos Cobo {
340472dbc45SJohannes Berg 	return sdata->u.mesh.mshcfg.dot11MeshMaxPeerLinks -
3411258d976SAshok Nagarajan 	       atomic_read(&sdata->u.mesh.estab_plinks);
342ccf80ddfSLuis Carlos Cobo }
343ccf80ddfSLuis Carlos Cobo 
344ccf80ddfSLuis Carlos Cobo static inline bool mesh_plink_availables(struct ieee80211_sub_if_data *sdata)
345ccf80ddfSLuis Carlos Cobo {
346d0709a65SJohannes Berg 	return (min_t(long, mesh_plink_free_count(sdata),
347ccf80ddfSLuis Carlos Cobo 		   MESH_MAX_PLINKS - sdata->local->num_sta)) > 0;
348ccf80ddfSLuis Carlos Cobo }
349ccf80ddfSLuis Carlos Cobo 
350ccf80ddfSLuis Carlos Cobo static inline void mesh_path_activate(struct mesh_path *mpath)
351ccf80ddfSLuis Carlos Cobo {
352ccf80ddfSLuis Carlos Cobo 	mpath->flags |= MESH_PATH_ACTIVE | MESH_PATH_RESOLVED;
353ccf80ddfSLuis Carlos Cobo }
354ccf80ddfSLuis Carlos Cobo 
355c7108a71SJavier Cardona static inline bool mesh_path_sel_is_hwmp(struct ieee80211_sub_if_data *sdata)
356c7108a71SJavier Cardona {
357c7108a71SJavier Cardona 	return sdata->u.mesh.mesh_pp_id == IEEE80211_PATH_PROTOCOL_HWMP;
358c7108a71SJavier Cardona }
359c7108a71SJavier Cardona 
360472dbc45SJohannes Berg void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local);
361472dbc45SJohannes Berg 
36294c514feSAndrei Emeltchenko void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata);
363dbf498fbSJavier Cardona void mesh_sync_adjust_tbtt(struct ieee80211_sub_if_data *sdata);
364bf7cd94dSJohannes Berg void ieee80211s_stop(void);
365902acc78SJohannes Berg #else
366472dbc45SJohannes Berg static inline void
367472dbc45SJohannes Berg ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local) {}
368c7108a71SJavier Cardona static inline bool mesh_path_sel_is_hwmp(struct ieee80211_sub_if_data *sdata)
369c7108a71SJavier Cardona { return false; }
37094c514feSAndrei Emeltchenko static inline void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata)
37194c514feSAndrei Emeltchenko {}
372bf7cd94dSJohannes Berg static inline void ieee80211s_stop(void) {}
373902acc78SJohannes Berg #endif
374902acc78SJohannes Berg 
375ccf80ddfSLuis Carlos Cobo #endif /* IEEE80211S_H */
376