sig_print.c revision 133492
1275970Scy/* 2275970Scy * Copyright (c) 2002-2003 3275970Scy * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4275970Scy * All rights reserved. 5275970Scy * 6275970Scy * Redistribution and use in source and binary forms, with or without 7275970Scy * modification, are permitted provided that the following conditions 8275970Scy * are met: 9275970Scy * 1. Redistributions of source code must retain the above copyright 10275970Scy * notice, this list of conditions and the following disclaimer. 11275970Scy * 2. Redistributions in binary form must reproduce the above copyright 12275970Scy * notice, this list of conditions and the following disclaimer in the 13275970Scy * documentation and/or other materials provided with the distribution. 14275970Scy * 15275970Scy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16275970Scy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17275970Scy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18275970Scy * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19275970Scy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20275970Scy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21275970Scy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22275970Scy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23275970Scy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24275970Scy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25275970Scy * SUCH DAMAGE. 26275970Scy * 27275970Scy * Author: Hartmut Brandt <harti@freebsd.org> 28275970Scy * Kendy Kutzner <kutzner@fokus.fraunhofer.de> 29275970Scy * 30275970Scy * $Begemot: libunimsg/netnatm/sig/sig_print.c,v 1.6 2004/08/05 07:11:02 brandt Exp $ 31275970Scy */ 32275970Scy 33275970Scy#include <sys/types.h> 34275970Scy#ifdef _KERNEL 35275970Scy#include <sys/param.h> 36275970Scy#include <sys/systm.h> 37275970Scy#include <sys/libkern.h> 38275970Scy#include <machine/stdarg.h> 39275970Scy#else 40275970Scy#include <stdio.h> 41275970Scy#include <stdlib.h> 42275970Scy#include <string.h> 43275970Scy#include <stdarg.h> 44275970Scy#endif 45275970Scy 46275970Scy#include <netnatm/saal/sscfu.h> 47275970Scy#include <netnatm/msg/uni_hdr.h> 48280849Scy#include <netnatm/msg/unistruct.h> 49280849Scy#include <netnatm/msg/unimsglib.h> 50280849Scy#include <netnatm/msg/uniprint.h> 51280849Scy#include <netnatm/sig/uni.h> 52280849Scy#include <netnatm/sig/unisig.h> 53280849Scy#include <netnatm/sig/unidef.h> 54280849Scy 55275970Scyconst char * 56275970Scyuni_strerr(u_int err) 57275970Scy{ 58275970Scy static const char *const errstr[] = { 59275970Scy#define DEF(NAME, VAL, STR) [UNIAPI_##NAME] = STR, 60275970ScyUNIAPI_DEF_ERRORS(DEF) 61275970Scy#undef DEF 62275970Scy }; 63275970Scy static char buf[100]; 64275970Scy 65275970Scy if (err >= sizeof(errstr)/sizeof(errstr[0]) || errstr[err] == NULL) { 66275970Scy sprintf(buf, "Unknown error %u", err); 67275970Scy return (buf); 68275970Scy } 69275970Scy return (errstr[err]); 70275970Scy} 71275970Scy 72275970Scy#define D(M) [M] = #M 73275970Scystatic const char *const msgs[] = { 74275970Scy D(UNIAPI_ERROR), 75275970Scy D(UNIAPI_CALL_CREATED), 76275970Scy D(UNIAPI_CALL_DESTROYED), 77275970Scy D(UNIAPI_PARTY_CREATED), 78275970Scy D(UNIAPI_PARTY_DESTROYED), 79275970Scy D(UNIAPI_LINK_ESTABLISH_request), 80275970Scy D(UNIAPI_LINK_ESTABLISH_confirm), 81275970Scy D(UNIAPI_LINK_RELEASE_request), 82275970Scy D(UNIAPI_LINK_RELEASE_confirm), 83275970Scy D(UNIAPI_RESET_request), 84275970Scy D(UNIAPI_RESET_confirm), 85275970Scy D(UNIAPI_RESET_indication), 86275970Scy D(UNIAPI_RESET_ERROR_indication), 87275970Scy D(UNIAPI_RESET_response), 88275970Scy D(UNIAPI_RESET_ERROR_response), 89275970Scy D(UNIAPI_RESET_STATUS_indication), 90275970Scy D(UNIAPI_SETUP_request), 91275970Scy D(UNIAPI_SETUP_indication), 92275970Scy D(UNIAPI_SETUP_response), 93275970Scy D(UNIAPI_SETUP_confirm), 94275970Scy D(UNIAPI_SETUP_COMPLETE_indication), 95275970Scy D(UNIAPI_SETUP_COMPLETE_request), 96275970Scy D(UNIAPI_ALERTING_request), 97275970Scy D(UNIAPI_ALERTING_indication), 98275970Scy D(UNIAPI_PROCEEDING_request), 99275970Scy D(UNIAPI_PROCEEDING_indication), 100275970Scy D(UNIAPI_RELEASE_request), 101275970Scy D(UNIAPI_RELEASE_indication), 102275970Scy D(UNIAPI_RELEASE_response), 103275970Scy D(UNIAPI_RELEASE_confirm), 104275970Scy D(UNIAPI_NOTIFY_request), 105275970Scy D(UNIAPI_NOTIFY_indication), 106275970Scy D(UNIAPI_STATUS_indication), 107275970Scy D(UNIAPI_STATUS_ENQUIRY_request), 108275970Scy D(UNIAPI_ADD_PARTY_request), 109275970Scy D(UNIAPI_ADD_PARTY_indication), 110275970Scy D(UNIAPI_PARTY_ALERTING_request), 111275970Scy D(UNIAPI_PARTY_ALERTING_indication), 112275970Scy D(UNIAPI_ADD_PARTY_ACK_request), 113275970Scy D(UNIAPI_ADD_PARTY_ACK_indication), 114275970Scy D(UNIAPI_ADD_PARTY_REJ_request), 115275970Scy D(UNIAPI_ADD_PARTY_REJ_indication), 116275970Scy D(UNIAPI_DROP_PARTY_request), 117275970Scy D(UNIAPI_DROP_PARTY_indication), 118275970Scy D(UNIAPI_DROP_PARTY_ACK_request), 119275970Scy D(UNIAPI_DROP_PARTY_ACK_indication), 120275970Scy D(UNIAPI_ABORT_CALL_request), 121275970Scy}; 122275970Scy#undef D 123275970Scy 124275970Scyvoid 125275970Scyuni_print_api(char *buf, size_t bufsiz, u_int type, u_int cookie, 126275970Scy const void *msg, struct unicx *cx) 127275970Scy{ 128275970Scy int old_dont_init = cx->dont_init; 129275970Scy 130275970Scy uni_print_init(buf, bufsiz, cx); 131275970Scy cx->dont_init = 1; 132275970Scy 133275970Scy if (type >= sizeof(msgs) / sizeof(msgs[0]) || msgs[type] == NULL) { 134275970Scy uni_print_flag("UNIAPI_UNKNOWN", cx); 135275970Scy uni_print_entry(cx, "sig", "%u", type); 136275970Scy uni_print_entry(cx, "cookie", "%u", cookie); 137275970Scy goto out; 138275970Scy } 139275970Scy 140275970Scy uni_print_flag(msgs[type], cx); 141275970Scy uni_print_entry(cx, "cookie", "%u", cookie); 142275970Scy cx->indent++; 143275970Scy 144275970Scy switch (type) { 145275970Scy 146275970Scy case UNIAPI_ERROR: 147275970Scy { 148275970Scy const struct uniapi_error *api = msg; 149275970Scy 150275970Scy uni_print_eol(cx); 151275970Scy uni_print_entry(cx, "reason", "%s", uni_strerr(api->reason)); 152275970Scy uni_print_entry(cx, "state", "U%u", api->state); 153275970Scy break; 154275970Scy } 155275970Scy 156275970Scy 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} 623