]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/contrib/ngatm/netnatm/sig/sig_print.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / contrib / ngatm / netnatm / sig / sig_print.c
1 /*
2  * Copyright (c) 2002-2003
3  *      Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4  *      All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * Author: Hartmut Brandt <harti@freebsd.org>
28  *         Kendy Kutzner <kutzner@fokus.fraunhofer.de>
29  *
30  * $Begemot: libunimsg/netnatm/sig/sig_print.c,v 1.6 2004/08/05 07:11:02 brandt Exp $
31  */
32
33 #include <sys/types.h>
34 #ifdef _KERNEL
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/libkern.h>
38 #include <machine/stdarg.h>
39 #else
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <stdarg.h>
44 #endif
45
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>
54
55 const char * 
56 uni_strerr(u_int err)
57 {
58         static const char *const errstr[] = {
59 #define DEF(NAME, VAL, STR) [UNIAPI_##NAME] = STR,
60 UNIAPI_DEF_ERRORS(DEF)
61 #undef DEF
62         };
63         static char buf[100];
64
65         if (err >= sizeof(errstr)/sizeof(errstr[0]) || errstr[err] == NULL) {
66                 sprintf(buf, "Unknown error %u", err);
67                 return (buf);
68         }
69         return (errstr[err]);
70 }
71
72 #define D(M) [M] = #M
73 static const char *const msgs[] = {
74         D(UNIAPI_ERROR),
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),
121 };
122 #undef D
123
124 void
125 uni_print_api(char *buf, size_t bufsiz, u_int type, u_int cookie,
126     const void *msg, struct unicx *cx)
127 {
128         int old_dont_init = cx->dont_init;
129
130         uni_print_init(buf, bufsiz, cx);
131         cx->dont_init = 1;
132
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);
137                 goto out;
138         }
139
140         uni_print_flag(msgs[type], cx);
141         uni_print_entry(cx, "cookie", "%u", cookie);
142         cx->indent++;
143
144         switch (type) {
145
146           case UNIAPI_ERROR:
147             {
148                 const struct uniapi_error *api = msg;
149
150                 uni_print_eol(cx);
151                 uni_print_entry(cx, "reason", "%s", uni_strerr(api->reason));
152                 uni_print_entry(cx, "state", "U%u", api->state);
153                 break;
154             }
155
156           case UNIAPI_CALL_CREATED:
157             {
158                 const struct uniapi_call_created *api = msg;
159
160                 uni_print_cref(NULL, 0, &api->cref, cx);
161                 break;
162             }
163
164           case UNIAPI_CALL_DESTROYED:
165             {
166                 const struct uniapi_call_destroyed *api = msg;
167
168                 uni_print_cref(NULL, 0, &api->cref, cx);
169                 break;
170             }
171
172           case UNIAPI_PARTY_CREATED:
173             {
174                 const struct uniapi_party_created *api = msg;
175
176                 uni_print_cref(NULL, 0, &api->cref, cx);
177                 uni_print_eol(cx);
178                 uni_print_ie(NULL, 0, UNI_IE_EPREF,
179                     (const union uni_ieall *)&api->epref, cx);
180                 break;
181             }
182
183           case UNIAPI_PARTY_DESTROYED:
184             {
185                 const struct uniapi_party_destroyed *api = msg;
186
187                 uni_print_cref(NULL, 0, &api->cref, cx);
188                 uni_print_eol(cx);
189                 uni_print_ie(NULL, 0, UNI_IE_EPREF,
190                     (const union uni_ieall *)&api->epref, cx);
191                 break;
192             }
193
194           case UNIAPI_LINK_ESTABLISH_request:
195           case UNIAPI_LINK_ESTABLISH_confirm:
196           case UNIAPI_LINK_RELEASE_request:
197           case UNIAPI_LINK_RELEASE_confirm:
198                 break;
199
200           case UNIAPI_RESET_request:
201             {
202                 const struct uniapi_reset_request *api = msg;
203
204                 uni_print_eol(cx);
205                 uni_print_ie(NULL, 0, UNI_IE_RESTART,
206                     (const union uni_ieall *)&api->restart, cx);
207                 uni_print_eol(cx);
208                 uni_print_ie(NULL, 0, UNI_IE_CONNID,
209                     (const union uni_ieall *)&api->restart, cx);
210                 break;
211             }
212
213           case UNIAPI_RESET_confirm:
214             {
215                 const struct uniapi_reset_confirm *api = msg;
216
217                 uni_print_eol(cx);
218                 uni_print_ie(NULL, 0, UNI_IE_RESTART,
219                     (const union uni_ieall *)&api->restart, cx);
220                 uni_print_eol(cx);
221                 uni_print_ie(NULL, 0, UNI_IE_CONNID,
222                     (const union uni_ieall *)&api->restart, cx);
223                 break;
224             }
225
226           case UNIAPI_RESET_indication:
227             {
228                 const struct uniapi_reset_indication *api = msg;
229
230                 uni_print_eol(cx);
231                 uni_print_ie(NULL, 0, UNI_IE_RESTART,
232                     (const union uni_ieall *)&api->restart, cx);
233                 uni_print_eol(cx);
234                 uni_print_ie(NULL, 0, UNI_IE_CONNID,
235                     (const union uni_ieall *)&api->restart, cx);
236                 break;
237             }
238
239           case UNIAPI_RESET_ERROR_indication:
240             {
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)
245 #undef DEF
246                         { NULL, 0 }
247                 };
248                 static const struct uni_print_tbl source[] = {
249                         { "start", 0 },
250                         { "respond", 1 },
251                         { NULL, 0 }
252                 };
253
254                 uni_print_eol(cx);
255                 uni_print_tbl("source", api->source, source, cx);
256                 uni_print_tbl("reason", api->reason, reason, cx);
257                 break;
258             }
259
260           case UNIAPI_RESET_response:
261             {
262                 const struct uniapi_reset_response *api = msg;
263
264                 uni_print_eol(cx);
265                 uni_print_ie(NULL, 0, UNI_IE_RESTART,
266                     (const union uni_ieall *)&api->restart, cx);
267                 uni_print_eol(cx);
268                 uni_print_ie(NULL, 0, UNI_IE_CONNID,
269                     (const union uni_ieall *)&api->restart, cx);
270                 break;
271             }
272
273           case UNIAPI_RESET_ERROR_response:
274             {
275                 const struct uniapi_reset_error_response *api = msg;
276
277                 uni_print_eol(cx);
278                 uni_print_ie(NULL, 0, UNI_IE_CAUSE,
279                     (const union uni_ieall *)&api->cause, cx);
280                 break;
281             }
282
283           case UNIAPI_RESET_STATUS_indication:
284             {
285                 const struct uniapi_reset_status_indication *api = msg;
286
287                 uni_print_cref(NULL, 0, &api->cref, cx);
288                 uni_print_eol(cx);
289                 uni_print_ie(NULL, 0, UNI_IE_CALLSTATE,
290                     (const union uni_ieall *)&api->callstate, cx);
291                 uni_print_eol(cx);
292                 uni_print_ie(NULL, 0, UNI_IE_CAUSE,
293                     (const union uni_ieall *)&api->cause, cx);
294                 break;
295             }
296
297           case UNIAPI_SETUP_request:
298             {
299                 const struct uniapi_setup_request *api = msg;
300
301                 uni_print_eol(cx);
302                 uni_print_msg(NULL, 0, UNI_SETUP,
303                     (const union uni_msgall *)&api->setup, cx);
304                 break;
305             }
306
307           case UNIAPI_SETUP_indication:
308             {
309                 const struct uniapi_setup_indication *api = msg;
310
311                 uni_print_eol(cx);
312                 uni_print_msg(NULL, 0, UNI_SETUP,
313                     (const union uni_msgall *)&api->setup, cx);
314                 break;
315             }
316
317           case UNIAPI_SETUP_response:
318             {
319                 const struct uniapi_setup_response *api = msg;
320
321                 uni_print_eol(cx);
322                 uni_print_msg(NULL, 0, UNI_CONNECT,
323                     (const union uni_msgall *)&api->connect, cx);
324                 break;
325             }
326
327           case UNIAPI_SETUP_confirm:
328             {
329                 const struct uniapi_setup_confirm *api = msg;
330
331                 uni_print_eol(cx);
332                 uni_print_msg(NULL, 0, UNI_CONNECT,
333                     (const union uni_msgall *)&api->connect, cx);
334                 break;
335             }
336
337           case UNIAPI_SETUP_COMPLETE_indication:
338             {
339                 const struct uniapi_setup_complete_indication *api = msg;
340
341                 uni_print_eol(cx);
342                 uni_print_msg(NULL, 0, UNI_CONNECT_ACK,
343                     (const union uni_msgall *)&api->connect_ack, cx);
344                 break;
345             }
346
347           case UNIAPI_SETUP_COMPLETE_request:
348             {
349                 const struct uniapi_setup_complete_request *api = msg;
350
351                 uni_print_eol(cx);
352                 uni_print_msg(NULL, 0, UNI_CONNECT_ACK,
353                     (const union uni_msgall *)&api->connect_ack, cx);
354                 break;
355             }
356
357           case UNIAPI_ALERTING_request:
358             {
359                 const struct uniapi_alerting_request *api = msg;
360
361                 uni_print_eol(cx);
362                 uni_print_msg(NULL, 0, UNI_ALERTING,
363                     (const union uni_msgall *)&api->alerting, cx);
364                 break;
365             }
366
367           case UNIAPI_ALERTING_indication:
368             {
369                 const struct uniapi_alerting_indication *api = msg;
370
371                 uni_print_eol(cx);
372                 uni_print_msg(NULL, 0, UNI_ALERTING,
373                     (const union uni_msgall *)&api->alerting, cx);
374                 break;
375             }
376
377           case UNIAPI_PROCEEDING_request:
378             {
379                 const struct uniapi_proceeding_request *api = msg;
380
381                 uni_print_eol(cx);
382                 uni_print_msg(NULL, 0, UNI_CALL_PROC,
383                     (const union uni_msgall *)&api->call_proc, cx);
384                 break;
385             }
386
387           case UNIAPI_PROCEEDING_indication:
388             {
389                 const struct uniapi_proceeding_indication *api = msg;
390
391                 uni_print_eol(cx);
392                 uni_print_msg(NULL, 0, UNI_CALL_PROC,
393                     (const union uni_msgall *)&api->call_proc, cx);
394                 break;
395             }
396
397           case UNIAPI_RELEASE_request:
398             {
399                 const struct uniapi_release_request *api = msg;
400
401                 uni_print_eol(cx);
402                 uni_print_msg(NULL, 0, UNI_RELEASE,
403                     (const union uni_msgall *)&api->release, cx);
404                 break;
405             }
406
407           case UNIAPI_RELEASE_indication:
408             {
409                 const struct uniapi_release_indication *api = msg;
410
411                 uni_print_eol(cx);
412                 uni_print_msg(NULL, 0, UNI_RELEASE,
413                     (const union uni_msgall *)&api->release, cx);
414                 break;
415             }
416
417           case UNIAPI_RELEASE_response:
418             {
419                 const struct uniapi_release_response *api = msg;
420
421                 uni_print_eol(cx);
422                 uni_print_msg(NULL, 0, UNI_RELEASE_COMPL,
423                     (const union uni_msgall *)&api->release_compl, cx);
424                 break;
425             }
426           case UNIAPI_RELEASE_confirm:
427             {
428                 const struct uniapi_release_confirm *api = msg;
429
430                 uni_print_eol(cx);
431                 uni_print_msg(NULL, 0, UNI_RELEASE,
432                     (const union uni_msgall *)&api->release, cx);
433                 break;
434             }
435
436           case UNIAPI_NOTIFY_request:
437             {
438                 const struct uniapi_notify_request *api = msg;
439
440                 uni_print_eol(cx);
441                 uni_print_msg(NULL, 0, UNI_NOTIFY,
442                     (const union uni_msgall *)&api->notify, cx);
443                 break;
444             }
445
446           case UNIAPI_NOTIFY_indication:
447             {
448                 const struct uniapi_notify_indication *api = msg;
449
450                 uni_print_eol(cx);
451                 uni_print_msg(NULL, 0, UNI_NOTIFY,
452                     (const union uni_msgall *)&api->notify, cx);
453                 break;
454             }
455
456           case UNIAPI_STATUS_indication:
457             {
458                 const struct uniapi_status_indication *api = msg;
459
460                 uni_print_cref(NULL, 0, &api->cref, cx);
461                 uni_print_eol(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));
465                 uni_print_eol(cx);
466                 uni_print_ie(NULL, 0, UNI_IE_CALLSTATE,
467                     (const union uni_ieall *)&api->his_state, cx);
468                 uni_print_eol(cx);
469                 uni_print_ie(NULL, 0, UNI_IE_CAUSE,
470                     (const union uni_ieall *)&api->his_cause, cx);
471                 uni_print_eol(cx);
472                 uni_print_ie(NULL, 0, UNI_IE_EPREF,
473                     (const union uni_ieall *)&api->epref, cx);
474                 break;
475             }
476
477           case UNIAPI_STATUS_ENQUIRY_request:
478             {
479                 const struct uniapi_status_enquiry_request *api = msg;
480
481                 uni_print_cref(NULL, 0, &api->cref, cx);
482                 uni_print_eol(cx);
483                 uni_print_ie(NULL, 0, UNI_IE_EPREF,
484                     (const union uni_ieall *)&api->epref, cx);
485                 break;
486             }
487
488           case UNIAPI_ADD_PARTY_request:
489             {
490                 const struct uniapi_add_party_request *api = msg;
491
492                 uni_print_eol(cx);
493                 uni_print_msg(NULL, 0, UNI_ADD_PARTY,
494                     (const union uni_msgall *)&api->add, cx);
495                 break;
496             }
497
498           case UNIAPI_ADD_PARTY_indication:
499             {
500                 const struct uniapi_add_party_indication *api = msg;
501
502                 uni_print_eol(cx);
503                 uni_print_msg(NULL, 0, UNI_ADD_PARTY,
504                     (const union uni_msgall *)&api->add, cx);
505                 break;
506             }
507
508           case UNIAPI_PARTY_ALERTING_request:
509             {
510                 const struct uniapi_party_alerting_request *api = msg;
511
512                 uni_print_eol(cx);
513                 uni_print_msg(NULL, 0, UNI_PARTY_ALERTING,
514                     (const union uni_msgall *)&api->alert, cx);
515                 break;
516             }
517
518           case UNIAPI_PARTY_ALERTING_indication:
519             {
520                 const struct uniapi_party_alerting_indication *api = msg;
521
522                 uni_print_eol(cx);
523                 uni_print_msg(NULL, 0, UNI_PARTY_ALERTING,
524                     (const union uni_msgall *)&api->alert, cx);
525                 break;
526             }
527
528           case UNIAPI_ADD_PARTY_ACK_request:
529             {
530                 const struct uniapi_add_party_ack_request *api = msg;
531
532                 uni_print_eol(cx);
533                 uni_print_msg(NULL, 0, UNI_ADD_PARTY_ACK,
534                     (const union uni_msgall *)&api->ack, cx);
535                 break;
536             }
537
538           case UNIAPI_ADD_PARTY_ACK_indication:
539             {
540                 const struct uniapi_add_party_ack_indication *api = msg;
541
542                 uni_print_eol(cx);
543                 uni_print_msg(NULL, 0, UNI_ADD_PARTY_ACK,
544                     (const union uni_msgall *)&api->ack, cx);
545                 break;
546             }
547
548           case UNIAPI_ADD_PARTY_REJ_request:
549             {
550                 const struct uniapi_add_party_rej_request *api = msg;
551
552                 uni_print_eol(cx);
553                 uni_print_msg(NULL, 0, UNI_ADD_PARTY_REJ,
554                     (const union uni_msgall *)&api->rej, cx);
555                 break;
556             }
557
558           case UNIAPI_ADD_PARTY_REJ_indication:
559             {
560                 const struct uniapi_add_party_rej_indication *api = msg;
561
562                 uni_print_eol(cx);
563                 uni_print_msg(NULL, 0, UNI_ADD_PARTY_REJ,
564                     (const union uni_msgall *)&api->rej, cx);
565                 break;
566             }
567
568           case UNIAPI_DROP_PARTY_request:
569             {
570                 const struct uniapi_drop_party_request *api = msg;
571
572                 uni_print_eol(cx);
573                 uni_print_msg(NULL, 0, UNI_DROP_PARTY,
574                     (const union uni_msgall *)&api->drop, cx);
575                 break;
576             }
577
578           case UNIAPI_DROP_PARTY_indication:
579             {
580                 const struct uniapi_drop_party_indication *api = msg;
581
582                 uni_print_eol(cx);
583                 uni_print_msg(NULL, 0, UNI_DROP_PARTY,
584                     (const union uni_msgall *)&api->drop, cx);
585                 break;
586             }
587
588           case UNIAPI_DROP_PARTY_ACK_request:
589             {
590                 const struct uniapi_drop_party_ack_request *api = msg;
591
592                 uni_print_eol(cx);
593                 uni_print_msg(NULL, 0, UNI_DROP_PARTY_ACK,
594                     (const union uni_msgall *)&api->ack, cx);
595                 break;
596             }
597
598           case UNIAPI_DROP_PARTY_ACK_indication:
599             {
600                 const struct uniapi_drop_party_ack_indication *api = msg;
601
602                 uni_print_eol(cx);
603                 uni_print_msg(NULL, 0, UNI_DROP_PARTY,
604                     (const union uni_msgall *)&api->drop, cx);
605                 uni_print_eol(cx);
606                 uni_print_ie(NULL, 0, UNI_IE_CRANKBACK,
607                     (const union uni_ieall *)&api->crankback, cx);
608                 break;
609             }
610
611           case UNIAPI_ABORT_CALL_request:
612             {
613                 const struct uniapi_abort_call_request *api = msg;
614
615                 uni_print_cref(NULL, 0, &api->cref, cx);
616                 break;
617             }
618         }
619
620   out:
621         cx->dont_init = old_dont_init;
622 }