batman-adv: remove vis functionality
[GitHub/exynos8895/android_kernel_samsung_universal8895.git] / net / batman-adv / packet.h
1 /* Copyright (C) 2007-2013 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
20 #ifndef _NET_BATMAN_ADV_PACKET_H_
21 #define _NET_BATMAN_ADV_PACKET_H_
22
23 /**
24 * enum batadv_packettype - types for batman-adv encapsulated packets
25 * @BATADV_UNICAST_TVLV: unicast packet carrying TVLV containers
26 */
27 enum batadv_packettype {
28 BATADV_IV_OGM = 0x01,
29 BATADV_ICMP = 0x02,
30 BATADV_UNICAST = 0x03,
31 BATADV_BCAST = 0x04,
32 BATADV_UNICAST_FRAG = 0x06,
33 BATADV_UNICAST_4ADDR = 0x09,
34 BATADV_CODED = 0x0a,
35 BATADV_UNICAST_TVLV = 0x0b,
36 };
37
38 /**
39 * enum batadv_subtype - packet subtype for unicast4addr
40 * @BATADV_P_DATA: user payload
41 * @BATADV_P_DAT_DHT_GET: DHT request message
42 * @BATADV_P_DAT_DHT_PUT: DHT store message
43 * @BATADV_P_DAT_CACHE_REPLY: ARP reply generated by DAT
44 */
45 enum batadv_subtype {
46 BATADV_P_DATA = 0x01,
47 BATADV_P_DAT_DHT_GET = 0x02,
48 BATADV_P_DAT_DHT_PUT = 0x03,
49 BATADV_P_DAT_CACHE_REPLY = 0x04,
50 };
51
52 /* this file is included by batctl which needs these defines */
53 #define BATADV_COMPAT_VERSION 15
54
55 enum batadv_iv_flags {
56 BATADV_NOT_BEST_NEXT_HOP = BIT(3),
57 BATADV_PRIMARIES_FIRST_HOP = BIT(4),
58 BATADV_DIRECTLINK = BIT(6),
59 };
60
61 /* ICMP message types */
62 enum batadv_icmp_packettype {
63 BATADV_ECHO_REPLY = 0,
64 BATADV_DESTINATION_UNREACHABLE = 3,
65 BATADV_ECHO_REQUEST = 8,
66 BATADV_TTL_EXCEEDED = 11,
67 BATADV_PARAMETER_PROBLEM = 12,
68 };
69
70 /* fragmentation defines */
71 enum batadv_unicast_frag_flags {
72 BATADV_UNI_FRAG_HEAD = BIT(0),
73 BATADV_UNI_FRAG_LARGETAIL = BIT(1),
74 };
75
76 /* tt data subtypes */
77 #define BATADV_TT_DATA_TYPE_MASK 0x0F
78
79 /**
80 * enum batadv_tt_data_flags - flags for tt data tvlv
81 * @BATADV_TT_OGM_DIFF: TT diff propagated through OGM
82 * @BATADV_TT_REQUEST: TT request message
83 * @BATADV_TT_RESPONSE: TT response message
84 * @BATADV_TT_FULL_TABLE: contains full table to replace existing table
85 */
86 enum batadv_tt_data_flags {
87 BATADV_TT_OGM_DIFF = BIT(0),
88 BATADV_TT_REQUEST = BIT(1),
89 BATADV_TT_RESPONSE = BIT(2),
90 BATADV_TT_FULL_TABLE = BIT(4),
91 };
92
93 /* BATADV_TT_CLIENT flags.
94 * Flags from BIT(0) to BIT(7) are sent on the wire, while flags from BIT(8) to
95 * BIT(15) are used for local computation only
96 */
97 enum batadv_tt_client_flags {
98 BATADV_TT_CLIENT_DEL = BIT(0),
99 BATADV_TT_CLIENT_ROAM = BIT(1),
100 BATADV_TT_CLIENT_WIFI = BIT(2),
101 BATADV_TT_CLIENT_NOPURGE = BIT(8),
102 BATADV_TT_CLIENT_NEW = BIT(9),
103 BATADV_TT_CLIENT_PENDING = BIT(10),
104 BATADV_TT_CLIENT_TEMP = BIT(11),
105 };
106
107 /* claim frame types for the bridge loop avoidance */
108 enum batadv_bla_claimframe {
109 BATADV_CLAIM_TYPE_CLAIM = 0x00,
110 BATADV_CLAIM_TYPE_UNCLAIM = 0x01,
111 BATADV_CLAIM_TYPE_ANNOUNCE = 0x02,
112 BATADV_CLAIM_TYPE_REQUEST = 0x03,
113 };
114
115 /**
116 * enum batadv_tvlv_type - tvlv type definitions
117 * @BATADV_TVLV_GW: gateway tvlv
118 * @BATADV_TVLV_DAT: distributed arp table tvlv
119 * @BATADV_TVLV_NC: network coding tvlv
120 * @BATADV_TVLV_TT: translation table tvlv
121 * @BATADV_TVLV_ROAM: roaming advertisement tvlv
122 */
123 enum batadv_tvlv_type {
124 BATADV_TVLV_GW = 0x01,
125 BATADV_TVLV_DAT = 0x02,
126 BATADV_TVLV_NC = 0x03,
127 BATADV_TVLV_TT = 0x04,
128 BATADV_TVLV_ROAM = 0x05,
129 };
130
131 /* the destination hardware field in the ARP frame is used to
132 * transport the claim type and the group id
133 */
134 struct batadv_bla_claim_dst {
135 uint8_t magic[3]; /* FF:43:05 */
136 uint8_t type; /* bla_claimframe */
137 __be16 group; /* group id */
138 };
139
140 struct batadv_header {
141 uint8_t packet_type;
142 uint8_t version; /* batman version field */
143 uint8_t ttl;
144 /* the parent struct has to add a byte after the header to make
145 * everything 4 bytes aligned again
146 */
147 };
148
149 /**
150 * struct batadv_ogm_packet - ogm (routing protocol) packet
151 * @header: common batman packet header
152 * @tvlv_len: length of tvlv data following the ogm header
153 */
154 struct batadv_ogm_packet {
155 struct batadv_header header;
156 uint8_t flags; /* 0x40: DIRECTLINK flag ... */
157 __be32 seqno;
158 uint8_t orig[ETH_ALEN];
159 uint8_t prev_sender[ETH_ALEN];
160 uint8_t reserved;
161 uint8_t tq;
162 __be16 tvlv_len;
163 } __packed;
164
165 #define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
166
167 struct batadv_icmp_packet {
168 struct batadv_header header;
169 uint8_t msg_type; /* see ICMP message types above */
170 uint8_t dst[ETH_ALEN];
171 uint8_t orig[ETH_ALEN];
172 __be16 seqno;
173 uint8_t uid;
174 uint8_t reserved;
175 };
176
177 #define BATADV_RR_LEN 16
178
179 /* icmp_packet_rr must start with all fields from imcp_packet
180 * as this is assumed by code that handles ICMP packets
181 */
182 struct batadv_icmp_packet_rr {
183 struct batadv_header header;
184 uint8_t msg_type; /* see ICMP message types above */
185 uint8_t dst[ETH_ALEN];
186 uint8_t orig[ETH_ALEN];
187 __be16 seqno;
188 uint8_t uid;
189 uint8_t rr_cur;
190 uint8_t rr[BATADV_RR_LEN][ETH_ALEN];
191 };
192
193 /* All packet headers in front of an ethernet header have to be completely
194 * divisible by 2 but not by 4 to make the payload after the ethernet
195 * header again 4 bytes boundary aligned.
196 *
197 * A packing of 2 is necessary to avoid extra padding at the end of the struct
198 * caused by a structure member which is larger than two bytes. Otherwise
199 * the structure would not fulfill the previously mentioned rule to avoid the
200 * misalignment of the payload after the ethernet header. It may also lead to
201 * leakage of information when the padding it not initialized before sending.
202 */
203 #pragma pack(2)
204
205 struct batadv_unicast_packet {
206 struct batadv_header header;
207 uint8_t ttvn; /* destination translation table version number */
208 uint8_t dest[ETH_ALEN];
209 /* "4 bytes boundary + 2 bytes" long to make the payload after the
210 * following ethernet header again 4 bytes boundary aligned
211 */
212 };
213
214 /**
215 * struct batadv_unicast_4addr_packet - extended unicast packet
216 * @u: common unicast packet header
217 * @src: address of the source
218 * @subtype: packet subtype
219 */
220 struct batadv_unicast_4addr_packet {
221 struct batadv_unicast_packet u;
222 uint8_t src[ETH_ALEN];
223 uint8_t subtype;
224 uint8_t reserved;
225 /* "4 bytes boundary + 2 bytes" long to make the payload after the
226 * following ethernet header again 4 bytes boundary aligned
227 */
228 };
229
230 struct batadv_unicast_frag_packet {
231 struct batadv_header header;
232 uint8_t ttvn; /* destination translation table version number */
233 uint8_t dest[ETH_ALEN];
234 uint8_t flags;
235 uint8_t align;
236 uint8_t orig[ETH_ALEN];
237 __be16 seqno;
238 } __packed;
239
240 struct batadv_bcast_packet {
241 struct batadv_header header;
242 uint8_t reserved;
243 __be32 seqno;
244 uint8_t orig[ETH_ALEN];
245 /* "4 bytes boundary + 2 bytes" long to make the payload after the
246 * following ethernet header again 4 bytes boundary aligned
247 */
248 };
249
250 #pragma pack()
251
252 /**
253 * struct batadv_coded_packet - network coded packet
254 * @header: common batman packet header and ttl of first included packet
255 * @reserved: Align following fields to 2-byte boundaries
256 * @first_source: original source of first included packet
257 * @first_orig_dest: original destinal of first included packet
258 * @first_crc: checksum of first included packet
259 * @first_ttvn: tt-version number of first included packet
260 * @second_ttl: ttl of second packet
261 * @second_dest: second receiver of this coded packet
262 * @second_source: original source of second included packet
263 * @second_orig_dest: original destination of second included packet
264 * @second_crc: checksum of second included packet
265 * @second_ttvn: tt version number of second included packet
266 * @coded_len: length of network coded part of the payload
267 */
268 struct batadv_coded_packet {
269 struct batadv_header header;
270 uint8_t first_ttvn;
271 /* uint8_t first_dest[ETH_ALEN]; - saved in mac header destination */
272 uint8_t first_source[ETH_ALEN];
273 uint8_t first_orig_dest[ETH_ALEN];
274 __be32 first_crc;
275 uint8_t second_ttl;
276 uint8_t second_ttvn;
277 uint8_t second_dest[ETH_ALEN];
278 uint8_t second_source[ETH_ALEN];
279 uint8_t second_orig_dest[ETH_ALEN];
280 __be32 second_crc;
281 __be16 coded_len;
282 };
283
284 /**
285 * struct batadv_unicast_tvlv - generic unicast packet with tvlv payload
286 * @header: common batman packet header
287 * @reserved: reserved field (for packet alignment)
288 * @src: address of the source
289 * @dst: address of the destination
290 * @tvlv_len: length of tvlv data following the unicast tvlv header
291 * @align: 2 bytes to align the header to a 4 byte boundry
292 */
293 struct batadv_unicast_tvlv_packet {
294 struct batadv_header header;
295 uint8_t reserved;
296 uint8_t dst[ETH_ALEN];
297 uint8_t src[ETH_ALEN];
298 __be16 tvlv_len;
299 uint16_t align;
300 };
301
302 /**
303 * struct batadv_tvlv_hdr - base tvlv header struct
304 * @type: tvlv container type (see batadv_tvlv_type)
305 * @version: tvlv container version
306 * @len: tvlv container length
307 */
308 struct batadv_tvlv_hdr {
309 uint8_t type;
310 uint8_t version;
311 __be16 len;
312 };
313
314 /**
315 * struct batadv_tvlv_gateway_data - gateway data propagated through gw tvlv
316 * container
317 * @bandwidth_down: advertised uplink download bandwidth
318 * @bandwidth_up: advertised uplink upload bandwidth
319 */
320 struct batadv_tvlv_gateway_data {
321 __be32 bandwidth_down;
322 __be32 bandwidth_up;
323 };
324
325 /**
326 * struct batadv_tvlv_tt_data - tt data propagated through the tt tvlv container
327 * @flags: translation table flags (see batadv_tt_data_flags)
328 * @ttvn: translation table version number
329 * @reserved: field reserved for future use
330 * @crc: crc32 checksum of the local translation table
331 */
332 struct batadv_tvlv_tt_data {
333 uint8_t flags;
334 uint8_t ttvn;
335 uint16_t reserved;
336 __be32 crc;
337 };
338
339 /**
340 * struct batadv_tvlv_tt_change - translation table diff data
341 * @flags: status indicators concerning the non-mesh client (see
342 * batadv_tt_client_flags)
343 * @reserved: reserved field
344 * @addr: mac address of non-mesh client that triggered this tt change
345 */
346 struct batadv_tvlv_tt_change {
347 uint8_t flags;
348 uint8_t reserved;
349 uint8_t addr[ETH_ALEN];
350 };
351
352 /**
353 * struct batadv_tvlv_roam_adv - roaming advertisement
354 * @client: mac address of roaming client
355 * @reserved: field reserved for future use
356 */
357 struct batadv_tvlv_roam_adv {
358 uint8_t client[ETH_ALEN];
359 uint16_t reserved;
360 };
361
362 #endif /* _NET_BATMAN_ADV_PACKET_H_ */