1121934Sharti/*
2121934Sharti * Copyright (c) 1996-2003
3121934Sharti *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4121934Sharti * 	All rights reserved.
5121934Sharti *
6121934Sharti * Redistribution and use in source and binary forms, with or without
7121934Sharti * modification, are permitted provided that the following conditions
8121934Sharti * are met:
9121934Sharti * 1. Redistributions of source code must retain the above copyright
10121934Sharti *    notice, this list of conditions and the following disclaimer.
11121934Sharti * 2. Redistributions in binary form must reproduce the above copyright
12121934Sharti *    notice, this list of conditions and the following disclaimer in the
13121934Sharti *    documentation and/or other materials provided with the distribution.
14121934Sharti *
15121934Sharti * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16121934Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17121934Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18121934Sharti * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19121934Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20121934Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21121934Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22121934Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23121934Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24121934Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25121934Sharti * SUCH DAMAGE.
26121934Sharti *
27121934Sharti * Author: Hartmut Brandt <harti@freebsd.org>
28121934Sharti *
29131826Sharti * $Begemot: libunimsg/netnatm/msg/unimsglib.h,v 1.6 2004/07/08 08:22:07 brandt Exp $
30121934Sharti */
31121934Sharti#ifndef _NETNATM_MSG_UNIMSGLIB_H_
32121934Sharti#define _NETNATM_MSG_UNIMSGLIB_H_
33121934Sharti
34121934Sharti#include <netnatm/msg/uni_config.h>
35121934Sharti
36121934Shartistruct uni_msg;
37121934Sharti
38121934Shartienum uni_ierr_type {
39121934Sharti	UNI_IERR_UNK,	/* unknown IE */
40121934Sharti	UNI_IERR_LEN,	/* length error */
41121934Sharti	UNI_IERR_BAD,	/* content error */
42121934Sharti	UNI_IERR_ACC,	/* access element content error */
43121934Sharti	UNI_IERR_MIS,	/* mandatory IE missing (not used here) */
44121934Sharti};
45121934Sharti
46121934Shartistruct uni_ierr {
47121934Sharti	enum uni_ierr_type	err;	/* what error */
48121934Sharti	enum uni_ieact		act;	/* the action indicator */
49121934Sharti	u_int			ie:8;	/* the ie type */
50121934Sharti	u_int			man:1;	/* mandatory flag */
51121934Sharti	u_int			epref:1;/* Q.2971 9.5.3.2.1 low-pri epref */
52121934Sharti};
53121934Sharti
54121934Sharti/*
55121934Sharti * Context buffer. Needed to reduce number of arguments to routines.
56121934Sharti */
57121934Shartistruct unicx {
58121934Sharti	/*
59121934Sharti	 * globals for error handling
60121934Sharti	 */
61121934Sharti	u_int		errcnt;		/* number of bad IEs */
62121934Sharti	struct uni_ierr	err[UNI_MAX_ERRIE]; /* the errors */
63121934Sharti
64121934Sharti	int		q2932;		/* Enable GFP */
65121934Sharti	int		pnni;		/* Enable PNNI */
66121934Sharti
67121934Sharti	int		git_hard;	/* do hard check on GIT IE */
68121934Sharti	int		bearer_hard;	/* do hard check on BEARER IE */
69121934Sharti	int		cause_hard;	/* do hard check on cause */
70121934Sharti
71121934Sharti	int		multiline;	/* printing mode */
72121934Sharti	u_int		tabsiz;		/* tabulation size */
73121934Sharti
74121934Sharti	/*
75121934Sharti	 * Internal context of library -- don't touch
76121934Sharti	 */
77121934Sharti	struct uni_ie_repeat	repeat;	/* repeat IE during decoding */
78121934Sharti	enum uni_ietype		ielast;	/* last IE seen for repeat handling */
79121934Sharti
80121934Sharti	const char 		*prefix[20];
81121934Sharti	u_int			nprefix;
82121934Sharti	int			doindent;
83121934Sharti	char			*buf;
84121934Sharti	size_t			bufsiz;
85121934Sharti	u_int			indent;		/* indentation */
86121934Sharti	int			dont_init;
87121934Sharti};
88121934Sharti
89121934Sharti/*
90121934Sharti * Functions for all messages
91121934Sharti */
92121934Shartivoid uni_print_cref(char *, size_t, const struct uni_cref *, struct unicx *);
93121934Shartivoid uni_print_msghdr(char *, size_t, const struct uni_msghdr *, struct unicx *);
94121934Shartivoid uni_print(char *, size_t, const struct uni_all *, struct unicx *);
95121934Shartivoid uni_print_msg(char *, size_t, u_int _mtype, const union uni_msgall *,
96121934Sharti    struct unicx *);
97121934Shartiint uni_encode(struct uni_msg *, struct uni_all *, struct unicx *);
98121934Shartiint uni_decode(struct uni_msg *, struct uni_all *, struct unicx *);
99121934Sharti
100121934Shartiint uni_decode_head(struct uni_msg *, struct uni_all *, struct unicx *);
101121934Shartiint uni_decode_body(struct uni_msg *, struct uni_all *, struct unicx *);
102121934Sharti
103121934Shartiint uni_encode_msg_hdr(struct uni_msg *, struct uni_msghdr *, enum uni_msgtype,
104121934Sharti    struct unicx *, int *);
105121934Sharti
106121934Sharti
107121934Sharti/*
108121934Sharti * Functions for all information elements
109121934Sharti */
110121934Shartivoid uni_print_ie(char *, size_t, enum uni_ietype, const union uni_ieall *,
111121934Sharti    struct unicx *);
112121934Shartiint uni_check_ie(enum uni_ietype, union uni_ieall *, struct unicx *);
113121934Shartiint uni_encode_ie(enum uni_ietype, struct uni_msg *, union uni_ieall *,
114121934Sharti    struct unicx *);
115121934Shartiint uni_decode_ie_hdr(enum uni_ietype *, struct uni_iehdr *, struct uni_msg *,
116121934Sharti    struct unicx *, u_int *);
117121934Shartiint uni_encode_ie_hdr(struct uni_msg *, enum uni_ietype, struct uni_iehdr *,
118121934Sharti    u_int, struct unicx *);
119121934Shartiint uni_decode_ie_body(enum uni_ietype, union uni_ieall *, struct uni_msg *,
120121934Sharti    u_int, struct unicx *);
121121934Sharti
122121934Sharti
123121934Sharti/*
124121934Sharti * Context handling
125121934Sharti */
126121934Shartivoid uni_initcx(struct unicx *);
127121934Shartivoid uni_print_cx(char *, size_t, struct unicx *);
128121934Sharti
129121934Sharti#define	UNI_SAVE_IERR(CX, IETYPE, ACT, ERRCODE)				\
130121934Sharti	(((CX)->errcnt < UNI_MAX_ERRIE) ?				\
131121934Sharti	 ((CX)->err[(CX)->errcnt].ie = (IETYPE),			\
132121934Sharti	  (CX)->err[(CX)->errcnt].act = (ACT),				\
133121934Sharti	  (CX)->err[(CX)->errcnt].err = (ERRCODE),			\
134121934Sharti	  (CX)->err[(CX)->errcnt].man = 0,				\
135121934Sharti	  (CX)->errcnt++,						\
136121934Sharti	  1) : 0)
137121934Sharti
138121934Sharti/*
139121934Sharti * Traffic classification
140121934Sharti */
141121934Shartienum uni_traffic_class {
142121934Sharti	UNI_TRAFFIC_CBR1,
143121934Sharti	UNI_TRAFFIC_CBR2,
144121934Sharti	UNI_TRAFFIC_CBR3,
145121934Sharti	UNI_TRAFFIC_rtVBR1,
146121934Sharti	UNI_TRAFFIC_rtVBR2,
147121934Sharti	UNI_TRAFFIC_rtVBR3,
148121934Sharti	UNI_TRAFFIC_rtVBR4,
149121934Sharti	UNI_TRAFFIC_rtVBR5,
150121934Sharti	UNI_TRAFFIC_rtVBR6,
151121934Sharti	UNI_TRAFFIC_nrtVBR1,
152121934Sharti	UNI_TRAFFIC_nrtVBR2,
153121934Sharti	UNI_TRAFFIC_nrtVBR3,
154121934Sharti	UNI_TRAFFIC_nrtVBR4,
155121934Sharti	UNI_TRAFFIC_nrtVBR5,
156121934Sharti	UNI_TRAFFIC_nrtVBR6,
157121934Sharti	UNI_TRAFFIC_ABR,
158121934Sharti	UNI_TRAFFIC_UBR1,
159121934Sharti	UNI_TRAFFIC_UBR2,
160121934Sharti};
161121934Sharti
162121934Sharti/* classify traffic */
163121934Shartiint uni_classify_traffic(const struct uni_ie_bearer *,
164121934Sharti    const struct uni_ie_traffic *,
165121934Sharti    enum uni_traffic_class *, enum uni_traffic_class *,
166121934Sharti    char *, size_t);
167121934Sharti
168121934Sharti#endif
169