blob: 9f77086a5461d9eb43dea2451aceb220e0cb1ba8 [file] [log] [blame]
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001/*
Sven Eckelmann64afe352011-01-27 10:38:15 +01002 * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
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
22#ifndef _NET_BATMAN_ADV_PACKET_H_
23#define _NET_BATMAN_ADV_PACKET_H_
24
25#define ETH_P_BATMAN 0x4305 /* unofficial/not registered Ethertype */
26
Sven Eckelmanne8958db2011-06-04 11:26:00 +020027enum bat_packettype {
28 BAT_PACKET = 0x01,
29 BAT_ICMP = 0x02,
30 BAT_UNICAST = 0x03,
31 BAT_BCAST = 0x04,
32 BAT_VIS = 0x05,
33 BAT_UNICAST_FRAG = 0x06
34};
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000035
36/* this file is included by batctl which needs these defines */
37#define COMPAT_VERSION 12
Sven Eckelmanne8958db2011-06-04 11:26:00 +020038
39enum batman_flags {
40 PRIMARIES_FIRST_HOP = 1 << 4,
41 VIS_SERVER = 1 << 5,
42 DIRECTLINK = 1 << 6
43};
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000044
45/* ICMP message types */
Sven Eckelmanne8958db2011-06-04 11:26:00 +020046enum icmp_packettype {
47 ECHO_REPLY = 0,
48 DESTINATION_UNREACHABLE = 3,
49 ECHO_REQUEST = 8,
50 TTL_EXCEEDED = 11,
51 PARAMETER_PROBLEM = 12
52};
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000053
54/* vis defines */
Sven Eckelmanne8958db2011-06-04 11:26:00 +020055enum vis_packettype {
56 VIS_TYPE_SERVER_SYNC = 0,
57 VIS_TYPE_CLIENT_UPDATE = 1
58};
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000059
60/* fragmentation defines */
Sven Eckelmanne8958db2011-06-04 11:26:00 +020061enum unicast_frag_flags {
62 UNI_FRAG_HEAD = 1 << 0,
63 UNI_FRAG_LARGETAIL = 1 << 1
64};
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000065
66struct batman_packet {
67 uint8_t packet_type;
68 uint8_t version; /* batman version field */
69 uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
70 uint8_t tq;
71 uint32_t seqno;
72 uint8_t orig[6];
73 uint8_t prev_sender[6];
74 uint8_t ttl;
Antonio Quartulli2dafb492011-05-05 08:42:45 +020075 uint8_t num_tt;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000076 uint8_t gw_flags; /* flags related to gateway class */
77 uint8_t align;
Sven Eckelmannaa0adb12011-01-15 14:39:43 +000078} __packed;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000079
80#define BAT_PACKET_LEN sizeof(struct batman_packet)
81
82struct icmp_packet {
83 uint8_t packet_type;
84 uint8_t version; /* batman version field */
85 uint8_t msg_type; /* see ICMP message types above */
86 uint8_t ttl;
87 uint8_t dst[6];
88 uint8_t orig[6];
89 uint16_t seqno;
90 uint8_t uid;
Sven Eckelmannaa0adb12011-01-15 14:39:43 +000091} __packed;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000092
93#define BAT_RR_LEN 16
94
95/* icmp_packet_rr must start with all fields from imcp_packet
96 * as this is assumed by code that handles ICMP packets */
97struct icmp_packet_rr {
98 uint8_t packet_type;
99 uint8_t version; /* batman version field */
100 uint8_t msg_type; /* see ICMP message types above */
101 uint8_t ttl;
102 uint8_t dst[6];
103 uint8_t orig[6];
104 uint16_t seqno;
105 uint8_t uid;
106 uint8_t rr_cur;
107 uint8_t rr[BAT_RR_LEN][ETH_ALEN];
Sven Eckelmannaa0adb12011-01-15 14:39:43 +0000108} __packed;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000109
110struct unicast_packet {
111 uint8_t packet_type;
112 uint8_t version; /* batman version field */
113 uint8_t dest[6];
114 uint8_t ttl;
Sven Eckelmannaa0adb12011-01-15 14:39:43 +0000115} __packed;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000116
117struct unicast_frag_packet {
118 uint8_t packet_type;
119 uint8_t version; /* batman version field */
120 uint8_t dest[6];
121 uint8_t ttl;
122 uint8_t flags;
123 uint8_t orig[6];
124 uint16_t seqno;
Sven Eckelmannaa0adb12011-01-15 14:39:43 +0000125} __packed;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000126
127struct bcast_packet {
128 uint8_t packet_type;
129 uint8_t version; /* batman version field */
130 uint8_t orig[6];
131 uint8_t ttl;
132 uint32_t seqno;
Sven Eckelmannaa0adb12011-01-15 14:39:43 +0000133} __packed;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000134
135struct vis_packet {
136 uint8_t packet_type;
137 uint8_t version; /* batman version field */
138 uint8_t vis_type; /* which type of vis-participant sent this? */
139 uint8_t entries; /* number of entries behind this struct */
140 uint32_t seqno; /* sequence number */
141 uint8_t ttl; /* TTL */
Sven Eckelmann6e215fd2011-05-08 12:45:45 +0200142 uint8_t vis_orig[6]; /* originator that announces its neighbors */
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000143 uint8_t target_orig[6]; /* who should receive this packet */
144 uint8_t sender_orig[6]; /* who sent or rebroadcasted this packet */
Sven Eckelmannaa0adb12011-01-15 14:39:43 +0000145} __packed;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000146
147#endif /* _NET_BATMAN_ADV_PACKET_H_ */