xref: /linux/net/mac80211/mesh.h (revision 2bdaf386f99c4a82788812e583ff59c6714ae4d6)
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
61f81a9dedSThomas 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,
69f81a9dedSThomas 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
1405ee68e5bSJavier Cardona  * @known_gates: list of known mesh gates and their mpaths by the station. The
1415ee68e5bSJavier Cardona  * gate's mpath may or may not be resolved and active.
1425ee68e5bSJavier Cardona  *
1431928ecabSJohannes Berg  * rcu_head: RCU head to free the table
144ccf80ddfSLuis Carlos Cobo  */
145ccf80ddfSLuis Carlos Cobo struct mesh_table {
146ccf80ddfSLuis Carlos Cobo 	/* Number of buckets will be 2^N */
147ccf80ddfSLuis Carlos Cobo 	struct hlist_head *hash_buckets;
148ccf80ddfSLuis Carlos Cobo 	spinlock_t *hashwlock;		/* One per bucket, for add/del */
149ccf80ddfSLuis Carlos Cobo 	unsigned int hash_mask;		/* (2^size_order) - 1 */
150ccf80ddfSLuis Carlos Cobo 	__u32 hash_rnd;			/* Used for hash generation */
151ccf80ddfSLuis Carlos Cobo 	atomic_t entries;		/* Up to MAX_MESH_NEIGHBOURS */
152ccf80ddfSLuis Carlos Cobo 	void (*free_node) (struct hlist_node *p, bool free_leafs);
1534caf86c6SPavel Emelyanov 	int (*copy_node) (struct hlist_node *p, struct mesh_table *newtbl);
154ccf80ddfSLuis Carlos Cobo 	int size_order;
1555ee68e5bSJavier Cardona 	struct hlist_head *known_gates;
1565ee68e5bSJavier Cardona 	spinlock_t gates_lock;
1571928ecabSJohannes Berg 
1581928ecabSJohannes Berg 	struct rcu_head rcu_head;
159ccf80ddfSLuis Carlos Cobo };
160ccf80ddfSLuis Carlos Cobo 
161ccf80ddfSLuis Carlos Cobo /* Recent multicast cache */
162ccf80ddfSLuis Carlos Cobo /* RMC_BUCKETS must be a power of 2, maximum 256 */
163ccf80ddfSLuis Carlos Cobo #define RMC_BUCKETS		256
164ccf80ddfSLuis Carlos Cobo #define RMC_QUEUE_MAX_LEN	4
165ccf80ddfSLuis Carlos Cobo #define RMC_TIMEOUT		(3 * HZ)
166ccf80ddfSLuis Carlos Cobo 
167ccf80ddfSLuis Carlos Cobo /**
168ccf80ddfSLuis Carlos Cobo  * struct rmc_entry - entry in the Recent Multicast Cache
169ccf80ddfSLuis Carlos Cobo  *
170ccf80ddfSLuis Carlos Cobo  * @seqnum: mesh sequence number of the frame
171ccf80ddfSLuis Carlos Cobo  * @exp_time: expiration time of the entry, in jiffies
172ccf80ddfSLuis Carlos Cobo  * @sa: source address of the frame
173ccf80ddfSLuis Carlos Cobo  *
174ccf80ddfSLuis Carlos Cobo  * The Recent Multicast Cache keeps track of the latest multicast frames that
175ccf80ddfSLuis Carlos Cobo  * have been received by a mesh interface and discards received multicast frames
176ccf80ddfSLuis Carlos Cobo  * that are found in the cache.
177ccf80ddfSLuis Carlos Cobo  */
178ccf80ddfSLuis Carlos Cobo struct rmc_entry {
179ccf80ddfSLuis Carlos Cobo 	struct list_head list;
180ccf80ddfSLuis Carlos Cobo 	u32 seqnum;
181ccf80ddfSLuis Carlos Cobo 	unsigned long exp_time;
182ccf80ddfSLuis Carlos Cobo 	u8 sa[ETH_ALEN];
183ccf80ddfSLuis Carlos Cobo };
184ccf80ddfSLuis Carlos Cobo 
185ccf80ddfSLuis Carlos Cobo struct mesh_rmc {
186b7cfcd11SThomas Pedersen 	struct list_head bucket[RMC_BUCKETS];
18751ceddadSLuis Carlos Cobo 	u32 idx_mask;
188ccf80ddfSLuis Carlos Cobo };
189ccf80ddfSLuis Carlos Cobo 
19025d49e4dSThomas Pedersen #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
191ccf80ddfSLuis Carlos Cobo 
192ccf80ddfSLuis Carlos Cobo #define MESH_PATH_EXPIRE (600 * HZ)
193ccf80ddfSLuis Carlos Cobo 
194ccf80ddfSLuis Carlos Cobo /* Default maximum number of plinks per interface */
195ccf80ddfSLuis Carlos Cobo #define MESH_MAX_PLINKS		256
196ccf80ddfSLuis Carlos Cobo 
197ccf80ddfSLuis Carlos Cobo /* Maximum number of paths per interface */
198ccf80ddfSLuis Carlos Cobo #define MESH_MAX_MPATHS		1024
199ccf80ddfSLuis Carlos Cobo 
2004bd4c2ddSThomas Pedersen /* Number of frames buffered per destination for unresolved destinations */
2014bd4c2ddSThomas Pedersen #define MESH_FRAME_QUEUE_LEN	10
2024bd4c2ddSThomas Pedersen 
203ccf80ddfSLuis Carlos Cobo /* Public interfaces */
204ccf80ddfSLuis Carlos Cobo /* Various */
2053c5772a5SJavier Cardona int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
20615ff6365SJohannes Berg 				  const u8 *da, const u8 *sa);
2075edfcee5SAndrzej Hajda unsigned int ieee80211_new_mesh_header(struct ieee80211_sub_if_data *sdata,
208bf7cd94dSJohannes Berg 				       struct ieee80211s_hdr *meshhdr,
209bf7cd94dSJohannes Berg 				       const char *addr4or5, const char *addr6);
210bf7cd94dSJohannes Berg int mesh_rmc_check(struct ieee80211_sub_if_data *sdata,
211bf7cd94dSJohannes Berg 		   const u8 *addr, struct ieee80211s_hdr *mesh_hdr);
212f743ff49SThomas Pedersen bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
213f743ff49SThomas Pedersen 			struct ieee802_11_elems *ie);
214472dbc45SJohannes Berg void mesh_ids_set_default(struct ieee80211_if_mesh *mesh);
215bf7cd94dSJohannes Berg int mesh_add_meshconf_ie(struct ieee80211_sub_if_data *sdata,
216bf7cd94dSJohannes Berg 			 struct sk_buff *skb);
217bf7cd94dSJohannes Berg int mesh_add_meshid_ie(struct ieee80211_sub_if_data *sdata,
218bf7cd94dSJohannes Berg 		       struct sk_buff *skb);
219bf7cd94dSJohannes Berg int mesh_add_rsn_ie(struct ieee80211_sub_if_data *sdata,
220bf7cd94dSJohannes Berg 		    struct sk_buff *skb);
221bf7cd94dSJohannes Berg int mesh_add_vendor_ies(struct ieee80211_sub_if_data *sdata,
222bf7cd94dSJohannes Berg 			struct sk_buff *skb);
223bf7cd94dSJohannes Berg int mesh_add_ht_cap_ie(struct ieee80211_sub_if_data *sdata,
224bf7cd94dSJohannes Berg 		       struct sk_buff *skb);
225bf7cd94dSJohannes Berg int mesh_add_ht_oper_ie(struct ieee80211_sub_if_data *sdata,
226bf7cd94dSJohannes Berg 			struct sk_buff *skb);
227c85fb53cSBob Copeland int mesh_add_vht_cap_ie(struct ieee80211_sub_if_data *sdata,
228c85fb53cSBob Copeland 			struct sk_buff *skb);
229c85fb53cSBob Copeland int mesh_add_vht_oper_ie(struct ieee80211_sub_if_data *sdata,
230c85fb53cSBob Copeland 			 struct sk_buff *skb);
231f698d856SJasper Bryant-Greene void mesh_rmc_free(struct ieee80211_sub_if_data *sdata);
232f698d856SJasper Bryant-Greene int mesh_rmc_init(struct ieee80211_sub_if_data *sdata);
233ccf80ddfSLuis Carlos Cobo void ieee80211s_init(void);
234bfc32e6aSJavier Cardona void ieee80211s_update_metric(struct ieee80211_local *local,
23535b3fe1cSJavier Cardona 			      struct sta_info *sta, struct sk_buff *skb);
236902acc78SJohannes Berg void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata);
2372b5e1967SThomas Pedersen int ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata);
238472dbc45SJohannes Berg void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata);
23963c5723bSRui Paulo void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh);
2408ba7acf3SJohannes Berg const struct ieee80211_mesh_sync_ops *ieee80211_mesh_sync_ops_get(u8 method);
2412b5e1967SThomas Pedersen /* wrapper for ieee80211_bss_info_change_notify() */
2422b5e1967SThomas Pedersen void ieee80211_mbss_info_change_notify(struct ieee80211_sub_if_data *sdata,
2432b5e1967SThomas Pedersen 				       u32 changed);
244902acc78SJohannes Berg 
2453f52b7e3SMarco Porsch /* mesh power save */
24639886b61SThomas Pedersen u32 ieee80211_mps_local_status_update(struct ieee80211_sub_if_data *sdata);
24739886b61SThomas Pedersen u32 ieee80211_mps_set_sta_local_pm(struct sta_info *sta,
2483f52b7e3SMarco Porsch 				   enum nl80211_mesh_power_mode pm);
2493f52b7e3SMarco Porsch void ieee80211_mps_set_frame_flags(struct ieee80211_sub_if_data *sdata,
2503f52b7e3SMarco Porsch 				   struct sta_info *sta,
2513f52b7e3SMarco Porsch 				   struct ieee80211_hdr *hdr);
2523f52b7e3SMarco Porsch void ieee80211_mps_sta_status_update(struct sta_info *sta);
2533f52b7e3SMarco Porsch void ieee80211_mps_rx_h_sta_process(struct sta_info *sta,
2543f52b7e3SMarco Porsch 				    struct ieee80211_hdr *hdr);
2553f52b7e3SMarco Porsch void ieee80211_mpsp_trigger_process(u8 *qc, struct sta_info *sta,
2563f52b7e3SMarco Porsch 				    bool tx, bool acked);
2573f52b7e3SMarco Porsch void ieee80211_mps_frame_release(struct sta_info *sta,
2583f52b7e3SMarco Porsch 				 struct ieee802_11_elems *elems);
2593f52b7e3SMarco Porsch 
260ccf80ddfSLuis Carlos Cobo /* Mesh paths */
261bf7cd94dSJohannes Berg int mesh_nexthop_lookup(struct ieee80211_sub_if_data *sdata,
262bf7cd94dSJohannes Berg 			struct sk_buff *skb);
263bf7cd94dSJohannes Berg int mesh_nexthop_resolve(struct ieee80211_sub_if_data *sdata,
264bf7cd94dSJohannes Berg 			 struct sk_buff *skb);
265f698d856SJasper Bryant-Greene void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata);
266bf7cd94dSJohannes Berg struct mesh_path *mesh_path_lookup(struct ieee80211_sub_if_data *sdata,
267bf7cd94dSJohannes Berg 				   const u8 *dst);
268bf7cd94dSJohannes Berg struct mesh_path *mpp_path_lookup(struct ieee80211_sub_if_data *sdata,
269bf7cd94dSJohannes Berg 				  const u8 *dst);
270bf7cd94dSJohannes Berg int mpp_path_add(struct ieee80211_sub_if_data *sdata,
271bf7cd94dSJohannes Berg 		 const u8 *dst, const u8 *mpp);
272bf7cd94dSJohannes Berg struct mesh_path *
273bf7cd94dSJohannes Berg mesh_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx);
274a2db2ed3SHenning Rogge struct mesh_path *
275a2db2ed3SHenning Rogge mpp_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx);
276ccf80ddfSLuis Carlos Cobo void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop);
277f698d856SJasper Bryant-Greene void mesh_path_expire(struct ieee80211_sub_if_data *sdata);
278f698d856SJasper Bryant-Greene void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata,
279f698d856SJasper Bryant-Greene 			    struct ieee80211_mgmt *mgmt, size_t len);
280ae76eef0SBob Copeland struct mesh_path *
281ae76eef0SBob Copeland mesh_path_add(struct ieee80211_sub_if_data *sdata, const u8 *dst);
2825ee68e5bSJavier Cardona 
2835ee68e5bSJavier Cardona int mesh_path_add_gate(struct mesh_path *mpath);
2845ee68e5bSJavier Cardona int mesh_path_send_to_gates(struct mesh_path *mpath);
2855ee68e5bSJavier Cardona int mesh_gate_num(struct ieee80211_sub_if_data *sdata);
286bf7cd94dSJohannes Berg 
287ccf80ddfSLuis Carlos Cobo /* Mesh plinks */
288f743ff49SThomas Pedersen void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
289bf7cd94dSJohannes Berg 			   u8 *hw_addr, struct ieee802_11_elems *ie);
290f698d856SJasper Bryant-Greene bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie);
291df323818SMarco Porsch u32 mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata);
292ccf80ddfSLuis Carlos Cobo void mesh_plink_broken(struct sta_info *sta);
29345b5028eSThomas Pedersen u32 mesh_plink_deactivate(struct sta_info *sta);
29439886b61SThomas Pedersen u32 mesh_plink_open(struct sta_info *sta);
29539886b61SThomas Pedersen u32 mesh_plink_block(struct sta_info *sta);
296f698d856SJasper Bryant-Greene void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata,
297f698d856SJasper Bryant-Greene 			 struct ieee80211_mgmt *mgmt, size_t len,
298f698d856SJasper Bryant-Greene 			 struct ieee80211_rx_status *rx_status);
29945b5028eSThomas Pedersen void mesh_sta_cleanup(struct sta_info *sta);
300ccf80ddfSLuis Carlos Cobo 
301ccf80ddfSLuis Carlos Cobo /* Private interfaces */
302ccf80ddfSLuis Carlos Cobo /* Mesh tables */
303*2bdaf386SBob Copeland void mesh_mpath_table_grow(struct ieee80211_sub_if_data *sdata);
304*2bdaf386SBob Copeland void mesh_mpp_table_grow(struct ieee80211_sub_if_data *sdata);
305ccf80ddfSLuis Carlos Cobo /* Mesh paths */
306bf7cd94dSJohannes Berg int mesh_path_error_tx(struct ieee80211_sub_if_data *sdata,
307f63f8421SChun-Yeow Yeoh 		       u8 ttl, const u8 *target, u32 target_sn,
308f63f8421SChun-Yeow Yeoh 		       u16 target_rcode, const u8 *ra);
309ccf80ddfSLuis Carlos Cobo void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta);
310ccf80ddfSLuis Carlos Cobo void mesh_path_flush_pending(struct mesh_path *mpath);
311ccf80ddfSLuis Carlos Cobo void mesh_path_tx_pending(struct mesh_path *mpath);
312*2bdaf386SBob Copeland int mesh_pathtbl_init(struct ieee80211_sub_if_data *sdata);
313*2bdaf386SBob Copeland void mesh_pathtbl_unregister(struct ieee80211_sub_if_data *sdata);
314bf7cd94dSJohannes Berg int mesh_path_del(struct ieee80211_sub_if_data *sdata, const u8 *addr);
315ccf80ddfSLuis Carlos Cobo void mesh_path_timer(unsigned long data);
316ccf80ddfSLuis Carlos Cobo void mesh_path_flush_by_nexthop(struct sta_info *sta);
317bf7cd94dSJohannes Berg void mesh_path_discard_frame(struct ieee80211_sub_if_data *sdata,
318bf7cd94dSJohannes Berg 			     struct sk_buff *skb);
319e304bfd3SRui Paulo void mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata);
320ccf80ddfSLuis Carlos Cobo 
32125d49e4dSThomas Pedersen bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt);
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 
36094c514feSAndrei Emeltchenko void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata);
361dbf498fbSJavier Cardona void mesh_sync_adjust_tbtt(struct ieee80211_sub_if_data *sdata);
362bf7cd94dSJohannes Berg void ieee80211s_stop(void);
363902acc78SJohannes Berg #else
364c7108a71SJavier Cardona static inline bool mesh_path_sel_is_hwmp(struct ieee80211_sub_if_data *sdata)
365c7108a71SJavier Cardona { return false; }
36694c514feSAndrei Emeltchenko static inline void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata)
36794c514feSAndrei Emeltchenko {}
368bf7cd94dSJohannes Berg static inline void ieee80211s_stop(void) {}
369902acc78SJohannes Berg #endif
370902acc78SJohannes Berg 
371ccf80ddfSLuis Carlos Cobo #endif /* IEEE80211S_H */
372