main.h 5.1 KB

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