2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
4 * Marek Lindner, Simon Wunderlich
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.
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.
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
22 /* Kernel Programming */
25 #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"
30 #define SOURCE_VERSION "0.2.2-beta"
33 /* B.A.T.M.A.N. parameters */
35 #define TQ_MAX_VALUE 255
37 #define TTL 50 /* Time To Live of broadcast messages */
39 #define PURGE_TIMEOUT 200000 /* purge originators after time in ms if no
40 * valid packet comes in -> TODO: check
41 * influence on TQ_LOCAL_WINDOW_SIZE */
42 #define LOCAL_HNA_TIMEOUT 3600000
44 #define TQ_LOCAL_WINDOW_SIZE 64 /* sliding packet range of received originator
45 * messages in squence numbers (should be a
46 * multiple of our word size) */
47 #define TQ_GLOBAL_WINDOW_SIZE 5
48 #define TQ_LOCAL_BIDRECT_SEND_MINIMUM 1
49 #define TQ_LOCAL_BIDRECT_RECV_MINIMUM 1
50 #define TQ_TOTAL_BIDRECT_LIMIT 1
52 #define TQ_HOP_PENALTY 10
54 #define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE)
56 #define PACKBUFF_SIZE 2000
57 #define LOG_BUF_LEN 8192 /* has to be a power of 2 */
58 #define ETH_STR_LEN 20
60 #define MAX_AGGREGATION_BYTES 512 /* should not be bigger than 512 bytes or
62 * forw_packet->direct_link_flags */
63 #define MAX_AGGREGATION_MS 100
65 #define RESET_PROTECTION_MS 30000
66 #define EXPECTED_SEQNO_RANGE 4096
67 /* don't reset again within 30 seconds */
69 #define MODULE_INACTIVE 0
70 #define MODULE_ACTIVE 1
71 #define MODULE_DEACTIVATING 2
73 #define BCAST_QUEUE_LEN 256
74 #define BATMAN_QUEUE_LEN 256
80 #define DBG_BATMAN 1 /* all messages related to routing / flooding /
81 * broadcasting / etc */
82 #define DBG_ROUTES 2 /* route or hna added / changed / deleted */
84 #ifdef CONFIG_BATMAN_ADV_DEBUG
87 extern int bat_debug_type(int type);
88 #define bat_dbg(type, fmt, arg...) do { \
89 if (bat_debug_type(type)) \
90 printk(KERN_DEBUG "batman-adv:" fmt, ## arg); \
93 #else /* !CONFIG_BATMAN_ADV_DEBUG */
94 #define bat_dbg(type, fmt, arg...) do { \
103 /* #define VIS_SUBCLUSTERS_DISABLED */
109 #include <linux/mutex.h> /* mutex */
110 #include <linux/module.h> /* needed by all modules */
111 #include <linux/netdevice.h> /* netdevice */
112 #include <linux/if_ether.h> /* ethernet header */
113 #include <linux/poll.h> /* poll_table */
114 #include <linux/kthread.h> /* kernel threads */
115 #include <linux/pkt_sched.h> /* schedule types */
116 #include <linux/workqueue.h> /* workqueue */
117 #include <linux/slab.h>
118 #include <net/sock.h> /* struct sock */
119 #include <linux/jiffies.h>
122 #ifndef REVISION_VERSION
123 #define REVISION_VERSION_STR ""
125 #define REVISION_VERSION_STR " "REVISION_VERSION
128 extern struct list_head if_list;
129 extern struct hlist_head forw_bat_list;
130 extern struct hlist_head forw_bcast_list;
131 extern struct hashtable_t *orig_hash;
133 extern spinlock_t orig_hash_lock;
134 extern spinlock_t forw_bat_list_lock;
135 extern spinlock_t forw_bcast_list_lock;
137 extern atomic_t vis_interval;
138 extern atomic_t bcast_queue_left;
139 extern atomic_t batman_queue_left;
140 extern int16_t num_hna;
142 extern struct net_device *soft_device;
144 extern unsigned char broadcastAddr[];
145 extern atomic_t module_state;
146 extern struct workqueue_struct *bat_event_workqueue;
148 void activate_module(void);
149 void deactivate_module(void);
150 void inc_module_count(void);
151 void dec_module_count(void);
152 int addr_to_string(char *buff, uint8_t *addr);
153 int compare_orig(void *data1, void *data2);
154 int choose_orig(void *data, int32_t size);
155 int is_my_mac(uint8_t *addr);
156 int is_bcast(uint8_t *addr);
157 int is_mcast(uint8_t *addr);