packet.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. 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. /* claim frame types for the bridge loop avoidance */
  81. enum bla_claimframe {
  82. CLAIM_TYPE_ADD = 0x00,
  83. CLAIM_TYPE_DEL = 0x01,
  84. CLAIM_TYPE_ANNOUNCE = 0x02,
  85. CLAIM_TYPE_REQUEST = 0x03
  86. };
  87. /* the destination hardware field in the ARP frame is used to
  88. * transport the claim type and the group id
  89. */
  90. struct bla_claim_dst {
  91. uint8_t magic[3]; /* FF:43:05 */
  92. uint8_t type; /* bla_claimframe */
  93. uint16_t group; /* group id */
  94. } __packed;
  95. struct batman_header {
  96. uint8_t packet_type;
  97. uint8_t version; /* batman version field */
  98. uint8_t ttl;
  99. } __packed;
  100. struct batman_ogm_packet {
  101. struct batman_header header;
  102. uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
  103. uint32_t seqno;
  104. uint8_t orig[ETH_ALEN];
  105. uint8_t prev_sender[ETH_ALEN];
  106. uint8_t gw_flags; /* flags related to gateway class */
  107. uint8_t tq;
  108. uint8_t tt_num_changes;
  109. uint8_t ttvn; /* translation table version number */
  110. uint16_t tt_crc;
  111. } __packed;
  112. #define BATMAN_OGM_HLEN sizeof(struct batman_ogm_packet)
  113. struct icmp_packet {
  114. struct batman_header header;
  115. uint8_t msg_type; /* see ICMP message types above */
  116. uint8_t dst[ETH_ALEN];
  117. uint8_t orig[ETH_ALEN];
  118. uint16_t seqno;
  119. uint8_t uid;
  120. uint8_t reserved;
  121. } __packed;
  122. #define BAT_RR_LEN 16
  123. /* icmp_packet_rr must start with all fields from imcp_packet
  124. * as this is assumed by code that handles ICMP packets */
  125. struct icmp_packet_rr {
  126. struct batman_header header;
  127. uint8_t msg_type; /* see ICMP message types above */
  128. uint8_t dst[ETH_ALEN];
  129. uint8_t orig[ETH_ALEN];
  130. uint16_t seqno;
  131. uint8_t uid;
  132. uint8_t rr_cur;
  133. uint8_t rr[BAT_RR_LEN][ETH_ALEN];
  134. } __packed;
  135. struct unicast_packet {
  136. struct batman_header header;
  137. uint8_t ttvn; /* destination translation table version number */
  138. uint8_t dest[ETH_ALEN];
  139. } __packed;
  140. struct unicast_frag_packet {
  141. struct batman_header header;
  142. uint8_t ttvn; /* destination translation table version number */
  143. uint8_t dest[ETH_ALEN];
  144. uint8_t flags;
  145. uint8_t align;
  146. uint8_t orig[ETH_ALEN];
  147. uint16_t seqno;
  148. } __packed;
  149. struct bcast_packet {
  150. struct batman_header header;
  151. uint8_t reserved;
  152. uint32_t seqno;
  153. uint8_t orig[ETH_ALEN];
  154. } __packed;
  155. struct vis_packet {
  156. struct batman_header header;
  157. uint8_t vis_type; /* which type of vis-participant sent this? */
  158. uint32_t seqno; /* sequence number */
  159. uint8_t entries; /* number of entries behind this struct */
  160. uint8_t reserved;
  161. uint8_t vis_orig[ETH_ALEN]; /* originator reporting its neighbors */
  162. uint8_t target_orig[ETH_ALEN]; /* who should receive this packet */
  163. uint8_t sender_orig[ETH_ALEN]; /* who sent or forwarded this packet */
  164. } __packed;
  165. struct tt_query_packet {
  166. struct batman_header header;
  167. /* the flag field is a combination of:
  168. * - TT_REQUEST or TT_RESPONSE
  169. * - TT_FULL_TABLE */
  170. uint8_t flags;
  171. uint8_t dst[ETH_ALEN];
  172. uint8_t src[ETH_ALEN];
  173. /* the ttvn field is:
  174. * if TT_REQUEST: ttvn that triggered the
  175. * request
  176. * if TT_RESPONSE: new ttvn for the src
  177. * orig_node */
  178. uint8_t ttvn;
  179. /* tt_data field is:
  180. * if TT_REQUEST: crc associated with the
  181. * ttvn
  182. * if TT_RESPONSE: table_size */
  183. uint16_t tt_data;
  184. } __packed;
  185. struct roam_adv_packet {
  186. struct batman_header header;
  187. uint8_t reserved;
  188. uint8_t dst[ETH_ALEN];
  189. uint8_t src[ETH_ALEN];
  190. uint8_t client[ETH_ALEN];
  191. } __packed;
  192. struct tt_change {
  193. uint8_t flags;
  194. uint8_t addr[ETH_ALEN];
  195. } __packed;
  196. #endif /* _NET_BATMAN_ADV_PACKET_H_ */