1c6c8fea2SSven Eckelmann /* 264afe353SSven Eckelmann * Copyright (C) 2007-2011 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 #define DRIVER_AUTHOR "Marek Lindner <lindner_marek@yahoo.de>, " \ 26c6c8fea2SSven Eckelmann "Simon Wunderlich <siwu@hrz.tu-chemnitz.de>" 27c6c8fea2SSven Eckelmann #define DRIVER_DESC "B.A.T.M.A.N. advanced" 28c6c8fea2SSven Eckelmann #define DRIVER_DEVICE "batman-adv" 29c6c8fea2SSven Eckelmann 30c6c8fea2SSven Eckelmann #define SOURCE_VERSION "next" 31c6c8fea2SSven Eckelmann 32c6c8fea2SSven Eckelmann 33c6c8fea2SSven Eckelmann /* B.A.T.M.A.N. parameters */ 34c6c8fea2SSven Eckelmann 35c6c8fea2SSven Eckelmann #define TQ_MAX_VALUE 255 36c6c8fea2SSven Eckelmann #define JITTER 20 37c6c8fea2SSven Eckelmann 386e215fd8SSven Eckelmann /* Time To Live of broadcast messages */ 396e215fd8SSven Eckelmann #define TTL 50 406e215fd8SSven Eckelmann 416e215fd8SSven Eckelmann /* purge originators after time in seconds if no valid packet comes in 426e215fd8SSven Eckelmann * -> TODO: check influence on TQ_LOCAL_WINDOW_SIZE */ 436e215fd8SSven Eckelmann #define PURGE_TIMEOUT 200 442dafb49dSAntonio Quartulli #define TT_LOCAL_TIMEOUT 3600 /* in seconds */ 45c6c8fea2SSven Eckelmann 466e215fd8SSven Eckelmann /* sliding packet range of received originator messages in squence numbers 476e215fd8SSven Eckelmann * (should be a multiple of our word size) */ 486e215fd8SSven Eckelmann #define TQ_LOCAL_WINDOW_SIZE 64 49c6c8fea2SSven Eckelmann #define TQ_GLOBAL_WINDOW_SIZE 5 50c6c8fea2SSven Eckelmann #define TQ_LOCAL_BIDRECT_SEND_MINIMUM 1 51c6c8fea2SSven Eckelmann #define TQ_LOCAL_BIDRECT_RECV_MINIMUM 1 52c6c8fea2SSven Eckelmann #define TQ_TOTAL_BIDRECT_LIMIT 1 53c6c8fea2SSven Eckelmann 54c6c8fea2SSven Eckelmann #define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE) 55c6c8fea2SSven Eckelmann 56c6c8fea2SSven Eckelmann #define LOG_BUF_LEN 8192 /* has to be a power of 2 */ 57c6c8fea2SSven Eckelmann 58c6c8fea2SSven Eckelmann #define VIS_INTERVAL 5000 /* 5 seconds */ 59c6c8fea2SSven Eckelmann 606e215fd8SSven Eckelmann /* how much worse secondary interfaces may be to be considered as bonding 616e215fd8SSven Eckelmann * candidates */ 62c6c8fea2SSven Eckelmann #define BONDING_TQ_THRESHOLD 50 63c6c8fea2SSven Eckelmann 646e215fd8SSven Eckelmann /* should not be bigger than 512 bytes or change the size of 65c6c8fea2SSven Eckelmann * forw_packet->direct_link_flags */ 666e215fd8SSven Eckelmann #define MAX_AGGREGATION_BYTES 512 67c6c8fea2SSven Eckelmann #define MAX_AGGREGATION_MS 100 68c6c8fea2SSven Eckelmann 69c6c8fea2SSven Eckelmann #define SOFTIF_NEIGH_TIMEOUT 180000 /* 3 minutes */ 70c6c8fea2SSven Eckelmann 716e215fd8SSven Eckelmann /* don't reset again within 30 seconds */ 72c6c8fea2SSven Eckelmann #define RESET_PROTECTION_MS 30000 73c6c8fea2SSven Eckelmann #define EXPECTED_SEQNO_RANGE 65536 74c6c8fea2SSven Eckelmann 75c6c8fea2SSven Eckelmann #define MESH_INACTIVE 0 76c6c8fea2SSven Eckelmann #define MESH_ACTIVE 1 77c6c8fea2SSven Eckelmann #define MESH_DEACTIVATING 2 78c6c8fea2SSven Eckelmann 79c6c8fea2SSven Eckelmann #define BCAST_QUEUE_LEN 256 80c6c8fea2SSven Eckelmann #define BATMAN_QUEUE_LEN 256 81c6c8fea2SSven Eckelmann 82c6c8fea2SSven Eckelmann /* 83c6c8fea2SSven Eckelmann * Debug Messages 84c6c8fea2SSven Eckelmann */ 85c6c8fea2SSven Eckelmann #ifdef pr_fmt 86c6c8fea2SSven Eckelmann #undef pr_fmt 87c6c8fea2SSven Eckelmann #endif 886e215fd8SSven Eckelmann /* Append 'batman-adv: ' before kernel messages */ 896e215fd8SSven Eckelmann #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 90c6c8fea2SSven Eckelmann 916e215fd8SSven Eckelmann /* all messages related to routing / flooding / broadcasting / etc */ 926e215fd8SSven Eckelmann #define DBG_BATMAN 1 936e215fd8SSven Eckelmann /* route or tt entry added / changed / deleted */ 946e215fd8SSven Eckelmann #define DBG_ROUTES 2 95c6c8fea2SSven Eckelmann #define DBG_ALL 3 96c6c8fea2SSven Eckelmann 97c6c8fea2SSven Eckelmann 98c6c8fea2SSven Eckelmann /* 99c6c8fea2SSven Eckelmann * Vis 100c6c8fea2SSven Eckelmann */ 101c6c8fea2SSven Eckelmann 102c6c8fea2SSven Eckelmann /* 103c6c8fea2SSven Eckelmann * Kernel headers 104c6c8fea2SSven Eckelmann */ 105c6c8fea2SSven Eckelmann 106c6c8fea2SSven Eckelmann #include <linux/mutex.h> /* mutex */ 107c6c8fea2SSven Eckelmann #include <linux/module.h> /* needed by all modules */ 108c6c8fea2SSven Eckelmann #include <linux/netdevice.h> /* netdevice */ 109c6c8fea2SSven Eckelmann #include <linux/etherdevice.h> /* ethernet address classifaction */ 110c6c8fea2SSven Eckelmann #include <linux/if_ether.h> /* ethernet header */ 111c6c8fea2SSven Eckelmann #include <linux/poll.h> /* poll_table */ 112c6c8fea2SSven Eckelmann #include <linux/kthread.h> /* kernel threads */ 113c6c8fea2SSven Eckelmann #include <linux/pkt_sched.h> /* schedule types */ 114c6c8fea2SSven Eckelmann #include <linux/workqueue.h> /* workqueue */ 115c6c8fea2SSven Eckelmann #include <linux/slab.h> 116c6c8fea2SSven Eckelmann #include <net/sock.h> /* struct sock */ 117c6c8fea2SSven Eckelmann #include <linux/jiffies.h> 118c6c8fea2SSven Eckelmann #include <linux/seq_file.h> 119c6c8fea2SSven Eckelmann #include "types.h" 120c6c8fea2SSven Eckelmann 121c6c8fea2SSven Eckelmann #ifndef REVISION_VERSION 122c6c8fea2SSven Eckelmann #define REVISION_VERSION_STR "" 123c6c8fea2SSven Eckelmann #else 124c6c8fea2SSven Eckelmann #define REVISION_VERSION_STR " "REVISION_VERSION 125c6c8fea2SSven Eckelmann #endif 126c6c8fea2SSven Eckelmann 1274389e47aSMarek Lindner extern struct list_head hardif_list; 128c6c8fea2SSven Eckelmann 129c6c8fea2SSven Eckelmann extern unsigned char broadcast_addr[]; 130c6c8fea2SSven Eckelmann extern struct workqueue_struct *bat_event_workqueue; 131c6c8fea2SSven Eckelmann 132c6c8fea2SSven Eckelmann int mesh_init(struct net_device *soft_iface); 133c6c8fea2SSven Eckelmann void mesh_free(struct net_device *soft_iface); 134c6c8fea2SSven Eckelmann void inc_module_count(void); 135c6c8fea2SSven Eckelmann void dec_module_count(void); 136747e4221SSven Eckelmann int is_my_mac(const uint8_t *addr); 137c6c8fea2SSven Eckelmann 138c6c8fea2SSven Eckelmann #ifdef CONFIG_BATMAN_ADV_DEBUG 139747e4221SSven Eckelmann int debug_log(struct bat_priv *bat_priv, const char *fmt, ...) __printf(2, 3); 140c6c8fea2SSven Eckelmann 141c6c8fea2SSven Eckelmann #define bat_dbg(type, bat_priv, fmt, arg...) \ 142c6c8fea2SSven Eckelmann do { \ 143c6c8fea2SSven Eckelmann if (atomic_read(&bat_priv->log_level) & type) \ 144c6c8fea2SSven Eckelmann debug_log(bat_priv, fmt, ## arg); \ 145c6c8fea2SSven Eckelmann } \ 146c6c8fea2SSven Eckelmann while (0) 147c6c8fea2SSven Eckelmann #else /* !CONFIG_BATMAN_ADV_DEBUG */ 148d3a547beSSven Eckelmann __printf(3, 4) 149aa0adb1aSSven Eckelmann static inline void bat_dbg(char type __always_unused, 150aa0adb1aSSven Eckelmann struct bat_priv *bat_priv __always_unused, 151747e4221SSven Eckelmann const char *fmt __always_unused, ...) 152c6c8fea2SSven Eckelmann { 153c6c8fea2SSven Eckelmann } 154c6c8fea2SSven Eckelmann #endif 155c6c8fea2SSven Eckelmann 156c6c8fea2SSven Eckelmann #define bat_info(net_dev, fmt, arg...) \ 157c6c8fea2SSven Eckelmann do { \ 158c6c8fea2SSven Eckelmann struct net_device *_netdev = (net_dev); \ 159c6c8fea2SSven Eckelmann struct bat_priv *_batpriv = netdev_priv(_netdev); \ 160c6c8fea2SSven Eckelmann bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \ 161c6c8fea2SSven Eckelmann pr_info("%s: " fmt, _netdev->name, ## arg); \ 162c6c8fea2SSven Eckelmann } while (0) 163c6c8fea2SSven Eckelmann #define bat_err(net_dev, fmt, arg...) \ 164c6c8fea2SSven Eckelmann do { \ 165c6c8fea2SSven Eckelmann struct net_device *_netdev = (net_dev); \ 166c6c8fea2SSven Eckelmann struct bat_priv *_batpriv = netdev_priv(_netdev); \ 167c6c8fea2SSven Eckelmann bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \ 168c6c8fea2SSven Eckelmann pr_err("%s: " fmt, _netdev->name, ## arg); \ 169c6c8fea2SSven Eckelmann } while (0) 170c6c8fea2SSven Eckelmann 17139901e71SMarek Lindner /** 17239901e71SMarek Lindner * returns 1 if they are the same ethernet addr 17339901e71SMarek Lindner * 17439901e71SMarek Lindner * note: can't use compare_ether_addr() as it requires aligned memory 17539901e71SMarek Lindner */ 176747e4221SSven Eckelmann 177747e4221SSven Eckelmann static inline int compare_eth(const void *data1, const void *data2) 17839901e71SMarek Lindner { 17939901e71SMarek Lindner return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); 18039901e71SMarek Lindner } 18139901e71SMarek Lindner 182747e4221SSven Eckelmann 1835f657ec0SAntonio Quartulli #define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) 1845f657ec0SAntonio Quartulli 185*f5d33d37SAntonio Quartulli /* Returns the smallest signed integer in two's complement with the sizeof x */ 186*f5d33d37SAntonio Quartulli #define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u))) 187*f5d33d37SAntonio Quartulli 188*f5d33d37SAntonio Quartulli /* Checks if a sequence number x is a predecessor/successor of y. 189*f5d33d37SAntonio Quartulli * they handle overflows/underflows and can correctly check for a 190*f5d33d37SAntonio Quartulli * predecessor/successor unless the variable sequence number has grown by 191*f5d33d37SAntonio Quartulli * more then 2**(bitwidth(x)-1)-1. 192*f5d33d37SAntonio Quartulli * This means that for a uint8_t with the maximum value 255, it would think: 193*f5d33d37SAntonio Quartulli * - when adding nothing - it is neither a predecessor nor a successor 194*f5d33d37SAntonio Quartulli * - before adding more than 127 to the starting value - it is a predecessor, 195*f5d33d37SAntonio Quartulli * - when adding 128 - it is neither a predecessor nor a successor, 196*f5d33d37SAntonio Quartulli * - after adding more than 127 to the starting value - it is a successor */ 197*f5d33d37SAntonio Quartulli #define seq_before(x, y) ({typeof(x) _dummy = (x - y); \ 198*f5d33d37SAntonio Quartulli _dummy > smallest_signed_int(_dummy); }) 199*f5d33d37SAntonio Quartulli #define seq_after(x, y) seq_before(y, x) 200*f5d33d37SAntonio Quartulli 201c6c8fea2SSven Eckelmann #endif /* _NET_BATMAN_ADV_MAIN_H_ */ 202