packet.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. };
  96. struct batadv_header {
  97. uint8_t packet_type;
  98. uint8_t version; /* batman version field */
  99. uint8_t ttl;
  100. /* the parent struct has to add a byte after the header to make
  101. * everything 4 bytes aligned again
  102. */
  103. };
  104. struct batadv_ogm_packet {
  105. struct batadv_header header;
  106. uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
  107. __be32 seqno;
  108. uint8_t orig[ETH_ALEN];
  109. uint8_t prev_sender[ETH_ALEN];
  110. uint8_t gw_flags; /* flags related to gateway class */
  111. uint8_t tq;
  112. uint8_t tt_num_changes;
  113. uint8_t ttvn; /* translation table version number */
  114. __be16 tt_crc;
  115. } __packed;
  116. #define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
  117. struct batadv_icmp_packet {
  118. struct batadv_header header;
  119. uint8_t msg_type; /* see ICMP message types above */
  120. uint8_t dst[ETH_ALEN];
  121. uint8_t orig[ETH_ALEN];
  122. __be16 seqno;
  123. uint8_t uid;
  124. uint8_t reserved;
  125. };
  126. #define BATADV_RR_LEN 16
  127. /* icmp_packet_rr must start with all fields from imcp_packet
  128. * as this is assumed by code that handles ICMP packets
  129. */
  130. struct batadv_icmp_packet_rr {
  131. struct batadv_header header;
  132. uint8_t msg_type; /* see ICMP message types above */
  133. uint8_t dst[ETH_ALEN];
  134. uint8_t orig[ETH_ALEN];
  135. __be16 seqno;
  136. uint8_t uid;
  137. uint8_t rr_cur;
  138. uint8_t rr[BATADV_RR_LEN][ETH_ALEN];
  139. };
  140. struct batadv_unicast_packet {
  141. struct batadv_header header;
  142. uint8_t ttvn; /* destination translation table version number */
  143. uint8_t dest[ETH_ALEN];
  144. /* "4 bytes boundary + 2 bytes" long to make the payload after the
  145. * following ethernet header again 4 bytes boundary aligned
  146. */
  147. };
  148. struct batadv_unicast_frag_packet {
  149. struct batadv_header header;
  150. uint8_t ttvn; /* destination translation table version number */
  151. uint8_t dest[ETH_ALEN];
  152. uint8_t flags;
  153. uint8_t align;
  154. uint8_t orig[ETH_ALEN];
  155. __be16 seqno;
  156. } __packed;
  157. struct batadv_bcast_packet {
  158. struct batadv_header header;
  159. uint8_t reserved;
  160. __be32 seqno;
  161. uint8_t orig[ETH_ALEN];
  162. /* "4 bytes boundary + 2 bytes" long to make the payload after the
  163. * following ethernet header again 4 bytes boundary aligned
  164. */
  165. } __packed;
  166. struct batadv_vis_packet {
  167. struct batadv_header header;
  168. uint8_t vis_type; /* which type of vis-participant sent this? */
  169. __be32 seqno; /* sequence number */
  170. uint8_t entries; /* number of entries behind this struct */
  171. uint8_t reserved;
  172. uint8_t vis_orig[ETH_ALEN]; /* originator reporting its neighbors */
  173. uint8_t target_orig[ETH_ALEN]; /* who should receive this packet */
  174. uint8_t sender_orig[ETH_ALEN]; /* who sent or forwarded this packet */
  175. };
  176. struct batadv_tt_query_packet {
  177. struct batadv_header header;
  178. /* the flag field is a combination of:
  179. * - TT_REQUEST or TT_RESPONSE
  180. * - TT_FULL_TABLE
  181. */
  182. uint8_t flags;
  183. uint8_t dst[ETH_ALEN];
  184. uint8_t src[ETH_ALEN];
  185. /* the ttvn field is:
  186. * if TT_REQUEST: ttvn that triggered the
  187. * request
  188. * if TT_RESPONSE: new ttvn for the src
  189. * orig_node
  190. */
  191. uint8_t ttvn;
  192. /* tt_data field is:
  193. * if TT_REQUEST: crc associated with the
  194. * ttvn
  195. * if TT_RESPONSE: table_size
  196. */
  197. __be16 tt_data;
  198. } __packed;
  199. struct batadv_roam_adv_packet {
  200. struct batadv_header header;
  201. uint8_t reserved;
  202. uint8_t dst[ETH_ALEN];
  203. uint8_t src[ETH_ALEN];
  204. uint8_t client[ETH_ALEN];
  205. } __packed;
  206. struct batadv_tt_change {
  207. uint8_t flags;
  208. uint8_t addr[ETH_ALEN];
  209. } __packed;
  210. #endif /* _NET_BATMAN_ADV_PACKET_H_ */