1/* This file was created automatically
2 * Source file: $Begemot: libunimsg/atm/msg/msg.def,v 1.3 2003/09/19 11:58:15 hbb Exp $
3 * $FreeBSD: releng/10.2/sys/contrib/ngatm/netnatm/msg/uni_msg.c 121936 2003-11-03 09:11:53Z harti $
4 */
5
6#include <sys/types.h>
7#include <sys/param.h>
8
9#ifdef _KERNEL
10#include <sys/libkern.h>
11#else
12#include <string.h>
13#endif
14#include <netnatm/unimsg.h>
15#include <netnatm/msg/unistruct.h>
16#include <netnatm/msg/unimsglib.h>
17#include <netnatm/msg/priv.h>
18#include <netnatm/msg/privmsg.c>
19
20static void
21print_alerting(struct uni_alerting *msg, struct unicx *cx)
22{
23	u_int i;
24
25	if(msg->connid.h.present & UNI_IE_PRESENT)
26		uni_print_ie_internal(UNI_IE_CONNID, (union uni_ieall *)&msg->connid, cx);
27	if(msg->epref.h.present & UNI_IE_PRESENT)
28		uni_print_ie_internal(UNI_IE_EPREF, (union uni_ieall *)&msg->epref, cx);
29	if(msg->notify.h.present & UNI_IE_PRESENT)
30		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
31	for(i = 0; i < UNI_NUM_IE_GIT; i++)
32		if(msg->git[i].h.present & UNI_IE_PRESENT)
33			uni_print_ie_internal(UNI_IE_GIT, (union uni_ieall *)&msg->git[i], cx);
34	if(msg->uu.h.present & UNI_IE_PRESENT)
35		uni_print_ie_internal(UNI_IE_UU, (union uni_ieall *)&msg->uu, cx);
36	if(msg->report.h.present & UNI_IE_PRESENT)
37		uni_print_ie_internal(UNI_IE_REPORT, (union uni_ieall *)&msg->report, cx);
38	if(msg->unrec.h.present & UNI_IE_PRESENT)
39		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
40}
41
42static int
43check_alerting(struct uni_alerting *m, struct unicx *cx)
44{
45	int ret = 0;
46	u_int i;
47
48	if(!(!cx->pnni))
49		ret |= IE_ISPRESENT(m->connid);
50	else
51		ret |= uni_check_ie(UNI_IE_CONNID, (union uni_ieall *)&m->connid, cx);
52	ret |= uni_check_ie(UNI_IE_EPREF, (union uni_ieall *)&m->epref, cx);
53	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
54	for(i = 0; i < UNI_NUM_IE_GIT ; i++) {
55		ret |= uni_check_ie(UNI_IE_GIT, (union uni_ieall *)&m->git[i], cx);
56	}
57	if(!(!cx->pnni))
58		ret |= IE_ISPRESENT(m->uu);
59	else
60		ret |= uni_check_ie(UNI_IE_UU, (union uni_ieall *)&m->uu, cx);
61	if(!(!cx->pnni))
62		ret |= IE_ISPRESENT(m->report);
63	else
64		ret |= uni_check_ie(UNI_IE_REPORT, (union uni_ieall *)&m->report, cx);
65	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
66
67	return ret;
68}
69
70static int
71encode_alerting(struct uni_msg *msg, struct uni_alerting *p, struct unicx *cx)
72{
73	u_int mlen;
74	u_int i;
75
76	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_ALERTING, cx, &mlen))
77		return (-2);
78
79	if((p->connid.h.present & UNI_IE_PRESENT) &&
80	   uni_encode_ie(UNI_IE_CONNID, msg, (union uni_ieall *)&p->connid, cx))
81		return (UNI_IE_CONNID);
82	if((p->epref.h.present & UNI_IE_PRESENT) &&
83	   uni_encode_ie(UNI_IE_EPREF, msg, (union uni_ieall *)&p->epref, cx))
84		return (UNI_IE_EPREF);
85	if((p->notify.h.present & UNI_IE_PRESENT) &&
86	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
87		return (UNI_IE_NOTIFY);
88	for(i = 0; i < UNI_NUM_IE_GIT; i++)
89		if((p->git[i].h.present & UNI_IE_PRESENT) &&
90		   uni_encode_ie(UNI_IE_GIT, msg, (union uni_ieall *)&p->git[i], cx))
91		return ((i << 16) + UNI_IE_GIT);
92	if((p->uu.h.present & UNI_IE_PRESENT) &&
93	   uni_encode_ie(UNI_IE_UU, msg, (union uni_ieall *)&p->uu, cx))
94		return (UNI_IE_UU);
95	if((p->report.h.present & UNI_IE_PRESENT) &&
96	   uni_encode_ie(UNI_IE_REPORT, msg, (union uni_ieall *)&p->report, cx))
97		return (UNI_IE_REPORT);
98	if((p->unrec.h.present & UNI_IE_PRESENT) &&
99	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
100		return (UNI_IE_UNREC);
101
102	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
103	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
104
105	return (0);
106}
107
108static int
109decode_alerting(struct uni_alerting *out, struct uni_msg *msg,
110    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
111    struct unicx *cx)
112{
113	u_int i;
114
115	switch (ie) {
116
117	  case UNI_IE_CONNID:
118		if (!(!cx->pnni))
119			return (DEC_ILL);
120		out->connid.h = *hdr;
121		if (hdr->present & UNI_IE_ERROR)
122			return (DEC_ERR);
123		if(uni_decode_ie_body(UNI_IE_CONNID, (union uni_ieall *)&out->connid, msg, ielen, cx))
124			return (DEC_ERR);
125		break;
126
127	  case UNI_IE_EPREF:
128		out->epref.h = *hdr;
129		if (hdr->present & UNI_IE_ERROR)
130			return (DEC_ERR);
131		if(uni_decode_ie_body(UNI_IE_EPREF, (union uni_ieall *)&out->epref, msg, ielen, cx))
132			return (DEC_ERR);
133		break;
134
135	  case UNI_IE_NOTIFY:
136		out->notify.h = *hdr;
137		if (hdr->present & UNI_IE_ERROR)
138			return (DEC_ERR);
139		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
140			return (DEC_ERR);
141		break;
142
143	  case UNI_IE_GIT:
144		for(i = 0; i < UNI_NUM_IE_GIT; i++)
145			if (!IE_ISPRESENT(out->git[i])) {
146				out->git[i].h = *hdr;
147				if (hdr->present & UNI_IE_ERROR)
148					return (DEC_ERR);
149				if(uni_decode_ie_body(UNI_IE_GIT, (union uni_ieall *)&out->git[i], msg, ielen, cx))
150					return (DEC_ERR);
151				break;
152			}
153		break;
154
155	  case UNI_IE_UU:
156		if (!(!cx->pnni))
157			return (DEC_ILL);
158		out->uu.h = *hdr;
159		if (hdr->present & UNI_IE_ERROR)
160			return (DEC_ERR);
161		if(uni_decode_ie_body(UNI_IE_UU, (union uni_ieall *)&out->uu, msg, ielen, cx))
162			return (DEC_ERR);
163		break;
164
165	  case UNI_IE_REPORT:
166		if (!(!cx->pnni))
167			return (DEC_ILL);
168		out->report.h = *hdr;
169		if (hdr->present & UNI_IE_ERROR)
170			return (DEC_ERR);
171		if(uni_decode_ie_body(UNI_IE_REPORT, (union uni_ieall *)&out->report, msg, ielen, cx))
172			return (DEC_ERR);
173		break;
174
175	  case UNI_IE_UNREC:
176		out->unrec.h = *hdr;
177		if (hdr->present & UNI_IE_ERROR)
178			return (DEC_ERR);
179		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
180			return (DEC_ERR);
181		break;
182
183	  default:
184		return (DEC_ILL);
185	}
186	return (DEC_OK);
187}
188
189static const struct msgdecl decl_alerting = {
190	0,
191	"alerting",
192	(uni_msg_print_f)print_alerting,
193	(uni_msg_check_f)check_alerting,
194	(uni_msg_encode_f)encode_alerting,
195	(uni_msg_decode_f)decode_alerting
196};
197
198static void
199print_call_proc(struct uni_call_proc *msg, struct unicx *cx)
200{
201	if(msg->connid.h.present & UNI_IE_PRESENT)
202		uni_print_ie_internal(UNI_IE_CONNID, (union uni_ieall *)&msg->connid, cx);
203	if(msg->epref.h.present & UNI_IE_PRESENT)
204		uni_print_ie_internal(UNI_IE_EPREF, (union uni_ieall *)&msg->epref, cx);
205	if(msg->notify.h.present & UNI_IE_PRESENT)
206		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
207	if(msg->unrec.h.present & UNI_IE_PRESENT)
208		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
209}
210
211static int
212check_call_proc(struct uni_call_proc *m, struct unicx *cx)
213{
214	int ret = 0;
215
216	ret |= uni_check_ie(UNI_IE_CONNID, (union uni_ieall *)&m->connid, cx);
217	ret |= uni_check_ie(UNI_IE_EPREF, (union uni_ieall *)&m->epref, cx);
218	if(!(!cx->pnni))
219		ret |= IE_ISPRESENT(m->notify);
220	else
221		ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
222	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
223
224	return ret;
225}
226
227static int
228encode_call_proc(struct uni_msg *msg, struct uni_call_proc *p, struct unicx *cx)
229{
230	u_int mlen;
231
232	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_CALL_PROC, cx, &mlen))
233		return (-2);
234
235	if((p->connid.h.present & UNI_IE_PRESENT) &&
236	   uni_encode_ie(UNI_IE_CONNID, msg, (union uni_ieall *)&p->connid, cx))
237		return (UNI_IE_CONNID);
238	if((p->epref.h.present & UNI_IE_PRESENT) &&
239	   uni_encode_ie(UNI_IE_EPREF, msg, (union uni_ieall *)&p->epref, cx))
240		return (UNI_IE_EPREF);
241	if((p->notify.h.present & UNI_IE_PRESENT) &&
242	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
243		return (UNI_IE_NOTIFY);
244	if((p->unrec.h.present & UNI_IE_PRESENT) &&
245	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
246		return (UNI_IE_UNREC);
247
248	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
249	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
250
251	return (0);
252}
253
254static int
255decode_call_proc(struct uni_call_proc *out, struct uni_msg *msg,
256    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
257    struct unicx *cx)
258{
259	switch (ie) {
260
261	  case UNI_IE_CONNID:
262		out->connid.h = *hdr;
263		if (hdr->present & UNI_IE_ERROR)
264			return (DEC_ERR);
265		if(uni_decode_ie_body(UNI_IE_CONNID, (union uni_ieall *)&out->connid, msg, ielen, cx))
266			return (DEC_ERR);
267		break;
268
269	  case UNI_IE_EPREF:
270		out->epref.h = *hdr;
271		if (hdr->present & UNI_IE_ERROR)
272			return (DEC_ERR);
273		if(uni_decode_ie_body(UNI_IE_EPREF, (union uni_ieall *)&out->epref, msg, ielen, cx))
274			return (DEC_ERR);
275		break;
276
277	  case UNI_IE_NOTIFY:
278		if (!(!cx->pnni))
279			return (DEC_ILL);
280		out->notify.h = *hdr;
281		if (hdr->present & UNI_IE_ERROR)
282			return (DEC_ERR);
283		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
284			return (DEC_ERR);
285		break;
286
287	  case UNI_IE_UNREC:
288		out->unrec.h = *hdr;
289		if (hdr->present & UNI_IE_ERROR)
290			return (DEC_ERR);
291		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
292			return (DEC_ERR);
293		break;
294
295	  default:
296		return (DEC_ILL);
297	}
298	return (DEC_OK);
299}
300
301static const struct msgdecl decl_call_proc = {
302	0,
303	"call_proc",
304	(uni_msg_print_f)print_call_proc,
305	(uni_msg_check_f)check_call_proc,
306	(uni_msg_encode_f)encode_call_proc,
307	(uni_msg_decode_f)decode_call_proc
308};
309
310static void
311print_connect(struct uni_connect *msg, struct unicx *cx)
312{
313	u_int i;
314
315	if(msg->aal.h.present & UNI_IE_PRESENT)
316		uni_print_ie_internal(UNI_IE_AAL, (union uni_ieall *)&msg->aal, cx);
317	if(msg->blli.h.present & UNI_IE_PRESENT)
318		uni_print_ie_internal(UNI_IE_BLLI, (union uni_ieall *)&msg->blli, cx);
319	if(msg->connid.h.present & UNI_IE_PRESENT)
320		uni_print_ie_internal(UNI_IE_CONNID, (union uni_ieall *)&msg->connid, cx);
321	if(msg->epref.h.present & UNI_IE_PRESENT)
322		uni_print_ie_internal(UNI_IE_EPREF, (union uni_ieall *)&msg->epref, cx);
323	if(msg->notify.h.present & UNI_IE_PRESENT)
324		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
325	if(msg->conned.h.present & UNI_IE_PRESENT)
326		uni_print_ie_internal(UNI_IE_CONNED, (union uni_ieall *)&msg->conned, cx);
327	if(msg->connedsub.h.present & UNI_IE_PRESENT)
328		uni_print_ie_internal(UNI_IE_CONNEDSUB, (union uni_ieall *)&msg->connedsub, cx);
329	if(msg->eetd.h.present & UNI_IE_PRESENT)
330		uni_print_ie_internal(UNI_IE_EETD, (union uni_ieall *)&msg->eetd, cx);
331	for(i = 0; i < UNI_NUM_IE_GIT; i++)
332		if(msg->git[i].h.present & UNI_IE_PRESENT)
333			uni_print_ie_internal(UNI_IE_GIT, (union uni_ieall *)&msg->git[i], cx);
334	if(msg->uu.h.present & UNI_IE_PRESENT)
335		uni_print_ie_internal(UNI_IE_UU, (union uni_ieall *)&msg->uu, cx);
336	if(msg->traffic.h.present & UNI_IE_PRESENT)
337		uni_print_ie_internal(UNI_IE_TRAFFIC, (union uni_ieall *)&msg->traffic, cx);
338	if(msg->exqos.h.present & UNI_IE_PRESENT)
339		uni_print_ie_internal(UNI_IE_EXQOS, (union uni_ieall *)&msg->exqos, cx);
340	if(msg->facility.h.present & UNI_IE_PRESENT)
341		uni_print_ie_internal(UNI_IE_FACILITY, (union uni_ieall *)&msg->facility, cx);
342	if(msg->abrsetup.h.present & UNI_IE_PRESENT)
343		uni_print_ie_internal(UNI_IE_ABRSETUP, (union uni_ieall *)&msg->abrsetup, cx);
344	if(msg->abradd.h.present & UNI_IE_PRESENT)
345		uni_print_ie_internal(UNI_IE_ABRADD, (union uni_ieall *)&msg->abradd, cx);
346	if(msg->called_soft.h.present & UNI_IE_PRESENT)
347		uni_print_ie_internal(UNI_IE_CALLED_SOFT, (union uni_ieall *)&msg->called_soft, cx);
348	if(msg->report.h.present & UNI_IE_PRESENT)
349		uni_print_ie_internal(UNI_IE_REPORT, (union uni_ieall *)&msg->report, cx);
350	if(msg->unrec.h.present & UNI_IE_PRESENT)
351		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
352}
353
354static int
355check_connect(struct uni_connect *m, struct unicx *cx)
356{
357	int ret = 0;
358	u_int i;
359
360	ret |= uni_check_ie(UNI_IE_AAL, (union uni_ieall *)&m->aal, cx);
361	ret |= uni_check_ie(UNI_IE_BLLI, (union uni_ieall *)&m->blli, cx);
362	if(!(!cx->pnni))
363		ret |= IE_ISPRESENT(m->connid);
364	else
365		ret |= uni_check_ie(UNI_IE_CONNID, (union uni_ieall *)&m->connid, cx);
366	ret |= uni_check_ie(UNI_IE_EPREF, (union uni_ieall *)&m->epref, cx);
367	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
368	ret |= uni_check_ie(UNI_IE_CONNED, (union uni_ieall *)&m->conned, cx);
369	ret |= uni_check_ie(UNI_IE_CONNEDSUB, (union uni_ieall *)&m->connedsub, cx);
370	ret |= uni_check_ie(UNI_IE_EETD, (union uni_ieall *)&m->eetd, cx);
371	for(i = 0; i < UNI_NUM_IE_GIT ; i++) {
372		ret |= uni_check_ie(UNI_IE_GIT, (union uni_ieall *)&m->git[i], cx);
373	}
374	if(!(!cx->pnni))
375		ret |= IE_ISPRESENT(m->uu);
376	else
377		ret |= uni_check_ie(UNI_IE_UU, (union uni_ieall *)&m->uu, cx);
378	ret |= uni_check_ie(UNI_IE_TRAFFIC, (union uni_ieall *)&m->traffic, cx);
379	ret |= uni_check_ie(UNI_IE_EXQOS, (union uni_ieall *)&m->exqos, cx);
380	if(!(cx->q2932))
381		ret |= IE_ISPRESENT(m->facility);
382	else
383		ret |= uni_check_ie(UNI_IE_FACILITY, (union uni_ieall *)&m->facility, cx);
384	ret |= uni_check_ie(UNI_IE_ABRSETUP, (union uni_ieall *)&m->abrsetup, cx);
385	ret |= uni_check_ie(UNI_IE_ABRADD, (union uni_ieall *)&m->abradd, cx);
386	if(!(cx->pnni))
387		ret |= IE_ISPRESENT(m->called_soft);
388	else
389		ret |= uni_check_ie(UNI_IE_CALLED_SOFT, (union uni_ieall *)&m->called_soft, cx);
390	if(!(!cx->pnni))
391		ret |= IE_ISPRESENT(m->report);
392	else
393		ret |= uni_check_ie(UNI_IE_REPORT, (union uni_ieall *)&m->report, cx);
394	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
395
396	return ret;
397}
398
399static int
400encode_connect(struct uni_msg *msg, struct uni_connect *p, struct unicx *cx)
401{
402	u_int mlen;
403	u_int i;
404
405	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_CONNECT, cx, &mlen))
406		return (-2);
407
408	if((p->aal.h.present & UNI_IE_PRESENT) &&
409	   uni_encode_ie(UNI_IE_AAL, msg, (union uni_ieall *)&p->aal, cx))
410		return (UNI_IE_AAL);
411	if((p->blli.h.present & UNI_IE_PRESENT) &&
412	   uni_encode_ie(UNI_IE_BLLI, msg, (union uni_ieall *)&p->blli, cx))
413		return (UNI_IE_BLLI);
414	if((p->connid.h.present & UNI_IE_PRESENT) &&
415	   uni_encode_ie(UNI_IE_CONNID, msg, (union uni_ieall *)&p->connid, cx))
416		return (UNI_IE_CONNID);
417	if((p->epref.h.present & UNI_IE_PRESENT) &&
418	   uni_encode_ie(UNI_IE_EPREF, msg, (union uni_ieall *)&p->epref, cx))
419		return (UNI_IE_EPREF);
420	if((p->notify.h.present & UNI_IE_PRESENT) &&
421	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
422		return (UNI_IE_NOTIFY);
423	if((p->conned.h.present & UNI_IE_PRESENT) &&
424	   uni_encode_ie(UNI_IE_CONNED, msg, (union uni_ieall *)&p->conned, cx))
425		return (UNI_IE_CONNED);
426	if((p->connedsub.h.present & UNI_IE_PRESENT) &&
427	   uni_encode_ie(UNI_IE_CONNEDSUB, msg, (union uni_ieall *)&p->connedsub, cx))
428		return (UNI_IE_CONNEDSUB);
429	if((p->eetd.h.present & UNI_IE_PRESENT) &&
430	   uni_encode_ie(UNI_IE_EETD, msg, (union uni_ieall *)&p->eetd, cx))
431		return (UNI_IE_EETD);
432	for(i = 0; i < UNI_NUM_IE_GIT; i++)
433		if((p->git[i].h.present & UNI_IE_PRESENT) &&
434		   uni_encode_ie(UNI_IE_GIT, msg, (union uni_ieall *)&p->git[i], cx))
435		return ((i << 16) + UNI_IE_GIT);
436	if((p->uu.h.present & UNI_IE_PRESENT) &&
437	   uni_encode_ie(UNI_IE_UU, msg, (union uni_ieall *)&p->uu, cx))
438		return (UNI_IE_UU);
439	if((p->traffic.h.present & UNI_IE_PRESENT) &&
440	   uni_encode_ie(UNI_IE_TRAFFIC, msg, (union uni_ieall *)&p->traffic, cx))
441		return (UNI_IE_TRAFFIC);
442	if((p->exqos.h.present & UNI_IE_PRESENT) &&
443	   uni_encode_ie(UNI_IE_EXQOS, msg, (union uni_ieall *)&p->exqos, cx))
444		return (UNI_IE_EXQOS);
445	if((p->facility.h.present & UNI_IE_PRESENT) &&
446	   uni_encode_ie(UNI_IE_FACILITY, msg, (union uni_ieall *)&p->facility, cx))
447		return (UNI_IE_FACILITY);
448	if((p->abrsetup.h.present & UNI_IE_PRESENT) &&
449	   uni_encode_ie(UNI_IE_ABRSETUP, msg, (union uni_ieall *)&p->abrsetup, cx))
450		return (UNI_IE_ABRSETUP);
451	if((p->abradd.h.present & UNI_IE_PRESENT) &&
452	   uni_encode_ie(UNI_IE_ABRADD, msg, (union uni_ieall *)&p->abradd, cx))
453		return (UNI_IE_ABRADD);
454	if((p->called_soft.h.present & UNI_IE_PRESENT) &&
455	   uni_encode_ie(UNI_IE_CALLED_SOFT, msg, (union uni_ieall *)&p->called_soft, cx))
456		return (UNI_IE_CALLED_SOFT);
457	if((p->report.h.present & UNI_IE_PRESENT) &&
458	   uni_encode_ie(UNI_IE_REPORT, msg, (union uni_ieall *)&p->report, cx))
459		return (UNI_IE_REPORT);
460	if((p->unrec.h.present & UNI_IE_PRESENT) &&
461	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
462		return (UNI_IE_UNREC);
463
464	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
465	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
466
467	return (0);
468}
469
470static int
471decode_connect(struct uni_connect *out, struct uni_msg *msg,
472    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
473    struct unicx *cx)
474{
475	u_int i;
476
477	switch (ie) {
478
479	  case UNI_IE_AAL:
480		out->aal.h = *hdr;
481		if (hdr->present & UNI_IE_ERROR)
482			return (DEC_ERR);
483		if(uni_decode_ie_body(UNI_IE_AAL, (union uni_ieall *)&out->aal, msg, ielen, cx))
484			return (DEC_ERR);
485		break;
486
487	  case UNI_IE_BLLI:
488		out->blli.h = *hdr;
489		if (hdr->present & UNI_IE_ERROR)
490			return (DEC_ERR);
491		if(uni_decode_ie_body(UNI_IE_BLLI, (union uni_ieall *)&out->blli, msg, ielen, cx))
492			return (DEC_ERR);
493		break;
494
495	  case UNI_IE_CONNID:
496		if (!(!cx->pnni))
497			return (DEC_ILL);
498		out->connid.h = *hdr;
499		if (hdr->present & UNI_IE_ERROR)
500			return (DEC_ERR);
501		if(uni_decode_ie_body(UNI_IE_CONNID, (union uni_ieall *)&out->connid, msg, ielen, cx))
502			return (DEC_ERR);
503		break;
504
505	  case UNI_IE_EPREF:
506		out->epref.h = *hdr;
507		if (hdr->present & UNI_IE_ERROR)
508			return (DEC_ERR);
509		if(uni_decode_ie_body(UNI_IE_EPREF, (union uni_ieall *)&out->epref, msg, ielen, cx))
510			return (DEC_ERR);
511		break;
512
513	  case UNI_IE_NOTIFY:
514		out->notify.h = *hdr;
515		if (hdr->present & UNI_IE_ERROR)
516			return (DEC_ERR);
517		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
518			return (DEC_ERR);
519		break;
520
521	  case UNI_IE_CONNED:
522		out->conned.h = *hdr;
523		if (hdr->present & UNI_IE_ERROR)
524			return (DEC_ERR);
525		if(uni_decode_ie_body(UNI_IE_CONNED, (union uni_ieall *)&out->conned, msg, ielen, cx))
526			return (DEC_ERR);
527		break;
528
529	  case UNI_IE_CONNEDSUB:
530		out->connedsub.h = *hdr;
531		if (hdr->present & UNI_IE_ERROR)
532			return (DEC_ERR);
533		if(uni_decode_ie_body(UNI_IE_CONNEDSUB, (union uni_ieall *)&out->connedsub, msg, ielen, cx))
534			return (DEC_ERR);
535		break;
536
537	  case UNI_IE_EETD:
538		out->eetd.h = *hdr;
539		if (hdr->present & UNI_IE_ERROR)
540			return (DEC_ERR);
541		if(uni_decode_ie_body(UNI_IE_EETD, (union uni_ieall *)&out->eetd, msg, ielen, cx))
542			return (DEC_ERR);
543		break;
544
545	  case UNI_IE_GIT:
546		for(i = 0; i < UNI_NUM_IE_GIT; i++)
547			if (!IE_ISPRESENT(out->git[i])) {
548				out->git[i].h = *hdr;
549				if (hdr->present & UNI_IE_ERROR)
550					return (DEC_ERR);
551				if(uni_decode_ie_body(UNI_IE_GIT, (union uni_ieall *)&out->git[i], msg, ielen, cx))
552					return (DEC_ERR);
553				break;
554			}
555		break;
556
557	  case UNI_IE_UU:
558		if (!(!cx->pnni))
559			return (DEC_ILL);
560		out->uu.h = *hdr;
561		if (hdr->present & UNI_IE_ERROR)
562			return (DEC_ERR);
563		if(uni_decode_ie_body(UNI_IE_UU, (union uni_ieall *)&out->uu, msg, ielen, cx))
564			return (DEC_ERR);
565		break;
566
567	  case UNI_IE_TRAFFIC:
568		out->traffic.h = *hdr;
569		if (hdr->present & UNI_IE_ERROR)
570			return (DEC_ERR);
571		if(uni_decode_ie_body(UNI_IE_TRAFFIC, (union uni_ieall *)&out->traffic, msg, ielen, cx))
572			return (DEC_ERR);
573		break;
574
575	  case UNI_IE_EXQOS:
576		out->exqos.h = *hdr;
577		if (hdr->present & UNI_IE_ERROR)
578			return (DEC_ERR);
579		if(uni_decode_ie_body(UNI_IE_EXQOS, (union uni_ieall *)&out->exqos, msg, ielen, cx))
580			return (DEC_ERR);
581		break;
582
583	  case UNI_IE_FACILITY:
584		if (!(cx->q2932))
585			return (DEC_ILL);
586		out->facility.h = *hdr;
587		if (hdr->present & UNI_IE_ERROR)
588			return (DEC_ERR);
589		if(uni_decode_ie_body(UNI_IE_FACILITY, (union uni_ieall *)&out->facility, msg, ielen, cx))
590			return (DEC_ERR);
591		break;
592
593	  case UNI_IE_ABRSETUP:
594		out->abrsetup.h = *hdr;
595		if (hdr->present & UNI_IE_ERROR)
596			return (DEC_ERR);
597		if(uni_decode_ie_body(UNI_IE_ABRSETUP, (union uni_ieall *)&out->abrsetup, msg, ielen, cx))
598			return (DEC_ERR);
599		break;
600
601	  case UNI_IE_ABRADD:
602		out->abradd.h = *hdr;
603		if (hdr->present & UNI_IE_ERROR)
604			return (DEC_ERR);
605		if(uni_decode_ie_body(UNI_IE_ABRADD, (union uni_ieall *)&out->abradd, msg, ielen, cx))
606			return (DEC_ERR);
607		break;
608
609	  case UNI_IE_CALLED_SOFT:
610		if (!(cx->pnni))
611			return (DEC_ILL);
612		out->called_soft.h = *hdr;
613		if (hdr->present & UNI_IE_ERROR)
614			return (DEC_ERR);
615		if(uni_decode_ie_body(UNI_IE_CALLED_SOFT, (union uni_ieall *)&out->called_soft, msg, ielen, cx))
616			return (DEC_ERR);
617		break;
618
619	  case UNI_IE_REPORT:
620		if (!(!cx->pnni))
621			return (DEC_ILL);
622		out->report.h = *hdr;
623		if (hdr->present & UNI_IE_ERROR)
624			return (DEC_ERR);
625		if(uni_decode_ie_body(UNI_IE_REPORT, (union uni_ieall *)&out->report, msg, ielen, cx))
626			return (DEC_ERR);
627		break;
628
629	  case UNI_IE_UNREC:
630		out->unrec.h = *hdr;
631		if (hdr->present & UNI_IE_ERROR)
632			return (DEC_ERR);
633		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
634			return (DEC_ERR);
635		break;
636
637	  default:
638		return (DEC_ILL);
639	}
640	return (DEC_OK);
641}
642
643static const struct msgdecl decl_connect = {
644	0,
645	"connect",
646	(uni_msg_print_f)print_connect,
647	(uni_msg_check_f)check_connect,
648	(uni_msg_encode_f)encode_connect,
649	(uni_msg_decode_f)decode_connect
650};
651
652static void
653print_connect_ack(struct uni_connect_ack *msg, struct unicx *cx)
654{
655	if(msg->notify.h.present & UNI_IE_PRESENT)
656		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
657	if(msg->unrec.h.present & UNI_IE_PRESENT)
658		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
659}
660
661static int
662check_connect_ack(struct uni_connect_ack *m, struct unicx *cx)
663{
664	int ret = 0;
665
666	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
667	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
668
669	return ret;
670}
671
672static int
673encode_connect_ack(struct uni_msg *msg, struct uni_connect_ack *p, struct unicx *cx)
674{
675	u_int mlen;
676
677	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_CONNECT_ACK, cx, &mlen))
678		return (-2);
679
680	if((p->notify.h.present & UNI_IE_PRESENT) &&
681	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
682		return (UNI_IE_NOTIFY);
683	if((p->unrec.h.present & UNI_IE_PRESENT) &&
684	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
685		return (UNI_IE_UNREC);
686
687	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
688	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
689
690	return (0);
691}
692
693static int
694decode_connect_ack(struct uni_connect_ack *out, struct uni_msg *msg,
695    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
696    struct unicx *cx)
697{
698	switch (ie) {
699
700	  case UNI_IE_NOTIFY:
701		out->notify.h = *hdr;
702		if (hdr->present & UNI_IE_ERROR)
703			return (DEC_ERR);
704		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
705			return (DEC_ERR);
706		break;
707
708	  case UNI_IE_UNREC:
709		out->unrec.h = *hdr;
710		if (hdr->present & UNI_IE_ERROR)
711			return (DEC_ERR);
712		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
713			return (DEC_ERR);
714		break;
715
716	  default:
717		return (DEC_ILL);
718	}
719	return (DEC_OK);
720}
721
722static const struct msgdecl decl_connect_ack = {
723	0,
724	"connect_ack",
725	(uni_msg_print_f)print_connect_ack,
726	(uni_msg_check_f)check_connect_ack,
727	(uni_msg_encode_f)encode_connect_ack,
728	(uni_msg_decode_f)decode_connect_ack
729};
730
731static void
732print_release(struct uni_release *msg, struct unicx *cx)
733{
734	u_int i;
735
736	for(i = 0; i < 2; i++)
737		if(msg->cause[i].h.present & UNI_IE_PRESENT)
738			uni_print_ie_internal(UNI_IE_CAUSE, (union uni_ieall *)&msg->cause[i], cx);
739	if(msg->notify.h.present & UNI_IE_PRESENT)
740		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
741	for(i = 0; i < UNI_NUM_IE_GIT; i++)
742		if(msg->git[i].h.present & UNI_IE_PRESENT)
743			uni_print_ie_internal(UNI_IE_GIT, (union uni_ieall *)&msg->git[i], cx);
744	if(msg->uu.h.present & UNI_IE_PRESENT)
745		uni_print_ie_internal(UNI_IE_UU, (union uni_ieall *)&msg->uu, cx);
746	if(msg->facility.h.present & UNI_IE_PRESENT)
747		uni_print_ie_internal(UNI_IE_FACILITY, (union uni_ieall *)&msg->facility, cx);
748	if(msg->crankback.h.present & UNI_IE_PRESENT)
749		uni_print_ie_internal(UNI_IE_CRANKBACK, (union uni_ieall *)&msg->crankback, cx);
750	if(msg->unrec.h.present & UNI_IE_PRESENT)
751		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
752}
753
754static int
755check_release(struct uni_release *m, struct unicx *cx)
756{
757	int ret = 0;
758	u_int i;
759
760	for(i = 0; i < 2 ; i++) {
761		ret |= uni_check_ie(UNI_IE_CAUSE, (union uni_ieall *)&m->cause[i], cx);
762	}
763	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
764	for(i = 0; i < UNI_NUM_IE_GIT ; i++) {
765		ret |= uni_check_ie(UNI_IE_GIT, (union uni_ieall *)&m->git[i], cx);
766	}
767	if(!(!cx->pnni))
768		ret |= IE_ISPRESENT(m->uu);
769	else
770		ret |= uni_check_ie(UNI_IE_UU, (union uni_ieall *)&m->uu, cx);
771	if(!(cx->q2932))
772		ret |= IE_ISPRESENT(m->facility);
773	else
774		ret |= uni_check_ie(UNI_IE_FACILITY, (union uni_ieall *)&m->facility, cx);
775	if(!(cx->pnni))
776		ret |= IE_ISPRESENT(m->crankback);
777	else
778		ret |= uni_check_ie(UNI_IE_CRANKBACK, (union uni_ieall *)&m->crankback, cx);
779	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
780
781	return ret;
782}
783
784static int
785encode_release(struct uni_msg *msg, struct uni_release *p, struct unicx *cx)
786{
787	u_int mlen;
788	u_int i;
789
790	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_RELEASE, cx, &mlen))
791		return (-2);
792
793	for(i = 0; i < 2; i++)
794		if((p->cause[i].h.present & UNI_IE_PRESENT) &&
795		   uni_encode_ie(UNI_IE_CAUSE, msg, (union uni_ieall *)&p->cause[i], cx))
796		return ((i << 16) + UNI_IE_CAUSE);
797	if((p->notify.h.present & UNI_IE_PRESENT) &&
798	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
799		return (UNI_IE_NOTIFY);
800	for(i = 0; i < UNI_NUM_IE_GIT; i++)
801		if((p->git[i].h.present & UNI_IE_PRESENT) &&
802		   uni_encode_ie(UNI_IE_GIT, msg, (union uni_ieall *)&p->git[i], cx))
803		return ((i << 16) + UNI_IE_GIT);
804	if((p->uu.h.present & UNI_IE_PRESENT) &&
805	   uni_encode_ie(UNI_IE_UU, msg, (union uni_ieall *)&p->uu, cx))
806		return (UNI_IE_UU);
807	if((p->facility.h.present & UNI_IE_PRESENT) &&
808	   uni_encode_ie(UNI_IE_FACILITY, msg, (union uni_ieall *)&p->facility, cx))
809		return (UNI_IE_FACILITY);
810	if((p->crankback.h.present & UNI_IE_PRESENT) &&
811	   uni_encode_ie(UNI_IE_CRANKBACK, msg, (union uni_ieall *)&p->crankback, cx))
812		return (UNI_IE_CRANKBACK);
813	if((p->unrec.h.present & UNI_IE_PRESENT) &&
814	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
815		return (UNI_IE_UNREC);
816
817	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
818	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
819
820	return (0);
821}
822
823static int
824decode_release(struct uni_release *out, struct uni_msg *msg,
825    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
826    struct unicx *cx)
827{
828	u_int i;
829
830	switch (ie) {
831
832	  case UNI_IE_CAUSE:
833		for(i = 0; i < 2; i++)
834			if (!IE_ISPRESENT(out->cause[i])) {
835				out->cause[i].h = *hdr;
836				if (hdr->present & UNI_IE_ERROR)
837					return (DEC_ERR);
838				if(uni_decode_ie_body(UNI_IE_CAUSE, (union uni_ieall *)&out->cause[i], msg, ielen, cx))
839					return (DEC_ERR);
840				break;
841			}
842		break;
843
844	  case UNI_IE_NOTIFY:
845		out->notify.h = *hdr;
846		if (hdr->present & UNI_IE_ERROR)
847			return (DEC_ERR);
848		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
849			return (DEC_ERR);
850		break;
851
852	  case UNI_IE_GIT:
853		for(i = 0; i < UNI_NUM_IE_GIT; i++)
854			if (!IE_ISPRESENT(out->git[i])) {
855				out->git[i].h = *hdr;
856				if (hdr->present & UNI_IE_ERROR)
857					return (DEC_ERR);
858				if(uni_decode_ie_body(UNI_IE_GIT, (union uni_ieall *)&out->git[i], msg, ielen, cx))
859					return (DEC_ERR);
860				break;
861			}
862		break;
863
864	  case UNI_IE_UU:
865		if (!(!cx->pnni))
866			return (DEC_ILL);
867		out->uu.h = *hdr;
868		if (hdr->present & UNI_IE_ERROR)
869			return (DEC_ERR);
870		if(uni_decode_ie_body(UNI_IE_UU, (union uni_ieall *)&out->uu, msg, ielen, cx))
871			return (DEC_ERR);
872		break;
873
874	  case UNI_IE_FACILITY:
875		if (!(cx->q2932))
876			return (DEC_ILL);
877		out->facility.h = *hdr;
878		if (hdr->present & UNI_IE_ERROR)
879			return (DEC_ERR);
880		if(uni_decode_ie_body(UNI_IE_FACILITY, (union uni_ieall *)&out->facility, msg, ielen, cx))
881			return (DEC_ERR);
882		break;
883
884	  case UNI_IE_CRANKBACK:
885		if (!(cx->pnni))
886			return (DEC_ILL);
887		out->crankback.h = *hdr;
888		if (hdr->present & UNI_IE_ERROR)
889			return (DEC_ERR);
890		if(uni_decode_ie_body(UNI_IE_CRANKBACK, (union uni_ieall *)&out->crankback, msg, ielen, cx))
891			return (DEC_ERR);
892		break;
893
894	  case UNI_IE_UNREC:
895		out->unrec.h = *hdr;
896		if (hdr->present & UNI_IE_ERROR)
897			return (DEC_ERR);
898		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
899			return (DEC_ERR);
900		break;
901
902	  default:
903		return (DEC_ILL);
904	}
905	return (DEC_OK);
906}
907
908static const struct msgdecl decl_release = {
909	0,
910	"release",
911	(uni_msg_print_f)print_release,
912	(uni_msg_check_f)check_release,
913	(uni_msg_encode_f)encode_release,
914	(uni_msg_decode_f)decode_release
915};
916
917static void
918print_release_compl(struct uni_release_compl *msg, struct unicx *cx)
919{
920	u_int i;
921
922	for(i = 0; i < 2; i++)
923		if(msg->cause[i].h.present & UNI_IE_PRESENT)
924			uni_print_ie_internal(UNI_IE_CAUSE, (union uni_ieall *)&msg->cause[i], cx);
925	for(i = 0; i < UNI_NUM_IE_GIT; i++)
926		if(msg->git[i].h.present & UNI_IE_PRESENT)
927			uni_print_ie_internal(UNI_IE_GIT, (union uni_ieall *)&msg->git[i], cx);
928	if(msg->uu.h.present & UNI_IE_PRESENT)
929		uni_print_ie_internal(UNI_IE_UU, (union uni_ieall *)&msg->uu, cx);
930	if(msg->crankback.h.present & UNI_IE_PRESENT)
931		uni_print_ie_internal(UNI_IE_CRANKBACK, (union uni_ieall *)&msg->crankback, cx);
932	if(msg->unrec.h.present & UNI_IE_PRESENT)
933		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
934}
935
936static int
937check_release_compl(struct uni_release_compl *m, struct unicx *cx)
938{
939	int ret = 0;
940	u_int i;
941
942	for(i = 0; i < 2 ; i++) {
943		ret |= uni_check_ie(UNI_IE_CAUSE, (union uni_ieall *)&m->cause[i], cx);
944	}
945	for(i = 0; i < UNI_NUM_IE_GIT ; i++) {
946		if(!(!cx->pnni))
947			ret |= IE_ISPRESENT(m->git[i]);
948		else
949			ret |= uni_check_ie(UNI_IE_GIT, (union uni_ieall *)&m->git[i], cx);
950	}
951	if(!(!cx->pnni))
952		ret |= IE_ISPRESENT(m->uu);
953	else
954		ret |= uni_check_ie(UNI_IE_UU, (union uni_ieall *)&m->uu, cx);
955	if(!(cx->pnni))
956		ret |= IE_ISPRESENT(m->crankback);
957	else
958		ret |= uni_check_ie(UNI_IE_CRANKBACK, (union uni_ieall *)&m->crankback, cx);
959	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
960
961	return ret;
962}
963
964static int
965encode_release_compl(struct uni_msg *msg, struct uni_release_compl *p, struct unicx *cx)
966{
967	u_int mlen;
968	u_int i;
969
970	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_RELEASE_COMPL, cx, &mlen))
971		return (-2);
972
973	for(i = 0; i < 2; i++)
974		if((p->cause[i].h.present & UNI_IE_PRESENT) &&
975		   uni_encode_ie(UNI_IE_CAUSE, msg, (union uni_ieall *)&p->cause[i], cx))
976		return ((i << 16) + UNI_IE_CAUSE);
977	for(i = 0; i < UNI_NUM_IE_GIT; i++)
978		if((p->git[i].h.present & UNI_IE_PRESENT) &&
979		   uni_encode_ie(UNI_IE_GIT, msg, (union uni_ieall *)&p->git[i], cx))
980		return ((i << 16) + UNI_IE_GIT);
981	if((p->uu.h.present & UNI_IE_PRESENT) &&
982	   uni_encode_ie(UNI_IE_UU, msg, (union uni_ieall *)&p->uu, cx))
983		return (UNI_IE_UU);
984	if((p->crankback.h.present & UNI_IE_PRESENT) &&
985	   uni_encode_ie(UNI_IE_CRANKBACK, msg, (union uni_ieall *)&p->crankback, cx))
986		return (UNI_IE_CRANKBACK);
987	if((p->unrec.h.present & UNI_IE_PRESENT) &&
988	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
989		return (UNI_IE_UNREC);
990
991	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
992	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
993
994	return (0);
995}
996
997static int
998decode_release_compl(struct uni_release_compl *out, struct uni_msg *msg,
999    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
1000    struct unicx *cx)
1001{
1002	u_int i;
1003
1004	switch (ie) {
1005
1006	  case UNI_IE_CAUSE:
1007		for(i = 0; i < 2; i++)
1008			if (!IE_ISPRESENT(out->cause[i])) {
1009				out->cause[i].h = *hdr;
1010				if (hdr->present & UNI_IE_ERROR)
1011					return (DEC_ERR);
1012				if(uni_decode_ie_body(UNI_IE_CAUSE, (union uni_ieall *)&out->cause[i], msg, ielen, cx))
1013					return (DEC_ERR);
1014				break;
1015			}
1016		break;
1017
1018	  case UNI_IE_GIT:
1019		if (!(!cx->pnni))
1020			return (DEC_ILL);
1021		for(i = 0; i < UNI_NUM_IE_GIT; i++)
1022			if (!IE_ISPRESENT(out->git[i])) {
1023				out->git[i].h = *hdr;
1024				if (hdr->present & UNI_IE_ERROR)
1025					return (DEC_ERR);
1026				if(uni_decode_ie_body(UNI_IE_GIT, (union uni_ieall *)&out->git[i], msg, ielen, cx))
1027					return (DEC_ERR);
1028				break;
1029			}
1030		break;
1031
1032	  case UNI_IE_UU:
1033		if (!(!cx->pnni))
1034			return (DEC_ILL);
1035		out->uu.h = *hdr;
1036		if (hdr->present & UNI_IE_ERROR)
1037			return (DEC_ERR);
1038		if(uni_decode_ie_body(UNI_IE_UU, (union uni_ieall *)&out->uu, msg, ielen, cx))
1039			return (DEC_ERR);
1040		break;
1041
1042	  case UNI_IE_CRANKBACK:
1043		if (!(cx->pnni))
1044			return (DEC_ILL);
1045		out->crankback.h = *hdr;
1046		if (hdr->present & UNI_IE_ERROR)
1047			return (DEC_ERR);
1048		if(uni_decode_ie_body(UNI_IE_CRANKBACK, (union uni_ieall *)&out->crankback, msg, ielen, cx))
1049			return (DEC_ERR);
1050		break;
1051
1052	  case UNI_IE_UNREC:
1053		out->unrec.h = *hdr;
1054		if (hdr->present & UNI_IE_ERROR)
1055			return (DEC_ERR);
1056		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
1057			return (DEC_ERR);
1058		break;
1059
1060	  default:
1061		return (DEC_ILL);
1062	}
1063	return (DEC_OK);
1064}
1065
1066static const struct msgdecl decl_release_compl = {
1067	0,
1068	"release_compl",
1069	(uni_msg_print_f)print_release_compl,
1070	(uni_msg_check_f)check_release_compl,
1071	(uni_msg_encode_f)encode_release_compl,
1072	(uni_msg_decode_f)decode_release_compl
1073};
1074
1075static void
1076print_setup(struct uni_setup *msg, struct unicx *cx)
1077{
1078	u_int i;
1079
1080	if(msg->aal.h.present & UNI_IE_PRESENT)
1081		uni_print_ie_internal(UNI_IE_AAL, (union uni_ieall *)&msg->aal, cx);
1082	if(msg->traffic.h.present & UNI_IE_PRESENT)
1083		uni_print_ie_internal(UNI_IE_TRAFFIC, (union uni_ieall *)&msg->traffic, cx);
1084	if(msg->bearer.h.present & UNI_IE_PRESENT)
1085		uni_print_ie_internal(UNI_IE_BEARER, (union uni_ieall *)&msg->bearer, cx);
1086	if(msg->bhli.h.present & UNI_IE_PRESENT)
1087		uni_print_ie_internal(UNI_IE_BHLI, (union uni_ieall *)&msg->bhli, cx);
1088	if(msg->blli_repeat.h.present & UNI_IE_PRESENT)
1089		uni_print_ie_internal(UNI_IE_REPEAT, (union uni_ieall *)&msg->blli_repeat, cx);
1090	for(i = 0; i < UNI_NUM_IE_BLLI; i++)
1091		if(msg->blli[i].h.present & UNI_IE_PRESENT)
1092			uni_print_ie_internal(UNI_IE_BLLI, (union uni_ieall *)&msg->blli[i], cx);
1093	if(msg->called.h.present & UNI_IE_PRESENT)
1094		uni_print_ie_internal(UNI_IE_CALLED, (union uni_ieall *)&msg->called, cx);
1095	for(i = 0; i < UNI_NUM_IE_CALLEDSUB; i++)
1096		if(msg->calledsub[i].h.present & UNI_IE_PRESENT)
1097			uni_print_ie_internal(UNI_IE_CALLEDSUB, (union uni_ieall *)&msg->calledsub[i], cx);
1098	if(msg->calling.h.present & UNI_IE_PRESENT)
1099		uni_print_ie_internal(UNI_IE_CALLING, (union uni_ieall *)&msg->calling, cx);
1100	for(i = 0; i < UNI_NUM_IE_CALLINGSUB; i++)
1101		if(msg->callingsub[i].h.present & UNI_IE_PRESENT)
1102			uni_print_ie_internal(UNI_IE_CALLINGSUB, (union uni_ieall *)&msg->callingsub[i], cx);
1103	if(msg->connid.h.present & UNI_IE_PRESENT)
1104		uni_print_ie_internal(UNI_IE_CONNID, (union uni_ieall *)&msg->connid, cx);
1105	if(msg->qos.h.present & UNI_IE_PRESENT)
1106		uni_print_ie_internal(UNI_IE_QOS, (union uni_ieall *)&msg->qos, cx);
1107	if(msg->eetd.h.present & UNI_IE_PRESENT)
1108		uni_print_ie_internal(UNI_IE_EETD, (union uni_ieall *)&msg->eetd, cx);
1109	if(msg->notify.h.present & UNI_IE_PRESENT)
1110		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
1111	if(msg->scompl.h.present & UNI_IE_PRESENT)
1112		uni_print_ie_internal(UNI_IE_SCOMPL, (union uni_ieall *)&msg->scompl, cx);
1113	for(i = 0; i < UNI_NUM_IE_TNS; i++)
1114		if(msg->tns[i].h.present & UNI_IE_PRESENT)
1115			uni_print_ie_internal(UNI_IE_TNS, (union uni_ieall *)&msg->tns[i], cx);
1116	if(msg->epref.h.present & UNI_IE_PRESENT)
1117		uni_print_ie_internal(UNI_IE_EPREF, (union uni_ieall *)&msg->epref, cx);
1118	if(msg->atraffic.h.present & UNI_IE_PRESENT)
1119		uni_print_ie_internal(UNI_IE_ATRAFFIC, (union uni_ieall *)&msg->atraffic, cx);
1120	if(msg->mintraffic.h.present & UNI_IE_PRESENT)
1121		uni_print_ie_internal(UNI_IE_MINTRAFFIC, (union uni_ieall *)&msg->mintraffic, cx);
1122	if(msg->uu.h.present & UNI_IE_PRESENT)
1123		uni_print_ie_internal(UNI_IE_UU, (union uni_ieall *)&msg->uu, cx);
1124	for(i = 0; i < UNI_NUM_IE_GIT; i++)
1125		if(msg->git[i].h.present & UNI_IE_PRESENT)
1126			uni_print_ie_internal(UNI_IE_GIT, (union uni_ieall *)&msg->git[i], cx);
1127	if(msg->lij_callid.h.present & UNI_IE_PRESENT)
1128		uni_print_ie_internal(UNI_IE_LIJ_CALLID, (union uni_ieall *)&msg->lij_callid, cx);
1129	if(msg->lij_param.h.present & UNI_IE_PRESENT)
1130		uni_print_ie_internal(UNI_IE_LIJ_PARAM, (union uni_ieall *)&msg->lij_param, cx);
1131	if(msg->lij_seqno.h.present & UNI_IE_PRESENT)
1132		uni_print_ie_internal(UNI_IE_LIJ_SEQNO, (union uni_ieall *)&msg->lij_seqno, cx);
1133	if(msg->exqos.h.present & UNI_IE_PRESENT)
1134		uni_print_ie_internal(UNI_IE_EXQOS, (union uni_ieall *)&msg->exqos, cx);
1135	if(msg->abrsetup.h.present & UNI_IE_PRESENT)
1136		uni_print_ie_internal(UNI_IE_ABRSETUP, (union uni_ieall *)&msg->abrsetup, cx);
1137	if(msg->abradd.h.present & UNI_IE_PRESENT)
1138		uni_print_ie_internal(UNI_IE_ABRADD, (union uni_ieall *)&msg->abradd, cx);
1139	if(msg->cscope.h.present & UNI_IE_PRESENT)
1140		uni_print_ie_internal(UNI_IE_CSCOPE, (union uni_ieall *)&msg->cscope, cx);
1141	if(msg->calling_soft.h.present & UNI_IE_PRESENT)
1142		uni_print_ie_internal(UNI_IE_CALLING_SOFT, (union uni_ieall *)&msg->calling_soft, cx);
1143	if(msg->called_soft.h.present & UNI_IE_PRESENT)
1144		uni_print_ie_internal(UNI_IE_CALLED_SOFT, (union uni_ieall *)&msg->called_soft, cx);
1145	if(msg->dtl_repeat.h.present & UNI_IE_PRESENT)
1146		uni_print_ie_internal(UNI_IE_REPEAT, (union uni_ieall *)&msg->dtl_repeat, cx);
1147	for(i = 0; i < UNI_NUM_IE_DTL; i++)
1148		if(msg->dtl[i].h.present & UNI_IE_PRESENT)
1149			uni_print_ie_internal(UNI_IE_DTL, (union uni_ieall *)&msg->dtl[i], cx);
1150	if(msg->report.h.present & UNI_IE_PRESENT)
1151		uni_print_ie_internal(UNI_IE_REPORT, (union uni_ieall *)&msg->report, cx);
1152	if(msg->mdcr.h.present & UNI_IE_PRESENT)
1153		uni_print_ie_internal(UNI_IE_MDCR, (union uni_ieall *)&msg->mdcr, cx);
1154	if(msg->unrec.h.present & UNI_IE_PRESENT)
1155		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
1156}
1157
1158static int
1159check_setup(struct uni_setup *m, struct unicx *cx)
1160{
1161	int ret = 0;
1162	u_int i;
1163
1164	ret |= uni_check_ie(UNI_IE_AAL, (union uni_ieall *)&m->aal, cx);
1165	ret |= uni_check_ie(UNI_IE_TRAFFIC, (union uni_ieall *)&m->traffic, cx);
1166	ret |= uni_check_ie(UNI_IE_BEARER, (union uni_ieall *)&m->bearer, cx);
1167	ret |= uni_check_ie(UNI_IE_BHLI, (union uni_ieall *)&m->bhli, cx);
1168	ret |= uni_check_ie(UNI_IE_REPEAT, (union uni_ieall *)&m->blli_repeat, cx);
1169	for(i = 0; i < UNI_NUM_IE_BLLI ; i++) {
1170		ret |= uni_check_ie(UNI_IE_BLLI, (union uni_ieall *)&m->blli[i], cx);
1171	}
1172	ret |= uni_check_ie(UNI_IE_CALLED, (union uni_ieall *)&m->called, cx);
1173	for(i = 0; i < UNI_NUM_IE_CALLEDSUB ; i++) {
1174		ret |= uni_check_ie(UNI_IE_CALLEDSUB, (union uni_ieall *)&m->calledsub[i], cx);
1175	}
1176	ret |= uni_check_ie(UNI_IE_CALLING, (union uni_ieall *)&m->calling, cx);
1177	for(i = 0; i < UNI_NUM_IE_CALLINGSUB ; i++) {
1178		ret |= uni_check_ie(UNI_IE_CALLINGSUB, (union uni_ieall *)&m->callingsub[i], cx);
1179	}
1180	ret |= uni_check_ie(UNI_IE_CONNID, (union uni_ieall *)&m->connid, cx);
1181	ret |= uni_check_ie(UNI_IE_QOS, (union uni_ieall *)&m->qos, cx);
1182	ret |= uni_check_ie(UNI_IE_EETD, (union uni_ieall *)&m->eetd, cx);
1183	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
1184	if(!(!cx->pnni))
1185		ret |= IE_ISPRESENT(m->scompl);
1186	else
1187		ret |= uni_check_ie(UNI_IE_SCOMPL, (union uni_ieall *)&m->scompl, cx);
1188	for(i = 0; i < UNI_NUM_IE_TNS ; i++) {
1189		ret |= uni_check_ie(UNI_IE_TNS, (union uni_ieall *)&m->tns[i], cx);
1190	}
1191	ret |= uni_check_ie(UNI_IE_EPREF, (union uni_ieall *)&m->epref, cx);
1192	ret |= uni_check_ie(UNI_IE_ATRAFFIC, (union uni_ieall *)&m->atraffic, cx);
1193	ret |= uni_check_ie(UNI_IE_MINTRAFFIC, (union uni_ieall *)&m->mintraffic, cx);
1194	if(!(!cx->pnni))
1195		ret |= IE_ISPRESENT(m->uu);
1196	else
1197		ret |= uni_check_ie(UNI_IE_UU, (union uni_ieall *)&m->uu, cx);
1198	for(i = 0; i < UNI_NUM_IE_GIT ; i++) {
1199		ret |= uni_check_ie(UNI_IE_GIT, (union uni_ieall *)&m->git[i], cx);
1200	}
1201	if(!(!cx->pnni))
1202		ret |= IE_ISPRESENT(m->lij_callid);
1203	else
1204		ret |= uni_check_ie(UNI_IE_LIJ_CALLID, (union uni_ieall *)&m->lij_callid, cx);
1205	if(!(!cx->pnni))
1206		ret |= IE_ISPRESENT(m->lij_param);
1207	else
1208		ret |= uni_check_ie(UNI_IE_LIJ_PARAM, (union uni_ieall *)&m->lij_param, cx);
1209	if(!(!cx->pnni))
1210		ret |= IE_ISPRESENT(m->lij_seqno);
1211	else
1212		ret |= uni_check_ie(UNI_IE_LIJ_SEQNO, (union uni_ieall *)&m->lij_seqno, cx);
1213	ret |= uni_check_ie(UNI_IE_EXQOS, (union uni_ieall *)&m->exqos, cx);
1214	ret |= uni_check_ie(UNI_IE_ABRSETUP, (union uni_ieall *)&m->abrsetup, cx);
1215	ret |= uni_check_ie(UNI_IE_ABRADD, (union uni_ieall *)&m->abradd, cx);
1216	ret |= uni_check_ie(UNI_IE_CSCOPE, (union uni_ieall *)&m->cscope, cx);
1217	if(!(cx->pnni))
1218		ret |= IE_ISPRESENT(m->calling_soft);
1219	else
1220		ret |= uni_check_ie(UNI_IE_CALLING_SOFT, (union uni_ieall *)&m->calling_soft, cx);
1221	if(!(cx->pnni))
1222		ret |= IE_ISPRESENT(m->called_soft);
1223	else
1224		ret |= uni_check_ie(UNI_IE_CALLED_SOFT, (union uni_ieall *)&m->called_soft, cx);
1225	if(!(cx->pnni))
1226		ret |= IE_ISPRESENT(m->dtl_repeat);
1227	else
1228		ret |= uni_check_ie(UNI_IE_REPEAT, (union uni_ieall *)&m->dtl_repeat, cx);
1229	for(i = 0; i < UNI_NUM_IE_DTL ; i++) {
1230		if(!(cx->pnni))
1231			ret |= IE_ISPRESENT(m->dtl[i]);
1232		else
1233			ret |= uni_check_ie(UNI_IE_DTL, (union uni_ieall *)&m->dtl[i], cx);
1234	}
1235	if(!(!cx->pnni))
1236		ret |= IE_ISPRESENT(m->report);
1237	else
1238		ret |= uni_check_ie(UNI_IE_REPORT, (union uni_ieall *)&m->report, cx);
1239	ret |= uni_check_ie(UNI_IE_MDCR, (union uni_ieall *)&m->mdcr, cx);
1240	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
1241
1242	return ret;
1243}
1244
1245static int
1246encode_setup(struct uni_msg *msg, struct uni_setup *p, struct unicx *cx)
1247{
1248	u_int mlen;
1249	u_int i;
1250
1251	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_SETUP, cx, &mlen))
1252		return (-2);
1253
1254	if((p->aal.h.present & UNI_IE_PRESENT) &&
1255	   uni_encode_ie(UNI_IE_AAL, msg, (union uni_ieall *)&p->aal, cx))
1256		return (UNI_IE_AAL);
1257	if((p->traffic.h.present & UNI_IE_PRESENT) &&
1258	   uni_encode_ie(UNI_IE_TRAFFIC, msg, (union uni_ieall *)&p->traffic, cx))
1259		return (UNI_IE_TRAFFIC);
1260	if((p->bearer.h.present & UNI_IE_PRESENT) &&
1261	   uni_encode_ie(UNI_IE_BEARER, msg, (union uni_ieall *)&p->bearer, cx))
1262		return (UNI_IE_BEARER);
1263	if((p->bhli.h.present & UNI_IE_PRESENT) &&
1264	   uni_encode_ie(UNI_IE_BHLI, msg, (union uni_ieall *)&p->bhli, cx))
1265		return (UNI_IE_BHLI);
1266	if((p->blli_repeat.h.present & UNI_IE_PRESENT) &&
1267	   uni_encode_ie(UNI_IE_BLLI, msg, (union uni_ieall *)&p->blli_repeat, cx))
1268		return (0x10000000 + UNI_IE_BLLI);
1269	for(i = 0; i < UNI_NUM_IE_BLLI; i++)
1270		if((p->blli[i].h.present & UNI_IE_PRESENT) &&
1271		   uni_encode_ie(UNI_IE_BLLI, msg, (union uni_ieall *)&p->blli[i], cx))
1272		return ((i << 16) + UNI_IE_BLLI);
1273	if((p->called.h.present & UNI_IE_PRESENT) &&
1274	   uni_encode_ie(UNI_IE_CALLED, msg, (union uni_ieall *)&p->called, cx))
1275		return (UNI_IE_CALLED);
1276	for(i = 0; i < UNI_NUM_IE_CALLEDSUB; i++)
1277		if((p->calledsub[i].h.present & UNI_IE_PRESENT) &&
1278		   uni_encode_ie(UNI_IE_CALLEDSUB, msg, (union uni_ieall *)&p->calledsub[i], cx))
1279		return ((i << 16) + UNI_IE_CALLEDSUB);
1280	if((p->calling.h.present & UNI_IE_PRESENT) &&
1281	   uni_encode_ie(UNI_IE_CALLING, msg, (union uni_ieall *)&p->calling, cx))
1282		return (UNI_IE_CALLING);
1283	for(i = 0; i < UNI_NUM_IE_CALLINGSUB; i++)
1284		if((p->callingsub[i].h.present & UNI_IE_PRESENT) &&
1285		   uni_encode_ie(UNI_IE_CALLINGSUB, msg, (union uni_ieall *)&p->callingsub[i], cx))
1286		return ((i << 16) + UNI_IE_CALLINGSUB);
1287	if((p->connid.h.present & UNI_IE_PRESENT) &&
1288	   uni_encode_ie(UNI_IE_CONNID, msg, (union uni_ieall *)&p->connid, cx))
1289		return (UNI_IE_CONNID);
1290	if((p->qos.h.present & UNI_IE_PRESENT) &&
1291	   uni_encode_ie(UNI_IE_QOS, msg, (union uni_ieall *)&p->qos, cx))
1292		return (UNI_IE_QOS);
1293	if((p->eetd.h.present & UNI_IE_PRESENT) &&
1294	   uni_encode_ie(UNI_IE_EETD, msg, (union uni_ieall *)&p->eetd, cx))
1295		return (UNI_IE_EETD);
1296	if((p->notify.h.present & UNI_IE_PRESENT) &&
1297	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
1298		return (UNI_IE_NOTIFY);
1299	if((p->scompl.h.present & UNI_IE_PRESENT) &&
1300	   uni_encode_ie(UNI_IE_SCOMPL, msg, (union uni_ieall *)&p->scompl, cx))
1301		return (UNI_IE_SCOMPL);
1302	for(i = 0; i < UNI_NUM_IE_TNS; i++)
1303		if((p->tns[i].h.present & UNI_IE_PRESENT) &&
1304		   uni_encode_ie(UNI_IE_TNS, msg, (union uni_ieall *)&p->tns[i], cx))
1305		return ((i << 16) + UNI_IE_TNS);
1306	if((p->epref.h.present & UNI_IE_PRESENT) &&
1307	   uni_encode_ie(UNI_IE_EPREF, msg, (union uni_ieall *)&p->epref, cx))
1308		return (UNI_IE_EPREF);
1309	if((p->atraffic.h.present & UNI_IE_PRESENT) &&
1310	   uni_encode_ie(UNI_IE_ATRAFFIC, msg, (union uni_ieall *)&p->atraffic, cx))
1311		return (UNI_IE_ATRAFFIC);
1312	if((p->mintraffic.h.present & UNI_IE_PRESENT) &&
1313	   uni_encode_ie(UNI_IE_MINTRAFFIC, msg, (union uni_ieall *)&p->mintraffic, cx))
1314		return (UNI_IE_MINTRAFFIC);
1315	if((p->uu.h.present & UNI_IE_PRESENT) &&
1316	   uni_encode_ie(UNI_IE_UU, msg, (union uni_ieall *)&p->uu, cx))
1317		return (UNI_IE_UU);
1318	for(i = 0; i < UNI_NUM_IE_GIT; i++)
1319		if((p->git[i].h.present & UNI_IE_PRESENT) &&
1320		   uni_encode_ie(UNI_IE_GIT, msg, (union uni_ieall *)&p->git[i], cx))
1321		return ((i << 16) + UNI_IE_GIT);
1322	if((p->lij_callid.h.present & UNI_IE_PRESENT) &&
1323	   uni_encode_ie(UNI_IE_LIJ_CALLID, msg, (union uni_ieall *)&p->lij_callid, cx))
1324		return (UNI_IE_LIJ_CALLID);
1325	if((p->lij_param.h.present & UNI_IE_PRESENT) &&
1326	   uni_encode_ie(UNI_IE_LIJ_PARAM, msg, (union uni_ieall *)&p->lij_param, cx))
1327		return (UNI_IE_LIJ_PARAM);
1328	if((p->lij_seqno.h.present & UNI_IE_PRESENT) &&
1329	   uni_encode_ie(UNI_IE_LIJ_SEQNO, msg, (union uni_ieall *)&p->lij_seqno, cx))
1330		return (UNI_IE_LIJ_SEQNO);
1331	if((p->exqos.h.present & UNI_IE_PRESENT) &&
1332	   uni_encode_ie(UNI_IE_EXQOS, msg, (union uni_ieall *)&p->exqos, cx))
1333		return (UNI_IE_EXQOS);
1334	if((p->abrsetup.h.present & UNI_IE_PRESENT) &&
1335	   uni_encode_ie(UNI_IE_ABRSETUP, msg, (union uni_ieall *)&p->abrsetup, cx))
1336		return (UNI_IE_ABRSETUP);
1337	if((p->abradd.h.present & UNI_IE_PRESENT) &&
1338	   uni_encode_ie(UNI_IE_ABRADD, msg, (union uni_ieall *)&p->abradd, cx))
1339		return (UNI_IE_ABRADD);
1340	if((p->cscope.h.present & UNI_IE_PRESENT) &&
1341	   uni_encode_ie(UNI_IE_CSCOPE, msg, (union uni_ieall *)&p->cscope, cx))
1342		return (UNI_IE_CSCOPE);
1343	if((p->calling_soft.h.present & UNI_IE_PRESENT) &&
1344	   uni_encode_ie(UNI_IE_CALLING_SOFT, msg, (union uni_ieall *)&p->calling_soft, cx))
1345		return (UNI_IE_CALLING_SOFT);
1346	if((p->called_soft.h.present & UNI_IE_PRESENT) &&
1347	   uni_encode_ie(UNI_IE_CALLED_SOFT, msg, (union uni_ieall *)&p->called_soft, cx))
1348		return (UNI_IE_CALLED_SOFT);
1349	if((p->dtl_repeat.h.present & UNI_IE_PRESENT) &&
1350	   uni_encode_ie(UNI_IE_DTL, msg, (union uni_ieall *)&p->dtl_repeat, cx))
1351		return (0x10000000 + UNI_IE_DTL);
1352	for(i = 0; i < UNI_NUM_IE_DTL; i++)
1353		if((p->dtl[i].h.present & UNI_IE_PRESENT) &&
1354		   uni_encode_ie(UNI_IE_DTL, msg, (union uni_ieall *)&p->dtl[i], cx))
1355		return ((i << 16) + UNI_IE_DTL);
1356	if((p->report.h.present & UNI_IE_PRESENT) &&
1357	   uni_encode_ie(UNI_IE_REPORT, msg, (union uni_ieall *)&p->report, cx))
1358		return (UNI_IE_REPORT);
1359	if((p->mdcr.h.present & UNI_IE_PRESENT) &&
1360	   uni_encode_ie(UNI_IE_MDCR, msg, (union uni_ieall *)&p->mdcr, cx))
1361		return (UNI_IE_MDCR);
1362	if((p->unrec.h.present & UNI_IE_PRESENT) &&
1363	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
1364		return (UNI_IE_UNREC);
1365
1366	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
1367	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
1368
1369	return (0);
1370}
1371
1372static int
1373decode_setup(struct uni_setup *out, struct uni_msg *msg,
1374    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
1375    struct unicx *cx)
1376{
1377	u_int i;
1378
1379	switch (ie) {
1380
1381	  case UNI_IE_AAL:
1382		out->aal.h = *hdr;
1383		if (hdr->present & UNI_IE_ERROR)
1384			return (DEC_ERR);
1385		if(uni_decode_ie_body(UNI_IE_AAL, (union uni_ieall *)&out->aal, msg, ielen, cx))
1386			return (DEC_ERR);
1387		break;
1388
1389	  case UNI_IE_TRAFFIC:
1390		out->traffic.h = *hdr;
1391		if (hdr->present & UNI_IE_ERROR)
1392			return (DEC_ERR);
1393		if(uni_decode_ie_body(UNI_IE_TRAFFIC, (union uni_ieall *)&out->traffic, msg, ielen, cx))
1394			return (DEC_ERR);
1395		break;
1396
1397	  case UNI_IE_BEARER:
1398		out->bearer.h = *hdr;
1399		if (hdr->present & UNI_IE_ERROR)
1400			return (DEC_ERR);
1401		if(uni_decode_ie_body(UNI_IE_BEARER, (union uni_ieall *)&out->bearer, msg, ielen, cx))
1402			return (DEC_ERR);
1403		break;
1404
1405	  case UNI_IE_BHLI:
1406		out->bhli.h = *hdr;
1407		if (hdr->present & UNI_IE_ERROR)
1408			return (DEC_ERR);
1409		if(uni_decode_ie_body(UNI_IE_BHLI, (union uni_ieall *)&out->bhli, msg, ielen, cx))
1410			return (DEC_ERR);
1411		break;
1412
1413	  case UNI_IE_BLLI:
1414		if (IE_ISPRESENT(cx->repeat))
1415			out->blli_repeat = cx->repeat;
1416		for(i = 0; i < UNI_NUM_IE_BLLI; i++)
1417			if (!IE_ISPRESENT(out->blli[i])) {
1418				out->blli[i].h = *hdr;
1419				if (hdr->present & UNI_IE_ERROR)
1420					return (DEC_ERR);
1421				if(uni_decode_ie_body(UNI_IE_BLLI, (union uni_ieall *)&out->blli[i], msg, ielen, cx))
1422					return (DEC_ERR);
1423				break;
1424			}
1425		break;
1426
1427	  case UNI_IE_CALLED:
1428		out->called.h = *hdr;
1429		if (hdr->present & UNI_IE_ERROR)
1430			return (DEC_ERR);
1431		if(uni_decode_ie_body(UNI_IE_CALLED, (union uni_ieall *)&out->called, msg, ielen, cx))
1432			return (DEC_ERR);
1433		break;
1434
1435	  case UNI_IE_CALLEDSUB:
1436		for(i = 0; i < UNI_NUM_IE_CALLEDSUB; i++)
1437			if (!IE_ISPRESENT(out->calledsub[i])) {
1438				out->calledsub[i].h = *hdr;
1439				if (hdr->present & UNI_IE_ERROR)
1440					return (DEC_ERR);
1441				if(uni_decode_ie_body(UNI_IE_CALLEDSUB, (union uni_ieall *)&out->calledsub[i], msg, ielen, cx))
1442					return (DEC_ERR);
1443				break;
1444			}
1445		break;
1446
1447	  case UNI_IE_CALLING:
1448		out->calling.h = *hdr;
1449		if (hdr->present & UNI_IE_ERROR)
1450			return (DEC_ERR);
1451		if(uni_decode_ie_body(UNI_IE_CALLING, (union uni_ieall *)&out->calling, msg, ielen, cx))
1452			return (DEC_ERR);
1453		break;
1454
1455	  case UNI_IE_CALLINGSUB:
1456		for(i = 0; i < UNI_NUM_IE_CALLINGSUB; i++)
1457			if (!IE_ISPRESENT(out->callingsub[i])) {
1458				out->callingsub[i].h = *hdr;
1459				if (hdr->present & UNI_IE_ERROR)
1460					return (DEC_ERR);
1461				if(uni_decode_ie_body(UNI_IE_CALLINGSUB, (union uni_ieall *)&out->callingsub[i], msg, ielen, cx))
1462					return (DEC_ERR);
1463				break;
1464			}
1465		break;
1466
1467	  case UNI_IE_CONNID:
1468		out->connid.h = *hdr;
1469		if (hdr->present & UNI_IE_ERROR)
1470			return (DEC_ERR);
1471		if(uni_decode_ie_body(UNI_IE_CONNID, (union uni_ieall *)&out->connid, msg, ielen, cx))
1472			return (DEC_ERR);
1473		break;
1474
1475	  case UNI_IE_QOS:
1476		out->qos.h = *hdr;
1477		if (hdr->present & UNI_IE_ERROR)
1478			return (DEC_ERR);
1479		if(uni_decode_ie_body(UNI_IE_QOS, (union uni_ieall *)&out->qos, msg, ielen, cx))
1480			return (DEC_ERR);
1481		break;
1482
1483	  case UNI_IE_EETD:
1484		out->eetd.h = *hdr;
1485		if (hdr->present & UNI_IE_ERROR)
1486			return (DEC_ERR);
1487		if(uni_decode_ie_body(UNI_IE_EETD, (union uni_ieall *)&out->eetd, msg, ielen, cx))
1488			return (DEC_ERR);
1489		break;
1490
1491	  case UNI_IE_NOTIFY:
1492		out->notify.h = *hdr;
1493		if (hdr->present & UNI_IE_ERROR)
1494			return (DEC_ERR);
1495		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
1496			return (DEC_ERR);
1497		break;
1498
1499	  case UNI_IE_SCOMPL:
1500		if (!(!cx->pnni))
1501			return (DEC_ILL);
1502		out->scompl.h = *hdr;
1503		if (hdr->present & UNI_IE_ERROR)
1504			return (DEC_ERR);
1505		if(uni_decode_ie_body(UNI_IE_SCOMPL, (union uni_ieall *)&out->scompl, msg, ielen, cx))
1506			return (DEC_ERR);
1507		break;
1508
1509	  case UNI_IE_TNS:
1510		for(i = 0; i < UNI_NUM_IE_TNS; i++)
1511			if (!IE_ISPRESENT(out->tns[i])) {
1512				out->tns[i].h = *hdr;
1513				if (hdr->present & UNI_IE_ERROR)
1514					return (DEC_ERR);
1515				if(uni_decode_ie_body(UNI_IE_TNS, (union uni_ieall *)&out->tns[i], msg, ielen, cx))
1516					return (DEC_ERR);
1517				break;
1518			}
1519		break;
1520
1521	  case UNI_IE_EPREF:
1522		out->epref.h = *hdr;
1523		if (hdr->present & UNI_IE_ERROR)
1524			return (DEC_ERR);
1525		if(uni_decode_ie_body(UNI_IE_EPREF, (union uni_ieall *)&out->epref, msg, ielen, cx))
1526			return (DEC_ERR);
1527		break;
1528
1529	  case UNI_IE_ATRAFFIC:
1530		out->atraffic.h = *hdr;
1531		if (hdr->present & UNI_IE_ERROR)
1532			return (DEC_ERR);
1533		if(uni_decode_ie_body(UNI_IE_ATRAFFIC, (union uni_ieall *)&out->atraffic, msg, ielen, cx))
1534			return (DEC_ERR);
1535		break;
1536
1537	  case UNI_IE_MINTRAFFIC:
1538		out->mintraffic.h = *hdr;
1539		if (hdr->present & UNI_IE_ERROR)
1540			return (DEC_ERR);
1541		if(uni_decode_ie_body(UNI_IE_MINTRAFFIC, (union uni_ieall *)&out->mintraffic, msg, ielen, cx))
1542			return (DEC_ERR);
1543		break;
1544
1545	  case UNI_IE_UU:
1546		if (!(!cx->pnni))
1547			return (DEC_ILL);
1548		out->uu.h = *hdr;
1549		if (hdr->present & UNI_IE_ERROR)
1550			return (DEC_ERR);
1551		if(uni_decode_ie_body(UNI_IE_UU, (union uni_ieall *)&out->uu, msg, ielen, cx))
1552			return (DEC_ERR);
1553		break;
1554
1555	  case UNI_IE_GIT:
1556		for(i = 0; i < UNI_NUM_IE_GIT; i++)
1557			if (!IE_ISPRESENT(out->git[i])) {
1558				out->git[i].h = *hdr;
1559				if (hdr->present & UNI_IE_ERROR)
1560					return (DEC_ERR);
1561				if(uni_decode_ie_body(UNI_IE_GIT, (union uni_ieall *)&out->git[i], msg, ielen, cx))
1562					return (DEC_ERR);
1563				break;
1564			}
1565		break;
1566
1567	  case UNI_IE_LIJ_CALLID:
1568		if (!(!cx->pnni))
1569			return (DEC_ILL);
1570		out->lij_callid.h = *hdr;
1571		if (hdr->present & UNI_IE_ERROR)
1572			return (DEC_ERR);
1573		if(uni_decode_ie_body(UNI_IE_LIJ_CALLID, (union uni_ieall *)&out->lij_callid, msg, ielen, cx))
1574			return (DEC_ERR);
1575		break;
1576
1577	  case UNI_IE_LIJ_PARAM:
1578		if (!(!cx->pnni))
1579			return (DEC_ILL);
1580		out->lij_param.h = *hdr;
1581		if (hdr->present & UNI_IE_ERROR)
1582			return (DEC_ERR);
1583		if(uni_decode_ie_body(UNI_IE_LIJ_PARAM, (union uni_ieall *)&out->lij_param, msg, ielen, cx))
1584			return (DEC_ERR);
1585		break;
1586
1587	  case UNI_IE_LIJ_SEQNO:
1588		if (!(!cx->pnni))
1589			return (DEC_ILL);
1590		out->lij_seqno.h = *hdr;
1591		if (hdr->present & UNI_IE_ERROR)
1592			return (DEC_ERR);
1593		if(uni_decode_ie_body(UNI_IE_LIJ_SEQNO, (union uni_ieall *)&out->lij_seqno, msg, ielen, cx))
1594			return (DEC_ERR);
1595		break;
1596
1597	  case UNI_IE_EXQOS:
1598		out->exqos.h = *hdr;
1599		if (hdr->present & UNI_IE_ERROR)
1600			return (DEC_ERR);
1601		if(uni_decode_ie_body(UNI_IE_EXQOS, (union uni_ieall *)&out->exqos, msg, ielen, cx))
1602			return (DEC_ERR);
1603		break;
1604
1605	  case UNI_IE_ABRSETUP:
1606		out->abrsetup.h = *hdr;
1607		if (hdr->present & UNI_IE_ERROR)
1608			return (DEC_ERR);
1609		if(uni_decode_ie_body(UNI_IE_ABRSETUP, (union uni_ieall *)&out->abrsetup, msg, ielen, cx))
1610			return (DEC_ERR);
1611		break;
1612
1613	  case UNI_IE_ABRADD:
1614		out->abradd.h = *hdr;
1615		if (hdr->present & UNI_IE_ERROR)
1616			return (DEC_ERR);
1617		if(uni_decode_ie_body(UNI_IE_ABRADD, (union uni_ieall *)&out->abradd, msg, ielen, cx))
1618			return (DEC_ERR);
1619		break;
1620
1621	  case UNI_IE_CSCOPE:
1622		out->cscope.h = *hdr;
1623		if (hdr->present & UNI_IE_ERROR)
1624			return (DEC_ERR);
1625		if(uni_decode_ie_body(UNI_IE_CSCOPE, (union uni_ieall *)&out->cscope, msg, ielen, cx))
1626			return (DEC_ERR);
1627		break;
1628
1629	  case UNI_IE_CALLING_SOFT:
1630		if (!(cx->pnni))
1631			return (DEC_ILL);
1632		out->calling_soft.h = *hdr;
1633		if (hdr->present & UNI_IE_ERROR)
1634			return (DEC_ERR);
1635		if(uni_decode_ie_body(UNI_IE_CALLING_SOFT, (union uni_ieall *)&out->calling_soft, msg, ielen, cx))
1636			return (DEC_ERR);
1637		break;
1638
1639	  case UNI_IE_CALLED_SOFT:
1640		if (!(cx->pnni))
1641			return (DEC_ILL);
1642		out->called_soft.h = *hdr;
1643		if (hdr->present & UNI_IE_ERROR)
1644			return (DEC_ERR);
1645		if(uni_decode_ie_body(UNI_IE_CALLED_SOFT, (union uni_ieall *)&out->called_soft, msg, ielen, cx))
1646			return (DEC_ERR);
1647		break;
1648
1649	  case UNI_IE_DTL:
1650		if (!(cx->pnni))
1651			return (DEC_ILL);
1652		if (IE_ISPRESENT(cx->repeat))
1653			out->dtl_repeat = cx->repeat;
1654		for(i = 0; i < UNI_NUM_IE_DTL; i++)
1655			if (!IE_ISPRESENT(out->dtl[i])) {
1656				out->dtl[i].h = *hdr;
1657				if (hdr->present & UNI_IE_ERROR)
1658					return (DEC_ERR);
1659				if(uni_decode_ie_body(UNI_IE_DTL, (union uni_ieall *)&out->dtl[i], msg, ielen, cx))
1660					return (DEC_ERR);
1661				break;
1662			}
1663		break;
1664
1665	  case UNI_IE_REPORT:
1666		if (!(!cx->pnni))
1667			return (DEC_ILL);
1668		out->report.h = *hdr;
1669		if (hdr->present & UNI_IE_ERROR)
1670			return (DEC_ERR);
1671		if(uni_decode_ie_body(UNI_IE_REPORT, (union uni_ieall *)&out->report, msg, ielen, cx))
1672			return (DEC_ERR);
1673		break;
1674
1675	  case UNI_IE_MDCR:
1676		out->mdcr.h = *hdr;
1677		if (hdr->present & UNI_IE_ERROR)
1678			return (DEC_ERR);
1679		if(uni_decode_ie_body(UNI_IE_MDCR, (union uni_ieall *)&out->mdcr, msg, ielen, cx))
1680			return (DEC_ERR);
1681		break;
1682
1683	  case UNI_IE_UNREC:
1684		out->unrec.h = *hdr;
1685		if (hdr->present & UNI_IE_ERROR)
1686			return (DEC_ERR);
1687		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
1688			return (DEC_ERR);
1689		break;
1690
1691	  case UNI_IE_REPEAT:
1692		cx->repeat.h = *hdr;
1693		if (hdr->present & UNI_IE_ERROR)
1694			return (DEC_ERR);
1695		if (uni_decode_ie_body(UNI_IE_REPEAT, (union uni_ieall *)&cx->repeat, msg, ielen, cx))
1696			return (DEC_ERR);
1697		break;
1698
1699	  default:
1700		return (DEC_ILL);
1701	}
1702	return (DEC_OK);
1703}
1704
1705static const struct msgdecl decl_setup = {
1706	0,
1707	"setup",
1708	(uni_msg_print_f)print_setup,
1709	(uni_msg_check_f)check_setup,
1710	(uni_msg_encode_f)encode_setup,
1711	(uni_msg_decode_f)decode_setup
1712};
1713
1714static void
1715print_status(struct uni_status *msg, struct unicx *cx)
1716{
1717	if(msg->callstate.h.present & UNI_IE_PRESENT)
1718		uni_print_ie_internal(UNI_IE_CALLSTATE, (union uni_ieall *)&msg->callstate, cx);
1719	if(msg->cause.h.present & UNI_IE_PRESENT)
1720		uni_print_ie_internal(UNI_IE_CAUSE, (union uni_ieall *)&msg->cause, cx);
1721	if(msg->epref.h.present & UNI_IE_PRESENT)
1722		uni_print_ie_internal(UNI_IE_EPREF, (union uni_ieall *)&msg->epref, cx);
1723	if(msg->epstate.h.present & UNI_IE_PRESENT)
1724		uni_print_ie_internal(UNI_IE_EPSTATE, (union uni_ieall *)&msg->epstate, cx);
1725	if(msg->unrec.h.present & UNI_IE_PRESENT)
1726		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
1727}
1728
1729static int
1730check_status(struct uni_status *m, struct unicx *cx)
1731{
1732	int ret = 0;
1733
1734	ret |= uni_check_ie(UNI_IE_CALLSTATE, (union uni_ieall *)&m->callstate, cx);
1735	ret |= uni_check_ie(UNI_IE_CAUSE, (union uni_ieall *)&m->cause, cx);
1736	ret |= uni_check_ie(UNI_IE_EPREF, (union uni_ieall *)&m->epref, cx);
1737	ret |= uni_check_ie(UNI_IE_EPSTATE, (union uni_ieall *)&m->epstate, cx);
1738	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
1739
1740	return ret;
1741}
1742
1743static int
1744encode_status(struct uni_msg *msg, struct uni_status *p, struct unicx *cx)
1745{
1746	u_int mlen;
1747
1748	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_STATUS, cx, &mlen))
1749		return (-2);
1750
1751	if((p->callstate.h.present & UNI_IE_PRESENT) &&
1752	   uni_encode_ie(UNI_IE_CALLSTATE, msg, (union uni_ieall *)&p->callstate, cx))
1753		return (UNI_IE_CALLSTATE);
1754	if((p->cause.h.present & UNI_IE_PRESENT) &&
1755	   uni_encode_ie(UNI_IE_CAUSE, msg, (union uni_ieall *)&p->cause, cx))
1756		return (UNI_IE_CAUSE);
1757	if((p->epref.h.present & UNI_IE_PRESENT) &&
1758	   uni_encode_ie(UNI_IE_EPREF, msg, (union uni_ieall *)&p->epref, cx))
1759		return (UNI_IE_EPREF);
1760	if((p->epstate.h.present & UNI_IE_PRESENT) &&
1761	   uni_encode_ie(UNI_IE_EPSTATE, msg, (union uni_ieall *)&p->epstate, cx))
1762		return (UNI_IE_EPSTATE);
1763	if((p->unrec.h.present & UNI_IE_PRESENT) &&
1764	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
1765		return (UNI_IE_UNREC);
1766
1767	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
1768	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
1769
1770	return (0);
1771}
1772
1773static int
1774decode_status(struct uni_status *out, struct uni_msg *msg,
1775    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
1776    struct unicx *cx)
1777{
1778	switch (ie) {
1779
1780	  case UNI_IE_CALLSTATE:
1781		out->callstate.h = *hdr;
1782		if (hdr->present & UNI_IE_ERROR)
1783			return (DEC_ERR);
1784		if(uni_decode_ie_body(UNI_IE_CALLSTATE, (union uni_ieall *)&out->callstate, msg, ielen, cx))
1785			return (DEC_ERR);
1786		break;
1787
1788	  case UNI_IE_CAUSE:
1789		out->cause.h = *hdr;
1790		if (hdr->present & UNI_IE_ERROR)
1791			return (DEC_ERR);
1792		if(uni_decode_ie_body(UNI_IE_CAUSE, (union uni_ieall *)&out->cause, msg, ielen, cx))
1793			return (DEC_ERR);
1794		break;
1795
1796	  case UNI_IE_EPREF:
1797		out->epref.h = *hdr;
1798		if (hdr->present & UNI_IE_ERROR)
1799			return (DEC_ERR);
1800		if(uni_decode_ie_body(UNI_IE_EPREF, (union uni_ieall *)&out->epref, msg, ielen, cx))
1801			return (DEC_ERR);
1802		break;
1803
1804	  case UNI_IE_EPSTATE:
1805		out->epstate.h = *hdr;
1806		if (hdr->present & UNI_IE_ERROR)
1807			return (DEC_ERR);
1808		if(uni_decode_ie_body(UNI_IE_EPSTATE, (union uni_ieall *)&out->epstate, msg, ielen, cx))
1809			return (DEC_ERR);
1810		break;
1811
1812	  case UNI_IE_UNREC:
1813		out->unrec.h = *hdr;
1814		if (hdr->present & UNI_IE_ERROR)
1815			return (DEC_ERR);
1816		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
1817			return (DEC_ERR);
1818		break;
1819
1820	  default:
1821		return (DEC_ILL);
1822	}
1823	return (DEC_OK);
1824}
1825
1826static const struct msgdecl decl_status = {
1827	0,
1828	"status",
1829	(uni_msg_print_f)print_status,
1830	(uni_msg_check_f)check_status,
1831	(uni_msg_encode_f)encode_status,
1832	(uni_msg_decode_f)decode_status
1833};
1834
1835static void
1836print_status_enq(struct uni_status_enq *msg, struct unicx *cx)
1837{
1838	if(msg->epref.h.present & UNI_IE_PRESENT)
1839		uni_print_ie_internal(UNI_IE_EPREF, (union uni_ieall *)&msg->epref, cx);
1840	if(msg->unrec.h.present & UNI_IE_PRESENT)
1841		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
1842}
1843
1844static int
1845check_status_enq(struct uni_status_enq *m, struct unicx *cx)
1846{
1847	int ret = 0;
1848
1849	ret |= uni_check_ie(UNI_IE_EPREF, (union uni_ieall *)&m->epref, cx);
1850	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
1851
1852	return ret;
1853}
1854
1855static int
1856encode_status_enq(struct uni_msg *msg, struct uni_status_enq *p, struct unicx *cx)
1857{
1858	u_int mlen;
1859
1860	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_STATUS_ENQ, cx, &mlen))
1861		return (-2);
1862
1863	if((p->epref.h.present & UNI_IE_PRESENT) &&
1864	   uni_encode_ie(UNI_IE_EPREF, msg, (union uni_ieall *)&p->epref, cx))
1865		return (UNI_IE_EPREF);
1866	if((p->unrec.h.present & UNI_IE_PRESENT) &&
1867	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
1868		return (UNI_IE_UNREC);
1869
1870	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
1871	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
1872
1873	return (0);
1874}
1875
1876static int
1877decode_status_enq(struct uni_status_enq *out, struct uni_msg *msg,
1878    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
1879    struct unicx *cx)
1880{
1881	switch (ie) {
1882
1883	  case UNI_IE_EPREF:
1884		out->epref.h = *hdr;
1885		if (hdr->present & UNI_IE_ERROR)
1886			return (DEC_ERR);
1887		if(uni_decode_ie_body(UNI_IE_EPREF, (union uni_ieall *)&out->epref, msg, ielen, cx))
1888			return (DEC_ERR);
1889		break;
1890
1891	  case UNI_IE_UNREC:
1892		out->unrec.h = *hdr;
1893		if (hdr->present & UNI_IE_ERROR)
1894			return (DEC_ERR);
1895		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
1896			return (DEC_ERR);
1897		break;
1898
1899	  default:
1900		return (DEC_ILL);
1901	}
1902	return (DEC_OK);
1903}
1904
1905static const struct msgdecl decl_status_enq = {
1906	0,
1907	"status_enq",
1908	(uni_msg_print_f)print_status_enq,
1909	(uni_msg_check_f)check_status_enq,
1910	(uni_msg_encode_f)encode_status_enq,
1911	(uni_msg_decode_f)decode_status_enq
1912};
1913
1914static void
1915print_notify(struct uni_notify *msg, struct unicx *cx)
1916{
1917	if(msg->notify.h.present & UNI_IE_PRESENT)
1918		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
1919	if(msg->epref.h.present & UNI_IE_PRESENT)
1920		uni_print_ie_internal(UNI_IE_EPREF, (union uni_ieall *)&msg->epref, cx);
1921	if(msg->unrec.h.present & UNI_IE_PRESENT)
1922		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
1923}
1924
1925static int
1926check_notify(struct uni_notify *m, struct unicx *cx)
1927{
1928	int ret = 0;
1929
1930	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
1931	ret |= uni_check_ie(UNI_IE_EPREF, (union uni_ieall *)&m->epref, cx);
1932	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
1933
1934	return ret;
1935}
1936
1937static int
1938encode_notify(struct uni_msg *msg, struct uni_notify *p, struct unicx *cx)
1939{
1940	u_int mlen;
1941
1942	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_NOTIFY, cx, &mlen))
1943		return (-2);
1944
1945	if((p->notify.h.present & UNI_IE_PRESENT) &&
1946	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
1947		return (UNI_IE_NOTIFY);
1948	if((p->epref.h.present & UNI_IE_PRESENT) &&
1949	   uni_encode_ie(UNI_IE_EPREF, msg, (union uni_ieall *)&p->epref, cx))
1950		return (UNI_IE_EPREF);
1951	if((p->unrec.h.present & UNI_IE_PRESENT) &&
1952	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
1953		return (UNI_IE_UNREC);
1954
1955	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
1956	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
1957
1958	return (0);
1959}
1960
1961static int
1962decode_notify(struct uni_notify *out, struct uni_msg *msg,
1963    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
1964    struct unicx *cx)
1965{
1966	switch (ie) {
1967
1968	  case UNI_IE_NOTIFY:
1969		out->notify.h = *hdr;
1970		if (hdr->present & UNI_IE_ERROR)
1971			return (DEC_ERR);
1972		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
1973			return (DEC_ERR);
1974		break;
1975
1976	  case UNI_IE_EPREF:
1977		out->epref.h = *hdr;
1978		if (hdr->present & UNI_IE_ERROR)
1979			return (DEC_ERR);
1980		if(uni_decode_ie_body(UNI_IE_EPREF, (union uni_ieall *)&out->epref, msg, ielen, cx))
1981			return (DEC_ERR);
1982		break;
1983
1984	  case UNI_IE_UNREC:
1985		out->unrec.h = *hdr;
1986		if (hdr->present & UNI_IE_ERROR)
1987			return (DEC_ERR);
1988		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
1989			return (DEC_ERR);
1990		break;
1991
1992	  default:
1993		return (DEC_ILL);
1994	}
1995	return (DEC_OK);
1996}
1997
1998static const struct msgdecl decl_notify = {
1999	0,
2000	"notify",
2001	(uni_msg_print_f)print_notify,
2002	(uni_msg_check_f)check_notify,
2003	(uni_msg_encode_f)encode_notify,
2004	(uni_msg_decode_f)decode_notify
2005};
2006
2007static void
2008print_restart(struct uni_restart *msg, struct unicx *cx)
2009{
2010	if(msg->connid.h.present & UNI_IE_PRESENT)
2011		uni_print_ie_internal(UNI_IE_CONNID, (union uni_ieall *)&msg->connid, cx);
2012	if(msg->restart.h.present & UNI_IE_PRESENT)
2013		uni_print_ie_internal(UNI_IE_RESTART, (union uni_ieall *)&msg->restart, cx);
2014	if(msg->unrec.h.present & UNI_IE_PRESENT)
2015		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
2016}
2017
2018static int
2019check_restart(struct uni_restart *m, struct unicx *cx)
2020{
2021	int ret = 0;
2022
2023	ret |= uni_check_ie(UNI_IE_CONNID, (union uni_ieall *)&m->connid, cx);
2024	ret |= uni_check_ie(UNI_IE_RESTART, (union uni_ieall *)&m->restart, cx);
2025	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
2026
2027	return ret;
2028}
2029
2030static int
2031encode_restart(struct uni_msg *msg, struct uni_restart *p, struct unicx *cx)
2032{
2033	u_int mlen;
2034
2035	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_RESTART, cx, &mlen))
2036		return (-2);
2037
2038	if((p->connid.h.present & UNI_IE_PRESENT) &&
2039	   uni_encode_ie(UNI_IE_CONNID, msg, (union uni_ieall *)&p->connid, cx))
2040		return (UNI_IE_CONNID);
2041	if((p->restart.h.present & UNI_IE_PRESENT) &&
2042	   uni_encode_ie(UNI_IE_RESTART, msg, (union uni_ieall *)&p->restart, cx))
2043		return (UNI_IE_RESTART);
2044	if((p->unrec.h.present & UNI_IE_PRESENT) &&
2045	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
2046		return (UNI_IE_UNREC);
2047
2048	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
2049	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
2050
2051	return (0);
2052}
2053
2054static int
2055decode_restart(struct uni_restart *out, struct uni_msg *msg,
2056    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
2057    struct unicx *cx)
2058{
2059	switch (ie) {
2060
2061	  case UNI_IE_CONNID:
2062		out->connid.h = *hdr;
2063		if (hdr->present & UNI_IE_ERROR)
2064			return (DEC_ERR);
2065		if(uni_decode_ie_body(UNI_IE_CONNID, (union uni_ieall *)&out->connid, msg, ielen, cx))
2066			return (DEC_ERR);
2067		break;
2068
2069	  case UNI_IE_RESTART:
2070		out->restart.h = *hdr;
2071		if (hdr->present & UNI_IE_ERROR)
2072			return (DEC_ERR);
2073		if(uni_decode_ie_body(UNI_IE_RESTART, (union uni_ieall *)&out->restart, msg, ielen, cx))
2074			return (DEC_ERR);
2075		break;
2076
2077	  case UNI_IE_UNREC:
2078		out->unrec.h = *hdr;
2079		if (hdr->present & UNI_IE_ERROR)
2080			return (DEC_ERR);
2081		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
2082			return (DEC_ERR);
2083		break;
2084
2085	  default:
2086		return (DEC_ILL);
2087	}
2088	return (DEC_OK);
2089}
2090
2091static const struct msgdecl decl_restart = {
2092	0,
2093	"restart",
2094	(uni_msg_print_f)print_restart,
2095	(uni_msg_check_f)check_restart,
2096	(uni_msg_encode_f)encode_restart,
2097	(uni_msg_decode_f)decode_restart
2098};
2099
2100static void
2101print_restart_ack(struct uni_restart_ack *msg, struct unicx *cx)
2102{
2103	if(msg->connid.h.present & UNI_IE_PRESENT)
2104		uni_print_ie_internal(UNI_IE_CONNID, (union uni_ieall *)&msg->connid, cx);
2105	if(msg->restart.h.present & UNI_IE_PRESENT)
2106		uni_print_ie_internal(UNI_IE_RESTART, (union uni_ieall *)&msg->restart, cx);
2107	if(msg->unrec.h.present & UNI_IE_PRESENT)
2108		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
2109}
2110
2111static int
2112check_restart_ack(struct uni_restart_ack *m, struct unicx *cx)
2113{
2114	int ret = 0;
2115
2116	ret |= uni_check_ie(UNI_IE_CONNID, (union uni_ieall *)&m->connid, cx);
2117	ret |= uni_check_ie(UNI_IE_RESTART, (union uni_ieall *)&m->restart, cx);
2118	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
2119
2120	return ret;
2121}
2122
2123static int
2124encode_restart_ack(struct uni_msg *msg, struct uni_restart_ack *p, struct unicx *cx)
2125{
2126	u_int mlen;
2127
2128	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_RESTART_ACK, cx, &mlen))
2129		return (-2);
2130
2131	if((p->connid.h.present & UNI_IE_PRESENT) &&
2132	   uni_encode_ie(UNI_IE_CONNID, msg, (union uni_ieall *)&p->connid, cx))
2133		return (UNI_IE_CONNID);
2134	if((p->restart.h.present & UNI_IE_PRESENT) &&
2135	   uni_encode_ie(UNI_IE_RESTART, msg, (union uni_ieall *)&p->restart, cx))
2136		return (UNI_IE_RESTART);
2137	if((p->unrec.h.present & UNI_IE_PRESENT) &&
2138	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
2139		return (UNI_IE_UNREC);
2140
2141	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
2142	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
2143
2144	return (0);
2145}
2146
2147static int
2148decode_restart_ack(struct uni_restart_ack *out, struct uni_msg *msg,
2149    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
2150    struct unicx *cx)
2151{
2152	switch (ie) {
2153
2154	  case UNI_IE_CONNID:
2155		out->connid.h = *hdr;
2156		if (hdr->present & UNI_IE_ERROR)
2157			return (DEC_ERR);
2158		if(uni_decode_ie_body(UNI_IE_CONNID, (union uni_ieall *)&out->connid, msg, ielen, cx))
2159			return (DEC_ERR);
2160		break;
2161
2162	  case UNI_IE_RESTART:
2163		out->restart.h = *hdr;
2164		if (hdr->present & UNI_IE_ERROR)
2165			return (DEC_ERR);
2166		if(uni_decode_ie_body(UNI_IE_RESTART, (union uni_ieall *)&out->restart, msg, ielen, cx))
2167			return (DEC_ERR);
2168		break;
2169
2170	  case UNI_IE_UNREC:
2171		out->unrec.h = *hdr;
2172		if (hdr->present & UNI_IE_ERROR)
2173			return (DEC_ERR);
2174		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
2175			return (DEC_ERR);
2176		break;
2177
2178	  default:
2179		return (DEC_ILL);
2180	}
2181	return (DEC_OK);
2182}
2183
2184static const struct msgdecl decl_restart_ack = {
2185	0,
2186	"restart_ack",
2187	(uni_msg_print_f)print_restart_ack,
2188	(uni_msg_check_f)check_restart_ack,
2189	(uni_msg_encode_f)encode_restart_ack,
2190	(uni_msg_decode_f)decode_restart_ack
2191};
2192
2193static void
2194print_add_party(struct uni_add_party *msg, struct unicx *cx)
2195{
2196	u_int i;
2197
2198	if(msg->aal.h.present & UNI_IE_PRESENT)
2199		uni_print_ie_internal(UNI_IE_AAL, (union uni_ieall *)&msg->aal, cx);
2200	if(msg->bhli.h.present & UNI_IE_PRESENT)
2201		uni_print_ie_internal(UNI_IE_BHLI, (union uni_ieall *)&msg->bhli, cx);
2202	if(msg->blli.h.present & UNI_IE_PRESENT)
2203		uni_print_ie_internal(UNI_IE_BLLI, (union uni_ieall *)&msg->blli, cx);
2204	if(msg->called.h.present & UNI_IE_PRESENT)
2205		uni_print_ie_internal(UNI_IE_CALLED, (union uni_ieall *)&msg->called, cx);
2206	for(i = 0; i < UNI_NUM_IE_CALLEDSUB; i++)
2207		if(msg->calledsub[i].h.present & UNI_IE_PRESENT)
2208			uni_print_ie_internal(UNI_IE_CALLEDSUB, (union uni_ieall *)&msg->calledsub[i], cx);
2209	if(msg->calling.h.present & UNI_IE_PRESENT)
2210		uni_print_ie_internal(UNI_IE_CALLING, (union uni_ieall *)&msg->calling, cx);
2211	for(i = 0; i < UNI_NUM_IE_CALLINGSUB; i++)
2212		if(msg->callingsub[i].h.present & UNI_IE_PRESENT)
2213			uni_print_ie_internal(UNI_IE_CALLINGSUB, (union uni_ieall *)&msg->callingsub[i], cx);
2214	if(msg->scompl.h.present & UNI_IE_PRESENT)
2215		uni_print_ie_internal(UNI_IE_SCOMPL, (union uni_ieall *)&msg->scompl, cx);
2216	for(i = 0; i < UNI_NUM_IE_TNS; i++)
2217		if(msg->tns[i].h.present & UNI_IE_PRESENT)
2218			uni_print_ie_internal(UNI_IE_TNS, (union uni_ieall *)&msg->tns[i], cx);
2219	if(msg->epref.h.present & UNI_IE_PRESENT)
2220		uni_print_ie_internal(UNI_IE_EPREF, (union uni_ieall *)&msg->epref, cx);
2221	if(msg->notify.h.present & UNI_IE_PRESENT)
2222		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
2223	if(msg->eetd.h.present & UNI_IE_PRESENT)
2224		uni_print_ie_internal(UNI_IE_EETD, (union uni_ieall *)&msg->eetd, cx);
2225	if(msg->uu.h.present & UNI_IE_PRESENT)
2226		uni_print_ie_internal(UNI_IE_UU, (union uni_ieall *)&msg->uu, cx);
2227	for(i = 0; i < UNI_NUM_IE_GIT; i++)
2228		if(msg->git[i].h.present & UNI_IE_PRESENT)
2229			uni_print_ie_internal(UNI_IE_GIT, (union uni_ieall *)&msg->git[i], cx);
2230	if(msg->lij_seqno.h.present & UNI_IE_PRESENT)
2231		uni_print_ie_internal(UNI_IE_LIJ_SEQNO, (union uni_ieall *)&msg->lij_seqno, cx);
2232	if(msg->calling_soft.h.present & UNI_IE_PRESENT)
2233		uni_print_ie_internal(UNI_IE_CALLING_SOFT, (union uni_ieall *)&msg->calling_soft, cx);
2234	if(msg->called_soft.h.present & UNI_IE_PRESENT)
2235		uni_print_ie_internal(UNI_IE_CALLED_SOFT, (union uni_ieall *)&msg->called_soft, cx);
2236	if(msg->dtl_repeat.h.present & UNI_IE_PRESENT)
2237		uni_print_ie_internal(UNI_IE_REPEAT, (union uni_ieall *)&msg->dtl_repeat, cx);
2238	for(i = 0; i < UNI_NUM_IE_DTL; i++)
2239		if(msg->dtl[i].h.present & UNI_IE_PRESENT)
2240			uni_print_ie_internal(UNI_IE_DTL, (union uni_ieall *)&msg->dtl[i], cx);
2241	if(msg->unrec.h.present & UNI_IE_PRESENT)
2242		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
2243}
2244
2245static int
2246check_add_party(struct uni_add_party *m, struct unicx *cx)
2247{
2248	int ret = 0;
2249	u_int i;
2250
2251	ret |= uni_check_ie(UNI_IE_AAL, (union uni_ieall *)&m->aal, cx);
2252	ret |= uni_check_ie(UNI_IE_BHLI, (union uni_ieall *)&m->bhli, cx);
2253	ret |= uni_check_ie(UNI_IE_BLLI, (union uni_ieall *)&m->blli, cx);
2254	ret |= uni_check_ie(UNI_IE_CALLED, (union uni_ieall *)&m->called, cx);
2255	for(i = 0; i < UNI_NUM_IE_CALLEDSUB ; i++) {
2256		ret |= uni_check_ie(UNI_IE_CALLEDSUB, (union uni_ieall *)&m->calledsub[i], cx);
2257	}
2258	ret |= uni_check_ie(UNI_IE_CALLING, (union uni_ieall *)&m->calling, cx);
2259	for(i = 0; i < UNI_NUM_IE_CALLINGSUB ; i++) {
2260		ret |= uni_check_ie(UNI_IE_CALLINGSUB, (union uni_ieall *)&m->callingsub[i], cx);
2261	}
2262	if(!(!cx->pnni))
2263		ret |= IE_ISPRESENT(m->scompl);
2264	else
2265		ret |= uni_check_ie(UNI_IE_SCOMPL, (union uni_ieall *)&m->scompl, cx);
2266	for(i = 0; i < UNI_NUM_IE_TNS ; i++) {
2267		ret |= uni_check_ie(UNI_IE_TNS, (union uni_ieall *)&m->tns[i], cx);
2268	}
2269	ret |= uni_check_ie(UNI_IE_EPREF, (union uni_ieall *)&m->epref, cx);
2270	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
2271	ret |= uni_check_ie(UNI_IE_EETD, (union uni_ieall *)&m->eetd, cx);
2272	if(!(!cx->pnni))
2273		ret |= IE_ISPRESENT(m->uu);
2274	else
2275		ret |= uni_check_ie(UNI_IE_UU, (union uni_ieall *)&m->uu, cx);
2276	for(i = 0; i < UNI_NUM_IE_GIT ; i++) {
2277		ret |= uni_check_ie(UNI_IE_GIT, (union uni_ieall *)&m->git[i], cx);
2278	}
2279	if(!(!cx->pnni))
2280		ret |= IE_ISPRESENT(m->lij_seqno);
2281	else
2282		ret |= uni_check_ie(UNI_IE_LIJ_SEQNO, (union uni_ieall *)&m->lij_seqno, cx);
2283	if(!(cx->pnni))
2284		ret |= IE_ISPRESENT(m->calling_soft);
2285	else
2286		ret |= uni_check_ie(UNI_IE_CALLING_SOFT, (union uni_ieall *)&m->calling_soft, cx);
2287	if(!(cx->pnni))
2288		ret |= IE_ISPRESENT(m->called_soft);
2289	else
2290		ret |= uni_check_ie(UNI_IE_CALLED_SOFT, (union uni_ieall *)&m->called_soft, cx);
2291	if(!(cx->pnni))
2292		ret |= IE_ISPRESENT(m->dtl_repeat);
2293	else
2294		ret |= uni_check_ie(UNI_IE_REPEAT, (union uni_ieall *)&m->dtl_repeat, cx);
2295	for(i = 0; i < UNI_NUM_IE_DTL ; i++) {
2296		if(!(cx->pnni))
2297			ret |= IE_ISPRESENT(m->dtl[i]);
2298		else
2299			ret |= uni_check_ie(UNI_IE_DTL, (union uni_ieall *)&m->dtl[i], cx);
2300	}
2301	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
2302
2303	return ret;
2304}
2305
2306static int
2307encode_add_party(struct uni_msg *msg, struct uni_add_party *p, struct unicx *cx)
2308{
2309	u_int mlen;
2310	u_int i;
2311
2312	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_ADD_PARTY, cx, &mlen))
2313		return (-2);
2314
2315	if((p->aal.h.present & UNI_IE_PRESENT) &&
2316	   uni_encode_ie(UNI_IE_AAL, msg, (union uni_ieall *)&p->aal, cx))
2317		return (UNI_IE_AAL);
2318	if((p->bhli.h.present & UNI_IE_PRESENT) &&
2319	   uni_encode_ie(UNI_IE_BHLI, msg, (union uni_ieall *)&p->bhli, cx))
2320		return (UNI_IE_BHLI);
2321	if((p->blli.h.present & UNI_IE_PRESENT) &&
2322	   uni_encode_ie(UNI_IE_BLLI, msg, (union uni_ieall *)&p->blli, cx))
2323		return (UNI_IE_BLLI);
2324	if((p->called.h.present & UNI_IE_PRESENT) &&
2325	   uni_encode_ie(UNI_IE_CALLED, msg, (union uni_ieall *)&p->called, cx))
2326		return (UNI_IE_CALLED);
2327	for(i = 0; i < UNI_NUM_IE_CALLEDSUB; i++)
2328		if((p->calledsub[i].h.present & UNI_IE_PRESENT) &&
2329		   uni_encode_ie(UNI_IE_CALLEDSUB, msg, (union uni_ieall *)&p->calledsub[i], cx))
2330		return ((i << 16) + UNI_IE_CALLEDSUB);
2331	if((p->calling.h.present & UNI_IE_PRESENT) &&
2332	   uni_encode_ie(UNI_IE_CALLING, msg, (union uni_ieall *)&p->calling, cx))
2333		return (UNI_IE_CALLING);
2334	for(i = 0; i < UNI_NUM_IE_CALLINGSUB; i++)
2335		if((p->callingsub[i].h.present & UNI_IE_PRESENT) &&
2336		   uni_encode_ie(UNI_IE_CALLINGSUB, msg, (union uni_ieall *)&p->callingsub[i], cx))
2337		return ((i << 16) + UNI_IE_CALLINGSUB);
2338	if((p->scompl.h.present & UNI_IE_PRESENT) &&
2339	   uni_encode_ie(UNI_IE_SCOMPL, msg, (union uni_ieall *)&p->scompl, cx))
2340		return (UNI_IE_SCOMPL);
2341	for(i = 0; i < UNI_NUM_IE_TNS; i++)
2342		if((p->tns[i].h.present & UNI_IE_PRESENT) &&
2343		   uni_encode_ie(UNI_IE_TNS, msg, (union uni_ieall *)&p->tns[i], cx))
2344		return ((i << 16) + UNI_IE_TNS);
2345	if((p->epref.h.present & UNI_IE_PRESENT) &&
2346	   uni_encode_ie(UNI_IE_EPREF, msg, (union uni_ieall *)&p->epref, cx))
2347		return (UNI_IE_EPREF);
2348	if((p->notify.h.present & UNI_IE_PRESENT) &&
2349	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
2350		return (UNI_IE_NOTIFY);
2351	if((p->eetd.h.present & UNI_IE_PRESENT) &&
2352	   uni_encode_ie(UNI_IE_EETD, msg, (union uni_ieall *)&p->eetd, cx))
2353		return (UNI_IE_EETD);
2354	if((p->uu.h.present & UNI_IE_PRESENT) &&
2355	   uni_encode_ie(UNI_IE_UU, msg, (union uni_ieall *)&p->uu, cx))
2356		return (UNI_IE_UU);
2357	for(i = 0; i < UNI_NUM_IE_GIT; i++)
2358		if((p->git[i].h.present & UNI_IE_PRESENT) &&
2359		   uni_encode_ie(UNI_IE_GIT, msg, (union uni_ieall *)&p->git[i], cx))
2360		return ((i << 16) + UNI_IE_GIT);
2361	if((p->lij_seqno.h.present & UNI_IE_PRESENT) &&
2362	   uni_encode_ie(UNI_IE_LIJ_SEQNO, msg, (union uni_ieall *)&p->lij_seqno, cx))
2363		return (UNI_IE_LIJ_SEQNO);
2364	if((p->calling_soft.h.present & UNI_IE_PRESENT) &&
2365	   uni_encode_ie(UNI_IE_CALLING_SOFT, msg, (union uni_ieall *)&p->calling_soft, cx))
2366		return (UNI_IE_CALLING_SOFT);
2367	if((p->called_soft.h.present & UNI_IE_PRESENT) &&
2368	   uni_encode_ie(UNI_IE_CALLED_SOFT, msg, (union uni_ieall *)&p->called_soft, cx))
2369		return (UNI_IE_CALLED_SOFT);
2370	if((p->dtl_repeat.h.present & UNI_IE_PRESENT) &&
2371	   uni_encode_ie(UNI_IE_DTL, msg, (union uni_ieall *)&p->dtl_repeat, cx))
2372		return (0x10000000 + UNI_IE_DTL);
2373	for(i = 0; i < UNI_NUM_IE_DTL; i++)
2374		if((p->dtl[i].h.present & UNI_IE_PRESENT) &&
2375		   uni_encode_ie(UNI_IE_DTL, msg, (union uni_ieall *)&p->dtl[i], cx))
2376		return ((i << 16) + UNI_IE_DTL);
2377	if((p->unrec.h.present & UNI_IE_PRESENT) &&
2378	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
2379		return (UNI_IE_UNREC);
2380
2381	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
2382	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
2383
2384	return (0);
2385}
2386
2387static int
2388decode_add_party(struct uni_add_party *out, struct uni_msg *msg,
2389    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
2390    struct unicx *cx)
2391{
2392	u_int i;
2393
2394	switch (ie) {
2395
2396	  case UNI_IE_AAL:
2397		out->aal.h = *hdr;
2398		if (hdr->present & UNI_IE_ERROR)
2399			return (DEC_ERR);
2400		if(uni_decode_ie_body(UNI_IE_AAL, (union uni_ieall *)&out->aal, msg, ielen, cx))
2401			return (DEC_ERR);
2402		break;
2403
2404	  case UNI_IE_BHLI:
2405		out->bhli.h = *hdr;
2406		if (hdr->present & UNI_IE_ERROR)
2407			return (DEC_ERR);
2408		if(uni_decode_ie_body(UNI_IE_BHLI, (union uni_ieall *)&out->bhli, msg, ielen, cx))
2409			return (DEC_ERR);
2410		break;
2411
2412	  case UNI_IE_BLLI:
2413		out->blli.h = *hdr;
2414		if (hdr->present & UNI_IE_ERROR)
2415			return (DEC_ERR);
2416		if(uni_decode_ie_body(UNI_IE_BLLI, (union uni_ieall *)&out->blli, msg, ielen, cx))
2417			return (DEC_ERR);
2418		break;
2419
2420	  case UNI_IE_CALLED:
2421		out->called.h = *hdr;
2422		if (hdr->present & UNI_IE_ERROR)
2423			return (DEC_ERR);
2424		if(uni_decode_ie_body(UNI_IE_CALLED, (union uni_ieall *)&out->called, msg, ielen, cx))
2425			return (DEC_ERR);
2426		break;
2427
2428	  case UNI_IE_CALLEDSUB:
2429		for(i = 0; i < UNI_NUM_IE_CALLEDSUB; i++)
2430			if (!IE_ISPRESENT(out->calledsub[i])) {
2431				out->calledsub[i].h = *hdr;
2432				if (hdr->present & UNI_IE_ERROR)
2433					return (DEC_ERR);
2434				if(uni_decode_ie_body(UNI_IE_CALLEDSUB, (union uni_ieall *)&out->calledsub[i], msg, ielen, cx))
2435					return (DEC_ERR);
2436				break;
2437			}
2438		break;
2439
2440	  case UNI_IE_CALLING:
2441		out->calling.h = *hdr;
2442		if (hdr->present & UNI_IE_ERROR)
2443			return (DEC_ERR);
2444		if(uni_decode_ie_body(UNI_IE_CALLING, (union uni_ieall *)&out->calling, msg, ielen, cx))
2445			return (DEC_ERR);
2446		break;
2447
2448	  case UNI_IE_CALLINGSUB:
2449		for(i = 0; i < UNI_NUM_IE_CALLINGSUB; i++)
2450			if (!IE_ISPRESENT(out->callingsub[i])) {
2451				out->callingsub[i].h = *hdr;
2452				if (hdr->present & UNI_IE_ERROR)
2453					return (DEC_ERR);
2454				if(uni_decode_ie_body(UNI_IE_CALLINGSUB, (union uni_ieall *)&out->callingsub[i], msg, ielen, cx))
2455					return (DEC_ERR);
2456				break;
2457			}
2458		break;
2459
2460	  case UNI_IE_SCOMPL:
2461		if (!(!cx->pnni))
2462			return (DEC_ILL);
2463		out->scompl.h = *hdr;
2464		if (hdr->present & UNI_IE_ERROR)
2465			return (DEC_ERR);
2466		if(uni_decode_ie_body(UNI_IE_SCOMPL, (union uni_ieall *)&out->scompl, msg, ielen, cx))
2467			return (DEC_ERR);
2468		break;
2469
2470	  case UNI_IE_TNS:
2471		for(i = 0; i < UNI_NUM_IE_TNS; i++)
2472			if (!IE_ISPRESENT(out->tns[i])) {
2473				out->tns[i].h = *hdr;
2474				if (hdr->present & UNI_IE_ERROR)
2475					return (DEC_ERR);
2476				if(uni_decode_ie_body(UNI_IE_TNS, (union uni_ieall *)&out->tns[i], msg, ielen, cx))
2477					return (DEC_ERR);
2478				break;
2479			}
2480		break;
2481
2482	  case UNI_IE_EPREF:
2483		out->epref.h = *hdr;
2484		if (hdr->present & UNI_IE_ERROR)
2485			return (DEC_ERR);
2486		if(uni_decode_ie_body(UNI_IE_EPREF, (union uni_ieall *)&out->epref, msg, ielen, cx))
2487			return (DEC_ERR);
2488		break;
2489
2490	  case UNI_IE_NOTIFY:
2491		out->notify.h = *hdr;
2492		if (hdr->present & UNI_IE_ERROR)
2493			return (DEC_ERR);
2494		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
2495			return (DEC_ERR);
2496		break;
2497
2498	  case UNI_IE_EETD:
2499		out->eetd.h = *hdr;
2500		if (hdr->present & UNI_IE_ERROR)
2501			return (DEC_ERR);
2502		if(uni_decode_ie_body(UNI_IE_EETD, (union uni_ieall *)&out->eetd, msg, ielen, cx))
2503			return (DEC_ERR);
2504		break;
2505
2506	  case UNI_IE_UU:
2507		if (!(!cx->pnni))
2508			return (DEC_ILL);
2509		out->uu.h = *hdr;
2510		if (hdr->present & UNI_IE_ERROR)
2511			return (DEC_ERR);
2512		if(uni_decode_ie_body(UNI_IE_UU, (union uni_ieall *)&out->uu, msg, ielen, cx))
2513			return (DEC_ERR);
2514		break;
2515
2516	  case UNI_IE_GIT:
2517		for(i = 0; i < UNI_NUM_IE_GIT; i++)
2518			if (!IE_ISPRESENT(out->git[i])) {
2519				out->git[i].h = *hdr;
2520				if (hdr->present & UNI_IE_ERROR)
2521					return (DEC_ERR);
2522				if(uni_decode_ie_body(UNI_IE_GIT, (union uni_ieall *)&out->git[i], msg, ielen, cx))
2523					return (DEC_ERR);
2524				break;
2525			}
2526		break;
2527
2528	  case UNI_IE_LIJ_SEQNO:
2529		if (!(!cx->pnni))
2530			return (DEC_ILL);
2531		out->lij_seqno.h = *hdr;
2532		if (hdr->present & UNI_IE_ERROR)
2533			return (DEC_ERR);
2534		if(uni_decode_ie_body(UNI_IE_LIJ_SEQNO, (union uni_ieall *)&out->lij_seqno, msg, ielen, cx))
2535			return (DEC_ERR);
2536		break;
2537
2538	  case UNI_IE_CALLING_SOFT:
2539		if (!(cx->pnni))
2540			return (DEC_ILL);
2541		out->calling_soft.h = *hdr;
2542		if (hdr->present & UNI_IE_ERROR)
2543			return (DEC_ERR);
2544		if(uni_decode_ie_body(UNI_IE_CALLING_SOFT, (union uni_ieall *)&out->calling_soft, msg, ielen, cx))
2545			return (DEC_ERR);
2546		break;
2547
2548	  case UNI_IE_CALLED_SOFT:
2549		if (!(cx->pnni))
2550			return (DEC_ILL);
2551		out->called_soft.h = *hdr;
2552		if (hdr->present & UNI_IE_ERROR)
2553			return (DEC_ERR);
2554		if(uni_decode_ie_body(UNI_IE_CALLED_SOFT, (union uni_ieall *)&out->called_soft, msg, ielen, cx))
2555			return (DEC_ERR);
2556		break;
2557
2558	  case UNI_IE_DTL:
2559		if (!(cx->pnni))
2560			return (DEC_ILL);
2561		if (IE_ISPRESENT(cx->repeat))
2562			out->dtl_repeat = cx->repeat;
2563		for(i = 0; i < UNI_NUM_IE_DTL; i++)
2564			if (!IE_ISPRESENT(out->dtl[i])) {
2565				out->dtl[i].h = *hdr;
2566				if (hdr->present & UNI_IE_ERROR)
2567					return (DEC_ERR);
2568				if(uni_decode_ie_body(UNI_IE_DTL, (union uni_ieall *)&out->dtl[i], msg, ielen, cx))
2569					return (DEC_ERR);
2570				break;
2571			}
2572		break;
2573
2574	  case UNI_IE_UNREC:
2575		out->unrec.h = *hdr;
2576		if (hdr->present & UNI_IE_ERROR)
2577			return (DEC_ERR);
2578		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
2579			return (DEC_ERR);
2580		break;
2581
2582	  case UNI_IE_REPEAT:
2583		cx->repeat.h = *hdr;
2584		if (hdr->present & UNI_IE_ERROR)
2585			return (DEC_ERR);
2586		if (uni_decode_ie_body(UNI_IE_REPEAT, (union uni_ieall *)&cx->repeat, msg, ielen, cx))
2587			return (DEC_ERR);
2588		break;
2589
2590	  default:
2591		return (DEC_ILL);
2592	}
2593	return (DEC_OK);
2594}
2595
2596static const struct msgdecl decl_add_party = {
2597	0,
2598	"add_party",
2599	(uni_msg_print_f)print_add_party,
2600	(uni_msg_check_f)check_add_party,
2601	(uni_msg_encode_f)encode_add_party,
2602	(uni_msg_decode_f)decode_add_party
2603};
2604
2605static void
2606print_add_party_ack(struct uni_add_party_ack *msg, struct unicx *cx)
2607{
2608	u_int i;
2609
2610	if(msg->epref.h.present & UNI_IE_PRESENT)
2611		uni_print_ie_internal(UNI_IE_EPREF, (union uni_ieall *)&msg->epref, cx);
2612	if(msg->aal.h.present & UNI_IE_PRESENT)
2613		uni_print_ie_internal(UNI_IE_AAL, (union uni_ieall *)&msg->aal, cx);
2614	if(msg->blli.h.present & UNI_IE_PRESENT)
2615		uni_print_ie_internal(UNI_IE_BLLI, (union uni_ieall *)&msg->blli, cx);
2616	if(msg->notify.h.present & UNI_IE_PRESENT)
2617		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
2618	if(msg->eetd.h.present & UNI_IE_PRESENT)
2619		uni_print_ie_internal(UNI_IE_EETD, (union uni_ieall *)&msg->eetd, cx);
2620	if(msg->conned.h.present & UNI_IE_PRESENT)
2621		uni_print_ie_internal(UNI_IE_CONNED, (union uni_ieall *)&msg->conned, cx);
2622	if(msg->connedsub.h.present & UNI_IE_PRESENT)
2623		uni_print_ie_internal(UNI_IE_CONNEDSUB, (union uni_ieall *)&msg->connedsub, cx);
2624	if(msg->uu.h.present & UNI_IE_PRESENT)
2625		uni_print_ie_internal(UNI_IE_UU, (union uni_ieall *)&msg->uu, cx);
2626	for(i = 0; i < UNI_NUM_IE_GIT; i++)
2627		if(msg->git[i].h.present & UNI_IE_PRESENT)
2628			uni_print_ie_internal(UNI_IE_GIT, (union uni_ieall *)&msg->git[i], cx);
2629	if(msg->called_soft.h.present & UNI_IE_PRESENT)
2630		uni_print_ie_internal(UNI_IE_CALLED_SOFT, (union uni_ieall *)&msg->called_soft, cx);
2631	if(msg->unrec.h.present & UNI_IE_PRESENT)
2632		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
2633}
2634
2635static int
2636check_add_party_ack(struct uni_add_party_ack *m, struct unicx *cx)
2637{
2638	int ret = 0;
2639	u_int i;
2640
2641	ret |= uni_check_ie(UNI_IE_EPREF, (union uni_ieall *)&m->epref, cx);
2642	ret |= uni_check_ie(UNI_IE_AAL, (union uni_ieall *)&m->aal, cx);
2643	ret |= uni_check_ie(UNI_IE_BLLI, (union uni_ieall *)&m->blli, cx);
2644	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
2645	ret |= uni_check_ie(UNI_IE_EETD, (union uni_ieall *)&m->eetd, cx);
2646	ret |= uni_check_ie(UNI_IE_CONNED, (union uni_ieall *)&m->conned, cx);
2647	ret |= uni_check_ie(UNI_IE_CONNEDSUB, (union uni_ieall *)&m->connedsub, cx);
2648	if(!(!cx->pnni))
2649		ret |= IE_ISPRESENT(m->uu);
2650	else
2651		ret |= uni_check_ie(UNI_IE_UU, (union uni_ieall *)&m->uu, cx);
2652	for(i = 0; i < UNI_NUM_IE_GIT ; i++) {
2653		ret |= uni_check_ie(UNI_IE_GIT, (union uni_ieall *)&m->git[i], cx);
2654	}
2655	if(!(cx->pnni))
2656		ret |= IE_ISPRESENT(m->called_soft);
2657	else
2658		ret |= uni_check_ie(UNI_IE_CALLED_SOFT, (union uni_ieall *)&m->called_soft, cx);
2659	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
2660
2661	return ret;
2662}
2663
2664static int
2665encode_add_party_ack(struct uni_msg *msg, struct uni_add_party_ack *p, struct unicx *cx)
2666{
2667	u_int mlen;
2668	u_int i;
2669
2670	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_ADD_PARTY_ACK, cx, &mlen))
2671		return (-2);
2672
2673	if((p->epref.h.present & UNI_IE_PRESENT) &&
2674	   uni_encode_ie(UNI_IE_EPREF, msg, (union uni_ieall *)&p->epref, cx))
2675		return (UNI_IE_EPREF);
2676	if((p->aal.h.present & UNI_IE_PRESENT) &&
2677	   uni_encode_ie(UNI_IE_AAL, msg, (union uni_ieall *)&p->aal, cx))
2678		return (UNI_IE_AAL);
2679	if((p->blli.h.present & UNI_IE_PRESENT) &&
2680	   uni_encode_ie(UNI_IE_BLLI, msg, (union uni_ieall *)&p->blli, cx))
2681		return (UNI_IE_BLLI);
2682	if((p->notify.h.present & UNI_IE_PRESENT) &&
2683	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
2684		return (UNI_IE_NOTIFY);
2685	if((p->eetd.h.present & UNI_IE_PRESENT) &&
2686	   uni_encode_ie(UNI_IE_EETD, msg, (union uni_ieall *)&p->eetd, cx))
2687		return (UNI_IE_EETD);
2688	if((p->conned.h.present & UNI_IE_PRESENT) &&
2689	   uni_encode_ie(UNI_IE_CONNED, msg, (union uni_ieall *)&p->conned, cx))
2690		return (UNI_IE_CONNED);
2691	if((p->connedsub.h.present & UNI_IE_PRESENT) &&
2692	   uni_encode_ie(UNI_IE_CONNEDSUB, msg, (union uni_ieall *)&p->connedsub, cx))
2693		return (UNI_IE_CONNEDSUB);
2694	if((p->uu.h.present & UNI_IE_PRESENT) &&
2695	   uni_encode_ie(UNI_IE_UU, msg, (union uni_ieall *)&p->uu, cx))
2696		return (UNI_IE_UU);
2697	for(i = 0; i < UNI_NUM_IE_GIT; i++)
2698		if((p->git[i].h.present & UNI_IE_PRESENT) &&
2699		   uni_encode_ie(UNI_IE_GIT, msg, (union uni_ieall *)&p->git[i], cx))
2700		return ((i << 16) + UNI_IE_GIT);
2701	if((p->called_soft.h.present & UNI_IE_PRESENT) &&
2702	   uni_encode_ie(UNI_IE_CALLED_SOFT, msg, (union uni_ieall *)&p->called_soft, cx))
2703		return (UNI_IE_CALLED_SOFT);
2704	if((p->unrec.h.present & UNI_IE_PRESENT) &&
2705	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
2706		return (UNI_IE_UNREC);
2707
2708	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
2709	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
2710
2711	return (0);
2712}
2713
2714static int
2715decode_add_party_ack(struct uni_add_party_ack *out, struct uni_msg *msg,
2716    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
2717    struct unicx *cx)
2718{
2719	u_int i;
2720
2721	switch (ie) {
2722
2723	  case UNI_IE_EPREF:
2724		out->epref.h = *hdr;
2725		if (hdr->present & UNI_IE_ERROR)
2726			return (DEC_ERR);
2727		if(uni_decode_ie_body(UNI_IE_EPREF, (union uni_ieall *)&out->epref, msg, ielen, cx))
2728			return (DEC_ERR);
2729		break;
2730
2731	  case UNI_IE_AAL:
2732		out->aal.h = *hdr;
2733		if (hdr->present & UNI_IE_ERROR)
2734			return (DEC_ERR);
2735		if(uni_decode_ie_body(UNI_IE_AAL, (union uni_ieall *)&out->aal, msg, ielen, cx))
2736			return (DEC_ERR);
2737		break;
2738
2739	  case UNI_IE_BLLI:
2740		out->blli.h = *hdr;
2741		if (hdr->present & UNI_IE_ERROR)
2742			return (DEC_ERR);
2743		if(uni_decode_ie_body(UNI_IE_BLLI, (union uni_ieall *)&out->blli, msg, ielen, cx))
2744			return (DEC_ERR);
2745		break;
2746
2747	  case UNI_IE_NOTIFY:
2748		out->notify.h = *hdr;
2749		if (hdr->present & UNI_IE_ERROR)
2750			return (DEC_ERR);
2751		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
2752			return (DEC_ERR);
2753		break;
2754
2755	  case UNI_IE_EETD:
2756		out->eetd.h = *hdr;
2757		if (hdr->present & UNI_IE_ERROR)
2758			return (DEC_ERR);
2759		if(uni_decode_ie_body(UNI_IE_EETD, (union uni_ieall *)&out->eetd, msg, ielen, cx))
2760			return (DEC_ERR);
2761		break;
2762
2763	  case UNI_IE_CONNED:
2764		out->conned.h = *hdr;
2765		if (hdr->present & UNI_IE_ERROR)
2766			return (DEC_ERR);
2767		if(uni_decode_ie_body(UNI_IE_CONNED, (union uni_ieall *)&out->conned, msg, ielen, cx))
2768			return (DEC_ERR);
2769		break;
2770
2771	  case UNI_IE_CONNEDSUB:
2772		out->connedsub.h = *hdr;
2773		if (hdr->present & UNI_IE_ERROR)
2774			return (DEC_ERR);
2775		if(uni_decode_ie_body(UNI_IE_CONNEDSUB, (union uni_ieall *)&out->connedsub, msg, ielen, cx))
2776			return (DEC_ERR);
2777		break;
2778
2779	  case UNI_IE_UU:
2780		if (!(!cx->pnni))
2781			return (DEC_ILL);
2782		out->uu.h = *hdr;
2783		if (hdr->present & UNI_IE_ERROR)
2784			return (DEC_ERR);
2785		if(uni_decode_ie_body(UNI_IE_UU, (union uni_ieall *)&out->uu, msg, ielen, cx))
2786			return (DEC_ERR);
2787		break;
2788
2789	  case UNI_IE_GIT:
2790		for(i = 0; i < UNI_NUM_IE_GIT; i++)
2791			if (!IE_ISPRESENT(out->git[i])) {
2792				out->git[i].h = *hdr;
2793				if (hdr->present & UNI_IE_ERROR)
2794					return (DEC_ERR);
2795				if(uni_decode_ie_body(UNI_IE_GIT, (union uni_ieall *)&out->git[i], msg, ielen, cx))
2796					return (DEC_ERR);
2797				break;
2798			}
2799		break;
2800
2801	  case UNI_IE_CALLED_SOFT:
2802		if (!(cx->pnni))
2803			return (DEC_ILL);
2804		out->called_soft.h = *hdr;
2805		if (hdr->present & UNI_IE_ERROR)
2806			return (DEC_ERR);
2807		if(uni_decode_ie_body(UNI_IE_CALLED_SOFT, (union uni_ieall *)&out->called_soft, msg, ielen, cx))
2808			return (DEC_ERR);
2809		break;
2810
2811	  case UNI_IE_UNREC:
2812		out->unrec.h = *hdr;
2813		if (hdr->present & UNI_IE_ERROR)
2814			return (DEC_ERR);
2815		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
2816			return (DEC_ERR);
2817		break;
2818
2819	  default:
2820		return (DEC_ILL);
2821	}
2822	return (DEC_OK);
2823}
2824
2825static const struct msgdecl decl_add_party_ack = {
2826	0,
2827	"add_party_ack",
2828	(uni_msg_print_f)print_add_party_ack,
2829	(uni_msg_check_f)check_add_party_ack,
2830	(uni_msg_encode_f)encode_add_party_ack,
2831	(uni_msg_decode_f)decode_add_party_ack
2832};
2833
2834static void
2835print_party_alerting(struct uni_party_alerting *msg, struct unicx *cx)
2836{
2837	u_int i;
2838
2839	if(msg->epref.h.present & UNI_IE_PRESENT)
2840		uni_print_ie_internal(UNI_IE_EPREF, (union uni_ieall *)&msg->epref, cx);
2841	if(msg->notify.h.present & UNI_IE_PRESENT)
2842		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
2843	if(msg->uu.h.present & UNI_IE_PRESENT)
2844		uni_print_ie_internal(UNI_IE_UU, (union uni_ieall *)&msg->uu, cx);
2845	for(i = 0; i < UNI_NUM_IE_GIT; i++)
2846		if(msg->git[i].h.present & UNI_IE_PRESENT)
2847			uni_print_ie_internal(UNI_IE_GIT, (union uni_ieall *)&msg->git[i], cx);
2848	if(msg->unrec.h.present & UNI_IE_PRESENT)
2849		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
2850}
2851
2852static int
2853check_party_alerting(struct uni_party_alerting *m, struct unicx *cx)
2854{
2855	int ret = 0;
2856	u_int i;
2857
2858	ret |= uni_check_ie(UNI_IE_EPREF, (union uni_ieall *)&m->epref, cx);
2859	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
2860	if(!(!cx->pnni))
2861		ret |= IE_ISPRESENT(m->uu);
2862	else
2863		ret |= uni_check_ie(UNI_IE_UU, (union uni_ieall *)&m->uu, cx);
2864	for(i = 0; i < UNI_NUM_IE_GIT ; i++) {
2865		ret |= uni_check_ie(UNI_IE_GIT, (union uni_ieall *)&m->git[i], cx);
2866	}
2867	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
2868
2869	return ret;
2870}
2871
2872static int
2873encode_party_alerting(struct uni_msg *msg, struct uni_party_alerting *p, struct unicx *cx)
2874{
2875	u_int mlen;
2876	u_int i;
2877
2878	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_PARTY_ALERTING, cx, &mlen))
2879		return (-2);
2880
2881	if((p->epref.h.present & UNI_IE_PRESENT) &&
2882	   uni_encode_ie(UNI_IE_EPREF, msg, (union uni_ieall *)&p->epref, cx))
2883		return (UNI_IE_EPREF);
2884	if((p->notify.h.present & UNI_IE_PRESENT) &&
2885	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
2886		return (UNI_IE_NOTIFY);
2887	if((p->uu.h.present & UNI_IE_PRESENT) &&
2888	   uni_encode_ie(UNI_IE_UU, msg, (union uni_ieall *)&p->uu, cx))
2889		return (UNI_IE_UU);
2890	for(i = 0; i < UNI_NUM_IE_GIT; i++)
2891		if((p->git[i].h.present & UNI_IE_PRESENT) &&
2892		   uni_encode_ie(UNI_IE_GIT, msg, (union uni_ieall *)&p->git[i], cx))
2893		return ((i << 16) + UNI_IE_GIT);
2894	if((p->unrec.h.present & UNI_IE_PRESENT) &&
2895	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
2896		return (UNI_IE_UNREC);
2897
2898	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
2899	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
2900
2901	return (0);
2902}
2903
2904static int
2905decode_party_alerting(struct uni_party_alerting *out, struct uni_msg *msg,
2906    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
2907    struct unicx *cx)
2908{
2909	u_int i;
2910
2911	switch (ie) {
2912
2913	  case UNI_IE_EPREF:
2914		out->epref.h = *hdr;
2915		if (hdr->present & UNI_IE_ERROR)
2916			return (DEC_ERR);
2917		if(uni_decode_ie_body(UNI_IE_EPREF, (union uni_ieall *)&out->epref, msg, ielen, cx))
2918			return (DEC_ERR);
2919		break;
2920
2921	  case UNI_IE_NOTIFY:
2922		out->notify.h = *hdr;
2923		if (hdr->present & UNI_IE_ERROR)
2924			return (DEC_ERR);
2925		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
2926			return (DEC_ERR);
2927		break;
2928
2929	  case UNI_IE_UU:
2930		if (!(!cx->pnni))
2931			return (DEC_ILL);
2932		out->uu.h = *hdr;
2933		if (hdr->present & UNI_IE_ERROR)
2934			return (DEC_ERR);
2935		if(uni_decode_ie_body(UNI_IE_UU, (union uni_ieall *)&out->uu, msg, ielen, cx))
2936			return (DEC_ERR);
2937		break;
2938
2939	  case UNI_IE_GIT:
2940		for(i = 0; i < UNI_NUM_IE_GIT; i++)
2941			if (!IE_ISPRESENT(out->git[i])) {
2942				out->git[i].h = *hdr;
2943				if (hdr->present & UNI_IE_ERROR)
2944					return (DEC_ERR);
2945				if(uni_decode_ie_body(UNI_IE_GIT, (union uni_ieall *)&out->git[i], msg, ielen, cx))
2946					return (DEC_ERR);
2947				break;
2948			}
2949		break;
2950
2951	  case UNI_IE_UNREC:
2952		out->unrec.h = *hdr;
2953		if (hdr->present & UNI_IE_ERROR)
2954			return (DEC_ERR);
2955		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
2956			return (DEC_ERR);
2957		break;
2958
2959	  default:
2960		return (DEC_ILL);
2961	}
2962	return (DEC_OK);
2963}
2964
2965static const struct msgdecl decl_party_alerting = {
2966	0,
2967	"party_alerting",
2968	(uni_msg_print_f)print_party_alerting,
2969	(uni_msg_check_f)check_party_alerting,
2970	(uni_msg_encode_f)encode_party_alerting,
2971	(uni_msg_decode_f)decode_party_alerting
2972};
2973
2974static void
2975print_add_party_rej(struct uni_add_party_rej *msg, struct unicx *cx)
2976{
2977	u_int i;
2978
2979	if(msg->cause.h.present & UNI_IE_PRESENT)
2980		uni_print_ie_internal(UNI_IE_CAUSE, (union uni_ieall *)&msg->cause, cx);
2981	if(msg->epref.h.present & UNI_IE_PRESENT)
2982		uni_print_ie_internal(UNI_IE_EPREF, (union uni_ieall *)&msg->epref, cx);
2983	if(msg->uu.h.present & UNI_IE_PRESENT)
2984		uni_print_ie_internal(UNI_IE_UU, (union uni_ieall *)&msg->uu, cx);
2985	for(i = 0; i < UNI_NUM_IE_GIT; i++)
2986		if(msg->git[i].h.present & UNI_IE_PRESENT)
2987			uni_print_ie_internal(UNI_IE_GIT, (union uni_ieall *)&msg->git[i], cx);
2988	if(msg->crankback.h.present & UNI_IE_PRESENT)
2989		uni_print_ie_internal(UNI_IE_CRANKBACK, (union uni_ieall *)&msg->crankback, cx);
2990	if(msg->unrec.h.present & UNI_IE_PRESENT)
2991		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
2992}
2993
2994static int
2995check_add_party_rej(struct uni_add_party_rej *m, struct unicx *cx)
2996{
2997	int ret = 0;
2998	u_int i;
2999
3000	ret |= uni_check_ie(UNI_IE_CAUSE, (union uni_ieall *)&m->cause, cx);
3001	ret |= uni_check_ie(UNI_IE_EPREF, (union uni_ieall *)&m->epref, cx);
3002	if(!(!cx->pnni))
3003		ret |= IE_ISPRESENT(m->uu);
3004	else
3005		ret |= uni_check_ie(UNI_IE_UU, (union uni_ieall *)&m->uu, cx);
3006	for(i = 0; i < UNI_NUM_IE_GIT ; i++) {
3007		ret |= uni_check_ie(UNI_IE_GIT, (union uni_ieall *)&m->git[i], cx);
3008	}
3009	if(!(cx->pnni))
3010		ret |= IE_ISPRESENT(m->crankback);
3011	else
3012		ret |= uni_check_ie(UNI_IE_CRANKBACK, (union uni_ieall *)&m->crankback, cx);
3013	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
3014
3015	return ret;
3016}
3017
3018static int
3019encode_add_party_rej(struct uni_msg *msg, struct uni_add_party_rej *p, struct unicx *cx)
3020{
3021	u_int mlen;
3022	u_int i;
3023
3024	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_ADD_PARTY_REJ, cx, &mlen))
3025		return (-2);
3026
3027	if((p->cause.h.present & UNI_IE_PRESENT) &&
3028	   uni_encode_ie(UNI_IE_CAUSE, msg, (union uni_ieall *)&p->cause, cx))
3029		return (UNI_IE_CAUSE);
3030	if((p->epref.h.present & UNI_IE_PRESENT) &&
3031	   uni_encode_ie(UNI_IE_EPREF, msg, (union uni_ieall *)&p->epref, cx))
3032		return (UNI_IE_EPREF);
3033	if((p->uu.h.present & UNI_IE_PRESENT) &&
3034	   uni_encode_ie(UNI_IE_UU, msg, (union uni_ieall *)&p->uu, cx))
3035		return (UNI_IE_UU);
3036	for(i = 0; i < UNI_NUM_IE_GIT; i++)
3037		if((p->git[i].h.present & UNI_IE_PRESENT) &&
3038		   uni_encode_ie(UNI_IE_GIT, msg, (union uni_ieall *)&p->git[i], cx))
3039		return ((i << 16) + UNI_IE_GIT);
3040	if((p->crankback.h.present & UNI_IE_PRESENT) &&
3041	   uni_encode_ie(UNI_IE_CRANKBACK, msg, (union uni_ieall *)&p->crankback, cx))
3042		return (UNI_IE_CRANKBACK);
3043	if((p->unrec.h.present & UNI_IE_PRESENT) &&
3044	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
3045		return (UNI_IE_UNREC);
3046
3047	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
3048	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
3049
3050	return (0);
3051}
3052
3053static int
3054decode_add_party_rej(struct uni_add_party_rej *out, struct uni_msg *msg,
3055    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
3056    struct unicx *cx)
3057{
3058	u_int i;
3059
3060	switch (ie) {
3061
3062	  case UNI_IE_CAUSE:
3063		out->cause.h = *hdr;
3064		if (hdr->present & UNI_IE_ERROR)
3065			return (DEC_ERR);
3066		if(uni_decode_ie_body(UNI_IE_CAUSE, (union uni_ieall *)&out->cause, msg, ielen, cx))
3067			return (DEC_ERR);
3068		break;
3069
3070	  case UNI_IE_EPREF:
3071		out->epref.h = *hdr;
3072		if (hdr->present & UNI_IE_ERROR)
3073			return (DEC_ERR);
3074		if(uni_decode_ie_body(UNI_IE_EPREF, (union uni_ieall *)&out->epref, msg, ielen, cx))
3075			return (DEC_ERR);
3076		break;
3077
3078	  case UNI_IE_UU:
3079		if (!(!cx->pnni))
3080			return (DEC_ILL);
3081		out->uu.h = *hdr;
3082		if (hdr->present & UNI_IE_ERROR)
3083			return (DEC_ERR);
3084		if(uni_decode_ie_body(UNI_IE_UU, (union uni_ieall *)&out->uu, msg, ielen, cx))
3085			return (DEC_ERR);
3086		break;
3087
3088	  case UNI_IE_GIT:
3089		for(i = 0; i < UNI_NUM_IE_GIT; i++)
3090			if (!IE_ISPRESENT(out->git[i])) {
3091				out->git[i].h = *hdr;
3092				if (hdr->present & UNI_IE_ERROR)
3093					return (DEC_ERR);
3094				if(uni_decode_ie_body(UNI_IE_GIT, (union uni_ieall *)&out->git[i], msg, ielen, cx))
3095					return (DEC_ERR);
3096				break;
3097			}
3098		break;
3099
3100	  case UNI_IE_CRANKBACK:
3101		if (!(cx->pnni))
3102			return (DEC_ILL);
3103		out->crankback.h = *hdr;
3104		if (hdr->present & UNI_IE_ERROR)
3105			return (DEC_ERR);
3106		if(uni_decode_ie_body(UNI_IE_CRANKBACK, (union uni_ieall *)&out->crankback, msg, ielen, cx))
3107			return (DEC_ERR);
3108		break;
3109
3110	  case UNI_IE_UNREC:
3111		out->unrec.h = *hdr;
3112		if (hdr->present & UNI_IE_ERROR)
3113			return (DEC_ERR);
3114		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
3115			return (DEC_ERR);
3116		break;
3117
3118	  default:
3119		return (DEC_ILL);
3120	}
3121	return (DEC_OK);
3122}
3123
3124static const struct msgdecl decl_add_party_rej = {
3125	0,
3126	"add_party_rej",
3127	(uni_msg_print_f)print_add_party_rej,
3128	(uni_msg_check_f)check_add_party_rej,
3129	(uni_msg_encode_f)encode_add_party_rej,
3130	(uni_msg_decode_f)decode_add_party_rej
3131};
3132
3133static void
3134print_drop_party(struct uni_drop_party *msg, struct unicx *cx)
3135{
3136	u_int i;
3137
3138	if(msg->cause.h.present & UNI_IE_PRESENT)
3139		uni_print_ie_internal(UNI_IE_CAUSE, (union uni_ieall *)&msg->cause, cx);
3140	if(msg->epref.h.present & UNI_IE_PRESENT)
3141		uni_print_ie_internal(UNI_IE_EPREF, (union uni_ieall *)&msg->epref, cx);
3142	if(msg->notify.h.present & UNI_IE_PRESENT)
3143		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
3144	if(msg->uu.h.present & UNI_IE_PRESENT)
3145		uni_print_ie_internal(UNI_IE_UU, (union uni_ieall *)&msg->uu, cx);
3146	for(i = 0; i < UNI_NUM_IE_GIT; i++)
3147		if(msg->git[i].h.present & UNI_IE_PRESENT)
3148			uni_print_ie_internal(UNI_IE_GIT, (union uni_ieall *)&msg->git[i], cx);
3149	if(msg->unrec.h.present & UNI_IE_PRESENT)
3150		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
3151}
3152
3153static int
3154check_drop_party(struct uni_drop_party *m, struct unicx *cx)
3155{
3156	int ret = 0;
3157	u_int i;
3158
3159	ret |= uni_check_ie(UNI_IE_CAUSE, (union uni_ieall *)&m->cause, cx);
3160	ret |= uni_check_ie(UNI_IE_EPREF, (union uni_ieall *)&m->epref, cx);
3161	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
3162	if(!(!cx->pnni))
3163		ret |= IE_ISPRESENT(m->uu);
3164	else
3165		ret |= uni_check_ie(UNI_IE_UU, (union uni_ieall *)&m->uu, cx);
3166	for(i = 0; i < UNI_NUM_IE_GIT ; i++) {
3167		ret |= uni_check_ie(UNI_IE_GIT, (union uni_ieall *)&m->git[i], cx);
3168	}
3169	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
3170
3171	return ret;
3172}
3173
3174static int
3175encode_drop_party(struct uni_msg *msg, struct uni_drop_party *p, struct unicx *cx)
3176{
3177	u_int mlen;
3178	u_int i;
3179
3180	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_DROP_PARTY, cx, &mlen))
3181		return (-2);
3182
3183	if((p->cause.h.present & UNI_IE_PRESENT) &&
3184	   uni_encode_ie(UNI_IE_CAUSE, msg, (union uni_ieall *)&p->cause, cx))
3185		return (UNI_IE_CAUSE);
3186	if((p->epref.h.present & UNI_IE_PRESENT) &&
3187	   uni_encode_ie(UNI_IE_EPREF, msg, (union uni_ieall *)&p->epref, cx))
3188		return (UNI_IE_EPREF);
3189	if((p->notify.h.present & UNI_IE_PRESENT) &&
3190	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
3191		return (UNI_IE_NOTIFY);
3192	if((p->uu.h.present & UNI_IE_PRESENT) &&
3193	   uni_encode_ie(UNI_IE_UU, msg, (union uni_ieall *)&p->uu, cx))
3194		return (UNI_IE_UU);
3195	for(i = 0; i < UNI_NUM_IE_GIT; i++)
3196		if((p->git[i].h.present & UNI_IE_PRESENT) &&
3197		   uni_encode_ie(UNI_IE_GIT, msg, (union uni_ieall *)&p->git[i], cx))
3198		return ((i << 16) + UNI_IE_GIT);
3199	if((p->unrec.h.present & UNI_IE_PRESENT) &&
3200	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
3201		return (UNI_IE_UNREC);
3202
3203	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
3204	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
3205
3206	return (0);
3207}
3208
3209static int
3210decode_drop_party(struct uni_drop_party *out, struct uni_msg *msg,
3211    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
3212    struct unicx *cx)
3213{
3214	u_int i;
3215
3216	switch (ie) {
3217
3218	  case UNI_IE_CAUSE:
3219		out->cause.h = *hdr;
3220		if (hdr->present & UNI_IE_ERROR)
3221			return (DEC_ERR);
3222		if(uni_decode_ie_body(UNI_IE_CAUSE, (union uni_ieall *)&out->cause, msg, ielen, cx))
3223			return (DEC_ERR);
3224		break;
3225
3226	  case UNI_IE_EPREF:
3227		out->epref.h = *hdr;
3228		if (hdr->present & UNI_IE_ERROR)
3229			return (DEC_ERR);
3230		if(uni_decode_ie_body(UNI_IE_EPREF, (union uni_ieall *)&out->epref, msg, ielen, cx))
3231			return (DEC_ERR);
3232		break;
3233
3234	  case UNI_IE_NOTIFY:
3235		out->notify.h = *hdr;
3236		if (hdr->present & UNI_IE_ERROR)
3237			return (DEC_ERR);
3238		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
3239			return (DEC_ERR);
3240		break;
3241
3242	  case UNI_IE_UU:
3243		if (!(!cx->pnni))
3244			return (DEC_ILL);
3245		out->uu.h = *hdr;
3246		if (hdr->present & UNI_IE_ERROR)
3247			return (DEC_ERR);
3248		if(uni_decode_ie_body(UNI_IE_UU, (union uni_ieall *)&out->uu, msg, ielen, cx))
3249			return (DEC_ERR);
3250		break;
3251
3252	  case UNI_IE_GIT:
3253		for(i = 0; i < UNI_NUM_IE_GIT; i++)
3254			if (!IE_ISPRESENT(out->git[i])) {
3255				out->git[i].h = *hdr;
3256				if (hdr->present & UNI_IE_ERROR)
3257					return (DEC_ERR);
3258				if(uni_decode_ie_body(UNI_IE_GIT, (union uni_ieall *)&out->git[i], msg, ielen, cx))
3259					return (DEC_ERR);
3260				break;
3261			}
3262		break;
3263
3264	  case UNI_IE_UNREC:
3265		out->unrec.h = *hdr;
3266		if (hdr->present & UNI_IE_ERROR)
3267			return (DEC_ERR);
3268		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
3269			return (DEC_ERR);
3270		break;
3271
3272	  default:
3273		return (DEC_ILL);
3274	}
3275	return (DEC_OK);
3276}
3277
3278static const struct msgdecl decl_drop_party = {
3279	0,
3280	"drop_party",
3281	(uni_msg_print_f)print_drop_party,
3282	(uni_msg_check_f)check_drop_party,
3283	(uni_msg_encode_f)encode_drop_party,
3284	(uni_msg_decode_f)decode_drop_party
3285};
3286
3287static void
3288print_drop_party_ack(struct uni_drop_party_ack *msg, struct unicx *cx)
3289{
3290	u_int i;
3291
3292	if(msg->epref.h.present & UNI_IE_PRESENT)
3293		uni_print_ie_internal(UNI_IE_EPREF, (union uni_ieall *)&msg->epref, cx);
3294	if(msg->cause.h.present & UNI_IE_PRESENT)
3295		uni_print_ie_internal(UNI_IE_CAUSE, (union uni_ieall *)&msg->cause, cx);
3296	if(msg->uu.h.present & UNI_IE_PRESENT)
3297		uni_print_ie_internal(UNI_IE_UU, (union uni_ieall *)&msg->uu, cx);
3298	for(i = 0; i < UNI_NUM_IE_GIT; i++)
3299		if(msg->git[i].h.present & UNI_IE_PRESENT)
3300			uni_print_ie_internal(UNI_IE_GIT, (union uni_ieall *)&msg->git[i], cx);
3301	if(msg->unrec.h.present & UNI_IE_PRESENT)
3302		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
3303}
3304
3305static int
3306check_drop_party_ack(struct uni_drop_party_ack *m, struct unicx *cx)
3307{
3308	int ret = 0;
3309	u_int i;
3310
3311	ret |= uni_check_ie(UNI_IE_EPREF, (union uni_ieall *)&m->epref, cx);
3312	ret |= uni_check_ie(UNI_IE_CAUSE, (union uni_ieall *)&m->cause, cx);
3313	if(!(!cx->pnni))
3314		ret |= IE_ISPRESENT(m->uu);
3315	else
3316		ret |= uni_check_ie(UNI_IE_UU, (union uni_ieall *)&m->uu, cx);
3317	for(i = 0; i < UNI_NUM_IE_GIT ; i++) {
3318		ret |= uni_check_ie(UNI_IE_GIT, (union uni_ieall *)&m->git[i], cx);
3319	}
3320	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
3321
3322	return ret;
3323}
3324
3325static int
3326encode_drop_party_ack(struct uni_msg *msg, struct uni_drop_party_ack *p, struct unicx *cx)
3327{
3328	u_int mlen;
3329	u_int i;
3330
3331	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_DROP_PARTY_ACK, cx, &mlen))
3332		return (-2);
3333
3334	if((p->epref.h.present & UNI_IE_PRESENT) &&
3335	   uni_encode_ie(UNI_IE_EPREF, msg, (union uni_ieall *)&p->epref, cx))
3336		return (UNI_IE_EPREF);
3337	if((p->cause.h.present & UNI_IE_PRESENT) &&
3338	   uni_encode_ie(UNI_IE_CAUSE, msg, (union uni_ieall *)&p->cause, cx))
3339		return (UNI_IE_CAUSE);
3340	if((p->uu.h.present & UNI_IE_PRESENT) &&
3341	   uni_encode_ie(UNI_IE_UU, msg, (union uni_ieall *)&p->uu, cx))
3342		return (UNI_IE_UU);
3343	for(i = 0; i < UNI_NUM_IE_GIT; i++)
3344		if((p->git[i].h.present & UNI_IE_PRESENT) &&
3345		   uni_encode_ie(UNI_IE_GIT, msg, (union uni_ieall *)&p->git[i], cx))
3346		return ((i << 16) + UNI_IE_GIT);
3347	if((p->unrec.h.present & UNI_IE_PRESENT) &&
3348	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
3349		return (UNI_IE_UNREC);
3350
3351	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
3352	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
3353
3354	return (0);
3355}
3356
3357static int
3358decode_drop_party_ack(struct uni_drop_party_ack *out, struct uni_msg *msg,
3359    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
3360    struct unicx *cx)
3361{
3362	u_int i;
3363
3364	switch (ie) {
3365
3366	  case UNI_IE_EPREF:
3367		out->epref.h = *hdr;
3368		if (hdr->present & UNI_IE_ERROR)
3369			return (DEC_ERR);
3370		if(uni_decode_ie_body(UNI_IE_EPREF, (union uni_ieall *)&out->epref, msg, ielen, cx))
3371			return (DEC_ERR);
3372		break;
3373
3374	  case UNI_IE_CAUSE:
3375		out->cause.h = *hdr;
3376		if (hdr->present & UNI_IE_ERROR)
3377			return (DEC_ERR);
3378		if(uni_decode_ie_body(UNI_IE_CAUSE, (union uni_ieall *)&out->cause, msg, ielen, cx))
3379			return (DEC_ERR);
3380		break;
3381
3382	  case UNI_IE_UU:
3383		if (!(!cx->pnni))
3384			return (DEC_ILL);
3385		out->uu.h = *hdr;
3386		if (hdr->present & UNI_IE_ERROR)
3387			return (DEC_ERR);
3388		if(uni_decode_ie_body(UNI_IE_UU, (union uni_ieall *)&out->uu, msg, ielen, cx))
3389			return (DEC_ERR);
3390		break;
3391
3392	  case UNI_IE_GIT:
3393		for(i = 0; i < UNI_NUM_IE_GIT; i++)
3394			if (!IE_ISPRESENT(out->git[i])) {
3395				out->git[i].h = *hdr;
3396				if (hdr->present & UNI_IE_ERROR)
3397					return (DEC_ERR);
3398				if(uni_decode_ie_body(UNI_IE_GIT, (union uni_ieall *)&out->git[i], msg, ielen, cx))
3399					return (DEC_ERR);
3400				break;
3401			}
3402		break;
3403
3404	  case UNI_IE_UNREC:
3405		out->unrec.h = *hdr;
3406		if (hdr->present & UNI_IE_ERROR)
3407			return (DEC_ERR);
3408		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
3409			return (DEC_ERR);
3410		break;
3411
3412	  default:
3413		return (DEC_ILL);
3414	}
3415	return (DEC_OK);
3416}
3417
3418static const struct msgdecl decl_drop_party_ack = {
3419	0,
3420	"drop_party_ack",
3421	(uni_msg_print_f)print_drop_party_ack,
3422	(uni_msg_check_f)check_drop_party_ack,
3423	(uni_msg_encode_f)encode_drop_party_ack,
3424	(uni_msg_decode_f)decode_drop_party_ack
3425};
3426
3427static void
3428print_leaf_setup_req(struct uni_leaf_setup_req *msg, struct unicx *cx)
3429{
3430	u_int i;
3431
3432	for(i = 0; i < UNI_NUM_IE_TNS; i++)
3433		if(msg->tns[i].h.present & UNI_IE_PRESENT)
3434			uni_print_ie_internal(UNI_IE_TNS, (union uni_ieall *)&msg->tns[i], cx);
3435	if(msg->calling.h.present & UNI_IE_PRESENT)
3436		uni_print_ie_internal(UNI_IE_CALLING, (union uni_ieall *)&msg->calling, cx);
3437	for(i = 0; i < UNI_NUM_IE_CALLINGSUB; i++)
3438		if(msg->callingsub[i].h.present & UNI_IE_PRESENT)
3439			uni_print_ie_internal(UNI_IE_CALLINGSUB, (union uni_ieall *)&msg->callingsub[i], cx);
3440	if(msg->called.h.present & UNI_IE_PRESENT)
3441		uni_print_ie_internal(UNI_IE_CALLED, (union uni_ieall *)&msg->called, cx);
3442	for(i = 0; i < UNI_NUM_IE_CALLEDSUB; i++)
3443		if(msg->calledsub[i].h.present & UNI_IE_PRESENT)
3444			uni_print_ie_internal(UNI_IE_CALLEDSUB, (union uni_ieall *)&msg->calledsub[i], cx);
3445	if(msg->lij_callid.h.present & UNI_IE_PRESENT)
3446		uni_print_ie_internal(UNI_IE_LIJ_CALLID, (union uni_ieall *)&msg->lij_callid, cx);
3447	if(msg->lij_seqno.h.present & UNI_IE_PRESENT)
3448		uni_print_ie_internal(UNI_IE_LIJ_SEQNO, (union uni_ieall *)&msg->lij_seqno, cx);
3449	if(msg->unrec.h.present & UNI_IE_PRESENT)
3450		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
3451}
3452
3453static int
3454check_leaf_setup_req(struct uni_leaf_setup_req *m, struct unicx *cx)
3455{
3456	int ret = 0;
3457	u_int i;
3458
3459	for(i = 0; i < UNI_NUM_IE_TNS ; i++) {
3460		ret |= uni_check_ie(UNI_IE_TNS, (union uni_ieall *)&m->tns[i], cx);
3461	}
3462	ret |= uni_check_ie(UNI_IE_CALLING, (union uni_ieall *)&m->calling, cx);
3463	for(i = 0; i < UNI_NUM_IE_CALLINGSUB ; i++) {
3464		ret |= uni_check_ie(UNI_IE_CALLINGSUB, (union uni_ieall *)&m->callingsub[i], cx);
3465	}
3466	ret |= uni_check_ie(UNI_IE_CALLED, (union uni_ieall *)&m->called, cx);
3467	for(i = 0; i < UNI_NUM_IE_CALLEDSUB ; i++) {
3468		ret |= uni_check_ie(UNI_IE_CALLEDSUB, (union uni_ieall *)&m->calledsub[i], cx);
3469	}
3470	ret |= uni_check_ie(UNI_IE_LIJ_CALLID, (union uni_ieall *)&m->lij_callid, cx);
3471	ret |= uni_check_ie(UNI_IE_LIJ_SEQNO, (union uni_ieall *)&m->lij_seqno, cx);
3472	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
3473
3474	return ret;
3475}
3476
3477static int
3478encode_leaf_setup_req(struct uni_msg *msg, struct uni_leaf_setup_req *p, struct unicx *cx)
3479{
3480	u_int mlen;
3481	u_int i;
3482
3483	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_LEAF_SETUP_REQ, cx, &mlen))
3484		return (-2);
3485
3486	for(i = 0; i < UNI_NUM_IE_TNS; i++)
3487		if((p->tns[i].h.present & UNI_IE_PRESENT) &&
3488		   uni_encode_ie(UNI_IE_TNS, msg, (union uni_ieall *)&p->tns[i], cx))
3489		return ((i << 16) + UNI_IE_TNS);
3490	if((p->calling.h.present & UNI_IE_PRESENT) &&
3491	   uni_encode_ie(UNI_IE_CALLING, msg, (union uni_ieall *)&p->calling, cx))
3492		return (UNI_IE_CALLING);
3493	for(i = 0; i < UNI_NUM_IE_CALLINGSUB; i++)
3494		if((p->callingsub[i].h.present & UNI_IE_PRESENT) &&
3495		   uni_encode_ie(UNI_IE_CALLINGSUB, msg, (union uni_ieall *)&p->callingsub[i], cx))
3496		return ((i << 16) + UNI_IE_CALLINGSUB);
3497	if((p->called.h.present & UNI_IE_PRESENT) &&
3498	   uni_encode_ie(UNI_IE_CALLED, msg, (union uni_ieall *)&p->called, cx))
3499		return (UNI_IE_CALLED);
3500	for(i = 0; i < UNI_NUM_IE_CALLEDSUB; i++)
3501		if((p->calledsub[i].h.present & UNI_IE_PRESENT) &&
3502		   uni_encode_ie(UNI_IE_CALLEDSUB, msg, (union uni_ieall *)&p->calledsub[i], cx))
3503		return ((i << 16) + UNI_IE_CALLEDSUB);
3504	if((p->lij_callid.h.present & UNI_IE_PRESENT) &&
3505	   uni_encode_ie(UNI_IE_LIJ_CALLID, msg, (union uni_ieall *)&p->lij_callid, cx))
3506		return (UNI_IE_LIJ_CALLID);
3507	if((p->lij_seqno.h.present & UNI_IE_PRESENT) &&
3508	   uni_encode_ie(UNI_IE_LIJ_SEQNO, msg, (union uni_ieall *)&p->lij_seqno, cx))
3509		return (UNI_IE_LIJ_SEQNO);
3510	if((p->unrec.h.present & UNI_IE_PRESENT) &&
3511	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
3512		return (UNI_IE_UNREC);
3513
3514	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
3515	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
3516
3517	return (0);
3518}
3519
3520static int
3521decode_leaf_setup_req(struct uni_leaf_setup_req *out, struct uni_msg *msg,
3522    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
3523    struct unicx *cx)
3524{
3525	u_int i;
3526
3527	switch (ie) {
3528
3529	  case UNI_IE_TNS:
3530		for(i = 0; i < UNI_NUM_IE_TNS; i++)
3531			if (!IE_ISPRESENT(out->tns[i])) {
3532				out->tns[i].h = *hdr;
3533				if (hdr->present & UNI_IE_ERROR)
3534					return (DEC_ERR);
3535				if(uni_decode_ie_body(UNI_IE_TNS, (union uni_ieall *)&out->tns[i], msg, ielen, cx))
3536					return (DEC_ERR);
3537				break;
3538			}
3539		break;
3540
3541	  case UNI_IE_CALLING:
3542		out->calling.h = *hdr;
3543		if (hdr->present & UNI_IE_ERROR)
3544			return (DEC_ERR);
3545		if(uni_decode_ie_body(UNI_IE_CALLING, (union uni_ieall *)&out->calling, msg, ielen, cx))
3546			return (DEC_ERR);
3547		break;
3548
3549	  case UNI_IE_CALLINGSUB:
3550		for(i = 0; i < UNI_NUM_IE_CALLINGSUB; i++)
3551			if (!IE_ISPRESENT(out->callingsub[i])) {
3552				out->callingsub[i].h = *hdr;
3553				if (hdr->present & UNI_IE_ERROR)
3554					return (DEC_ERR);
3555				if(uni_decode_ie_body(UNI_IE_CALLINGSUB, (union uni_ieall *)&out->callingsub[i], msg, ielen, cx))
3556					return (DEC_ERR);
3557				break;
3558			}
3559		break;
3560
3561	  case UNI_IE_CALLED:
3562		out->called.h = *hdr;
3563		if (hdr->present & UNI_IE_ERROR)
3564			return (DEC_ERR);
3565		if(uni_decode_ie_body(UNI_IE_CALLED, (union uni_ieall *)&out->called, msg, ielen, cx))
3566			return (DEC_ERR);
3567		break;
3568
3569	  case UNI_IE_CALLEDSUB:
3570		for(i = 0; i < UNI_NUM_IE_CALLEDSUB; i++)
3571			if (!IE_ISPRESENT(out->calledsub[i])) {
3572				out->calledsub[i].h = *hdr;
3573				if (hdr->present & UNI_IE_ERROR)
3574					return (DEC_ERR);
3575				if(uni_decode_ie_body(UNI_IE_CALLEDSUB, (union uni_ieall *)&out->calledsub[i], msg, ielen, cx))
3576					return (DEC_ERR);
3577				break;
3578			}
3579		break;
3580
3581	  case UNI_IE_LIJ_CALLID:
3582		out->lij_callid.h = *hdr;
3583		if (hdr->present & UNI_IE_ERROR)
3584			return (DEC_ERR);
3585		if(uni_decode_ie_body(UNI_IE_LIJ_CALLID, (union uni_ieall *)&out->lij_callid, msg, ielen, cx))
3586			return (DEC_ERR);
3587		break;
3588
3589	  case UNI_IE_LIJ_SEQNO:
3590		out->lij_seqno.h = *hdr;
3591		if (hdr->present & UNI_IE_ERROR)
3592			return (DEC_ERR);
3593		if(uni_decode_ie_body(UNI_IE_LIJ_SEQNO, (union uni_ieall *)&out->lij_seqno, msg, ielen, cx))
3594			return (DEC_ERR);
3595		break;
3596
3597	  case UNI_IE_UNREC:
3598		out->unrec.h = *hdr;
3599		if (hdr->present & UNI_IE_ERROR)
3600			return (DEC_ERR);
3601		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
3602			return (DEC_ERR);
3603		break;
3604
3605	  default:
3606		return (DEC_ILL);
3607	}
3608	return (DEC_OK);
3609}
3610
3611static const struct msgdecl decl_leaf_setup_req = {
3612	0,
3613	"leaf_setup_req",
3614	(uni_msg_print_f)print_leaf_setup_req,
3615	(uni_msg_check_f)check_leaf_setup_req,
3616	(uni_msg_encode_f)encode_leaf_setup_req,
3617	(uni_msg_decode_f)decode_leaf_setup_req
3618};
3619
3620static void
3621print_leaf_setup_fail(struct uni_leaf_setup_fail *msg, struct unicx *cx)
3622{
3623	u_int i;
3624
3625	if(msg->cause.h.present & UNI_IE_PRESENT)
3626		uni_print_ie_internal(UNI_IE_CAUSE, (union uni_ieall *)&msg->cause, cx);
3627	if(msg->called.h.present & UNI_IE_PRESENT)
3628		uni_print_ie_internal(UNI_IE_CALLED, (union uni_ieall *)&msg->called, cx);
3629	if(msg->calledsub.h.present & UNI_IE_PRESENT)
3630		uni_print_ie_internal(UNI_IE_CALLEDSUB, (union uni_ieall *)&msg->calledsub, cx);
3631	if(msg->lij_seqno.h.present & UNI_IE_PRESENT)
3632		uni_print_ie_internal(UNI_IE_LIJ_SEQNO, (union uni_ieall *)&msg->lij_seqno, cx);
3633	for(i = 0; i < UNI_NUM_IE_TNS; i++)
3634		if(msg->tns[i].h.present & UNI_IE_PRESENT)
3635			uni_print_ie_internal(UNI_IE_TNS, (union uni_ieall *)&msg->tns[i], cx);
3636	if(msg->unrec.h.present & UNI_IE_PRESENT)
3637		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
3638}
3639
3640static int
3641check_leaf_setup_fail(struct uni_leaf_setup_fail *m, struct unicx *cx)
3642{
3643	int ret = 0;
3644	u_int i;
3645
3646	ret |= uni_check_ie(UNI_IE_CAUSE, (union uni_ieall *)&m->cause, cx);
3647	ret |= uni_check_ie(UNI_IE_CALLED, (union uni_ieall *)&m->called, cx);
3648	ret |= uni_check_ie(UNI_IE_CALLEDSUB, (union uni_ieall *)&m->calledsub, cx);
3649	ret |= uni_check_ie(UNI_IE_LIJ_SEQNO, (union uni_ieall *)&m->lij_seqno, cx);
3650	for(i = 0; i < UNI_NUM_IE_TNS ; i++) {
3651		ret |= uni_check_ie(UNI_IE_TNS, (union uni_ieall *)&m->tns[i], cx);
3652	}
3653	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
3654
3655	return ret;
3656}
3657
3658static int
3659encode_leaf_setup_fail(struct uni_msg *msg, struct uni_leaf_setup_fail *p, struct unicx *cx)
3660{
3661	u_int mlen;
3662	u_int i;
3663
3664	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_LEAF_SETUP_FAIL, cx, &mlen))
3665		return (-2);
3666
3667	if((p->cause.h.present & UNI_IE_PRESENT) &&
3668	   uni_encode_ie(UNI_IE_CAUSE, msg, (union uni_ieall *)&p->cause, cx))
3669		return (UNI_IE_CAUSE);
3670	if((p->called.h.present & UNI_IE_PRESENT) &&
3671	   uni_encode_ie(UNI_IE_CALLED, msg, (union uni_ieall *)&p->called, cx))
3672		return (UNI_IE_CALLED);
3673	if((p->calledsub.h.present & UNI_IE_PRESENT) &&
3674	   uni_encode_ie(UNI_IE_CALLEDSUB, msg, (union uni_ieall *)&p->calledsub, cx))
3675		return (UNI_IE_CALLEDSUB);
3676	if((p->lij_seqno.h.present & UNI_IE_PRESENT) &&
3677	   uni_encode_ie(UNI_IE_LIJ_SEQNO, msg, (union uni_ieall *)&p->lij_seqno, cx))
3678		return (UNI_IE_LIJ_SEQNO);
3679	for(i = 0; i < UNI_NUM_IE_TNS; i++)
3680		if((p->tns[i].h.present & UNI_IE_PRESENT) &&
3681		   uni_encode_ie(UNI_IE_TNS, msg, (union uni_ieall *)&p->tns[i], cx))
3682		return ((i << 16) + UNI_IE_TNS);
3683	if((p->unrec.h.present & UNI_IE_PRESENT) &&
3684	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
3685		return (UNI_IE_UNREC);
3686
3687	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
3688	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
3689
3690	return (0);
3691}
3692
3693static int
3694decode_leaf_setup_fail(struct uni_leaf_setup_fail *out, struct uni_msg *msg,
3695    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
3696    struct unicx *cx)
3697{
3698	u_int i;
3699
3700	switch (ie) {
3701
3702	  case UNI_IE_CAUSE:
3703		out->cause.h = *hdr;
3704		if (hdr->present & UNI_IE_ERROR)
3705			return (DEC_ERR);
3706		if(uni_decode_ie_body(UNI_IE_CAUSE, (union uni_ieall *)&out->cause, msg, ielen, cx))
3707			return (DEC_ERR);
3708		break;
3709
3710	  case UNI_IE_CALLED:
3711		out->called.h = *hdr;
3712		if (hdr->present & UNI_IE_ERROR)
3713			return (DEC_ERR);
3714		if(uni_decode_ie_body(UNI_IE_CALLED, (union uni_ieall *)&out->called, msg, ielen, cx))
3715			return (DEC_ERR);
3716		break;
3717
3718	  case UNI_IE_CALLEDSUB:
3719		out->calledsub.h = *hdr;
3720		if (hdr->present & UNI_IE_ERROR)
3721			return (DEC_ERR);
3722		if(uni_decode_ie_body(UNI_IE_CALLEDSUB, (union uni_ieall *)&out->calledsub, msg, ielen, cx))
3723			return (DEC_ERR);
3724		break;
3725
3726	  case UNI_IE_LIJ_SEQNO:
3727		out->lij_seqno.h = *hdr;
3728		if (hdr->present & UNI_IE_ERROR)
3729			return (DEC_ERR);
3730		if(uni_decode_ie_body(UNI_IE_LIJ_SEQNO, (union uni_ieall *)&out->lij_seqno, msg, ielen, cx))
3731			return (DEC_ERR);
3732		break;
3733
3734	  case UNI_IE_TNS:
3735		for(i = 0; i < UNI_NUM_IE_TNS; i++)
3736			if (!IE_ISPRESENT(out->tns[i])) {
3737				out->tns[i].h = *hdr;
3738				if (hdr->present & UNI_IE_ERROR)
3739					return (DEC_ERR);
3740				if(uni_decode_ie_body(UNI_IE_TNS, (union uni_ieall *)&out->tns[i], msg, ielen, cx))
3741					return (DEC_ERR);
3742				break;
3743			}
3744		break;
3745
3746	  case UNI_IE_UNREC:
3747		out->unrec.h = *hdr;
3748		if (hdr->present & UNI_IE_ERROR)
3749			return (DEC_ERR);
3750		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
3751			return (DEC_ERR);
3752		break;
3753
3754	  default:
3755		return (DEC_ILL);
3756	}
3757	return (DEC_OK);
3758}
3759
3760static const struct msgdecl decl_leaf_setup_fail = {
3761	0,
3762	"leaf_setup_fail",
3763	(uni_msg_print_f)print_leaf_setup_fail,
3764	(uni_msg_check_f)check_leaf_setup_fail,
3765	(uni_msg_encode_f)encode_leaf_setup_fail,
3766	(uni_msg_decode_f)decode_leaf_setup_fail
3767};
3768
3769static void
3770print_cobisetup(struct uni_cobisetup *msg, struct unicx *cx)
3771{
3772	if(msg->facility.h.present & UNI_IE_PRESENT)
3773		uni_print_ie_internal(UNI_IE_FACILITY, (union uni_ieall *)&msg->facility, cx);
3774	if(msg->called.h.present & UNI_IE_PRESENT)
3775		uni_print_ie_internal(UNI_IE_CALLED, (union uni_ieall *)&msg->called, cx);
3776	if(msg->calledsub.h.present & UNI_IE_PRESENT)
3777		uni_print_ie_internal(UNI_IE_CALLEDSUB, (union uni_ieall *)&msg->calledsub, cx);
3778	if(msg->calling.h.present & UNI_IE_PRESENT)
3779		uni_print_ie_internal(UNI_IE_CALLING, (union uni_ieall *)&msg->calling, cx);
3780	if(msg->notify.h.present & UNI_IE_PRESENT)
3781		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
3782	if(msg->unrec.h.present & UNI_IE_PRESENT)
3783		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
3784}
3785
3786static int
3787check_cobisetup(struct uni_cobisetup *m, struct unicx *cx)
3788{
3789	int ret = 0;
3790
3791	ret |= uni_check_ie(UNI_IE_FACILITY, (union uni_ieall *)&m->facility, cx);
3792	ret |= uni_check_ie(UNI_IE_CALLED, (union uni_ieall *)&m->called, cx);
3793	ret |= uni_check_ie(UNI_IE_CALLEDSUB, (union uni_ieall *)&m->calledsub, cx);
3794	ret |= uni_check_ie(UNI_IE_CALLING, (union uni_ieall *)&m->calling, cx);
3795	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
3796	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
3797
3798	return ret;
3799}
3800
3801static int
3802encode_cobisetup(struct uni_msg *msg, struct uni_cobisetup *p, struct unicx *cx)
3803{
3804	u_int mlen;
3805
3806	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_COBISETUP, cx, &mlen))
3807		return (-2);
3808
3809	if((p->facility.h.present & UNI_IE_PRESENT) &&
3810	   uni_encode_ie(UNI_IE_FACILITY, msg, (union uni_ieall *)&p->facility, cx))
3811		return (UNI_IE_FACILITY);
3812	if((p->called.h.present & UNI_IE_PRESENT) &&
3813	   uni_encode_ie(UNI_IE_CALLED, msg, (union uni_ieall *)&p->called, cx))
3814		return (UNI_IE_CALLED);
3815	if((p->calledsub.h.present & UNI_IE_PRESENT) &&
3816	   uni_encode_ie(UNI_IE_CALLEDSUB, msg, (union uni_ieall *)&p->calledsub, cx))
3817		return (UNI_IE_CALLEDSUB);
3818	if((p->calling.h.present & UNI_IE_PRESENT) &&
3819	   uni_encode_ie(UNI_IE_CALLING, msg, (union uni_ieall *)&p->calling, cx))
3820		return (UNI_IE_CALLING);
3821	if((p->notify.h.present & UNI_IE_PRESENT) &&
3822	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
3823		return (UNI_IE_NOTIFY);
3824	if((p->unrec.h.present & UNI_IE_PRESENT) &&
3825	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
3826		return (UNI_IE_UNREC);
3827
3828	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
3829	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
3830
3831	return (0);
3832}
3833
3834static int
3835decode_cobisetup(struct uni_cobisetup *out, struct uni_msg *msg,
3836    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
3837    struct unicx *cx)
3838{
3839	switch (ie) {
3840
3841	  case UNI_IE_FACILITY:
3842		out->facility.h = *hdr;
3843		if (hdr->present & UNI_IE_ERROR)
3844			return (DEC_ERR);
3845		if(uni_decode_ie_body(UNI_IE_FACILITY, (union uni_ieall *)&out->facility, msg, ielen, cx))
3846			return (DEC_ERR);
3847		break;
3848
3849	  case UNI_IE_CALLED:
3850		out->called.h = *hdr;
3851		if (hdr->present & UNI_IE_ERROR)
3852			return (DEC_ERR);
3853		if(uni_decode_ie_body(UNI_IE_CALLED, (union uni_ieall *)&out->called, msg, ielen, cx))
3854			return (DEC_ERR);
3855		break;
3856
3857	  case UNI_IE_CALLEDSUB:
3858		out->calledsub.h = *hdr;
3859		if (hdr->present & UNI_IE_ERROR)
3860			return (DEC_ERR);
3861		if(uni_decode_ie_body(UNI_IE_CALLEDSUB, (union uni_ieall *)&out->calledsub, msg, ielen, cx))
3862			return (DEC_ERR);
3863		break;
3864
3865	  case UNI_IE_CALLING:
3866		out->calling.h = *hdr;
3867		if (hdr->present & UNI_IE_ERROR)
3868			return (DEC_ERR);
3869		if(uni_decode_ie_body(UNI_IE_CALLING, (union uni_ieall *)&out->calling, msg, ielen, cx))
3870			return (DEC_ERR);
3871		break;
3872
3873	  case UNI_IE_NOTIFY:
3874		out->notify.h = *hdr;
3875		if (hdr->present & UNI_IE_ERROR)
3876			return (DEC_ERR);
3877		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
3878			return (DEC_ERR);
3879		break;
3880
3881	  case UNI_IE_UNREC:
3882		out->unrec.h = *hdr;
3883		if (hdr->present & UNI_IE_ERROR)
3884			return (DEC_ERR);
3885		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
3886			return (DEC_ERR);
3887		break;
3888
3889	  default:
3890		return (DEC_ILL);
3891	}
3892	return (DEC_OK);
3893}
3894
3895static const struct msgdecl decl_cobisetup = {
3896	0,
3897	"cobisetup",
3898	(uni_msg_print_f)print_cobisetup,
3899	(uni_msg_check_f)check_cobisetup,
3900	(uni_msg_encode_f)encode_cobisetup,
3901	(uni_msg_decode_f)decode_cobisetup
3902};
3903
3904static void
3905print_facility(struct uni_facility *msg, struct unicx *cx)
3906{
3907	if(msg->facility.h.present & UNI_IE_PRESENT)
3908		uni_print_ie_internal(UNI_IE_FACILITY, (union uni_ieall *)&msg->facility, cx);
3909	if(msg->called.h.present & UNI_IE_PRESENT)
3910		uni_print_ie_internal(UNI_IE_CALLED, (union uni_ieall *)&msg->called, cx);
3911	if(msg->calledsub.h.present & UNI_IE_PRESENT)
3912		uni_print_ie_internal(UNI_IE_CALLEDSUB, (union uni_ieall *)&msg->calledsub, cx);
3913	if(msg->calling.h.present & UNI_IE_PRESENT)
3914		uni_print_ie_internal(UNI_IE_CALLING, (union uni_ieall *)&msg->calling, cx);
3915	if(msg->notify.h.present & UNI_IE_PRESENT)
3916		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
3917	if(msg->unrec.h.present & UNI_IE_PRESENT)
3918		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
3919}
3920
3921static int
3922check_facility(struct uni_facility *m, struct unicx *cx)
3923{
3924	int ret = 0;
3925
3926	ret |= uni_check_ie(UNI_IE_FACILITY, (union uni_ieall *)&m->facility, cx);
3927	ret |= uni_check_ie(UNI_IE_CALLED, (union uni_ieall *)&m->called, cx);
3928	ret |= uni_check_ie(UNI_IE_CALLEDSUB, (union uni_ieall *)&m->calledsub, cx);
3929	ret |= uni_check_ie(UNI_IE_CALLING, (union uni_ieall *)&m->calling, cx);
3930	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
3931	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
3932
3933	return ret;
3934}
3935
3936static int
3937encode_facility(struct uni_msg *msg, struct uni_facility *p, struct unicx *cx)
3938{
3939	u_int mlen;
3940
3941	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_FACILITY, cx, &mlen))
3942		return (-2);
3943
3944	if((p->facility.h.present & UNI_IE_PRESENT) &&
3945	   uni_encode_ie(UNI_IE_FACILITY, msg, (union uni_ieall *)&p->facility, cx))
3946		return (UNI_IE_FACILITY);
3947	if((p->called.h.present & UNI_IE_PRESENT) &&
3948	   uni_encode_ie(UNI_IE_CALLED, msg, (union uni_ieall *)&p->called, cx))
3949		return (UNI_IE_CALLED);
3950	if((p->calledsub.h.present & UNI_IE_PRESENT) &&
3951	   uni_encode_ie(UNI_IE_CALLEDSUB, msg, (union uni_ieall *)&p->calledsub, cx))
3952		return (UNI_IE_CALLEDSUB);
3953	if((p->calling.h.present & UNI_IE_PRESENT) &&
3954	   uni_encode_ie(UNI_IE_CALLING, msg, (union uni_ieall *)&p->calling, cx))
3955		return (UNI_IE_CALLING);
3956	if((p->notify.h.present & UNI_IE_PRESENT) &&
3957	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
3958		return (UNI_IE_NOTIFY);
3959	if((p->unrec.h.present & UNI_IE_PRESENT) &&
3960	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
3961		return (UNI_IE_UNREC);
3962
3963	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
3964	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
3965
3966	return (0);
3967}
3968
3969static int
3970decode_facility(struct uni_facility *out, struct uni_msg *msg,
3971    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
3972    struct unicx *cx)
3973{
3974	switch (ie) {
3975
3976	  case UNI_IE_FACILITY:
3977		out->facility.h = *hdr;
3978		if (hdr->present & UNI_IE_ERROR)
3979			return (DEC_ERR);
3980		if(uni_decode_ie_body(UNI_IE_FACILITY, (union uni_ieall *)&out->facility, msg, ielen, cx))
3981			return (DEC_ERR);
3982		break;
3983
3984	  case UNI_IE_CALLED:
3985		out->called.h = *hdr;
3986		if (hdr->present & UNI_IE_ERROR)
3987			return (DEC_ERR);
3988		if(uni_decode_ie_body(UNI_IE_CALLED, (union uni_ieall *)&out->called, msg, ielen, cx))
3989			return (DEC_ERR);
3990		break;
3991
3992	  case UNI_IE_CALLEDSUB:
3993		out->calledsub.h = *hdr;
3994		if (hdr->present & UNI_IE_ERROR)
3995			return (DEC_ERR);
3996		if(uni_decode_ie_body(UNI_IE_CALLEDSUB, (union uni_ieall *)&out->calledsub, msg, ielen, cx))
3997			return (DEC_ERR);
3998		break;
3999
4000	  case UNI_IE_CALLING:
4001		out->calling.h = *hdr;
4002		if (hdr->present & UNI_IE_ERROR)
4003			return (DEC_ERR);
4004		if(uni_decode_ie_body(UNI_IE_CALLING, (union uni_ieall *)&out->calling, msg, ielen, cx))
4005			return (DEC_ERR);
4006		break;
4007
4008	  case UNI_IE_NOTIFY:
4009		out->notify.h = *hdr;
4010		if (hdr->present & UNI_IE_ERROR)
4011			return (DEC_ERR);
4012		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
4013			return (DEC_ERR);
4014		break;
4015
4016	  case UNI_IE_UNREC:
4017		out->unrec.h = *hdr;
4018		if (hdr->present & UNI_IE_ERROR)
4019			return (DEC_ERR);
4020		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
4021			return (DEC_ERR);
4022		break;
4023
4024	  default:
4025		return (DEC_ILL);
4026	}
4027	return (DEC_OK);
4028}
4029
4030static const struct msgdecl decl_facility = {
4031	0,
4032	"facility",
4033	(uni_msg_print_f)print_facility,
4034	(uni_msg_check_f)check_facility,
4035	(uni_msg_encode_f)encode_facility,
4036	(uni_msg_decode_f)decode_facility
4037};
4038
4039static void
4040print_modify_req(struct uni_modify_req *msg, struct unicx *cx)
4041{
4042	u_int i;
4043
4044	if(msg->traffic.h.present & UNI_IE_PRESENT)
4045		uni_print_ie_internal(UNI_IE_TRAFFIC, (union uni_ieall *)&msg->traffic, cx);
4046	if(msg->atraffic.h.present & UNI_IE_PRESENT)
4047		uni_print_ie_internal(UNI_IE_ATRAFFIC, (union uni_ieall *)&msg->atraffic, cx);
4048	if(msg->mintraffic.h.present & UNI_IE_PRESENT)
4049		uni_print_ie_internal(UNI_IE_MINTRAFFIC, (union uni_ieall *)&msg->mintraffic, cx);
4050	if(msg->notify.h.present & UNI_IE_PRESENT)
4051		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
4052	for(i = 0; i < UNI_NUM_IE_GIT; i++)
4053		if(msg->git[i].h.present & UNI_IE_PRESENT)
4054			uni_print_ie_internal(UNI_IE_GIT, (union uni_ieall *)&msg->git[i], cx);
4055	if(msg->unrec.h.present & UNI_IE_PRESENT)
4056		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
4057}
4058
4059static int
4060check_modify_req(struct uni_modify_req *m, struct unicx *cx)
4061{
4062	int ret = 0;
4063	u_int i;
4064
4065	ret |= uni_check_ie(UNI_IE_TRAFFIC, (union uni_ieall *)&m->traffic, cx);
4066	ret |= uni_check_ie(UNI_IE_ATRAFFIC, (union uni_ieall *)&m->atraffic, cx);
4067	ret |= uni_check_ie(UNI_IE_MINTRAFFIC, (union uni_ieall *)&m->mintraffic, cx);
4068	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
4069	for(i = 0; i < UNI_NUM_IE_GIT ; i++) {
4070		ret |= uni_check_ie(UNI_IE_GIT, (union uni_ieall *)&m->git[i], cx);
4071	}
4072	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
4073
4074	return ret;
4075}
4076
4077static int
4078encode_modify_req(struct uni_msg *msg, struct uni_modify_req *p, struct unicx *cx)
4079{
4080	u_int mlen;
4081	u_int i;
4082
4083	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_MODIFY_REQ, cx, &mlen))
4084		return (-2);
4085
4086	if((p->traffic.h.present & UNI_IE_PRESENT) &&
4087	   uni_encode_ie(UNI_IE_TRAFFIC, msg, (union uni_ieall *)&p->traffic, cx))
4088		return (UNI_IE_TRAFFIC);
4089	if((p->atraffic.h.present & UNI_IE_PRESENT) &&
4090	   uni_encode_ie(UNI_IE_ATRAFFIC, msg, (union uni_ieall *)&p->atraffic, cx))
4091		return (UNI_IE_ATRAFFIC);
4092	if((p->mintraffic.h.present & UNI_IE_PRESENT) &&
4093	   uni_encode_ie(UNI_IE_MINTRAFFIC, msg, (union uni_ieall *)&p->mintraffic, cx))
4094		return (UNI_IE_MINTRAFFIC);
4095	if((p->notify.h.present & UNI_IE_PRESENT) &&
4096	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
4097		return (UNI_IE_NOTIFY);
4098	for(i = 0; i < UNI_NUM_IE_GIT; i++)
4099		if((p->git[i].h.present & UNI_IE_PRESENT) &&
4100		   uni_encode_ie(UNI_IE_GIT, msg, (union uni_ieall *)&p->git[i], cx))
4101		return ((i << 16) + UNI_IE_GIT);
4102	if((p->unrec.h.present & UNI_IE_PRESENT) &&
4103	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
4104		return (UNI_IE_UNREC);
4105
4106	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
4107	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
4108
4109	return (0);
4110}
4111
4112static int
4113decode_modify_req(struct uni_modify_req *out, struct uni_msg *msg,
4114    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
4115    struct unicx *cx)
4116{
4117	u_int i;
4118
4119	switch (ie) {
4120
4121	  case UNI_IE_TRAFFIC:
4122		out->traffic.h = *hdr;
4123		if (hdr->present & UNI_IE_ERROR)
4124			return (DEC_ERR);
4125		if(uni_decode_ie_body(UNI_IE_TRAFFIC, (union uni_ieall *)&out->traffic, msg, ielen, cx))
4126			return (DEC_ERR);
4127		break;
4128
4129	  case UNI_IE_ATRAFFIC:
4130		out->atraffic.h = *hdr;
4131		if (hdr->present & UNI_IE_ERROR)
4132			return (DEC_ERR);
4133		if(uni_decode_ie_body(UNI_IE_ATRAFFIC, (union uni_ieall *)&out->atraffic, msg, ielen, cx))
4134			return (DEC_ERR);
4135		break;
4136
4137	  case UNI_IE_MINTRAFFIC:
4138		out->mintraffic.h = *hdr;
4139		if (hdr->present & UNI_IE_ERROR)
4140			return (DEC_ERR);
4141		if(uni_decode_ie_body(UNI_IE_MINTRAFFIC, (union uni_ieall *)&out->mintraffic, msg, ielen, cx))
4142			return (DEC_ERR);
4143		break;
4144
4145	  case UNI_IE_NOTIFY:
4146		out->notify.h = *hdr;
4147		if (hdr->present & UNI_IE_ERROR)
4148			return (DEC_ERR);
4149		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
4150			return (DEC_ERR);
4151		break;
4152
4153	  case UNI_IE_GIT:
4154		for(i = 0; i < UNI_NUM_IE_GIT; i++)
4155			if (!IE_ISPRESENT(out->git[i])) {
4156				out->git[i].h = *hdr;
4157				if (hdr->present & UNI_IE_ERROR)
4158					return (DEC_ERR);
4159				if(uni_decode_ie_body(UNI_IE_GIT, (union uni_ieall *)&out->git[i], msg, ielen, cx))
4160					return (DEC_ERR);
4161				break;
4162			}
4163		break;
4164
4165	  case UNI_IE_UNREC:
4166		out->unrec.h = *hdr;
4167		if (hdr->present & UNI_IE_ERROR)
4168			return (DEC_ERR);
4169		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
4170			return (DEC_ERR);
4171		break;
4172
4173	  default:
4174		return (DEC_ILL);
4175	}
4176	return (DEC_OK);
4177}
4178
4179static const struct msgdecl decl_modify_req = {
4180	0,
4181	"modify_req",
4182	(uni_msg_print_f)print_modify_req,
4183	(uni_msg_check_f)check_modify_req,
4184	(uni_msg_encode_f)encode_modify_req,
4185	(uni_msg_decode_f)decode_modify_req
4186};
4187
4188static void
4189print_modify_ack(struct uni_modify_ack *msg, struct unicx *cx)
4190{
4191	u_int i;
4192
4193	if(msg->report.h.present & UNI_IE_PRESENT)
4194		uni_print_ie_internal(UNI_IE_REPORT, (union uni_ieall *)&msg->report, cx);
4195	if(msg->traffic.h.present & UNI_IE_PRESENT)
4196		uni_print_ie_internal(UNI_IE_TRAFFIC, (union uni_ieall *)&msg->traffic, cx);
4197	if(msg->notify.h.present & UNI_IE_PRESENT)
4198		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
4199	for(i = 0; i < UNI_NUM_IE_GIT; i++)
4200		if(msg->git[i].h.present & UNI_IE_PRESENT)
4201			uni_print_ie_internal(UNI_IE_GIT, (union uni_ieall *)&msg->git[i], cx);
4202	if(msg->unrec.h.present & UNI_IE_PRESENT)
4203		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
4204}
4205
4206static int
4207check_modify_ack(struct uni_modify_ack *m, struct unicx *cx)
4208{
4209	int ret = 0;
4210	u_int i;
4211
4212	ret |= uni_check_ie(UNI_IE_REPORT, (union uni_ieall *)&m->report, cx);
4213	ret |= uni_check_ie(UNI_IE_TRAFFIC, (union uni_ieall *)&m->traffic, cx);
4214	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
4215	for(i = 0; i < UNI_NUM_IE_GIT ; i++) {
4216		ret |= uni_check_ie(UNI_IE_GIT, (union uni_ieall *)&m->git[i], cx);
4217	}
4218	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
4219
4220	return ret;
4221}
4222
4223static int
4224encode_modify_ack(struct uni_msg *msg, struct uni_modify_ack *p, struct unicx *cx)
4225{
4226	u_int mlen;
4227	u_int i;
4228
4229	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_MODIFY_ACK, cx, &mlen))
4230		return (-2);
4231
4232	if((p->report.h.present & UNI_IE_PRESENT) &&
4233	   uni_encode_ie(UNI_IE_REPORT, msg, (union uni_ieall *)&p->report, cx))
4234		return (UNI_IE_REPORT);
4235	if((p->traffic.h.present & UNI_IE_PRESENT) &&
4236	   uni_encode_ie(UNI_IE_TRAFFIC, msg, (union uni_ieall *)&p->traffic, cx))
4237		return (UNI_IE_TRAFFIC);
4238	if((p->notify.h.present & UNI_IE_PRESENT) &&
4239	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
4240		return (UNI_IE_NOTIFY);
4241	for(i = 0; i < UNI_NUM_IE_GIT; i++)
4242		if((p->git[i].h.present & UNI_IE_PRESENT) &&
4243		   uni_encode_ie(UNI_IE_GIT, msg, (union uni_ieall *)&p->git[i], cx))
4244		return ((i << 16) + UNI_IE_GIT);
4245	if((p->unrec.h.present & UNI_IE_PRESENT) &&
4246	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
4247		return (UNI_IE_UNREC);
4248
4249	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
4250	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
4251
4252	return (0);
4253}
4254
4255static int
4256decode_modify_ack(struct uni_modify_ack *out, struct uni_msg *msg,
4257    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
4258    struct unicx *cx)
4259{
4260	u_int i;
4261
4262	switch (ie) {
4263
4264	  case UNI_IE_REPORT:
4265		out->report.h = *hdr;
4266		if (hdr->present & UNI_IE_ERROR)
4267			return (DEC_ERR);
4268		if(uni_decode_ie_body(UNI_IE_REPORT, (union uni_ieall *)&out->report, msg, ielen, cx))
4269			return (DEC_ERR);
4270		break;
4271
4272	  case UNI_IE_TRAFFIC:
4273		out->traffic.h = *hdr;
4274		if (hdr->present & UNI_IE_ERROR)
4275			return (DEC_ERR);
4276		if(uni_decode_ie_body(UNI_IE_TRAFFIC, (union uni_ieall *)&out->traffic, msg, ielen, cx))
4277			return (DEC_ERR);
4278		break;
4279
4280	  case UNI_IE_NOTIFY:
4281		out->notify.h = *hdr;
4282		if (hdr->present & UNI_IE_ERROR)
4283			return (DEC_ERR);
4284		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
4285			return (DEC_ERR);
4286		break;
4287
4288	  case UNI_IE_GIT:
4289		for(i = 0; i < UNI_NUM_IE_GIT; i++)
4290			if (!IE_ISPRESENT(out->git[i])) {
4291				out->git[i].h = *hdr;
4292				if (hdr->present & UNI_IE_ERROR)
4293					return (DEC_ERR);
4294				if(uni_decode_ie_body(UNI_IE_GIT, (union uni_ieall *)&out->git[i], msg, ielen, cx))
4295					return (DEC_ERR);
4296				break;
4297			}
4298		break;
4299
4300	  case UNI_IE_UNREC:
4301		out->unrec.h = *hdr;
4302		if (hdr->present & UNI_IE_ERROR)
4303			return (DEC_ERR);
4304		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
4305			return (DEC_ERR);
4306		break;
4307
4308	  default:
4309		return (DEC_ILL);
4310	}
4311	return (DEC_OK);
4312}
4313
4314static const struct msgdecl decl_modify_ack = {
4315	0,
4316	"modify_ack",
4317	(uni_msg_print_f)print_modify_ack,
4318	(uni_msg_check_f)check_modify_ack,
4319	(uni_msg_encode_f)encode_modify_ack,
4320	(uni_msg_decode_f)decode_modify_ack
4321};
4322
4323static void
4324print_modify_rej(struct uni_modify_rej *msg, struct unicx *cx)
4325{
4326	u_int i;
4327
4328	if(msg->cause.h.present & UNI_IE_PRESENT)
4329		uni_print_ie_internal(UNI_IE_CAUSE, (union uni_ieall *)&msg->cause, cx);
4330	if(msg->notify.h.present & UNI_IE_PRESENT)
4331		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
4332	for(i = 0; i < UNI_NUM_IE_GIT; i++)
4333		if(msg->git[i].h.present & UNI_IE_PRESENT)
4334			uni_print_ie_internal(UNI_IE_GIT, (union uni_ieall *)&msg->git[i], cx);
4335	if(msg->unrec.h.present & UNI_IE_PRESENT)
4336		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
4337}
4338
4339static int
4340check_modify_rej(struct uni_modify_rej *m, struct unicx *cx)
4341{
4342	int ret = 0;
4343	u_int i;
4344
4345	ret |= uni_check_ie(UNI_IE_CAUSE, (union uni_ieall *)&m->cause, cx);
4346	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
4347	for(i = 0; i < UNI_NUM_IE_GIT ; i++) {
4348		ret |= uni_check_ie(UNI_IE_GIT, (union uni_ieall *)&m->git[i], cx);
4349	}
4350	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
4351
4352	return ret;
4353}
4354
4355static int
4356encode_modify_rej(struct uni_msg *msg, struct uni_modify_rej *p, struct unicx *cx)
4357{
4358	u_int mlen;
4359	u_int i;
4360
4361	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_MODIFY_REJ, cx, &mlen))
4362		return (-2);
4363
4364	if((p->cause.h.present & UNI_IE_PRESENT) &&
4365	   uni_encode_ie(UNI_IE_CAUSE, msg, (union uni_ieall *)&p->cause, cx))
4366		return (UNI_IE_CAUSE);
4367	if((p->notify.h.present & UNI_IE_PRESENT) &&
4368	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
4369		return (UNI_IE_NOTIFY);
4370	for(i = 0; i < UNI_NUM_IE_GIT; i++)
4371		if((p->git[i].h.present & UNI_IE_PRESENT) &&
4372		   uni_encode_ie(UNI_IE_GIT, msg, (union uni_ieall *)&p->git[i], cx))
4373		return ((i << 16) + UNI_IE_GIT);
4374	if((p->unrec.h.present & UNI_IE_PRESENT) &&
4375	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
4376		return (UNI_IE_UNREC);
4377
4378	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
4379	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
4380
4381	return (0);
4382}
4383
4384static int
4385decode_modify_rej(struct uni_modify_rej *out, struct uni_msg *msg,
4386    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
4387    struct unicx *cx)
4388{
4389	u_int i;
4390
4391	switch (ie) {
4392
4393	  case UNI_IE_CAUSE:
4394		out->cause.h = *hdr;
4395		if (hdr->present & UNI_IE_ERROR)
4396			return (DEC_ERR);
4397		if(uni_decode_ie_body(UNI_IE_CAUSE, (union uni_ieall *)&out->cause, msg, ielen, cx))
4398			return (DEC_ERR);
4399		break;
4400
4401	  case UNI_IE_NOTIFY:
4402		out->notify.h = *hdr;
4403		if (hdr->present & UNI_IE_ERROR)
4404			return (DEC_ERR);
4405		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
4406			return (DEC_ERR);
4407		break;
4408
4409	  case UNI_IE_GIT:
4410		for(i = 0; i < UNI_NUM_IE_GIT; i++)
4411			if (!IE_ISPRESENT(out->git[i])) {
4412				out->git[i].h = *hdr;
4413				if (hdr->present & UNI_IE_ERROR)
4414					return (DEC_ERR);
4415				if(uni_decode_ie_body(UNI_IE_GIT, (union uni_ieall *)&out->git[i], msg, ielen, cx))
4416					return (DEC_ERR);
4417				break;
4418			}
4419		break;
4420
4421	  case UNI_IE_UNREC:
4422		out->unrec.h = *hdr;
4423		if (hdr->present & UNI_IE_ERROR)
4424			return (DEC_ERR);
4425		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
4426			return (DEC_ERR);
4427		break;
4428
4429	  default:
4430		return (DEC_ILL);
4431	}
4432	return (DEC_OK);
4433}
4434
4435static const struct msgdecl decl_modify_rej = {
4436	0,
4437	"modify_rej",
4438	(uni_msg_print_f)print_modify_rej,
4439	(uni_msg_check_f)check_modify_rej,
4440	(uni_msg_encode_f)encode_modify_rej,
4441	(uni_msg_decode_f)decode_modify_rej
4442};
4443
4444static void
4445print_conn_avail(struct uni_conn_avail *msg, struct unicx *cx)
4446{
4447	u_int i;
4448
4449	if(msg->notify.h.present & UNI_IE_PRESENT)
4450		uni_print_ie_internal(UNI_IE_NOTIFY, (union uni_ieall *)&msg->notify, cx);
4451	for(i = 0; i < UNI_NUM_IE_GIT; i++)
4452		if(msg->git[i].h.present & UNI_IE_PRESENT)
4453			uni_print_ie_internal(UNI_IE_GIT, (union uni_ieall *)&msg->git[i], cx);
4454	if(msg->report.h.present & UNI_IE_PRESENT)
4455		uni_print_ie_internal(UNI_IE_REPORT, (union uni_ieall *)&msg->report, cx);
4456	if(msg->unrec.h.present & UNI_IE_PRESENT)
4457		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
4458}
4459
4460static int
4461check_conn_avail(struct uni_conn_avail *m, struct unicx *cx)
4462{
4463	int ret = 0;
4464	u_int i;
4465
4466	ret |= uni_check_ie(UNI_IE_NOTIFY, (union uni_ieall *)&m->notify, cx);
4467	for(i = 0; i < UNI_NUM_IE_GIT ; i++) {
4468		ret |= uni_check_ie(UNI_IE_GIT, (union uni_ieall *)&m->git[i], cx);
4469	}
4470	ret |= uni_check_ie(UNI_IE_REPORT, (union uni_ieall *)&m->report, cx);
4471	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
4472
4473	return ret;
4474}
4475
4476static int
4477encode_conn_avail(struct uni_msg *msg, struct uni_conn_avail *p, struct unicx *cx)
4478{
4479	u_int mlen;
4480	u_int i;
4481
4482	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_CONN_AVAIL, cx, &mlen))
4483		return (-2);
4484
4485	if((p->notify.h.present & UNI_IE_PRESENT) &&
4486	   uni_encode_ie(UNI_IE_NOTIFY, msg, (union uni_ieall *)&p->notify, cx))
4487		return (UNI_IE_NOTIFY);
4488	for(i = 0; i < UNI_NUM_IE_GIT; i++)
4489		if((p->git[i].h.present & UNI_IE_PRESENT) &&
4490		   uni_encode_ie(UNI_IE_GIT, msg, (union uni_ieall *)&p->git[i], cx))
4491		return ((i << 16) + UNI_IE_GIT);
4492	if((p->report.h.present & UNI_IE_PRESENT) &&
4493	   uni_encode_ie(UNI_IE_REPORT, msg, (union uni_ieall *)&p->report, cx))
4494		return (UNI_IE_REPORT);
4495	if((p->unrec.h.present & UNI_IE_PRESENT) &&
4496	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
4497		return (UNI_IE_UNREC);
4498
4499	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
4500	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
4501
4502	return (0);
4503}
4504
4505static int
4506decode_conn_avail(struct uni_conn_avail *out, struct uni_msg *msg,
4507    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
4508    struct unicx *cx)
4509{
4510	u_int i;
4511
4512	switch (ie) {
4513
4514	  case UNI_IE_NOTIFY:
4515		out->notify.h = *hdr;
4516		if (hdr->present & UNI_IE_ERROR)
4517			return (DEC_ERR);
4518		if(uni_decode_ie_body(UNI_IE_NOTIFY, (union uni_ieall *)&out->notify, msg, ielen, cx))
4519			return (DEC_ERR);
4520		break;
4521
4522	  case UNI_IE_GIT:
4523		for(i = 0; i < UNI_NUM_IE_GIT; i++)
4524			if (!IE_ISPRESENT(out->git[i])) {
4525				out->git[i].h = *hdr;
4526				if (hdr->present & UNI_IE_ERROR)
4527					return (DEC_ERR);
4528				if(uni_decode_ie_body(UNI_IE_GIT, (union uni_ieall *)&out->git[i], msg, ielen, cx))
4529					return (DEC_ERR);
4530				break;
4531			}
4532		break;
4533
4534	  case UNI_IE_REPORT:
4535		out->report.h = *hdr;
4536		if (hdr->present & UNI_IE_ERROR)
4537			return (DEC_ERR);
4538		if(uni_decode_ie_body(UNI_IE_REPORT, (union uni_ieall *)&out->report, msg, ielen, cx))
4539			return (DEC_ERR);
4540		break;
4541
4542	  case UNI_IE_UNREC:
4543		out->unrec.h = *hdr;
4544		if (hdr->present & UNI_IE_ERROR)
4545			return (DEC_ERR);
4546		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
4547			return (DEC_ERR);
4548		break;
4549
4550	  default:
4551		return (DEC_ILL);
4552	}
4553	return (DEC_OK);
4554}
4555
4556static const struct msgdecl decl_conn_avail = {
4557	0,
4558	"conn_avail",
4559	(uni_msg_print_f)print_conn_avail,
4560	(uni_msg_check_f)check_conn_avail,
4561	(uni_msg_encode_f)encode_conn_avail,
4562	(uni_msg_decode_f)decode_conn_avail
4563};
4564
4565static void
4566print_unknown(struct uni_unknown *msg, struct unicx *cx)
4567{
4568	if(msg->epref.h.present & UNI_IE_PRESENT)
4569		uni_print_ie_internal(UNI_IE_EPREF, (union uni_ieall *)&msg->epref, cx);
4570	if(msg->unrec.h.present & UNI_IE_PRESENT)
4571		uni_print_ie_internal(UNI_IE_UNREC, (union uni_ieall *)&msg->unrec, cx);
4572}
4573
4574static int
4575check_unknown(struct uni_unknown *m, struct unicx *cx)
4576{
4577	int ret = 0;
4578
4579	ret |= uni_check_ie(UNI_IE_EPREF, (union uni_ieall *)&m->epref, cx);
4580	ret |= uni_check_ie(UNI_IE_UNREC, (union uni_ieall *)&m->unrec, cx);
4581
4582	return ret;
4583}
4584
4585static int
4586encode_unknown(struct uni_msg *msg, struct uni_unknown *p, struct unicx *cx)
4587{
4588	u_int mlen;
4589
4590	if(uni_encode_msg_hdr(msg, &p->hdr, UNI_UNKNOWN, cx, &mlen))
4591		return (-2);
4592
4593	if((p->epref.h.present & UNI_IE_PRESENT) &&
4594	   uni_encode_ie(UNI_IE_EPREF, msg, (union uni_ieall *)&p->epref, cx))
4595		return (UNI_IE_EPREF);
4596	if((p->unrec.h.present & UNI_IE_PRESENT) &&
4597	   uni_encode_ie(UNI_IE_UNREC, msg, (union uni_ieall *)&p->unrec, cx))
4598		return (UNI_IE_UNREC);
4599
4600	msg->b_buf[mlen+0] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 8;
4601	msg->b_buf[mlen+1] = ((msg->b_wptr-msg->b_rptr)-mlen-2) >> 0;
4602
4603	return (0);
4604}
4605
4606static int
4607decode_unknown(struct uni_unknown *out, struct uni_msg *msg,
4608    enum uni_ietype ie, struct uni_iehdr *hdr, u_int ielen,
4609    struct unicx *cx)
4610{
4611	switch (ie) {
4612
4613	  case UNI_IE_EPREF:
4614		out->epref.h = *hdr;
4615		if (hdr->present & UNI_IE_ERROR)
4616			return (DEC_ERR);
4617		if(uni_decode_ie_body(UNI_IE_EPREF, (union uni_ieall *)&out->epref, msg, ielen, cx))
4618			return (DEC_ERR);
4619		break;
4620
4621	  case UNI_IE_UNREC:
4622		out->unrec.h = *hdr;
4623		if (hdr->present & UNI_IE_ERROR)
4624			return (DEC_ERR);
4625		if(uni_decode_ie_body(UNI_IE_UNREC, (union uni_ieall *)&out->unrec, msg, ielen, cx))
4626			return (DEC_ERR);
4627		break;
4628
4629	  default:
4630		return (DEC_ILL);
4631	}
4632	return (DEC_OK);
4633}
4634
4635static const struct msgdecl decl_unknown = {
4636	0,
4637	"unknown",
4638	(uni_msg_print_f)print_unknown,
4639	(uni_msg_check_f)check_unknown,
4640	(uni_msg_encode_f)encode_unknown,
4641	(uni_msg_decode_f)decode_unknown
4642};
4643
4644const struct msgdecl *uni_msgtable[256] = {
4645	&decl_unknown,	/* 0x00 */
4646	&decl_alerting,	/* 0x01 */
4647	&decl_call_proc,	/* 0x02 */
4648	&decl_unknown,	/* 0x03 */
4649	&decl_unknown,	/* 0x04 */
4650	&decl_setup,	/* 0x05 */
4651	&decl_unknown,	/* 0x06 */
4652	&decl_connect,	/* 0x07 */
4653	&decl_unknown,	/* 0x08 */
4654	&decl_unknown,	/* 0x09 */
4655	&decl_unknown,	/* 0x0a */
4656	&decl_unknown,	/* 0x0b */
4657	&decl_unknown,	/* 0x0c */
4658	&decl_unknown,	/* 0x0d */
4659	&decl_unknown,	/* 0x0e */
4660	&decl_connect_ack,	/* 0x0f */
4661	&decl_unknown,	/* 0x10 */
4662	&decl_unknown,	/* 0x11 */
4663	&decl_unknown,	/* 0x12 */
4664	&decl_unknown,	/* 0x13 */
4665	&decl_unknown,	/* 0x14 */
4666	&decl_cobisetup,	/* 0x15 */
4667	&decl_unknown,	/* 0x16 */
4668	&decl_unknown,	/* 0x17 */
4669	&decl_unknown,	/* 0x18 */
4670	&decl_unknown,	/* 0x19 */
4671	&decl_unknown,	/* 0x1a */
4672	&decl_unknown,	/* 0x1b */
4673	&decl_unknown,	/* 0x1c */
4674	&decl_unknown,	/* 0x1d */
4675	&decl_unknown,	/* 0x1e */
4676	&decl_unknown,	/* 0x1f */
4677	&decl_unknown,	/* 0x20 */
4678	&decl_unknown,	/* 0x21 */
4679	&decl_unknown,	/* 0x22 */
4680	&decl_unknown,	/* 0x23 */
4681	&decl_unknown,	/* 0x24 */
4682	&decl_unknown,	/* 0x25 */
4683	&decl_unknown,	/* 0x26 */
4684	&decl_unknown,	/* 0x27 */
4685	&decl_unknown,	/* 0x28 */
4686	&decl_unknown,	/* 0x29 */
4687	&decl_unknown,	/* 0x2a */
4688	&decl_unknown,	/* 0x2b */
4689	&decl_unknown,	/* 0x2c */
4690	&decl_unknown,	/* 0x2d */
4691	&decl_unknown,	/* 0x2e */
4692	&decl_unknown,	/* 0x2f */
4693	&decl_unknown,	/* 0x30 */
4694	&decl_unknown,	/* 0x31 */
4695	&decl_unknown,	/* 0x32 */
4696	&decl_unknown,	/* 0x33 */
4697	&decl_unknown,	/* 0x34 */
4698	&decl_unknown,	/* 0x35 */
4699	&decl_unknown,	/* 0x36 */
4700	&decl_unknown,	/* 0x37 */
4701	&decl_unknown,	/* 0x38 */
4702	&decl_unknown,	/* 0x39 */
4703	&decl_unknown,	/* 0x3a */
4704	&decl_unknown,	/* 0x3b */
4705	&decl_unknown,	/* 0x3c */
4706	&decl_unknown,	/* 0x3d */
4707	&decl_unknown,	/* 0x3e */
4708	&decl_unknown,	/* 0x3f */
4709	&decl_unknown,	/* 0x40 */
4710	&decl_unknown,	/* 0x41 */
4711	&decl_unknown,	/* 0x42 */
4712	&decl_unknown,	/* 0x43 */
4713	&decl_unknown,	/* 0x44 */
4714	&decl_unknown,	/* 0x45 */
4715	&decl_restart,	/* 0x46 */
4716	&decl_unknown,	/* 0x47 */
4717	&decl_unknown,	/* 0x48 */
4718	&decl_unknown,	/* 0x49 */
4719	&decl_unknown,	/* 0x4a */
4720	&decl_unknown,	/* 0x4b */
4721	&decl_unknown,	/* 0x4c */
4722	&decl_release,	/* 0x4d */
4723	&decl_restart_ack,	/* 0x4e */
4724	&decl_unknown,	/* 0x4f */
4725	&decl_unknown,	/* 0x50 */
4726	&decl_unknown,	/* 0x51 */
4727	&decl_unknown,	/* 0x52 */
4728	&decl_unknown,	/* 0x53 */
4729	&decl_unknown,	/* 0x54 */
4730	&decl_unknown,	/* 0x55 */
4731	&decl_unknown,	/* 0x56 */
4732	&decl_unknown,	/* 0x57 */
4733	&decl_unknown,	/* 0x58 */
4734	&decl_unknown,	/* 0x59 */
4735	&decl_release_compl,	/* 0x5a */
4736	&decl_unknown,	/* 0x5b */
4737	&decl_unknown,	/* 0x5c */
4738	&decl_unknown,	/* 0x5d */
4739	&decl_unknown,	/* 0x5e */
4740	&decl_unknown,	/* 0x5f */
4741	&decl_unknown,	/* 0x60 */
4742	&decl_unknown,	/* 0x61 */
4743	&decl_facility,	/* 0x62 */
4744	&decl_unknown,	/* 0x63 */
4745	&decl_unknown,	/* 0x64 */
4746	&decl_unknown,	/* 0x65 */
4747	&decl_unknown,	/* 0x66 */
4748	&decl_unknown,	/* 0x67 */
4749	&decl_unknown,	/* 0x68 */
4750	&decl_unknown,	/* 0x69 */
4751	&decl_unknown,	/* 0x6a */
4752	&decl_unknown,	/* 0x6b */
4753	&decl_unknown,	/* 0x6c */
4754	&decl_unknown,	/* 0x6d */
4755	&decl_notify,	/* 0x6e */
4756	&decl_unknown,	/* 0x6f */
4757	&decl_unknown,	/* 0x70 */
4758	&decl_unknown,	/* 0x71 */
4759	&decl_unknown,	/* 0x72 */
4760	&decl_unknown,	/* 0x73 */
4761	&decl_unknown,	/* 0x74 */
4762	&decl_status_enq,	/* 0x75 */
4763	&decl_unknown,	/* 0x76 */
4764	&decl_unknown,	/* 0x77 */
4765	&decl_unknown,	/* 0x78 */
4766	&decl_unknown,	/* 0x79 */
4767	&decl_unknown,	/* 0x7a */
4768	&decl_unknown,	/* 0x7b */
4769	&decl_unknown,	/* 0x7c */
4770	&decl_status,	/* 0x7d */
4771	&decl_unknown,	/* 0x7e */
4772	&decl_unknown,	/* 0x7f */
4773	&decl_add_party,	/* 0x80 */
4774	&decl_add_party_ack,	/* 0x81 */
4775	&decl_add_party_rej,	/* 0x82 */
4776	&decl_drop_party,	/* 0x83 */
4777	&decl_drop_party_ack,	/* 0x84 */
4778	&decl_party_alerting,	/* 0x85 */
4779	&decl_unknown,	/* 0x86 */
4780	&decl_unknown,	/* 0x87 */
4781	&decl_modify_req,	/* 0x88 */
4782	&decl_modify_ack,	/* 0x89 */
4783	&decl_modify_rej,	/* 0x8a */
4784	&decl_conn_avail,	/* 0x8b */
4785	&decl_unknown,	/* 0x8c */
4786	&decl_unknown,	/* 0x8d */
4787	&decl_unknown,	/* 0x8e */
4788	&decl_unknown,	/* 0x8f */
4789	&decl_leaf_setup_fail,	/* 0x90 */
4790	&decl_leaf_setup_req,	/* 0x91 */
4791	&decl_unknown,	/* 0x92 */
4792	&decl_unknown,	/* 0x93 */
4793	&decl_unknown,	/* 0x94 */
4794	&decl_unknown,	/* 0x95 */
4795	&decl_unknown,	/* 0x96 */
4796	&decl_unknown,	/* 0x97 */
4797	&decl_unknown,	/* 0x98 */
4798	&decl_unknown,	/* 0x99 */
4799	&decl_unknown,	/* 0x9a */
4800	&decl_unknown,	/* 0x9b */
4801	&decl_unknown,	/* 0x9c */
4802	&decl_unknown,	/* 0x9d */
4803	&decl_unknown,	/* 0x9e */
4804	&decl_unknown,	/* 0x9f */
4805	&decl_unknown,	/* 0xa0 */
4806	&decl_unknown,	/* 0xa1 */
4807	&decl_unknown,	/* 0xa2 */
4808	&decl_unknown,	/* 0xa3 */
4809	&decl_unknown,	/* 0xa4 */
4810	&decl_unknown,	/* 0xa5 */
4811	&decl_unknown,	/* 0xa6 */
4812	&decl_unknown,	/* 0xa7 */
4813	&decl_unknown,	/* 0xa8 */
4814	&decl_unknown,	/* 0xa9 */
4815	&decl_unknown,	/* 0xaa */
4816	&decl_unknown,	/* 0xab */
4817	&decl_unknown,	/* 0xac */
4818	&decl_unknown,	/* 0xad */
4819	&decl_unknown,	/* 0xae */
4820	&decl_unknown,	/* 0xaf */
4821	&decl_unknown,	/* 0xb0 */
4822	&decl_unknown,	/* 0xb1 */
4823	&decl_unknown,	/* 0xb2 */
4824	&decl_unknown,	/* 0xb3 */
4825	&decl_unknown,	/* 0xb4 */
4826	&decl_unknown,	/* 0xb5 */
4827	&decl_unknown,	/* 0xb6 */
4828	&decl_unknown,	/* 0xb7 */
4829	&decl_unknown,	/* 0xb8 */
4830	&decl_unknown,	/* 0xb9 */
4831	&decl_unknown,	/* 0xba */
4832	&decl_unknown,	/* 0xbb */
4833	&decl_unknown,	/* 0xbc */
4834	&decl_unknown,	/* 0xbd */
4835	&decl_unknown,	/* 0xbe */
4836	&decl_unknown,	/* 0xbf */
4837	&decl_unknown,	/* 0xc0 */
4838	&decl_unknown,	/* 0xc1 */
4839	&decl_unknown,	/* 0xc2 */
4840	&decl_unknown,	/* 0xc3 */
4841	&decl_unknown,	/* 0xc4 */
4842	&decl_unknown,	/* 0xc5 */
4843	&decl_unknown,	/* 0xc6 */
4844	&decl_unknown,	/* 0xc7 */
4845	&decl_unknown,	/* 0xc8 */
4846	&decl_unknown,	/* 0xc9 */
4847	&decl_unknown,	/* 0xca */
4848	&decl_unknown,	/* 0xcb */
4849	&decl_unknown,	/* 0xcc */
4850	&decl_unknown,	/* 0xcd */
4851	&decl_unknown,	/* 0xce */
4852	&decl_unknown,	/* 0xcf */
4853	&decl_unknown,	/* 0xd0 */
4854	&decl_unknown,	/* 0xd1 */
4855	&decl_unknown,	/* 0xd2 */
4856	&decl_unknown,	/* 0xd3 */
4857	&decl_unknown,	/* 0xd4 */
4858	&decl_unknown,	/* 0xd5 */
4859	&decl_unknown,	/* 0xd6 */
4860	&decl_unknown,	/* 0xd7 */
4861	&decl_unknown,	/* 0xd8 */
4862	&decl_unknown,	/* 0xd9 */
4863	&decl_unknown,	/* 0xda */
4864	&decl_unknown,	/* 0xdb */
4865	&decl_unknown,	/* 0xdc */
4866	&decl_unknown,	/* 0xdd */
4867	&decl_unknown,	/* 0xde */
4868	&decl_unknown,	/* 0xdf */
4869	&decl_unknown,	/* 0xe0 */
4870	&decl_unknown,	/* 0xe1 */
4871	&decl_unknown,	/* 0xe2 */
4872	&decl_unknown,	/* 0xe3 */
4873	&decl_unknown,	/* 0xe4 */
4874	&decl_unknown,	/* 0xe5 */
4875	&decl_unknown,	/* 0xe6 */
4876	&decl_unknown,	/* 0xe7 */
4877	&decl_unknown,	/* 0xe8 */
4878	&decl_unknown,	/* 0xe9 */
4879	&decl_unknown,	/* 0xea */
4880	&decl_unknown,	/* 0xeb */
4881	&decl_unknown,	/* 0xec */
4882	&decl_unknown,	/* 0xed */
4883	&decl_unknown,	/* 0xee */
4884	&decl_unknown,	/* 0xef */
4885	&decl_unknown,	/* 0xf0 */
4886	&decl_unknown,	/* 0xf1 */
4887	&decl_unknown,	/* 0xf2 */
4888	&decl_unknown,	/* 0xf3 */
4889	&decl_unknown,	/* 0xf4 */
4890	&decl_unknown,	/* 0xf5 */
4891	&decl_unknown,	/* 0xf6 */
4892	&decl_unknown,	/* 0xf7 */
4893	&decl_unknown,	/* 0xf8 */
4894	&decl_unknown,	/* 0xf9 */
4895	&decl_unknown,	/* 0xfa */
4896	&decl_unknown,	/* 0xfb */
4897	&decl_unknown,	/* 0xfc */
4898	&decl_unknown,	/* 0xfd */
4899	&decl_unknown,	/* 0xfe */
4900	&decl_unknown,	/* 0xff */
4901};
4902