]> The Tcpdump Group git mirrors - tcpdump/blob - forces.h
Add support for getting table ranges Fixup get by key formatting while at it
[tcpdump] / forces.h
1 /*
2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * Copyright (c) 2009 Mojatatu Networks, Inc
34 *
35 */
36
37 /*
38 * Per draft-ietf-forces-protocol-22
39 */
40 #define ForCES_VERS 1
41 #define ForCES_HDRL 24
42 #define ForCES_ALNL 4U
43 #define TLV_HDRL 4
44 #define ILV_HDRL 8
45
46 #define TOM_RSVD 0x0
47 #define TOM_ASSNSETUP 0x1
48 #define TOM_ASSNTEARD 0x2
49 #define TOM_CONFIG 0x3
50 #define TOM_QUERY 0x4
51 #define TOM_EVENTNOT 0x5
52 #define TOM_PKTREDIR 0x6
53 #define TOM_HEARTBT 0x0F
54 #define TOM_ASSNSETREP 0x11
55 #define TOM_CONFIGREP 0x13
56 #define TOM_QUERYREP 0x14
57
58 /*
59 * tom_h Flags: resv1(8b):maxtlvs(4b):resv2(2b):mintlv(2b)
60 */
61 #define ZERO_TTLV 0x01
62 #define ZERO_MORE_TTLV 0x02
63 #define ONE_MORE_TTLV 0x04
64 #define ZERO_TLV 0x00
65 #define ONE_TLV 0x10
66 #define TWO_TLV 0x20
67 #define MAX_TLV 0xF0
68
69 #define TTLV_T1 (ONE_MORE_TTLV|ONE_TLV)
70 #define TTLV_T2 (ONE_MORE_TTLV|MAX_TLV)
71
72 struct tom_h {
73 u_int32_t v;
74 u_int16_t flags;
75 u_int16_t op_msk;
76 const char *s;
77 int (*print) (register const u_char * pptr, register u_int len,
78 u_int16_t op_msk, int indent);
79 };
80
81 enum {
82 TOM_RSV_I,
83 TOM_ASS_I,
84 TOM_AST_I,
85 TOM_CFG_I,
86 TOM_QRY_I,
87 TOM_EVN_I,
88 TOM_RED_I,
89 TOM_HBT_I,
90 TOM_ASR_I,
91 TOM_CNR_I,
92 TOM_QRR_I,
93 _TOM_RSV_MAX
94 };
95 #define TOM_MAX_IND (_TOM_RSV_MAX - 1)
96
97 int lfbselect_print(register const u_char * pptr, register u_int len,
98 u_int16_t op_msk, int indent);
99 int redirect_print(register const u_char * pptr, register u_int len,
100 u_int16_t op_msk, int indent);
101 int asrtlv_print(register const u_char * pptr, register u_int len,
102 u_int16_t op_msk, int indent);
103 int asttlv_print(register const u_char * pptr, register u_int len,
104 u_int16_t op_msk, int indent);
105 int gentltlv_print(register const u_char * pptr, register u_int len,
106 u_int16_t op_msk, int indent);
107 int print_metailv(register const u_char * pptr, register u_int len,
108 u_int16_t op_msk, int indent);
109 int print_metatlv(register const u_char * pptr, register u_int len,
110 u_int16_t op_msk, int indent);
111 int print_reddata(register const u_char * pptr, register u_int len,
112 u_int16_t op_msk, int indent);
113
114 static inline int tom_valid(u_int8_t tom)
115 {
116 if (tom > 0) {
117 if (tom >= 0x7 && tom <= 0xe)
118 return 0;
119 if (tom == 0x10)
120 return 0;
121 if (tom > 0x14)
122 return 0;
123 return 1;
124 } else
125 return 0;
126 }
127
128 static inline const char *ForCES_node(u_int32_t node)
129 {
130 if (node <= 0x3FFFFFFF)
131 return "FE";
132 if (node >= 0x40000000 && node <= 0x7FFFFFFF)
133 return "CE";
134 if (node >= 0xC0000000 && node <= 0xFFFFFFEF)
135 return "AllMulticast";
136 if (node == 0xFFFFFFFD)
137 return "AllCEsBroadcast";
138 if (node == 0xFFFFFFFE)
139 return "AllFEsBroadcast";
140 if (node == 0xFFFFFFFF)
141 return "AllBroadcast";
142
143 return "ForCESreserved";
144
145 }
146
147 static inline const char *ForCES_ACKp(u_int32_t flg)
148 {
149 if (flg == 0x0)
150 return "NoACK";
151 if (flg == 0x1)
152 return "SuccessACK";
153 if (flg == 0x2)
154 return "FailureACK";
155 if (flg == 0x3)
156 return "AlwaysACK";
157 return "ACKUnknown";
158 }
159
160 static inline const char *ForCES_EMp(u_int32_t flg)
161 {
162 if (flg == 0x0)
163 return "EMReserved";
164 if (flg == 0x1)
165 return "execute-all-or-none";
166 if (flg == 0x2)
167 return "execute-until-failure";
168 if (flg == 0x3)
169 return "continue-execute-on-failure";
170 return "EMUnknown";
171 }
172
173 static inline const char *ForCES_ATp(u_int32_t flg)
174 {
175 if (flg == 0x0)
176 return "Standalone";
177 if (flg == 0x1)
178 return "2PCtransaction";
179 return "ATUnknown";
180 }
181
182 static inline const char *ForCES_TPp(u_int32_t flg)
183 {
184 if (flg == 0x0)
185 return "StartofTransaction";
186 if (flg == 0x1)
187 return "MiddleofTransaction";
188 if (flg == 0x2)
189 return "EndofTransaction";
190 if (flg == 0x3)
191 return "abort";
192 return "TPUnknown";
193 }
194
195 /*
196 * Structure of forces header, naked of TLVs.
197 */
198 struct forcesh {
199 u_int8_t fm_vrsvd; /* version and reserved */
200 #define ForCES_V(forcesh) ((forcesh)->fm_vrsvd >> 4)
201 u_int8_t fm_tom; /* type of message */
202 u_int16_t fm_len; /* total length * 4 bytes */
203 #define ForCES_BLN(forcesh) ((u_int32_t)(EXTRACT_16BITS(&(forcesh)->fm_len) << 2))
204 u_int32_t fm_sid; /* Source ID */
205 #define ForCES_SID(forcesh) EXTRACT_32BITS(&(forcesh)->fm_sid)
206 u_int32_t fm_did; /* Destination ID */
207 #define ForCES_DID(forcesh) EXTRACT_32BITS(&(forcesh)->fm_did)
208 u_int8_t fm_cor[8]; /* correlator */
209 u_int32_t fm_flags; /* flags */
210 #define ForCES_ACK(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0xC0000000) >> 30)
211 #define ForCES_PRI(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x38000000) >> 27)
212 #define ForCES_RS1(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x07000000) >> 24)
213 #define ForCES_EM(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x00C00000) >> 22)
214 #define ForCES_AT(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x00200000) >> 21)
215 #define ForCES_TP(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x00180000) >> 19)
216 #define ForCES_RS2(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x0007FFFF) >> 0)
217 };
218
219 #define ForCES_HLN_VALID(fhl,tlen) ((tlen) >= ForCES_HDRL && \
220 (fhl) >= ForCES_HDRL && \
221 (fhl) == (tlen))
222
223 #define F_LFB_RSVD 0x0
224 #define F_LFB_FEO 0x1
225 #define F_LFB_FEPO 0x2
226 const struct tok ForCES_LFBs[] = {
227 {F_LFB_RSVD, "Invalid TLV"},
228 {F_LFB_FEO, "FEObj LFB"},
229 {F_LFB_FEPO, "FEProtoObj LFB"},
230 {0, NULL}
231 };
232
233 int forces_type_print(register const u_char * pptr, const struct forcesh *fhdr,
234 register u_int mlen, const struct tom_h *tops);
235
236 enum {
237 F_OP_RSV,
238 F_OP_SET,
239 F_OP_SETPROP,
240 F_OP_SETRESP,
241 F_OP_SETPRESP,
242 F_OP_DEL,
243 F_OP_DELRESP,
244 F_OP_GET,
245 F_OP_GETPROP,
246 F_OP_GETRESP,
247 F_OP_GETPRESP,
248 F_OP_REPORT,
249 F_OP_COMMIT,
250 F_OP_RCOMMIT,
251 F_OP_RTRCOMP,
252 _F_OP_MAX
253 };
254
255 #define F_OP_MAX (_F_OP_MAX - 1)
256 enum {
257 B_OP_SET = 1 << (F_OP_SET - 1),
258 B_OP_SETPROP = 1 << (F_OP_SETPROP - 1),
259 B_OP_SETRESP = 1 << (F_OP_SETRESP - 1),
260 B_OP_SETPRESP = 1 << (F_OP_SETPRESP - 1),
261 B_OP_DEL = 1 << (F_OP_DEL - 1),
262 B_OP_DELRESP = 1 << (F_OP_DELRESP - 1),
263 B_OP_GET = 1 << (F_OP_GET - 1),
264 B_OP_GETPROP = 1 << (F_OP_GETPROP - 1),
265 B_OP_GETRESP = 1 << (F_OP_GETRESP - 1),
266 B_OP_GETPRESP = 1 << (F_OP_GETPRESP - 1),
267 B_OP_REPORT = 1 << (F_OP_REPORT - 1),
268 B_OP_COMMIT = 1 << (F_OP_COMMIT - 1),
269 B_OP_RCOMMIT = 1 << (F_OP_RCOMMIT - 1),
270 B_OP_RTRCOMP = 1 << (F_OP_RTRCOMP - 1),
271 };
272
273 struct optlv_h {
274 u_int16_t flags;
275 u_int16_t op_msk;
276 const char *s;
277 int (*print) (register const u_char * pptr, register u_int len,
278 u_int16_t op_msk, int indent);
279 };
280
281 int genoptlv_print(register const u_char * pptr, register u_int len,
282 u_int16_t op_msk, int indent);
283 int recpdoptlv_print(register const u_char * pptr, register u_int len,
284 u_int16_t op_msk, int indent);
285 int invoptlv_print(register const u_char * pptr, register u_int len,
286 u_int16_t op_msk, int indent);
287
288 #define OP_MIN_SIZ 8
289 struct pathdata_h {
290 u_int16_t pflags;
291 u_int16_t pIDcnt;
292 };
293
294 #define B_FULLD 0x1
295 #define B_SPARD 0x2
296 #define B_RESTV 0x4
297 #define B_KEYIN 0x8
298 #define B_TRNG 0x20
299
300 static const struct optlv_h OPTLV_msg[F_OP_MAX + 1] = {
301 /* F_OP_RSV */ {ZERO_TTLV, 0, "Invalid OPTLV", invoptlv_print},
302 /* F_OP_SET */ {TTLV_T2, B_FULLD | B_SPARD, " Set", recpdoptlv_print},
303 /* F_OP_SETPROP */
304 {TTLV_T2, B_FULLD | B_SPARD, " SetProp", recpdoptlv_print},
305 /* F_OP_SETRESP */ {TTLV_T2, B_RESTV, " SetResp", recpdoptlv_print},
306 /* F_OP_SETPRESP */ {TTLV_T2, B_RESTV, " SetPropResp", recpdoptlv_print},
307 /* F_OP_DEL */ {ZERO_TTLV, 0, " Del", recpdoptlv_print},
308 /* F_OP_DELRESP */ {TTLV_T2, B_RESTV, " DelResp", recpdoptlv_print},
309 /* F_OP_GET */ {ZERO_TTLV, 0, " Get", recpdoptlv_print},
310 /* F_OP_GETPROP */ {ZERO_TTLV, 0, " GetProp", recpdoptlv_print},
311 /* F_OP_GETRESP */
312 {TTLV_T2, B_FULLD | B_SPARD | B_RESTV, " GetResp", recpdoptlv_print},
313 /* F_OP_GETPRESP */
314 {TTLV_T2, B_FULLD | B_RESTV, " GetPropResp", recpdoptlv_print},
315 /* F_OP_REPORT */
316 {TTLV_T2, B_FULLD | B_SPARD, " Report", recpdoptlv_print},
317 /* F_OP_COMMIT */ {ZERO_TTLV, 0, " Commit", NULL},
318 /* F_OP_RCOMMIT */ {TTLV_T1, B_RESTV, " RCommit", genoptlv_print},
319 /* F_OP_RTRCOMP */ {ZERO_TTLV, 0, " RTRCOMP", NULL},
320 };
321
322 static inline const struct optlv_h *get_forces_optlv_h(u_int16_t opt)
323 {
324 if (opt > F_OP_MAX || opt <= F_OP_RSV)
325 return &OPTLV_msg[F_OP_RSV];
326
327 return &OPTLV_msg[opt];
328 }
329
330 #define IND_SIZE 256
331 #define IND_CHR ' '
332 #define IND_PREF '\n'
333 #define IND_SUF 0x0
334 char ind_buf[IND_SIZE];
335
336 static inline char *indent_pr(int indent, int nlpref)
337 {
338 int i = 0;
339 char *r = ind_buf;
340
341 if (indent > (IND_SIZE - 1))
342 indent = IND_SIZE - 1;
343
344 if (nlpref) {
345 r[i] = IND_PREF;
346 i++;
347 indent--;
348 }
349
350 while (--indent >= 0)
351 r[i++] = IND_CHR;
352
353 r[i] = IND_SUF;
354 return r;
355 }
356
357 static inline int op_valid(u_int16_t op, u_int16_t mask)
358 {
359 int opb = 1 << (op - 1);
360
361 if (op == 0)
362 return 0;
363 if (opb & mask)
364 return 1;
365 /* I guess we should allow vendor operations? */
366 if (op >= 0x8000)
367 return 1;
368 return 0;
369 }
370
371 #define F_TLV_RSVD 0x0000
372 #define F_TLV_REDR 0x0001
373 #define F_TLV_ASRS 0x0010
374 #define F_TLV_ASRT 0x0011
375 #define F_TLV_LFBS 0x1000
376 #define F_TLV_PDAT 0x0110
377 #define F_TLV_KEYI 0x0111
378 #define F_TLV_FULD 0x0112
379 #define F_TLV_SPAD 0x0113
380 #define F_TLV_REST 0x0114
381 #define F_TLV_METD 0x0115
382 #define F_TLV_REDD 0x0116
383 #define F_TLV_TRNG 0x0117
384
385
386 #define F_TLV_VNST 0x8000
387
388 static const struct tok ForCES_TLV[] = {
389 {F_TLV_RSVD, "Invalid TLV"},
390 {F_TLV_REDR, "REDIRECT TLV"},
391 {F_TLV_ASRS, "ASResult TLV"},
392 {F_TLV_ASRT, "ASTreason TLV"},
393 {F_TLV_LFBS, "LFBselect TLV"},
394 {F_TLV_PDAT, "PATH-DATA TLV"},
395 {F_TLV_KEYI, "KEYINFO TLV"},
396 {F_TLV_FULD, "FULLDATA TLV"},
397 {F_TLV_SPAD, "SPARSEDATA TLV"},
398 {F_TLV_REST, "RESULT TLV"},
399 {F_TLV_METD, "METADATA TLV"},
400 {F_TLV_REDD, "REDIRECTDATA TLV"},
401 {0, NULL}
402 };
403
404 #define TLV_HLN 4
405 static inline int ttlv_valid(u_int16_t ttlv)
406 {
407 if (ttlv > 0) {
408 if (ttlv == 1 || ttlv == 0x1000)
409 return 1;
410 if (ttlv >= 0x10 && ttlv <= 0x11)
411 return 1;
412 if (ttlv >= 0x110 && ttlv <= 0x116)
413 return 1;
414 if (ttlv >= 0x8000)
415 return 0; /* XXX: */
416 }
417
418 return 0;
419 }
420
421 struct forces_ilv {
422 u_int32_t type;
423 u_int32_t length;
424 };
425
426 struct forces_tlv {
427 u_int16_t type;
428 u_int16_t length;
429 };
430
431 int otlv_print(const struct forces_tlv *otlv, u_int16_t op_msk, int indent);
432
433 #define F_ALN_LEN(len) ( ((len)+ForCES_ALNL-1) & ~(ForCES_ALNL-1) )
434 #define GET_TOP_TLV(fhdr) ((struct forces_tlv *)((fhdr) + sizeof (struct forcesh)))
435 #define TLV_SET_LEN(len) (F_ALN_LEN(TLV_HDRL) + (len))
436 #define TLV_ALN_LEN(len) F_ALN_LEN(TLV_SET_LEN(len))
437 #define TLV_RDAT_LEN(tlv) ((int)(EXTRACT_16BITS(&(tlv)->length) - TLV_SET_LEN(0))
438 #define TLV_DATA(tlvp) ((void*)(((char*)(tlvp)) + TLV_SET_LEN(0)))
439 #define GO_NXT_TLV(tlv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_16BITS(&(tlv)->length)), \
440 (struct forces_tlv*)(((char*)(tlv)) \
441 + F_ALN_LEN(EXTRACT_16BITS(&(tlv)->length))))
442 #define ILV_SET_LEN(len) (F_ALN_LEN(ILV_HDRL) + (len))
443 #define ILV_ALN_LEN(len) F_ALN_LEN(ILV_SET_LEN(len))
444 #define ILV_RDAT_LEN(ilv) ((int)(EXTRACT_32BITS(&(ilv)->length)) - ILV_SET_LEN(0))
445 #define ILV_DATA(ilvp) ((void*)(((char*)(ilvp)) + ILV_SET_LEN(0)))
446 #define GO_NXT_ILV(ilv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_32BITS(&(ilv)->length)), \
447 (struct forces_ilv *)(((char*)(ilv)) \
448 + F_ALN_LEN(EXTRACT_32BITS(&(ilv)->length))))
449 #define INVALID_RLEN -1
450 #define INVALID_STLN -2
451 #define INVALID_LTLN -3
452 #define INVALID_ALEN -4
453
454 static const struct tok ForCES_TLV_err[] = {
455 {INVALID_RLEN, "Invalid total length"},
456 {INVALID_STLN, "xLV too short"},
457 {INVALID_LTLN, "xLV too long"},
458 {INVALID_ALEN, "data padding missing"},
459 {0, NULL}
460 };
461
462 static inline int tlv_valid(const struct forces_tlv *tlv, u_int rlen)
463 {
464 if (rlen < TLV_HDRL)
465 return INVALID_RLEN;
466 if (EXTRACT_16BITS(&tlv->length) < TLV_HDRL)
467 return INVALID_STLN;
468 if (EXTRACT_16BITS(&tlv->length) > rlen)
469 return INVALID_LTLN;
470 if (rlen < F_ALN_LEN(EXTRACT_16BITS(&tlv->length)))
471 return INVALID_ALEN;
472
473 return 0;
474 }
475
476 static inline int ilv_valid(const struct forces_ilv *ilv, u_int rlen)
477 {
478 if (rlen < ILV_HDRL)
479 return INVALID_RLEN;
480 if (EXTRACT_32BITS(&ilv->length) < ILV_HDRL)
481 return INVALID_STLN;
482 if (EXTRACT_32BITS(&ilv->length) > rlen)
483 return INVALID_LTLN;
484 if (rlen < F_ALN_LEN(EXTRACT_32BITS(&ilv->length)))
485 return INVALID_ALEN;
486
487 return 0;
488 }
489
490 struct forces_lfbsh {
491 u_int32_t class;
492 u_int32_t instance;
493 };
494
495 #define ASSNS_OPS (B_OP_REPORT)
496 #define CFG_OPS (B_OP_SET|B_OP_SETPROP|B_OP_DEL|B_OP_COMMIT|B_OP_RTRCOMP)
497 #define CFG_ROPS (B_OP_SETRESP|B_OP_SETPRESP|B_OP_DELRESP|B_OP_RCOMMIT)
498 #define CFG_QY (B_OP_GET|B_OP_GETPROP)
499 #define CFG_QYR (B_OP_GETRESP|B_OP_GETPRESP)
500 #define CFG_EVN (B_OP_REPORT)
501
502 static const struct tom_h ForCES_msg[TOM_MAX_IND + 1] = {
503 /* TOM_RSV_I */ {TOM_RSVD, ZERO_TTLV, 0, "Invalid message", NULL},
504 /* TOM_ASS_I */ {TOM_ASSNSETUP, ZERO_MORE_TTLV | TWO_TLV, ASSNS_OPS,
505 "Association Setup", lfbselect_print},
506 /* TOM_AST_I */
507 {TOM_ASSNTEARD, TTLV_T1, 0, "Association TearDown", asttlv_print},
508 /* TOM_CFG_I */ {TOM_CONFIG, TTLV_T2, CFG_OPS, "Config", lfbselect_print},
509 /* TOM_QRY_I */ {TOM_QUERY, TTLV_T2, CFG_QY, "Query", lfbselect_print},
510 /* TOM_EVN_I */ {TOM_EVENTNOT, TTLV_T1, CFG_EVN, "Event Notification",
511 lfbselect_print},
512 /* TOM_RED_I */
513 {TOM_PKTREDIR, TTLV_T2, 0, "Packet Redirect", redirect_print},
514 /* TOM_HBT_I */ {TOM_HEARTBT, ZERO_TTLV, 0, "HeartBeat", NULL},
515 /* TOM_ASR_I */
516 {TOM_ASSNSETREP, TTLV_T1, 0, "Association Response", asrtlv_print},
517 /* TOM_CNR_I */ {TOM_CONFIGREP, TTLV_T2, CFG_ROPS, "Config Response",
518 lfbselect_print},
519 /* TOM_QRR_I */
520 {TOM_QUERYREP, TTLV_T2, CFG_QYR, "Query Response", lfbselect_print},
521 };
522
523 static inline const struct tom_h *get_forces_tom(u_int8_t tom)
524 {
525 int i;
526 for (i = TOM_RSV_I; i <= TOM_MAX_IND; i++) {
527 const struct tom_h *th = &ForCES_msg[i];
528 if (th->v == tom)
529 return th;
530 }
531 return &ForCES_msg[TOM_RSV_I];
532 }
533
534 struct pdata_ops {
535 u_int32_t v;
536 u_int16_t flags;
537 u_int16_t op_msk;
538 const char *s;
539 int (*print) (register const u_char * pptr, register u_int len,
540 u_int16_t op_msk, int indent);
541 };
542
543 enum {
544 PD_RSV_I,
545 PD_SEL_I,
546 PD_FDT_I,
547 PD_SDT_I,
548 PD_RES_I,
549 PD_PDT_I,
550 _PD_RSV_MAX
551 };
552 #define PD_MAX_IND (_TOM_RSV_MAX - 1)
553
554 static inline int pd_valid(u_int16_t pd)
555 {
556 if (pd >= F_TLV_PDAT && pd <= F_TLV_REST)
557 return 1;
558 return 0;
559 }
560
561 static inline void chk_op_type(u_int16_t type, u_int16_t msk, u_int16_t omsk)
562 {
563 if (type != F_TLV_PDAT) {
564 if (msk & B_KEYIN) {
565 if (type != F_TLV_KEYI) {
566 printf
567 ("Based on flags expected KEYINFO TLV!\n");
568 }
569 } else {
570 if (!(msk & omsk)) {
571 printf
572 ("Illegal DATA encoding for type 0x%x programmed %x got %x \n",
573 type, omsk, msk);
574 }
575 }
576 }
577
578 }
579
580 int fdatatlv_print(register const u_char * pptr, register u_int len,
581 u_int16_t op_msk, int indent);
582 int sdatailv_print(register const u_char * pptr, register u_int len,
583 u_int16_t op_msk, int indent);
584 int sdatatlv_print(register const u_char * pptr, register u_int len,
585 u_int16_t op_msk, int indent);
586 int pdatatlv_print(register const u_char * pptr, register u_int len,
587 u_int16_t op_msk, int indent);
588 int pkeyitlv_print(register const u_char * pptr, register u_int len,
589 u_int16_t op_msk, int indent);
590
591 int pdatacnt_print(register const u_char * pptr, register u_int len,
592 u_int16_t IDcnt, u_int16_t op_msk, int indent);
593 int pdata_print(register const u_char * pptr, register u_int len,
594 u_int16_t op_msk, int indent);
595
596 int prestlv_print(register const u_char * pptr, register u_int len,
597 u_int16_t op_msk, int indent);
598 #define F_SELKEY 1
599 #define F_SELTABRANGE 2
600
601 struct res_val {
602 u_int8_t result;
603 u_int8_t resv1;
604 u_int16_t resv2;
605 };
606
607 static const struct pdata_ops ForCES_pdata[PD_MAX_IND + 1] = {
608 /* PD_RSV_I */ {0, 0, 0, "Invalid message", NULL},
609 /* PD_SEL_I */ {F_TLV_KEYI, 0, 0, "KEYINFO TLV", pkeyitlv_print},
610 /* PD_FDT_I */ {F_TLV_FULD, 0, B_FULLD, "FULLDATA TLV", fdatatlv_print},
611 /* PD_SDT_I */ {F_TLV_SPAD, 0, B_SPARD, "SPARSEDATA TLV", sdatatlv_print},
612 /* PD_RES_I */ {F_TLV_REST, 0, B_RESTV, "RESULT TLV", prestlv_print},
613 /* PD_PDT_I */
614 {F_TLV_PDAT, 0, 0, "Inner PATH-DATA TLV", recpdoptlv_print},
615 };
616
617 static inline const struct pdata_ops *get_forces_pd(u_int16_t pd)
618 {
619 int i;
620 for (i = PD_RSV_I + 1; i <= PD_MAX_IND; i++) {
621 const struct pdata_ops *pdo = &ForCES_pdata[i];
622 if (pdo->v == pd)
623 return pdo;
624 }
625 return &ForCES_pdata[TOM_RSV_I];
626 }
627
628 enum {
629 E_SUCCESS,
630 E_INVALID_HEADER,
631 E_LENGTH_MISMATCH,
632 E_VERSION_MISMATCH,
633 E_INVALID_DESTINATION_PID,
634 E_LFB_UNKNOWN,
635 E_LFB_NOT_FOUND,
636 E_LFB_INSTANCE_ID_NOT_FOUND,
637 E_INVALID_PATH,
638 E_COMPONENT_DOES_NOT_EXIST,
639 E_EXISTS,
640 E_NOT_FOUND,
641 E_READ_ONLY,
642 E_INVALID_ARRAY_CREATION,
643 E_VALUE_OUT_OF_RANGE,
644 E_CONTENTS_TOO_LONG,
645 E_INVALID_PARAMETERS,
646 E_INVALID_MESSAGE_TYPE,
647 E_INVALID_FLAGS,
648 E_INVALID_TLV,
649 E_EVENT_ERROR,
650 E_NOT_SUPPORTED,
651 E_MEMORY_ERROR,
652 E_INTERNAL_ERROR,
653 /* 0x18-0xFE are reserved .. */
654 E_UNSPECIFIED_ERROR = 0XFF
655 };
656
657 const struct tok ForCES_errs[] = {
658 {E_SUCCESS, "SUCCESS"},
659 {E_INVALID_HEADER, "INVALID HEADER"},
660 {E_LENGTH_MISMATCH, "LENGTH MISMATCH"},
661 {E_VERSION_MISMATCH, "VERSION MISMATCH"},
662 {E_INVALID_DESTINATION_PID, "INVALID DESTINATION PID"},
663 {E_LFB_UNKNOWN, "LFB UNKNOWN"},
664 {E_LFB_NOT_FOUND, "LFB NOT FOUND"},
665 {E_LFB_INSTANCE_ID_NOT_FOUND, "LFB INSTANCE ID NOT FOUND"},
666 {E_INVALID_PATH, "INVALID PATH"},
667 {E_COMPONENT_DOES_NOT_EXIST, "COMPONENT DOES NOT EXIST"},
668 {E_EXISTS, "EXISTS ALREADY"},
669 {E_NOT_FOUND, "NOT FOUND"},
670 {E_READ_ONLY, "READ ONLY"},
671 {E_INVALID_ARRAY_CREATION, "INVALID ARRAY CREATION"},
672 {E_VALUE_OUT_OF_RANGE, "VALUE OUT OF RANGE"},
673 {E_CONTENTS_TOO_LONG, "CONTENTS TOO LONG"},
674 {E_INVALID_PARAMETERS, "INVALID PARAMETERS"},
675 {E_INVALID_MESSAGE_TYPE, "INVALID MESSAGE TYPE"},
676 {E_INVALID_FLAGS, "INVALID FLAGS"},
677 {E_INVALID_TLV, "INVALID TLV"},
678 {E_EVENT_ERROR, "EVENT ERROR"},
679 {E_NOT_SUPPORTED, "NOT SUPPORTED"},
680 {E_MEMORY_ERROR, "MEMORY ERROR"},
681 {E_INTERNAL_ERROR, "INTERNAL ERROR"},
682 {E_UNSPECIFIED_ERROR, "UNSPECIFIED ERROR"},
683 {0, NULL}
684 };