1 /*
2 *
3 * Copyright (c) 2003 The Regents of the University of California. All
4 * rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * - Neither the name of the University nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 */
30
31 #include <timesync/sync_structs.h>
32
33 #ifndef __LINK_HEADERS_H__
34 #define __LINK_HEADERS_H__
35
36 /*
37 * Flooding Wire Protocol
38 */
39
40 typedef uint16_t flood_nonce_t;
41
42 typedef struct flood_pkt {
43 node_id_t original_src; /* who sent this packet originally */
44 node_id_t final_dst; /* where it's ultimately going to */
45 uint8_t hops_remaining; /* how many more hops it can be forwarded */
46 uint8_t inner_type; /* the type of the packet once flood header is stripped */
47 flood_nonce_t nonce; /* unique id to prevent floodd looping */
48 char data[0];
49 } __attribute__((packed)) flood_pkt_t;
50
51
52 /*
53 * RNP Routing Wire Protocol
54 */
55
56 typedef struct rnp_pkt {
57 node_id_t original_src; /* who sent this packet originally */
58 node_id_t final_dst; /* where it's ultimately going to */
59 uint8_t hops_remaining; /* how many more hops it can be
60 forwarded */
61 uint8_t inner_type; /* the type of the packet once flood
62 header is stripped */
63 conn_t arnp; /* acummulative rnp for this packet */
64 char data[0];
65 } __attribute__((packed)) rnp_pkt_t;
66
67
68
69 /*
70 * Neighbors Wire Protocol
71 *
72 * These are the over-the-air packet formats used by heartbeats. Each
73 * heartbeat packet contains a header (my ID, my sequence number)
74 * followed by several "HB Acks" that ack HBs we have seen from other
75 * nodes.
76 */
77
78 typedef struct heartbeat_ack_pkt {
79 uint16_t if_id; /* lower 16 bits of the interface id
80 to save space */
81 uint16_t last_seqno_heard; /* last seqno we heard from you */
82 uint16_t conn; /* conn value of neigh node_id */
83 } __attribute__((packed)) heartbeat_ack_pkt_t;
84
85 typedef struct heartbeat_pkt {
86 node_id_t src_id; /* my node ID */
87 uint16_t loc_x; /* my location, x, in cm */
88 uint16_t loc_y; /* my location, y, in cm */
89 uint16_t period; /* my period in msec */
90 uint16_t seqno; /* the none of this heartbeat */
91 heartbeat_ack_pkt_t hb_ack_list[0]; /* list of acks of other seqnos */
92 } __attribute__((packed)) heartbeat_pkt_t;
93
94
95 /*
96 * LinkStats Wire Protocol
97 *
98 * This is the over-the-air packet format used by linkstats. Each
99 * packet contains a header (my ID, my sequence number) followed by
100 * application data packet.
101 */
102
103 typedef struct linkstats_pkt {
104 node_id_t src_id; /* my node ID */
105 uint64_t seqno; /* the sequence number of this packet */
106 uint8_t inner_type; /* the type of the packet once linkstats
107 header is stripped */
108 uint8_t data[0]; /* pointer to the following data packet */
109 } __attribute__ ((packed)) linkstats_pkt_t;
110
111
112 /*
113 * Linkstats NG wire protocol
114 *
115 * Currently the default disables prev sends functionality (set to 0)
116 * if LS_MAX_PREV_SENDS is set to larger number, will report time since N
117 * last sends
118 */
119
120 #define LS_MAX_PREV_SENDS 0
121 #define LS_RADIX 5000
122 #define LS_BYTES_PER_RADIX 12
123
124 /* length assumed for unknown losses (in radices) */
125 #define LS_ASSUMED_PACKET_LENGTH (50 / LS_BYTES_PER_RADIX)
126
127 struct prev_send {
128 uint16_t timing:12;
129 uint16_t length:4;
130 } __attribute__ ((packed));
131
132 typedef struct linkstats2_pkt {
133 uint8_t seq;
134 uint8_t type;
135 struct prev_send prev_send[LS_MAX_PREV_SENDS];
136 char data[0];
137 } __attribute__ ((packed)) linkstats2_pkt_t;
138
139
140 /*
141 * LQE Wire Protocol
142 *
143 * This is the over-the-air packet format used by link quality
144 * estimator (lqe). Each packet contains a header (my ID, my
145 * sequence number, etc.) followed by an application data packet.
146 */
147
148 typedef struct lqe_pkt {
149 node_id_t src_id; /* my node ID */
150 uint64_t seqno; /* the sequence number of this packet */
151 node_id_t sender_id; /* the original sender ID */
152 uint8_t inner_type; /* the type of the packet once lqe header
153 is stripped */
154 uint8_t data[0]; /* pointer to the following data packet */
155 } __attribute__ ((packed)) lqe_pkt_t;
156
157
158 /*
159 * HBH Wire Protocol
160 *
161 * This is the over-the-air packet format used by hop-by-hop reliable
162 * scheme (hbh). Each packet contains a header (my ID, my
163 * sequence number, etc.) followed by an application data packet.
164 */
165
166 #define HBH_ACK 1
167 #define HBH_DATA 2
168
169 typedef struct hbh_pkt {
170 node_id_t src_id; /* my node ID */
171 uint8_t type; /* data or ack? */
172 uint64_t seqno; /* the sequence number of this packet */
173 uint8_t inner_type; /* the type of the packet once lqe header
174 is stripped */
175 uint8_t data[0]; /* pointer to the following data packet */
176 } __attribute__ ((packed)) hbh_pkt_t;
177
178
179
180 /*
181 * Fragmentation Wire Protocol
182 */
183
184 #define FRAG_INTRO 0
185 #define FRAG_DATA 1
186
187 /* header that RPC daemon sends before a fragment: the part common to
188 * both fragment intro and fragment data */
189 typedef struct {
190 u_int packet_type:1;
191 u_int frag_id:7;
192 u_int16_t byte_id;
193 } frag_common_header_t;
194
195 /* common header used for default fragmentation scheme (fragd) */
196 typedef struct {
197 u_int16_t packet_type:1;
198 u_int16_t byte_id:15;
199 char pkt_struct[0];
200 } __attribute__ ((packed)) frag_new_common_header_t;
201
202 /* header that RPC daemon sends before a fragment: for a "fragment
203 * info" type packet. */
204 typedef struct {
205 frag_common_header_t hdr;
206 u_int32_t checksum;
207 u_int8_t type;
208 } frag_intro_t;
209
210 /* intro header used for default fragmentation scheme (fragd) */
211 typedef struct {
212 u_int32_t checksum;
213 u_int8_t type;
214 char data[0];
215 } __attribute__ ((packed)) frag_new_intro_t;
216
217 /*
218 * StateSync protocols
219 */
220
221 typedef uint32_t ssync_seq_t;
222 typedef uint16_t log_seqno_t;
223 typedef uint64_t list_seqno_t;
224
225
226 typedef struct flow_id {
227 if_id_t src;
228 if_id_t dst;
229 uint8_t src_if;
230 uint8_t dst_if;
231 uint8_t max_hops;
232 uint8_t flow_index;
233 } __attribute__ ((packed)) flow_id_t;
234
235
236 typedef union {
237 uint8_t byte;
238 struct {
239 uint8_t index:7;
240 uint8_t head:1;
241 } __attribute__ ((packed)) ci;
242 } __attribute__ ((packed)) cl_index_t;
243
244
245 /* opcodes.. */
246 #define CP_OPCODE_DATA 0 /* data transmission */
247 #define CP_OPCODE_REFRESH 1 /* seqno refresh */
248 #define CP_OPCODE_REQ 2 /* request transmission */
249 #define CP_OPCODE_CINIT 3 /* request initial entry */
250
251 /* State Sync protocol subtypes */
252 #define SSYNC_FLOOD_V1 1
253 #define SSYNC_RETRANS_V2 4
254
255 /* log entry opcodes */
256 #define SSYNC_LOG_INIT 0 /* init entry (blank?) */
257 #define SSYNC_LOG_ADD 1 /* add in one chunk */
258 #define SSYNC_LOG_DEL 2 /* delete key */
259 #define SSYNC_LOG_FRAG 3 /* add, fragmented */
260 #define SSYNC_LOG_CONT 4 /* continued, fragmented */
261 #define SSYNC_LOG_LAST 5 /* last frag */
262 #define SSYNC_LOG_CHK 6 /* checksum */
263 #define SSYNC_LOG_TERM 7 /* term/compress/restart log */
264
265 #define SSYNC_TYPE_MAX 10
266 typedef struct ssync_type {
267 uint16_t fixed_len:10;
268 uint16_t key_len:6;
269 char type[SSYNC_TYPE_MAX];
270 } __attribute__ ((packed)) ssync_type_t;
271
272 /* generic header */
273
274 typedef struct ssync_hdr {
275 uint8_t version:4;
276 uint8_t opcode:3;
277 uint8_t unicast:1;
278 uint8_t data[0];
279 } __attribute__ ((packed)) ssync_hdr_t;
280
281
282 /* Multihop protocol version 1 */
283 typedef struct ssync_protocol {
284 ssync_hdr_t hdr;
285 uint8_t hops;
286 node_id_t source; /* or, we could just use pkt->src.id */
287 ssync_seq_t seqno;
288 ssync_type_t type;
289 uint8_t data[0];
290 } __attribute__ ((packed)) ssync_protocol_t;
291
292
293 /*
294 * retrans v2
295 */
296
297 /* retx command values (in addition to log commands) */
298 #define RETX2_CTRL_SEQNO 0x08
299 #define RETX2_CTRL_LIST 0x09
300 #define RETX2_CTRL_NACK 0x0A
301 #define RETX2_CTRL_ADDR 0x0B
302 #define RETX2_CTRL_FLOW 0x0C
303 #define RETX2_CTRL_NOP 0x0F
304
305 /* values for format parameter, when !code_book */
306 #define RETX2_FMT_SAME 0x00
307 #define RETX2_FMT_NEW_FID 0x01
308 #define RETX2_FMT_NEW_TARGET 0x02
309 #define RETX2_FMT_ESC 0x03
310
311 /* retrans2 control byte */
312 typedef struct ssync_retx2_ctrl {
313 uint8_t format:2; /* FID or codebook bits */
314 uint8_t length_set:1; /* length is set */
315 uint8_t code_book:1; /* code book mode */
316 uint8_t command:4; /* command nybble */
317 } __attribute__ ((packed)) ssync_retx2_ctrl_t;
318
319 /* nack init modes */
320 #define RETX2_NACK_NONE 0 /* normal nack */
321 #define RETX2_NACK_INIT_CHK 1 /* init "check" mode -- first entry only */
322 #define RETX2_NACK_INIT 2 /* init mode */
323 #define RETX2_NACK_LIST_SET 3 /* list index set */
324
325 /* retrans2 NACK control byte */
326 typedef struct ssync_retx2_nack_ctrl {
327 uint8_t last_nack:1; /* last nack in message */
328 uint8_t mode:2; /* init mode */
329 uint8_t seq_count:5; /* count of missing, or 0 if length set */
330 } __attribute__ ((packed)) ssync_retx2_nack_ctrl_t;
331
332 /* list + sequence number entry (type LIST) */
333 typedef struct ssync_seqno_entry {
334 uint8_t list_index;
335 log_seqno_t seqno;
336 } __attribute__ ((packed)) ssync_seqno_entry_t;
337
338 /* flow map entry */
339 typedef struct flow_entry {
340 flow_id_t id;
341 uint8_t hops;
342 } __attribute__ ((packed)) flow_entry_t;
343
344
345 /*
346 * Acoustic range notify and trigger packet headers
347 * (typically sent via flooding)
348 */
349
350 typedef struct range_notify_pkt {
351 remote_ts_t chirp_time;
352 remote_ts_t chirp_time_end;
353 int32_t seqno;
354 uint8_t modulation:4;
355 uint8_t skip_computation:1; /* for recording raw data.. skip actual computation */
356 uint8_t reserved:3;
357 uint32_t seed:24;
358 int32_t chirp_index;
359 char notation[20];
360 } __attribute__ ((packed)) range_notify_pkt_t;
361
362 #define RANGE_TRIGGER_MAX_NODES 20
363 typedef struct range_trigger_pkt {
364 remote_ts_t start_time;
365 uint32_t invalidate:1;
366 uint32_t reserved:31;
367 node_id_t sequence[RANGE_TRIGGER_MAX_NODES];
368 } __attribute__ ((packed)) range_trigger_pkt_t;
369
370
371 /*
372 * Acoustic recording triggering packet headers
373 * (typically sent via flooding)
374 */
375
376 typedef struct audio_trigger_pkt {
377 struct timeval global_start_time;
378 uint32_t run_length;
379 } __attribute__ ((packed)) audio_trigger_pkt_t;
380
381
382 /*
383 * Ping Wire Protocol
384 */
385
386 /* values for the 'cmd' field */
387 #define PING_REQUEST 1
388 #define PING_REPLY 2
389
390 /* NOTE: this sucks! *** FIX ME ***
391 * I put the ping wire protocol struct here so linkdump could decode
392 * it. I am trying to compile the entire repo, and there is a conflict
393 * with a ping_pkt_t define in tos-contrib... this is a naming issue.
394 * For now, I will just define it locally in ping and I will not commit
395 * the new linkdump (until we fix this).
396 */
397
398 #if 0
399 typedef struct ping_pkt {
400 unsigned int cmd:2; /* request or reply, 2 bits */
401 unsigned int random_id:14; /* random client ID, 14 bits */
402 uint16_t seqno; /* sequence number of the ping, 16 bits */
403 node_id_t node_id; /* node ID (it's not part of the link layer) */
404 } __attribute__ ((packed)) ping_pkt_t;
405 #endif
406
407 #endif
408
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.