1/*
2 * Copyright (c) 1996-2003
3 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4 * 	All 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 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * Author: Hartmut Brandt <harti@freebsd.org>
28 *
29 * $Begemot: libunimsg/netnatm/msg/unimsglib.h,v 1.6 2004/07/08 08:22:07 brandt Exp $
30 */
31#ifndef _NETNATM_MSG_UNIMSGLIB_H_
32#define _NETNATM_MSG_UNIMSGLIB_H_
33
34#include <netnatm/msg/uni_config.h>
35
36struct uni_msg;
37
38enum uni_ierr_type {
39	UNI_IERR_UNK,	/* unknown IE */
40	UNI_IERR_LEN,	/* length error */
41	UNI_IERR_BAD,	/* content error */
42	UNI_IERR_ACC,	/* access element content error */
43	UNI_IERR_MIS,	/* mandatory IE missing (not used here) */
44};
45
46struct uni_ierr {
47	enum uni_ierr_type	err;	/* what error */
48	enum uni_ieact		act;	/* the action indicator */
49	u_int			ie:8;	/* the ie type */
50	u_int			man:1;	/* mandatory flag */
51	u_int			epref:1;/* Q.2971 9.5.3.2.1 low-pri epref */
52};
53
54/*
55 * Context buffer. Needed to reduce number of arguments to routines.
56 */
57struct unicx {
58	/*
59	 * globals for error handling
60	 */
61	u_int		errcnt;		/* number of bad IEs */
62	struct uni_ierr	err[UNI_MAX_ERRIE]; /* the errors */
63
64	int		q2932;		/* Enable GFP */
65	int		pnni;		/* Enable PNNI */
66
67	int		git_hard;	/* do hard check on GIT IE */
68	int		bearer_hard;	/* do hard check on BEARER IE */
69	int		cause_hard;	/* do hard check on cause */
70
71	int		multiline;	/* printing mode */
72	u_int		tabsiz;		/* tabulation size */
73
74	/*
75	 * Internal context of library -- don't touch
76	 */
77	struct uni_ie_repeat	repeat;	/* repeat IE during decoding */
78	enum uni_ietype		ielast;	/* last IE seen for repeat handling */
79
80	const char 		*prefix[20];
81	u_int			nprefix;
82	int			doindent;
83	char			*buf;
84	size_t			bufsiz;
85	u_int			indent;		/* indentation */
86	int			dont_init;
87};
88
89/*
90 * Functions for all messages
91 */
92void uni_print_cref(char *, size_t, const struct uni_cref *, struct unicx *);
93void uni_print_msghdr(char *, size_t, const struct uni_msghdr *, struct unicx *);
94void uni_print(char *, size_t, const struct uni_all *, struct unicx *);
95void uni_print_msg(char *, size_t, u_int _mtype, const union uni_msgall *,
96    struct unicx *);
97int uni_encode(struct uni_msg *, struct uni_all *, struct unicx *);
98int uni_decode(struct uni_msg *, struct uni_all *, struct unicx *);
99
100int uni_decode_head(struct uni_msg *, struct uni_all *, struct unicx *);
101int uni_decode_body(struct uni_msg *, struct uni_all *, struct unicx *);
102
103int uni_encode_msg_hdr(struct uni_msg *, struct uni_msghdr *, enum uni_msgtype,
104    struct unicx *, int *);
105
106
107/*
108 * Functions for all information elements
109 */
110void uni_print_ie(char *, size_t, enum uni_ietype, const union uni_ieall *,
111    struct unicx *);
112int uni_check_ie(enum uni_ietype, union uni_ieall *, struct unicx *);
113int uni_encode_ie(enum uni_ietype, struct uni_msg *, union uni_ieall *,
114    struct unicx *);
115int uni_decode_ie_hdr(enum uni_ietype *, struct uni_iehdr *, struct uni_msg *,
116    struct unicx *, u_int *);
117int uni_encode_ie_hdr(struct uni_msg *, enum uni_ietype, struct uni_iehdr *,
118    u_int, struct unicx *);
119int uni_decode_ie_body(enum uni_ietype, union uni_ieall *, struct uni_msg *,
120    u_int, struct unicx *);
121
122
123/*
124 * Context handling
125 */
126void uni_initcx(struct unicx *);
127void uni_print_cx(char *, size_t, struct unicx *);
128
129#define	UNI_SAVE_IERR(CX, IETYPE, ACT, ERRCODE)				\
130	(((CX)->errcnt < UNI_MAX_ERRIE) ?				\
131	 ((CX)->err[(CX)->errcnt].ie = (IETYPE),			\
132	  (CX)->err[(CX)->errcnt].act = (ACT),				\
133	  (CX)->err[(CX)->errcnt].err = (ERRCODE),			\
134	  (CX)->err[(CX)->errcnt].man = 0,				\
135	  (CX)->errcnt++,						\
136	  1) : 0)
137
138/*
139 * Traffic classification
140 */
141enum uni_traffic_class {
142	UNI_TRAFFIC_CBR1,
143	UNI_TRAFFIC_CBR2,
144	UNI_TRAFFIC_CBR3,
145	UNI_TRAFFIC_rtVBR1,
146	UNI_TRAFFIC_rtVBR2,
147	UNI_TRAFFIC_rtVBR3,
148	UNI_TRAFFIC_rtVBR4,
149	UNI_TRAFFIC_rtVBR5,
150	UNI_TRAFFIC_rtVBR6,
151	UNI_TRAFFIC_nrtVBR1,
152	UNI_TRAFFIC_nrtVBR2,
153	UNI_TRAFFIC_nrtVBR3,
154	UNI_TRAFFIC_nrtVBR4,
155	UNI_TRAFFIC_nrtVBR5,
156	UNI_TRAFFIC_nrtVBR6,
157	UNI_TRAFFIC_ABR,
158	UNI_TRAFFIC_UBR1,
159	UNI_TRAFFIC_UBR2,
160};
161
162/* classify traffic */
163int uni_classify_traffic(const struct uni_ie_bearer *,
164    const struct uni_ie_traffic *,
165    enum uni_traffic_class *, enum uni_traffic_class *,
166    char *, size_t);
167
168#endif
169