packet.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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_PACKET_H_
  22. #define _NET_BATMAN_ADV_PACKET_H_
  23. #define ETH_P_BATMAN 0x4305 /* unofficial/not registered Ethertype */
  24. enum bat_packettype {
  25. BAT_PACKET = 0x01,
  26. BAT_ICMP = 0x02,
  27. BAT_UNICAST = 0x03,
  28. BAT_BCAST = 0x04,
  29. BAT_VIS = 0x05,
  30. BAT_UNICAST_FRAG = 0x06,
  31. BAT_TT_QUERY = 0x07,
  32. BAT_ROAM_ADV = 0x08
  33. };
  34. /* this file is included by batctl which needs these defines */
  35. #define COMPAT_VERSION 14
  36. enum batman_flags {
  37. PRIMARIES_FIRST_HOP = 1 << 4,
  38. VIS_SERVER = 1 << 5,
  39. DIRECTLINK = 1 << 6
  40. };
  41. /* ICMP message types */
  42. enum icmp_packettype {
  43. ECHO_REPLY = 0,
  44. DESTINATION_UNREACHABLE = 3,
  45. ECHO_REQUEST = 8,
  46. TTL_EXCEEDED = 11,
  47. PARAMETER_PROBLEM = 12
  48. };
  49. /* vis defines */
  50. enum vis_packettype {
  51. VIS_TYPE_SERVER_SYNC = 0,
  52. VIS_TYPE_CLIENT_UPDATE = 1
  53. };
  54. /* fragmentation defines */
  55. enum unicast_frag_flags {
  56. UNI_FRAG_HEAD = 1 << 0,
  57. UNI_FRAG_LARGETAIL = 1 << 1
  58. };
  59. /* TT_QUERY subtypes */
  60. #define TT_QUERY_TYPE_MASK 0x3
  61. enum tt_query_packettype {
  62. TT_REQUEST = 0,
  63. TT_RESPONSE = 1
  64. };
  65. /* TT_QUERY flags */
  66. enum tt_query_flags {
  67. TT_FULL_TABLE = 1 << 2
  68. };
  69. /* TT_CHANGE flags */
  70. enum tt_change_flags {
  71. TT_CHANGE_DEL = 0x01,
  72. TT_CLIENT_ROAM = 0x02
  73. };
  74. struct batman_packet {
  75. uint8_t packet_type;
  76. uint8_t version; /* batman version field */
  77. uint8_t ttl;
  78. uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
  79. uint32_t seqno;
  80. uint8_t orig[6];
  81. uint8_t prev_sender[6];
  82. uint8_t gw_flags; /* flags related to gateway class */
  83. uint8_t tq;
  84. uint8_t tt_num_changes;
  85. uint8_t ttvn; /* translation table version number */
  86. uint16_t tt_crc;
  87. } __packed;
  88. #define BAT_PACKET_LEN sizeof(struct batman_packet)
  89. struct icmp_packet {
  90. uint8_t packet_type;
  91. uint8_t version; /* batman version field */
  92. uint8_t ttl;
  93. uint8_t msg_type; /* see ICMP message types above */
  94. uint8_t dst[6];
  95. uint8_t orig[6];
  96. uint16_t seqno;
  97. uint8_t uid;
  98. uint8_t reserved;
  99. } __packed;
  100. #define BAT_RR_LEN 16
  101. /* icmp_packet_rr must start with all fields from imcp_packet
  102. * as this is assumed by code that handles ICMP packets */
  103. struct icmp_packet_rr {
  104. uint8_t packet_type;
  105. uint8_t version; /* batman version field */
  106. uint8_t ttl;
  107. uint8_t msg_type; /* see ICMP message types above */
  108. uint8_t dst[6];
  109. uint8_t orig[6];
  110. uint16_t seqno;
  111. uint8_t uid;
  112. uint8_t rr_cur;
  113. uint8_t rr[BAT_RR_LEN][ETH_ALEN];
  114. } __packed;
  115. struct unicast_packet {
  116. uint8_t packet_type;
  117. uint8_t version; /* batman version field */
  118. uint8_t ttl;
  119. uint8_t ttvn; /* destination translation table version number */
  120. uint8_t dest[6];
  121. } __packed;
  122. struct unicast_frag_packet {
  123. uint8_t packet_type;
  124. uint8_t version; /* batman version field */
  125. uint8_t ttl;
  126. uint8_t ttvn; /* destination translation table version number */
  127. uint8_t dest[6];
  128. uint8_t flags;
  129. uint8_t align;
  130. uint8_t orig[6];
  131. uint16_t seqno;
  132. } __packed;
  133. struct bcast_packet {
  134. uint8_t packet_type;
  135. uint8_t version; /* batman version field */
  136. uint8_t ttl;
  137. uint8_t reserved;
  138. uint32_t seqno;
  139. uint8_t orig[6];
  140. } __packed;
  141. struct vis_packet {
  142. uint8_t packet_type;
  143. uint8_t version; /* batman version field */
  144. uint8_t ttl; /* TTL */
  145. uint8_t vis_type; /* which type of vis-participant sent this? */
  146. uint32_t seqno; /* sequence number */
  147. uint8_t entries; /* number of entries behind this struct */
  148. uint8_t reserved;
  149. uint8_t vis_orig[6]; /* originator that announces its neighbors */
  150. uint8_t target_orig[6]; /* who should receive this packet */
  151. uint8_t sender_orig[6]; /* who sent or rebroadcasted this packet */
  152. } __packed;
  153. struct tt_query_packet {
  154. uint8_t packet_type;
  155. uint8_t version; /* batman version field */
  156. uint8_t ttl;
  157. /* the flag field is a combination of:
  158. * - TT_REQUEST or TT_RESPONSE
  159. * - TT_FULL_TABLE */
  160. uint8_t flags;
  161. uint8_t dst[ETH_ALEN];
  162. uint8_t src[ETH_ALEN];
  163. /* the ttvn field is:
  164. * if TT_REQUEST: ttvn that triggered the
  165. * request
  166. * if TT_RESPONSE: new ttvn for the src
  167. * orig_node */
  168. uint8_t ttvn;
  169. /* tt_data field is:
  170. * if TT_REQUEST: crc associated with the
  171. * ttvn
  172. * if TT_RESPONSE: table_size */
  173. uint16_t tt_data;
  174. } __packed;
  175. struct roam_adv_packet {
  176. uint8_t packet_type;
  177. uint8_t version;
  178. uint8_t ttl;
  179. uint8_t reserved;
  180. uint8_t dst[ETH_ALEN];
  181. uint8_t src[ETH_ALEN];
  182. uint8_t client[ETH_ALEN];
  183. } __packed;
  184. struct tt_change {
  185. uint8_t flags;
  186. uint8_t addr[ETH_ALEN];
  187. } __packed;
  188. #endif /* _NET_BATMAN_ADV_PACKET_H_ */