2 * Copyright (c) 1996-2003
3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
27 * Author: Hartmut Brandt <harti@freebsd.org>
29 * $Begemot: libunimsg/netnatm/msg/unimsglib.h,v 1.6 2004/07/08 08:22:07 brandt Exp $
31 #ifndef _NETNATM_MSG_UNIMSGLIB_H_
32 #define _NETNATM_MSG_UNIMSGLIB_H_
34 #include <netnatm/msg/uni_config.h>
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) */
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 */
55 * Context buffer. Needed to reduce number of arguments to routines.
59 * globals for error handling
61 u_int errcnt; /* number of bad IEs */
62 struct uni_ierr err[UNI_MAX_ERRIE]; /* the errors */
64 int q2932; /* Enable GFP */
65 int pnni; /* Enable PNNI */
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 */
71 int multiline; /* printing mode */
72 u_int tabsiz; /* tabulation size */
75 * Internal context of library -- don't touch
77 struct uni_ie_repeat repeat; /* repeat IE during decoding */
78 enum uni_ietype ielast; /* last IE seen for repeat handling */
80 const char *prefix[20];
85 u_int indent; /* indentation */
90 * Functions for all messages
92 void uni_print_cref(char *, size_t, const struct uni_cref *, struct unicx *);
93 void uni_print_msghdr(char *, size_t, const struct uni_msghdr *, struct unicx *);
94 void uni_print(char *, size_t, const struct uni_all *, struct unicx *);
95 void uni_print_msg(char *, size_t, u_int _mtype, const union uni_msgall *,
97 int uni_encode(struct uni_msg *, struct uni_all *, struct unicx *);
98 int uni_decode(struct uni_msg *, struct uni_all *, struct unicx *);
100 int uni_decode_head(struct uni_msg *, struct uni_all *, struct unicx *);
101 int uni_decode_body(struct uni_msg *, struct uni_all *, struct unicx *);
103 int uni_encode_msg_hdr(struct uni_msg *, struct uni_msghdr *, enum uni_msgtype,
104 struct unicx *, int *);
108 * Functions for all information elements
110 void uni_print_ie(char *, size_t, enum uni_ietype, const union uni_ieall *,
112 int uni_check_ie(enum uni_ietype, union uni_ieall *, struct unicx *);
113 int uni_encode_ie(enum uni_ietype, struct uni_msg *, union uni_ieall *,
115 int uni_decode_ie_hdr(enum uni_ietype *, struct uni_iehdr *, struct uni_msg *,
116 struct unicx *, u_int *);
117 int uni_encode_ie_hdr(struct uni_msg *, enum uni_ietype, struct uni_iehdr *,
118 u_int, struct unicx *);
119 int uni_decode_ie_body(enum uni_ietype, union uni_ieall *, struct uni_msg *,
120 u_int, struct unicx *);
126 void uni_initcx(struct unicx *);
127 void uni_print_cx(char *, size_t, struct unicx *);
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, \
139 * Traffic classification
141 enum uni_traffic_class {
162 /* classify traffic */
163 int uni_classify_traffic(const struct uni_ie_bearer *,
164 const struct uni_ie_traffic *,
165 enum uni_traffic_class *, enum uni_traffic_class *,