blob: ba28436bcdd6379c0e20fbca2b6fea67b8b64e0c [file] [log] [blame]
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001/*
Sven Eckelmann64afe352011-01-27 10:38:15 +01002 * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_MAIN_H_
23#define _NET_BATMAN_ADV_MAIN_H_
24
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000025#define DRIVER_AUTHOR "Marek Lindner <lindner_marek@yahoo.de>, " \
26 "Simon Wunderlich <siwu@hrz.tu-chemnitz.de>"
27#define DRIVER_DESC "B.A.T.M.A.N. advanced"
28#define DRIVER_DEVICE "batman-adv"
29
30#define SOURCE_VERSION "next"
31
32
33/* B.A.T.M.A.N. parameters */
34
35#define TQ_MAX_VALUE 255
36#define JITTER 20
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000037
Sven Eckelmann6e215fd2011-05-08 12:45:45 +020038 /* Time To Live of broadcast messages */
39#define TTL 50
40
41/* purge originators after time in seconds if no valid packet comes in
42 * -> TODO: check influence on TQ_LOCAL_WINDOW_SIZE */
43#define PURGE_TIMEOUT 200
Antonio Quartulli2dafb492011-05-05 08:42:45 +020044#define TT_LOCAL_TIMEOUT 3600 /* in seconds */
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000045
Sven Eckelmann6e215fd2011-05-08 12:45:45 +020046/* sliding packet range of received originator messages in squence numbers
47 * (should be a multiple of our word size) */
48#define TQ_LOCAL_WINDOW_SIZE 64
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000049#define TQ_GLOBAL_WINDOW_SIZE 5
50#define TQ_LOCAL_BIDRECT_SEND_MINIMUM 1
51#define TQ_LOCAL_BIDRECT_RECV_MINIMUM 1
52#define TQ_TOTAL_BIDRECT_LIMIT 1
53
54#define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE)
55
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000056#define LOG_BUF_LEN 8192 /* has to be a power of 2 */
57
58#define VIS_INTERVAL 5000 /* 5 seconds */
59
Sven Eckelmann6e215fd2011-05-08 12:45:45 +020060/* how much worse secondary interfaces may be to be considered as bonding
61 * candidates */
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000062#define BONDING_TQ_THRESHOLD 50
63
Sven Eckelmann6e215fd2011-05-08 12:45:45 +020064/* should not be bigger than 512 bytes or change the size of
65 * forw_packet->direct_link_flags */
66#define MAX_AGGREGATION_BYTES 512
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000067#define MAX_AGGREGATION_MS 100
68
69#define SOFTIF_NEIGH_TIMEOUT 180000 /* 3 minutes */
70
Sven Eckelmann6e215fd2011-05-08 12:45:45 +020071/* don't reset again within 30 seconds */
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000072#define RESET_PROTECTION_MS 30000
73#define EXPECTED_SEQNO_RANGE 65536
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000074
75#define MESH_INACTIVE 0
76#define MESH_ACTIVE 1
77#define MESH_DEACTIVATING 2
78
79#define BCAST_QUEUE_LEN 256
80#define BATMAN_QUEUE_LEN 256
81
82/*
83 * Debug Messages
84 */
85#ifdef pr_fmt
86#undef pr_fmt
87#endif
Sven Eckelmann6e215fd2011-05-08 12:45:45 +020088/* Append 'batman-adv: ' before kernel messages */
89#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000090
Sven Eckelmann6e215fd2011-05-08 12:45:45 +020091/* all messages related to routing / flooding / broadcasting / etc */
92#define DBG_BATMAN 1
93/* route or tt entry added / changed / deleted */
94#define DBG_ROUTES 2
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000095#define DBG_ALL 3
96
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000097
98/*
99 * Vis
100 */
101
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000102/*
103 * Kernel headers
104 */
105
106#include <linux/mutex.h> /* mutex */
107#include <linux/module.h> /* needed by all modules */
108#include <linux/netdevice.h> /* netdevice */
109#include <linux/etherdevice.h> /* ethernet address classifaction */
110#include <linux/if_ether.h> /* ethernet header */
111#include <linux/poll.h> /* poll_table */
112#include <linux/kthread.h> /* kernel threads */
113#include <linux/pkt_sched.h> /* schedule types */
114#include <linux/workqueue.h> /* workqueue */
115#include <linux/slab.h>
116#include <net/sock.h> /* struct sock */
117#include <linux/jiffies.h>
118#include <linux/seq_file.h>
119#include "types.h"
120
121#ifndef REVISION_VERSION
122#define REVISION_VERSION_STR ""
123#else
124#define REVISION_VERSION_STR " "REVISION_VERSION
125#endif
126
Marek Lindner4389e472011-02-18 12:33:19 +0000127extern struct list_head hardif_list;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000128
129extern unsigned char broadcast_addr[];
130extern struct workqueue_struct *bat_event_workqueue;
131
132int mesh_init(struct net_device *soft_iface);
133void mesh_free(struct net_device *soft_iface);
134void inc_module_count(void);
135void dec_module_count(void);
136int is_my_mac(uint8_t *addr);
137
138#ifdef CONFIG_BATMAN_ADV_DEBUG
Sven Eckelmannd3a547b2011-05-14 23:14:46 +0200139int debug_log(struct bat_priv *bat_priv, char *fmt, ...) __printf(2, 3);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000140
141#define bat_dbg(type, bat_priv, fmt, arg...) \
142 do { \
143 if (atomic_read(&bat_priv->log_level) & type) \
144 debug_log(bat_priv, fmt, ## arg); \
145 } \
146 while (0)
147#else /* !CONFIG_BATMAN_ADV_DEBUG */
Sven Eckelmannd3a547b2011-05-14 23:14:46 +0200148__printf(3, 4)
Sven Eckelmannaa0adb12011-01-15 14:39:43 +0000149static inline void bat_dbg(char type __always_unused,
150 struct bat_priv *bat_priv __always_unused,
151 char *fmt __always_unused, ...)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000152{
153}
154#endif
155
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000156#define bat_info(net_dev, fmt, arg...) \
157 do { \
158 struct net_device *_netdev = (net_dev); \
159 struct bat_priv *_batpriv = netdev_priv(_netdev); \
160 bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \
161 pr_info("%s: " fmt, _netdev->name, ## arg); \
162 } while (0)
163#define bat_err(net_dev, fmt, arg...) \
164 do { \
165 struct net_device *_netdev = (net_dev); \
166 struct bat_priv *_batpriv = netdev_priv(_netdev); \
167 bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \
168 pr_err("%s: " fmt, _netdev->name, ## arg); \
169 } while (0)
170
Marek Lindner39901e72011-02-18 12:28:08 +0000171/**
172 * returns 1 if they are the same ethernet addr
173 *
174 * note: can't use compare_ether_addr() as it requires aligned memory
175 */
176static inline int compare_eth(void *data1, void *data2)
177{
178 return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
179}
180
Antonio Quartulli5f657ec2011-04-20 09:52:56 +0200181#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)
182
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000183#endif /* _NET_BATMAN_ADV_MAIN_H_ */