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 #define TTL 50 /* Time To Live of broadcast messages */ 38c6c8fea2SSven Eckelmann 39c6c8fea2SSven Eckelmann #define PURGE_TIMEOUT 200 /* purge originators after time in seconds if no 40c6c8fea2SSven Eckelmann * valid packet comes in -> TODO: check 41c6c8fea2SSven Eckelmann * influence on TQ_LOCAL_WINDOW_SIZE */ 42c6c8fea2SSven Eckelmann #define LOCAL_HNA_TIMEOUT 3600 /* in seconds */ 43c6c8fea2SSven Eckelmann 44c6c8fea2SSven Eckelmann #define TQ_LOCAL_WINDOW_SIZE 64 /* sliding packet range of received originator 45c6c8fea2SSven Eckelmann * messages in squence numbers (should be a 46c6c8fea2SSven Eckelmann * multiple of our word size) */ 47c6c8fea2SSven Eckelmann #define TQ_GLOBAL_WINDOW_SIZE 5 48c6c8fea2SSven Eckelmann #define TQ_LOCAL_BIDRECT_SEND_MINIMUM 1 49c6c8fea2SSven Eckelmann #define TQ_LOCAL_BIDRECT_RECV_MINIMUM 1 50c6c8fea2SSven Eckelmann #define TQ_TOTAL_BIDRECT_LIMIT 1 51c6c8fea2SSven Eckelmann 52c6c8fea2SSven Eckelmann #define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE) 53c6c8fea2SSven Eckelmann 54c6c8fea2SSven Eckelmann #define LOG_BUF_LEN 8192 /* has to be a power of 2 */ 55c6c8fea2SSven Eckelmann 56c6c8fea2SSven Eckelmann #define VIS_INTERVAL 5000 /* 5 seconds */ 57c6c8fea2SSven Eckelmann 58c6c8fea2SSven Eckelmann /* how much worse secondary interfaces may be to 59c6c8fea2SSven Eckelmann * to be considered as bonding candidates */ 60c6c8fea2SSven Eckelmann 61c6c8fea2SSven Eckelmann #define BONDING_TQ_THRESHOLD 50 62c6c8fea2SSven Eckelmann 63c6c8fea2SSven Eckelmann #define MAX_AGGREGATION_BYTES 512 /* should not be bigger than 512 bytes or 64c6c8fea2SSven Eckelmann * change the size of 65c6c8fea2SSven Eckelmann * forw_packet->direct_link_flags */ 66c6c8fea2SSven Eckelmann #define MAX_AGGREGATION_MS 100 67c6c8fea2SSven Eckelmann 68c6c8fea2SSven Eckelmann #define SOFTIF_NEIGH_TIMEOUT 180000 /* 3 minutes */ 69c6c8fea2SSven Eckelmann 70c6c8fea2SSven Eckelmann #define RESET_PROTECTION_MS 30000 71c6c8fea2SSven Eckelmann #define EXPECTED_SEQNO_RANGE 65536 72c6c8fea2SSven Eckelmann /* don't reset again within 30 seconds */ 73c6c8fea2SSven Eckelmann 74c6c8fea2SSven Eckelmann #define MESH_INACTIVE 0 75c6c8fea2SSven Eckelmann #define MESH_ACTIVE 1 76c6c8fea2SSven Eckelmann #define MESH_DEACTIVATING 2 77c6c8fea2SSven Eckelmann 78c6c8fea2SSven Eckelmann #define BCAST_QUEUE_LEN 256 79c6c8fea2SSven Eckelmann #define BATMAN_QUEUE_LEN 256 80c6c8fea2SSven Eckelmann 81c6c8fea2SSven Eckelmann /* 82c6c8fea2SSven Eckelmann * Debug Messages 83c6c8fea2SSven Eckelmann */ 84c6c8fea2SSven Eckelmann #ifdef pr_fmt 85c6c8fea2SSven Eckelmann #undef pr_fmt 86c6c8fea2SSven Eckelmann #endif 87c6c8fea2SSven Eckelmann #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt /* Append 'batman-adv: ' before 88c6c8fea2SSven Eckelmann * kernel messages */ 89c6c8fea2SSven Eckelmann 90c6c8fea2SSven Eckelmann #define DBG_BATMAN 1 /* all messages related to routing / flooding / 91c6c8fea2SSven Eckelmann * broadcasting / etc */ 92c6c8fea2SSven Eckelmann #define DBG_ROUTES 2 /* route or hna added / changed / deleted */ 93c6c8fea2SSven Eckelmann #define DBG_ALL 3 94c6c8fea2SSven Eckelmann 95c6c8fea2SSven Eckelmann 96c6c8fea2SSven Eckelmann /* 97c6c8fea2SSven Eckelmann * Vis 98c6c8fea2SSven Eckelmann */ 99c6c8fea2SSven Eckelmann 100c6c8fea2SSven Eckelmann /* 101c6c8fea2SSven Eckelmann * Kernel headers 102c6c8fea2SSven Eckelmann */ 103c6c8fea2SSven Eckelmann 104c6c8fea2SSven Eckelmann #include <linux/mutex.h> /* mutex */ 105c6c8fea2SSven Eckelmann #include <linux/module.h> /* needed by all modules */ 106c6c8fea2SSven Eckelmann #include <linux/netdevice.h> /* netdevice */ 107c6c8fea2SSven Eckelmann #include <linux/etherdevice.h> /* ethernet address classifaction */ 108c6c8fea2SSven Eckelmann #include <linux/if_ether.h> /* ethernet header */ 109c6c8fea2SSven Eckelmann #include <linux/poll.h> /* poll_table */ 110c6c8fea2SSven Eckelmann #include <linux/kthread.h> /* kernel threads */ 111c6c8fea2SSven Eckelmann #include <linux/pkt_sched.h> /* schedule types */ 112c6c8fea2SSven Eckelmann #include <linux/workqueue.h> /* workqueue */ 113c6c8fea2SSven Eckelmann #include <linux/slab.h> 114c6c8fea2SSven Eckelmann #include <net/sock.h> /* struct sock */ 115c6c8fea2SSven Eckelmann #include <linux/jiffies.h> 116c6c8fea2SSven Eckelmann #include <linux/seq_file.h> 117c6c8fea2SSven Eckelmann #include "types.h" 118c6c8fea2SSven Eckelmann 119c6c8fea2SSven Eckelmann #ifndef REVISION_VERSION 120c6c8fea2SSven Eckelmann #define REVISION_VERSION_STR "" 121c6c8fea2SSven Eckelmann #else 122c6c8fea2SSven Eckelmann #define REVISION_VERSION_STR " "REVISION_VERSION 123c6c8fea2SSven Eckelmann #endif 124c6c8fea2SSven Eckelmann 125c6c8fea2SSven Eckelmann extern struct list_head if_list; 126c6c8fea2SSven Eckelmann 127c6c8fea2SSven Eckelmann extern unsigned char broadcast_addr[]; 128c6c8fea2SSven Eckelmann extern struct workqueue_struct *bat_event_workqueue; 129c6c8fea2SSven Eckelmann 130c6c8fea2SSven Eckelmann int mesh_init(struct net_device *soft_iface); 131c6c8fea2SSven Eckelmann void mesh_free(struct net_device *soft_iface); 132c6c8fea2SSven Eckelmann void inc_module_count(void); 133c6c8fea2SSven Eckelmann void dec_module_count(void); 134c6c8fea2SSven Eckelmann int is_my_mac(uint8_t *addr); 135c6c8fea2SSven Eckelmann 136c6c8fea2SSven Eckelmann #ifdef CONFIG_BATMAN_ADV_DEBUG 137c6c8fea2SSven Eckelmann int debug_log(struct bat_priv *bat_priv, char *fmt, ...); 138c6c8fea2SSven Eckelmann 139c6c8fea2SSven Eckelmann #define bat_dbg(type, bat_priv, fmt, arg...) \ 140c6c8fea2SSven Eckelmann do { \ 141c6c8fea2SSven Eckelmann if (atomic_read(&bat_priv->log_level) & type) \ 142c6c8fea2SSven Eckelmann debug_log(bat_priv, fmt, ## arg); \ 143c6c8fea2SSven Eckelmann } \ 144c6c8fea2SSven Eckelmann while (0) 145c6c8fea2SSven Eckelmann #else /* !CONFIG_BATMAN_ADV_DEBUG */ 146aa0adb1aSSven Eckelmann static inline void bat_dbg(char type __always_unused, 147aa0adb1aSSven Eckelmann struct bat_priv *bat_priv __always_unused, 148aa0adb1aSSven Eckelmann char *fmt __always_unused, ...) 149c6c8fea2SSven Eckelmann { 150c6c8fea2SSven Eckelmann } 151c6c8fea2SSven Eckelmann #endif 152c6c8fea2SSven Eckelmann 153c6c8fea2SSven Eckelmann #define bat_info(net_dev, fmt, arg...) \ 154c6c8fea2SSven Eckelmann do { \ 155c6c8fea2SSven Eckelmann struct net_device *_netdev = (net_dev); \ 156c6c8fea2SSven Eckelmann struct bat_priv *_batpriv = netdev_priv(_netdev); \ 157c6c8fea2SSven Eckelmann bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \ 158c6c8fea2SSven Eckelmann pr_info("%s: " fmt, _netdev->name, ## arg); \ 159c6c8fea2SSven Eckelmann } while (0) 160c6c8fea2SSven Eckelmann #define bat_err(net_dev, fmt, arg...) \ 161c6c8fea2SSven Eckelmann do { \ 162c6c8fea2SSven Eckelmann struct net_device *_netdev = (net_dev); \ 163c6c8fea2SSven Eckelmann struct bat_priv *_batpriv = netdev_priv(_netdev); \ 164c6c8fea2SSven Eckelmann bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \ 165c6c8fea2SSven Eckelmann pr_err("%s: " fmt, _netdev->name, ## arg); \ 166c6c8fea2SSven Eckelmann } while (0) 167c6c8fea2SSven Eckelmann 168*39901e71SMarek Lindner /** 169*39901e71SMarek Lindner * returns 1 if they are the same ethernet addr 170*39901e71SMarek Lindner * 171*39901e71SMarek Lindner * note: can't use compare_ether_addr() as it requires aligned memory 172*39901e71SMarek Lindner */ 173*39901e71SMarek Lindner static inline int compare_eth(void *data1, void *data2) 174*39901e71SMarek Lindner { 175*39901e71SMarek Lindner return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); 176*39901e71SMarek Lindner } 177*39901e71SMarek Lindner 178c6c8fea2SSven Eckelmann #endif /* _NET_BATMAN_ADV_MAIN_H_ */ 179