Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (c) 2008, 2009 open80211s Ltd.
0004  * Authors:    Luis Carlos Cobo <luisca@cozybit.com>
0005  *             Javier Cardona <javier@cozybit.com>
0006  */
0007 
0008 #ifndef IEEE80211S_H
0009 #define IEEE80211S_H
0010 
0011 #include <linux/types.h>
0012 #include <linux/jhash.h>
0013 #include "ieee80211_i.h"
0014 
0015 
0016 /* Data structures */
0017 
0018 /**
0019  * enum mesh_path_flags - mac80211 mesh path flags
0020  *
0021  * @MESH_PATH_ACTIVE: the mesh path can be used for forwarding
0022  * @MESH_PATH_RESOLVING: the discovery process is running for this mesh path
0023  * @MESH_PATH_SN_VALID: the mesh path contains a valid destination sequence
0024  *  number
0025  * @MESH_PATH_FIXED: the mesh path has been manually set and should not be
0026  *  modified
0027  * @MESH_PATH_RESOLVED: the mesh path can has been resolved
0028  * @MESH_PATH_REQ_QUEUED: there is an unsent path request for this destination
0029  *  already queued up, waiting for the discovery process to start.
0030  * @MESH_PATH_DELETED: the mesh path has been deleted and should no longer
0031  *  be used
0032  *
0033  * MESH_PATH_RESOLVED is used by the mesh path timer to
0034  * decide when to stop or cancel the mesh path discovery.
0035  */
0036 enum mesh_path_flags {
0037     MESH_PATH_ACTIVE =  BIT(0),
0038     MESH_PATH_RESOLVING =   BIT(1),
0039     MESH_PATH_SN_VALID =    BIT(2),
0040     MESH_PATH_FIXED =   BIT(3),
0041     MESH_PATH_RESOLVED =    BIT(4),
0042     MESH_PATH_REQ_QUEUED =  BIT(5),
0043     MESH_PATH_DELETED = BIT(6),
0044 };
0045 
0046 /**
0047  * enum mesh_deferred_task_flags - mac80211 mesh deferred tasks
0048  *
0049  *
0050  *
0051  * @MESH_WORK_HOUSEKEEPING: run the periodic mesh housekeeping tasks
0052  * @MESH_WORK_ROOT: the mesh root station needs to send a frame
0053  * @MESH_WORK_DRIFT_ADJUST: time to compensate for clock drift relative to other
0054  * mesh nodes
0055  * @MESH_WORK_MBSS_CHANGED: rebuild beacon and notify driver of BSS changes
0056  */
0057 enum mesh_deferred_task_flags {
0058     MESH_WORK_HOUSEKEEPING,
0059     MESH_WORK_ROOT,
0060     MESH_WORK_DRIFT_ADJUST,
0061     MESH_WORK_MBSS_CHANGED,
0062 };
0063 
0064 /**
0065  * struct mesh_path - mac80211 mesh path structure
0066  *
0067  * @dst: mesh path destination mac address
0068  * @mpp: mesh proxy mac address
0069  * @rhash: rhashtable list pointer
0070  * @walk_list: linked list containing all mesh_path objects.
0071  * @gate_list: list pointer for known gates list
0072  * @sdata: mesh subif
0073  * @next_hop: mesh neighbor to which frames for this destination will be
0074  *  forwarded
0075  * @timer: mesh path discovery timer
0076  * @frame_queue: pending queue for frames sent to this destination while the
0077  *  path is unresolved
0078  * @rcu: rcu head for freeing mesh path
0079  * @sn: target sequence number
0080  * @metric: current metric to this destination
0081  * @hop_count: hops to destination
0082  * @exp_time: in jiffies, when the path will expire or when it expired
0083  * @discovery_timeout: timeout (lapse in jiffies) used for the last discovery
0084  *  retry
0085  * @discovery_retries: number of discovery retries
0086  * @flags: mesh path flags, as specified on &enum mesh_path_flags
0087  * @state_lock: mesh path state lock used to protect changes to the
0088  * mpath itself.  No need to take this lock when adding or removing
0089  * an mpath to a hash bucket on a path table.
0090  * @rann_snd_addr: the RANN sender address
0091  * @rann_metric: the aggregated path metric towards the root node
0092  * @last_preq_to_root: Timestamp of last PREQ sent to root
0093  * @is_root: the destination station of this path is a root node
0094  * @is_gate: the destination station of this path is a mesh gate
0095  * @path_change_count: the number of path changes to destination
0096  *
0097  *
0098  * The dst address is unique in the mesh path table. Since the mesh_path is
0099  * protected by RCU, deleting the next_hop STA must remove / substitute the
0100  * mesh_path structure and wait until that is no longer reachable before
0101  * destroying the STA completely.
0102  */
0103 struct mesh_path {
0104     u8 dst[ETH_ALEN];
0105     u8 mpp[ETH_ALEN];   /* used for MPP or MAP */
0106     struct rhash_head rhash;
0107     struct hlist_node walk_list;
0108     struct hlist_node gate_list;
0109     struct ieee80211_sub_if_data *sdata;
0110     struct sta_info __rcu *next_hop;
0111     struct timer_list timer;
0112     struct sk_buff_head frame_queue;
0113     struct rcu_head rcu;
0114     u32 sn;
0115     u32 metric;
0116     u8 hop_count;
0117     unsigned long exp_time;
0118     u32 discovery_timeout;
0119     u8 discovery_retries;
0120     enum mesh_path_flags flags;
0121     spinlock_t state_lock;
0122     u8 rann_snd_addr[ETH_ALEN];
0123     u32 rann_metric;
0124     unsigned long last_preq_to_root;
0125     bool is_root;
0126     bool is_gate;
0127     u32 path_change_count;
0128 };
0129 
0130 /* Recent multicast cache */
0131 /* RMC_BUCKETS must be a power of 2, maximum 256 */
0132 #define RMC_BUCKETS     256
0133 #define RMC_QUEUE_MAX_LEN   4
0134 #define RMC_TIMEOUT     (3 * HZ)
0135 
0136 /**
0137  * struct rmc_entry - entry in the Recent Multicast Cache
0138  *
0139  * @seqnum: mesh sequence number of the frame
0140  * @exp_time: expiration time of the entry, in jiffies
0141  * @sa: source address of the frame
0142  * @list: hashtable list pointer
0143  *
0144  * The Recent Multicast Cache keeps track of the latest multicast frames that
0145  * have been received by a mesh interface and discards received multicast frames
0146  * that are found in the cache.
0147  */
0148 struct rmc_entry {
0149     struct hlist_node list;
0150     unsigned long exp_time;
0151     u32 seqnum;
0152     u8 sa[ETH_ALEN];
0153 };
0154 
0155 struct mesh_rmc {
0156     struct hlist_head bucket[RMC_BUCKETS];
0157     u32 idx_mask;
0158 };
0159 
0160 #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
0161 
0162 #define MESH_PATH_EXPIRE (600 * HZ)
0163 
0164 /* Default maximum number of plinks per interface */
0165 #define MESH_MAX_PLINKS     256
0166 
0167 /* Maximum number of paths per interface */
0168 #define MESH_MAX_MPATHS     1024
0169 
0170 /* Number of frames buffered per destination for unresolved destinations */
0171 #define MESH_FRAME_QUEUE_LEN    10
0172 
0173 /* Public interfaces */
0174 /* Various */
0175 int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
0176                   const u8 *da, const u8 *sa);
0177 unsigned int ieee80211_new_mesh_header(struct ieee80211_sub_if_data *sdata,
0178                        struct ieee80211s_hdr *meshhdr,
0179                        const char *addr4or5, const char *addr6);
0180 int mesh_rmc_check(struct ieee80211_sub_if_data *sdata,
0181            const u8 *addr, struct ieee80211s_hdr *mesh_hdr);
0182 bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
0183             struct ieee802_11_elems *ie);
0184 void mesh_ids_set_default(struct ieee80211_if_mesh *mesh);
0185 int mesh_add_meshconf_ie(struct ieee80211_sub_if_data *sdata,
0186              struct sk_buff *skb);
0187 int mesh_add_meshid_ie(struct ieee80211_sub_if_data *sdata,
0188                struct sk_buff *skb);
0189 int mesh_add_rsn_ie(struct ieee80211_sub_if_data *sdata,
0190             struct sk_buff *skb);
0191 int mesh_add_vendor_ies(struct ieee80211_sub_if_data *sdata,
0192             struct sk_buff *skb);
0193 int mesh_add_ht_cap_ie(struct ieee80211_sub_if_data *sdata,
0194                struct sk_buff *skb);
0195 int mesh_add_ht_oper_ie(struct ieee80211_sub_if_data *sdata,
0196             struct sk_buff *skb);
0197 int mesh_add_vht_cap_ie(struct ieee80211_sub_if_data *sdata,
0198             struct sk_buff *skb);
0199 int mesh_add_vht_oper_ie(struct ieee80211_sub_if_data *sdata,
0200              struct sk_buff *skb);
0201 int mesh_add_he_cap_ie(struct ieee80211_sub_if_data *sdata,
0202                struct sk_buff *skb, u8 ie_len);
0203 int mesh_add_he_oper_ie(struct ieee80211_sub_if_data *sdata,
0204             struct sk_buff *skb);
0205 int mesh_add_he_6ghz_cap_ie(struct ieee80211_sub_if_data *sdata,
0206                 struct sk_buff *skb);
0207 void mesh_rmc_free(struct ieee80211_sub_if_data *sdata);
0208 int mesh_rmc_init(struct ieee80211_sub_if_data *sdata);
0209 void ieee80211s_init(void);
0210 void ieee80211s_update_metric(struct ieee80211_local *local,
0211                   struct sta_info *sta,
0212                   struct ieee80211_tx_status *st);
0213 void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata);
0214 void ieee80211_mesh_teardown_sdata(struct ieee80211_sub_if_data *sdata);
0215 int ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata);
0216 void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata);
0217 void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh);
0218 const struct ieee80211_mesh_sync_ops *ieee80211_mesh_sync_ops_get(u8 method);
0219 /* wrapper for ieee80211_bss_info_change_notify() */
0220 void ieee80211_mbss_info_change_notify(struct ieee80211_sub_if_data *sdata,
0221                        u32 changed);
0222 
0223 /* mesh power save */
0224 u32 ieee80211_mps_local_status_update(struct ieee80211_sub_if_data *sdata);
0225 u32 ieee80211_mps_set_sta_local_pm(struct sta_info *sta,
0226                    enum nl80211_mesh_power_mode pm);
0227 void ieee80211_mps_set_frame_flags(struct ieee80211_sub_if_data *sdata,
0228                    struct sta_info *sta,
0229                    struct ieee80211_hdr *hdr);
0230 void ieee80211_mps_sta_status_update(struct sta_info *sta);
0231 void ieee80211_mps_rx_h_sta_process(struct sta_info *sta,
0232                     struct ieee80211_hdr *hdr);
0233 void ieee80211_mpsp_trigger_process(u8 *qc, struct sta_info *sta,
0234                     bool tx, bool acked);
0235 void ieee80211_mps_frame_release(struct sta_info *sta,
0236                  struct ieee802_11_elems *elems);
0237 
0238 /* Mesh paths */
0239 int mesh_nexthop_lookup(struct ieee80211_sub_if_data *sdata,
0240             struct sk_buff *skb);
0241 int mesh_nexthop_resolve(struct ieee80211_sub_if_data *sdata,
0242              struct sk_buff *skb);
0243 void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata);
0244 struct mesh_path *mesh_path_lookup(struct ieee80211_sub_if_data *sdata,
0245                    const u8 *dst);
0246 struct mesh_path *mpp_path_lookup(struct ieee80211_sub_if_data *sdata,
0247                   const u8 *dst);
0248 int mpp_path_add(struct ieee80211_sub_if_data *sdata,
0249          const u8 *dst, const u8 *mpp);
0250 struct mesh_path *
0251 mesh_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx);
0252 struct mesh_path *
0253 mpp_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx);
0254 void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop);
0255 void mesh_path_expire(struct ieee80211_sub_if_data *sdata);
0256 void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata,
0257                 struct ieee80211_mgmt *mgmt, size_t len);
0258 struct mesh_path *
0259 mesh_path_add(struct ieee80211_sub_if_data *sdata, const u8 *dst);
0260 
0261 int mesh_path_add_gate(struct mesh_path *mpath);
0262 int mesh_path_send_to_gates(struct mesh_path *mpath);
0263 int mesh_gate_num(struct ieee80211_sub_if_data *sdata);
0264 u32 airtime_link_metric_get(struct ieee80211_local *local,
0265                 struct sta_info *sta);
0266 
0267 /* Mesh plinks */
0268 void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
0269                u8 *hw_addr, struct ieee802_11_elems *ie,
0270                struct ieee80211_rx_status *rx_status);
0271 bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie);
0272 u32 mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata);
0273 void mesh_plink_timer(struct timer_list *t);
0274 void mesh_plink_broken(struct sta_info *sta);
0275 u32 mesh_plink_deactivate(struct sta_info *sta);
0276 u32 mesh_plink_open(struct sta_info *sta);
0277 u32 mesh_plink_block(struct sta_info *sta);
0278 void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata,
0279              struct ieee80211_mgmt *mgmt, size_t len,
0280              struct ieee80211_rx_status *rx_status);
0281 void mesh_sta_cleanup(struct sta_info *sta);
0282 
0283 /* Private interfaces */
0284 /* Mesh paths */
0285 int mesh_path_error_tx(struct ieee80211_sub_if_data *sdata,
0286                u8 ttl, const u8 *target, u32 target_sn,
0287                u16 target_rcode, const u8 *ra);
0288 void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta);
0289 void mesh_path_flush_pending(struct mesh_path *mpath);
0290 void mesh_path_tx_pending(struct mesh_path *mpath);
0291 void mesh_pathtbl_init(struct ieee80211_sub_if_data *sdata);
0292 void mesh_pathtbl_unregister(struct ieee80211_sub_if_data *sdata);
0293 int mesh_path_del(struct ieee80211_sub_if_data *sdata, const u8 *addr);
0294 void mesh_path_timer(struct timer_list *t);
0295 void mesh_path_flush_by_nexthop(struct sta_info *sta);
0296 void mesh_path_discard_frame(struct ieee80211_sub_if_data *sdata,
0297                  struct sk_buff *skb);
0298 void mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata);
0299 
0300 bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt);
0301 
0302 #ifdef CONFIG_MAC80211_MESH
0303 static inline
0304 u32 mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
0305 {
0306     atomic_inc(&sdata->u.mesh.estab_plinks);
0307     return mesh_accept_plinks_update(sdata) | BSS_CHANGED_BEACON;
0308 }
0309 
0310 static inline
0311 u32 mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
0312 {
0313     atomic_dec(&sdata->u.mesh.estab_plinks);
0314     return mesh_accept_plinks_update(sdata) | BSS_CHANGED_BEACON;
0315 }
0316 
0317 static inline int mesh_plink_free_count(struct ieee80211_sub_if_data *sdata)
0318 {
0319     return sdata->u.mesh.mshcfg.dot11MeshMaxPeerLinks -
0320            atomic_read(&sdata->u.mesh.estab_plinks);
0321 }
0322 
0323 static inline bool mesh_plink_availables(struct ieee80211_sub_if_data *sdata)
0324 {
0325     return (min_t(long, mesh_plink_free_count(sdata),
0326            MESH_MAX_PLINKS - sdata->local->num_sta)) > 0;
0327 }
0328 
0329 static inline void mesh_path_activate(struct mesh_path *mpath)
0330 {
0331     mpath->flags |= MESH_PATH_ACTIVE | MESH_PATH_RESOLVED;
0332 }
0333 
0334 static inline bool mesh_path_sel_is_hwmp(struct ieee80211_sub_if_data *sdata)
0335 {
0336     return sdata->u.mesh.mesh_pp_id == IEEE80211_PATH_PROTOCOL_HWMP;
0337 }
0338 
0339 void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata);
0340 void mesh_sync_adjust_tsf(struct ieee80211_sub_if_data *sdata);
0341 void ieee80211s_stop(void);
0342 #else
0343 static inline bool mesh_path_sel_is_hwmp(struct ieee80211_sub_if_data *sdata)
0344 { return false; }
0345 static inline void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata)
0346 {}
0347 static inline void ieee80211s_stop(void) {}
0348 #endif
0349 
0350 #endif /* IEEE80211S_H */