2 * Copyright (c) 2002-2003
3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * Author: Hartmut Brandt <harti@freebsd.org>
28 * Kendy Kutzner <kutzner@fokus.fraunhofer.de>
30 * $Begemot: libunimsg/netnatm/sig/sig_print.c,v 1.6 2004/08/05 07:11:02 brandt Exp $
33 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/libkern.h>
38 #include <machine/stdarg.h>
46 #include <netnatm/saal/sscfu.h>
47 #include <netnatm/msg/uni_hdr.h>
48 #include <netnatm/msg/unistruct.h>
49 #include <netnatm/msg/unimsglib.h>
50 #include <netnatm/msg/uniprint.h>
51 #include <netnatm/sig/uni.h>
52 #include <netnatm/sig/unisig.h>
53 #include <netnatm/sig/unidef.h>
58 static const char *const errstr[] = {
59 #define DEF(NAME, VAL, STR) [UNIAPI_##NAME] = STR,
60 UNIAPI_DEF_ERRORS(DEF)
65 if (err >= sizeof(errstr)/sizeof(errstr[0]) || errstr[err] == NULL) {
66 sprintf(buf, "Unknown error %u", err);
73 static const char *const msgs[] = {
75 D(UNIAPI_CALL_CREATED),
76 D(UNIAPI_CALL_DESTROYED),
77 D(UNIAPI_PARTY_CREATED),
78 D(UNIAPI_PARTY_DESTROYED),
79 D(UNIAPI_LINK_ESTABLISH_request),
80 D(UNIAPI_LINK_ESTABLISH_confirm),
81 D(UNIAPI_LINK_RELEASE_request),
82 D(UNIAPI_LINK_RELEASE_confirm),
83 D(UNIAPI_RESET_request),
84 D(UNIAPI_RESET_confirm),
85 D(UNIAPI_RESET_indication),
86 D(UNIAPI_RESET_ERROR_indication),
87 D(UNIAPI_RESET_response),
88 D(UNIAPI_RESET_ERROR_response),
89 D(UNIAPI_RESET_STATUS_indication),
90 D(UNIAPI_SETUP_request),
91 D(UNIAPI_SETUP_indication),
92 D(UNIAPI_SETUP_response),
93 D(UNIAPI_SETUP_confirm),
94 D(UNIAPI_SETUP_COMPLETE_indication),
95 D(UNIAPI_SETUP_COMPLETE_request),
96 D(UNIAPI_ALERTING_request),
97 D(UNIAPI_ALERTING_indication),
98 D(UNIAPI_PROCEEDING_request),
99 D(UNIAPI_PROCEEDING_indication),
100 D(UNIAPI_RELEASE_request),
101 D(UNIAPI_RELEASE_indication),
102 D(UNIAPI_RELEASE_response),
103 D(UNIAPI_RELEASE_confirm),
104 D(UNIAPI_NOTIFY_request),
105 D(UNIAPI_NOTIFY_indication),
106 D(UNIAPI_STATUS_indication),
107 D(UNIAPI_STATUS_ENQUIRY_request),
108 D(UNIAPI_ADD_PARTY_request),
109 D(UNIAPI_ADD_PARTY_indication),
110 D(UNIAPI_PARTY_ALERTING_request),
111 D(UNIAPI_PARTY_ALERTING_indication),
112 D(UNIAPI_ADD_PARTY_ACK_request),
113 D(UNIAPI_ADD_PARTY_ACK_indication),
114 D(UNIAPI_ADD_PARTY_REJ_request),
115 D(UNIAPI_ADD_PARTY_REJ_indication),
116 D(UNIAPI_DROP_PARTY_request),
117 D(UNIAPI_DROP_PARTY_indication),
118 D(UNIAPI_DROP_PARTY_ACK_request),
119 D(UNIAPI_DROP_PARTY_ACK_indication),
120 D(UNIAPI_ABORT_CALL_request),
125 uni_print_api(char *buf, size_t bufsiz, u_int type, u_int cookie,
126 const void *msg, struct unicx *cx)
128 int old_dont_init = cx->dont_init;
130 uni_print_init(buf, bufsiz, cx);
133 if (type >= sizeof(msgs) / sizeof(msgs[0]) || msgs[type] == NULL) {
134 uni_print_flag("UNIAPI_UNKNOWN", cx);
135 uni_print_entry(cx, "sig", "%u", type);
136 uni_print_entry(cx, "cookie", "%u", cookie);
140 uni_print_flag(msgs[type], cx);
141 uni_print_entry(cx, "cookie", "%u", cookie);
148 const struct uniapi_error *api = msg;
151 uni_print_entry(cx, "reason", "%s", uni_strerr(api->reason));
152 uni_print_entry(cx, "state", "U%u", api->state);
156 case UNIAPI_CALL_CREATED:
158 const struct uniapi_call_created *api = msg;
160 uni_print_cref(NULL, 0, &api->cref, cx);
164 case UNIAPI_CALL_DESTROYED:
166 const struct uniapi_call_destroyed *api = msg;
168 uni_print_cref(NULL, 0, &api->cref, cx);
172 case UNIAPI_PARTY_CREATED:
174 const struct uniapi_party_created *api = msg;
176 uni_print_cref(NULL, 0, &api->cref, cx);
178 uni_print_ie(NULL, 0, UNI_IE_EPREF,
179 (const union uni_ieall *)&api->epref, cx);
183 case UNIAPI_PARTY_DESTROYED:
185 const struct uniapi_party_destroyed *api = msg;
187 uni_print_cref(NULL, 0, &api->cref, cx);
189 uni_print_ie(NULL, 0, UNI_IE_EPREF,
190 (const union uni_ieall *)&api->epref, cx);
194 case UNIAPI_LINK_ESTABLISH_request:
195 case UNIAPI_LINK_ESTABLISH_confirm:
196 case UNIAPI_LINK_RELEASE_request:
197 case UNIAPI_LINK_RELEASE_confirm:
200 case UNIAPI_RESET_request:
202 const struct uniapi_reset_request *api = msg;
205 uni_print_ie(NULL, 0, UNI_IE_RESTART,
206 (const union uni_ieall *)&api->restart, cx);
208 uni_print_ie(NULL, 0, UNI_IE_CONNID,
209 (const union uni_ieall *)&api->restart, cx);
213 case UNIAPI_RESET_confirm:
215 const struct uniapi_reset_confirm *api = msg;
218 uni_print_ie(NULL, 0, UNI_IE_RESTART,
219 (const union uni_ieall *)&api->restart, cx);
221 uni_print_ie(NULL, 0, UNI_IE_CONNID,
222 (const union uni_ieall *)&api->restart, cx);
226 case UNIAPI_RESET_indication:
228 const struct uniapi_reset_indication *api = msg;
231 uni_print_ie(NULL, 0, UNI_IE_RESTART,
232 (const union uni_ieall *)&api->restart, cx);
234 uni_print_ie(NULL, 0, UNI_IE_CONNID,
235 (const union uni_ieall *)&api->restart, cx);
239 case UNIAPI_RESET_ERROR_indication:
241 const struct uniapi_reset_error_indication *api = msg;
242 static const struct uni_print_tbl reason[] = {
243 #define DEF(NAME, VALUE, STR) { STR, VALUE },
244 UNIAPI_DEF_RESET_ERRORS(DEF)
248 static const struct uni_print_tbl source[] = {
255 uni_print_tbl("source", api->source, source, cx);
256 uni_print_tbl("reason", api->reason, reason, cx);
260 case UNIAPI_RESET_response:
262 const struct uniapi_reset_response *api = msg;
265 uni_print_ie(NULL, 0, UNI_IE_RESTART,
266 (const union uni_ieall *)&api->restart, cx);
268 uni_print_ie(NULL, 0, UNI_IE_CONNID,
269 (const union uni_ieall *)&api->restart, cx);
273 case UNIAPI_RESET_ERROR_response:
275 const struct uniapi_reset_error_response *api = msg;
278 uni_print_ie(NULL, 0, UNI_IE_CAUSE,
279 (const union uni_ieall *)&api->cause, cx);
283 case UNIAPI_RESET_STATUS_indication:
285 const struct uniapi_reset_status_indication *api = msg;
287 uni_print_cref(NULL, 0, &api->cref, cx);
289 uni_print_ie(NULL, 0, UNI_IE_CALLSTATE,
290 (const union uni_ieall *)&api->callstate, cx);
292 uni_print_ie(NULL, 0, UNI_IE_CAUSE,
293 (const union uni_ieall *)&api->cause, cx);
297 case UNIAPI_SETUP_request:
299 const struct uniapi_setup_request *api = msg;
302 uni_print_msg(NULL, 0, UNI_SETUP,
303 (const union uni_msgall *)&api->setup, cx);
307 case UNIAPI_SETUP_indication:
309 const struct uniapi_setup_indication *api = msg;
312 uni_print_msg(NULL, 0, UNI_SETUP,
313 (const union uni_msgall *)&api->setup, cx);
317 case UNIAPI_SETUP_response:
319 const struct uniapi_setup_response *api = msg;
322 uni_print_msg(NULL, 0, UNI_CONNECT,
323 (const union uni_msgall *)&api->connect, cx);
327 case UNIAPI_SETUP_confirm:
329 const struct uniapi_setup_confirm *api = msg;
332 uni_print_msg(NULL, 0, UNI_CONNECT,
333 (const union uni_msgall *)&api->connect, cx);
337 case UNIAPI_SETUP_COMPLETE_indication:
339 const struct uniapi_setup_complete_indication *api = msg;
342 uni_print_msg(NULL, 0, UNI_CONNECT_ACK,
343 (const union uni_msgall *)&api->connect_ack, cx);
347 case UNIAPI_SETUP_COMPLETE_request:
349 const struct uniapi_setup_complete_request *api = msg;
352 uni_print_msg(NULL, 0, UNI_CONNECT_ACK,
353 (const union uni_msgall *)&api->connect_ack, cx);
357 case UNIAPI_ALERTING_request:
359 const struct uniapi_alerting_request *api = msg;
362 uni_print_msg(NULL, 0, UNI_ALERTING,
363 (const union uni_msgall *)&api->alerting, cx);
367 case UNIAPI_ALERTING_indication:
369 const struct uniapi_alerting_indication *api = msg;
372 uni_print_msg(NULL, 0, UNI_ALERTING,
373 (const union uni_msgall *)&api->alerting, cx);
377 case UNIAPI_PROCEEDING_request:
379 const struct uniapi_proceeding_request *api = msg;
382 uni_print_msg(NULL, 0, UNI_CALL_PROC,
383 (const union uni_msgall *)&api->call_proc, cx);
387 case UNIAPI_PROCEEDING_indication:
389 const struct uniapi_proceeding_indication *api = msg;
392 uni_print_msg(NULL, 0, UNI_CALL_PROC,
393 (const union uni_msgall *)&api->call_proc, cx);
397 case UNIAPI_RELEASE_request:
399 const struct uniapi_release_request *api = msg;
402 uni_print_msg(NULL, 0, UNI_RELEASE,
403 (const union uni_msgall *)&api->release, cx);
407 case UNIAPI_RELEASE_indication:
409 const struct uniapi_release_indication *api = msg;
412 uni_print_msg(NULL, 0, UNI_RELEASE,
413 (const union uni_msgall *)&api->release, cx);
417 case UNIAPI_RELEASE_response:
419 const struct uniapi_release_response *api = msg;
422 uni_print_msg(NULL, 0, UNI_RELEASE_COMPL,
423 (const union uni_msgall *)&api->release_compl, cx);
426 case UNIAPI_RELEASE_confirm:
428 const struct uniapi_release_confirm *api = msg;
431 uni_print_msg(NULL, 0, UNI_RELEASE,
432 (const union uni_msgall *)&api->release, cx);
436 case UNIAPI_NOTIFY_request:
438 const struct uniapi_notify_request *api = msg;
441 uni_print_msg(NULL, 0, UNI_NOTIFY,
442 (const union uni_msgall *)&api->notify, cx);
446 case UNIAPI_NOTIFY_indication:
448 const struct uniapi_notify_indication *api = msg;
451 uni_print_msg(NULL, 0, UNI_NOTIFY,
452 (const union uni_msgall *)&api->notify, cx);
456 case UNIAPI_STATUS_indication:
458 const struct uniapi_status_indication *api = msg;
460 uni_print_cref(NULL, 0, &api->cref, cx);
462 uni_print_entry(cx, "my_state", "U%u", api->my_state);
463 uni_print_entry(cx, "my_cause", "%s",
464 uni_ie_cause2str(UNI_CODING_ITU, api->my_cause));
466 uni_print_ie(NULL, 0, UNI_IE_CALLSTATE,
467 (const union uni_ieall *)&api->his_state, cx);
469 uni_print_ie(NULL, 0, UNI_IE_CAUSE,
470 (const union uni_ieall *)&api->his_cause, cx);
472 uni_print_ie(NULL, 0, UNI_IE_EPREF,
473 (const union uni_ieall *)&api->epref, cx);
477 case UNIAPI_STATUS_ENQUIRY_request:
479 const struct uniapi_status_enquiry_request *api = msg;
481 uni_print_cref(NULL, 0, &api->cref, cx);
483 uni_print_ie(NULL, 0, UNI_IE_EPREF,
484 (const union uni_ieall *)&api->epref, cx);
488 case UNIAPI_ADD_PARTY_request:
490 const struct uniapi_add_party_request *api = msg;
493 uni_print_msg(NULL, 0, UNI_ADD_PARTY,
494 (const union uni_msgall *)&api->add, cx);
498 case UNIAPI_ADD_PARTY_indication:
500 const struct uniapi_add_party_indication *api = msg;
503 uni_print_msg(NULL, 0, UNI_ADD_PARTY,
504 (const union uni_msgall *)&api->add, cx);
508 case UNIAPI_PARTY_ALERTING_request:
510 const struct uniapi_party_alerting_request *api = msg;
513 uni_print_msg(NULL, 0, UNI_PARTY_ALERTING,
514 (const union uni_msgall *)&api->alert, cx);
518 case UNIAPI_PARTY_ALERTING_indication:
520 const struct uniapi_party_alerting_indication *api = msg;
523 uni_print_msg(NULL, 0, UNI_PARTY_ALERTING,
524 (const union uni_msgall *)&api->alert, cx);
528 case UNIAPI_ADD_PARTY_ACK_request:
530 const struct uniapi_add_party_ack_request *api = msg;
533 uni_print_msg(NULL, 0, UNI_ADD_PARTY_ACK,
534 (const union uni_msgall *)&api->ack, cx);
538 case UNIAPI_ADD_PARTY_ACK_indication:
540 const struct uniapi_add_party_ack_indication *api = msg;
543 uni_print_msg(NULL, 0, UNI_ADD_PARTY_ACK,
544 (const union uni_msgall *)&api->ack, cx);
548 case UNIAPI_ADD_PARTY_REJ_request:
550 const struct uniapi_add_party_rej_request *api = msg;
553 uni_print_msg(NULL, 0, UNI_ADD_PARTY_REJ,
554 (const union uni_msgall *)&api->rej, cx);
558 case UNIAPI_ADD_PARTY_REJ_indication:
560 const struct uniapi_add_party_rej_indication *api = msg;
563 uni_print_msg(NULL, 0, UNI_ADD_PARTY_REJ,
564 (const union uni_msgall *)&api->rej, cx);
568 case UNIAPI_DROP_PARTY_request:
570 const struct uniapi_drop_party_request *api = msg;
573 uni_print_msg(NULL, 0, UNI_DROP_PARTY,
574 (const union uni_msgall *)&api->drop, cx);
578 case UNIAPI_DROP_PARTY_indication:
580 const struct uniapi_drop_party_indication *api = msg;
583 uni_print_msg(NULL, 0, UNI_DROP_PARTY,
584 (const union uni_msgall *)&api->drop, cx);
588 case UNIAPI_DROP_PARTY_ACK_request:
590 const struct uniapi_drop_party_ack_request *api = msg;
593 uni_print_msg(NULL, 0, UNI_DROP_PARTY_ACK,
594 (const union uni_msgall *)&api->ack, cx);
598 case UNIAPI_DROP_PARTY_ACK_indication:
600 const struct uniapi_drop_party_ack_indication *api = msg;
603 uni_print_msg(NULL, 0, UNI_DROP_PARTY,
604 (const union uni_msgall *)&api->drop, cx);
606 uni_print_ie(NULL, 0, UNI_IE_CRANKBACK,
607 (const union uni_ieall *)&api->crankback, cx);
611 case UNIAPI_ABORT_CALL_request:
613 const struct uniapi_abort_call_request *api = msg;
615 uni_print_cref(NULL, 0, &api->cref, cx);
621 cx->dont_init = old_dont_init;