1121934Sharti/*
2121934Sharti * Copyright (c) 2001-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/priv.h,v 1.4 2003/10/10 14:50:05 hbb Exp $
30121934Sharti *
31121934Sharti * Private definitions for the IE code file.
32121934Sharti */
33121934Sharti#ifndef unimsg_priv_h
34121934Sharti#define unimsg_priv_h
35121934Sharti
36121934Sharti#ifdef _KERNEL
37121934Sharti#include <sys/systm.h>
38121934Sharti#include <machine/stdarg.h>
39121934Sharti#define PANIC(X) panic X
40121934Sharti#else
41121934Sharti#include <stdio.h>
42121934Sharti#include <stdarg.h>
43121934Sharti#include <stdlib.h>
44121934Sharti#define PANIC(X) abort()
45121934Sharti#endif
46121934Sharti
47121934Sharti/*
48121934Sharti * Define a structure for the declaration of information elements.
49121934Sharti * For each coding scheme a quadrupel of check, print, encode and
50121934Sharti * decode functions must be defined. A structure of the same format
51121934Sharti * is used for messages.
52121934Sharti */
53121934Shartitypedef void (*uni_print_f)(const union uni_ieall *, struct unicx *);
54121934Shartitypedef int (*uni_check_f)(union uni_ieall *, struct unicx *);
55121934Shartitypedef int (*uni_encode_f)(struct uni_msg *, union uni_ieall *,
56121934Sharti    struct unicx *);
57121934Shartitypedef int (*uni_decode_f)(union uni_ieall *, struct uni_msg *, u_int,
58121934Sharti    struct unicx *);
59121934Sharti
60121934Shartitypedef void (*uni_msg_print_f)(const union uni_msgall *, struct unicx *);
61121934Shartitypedef int (*uni_msg_check_f)(struct uni_all *, struct unicx *);
62121934Shartitypedef int (*uni_msg_encode_f)(struct uni_msg *, union uni_msgall *,
63121934Sharti    struct unicx *);
64121934Shartitypedef int (*uni_msg_decode_f)(union uni_msgall *, struct uni_msg *,
65121934Sharti    enum uni_ietype, struct uni_iehdr *, u_int, struct unicx *);
66121934Sharti
67121934Shartistruct iedecl {
68121934Sharti	u_int		flags;		/* information element flags */
69121934Sharti	u_int		maxlen;		/* maximum size */
70121934Sharti	uni_print_f	print;
71121934Sharti	uni_check_f	check;
72121934Sharti	uni_encode_f	encode;
73121934Sharti	uni_decode_f	decode;
74121934Sharti};
75121934Sharti
76121934Shartistruct msgdecl {
77121934Sharti	u_int		flags;
78121934Sharti	const char	*name;
79121934Sharti	uni_msg_print_f	print;
80121934Sharti	uni_msg_check_f	check;
81121934Sharti	uni_msg_encode_f encode;
82121934Sharti	uni_msg_decode_f decode;
83121934Sharti};
84121934Sharti
85121934Shartienum {
86121934Sharti	UNIFL_DEFAULT	= 0x0001,
87121934Sharti	UNIFL_ACCESS	= 0x0002,
88121934Sharti};
89121934Sharti
90121934Shartiextern const struct iedecl *uni_ietable[256][4];
91121934Shartiextern const struct msgdecl *uni_msgtable[256];
92121934Sharti
93121934Sharti/*
94121934Sharti * Need to check range here because declaring a variable as a enum does not
95121934Sharti * guarantee that the values will be legal.
96121934Sharti */
97121934Sharti#define GET_IEDECL(IE, CODING) 						\
98121934Sharti({									\
99121934Sharti	const struct iedecl *_decl = NULL;				\
100121934Sharti									\
101121934Sharti	if((CODING) <= 3 && (IE) <= 255)				\
102121934Sharti	    if((_decl = uni_ietable[IE][CODING]) != NULL)		\
103121934Sharti		if((_decl->flags & UNIFL_DEFAULT) != 0)			\
104121934Sharti		    if((_decl = uni_ietable[IE][0]) == NULL)		\
105121934Sharti			PANIC(("IE %02x,%02x -- no default", CODING,IE));\
106121934Sharti	_decl;								\
107121934Sharti})
108121934Sharti
109121934Sharti
110121934Shartienum {
111121934Sharti	DEC_OK,
112121934Sharti	DEC_ILL,
113121934Sharti	DEC_ERR,
114121934Sharti};
115121934Sharti
116121934Shartivoid uni_print_ie_internal(enum uni_ietype, const union uni_ieall *,
117121934Sharti    struct unicx *);
118121934Sharti
119121934Sharti#endif
120