priv.h revision 131826
1184902Srwatson/*
2184902Srwatson * Copyright (c) 2001-2003
3243750Srwatson *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4243750Srwatson * 	All rights reserved.
5243750Srwatson *
6243750Srwatson * Redistribution and use in source and binary forms, with or without
7243750Srwatson * modification, are permitted provided that the following conditions
8243750Srwatson * are met:
9243750Srwatson * 1. Redistributions of source code must retain the above copyright
10243750Srwatson *    notice, this list of conditions and the following disclaimer.
11243750Srwatson * 2. Redistributions in binary form must reproduce the above copyright
12243750Srwatson *    notice, this list of conditions and the following disclaimer in the
13243750Srwatson *    documentation and/or other materials provided with the distribution.
14243750Srwatson *
15243750Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16243750Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17243750Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18243750Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19243750Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20243750Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21243750Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22243750Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23243750Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24243750Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25243750Srwatson * SUCH DAMAGE.
26243750Srwatson *
27243750Srwatson * Author: Hartmut Brandt <harti@freebsd.org>
28196031Srwatson *
29196031Srwatson * $Begemot: libunimsg/netnatm/msg/priv.h,v 1.4 2003/10/10 14:50:05 hbb Exp $
30196031Srwatson *
31196031Srwatson * Private definitions for the IE code file.
32196031Srwatson */
33196031Srwatson#ifndef unimsg_priv_h
34195740Srwatson#define unimsg_priv_h
35195740Srwatson
36195740Srwatson#ifdef _KERNEL
37195740Srwatson#include <sys/systm.h>
38195740Srwatson#include <machine/stdarg.h>
39195740Srwatson#define PANIC(X) panic X
40195740Srwatson#else
41195740Srwatson#include <stdio.h>
42195740Srwatson#include <stdarg.h>
43191273Srwatson#include <stdlib.h>
44191273Srwatson#define PANIC(X) abort()
45191273Srwatson#endif
46191273Srwatson
47191273Srwatson/*
48191273Srwatson * Define a structure for the declaration of information elements.
49191273Srwatson * For each coding scheme a quadrupel of check, print, encode and
50191273Srwatson * decode functions must be defined. A structure of the same format
51191273Srwatson * is used for messages.
52191273Srwatson */
53191273Srwatsontypedef void (*uni_print_f)(const union uni_ieall *, struct unicx *);
54191273Srwatsontypedef int (*uni_check_f)(union uni_ieall *, struct unicx *);
55191273Srwatsontypedef int (*uni_encode_f)(struct uni_msg *, union uni_ieall *,
56191273Srwatson    struct unicx *);
57191273Srwatsontypedef int (*uni_decode_f)(union uni_ieall *, struct uni_msg *, u_int,
58191273Srwatson    struct unicx *);
59191273Srwatson
60191273Srwatsontypedef void (*uni_msg_print_f)(const union uni_msgall *, struct unicx *);
61189279Srwatsontypedef int (*uni_msg_check_f)(struct uni_all *, struct unicx *);
62189279Srwatsontypedef int (*uni_msg_encode_f)(struct uni_msg *, union uni_msgall *,
63189279Srwatson    struct unicx *);
64189279Srwatsontypedef int (*uni_msg_decode_f)(union uni_msgall *, struct uni_msg *,
65189279Srwatson    enum uni_ietype, struct uni_iehdr *, u_int, struct unicx *);
66189279Srwatson
67189279Srwatsonstruct iedecl {
68189279Srwatson	u_int		flags;		/* information element flags */
69189279Srwatson	u_int		maxlen;		/* maximum size */
70189279Srwatson	uni_print_f	print;
71189279Srwatson	uni_check_f	check;
72189279Srwatson	uni_encode_f	encode;
73189279Srwatson	uni_decode_f	decode;
74189279Srwatson};
75189279Srwatson
76189279Srwatsonstruct msgdecl {
77189279Srwatson	u_int		flags;
78189279Srwatson	const char	*name;
79189279Srwatson	uni_msg_print_f	print;
80187214Srwatson	uni_msg_check_f	check;
81187214Srwatson	uni_msg_encode_f encode;
82187214Srwatson	uni_msg_decode_f decode;
83187214Srwatson};
84187214Srwatson
85187214Srwatsonenum {
86187214Srwatson	UNIFL_DEFAULT	= 0x0001,
87187214Srwatson	UNIFL_ACCESS	= 0x0002,
88187214Srwatson};
89187214Srwatson
90187214Srwatsonextern const struct iedecl *uni_ietable[256][4];
91187214Srwatsonextern const struct msgdecl *uni_msgtable[256];
92187214Srwatson
93187214Srwatson/*
94187214Srwatson * Need to check range here because declaring a variable as a enum does not
95187214Srwatson * guarantee that the values will be legal.
96187214Srwatson */
97187214Srwatson#define GET_IEDECL(IE, CODING) 						\
98187214Srwatson({									\
99186647Srwatson	const struct iedecl *_decl = NULL;				\
100186647Srwatson									\
101186647Srwatson	if((CODING) <= 3 && (IE) <= 255)				\
102186647Srwatson	    if((_decl = uni_ietable[IE][CODING]) != NULL)		\
103186647Srwatson		if((_decl->flags & UNIFL_DEFAULT) != 0)			\
104186647Srwatson		    if((_decl = uni_ietable[IE][0]) == NULL)		\
105186647Srwatson			PANIC(("IE %02x,%02x -- no default", CODING,IE));\
106186647Srwatson	_decl;								\
107186647Srwatson})
108186647Srwatson
109186647Srwatson
110186647Srwatsonenum {
111186647Srwatson	DEC_OK,
112186647Srwatson	DEC_ILL,
113186647Srwatson	DEC_ERR,
114186647Srwatson};
115186647Srwatson
116186647Srwatsonvoid uni_print_ie_internal(enum uni_ietype, const union uni_ieall *,
117186647Srwatson    struct unicx *);
118186647Srwatson
119186647Srwatson#endif
120186647Srwatson