xref: /linux/net/batman-adv/main.h (revision aa0adb1a85e159cf57f0e11282bc6c9e3606a5f3)
1c6c8fea2SSven Eckelmann /*
2c6c8fea2SSven Eckelmann  * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3c6c8fea2SSven Eckelmann  *
4c6c8fea2SSven Eckelmann  * Marek Lindner, Simon Wunderlich
5c6c8fea2SSven Eckelmann  *
6c6c8fea2SSven Eckelmann  * This program is free software; you can redistribute it and/or
7c6c8fea2SSven Eckelmann  * modify it under the terms of version 2 of the GNU General Public
8c6c8fea2SSven Eckelmann  * License as published by the Free Software Foundation.
9c6c8fea2SSven Eckelmann  *
10c6c8fea2SSven Eckelmann  * This program is distributed in the hope that it will be useful, but
11c6c8fea2SSven Eckelmann  * WITHOUT ANY WARRANTY; without even the implied warranty of
12c6c8fea2SSven Eckelmann  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13c6c8fea2SSven Eckelmann  * General Public License for more details.
14c6c8fea2SSven Eckelmann  *
15c6c8fea2SSven Eckelmann  * You should have received a copy of the GNU General Public License
16c6c8fea2SSven Eckelmann  * along with this program; if not, write to the Free Software
17c6c8fea2SSven Eckelmann  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18c6c8fea2SSven Eckelmann  * 02110-1301, USA
19c6c8fea2SSven Eckelmann  *
20c6c8fea2SSven Eckelmann  */
21c6c8fea2SSven Eckelmann 
22c6c8fea2SSven Eckelmann #ifndef _NET_BATMAN_ADV_MAIN_H_
23c6c8fea2SSven Eckelmann #define _NET_BATMAN_ADV_MAIN_H_
24c6c8fea2SSven Eckelmann 
25c6c8fea2SSven Eckelmann /* Kernel Programming */
26c6c8fea2SSven Eckelmann #define LINUX
27c6c8fea2SSven Eckelmann 
28c6c8fea2SSven Eckelmann #define DRIVER_AUTHOR "Marek Lindner <lindner_marek@yahoo.de>, " \
29c6c8fea2SSven Eckelmann 		      "Simon Wunderlich <siwu@hrz.tu-chemnitz.de>"
30c6c8fea2SSven Eckelmann #define DRIVER_DESC   "B.A.T.M.A.N. advanced"
31c6c8fea2SSven Eckelmann #define DRIVER_DEVICE "batman-adv"
32c6c8fea2SSven Eckelmann 
33c6c8fea2SSven Eckelmann #define SOURCE_VERSION "next"
34c6c8fea2SSven Eckelmann 
35c6c8fea2SSven Eckelmann 
36c6c8fea2SSven Eckelmann /* B.A.T.M.A.N. parameters */
37c6c8fea2SSven Eckelmann 
38c6c8fea2SSven Eckelmann #define TQ_MAX_VALUE 255
39c6c8fea2SSven Eckelmann #define JITTER 20
40c6c8fea2SSven Eckelmann #define TTL 50			  /* Time To Live of broadcast messages */
41c6c8fea2SSven Eckelmann 
42c6c8fea2SSven Eckelmann #define PURGE_TIMEOUT 200	/* purge originators after time in seconds if no
43c6c8fea2SSven Eckelmann 				   * valid packet comes in -> TODO: check
44c6c8fea2SSven Eckelmann 				   * influence on TQ_LOCAL_WINDOW_SIZE */
45c6c8fea2SSven Eckelmann #define LOCAL_HNA_TIMEOUT 3600 /* in seconds */
46c6c8fea2SSven Eckelmann 
47c6c8fea2SSven Eckelmann #define TQ_LOCAL_WINDOW_SIZE 64	  /* sliding packet range of received originator
48c6c8fea2SSven Eckelmann 				   * messages in squence numbers (should be a
49c6c8fea2SSven Eckelmann 				   * multiple of our word size) */
50c6c8fea2SSven Eckelmann #define TQ_GLOBAL_WINDOW_SIZE 5
51c6c8fea2SSven Eckelmann #define TQ_LOCAL_BIDRECT_SEND_MINIMUM 1
52c6c8fea2SSven Eckelmann #define TQ_LOCAL_BIDRECT_RECV_MINIMUM 1
53c6c8fea2SSven Eckelmann #define TQ_TOTAL_BIDRECT_LIMIT 1
54c6c8fea2SSven Eckelmann 
55c6c8fea2SSven Eckelmann #define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE)
56c6c8fea2SSven Eckelmann 
57c6c8fea2SSven Eckelmann #define PACKBUFF_SIZE 2000
58c6c8fea2SSven Eckelmann #define LOG_BUF_LEN 8192	  /* has to be a power of 2 */
59c6c8fea2SSven Eckelmann 
60c6c8fea2SSven Eckelmann #define VIS_INTERVAL 5000	/* 5 seconds */
61c6c8fea2SSven Eckelmann 
62c6c8fea2SSven Eckelmann /* how much worse secondary interfaces may be to
63c6c8fea2SSven Eckelmann  * to be considered as bonding candidates */
64c6c8fea2SSven Eckelmann 
65c6c8fea2SSven Eckelmann #define BONDING_TQ_THRESHOLD	50
66c6c8fea2SSven Eckelmann 
67c6c8fea2SSven Eckelmann #define MAX_AGGREGATION_BYTES 512 /* should not be bigger than 512 bytes or
68c6c8fea2SSven Eckelmann 				   * change the size of
69c6c8fea2SSven Eckelmann 				   * forw_packet->direct_link_flags */
70c6c8fea2SSven Eckelmann #define MAX_AGGREGATION_MS 100
71c6c8fea2SSven Eckelmann 
72c6c8fea2SSven Eckelmann #define SOFTIF_NEIGH_TIMEOUT 180000 /* 3 minutes */
73c6c8fea2SSven Eckelmann 
74c6c8fea2SSven Eckelmann #define RESET_PROTECTION_MS 30000
75c6c8fea2SSven Eckelmann #define EXPECTED_SEQNO_RANGE	65536
76c6c8fea2SSven Eckelmann /* don't reset again within 30 seconds */
77c6c8fea2SSven Eckelmann 
78c6c8fea2SSven Eckelmann #define MESH_INACTIVE 0
79c6c8fea2SSven Eckelmann #define MESH_ACTIVE 1
80c6c8fea2SSven Eckelmann #define MESH_DEACTIVATING 2
81c6c8fea2SSven Eckelmann 
82c6c8fea2SSven Eckelmann #define BCAST_QUEUE_LEN		256
83c6c8fea2SSven Eckelmann #define BATMAN_QUEUE_LEN	256
84c6c8fea2SSven Eckelmann 
85c6c8fea2SSven Eckelmann /*
86c6c8fea2SSven Eckelmann  * Debug Messages
87c6c8fea2SSven Eckelmann  */
88c6c8fea2SSven Eckelmann #ifdef pr_fmt
89c6c8fea2SSven Eckelmann #undef pr_fmt
90c6c8fea2SSven Eckelmann #endif
91c6c8fea2SSven Eckelmann #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt /* Append 'batman-adv: ' before
92c6c8fea2SSven Eckelmann 					     * kernel messages */
93c6c8fea2SSven Eckelmann 
94c6c8fea2SSven Eckelmann #define DBG_BATMAN 1	/* all messages related to routing / flooding /
95c6c8fea2SSven Eckelmann 			 * broadcasting / etc */
96c6c8fea2SSven Eckelmann #define DBG_ROUTES 2	/* route or hna added / changed / deleted */
97c6c8fea2SSven Eckelmann #define DBG_ALL 3
98c6c8fea2SSven Eckelmann 
99c6c8fea2SSven Eckelmann #define LOG_BUF_LEN 8192          /* has to be a power of 2 */
100c6c8fea2SSven Eckelmann 
101c6c8fea2SSven Eckelmann 
102c6c8fea2SSven Eckelmann /*
103c6c8fea2SSven Eckelmann  *  Vis
104c6c8fea2SSven Eckelmann  */
105c6c8fea2SSven Eckelmann 
106c6c8fea2SSven Eckelmann /* #define VIS_SUBCLUSTERS_DISABLED */
107c6c8fea2SSven Eckelmann 
108c6c8fea2SSven Eckelmann /*
109c6c8fea2SSven Eckelmann  * Kernel headers
110c6c8fea2SSven Eckelmann  */
111c6c8fea2SSven Eckelmann 
112c6c8fea2SSven Eckelmann #include <linux/mutex.h>	/* mutex */
113c6c8fea2SSven Eckelmann #include <linux/module.h>	/* needed by all modules */
114c6c8fea2SSven Eckelmann #include <linux/netdevice.h>	/* netdevice */
115c6c8fea2SSven Eckelmann #include <linux/etherdevice.h>  /* ethernet address classifaction */
116c6c8fea2SSven Eckelmann #include <linux/if_ether.h>	/* ethernet header */
117c6c8fea2SSven Eckelmann #include <linux/poll.h>		/* poll_table */
118c6c8fea2SSven Eckelmann #include <linux/kthread.h>	/* kernel threads */
119c6c8fea2SSven Eckelmann #include <linux/pkt_sched.h>	/* schedule types */
120c6c8fea2SSven Eckelmann #include <linux/workqueue.h>	/* workqueue */
121c6c8fea2SSven Eckelmann #include <linux/slab.h>
122c6c8fea2SSven Eckelmann #include <net/sock.h>		/* struct sock */
123c6c8fea2SSven Eckelmann #include <linux/jiffies.h>
124c6c8fea2SSven Eckelmann #include <linux/seq_file.h>
125c6c8fea2SSven Eckelmann #include "types.h"
126c6c8fea2SSven Eckelmann 
127c6c8fea2SSven Eckelmann #ifndef REVISION_VERSION
128c6c8fea2SSven Eckelmann #define REVISION_VERSION_STR ""
129c6c8fea2SSven Eckelmann #else
130c6c8fea2SSven Eckelmann #define REVISION_VERSION_STR " "REVISION_VERSION
131c6c8fea2SSven Eckelmann #endif
132c6c8fea2SSven Eckelmann 
133c6c8fea2SSven Eckelmann extern struct list_head if_list;
134c6c8fea2SSven Eckelmann 
135c6c8fea2SSven Eckelmann extern unsigned char broadcast_addr[];
136c6c8fea2SSven Eckelmann extern struct workqueue_struct *bat_event_workqueue;
137c6c8fea2SSven Eckelmann 
138c6c8fea2SSven Eckelmann int mesh_init(struct net_device *soft_iface);
139c6c8fea2SSven Eckelmann void mesh_free(struct net_device *soft_iface);
140c6c8fea2SSven Eckelmann void inc_module_count(void);
141c6c8fea2SSven Eckelmann void dec_module_count(void);
142c6c8fea2SSven Eckelmann int is_my_mac(uint8_t *addr);
143c6c8fea2SSven Eckelmann 
144c6c8fea2SSven Eckelmann #ifdef CONFIG_BATMAN_ADV_DEBUG
145c6c8fea2SSven Eckelmann int debug_log(struct bat_priv *bat_priv, char *fmt, ...);
146c6c8fea2SSven Eckelmann 
147c6c8fea2SSven Eckelmann #define bat_dbg(type, bat_priv, fmt, arg...)			\
148c6c8fea2SSven Eckelmann 	do {							\
149c6c8fea2SSven Eckelmann 		if (atomic_read(&bat_priv->log_level) & type)	\
150c6c8fea2SSven Eckelmann 			debug_log(bat_priv, fmt, ## arg);	\
151c6c8fea2SSven Eckelmann 	}							\
152c6c8fea2SSven Eckelmann 	while (0)
153c6c8fea2SSven Eckelmann #else /* !CONFIG_BATMAN_ADV_DEBUG */
154*aa0adb1aSSven Eckelmann static inline void bat_dbg(char type __always_unused,
155*aa0adb1aSSven Eckelmann 			   struct bat_priv *bat_priv __always_unused,
156*aa0adb1aSSven Eckelmann 			   char *fmt __always_unused, ...)
157c6c8fea2SSven Eckelmann {
158c6c8fea2SSven Eckelmann }
159c6c8fea2SSven Eckelmann #endif
160c6c8fea2SSven Eckelmann 
161c6c8fea2SSven Eckelmann #define bat_warning(net_dev, fmt, arg...)				\
162c6c8fea2SSven Eckelmann 	do {								\
163c6c8fea2SSven Eckelmann 		struct net_device *_netdev = (net_dev);                 \
164c6c8fea2SSven Eckelmann 		struct bat_priv *_batpriv = netdev_priv(_netdev);       \
165c6c8fea2SSven Eckelmann 		bat_dbg(DBG_ALL, _batpriv, fmt, ## arg);		\
166c6c8fea2SSven Eckelmann 		pr_warning("%s: " fmt, _netdev->name, ## arg);		\
167c6c8fea2SSven Eckelmann 	} while (0)
168c6c8fea2SSven Eckelmann #define bat_info(net_dev, fmt, arg...)					\
169c6c8fea2SSven Eckelmann 	do {								\
170c6c8fea2SSven Eckelmann 		struct net_device *_netdev = (net_dev);                 \
171c6c8fea2SSven Eckelmann 		struct bat_priv *_batpriv = netdev_priv(_netdev);       \
172c6c8fea2SSven Eckelmann 		bat_dbg(DBG_ALL, _batpriv, fmt, ## arg);		\
173c6c8fea2SSven Eckelmann 		pr_info("%s: " fmt, _netdev->name, ## arg);		\
174c6c8fea2SSven Eckelmann 	} while (0)
175c6c8fea2SSven Eckelmann #define bat_err(net_dev, fmt, arg...)					\
176c6c8fea2SSven Eckelmann 	do {								\
177c6c8fea2SSven Eckelmann 		struct net_device *_netdev = (net_dev);                 \
178c6c8fea2SSven Eckelmann 		struct bat_priv *_batpriv = netdev_priv(_netdev);       \
179c6c8fea2SSven Eckelmann 		bat_dbg(DBG_ALL, _batpriv, fmt, ## arg);		\
180c6c8fea2SSven Eckelmann 		pr_err("%s: " fmt, _netdev->name, ## arg);		\
181c6c8fea2SSven Eckelmann 	} while (0)
182c6c8fea2SSven Eckelmann 
183c6c8fea2SSven Eckelmann #endif /* _NET_BATMAN_ADV_MAIN_H_ */
184