1/*
2 * Copyright (c) 2001-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/priv.h,v 1.4 2003/10/10 14:50:05 hbb Exp $
30 *
31 * Private definitions for the IE code file.
32 */
33#ifndef unimsg_priv_h
34#define unimsg_priv_h
35
36#ifdef _KERNEL
37#include <sys/systm.h>
38#include <machine/stdarg.h>
39#define PANIC(X) panic X
40#else
41#include <stdio.h>
42#include <stdarg.h>
43#include <stdlib.h>
44#define PANIC(X) abort()
45#endif
46
47/*
48 * Define a structure for the declaration of information elements.
49 * For each coding scheme a quadrupel of check, print, encode and
50 * decode functions must be defined. A structure of the same format
51 * is used for messages.
52 */
53typedef void (*uni_print_f)(const union uni_ieall *, struct unicx *);
54typedef int (*uni_check_f)(union uni_ieall *, struct unicx *);
55typedef int (*uni_encode_f)(struct uni_msg *, union uni_ieall *,
56    struct unicx *);
57typedef int (*uni_decode_f)(union uni_ieall *, struct uni_msg *, u_int,
58    struct unicx *);
59
60typedef void (*uni_msg_print_f)(const union uni_msgall *, struct unicx *);
61typedef int (*uni_msg_check_f)(struct uni_all *, struct unicx *);
62typedef int (*uni_msg_encode_f)(struct uni_msg *, union uni_msgall *,
63    struct unicx *);
64typedef int (*uni_msg_decode_f)(union uni_msgall *, struct uni_msg *,
65    enum uni_ietype, struct uni_iehdr *, u_int, struct unicx *);
66
67struct iedecl {
68	u_int		flags;		/* information element flags */
69	u_int		maxlen;		/* maximum size */
70	uni_print_f	print;
71	uni_check_f	check;
72	uni_encode_f	encode;
73	uni_decode_f	decode;
74};
75
76struct msgdecl {
77	u_int		flags;
78	const char	*name;
79	uni_msg_print_f	print;
80	uni_msg_check_f	check;
81	uni_msg_encode_f encode;
82	uni_msg_decode_f decode;
83};
84
85enum {
86	UNIFL_DEFAULT	= 0x0001,
87	UNIFL_ACCESS	= 0x0002,
88};
89
90extern const struct iedecl *uni_ietable[256][4];
91extern const struct msgdecl *uni_msgtable[256];
92
93/*
94 * Need to check range here because declaring a variable as a enum does not
95 * guarantee that the values will be legal.
96 */
97#define GET_IEDECL(IE, CODING) 						\
98({									\
99	const struct iedecl *_decl = NULL;				\
100									\
101	if((CODING) <= 3 && (IE) <= 255)				\
102	    if((_decl = uni_ietable[IE][CODING]) != NULL)		\
103		if((_decl->flags & UNIFL_DEFAULT) != 0)			\
104		    if((_decl = uni_ietable[IE][0]) == NULL)		\
105			PANIC(("IE %02x,%02x -- no default", CODING,IE));\
106	_decl;								\
107})
108
109
110enum {
111	DEC_OK,
112	DEC_ILL,
113	DEC_ERR,
114};
115
116void uni_print_ie_internal(enum uni_ietype, const union uni_ieall *,
117    struct unicx *);
118
119#endif
120