packet.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Copyright (C) 2007-2012 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_OGM = 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_CLIENT flags.
  70. * Flags from 1 to 1 << 7 are sent on the wire, while flags from 1 << 8 to
  71. * 1 << 15 are used for local computation only */
  72. enum tt_client_flags {
  73. TT_CLIENT_DEL = 1 << 0,
  74. TT_CLIENT_ROAM = 1 << 1,
  75. TT_CLIENT_WIFI = 1 << 2,
  76. TT_CLIENT_NOPURGE = 1 << 8,
  77. TT_CLIENT_NEW = 1 << 9,
  78. TT_CLIENT_PENDING = 1 << 10
  79. };
  80. struct batman_header {
  81. uint8_t packet_type;
  82. uint8_t version; /* batman version field */
  83. uint8_t ttl;
  84. } __packed;
  85. struct batman_ogm_packet {
  86. struct batman_header header;
  87. uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
  88. uint32_t seqno;
  89. uint8_t orig[6];
  90. uint8_t prev_sender[6];
  91. uint8_t gw_flags; /* flags related to gateway class */
  92. uint8_t tq;
  93. uint8_t tt_num_changes;
  94. uint8_t ttvn; /* translation table version number */
  95. uint16_t tt_crc;
  96. } __packed;
  97. #define BATMAN_OGM_LEN sizeof(struct batman_ogm_packet)
  98. struct icmp_packet {
  99. struct batman_header header;
  100. uint8_t msg_type; /* see ICMP message types above */
  101. uint8_t dst[6];
  102. uint8_t orig[6];
  103. uint16_t seqno;
  104. uint8_t uid;
  105. uint8_t reserved;
  106. } __packed;
  107. #define BAT_RR_LEN 16
  108. /* icmp_packet_rr must start with all fields from imcp_packet
  109. * as this is assumed by code that handles ICMP packets */
  110. struct icmp_packet_rr {
  111. struct batman_header header;
  112. uint8_t msg_type; /* see ICMP message types above */
  113. uint8_t dst[6];
  114. uint8_t orig[6];
  115. uint16_t seqno;
  116. uint8_t uid;
  117. uint8_t rr_cur;
  118. uint8_t rr[BAT_RR_LEN][ETH_ALEN];
  119. } __packed;
  120. struct unicast_packet {
  121. struct batman_header header;
  122. uint8_t ttvn; /* destination translation table version number */
  123. uint8_t dest[6];
  124. } __packed;
  125. struct unicast_frag_packet {
  126. struct batman_header header;
  127. uint8_t ttvn; /* destination translation table version number */
  128. uint8_t dest[6];
  129. uint8_t flags;
  130. uint8_t align;
  131. uint8_t orig[6];
  132. uint16_t seqno;
  133. } __packed;
  134. struct bcast_packet {
  135. struct batman_header header;
  136. uint8_t reserved;
  137. uint32_t seqno;
  138. uint8_t orig[6];
  139. } __packed;
  140. struct vis_packet {
  141. struct batman_header header;
  142. uint8_t vis_type; /* which type of vis-participant sent this? */
  143. uint32_t seqno; /* sequence number */
  144. uint8_t entries; /* number of entries behind this struct */
  145. uint8_t reserved;
  146. uint8_t vis_orig[6]; /* originator that announces its neighbors */
  147. uint8_t target_orig[6]; /* who should receive this packet */
  148. uint8_t sender_orig[6]; /* who sent or rebroadcasted this packet */
  149. } __packed;
  150. struct tt_query_packet {
  151. struct batman_header header;
  152. /* the flag field is a combination of:
  153. * - TT_REQUEST or TT_RESPONSE
  154. * - TT_FULL_TABLE */
  155. uint8_t flags;
  156. uint8_t dst[ETH_ALEN];
  157. uint8_t src[ETH_ALEN];
  158. /* the ttvn field is:
  159. * if TT_REQUEST: ttvn that triggered the
  160. * request
  161. * if TT_RESPONSE: new ttvn for the src
  162. * orig_node */
  163. uint8_t ttvn;
  164. /* tt_data field is:
  165. * if TT_REQUEST: crc associated with the
  166. * ttvn
  167. * if TT_RESPONSE: table_size */
  168. uint16_t tt_data;
  169. } __packed;
  170. struct roam_adv_packet {
  171. struct batman_header header;
  172. uint8_t reserved;
  173. uint8_t dst[ETH_ALEN];
  174. uint8_t src[ETH_ALEN];
  175. uint8_t client[ETH_ALEN];
  176. } __packed;
  177. struct tt_change {
  178. uint8_t flags;
  179. uint8_t addr[ETH_ALEN];
  180. } __packed;
  181. #endif /* _NET_BATMAN_ADV_PACKET_H_ */