packet.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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_IV_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_iv_flags {
  37. NOT_BEST_NEXT_HOP = 1 << 3,
  38. PRIMARIES_FIRST_HOP = 1 << 4,
  39. VIS_SERVER = 1 << 5,
  40. DIRECTLINK = 1 << 6
  41. };
  42. /* ICMP message types */
  43. enum icmp_packettype {
  44. ECHO_REPLY = 0,
  45. DESTINATION_UNREACHABLE = 3,
  46. ECHO_REQUEST = 8,
  47. TTL_EXCEEDED = 11,
  48. PARAMETER_PROBLEM = 12
  49. };
  50. /* vis defines */
  51. enum vis_packettype {
  52. VIS_TYPE_SERVER_SYNC = 0,
  53. VIS_TYPE_CLIENT_UPDATE = 1
  54. };
  55. /* fragmentation defines */
  56. enum unicast_frag_flags {
  57. UNI_FRAG_HEAD = 1 << 0,
  58. UNI_FRAG_LARGETAIL = 1 << 1
  59. };
  60. /* TT_QUERY subtypes */
  61. #define TT_QUERY_TYPE_MASK 0x3
  62. enum tt_query_packettype {
  63. TT_REQUEST = 0,
  64. TT_RESPONSE = 1
  65. };
  66. /* TT_QUERY flags */
  67. enum tt_query_flags {
  68. TT_FULL_TABLE = 1 << 2
  69. };
  70. /* TT_CLIENT flags.
  71. * Flags from 1 to 1 << 7 are sent on the wire, while flags from 1 << 8 to
  72. * 1 << 15 are used for local computation only */
  73. enum tt_client_flags {
  74. TT_CLIENT_DEL = 1 << 0,
  75. TT_CLIENT_ROAM = 1 << 1,
  76. TT_CLIENT_WIFI = 1 << 2,
  77. TT_CLIENT_NOPURGE = 1 << 8,
  78. TT_CLIENT_NEW = 1 << 9,
  79. TT_CLIENT_PENDING = 1 << 10
  80. };
  81. /* claim frame types for the bridge loop avoidance */
  82. enum bla_claimframe {
  83. CLAIM_TYPE_ADD = 0x00,
  84. CLAIM_TYPE_DEL = 0x01,
  85. CLAIM_TYPE_ANNOUNCE = 0x02,
  86. CLAIM_TYPE_REQUEST = 0x03
  87. };
  88. /* the destination hardware field in the ARP frame is used to
  89. * transport the claim type and the group id
  90. */
  91. struct bla_claim_dst {
  92. uint8_t magic[3]; /* FF:43:05 */
  93. uint8_t type; /* bla_claimframe */
  94. uint16_t group; /* group id */
  95. } __packed;
  96. struct batman_header {
  97. uint8_t packet_type;
  98. uint8_t version; /* batman version field */
  99. uint8_t ttl;
  100. } __packed;
  101. struct batman_ogm_packet {
  102. struct batman_header header;
  103. uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
  104. uint32_t seqno;
  105. uint8_t orig[ETH_ALEN];
  106. uint8_t prev_sender[ETH_ALEN];
  107. uint8_t gw_flags; /* flags related to gateway class */
  108. uint8_t tq;
  109. uint8_t tt_num_changes;
  110. uint8_t ttvn; /* translation table version number */
  111. uint16_t tt_crc;
  112. } __packed;
  113. #define BATMAN_OGM_HLEN sizeof(struct batman_ogm_packet)
  114. struct icmp_packet {
  115. struct batman_header header;
  116. uint8_t msg_type; /* see ICMP message types above */
  117. uint8_t dst[ETH_ALEN];
  118. uint8_t orig[ETH_ALEN];
  119. uint16_t seqno;
  120. uint8_t uid;
  121. uint8_t reserved;
  122. } __packed;
  123. #define BAT_RR_LEN 16
  124. /* icmp_packet_rr must start with all fields from imcp_packet
  125. * as this is assumed by code that handles ICMP packets */
  126. struct icmp_packet_rr {
  127. struct batman_header header;
  128. uint8_t msg_type; /* see ICMP message types above */
  129. uint8_t dst[ETH_ALEN];
  130. uint8_t orig[ETH_ALEN];
  131. uint16_t seqno;
  132. uint8_t uid;
  133. uint8_t rr_cur;
  134. uint8_t rr[BAT_RR_LEN][ETH_ALEN];
  135. } __packed;
  136. struct unicast_packet {
  137. struct batman_header header;
  138. uint8_t ttvn; /* destination translation table version number */
  139. uint8_t dest[ETH_ALEN];
  140. } __packed;
  141. struct unicast_frag_packet {
  142. struct batman_header header;
  143. uint8_t ttvn; /* destination translation table version number */
  144. uint8_t dest[ETH_ALEN];
  145. uint8_t flags;
  146. uint8_t align;
  147. uint8_t orig[ETH_ALEN];
  148. uint16_t seqno;
  149. } __packed;
  150. struct bcast_packet {
  151. struct batman_header header;
  152. uint8_t reserved;
  153. uint32_t seqno;
  154. uint8_t orig[ETH_ALEN];
  155. } __packed;
  156. struct vis_packet {
  157. struct batman_header header;
  158. uint8_t vis_type; /* which type of vis-participant sent this? */
  159. uint32_t seqno; /* sequence number */
  160. uint8_t entries; /* number of entries behind this struct */
  161. uint8_t reserved;
  162. uint8_t vis_orig[ETH_ALEN]; /* originator reporting its neighbors */
  163. uint8_t target_orig[ETH_ALEN]; /* who should receive this packet */
  164. uint8_t sender_orig[ETH_ALEN]; /* who sent or forwarded this packet */
  165. } __packed;
  166. struct tt_query_packet {
  167. struct batman_header header;
  168. /* the flag field is a combination of:
  169. * - TT_REQUEST or TT_RESPONSE
  170. * - TT_FULL_TABLE */
  171. uint8_t flags;
  172. uint8_t dst[ETH_ALEN];
  173. uint8_t src[ETH_ALEN];
  174. /* the ttvn field is:
  175. * if TT_REQUEST: ttvn that triggered the
  176. * request
  177. * if TT_RESPONSE: new ttvn for the src
  178. * orig_node */
  179. uint8_t ttvn;
  180. /* tt_data field is:
  181. * if TT_REQUEST: crc associated with the
  182. * ttvn
  183. * if TT_RESPONSE: table_size */
  184. uint16_t tt_data;
  185. } __packed;
  186. struct roam_adv_packet {
  187. struct batman_header header;
  188. uint8_t reserved;
  189. uint8_t dst[ETH_ALEN];
  190. uint8_t src[ETH_ALEN];
  191. uint8_t client[ETH_ALEN];
  192. } __packed;
  193. struct tt_change {
  194. uint8_t flags;
  195. uint8_t addr[ETH_ALEN];
  196. } __packed;
  197. #endif /* _NET_BATMAN_ADV_PACKET_H_ */