packet.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /* Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
  2. *
  3. * Marek Lindner, Simon Wunderlich
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of version 2 of the GNU General Public
  7. * License as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA
  18. */
  19. #ifndef _NET_BATMAN_ADV_PACKET_H_
  20. #define _NET_BATMAN_ADV_PACKET_H_
  21. #define BATADV_ETH_P_BATMAN 0x4305 /* unofficial/not registered Ethertype */
  22. enum batadv_packettype {
  23. BATADV_IV_OGM = 0x01,
  24. BATADV_ICMP = 0x02,
  25. BATADV_UNICAST = 0x03,
  26. BATADV_BCAST = 0x04,
  27. BATADV_VIS = 0x05,
  28. BATADV_UNICAST_FRAG = 0x06,
  29. BATADV_TT_QUERY = 0x07,
  30. BATADV_ROAM_ADV = 0x08,
  31. };
  32. /* this file is included by batctl which needs these defines */
  33. #define BATADV_COMPAT_VERSION 14
  34. enum batadv_iv_flags {
  35. BATADV_NOT_BEST_NEXT_HOP = BIT(3),
  36. BATADV_PRIMARIES_FIRST_HOP = BIT(4),
  37. BATADV_VIS_SERVER = BIT(5),
  38. BATADV_DIRECTLINK = BIT(6),
  39. };
  40. /* ICMP message types */
  41. enum batadv_icmp_packettype {
  42. BATADV_ECHO_REPLY = 0,
  43. BATADV_DESTINATION_UNREACHABLE = 3,
  44. BATADV_ECHO_REQUEST = 8,
  45. BATADV_TTL_EXCEEDED = 11,
  46. BATADV_PARAMETER_PROBLEM = 12,
  47. };
  48. /* vis defines */
  49. enum batadv_vis_packettype {
  50. BATADV_VIS_TYPE_SERVER_SYNC = 0,
  51. BATADV_VIS_TYPE_CLIENT_UPDATE = 1,
  52. };
  53. /* fragmentation defines */
  54. enum batadv_unicast_frag_flags {
  55. BATADV_UNI_FRAG_HEAD = BIT(0),
  56. BATADV_UNI_FRAG_LARGETAIL = BIT(1),
  57. };
  58. /* TT_QUERY subtypes */
  59. #define BATADV_TT_QUERY_TYPE_MASK 0x3
  60. enum batadv_tt_query_packettype {
  61. BATADV_TT_REQUEST = 0,
  62. BATADV_TT_RESPONSE = 1,
  63. };
  64. /* TT_QUERY flags */
  65. enum batadv_tt_query_flags {
  66. BATADV_TT_FULL_TABLE = BIT(2),
  67. };
  68. /* BATADV_TT_CLIENT flags.
  69. * Flags from BIT(0) to BIT(7) are sent on the wire, while flags from BIT(8) to
  70. * BIT(15) are used for local computation only
  71. */
  72. enum batadv_tt_client_flags {
  73. BATADV_TT_CLIENT_DEL = BIT(0),
  74. BATADV_TT_CLIENT_ROAM = BIT(1),
  75. BATADV_TT_CLIENT_WIFI = BIT(2),
  76. BATADV_TT_CLIENT_TEMP = BIT(3),
  77. BATADV_TT_CLIENT_NOPURGE = BIT(8),
  78. BATADV_TT_CLIENT_NEW = BIT(9),
  79. BATADV_TT_CLIENT_PENDING = BIT(10),
  80. };
  81. /* claim frame types for the bridge loop avoidance */
  82. enum batadv_bla_claimframe {
  83. BATADV_CLAIM_TYPE_CLAIM = 0x00,
  84. BATADV_CLAIM_TYPE_UNCLAIM = 0x01,
  85. BATADV_CLAIM_TYPE_ANNOUNCE = 0x02,
  86. BATADV_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 batadv_bla_claim_dst {
  92. uint8_t magic[3]; /* FF:43:05 */
  93. uint8_t type; /* bla_claimframe */
  94. __be16 group; /* group id */
  95. } __packed;
  96. struct batadv_header {
  97. uint8_t packet_type;
  98. uint8_t version; /* batman version field */
  99. uint8_t ttl;
  100. } __packed;
  101. struct batadv_ogm_packet {
  102. struct batadv_header header;
  103. uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
  104. __be32 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. __be16 tt_crc;
  112. } __packed;
  113. #define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
  114. struct batadv_icmp_packet {
  115. struct batadv_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. __be16 seqno;
  120. uint8_t uid;
  121. uint8_t reserved;
  122. } __packed;
  123. #define BATADV_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. */
  127. struct batadv_icmp_packet_rr {
  128. struct batadv_header header;
  129. uint8_t msg_type; /* see ICMP message types above */
  130. uint8_t dst[ETH_ALEN];
  131. uint8_t orig[ETH_ALEN];
  132. __be16 seqno;
  133. uint8_t uid;
  134. uint8_t rr_cur;
  135. uint8_t rr[BATADV_RR_LEN][ETH_ALEN];
  136. } __packed;
  137. struct batadv_unicast_packet {
  138. struct batadv_header header;
  139. uint8_t ttvn; /* destination translation table version number */
  140. uint8_t dest[ETH_ALEN];
  141. } __packed;
  142. struct batadv_unicast_frag_packet {
  143. struct batadv_header header;
  144. uint8_t ttvn; /* destination translation table version number */
  145. uint8_t dest[ETH_ALEN];
  146. uint8_t flags;
  147. uint8_t align;
  148. uint8_t orig[ETH_ALEN];
  149. __be16 seqno;
  150. } __packed;
  151. struct batadv_bcast_packet {
  152. struct batadv_header header;
  153. uint8_t reserved;
  154. __be32 seqno;
  155. uint8_t orig[ETH_ALEN];
  156. } __packed;
  157. struct batadv_vis_packet {
  158. struct batadv_header header;
  159. uint8_t vis_type; /* which type of vis-participant sent this? */
  160. __be32 seqno; /* sequence number */
  161. uint8_t entries; /* number of entries behind this struct */
  162. uint8_t reserved;
  163. uint8_t vis_orig[ETH_ALEN]; /* originator reporting its neighbors */
  164. uint8_t target_orig[ETH_ALEN]; /* who should receive this packet */
  165. uint8_t sender_orig[ETH_ALEN]; /* who sent or forwarded this packet */
  166. } __packed;
  167. struct batadv_tt_query_packet {
  168. struct batadv_header header;
  169. /* the flag field is a combination of:
  170. * - TT_REQUEST or TT_RESPONSE
  171. * - TT_FULL_TABLE
  172. */
  173. uint8_t flags;
  174. uint8_t dst[ETH_ALEN];
  175. uint8_t src[ETH_ALEN];
  176. /* the ttvn field is:
  177. * if TT_REQUEST: ttvn that triggered the
  178. * request
  179. * if TT_RESPONSE: new ttvn for the src
  180. * orig_node
  181. */
  182. uint8_t ttvn;
  183. /* tt_data field is:
  184. * if TT_REQUEST: crc associated with the
  185. * ttvn
  186. * if TT_RESPONSE: table_size
  187. */
  188. __be16 tt_data;
  189. } __packed;
  190. struct batadv_roam_adv_packet {
  191. struct batadv_header header;
  192. uint8_t reserved;
  193. uint8_t dst[ETH_ALEN];
  194. uint8_t src[ETH_ALEN];
  195. uint8_t client[ETH_ALEN];
  196. } __packed;
  197. struct batadv_tt_change {
  198. uint8_t flags;
  199. uint8_t addr[ETH_ALEN];
  200. } __packed;
  201. #endif /* _NET_BATMAN_ADV_PACKET_H_ */