| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
#include "asterisk.h" |
| 56 |
|
| 57 |
#if defined(__NetBSD__) || defined(__FreeBSD__) |
| 58 |
#include <pthread.h> |
| 59 |
#else |
| 60 |
#include <sys/sysmacros.h> |
| 61 |
#endif |
| 62 |
#include <signal.h> |
| 63 |
#include <sys/stat.h> |
| 64 |
#include <math.h> |
| 65 |
|
| 66 |
#include "sig_analog.h" |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
#if defined(HAVE_PRI) |
| 74 |
#include "sig_pri.h" |
| 75 |
#ifndef PRI_RESTART |
| 76 |
#error "Upgrade your libpri" |
| 77 |
#endif |
| 78 |
#endif |
| 79 |
|
| 80 |
#if defined(HAVE_SS7) |
| 81 |
#include "sig_ss7.h" |
| 82 |
#if !defined(LIBSS7_ABI_COMPATIBILITY) |
| 83 |
#error "Upgrade your libss7" |
| 84 |
#elif LIBSS7_ABI_COMPATIBILITY != 2 |
| 85 |
#error "Your installed libss7 is not compatible" |
| 86 |
#endif |
| 87 |
#endif |
| 88 |
|
| 89 |
#if defined(HAVE_OPENR2) |
| 90 |
|
| 91 |
#define SIG_MFCR2_MAX_CHANNELS 672 |
| 92 |
#endif |
| 93 |
|
| 94 |
#include "asterisk/lock.h" |
| 95 |
#include "asterisk/channel.h" |
| 96 |
#include "asterisk/config.h" |
| 97 |
#include "asterisk/module.h" |
| 98 |
#include "asterisk/pbx.h" |
| 99 |
#include "asterisk/file.h" |
| 100 |
#include "asterisk/ulaw.h" |
| 101 |
#include "asterisk/alaw.h" |
| 102 |
#include "asterisk/callerid.h" |
| 103 |
#include "asterisk/adsi.h" |
| 104 |
#include "asterisk/cli.h" |
| 105 |
#include "asterisk/pickup.h" |
| 106 |
#include "asterisk/features.h" |
| 107 |
#include "asterisk/musiconhold.h" |
| 108 |
#include "asterisk/say.h" |
| 109 |
#include "asterisk/tdd.h" |
| 110 |
#include "asterisk/mwi.h" |
| 111 |
#include "asterisk/dsp.h" |
| 112 |
#include "asterisk/astdb.h" |
| 113 |
#include "asterisk/manager.h" |
| 114 |
#include "asterisk/causes.h" |
| 115 |
#include "asterisk/term.h" |
| 116 |
#include "asterisk/utils.h" |
| 117 |
#include "asterisk/transcap.h" |
| 118 |
#include "asterisk/stringfields.h" |
| 119 |
#include "asterisk/abstract_jb.h" |
| 120 |
#include "asterisk/smdi.h" |
| 121 |
#include "asterisk/devicestate.h" |
| 122 |
#include "asterisk/paths.h" |
| 123 |
#include "asterisk/ccss.h" |
| 124 |
#include "asterisk/features_config.h" |
| 125 |
#include "asterisk/bridge.h" |
| 126 |
#include "asterisk/stasis_channels.h" |
| 127 |
#include "asterisk/parking.h" |
| 128 |
#include "asterisk/format_cache.h" |
| 129 |
#include "chan_dahdi.h" |
| 130 |
#include "dahdi/bridge_native_dahdi.h" |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
#define SMDI_MD_WAIT_TIMEOUT 1500 |
| 734 |
|
| 735 |
static const char * const lbostr[] = { |
| 736 |
"0 db (CSU)/0-133 feet (DSX-1)", |
| 737 |
"133-266 feet (DSX-1)", |
| 738 |
"266-399 feet (DSX-1)", |
| 739 |
"399-533 feet (DSX-1)", |
| 740 |
"533-655 feet (DSX-1)", |
| 741 |
"-7.5db (CSU)", |
| 742 |
"-15db (CSU)", |
| 743 |
"-22.5db (CSU)" |
| 744 |
}; |
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
static struct ast_jb_conf default_jbconf = |
| 749 |
{ |
| 750 |
.flags = 0, |
| 751 |
.max_size = 200, |
| 752 |
.resync_threshold = 1000, |
| 753 |
.impl = "fixed", |
| 754 |
.target_extra = 40, |
| 755 |
}; |
| 756 |
static struct ast_jb_conf global_jbconf; |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
#define DEFAULT_CIDRINGS 1 |
| 771 |
|
| 772 |
#define AST_LAW(p) (((p)->law == DAHDI_LAW_ALAW) ? ast_format_alaw : ast_format_ulaw) |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
#define NEED_MFDETECT(p) (((p)->sig == SIG_FEATDMF) || ((p)->sig == SIG_FEATDMF_TA) || ((p)->sig == SIG_E911) || ((p)->sig == SIG_FGC_CAMA) || ((p)->sig == SIG_FGC_CAMAMF) || ((p)->sig == SIG_FEATB)) |
| 777 |
|
| 778 |
static const char tdesc[] = "DAHDI Telephony" |
| 779 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) || defined(HAVE_OPENR2) |
| 780 |
" w/" |
| 781 |
#if defined(HAVE_PRI) |
| 782 |
"PRI" |
| 783 |
#endif |
| 784 |
#if defined(HAVE_SS7) |
| 785 |
#if defined(HAVE_PRI) |
| 786 |
" & " |
| 787 |
#endif |
| 788 |
"SS7" |
| 789 |
#endif |
| 790 |
#if defined(HAVE_OPENR2) |
| 791 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 792 |
" & " |
| 793 |
#endif |
| 794 |
"MFC/R2" |
| 795 |
#endif |
| 796 |
#endif |
| 797 |
; |
| 798 |
|
| 799 |
static const char config[] = "chan_dahdi.conf"; |
| 800 |
|
| 801 |
#ifdef LOTS_OF_SPANS |
| 802 |
#define NUM_SPANS DAHDI_MAX_SPANS |
| 803 |
#else |
| 804 |
#define NUM_SPANS 32 |
| 805 |
#endif |
| 806 |
|
| 807 |
#define CHAN_PSEUDO -2 |
| 808 |
|
| 809 |
#define CALLPROGRESS_PROGRESS 1 |
| 810 |
#define CALLPROGRESS_FAX_OUTGOING 2 |
| 811 |
#define CALLPROGRESS_FAX_INCOMING 4 |
| 812 |
#define CALLPROGRESS_FAX (CALLPROGRESS_FAX_INCOMING | CALLPROGRESS_FAX_OUTGOING) |
| 813 |
|
| 814 |
#define NUM_CADENCE_MAX 25 |
| 815 |
static int num_cadence = 4; |
| 816 |
static int user_has_defined_cadences = 0; |
| 817 |
|
| 818 |
static int has_pseudo; |
| 819 |
|
| 820 |
static struct dahdi_ring_cadence cadences[NUM_CADENCE_MAX] = { |
| 821 |
{ { 125, 125, 2000, 4000 } }, |
| 822 |
{ { 250, 250, 500, 1000, 250, 250, 500, 4000 } }, |
| 823 |
{ { 125, 125, 125, 125, 125, 4000 } }, |
| 824 |
{ { 1000, 500, 2500, 5000 } }, |
| 825 |
}; |
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
static int cidrings[NUM_CADENCE_MAX] = { |
| 832 |
2, |
| 833 |
4, |
| 834 |
3, |
| 835 |
2, |
| 836 |
}; |
| 837 |
|
| 838 |
|
| 839 |
static struct dahdi_ring_cadence AS_RP_cadence = {{250, 10000}}; |
| 840 |
|
| 841 |
#define ISTRUNK(p) ((p->sig == SIG_FXSLS) || (p->sig == SIG_FXSKS) || \ |
| 842 |
(p->sig == SIG_FXSGS) || (p->sig == SIG_PRI)) |
| 843 |
|
| 844 |
#define CANBUSYDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) ) |
| 845 |
#define CANPROGRESSDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) ) |
| 846 |
|
| 847 |
static char defaultcic[64] = ""; |
| 848 |
static char defaultozz[64] = ""; |
| 849 |
|
| 850 |
|
| 851 |
static char mwimonitornotify[PATH_MAX] = ""; |
| 852 |
#ifndef HAVE_DAHDI_LINEREVERSE_VMWI |
| 853 |
static int mwisend_rpas = 0; |
| 854 |
#endif |
| 855 |
|
| 856 |
static char progzone[10] = ""; |
| 857 |
|
| 858 |
static int usedistinctiveringdetection = 0; |
| 859 |
static int distinctiveringaftercid = 0; |
| 860 |
|
| 861 |
static int numbufs = 4; |
| 862 |
|
| 863 |
static int mwilevel = 512; |
| 864 |
static int dtmfcid_level = 256; |
| 865 |
|
| 866 |
#define REPORT_CHANNEL_ALARMS 1 |
| 867 |
#define REPORT_SPAN_ALARMS 2 |
| 868 |
static int report_alarms = REPORT_CHANNEL_ALARMS; |
| 869 |
|
| 870 |
#ifdef HAVE_PRI |
| 871 |
static int pridebugfd = -1; |
| 872 |
static char pridebugfilename[1024] = ""; |
| 873 |
#endif |
| 874 |
|
| 875 |
|
| 876 |
AST_MUTEX_DEFINE_STATIC(iflock); |
| 877 |
|
| 878 |
|
| 879 |
static int ifcount = 0; |
| 880 |
|
| 881 |
#ifdef HAVE_PRI |
| 882 |
AST_MUTEX_DEFINE_STATIC(pridebugfdlock); |
| 883 |
#endif |
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
AST_MUTEX_DEFINE_STATIC(monlock); |
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
static pthread_t monitor_thread = AST_PTHREADT_NULL; |
| 892 |
static ast_cond_t ss_thread_complete; |
| 893 |
AST_MUTEX_DEFINE_STATIC(ss_thread_lock); |
| 894 |
AST_MUTEX_DEFINE_STATIC(restart_lock); |
| 895 |
static int ss_thread_count = 0; |
| 896 |
static int num_restart_pending = 0; |
| 897 |
|
| 898 |
static int restart_monitor(void); |
| 899 |
|
| 900 |
static int dahdi_sendtext(struct ast_channel *c, const char *text); |
| 901 |
|
| 902 |
|
| 903 |
static inline int dahdi_get_event(int fd) |
| 904 |
{ |
| 905 |
int j; |
| 906 |
if (ioctl(fd, DAHDI_GETEVENT, &j) == -1) |
| 907 |
return -1; |
| 908 |
return j; |
| 909 |
} |
| 910 |
|
| 911 |
|
| 912 |
static inline int dahdi_wait_event(int fd) |
| 913 |
{ |
| 914 |
int i, j = 0; |
| 915 |
i = DAHDI_IOMUX_SIGEVENT; |
| 916 |
if (ioctl(fd, DAHDI_IOMUX, &i) == -1) |
| 917 |
return -1; |
| 918 |
if (ioctl(fd, DAHDI_GETEVENT, &j) == -1) |
| 919 |
return -1; |
| 920 |
return j; |
| 921 |
} |
| 922 |
|
| 923 |
|
| 924 |
#define READ_SIZE 160 |
| 925 |
|
| 926 |
#define MASK_AVAIL (1 << 0) |
| 927 |
#define MASK_INUSE (1 << 1) |
| 928 |
|
| 929 |
#define CALLWAITING_SILENT_SAMPLES ((300 * 8) / READ_SIZE) |
| 930 |
#define CALLWAITING_REPEAT_SAMPLES ((10000 * 8) / READ_SIZE) |
| 931 |
#define CALLWAITING_SUPPRESS_SAMPLES ((100 * 8) / READ_SIZE) |
| 932 |
#define CIDCW_EXPIRE_SAMPLES ((500 * 8) / READ_SIZE) |
| 933 |
#define MIN_MS_SINCE_FLASH ((2000) ) |
| 934 |
#define DEFAULT_RINGT ((8000 * 8) / READ_SIZE) |
| 935 |
#define DEFAULT_DIALTONE_DETECT_TIMEOUT ((10000 * 8) / READ_SIZE) |
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
static int ringt_base = DEFAULT_RINGT; |
| 942 |
|
| 943 |
#if defined(HAVE_SS7) |
| 944 |
|
| 945 |
struct dahdi_ss7 { |
| 946 |
struct sig_ss7_linkset ss7; |
| 947 |
}; |
| 948 |
|
| 949 |
static struct dahdi_ss7 linksets[NUM_SPANS]; |
| 950 |
|
| 951 |
static int cur_ss7type = -1; |
| 952 |
static int cur_slc = -1; |
| 953 |
static int cur_linkset = -1; |
| 954 |
static int cur_pointcode = -1; |
| 955 |
static int cur_cicbeginswith = -1; |
| 956 |
static int cur_adjpointcode = -1; |
| 957 |
static int cur_networkindicator = -1; |
| 958 |
static int cur_defaultdpc = -1; |
| 959 |
#endif |
| 960 |
|
| 961 |
#ifdef HAVE_OPENR2 |
| 962 |
struct dahdi_mfcr2_conf { |
| 963 |
openr2_variant_t variant; |
| 964 |
int mfback_timeout; |
| 965 |
int metering_pulse_timeout; |
| 966 |
int max_ani; |
| 967 |
int max_dnis; |
| 968 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2 |
| 969 |
int dtmf_time_on; |
| 970 |
int dtmf_time_off; |
| 971 |
#endif |
| 972 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3 |
| 973 |
int dtmf_end_timeout; |
| 974 |
#endif |
| 975 |
signed int get_ani_first:2; |
| 976 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1 |
| 977 |
signed int skip_category_request:2; |
| 978 |
#endif |
| 979 |
unsigned int call_files:1; |
| 980 |
unsigned int allow_collect_calls:1; |
| 981 |
unsigned int charge_calls:1; |
| 982 |
unsigned int accept_on_offer:1; |
| 983 |
unsigned int forced_release:1; |
| 984 |
unsigned int double_answer:1; |
| 985 |
signed int immediate_accept:2; |
| 986 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2 |
| 987 |
signed int dtmf_dialing:2; |
| 988 |
signed int dtmf_detection:2; |
| 989 |
#endif |
| 990 |
char logdir[OR2_MAX_PATH]; |
| 991 |
char r2proto_file[OR2_MAX_PATH]; |
| 992 |
openr2_log_level_t loglevel; |
| 993 |
openr2_calling_party_category_t category; |
| 994 |
}; |
| 995 |
|
| 996 |
|
| 997 |
struct dahdi_mfcr2 { |
| 998 |
int index; |
| 999 |
pthread_t r2master; |
| 1000 |
openr2_context_t *protocol_context; |
| 1001 |
struct dahdi_pvt *pvts[SIG_MFCR2_MAX_CHANNELS]; |
| 1002 |
int numchans; |
| 1003 |
int live_chans; |
| 1004 |
int nodev; |
| 1005 |
struct dahdi_mfcr2_conf conf; |
| 1006 |
}; |
| 1007 |
|
| 1008 |
struct r2link_entry { |
| 1009 |
struct dahdi_mfcr2 mfcr2; |
| 1010 |
AST_LIST_ENTRY(r2link_entry) list; |
| 1011 |
}; |
| 1012 |
static AST_LIST_HEAD_STATIC(r2links, r2link_entry); |
| 1013 |
static struct r2links nodev_r2links = AST_LIST_HEAD_INIT_VALUE; |
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
static int r2links_count = 0; |
| 1018 |
|
| 1019 |
#endif |
| 1020 |
|
| 1021 |
#ifdef HAVE_PRI |
| 1022 |
|
| 1023 |
struct dahdi_pri { |
| 1024 |
int dchannels[SIG_PRI_NUM_DCHANS]; |
| 1025 |
int mastertrunkgroup; |
| 1026 |
int prilogicalspan; |
| 1027 |
struct sig_pri_span pri; |
| 1028 |
}; |
| 1029 |
|
| 1030 |
static struct dahdi_pri pris[NUM_SPANS]; |
| 1031 |
|
| 1032 |
#if defined(HAVE_PRI_CCSS) |
| 1033 |
|
| 1034 |
static const char dahdi_pri_cc_type[] = "DAHDI/PRI"; |
| 1035 |
#endif |
| 1036 |
|
| 1037 |
#else |
| 1038 |
|
| 1039 |
struct dahdi_pri; |
| 1040 |
#endif |
| 1041 |
|
| 1042 |
|
| 1043 |
#define POLARITY_IDLE 0 |
| 1044 |
#define POLARITY_REV 1 |
| 1045 |
|
| 1046 |
const char * const subnames[] = { |
| 1047 |
"Real", |
| 1048 |
"Callwait", |
| 1049 |
"Threeway" |
| 1050 |
}; |
| 1051 |
|
| 1052 |
static struct dahdi_pvt *iflist = NULL; |
| 1053 |
static struct dahdi_pvt *ifend = NULL; |
| 1054 |
|
| 1055 |
#if defined(HAVE_PRI) |
| 1056 |
struct doomed_pri { |
| 1057 |
struct sig_pri_span *pri; |
| 1058 |
AST_LIST_ENTRY(doomed_pri) list; |
| 1059 |
}; |
| 1060 |
static AST_LIST_HEAD_STATIC(doomed_pris, doomed_pri); |
| 1061 |
|
| 1062 |
static void pri_destroy_span(struct sig_pri_span *pri); |
| 1063 |
|
| 1064 |
static struct dahdi_parms_pseudo { |
| 1065 |
int buf_no; |
| 1066 |
int buf_policy; |
| 1067 |
int faxbuf_no; |
| 1068 |
int faxbuf_policy; |
| 1069 |
} dahdi_pseudo_parms; |
| 1070 |
#endif |
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
struct dahdi_chan_conf { |
| 1083 |
struct dahdi_pvt chan; |
| 1084 |
#ifdef HAVE_PRI |
| 1085 |
struct dahdi_pri pri; |
| 1086 |
#endif |
| 1087 |
|
| 1088 |
#if defined(HAVE_SS7) |
| 1089 |
struct dahdi_ss7 ss7; |
| 1090 |
#endif |
| 1091 |
|
| 1092 |
#ifdef HAVE_OPENR2 |
| 1093 |
struct dahdi_mfcr2_conf mfcr2; |
| 1094 |
#endif |
| 1095 |
struct dahdi_params timing; |
| 1096 |
int is_sig_auto; |
| 1097 |
|
| 1098 |
int ignore_failed_channels; |
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
char smdi_port[SMDI_MAX_FILENAME_LEN]; |
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
int wanted_channels_start; |
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
int wanted_channels_end; |
| 1117 |
}; |
| 1118 |
|
| 1119 |
|
| 1120 |
static struct dahdi_chan_conf dahdi_chan_conf_default(void) |
| 1121 |
{ |
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
struct dahdi_chan_conf conf = { |
| 1126 |
#ifdef HAVE_PRI |
| 1127 |
.pri.pri = { |
| 1128 |
.nsf = PRI_NSF_NONE, |
| 1129 |
.switchtype = PRI_SWITCH_NI2, |
| 1130 |
.dialplan = PRI_UNKNOWN + 1, |
| 1131 |
.localdialplan = PRI_NATIONAL_ISDN + 1, |
| 1132 |
.nodetype = PRI_CPE, |
| 1133 |
.qsigchannelmapping = DAHDI_CHAN_MAPPING_PHYSICAL, |
| 1134 |
|
| 1135 |
#if defined(HAVE_PRI_CCSS) |
| 1136 |
.cc_ptmp_recall_mode = 1, |
| 1137 |
.cc_qsig_signaling_link_req = 1, |
| 1138 |
.cc_qsig_signaling_link_rsp = 1, |
| 1139 |
#endif |
| 1140 |
|
| 1141 |
.minunused = 2, |
| 1142 |
.idleext = "", |
| 1143 |
.idledial = "", |
| 1144 |
.internationalprefix = "", |
| 1145 |
.nationalprefix = "", |
| 1146 |
.localprefix = "", |
| 1147 |
.privateprefix = "", |
| 1148 |
.unknownprefix = "", |
| 1149 |
.colp_send = SIG_PRI_COLP_UPDATE, |
| 1150 |
.resetinterval = -1, |
| 1151 |
}, |
| 1152 |
#endif |
| 1153 |
#if defined(HAVE_SS7) |
| 1154 |
.ss7.ss7 = { |
| 1155 |
.called_nai = SS7_NAI_NATIONAL, |
| 1156 |
.calling_nai = SS7_NAI_NATIONAL, |
| 1157 |
.internationalprefix = "", |
| 1158 |
.nationalprefix = "", |
| 1159 |
.subscriberprefix = "", |
| 1160 |
.unknownprefix = "", |
| 1161 |
.networkroutedprefix = "" |
| 1162 |
}, |
| 1163 |
#endif |
| 1164 |
#ifdef HAVE_OPENR2 |
| 1165 |
.mfcr2 = { |
| 1166 |
.variant = OR2_VAR_ITU, |
| 1167 |
.mfback_timeout = -1, |
| 1168 |
.metering_pulse_timeout = -1, |
| 1169 |
.max_ani = 10, |
| 1170 |
.max_dnis = 4, |
| 1171 |
.get_ani_first = -1, |
| 1172 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1 |
| 1173 |
.skip_category_request = -1, |
| 1174 |
#endif |
| 1175 |
.call_files = 0, |
| 1176 |
.allow_collect_calls = 0, |
| 1177 |
.charge_calls = 1, |
| 1178 |
.accept_on_offer = 1, |
| 1179 |
.forced_release = 0, |
| 1180 |
.double_answer = 0, |
| 1181 |
.immediate_accept = -1, |
| 1182 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2 |
| 1183 |
.dtmf_dialing = -1, |
| 1184 |
.dtmf_detection = -1, |
| 1185 |
.dtmf_time_on = OR2_DEFAULT_DTMF_ON, |
| 1186 |
.dtmf_time_off = OR2_DEFAULT_DTMF_OFF, |
| 1187 |
#endif |
| 1188 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3 |
| 1189 |
.dtmf_end_timeout = -1, |
| 1190 |
#endif |
| 1191 |
.logdir = "", |
| 1192 |
.r2proto_file = "", |
| 1193 |
.loglevel = OR2_LOG_ERROR | OR2_LOG_WARNING, |
| 1194 |
.category = OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER |
| 1195 |
}, |
| 1196 |
#endif |
| 1197 |
.chan = { |
| 1198 |
.context = "default", |
| 1199 |
.immediatering = 1, |
| 1200 |
.cid_num = "", |
| 1201 |
.cid_name = "", |
| 1202 |
.cid_tag = "", |
| 1203 |
.mohinterpret = "default", |
| 1204 |
.mohsuggest = "", |
| 1205 |
.parkinglot = "", |
| 1206 |
.transfertobusy = 1, |
| 1207 |
.permdialmode = ANALOG_DIALMODE_BOTH, |
| 1208 |
|
| 1209 |
.ani_info_digits = 2, |
| 1210 |
.ani_wink_time = 1000, |
| 1211 |
.ani_timeout = 10000, |
| 1212 |
|
| 1213 |
.cid_signalling = CID_SIG_BELL, |
| 1214 |
.cid_start = CID_START_RING, |
| 1215 |
.dahditrcallerid = 0, |
| 1216 |
.use_callerid = 1, |
| 1217 |
.sig = -1, |
| 1218 |
.outsigmod = -1, |
| 1219 |
|
| 1220 |
.cid_rxgain = +5.0, |
| 1221 |
|
| 1222 |
.tonezone = -1, |
| 1223 |
|
| 1224 |
.echocancel.head.tap_length = 1, |
| 1225 |
|
| 1226 |
.busycount = 3, |
| 1227 |
|
| 1228 |
.accountcode = "", |
| 1229 |
|
| 1230 |
.mailbox = "", |
| 1231 |
|
| 1232 |
#ifdef HAVE_DAHDI_LINEREVERSE_VMWI |
| 1233 |
.mwisend_fsk = 1, |
| 1234 |
#endif |
| 1235 |
.polarityonanswerdelay = 600, |
| 1236 |
|
| 1237 |
.sendcalleridafter = DEFAULT_CIDRINGS, |
| 1238 |
|
| 1239 |
.buf_policy = DAHDI_POLICY_IMMEDIATE, |
| 1240 |
.buf_no = numbufs, |
| 1241 |
.usefaxbuffers = 0, |
| 1242 |
.cc_params = ast_cc_config_params_init(), |
| 1243 |
.firstdigit_timeout = ANALOG_FIRST_DIGIT_TIMEOUT, |
| 1244 |
.interdigit_timeout = ANALOG_INTER_DIGIT_TIMEOUT, |
| 1245 |
.matchdigit_timeout = ANALOG_MATCH_DIGIT_TIMEOUT, |
| 1246 |
}, |
| 1247 |
.timing = { |
| 1248 |
.prewinktime = -1, |
| 1249 |
.preflashtime = -1, |
| 1250 |
.winktime = -1, |
| 1251 |
.flashtime = -1, |
| 1252 |
.starttime = -1, |
| 1253 |
.rxwinktime = -1, |
| 1254 |
.rxflashtime = -1, |
| 1255 |
.debouncetime = -1 |
| 1256 |
}, |
| 1257 |
.is_sig_auto = 1, |
| 1258 |
.ignore_failed_channels = 1, |
| 1259 |
.smdi_port = "/dev/ttyS0", |
| 1260 |
}; |
| 1261 |
|
| 1262 |
return conf; |
| 1263 |
} |
| 1264 |
|
| 1265 |
|
| 1266 |
static struct ast_channel *dahdi_request(const char *type, struct ast_format_cap *cap, |
| 1267 |
const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, |
| 1268 |
const char *data, int *cause); |
| 1269 |
static int dahdi_digit_begin(struct ast_channel *ast, char digit); |
| 1270 |
static int dahdi_digit_end(struct ast_channel *ast, char digit, unsigned int duration); |
| 1271 |
static int dahdi_sendtext(struct ast_channel *c, const char *text); |
| 1272 |
static int dahdi_call(struct ast_channel *ast, const char *rdest, int timeout); |
| 1273 |
static int dahdi_hangup(struct ast_channel *ast); |
| 1274 |
static int dahdi_answer(struct ast_channel *ast); |
| 1275 |
static struct ast_frame *dahdi_read(struct ast_channel *ast); |
| 1276 |
static int dahdi_write(struct ast_channel *ast, struct ast_frame *frame); |
| 1277 |
static struct ast_frame *dahdi_exception(struct ast_channel *ast); |
| 1278 |
static int dahdi_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen); |
| 1279 |
static int dahdi_fixup(struct ast_channel *oldchan, struct ast_channel *newchan); |
| 1280 |
static int dahdi_setoption(struct ast_channel *chan, int option, void *data, int datalen); |
| 1281 |
static int dahdi_queryoption(struct ast_channel *chan, int option, void *data, int *datalen); |
| 1282 |
static int dahdi_func_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len); |
| 1283 |
static int dahdi_func_write(struct ast_channel *chan, const char *function, char *data, const char *value); |
| 1284 |
static int dahdi_devicestate(const char *data); |
| 1285 |
static int dahdi_cc_callback(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback); |
| 1286 |
|
| 1287 |
static struct ast_channel_tech dahdi_tech = { |
| 1288 |
.type = "DAHDI", |
| 1289 |
.description = tdesc, |
| 1290 |
.requester = dahdi_request, |
| 1291 |
.send_digit_begin = dahdi_digit_begin, |
| 1292 |
.send_digit_end = dahdi_digit_end, |
| 1293 |
.send_text = dahdi_sendtext, |
| 1294 |
.call = dahdi_call, |
| 1295 |
.hangup = dahdi_hangup, |
| 1296 |
.answer = dahdi_answer, |
| 1297 |
.read = dahdi_read, |
| 1298 |
.write = dahdi_write, |
| 1299 |
.exception = dahdi_exception, |
| 1300 |
.indicate = dahdi_indicate, |
| 1301 |
.fixup = dahdi_fixup, |
| 1302 |
.setoption = dahdi_setoption, |
| 1303 |
.queryoption = dahdi_queryoption, |
| 1304 |
.func_channel_read = dahdi_func_read, |
| 1305 |
.func_channel_write = dahdi_func_write, |
| 1306 |
.devicestate = dahdi_devicestate, |
| 1307 |
.cc_callback = dahdi_cc_callback, |
| 1308 |
}; |
| 1309 |
|
| 1310 |
#define GET_CHANNEL(p) ((p)->channel) |
| 1311 |
|
| 1312 |
static enum analog_sigtype dahdisig_to_analogsig(int sig) |
| 1313 |
{ |
| 1314 |
switch (sig) { |
| 1315 |
case SIG_FXOLS: |
| 1316 |
return ANALOG_SIG_FXOLS; |
| 1317 |
case SIG_FXOGS: |
| 1318 |
return ANALOG_SIG_FXOGS; |
| 1319 |
case SIG_FXOKS: |
| 1320 |
return ANALOG_SIG_FXOKS; |
| 1321 |
case SIG_FXSLS: |
| 1322 |
return ANALOG_SIG_FXSLS; |
| 1323 |
case SIG_FXSGS: |
| 1324 |
return ANALOG_SIG_FXSGS; |
| 1325 |
case SIG_FXSKS: |
| 1326 |
return ANALOG_SIG_FXSKS; |
| 1327 |
case SIG_EMWINK: |
| 1328 |
return ANALOG_SIG_EMWINK; |
| 1329 |
case SIG_EM: |
| 1330 |
return ANALOG_SIG_EM; |
| 1331 |
case SIG_EM_E1: |
| 1332 |
return ANALOG_SIG_EM_E1; |
| 1333 |
case SIG_FEATD: |
| 1334 |
return ANALOG_SIG_FEATD; |
| 1335 |
case SIG_FEATDMF: |
| 1336 |
return ANALOG_SIG_FEATDMF; |
| 1337 |
case SIG_E911: |
| 1338 |
return SIG_E911; |
| 1339 |
case SIG_FGC_CAMA: |
| 1340 |
return ANALOG_SIG_FGC_CAMA; |
| 1341 |
case SIG_FGC_CAMAMF: |
| 1342 |
return ANALOG_SIG_FGC_CAMAMF; |
| 1343 |
case SIG_FEATB: |
| 1344 |
return ANALOG_SIG_FEATB; |
| 1345 |
case SIG_SFWINK: |
| 1346 |
return ANALOG_SIG_SFWINK; |
| 1347 |
case SIG_SF: |
| 1348 |
return ANALOG_SIG_SF; |
| 1349 |
case SIG_SF_FEATD: |
| 1350 |
return ANALOG_SIG_SF_FEATD; |
| 1351 |
case SIG_SF_FEATDMF: |
| 1352 |
return ANALOG_SIG_SF_FEATDMF; |
| 1353 |
case SIG_FEATDMF_TA: |
| 1354 |
return ANALOG_SIG_FEATDMF_TA; |
| 1355 |
case SIG_SF_FEATB: |
| 1356 |
return ANALOG_SIG_FEATB; |
| 1357 |
default: |
| 1358 |
return -1; |
| 1359 |
} |
| 1360 |
} |
| 1361 |
|
| 1362 |
|
| 1363 |
static int analog_tone_to_dahditone(enum analog_tone tone) |
| 1364 |
{ |
| 1365 |
switch (tone) { |
| 1366 |
case ANALOG_TONE_RINGTONE: |
| 1367 |
return DAHDI_TONE_RINGTONE; |
| 1368 |
case ANALOG_TONE_STUTTER: |
| 1369 |
return DAHDI_TONE_STUTTER; |
| 1370 |
case ANALOG_TONE_CONGESTION: |
| 1371 |
return DAHDI_TONE_CONGESTION; |
| 1372 |
case ANALOG_TONE_DIALTONE: |
| 1373 |
return DAHDI_TONE_DIALTONE; |
| 1374 |
case ANALOG_TONE_DIALRECALL: |
| 1375 |
return DAHDI_TONE_DIALRECALL; |
| 1376 |
case ANALOG_TONE_INFO: |
| 1377 |
return DAHDI_TONE_INFO; |
| 1378 |
default: |
| 1379 |
return -1; |
| 1380 |
} |
| 1381 |
} |
| 1382 |
|
| 1383 |
static int analogsub_to_dahdisub(enum analog_sub analogsub) |
| 1384 |
{ |
| 1385 |
int index; |
| 1386 |
|
| 1387 |
switch (analogsub) { |
| 1388 |
case ANALOG_SUB_REAL: |
| 1389 |
index = SUB_REAL; |
| 1390 |
break; |
| 1391 |
case ANALOG_SUB_CALLWAIT: |
| 1392 |
index = SUB_CALLWAIT; |
| 1393 |
break; |
| 1394 |
case ANALOG_SUB_THREEWAY: |
| 1395 |
index = SUB_THREEWAY; |
| 1396 |
break; |
| 1397 |
default: |
| 1398 |
ast_log(LOG_ERROR, "Unidentified sub!\n"); |
| 1399 |
index = SUB_REAL; |
| 1400 |
} |
| 1401 |
|
| 1402 |
return index; |
| 1403 |
} |
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
static void release_doomed_pris(void) |
| 1414 |
{ |
| 1415 |
#ifdef HAVE_PRI |
| 1416 |
struct doomed_pri *entry; |
| 1417 |
|
| 1418 |
AST_LIST_LOCK(&doomed_pris); |
| 1419 |
while ((entry = AST_LIST_REMOVE_HEAD(&doomed_pris, list))) { |
| 1420 |
|
| 1421 |
AST_LIST_UNLOCK(&doomed_pris); |
| 1422 |
ast_debug(4, "Destroying span %d from doomed queue.\n", |
| 1423 |
entry->pri->span); |
| 1424 |
pri_destroy_span(entry->pri); |
| 1425 |
ast_free(entry); |
| 1426 |
AST_LIST_LOCK(&doomed_pris); |
| 1427 |
} |
| 1428 |
AST_LIST_UNLOCK(&doomed_pris); |
| 1429 |
#endif |
| 1430 |
} |
| 1431 |
|
| 1432 |
#ifdef HAVE_PRI |
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
static void pri_queue_for_destruction(struct sig_pri_span *pri) |
| 1444 |
{ |
| 1445 |
struct doomed_pri *entry; |
| 1446 |
|
| 1447 |
AST_LIST_LOCK(&doomed_pris); |
| 1448 |
AST_LIST_TRAVERSE(&doomed_pris, entry, list) { |
| 1449 |
if (entry->pri == pri) { |
| 1450 |
AST_LIST_UNLOCK(&doomed_pris); |
| 1451 |
return; |
| 1452 |
} |
| 1453 |
} |
| 1454 |
entry = ast_calloc(sizeof(struct doomed_pri), 1); |
| 1455 |
if (!entry) { |
| 1456 |
|
| 1457 |
ast_log(LOG_WARNING, "Failed allocating memory for a doomed_pri.\n"); |
| 1458 |
AST_LIST_UNLOCK(&doomed_pris); |
| 1459 |
return; |
| 1460 |
} |
| 1461 |
entry->pri = pri; |
| 1462 |
ast_debug(4, "Queue span %d for destruction.\n", pri->span); |
| 1463 |
AST_LIST_INSERT_TAIL(&doomed_pris, entry, list); |
| 1464 |
AST_LIST_UNLOCK(&doomed_pris); |
| 1465 |
} |
| 1466 |
#endif |
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
static int dahdi_dial_str(struct dahdi_pvt *pvt, int operation, const char *dial_str) |
| 1481 |
{ |
| 1482 |
int res; |
| 1483 |
int offset; |
| 1484 |
const char *pos; |
| 1485 |
struct dahdi_dialoperation zo = { |
| 1486 |
.op = operation, |
| 1487 |
}; |
| 1488 |
|
| 1489 |
|
| 1490 |
pos = dial_str; |
| 1491 |
for (offset = 0; offset < sizeof(zo.dialstr) - 1; ++offset) { |
| 1492 |
if (!*pos) { |
| 1493 |
break; |
| 1494 |
} |
| 1495 |
if (*pos == 'W') { |
| 1496 |
|
| 1497 |
++pos; |
| 1498 |
if (offset >= sizeof(zo.dialstr) - 3) { |
| 1499 |
|
| 1500 |
break; |
| 1501 |
} |
| 1502 |
zo.dialstr[offset] = 'w'; |
| 1503 |
++offset; |
| 1504 |
zo.dialstr[offset] = 'w'; |
| 1505 |
continue; |
| 1506 |
} |
| 1507 |
zo.dialstr[offset] = *pos++; |
| 1508 |
} |
| 1509 |
|
| 1510 |
|
| 1511 |
ast_debug(1, "Channel %d: Dial str '%s' expanded to '%s' sent to DAHDI_DIAL.\n", |
| 1512 |
pvt->channel, dial_str, zo.dialstr); |
| 1513 |
res = ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_DIAL, &zo); |
| 1514 |
if (res) { |
| 1515 |
ast_log(LOG_WARNING, "Channel %d: Couldn't dial '%s': %s\n", |
| 1516 |
pvt->channel, dial_str, strerror(errno)); |
| 1517 |
} |
| 1518 |
|
| 1519 |
return res; |
| 1520 |
} |
| 1521 |
|
| 1522 |
static enum analog_event dahdievent_to_analogevent(int event); |
| 1523 |
static int bump_gains(struct dahdi_pvt *p); |
| 1524 |
static int dahdi_setlinear(int dfd, int linear); |
| 1525 |
|
| 1526 |
static int my_start_cid_detect(void *pvt, int cid_signalling) |
| 1527 |
{ |
| 1528 |
struct dahdi_pvt *p = pvt; |
| 1529 |
int index = SUB_REAL; |
| 1530 |
p->cs = callerid_new(cid_signalling); |
| 1531 |
if (!p->cs) { |
| 1532 |
ast_log(LOG_ERROR, "Unable to alloc callerid\n"); |
| 1533 |
return -1; |
| 1534 |
} |
| 1535 |
bump_gains(p); |
| 1536 |
dahdi_setlinear(p->subs[index].dfd, 0); |
| 1537 |
|
| 1538 |
return 0; |
| 1539 |
} |
| 1540 |
|
| 1541 |
static int restore_gains(struct dahdi_pvt *p); |
| 1542 |
|
| 1543 |
static int my_stop_cid_detect(void *pvt) |
| 1544 |
{ |
| 1545 |
struct dahdi_pvt *p = pvt; |
| 1546 |
int index = SUB_REAL; |
| 1547 |
|
| 1548 |
if (p->cs) { |
| 1549 |
callerid_free(p->cs); |
| 1550 |
} |
| 1551 |
|
| 1552 |
|
| 1553 |
dahdi_setlinear(p->subs[index].dfd, p->subs[index].linear); |
| 1554 |
restore_gains(p); |
| 1555 |
|
| 1556 |
return 0; |
| 1557 |
} |
| 1558 |
|
| 1559 |
static int my_get_callerid(void *pvt, char *namebuf, char *numbuf, enum analog_event *ev, size_t timeout) |
| 1560 |
{ |
| 1561 |
struct dahdi_pvt *p = pvt; |
| 1562 |
struct analog_pvt *analog_p = p->sig_pvt; |
| 1563 |
struct pollfd poller; |
| 1564 |
char *name, *num; |
| 1565 |
int index = SUB_REAL; |
| 1566 |
int res; |
| 1567 |
unsigned char buf[256]; |
| 1568 |
int flags; |
| 1569 |
int redirecting; |
| 1570 |
|
| 1571 |
poller.fd = p->subs[SUB_REAL].dfd; |
| 1572 |
poller.events = POLLPRI | POLLIN; |
| 1573 |
poller.revents = 0; |
| 1574 |
|
| 1575 |
res = poll(&poller, 1, timeout); |
| 1576 |
|
| 1577 |
if (poller.revents & POLLPRI) { |
| 1578 |
*ev = dahdievent_to_analogevent(dahdi_get_event(p->subs[SUB_REAL].dfd)); |
| 1579 |
return 1; |
| 1580 |
} |
| 1581 |
|
| 1582 |
if (poller.revents & POLLIN) { |
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
res = read(p->subs[index].dfd, buf, sizeof(buf)); |
| 1589 |
if (res < 0) { |
| 1590 |
ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno)); |
| 1591 |
return -1; |
| 1592 |
} |
| 1593 |
|
| 1594 |
if (analog_p->ringt > 0) { |
| 1595 |
if (!(--analog_p->ringt)) { |
| 1596 |
|
| 1597 |
return -1; |
| 1598 |
} |
| 1599 |
} |
| 1600 |
|
| 1601 |
if (p->cid_signalling == CID_SIG_V23_JP) { |
| 1602 |
res = callerid_feed_jp(p->cs, buf, res, AST_LAW(p)); |
| 1603 |
} else { |
| 1604 |
res = callerid_feed(p->cs, buf, res, AST_LAW(p)); |
| 1605 |
} |
| 1606 |
if (res < 0) { |
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
ast_log(LOG_WARNING, "Failed to decode CallerID\n"); |
| 1612 |
return -1; |
| 1613 |
} |
| 1614 |
|
| 1615 |
if (res == 1) { |
| 1616 |
struct ast_channel *chan = analog_p->ss_astchan; |
| 1617 |
callerid_get_with_redirecting(p->cs, &name, &num, &flags, &redirecting); |
| 1618 |
if (name) |
| 1619 |
ast_copy_string(namebuf, name, ANALOG_MAX_CID); |
| 1620 |
if (num) |
| 1621 |
ast_copy_string(numbuf, num, ANALOG_MAX_CID); |
| 1622 |
|
| 1623 |
if (flags & (CID_PRIVATE_NUMBER | CID_UNKNOWN_NUMBER)) { |
| 1624 |
|
| 1625 |
struct ast_party_caller caller; |
| 1626 |
|
| 1627 |
ast_party_caller_set_init(&caller, ast_channel_caller(chan)); |
| 1628 |
caller.id.name.presentation = caller.id.number.presentation = (flags & CID_PRIVATE_NUMBER) ? |
| 1629 |
AST_PRES_RESTRICTED | AST_PRES_USER_NUMBER_UNSCREENED : AST_PRES_UNAVAILABLE | AST_PRES_USER_NUMBER_UNSCREENED; |
| 1630 |
ast_party_caller_set(ast_channel_caller(chan), &caller, NULL); |
| 1631 |
ast_party_caller_free(&caller); |
| 1632 |
} |
| 1633 |
if (redirecting) { |
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
ast_channel_redirecting(chan)->reason.code = redirecting; |
| 1638 |
} |
| 1639 |
|
| 1640 |
if (flags & CID_QUALIFIER) { |
| 1641 |
|
| 1642 |
pbx_builtin_setvar_helper(chan, "CALL_QUALIFIER", "1"); |
| 1643 |
} |
| 1644 |
|
| 1645 |
ast_debug(1, "CallerID number: %s, name: %s, flags=%d, redirecting=%s\n", num, name, flags, ast_redirecting_reason_name(&ast_channel_redirecting(chan)->reason)); |
| 1646 |
return 0; |
| 1647 |
} |
| 1648 |
} |
| 1649 |
|
| 1650 |
*ev = ANALOG_EVENT_NONE; |
| 1651 |
return 2; |
| 1652 |
} |
| 1653 |
|
| 1654 |
static const char *event2str(int event); |
| 1655 |
|
| 1656 |
static int my_distinctive_ring(struct ast_channel *chan, void *pvt, int idx, int *ringdata) |
| 1657 |
{ |
| 1658 |
unsigned char buf[256]; |
| 1659 |
int distMatches; |
| 1660 |
int curRingData[RING_PATTERNS]; |
| 1661 |
int receivedRingT; |
| 1662 |
int counter1; |
| 1663 |
int counter; |
| 1664 |
int i; |
| 1665 |
int res; |
| 1666 |
int checkaftercid = 0; |
| 1667 |
const char *matched_context; |
| 1668 |
struct dahdi_pvt *p = pvt; |
| 1669 |
struct analog_pvt *analog_p = p->sig_pvt; |
| 1670 |
|
| 1671 |
if (ringdata == NULL) { |
| 1672 |
ringdata = curRingData; |
| 1673 |
} else { |
| 1674 |
checkaftercid = 1; |
| 1675 |
} |
| 1676 |
|
| 1677 |
|
| 1678 |
if ((checkaftercid && distinctiveringaftercid) || !checkaftercid) { |
| 1679 |
|
| 1680 |
for (receivedRingT = 0; receivedRingT < RING_PATTERNS; receivedRingT++) |
| 1681 |
ringdata[receivedRingT] = 0; |
| 1682 |
receivedRingT = 0; |
| 1683 |
|
| 1684 |
if (checkaftercid && distinctiveringaftercid) { |
| 1685 |
ast_verb(3, "Detecting post-CID distinctive ring\n"); |
| 1686 |
} |
| 1687 |
|
| 1688 |
for (;;) { |
| 1689 |
i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT; |
| 1690 |
res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i); |
| 1691 |
if (res) { |
| 1692 |
ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno)); |
| 1693 |
ast_hangup(chan); |
| 1694 |
return 1; |
| 1695 |
} |
| 1696 |
if (i & DAHDI_IOMUX_SIGEVENT) { |
| 1697 |
res = dahdi_get_event(p->subs[idx].dfd); |
| 1698 |
ast_debug(3, "Got event %d (%s)...\n", res, event2str(res)); |
| 1699 |
if (res == DAHDI_EVENT_NOALARM) { |
| 1700 |
p->inalarm = 0; |
| 1701 |
analog_p->inalarm = 0; |
| 1702 |
} else if (res == DAHDI_EVENT_RINGOFFHOOK) { |
| 1703 |
|
| 1704 |
ringdata[receivedRingT] = analog_p->ringt; |
| 1705 |
|
| 1706 |
if (analog_p->ringt < analog_p->ringt_base / 2) { |
| 1707 |
break; |
| 1708 |
} |
| 1709 |
|
| 1710 |
|
| 1711 |
if (++receivedRingT == RING_PATTERNS) { |
| 1712 |
break; |
| 1713 |
} |
| 1714 |
} |
| 1715 |
} else if (i & DAHDI_IOMUX_READ) { |
| 1716 |
res = read(p->subs[idx].dfd, buf, sizeof(buf)); |
| 1717 |
if (res < 0) { |
| 1718 |
if (errno != ELAST) { |
| 1719 |
ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno)); |
| 1720 |
ast_hangup(chan); |
| 1721 |
return 1; |
| 1722 |
} |
| 1723 |
break; |
| 1724 |
} |
| 1725 |
if (analog_p->ringt > 0) { |
| 1726 |
if (!(--analog_p->ringt)) { |
| 1727 |
break; |
| 1728 |
} |
| 1729 |
} |
| 1730 |
} |
| 1731 |
} |
| 1732 |
} |
| 1733 |
|
| 1734 |
|
| 1735 |
ast_verb(3, "Detected ring pattern: %d,%d,%d\n", ringdata[0], ringdata[1], ringdata[2]); |
| 1736 |
matched_context = p->defcontext; |
| 1737 |
for (counter = 0; counter < 3; counter++) { |
| 1738 |
int range = p->drings.ringnum[counter].range; |
| 1739 |
|
| 1740 |
distMatches = 0; |
| 1741 |
ast_verb(3, "Checking %d,%d,%d with +/- %d range\n", |
| 1742 |
p->drings.ringnum[counter].ring[0], |
| 1743 |
p->drings.ringnum[counter].ring[1], |
| 1744 |
p->drings.ringnum[counter].ring[2], |
| 1745 |
range); |
| 1746 |
for (counter1 = 0; counter1 < 3; counter1++) { |
| 1747 |
int ring = p->drings.ringnum[counter].ring[counter1]; |
| 1748 |
|
| 1749 |
if (ring == -1) { |
| 1750 |
ast_verb(3, "Pattern ignore (-1) detected, so matching pattern %d regardless.\n", |
| 1751 |
ringdata[counter1]); |
| 1752 |
distMatches++; |
| 1753 |
} else if (ring - range <= ringdata[counter1] && ringdata[counter1] <= ring + range) { |
| 1754 |
ast_verb(3, "Ring pattern %d is in range: %d to %d\n", |
| 1755 |
ringdata[counter1], ring - range, ring + range); |
| 1756 |
distMatches++; |
| 1757 |
} else { |
| 1758 |
|
| 1759 |
break; |
| 1760 |
} |
| 1761 |
} |
| 1762 |
|
| 1763 |
if (distMatches == 3) { |
| 1764 |
|
| 1765 |
matched_context = S_OR(p->drings.ringContext[counter].contextData, p->defcontext); |
| 1766 |
ast_verb(3, "Matched Distinctive Ring context %s\n", matched_context); |
| 1767 |
break; |
| 1768 |
} |
| 1769 |
} |
| 1770 |
|
| 1771 |
|
| 1772 |
if (strcmp(p->context, matched_context) != 0) { |
| 1773 |
ast_copy_string(p->context, matched_context, sizeof(p->context)); |
| 1774 |
ast_channel_context_set(chan, matched_context); |
| 1775 |
} |
| 1776 |
|
| 1777 |
return 0; |
| 1778 |
} |
| 1779 |
|
| 1780 |
static int my_stop_callwait(void *pvt) |
| 1781 |
{ |
| 1782 |
struct dahdi_pvt *p = pvt; |
| 1783 |
p->callwaitingrepeat = 0; |
| 1784 |
p->cidcwexpire = 0; |
| 1785 |
p->cid_suppress_expire = 0; |
| 1786 |
|
| 1787 |
return 0; |
| 1788 |
} |
| 1789 |
|
| 1790 |
static int send_callerid(struct dahdi_pvt *p); |
| 1791 |
static int save_conference(struct dahdi_pvt *p); |
| 1792 |
static int restore_conference(struct dahdi_pvt *p); |
| 1793 |
|
| 1794 |
static int my_callwait(void *pvt) |
| 1795 |
{ |
| 1796 |
struct dahdi_pvt *p = pvt; |
| 1797 |
|
| 1798 |
p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES; |
| 1799 |
if (p->cidspill) { |
| 1800 |
ast_log(LOG_WARNING, "Spill already exists?!?\n"); |
| 1801 |
ast_free(p->cidspill); |
| 1802 |
} |
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
if (!(p->cidspill = ast_malloc(2400 + 680 + READ_SIZE * 4))) |
| 1809 |
return -1; |
| 1810 |
save_conference(p); |
| 1811 |
|
| 1812 |
memset(p->cidspill, 0x7f, 2400 + 600 + READ_SIZE * 4); |
| 1813 |
if (!p->callwaitrings && p->callwaitingcallerid) { |
| 1814 |
ast_gen_cas(p->cidspill, 1, 2400 + 680, AST_LAW(p)); |
| 1815 |
p->callwaitcas = 1; |
| 1816 |
p->cidlen = 2400 + 680 + READ_SIZE * 4; |
| 1817 |
} else { |
| 1818 |
ast_gen_cas(p->cidspill, 1, 2400, AST_LAW(p)); |
| 1819 |
p->callwaitcas = 0; |
| 1820 |
p->cidlen = 2400 + READ_SIZE * 4; |
| 1821 |
} |
| 1822 |
p->cidpos = 0; |
| 1823 |
send_callerid(p); |
| 1824 |
|
| 1825 |
return 0; |
| 1826 |
} |
| 1827 |
|
| 1828 |
static int my_send_callerid(void *pvt, int cwcid, struct ast_party_caller *caller) |
| 1829 |
{ |
| 1830 |
struct dahdi_pvt *p = pvt; |
| 1831 |
struct analog_pvt *analog_p = p->sig_pvt; |
| 1832 |
|
| 1833 |
ast_debug(2, "Starting cid spill\n"); |
| 1834 |
|
| 1835 |
if (p->cidspill) { |
| 1836 |
ast_log(LOG_WARNING, "cidspill already exists??\n"); |
| 1837 |
ast_free(p->cidspill); |
| 1838 |
} |
| 1839 |
|
| 1840 |
if ((p->cidspill = ast_malloc(MAX_CALLERID_SIZE))) { |
| 1841 |
int pres = ast_party_id_presentation(&caller->id); |
| 1842 |
if (cwcid == 0) { |
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
p->cidlen = ast_callerid_full_generate(p->cidspill, |
| 1851 |
caller->id.name.str, |
| 1852 |
caller->id.number.str, |
| 1853 |
NULL, |
| 1854 |
analog_p->redirecting_reason, |
| 1855 |
pres, |
| 1856 |
analog_p->call_qualifier, |
| 1857 |
CID_TYPE_MDMF, |
| 1858 |
AST_LAW(p)); |
| 1859 |
} else { |
| 1860 |
ast_verb(3, "CPE supports Call Waiting Caller*ID. Sending '%s/%s'\n", |
| 1861 |
caller->id.name.str, caller->id.number.str); |
| 1862 |
p->callwaitcas = 0; |
| 1863 |
p->cidcwexpire = 0; |
| 1864 |
p->cidlen = ast_callerid_callwaiting_full_generate(p->cidspill, |
| 1865 |
caller->id.name.str, |
| 1866 |
caller->id.number.str, |
| 1867 |
NULL, |
| 1868 |
-1, |
| 1869 |
pres, |
| 1870 |
0, |
| 1871 |
AST_LAW(p)); |
| 1872 |
p->cidlen += READ_SIZE * 4; |
| 1873 |
} |
| 1874 |
p->cidpos = 0; |
| 1875 |
p->cid_suppress_expire = 0; |
| 1876 |
send_callerid(p); |
| 1877 |
} |
| 1878 |
return 0; |
| 1879 |
} |
| 1880 |
|
| 1881 |
static int my_dsp_reset_and_flush_digits(void *pvt) |
| 1882 |
{ |
| 1883 |
struct dahdi_pvt *p = pvt; |
| 1884 |
if (p->dsp) |
| 1885 |
ast_dsp_digitreset(p->dsp); |
| 1886 |
|
| 1887 |
return 0; |
| 1888 |
} |
| 1889 |
|
| 1890 |
static int my_dsp_set_digitmode(void *pvt, enum analog_dsp_digitmode mode) |
| 1891 |
{ |
| 1892 |
struct dahdi_pvt *p = pvt; |
| 1893 |
|
| 1894 |
if (p->channel == CHAN_PSEUDO) |
| 1895 |
ast_log(LOG_ERROR, "You have assumed incorrectly sir!\n"); |
| 1896 |
|
| 1897 |
if (mode == ANALOG_DIGITMODE_DTMF) { |
| 1898 |
|
| 1899 |
if (p->hardwaredtmf) { |
| 1900 |
if (p->dsp) { |
| 1901 |
ast_dsp_free(p->dsp); |
| 1902 |
p->dsp = NULL; |
| 1903 |
} |
| 1904 |
return 0; |
| 1905 |
} |
| 1906 |
|
| 1907 |
if (!p->dsp) { |
| 1908 |
p->dsp = ast_dsp_new(); |
| 1909 |
if (!p->dsp) { |
| 1910 |
ast_log(LOG_ERROR, "Unable to allocate DSP\n"); |
| 1911 |
return -1; |
| 1912 |
} |
| 1913 |
} |
| 1914 |
|
| 1915 |
ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax); |
| 1916 |
} else if (mode == ANALOG_DIGITMODE_MF) { |
| 1917 |
if (!p->dsp) { |
| 1918 |
p->dsp = ast_dsp_new(); |
| 1919 |
if (!p->dsp) { |
| 1920 |
ast_log(LOG_ERROR, "Unable to allocate DSP\n"); |
| 1921 |
return -1; |
| 1922 |
} |
| 1923 |
} |
| 1924 |
ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MF | p->dtmfrelax); |
| 1925 |
} |
| 1926 |
return 0; |
| 1927 |
} |
| 1928 |
|
| 1929 |
static int dahdi_wink(struct dahdi_pvt *p, int index); |
| 1930 |
|
| 1931 |
static int my_wink(void *pvt, enum analog_sub sub) |
| 1932 |
{ |
| 1933 |
struct dahdi_pvt *p = pvt; |
| 1934 |
int index = analogsub_to_dahdisub(sub); |
| 1935 |
if (index != SUB_REAL) { |
| 1936 |
ast_log(LOG_ERROR, "We used a sub other than SUB_REAL (incorrect assumption sir)\n"); |
| 1937 |
} |
| 1938 |
return dahdi_wink(p, index); |
| 1939 |
} |
| 1940 |
|
| 1941 |
static void wakeup_sub(struct dahdi_pvt *p, int a); |
| 1942 |
|
| 1943 |
static int reset_conf(struct dahdi_pvt *p); |
| 1944 |
|
| 1945 |
static inline int dahdi_confmute(struct dahdi_pvt *p, int muted); |
| 1946 |
|
| 1947 |
static void my_handle_dtmf(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest) |
| 1948 |
{ |
| 1949 |
struct ast_frame *f = *dest; |
| 1950 |
struct dahdi_pvt *p = pvt; |
| 1951 |
int idx = analogsub_to_dahdisub(analog_index); |
| 1952 |
|
| 1953 |
ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n", |
| 1954 |
f->frametype == AST_FRAME_DTMF_BEGIN ? "Begin" : "End", |
| 1955 |
(unsigned)f->subclass.integer, f->subclass.integer, ast_channel_name(ast)); |
| 1956 |
|
| 1957 |
if (f->subclass.integer == 'f') { |
| 1958 |
if (f->frametype == AST_FRAME_DTMF_END) { |
| 1959 |
|
| 1960 |
if ((p->callprogress & CALLPROGRESS_FAX) && !p->faxhandled) { |
| 1961 |
|
| 1962 |
if (p->usefaxbuffers && !p->bufferoverrideinuse) { |
| 1963 |
struct dahdi_bufferinfo bi = { |
| 1964 |
.txbufpolicy = p->faxbuf_policy, |
| 1965 |
.bufsize = p->bufsize, |
| 1966 |
.numbufs = p->faxbuf_no |
| 1967 |
}; |
| 1968 |
int res; |
| 1969 |
|
| 1970 |
if ((res = ioctl(p->subs[idx].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) { |
| 1971 |
ast_log(LOG_WARNING, "Channel '%s' unable to set buffer policy, reason: %s\n", ast_channel_name(ast), strerror(errno)); |
| 1972 |
} else { |
| 1973 |
p->bufferoverrideinuse = 1; |
| 1974 |
} |
| 1975 |
} |
| 1976 |
p->faxhandled = 1; |
| 1977 |
if (p->dsp) { |
| 1978 |
p->dsp_features &= ~DSP_FEATURE_FAX_DETECT; |
| 1979 |
ast_dsp_set_features(p->dsp, p->dsp_features); |
| 1980 |
ast_debug(1, "Disabling FAX tone detection on %s after tone received\n", ast_channel_name(ast)); |
| 1981 |
} |
| 1982 |
if (strcmp(ast_channel_exten(ast), "fax")) { |
| 1983 |
const char *target_context = ast_channel_context(ast); |
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
ast_mutex_unlock(&p->lock); |
| 1994 |
ast_channel_unlock(ast); |
| 1995 |
if (ast_exists_extension(ast, target_context, "fax", 1, |
| 1996 |
S_COR(ast_channel_caller(ast)->id.number.valid, ast_channel_caller(ast)->id.number.str, NULL))) { |
| 1997 |
ast_verb(3, "Redirecting %s to fax extension\n", ast_channel_name(ast)); |
| 1998 |
|
| 1999 |
pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast_channel_exten(ast)); |
| 2000 |
if (ast_async_goto(ast, target_context, "fax", 1)) |
| 2001 |
ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast_channel_name(ast), target_context); |
| 2002 |
} else { |
| 2003 |
ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n"); |
| 2004 |
} |
| 2005 |
ast_channel_lock(ast); |
| 2006 |
ast_mutex_lock(&p->lock); |
| 2007 |
} else { |
| 2008 |
ast_debug(1, "Already in a fax extension, not redirecting\n"); |
| 2009 |
} |
| 2010 |
} else { |
| 2011 |
ast_debug(1, "Fax already handled\n"); |
| 2012 |
} |
| 2013 |
dahdi_confmute(p, 0); |
| 2014 |
} |
| 2015 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 2016 |
p->subs[idx].f.subclass.integer = 0; |
| 2017 |
*dest = &p->subs[idx].f; |
| 2018 |
} |
| 2019 |
} |
| 2020 |
|
| 2021 |
static void my_lock_private(void *pvt) |
| 2022 |
{ |
| 2023 |
struct dahdi_pvt *p = pvt; |
| 2024 |
ast_mutex_lock(&p->lock); |
| 2025 |
} |
| 2026 |
|
| 2027 |
static void my_unlock_private(void *pvt) |
| 2028 |
{ |
| 2029 |
struct dahdi_pvt *p = pvt; |
| 2030 |
ast_mutex_unlock(&p->lock); |
| 2031 |
} |
| 2032 |
|
| 2033 |
static void my_deadlock_avoidance_private(void *pvt) |
| 2034 |
{ |
| 2035 |
struct dahdi_pvt *p = pvt; |
| 2036 |
|
| 2037 |
DEADLOCK_AVOIDANCE(&p->lock); |
| 2038 |
} |
| 2039 |
|
| 2040 |
static struct ast_manager_event_blob *dahdichannel_to_ami(struct stasis_message *msg) |
| 2041 |
{ |
| 2042 |
RAII_VAR(struct ast_str *, channel_string, NULL, ast_free); |
| 2043 |
struct ast_channel_blob *obj = stasis_message_data(msg); |
| 2044 |
struct ast_json *group, *span, *channel; |
| 2045 |
|
| 2046 |
channel_string = ast_manager_build_channel_state_string(obj->snapshot); |
| 2047 |
if (!channel_string) { |
| 2048 |
return NULL; |
| 2049 |
} |
| 2050 |
|
| 2051 |
group = ast_json_object_get(obj->blob, "group"); |
| 2052 |
span = ast_json_object_get(obj->blob, "span"); |
| 2053 |
channel = ast_json_object_get(obj->blob, "channel"); |
| 2054 |
|
| 2055 |
return ast_manager_event_blob_create(EVENT_FLAG_CALL, "DAHDIChannel", |
| 2056 |
"%s" |
| 2057 |
"DAHDIGroup: %llu\r\n" |
| 2058 |
"DAHDISpan: %u\r\n" |
| 2059 |
"DAHDIChannel: %s\r\n", |
| 2060 |
ast_str_buffer(channel_string), |
| 2061 |
(ast_group_t)ast_json_integer_get(group), |
| 2062 |
(unsigned int)ast_json_integer_get(span), |
| 2063 |
ast_json_string_get(channel)); |
| 2064 |
} |
| 2065 |
|
| 2066 |
STASIS_MESSAGE_TYPE_DEFN_LOCAL(dahdichannel_type, |
| 2067 |
.to_ami = dahdichannel_to_ami, |
| 2068 |
); |
| 2069 |
|
| 2070 |
|
| 2071 |
static void publish_dahdichannel(struct ast_channel *chan, ast_group_t group, int span, const char *dahdi_channel) |
| 2072 |
{ |
| 2073 |
RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref); |
| 2074 |
|
| 2075 |
ast_assert(dahdi_channel != NULL); |
| 2076 |
|
| 2077 |
blob = ast_json_pack("{s: I, s: i, s: s}", |
| 2078 |
"group", (ast_json_int_t)group, |
| 2079 |
"span", span, |
| 2080 |
"channel", dahdi_channel); |
| 2081 |
if (!blob) { |
| 2082 |
return; |
| 2083 |
} |
| 2084 |
|
| 2085 |
ast_channel_lock(chan); |
| 2086 |
ast_channel_publish_blob(chan, dahdichannel_type(), blob); |
| 2087 |
ast_channel_unlock(chan); |
| 2088 |
} |
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
static void dahdi_ami_channel_event(struct dahdi_pvt *p, struct ast_channel *chan) |
| 2099 |
{ |
| 2100 |
char ch_name[23]; |
| 2101 |
|
| 2102 |
if (p->channel < CHAN_PSEUDO) { |
| 2103 |
|
| 2104 |
snprintf(ch_name, sizeof(ch_name), "no-media (%d)", p->channel); |
| 2105 |
} else if (p->channel == CHAN_PSEUDO) { |
| 2106 |
|
| 2107 |
strcpy(ch_name, "pseudo"); |
| 2108 |
} else { |
| 2109 |
|
| 2110 |
snprintf(ch_name, sizeof(ch_name), "%d", p->channel); |
| 2111 |
} |
| 2112 |
publish_dahdichannel(chan, p->group, p->span, ch_name); |
| 2113 |
} |
| 2114 |
|
| 2115 |
#ifdef HAVE_PRI |
| 2116 |
|
| 2117 |
|
| 2118 |
|
| 2119 |
|
| 2120 |
|
| 2121 |
|
| 2122 |
|
| 2123 |
|
| 2124 |
static void my_ami_channel_event(void *pvt, struct ast_channel *chan) |
| 2125 |
{ |
| 2126 |
struct dahdi_pvt *p = pvt; |
| 2127 |
|
| 2128 |
dahdi_ami_channel_event(p, chan); |
| 2129 |
} |
| 2130 |
#endif |
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
static int my_set_linear_mode(void *pvt, enum analog_sub sub, int linear_mode) |
| 2136 |
{ |
| 2137 |
struct dahdi_pvt *p = pvt; |
| 2138 |
int oldval; |
| 2139 |
int idx = analogsub_to_dahdisub(sub); |
| 2140 |
|
| 2141 |
dahdi_setlinear(p->subs[idx].dfd, linear_mode); |
| 2142 |
oldval = p->subs[idx].linear; |
| 2143 |
p->subs[idx].linear = linear_mode ? 1 : 0; |
| 2144 |
return oldval; |
| 2145 |
} |
| 2146 |
|
| 2147 |
static void my_set_inthreeway(void *pvt, enum analog_sub sub, int inthreeway) |
| 2148 |
{ |
| 2149 |
struct dahdi_pvt *p = pvt; |
| 2150 |
int idx = analogsub_to_dahdisub(sub); |
| 2151 |
|
| 2152 |
p->subs[idx].inthreeway = inthreeway; |
| 2153 |
} |
| 2154 |
|
| 2155 |
static int get_alarms(struct dahdi_pvt *p); |
| 2156 |
static void handle_alarms(struct dahdi_pvt *p, int alms); |
| 2157 |
static void my_get_and_handle_alarms(void *pvt) |
| 2158 |
{ |
| 2159 |
int res; |
| 2160 |
struct dahdi_pvt *p = pvt; |
| 2161 |
|
| 2162 |
res = get_alarms(p); |
| 2163 |
handle_alarms(p, res); |
| 2164 |
} |
| 2165 |
|
| 2166 |
static void *my_get_sigpvt_bridged_channel(struct ast_channel *chan) |
| 2167 |
{ |
| 2168 |
RAII_VAR(struct ast_channel *, bridged, ast_channel_bridge_peer(chan), ast_channel_cleanup); |
| 2169 |
|
| 2170 |
if (bridged && ast_channel_tech(bridged) == &dahdi_tech) { |
| 2171 |
struct dahdi_pvt *p = ast_channel_tech_pvt(bridged); |
| 2172 |
|
| 2173 |
if (dahdi_analog_lib_handles(p->sig, p->radio, p->oprmode)) { |
| 2174 |
return p->sig_pvt; |
| 2175 |
} |
| 2176 |
} |
| 2177 |
return NULL; |
| 2178 |
} |
| 2179 |
|
| 2180 |
static int my_get_sub_fd(void *pvt, enum analog_sub sub) |
| 2181 |
{ |
| 2182 |
struct dahdi_pvt *p = pvt; |
| 2183 |
int dahdi_sub = analogsub_to_dahdisub(sub); |
| 2184 |
return p->subs[dahdi_sub].dfd; |
| 2185 |
} |
| 2186 |
|
| 2187 |
static void my_set_cadence(void *pvt, int *cid_rings, struct ast_channel *ast) |
| 2188 |
{ |
| 2189 |
struct dahdi_pvt *p = pvt; |
| 2190 |
|
| 2191 |
|
| 2192 |
if ((p->distinctivering > 0) && (p->distinctivering <= num_cadence)) { |
| 2193 |
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &cadences[p->distinctivering - 1])) |
| 2194 |
ast_log(LOG_WARNING, "Unable to set distinctive ring cadence %d on '%s': %s\n", p->distinctivering, ast_channel_name(ast), strerror(errno)); |
| 2195 |
*cid_rings = cidrings[p->distinctivering - 1]; |
| 2196 |
} else { |
| 2197 |
if (p->distinctivering > 0) { |
| 2198 |
ast_log(LOG_WARNING, "Cadence %d is not defined, falling back to default ring cadence\n", p->distinctivering); |
| 2199 |
} |
| 2200 |
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, NULL)) |
| 2201 |
ast_log(LOG_WARNING, "Unable to reset default ring on '%s': %s\n", ast_channel_name(ast), strerror(errno)); |
| 2202 |
*cid_rings = p->sendcalleridafter; |
| 2203 |
} |
| 2204 |
} |
| 2205 |
|
| 2206 |
static void my_set_alarm(void *pvt, int in_alarm) |
| 2207 |
{ |
| 2208 |
struct dahdi_pvt *p = pvt; |
| 2209 |
|
| 2210 |
p->inalarm = in_alarm; |
| 2211 |
} |
| 2212 |
|
| 2213 |
static void my_set_dialing(void *pvt, int is_dialing) |
| 2214 |
{ |
| 2215 |
struct dahdi_pvt *p = pvt; |
| 2216 |
|
| 2217 |
p->dialing = is_dialing; |
| 2218 |
} |
| 2219 |
|
| 2220 |
static void my_set_outgoing(void *pvt, int is_outgoing) |
| 2221 |
{ |
| 2222 |
struct dahdi_pvt *p = pvt; |
| 2223 |
|
| 2224 |
p->outgoing = is_outgoing; |
| 2225 |
} |
| 2226 |
|
| 2227 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 2228 |
static void my_set_digital(void *pvt, int is_digital) |
| 2229 |
{ |
| 2230 |
struct dahdi_pvt *p = pvt; |
| 2231 |
|
| 2232 |
p->digital = is_digital; |
| 2233 |
} |
| 2234 |
#endif |
| 2235 |
|
| 2236 |
#if defined(HAVE_SS7) |
| 2237 |
static void my_set_inservice(void *pvt, int is_inservice) |
| 2238 |
{ |
| 2239 |
struct dahdi_pvt *p = pvt; |
| 2240 |
|
| 2241 |
p->inservice = is_inservice; |
| 2242 |
} |
| 2243 |
#endif |
| 2244 |
|
| 2245 |
#if defined(HAVE_SS7) |
| 2246 |
static void my_set_locallyblocked(void *pvt, int is_blocked) |
| 2247 |
{ |
| 2248 |
struct dahdi_pvt *p = pvt; |
| 2249 |
|
| 2250 |
p->locallyblocked = is_blocked; |
| 2251 |
} |
| 2252 |
#endif |
| 2253 |
|
| 2254 |
#if defined(HAVE_SS7) |
| 2255 |
static void my_set_remotelyblocked(void *pvt, int is_blocked) |
| 2256 |
{ |
| 2257 |
struct dahdi_pvt *p = pvt; |
| 2258 |
|
| 2259 |
p->remotelyblocked = is_blocked; |
| 2260 |
} |
| 2261 |
#endif |
| 2262 |
|
| 2263 |
static void my_set_ringtimeout(void *pvt, int ringt) |
| 2264 |
{ |
| 2265 |
struct dahdi_pvt *p = pvt; |
| 2266 |
p->ringt = ringt; |
| 2267 |
} |
| 2268 |
|
| 2269 |
static void my_set_waitingfordt(void *pvt, struct ast_channel *ast) |
| 2270 |
{ |
| 2271 |
struct dahdi_pvt *p = pvt; |
| 2272 |
|
| 2273 |
|
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
|
| 2284 |
p->waitfordialtoneduration = p->waitfordialtonetemp ? p->waitfordialtonetemp : p->waitfordialtone; |
| 2285 |
p->waitfordialtonetemp = 0; |
| 2286 |
|
| 2287 |
if (!(p->waitfordialtoneduration && CANPROGRESSDETECT(p))) { |
| 2288 |
return; |
| 2289 |
} |
| 2290 |
|
| 2291 |
|
| 2292 |
|
| 2293 |
|
| 2294 |
if (!p->dsp) { |
| 2295 |
p->dsp = ast_dsp_new(); |
| 2296 |
if (!p->dsp) { |
| 2297 |
ast_log(LOG_ERROR, "Unable to allocate DSP\n"); |
| 2298 |
return; |
| 2299 |
} |
| 2300 |
} |
| 2301 |
p->dsp_features |= DSP_FEATURE_WAITDIALTONE; |
| 2302 |
ast_dsp_set_features(p->dsp, p->dsp_features); |
| 2303 |
|
| 2304 |
ast_debug(1, "Defer dialing for %dms or dialtone\n", p->waitfordialtoneduration); |
| 2305 |
gettimeofday(&p->waitingfordt, NULL); |
| 2306 |
ast_setstate(ast, AST_STATE_OFFHOOK); |
| 2307 |
} |
| 2308 |
|
| 2309 |
static int my_check_waitingfordt(void *pvt) |
| 2310 |
{ |
| 2311 |
struct dahdi_pvt *p = pvt; |
| 2312 |
|
| 2313 |
if (p->waitingfordt.tv_sec) { |
| 2314 |
return 1; |
| 2315 |
} |
| 2316 |
|
| 2317 |
return 0; |
| 2318 |
} |
| 2319 |
|
| 2320 |
static void my_set_confirmanswer(void *pvt, int flag) |
| 2321 |
{ |
| 2322 |
struct dahdi_pvt *p = pvt; |
| 2323 |
p->confirmanswer = flag; |
| 2324 |
} |
| 2325 |
|
| 2326 |
static int my_check_confirmanswer(void *pvt) |
| 2327 |
{ |
| 2328 |
struct dahdi_pvt *p = pvt; |
| 2329 |
if (p->confirmanswer) { |
| 2330 |
return 1; |
| 2331 |
} |
| 2332 |
|
| 2333 |
return 0; |
| 2334 |
} |
| 2335 |
|
| 2336 |
static void my_set_callwaiting(void *pvt, int callwaiting_enable) |
| 2337 |
{ |
| 2338 |
struct dahdi_pvt *p = pvt; |
| 2339 |
|
| 2340 |
p->callwaiting = callwaiting_enable; |
| 2341 |
} |
| 2342 |
|
| 2343 |
static void my_cancel_cidspill(void *pvt) |
| 2344 |
{ |
| 2345 |
struct dahdi_pvt *p = pvt; |
| 2346 |
|
| 2347 |
ast_free(p->cidspill); |
| 2348 |
p->cidspill = NULL; |
| 2349 |
restore_conference(p); |
| 2350 |
} |
| 2351 |
|
| 2352 |
static int my_confmute(void *pvt, int mute) |
| 2353 |
{ |
| 2354 |
struct dahdi_pvt *p = pvt; |
| 2355 |
return dahdi_confmute(p, mute); |
| 2356 |
} |
| 2357 |
|
| 2358 |
static void my_set_pulsedial(void *pvt, int flag) |
| 2359 |
{ |
| 2360 |
struct dahdi_pvt *p = pvt; |
| 2361 |
p->pulsedial = flag; |
| 2362 |
} |
| 2363 |
|
| 2364 |
static void my_set_new_owner(void *pvt, struct ast_channel *new_owner) |
| 2365 |
{ |
| 2366 |
struct dahdi_pvt *p = pvt; |
| 2367 |
|
| 2368 |
p->owner = new_owner; |
| 2369 |
} |
| 2370 |
|
| 2371 |
static const char *my_get_orig_dialstring(void *pvt) |
| 2372 |
{ |
| 2373 |
struct dahdi_pvt *p = pvt; |
| 2374 |
|
| 2375 |
return p->dialstring; |
| 2376 |
} |
| 2377 |
|
| 2378 |
static void my_increase_ss_count(void) |
| 2379 |
{ |
| 2380 |
ast_mutex_lock(&ss_thread_lock); |
| 2381 |
ss_thread_count++; |
| 2382 |
ast_mutex_unlock(&ss_thread_lock); |
| 2383 |
} |
| 2384 |
|
| 2385 |
static void my_decrease_ss_count(void) |
| 2386 |
{ |
| 2387 |
ast_mutex_lock(&ss_thread_lock); |
| 2388 |
ss_thread_count--; |
| 2389 |
ast_cond_signal(&ss_thread_complete); |
| 2390 |
ast_mutex_unlock(&ss_thread_lock); |
| 2391 |
} |
| 2392 |
|
| 2393 |
static void my_all_subchannels_hungup(void *pvt) |
| 2394 |
{ |
| 2395 |
struct dahdi_pvt *p = pvt; |
| 2396 |
int res, law; |
| 2397 |
|
| 2398 |
p->faxhandled = 0; |
| 2399 |
p->didtdd = 0; |
| 2400 |
|
| 2401 |
if (p->dsp) { |
| 2402 |
ast_dsp_free(p->dsp); |
| 2403 |
p->dsp = NULL; |
| 2404 |
} |
| 2405 |
|
| 2406 |
p->law = p->law_default; |
| 2407 |
law = p->law_default; |
| 2408 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETLAW, &law); |
| 2409 |
if (res < 0) |
| 2410 |
ast_log(LOG_WARNING, "Unable to set law on channel %d to default: %s\n", p->channel, strerror(errno)); |
| 2411 |
|
| 2412 |
dahdi_setlinear(p->subs[SUB_REAL].dfd, 0); |
| 2413 |
|
| 2414 |
#if 1 |
| 2415 |
{ |
| 2416 |
int i; |
| 2417 |
p->owner = NULL; |
| 2418 |
|
| 2419 |
for (i = 0; i < 3; i++) { |
| 2420 |
p->subs[i].owner = NULL; |
| 2421 |
} |
| 2422 |
} |
| 2423 |
#endif |
| 2424 |
|
| 2425 |
reset_conf(p); |
| 2426 |
if (num_restart_pending == 0) { |
| 2427 |
restart_monitor(); |
| 2428 |
} |
| 2429 |
} |
| 2430 |
|
| 2431 |
static int conf_del(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index); |
| 2432 |
|
| 2433 |
static int my_conf_del(void *pvt, enum analog_sub sub) |
| 2434 |
{ |
| 2435 |
struct dahdi_pvt *p = pvt; |
| 2436 |
int x = analogsub_to_dahdisub(sub); |
| 2437 |
|
| 2438 |
return conf_del(p, &p->subs[x], x); |
| 2439 |
} |
| 2440 |
|
| 2441 |
static int conf_add(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index, int slavechannel); |
| 2442 |
|
| 2443 |
static int my_conf_add(void *pvt, enum analog_sub sub) |
| 2444 |
{ |
| 2445 |
struct dahdi_pvt *p = pvt; |
| 2446 |
int x = analogsub_to_dahdisub(sub); |
| 2447 |
|
| 2448 |
return conf_add(p, &p->subs[x], x, 0); |
| 2449 |
} |
| 2450 |
|
| 2451 |
static int isslavenative(struct dahdi_pvt *p, struct dahdi_pvt **out); |
| 2452 |
|
| 2453 |
static int my_complete_conference_update(void *pvt, int needconference) |
| 2454 |
{ |
| 2455 |
struct dahdi_pvt *p = pvt; |
| 2456 |
int needconf = needconference; |
| 2457 |
int x; |
| 2458 |
int useslavenative; |
| 2459 |
struct dahdi_pvt *slave = NULL; |
| 2460 |
|
| 2461 |
useslavenative = isslavenative(p, &slave); |
| 2462 |
|
| 2463 |
|
| 2464 |
|
| 2465 |
for (x = 0; x < MAX_SLAVES; x++) { |
| 2466 |
if (p->slaves[x]) { |
| 2467 |
if (useslavenative) |
| 2468 |
conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p)); |
| 2469 |
else { |
| 2470 |
conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, 0); |
| 2471 |
needconf++; |
| 2472 |
} |
| 2473 |
} |
| 2474 |
} |
| 2475 |
|
| 2476 |
if (p->inconference && !p->subs[SUB_REAL].inthreeway) { |
| 2477 |
if (useslavenative) |
| 2478 |
conf_add(p, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(slave)); |
| 2479 |
else { |
| 2480 |
conf_add(p, &p->subs[SUB_REAL], SUB_REAL, 0); |
| 2481 |
needconf++; |
| 2482 |
} |
| 2483 |
} |
| 2484 |
|
| 2485 |
if (p->master) { |
| 2486 |
if (isslavenative(p->master, NULL)) { |
| 2487 |
conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p->master)); |
| 2488 |
} else { |
| 2489 |
conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, 0); |
| 2490 |
} |
| 2491 |
} |
| 2492 |
if (!needconf) { |
| 2493 |
|
| 2494 |
|
| 2495 |
p->confno = -1; |
| 2496 |
} |
| 2497 |
|
| 2498 |
return 0; |
| 2499 |
} |
| 2500 |
|
| 2501 |
static int check_for_conference(struct dahdi_pvt *p); |
| 2502 |
|
| 2503 |
static int my_check_for_conference(void *pvt) |
| 2504 |
{ |
| 2505 |
struct dahdi_pvt *p = pvt; |
| 2506 |
return check_for_conference(p); |
| 2507 |
} |
| 2508 |
|
| 2509 |
static void my_swap_subchannels(void *pvt, enum analog_sub a, struct ast_channel *ast_a, enum analog_sub b, struct ast_channel *ast_b) |
| 2510 |
{ |
| 2511 |
struct dahdi_pvt *p = pvt; |
| 2512 |
int da, db; |
| 2513 |
int tchan; |
| 2514 |
int tinthreeway; |
| 2515 |
|
| 2516 |
da = analogsub_to_dahdisub(a); |
| 2517 |
db = analogsub_to_dahdisub(b); |
| 2518 |
|
| 2519 |
tchan = p->subs[da].chan; |
| 2520 |
p->subs[da].chan = p->subs[db].chan; |
| 2521 |
p->subs[db].chan = tchan; |
| 2522 |
|
| 2523 |
tinthreeway = p->subs[da].inthreeway; |
| 2524 |
p->subs[da].inthreeway = p->subs[db].inthreeway; |
| 2525 |
p->subs[db].inthreeway = tinthreeway; |
| 2526 |
|
| 2527 |
p->subs[da].owner = ast_a; |
| 2528 |
p->subs[db].owner = ast_b; |
| 2529 |
|
| 2530 |
if (ast_a) |
| 2531 |
ast_channel_set_fd(ast_a, 0, p->subs[da].dfd); |
| 2532 |
if (ast_b) |
| 2533 |
ast_channel_set_fd(ast_b, 0, p->subs[db].dfd); |
| 2534 |
|
| 2535 |
wakeup_sub(p, a); |
| 2536 |
wakeup_sub(p, b); |
| 2537 |
|
| 2538 |
return; |
| 2539 |
} |
| 2540 |
|
| 2541 |
|
| 2542 |
|
| 2543 |
|
| 2544 |
|
| 2545 |
|
| 2546 |
|
| 2547 |
|
| 2548 |
|
| 2549 |
static struct ast_channel *dahdi_new_callid_clean(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, ast_callid callid, int callid_created); |
| 2550 |
|
| 2551 |
static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, ast_callid callid); |
| 2552 |
|
| 2553 |
static struct ast_channel *my_new_analog_ast_channel(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor) |
| 2554 |
{ |
| 2555 |
ast_callid callid = 0; |
| 2556 |
int callid_created = ast_callid_threadstorage_auto(&callid); |
| 2557 |
struct dahdi_pvt *p = pvt; |
| 2558 |
int dsub = analogsub_to_dahdisub(sub); |
| 2559 |
|
| 2560 |
return dahdi_new_callid_clean(p, state, startpbx, dsub, 0, NULL, requestor, callid, callid_created); |
| 2561 |
} |
| 2562 |
|
| 2563 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 2564 |
static int dahdi_setlaw(int dfd, int law) |
| 2565 |
{ |
| 2566 |
int res; |
| 2567 |
res = ioctl(dfd, DAHDI_SETLAW, &law); |
| 2568 |
if (res) |
| 2569 |
return res; |
| 2570 |
return 0; |
| 2571 |
} |
| 2572 |
#endif |
| 2573 |
|
| 2574 |
#if defined(HAVE_PRI) |
| 2575 |
static struct ast_channel *my_new_pri_ast_channel(void *pvt, int state, |
| 2576 |
enum sig_pri_law law, char *exten, const struct ast_assigned_ids *assignedids, |
| 2577 |
const struct ast_channel *requestor) |
| 2578 |
{ |
| 2579 |
struct dahdi_pvt *p = pvt; |
| 2580 |
int audio; |
| 2581 |
int newlaw = -1; |
| 2582 |
ast_callid callid = 0; |
| 2583 |
int callid_created = ast_callid_threadstorage_auto(&callid); |
| 2584 |
|
| 2585 |
switch (p->sig) { |
| 2586 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 2587 |
if (((struct sig_pri_chan *) p->sig_pvt)->no_b_channel) { |
| 2588 |
|
| 2589 |
break; |
| 2590 |
} |
| 2591 |
|
| 2592 |
default: |
| 2593 |
|
| 2594 |
audio = 1; |
| 2595 |
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &audio) == -1) { |
| 2596 |
ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d: %s\n", |
| 2597 |
p->channel, audio, strerror(errno)); |
| 2598 |
} |
| 2599 |
break; |
| 2600 |
} |
| 2601 |
|
| 2602 |
if (law != SIG_PRI_DEFLAW) { |
| 2603 |
dahdi_setlaw(p->subs[SUB_REAL].dfd, (law == SIG_PRI_ULAW) ? DAHDI_LAW_MULAW : DAHDI_LAW_ALAW); |
| 2604 |
} |
| 2605 |
|
| 2606 |
ast_copy_string(p->exten, exten, sizeof(p->exten)); |
| 2607 |
|
| 2608 |
switch (law) { |
| 2609 |
case SIG_PRI_DEFLAW: |
| 2610 |
newlaw = 0; |
| 2611 |
break; |
| 2612 |
case SIG_PRI_ALAW: |
| 2613 |
newlaw = DAHDI_LAW_ALAW; |
| 2614 |
break; |
| 2615 |
case SIG_PRI_ULAW: |
| 2616 |
newlaw = DAHDI_LAW_MULAW; |
| 2617 |
break; |
| 2618 |
} |
| 2619 |
|
| 2620 |
return dahdi_new_callid_clean(p, state, 0, SUB_REAL, newlaw, assignedids, requestor, callid, callid_created); |
| 2621 |
} |
| 2622 |
#endif |
| 2623 |
|
| 2624 |
static int set_actual_gain(int fd, float rxgain, float txgain, float rxdrc, float txdrc, int law); |
| 2625 |
|
| 2626 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 2627 |
|
| 2628 |
|
| 2629 |
|
| 2630 |
|
| 2631 |
|
| 2632 |
|
| 2633 |
|
| 2634 |
static void my_pri_ss7_open_media(void *p) |
| 2635 |
{ |
| 2636 |
struct dahdi_pvt *pvt = p; |
| 2637 |
int res; |
| 2638 |
int dfd; |
| 2639 |
int set_val; |
| 2640 |
|
| 2641 |
dfd = pvt->subs[SUB_REAL].dfd; |
| 2642 |
|
| 2643 |
|
| 2644 |
set_val = 1; |
| 2645 |
res = ioctl(dfd, DAHDI_AUDIOMODE, &set_val); |
| 2646 |
if (res < 0) { |
| 2647 |
ast_log(LOG_WARNING, "Unable to enable audio mode on channel %d (%s)\n", |
| 2648 |
pvt->channel, strerror(errno)); |
| 2649 |
} |
| 2650 |
|
| 2651 |
|
| 2652 |
res = dahdi_setlaw(dfd, pvt->law); |
| 2653 |
if (res < 0) { |
| 2654 |
ast_log(LOG_WARNING, "Unable to set law on channel %d\n", pvt->channel); |
| 2655 |
} |
| 2656 |
|
| 2657 |
|
| 2658 |
if (pvt->digital) { |
| 2659 |
res = set_actual_gain(dfd, 0, 0, pvt->rxdrc, pvt->txdrc, pvt->law); |
| 2660 |
} else { |
| 2661 |
res = set_actual_gain(dfd, pvt->rxgain, pvt->txgain, pvt->rxdrc, pvt->txdrc, |
| 2662 |
pvt->law); |
| 2663 |
} |
| 2664 |
if (res < 0) { |
| 2665 |
ast_log(LOG_WARNING, "Unable to set gains on channel %d\n", pvt->channel); |
| 2666 |
} |
| 2667 |
|
| 2668 |
if (pvt->dsp_features && pvt->dsp) { |
| 2669 |
ast_dsp_set_features(pvt->dsp, pvt->dsp_features); |
| 2670 |
} |
| 2671 |
} |
| 2672 |
#endif |
| 2673 |
|
| 2674 |
#if defined(HAVE_PRI) |
| 2675 |
|
| 2676 |
|
| 2677 |
|
| 2678 |
|
| 2679 |
|
| 2680 |
|
| 2681 |
|
| 2682 |
|
| 2683 |
|
| 2684 |
|
| 2685 |
static void my_pri_dial_digits(void *p, const char *dial_string) |
| 2686 |
{ |
| 2687 |
char dial_str[DAHDI_MAX_DTMF_BUF]; |
| 2688 |
struct dahdi_pvt *pvt = p; |
| 2689 |
int res; |
| 2690 |
|
| 2691 |
snprintf(dial_str, sizeof(dial_str), "T%s", dial_string); |
| 2692 |
res = dahdi_dial_str(pvt, DAHDI_DIAL_OP_APPEND, dial_str); |
| 2693 |
if (!res) { |
| 2694 |
pvt->dialing = 1; |
| 2695 |
} |
| 2696 |
} |
| 2697 |
#endif |
| 2698 |
|
| 2699 |
static int unalloc_sub(struct dahdi_pvt *p, int x); |
| 2700 |
|
| 2701 |
static int my_unallocate_sub(void *pvt, enum analog_sub analogsub) |
| 2702 |
{ |
| 2703 |
struct dahdi_pvt *p = pvt; |
| 2704 |
|
| 2705 |
return unalloc_sub(p, analogsub_to_dahdisub(analogsub)); |
| 2706 |
} |
| 2707 |
|
| 2708 |
static int alloc_sub(struct dahdi_pvt *p, int x); |
| 2709 |
|
| 2710 |
static int my_allocate_sub(void *pvt, enum analog_sub analogsub) |
| 2711 |
{ |
| 2712 |
struct dahdi_pvt *p = pvt; |
| 2713 |
|
| 2714 |
return alloc_sub(p, analogsub_to_dahdisub(analogsub)); |
| 2715 |
} |
| 2716 |
|
| 2717 |
static int has_voicemail(struct dahdi_pvt *p); |
| 2718 |
|
| 2719 |
static int my_has_voicemail(void *pvt) |
| 2720 |
{ |
| 2721 |
struct dahdi_pvt *p = pvt; |
| 2722 |
|
| 2723 |
return has_voicemail(p); |
| 2724 |
} |
| 2725 |
|
| 2726 |
static int my_play_tone(void *pvt, enum analog_sub sub, enum analog_tone tone) |
| 2727 |
{ |
| 2728 |
struct dahdi_pvt *p = pvt; |
| 2729 |
int index; |
| 2730 |
|
| 2731 |
index = analogsub_to_dahdisub(sub); |
| 2732 |
|
| 2733 |
return tone_zone_play_tone(p->subs[index].dfd, analog_tone_to_dahditone(tone)); |
| 2734 |
} |
| 2735 |
|
| 2736 |
static enum analog_event dahdievent_to_analogevent(int event) |
| 2737 |
{ |
| 2738 |
enum analog_event res; |
| 2739 |
|
| 2740 |
switch (event) { |
| 2741 |
case DAHDI_EVENT_ONHOOK: |
| 2742 |
res = ANALOG_EVENT_ONHOOK; |
| 2743 |
break; |
| 2744 |
case DAHDI_EVENT_RINGOFFHOOK: |
| 2745 |
res = ANALOG_EVENT_RINGOFFHOOK; |
| 2746 |
break; |
| 2747 |
case DAHDI_EVENT_WINKFLASH: |
| 2748 |
res = ANALOG_EVENT_WINKFLASH; |
| 2749 |
break; |
| 2750 |
case DAHDI_EVENT_ALARM: |
| 2751 |
res = ANALOG_EVENT_ALARM; |
| 2752 |
break; |
| 2753 |
case DAHDI_EVENT_NOALARM: |
| 2754 |
res = ANALOG_EVENT_NOALARM; |
| 2755 |
break; |
| 2756 |
case DAHDI_EVENT_DIALCOMPLETE: |
| 2757 |
res = ANALOG_EVENT_DIALCOMPLETE; |
| 2758 |
break; |
| 2759 |
case DAHDI_EVENT_RINGERON: |
| 2760 |
res = ANALOG_EVENT_RINGERON; |
| 2761 |
break; |
| 2762 |
case DAHDI_EVENT_RINGEROFF: |
| 2763 |
res = ANALOG_EVENT_RINGEROFF; |
| 2764 |
break; |
| 2765 |
case DAHDI_EVENT_HOOKCOMPLETE: |
| 2766 |
res = ANALOG_EVENT_HOOKCOMPLETE; |
| 2767 |
break; |
| 2768 |
case DAHDI_EVENT_PULSE_START: |
| 2769 |
res = ANALOG_EVENT_PULSE_START; |
| 2770 |
break; |
| 2771 |
case DAHDI_EVENT_POLARITY: |
| 2772 |
res = ANALOG_EVENT_POLARITY; |
| 2773 |
break; |
| 2774 |
case DAHDI_EVENT_RINGBEGIN: |
| 2775 |
res = ANALOG_EVENT_RINGBEGIN; |
| 2776 |
break; |
| 2777 |
case DAHDI_EVENT_EC_DISABLED: |
| 2778 |
res = ANALOG_EVENT_EC_DISABLED; |
| 2779 |
break; |
| 2780 |
case DAHDI_EVENT_REMOVED: |
| 2781 |
res = ANALOG_EVENT_REMOVED; |
| 2782 |
break; |
| 2783 |
case DAHDI_EVENT_NEONMWI_ACTIVE: |
| 2784 |
res = ANALOG_EVENT_NEONMWI_ACTIVE; |
| 2785 |
break; |
| 2786 |
case DAHDI_EVENT_NEONMWI_INACTIVE: |
| 2787 |
res = ANALOG_EVENT_NEONMWI_INACTIVE; |
| 2788 |
break; |
| 2789 |
#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE |
| 2790 |
case DAHDI_EVENT_TX_CED_DETECTED: |
| 2791 |
res = ANALOG_EVENT_TX_CED_DETECTED; |
| 2792 |
break; |
| 2793 |
case DAHDI_EVENT_RX_CED_DETECTED: |
| 2794 |
res = ANALOG_EVENT_RX_CED_DETECTED; |
| 2795 |
break; |
| 2796 |
case DAHDI_EVENT_EC_NLP_DISABLED: |
| 2797 |
res = ANALOG_EVENT_EC_NLP_DISABLED; |
| 2798 |
break; |
| 2799 |
case DAHDI_EVENT_EC_NLP_ENABLED: |
| 2800 |
res = ANALOG_EVENT_EC_NLP_ENABLED; |
| 2801 |
break; |
| 2802 |
#endif |
| 2803 |
case DAHDI_EVENT_PULSEDIGIT: |
| 2804 |
res = ANALOG_EVENT_PULSEDIGIT; |
| 2805 |
break; |
| 2806 |
case DAHDI_EVENT_DTMFDOWN: |
| 2807 |
res = ANALOG_EVENT_DTMFDOWN; |
| 2808 |
break; |
| 2809 |
case DAHDI_EVENT_DTMFUP: |
| 2810 |
res = ANALOG_EVENT_DTMFUP; |
| 2811 |
break; |
| 2812 |
default: |
| 2813 |
switch(event & 0xFFFF0000) { |
| 2814 |
case DAHDI_EVENT_PULSEDIGIT: |
| 2815 |
case DAHDI_EVENT_DTMFDOWN: |
| 2816 |
case DAHDI_EVENT_DTMFUP: |
| 2817 |
|
| 2818 |
|
| 2819 |
|
| 2820 |
|
| 2821 |
return event; |
| 2822 |
} |
| 2823 |
|
| 2824 |
res = ANALOG_EVENT_ERROR; |
| 2825 |
break; |
| 2826 |
} |
| 2827 |
|
| 2828 |
return res; |
| 2829 |
} |
| 2830 |
|
| 2831 |
static inline int dahdi_wait_event(int fd); |
| 2832 |
|
| 2833 |
static int my_wait_event(void *pvt) |
| 2834 |
{ |
| 2835 |
struct dahdi_pvt *p = pvt; |
| 2836 |
|
| 2837 |
return dahdi_wait_event(p->subs[SUB_REAL].dfd); |
| 2838 |
} |
| 2839 |
|
| 2840 |
static int my_get_event(void *pvt) |
| 2841 |
{ |
| 2842 |
struct dahdi_pvt *p = pvt; |
| 2843 |
int res; |
| 2844 |
|
| 2845 |
if (p->fake_event) { |
| 2846 |
res = p->fake_event; |
| 2847 |
p->fake_event = 0; |
| 2848 |
} else |
| 2849 |
res = dahdi_get_event(p->subs[SUB_REAL].dfd); |
| 2850 |
|
| 2851 |
return dahdievent_to_analogevent(res); |
| 2852 |
} |
| 2853 |
|
| 2854 |
static int my_is_off_hook(void *pvt) |
| 2855 |
{ |
| 2856 |
struct dahdi_pvt *p = pvt; |
| 2857 |
int res; |
| 2858 |
struct dahdi_params par; |
| 2859 |
|
| 2860 |
memset(&par, 0, sizeof(par)); |
| 2861 |
|
| 2862 |
if (p->subs[SUB_REAL].dfd > -1) |
| 2863 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par); |
| 2864 |
else { |
| 2865 |
|
| 2866 |
res = 0; |
| 2867 |
par.rxisoffhook = 0; |
| 2868 |
} |
| 2869 |
if (res) { |
| 2870 |
ast_log(LOG_WARNING, "Unable to check hook state on channel %d: %s\n", p->channel, strerror(errno)); |
| 2871 |
} |
| 2872 |
|
| 2873 |
if ((p->sig == SIG_FXSKS) || (p->sig == SIG_FXSGS)) { |
| 2874 |
|
| 2875 |
|
| 2876 |
|
| 2877 |
return (par.rxbits > -1) || par.rxisoffhook; |
| 2878 |
} |
| 2879 |
|
| 2880 |
return par.rxisoffhook; |
| 2881 |
} |
| 2882 |
|
| 2883 |
static int my_set_echocanceller(void *pvt, int enable) |
| 2884 |
{ |
| 2885 |
struct dahdi_pvt *p = pvt; |
| 2886 |
|
| 2887 |
if (enable) |
| 2888 |
dahdi_ec_enable(p); |
| 2889 |
else |
| 2890 |
dahdi_ec_disable(p); |
| 2891 |
|
| 2892 |
return 0; |
| 2893 |
} |
| 2894 |
|
| 2895 |
static int dahdi_ring_phone(struct dahdi_pvt *p); |
| 2896 |
|
| 2897 |
static int my_ring(void *pvt) |
| 2898 |
{ |
| 2899 |
struct dahdi_pvt *p = pvt; |
| 2900 |
|
| 2901 |
return dahdi_ring_phone(p); |
| 2902 |
} |
| 2903 |
|
| 2904 |
static int my_flash(void *pvt) |
| 2905 |
{ |
| 2906 |
struct dahdi_pvt *p = pvt; |
| 2907 |
int func = DAHDI_FLASH; |
| 2908 |
return ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &func); |
| 2909 |
} |
| 2910 |
|
| 2911 |
static inline int dahdi_set_hook(int fd, int hs); |
| 2912 |
|
| 2913 |
static int my_off_hook(void *pvt) |
| 2914 |
{ |
| 2915 |
struct dahdi_pvt *p = pvt; |
| 2916 |
return dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK); |
| 2917 |
} |
| 2918 |
|
| 2919 |
static void my_set_needringing(void *pvt, int value) |
| 2920 |
{ |
| 2921 |
struct dahdi_pvt *p = pvt; |
| 2922 |
p->subs[SUB_REAL].needringing = value; |
| 2923 |
} |
| 2924 |
|
| 2925 |
static void my_set_polarity(void *pvt, int value) |
| 2926 |
{ |
| 2927 |
struct dahdi_pvt *p = pvt; |
| 2928 |
|
| 2929 |
if (p->channel == CHAN_PSEUDO) { |
| 2930 |
return; |
| 2931 |
} |
| 2932 |
p->polarity = value; |
| 2933 |
ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETPOLARITY, &value); |
| 2934 |
} |
| 2935 |
|
| 2936 |
static void my_start_polarityswitch(void *pvt) |
| 2937 |
{ |
| 2938 |
struct dahdi_pvt *p = pvt; |
| 2939 |
|
| 2940 |
if (p->answeronpolarityswitch || p->hanguponpolarityswitch) { |
| 2941 |
my_set_polarity(pvt, 0); |
| 2942 |
} |
| 2943 |
} |
| 2944 |
|
| 2945 |
static void my_answer_polarityswitch(void *pvt) |
| 2946 |
{ |
| 2947 |
struct dahdi_pvt *p = pvt; |
| 2948 |
|
| 2949 |
if (!p->answeronpolarityswitch) { |
| 2950 |
return; |
| 2951 |
} |
| 2952 |
|
| 2953 |
my_set_polarity(pvt, 1); |
| 2954 |
} |
| 2955 |
|
| 2956 |
static void my_hangup_polarityswitch(void *pvt) |
| 2957 |
{ |
| 2958 |
struct dahdi_pvt *p = pvt; |
| 2959 |
|
| 2960 |
if (!p->hanguponpolarityswitch) { |
| 2961 |
return; |
| 2962 |
} |
| 2963 |
|
| 2964 |
if (p->answeronpolarityswitch) { |
| 2965 |
my_set_polarity(pvt, 0); |
| 2966 |
} else { |
| 2967 |
my_set_polarity(pvt, 1); |
| 2968 |
} |
| 2969 |
} |
| 2970 |
|
| 2971 |
static int my_start(void *pvt) |
| 2972 |
{ |
| 2973 |
struct dahdi_pvt *p = pvt; |
| 2974 |
int x = DAHDI_START; |
| 2975 |
|
| 2976 |
return ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x); |
| 2977 |
} |
| 2978 |
|
| 2979 |
static int my_dial_digits(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop) |
| 2980 |
{ |
| 2981 |
struct dahdi_pvt *p = pvt; |
| 2982 |
|
| 2983 |
if (dop->op != ANALOG_DIAL_OP_REPLACE) { |
| 2984 |
ast_log(LOG_ERROR, "Fix the dial_digits callback!\n"); |
| 2985 |
return -1; |
| 2986 |
} |
| 2987 |
|
| 2988 |
if (sub != ANALOG_SUB_REAL) { |
| 2989 |
ast_log(LOG_ERROR, "Trying to dial_digits '%s' on channel %d subchannel %u\n", |
| 2990 |
dop->dialstr, p->channel, sub); |
| 2991 |
return -1; |
| 2992 |
} |
| 2993 |
|
| 2994 |
return dahdi_dial_str(p, DAHDI_DIAL_OP_REPLACE, dop->dialstr); |
| 2995 |
} |
| 2996 |
|
| 2997 |
static void dahdi_train_ec(struct dahdi_pvt *p); |
| 2998 |
|
| 2999 |
static int my_train_echocanceller(void *pvt) |
| 3000 |
{ |
| 3001 |
struct dahdi_pvt *p = pvt; |
| 3002 |
|
| 3003 |
dahdi_train_ec(p); |
| 3004 |
|
| 3005 |
return 0; |
| 3006 |
} |
| 3007 |
|
| 3008 |
static int my_is_dialing(void *pvt, enum analog_sub sub) |
| 3009 |
{ |
| 3010 |
struct dahdi_pvt *p = pvt; |
| 3011 |
int index; |
| 3012 |
int x; |
| 3013 |
|
| 3014 |
index = analogsub_to_dahdisub(sub); |
| 3015 |
|
| 3016 |
if (ioctl(p->subs[index].dfd, DAHDI_DIALING, &x)) { |
| 3017 |
ast_debug(1, "DAHDI_DIALING ioctl failed!\n"); |
| 3018 |
return -1; |
| 3019 |
} |
| 3020 |
|
| 3021 |
return x; |
| 3022 |
} |
| 3023 |
|
| 3024 |
static int my_on_hook(void *pvt) |
| 3025 |
{ |
| 3026 |
struct dahdi_pvt *p = pvt; |
| 3027 |
return dahdi_set_hook(p->subs[ANALOG_SUB_REAL].dfd, DAHDI_ONHOOK); |
| 3028 |
} |
| 3029 |
|
| 3030 |
#if defined(HAVE_PRI) |
| 3031 |
static void my_pri_fixup_chans(void *chan_old, void *chan_new) |
| 3032 |
{ |
| 3033 |
struct dahdi_pvt *old_chan = chan_old; |
| 3034 |
struct dahdi_pvt *new_chan = chan_new; |
| 3035 |
|
| 3036 |
new_chan->owner = old_chan->owner; |
| 3037 |
old_chan->owner = NULL; |
| 3038 |
if (new_chan->owner) { |
| 3039 |
ast_channel_tech_pvt_set(new_chan->owner, new_chan); |
| 3040 |
ast_channel_internal_fd_set(new_chan->owner, 0, new_chan->subs[SUB_REAL].dfd); |
| 3041 |
new_chan->subs[SUB_REAL].owner = old_chan->subs[SUB_REAL].owner; |
| 3042 |
old_chan->subs[SUB_REAL].owner = NULL; |
| 3043 |
} |
| 3044 |
|
| 3045 |
new_chan->dsp = old_chan->dsp; |
| 3046 |
new_chan->dsp_features = old_chan->dsp_features; |
| 3047 |
old_chan->dsp = NULL; |
| 3048 |
old_chan->dsp_features = 0; |
| 3049 |
|
| 3050 |
|
| 3051 |
new_chan->dialing = old_chan->dialing; |
| 3052 |
new_chan->digital = old_chan->digital; |
| 3053 |
new_chan->outgoing = old_chan->outgoing; |
| 3054 |
old_chan->dialing = 0; |
| 3055 |
old_chan->digital = 0; |
| 3056 |
old_chan->outgoing = 0; |
| 3057 |
|
| 3058 |
|
| 3059 |
new_chan->law = old_chan->law; |
| 3060 |
strcpy(new_chan->dialstring, old_chan->dialstring); |
| 3061 |
} |
| 3062 |
#endif |
| 3063 |
|
| 3064 |
#if defined(HAVE_PRI) |
| 3065 |
static int sig_pri_tone_to_dahditone(enum sig_pri_tone tone) |
| 3066 |
{ |
| 3067 |
switch (tone) { |
| 3068 |
case SIG_PRI_TONE_RINGTONE: |
| 3069 |
return DAHDI_TONE_RINGTONE; |
| 3070 |
case SIG_PRI_TONE_STUTTER: |
| 3071 |
return DAHDI_TONE_STUTTER; |
| 3072 |
case SIG_PRI_TONE_CONGESTION: |
| 3073 |
return DAHDI_TONE_CONGESTION; |
| 3074 |
case SIG_PRI_TONE_DIALTONE: |
| 3075 |
return DAHDI_TONE_DIALTONE; |
| 3076 |
case SIG_PRI_TONE_DIALRECALL: |
| 3077 |
return DAHDI_TONE_DIALRECALL; |
| 3078 |
case SIG_PRI_TONE_INFO: |
| 3079 |
return DAHDI_TONE_INFO; |
| 3080 |
case SIG_PRI_TONE_BUSY: |
| 3081 |
return DAHDI_TONE_BUSY; |
| 3082 |
default: |
| 3083 |
return -1; |
| 3084 |
} |
| 3085 |
} |
| 3086 |
#endif |
| 3087 |
|
| 3088 |
#if defined(HAVE_PRI) |
| 3089 |
static void my_handle_dchan_exception(struct sig_pri_span *pri, int index) |
| 3090 |
{ |
| 3091 |
int x; |
| 3092 |
|
| 3093 |
ioctl(pri->fds[index], DAHDI_GETEVENT, &x); |
| 3094 |
switch (x) { |
| 3095 |
case DAHDI_EVENT_NONE: |
| 3096 |
break; |
| 3097 |
case DAHDI_EVENT_ALARM: |
| 3098 |
case DAHDI_EVENT_NOALARM: |
| 3099 |
if (sig_pri_is_alarm_ignored(pri)) { |
| 3100 |
break; |
| 3101 |
} |
| 3102 |
|
| 3103 |
default: |
| 3104 |
ast_log(LOG_NOTICE, "Got DAHDI event: %s (%d) on D-channel of span %d\n", |
| 3105 |
event2str(x), x, pri->span); |
| 3106 |
break; |
| 3107 |
} |
| 3108 |
|
| 3109 |
switch (x) { |
| 3110 |
case DAHDI_EVENT_ALARM: |
| 3111 |
pri_event_alarm(pri, index, 0); |
| 3112 |
break; |
| 3113 |
case DAHDI_EVENT_NOALARM: |
| 3114 |
pri_event_noalarm(pri, index, 0); |
| 3115 |
break; |
| 3116 |
case DAHDI_EVENT_REMOVED: |
| 3117 |
pri_queue_for_destruction(pri); |
| 3118 |
break; |
| 3119 |
default: |
| 3120 |
break; |
| 3121 |
} |
| 3122 |
} |
| 3123 |
#endif |
| 3124 |
|
| 3125 |
#if defined(HAVE_PRI) |
| 3126 |
static int my_pri_play_tone(void *pvt, enum sig_pri_tone tone) |
| 3127 |
{ |
| 3128 |
struct dahdi_pvt *p = pvt; |
| 3129 |
|
| 3130 |
return tone_zone_play_tone(p->subs[SUB_REAL].dfd, sig_pri_tone_to_dahditone(tone)); |
| 3131 |
} |
| 3132 |
#endif |
| 3133 |
|
| 3134 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 3135 |
|
| 3136 |
|
| 3137 |
|
| 3138 |
|
| 3139 |
|
| 3140 |
|
| 3141 |
|
| 3142 |
|
| 3143 |
static void my_set_callerid(void *pvt, const struct ast_party_caller *caller) |
| 3144 |
{ |
| 3145 |
struct dahdi_pvt *p = pvt; |
| 3146 |
|
| 3147 |
ast_copy_string(p->cid_num, |
| 3148 |
S_COR(caller->id.number.valid, caller->id.number.str, ""), |
| 3149 |
sizeof(p->cid_num)); |
| 3150 |
ast_copy_string(p->cid_name, |
| 3151 |
S_COR(caller->id.name.valid, caller->id.name.str, ""), |
| 3152 |
sizeof(p->cid_name)); |
| 3153 |
ast_copy_string(p->cid_subaddr, |
| 3154 |
S_COR(caller->id.subaddress.valid, caller->id.subaddress.str, ""), |
| 3155 |
sizeof(p->cid_subaddr)); |
| 3156 |
p->cid_ton = caller->id.number.plan; |
| 3157 |
p->callingpres = ast_party_id_presentation(&caller->id); |
| 3158 |
if (caller->id.tag) { |
| 3159 |
ast_copy_string(p->cid_tag, caller->id.tag, sizeof(p->cid_tag)); |
| 3160 |
} |
| 3161 |
ast_copy_string(p->cid_ani, |
| 3162 |
S_COR(caller->ani.number.valid, caller->ani.number.str, ""), |
| 3163 |
sizeof(p->cid_ani)); |
| 3164 |
p->cid_ani2 = caller->ani2; |
| 3165 |
} |
| 3166 |
#endif |
| 3167 |
|
| 3168 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 3169 |
|
| 3170 |
|
| 3171 |
|
| 3172 |
|
| 3173 |
|
| 3174 |
|
| 3175 |
|
| 3176 |
|
| 3177 |
static void my_set_dnid(void *pvt, const char *dnid) |
| 3178 |
{ |
| 3179 |
struct dahdi_pvt *p = pvt; |
| 3180 |
|
| 3181 |
ast_copy_string(p->dnid, dnid, sizeof(p->dnid)); |
| 3182 |
} |
| 3183 |
#endif |
| 3184 |
|
| 3185 |
#if defined(HAVE_PRI) |
| 3186 |
|
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
|
| 3191 |
|
| 3192 |
|
| 3193 |
|
| 3194 |
static void my_set_rdnis(void *pvt, const char *rdnis) |
| 3195 |
{ |
| 3196 |
struct dahdi_pvt *p = pvt; |
| 3197 |
|
| 3198 |
ast_copy_string(p->rdnis, rdnis, sizeof(p->rdnis)); |
| 3199 |
} |
| 3200 |
#endif |
| 3201 |
|
| 3202 |
#if defined(HAVE_PRI) |
| 3203 |
|
| 3204 |
|
| 3205 |
|
| 3206 |
|
| 3207 |
|
| 3208 |
|
| 3209 |
|
| 3210 |
|
| 3211 |
|
| 3212 |
|
| 3213 |
|
| 3214 |
|
| 3215 |
|
| 3216 |
|
| 3217 |
|
| 3218 |
|
| 3219 |
|
| 3220 |
|
| 3221 |
|
| 3222 |
|
| 3223 |
|
| 3224 |
|
| 3225 |
|
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
static void my_pri_make_cc_dialstring(void *priv, char *buf, size_t buf_size) |
| 3230 |
{ |
| 3231 |
char *dial; |
| 3232 |
struct dahdi_pvt *pvt; |
| 3233 |
AST_DECLARE_APP_ARGS(args, |
| 3234 |
AST_APP_ARG(tech); |
| 3235 |
AST_APP_ARG(group); |
| 3236 |
|
| 3237 |
|
| 3238 |
|
| 3239 |
); |
| 3240 |
|
| 3241 |
pvt = priv; |
| 3242 |
dial = ast_strdupa(pvt->dialstring); |
| 3243 |
AST_NONSTANDARD_APP_ARGS(args, dial, '/'); |
| 3244 |
if (!args.tech) { |
| 3245 |
ast_copy_string(buf, pvt->dialstring, buf_size); |
| 3246 |
return; |
| 3247 |
} |
| 3248 |
if (!args.group) { |
| 3249 |
|
| 3250 |
snprintf(buf, buf_size, "%s/i%d-", args.tech, pvt->pri->span); |
| 3251 |
return; |
| 3252 |
} |
| 3253 |
if (isdigit(args.group[0]) || args.group[0] == 'i' || strchr(args.group, '!')) { |
| 3254 |
|
| 3255 |
|
| 3256 |
ast_copy_string(buf, pvt->dialstring, buf_size); |
| 3257 |
return; |
| 3258 |
} |
| 3259 |
|
| 3260 |
snprintf(buf, buf_size, "%s/i%d-%s", args.tech, pvt->pri->span, args.group); |
| 3261 |
} |
| 3262 |
#endif |
| 3263 |
|
| 3264 |
#if defined(HAVE_PRI) |
| 3265 |
|
| 3266 |
|
| 3267 |
|
| 3268 |
|
| 3269 |
|
| 3270 |
|
| 3271 |
|
| 3272 |
|
| 3273 |
|
| 3274 |
static void dahdi_pri_update_span_devstate(struct sig_pri_span *pri) |
| 3275 |
{ |
| 3276 |
unsigned idx; |
| 3277 |
unsigned num_b_chans; |
| 3278 |
unsigned in_use; |
| 3279 |
unsigned in_alarm; |
| 3280 |
enum ast_device_state new_state; |
| 3281 |
|
| 3282 |
|
| 3283 |
num_b_chans = 0; |
| 3284 |
in_use = 0; |
| 3285 |
in_alarm = 1; |
| 3286 |
for (idx = pri->numchans; idx--;) { |
| 3287 |
if (pri->pvts[idx] && !pri->pvts[idx]->no_b_channel) { |
| 3288 |
|
| 3289 |
++num_b_chans; |
| 3290 |
if (!sig_pri_is_chan_available(pri->pvts[idx])) { |
| 3291 |
++in_use; |
| 3292 |
} |
| 3293 |
if (!pri->pvts[idx]->inalarm) { |
| 3294 |
|
| 3295 |
in_alarm = 0; |
| 3296 |
} |
| 3297 |
} |
| 3298 |
} |
| 3299 |
|
| 3300 |
|
| 3301 |
if (in_alarm) { |
| 3302 |
new_state = AST_DEVICE_UNAVAILABLE; |
| 3303 |
} else { |
| 3304 |
new_state = num_b_chans == in_use ? AST_DEVICE_BUSY : AST_DEVICE_NOT_INUSE; |
| 3305 |
} |
| 3306 |
if (pri->congestion_devstate != new_state) { |
| 3307 |
pri->congestion_devstate = new_state; |
| 3308 |
ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_NOT_CACHABLE, "DAHDI/I%d/congestion", pri->span); |
| 3309 |
} |
| 3310 |
#if defined(THRESHOLD_DEVSTATE_PLACEHOLDER) |
| 3311 |
|
| 3312 |
if (in_alarm) { |
| 3313 |
new_state = AST_DEVICE_UNAVAILABLE; |
| 3314 |
} else if (!in_use) { |
| 3315 |
new_state = AST_DEVICE_NOT_INUSE; |
| 3316 |
} else if (!pri->user_busy_threshold) { |
| 3317 |
new_state = in_use < num_b_chans ? AST_DEVICE_INUSE : AST_DEVICE_BUSY; |
| 3318 |
} else { |
| 3319 |
new_state = in_use < pri->user_busy_threshold ? AST_DEVICE_INUSE |
| 3320 |
: AST_DEVICE_BUSY; |
| 3321 |
} |
| 3322 |
if (pri->threshold_devstate != new_state) { |
| 3323 |
pri->threshold_devstate = new_state; |
| 3324 |
ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_NOT_CACHABLE, "DAHDI/I%d/threshold", pri->span); |
| 3325 |
} |
| 3326 |
#endif |
| 3327 |
} |
| 3328 |
#endif |
| 3329 |
|
| 3330 |
#if defined(HAVE_PRI) |
| 3331 |
|
| 3332 |
|
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
static void my_module_ref(void) |
| 3337 |
{ |
| 3338 |
ast_module_ref(ast_module_info->self); |
| 3339 |
} |
| 3340 |
#endif |
| 3341 |
|
| 3342 |
#if defined(HAVE_PRI) |
| 3343 |
|
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
|
| 3348 |
static void my_module_unref(void) |
| 3349 |
{ |
| 3350 |
ast_module_unref(ast_module_info->self); |
| 3351 |
} |
| 3352 |
#endif |
| 3353 |
|
| 3354 |
#if defined(HAVE_PRI) |
| 3355 |
#if defined(HAVE_PRI_CALL_WAITING) |
| 3356 |
static void my_pri_init_config(void *priv, struct sig_pri_span *pri); |
| 3357 |
#endif |
| 3358 |
static int dahdi_new_pri_nobch_channel(struct sig_pri_span *pri); |
| 3359 |
|
| 3360 |
struct sig_pri_callback sig_pri_callbacks = |
| 3361 |
{ |
| 3362 |
.handle_dchan_exception = my_handle_dchan_exception, |
| 3363 |
.play_tone = my_pri_play_tone, |
| 3364 |
.set_echocanceller = my_set_echocanceller, |
| 3365 |
.dsp_reset_and_flush_digits = my_dsp_reset_and_flush_digits, |
| 3366 |
.lock_private = my_lock_private, |
| 3367 |
.unlock_private = my_unlock_private, |
| 3368 |
.deadlock_avoidance_private = my_deadlock_avoidance_private, |
| 3369 |
.new_ast_channel = my_new_pri_ast_channel, |
| 3370 |
.fixup_chans = my_pri_fixup_chans, |
| 3371 |
.set_alarm = my_set_alarm, |
| 3372 |
.set_dialing = my_set_dialing, |
| 3373 |
.set_outgoing = my_set_outgoing, |
| 3374 |
.set_digital = my_set_digital, |
| 3375 |
.set_callerid = my_set_callerid, |
| 3376 |
.set_dnid = my_set_dnid, |
| 3377 |
.set_rdnis = my_set_rdnis, |
| 3378 |
.new_nobch_intf = dahdi_new_pri_nobch_channel, |
| 3379 |
#if defined(HAVE_PRI_CALL_WAITING) |
| 3380 |
.init_config = my_pri_init_config, |
| 3381 |
#endif |
| 3382 |
.get_orig_dialstring = my_get_orig_dialstring, |
| 3383 |
.make_cc_dialstring = my_pri_make_cc_dialstring, |
| 3384 |
.update_span_devstate = dahdi_pri_update_span_devstate, |
| 3385 |
.module_ref = my_module_ref, |
| 3386 |
.module_unref = my_module_unref, |
| 3387 |
.dial_digits = my_pri_dial_digits, |
| 3388 |
.open_media = my_pri_ss7_open_media, |
| 3389 |
.ami_channel_event = my_ami_channel_event, |
| 3390 |
.destroy_later = pri_queue_for_destruction, |
| 3391 |
}; |
| 3392 |
#endif |
| 3393 |
|
| 3394 |
#if defined(HAVE_SS7) |
| 3395 |
|
| 3396 |
|
| 3397 |
|
| 3398 |
|
| 3399 |
|
| 3400 |
|
| 3401 |
|
| 3402 |
|
| 3403 |
static void my_handle_link_exception(struct sig_ss7_linkset *linkset, int which) |
| 3404 |
{ |
| 3405 |
int event; |
| 3406 |
|
| 3407 |
if (ioctl(linkset->fds[which], DAHDI_GETEVENT, &event)) { |
| 3408 |
ast_log(LOG_ERROR, "SS7: Error in exception retrieval on span %d/%d!\n", |
| 3409 |
linkset->span, which); |
| 3410 |
return; |
| 3411 |
} |
| 3412 |
switch (event) { |
| 3413 |
case DAHDI_EVENT_NONE: |
| 3414 |
break; |
| 3415 |
case DAHDI_EVENT_ALARM: |
| 3416 |
ast_log(LOG_ERROR, "SS7 got event: %s(%d) on span %d/%d\n", |
| 3417 |
event2str(event), event, linkset->span, which); |
| 3418 |
sig_ss7_link_alarm(linkset, which); |
| 3419 |
break; |
| 3420 |
case DAHDI_EVENT_NOALARM: |
| 3421 |
ast_log(LOG_ERROR, "SS7 got event: %s(%d) on span %d/%d\n", |
| 3422 |
event2str(event), event, linkset->span, which); |
| 3423 |
sig_ss7_link_noalarm(linkset, which); |
| 3424 |
break; |
| 3425 |
default: |
| 3426 |
ast_log(LOG_NOTICE, "SS7 got event: %s(%d) on span %d/%d\n", |
| 3427 |
event2str(event), event, linkset->span, which); |
| 3428 |
break; |
| 3429 |
} |
| 3430 |
} |
| 3431 |
#endif |
| 3432 |
|
| 3433 |
#if defined(HAVE_SS7) |
| 3434 |
static void my_ss7_set_loopback(void *pvt, int enable) |
| 3435 |
{ |
| 3436 |
struct dahdi_pvt *p = pvt; |
| 3437 |
|
| 3438 |
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_LOOPBACK, &enable)) { |
| 3439 |
ast_log(LOG_WARNING, "Unable to set loopback on channel %d: %s\n", p->channel, |
| 3440 |
strerror(errno)); |
| 3441 |
} |
| 3442 |
} |
| 3443 |
#endif |
| 3444 |
|
| 3445 |
#if defined(HAVE_SS7) |
| 3446 |
|
| 3447 |
|
| 3448 |
|
| 3449 |
|
| 3450 |
|
| 3451 |
|
| 3452 |
|
| 3453 |
|
| 3454 |
|
| 3455 |
|
| 3456 |
static struct sig_ss7_linkset *my_ss7_find_linkset(struct ss7 *ss7) |
| 3457 |
{ |
| 3458 |
int idx; |
| 3459 |
|
| 3460 |
if (!ss7) { |
| 3461 |
return NULL; |
| 3462 |
} |
| 3463 |
|
| 3464 |
for (idx = 0; idx < NUM_SPANS; ++idx) { |
| 3465 |
if (linksets[idx].ss7.ss7 == ss7) { |
| 3466 |
return &linksets[idx].ss7; |
| 3467 |
} |
| 3468 |
} |
| 3469 |
return NULL; |
| 3470 |
} |
| 3471 |
#endif |
| 3472 |
|
| 3473 |
#if defined(HAVE_SS7) |
| 3474 |
|
| 3475 |
|
| 3476 |
|
| 3477 |
|
| 3478 |
|
| 3479 |
|
| 3480 |
|
| 3481 |
|
| 3482 |
|
| 3483 |
|
| 3484 |
|
| 3485 |
|
| 3486 |
|
| 3487 |
|
| 3488 |
|
| 3489 |
static struct ast_channel *my_new_ss7_ast_channel(void *pvt, int state, enum sig_ss7_law law, char *exten, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor) |
| 3490 |
{ |
| 3491 |
struct dahdi_pvt *p = pvt; |
| 3492 |
int audio; |
| 3493 |
int newlaw; |
| 3494 |
ast_callid callid = 0; |
| 3495 |
int callid_created = ast_callid_threadstorage_auto(&callid); |
| 3496 |
|
| 3497 |
|
| 3498 |
audio = 1; |
| 3499 |
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &audio) == -1) |
| 3500 |
ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d: %s\n", |
| 3501 |
p->channel, audio, strerror(errno)); |
| 3502 |
|
| 3503 |
if (law != SIG_SS7_DEFLAW) { |
| 3504 |
dahdi_setlaw(p->subs[SUB_REAL].dfd, |
| 3505 |
(law == SIG_SS7_ULAW) ? DAHDI_LAW_MULAW : DAHDI_LAW_ALAW); |
| 3506 |
} |
| 3507 |
|
| 3508 |
ast_copy_string(p->exten, exten, sizeof(p->exten)); |
| 3509 |
|
| 3510 |
newlaw = -1; |
| 3511 |
switch (law) { |
| 3512 |
case SIG_SS7_DEFLAW: |
| 3513 |
newlaw = 0; |
| 3514 |
break; |
| 3515 |
case SIG_SS7_ALAW: |
| 3516 |
newlaw = DAHDI_LAW_ALAW; |
| 3517 |
break; |
| 3518 |
case SIG_SS7_ULAW: |
| 3519 |
newlaw = DAHDI_LAW_MULAW; |
| 3520 |
break; |
| 3521 |
} |
| 3522 |
return dahdi_new_callid_clean(p, state, 0, SUB_REAL, newlaw, assignedids, requestor, callid, callid_created); |
| 3523 |
} |
| 3524 |
#endif |
| 3525 |
|
| 3526 |
#if defined(HAVE_SS7) |
| 3527 |
static int sig_ss7_tone_to_dahditone(enum sig_ss7_tone tone) |
| 3528 |
{ |
| 3529 |
switch (tone) { |
| 3530 |
case SIG_SS7_TONE_RINGTONE: |
| 3531 |
return DAHDI_TONE_RINGTONE; |
| 3532 |
case SIG_SS7_TONE_STUTTER: |
| 3533 |
return DAHDI_TONE_STUTTER; |
| 3534 |
case SIG_SS7_TONE_CONGESTION: |
| 3535 |
return DAHDI_TONE_CONGESTION; |
| 3536 |
case SIG_SS7_TONE_DIALTONE: |
| 3537 |
return DAHDI_TONE_DIALTONE; |
| 3538 |
case SIG_SS7_TONE_DIALRECALL: |
| 3539 |
return DAHDI_TONE_DIALRECALL; |
| 3540 |
case SIG_SS7_TONE_INFO: |
| 3541 |
return DAHDI_TONE_INFO; |
| 3542 |
case SIG_SS7_TONE_BUSY: |
| 3543 |
return DAHDI_TONE_BUSY; |
| 3544 |
default: |
| 3545 |
return -1; |
| 3546 |
} |
| 3547 |
} |
| 3548 |
#endif |
| 3549 |
|
| 3550 |
#if defined(HAVE_SS7) |
| 3551 |
static int my_ss7_play_tone(void *pvt, enum sig_ss7_tone tone) |
| 3552 |
{ |
| 3553 |
struct dahdi_pvt *p = pvt; |
| 3554 |
|
| 3555 |
return tone_zone_play_tone(p->subs[SUB_REAL].dfd, sig_ss7_tone_to_dahditone(tone)); |
| 3556 |
} |
| 3557 |
#endif |
| 3558 |
|
| 3559 |
#if defined(HAVE_SS7) |
| 3560 |
struct sig_ss7_callback sig_ss7_callbacks = |
| 3561 |
{ |
| 3562 |
.lock_private = my_lock_private, |
| 3563 |
.unlock_private = my_unlock_private, |
| 3564 |
.deadlock_avoidance_private = my_deadlock_avoidance_private, |
| 3565 |
|
| 3566 |
.set_echocanceller = my_set_echocanceller, |
| 3567 |
.set_loopback = my_ss7_set_loopback, |
| 3568 |
|
| 3569 |
.new_ast_channel = my_new_ss7_ast_channel, |
| 3570 |
.play_tone = my_ss7_play_tone, |
| 3571 |
|
| 3572 |
.handle_link_exception = my_handle_link_exception, |
| 3573 |
.set_alarm = my_set_alarm, |
| 3574 |
.set_dialing = my_set_dialing, |
| 3575 |
.set_outgoing = my_set_outgoing, |
| 3576 |
.set_digital = my_set_digital, |
| 3577 |
.set_inservice = my_set_inservice, |
| 3578 |
.set_locallyblocked = my_set_locallyblocked, |
| 3579 |
.set_remotelyblocked = my_set_remotelyblocked, |
| 3580 |
.set_callerid = my_set_callerid, |
| 3581 |
.set_dnid = my_set_dnid, |
| 3582 |
.open_media = my_pri_ss7_open_media, |
| 3583 |
.find_linkset = my_ss7_find_linkset, |
| 3584 |
}; |
| 3585 |
#endif |
| 3586 |
|
| 3587 |
|
| 3588 |
|
| 3589 |
|
| 3590 |
|
| 3591 |
|
| 3592 |
|
| 3593 |
|
| 3594 |
|
| 3595 |
|
| 3596 |
|
| 3597 |
|
| 3598 |
|
| 3599 |
|
| 3600 |
|
| 3601 |
|
| 3602 |
|
| 3603 |
static void notify_message(char *mailbox, int thereornot) |
| 3604 |
{ |
| 3605 |
char s[sizeof(mwimonitornotify) + 164]; |
| 3606 |
|
| 3607 |
if (ast_strlen_zero(mailbox)) { |
| 3608 |
return; |
| 3609 |
} |
| 3610 |
|
| 3611 |
ast_publish_mwi_state(mailbox, NULL, thereornot, thereornot); |
| 3612 |
if (!ast_strlen_zero(mwimonitornotify)) { |
| 3613 |
snprintf(s, sizeof(s), "%s %s %d", mwimonitornotify, mailbox, thereornot); |
| 3614 |
ast_safe_system(s); |
| 3615 |
} |
| 3616 |
} |
| 3617 |
|
| 3618 |
static void my_handle_notify_message(struct ast_channel *chan, void *pvt, int cid_flags, int neon_mwievent) |
| 3619 |
{ |
| 3620 |
struct dahdi_pvt *p = pvt; |
| 3621 |
|
| 3622 |
if (neon_mwievent > -1 && !p->mwimonitor_neon) |
| 3623 |
return; |
| 3624 |
|
| 3625 |
if (neon_mwievent == ANALOG_EVENT_NEONMWI_ACTIVE || cid_flags & CID_MSGWAITING) { |
| 3626 |
ast_log(LOG_NOTICE, "MWI: Channel %d message waiting, mailbox %s\n", p->channel, p->mailbox); |
| 3627 |
notify_message(p->mailbox, 1); |
| 3628 |
} else if (neon_mwievent == ANALOG_EVENT_NEONMWI_INACTIVE || cid_flags & CID_NOMSGWAITING) { |
| 3629 |
ast_log(LOG_NOTICE, "MWI: Channel %d no message waiting, mailbox %s\n", p->channel, p->mailbox); |
| 3630 |
notify_message(p->mailbox, 0); |
| 3631 |
} |
| 3632 |
|
| 3633 |
|
| 3634 |
if (neon_mwievent == -1 && p->mwimonitor_rpas) { |
| 3635 |
ast_hangup(chan); |
| 3636 |
return; |
| 3637 |
} |
| 3638 |
} |
| 3639 |
|
| 3640 |
static int my_have_progressdetect(void *pvt) |
| 3641 |
{ |
| 3642 |
struct dahdi_pvt *p = pvt; |
| 3643 |
|
| 3644 |
if ((p->callprogress & CALLPROGRESS_PROGRESS) |
| 3645 |
&& CANPROGRESSDETECT(p) && p->dsp && p->outgoing) { |
| 3646 |
return 1; |
| 3647 |
} else { |
| 3648 |
|
| 3649 |
return 0; |
| 3650 |
} |
| 3651 |
} |
| 3652 |
|
| 3653 |
#define gen_pvt_field_callback(type, field) \ |
| 3654 |
static type my_get_##field(void *pvt) \ |
| 3655 |
{ \ |
| 3656 |
struct dahdi_pvt *p = pvt; \ |
| 3657 |
return p->field; \ |
| 3658 |
} |
| 3659 |
|
| 3660 |
gen_pvt_field_callback(int, firstdigit_timeout); |
| 3661 |
gen_pvt_field_callback(int, interdigit_timeout); |
| 3662 |
gen_pvt_field_callback(int, matchdigit_timeout); |
| 3663 |
|
| 3664 |
#undef gen_pvt_field_callback |
| 3665 |
|
| 3666 |
struct analog_callback analog_callbacks = |
| 3667 |
{ |
| 3668 |
.play_tone = my_play_tone, |
| 3669 |
.get_event = my_get_event, |
| 3670 |
.wait_event = my_wait_event, |
| 3671 |
.is_off_hook = my_is_off_hook, |
| 3672 |
.set_echocanceller = my_set_echocanceller, |
| 3673 |
.ring = my_ring, |
| 3674 |
.flash = my_flash, |
| 3675 |
.off_hook = my_off_hook, |
| 3676 |
.dial_digits = my_dial_digits, |
| 3677 |
.train_echocanceller = my_train_echocanceller, |
| 3678 |
.on_hook = my_on_hook, |
| 3679 |
.is_dialing = my_is_dialing, |
| 3680 |
.allocate_sub = my_allocate_sub, |
| 3681 |
.unallocate_sub = my_unallocate_sub, |
| 3682 |
.swap_subs = my_swap_subchannels, |
| 3683 |
.has_voicemail = my_has_voicemail, |
| 3684 |
.check_for_conference = my_check_for_conference, |
| 3685 |
.conf_add = my_conf_add, |
| 3686 |
.conf_del = my_conf_del, |
| 3687 |
.complete_conference_update = my_complete_conference_update, |
| 3688 |
.start = my_start, |
| 3689 |
.all_subchannels_hungup = my_all_subchannels_hungup, |
| 3690 |
.lock_private = my_lock_private, |
| 3691 |
.unlock_private = my_unlock_private, |
| 3692 |
.deadlock_avoidance_private = my_deadlock_avoidance_private, |
| 3693 |
.handle_dtmf = my_handle_dtmf, |
| 3694 |
.wink = my_wink, |
| 3695 |
.new_ast_channel = my_new_analog_ast_channel, |
| 3696 |
.dsp_set_digitmode = my_dsp_set_digitmode, |
| 3697 |
.dsp_reset_and_flush_digits = my_dsp_reset_and_flush_digits, |
| 3698 |
.send_callerid = my_send_callerid, |
| 3699 |
.callwait = my_callwait, |
| 3700 |
.stop_callwait = my_stop_callwait, |
| 3701 |
.get_callerid = my_get_callerid, |
| 3702 |
.start_cid_detect = my_start_cid_detect, |
| 3703 |
.stop_cid_detect = my_stop_cid_detect, |
| 3704 |
.handle_notify_message = my_handle_notify_message, |
| 3705 |
.increase_ss_count = my_increase_ss_count, |
| 3706 |
.decrease_ss_count = my_decrease_ss_count, |
| 3707 |
.distinctive_ring = my_distinctive_ring, |
| 3708 |
.set_linear_mode = my_set_linear_mode, |
| 3709 |
.set_inthreeway = my_set_inthreeway, |
| 3710 |
.get_and_handle_alarms = my_get_and_handle_alarms, |
| 3711 |
.get_sigpvt_bridged_channel = my_get_sigpvt_bridged_channel, |
| 3712 |
.get_sub_fd = my_get_sub_fd, |
| 3713 |
.set_cadence = my_set_cadence, |
| 3714 |
.set_alarm = my_set_alarm, |
| 3715 |
.set_dialing = my_set_dialing, |
| 3716 |
.set_outgoing = my_set_outgoing, |
| 3717 |
.set_ringtimeout = my_set_ringtimeout, |
| 3718 |
.set_waitingfordt = my_set_waitingfordt, |
| 3719 |
.check_waitingfordt = my_check_waitingfordt, |
| 3720 |
.set_confirmanswer = my_set_confirmanswer, |
| 3721 |
.check_confirmanswer = my_check_confirmanswer, |
| 3722 |
.set_callwaiting = my_set_callwaiting, |
| 3723 |
.cancel_cidspill = my_cancel_cidspill, |
| 3724 |
.confmute = my_confmute, |
| 3725 |
.set_pulsedial = my_set_pulsedial, |
| 3726 |
.set_new_owner = my_set_new_owner, |
| 3727 |
.get_orig_dialstring = my_get_orig_dialstring, |
| 3728 |
.set_needringing = my_set_needringing, |
| 3729 |
.set_polarity = my_set_polarity, |
| 3730 |
.start_polarityswitch = my_start_polarityswitch, |
| 3731 |
.answer_polarityswitch = my_answer_polarityswitch, |
| 3732 |
.hangup_polarityswitch = my_hangup_polarityswitch, |
| 3733 |
.have_progressdetect = my_have_progressdetect, |
| 3734 |
.get_firstdigit_timeout = my_get_firstdigit_timeout, |
| 3735 |
.get_matchdigit_timeout = my_get_matchdigit_timeout, |
| 3736 |
.get_interdigit_timeout = my_get_interdigit_timeout, |
| 3737 |
}; |
| 3738 |
|
| 3739 |
|
| 3740 |
static struct dahdi_pvt *round_robin[64]; |
| 3741 |
|
| 3742 |
int _dahdi_get_index(struct ast_channel *ast, struct dahdi_pvt *p, int nullok, const char *fname, unsigned long line) |
| 3743 |
{ |
| 3744 |
int res; |
| 3745 |
if (p->subs[SUB_REAL].owner == ast) |
| 3746 |
res = 0; |
| 3747 |
else if (p->subs[SUB_CALLWAIT].owner == ast) |
| 3748 |
res = 1; |
| 3749 |
else if (p->subs[SUB_THREEWAY].owner == ast) |
| 3750 |
res = 2; |
| 3751 |
else { |
| 3752 |
res = -1; |
| 3753 |
if (!nullok) |
| 3754 |
ast_log(LOG_WARNING, |
| 3755 |
"Unable to get index for '%s' on channel %d (%s(), line %lu)\n", |
| 3756 |
ast ? ast_channel_name(ast) : "", p->channel, fname, line); |
| 3757 |
} |
| 3758 |
return res; |
| 3759 |
} |
| 3760 |
|
| 3761 |
|
| 3762 |
|
| 3763 |
|
| 3764 |
|
| 3765 |
|
| 3766 |
|
| 3767 |
|
| 3768 |
|
| 3769 |
|
| 3770 |
|
| 3771 |
|
| 3772 |
|
| 3773 |
|
| 3774 |
static void dahdi_lock_sub_owner(struct dahdi_pvt *pvt, int sub_idx) |
| 3775 |
{ |
| 3776 |
for (;;) { |
| 3777 |
if (!pvt->subs[sub_idx].owner) { |
| 3778 |
|
| 3779 |
break; |
| 3780 |
} |
| 3781 |
if (!ast_channel_trylock(pvt->subs[sub_idx].owner)) { |
| 3782 |
|
| 3783 |
break; |
| 3784 |
} |
| 3785 |
|
| 3786 |
DEADLOCK_AVOIDANCE(&pvt->lock); |
| 3787 |
} |
| 3788 |
} |
| 3789 |
|
| 3790 |
static void wakeup_sub(struct dahdi_pvt *p, int a) |
| 3791 |
{ |
| 3792 |
dahdi_lock_sub_owner(p, a); |
| 3793 |
if (p->subs[a].owner) { |
| 3794 |
ast_queue_frame(p->subs[a].owner, &ast_null_frame); |
| 3795 |
ast_channel_unlock(p->subs[a].owner); |
| 3796 |
} |
| 3797 |
} |
| 3798 |
|
| 3799 |
static void dahdi_queue_frame(struct dahdi_pvt *p, struct ast_frame *f) |
| 3800 |
{ |
| 3801 |
for (;;) { |
| 3802 |
if (p->owner) { |
| 3803 |
if (ast_channel_trylock(p->owner)) { |
| 3804 |
DEADLOCK_AVOIDANCE(&p->lock); |
| 3805 |
} else { |
| 3806 |
ast_queue_frame(p->owner, f); |
| 3807 |
ast_channel_unlock(p->owner); |
| 3808 |
break; |
| 3809 |
} |
| 3810 |
} else |
| 3811 |
break; |
| 3812 |
} |
| 3813 |
} |
| 3814 |
|
| 3815 |
static void publish_channel_alarm_clear(int channel) |
| 3816 |
{ |
| 3817 |
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); |
| 3818 |
RAII_VAR(struct ast_str *, dahdi_chan, ast_str_create(32), ast_free); |
| 3819 |
if (!dahdi_chan) { |
| 3820 |
return; |
| 3821 |
} |
| 3822 |
|
| 3823 |
ast_str_set(&dahdi_chan, 0, "%d", channel); |
| 3824 |
ast_log(LOG_NOTICE, "Alarm cleared on channel DAHDI/%d\n", channel); |
| 3825 |
body = ast_json_pack("{s: s}", "DAHDIChannel", ast_str_buffer(dahdi_chan)); |
| 3826 |
if (!body) { |
| 3827 |
return; |
| 3828 |
} |
| 3829 |
|
| 3830 |
ast_manager_publish_event("AlarmClear", EVENT_FLAG_SYSTEM, body); |
| 3831 |
} |
| 3832 |
|
| 3833 |
static void publish_span_alarm_clear(int span) |
| 3834 |
{ |
| 3835 |
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); |
| 3836 |
|
| 3837 |
ast_log(LOG_NOTICE, "Alarm cleared on span %d\n", span); |
| 3838 |
body = ast_json_pack("{s: i}", "Span", span); |
| 3839 |
if (!body) { |
| 3840 |
return; |
| 3841 |
} |
| 3842 |
|
| 3843 |
ast_manager_publish_event("SpanAlarmClear", EVENT_FLAG_SYSTEM, body); |
| 3844 |
} |
| 3845 |
|
| 3846 |
static void handle_clear_alarms(struct dahdi_pvt *p) |
| 3847 |
{ |
| 3848 |
#if defined(HAVE_PRI) |
| 3849 |
if (dahdi_sig_pri_lib_handles(p->sig) && sig_pri_is_alarm_ignored(p->pri)) { |
| 3850 |
return; |
| 3851 |
} |
| 3852 |
#endif |
| 3853 |
|
| 3854 |
if (report_alarms & REPORT_CHANNEL_ALARMS) { |
| 3855 |
publish_channel_alarm_clear(p->channel); |
| 3856 |
} |
| 3857 |
if (report_alarms & REPORT_SPAN_ALARMS && p->manages_span_alarms) { |
| 3858 |
publish_span_alarm_clear(p->span); |
| 3859 |
} |
| 3860 |
} |
| 3861 |
|
| 3862 |
#ifdef HAVE_OPENR2 |
| 3863 |
static void mfcr2_queue_for_destruction(const struct dahdi_pvt *p) |
| 3864 |
{ |
| 3865 |
const struct dahdi_mfcr2 *r2link = p->mfcr2; |
| 3866 |
struct r2link_entry *cur; |
| 3867 |
AST_LIST_LOCK(&r2links); |
| 3868 |
AST_LIST_TRAVERSE_SAFE_BEGIN(&r2links, cur, list) { |
| 3869 |
if (r2link == &cur->mfcr2) { |
| 3870 |
ast_debug(3, "MFC/R2 channel %d queued for destruction\n", p->channel); |
| 3871 |
AST_LIST_MOVE_CURRENT(&nodev_r2links, list); |
| 3872 |
break; |
| 3873 |
} |
| 3874 |
} |
| 3875 |
AST_LIST_TRAVERSE_SAFE_END; |
| 3876 |
AST_LIST_UNLOCK(&r2links); |
| 3877 |
} |
| 3878 |
|
| 3879 |
static int dahdi_r2_answer(struct dahdi_pvt *p) |
| 3880 |
{ |
| 3881 |
int res = 0; |
| 3882 |
|
| 3883 |
|
| 3884 |
|
| 3885 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1 |
| 3886 |
const char *double_answer = pbx_builtin_getvar_helper(p->owner, "MFCR2_DOUBLE_ANSWER"); |
| 3887 |
int wants_double_answer = ast_true(double_answer) ? 1 : 0; |
| 3888 |
if (!double_answer) { |
| 3889 |
|
| 3890 |
|
| 3891 |
res = openr2_chan_answer_call(p->r2chan); |
| 3892 |
} else if (wants_double_answer) { |
| 3893 |
res = openr2_chan_answer_call_with_mode(p->r2chan, OR2_ANSWER_DOUBLE); |
| 3894 |
} else { |
| 3895 |
res = openr2_chan_answer_call_with_mode(p->r2chan, OR2_ANSWER_SIMPLE); |
| 3896 |
} |
| 3897 |
#else |
| 3898 |
res = openr2_chan_answer_call(p->r2chan); |
| 3899 |
#endif |
| 3900 |
return res; |
| 3901 |
} |
| 3902 |
|
| 3903 |
|
| 3904 |
|
| 3905 |
|
| 3906 |
static openr2_calling_party_category_t dahdi_r2_get_channel_category(struct ast_channel *c) |
| 3907 |
{ |
| 3908 |
openr2_calling_party_category_t cat; |
| 3909 |
const char *catstr = pbx_builtin_getvar_helper(c, "MFCR2_CATEGORY"); |
| 3910 |
struct dahdi_pvt *p = ast_channel_tech_pvt(c); |
| 3911 |
if (ast_strlen_zero(catstr)) { |
| 3912 |
ast_debug(1, "No MFC/R2 category specified for chan %s, using default %s\n", |
| 3913 |
ast_channel_name(c), openr2_proto_get_category_string(p->mfcr2_category)); |
| 3914 |
return p->mfcr2_category; |
| 3915 |
} |
| 3916 |
if ((cat = openr2_proto_get_category(catstr)) == OR2_CALLING_PARTY_CATEGORY_UNKNOWN) { |
| 3917 |
ast_log(LOG_WARNING, "Invalid category specified '%s' for chan %s, using default %s\n", |
| 3918 |
catstr, ast_channel_name(c), openr2_proto_get_category_string(p->mfcr2_category)); |
| 3919 |
return p->mfcr2_category; |
| 3920 |
} |
| 3921 |
ast_debug(1, "Using category %s\n", catstr); |
| 3922 |
return cat; |
| 3923 |
} |
| 3924 |
|
| 3925 |
static void dahdi_r2_on_call_init(openr2_chan_t *r2chan) |
| 3926 |
{ |
| 3927 |
struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan); |
| 3928 |
ast_mutex_lock(&p->lock); |
| 3929 |
if (p->mfcr2call) { |
| 3930 |
ast_mutex_unlock(&p->lock); |
| 3931 |
|
| 3932 |
|
| 3933 |
|
| 3934 |
|
| 3935 |
|
| 3936 |
ast_log(LOG_ERROR, "Collision of calls on chan %d detected!.\n", openr2_chan_get_number(r2chan)); |
| 3937 |
return; |
| 3938 |
} |
| 3939 |
p->mfcr2call = 1; |
| 3940 |
|
| 3941 |
p->cid_name[0] = '\0'; |
| 3942 |
p->cid_num[0] = '\0'; |
| 3943 |
p->cid_subaddr[0] = '\0'; |
| 3944 |
p->rdnis[0] = '\0'; |
| 3945 |
p->exten[0] = '\0'; |
| 3946 |
p->mfcr2_ani_index = '\0'; |
| 3947 |
p->mfcr2_dnis_index = '\0'; |
| 3948 |
p->mfcr2_dnis_matched = 0; |
| 3949 |
p->mfcr2_answer_pending = 0; |
| 3950 |
p->mfcr2_call_accepted = 0; |
| 3951 |
ast_mutex_unlock(&p->lock); |
| 3952 |
ast_verbose("New MFC/R2 call detected on chan %d.\n", openr2_chan_get_number(r2chan)); |
| 3953 |
} |
| 3954 |
|
| 3955 |
static void dahdi_r2_on_hardware_alarm(openr2_chan_t *r2chan, int alarm) |
| 3956 |
{ |
| 3957 |
int res; |
| 3958 |
struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan); |
| 3959 |
ast_mutex_lock(&p->lock); |
| 3960 |
p->inalarm = alarm ? 1 : 0; |
| 3961 |
if (p->inalarm) { |
| 3962 |
res = get_alarms(p); |
| 3963 |
if (res == DAHDI_ALARM_NOTOPEN) { |
| 3964 |
mfcr2_queue_for_destruction(p); |
| 3965 |
} |
| 3966 |
handle_alarms(p, res); |
| 3967 |
} else { |
| 3968 |
handle_clear_alarms(p); |
| 3969 |
} |
| 3970 |
ast_mutex_unlock(&p->lock); |
| 3971 |
} |
| 3972 |
|
| 3973 |
static void dahdi_r2_on_os_error(openr2_chan_t *r2chan, int errorcode) |
| 3974 |
{ |
| 3975 |
struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan); |
| 3976 |
|
| 3977 |
ast_log(LOG_ERROR, "OS error on chan %d: %s\n", openr2_chan_get_number(r2chan), strerror(errorcode)); |
| 3978 |
ast_mutex_lock(&p->lock); |
| 3979 |
|
| 3980 |
if (errorcode == ENODEV) { |
| 3981 |
struct dahdi_mfcr2 *r2link = p->mfcr2; |
| 3982 |
p->mfcr2call = 0; |
| 3983 |
if (r2link) { |
| 3984 |
r2link->nodev = 1; |
| 3985 |
} |
| 3986 |
} |
| 3987 |
ast_mutex_unlock(&p->lock); |
| 3988 |
} |
| 3989 |
|
| 3990 |
static void dahdi_r2_on_protocol_error(openr2_chan_t *r2chan, openr2_protocol_error_t reason) |
| 3991 |
{ |
| 3992 |
struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan); |
| 3993 |
ast_log(LOG_ERROR, "MFC/R2 protocol error on chan %d: %s\n", openr2_chan_get_number(r2chan), openr2_proto_get_error(reason)); |
| 3994 |
if (p->owner) { |
| 3995 |
ast_channel_hangupcause_set(p->owner, AST_CAUSE_PROTOCOL_ERROR); |
| 3996 |
ast_channel_softhangup_internal_flag_add(p->owner, AST_SOFTHANGUP_DEV); |
| 3997 |
} |
| 3998 |
ast_mutex_lock(&p->lock); |
| 3999 |
p->mfcr2call = 0; |
| 4000 |
ast_mutex_unlock(&p->lock); |
| 4001 |
} |
| 4002 |
|
| 4003 |
static void dahdi_r2_disconnect_call(struct dahdi_pvt *p, openr2_call_disconnect_cause_t cause) |
| 4004 |
{ |
| 4005 |
if (openr2_chan_disconnect_call(p->r2chan, cause)) { |
| 4006 |
ast_log(LOG_NOTICE, "Bad! failed to disconnect call on channel %d with reason %s, hope for the best!\n", |
| 4007 |
p->channel, openr2_proto_get_disconnect_string(cause)); |
| 4008 |
|
| 4009 |
openr2_chan_set_idle(p->r2chan); |
| 4010 |
ast_mutex_lock(&p->lock); |
| 4011 |
p->mfcr2call = 0; |
| 4012 |
ast_mutex_unlock(&p->lock); |
| 4013 |
} |
| 4014 |
} |
| 4015 |
|
| 4016 |
static void dahdi_r2_on_call_offered(openr2_chan_t *r2chan, const char *ani, const char *dnis, openr2_calling_party_category_t category) |
| 4017 |
{ |
| 4018 |
struct dahdi_pvt *p; |
| 4019 |
struct ast_channel *c; |
| 4020 |
ast_callid callid = 0; |
| 4021 |
int callid_created = ast_callid_threadstorage_auto(&callid); |
| 4022 |
ast_verbose("MFC/R2 call offered on chan %d. ANI = %s, DNIS = %s, Category = %s\n", |
| 4023 |
openr2_chan_get_number(r2chan), ani ? ani : "(restricted)", dnis, |
| 4024 |
openr2_proto_get_category_string(category)); |
| 4025 |
p = openr2_chan_get_client_data(r2chan); |
| 4026 |
|
| 4027 |
if (!p->mfcr2_allow_collect_calls && category == OR2_CALLING_PARTY_CATEGORY_COLLECT_CALL) { |
| 4028 |
ast_log(LOG_NOTICE, "Rejecting MFC/R2 collect call\n"); |
| 4029 |
dahdi_r2_disconnect_call(p, OR2_CAUSE_COLLECT_CALL_REJECTED); |
| 4030 |
goto dahdi_r2_on_call_offered_cleanup; |
| 4031 |
} |
| 4032 |
ast_mutex_lock(&p->lock); |
| 4033 |
p->mfcr2_recvd_category = category; |
| 4034 |
|
| 4035 |
if (!p->use_callerid) { |
| 4036 |
ast_debug(1, "No CID allowed in configuration, CID is being cleared!\n"); |
| 4037 |
p->cid_num[0] = 0; |
| 4038 |
p->cid_name[0] = 0; |
| 4039 |
} |
| 4040 |
|
| 4041 |
if (p->immediate || !openr2_context_get_max_dnis(openr2_chan_get_context(r2chan))) { |
| 4042 |
ast_debug(1, "Setting exten => s because of immediate or 0 DNIS configured\n"); |
| 4043 |
p->exten[0] = 's'; |
| 4044 |
p->exten[1] = 0; |
| 4045 |
} |
| 4046 |
ast_mutex_unlock(&p->lock); |
| 4047 |
if (!ast_exists_extension(NULL, p->context, p->exten, 1, p->cid_num)) { |
| 4048 |
ast_log(LOG_NOTICE, "MFC/R2 call on channel %d requested non-existent extension '%s' in context '%s'. Rejecting call.\n", |
| 4049 |
p->channel, p->exten, p->context); |
| 4050 |
dahdi_r2_disconnect_call(p, OR2_CAUSE_UNALLOCATED_NUMBER); |
| 4051 |
goto dahdi_r2_on_call_offered_cleanup; |
| 4052 |
} |
| 4053 |
if (!p->mfcr2_accept_on_offer) { |
| 4054 |
|
| 4055 |
c = dahdi_new(p, AST_STATE_RING, 1, SUB_REAL, DAHDI_LAW_ALAW, NULL, NULL, callid); |
| 4056 |
if (c) { |
| 4057 |
|
| 4058 |
|
| 4059 |
|
| 4060 |
goto dahdi_r2_on_call_offered_cleanup; |
| 4061 |
} |
| 4062 |
ast_log(LOG_WARNING, "Unable to create PBX channel in DAHDI channel %d\n", p->channel); |
| 4063 |
dahdi_r2_disconnect_call(p, OR2_CAUSE_OUT_OF_ORDER); |
| 4064 |
} else if (p->mfcr2_charge_calls) { |
| 4065 |
ast_debug(1, "Accepting MFC/R2 call with charge on chan %d\n", p->channel); |
| 4066 |
openr2_chan_accept_call(r2chan, OR2_CALL_WITH_CHARGE); |
| 4067 |
} else { |
| 4068 |
ast_debug(1, "Accepting MFC/R2 call with no charge on chan %d\n", p->channel); |
| 4069 |
openr2_chan_accept_call(r2chan, OR2_CALL_NO_CHARGE); |
| 4070 |
} |
| 4071 |
|
| 4072 |
dahdi_r2_on_call_offered_cleanup: |
| 4073 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 4074 |
} |
| 4075 |
|
| 4076 |
static void dahdi_r2_on_call_end(openr2_chan_t *r2chan) |
| 4077 |
{ |
| 4078 |
struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan); |
| 4079 |
ast_verbose("MFC/R2 call end on channel %d\n", p->channel); |
| 4080 |
ast_mutex_lock(&p->lock); |
| 4081 |
p->mfcr2call = 0; |
| 4082 |
ast_mutex_unlock(&p->lock); |
| 4083 |
} |
| 4084 |
|
| 4085 |
static void dahdi_r2_on_call_accepted(openr2_chan_t *r2chan, openr2_call_mode_t mode) |
| 4086 |
{ |
| 4087 |
struct dahdi_pvt *p = NULL; |
| 4088 |
struct ast_channel *c = NULL; |
| 4089 |
ast_callid callid = 0; |
| 4090 |
int callid_created = ast_callid_threadstorage_auto(&callid); |
| 4091 |
p = openr2_chan_get_client_data(r2chan); |
| 4092 |
dahdi_ec_enable(p); |
| 4093 |
p->mfcr2_call_accepted = 1; |
| 4094 |
|
| 4095 |
if (OR2_DIR_BACKWARD == openr2_chan_get_direction(r2chan)) { |
| 4096 |
ast_verbose("MFC/R2 call has been accepted on backward channel %d\n", openr2_chan_get_number(r2chan)); |
| 4097 |
|
| 4098 |
|
| 4099 |
|
| 4100 |
|
| 4101 |
if (!p->mfcr2_accept_on_offer) { |
| 4102 |
openr2_chan_disable_read(r2chan); |
| 4103 |
if (p->mfcr2_answer_pending) { |
| 4104 |
ast_debug(1, "Answering MFC/R2 call after accepting it on chan %d\n", openr2_chan_get_number(r2chan)); |
| 4105 |
dahdi_r2_answer(p); |
| 4106 |
} |
| 4107 |
goto dahdi_r2_on_call_accepted_cleanup; |
| 4108 |
} |
| 4109 |
c = dahdi_new(p, AST_STATE_RING, 1, SUB_REAL, DAHDI_LAW_ALAW, NULL, NULL, callid); |
| 4110 |
if (c) { |
| 4111 |
|
| 4112 |
|
| 4113 |
openr2_chan_disable_read(r2chan); |
| 4114 |
goto dahdi_r2_on_call_accepted_cleanup; |
| 4115 |
} |
| 4116 |
ast_log(LOG_WARNING, "Unable to create PBX channel in DAHDI channel %d\n", p->channel); |
| 4117 |
|
| 4118 |
dahdi_r2_disconnect_call(p, OR2_CAUSE_OUT_OF_ORDER); |
| 4119 |
goto dahdi_r2_on_call_accepted_cleanup; |
| 4120 |
} |
| 4121 |
|
| 4122 |
ast_verbose("MFC/R2 call has been accepted on forward channel %d\n", p->channel); |
| 4123 |
p->subs[SUB_REAL].needringing = 1; |
| 4124 |
p->dialing = 0; |
| 4125 |
|
| 4126 |
openr2_chan_disable_read(r2chan); |
| 4127 |
|
| 4128 |
dahdi_r2_on_call_accepted_cleanup: |
| 4129 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 4130 |
} |
| 4131 |
|
| 4132 |
static void dahdi_r2_on_call_answered(openr2_chan_t *r2chan) |
| 4133 |
{ |
| 4134 |
struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan); |
| 4135 |
ast_verbose("MFC/R2 call has been answered on channel %d\n", openr2_chan_get_number(r2chan)); |
| 4136 |
p->subs[SUB_REAL].needanswer = 1; |
| 4137 |
} |
| 4138 |
|
| 4139 |
static void dahdi_r2_on_call_read(openr2_chan_t *r2chan, const unsigned char *buf, int buflen) |
| 4140 |
{ |
| 4141 |
|
| 4142 |
} |
| 4143 |
|
| 4144 |
static int dahdi_r2_cause_to_ast_cause(openr2_call_disconnect_cause_t cause) |
| 4145 |
{ |
| 4146 |
switch (cause) { |
| 4147 |
case OR2_CAUSE_BUSY_NUMBER: |
| 4148 |
return AST_CAUSE_BUSY; |
| 4149 |
case OR2_CAUSE_NETWORK_CONGESTION: |
| 4150 |
return AST_CAUSE_CONGESTION; |
| 4151 |
case OR2_CAUSE_OUT_OF_ORDER: |
| 4152 |
return AST_CAUSE_DESTINATION_OUT_OF_ORDER; |
| 4153 |
case OR2_CAUSE_UNALLOCATED_NUMBER: |
| 4154 |
return AST_CAUSE_UNREGISTERED; |
| 4155 |
case OR2_CAUSE_NO_ANSWER: |
| 4156 |
return AST_CAUSE_NO_ANSWER; |
| 4157 |
case OR2_CAUSE_NORMAL_CLEARING: |
| 4158 |
return AST_CAUSE_NORMAL_CLEARING; |
| 4159 |
case OR2_CAUSE_UNSPECIFIED: |
| 4160 |
default: |
| 4161 |
return AST_CAUSE_NOTDEFINED; |
| 4162 |
} |
| 4163 |
} |
| 4164 |
|
| 4165 |
static void dahdi_r2_on_call_disconnect(openr2_chan_t *r2chan, openr2_call_disconnect_cause_t cause) |
| 4166 |
{ |
| 4167 |
struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan); |
| 4168 |
char cause_str[50]; |
| 4169 |
struct ast_control_pvt_cause_code *cause_code; |
| 4170 |
int datalen = sizeof(*cause_code); |
| 4171 |
|
| 4172 |
ast_verbose("MFC/R2 call disconnected on channel %d\n", openr2_chan_get_number(r2chan)); |
| 4173 |
ast_mutex_lock(&p->lock); |
| 4174 |
if (!p->owner) { |
| 4175 |
ast_mutex_unlock(&p->lock); |
| 4176 |
|
| 4177 |
dahdi_r2_disconnect_call(p, OR2_CAUSE_NORMAL_CLEARING); |
| 4178 |
return; |
| 4179 |
} |
| 4180 |
|
| 4181 |
snprintf(cause_str, sizeof(cause_str), "R2 DISCONNECT (%s)", openr2_proto_get_disconnect_string(cause)); |
| 4182 |
datalen += strlen(cause_str); |
| 4183 |
cause_code = ast_alloca(datalen); |
| 4184 |
memset(cause_code, 0, datalen); |
| 4185 |
cause_code->ast_cause = dahdi_r2_cause_to_ast_cause(cause); |
| 4186 |
ast_copy_string(cause_code->chan_name, ast_channel_name(p->owner), AST_CHANNEL_NAME); |
| 4187 |
ast_copy_string(cause_code->code, cause_str, datalen + 1 - sizeof(*cause_code)); |
| 4188 |
ast_queue_control_data(p->owner, AST_CONTROL_PVT_CAUSE_CODE, cause_code, datalen); |
| 4189 |
ast_channel_hangupcause_hash_set(p->owner, cause_code, datalen); |
| 4190 |
ast_channel_hangupcause_set(p->owner, cause_code->ast_cause); |
| 4191 |
|
| 4192 |
|
| 4193 |
|
| 4194 |
if (ast_channel_state(p->owner) == AST_STATE_UP) { |
| 4195 |
ast_channel_softhangup_internal_flag_add(p->owner, AST_SOFTHANGUP_DEV); |
| 4196 |
ast_mutex_unlock(&p->lock); |
| 4197 |
} else if (openr2_chan_get_direction(r2chan) == OR2_DIR_FORWARD) { |
| 4198 |
|
| 4199 |
switch (cause) { |
| 4200 |
case OR2_CAUSE_BUSY_NUMBER: |
| 4201 |
p->subs[SUB_REAL].needbusy = 1; |
| 4202 |
break; |
| 4203 |
case OR2_CAUSE_NETWORK_CONGESTION: |
| 4204 |
case OR2_CAUSE_OUT_OF_ORDER: |
| 4205 |
case OR2_CAUSE_UNALLOCATED_NUMBER: |
| 4206 |
case OR2_CAUSE_NO_ANSWER: |
| 4207 |
case OR2_CAUSE_UNSPECIFIED: |
| 4208 |
case OR2_CAUSE_NORMAL_CLEARING: |
| 4209 |
p->subs[SUB_REAL].needcongestion = 1; |
| 4210 |
break; |
| 4211 |
default: |
| 4212 |
ast_channel_softhangup_internal_flag_add(p->owner, AST_SOFTHANGUP_DEV); |
| 4213 |
} |
| 4214 |
ast_mutex_unlock(&p->lock); |
| 4215 |
} else { |
| 4216 |
ast_mutex_unlock(&p->lock); |
| 4217 |
|
| 4218 |
|
| 4219 |
ast_queue_hangup_with_cause(p->owner, dahdi_r2_cause_to_ast_cause(cause)); |
| 4220 |
} |
| 4221 |
} |
| 4222 |
|
| 4223 |
static void dahdi_r2_write_log(openr2_log_level_t level, char *logmessage) |
| 4224 |
{ |
| 4225 |
switch (level) { |
| 4226 |
case OR2_LOG_NOTICE: |
| 4227 |
ast_verbose("%s", logmessage); |
| 4228 |
break; |
| 4229 |
case OR2_LOG_WARNING: |
| 4230 |
ast_log(LOG_WARNING, "%s", logmessage); |
| 4231 |
break; |
| 4232 |
case OR2_LOG_ERROR: |
| 4233 |
ast_log(LOG_ERROR, "%s", logmessage); |
| 4234 |
break; |
| 4235 |
case OR2_LOG_STACK_TRACE: |
| 4236 |
case OR2_LOG_MF_TRACE: |
| 4237 |
case OR2_LOG_CAS_TRACE: |
| 4238 |
case OR2_LOG_DEBUG: |
| 4239 |
case OR2_LOG_EX_DEBUG: |
| 4240 |
ast_debug(1, "%s", logmessage); |
| 4241 |
break; |
| 4242 |
default: |
| 4243 |
ast_log(LOG_WARNING, "We should handle logging level %d here.\n", level); |
| 4244 |
ast_debug(1, "%s", logmessage); |
| 4245 |
break; |
| 4246 |
} |
| 4247 |
} |
| 4248 |
|
| 4249 |
static void dahdi_r2_on_line_blocked(openr2_chan_t *r2chan) |
| 4250 |
{ |
| 4251 |
struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan); |
| 4252 |
ast_mutex_lock(&p->lock); |
| 4253 |
p->remotelyblocked = 1; |
| 4254 |
ast_mutex_unlock(&p->lock); |
| 4255 |
ast_log(LOG_NOTICE, "Far end blocked on chan %d\n", openr2_chan_get_number(r2chan)); |
| 4256 |
} |
| 4257 |
|
| 4258 |
static void dahdi_r2_on_line_idle(openr2_chan_t *r2chan) |
| 4259 |
{ |
| 4260 |
struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan); |
| 4261 |
ast_mutex_lock(&p->lock); |
| 4262 |
p->remotelyblocked = 0; |
| 4263 |
ast_mutex_unlock(&p->lock); |
| 4264 |
ast_log(LOG_NOTICE, "Far end unblocked on chan %d\n", openr2_chan_get_number(r2chan)); |
| 4265 |
} |
| 4266 |
|
| 4267 |
static void dahdi_r2_on_context_log(openr2_context_t *r2context, openr2_log_level_t level, const char *fmt, va_list ap) |
| 4268 |
__attribute__((format (printf, 3, 0))); |
| 4269 |
static void dahdi_r2_on_context_log(openr2_context_t *r2context, openr2_log_level_t level, const char *fmt, va_list ap) |
| 4270 |
{ |
| 4271 |
#define CONTEXT_TAG "Context - " |
| 4272 |
char logmsg[256]; |
| 4273 |
char completemsg[sizeof(logmsg) * 2]; |
| 4274 |
vsnprintf(logmsg, sizeof(logmsg), fmt, ap); |
| 4275 |
snprintf(completemsg, sizeof(completemsg), CONTEXT_TAG "%s", logmsg); |
| 4276 |
dahdi_r2_write_log(level, completemsg); |
| 4277 |
#undef CONTEXT_TAG |
| 4278 |
} |
| 4279 |
|
| 4280 |
static void dahdi_r2_on_chan_log(openr2_chan_t *r2chan, openr2_log_level_t level, const char *fmt, va_list ap) |
| 4281 |
__attribute__((format (printf, 3, 0))); |
| 4282 |
static void dahdi_r2_on_chan_log(openr2_chan_t *r2chan, openr2_log_level_t level, const char *fmt, va_list ap) |
| 4283 |
{ |
| 4284 |
#define CHAN_TAG "Chan " |
| 4285 |
char logmsg[256]; |
| 4286 |
char completemsg[sizeof(logmsg) * 2]; |
| 4287 |
vsnprintf(logmsg, sizeof(logmsg), fmt, ap); |
| 4288 |
snprintf(completemsg, sizeof(completemsg), CHAN_TAG "%d - %s", openr2_chan_get_number(r2chan), logmsg); |
| 4289 |
dahdi_r2_write_log(level, completemsg); |
| 4290 |
#undef CHAN_TAG |
| 4291 |
} |
| 4292 |
|
| 4293 |
static int dahdi_r2_on_dnis_digit_received(openr2_chan_t *r2chan, char digit) |
| 4294 |
{ |
| 4295 |
struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan); |
| 4296 |
|
| 4297 |
if (p->immediate) { |
| 4298 |
return 0; |
| 4299 |
} |
| 4300 |
p->exten[p->mfcr2_dnis_index] = digit; |
| 4301 |
p->rdnis[p->mfcr2_dnis_index] = digit; |
| 4302 |
p->mfcr2_dnis_index++; |
| 4303 |
p->exten[p->mfcr2_dnis_index] = 0; |
| 4304 |
p->rdnis[p->mfcr2_dnis_index] = 0; |
| 4305 |
|
| 4306 |
if ((p->mfcr2_dnis_matched || |
| 4307 |
(ast_exists_extension(NULL, p->context, p->exten, 1, p->cid_num) && (p->mfcr2_dnis_matched = 1))) && |
| 4308 |
!ast_matchmore_extension(NULL, p->context, p->exten, 1, p->cid_num)) { |
| 4309 |
return 0; |
| 4310 |
} |
| 4311 |
|
| 4312 |
return 1; |
| 4313 |
} |
| 4314 |
|
| 4315 |
static void dahdi_r2_on_ani_digit_received(openr2_chan_t *r2chan, char digit) |
| 4316 |
{ |
| 4317 |
struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan); |
| 4318 |
p->cid_num[p->mfcr2_ani_index] = digit; |
| 4319 |
p->cid_name[p->mfcr2_ani_index] = digit; |
| 4320 |
p->mfcr2_ani_index++; |
| 4321 |
p->cid_num[p->mfcr2_ani_index] = 0; |
| 4322 |
p->cid_name[p->mfcr2_ani_index] = 0; |
| 4323 |
} |
| 4324 |
|
| 4325 |
static void dahdi_r2_on_billing_pulse_received(openr2_chan_t *r2chan) |
| 4326 |
{ |
| 4327 |
ast_verbose("MFC/R2 billing pulse received on channel %d\n", openr2_chan_get_number(r2chan)); |
| 4328 |
} |
| 4329 |
|
| 4330 |
static openr2_event_interface_t dahdi_r2_event_iface = { |
| 4331 |
.on_call_init = dahdi_r2_on_call_init, |
| 4332 |
.on_call_offered = dahdi_r2_on_call_offered, |
| 4333 |
.on_call_accepted = dahdi_r2_on_call_accepted, |
| 4334 |
.on_call_answered = dahdi_r2_on_call_answered, |
| 4335 |
.on_call_disconnect = dahdi_r2_on_call_disconnect, |
| 4336 |
.on_call_end = dahdi_r2_on_call_end, |
| 4337 |
.on_call_read = dahdi_r2_on_call_read, |
| 4338 |
.on_hardware_alarm = dahdi_r2_on_hardware_alarm, |
| 4339 |
.on_os_error = dahdi_r2_on_os_error, |
| 4340 |
.on_protocol_error = dahdi_r2_on_protocol_error, |
| 4341 |
.on_line_blocked = dahdi_r2_on_line_blocked, |
| 4342 |
.on_line_idle = dahdi_r2_on_line_idle, |
| 4343 |
|
| 4344 |
.on_context_log = (openr2_handle_context_logging_func)dahdi_r2_on_context_log, |
| 4345 |
.on_dnis_digit_received = dahdi_r2_on_dnis_digit_received, |
| 4346 |
.on_ani_digit_received = dahdi_r2_on_ani_digit_received, |
| 4347 |
|
| 4348 |
.on_billing_pulse_received = dahdi_r2_on_billing_pulse_received |
| 4349 |
}; |
| 4350 |
|
| 4351 |
static inline int16_t dahdi_r2_alaw_to_linear(uint8_t sample) |
| 4352 |
{ |
| 4353 |
return AST_ALAW(sample); |
| 4354 |
} |
| 4355 |
|
| 4356 |
static inline uint8_t dahdi_r2_linear_to_alaw(int sample) |
| 4357 |
{ |
| 4358 |
return AST_LIN2A(sample); |
| 4359 |
} |
| 4360 |
|
| 4361 |
static openr2_transcoder_interface_t dahdi_r2_transcode_iface = { |
| 4362 |
dahdi_r2_alaw_to_linear, |
| 4363 |
dahdi_r2_linear_to_alaw |
| 4364 |
}; |
| 4365 |
|
| 4366 |
#endif |
| 4367 |
|
| 4368 |
static void swap_subs(struct dahdi_pvt *p, int a, int b) |
| 4369 |
{ |
| 4370 |
int tchan; |
| 4371 |
int tinthreeway; |
| 4372 |
struct ast_channel *towner; |
| 4373 |
|
| 4374 |
ast_debug(1, "Swapping %d and %d\n", a, b); |
| 4375 |
|
| 4376 |
tchan = p->subs[a].chan; |
| 4377 |
towner = p->subs[a].owner; |
| 4378 |
tinthreeway = p->subs[a].inthreeway; |
| 4379 |
|
| 4380 |
p->subs[a].chan = p->subs[b].chan; |
| 4381 |
p->subs[a].owner = p->subs[b].owner; |
| 4382 |
p->subs[a].inthreeway = p->subs[b].inthreeway; |
| 4383 |
|
| 4384 |
p->subs[b].chan = tchan; |
| 4385 |
p->subs[b].owner = towner; |
| 4386 |
p->subs[b].inthreeway = tinthreeway; |
| 4387 |
|
| 4388 |
if (p->subs[a].owner) |
| 4389 |
ast_channel_set_fd(p->subs[a].owner, 0, p->subs[a].dfd); |
| 4390 |
if (p->subs[b].owner) |
| 4391 |
ast_channel_set_fd(p->subs[b].owner, 0, p->subs[b].dfd); |
| 4392 |
wakeup_sub(p, a); |
| 4393 |
wakeup_sub(p, b); |
| 4394 |
} |
| 4395 |
|
| 4396 |
static int dahdi_open(char *fn) |
| 4397 |
{ |
| 4398 |
int fd; |
| 4399 |
int isnum; |
| 4400 |
int chan = 0; |
| 4401 |
int bs; |
| 4402 |
int x; |
| 4403 |
isnum = 1; |
| 4404 |
for (x = 0; x < strlen(fn); x++) { |
| 4405 |
if (!isdigit(fn[x])) { |
| 4406 |
isnum = 0; |
| 4407 |
break; |
| 4408 |
} |
| 4409 |
} |
| 4410 |
if (isnum) { |
| 4411 |
chan = atoi(fn); |
| 4412 |
if (chan < 1) { |
| 4413 |
ast_log(LOG_WARNING, "Invalid channel number '%s'\n", fn); |
| 4414 |
return -1; |
| 4415 |
} |
| 4416 |
fn = "/dev/dahdi/channel"; |
| 4417 |
} |
| 4418 |
fd = open(fn, O_RDWR | O_NONBLOCK); |
| 4419 |
if (fd < 0) { |
| 4420 |
ast_log(LOG_WARNING, "Unable to open '%s': %s\n", fn, strerror(errno)); |
| 4421 |
return -1; |
| 4422 |
} |
| 4423 |
if (chan) { |
| 4424 |
if (ioctl(fd, DAHDI_SPECIFY, &chan)) { |
| 4425 |
x = errno; |
| 4426 |
close(fd); |
| 4427 |
errno = x; |
| 4428 |
ast_log(LOG_WARNING, "Unable to specify channel %d: %s\n", chan, strerror(errno)); |
| 4429 |
return -1; |
| 4430 |
} |
| 4431 |
} |
| 4432 |
bs = READ_SIZE; |
| 4433 |
if (ioctl(fd, DAHDI_SET_BLOCKSIZE, &bs) == -1) { |
| 4434 |
ast_log(LOG_WARNING, "Unable to set blocksize '%d': %s\n", bs, strerror(errno)); |
| 4435 |
x = errno; |
| 4436 |
close(fd); |
| 4437 |
errno = x; |
| 4438 |
return -1; |
| 4439 |
} |
| 4440 |
return fd; |
| 4441 |
} |
| 4442 |
|
| 4443 |
static void dahdi_close(int fd) |
| 4444 |
{ |
| 4445 |
if (fd > 0) |
| 4446 |
close(fd); |
| 4447 |
} |
| 4448 |
|
| 4449 |
static void dahdi_close_sub(struct dahdi_pvt *chan_pvt, int sub_num) |
| 4450 |
{ |
| 4451 |
dahdi_close(chan_pvt->subs[sub_num].dfd); |
| 4452 |
chan_pvt->subs[sub_num].dfd = -1; |
| 4453 |
} |
| 4454 |
|
| 4455 |
#if defined(HAVE_PRI) |
| 4456 |
static void dahdi_close_pri_fd(struct dahdi_pri *pri, int fd_num) |
| 4457 |
{ |
| 4458 |
dahdi_close(pri->pri.fds[fd_num]); |
| 4459 |
pri->pri.fds[fd_num] = -1; |
| 4460 |
} |
| 4461 |
#endif |
| 4462 |
|
| 4463 |
#if defined(HAVE_SS7) |
| 4464 |
static void dahdi_close_ss7_fd(struct dahdi_ss7 *ss7, int fd_num) |
| 4465 |
{ |
| 4466 |
dahdi_close(ss7->ss7.fds[fd_num]); |
| 4467 |
ss7->ss7.fds[fd_num] = -1; |
| 4468 |
} |
| 4469 |
#endif |
| 4470 |
|
| 4471 |
static int dahdi_setlinear(int dfd, int linear) |
| 4472 |
{ |
| 4473 |
return ioctl(dfd, DAHDI_SETLINEAR, &linear); |
| 4474 |
} |
| 4475 |
|
| 4476 |
|
| 4477 |
static int alloc_sub(struct dahdi_pvt *p, int x) |
| 4478 |
{ |
| 4479 |
struct dahdi_bufferinfo bi; |
| 4480 |
int res; |
| 4481 |
if (p->subs[x].dfd >= 0) { |
| 4482 |
ast_log(LOG_WARNING, "%s subchannel of %d already in use\n", subnames[x], p->channel); |
| 4483 |
return -1; |
| 4484 |
} |
| 4485 |
|
| 4486 |
p->subs[x].dfd = dahdi_open("/dev/dahdi/pseudo"); |
| 4487 |
if (p->subs[x].dfd <= -1) { |
| 4488 |
ast_log(LOG_WARNING, "Unable to open pseudo channel: %s\n", strerror(errno)); |
| 4489 |
return -1; |
| 4490 |
} |
| 4491 |
|
| 4492 |
res = ioctl(p->subs[x].dfd, DAHDI_GET_BUFINFO, &bi); |
| 4493 |
if (!res) { |
| 4494 |
bi.txbufpolicy = p->buf_policy; |
| 4495 |
bi.rxbufpolicy = p->buf_policy; |
| 4496 |
bi.numbufs = p->buf_no; |
| 4497 |
res = ioctl(p->subs[x].dfd, DAHDI_SET_BUFINFO, &bi); |
| 4498 |
if (res < 0) { |
| 4499 |
ast_log(LOG_WARNING, "Unable to set buffer policy on channel %d: %s\n", x, strerror(errno)); |
| 4500 |
} |
| 4501 |
} else |
| 4502 |
ast_log(LOG_WARNING, "Unable to check buffer policy on channel %d: %s\n", x, strerror(errno)); |
| 4503 |
|
| 4504 |
if (ioctl(p->subs[x].dfd, DAHDI_CHANNO, &p->subs[x].chan) == 1) { |
| 4505 |
ast_log(LOG_WARNING, "Unable to get channel number for pseudo channel on FD %d: %s\n", p->subs[x].dfd, strerror(errno)); |
| 4506 |
dahdi_close_sub(p, x); |
| 4507 |
p->subs[x].dfd = -1; |
| 4508 |
return -1; |
| 4509 |
} |
| 4510 |
ast_debug(1, "Allocated %s subchannel on FD %d channel %d\n", subnames[x], p->subs[x].dfd, p->subs[x].chan); |
| 4511 |
return 0; |
| 4512 |
} |
| 4513 |
|
| 4514 |
static int unalloc_sub(struct dahdi_pvt *p, int x) |
| 4515 |
{ |
| 4516 |
if (!x) { |
| 4517 |
ast_log(LOG_WARNING, "Trying to unalloc the real channel %d?!?\n", p->channel); |
| 4518 |
return -1; |
| 4519 |
} |
| 4520 |
ast_debug(1, "Released sub %d of channel %d\n", x, p->channel); |
| 4521 |
dahdi_close_sub(p, x); |
| 4522 |
p->subs[x].linear = 0; |
| 4523 |
p->subs[x].chan = 0; |
| 4524 |
p->subs[x].owner = NULL; |
| 4525 |
p->subs[x].inthreeway = 0; |
| 4526 |
p->polarity = POLARITY_IDLE; |
| 4527 |
memset(&p->subs[x].curconf, 0, sizeof(p->subs[x].curconf)); |
| 4528 |
return 0; |
| 4529 |
} |
| 4530 |
|
| 4531 |
static int digit_to_dtmfindex(char digit) |
| 4532 |
{ |
| 4533 |
if (isdigit(digit)) |
| 4534 |
return DAHDI_TONE_DTMF_BASE + (digit - '0'); |
| 4535 |
else if (digit >= 'A' && digit <= 'D') |
| 4536 |
return DAHDI_TONE_DTMF_A + (digit - 'A'); |
| 4537 |
else if (digit >= 'a' && digit <= 'd') |
| 4538 |
return DAHDI_TONE_DTMF_A + (digit - 'a'); |
| 4539 |
else if (digit == '*') |
| 4540 |
return DAHDI_TONE_DTMF_s; |
| 4541 |
else if (digit == '#') |
| 4542 |
return DAHDI_TONE_DTMF_p; |
| 4543 |
else |
| 4544 |
return -1; |
| 4545 |
} |
| 4546 |
|
| 4547 |
static int dahdi_digit_begin(struct ast_channel *chan, char digit) |
| 4548 |
{ |
| 4549 |
struct dahdi_pvt *pvt; |
| 4550 |
int idx; |
| 4551 |
int dtmf; |
| 4552 |
int res; |
| 4553 |
|
| 4554 |
pvt = ast_channel_tech_pvt(chan); |
| 4555 |
|
| 4556 |
ast_mutex_lock(&pvt->lock); |
| 4557 |
|
| 4558 |
idx = dahdi_get_index(chan, pvt, 0); |
| 4559 |
|
| 4560 |
if ((idx != SUB_REAL) || !pvt->owner) |
| 4561 |
goto out; |
| 4562 |
|
| 4563 |
#ifdef HAVE_PRI |
| 4564 |
switch (pvt->sig) { |
| 4565 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 4566 |
res = sig_pri_digit_begin(pvt->sig_pvt, chan, digit); |
| 4567 |
if (!res) |
| 4568 |
goto out; |
| 4569 |
break; |
| 4570 |
default: |
| 4571 |
break; |
| 4572 |
} |
| 4573 |
#endif |
| 4574 |
dtmf = digit_to_dtmfindex(digit); |
| 4575 |
if (dtmf == -1) { |
| 4576 |
|
| 4577 |
goto out; |
| 4578 |
} |
| 4579 |
|
| 4580 |
if (pvt->pulse || ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_SENDTONE, &dtmf)) { |
| 4581 |
char dial_str[] = { 'T', digit, '\0' }; |
| 4582 |
|
| 4583 |
res = dahdi_dial_str(pvt, DAHDI_DIAL_OP_APPEND, dial_str); |
| 4584 |
if (!res) { |
| 4585 |
pvt->dialing = 1; |
| 4586 |
} |
| 4587 |
} else { |
| 4588 |
pvt->dialing = 1; |
| 4589 |
pvt->begindigit = digit; |
| 4590 |
|
| 4591 |
|
| 4592 |
dtmf = DAHDI_FLUSH_WRITE; |
| 4593 |
res = ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_FLUSH, &dtmf); |
| 4594 |
if (res) { |
| 4595 |
ast_log(LOG_WARNING, "Unable to flush the DAHDI write buffer to send DTMF on channel %d: %s\n", |
| 4596 |
pvt->channel, strerror(errno)); |
| 4597 |
} |
| 4598 |
|
| 4599 |
ast_debug(1, "Channel %s started VLDTMF digit '%c'\n", |
| 4600 |
ast_channel_name(chan), digit); |
| 4601 |
} |
| 4602 |
|
| 4603 |
out: |
| 4604 |
ast_mutex_unlock(&pvt->lock); |
| 4605 |
|
| 4606 |
return 0; |
| 4607 |
} |
| 4608 |
|
| 4609 |
static int dahdi_digit_end(struct ast_channel *chan, char digit, unsigned int duration) |
| 4610 |
{ |
| 4611 |
struct dahdi_pvt *pvt; |
| 4612 |
int res = 0; |
| 4613 |
int idx; |
| 4614 |
int x; |
| 4615 |
|
| 4616 |
pvt = ast_channel_tech_pvt(chan); |
| 4617 |
|
| 4618 |
ast_mutex_lock(&pvt->lock); |
| 4619 |
|
| 4620 |
idx = dahdi_get_index(chan, pvt, 0); |
| 4621 |
|
| 4622 |
if ((idx != SUB_REAL) || !pvt->owner || pvt->pulse) |
| 4623 |
goto out; |
| 4624 |
|
| 4625 |
#ifdef HAVE_PRI |
| 4626 |
|
| 4627 |
if (dahdi_sig_pri_lib_handles(pvt->sig) && !pvt->begindigit) { |
| 4628 |
goto out; |
| 4629 |
} |
| 4630 |
#endif |
| 4631 |
|
| 4632 |
if (pvt->begindigit) { |
| 4633 |
x = -1; |
| 4634 |
ast_debug(1, "Channel %s ending VLDTMF digit '%c'\n", |
| 4635 |
ast_channel_name(chan), digit); |
| 4636 |
res = ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_SENDTONE, &x); |
| 4637 |
pvt->dialing = 0; |
| 4638 |
pvt->begindigit = 0; |
| 4639 |
} |
| 4640 |
|
| 4641 |
out: |
| 4642 |
ast_mutex_unlock(&pvt->lock); |
| 4643 |
|
| 4644 |
return res; |
| 4645 |
} |
| 4646 |
|
| 4647 |
static const char * const events[] = { |
| 4648 |
"No event", |
| 4649 |
"On hook", |
| 4650 |
"Ring/Answered", |
| 4651 |
"Wink/Flash", |
| 4652 |
"Alarm", |
| 4653 |
"No more alarm", |
| 4654 |
"HDLC Abort", |
| 4655 |
"HDLC Overrun", |
| 4656 |
"HDLC Bad FCS", |
| 4657 |
"Dial Complete", |
| 4658 |
"Ringer On", |
| 4659 |
"Ringer Off", |
| 4660 |
"Hook Transition Complete", |
| 4661 |
"Bits Changed", |
| 4662 |
"Pulse Start", |
| 4663 |
"Timer Expired", |
| 4664 |
"Timer Ping", |
| 4665 |
"Polarity Reversal", |
| 4666 |
"Ring Begin", |
| 4667 |
}; |
| 4668 |
|
| 4669 |
static struct { |
| 4670 |
int alarm; |
| 4671 |
char *name; |
| 4672 |
} alarms[] = { |
| 4673 |
{ DAHDI_ALARM_RED, "Red Alarm" }, |
| 4674 |
{ DAHDI_ALARM_YELLOW, "Yellow Alarm" }, |
| 4675 |
{ DAHDI_ALARM_BLUE, "Blue Alarm" }, |
| 4676 |
{ DAHDI_ALARM_RECOVER, "Recovering" }, |
| 4677 |
{ DAHDI_ALARM_LOOPBACK, "Loopback" }, |
| 4678 |
{ DAHDI_ALARM_NOTOPEN, "Not Open" }, |
| 4679 |
{ DAHDI_ALARM_NONE, "None" }, |
| 4680 |
}; |
| 4681 |
|
| 4682 |
static char *alarm2str(int alm) |
| 4683 |
{ |
| 4684 |
int x; |
| 4685 |
for (x = 0; x < ARRAY_LEN(alarms); x++) { |
| 4686 |
if (alarms[x].alarm & alm) |
| 4687 |
return alarms[x].name; |
| 4688 |
} |
| 4689 |
return alm ? "Unknown Alarm" : "No Alarm"; |
| 4690 |
} |
| 4691 |
|
| 4692 |
static const char *event2str(int event) |
| 4693 |
{ |
| 4694 |
static char buf[256]; |
| 4695 |
if ((event > -1) && (event < (ARRAY_LEN(events))) ) |
| 4696 |
return events[event]; |
| 4697 |
sprintf(buf, "Event %d", event); |
| 4698 |
return buf; |
| 4699 |
} |
| 4700 |
|
| 4701 |
static char *dahdi_sig2str(int sig) |
| 4702 |
{ |
| 4703 |
static char buf[256]; |
| 4704 |
switch (sig) { |
| 4705 |
case SIG_EM: |
| 4706 |
return "E & M Immediate"; |
| 4707 |
case SIG_EMWINK: |
| 4708 |
return "E & M Wink"; |
| 4709 |
case SIG_EM_E1: |
| 4710 |
return "E & M E1"; |
| 4711 |
case SIG_FEATD: |
| 4712 |
return "Feature Group D (DTMF)"; |
| 4713 |
case SIG_FEATDMF: |
| 4714 |
return "Feature Group D (MF)"; |
| 4715 |
case SIG_FEATDMF_TA: |
| 4716 |
return "Feature Group D (MF) Tandem Access"; |
| 4717 |
case SIG_FEATB: |
| 4718 |
return "Feature Group B (MF)"; |
| 4719 |
case SIG_E911: |
| 4720 |
return "E911 (MF)"; |
| 4721 |
case SIG_FGC_CAMA: |
| 4722 |
return "FGC/CAMA (Dialpulse)"; |
| 4723 |
case SIG_FGC_CAMAMF: |
| 4724 |
return "FGC/CAMA (MF)"; |
| 4725 |
case SIG_FXSLS: |
| 4726 |
return "FXS Loopstart"; |
| 4727 |
case SIG_FXSGS: |
| 4728 |
return "FXS Groundstart"; |
| 4729 |
case SIG_FXSKS: |
| 4730 |
return "FXS Kewlstart"; |
| 4731 |
case SIG_FXOLS: |
| 4732 |
return "FXO Loopstart"; |
| 4733 |
case SIG_FXOGS: |
| 4734 |
return "FXO Groundstart"; |
| 4735 |
case SIG_FXOKS: |
| 4736 |
return "FXO Kewlstart"; |
| 4737 |
case SIG_PRI: |
| 4738 |
return "ISDN PRI"; |
| 4739 |
case SIG_BRI: |
| 4740 |
return "ISDN BRI Point to Point"; |
| 4741 |
case SIG_BRI_PTMP: |
| 4742 |
return "ISDN BRI Point to MultiPoint"; |
| 4743 |
case SIG_SS7: |
| 4744 |
return "SS7"; |
| 4745 |
case SIG_MFCR2: |
| 4746 |
return "MFC/R2"; |
| 4747 |
case SIG_SF: |
| 4748 |
return "SF (Tone) Immediate"; |
| 4749 |
case SIG_SFWINK: |
| 4750 |
return "SF (Tone) Wink"; |
| 4751 |
case SIG_SF_FEATD: |
| 4752 |
return "SF (Tone) with Feature Group D (DTMF)"; |
| 4753 |
case SIG_SF_FEATDMF: |
| 4754 |
return "SF (Tone) with Feature Group D (MF)"; |
| 4755 |
case SIG_SF_FEATB: |
| 4756 |
return "SF (Tone) with Feature Group B (MF)"; |
| 4757 |
case 0: |
| 4758 |
return "Pseudo"; |
| 4759 |
default: |
| 4760 |
snprintf(buf, sizeof(buf), "Unknown signalling %d", sig); |
| 4761 |
return buf; |
| 4762 |
} |
| 4763 |
} |
| 4764 |
|
| 4765 |
#define sig2str dahdi_sig2str |
| 4766 |
|
| 4767 |
static int conf_add(struct dahdi_pvt *p, struct dahdi_subchannel *c, int idx, int slavechannel) |
| 4768 |
{ |
| 4769 |
|
| 4770 |
|
| 4771 |
struct dahdi_confinfo zi; |
| 4772 |
|
| 4773 |
memset(&zi, 0, sizeof(zi)); |
| 4774 |
zi.chan = 0; |
| 4775 |
|
| 4776 |
if (slavechannel > 0) { |
| 4777 |
|
| 4778 |
zi.confmode = DAHDI_CONF_DIGITALMON; |
| 4779 |
zi.confno = slavechannel; |
| 4780 |
} else { |
| 4781 |
if (!idx) { |
| 4782 |
|
| 4783 |
zi.confmode = DAHDI_CONF_REALANDPSEUDO | DAHDI_CONF_TALKER | DAHDI_CONF_LISTENER | |
| 4784 |
DAHDI_CONF_PSEUDO_TALKER | DAHDI_CONF_PSEUDO_LISTENER; |
| 4785 |
} else |
| 4786 |
zi.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER | DAHDI_CONF_LISTENER; |
| 4787 |
zi.confno = p->confno; |
| 4788 |
} |
| 4789 |
if ((zi.confno == c->curconf.confno) && (zi.confmode == c->curconf.confmode)) |
| 4790 |
return 0; |
| 4791 |
if (c->dfd < 0) |
| 4792 |
return 0; |
| 4793 |
if (ioctl(c->dfd, DAHDI_SETCONF, &zi)) { |
| 4794 |
ast_log(LOG_WARNING, "Failed to add %d to conference %d/%d: %s\n", c->dfd, zi.confmode, zi.confno, strerror(errno)); |
| 4795 |
return -1; |
| 4796 |
} |
| 4797 |
if (slavechannel < 1) { |
| 4798 |
p->confno = zi.confno; |
| 4799 |
} |
| 4800 |
c->curconf = zi; |
| 4801 |
ast_debug(1, "Added %d to conference %d/%d\n", c->dfd, c->curconf.confmode, c->curconf.confno); |
| 4802 |
return 0; |
| 4803 |
} |
| 4804 |
|
| 4805 |
static int isourconf(struct dahdi_pvt *p, struct dahdi_subchannel *c) |
| 4806 |
{ |
| 4807 |
|
| 4808 |
if ((p->channel == c->curconf.confno) && (c->curconf.confmode == DAHDI_CONF_DIGITALMON)) |
| 4809 |
return 1; |
| 4810 |
|
| 4811 |
if ((p->confno > 0) && (p->confno == c->curconf.confno) && (c->curconf.confmode & DAHDI_CONF_TALKER)) |
| 4812 |
return 1; |
| 4813 |
return 0; |
| 4814 |
} |
| 4815 |
|
| 4816 |
static int conf_del(struct dahdi_pvt *p, struct dahdi_subchannel *c, int idx) |
| 4817 |
{ |
| 4818 |
struct dahdi_confinfo zi; |
| 4819 |
if ( |
| 4820 |
(c->dfd < 0) || |
| 4821 |
|
| 4822 |
!isourconf(p, c) |
| 4823 |
|
| 4824 |
) return 0; |
| 4825 |
memset(&zi, 0, sizeof(zi)); |
| 4826 |
if (ioctl(c->dfd, DAHDI_SETCONF, &zi)) { |
| 4827 |
ast_log(LOG_WARNING, "Failed to drop %d from conference %d/%d: %s\n", c->dfd, c->curconf.confmode, c->curconf.confno, strerror(errno)); |
| 4828 |
return -1; |
| 4829 |
} |
| 4830 |
ast_debug(1, "Removed %d from conference %d/%d\n", c->dfd, c->curconf.confmode, c->curconf.confno); |
| 4831 |
memcpy(&c->curconf, &zi, sizeof(c->curconf)); |
| 4832 |
return 0; |
| 4833 |
} |
| 4834 |
|
| 4835 |
static int isslavenative(struct dahdi_pvt *p, struct dahdi_pvt **out) |
| 4836 |
{ |
| 4837 |
int x; |
| 4838 |
int useslavenative; |
| 4839 |
struct dahdi_pvt *slave = NULL; |
| 4840 |
|
| 4841 |
useslavenative = 1; |
| 4842 |
|
| 4843 |
for (x = 0; x < 3; x++) { |
| 4844 |
|
| 4845 |
|
| 4846 |
if ((p->subs[x].dfd > -1) && p->subs[x].inthreeway) |
| 4847 |
useslavenative = 0; |
| 4848 |
} |
| 4849 |
|
| 4850 |
|
| 4851 |
if (useslavenative) { |
| 4852 |
for (x = 0; x < MAX_SLAVES; x++) { |
| 4853 |
if (p->slaves[x]) { |
| 4854 |
if (slave) { |
| 4855 |
|
| 4856 |
|
| 4857 |
slave = NULL; |
| 4858 |
useslavenative = 0; |
| 4859 |
break; |
| 4860 |
} else { |
| 4861 |
|
| 4862 |
slave = p->slaves[x]; |
| 4863 |
} |
| 4864 |
} |
| 4865 |
} |
| 4866 |
} |
| 4867 |
|
| 4868 |
if (!slave) |
| 4869 |
useslavenative = 0; |
| 4870 |
else if (slave->law != p->law) { |
| 4871 |
useslavenative = 0; |
| 4872 |
slave = NULL; |
| 4873 |
} |
| 4874 |
if (out) |
| 4875 |
*out = slave; |
| 4876 |
return useslavenative; |
| 4877 |
} |
| 4878 |
|
| 4879 |
static int reset_conf(struct dahdi_pvt *p) |
| 4880 |
{ |
| 4881 |
p->confno = -1; |
| 4882 |
memset(&p->subs[SUB_REAL].curconf, 0, sizeof(p->subs[SUB_REAL].curconf)); |
| 4883 |
if (p->subs[SUB_REAL].dfd > -1) { |
| 4884 |
struct dahdi_confinfo zi; |
| 4885 |
|
| 4886 |
memset(&zi, 0, sizeof(zi)); |
| 4887 |
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCONF, &zi)) |
| 4888 |
ast_log(LOG_WARNING, "Failed to reset conferencing on channel %d: %s\n", p->channel, strerror(errno)); |
| 4889 |
} |
| 4890 |
return 0; |
| 4891 |
} |
| 4892 |
|
| 4893 |
void dahdi_conf_update(struct dahdi_pvt *p) |
| 4894 |
{ |
| 4895 |
int needconf = 0; |
| 4896 |
int x; |
| 4897 |
int useslavenative; |
| 4898 |
struct dahdi_pvt *slave = NULL; |
| 4899 |
|
| 4900 |
useslavenative = isslavenative(p, &slave); |
| 4901 |
|
| 4902 |
for (x = 0; x < 3; x++) { |
| 4903 |
|
| 4904 |
if ((p->subs[x].dfd > -1) && p->subs[x].inthreeway) { |
| 4905 |
conf_add(p, &p->subs[x], x, 0); |
| 4906 |
needconf++; |
| 4907 |
} else { |
| 4908 |
conf_del(p, &p->subs[x], x); |
| 4909 |
} |
| 4910 |
} |
| 4911 |
|
| 4912 |
|
| 4913 |
for (x = 0; x < MAX_SLAVES; x++) { |
| 4914 |
if (p->slaves[x]) { |
| 4915 |
if (useslavenative) |
| 4916 |
conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p)); |
| 4917 |
else { |
| 4918 |
conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, 0); |
| 4919 |
needconf++; |
| 4920 |
} |
| 4921 |
} |
| 4922 |
} |
| 4923 |
|
| 4924 |
if (p->inconference && !p->subs[SUB_REAL].inthreeway) { |
| 4925 |
if (useslavenative) |
| 4926 |
conf_add(p, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(slave)); |
| 4927 |
else { |
| 4928 |
conf_add(p, &p->subs[SUB_REAL], SUB_REAL, 0); |
| 4929 |
needconf++; |
| 4930 |
} |
| 4931 |
} |
| 4932 |
|
| 4933 |
if (p->master) { |
| 4934 |
if (isslavenative(p->master, NULL)) { |
| 4935 |
conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p->master)); |
| 4936 |
} else { |
| 4937 |
conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, 0); |
| 4938 |
} |
| 4939 |
} |
| 4940 |
if (!needconf) { |
| 4941 |
|
| 4942 |
|
| 4943 |
p->confno = -1; |
| 4944 |
} |
| 4945 |
ast_debug(1, "Updated conferencing on %d, with %d conference users\n", p->channel, needconf); |
| 4946 |
} |
| 4947 |
|
| 4948 |
void dahdi_ec_enable(struct dahdi_pvt *p) |
| 4949 |
{ |
| 4950 |
int res; |
| 4951 |
if (!p) |
| 4952 |
return; |
| 4953 |
if (p->echocanon) { |
| 4954 |
ast_debug(1, "Echo cancellation already on\n"); |
| 4955 |
return; |
| 4956 |
} |
| 4957 |
if (p->digital) { |
| 4958 |
ast_debug(1, "Echo cancellation isn't required on digital connection\n"); |
| 4959 |
return; |
| 4960 |
} |
| 4961 |
if (p->echocancel.head.tap_length) { |
| 4962 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 4963 |
switch (p->sig) { |
| 4964 |
#if defined(HAVE_PRI) |
| 4965 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 4966 |
if (((struct sig_pri_chan *) p->sig_pvt)->no_b_channel) { |
| 4967 |
|
| 4968 |
|
| 4969 |
|
| 4970 |
|
| 4971 |
return; |
| 4972 |
} |
| 4973 |
|
| 4974 |
#endif |
| 4975 |
#if defined(HAVE_SS7) |
| 4976 |
case SIG_SS7: |
| 4977 |
#endif |
| 4978 |
{ |
| 4979 |
int x = 1; |
| 4980 |
|
| 4981 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &x); |
| 4982 |
if (res) |
| 4983 |
ast_log(LOG_WARNING, |
| 4984 |
"Unable to enable audio mode on channel %d (%s)\n", |
| 4985 |
p->channel, strerror(errno)); |
| 4986 |
} |
| 4987 |
break; |
| 4988 |
default: |
| 4989 |
break; |
| 4990 |
} |
| 4991 |
#endif |
| 4992 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_ECHOCANCEL_PARAMS, &p->echocancel); |
| 4993 |
if (res) { |
| 4994 |
ast_log(LOG_WARNING, "Unable to enable echo cancellation on channel %d (%s)\n", p->channel, strerror(errno)); |
| 4995 |
} else { |
| 4996 |
p->echocanon = 1; |
| 4997 |
ast_debug(1, "Enabled echo cancellation on channel %d\n", p->channel); |
| 4998 |
} |
| 4999 |
} else |
| 5000 |
ast_debug(1, "No echo cancellation requested\n"); |
| 5001 |
} |
| 5002 |
|
| 5003 |
static void dahdi_train_ec(struct dahdi_pvt *p) |
| 5004 |
{ |
| 5005 |
int x; |
| 5006 |
int res; |
| 5007 |
|
| 5008 |
if (p && p->echocanon && p->echotraining) { |
| 5009 |
x = p->echotraining; |
| 5010 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_ECHOTRAIN, &x); |
| 5011 |
if (res) |
| 5012 |
ast_log(LOG_WARNING, "Unable to request echo training on channel %d: %s\n", p->channel, strerror(errno)); |
| 5013 |
else |
| 5014 |
ast_debug(1, "Engaged echo training on channel %d\n", p->channel); |
| 5015 |
} else { |
| 5016 |
ast_debug(1, "No echo training requested\n"); |
| 5017 |
} |
| 5018 |
} |
| 5019 |
|
| 5020 |
void dahdi_ec_disable(struct dahdi_pvt *p) |
| 5021 |
{ |
| 5022 |
int res; |
| 5023 |
|
| 5024 |
if (p->echocanon) { |
| 5025 |
struct dahdi_echocanparams ecp = { .tap_length = 0 }; |
| 5026 |
|
| 5027 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_ECHOCANCEL_PARAMS, &ecp); |
| 5028 |
|
| 5029 |
if (res) |
| 5030 |
ast_log(LOG_WARNING, "Unable to disable echo cancellation on channel %d: %s\n", p->channel, strerror(errno)); |
| 5031 |
else |
| 5032 |
ast_debug(1, "Disabled echo cancellation on channel %d\n", p->channel); |
| 5033 |
} |
| 5034 |
|
| 5035 |
p->echocanon = 0; |
| 5036 |
} |
| 5037 |
|
| 5038 |
static int set_hwgain(int fd, float gain, int tx_direction) |
| 5039 |
{ |
| 5040 |
struct dahdi_hwgain hwgain; |
| 5041 |
|
| 5042 |
hwgain.newgain = gain * 10.0; |
| 5043 |
hwgain.tx = tx_direction; |
| 5044 |
return ioctl(fd, DAHDI_SET_HWGAIN, &hwgain) < 0; |
| 5045 |
} |
| 5046 |
|
| 5047 |
|
| 5048 |
static int drc_sample(int sample, float drc) |
| 5049 |
{ |
| 5050 |
float neg; |
| 5051 |
float shallow, steep; |
| 5052 |
float max = SHRT_MAX; |
| 5053 |
|
| 5054 |
neg = (sample < 0 ? -1 : 1); |
| 5055 |
steep = drc*sample; |
| 5056 |
shallow = neg*(max-max/drc)+(float)sample/drc; |
| 5057 |
if (fabsf(steep) < fabsf(shallow)) { |
| 5058 |
sample = steep; |
| 5059 |
} |
| 5060 |
else { |
| 5061 |
sample = shallow; |
| 5062 |
} |
| 5063 |
|
| 5064 |
return sample; |
| 5065 |
} |
| 5066 |
|
| 5067 |
|
| 5068 |
static void fill_txgain(struct dahdi_gains *g, float gain, float drc, int law) |
| 5069 |
{ |
| 5070 |
int j; |
| 5071 |
int k; |
| 5072 |
|
| 5073 |
float linear_gain = pow(10.0, gain / 20.0); |
| 5074 |
|
| 5075 |
switch (law) { |
| 5076 |
case DAHDI_LAW_ALAW: |
| 5077 |
for (j = 0; j < ARRAY_LEN(g->txgain); j++) { |
| 5078 |
if (gain || drc) { |
| 5079 |
k = AST_ALAW(j); |
| 5080 |
if (drc) { |
| 5081 |
k = drc_sample(k, drc); |
| 5082 |
} |
| 5083 |
k = (float)k * linear_gain; |
| 5084 |
if (k > 32767) { |
| 5085 |
k = 32767; |
| 5086 |
} else if (k < -32768) { |
| 5087 |
k = -32768; |
| 5088 |
} |
| 5089 |
g->txgain[j] = AST_LIN2A(k); |
| 5090 |
} else { |
| 5091 |
g->txgain[j] = j; |
| 5092 |
} |
| 5093 |
} |
| 5094 |
break; |
| 5095 |
case DAHDI_LAW_MULAW: |
| 5096 |
for (j = 0; j < ARRAY_LEN(g->txgain); j++) { |
| 5097 |
if (gain || drc) { |
| 5098 |
k = AST_MULAW(j); |
| 5099 |
if (drc) { |
| 5100 |
k = drc_sample(k, drc); |
| 5101 |
} |
| 5102 |
k = (float)k * linear_gain; |
| 5103 |
if (k > 32767) { |
| 5104 |
k = 32767; |
| 5105 |
} else if (k < -32768) { |
| 5106 |
k = -32768; |
| 5107 |
} |
| 5108 |
g->txgain[j] = AST_LIN2MU(k); |
| 5109 |
|
| 5110 |
} else { |
| 5111 |
g->txgain[j] = j; |
| 5112 |
} |
| 5113 |
} |
| 5114 |
break; |
| 5115 |
} |
| 5116 |
} |
| 5117 |
|
| 5118 |
static void fill_rxgain(struct dahdi_gains *g, float gain, float drc, int law) |
| 5119 |
{ |
| 5120 |
int j; |
| 5121 |
int k; |
| 5122 |
float linear_gain = pow(10.0, gain / 20.0); |
| 5123 |
|
| 5124 |
switch (law) { |
| 5125 |
case DAHDI_LAW_ALAW: |
| 5126 |
for (j = 0; j < ARRAY_LEN(g->rxgain); j++) { |
| 5127 |
if (gain || drc) { |
| 5128 |
k = AST_ALAW(j); |
| 5129 |
if (drc) { |
| 5130 |
k = drc_sample(k, drc); |
| 5131 |
} |
| 5132 |
k = (float)k * linear_gain; |
| 5133 |
if (k > 32767) { |
| 5134 |
k = 32767; |
| 5135 |
} else if (k < -32768) { |
| 5136 |
k = -32768; |
| 5137 |
} |
| 5138 |
g->rxgain[j] = AST_LIN2A(k); |
| 5139 |
} else { |
| 5140 |
g->rxgain[j] = j; |
| 5141 |
} |
| 5142 |
} |
| 5143 |
break; |
| 5144 |
case DAHDI_LAW_MULAW: |
| 5145 |
for (j = 0; j < ARRAY_LEN(g->rxgain); j++) { |
| 5146 |
if (gain || drc) { |
| 5147 |
k = AST_MULAW(j); |
| 5148 |
if (drc) { |
| 5149 |
k = drc_sample(k, drc); |
| 5150 |
} |
| 5151 |
k = (float)k * linear_gain; |
| 5152 |
if (k > 32767) { |
| 5153 |
k = 32767; |
| 5154 |
} else if (k < -32768) { |
| 5155 |
k = -32768; |
| 5156 |
} |
| 5157 |
g->rxgain[j] = AST_LIN2MU(k); |
| 5158 |
} else { |
| 5159 |
g->rxgain[j] = j; |
| 5160 |
} |
| 5161 |
} |
| 5162 |
break; |
| 5163 |
} |
| 5164 |
} |
| 5165 |
|
| 5166 |
static int set_actual_txgain(int fd, float gain, float drc, int law) |
| 5167 |
{ |
| 5168 |
struct dahdi_gains g; |
| 5169 |
int res; |
| 5170 |
|
| 5171 |
memset(&g, 0, sizeof(g)); |
| 5172 |
res = ioctl(fd, DAHDI_GETGAINS, &g); |
| 5173 |
if (res) { |
| 5174 |
ast_debug(1, "Failed to read gains: %s\n", strerror(errno)); |
| 5175 |
return res; |
| 5176 |
} |
| 5177 |
|
| 5178 |
fill_txgain(&g, gain, drc, law); |
| 5179 |
|
| 5180 |
return ioctl(fd, DAHDI_SETGAINS, &g); |
| 5181 |
} |
| 5182 |
|
| 5183 |
static int set_actual_rxgain(int fd, float gain, float drc, int law) |
| 5184 |
{ |
| 5185 |
struct dahdi_gains g; |
| 5186 |
int res; |
| 5187 |
|
| 5188 |
memset(&g, 0, sizeof(g)); |
| 5189 |
res = ioctl(fd, DAHDI_GETGAINS, &g); |
| 5190 |
if (res) { |
| 5191 |
ast_debug(1, "Failed to read gains: %s\n", strerror(errno)); |
| 5192 |
return res; |
| 5193 |
} |
| 5194 |
|
| 5195 |
fill_rxgain(&g, gain, drc, law); |
| 5196 |
|
| 5197 |
return ioctl(fd, DAHDI_SETGAINS, &g); |
| 5198 |
} |
| 5199 |
|
| 5200 |
static int set_actual_gain(int fd, float rxgain, float txgain, float rxdrc, float txdrc, int law) |
| 5201 |
{ |
| 5202 |
return set_actual_txgain(fd, txgain, txdrc, law) | set_actual_rxgain(fd, rxgain, rxdrc, law); |
| 5203 |
} |
| 5204 |
|
| 5205 |
static int bump_gains(struct dahdi_pvt *p) |
| 5206 |
{ |
| 5207 |
int res; |
| 5208 |
|
| 5209 |
|
| 5210 |
res = set_actual_gain(p->subs[SUB_REAL].dfd, p->rxgain + p->cid_rxgain, p->txgain, p->rxdrc, p->txdrc, p->law); |
| 5211 |
if (res) { |
| 5212 |
ast_log(LOG_WARNING, "Unable to bump gain: %s\n", strerror(errno)); |
| 5213 |
return -1; |
| 5214 |
} |
| 5215 |
|
| 5216 |
return 0; |
| 5217 |
} |
| 5218 |
|
| 5219 |
static int restore_gains(struct dahdi_pvt *p) |
| 5220 |
{ |
| 5221 |
int res; |
| 5222 |
|
| 5223 |
res = set_actual_gain(p->subs[SUB_REAL].dfd, p->rxgain, p->txgain, p->rxdrc, p->txdrc, p->law); |
| 5224 |
if (res) { |
| 5225 |
ast_log(LOG_WARNING, "Unable to restore gains: %s\n", strerror(errno)); |
| 5226 |
return -1; |
| 5227 |
} |
| 5228 |
|
| 5229 |
return 0; |
| 5230 |
} |
| 5231 |
|
| 5232 |
static inline int dahdi_set_hook(int fd, int hs) |
| 5233 |
{ |
| 5234 |
int x, res; |
| 5235 |
|
| 5236 |
x = hs; |
| 5237 |
res = ioctl(fd, DAHDI_HOOK, &x); |
| 5238 |
|
| 5239 |
if (res < 0) { |
| 5240 |
if (errno == EINPROGRESS) |
| 5241 |
return 0; |
| 5242 |
ast_log(LOG_WARNING, "DAHDI hook failed returned %d (trying %d): %s\n", res, hs, strerror(errno)); |
| 5243 |
|
| 5244 |
} |
| 5245 |
|
| 5246 |
return res; |
| 5247 |
} |
| 5248 |
|
| 5249 |
static inline int dahdi_confmute(struct dahdi_pvt *p, int muted) |
| 5250 |
{ |
| 5251 |
int x, res; |
| 5252 |
|
| 5253 |
x = muted; |
| 5254 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 5255 |
switch (p->sig) { |
| 5256 |
#if defined(HAVE_PRI) |
| 5257 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 5258 |
if (((struct sig_pri_chan *) p->sig_pvt)->no_b_channel) { |
| 5259 |
|
| 5260 |
break; |
| 5261 |
} |
| 5262 |
|
| 5263 |
#endif |
| 5264 |
#if defined(HAVE_SS7) |
| 5265 |
case SIG_SS7: |
| 5266 |
#endif |
| 5267 |
{ |
| 5268 |
int y = 1; |
| 5269 |
|
| 5270 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &y); |
| 5271 |
if (res) |
| 5272 |
ast_log(LOG_WARNING, "Unable to set audio mode on %d: %s\n", |
| 5273 |
p->channel, strerror(errno)); |
| 5274 |
} |
| 5275 |
break; |
| 5276 |
default: |
| 5277 |
break; |
| 5278 |
} |
| 5279 |
#endif |
| 5280 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_CONFMUTE, &x); |
| 5281 |
if (res < 0) |
| 5282 |
ast_log(LOG_WARNING, "DAHDI confmute(%d) failed on channel %d: %s\n", muted, p->channel, strerror(errno)); |
| 5283 |
return res; |
| 5284 |
} |
| 5285 |
|
| 5286 |
static int save_conference(struct dahdi_pvt *p) |
| 5287 |
{ |
| 5288 |
struct dahdi_confinfo c; |
| 5289 |
int res; |
| 5290 |
if (p->saveconf.confmode) { |
| 5291 |
ast_log(LOG_WARNING, "Can't save conference -- already in use\n"); |
| 5292 |
return -1; |
| 5293 |
} |
| 5294 |
p->saveconf.chan = 0; |
| 5295 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GETCONF, &p->saveconf); |
| 5296 |
if (res) { |
| 5297 |
ast_log(LOG_WARNING, "Unable to get conference info: %s\n", strerror(errno)); |
| 5298 |
p->saveconf.confmode = 0; |
| 5299 |
return -1; |
| 5300 |
} |
| 5301 |
memset(&c, 0, sizeof(c)); |
| 5302 |
c.confmode = DAHDI_CONF_NORMAL; |
| 5303 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCONF, &c); |
| 5304 |
if (res) { |
| 5305 |
ast_log(LOG_WARNING, "Unable to set conference info: %s\n", strerror(errno)); |
| 5306 |
return -1; |
| 5307 |
} |
| 5308 |
ast_debug(1, "Disabled conferencing\n"); |
| 5309 |
return 0; |
| 5310 |
} |
| 5311 |
|
| 5312 |
static int restore_conference(struct dahdi_pvt *p) |
| 5313 |
{ |
| 5314 |
int res; |
| 5315 |
if (p->saveconf.confmode) { |
| 5316 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCONF, &p->saveconf); |
| 5317 |
p->saveconf.confmode = 0; |
| 5318 |
if (res) { |
| 5319 |
ast_log(LOG_WARNING, "Unable to restore conference info: %s\n", strerror(errno)); |
| 5320 |
return -1; |
| 5321 |
} |
| 5322 |
ast_debug(1, "Restored conferencing\n"); |
| 5323 |
} |
| 5324 |
return 0; |
| 5325 |
} |
| 5326 |
|
| 5327 |
static int send_cwcidspill(struct dahdi_pvt *p) |
| 5328 |
{ |
| 5329 |
p->callwaitcas = 0; |
| 5330 |
p->cidcwexpire = 0; |
| 5331 |
p->cid_suppress_expire = 0; |
| 5332 |
if (!(p->cidspill = ast_malloc(MAX_CALLERID_SIZE))) |
| 5333 |
return -1; |
| 5334 |
p->cidlen = ast_callerid_callwaiting_generate(p->cidspill, p->callwait_name, p->callwait_num, AST_LAW(p)); |
| 5335 |
|
| 5336 |
p->cidlen += READ_SIZE * 4; |
| 5337 |
p->cidpos = 0; |
| 5338 |
send_callerid(p); |
| 5339 |
ast_verb(3, "CPE supports Call Waiting Caller*ID. Sending '%s/%s'\n", p->callwait_name, p->callwait_num); |
| 5340 |
return 0; |
| 5341 |
} |
| 5342 |
|
| 5343 |
static int has_voicemail(struct dahdi_pvt *p) |
| 5344 |
{ |
| 5345 |
int new_msgs; |
| 5346 |
RAII_VAR(struct stasis_message *, mwi_message, NULL, ao2_cleanup); |
| 5347 |
|
| 5348 |
|
| 5349 |
|
| 5350 |
if (p->mwioverride_active) { |
| 5351 |
|
| 5352 |
|
| 5353 |
|
| 5354 |
|
| 5355 |
ast_debug(6, "MWI manual override active on channel %d: pretending that it should be %s\n", |
| 5356 |
p->channel, p->mwioverride_disposition ? "active" : "inactive"); |
| 5357 |
return p->mwioverride_disposition; |
| 5358 |
} |
| 5359 |
|
| 5360 |
mwi_message = stasis_cache_get(ast_mwi_state_cache(), ast_mwi_state_type(), p->mailbox); |
| 5361 |
if (mwi_message) { |
| 5362 |
struct ast_mwi_state *mwi_state = stasis_message_data(mwi_message); |
| 5363 |
new_msgs = mwi_state->new_msgs; |
| 5364 |
} else { |
| 5365 |
new_msgs = ast_app_has_voicemail(p->mailbox, NULL); |
| 5366 |
} |
| 5367 |
|
| 5368 |
return new_msgs; |
| 5369 |
} |
| 5370 |
|
| 5371 |
|
| 5372 |
|
| 5373 |
static int send_callerid(struct dahdi_pvt *p) |
| 5374 |
{ |
| 5375 |
|
| 5376 |
int res; |
| 5377 |
|
| 5378 |
if (p->subs[SUB_REAL].linear) { |
| 5379 |
p->subs[SUB_REAL].linear = 0; |
| 5380 |
dahdi_setlinear(p->subs[SUB_REAL].dfd, 0); |
| 5381 |
} |
| 5382 |
while (p->cidpos < p->cidlen) { |
| 5383 |
res = write(p->subs[SUB_REAL].dfd, p->cidspill + p->cidpos, p->cidlen - p->cidpos); |
| 5384 |
ast_debug(4, "writing callerid at pos %d of %d, res = %d\n", p->cidpos, p->cidlen, res); |
| 5385 |
if (res < 0) { |
| 5386 |
if (errno == EAGAIN) |
| 5387 |
return 0; |
| 5388 |
else { |
| 5389 |
ast_log(LOG_WARNING, "write failed: %s\n", strerror(errno)); |
| 5390 |
return -1; |
| 5391 |
} |
| 5392 |
} |
| 5393 |
if (!res) |
| 5394 |
return 0; |
| 5395 |
p->cidpos += res; |
| 5396 |
} |
| 5397 |
p->cid_suppress_expire = CALLWAITING_SUPPRESS_SAMPLES; |
| 5398 |
ast_free(p->cidspill); |
| 5399 |
p->cidspill = NULL; |
| 5400 |
if (p->callwaitcas) { |
| 5401 |
|
| 5402 |
p->cidcwexpire = CIDCW_EXPIRE_SAMPLES; |
| 5403 |
p->cid_suppress_expire = p->cidcwexpire; |
| 5404 |
} else |
| 5405 |
restore_conference(p); |
| 5406 |
return 0; |
| 5407 |
} |
| 5408 |
|
| 5409 |
static int dahdi_callwait(struct ast_channel *ast) |
| 5410 |
{ |
| 5411 |
struct dahdi_pvt *p = ast_channel_tech_pvt(ast); |
| 5412 |
|
| 5413 |
p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES; |
| 5414 |
if (p->cidspill) { |
| 5415 |
ast_log(LOG_WARNING, "Spill already exists?!?\n"); |
| 5416 |
ast_free(p->cidspill); |
| 5417 |
} |
| 5418 |
|
| 5419 |
|
| 5420 |
|
| 5421 |
|
| 5422 |
|
| 5423 |
if (!(p->cidspill = ast_malloc(2400 + 680 + READ_SIZE * 4))) |
| 5424 |
return -1; |
| 5425 |
save_conference(p); |
| 5426 |
|
| 5427 |
memset(p->cidspill, 0x7f, 2400 + 600 + READ_SIZE * 4); |
| 5428 |
if (!p->callwaitrings && p->callwaitingcallerid) { |
| 5429 |
ast_gen_cas(p->cidspill, 1, 2400 + 680, AST_LAW(p)); |
| 5430 |
p->callwaitcas = 1; |
| 5431 |
p->cidlen = 2400 + 680 + READ_SIZE * 4; |
| 5432 |
} else { |
| 5433 |
ast_gen_cas(p->cidspill, 1, 2400, AST_LAW(p)); |
| 5434 |
p->callwaitcas = 0; |
| 5435 |
p->cidlen = 2400 + READ_SIZE * 4; |
| 5436 |
} |
| 5437 |
p->cidpos = 0; |
| 5438 |
send_callerid(p); |
| 5439 |
|
| 5440 |
return 0; |
| 5441 |
} |
| 5442 |
|
| 5443 |
static int dahdi_call(struct ast_channel *ast, const char *rdest, int timeout) |
| 5444 |
{ |
| 5445 |
struct dahdi_pvt *p = ast_channel_tech_pvt(ast); |
| 5446 |
int x, res, mysig; |
| 5447 |
char *dest; |
| 5448 |
AST_DECLARE_APP_ARGS(args, |
| 5449 |
AST_APP_ARG(group); |
| 5450 |
AST_APP_ARG(ext); |
| 5451 |
|
| 5452 |
AST_APP_ARG(other); |
| 5453 |
); |
| 5454 |
|
| 5455 |
ast_mutex_lock(&p->lock); |
| 5456 |
ast_copy_string(p->dialdest, rdest, sizeof(p->dialdest)); |
| 5457 |
|
| 5458 |
|
| 5459 |
dest = ast_strdupa(rdest); |
| 5460 |
AST_NONSTANDARD_APP_ARGS(args, dest, '/'); |
| 5461 |
if (!args.ext) { |
| 5462 |
args.ext = ""; |
| 5463 |
} |
| 5464 |
|
| 5465 |
#if defined(HAVE_PRI) |
| 5466 |
if (dahdi_sig_pri_lib_handles(p->sig)) { |
| 5467 |
char *subaddr; |
| 5468 |
|
| 5469 |
sig_pri_extract_called_num_subaddr(p->sig_pvt, rdest, p->exten, sizeof(p->exten)); |
| 5470 |
|
| 5471 |
|
| 5472 |
subaddr = strchr(p->exten, ':'); |
| 5473 |
if (subaddr) { |
| 5474 |
*subaddr = '\0'; |
| 5475 |
} |
| 5476 |
} else |
| 5477 |
#endif |
| 5478 |
{ |
| 5479 |
ast_copy_string(p->exten, args.ext, sizeof(p->exten)); |
| 5480 |
} |
| 5481 |
|
| 5482 |
if ((ast_channel_state(ast) == AST_STATE_BUSY)) { |
| 5483 |
p->subs[SUB_REAL].needbusy = 1; |
| 5484 |
ast_mutex_unlock(&p->lock); |
| 5485 |
return 0; |
| 5486 |
} |
| 5487 |
if ((ast_channel_state(ast) != AST_STATE_DOWN) && (ast_channel_state(ast) != AST_STATE_RESERVED)) { |
| 5488 |
ast_log(LOG_WARNING, "dahdi_call called on %s, neither down nor reserved\n", ast_channel_name(ast)); |
| 5489 |
ast_mutex_unlock(&p->lock); |
| 5490 |
return -1; |
| 5491 |
} |
| 5492 |
p->waitingfordt.tv_sec = 0; |
| 5493 |
p->dialednone = 0; |
| 5494 |
if ((p->radio || (p->oprmode < 0))) |
| 5495 |
{ |
| 5496 |
|
| 5497 |
ast_setstate(ast, AST_STATE_UP); |
| 5498 |
ast_mutex_unlock(&p->lock); |
| 5499 |
return 0; |
| 5500 |
} |
| 5501 |
x = DAHDI_FLUSH_READ | DAHDI_FLUSH_WRITE; |
| 5502 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_FLUSH, &x); |
| 5503 |
if (res) |
| 5504 |
ast_log(LOG_WARNING, "Unable to flush input on channel %d: %s\n", p->channel, strerror(errno)); |
| 5505 |
p->outgoing = 1; |
| 5506 |
|
| 5507 |
if (IS_DIGITAL(ast_channel_transfercapability(ast))){ |
| 5508 |
set_actual_gain(p->subs[SUB_REAL].dfd, 0, 0, p->rxdrc, p->txdrc, p->law); |
| 5509 |
} else { |
| 5510 |
set_actual_gain(p->subs[SUB_REAL].dfd, p->rxgain, p->txgain, p->rxdrc, p->txdrc, p->law); |
| 5511 |
} |
| 5512 |
|
| 5513 |
#ifdef HAVE_PRI |
| 5514 |
if (dahdi_sig_pri_lib_handles(p->sig)) { |
| 5515 |
res = sig_pri_call(p->sig_pvt, ast, rdest, timeout, |
| 5516 |
(p->law == DAHDI_LAW_ALAW) ? PRI_LAYER_1_ALAW : PRI_LAYER_1_ULAW); |
| 5517 |
ast_mutex_unlock(&p->lock); |
| 5518 |
return res; |
| 5519 |
} |
| 5520 |
#endif |
| 5521 |
|
| 5522 |
#if defined(HAVE_SS7) |
| 5523 |
if (p->sig == SIG_SS7) { |
| 5524 |
res = sig_ss7_call(p->sig_pvt, ast, rdest); |
| 5525 |
ast_mutex_unlock(&p->lock); |
| 5526 |
return res; |
| 5527 |
} |
| 5528 |
#endif |
| 5529 |
|
| 5530 |
|
| 5531 |
if (dahdi_analog_lib_handles(p->sig, p->radio, p->oprmode)) { |
| 5532 |
p->callwaitrings = 0; |
| 5533 |
res = analog_call(p->sig_pvt, ast, rdest, timeout); |
| 5534 |
ast_mutex_unlock(&p->lock); |
| 5535 |
return res; |
| 5536 |
} |
| 5537 |
|
| 5538 |
mysig = p->outsigmod > -1 ? p->outsigmod : p->sig; |
| 5539 |
switch (mysig) { |
| 5540 |
case 0: |
| 5541 |
|
| 5542 |
ast_setstate(ast, AST_STATE_UP); |
| 5543 |
break; |
| 5544 |
case SIG_MFCR2: |
| 5545 |
break; |
| 5546 |
default: |
| 5547 |
ast_debug(1, "not yet implemented\n"); |
| 5548 |
ast_mutex_unlock(&p->lock); |
| 5549 |
return -1; |
| 5550 |
} |
| 5551 |
|
| 5552 |
#ifdef HAVE_OPENR2 |
| 5553 |
if (p->mfcr2) { |
| 5554 |
openr2_calling_party_category_t chancat; |
| 5555 |
int callres = 0; |
| 5556 |
char *c, *l; |
| 5557 |
|
| 5558 |
|
| 5559 |
p->dialdest[0] = '\0'; |
| 5560 |
|
| 5561 |
c = args.ext; |
| 5562 |
if (!p->hidecallerid) { |
| 5563 |
l = ast_channel_connected(ast)->id.number.valid ? ast_channel_connected(ast)->id.number.str : NULL; |
| 5564 |
} else { |
| 5565 |
l = NULL; |
| 5566 |
} |
| 5567 |
if (strlen(c) < p->stripmsd) { |
| 5568 |
ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd); |
| 5569 |
ast_mutex_unlock(&p->lock); |
| 5570 |
return -1; |
| 5571 |
} |
| 5572 |
p->dialing = 1; |
| 5573 |
chancat = dahdi_r2_get_channel_category(ast); |
| 5574 |
callres = openr2_chan_make_call(p->r2chan, l, (c + p->stripmsd), chancat); |
| 5575 |
if (-1 == callres) { |
| 5576 |
ast_mutex_unlock(&p->lock); |
| 5577 |
ast_log(LOG_ERROR, "unable to make new MFC/R2 call!\n"); |
| 5578 |
return -1; |
| 5579 |
} |
| 5580 |
p->mfcr2_call_accepted = 0; |
| 5581 |
p->mfcr2_progress_sent = 0; |
| 5582 |
ast_setstate(ast, AST_STATE_DIALING); |
| 5583 |
} |
| 5584 |
#endif |
| 5585 |
ast_mutex_unlock(&p->lock); |
| 5586 |
return 0; |
| 5587 |
} |
| 5588 |
|
| 5589 |
|
| 5590 |
|
| 5591 |
|
| 5592 |
|
| 5593 |
|
| 5594 |
|
| 5595 |
|
| 5596 |
|
| 5597 |
|
| 5598 |
|
| 5599 |
|
| 5600 |
|
| 5601 |
|
| 5602 |
static void dahdi_iflist_insert(struct dahdi_pvt *pvt) |
| 5603 |
{ |
| 5604 |
struct dahdi_pvt *cur; |
| 5605 |
|
| 5606 |
pvt->which_iflist = DAHDI_IFLIST_MAIN; |
| 5607 |
|
| 5608 |
|
| 5609 |
for (cur = iflist; cur; cur = cur->next) { |
| 5610 |
if (pvt->channel < cur->channel) { |
| 5611 |
|
| 5612 |
pvt->prev = cur->prev; |
| 5613 |
pvt->next = cur; |
| 5614 |
if (cur->prev) { |
| 5615 |
|
| 5616 |
cur->prev->next = pvt; |
| 5617 |
} else { |
| 5618 |
|
| 5619 |
iflist = pvt; |
| 5620 |
} |
| 5621 |
cur->prev = pvt; |
| 5622 |
return; |
| 5623 |
} |
| 5624 |
} |
| 5625 |
|
| 5626 |
|
| 5627 |
pvt->prev = ifend; |
| 5628 |
pvt->next = NULL; |
| 5629 |
if (ifend) { |
| 5630 |
ifend->next = pvt; |
| 5631 |
} |
| 5632 |
ifend = pvt; |
| 5633 |
if (!iflist) { |
| 5634 |
|
| 5635 |
iflist = pvt; |
| 5636 |
} |
| 5637 |
} |
| 5638 |
|
| 5639 |
|
| 5640 |
|
| 5641 |
|
| 5642 |
|
| 5643 |
|
| 5644 |
|
| 5645 |
|
| 5646 |
|
| 5647 |
|
| 5648 |
|
| 5649 |
|
| 5650 |
static void dahdi_iflist_extract(struct dahdi_pvt *pvt) |
| 5651 |
{ |
| 5652 |
|
| 5653 |
if (pvt->prev) { |
| 5654 |
pvt->prev->next = pvt->next; |
| 5655 |
} else if (iflist == pvt) { |
| 5656 |
|
| 5657 |
iflist = pvt->next; |
| 5658 |
} |
| 5659 |
|
| 5660 |
|
| 5661 |
if (pvt->next) { |
| 5662 |
pvt->next->prev = pvt->prev; |
| 5663 |
} else if (ifend == pvt) { |
| 5664 |
|
| 5665 |
ifend = pvt->prev; |
| 5666 |
} |
| 5667 |
|
| 5668 |
|
| 5669 |
pvt->which_iflist = DAHDI_IFLIST_NONE; |
| 5670 |
pvt->prev = NULL; |
| 5671 |
pvt->next = NULL; |
| 5672 |
} |
| 5673 |
|
| 5674 |
#if defined(HAVE_PRI) |
| 5675 |
|
| 5676 |
|
| 5677 |
|
| 5678 |
|
| 5679 |
|
| 5680 |
|
| 5681 |
|
| 5682 |
|
| 5683 |
|
| 5684 |
|
| 5685 |
|
| 5686 |
|
| 5687 |
|
| 5688 |
|
| 5689 |
static void dahdi_nobch_insert(struct sig_pri_span *pri, struct dahdi_pvt *pvt) |
| 5690 |
{ |
| 5691 |
struct dahdi_pvt *cur; |
| 5692 |
|
| 5693 |
pvt->which_iflist = DAHDI_IFLIST_NO_B_CHAN; |
| 5694 |
|
| 5695 |
|
| 5696 |
for (cur = pri->no_b_chan_iflist; cur; cur = cur->next) { |
| 5697 |
if (pvt->channel < cur->channel) { |
| 5698 |
|
| 5699 |
pvt->prev = cur->prev; |
| 5700 |
pvt->next = cur; |
| 5701 |
if (cur->prev) { |
| 5702 |
|
| 5703 |
cur->prev->next = pvt; |
| 5704 |
} else { |
| 5705 |
|
| 5706 |
pri->no_b_chan_iflist = pvt; |
| 5707 |
} |
| 5708 |
cur->prev = pvt; |
| 5709 |
return; |
| 5710 |
} |
| 5711 |
} |
| 5712 |
|
| 5713 |
|
| 5714 |
pvt->prev = pri->no_b_chan_end; |
| 5715 |
pvt->next = NULL; |
| 5716 |
if (pri->no_b_chan_end) { |
| 5717 |
((struct dahdi_pvt *) pri->no_b_chan_end)->next = pvt; |
| 5718 |
} |
| 5719 |
pri->no_b_chan_end = pvt; |
| 5720 |
if (!pri->no_b_chan_iflist) { |
| 5721 |
|
| 5722 |
pri->no_b_chan_iflist = pvt; |
| 5723 |
} |
| 5724 |
} |
| 5725 |
#endif |
| 5726 |
|
| 5727 |
#if defined(HAVE_PRI) |
| 5728 |
|
| 5729 |
|
| 5730 |
|
| 5731 |
|
| 5732 |
|
| 5733 |
|
| 5734 |
|
| 5735 |
|
| 5736 |
|
| 5737 |
|
| 5738 |
|
| 5739 |
|
| 5740 |
static void dahdi_nobch_extract(struct sig_pri_span *pri, struct dahdi_pvt *pvt) |
| 5741 |
{ |
| 5742 |
|
| 5743 |
if (pvt->prev) { |
| 5744 |
pvt->prev->next = pvt->next; |
| 5745 |
} else if (pri->no_b_chan_iflist == pvt) { |
| 5746 |
|
| 5747 |
pri->no_b_chan_iflist = pvt->next; |
| 5748 |
} |
| 5749 |
|
| 5750 |
|
| 5751 |
if (pvt->next) { |
| 5752 |
pvt->next->prev = pvt->prev; |
| 5753 |
} else if (pri->no_b_chan_end == pvt) { |
| 5754 |
|
| 5755 |
pri->no_b_chan_end = pvt->prev; |
| 5756 |
} |
| 5757 |
|
| 5758 |
|
| 5759 |
pvt->which_iflist = DAHDI_IFLIST_NONE; |
| 5760 |
pvt->prev = NULL; |
| 5761 |
pvt->next = NULL; |
| 5762 |
} |
| 5763 |
#endif |
| 5764 |
|
| 5765 |
#if defined(HAVE_PRI) |
| 5766 |
|
| 5767 |
|
| 5768 |
|
| 5769 |
|
| 5770 |
|
| 5771 |
|
| 5772 |
|
| 5773 |
static void dahdi_unlink_pri_pvt(struct dahdi_pvt *pvt) |
| 5774 |
{ |
| 5775 |
unsigned idx; |
| 5776 |
struct sig_pri_span *pri; |
| 5777 |
|
| 5778 |
pri = pvt->pri; |
| 5779 |
if (!pri) { |
| 5780 |
|
| 5781 |
return; |
| 5782 |
} |
| 5783 |
ast_mutex_lock(&pri->lock); |
| 5784 |
for (idx = 0; idx < pri->numchans; ++idx) { |
| 5785 |
if (pri->pvts[idx] == pvt->sig_pvt) { |
| 5786 |
pri->pvts[idx] = NULL; |
| 5787 |
ast_mutex_unlock(&pri->lock); |
| 5788 |
return; |
| 5789 |
} |
| 5790 |
} |
| 5791 |
ast_mutex_unlock(&pri->lock); |
| 5792 |
} |
| 5793 |
#endif |
| 5794 |
|
| 5795 |
#if defined(HAVE_SS7) |
| 5796 |
|
| 5797 |
|
| 5798 |
|
| 5799 |
|
| 5800 |
|
| 5801 |
|
| 5802 |
|
| 5803 |
static void dahdi_unlink_ss7_pvt(struct dahdi_pvt *pvt) |
| 5804 |
{ |
| 5805 |
unsigned idx; |
| 5806 |
struct sig_ss7_linkset *ss7; |
| 5807 |
|
| 5808 |
ss7 = pvt->ss7; |
| 5809 |
if (!ss7) { |
| 5810 |
|
| 5811 |
return; |
| 5812 |
} |
| 5813 |
ast_mutex_lock(&ss7->lock); |
| 5814 |
for (idx = 0; idx < ss7->numchans; ++idx) { |
| 5815 |
if (ss7->pvts[idx] == pvt->sig_pvt) { |
| 5816 |
ss7->pvts[idx] = NULL; |
| 5817 |
ast_mutex_unlock(&ss7->lock); |
| 5818 |
return; |
| 5819 |
} |
| 5820 |
} |
| 5821 |
ast_mutex_unlock(&ss7->lock); |
| 5822 |
} |
| 5823 |
#endif |
| 5824 |
|
| 5825 |
#if defined(HAVE_OPENR2) |
| 5826 |
|
| 5827 |
|
| 5828 |
|
| 5829 |
|
| 5830 |
|
| 5831 |
|
| 5832 |
static void dahdi_unlink_mfcr2_pvt(struct dahdi_pvt *pvt) |
| 5833 |
{ |
| 5834 |
unsigned idx; |
| 5835 |
struct dahdi_mfcr2 *mfcr2; |
| 5836 |
int should_destroy_link = 0; |
| 5837 |
|
| 5838 |
ast_mutex_lock(&pvt->lock); |
| 5839 |
if (pvt->r2chan) { |
| 5840 |
ast_debug(1, "Disable MFC/R2 channel %d read\n", pvt->channel); |
| 5841 |
openr2_chan_disable_read(pvt->r2chan); |
| 5842 |
} |
| 5843 |
mfcr2 = pvt->mfcr2; |
| 5844 |
if (mfcr2) { |
| 5845 |
for (idx = 0; idx < mfcr2->numchans; ++idx) { |
| 5846 |
if (mfcr2->pvts[idx] == pvt) { |
| 5847 |
ast_debug(1, "Removing MFC/R2 channel %d from the mfcr2 link\n", pvt->channel); |
| 5848 |
mfcr2->pvts[idx] = NULL; |
| 5849 |
mfcr2->live_chans--; |
| 5850 |
break; |
| 5851 |
} |
| 5852 |
} |
| 5853 |
if (!mfcr2->live_chans) { |
| 5854 |
ast_debug(1, "MFC/R2 link is now empty\n"); |
| 5855 |
should_destroy_link = 1; |
| 5856 |
} |
| 5857 |
} |
| 5858 |
ast_mutex_unlock(&pvt->lock); |
| 5859 |
if (should_destroy_link) { |
| 5860 |
ast_debug(1, "MFC/R2 link is now empty\n"); |
| 5861 |
mfcr2_queue_for_destruction(pvt); |
| 5862 |
} |
| 5863 |
} |
| 5864 |
#endif |
| 5865 |
|
| 5866 |
static struct dahdi_pvt *find_next_iface_in_span(struct dahdi_pvt *cur) |
| 5867 |
{ |
| 5868 |
if (cur->next && cur->next->span == cur->span) { |
| 5869 |
return cur->next; |
| 5870 |
} else if (cur->prev && cur->prev->span == cur->span) { |
| 5871 |
return cur->prev; |
| 5872 |
} |
| 5873 |
|
| 5874 |
return NULL; |
| 5875 |
} |
| 5876 |
|
| 5877 |
static void destroy_dahdi_pvt(struct dahdi_pvt *pvt) |
| 5878 |
{ |
| 5879 |
struct dahdi_pvt *p = pvt; |
| 5880 |
|
| 5881 |
if (p->manages_span_alarms) { |
| 5882 |
struct dahdi_pvt *next = find_next_iface_in_span(p); |
| 5883 |
if (next) { |
| 5884 |
next->manages_span_alarms = 1; |
| 5885 |
} |
| 5886 |
} |
| 5887 |
|
| 5888 |
|
| 5889 |
#if defined(HAVE_PRI) |
| 5890 |
dahdi_unlink_pri_pvt(p); |
| 5891 |
#endif |
| 5892 |
#if defined(HAVE_SS7) |
| 5893 |
dahdi_unlink_ss7_pvt(p); |
| 5894 |
#endif |
| 5895 |
#if defined(HAVE_OPENR2) |
| 5896 |
dahdi_unlink_mfcr2_pvt(p); |
| 5897 |
#endif |
| 5898 |
switch (pvt->which_iflist) { |
| 5899 |
case DAHDI_IFLIST_NONE: |
| 5900 |
break; |
| 5901 |
case DAHDI_IFLIST_MAIN: |
| 5902 |
dahdi_iflist_extract(p); |
| 5903 |
break; |
| 5904 |
#if defined(HAVE_PRI) |
| 5905 |
case DAHDI_IFLIST_NO_B_CHAN: |
| 5906 |
if (p->pri) { |
| 5907 |
dahdi_nobch_extract(p->pri, p); |
| 5908 |
} |
| 5909 |
break; |
| 5910 |
#endif |
| 5911 |
} |
| 5912 |
|
| 5913 |
if (p->sig_pvt) { |
| 5914 |
if (dahdi_analog_lib_handles(p->sig, 0, 0)) { |
| 5915 |
analog_delete(p->sig_pvt); |
| 5916 |
} |
| 5917 |
switch (p->sig) { |
| 5918 |
#if defined(HAVE_PRI) |
| 5919 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 5920 |
sig_pri_chan_delete(p->sig_pvt); |
| 5921 |
break; |
| 5922 |
#endif |
| 5923 |
#if defined(HAVE_SS7) |
| 5924 |
case SIG_SS7: |
| 5925 |
sig_ss7_chan_delete(p->sig_pvt); |
| 5926 |
break; |
| 5927 |
#endif |
| 5928 |
default: |
| 5929 |
break; |
| 5930 |
} |
| 5931 |
} |
| 5932 |
ast_free(p->cidspill); |
| 5933 |
if (p->use_smdi) { |
| 5934 |
ao2_cleanup(p->smdi_iface); |
| 5935 |
} |
| 5936 |
if (p->mwi_event_sub) { |
| 5937 |
p->mwi_event_sub = ast_mwi_unsubscribe(p->mwi_event_sub); |
| 5938 |
} |
| 5939 |
if (p->vars) { |
| 5940 |
ast_variables_destroy(p->vars); |
| 5941 |
} |
| 5942 |
if (p->cc_params) { |
| 5943 |
ast_cc_config_params_destroy(p->cc_params); |
| 5944 |
} |
| 5945 |
|
| 5946 |
p->named_callgroups = ast_unref_namedgroups(p->named_callgroups); |
| 5947 |
p->named_pickupgroups = ast_unref_namedgroups(p->named_pickupgroups); |
| 5948 |
|
| 5949 |
ast_mutex_destroy(&p->lock); |
| 5950 |
dahdi_close_sub(p, SUB_REAL); |
| 5951 |
if (p->owner) { |
| 5952 |
ast_channel_tech_pvt_set(p->owner, NULL); |
| 5953 |
} |
| 5954 |
ast_free(p); |
| 5955 |
} |
| 5956 |
|
| 5957 |
static void destroy_channel(struct dahdi_pvt *cur, int now) |
| 5958 |
{ |
| 5959 |
int i; |
| 5960 |
|
| 5961 |
if (!now) { |
| 5962 |
|
| 5963 |
if (cur->owner) { |
| 5964 |
return; |
| 5965 |
} |
| 5966 |
for (i = 0; i < 3; i++) { |
| 5967 |
if (cur->subs[i].owner) { |
| 5968 |
return; |
| 5969 |
} |
| 5970 |
} |
| 5971 |
} |
| 5972 |
destroy_dahdi_pvt(cur); |
| 5973 |
} |
| 5974 |
|
| 5975 |
static void destroy_all_channels(void) |
| 5976 |
{ |
| 5977 |
int chan; |
| 5978 |
#if defined(HAVE_PRI) |
| 5979 |
unsigned span; |
| 5980 |
struct sig_pri_span *pri; |
| 5981 |
#endif |
| 5982 |
struct dahdi_pvt *p; |
| 5983 |
|
| 5984 |
while (num_restart_pending) { |
| 5985 |
usleep(1); |
| 5986 |
} |
| 5987 |
|
| 5988 |
ast_mutex_lock(&iflock); |
| 5989 |
|
| 5990 |
while (iflist) { |
| 5991 |
p = iflist; |
| 5992 |
|
| 5993 |
chan = p->channel; |
| 5994 |
#if defined(HAVE_PRI_SERVICE_MESSAGES) |
| 5995 |
{ |
| 5996 |
char db_chan_name[20]; |
| 5997 |
char db_answer[5]; |
| 5998 |
char state; |
| 5999 |
int why = -1; |
| 6000 |
|
| 6001 |
snprintf(db_chan_name, sizeof(db_chan_name), "%s/%d:%d", dahdi_db, p->span, chan); |
| 6002 |
if (!ast_db_get(db_chan_name, SRVST_DBKEY, db_answer, sizeof(db_answer))) { |
| 6003 |
sscanf(db_answer, "%1c:%30d", &state, &why); |
| 6004 |
} |
| 6005 |
if (!why) { |
| 6006 |
|
| 6007 |
ast_db_del(db_chan_name, SRVST_DBKEY); |
| 6008 |
} |
| 6009 |
} |
| 6010 |
#endif |
| 6011 |
|
| 6012 |
destroy_dahdi_pvt(p); |
| 6013 |
ast_verb(3, "Unregistered channel %d\n", chan); |
| 6014 |
} |
| 6015 |
ifcount = 0; |
| 6016 |
ast_mutex_unlock(&iflock); |
| 6017 |
|
| 6018 |
#if defined(HAVE_PRI) |
| 6019 |
|
| 6020 |
for (span = 0; span < NUM_SPANS; ++span) { |
| 6021 |
if (!pris[span].dchannels[0]) { |
| 6022 |
break; |
| 6023 |
} |
| 6024 |
pri = &pris[span].pri; |
| 6025 |
ast_mutex_lock(&pri->lock); |
| 6026 |
while (pri->no_b_chan_iflist) { |
| 6027 |
p = pri->no_b_chan_iflist; |
| 6028 |
|
| 6029 |
|
| 6030 |
destroy_dahdi_pvt(p); |
| 6031 |
} |
| 6032 |
ast_mutex_unlock(&pri->lock); |
| 6033 |
} |
| 6034 |
#endif |
| 6035 |
} |
| 6036 |
|
| 6037 |
#if defined(HAVE_PRI) |
| 6038 |
static char *dahdi_send_keypad_facility_app = "DAHDISendKeypadFacility"; |
| 6039 |
|
| 6040 |
static int dahdi_send_keypad_facility_exec(struct ast_channel *chan, const char *digits) |
| 6041 |
{ |
| 6042 |
|
| 6043 |
struct dahdi_pvt *p; |
| 6044 |
|
| 6045 |
if (ast_strlen_zero(digits)) { |
| 6046 |
ast_debug(1, "No digit string sent to application!\n"); |
| 6047 |
return -1; |
| 6048 |
} |
| 6049 |
|
| 6050 |
p = (struct dahdi_pvt *)ast_channel_tech_pvt(chan); |
| 6051 |
|
| 6052 |
if (!p) { |
| 6053 |
ast_debug(1, "Unable to find technology private\n"); |
| 6054 |
return -1; |
| 6055 |
} |
| 6056 |
|
| 6057 |
pri_send_keypad_facility_exec(p->sig_pvt, digits); |
| 6058 |
|
| 6059 |
return 0; |
| 6060 |
} |
| 6061 |
#endif |
| 6062 |
|
| 6063 |
#if defined(HAVE_PRI) |
| 6064 |
#if defined(HAVE_PRI_PROG_W_CAUSE) |
| 6065 |
static char *dahdi_send_callrerouting_facility_app = "DAHDISendCallreroutingFacility"; |
| 6066 |
|
| 6067 |
static int dahdi_send_callrerouting_facility_exec(struct ast_channel *chan, const char *data) |
| 6068 |
{ |
| 6069 |
|
| 6070 |
struct dahdi_pvt *pvt; |
| 6071 |
char *parse; |
| 6072 |
int res; |
| 6073 |
AST_DECLARE_APP_ARGS(args, |
| 6074 |
AST_APP_ARG(destination); |
| 6075 |
AST_APP_ARG(original); |
| 6076 |
AST_APP_ARG(reason); |
| 6077 |
); |
| 6078 |
|
| 6079 |
if (ast_strlen_zero(data)) { |
| 6080 |
ast_debug(1, "No data sent to application!\n"); |
| 6081 |
return -1; |
| 6082 |
} |
| 6083 |
if (ast_channel_tech(chan) != &dahdi_tech) { |
| 6084 |
ast_debug(1, "Only DAHDI technology accepted!\n"); |
| 6085 |
return -1; |
| 6086 |
} |
| 6087 |
pvt = (struct dahdi_pvt *) ast_channel_tech_pvt(chan); |
| 6088 |
if (!pvt) { |
| 6089 |
ast_debug(1, "Unable to find technology private\n"); |
| 6090 |
return -1; |
| 6091 |
} |
| 6092 |
switch (pvt->sig) { |
| 6093 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 6094 |
break; |
| 6095 |
default: |
| 6096 |
ast_debug(1, "callrerouting attempted on non-ISDN channel %s\n", |
| 6097 |
ast_channel_name(chan)); |
| 6098 |
return -1; |
| 6099 |
} |
| 6100 |
|
| 6101 |
parse = ast_strdupa(data); |
| 6102 |
AST_STANDARD_APP_ARGS(args, parse); |
| 6103 |
|
| 6104 |
if (ast_strlen_zero(args.destination)) { |
| 6105 |
ast_log(LOG_WARNING, "callrerouting facility requires at least destination number argument\n"); |
| 6106 |
return -1; |
| 6107 |
} |
| 6108 |
|
| 6109 |
if (ast_strlen_zero(args.original)) { |
| 6110 |
ast_log(LOG_WARNING, "Callrerouting Facility without original called number argument\n"); |
| 6111 |
args.original = NULL; |
| 6112 |
} |
| 6113 |
|
| 6114 |
if (ast_strlen_zero(args.reason)) { |
| 6115 |
ast_log(LOG_NOTICE, "Callrerouting Facility without diversion reason argument, defaulting to unknown\n"); |
| 6116 |
args.reason = NULL; |
| 6117 |
} |
| 6118 |
|
| 6119 |
res = pri_send_callrerouting_facility_exec(pvt->sig_pvt, ast_channel_state(chan), |
| 6120 |
args.destination, args.original, args.reason); |
| 6121 |
if (!res) { |
| 6122 |
|
| 6123 |
|
| 6124 |
|
| 6125 |
|
| 6126 |
ast_safe_sleep(chan, 5000); |
| 6127 |
} |
| 6128 |
|
| 6129 |
return -1; |
| 6130 |
} |
| 6131 |
#endif |
| 6132 |
#endif |
| 6133 |
|
| 6134 |
#if defined(HAVE_OPENR2) |
| 6135 |
static const char * const dahdi_accept_r2_call_app = "DAHDIAcceptR2Call"; |
| 6136 |
|
| 6137 |
static int dahdi_accept_r2_call_exec(struct ast_channel *chan, const char *data) |
| 6138 |
{ |
| 6139 |
|
| 6140 |
openr2_call_mode_t accept_mode; |
| 6141 |
int res, timeout, maxloops; |
| 6142 |
struct ast_frame *f; |
| 6143 |
struct dahdi_pvt *p; |
| 6144 |
char *parse; |
| 6145 |
AST_DECLARE_APP_ARGS(args, |
| 6146 |
AST_APP_ARG(charge); |
| 6147 |
); |
| 6148 |
|
| 6149 |
if (ast_strlen_zero(data)) { |
| 6150 |
ast_debug(1, "No data sent to application!\n"); |
| 6151 |
return -1; |
| 6152 |
} |
| 6153 |
|
| 6154 |
if (ast_channel_tech(chan) != &dahdi_tech) { |
| 6155 |
ast_debug(1, "Only DAHDI technology accepted!\n"); |
| 6156 |
return -1; |
| 6157 |
} |
| 6158 |
|
| 6159 |
p = (struct dahdi_pvt *)ast_channel_tech_pvt(chan); |
| 6160 |
if (!p) { |
| 6161 |
ast_debug(1, "Unable to find technology private!\n"); |
| 6162 |
return -1; |
| 6163 |
} |
| 6164 |
|
| 6165 |
parse = ast_strdupa(data); |
| 6166 |
AST_STANDARD_APP_ARGS(args, parse); |
| 6167 |
|
| 6168 |
if (ast_strlen_zero(args.charge)) { |
| 6169 |
ast_log(LOG_WARNING, "DAHDIAcceptR2Call requires 'yes' or 'no' for the charge parameter\n"); |
| 6170 |
return -1; |
| 6171 |
} |
| 6172 |
|
| 6173 |
ast_mutex_lock(&p->lock); |
| 6174 |
if (!p->mfcr2 || !p->mfcr2call) { |
| 6175 |
ast_mutex_unlock(&p->lock); |
| 6176 |
ast_debug(1, "Channel %s does not seems to be an R2 active channel!\n", ast_channel_name(chan)); |
| 6177 |
return -1; |
| 6178 |
} |
| 6179 |
|
| 6180 |
if (p->mfcr2_call_accepted) { |
| 6181 |
ast_mutex_unlock(&p->lock); |
| 6182 |
ast_debug(1, "MFC/R2 call already accepted on channel %s!\n", ast_channel_name(chan)); |
| 6183 |
return 0; |
| 6184 |
} |
| 6185 |
accept_mode = ast_true(args.charge) ? OR2_CALL_WITH_CHARGE : OR2_CALL_NO_CHARGE; |
| 6186 |
if (openr2_chan_accept_call(p->r2chan, accept_mode)) { |
| 6187 |
ast_mutex_unlock(&p->lock); |
| 6188 |
ast_log(LOG_WARNING, "Failed to accept MFC/R2 call!\n"); |
| 6189 |
return -1; |
| 6190 |
} |
| 6191 |
ast_mutex_unlock(&p->lock); |
| 6192 |
|
| 6193 |
res = 0; |
| 6194 |
timeout = 100; |
| 6195 |
maxloops = 50; |
| 6196 |
|
| 6197 |
while (maxloops > 0) { |
| 6198 |
maxloops--; |
| 6199 |
if (ast_check_hangup(chan)) { |
| 6200 |
break; |
| 6201 |
} |
| 6202 |
res = ast_waitfor(chan, timeout); |
| 6203 |
if (res < 0) { |
| 6204 |
ast_debug(1, "ast_waitfor failed on channel %s, going out ...\n", ast_channel_name(chan)); |
| 6205 |
res = -1; |
| 6206 |
break; |
| 6207 |
} |
| 6208 |
if (res == 0) { |
| 6209 |
continue; |
| 6210 |
} |
| 6211 |
res = 0; |
| 6212 |
f = ast_read(chan); |
| 6213 |
if (!f) { |
| 6214 |
ast_debug(1, "No frame read on channel %s, going out ...\n", ast_channel_name(chan)); |
| 6215 |
res = -1; |
| 6216 |
break; |
| 6217 |
} |
| 6218 |
if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_HANGUP) { |
| 6219 |
ast_debug(1, "Got HANGUP frame on channel %s, going out ...\n", ast_channel_name(chan)); |
| 6220 |
ast_frfree(f); |
| 6221 |
res = -1; |
| 6222 |
break; |
| 6223 |
} |
| 6224 |
ast_frfree(f); |
| 6225 |
ast_mutex_lock(&p->lock); |
| 6226 |
if (p->mfcr2_call_accepted) { |
| 6227 |
ast_mutex_unlock(&p->lock); |
| 6228 |
ast_debug(1, "Accepted MFC/R2 call!\n"); |
| 6229 |
break; |
| 6230 |
} |
| 6231 |
ast_mutex_unlock(&p->lock); |
| 6232 |
} |
| 6233 |
if (res == -1) { |
| 6234 |
ast_log(LOG_WARNING, "Failed to accept MFC/R2 call!\n"); |
| 6235 |
} |
| 6236 |
return res; |
| 6237 |
} |
| 6238 |
|
| 6239 |
static openr2_call_disconnect_cause_t dahdi_ast_cause_to_r2_cause(int cause) |
| 6240 |
{ |
| 6241 |
openr2_call_disconnect_cause_t r2cause = OR2_CAUSE_NORMAL_CLEARING; |
| 6242 |
switch (cause) { |
| 6243 |
case AST_CAUSE_USER_BUSY: |
| 6244 |
case AST_CAUSE_CALL_REJECTED: |
| 6245 |
case AST_CAUSE_INTERWORKING: |
| 6246 |
r2cause = OR2_CAUSE_BUSY_NUMBER; |
| 6247 |
break; |
| 6248 |
|
| 6249 |
case AST_CAUSE_NORMAL_CIRCUIT_CONGESTION: |
| 6250 |
case AST_CAUSE_SWITCH_CONGESTION: |
| 6251 |
r2cause = OR2_CAUSE_NETWORK_CONGESTION; |
| 6252 |
break; |
| 6253 |
|
| 6254 |
case AST_CAUSE_UNALLOCATED: |
| 6255 |
r2cause = OR2_CAUSE_UNALLOCATED_NUMBER; |
| 6256 |
break; |
| 6257 |
|
| 6258 |
case AST_CAUSE_NETWORK_OUT_OF_ORDER: |
| 6259 |
case AST_CAUSE_DESTINATION_OUT_OF_ORDER: |
| 6260 |
r2cause = OR2_CAUSE_OUT_OF_ORDER; |
| 6261 |
break; |
| 6262 |
|
| 6263 |
case AST_CAUSE_NO_ANSWER: |
| 6264 |
case AST_CAUSE_NO_USER_RESPONSE: |
| 6265 |
r2cause = OR2_CAUSE_NO_ANSWER; |
| 6266 |
break; |
| 6267 |
|
| 6268 |
default: |
| 6269 |
r2cause = OR2_CAUSE_NORMAL_CLEARING; |
| 6270 |
break; |
| 6271 |
} |
| 6272 |
ast_debug(1, "ast cause %d resulted in openr2 cause %d/%s\n", |
| 6273 |
cause, r2cause, openr2_proto_get_disconnect_string(r2cause)); |
| 6274 |
return r2cause; |
| 6275 |
} |
| 6276 |
#endif |
| 6277 |
|
| 6278 |
static int revert_fax_buffers(struct dahdi_pvt *p, struct ast_channel *ast) |
| 6279 |
{ |
| 6280 |
if (p->bufferoverrideinuse) { |
| 6281 |
|
| 6282 |
struct dahdi_bufferinfo bi = { |
| 6283 |
.txbufpolicy = p->buf_policy, |
| 6284 |
.rxbufpolicy = p->buf_policy, |
| 6285 |
.bufsize = p->bufsize, |
| 6286 |
.numbufs = p->buf_no |
| 6287 |
}; |
| 6288 |
int bpres; |
| 6289 |
|
| 6290 |
if ((bpres = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) { |
| 6291 |
ast_log(LOG_WARNING, "Channel '%s' unable to revert buffer policy: %s\n", ast_channel_name(ast), strerror(errno)); |
| 6292 |
} |
| 6293 |
p->bufferoverrideinuse = 0; |
| 6294 |
return bpres; |
| 6295 |
} |
| 6296 |
|
| 6297 |
return -1; |
| 6298 |
} |
| 6299 |
|
| 6300 |
static int dahdi_hangup(struct ast_channel *ast) |
| 6301 |
{ |
| 6302 |
int res = 0; |
| 6303 |
int idx,x; |
| 6304 |
int law; |
| 6305 |
|
| 6306 |
struct dahdi_pvt *p = ast_channel_tech_pvt(ast); |
| 6307 |
struct dahdi_params par; |
| 6308 |
|
| 6309 |
ast_debug(1, "dahdi_hangup(%s)\n", ast_channel_name(ast)); |
| 6310 |
if (!ast_channel_tech_pvt(ast)) { |
| 6311 |
ast_log(LOG_WARNING, "Asked to hangup channel not connected\n"); |
| 6312 |
return 0; |
| 6313 |
} |
| 6314 |
|
| 6315 |
ast_mutex_lock(&p->lock); |
| 6316 |
p->exten[0] = '\0'; |
| 6317 |
|
| 6318 |
if (dahdi_analog_lib_handles(p->sig, p->radio, 0)) { |
| 6319 |
p->oprmode = 0; |
| 6320 |
dahdi_confmute(p, 0); |
| 6321 |
restore_gains(p); |
| 6322 |
p->ignoredtmf = 0; |
| 6323 |
p->waitingfordt.tv_sec = 0; |
| 6324 |
|
| 6325 |
res = analog_hangup(p->sig_pvt, ast); |
| 6326 |
revert_fax_buffers(p, ast); |
| 6327 |
|
| 6328 |
goto hangup_out; |
| 6329 |
} else { |
| 6330 |
p->cid_num[0] = '\0'; |
| 6331 |
p->cid_name[0] = '\0'; |
| 6332 |
p->cid_subaddr[0] = '\0'; |
| 6333 |
} |
| 6334 |
|
| 6335 |
#if defined(HAVE_PRI) |
| 6336 |
if (dahdi_sig_pri_lib_handles(p->sig)) { |
| 6337 |
x = 1; |
| 6338 |
ast_channel_setoption(ast, AST_OPTION_AUDIO_MODE, &x, sizeof(char), 0); |
| 6339 |
|
| 6340 |
dahdi_confmute(p, 0); |
| 6341 |
p->muting = 0; |
| 6342 |
restore_gains(p); |
| 6343 |
if (p->dsp) { |
| 6344 |
ast_dsp_free(p->dsp); |
| 6345 |
p->dsp = NULL; |
| 6346 |
} |
| 6347 |
p->ignoredtmf = 0; |
| 6348 |
|
| 6349 |
|
| 6350 |
p->subs[SUB_REAL].owner = NULL; |
| 6351 |
p->subs[SUB_REAL].needbusy = 0; |
| 6352 |
dahdi_setlinear(p->subs[SUB_REAL].dfd, 0); |
| 6353 |
|
| 6354 |
p->owner = NULL; |
| 6355 |
p->cid_tag[0] = '\0'; |
| 6356 |
p->ringt = 0; |
| 6357 |
p->distinctivering = 0; |
| 6358 |
p->confirmanswer = 0; |
| 6359 |
p->outgoing = 0; |
| 6360 |
p->digital = 0; |
| 6361 |
p->faxhandled = 0; |
| 6362 |
p->pulsedial = 0; |
| 6363 |
|
| 6364 |
revert_fax_buffers(p, ast); |
| 6365 |
|
| 6366 |
p->law = p->law_default; |
| 6367 |
law = p->law_default; |
| 6368 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETLAW, &law); |
| 6369 |
if (res < 0) { |
| 6370 |
ast_log(LOG_WARNING, "Unable to set law on channel %d to default: %s\n", |
| 6371 |
p->channel, strerror(errno)); |
| 6372 |
} |
| 6373 |
|
| 6374 |
sig_pri_hangup(p->sig_pvt, ast); |
| 6375 |
|
| 6376 |
tone_zone_play_tone(p->subs[SUB_REAL].dfd, -1); |
| 6377 |
dahdi_ec_disable(p); |
| 6378 |
|
| 6379 |
x = 0; |
| 6380 |
ast_channel_setoption(ast, AST_OPTION_TDD, &x, sizeof(char), 0); |
| 6381 |
p->didtdd = 0; |
| 6382 |
|
| 6383 |
p->rdnis[0] = '\0'; |
| 6384 |
dahdi_conf_update(p); |
| 6385 |
reset_conf(p); |
| 6386 |
|
| 6387 |
|
| 6388 |
x = 0; |
| 6389 |
ast_channel_setoption(ast, AST_OPTION_AUDIO_MODE, &x, sizeof(char), 0); |
| 6390 |
|
| 6391 |
if (num_restart_pending == 0) { |
| 6392 |
restart_monitor(); |
| 6393 |
} |
| 6394 |
goto hangup_out; |
| 6395 |
} |
| 6396 |
#endif |
| 6397 |
|
| 6398 |
#if defined(HAVE_SS7) |
| 6399 |
if (p->sig == SIG_SS7) { |
| 6400 |
x = 1; |
| 6401 |
ast_channel_setoption(ast, AST_OPTION_AUDIO_MODE, &x, sizeof(char), 0); |
| 6402 |
|
| 6403 |
dahdi_confmute(p, 0); |
| 6404 |
p->muting = 0; |
| 6405 |
restore_gains(p); |
| 6406 |
if (p->dsp) { |
| 6407 |
ast_dsp_free(p->dsp); |
| 6408 |
p->dsp = NULL; |
| 6409 |
} |
| 6410 |
p->ignoredtmf = 0; |
| 6411 |
|
| 6412 |
|
| 6413 |
p->subs[SUB_REAL].owner = NULL; |
| 6414 |
p->subs[SUB_REAL].needbusy = 0; |
| 6415 |
dahdi_setlinear(p->subs[SUB_REAL].dfd, 0); |
| 6416 |
|
| 6417 |
p->owner = NULL; |
| 6418 |
p->ringt = 0; |
| 6419 |
p->distinctivering = 0; |
| 6420 |
p->confirmanswer = 0; |
| 6421 |
p->outgoing = 0; |
| 6422 |
p->digital = 0; |
| 6423 |
p->faxhandled = 0; |
| 6424 |
p->pulsedial = 0; |
| 6425 |
|
| 6426 |
revert_fax_buffers(p, ast); |
| 6427 |
|
| 6428 |
p->law = p->law_default; |
| 6429 |
law = p->law_default; |
| 6430 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETLAW, &law); |
| 6431 |
if (res < 0) { |
| 6432 |
ast_log(LOG_WARNING, "Unable to set law on channel %d to default: %s\n", |
| 6433 |
p->channel, strerror(errno)); |
| 6434 |
} |
| 6435 |
|
| 6436 |
sig_ss7_hangup(p->sig_pvt, ast); |
| 6437 |
|
| 6438 |
tone_zone_play_tone(p->subs[SUB_REAL].dfd, -1); |
| 6439 |
dahdi_ec_disable(p); |
| 6440 |
|
| 6441 |
x = 0; |
| 6442 |
ast_channel_setoption(ast, AST_OPTION_TDD, &x, sizeof(char), 0); |
| 6443 |
p->didtdd = 0; |
| 6444 |
|
| 6445 |
dahdi_conf_update(p); |
| 6446 |
reset_conf(p); |
| 6447 |
|
| 6448 |
|
| 6449 |
x = 0; |
| 6450 |
ast_channel_setoption(ast, AST_OPTION_AUDIO_MODE, &x, sizeof(char), 0); |
| 6451 |
|
| 6452 |
if (num_restart_pending == 0) { |
| 6453 |
restart_monitor(); |
| 6454 |
} |
| 6455 |
goto hangup_out; |
| 6456 |
} |
| 6457 |
#endif |
| 6458 |
|
| 6459 |
idx = dahdi_get_index(ast, p, 1); |
| 6460 |
|
| 6461 |
dahdi_confmute(p, 0); |
| 6462 |
p->muting = 0; |
| 6463 |
restore_gains(p); |
| 6464 |
if (p->origcid_num) { |
| 6465 |
ast_copy_string(p->cid_num, p->origcid_num, sizeof(p->cid_num)); |
| 6466 |
ast_free(p->origcid_num); |
| 6467 |
p->origcid_num = NULL; |
| 6468 |
} |
| 6469 |
if (p->origcid_name) { |
| 6470 |
ast_copy_string(p->cid_name, p->origcid_name, sizeof(p->cid_name)); |
| 6471 |
ast_free(p->origcid_name); |
| 6472 |
p->origcid_name = NULL; |
| 6473 |
} |
| 6474 |
if (p->dsp) |
| 6475 |
ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax); |
| 6476 |
|
| 6477 |
ast_debug(1, "Hangup: channel: %d index = %d, normal = %d, callwait = %d, thirdcall = %d\n", |
| 6478 |
p->channel, idx, p->subs[SUB_REAL].dfd, p->subs[SUB_CALLWAIT].dfd, p->subs[SUB_THREEWAY].dfd); |
| 6479 |
p->ignoredtmf = 0; |
| 6480 |
|
| 6481 |
if (idx > -1) { |
| 6482 |
|
| 6483 |
p->subs[idx].owner = NULL; |
| 6484 |
p->subs[idx].needanswer = 0; |
| 6485 |
p->subs[idx].needflash = 0; |
| 6486 |
p->subs[idx].needringing = 0; |
| 6487 |
p->subs[idx].needbusy = 0; |
| 6488 |
p->subs[idx].needcongestion = 0; |
| 6489 |
p->subs[idx].linear = 0; |
| 6490 |
p->polarity = POLARITY_IDLE; |
| 6491 |
dahdi_setlinear(p->subs[idx].dfd, 0); |
| 6492 |
if (idx == SUB_REAL) { |
| 6493 |
if ((p->subs[SUB_CALLWAIT].dfd > -1) && (p->subs[SUB_THREEWAY].dfd > -1)) { |
| 6494 |
ast_debug(1, "Normal call hung up with both three way call and a call waiting call in place?\n"); |
| 6495 |
if (p->subs[SUB_CALLWAIT].inthreeway) { |
| 6496 |
|
| 6497 |
ast_debug(1, "We were flipped over to the callwait, moving back and not owning.\n"); |
| 6498 |
|
| 6499 |
swap_subs(p, SUB_CALLWAIT, SUB_REAL); |
| 6500 |
unalloc_sub(p, SUB_CALLWAIT); |
| 6501 |
p->owner = NULL; |
| 6502 |
} else { |
| 6503 |
|
| 6504 |
ast_debug(1, "We were in the threeway and have a callwait still. Ditching the threeway.\n"); |
| 6505 |
swap_subs(p, SUB_THREEWAY, SUB_REAL); |
| 6506 |
unalloc_sub(p, SUB_THREEWAY); |
| 6507 |
if (p->subs[SUB_REAL].inthreeway) { |
| 6508 |
|
| 6509 |
|
| 6510 |
ast_debug(1, "Call was complete, setting owner to former third call\n"); |
| 6511 |
p->owner = p->subs[SUB_REAL].owner; |
| 6512 |
} else { |
| 6513 |
|
| 6514 |
ast_debug(1, "Call was incomplete, setting owner to NULL\n"); |
| 6515 |
p->owner = NULL; |
| 6516 |
} |
| 6517 |
p->subs[SUB_REAL].inthreeway = 0; |
| 6518 |
} |
| 6519 |
} else if (p->subs[SUB_CALLWAIT].dfd > -1) { |
| 6520 |
|
| 6521 |
swap_subs(p, SUB_CALLWAIT, SUB_REAL); |
| 6522 |
unalloc_sub(p, SUB_CALLWAIT); |
| 6523 |
p->owner = p->subs[SUB_REAL].owner; |
| 6524 |
if (ast_channel_state(p->owner) != AST_STATE_UP) |
| 6525 |
p->subs[SUB_REAL].needanswer = 1; |
| 6526 |
ast_queue_unhold(p->subs[SUB_REAL].owner); |
| 6527 |
} else if (p->subs[SUB_THREEWAY].dfd > -1) { |
| 6528 |
swap_subs(p, SUB_THREEWAY, SUB_REAL); |
| 6529 |
unalloc_sub(p, SUB_THREEWAY); |
| 6530 |
if (p->subs[SUB_REAL].inthreeway) { |
| 6531 |
|
| 6532 |
|
| 6533 |
ast_debug(1, "Call was complete, setting owner to former third call\n"); |
| 6534 |
p->owner = p->subs[SUB_REAL].owner; |
| 6535 |
} else { |
| 6536 |
|
| 6537 |
ast_debug(1, "Call was incomplete, setting owner to NULL\n"); |
| 6538 |
p->owner = NULL; |
| 6539 |
} |
| 6540 |
p->subs[SUB_REAL].inthreeway = 0; |
| 6541 |
} |
| 6542 |
} else if (idx == SUB_CALLWAIT) { |
| 6543 |
|
| 6544 |
if (p->subs[SUB_CALLWAIT].inthreeway) { |
| 6545 |
|
| 6546 |
|
| 6547 |
if (p->subs[SUB_THREEWAY].owner) { |
| 6548 |
ast_queue_hold(p->subs[SUB_THREEWAY].owner, p->mohsuggest); |
| 6549 |
} |
| 6550 |
p->subs[SUB_THREEWAY].inthreeway = 0; |
| 6551 |
|
| 6552 |
swap_subs(p, SUB_CALLWAIT, SUB_THREEWAY); |
| 6553 |
unalloc_sub(p, SUB_THREEWAY); |
| 6554 |
} else |
| 6555 |
unalloc_sub(p, SUB_CALLWAIT); |
| 6556 |
} else if (idx == SUB_THREEWAY) { |
| 6557 |
if (p->subs[SUB_CALLWAIT].inthreeway) { |
| 6558 |
|
| 6559 |
|
| 6560 |
if (p->subs[SUB_CALLWAIT].owner) { |
| 6561 |
ast_queue_hold(p->subs[SUB_CALLWAIT].owner, p->mohsuggest); |
| 6562 |
} |
| 6563 |
p->subs[SUB_CALLWAIT].inthreeway = 0; |
| 6564 |
} |
| 6565 |
p->subs[SUB_REAL].inthreeway = 0; |
| 6566 |
|
| 6567 |
|
| 6568 |
unalloc_sub(p, SUB_THREEWAY); |
| 6569 |
} else { |
| 6570 |
|
| 6571 |
ast_log(LOG_WARNING, "Index found but not any type of call?\n"); |
| 6572 |
} |
| 6573 |
} |
| 6574 |
|
| 6575 |
if (!p->subs[SUB_REAL].owner && !p->subs[SUB_CALLWAIT].owner && !p->subs[SUB_THREEWAY].owner) { |
| 6576 |
p->owner = NULL; |
| 6577 |
p->ringt = 0; |
| 6578 |
p->distinctivering = 0; |
| 6579 |
p->confirmanswer = 0; |
| 6580 |
p->outgoing = 0; |
| 6581 |
p->digital = 0; |
| 6582 |
p->faxhandled = 0; |
| 6583 |
p->pulsedial = 0; |
| 6584 |
if (p->dsp) { |
| 6585 |
ast_dsp_free(p->dsp); |
| 6586 |
p->dsp = NULL; |
| 6587 |
} |
| 6588 |
|
| 6589 |
revert_fax_buffers(p, ast); |
| 6590 |
|
| 6591 |
p->law = p->law_default; |
| 6592 |
law = p->law_default; |
| 6593 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETLAW, &law); |
| 6594 |
if (res < 0) |
| 6595 |
ast_log(LOG_WARNING, "Unable to set law on channel %d to default: %s\n", p->channel, strerror(errno)); |
| 6596 |
|
| 6597 |
#ifdef HAVE_OPENR2 |
| 6598 |
if (p->mfcr2 && p->mfcr2call && openr2_chan_get_direction(p->r2chan) != OR2_DIR_STOPPED) { |
| 6599 |
ast_debug(1, "disconnecting MFC/R2 call on chan %d\n", p->channel); |
| 6600 |
|
| 6601 |
if (openr2_chan_get_direction(p->r2chan) == OR2_DIR_BACKWARD && p->mfcr2_forced_release) { |
| 6602 |
dahdi_r2_disconnect_call(p, OR2_CAUSE_FORCED_RELEASE); |
| 6603 |
} else { |
| 6604 |
const char *r2causestr = pbx_builtin_getvar_helper(ast, "MFCR2_CAUSE"); |
| 6605 |
int r2cause_user = r2causestr ? atoi(r2causestr) : 0; |
| 6606 |
openr2_call_disconnect_cause_t r2cause = r2cause_user ? dahdi_ast_cause_to_r2_cause(r2cause_user) |
| 6607 |
: dahdi_ast_cause_to_r2_cause(ast_channel_hangupcause(ast)); |
| 6608 |
dahdi_r2_disconnect_call(p, r2cause); |
| 6609 |
} |
| 6610 |
} else if (p->mfcr2call) { |
| 6611 |
ast_debug(1, "Clearing call request on channel %d\n", p->channel); |
| 6612 |
|
| 6613 |
|
| 6614 |
|
| 6615 |
|
| 6616 |
p->mfcr2call = 0; |
| 6617 |
} |
| 6618 |
#endif |
| 6619 |
switch (p->sig) { |
| 6620 |
case SIG_SS7: |
| 6621 |
case SIG_MFCR2: |
| 6622 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 6623 |
case 0: |
| 6624 |
break; |
| 6625 |
default: |
| 6626 |
res = dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_ONHOOK); |
| 6627 |
break; |
| 6628 |
} |
| 6629 |
if (res < 0) { |
| 6630 |
ast_log(LOG_WARNING, "Unable to hangup line %s\n", ast_channel_name(ast)); |
| 6631 |
} |
| 6632 |
switch (p->sig) { |
| 6633 |
case SIG_FXOGS: |
| 6634 |
case SIG_FXOLS: |
| 6635 |
case SIG_FXOKS: |
| 6636 |
memset(&par, 0, sizeof(par)); |
| 6637 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par); |
| 6638 |
if (!res) { |
| 6639 |
struct analog_pvt *analog_p = p->sig_pvt; |
| 6640 |
#if 0 |
| 6641 |
ast_debug(1, "Hanging up channel %d, offhook = %d\n", p->channel, par.rxisoffhook); |
| 6642 |
#endif |
| 6643 |
|
| 6644 |
if ((par.rxisoffhook) && (!(p->radio || (p->oprmode < 0)))) |
| 6645 |
tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_CONGESTION); |
| 6646 |
else |
| 6647 |
tone_zone_play_tone(p->subs[SUB_REAL].dfd, -1); |
| 6648 |
analog_p->fxsoffhookstate = par.rxisoffhook; |
| 6649 |
} |
| 6650 |
break; |
| 6651 |
case SIG_FXSGS: |
| 6652 |
case SIG_FXSLS: |
| 6653 |
case SIG_FXSKS: |
| 6654 |
|
| 6655 |
|
| 6656 |
if (ast_channel_state(ast) != AST_STATE_RESERVED) { |
| 6657 |
time(&p->guardtime); |
| 6658 |
p->guardtime += 2; |
| 6659 |
} |
| 6660 |
break; |
| 6661 |
default: |
| 6662 |
tone_zone_play_tone(p->subs[SUB_REAL].dfd, -1); |
| 6663 |
break; |
| 6664 |
} |
| 6665 |
if (p->sig) |
| 6666 |
dahdi_ec_disable(p); |
| 6667 |
x = 0; |
| 6668 |
ast_channel_setoption(ast,AST_OPTION_TONE_VERIFY,&x,sizeof(char),0); |
| 6669 |
ast_channel_setoption(ast,AST_OPTION_TDD,&x,sizeof(char),0); |
| 6670 |
p->didtdd = 0; |
| 6671 |
p->callwaitcas = 0; |
| 6672 |
p->callwaiting = p->permcallwaiting; |
| 6673 |
p->hidecallerid = p->permhidecallerid; |
| 6674 |
if (dahdi_analog_lib_handles(p->sig, p->radio, 0) && !p->owner) { |
| 6675 |
|
| 6676 |
|
| 6677 |
|
| 6678 |
struct analog_pvt *analog_p = p->sig_pvt; |
| 6679 |
|
| 6680 |
|
| 6681 |
|
| 6682 |
analog_p->dialmode = analog_p->permdialmode; |
| 6683 |
} |
| 6684 |
p->waitingfordt.tv_sec = 0; |
| 6685 |
p->dialing = 0; |
| 6686 |
p->rdnis[0] = '\0'; |
| 6687 |
dahdi_conf_update(p); |
| 6688 |
reset_conf(p); |
| 6689 |
|
| 6690 |
switch (p->sig) { |
| 6691 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 6692 |
case SIG_SS7: |
| 6693 |
x = 0; |
| 6694 |
ast_channel_setoption(ast,AST_OPTION_AUDIO_MODE,&x,sizeof(char),0); |
| 6695 |
break; |
| 6696 |
default: |
| 6697 |
break; |
| 6698 |
} |
| 6699 |
if (num_restart_pending == 0) |
| 6700 |
restart_monitor(); |
| 6701 |
} |
| 6702 |
|
| 6703 |
p->callwaitingrepeat = 0; |
| 6704 |
p->cidcwexpire = 0; |
| 6705 |
p->cid_suppress_expire = 0; |
| 6706 |
p->oprmode = 0; |
| 6707 |
hangup_out: |
| 6708 |
ast_channel_tech_pvt_set(ast, NULL); |
| 6709 |
ast_free(p->cidspill); |
| 6710 |
p->cidspill = NULL; |
| 6711 |
|
| 6712 |
if (p->reoriginate && p->sig == SIG_FXOKS && dahdi_analog_lib_handles(p->sig, p->radio, 0)) { |
| 6713 |
|
| 6714 |
|
| 6715 |
if (my_is_off_hook(p) && !p->owner) { |
| 6716 |
|
| 6717 |
ast_debug(1, "Queuing reorigination for channel %d\n", p->channel); |
| 6718 |
my_play_tone(p, SUB_REAL, -1); |
| 6719 |
|
| 6720 |
|
| 6721 |
|
| 6722 |
|
| 6723 |
usleep(800000); |
| 6724 |
|
| 6725 |
|
| 6726 |
if (!p->owner && my_is_off_hook(p)) { |
| 6727 |
p->doreoriginate = 1; |
| 6728 |
|
| 6729 |
|
| 6730 |
|
| 6731 |
|
| 6732 |
|
| 6733 |
|
| 6734 |
|
| 6735 |
my_off_hook(p); |
| 6736 |
} else { |
| 6737 |
ast_debug(1, "Channel %d is no longer eligible for reorigination (went back on hook or became in use)\n", p->channel); |
| 6738 |
} |
| 6739 |
} |
| 6740 |
} |
| 6741 |
|
| 6742 |
ast_mutex_unlock(&p->lock); |
| 6743 |
ast_verb(3, "Hungup '%s'\n", ast_channel_name(ast)); |
| 6744 |
|
| 6745 |
ast_mutex_lock(&iflock); |
| 6746 |
if (p->restartpending) { |
| 6747 |
num_restart_pending--; |
| 6748 |
} |
| 6749 |
|
| 6750 |
if (p->destroy) { |
| 6751 |
destroy_channel(p, 0); |
| 6752 |
} |
| 6753 |
ast_mutex_unlock(&iflock); |
| 6754 |
|
| 6755 |
ast_module_unref(ast_module_info->self); |
| 6756 |
return 0; |
| 6757 |
} |
| 6758 |
|
| 6759 |
static int dahdi_answer(struct ast_channel *ast) |
| 6760 |
{ |
| 6761 |
struct dahdi_pvt *p = ast_channel_tech_pvt(ast); |
| 6762 |
int res = 0; |
| 6763 |
int idx; |
| 6764 |
ast_setstate(ast, AST_STATE_UP); |
| 6765 |
ast_mutex_lock(&p->lock); |
| 6766 |
idx = dahdi_get_index(ast, p, 0); |
| 6767 |
if (idx < 0) |
| 6768 |
idx = SUB_REAL; |
| 6769 |
|
| 6770 |
if ((p->radio || (p->oprmode < 0))) { |
| 6771 |
ast_mutex_unlock(&p->lock); |
| 6772 |
return 0; |
| 6773 |
} |
| 6774 |
|
| 6775 |
if (dahdi_analog_lib_handles(p->sig, p->radio, p->oprmode)) { |
| 6776 |
res = analog_answer(p->sig_pvt, ast); |
| 6777 |
ast_mutex_unlock(&p->lock); |
| 6778 |
return res; |
| 6779 |
} |
| 6780 |
|
| 6781 |
switch (p->sig) { |
| 6782 |
#if defined(HAVE_PRI) |
| 6783 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 6784 |
res = sig_pri_answer(p->sig_pvt, ast); |
| 6785 |
break; |
| 6786 |
#endif |
| 6787 |
#if defined(HAVE_SS7) |
| 6788 |
case SIG_SS7: |
| 6789 |
res = sig_ss7_answer(p->sig_pvt, ast); |
| 6790 |
break; |
| 6791 |
#endif |
| 6792 |
#ifdef HAVE_OPENR2 |
| 6793 |
case SIG_MFCR2: |
| 6794 |
if (!p->mfcr2_call_accepted) { |
| 6795 |
|
| 6796 |
|
| 6797 |
p->mfcr2_answer_pending = 1; |
| 6798 |
if (p->mfcr2_charge_calls) { |
| 6799 |
ast_debug(1, "Accepting MFC/R2 call with charge before answering on chan %d\n", p->channel); |
| 6800 |
openr2_chan_accept_call(p->r2chan, OR2_CALL_WITH_CHARGE); |
| 6801 |
} else { |
| 6802 |
ast_debug(1, "Accepting MFC/R2 call with no charge before answering on chan %d\n", p->channel); |
| 6803 |
openr2_chan_accept_call(p->r2chan, OR2_CALL_NO_CHARGE); |
| 6804 |
} |
| 6805 |
} else { |
| 6806 |
ast_debug(1, "Answering MFC/R2 call on chan %d\n", p->channel); |
| 6807 |
dahdi_r2_answer(p); |
| 6808 |
} |
| 6809 |
break; |
| 6810 |
#endif |
| 6811 |
case 0: |
| 6812 |
ast_mutex_unlock(&p->lock); |
| 6813 |
return 0; |
| 6814 |
default: |
| 6815 |
ast_log(LOG_WARNING, "Don't know how to answer signalling %d (channel %d)\n", p->sig, p->channel); |
| 6816 |
res = -1; |
| 6817 |
break; |
| 6818 |
} |
| 6819 |
ast_mutex_unlock(&p->lock); |
| 6820 |
return res; |
| 6821 |
} |
| 6822 |
|
| 6823 |
void dahdi_dtmf_detect_disable(struct dahdi_pvt *p) |
| 6824 |
{ |
| 6825 |
int val = 0; |
| 6826 |
|
| 6827 |
p->ignoredtmf = 1; |
| 6828 |
|
| 6829 |
ioctl(p->subs[SUB_REAL].dfd, DAHDI_TONEDETECT, &val); |
| 6830 |
|
| 6831 |
if (!p->hardwaredtmf && p->dsp) { |
| 6832 |
p->dsp_features &= ~DSP_FEATURE_DIGIT_DETECT; |
| 6833 |
ast_dsp_set_features(p->dsp, p->dsp_features); |
| 6834 |
} |
| 6835 |
} |
| 6836 |
|
| 6837 |
void dahdi_dtmf_detect_enable(struct dahdi_pvt *p) |
| 6838 |
{ |
| 6839 |
int val = DAHDI_TONEDETECT_ON | DAHDI_TONEDETECT_MUTE; |
| 6840 |
|
| 6841 |
if (p->channel == CHAN_PSEUDO) |
| 6842 |
return; |
| 6843 |
|
| 6844 |
p->ignoredtmf = 0; |
| 6845 |
|
| 6846 |
ioctl(p->subs[SUB_REAL].dfd, DAHDI_TONEDETECT, &val); |
| 6847 |
|
| 6848 |
if (!p->hardwaredtmf && p->dsp) { |
| 6849 |
p->dsp_features |= DSP_FEATURE_DIGIT_DETECT; |
| 6850 |
ast_dsp_set_features(p->dsp, p->dsp_features); |
| 6851 |
} |
| 6852 |
} |
| 6853 |
|
| 6854 |
static int dahdi_queryoption(struct ast_channel *chan, int option, void *data, int *datalen) |
| 6855 |
{ |
| 6856 |
char *cp; |
| 6857 |
struct dahdi_pvt *p = ast_channel_tech_pvt(chan); |
| 6858 |
|
| 6859 |
|
| 6860 |
if (!p || !data || (*datalen < 1)) { |
| 6861 |
errno = EINVAL; |
| 6862 |
return -1; |
| 6863 |
} |
| 6864 |
|
| 6865 |
switch (option) { |
| 6866 |
case AST_OPTION_TDD: |
| 6867 |
cp = (char *) data; |
| 6868 |
if (p->mate) { |
| 6869 |
*cp = 2; |
| 6870 |
} else { |
| 6871 |
*cp = p->tdd ? 1 : 0; |
| 6872 |
} |
| 6873 |
break; |
| 6874 |
case AST_OPTION_DIGIT_DETECT: |
| 6875 |
cp = (char *) data; |
| 6876 |
*cp = p->ignoredtmf ? 0 : 1; |
| 6877 |
ast_debug(1, "Reporting digit detection %sabled on %s\n", *cp ? "en" : "dis", ast_channel_name(chan)); |
| 6878 |
break; |
| 6879 |
case AST_OPTION_FAX_DETECT: |
| 6880 |
cp = (char *) data; |
| 6881 |
*cp = (p->dsp_features & DSP_FEATURE_FAX_DETECT) ? 0 : 1; |
| 6882 |
ast_debug(1, "Reporting fax tone detection %sabled on %s\n", *cp ? "en" : "dis", ast_channel_name(chan)); |
| 6883 |
break; |
| 6884 |
case AST_OPTION_CC_AGENT_TYPE: |
| 6885 |
#if defined(HAVE_PRI) |
| 6886 |
#if defined(HAVE_PRI_CCSS) |
| 6887 |
if (dahdi_sig_pri_lib_handles(p->sig)) { |
| 6888 |
ast_copy_string((char *) data, dahdi_pri_cc_type, *datalen); |
| 6889 |
break; |
| 6890 |
} |
| 6891 |
#endif |
| 6892 |
#endif |
| 6893 |
return -1; |
| 6894 |
default: |
| 6895 |
return -1; |
| 6896 |
} |
| 6897 |
|
| 6898 |
errno = 0; |
| 6899 |
|
| 6900 |
return 0; |
| 6901 |
} |
| 6902 |
|
| 6903 |
static int dahdi_setoption(struct ast_channel *chan, int option, void *data, int datalen) |
| 6904 |
{ |
| 6905 |
char *cp; |
| 6906 |
signed char *scp; |
| 6907 |
int x; |
| 6908 |
int idx; |
| 6909 |
struct dahdi_pvt *p = ast_channel_tech_pvt(chan), *pp; |
| 6910 |
struct oprmode *oprmode; |
| 6911 |
|
| 6912 |
|
| 6913 |
|
| 6914 |
if (!p || !data || (datalen < 1)) { |
| 6915 |
errno = EINVAL; |
| 6916 |
return -1; |
| 6917 |
} |
| 6918 |
|
| 6919 |
switch (option) { |
| 6920 |
case AST_OPTION_TXGAIN: |
| 6921 |
scp = (signed char *) data; |
| 6922 |
idx = dahdi_get_index(chan, p, 0); |
| 6923 |
if (idx < 0) { |
| 6924 |
ast_log(LOG_WARNING, "No index in TXGAIN?\n"); |
| 6925 |
return -1; |
| 6926 |
} |
| 6927 |
ast_debug(1, "Setting actual tx gain on %s to %f\n", ast_channel_name(chan), p->txgain + (float) *scp); |
| 6928 |
return set_actual_txgain(p->subs[idx].dfd, p->txgain + (float) *scp, p->txdrc, p->law); |
| 6929 |
case AST_OPTION_RXGAIN: |
| 6930 |
scp = (signed char *) data; |
| 6931 |
idx = dahdi_get_index(chan, p, 0); |
| 6932 |
if (idx < 0) { |
| 6933 |
ast_log(LOG_WARNING, "No index in RXGAIN?\n"); |
| 6934 |
return -1; |
| 6935 |
} |
| 6936 |
ast_debug(1, "Setting actual rx gain on %s to %f\n", ast_channel_name(chan), p->rxgain + (float) *scp); |
| 6937 |
return set_actual_rxgain(p->subs[idx].dfd, p->rxgain + (float) *scp, p->rxdrc, p->law); |
| 6938 |
case AST_OPTION_TONE_VERIFY: |
| 6939 |
if (!p->dsp) |
| 6940 |
break; |
| 6941 |
cp = (char *) data; |
| 6942 |
switch (*cp) { |
| 6943 |
case 1: |
| 6944 |
ast_debug(1, "Set option TONE VERIFY, mode: MUTECONF(1) on %s\n",ast_channel_name(chan)); |
| 6945 |
ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MUTECONF | p->dtmfrelax); |
| 6946 |
break; |
| 6947 |
case 2: |
| 6948 |
ast_debug(1, "Set option TONE VERIFY, mode: MUTECONF/MAX(2) on %s\n",ast_channel_name(chan)); |
| 6949 |
ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX | p->dtmfrelax); |
| 6950 |
break; |
| 6951 |
default: |
| 6952 |
ast_debug(1, "Set option TONE VERIFY, mode: OFF(0) on %s\n",ast_channel_name(chan)); |
| 6953 |
ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax); |
| 6954 |
break; |
| 6955 |
} |
| 6956 |
break; |
| 6957 |
case AST_OPTION_TDD: |
| 6958 |
|
| 6959 |
cp = (char *) data; |
| 6960 |
p->mate = 0; |
| 6961 |
if (!*cp) { |
| 6962 |
ast_debug(1, "Set option TDD MODE, value: OFF(0) on %s\n",ast_channel_name(chan)); |
| 6963 |
if (p->tdd) |
| 6964 |
tdd_free(p->tdd); |
| 6965 |
p->tdd = 0; |
| 6966 |
break; |
| 6967 |
} |
| 6968 |
ast_debug(1, "Set option TDD MODE, value: %s(%d) on %s\n", |
| 6969 |
(*cp == 2) ? "MATE" : "ON", (int) *cp, ast_channel_name(chan)); |
| 6970 |
dahdi_ec_disable(p); |
| 6971 |
|
| 6972 |
if (!p->didtdd) { |
| 6973 |
unsigned char mybuf[41000]; |
| 6974 |
unsigned char *buf; |
| 6975 |
int size, res, fd, len; |
| 6976 |
struct pollfd fds[1]; |
| 6977 |
|
| 6978 |
buf = mybuf; |
| 6979 |
memset(buf, 0x7f, sizeof(mybuf)); |
| 6980 |
ast_tdd_gen_ecdisa(buf + 16000, 16000); |
| 6981 |
len = 40000; |
| 6982 |
idx = dahdi_get_index(chan, p, 0); |
| 6983 |
if (idx < 0) { |
| 6984 |
ast_log(LOG_WARNING, "No index in TDD?\n"); |
| 6985 |
return -1; |
| 6986 |
} |
| 6987 |
fd = p->subs[idx].dfd; |
| 6988 |
while (len) { |
| 6989 |
if (ast_check_hangup(chan)) |
| 6990 |
return -1; |
| 6991 |
size = len; |
| 6992 |
if (size > READ_SIZE) |
| 6993 |
size = READ_SIZE; |
| 6994 |
fds[0].fd = fd; |
| 6995 |
fds[0].events = POLLPRI | POLLOUT; |
| 6996 |
fds[0].revents = 0; |
| 6997 |
res = poll(fds, 1, -1); |
| 6998 |
if (!res) { |
| 6999 |
ast_debug(1, "poll (for write) ret. 0 on channel %d\n", p->channel); |
| 7000 |
continue; |
| 7001 |
} |
| 7002 |
|
| 7003 |
if (fds[0].revents & POLLPRI) |
| 7004 |
return -1; |
| 7005 |
if (!(fds[0].revents & POLLOUT)) { |
| 7006 |
ast_debug(1, "write fd not ready on channel %d\n", p->channel); |
| 7007 |
continue; |
| 7008 |
} |
| 7009 |
res = write(fd, buf, size); |
| 7010 |
if (res != size) { |
| 7011 |
if (res == -1) return -1; |
| 7012 |
ast_debug(1, "Write returned %d (%s) on channel %d\n", res, strerror(errno), p->channel); |
| 7013 |
break; |
| 7014 |
} |
| 7015 |
len -= size; |
| 7016 |
buf += size; |
| 7017 |
} |
| 7018 |
p->didtdd = 1; |
| 7019 |
} |
| 7020 |
if (*cp == 2) { |
| 7021 |
if (p->tdd) |
| 7022 |
tdd_free(p->tdd); |
| 7023 |
p->tdd = 0; |
| 7024 |
p->mate = 1; |
| 7025 |
break; |
| 7026 |
} |
| 7027 |
if (!p->tdd) { |
| 7028 |
p->tdd = tdd_new(); |
| 7029 |
} |
| 7030 |
break; |
| 7031 |
case AST_OPTION_RELAXDTMF: |
| 7032 |
if (!p->dsp) |
| 7033 |
break; |
| 7034 |
cp = (char *) data; |
| 7035 |
ast_debug(1, "Set option RELAX DTMF, value: %s(%d) on %s\n", |
| 7036 |
*cp ? "ON" : "OFF", (int) *cp, ast_channel_name(chan)); |
| 7037 |
ast_dsp_set_digitmode(p->dsp, ((*cp) ? DSP_DIGITMODE_RELAXDTMF : DSP_DIGITMODE_DTMF) | p->dtmfrelax); |
| 7038 |
break; |
| 7039 |
case AST_OPTION_AUDIO_MODE: |
| 7040 |
#if defined(HAVE_PRI) |
| 7041 |
if (dahdi_sig_pri_lib_handles(p->sig) |
| 7042 |
&& ((struct sig_pri_chan *) p->sig_pvt)->no_b_channel) { |
| 7043 |
|
| 7044 |
break; |
| 7045 |
} |
| 7046 |
#endif |
| 7047 |
|
| 7048 |
cp = (char *) data; |
| 7049 |
if (!*cp) { |
| 7050 |
ast_debug(1, "Set option AUDIO MODE, value: OFF(0) on %s\n", ast_channel_name(chan)); |
| 7051 |
x = 0; |
| 7052 |
dahdi_ec_disable(p); |
| 7053 |
} else { |
| 7054 |
ast_debug(1, "Set option AUDIO MODE, value: ON(1) on %s\n", ast_channel_name(chan)); |
| 7055 |
x = 1; |
| 7056 |
} |
| 7057 |
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &x) == -1) |
| 7058 |
ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d: %s\n", p->channel, x, strerror(errno)); |
| 7059 |
break; |
| 7060 |
case AST_OPTION_OPRMODE: |
| 7061 |
oprmode = (struct oprmode *) data; |
| 7062 |
|
| 7063 |
if (strcasecmp(ast_channel_tech(chan)->type, ast_channel_tech(oprmode->peer)->type)) { |
| 7064 |
ast_log(LOG_NOTICE, "Operator mode not supported on %s to %s calls.\n", |
| 7065 |
ast_channel_tech(chan)->type, ast_channel_tech(oprmode->peer)->type); |
| 7066 |
errno = EINVAL; |
| 7067 |
return -1; |
| 7068 |
} |
| 7069 |
pp = ast_channel_tech_pvt(oprmode->peer); |
| 7070 |
p->oprmode = pp->oprmode = 0; |
| 7071 |
|
| 7072 |
p->oprpeer = pp; |
| 7073 |
pp->oprpeer = p; |
| 7074 |
|
| 7075 |
if (oprmode->mode) |
| 7076 |
{ |
| 7077 |
pp->oprmode = oprmode->mode; |
| 7078 |
p->oprmode = -oprmode->mode; |
| 7079 |
} |
| 7080 |
ast_debug(1, "Set Operator Services mode, value: %d on %s/%s\n", |
| 7081 |
oprmode->mode, ast_channel_name(chan),ast_channel_name(oprmode->peer)); |
| 7082 |
break; |
| 7083 |
case AST_OPTION_ECHOCAN: |
| 7084 |
cp = (char *) data; |
| 7085 |
if (*cp) { |
| 7086 |
ast_debug(1, "Enabling echo cancellation on %s\n", ast_channel_name(chan)); |
| 7087 |
dahdi_ec_enable(p); |
| 7088 |
} else { |
| 7089 |
ast_debug(1, "Disabling echo cancellation on %s\n", ast_channel_name(chan)); |
| 7090 |
dahdi_ec_disable(p); |
| 7091 |
} |
| 7092 |
break; |
| 7093 |
case AST_OPTION_DIGIT_DETECT: |
| 7094 |
cp = (char *) data; |
| 7095 |
ast_debug(1, "%sabling digit detection on %s\n", *cp ? "En" : "Dis", ast_channel_name(chan)); |
| 7096 |
if (*cp) { |
| 7097 |
dahdi_dtmf_detect_enable(p); |
| 7098 |
} else { |
| 7099 |
dahdi_dtmf_detect_disable(p); |
| 7100 |
} |
| 7101 |
break; |
| 7102 |
case AST_OPTION_FAX_DETECT: |
| 7103 |
cp = (char *) data; |
| 7104 |
if (p->dsp) { |
| 7105 |
ast_debug(1, "%sabling fax tone detection on %s\n", *cp ? "En" : "Dis", ast_channel_name(chan)); |
| 7106 |
if (*cp) { |
| 7107 |
p->dsp_features |= DSP_FEATURE_FAX_DETECT; |
| 7108 |
} else { |
| 7109 |
p->dsp_features &= ~DSP_FEATURE_FAX_DETECT; |
| 7110 |
} |
| 7111 |
ast_dsp_set_features(p->dsp, p->dsp_features); |
| 7112 |
} |
| 7113 |
break; |
| 7114 |
default: |
| 7115 |
return -1; |
| 7116 |
} |
| 7117 |
errno = 0; |
| 7118 |
|
| 7119 |
return 0; |
| 7120 |
} |
| 7121 |
|
| 7122 |
static int dahdi_func_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len) |
| 7123 |
{ |
| 7124 |
struct dahdi_pvt *p = ast_channel_tech_pvt(chan); |
| 7125 |
int res = 0; |
| 7126 |
|
| 7127 |
if (!p) { |
| 7128 |
|
| 7129 |
*buf = '\0'; |
| 7130 |
return -1; |
| 7131 |
} |
| 7132 |
|
| 7133 |
if (!strcasecmp(data, "rxgain")) { |
| 7134 |
ast_mutex_lock(&p->lock); |
| 7135 |
snprintf(buf, len, "%f", p->rxgain); |
| 7136 |
ast_mutex_unlock(&p->lock); |
| 7137 |
} else if (!strcasecmp(data, "txgain")) { |
| 7138 |
ast_mutex_lock(&p->lock); |
| 7139 |
snprintf(buf, len, "%f", p->txgain); |
| 7140 |
ast_mutex_unlock(&p->lock); |
| 7141 |
} else if (!strcasecmp(data, "dahdi_channel")) { |
| 7142 |
ast_mutex_lock(&p->lock); |
| 7143 |
snprintf(buf, len, "%d", p->channel); |
| 7144 |
ast_mutex_unlock(&p->lock); |
| 7145 |
} else if (!strcasecmp(data, "dahdi_span")) { |
| 7146 |
ast_mutex_lock(&p->lock); |
| 7147 |
snprintf(buf, len, "%d", p->span); |
| 7148 |
ast_mutex_unlock(&p->lock); |
| 7149 |
} else if (!strcasecmp(data, "dahdi_group")) { |
| 7150 |
ast_mutex_lock(&p->lock); |
| 7151 |
snprintf(buf, len, "%llu", p->group); |
| 7152 |
ast_mutex_unlock(&p->lock); |
| 7153 |
} else if (!strcasecmp(data, "dahdi_type")) { |
| 7154 |
ast_mutex_lock(&p->lock); |
| 7155 |
switch (p->sig) { |
| 7156 |
#if defined(HAVE_OPENR2) |
| 7157 |
case SIG_MFCR2: |
| 7158 |
ast_copy_string(buf, "mfc/r2", len); |
| 7159 |
break; |
| 7160 |
#endif |
| 7161 |
#if defined(HAVE_PRI) |
| 7162 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 7163 |
ast_copy_string(buf, "pri", len); |
| 7164 |
break; |
| 7165 |
#endif |
| 7166 |
case 0: |
| 7167 |
ast_copy_string(buf, "pseudo", len); |
| 7168 |
break; |
| 7169 |
#if defined(HAVE_SS7) |
| 7170 |
case SIG_SS7: |
| 7171 |
ast_copy_string(buf, "ss7", len); |
| 7172 |
break; |
| 7173 |
#endif |
| 7174 |
default: |
| 7175 |
|
| 7176 |
ast_copy_string(buf, "analog", len); |
| 7177 |
break; |
| 7178 |
} |
| 7179 |
ast_mutex_unlock(&p->lock); |
| 7180 |
#if defined(HAVE_PRI) |
| 7181 |
#if defined(HAVE_PRI_REVERSE_CHARGE) |
| 7182 |
} else if (!strcasecmp(data, "reversecharge")) { |
| 7183 |
ast_mutex_lock(&p->lock); |
| 7184 |
switch (p->sig) { |
| 7185 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 7186 |
snprintf(buf, len, "%d", ((struct sig_pri_chan *) p->sig_pvt)->reverse_charging_indication); |
| 7187 |
break; |
| 7188 |
default: |
| 7189 |
*buf = '\0'; |
| 7190 |
res = -1; |
| 7191 |
break; |
| 7192 |
} |
| 7193 |
ast_mutex_unlock(&p->lock); |
| 7194 |
#endif |
| 7195 |
#if defined(HAVE_PRI_SETUP_KEYPAD) |
| 7196 |
} else if (!strcasecmp(data, "keypad_digits")) { |
| 7197 |
ast_mutex_lock(&p->lock); |
| 7198 |
switch (p->sig) { |
| 7199 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 7200 |
ast_copy_string(buf, ((struct sig_pri_chan *) p->sig_pvt)->keypad_digits, |
| 7201 |
len); |
| 7202 |
break; |
| 7203 |
default: |
| 7204 |
*buf = '\0'; |
| 7205 |
res = -1; |
| 7206 |
break; |
| 7207 |
} |
| 7208 |
ast_mutex_unlock(&p->lock); |
| 7209 |
#endif |
| 7210 |
} else if (!strcasecmp(data, "no_media_path")) { |
| 7211 |
ast_mutex_lock(&p->lock); |
| 7212 |
switch (p->sig) { |
| 7213 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 7214 |
|
| 7215 |
|
| 7216 |
|
| 7217 |
|
| 7218 |
snprintf(buf, len, "%d", ((struct sig_pri_chan *) p->sig_pvt)->no_b_channel); |
| 7219 |
break; |
| 7220 |
default: |
| 7221 |
*buf = '\0'; |
| 7222 |
res = -1; |
| 7223 |
break; |
| 7224 |
} |
| 7225 |
ast_mutex_unlock(&p->lock); |
| 7226 |
#endif |
| 7227 |
} else if (!strcasecmp(data, "dialmode")) { |
| 7228 |
struct analog_pvt *analog_p; |
| 7229 |
ast_mutex_lock(&p->lock); |
| 7230 |
analog_p = p->sig_pvt; |
| 7231 |
|
| 7232 |
if (dahdi_analog_lib_handles(p->sig, 0, 0) && analog_p) { |
| 7233 |
switch (analog_p->dialmode) { |
| 7234 |
case ANALOG_DIALMODE_BOTH: |
| 7235 |
ast_copy_string(buf, "both", len); |
| 7236 |
break; |
| 7237 |
case ANALOG_DIALMODE_PULSE: |
| 7238 |
ast_copy_string(buf, "pulse", len); |
| 7239 |
break; |
| 7240 |
case ANALOG_DIALMODE_DTMF: |
| 7241 |
ast_copy_string(buf, "dtmf", len); |
| 7242 |
break; |
| 7243 |
case ANALOG_DIALMODE_NONE: |
| 7244 |
ast_copy_string(buf, "none", len); |
| 7245 |
break; |
| 7246 |
} |
| 7247 |
} else { |
| 7248 |
ast_log(LOG_WARNING, "%s only supported on analog channels\n", data); |
| 7249 |
*buf = '\0'; |
| 7250 |
res = -1; |
| 7251 |
} |
| 7252 |
ast_mutex_unlock(&p->lock); |
| 7253 |
} else { |
| 7254 |
*buf = '\0'; |
| 7255 |
res = -1; |
| 7256 |
} |
| 7257 |
|
| 7258 |
return res; |
| 7259 |
} |
| 7260 |
|
| 7261 |
|
| 7262 |
static int parse_buffers_policy(const char *parse, int *num_buffers, int *policy) |
| 7263 |
{ |
| 7264 |
int res; |
| 7265 |
char policy_str[21] = ""; |
| 7266 |
|
| 7267 |
if ((res = sscanf(parse, "%30d,%20s", num_buffers, policy_str)) != 2) { |
| 7268 |
ast_log(LOG_WARNING, "Parsing buffer string '%s' failed.\n", parse); |
| 7269 |
return 1; |
| 7270 |
} |
| 7271 |
if (*num_buffers < 0) { |
| 7272 |
ast_log(LOG_WARNING, "Invalid buffer count given '%d'.\n", *num_buffers); |
| 7273 |
return -1; |
| 7274 |
} |
| 7275 |
if (!strcasecmp(policy_str, "full")) { |
| 7276 |
*policy = DAHDI_POLICY_WHEN_FULL; |
| 7277 |
} else if (!strcasecmp(policy_str, "immediate")) { |
| 7278 |
*policy = DAHDI_POLICY_IMMEDIATE; |
| 7279 |
#if defined(HAVE_DAHDI_HALF_FULL) |
| 7280 |
} else if (!strcasecmp(policy_str, "half")) { |
| 7281 |
*policy = DAHDI_POLICY_HALF_FULL; |
| 7282 |
#endif |
| 7283 |
} else { |
| 7284 |
ast_log(LOG_WARNING, "Invalid policy name given '%s'.\n", policy_str); |
| 7285 |
return -1; |
| 7286 |
} |
| 7287 |
|
| 7288 |
return 0; |
| 7289 |
} |
| 7290 |
|
| 7291 |
static int dahdi_func_write(struct ast_channel *chan, const char *function, char *data, const char *value) |
| 7292 |
{ |
| 7293 |
struct dahdi_pvt *p = ast_channel_tech_pvt(chan); |
| 7294 |
int res = 0; |
| 7295 |
|
| 7296 |
if (!p) { |
| 7297 |
|
| 7298 |
return -1; |
| 7299 |
} |
| 7300 |
|
| 7301 |
if (!strcasecmp(data, "buffers")) { |
| 7302 |
int num_bufs, policy; |
| 7303 |
|
| 7304 |
if (!(parse_buffers_policy(value, &num_bufs, &policy))) { |
| 7305 |
struct dahdi_bufferinfo bi = { |
| 7306 |
.txbufpolicy = policy, |
| 7307 |
.rxbufpolicy = policy, |
| 7308 |
.bufsize = p->bufsize, |
| 7309 |
.numbufs = num_bufs, |
| 7310 |
}; |
| 7311 |
int bpres; |
| 7312 |
|
| 7313 |
if ((bpres = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) { |
| 7314 |
ast_log(LOG_WARNING, "Channel '%d' unable to override buffer policy: %s\n", p->channel, strerror(errno)); |
| 7315 |
} else { |
| 7316 |
p->bufferoverrideinuse = 1; |
| 7317 |
} |
| 7318 |
} else { |
| 7319 |
res = -1; |
| 7320 |
} |
| 7321 |
} else if (!strcasecmp(data, "echocan_mode")) { |
| 7322 |
if (!strcasecmp(value, "on")) { |
| 7323 |
ast_mutex_lock(&p->lock); |
| 7324 |
dahdi_ec_enable(p); |
| 7325 |
ast_mutex_unlock(&p->lock); |
| 7326 |
} else if (!strcasecmp(value, "off")) { |
| 7327 |
ast_mutex_lock(&p->lock); |
| 7328 |
dahdi_ec_disable(p); |
| 7329 |
ast_mutex_unlock(&p->lock); |
| 7330 |
#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE |
| 7331 |
} else if (!strcasecmp(value, "fax")) { |
| 7332 |
int blah = 1; |
| 7333 |
|
| 7334 |
ast_mutex_lock(&p->lock); |
| 7335 |
if (!p->echocanon) { |
| 7336 |
dahdi_ec_enable(p); |
| 7337 |
} |
| 7338 |
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_ECHOCANCEL_FAX_MODE, &blah)) { |
| 7339 |
ast_log(LOG_WARNING, "Unable to place echocan into fax mode on channel %d: %s\n", p->channel, strerror(errno)); |
| 7340 |
} |
| 7341 |
ast_mutex_unlock(&p->lock); |
| 7342 |
} else if (!strcasecmp(value, "voice")) { |
| 7343 |
int blah = 0; |
| 7344 |
|
| 7345 |
ast_mutex_lock(&p->lock); |
| 7346 |
if (!p->echocanon) { |
| 7347 |
dahdi_ec_enable(p); |
| 7348 |
} |
| 7349 |
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_ECHOCANCEL_FAX_MODE, &blah)) { |
| 7350 |
ast_log(LOG_WARNING, "Unable to place echocan into voice mode on channel %d: %s\n", p->channel, strerror(errno)); |
| 7351 |
} |
| 7352 |
ast_mutex_unlock(&p->lock); |
| 7353 |
#endif |
| 7354 |
} else { |
| 7355 |
ast_log(LOG_WARNING, "Unsupported value '%s' provided for '%s' item.\n", value, data); |
| 7356 |
res = -1; |
| 7357 |
} |
| 7358 |
} else if (!strcasecmp(data, "dialmode")) { |
| 7359 |
struct analog_pvt *analog_p; |
| 7360 |
|
| 7361 |
ast_mutex_lock(&p->lock); |
| 7362 |
analog_p = p->sig_pvt; |
| 7363 |
if (!dahdi_analog_lib_handles(p->sig, 0, 0) || !analog_p) { |
| 7364 |
ast_log(LOG_WARNING, "%s only supported on analog channels\n", data); |
| 7365 |
ast_mutex_unlock(&p->lock); |
| 7366 |
return -1; |
| 7367 |
} |
| 7368 |
|
| 7369 |
if (!strcasecmp(value, "pulse")) { |
| 7370 |
analog_p->dialmode = ANALOG_DIALMODE_PULSE; |
| 7371 |
} else if (!strcasecmp(value, "dtmf") || !strcasecmp(value, "tone")) { |
| 7372 |
analog_p->dialmode = ANALOG_DIALMODE_DTMF; |
| 7373 |
} else if (!strcasecmp(value, "none")) { |
| 7374 |
analog_p->dialmode = ANALOG_DIALMODE_NONE; |
| 7375 |
} else if (!strcasecmp(value, "both")) { |
| 7376 |
analog_p->dialmode = ANALOG_DIALMODE_BOTH; |
| 7377 |
} else { |
| 7378 |
ast_log(LOG_WARNING, "'%s' is an invalid setting for %s\n", value, data); |
| 7379 |
res = -1; |
| 7380 |
} |
| 7381 |
ast_mutex_unlock(&p->lock); |
| 7382 |
} else if (!strcasecmp(data, "waitfordialtone")) { |
| 7383 |
if (ast_strlen_zero(value)) { |
| 7384 |
ast_log(LOG_WARNING, "waitfordialtone requires a duration in ms\n"); |
| 7385 |
return -1; |
| 7386 |
} |
| 7387 |
|
| 7388 |
ast_mutex_lock(&p->lock); |
| 7389 |
if (!CANPROGRESSDETECT(p)) { |
| 7390 |
ast_log(LOG_WARNING, "%s only supported on analog trunks\n", data); |
| 7391 |
ast_mutex_unlock(&p->lock); |
| 7392 |
return -1; |
| 7393 |
} |
| 7394 |
|
| 7395 |
p->waitfordialtonetemp = atoi(value); |
| 7396 |
ast_mutex_unlock(&p->lock); |
| 7397 |
} else { |
| 7398 |
res = -1; |
| 7399 |
} |
| 7400 |
|
| 7401 |
return res; |
| 7402 |
} |
| 7403 |
|
| 7404 |
void dahdi_master_slave_unlink(struct dahdi_pvt *slave, struct dahdi_pvt *master, int needlock) |
| 7405 |
{ |
| 7406 |
|
| 7407 |
int x; |
| 7408 |
int hasslaves; |
| 7409 |
if (!master) |
| 7410 |
return; |
| 7411 |
if (needlock) { |
| 7412 |
ast_mutex_lock(&master->lock); |
| 7413 |
if (slave) { |
| 7414 |
while (ast_mutex_trylock(&slave->lock)) { |
| 7415 |
DEADLOCK_AVOIDANCE(&master->lock); |
| 7416 |
} |
| 7417 |
} |
| 7418 |
} |
| 7419 |
hasslaves = 0; |
| 7420 |
for (x = 0; x < MAX_SLAVES; x++) { |
| 7421 |
if (master->slaves[x]) { |
| 7422 |
if (!slave || (master->slaves[x] == slave)) { |
| 7423 |
|
| 7424 |
ast_debug(1, "Unlinking slave %d from %d\n", master->slaves[x]->channel, master->channel); |
| 7425 |
conf_del(master, &master->slaves[x]->subs[SUB_REAL], SUB_REAL); |
| 7426 |
conf_del(master->slaves[x], &master->subs[SUB_REAL], SUB_REAL); |
| 7427 |
master->slaves[x]->master = NULL; |
| 7428 |
master->slaves[x] = NULL; |
| 7429 |
} else |
| 7430 |
hasslaves = 1; |
| 7431 |
} |
| 7432 |
if (!hasslaves) |
| 7433 |
master->inconference = 0; |
| 7434 |
} |
| 7435 |
if (!slave) { |
| 7436 |
if (master->master) { |
| 7437 |
|
| 7438 |
conf_del(master->master, &master->subs[SUB_REAL], SUB_REAL); |
| 7439 |
conf_del(master, &master->master->subs[SUB_REAL], SUB_REAL); |
| 7440 |
hasslaves = 0; |
| 7441 |
for (x = 0; x < MAX_SLAVES; x++) { |
| 7442 |
if (master->master->slaves[x] == master) |
| 7443 |
master->master->slaves[x] = NULL; |
| 7444 |
else if (master->master->slaves[x]) |
| 7445 |
hasslaves = 1; |
| 7446 |
} |
| 7447 |
if (!hasslaves) |
| 7448 |
master->master->inconference = 0; |
| 7449 |
} |
| 7450 |
master->master = NULL; |
| 7451 |
} |
| 7452 |
dahdi_conf_update(master); |
| 7453 |
if (needlock) { |
| 7454 |
if (slave) |
| 7455 |
ast_mutex_unlock(&slave->lock); |
| 7456 |
ast_mutex_unlock(&master->lock); |
| 7457 |
} |
| 7458 |
} |
| 7459 |
|
| 7460 |
void dahdi_master_slave_link(struct dahdi_pvt *slave, struct dahdi_pvt *master) |
| 7461 |
{ |
| 7462 |
int x; |
| 7463 |
if (!slave || !master) { |
| 7464 |
ast_log(LOG_WARNING, "Tried to link to/from NULL??\n"); |
| 7465 |
return; |
| 7466 |
} |
| 7467 |
for (x = 0; x < MAX_SLAVES; x++) { |
| 7468 |
if (!master->slaves[x]) { |
| 7469 |
master->slaves[x] = slave; |
| 7470 |
break; |
| 7471 |
} |
| 7472 |
} |
| 7473 |
if (x >= MAX_SLAVES) { |
| 7474 |
ast_log(LOG_WARNING, "Replacing slave %d with new slave, %d\n", master->slaves[MAX_SLAVES - 1]->channel, slave->channel); |
| 7475 |
master->slaves[MAX_SLAVES - 1] = slave; |
| 7476 |
} |
| 7477 |
if (slave->master) |
| 7478 |
ast_log(LOG_WARNING, "Replacing master %d with new master, %d\n", slave->master->channel, master->channel); |
| 7479 |
slave->master = master; |
| 7480 |
|
| 7481 |
ast_debug(1, "Making %d slave to master %d at %d\n", slave->channel, master->channel, x); |
| 7482 |
} |
| 7483 |
|
| 7484 |
static int dahdi_fixup(struct ast_channel *oldchan, struct ast_channel *newchan) |
| 7485 |
{ |
| 7486 |
struct dahdi_pvt *p = ast_channel_tech_pvt(newchan); |
| 7487 |
int x; |
| 7488 |
|
| 7489 |
ast_mutex_lock(&p->lock); |
| 7490 |
|
| 7491 |
ast_debug(1, "New owner for channel %d is %s\n", p->channel, ast_channel_name(newchan)); |
| 7492 |
if (p->owner == oldchan) { |
| 7493 |
p->owner = newchan; |
| 7494 |
} |
| 7495 |
for (x = 0; x < 3; x++) { |
| 7496 |
if (p->subs[x].owner == oldchan) { |
| 7497 |
if (!x) { |
| 7498 |
dahdi_master_slave_unlink(NULL, p, 0); |
| 7499 |
} |
| 7500 |
p->subs[x].owner = newchan; |
| 7501 |
} |
| 7502 |
} |
| 7503 |
if (dahdi_analog_lib_handles(p->sig, p->radio, p->oprmode)) { |
| 7504 |
analog_fixup(oldchan, newchan, p->sig_pvt); |
| 7505 |
#if defined(HAVE_PRI) |
| 7506 |
} else if (dahdi_sig_pri_lib_handles(p->sig)) { |
| 7507 |
sig_pri_fixup(oldchan, newchan, p->sig_pvt); |
| 7508 |
#endif |
| 7509 |
#if defined(HAVE_SS7) |
| 7510 |
} else if (p->sig == SIG_SS7) { |
| 7511 |
sig_ss7_fixup(oldchan, newchan, p->sig_pvt); |
| 7512 |
#endif |
| 7513 |
} |
| 7514 |
dahdi_conf_update(p); |
| 7515 |
|
| 7516 |
ast_mutex_unlock(&p->lock); |
| 7517 |
|
| 7518 |
if (ast_channel_state(newchan) == AST_STATE_RINGING) { |
| 7519 |
dahdi_indicate(newchan, AST_CONTROL_RINGING, NULL, 0); |
| 7520 |
} |
| 7521 |
return 0; |
| 7522 |
} |
| 7523 |
|
| 7524 |
static int dahdi_ring_phone(struct dahdi_pvt *p) |
| 7525 |
{ |
| 7526 |
int x; |
| 7527 |
int res; |
| 7528 |
|
| 7529 |
x = 0; |
| 7530 |
x = DAHDI_ONHOOK; |
| 7531 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x); |
| 7532 |
do { |
| 7533 |
x = DAHDI_RING; |
| 7534 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x); |
| 7535 |
if (res) { |
| 7536 |
switch (errno) { |
| 7537 |
case EBUSY: |
| 7538 |
case EINTR: |
| 7539 |
|
| 7540 |
usleep(10000); |
| 7541 |
continue; |
| 7542 |
case EINPROGRESS: |
| 7543 |
res = 0; |
| 7544 |
break; |
| 7545 |
default: |
| 7546 |
ast_log(LOG_WARNING, "Couldn't ring the phone: %s\n", strerror(errno)); |
| 7547 |
res = 0; |
| 7548 |
} |
| 7549 |
} |
| 7550 |
} while (res); |
| 7551 |
return res; |
| 7552 |
} |
| 7553 |
|
| 7554 |
static void *analog_ss_thread(void *data); |
| 7555 |
|
| 7556 |
|
| 7557 |
|
| 7558 |
|
| 7559 |
|
| 7560 |
|
| 7561 |
|
| 7562 |
|
| 7563 |
|
| 7564 |
|
| 7565 |
|
| 7566 |
|
| 7567 |
|
| 7568 |
static int attempt_transfer(struct dahdi_pvt *p) |
| 7569 |
{ |
| 7570 |
struct ast_channel *owner_real; |
| 7571 |
struct ast_channel *owner_3way; |
| 7572 |
enum ast_transfer_result xfer_res; |
| 7573 |
int res = 0; |
| 7574 |
|
| 7575 |
owner_real = ast_channel_ref(p->subs[SUB_REAL].owner); |
| 7576 |
owner_3way = ast_channel_ref(p->subs[SUB_THREEWAY].owner); |
| 7577 |
|
| 7578 |
ast_verb(3, "TRANSFERRING %s to %s\n", |
| 7579 |
ast_channel_name(owner_3way), ast_channel_name(owner_real)); |
| 7580 |
|
| 7581 |
ast_channel_unlock(owner_real); |
| 7582 |
ast_channel_unlock(owner_3way); |
| 7583 |
ast_mutex_unlock(&p->lock); |
| 7584 |
|
| 7585 |
xfer_res = ast_bridge_transfer_attended(owner_3way, owner_real); |
| 7586 |
if (xfer_res != AST_BRIDGE_TRANSFER_SUCCESS) { |
| 7587 |
ast_softhangup(owner_3way, AST_SOFTHANGUP_DEV); |
| 7588 |
res = -1; |
| 7589 |
} |
| 7590 |
|
| 7591 |
|
| 7592 |
ast_channel_lock(owner_real); |
| 7593 |
ast_mutex_lock(&p->lock); |
| 7594 |
|
| 7595 |
ast_channel_unref(owner_real); |
| 7596 |
ast_channel_unref(owner_3way); |
| 7597 |
|
| 7598 |
return res; |
| 7599 |
} |
| 7600 |
|
| 7601 |
static int check_for_conference(struct dahdi_pvt *p) |
| 7602 |
{ |
| 7603 |
struct dahdi_confinfo ci; |
| 7604 |
|
| 7605 |
if (p->master || (p->confno > -1)) |
| 7606 |
return 0; |
| 7607 |
memset(&ci, 0, sizeof(ci)); |
| 7608 |
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_GETCONF, &ci)) { |
| 7609 |
ast_log(LOG_WARNING, "Failed to get conference info on channel %d: %s\n", p->channel, strerror(errno)); |
| 7610 |
return 0; |
| 7611 |
} |
| 7612 |
|
| 7613 |
|
| 7614 |
|
| 7615 |
if ((p->subs[SUB_REAL].curconf.confno != ci.confno) || (p->subs[SUB_REAL].curconf.confmode != ci.confmode)) { |
| 7616 |
ast_verb(3, "Avoiding 3-way call when in an external conference\n"); |
| 7617 |
return 1; |
| 7618 |
} |
| 7619 |
return 0; |
| 7620 |
} |
| 7621 |
|
| 7622 |
|
| 7623 |
|
| 7624 |
|
| 7625 |
|
| 7626 |
|
| 7627 |
static int get_alarms(struct dahdi_pvt *p) |
| 7628 |
{ |
| 7629 |
int res; |
| 7630 |
struct dahdi_spaninfo zi; |
| 7631 |
struct dahdi_params params; |
| 7632 |
|
| 7633 |
memset(&zi, 0, sizeof(zi)); |
| 7634 |
zi.spanno = p->span; |
| 7635 |
|
| 7636 |
if ((res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SPANSTAT, &zi)) >= 0) { |
| 7637 |
if (zi.alarms != DAHDI_ALARM_NONE) |
| 7638 |
return zi.alarms; |
| 7639 |
} else { |
| 7640 |
ast_log(LOG_WARNING, "Unable to determine alarm on channel %d: %s\n", p->channel, strerror(errno)); |
| 7641 |
return 0; |
| 7642 |
} |
| 7643 |
|
| 7644 |
|
| 7645 |
memset(¶ms, 0, sizeof(params)); |
| 7646 |
if ((res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, ¶ms)) >= 0) |
| 7647 |
return params.chan_alarms; |
| 7648 |
|
| 7649 |
ast_log(LOG_WARNING, "Unable to determine alarm on channel %d\n", p->channel); |
| 7650 |
|
| 7651 |
return DAHDI_ALARM_NONE; |
| 7652 |
} |
| 7653 |
|
| 7654 |
static void dahdi_handle_dtmf(struct ast_channel *ast, int idx, struct ast_frame **dest) |
| 7655 |
{ |
| 7656 |
struct dahdi_pvt *p = ast_channel_tech_pvt(ast); |
| 7657 |
struct ast_frame *f = *dest; |
| 7658 |
|
| 7659 |
ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n", |
| 7660 |
f->frametype == AST_FRAME_DTMF_BEGIN ? "Begin" : "End", |
| 7661 |
(unsigned)f->subclass.integer, f->subclass.integer, ast_channel_name(ast)); |
| 7662 |
|
| 7663 |
if (p->confirmanswer) { |
| 7664 |
if (f->frametype == AST_FRAME_DTMF_END) { |
| 7665 |
ast_debug(1, "Confirm answer on %s!\n", ast_channel_name(ast)); |
| 7666 |
|
| 7667 |
|
| 7668 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 7669 |
p->subs[idx].f.subclass.integer = AST_CONTROL_ANSWER; |
| 7670 |
|
| 7671 |
p->confirmanswer = 0; |
| 7672 |
} else { |
| 7673 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 7674 |
p->subs[idx].f.subclass.integer = 0; |
| 7675 |
} |
| 7676 |
*dest = &p->subs[idx].f; |
| 7677 |
} else if (p->callwaitcas) { |
| 7678 |
if (f->frametype == AST_FRAME_DTMF_END) { |
| 7679 |
if ((f->subclass.integer == 'A') || (f->subclass.integer == 'D')) { |
| 7680 |
ast_debug(1, "Got some DTMF, but it's for the CAS\n"); |
| 7681 |
ast_free(p->cidspill); |
| 7682 |
p->cidspill = NULL; |
| 7683 |
send_cwcidspill(p); |
| 7684 |
} |
| 7685 |
p->callwaitcas = 0; |
| 7686 |
} |
| 7687 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 7688 |
p->subs[idx].f.subclass.integer = 0; |
| 7689 |
*dest = &p->subs[idx].f; |
| 7690 |
} else if (f->subclass.integer == 'f') { |
| 7691 |
if (f->frametype == AST_FRAME_DTMF_END) { |
| 7692 |
|
| 7693 |
if ((p->callprogress & CALLPROGRESS_FAX) && !p->faxhandled) { |
| 7694 |
|
| 7695 |
if (p->usefaxbuffers && !p->bufferoverrideinuse) { |
| 7696 |
struct dahdi_bufferinfo bi = { |
| 7697 |
.txbufpolicy = p->faxbuf_policy, |
| 7698 |
.bufsize = p->bufsize, |
| 7699 |
.numbufs = p->faxbuf_no |
| 7700 |
}; |
| 7701 |
int res; |
| 7702 |
|
| 7703 |
if ((res = ioctl(p->subs[idx].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) { |
| 7704 |
ast_log(LOG_WARNING, "Channel '%s' unable to set buffer policy, reason: %s\n", ast_channel_name(ast), strerror(errno)); |
| 7705 |
} else { |
| 7706 |
p->bufferoverrideinuse = 1; |
| 7707 |
} |
| 7708 |
} |
| 7709 |
p->faxhandled = 1; |
| 7710 |
if (p->dsp) { |
| 7711 |
p->dsp_features &= ~DSP_FEATURE_FAX_DETECT; |
| 7712 |
ast_dsp_set_features(p->dsp, p->dsp_features); |
| 7713 |
ast_debug(1, "Disabling FAX tone detection on %s after tone received\n", ast_channel_name(ast)); |
| 7714 |
} |
| 7715 |
if (strcmp(ast_channel_exten(ast), "fax")) { |
| 7716 |
const char *target_context = ast_channel_context(ast); |
| 7717 |
|
| 7718 |
|
| 7719 |
|
| 7720 |
|
| 7721 |
|
| 7722 |
|
| 7723 |
|
| 7724 |
|
| 7725 |
|
| 7726 |
ast_mutex_unlock(&p->lock); |
| 7727 |
ast_channel_unlock(ast); |
| 7728 |
if (ast_exists_extension(ast, target_context, "fax", 1, |
| 7729 |
S_COR(ast_channel_caller(ast)->id.number.valid, ast_channel_caller(ast)->id.number.str, NULL))) { |
| 7730 |
ast_verb(3, "Redirecting %s to fax extension\n", ast_channel_name(ast)); |
| 7731 |
|
| 7732 |
pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast_channel_exten(ast)); |
| 7733 |
if (ast_async_goto(ast, target_context, "fax", 1)) |
| 7734 |
ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast_channel_name(ast), target_context); |
| 7735 |
} else { |
| 7736 |
ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n"); |
| 7737 |
} |
| 7738 |
ast_channel_lock(ast); |
| 7739 |
ast_mutex_lock(&p->lock); |
| 7740 |
} else { |
| 7741 |
ast_debug(1, "Already in a fax extension, not redirecting\n"); |
| 7742 |
} |
| 7743 |
} else { |
| 7744 |
ast_debug(1, "Fax already handled\n"); |
| 7745 |
} |
| 7746 |
dahdi_confmute(p, 0); |
| 7747 |
} |
| 7748 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 7749 |
p->subs[idx].f.subclass.integer = 0; |
| 7750 |
*dest = &p->subs[idx].f; |
| 7751 |
} |
| 7752 |
} |
| 7753 |
|
| 7754 |
static void publish_span_alarm(int span, const char *alarm_txt) |
| 7755 |
{ |
| 7756 |
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); |
| 7757 |
|
| 7758 |
body = ast_json_pack("{s: i, s: s}", |
| 7759 |
"Span", span, |
| 7760 |
"Alarm", alarm_txt); |
| 7761 |
if (!body) { |
| 7762 |
return; |
| 7763 |
} |
| 7764 |
|
| 7765 |
ast_manager_publish_event("SpanAlarm", EVENT_FLAG_SYSTEM, body); |
| 7766 |
} |
| 7767 |
|
| 7768 |
static void publish_channel_alarm(int channel, const char *alarm_txt) |
| 7769 |
{ |
| 7770 |
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); |
| 7771 |
RAII_VAR(struct ast_str *, dahdi_chan, ast_str_create(32), ast_free); |
| 7772 |
if (!dahdi_chan) { |
| 7773 |
return; |
| 7774 |
} |
| 7775 |
|
| 7776 |
ast_str_set(&dahdi_chan, 0, "%d", channel); |
| 7777 |
body = ast_json_pack("{s: s, s: s}", |
| 7778 |
"DAHDIChannel", ast_str_buffer(dahdi_chan), |
| 7779 |
"Alarm", alarm_txt); |
| 7780 |
if (!body) { |
| 7781 |
return; |
| 7782 |
} |
| 7783 |
|
| 7784 |
ast_manager_publish_event("Alarm", EVENT_FLAG_SYSTEM, body); |
| 7785 |
} |
| 7786 |
|
| 7787 |
static void handle_alarms(struct dahdi_pvt *p, int alms) |
| 7788 |
{ |
| 7789 |
const char *alarm_str; |
| 7790 |
|
| 7791 |
#if defined(HAVE_PRI) |
| 7792 |
if (dahdi_sig_pri_lib_handles(p->sig) && sig_pri_is_alarm_ignored(p->pri)) { |
| 7793 |
return; |
| 7794 |
} |
| 7795 |
#endif |
| 7796 |
|
| 7797 |
alarm_str = alarm2str(alms); |
| 7798 |
if (report_alarms & REPORT_CHANNEL_ALARMS) { |
| 7799 |
ast_log(LOG_WARNING, "Detected alarm on channel %d: %s\n", p->channel, alarm_str); |
| 7800 |
publish_channel_alarm(p->channel, alarm_str); |
| 7801 |
} |
| 7802 |
|
| 7803 |
if (report_alarms & REPORT_SPAN_ALARMS && p->manages_span_alarms) { |
| 7804 |
ast_log(LOG_WARNING, "Detected alarm on span %d: %s\n", p->span, alarm_str); |
| 7805 |
publish_span_alarm(p->span, alarm_str); |
| 7806 |
} |
| 7807 |
} |
| 7808 |
|
| 7809 |
static struct ast_frame *dahdi_handle_event(struct ast_channel *ast) |
| 7810 |
{ |
| 7811 |
int res, x; |
| 7812 |
int idx, mysig; |
| 7813 |
char *c; |
| 7814 |
struct dahdi_pvt *p = ast_channel_tech_pvt(ast); |
| 7815 |
pthread_t threadid; |
| 7816 |
struct ast_channel *chan; |
| 7817 |
struct ast_frame *f; |
| 7818 |
|
| 7819 |
idx = dahdi_get_index(ast, p, 0); |
| 7820 |
if (idx < 0) { |
| 7821 |
return &ast_null_frame; |
| 7822 |
} |
| 7823 |
mysig = p->sig; |
| 7824 |
if (p->outsigmod > -1) |
| 7825 |
mysig = p->outsigmod; |
| 7826 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 7827 |
p->subs[idx].f.subclass.integer = 0; |
| 7828 |
p->subs[idx].f.datalen = 0; |
| 7829 |
p->subs[idx].f.samples = 0; |
| 7830 |
p->subs[idx].f.mallocd = 0; |
| 7831 |
p->subs[idx].f.offset = 0; |
| 7832 |
p->subs[idx].f.src = "dahdi_handle_event"; |
| 7833 |
p->subs[idx].f.data.ptr = NULL; |
| 7834 |
f = &p->subs[idx].f; |
| 7835 |
|
| 7836 |
if (p->fake_event) { |
| 7837 |
res = p->fake_event; |
| 7838 |
p->fake_event = 0; |
| 7839 |
} else |
| 7840 |
res = dahdi_get_event(p->subs[idx].dfd); |
| 7841 |
|
| 7842 |
ast_debug(1, "Got event %s(%d) on channel %d (index %d)\n", event2str(res), res, p->channel, idx); |
| 7843 |
|
| 7844 |
if (res & (DAHDI_EVENT_PULSEDIGIT | DAHDI_EVENT_DTMFUP)) { |
| 7845 |
p->pulsedial = (res & DAHDI_EVENT_PULSEDIGIT) ? 1 : 0; |
| 7846 |
ast_debug(1, "Detected %sdigit '%c'\n", p->pulsedial ? "pulse ": "", res & 0xff); |
| 7847 |
#if defined(HAVE_PRI) |
| 7848 |
if (dahdi_sig_pri_lib_handles(p->sig) |
| 7849 |
&& ((struct sig_pri_chan *) p->sig_pvt)->call_level < SIG_PRI_CALL_LEVEL_PROCEEDING |
| 7850 |
&& p->pri |
| 7851 |
&& (p->pri->overlapdial & DAHDI_OVERLAPDIAL_INCOMING)) { |
| 7852 |
|
| 7853 |
} else |
| 7854 |
#endif |
| 7855 |
{ |
| 7856 |
|
| 7857 |
dahdi_confmute(p, 0); |
| 7858 |
p->subs[idx].f.frametype = AST_FRAME_DTMF_END; |
| 7859 |
p->subs[idx].f.subclass.integer = res & 0xff; |
| 7860 |
dahdi_handle_dtmf(ast, idx, &f); |
| 7861 |
} |
| 7862 |
return f; |
| 7863 |
} |
| 7864 |
|
| 7865 |
if (res & DAHDI_EVENT_DTMFDOWN) { |
| 7866 |
ast_debug(1, "DTMF Down '%c'\n", res & 0xff); |
| 7867 |
#if defined(HAVE_PRI) |
| 7868 |
if (dahdi_sig_pri_lib_handles(p->sig) |
| 7869 |
&& ((struct sig_pri_chan *) p->sig_pvt)->call_level < SIG_PRI_CALL_LEVEL_PROCEEDING |
| 7870 |
&& p->pri |
| 7871 |
&& (p->pri->overlapdial & DAHDI_OVERLAPDIAL_INCOMING)) { |
| 7872 |
|
| 7873 |
} else |
| 7874 |
#endif |
| 7875 |
{ |
| 7876 |
|
| 7877 |
dahdi_confmute(p, 1); |
| 7878 |
p->subs[idx].f.frametype = AST_FRAME_DTMF_BEGIN; |
| 7879 |
p->subs[idx].f.subclass.integer = res & 0xff; |
| 7880 |
dahdi_handle_dtmf(ast, idx, &f); |
| 7881 |
} |
| 7882 |
return &p->subs[idx].f; |
| 7883 |
} |
| 7884 |
|
| 7885 |
switch (res) { |
| 7886 |
case DAHDI_EVENT_EC_DISABLED: |
| 7887 |
ast_verb(3, "Channel %d echo canceler disabled.\n", p->channel); |
| 7888 |
p->echocanon = 0; |
| 7889 |
break; |
| 7890 |
#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE |
| 7891 |
case DAHDI_EVENT_TX_CED_DETECTED: |
| 7892 |
ast_verb(3, "Channel %d detected a CED tone towards the network.\n", p->channel); |
| 7893 |
break; |
| 7894 |
case DAHDI_EVENT_RX_CED_DETECTED: |
| 7895 |
ast_verb(3, "Channel %d detected a CED tone from the network.\n", p->channel); |
| 7896 |
break; |
| 7897 |
case DAHDI_EVENT_EC_NLP_DISABLED: |
| 7898 |
ast_verb(3, "Channel %d echo canceler disabled its NLP.\n", p->channel); |
| 7899 |
break; |
| 7900 |
case DAHDI_EVENT_EC_NLP_ENABLED: |
| 7901 |
ast_verb(3, "Channel %d echo canceler enabled its NLP.\n", p->channel); |
| 7902 |
break; |
| 7903 |
#endif |
| 7904 |
case DAHDI_EVENT_BITSCHANGED: |
| 7905 |
#ifdef HAVE_OPENR2 |
| 7906 |
if (p->sig != SIG_MFCR2) { |
| 7907 |
ast_log(LOG_WARNING, "Received bits changed on %s signalling?\n", sig2str(p->sig)); |
| 7908 |
} else { |
| 7909 |
ast_debug(1, "bits changed in chan %d\n", p->channel); |
| 7910 |
openr2_chan_handle_cas(p->r2chan); |
| 7911 |
} |
| 7912 |
#else |
| 7913 |
ast_log(LOG_WARNING, "Received bits changed on %s signalling?\n", sig2str(p->sig)); |
| 7914 |
#endif |
| 7915 |
break; |
| 7916 |
case DAHDI_EVENT_PULSE_START: |
| 7917 |
|
| 7918 |
if (!ast_channel_pbx(ast)) |
| 7919 |
tone_zone_play_tone(p->subs[idx].dfd, -1); |
| 7920 |
break; |
| 7921 |
case DAHDI_EVENT_DIALCOMPLETE: |
| 7922 |
|
| 7923 |
#if defined(HAVE_PRI) |
| 7924 |
if (dahdi_sig_pri_lib_handles(p->sig)) { |
| 7925 |
if (p->inalarm) { |
| 7926 |
break; |
| 7927 |
} |
| 7928 |
if (ioctl(p->subs[idx].dfd, DAHDI_DIALING, &x) == -1) { |
| 7929 |
ast_debug(1, "DAHDI_DIALING ioctl failed on %s: %s\n", |
| 7930 |
ast_channel_name(ast), strerror(errno)); |
| 7931 |
return NULL; |
| 7932 |
} |
| 7933 |
if (x) { |
| 7934 |
|
| 7935 |
break; |
| 7936 |
} |
| 7937 |
|
| 7938 |
|
| 7939 |
|
| 7940 |
|
| 7941 |
sig_pri_dial_complete(p->sig_pvt, ast); |
| 7942 |
break; |
| 7943 |
} |
| 7944 |
#endif |
| 7945 |
#ifdef HAVE_OPENR2 |
| 7946 |
if ((p->sig & SIG_MFCR2) && p->r2chan && ast_channel_state(ast) != AST_STATE_UP) { |
| 7947 |
|
| 7948 |
|
| 7949 |
break; |
| 7950 |
} |
| 7951 |
#endif |
| 7952 |
if (p->inalarm) break; |
| 7953 |
if ((p->radio || (p->oprmode < 0))) break; |
| 7954 |
if (ioctl(p->subs[idx].dfd,DAHDI_DIALING,&x) == -1) { |
| 7955 |
ast_debug(1, "DAHDI_DIALING ioctl failed on %s: %s\n",ast_channel_name(ast), strerror(errno)); |
| 7956 |
return NULL; |
| 7957 |
} |
| 7958 |
if (!x) { |
| 7959 |
dahdi_ec_enable(p); |
| 7960 |
if (p->echobreak) { |
| 7961 |
dahdi_train_ec(p); |
| 7962 |
ast_copy_string(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr)); |
| 7963 |
p->dop.op = DAHDI_DIAL_OP_REPLACE; |
| 7964 |
res = dahdi_dial_str(p, p->dop.op, p->dop.dialstr); |
| 7965 |
p->echobreak = 0; |
| 7966 |
} else { |
| 7967 |
p->dialing = 0; |
| 7968 |
if ((mysig == SIG_E911) || (mysig == SIG_FGC_CAMA) || (mysig == SIG_FGC_CAMAMF)) { |
| 7969 |
|
| 7970 |
if (ast_channel_state(ast) == AST_STATE_DIALING_OFFHOOK) { |
| 7971 |
ast_setstate(ast, AST_STATE_UP); |
| 7972 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 7973 |
p->subs[idx].f.subclass.integer = AST_CONTROL_ANSWER; |
| 7974 |
break; |
| 7975 |
} else { |
| 7976 |
|
| 7977 |
ast_setstate(ast,AST_STATE_DIALING_OFFHOOK); |
| 7978 |
} |
| 7979 |
} |
| 7980 |
if (ast_channel_state(ast) == AST_STATE_DIALING) { |
| 7981 |
if ((p->callprogress & CALLPROGRESS_PROGRESS) && CANPROGRESSDETECT(p) && p->dsp && p->outgoing) { |
| 7982 |
ast_debug(1, "Done dialing, but waiting for progress detection before doing more...\n"); |
| 7983 |
} else if (p->confirmanswer || (!p->dialednone |
| 7984 |
&& ((mysig == SIG_EM) || (mysig == SIG_EM_E1) |
| 7985 |
|| (mysig == SIG_EMWINK) || (mysig == SIG_FEATD) |
| 7986 |
|| (mysig == SIG_FEATDMF_TA) || (mysig == SIG_FEATDMF) |
| 7987 |
|| (mysig == SIG_E911) || (mysig == SIG_FGC_CAMA) |
| 7988 |
|| (mysig == SIG_FGC_CAMAMF) || (mysig == SIG_FEATB) |
| 7989 |
|| (mysig == SIG_SF) || (mysig == SIG_SFWINK) |
| 7990 |
|| (mysig == SIG_SF_FEATD) || (mysig == SIG_SF_FEATDMF) |
| 7991 |
|| (mysig == SIG_SF_FEATB)))) { |
| 7992 |
ast_setstate(ast, AST_STATE_RINGING); |
| 7993 |
} else if (!p->answeronpolarityswitch) { |
| 7994 |
ast_setstate(ast, AST_STATE_UP); |
| 7995 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 7996 |
p->subs[idx].f.subclass.integer = AST_CONTROL_ANSWER; |
| 7997 |
|
| 7998 |
p->polarity = POLARITY_REV; |
| 7999 |
} else { |
| 8000 |
|
| 8001 |
p->polarity = POLARITY_IDLE; |
| 8002 |
} |
| 8003 |
} |
| 8004 |
} |
| 8005 |
} |
| 8006 |
break; |
| 8007 |
case DAHDI_EVENT_ALARM: |
| 8008 |
switch (p->sig) { |
| 8009 |
#if defined(HAVE_PRI) |
| 8010 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 8011 |
sig_pri_chan_alarm_notify(p->sig_pvt, 0); |
| 8012 |
break; |
| 8013 |
#endif |
| 8014 |
#if defined(HAVE_SS7) |
| 8015 |
case SIG_SS7: |
| 8016 |
sig_ss7_set_alarm(p->sig_pvt, 1); |
| 8017 |
break; |
| 8018 |
#endif |
| 8019 |
default: |
| 8020 |
p->inalarm = 1; |
| 8021 |
break; |
| 8022 |
} |
| 8023 |
res = get_alarms(p); |
| 8024 |
handle_alarms(p, res); |
| 8025 |
#ifdef HAVE_PRI |
| 8026 |
if (!p->pri || !p->pri->pri || pri_get_timer(p->pri->pri, PRI_TIMER_T309) < 0) { |
| 8027 |
|
| 8028 |
} else { |
| 8029 |
break; |
| 8030 |
} |
| 8031 |
#endif |
| 8032 |
#if defined(HAVE_SS7) |
| 8033 |
if (p->sig == SIG_SS7) |
| 8034 |
break; |
| 8035 |
#endif |
| 8036 |
#ifdef HAVE_OPENR2 |
| 8037 |
if (p->sig == SIG_MFCR2) |
| 8038 |
break; |
| 8039 |
#endif |
| 8040 |
case DAHDI_EVENT_ONHOOK: |
| 8041 |
if (p->radio) { |
| 8042 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 8043 |
p->subs[idx].f.subclass.integer = AST_CONTROL_RADIO_UNKEY; |
| 8044 |
break; |
| 8045 |
} |
| 8046 |
if (p->oprmode < 0) |
| 8047 |
{ |
| 8048 |
if (p->oprmode != -1) { |
| 8049 |
ast_verb(4, "Operator mode enabled on channel %d, holding line for channel %d\n", p->channel, p->oprpeer->channel); |
| 8050 |
break; |
| 8051 |
} |
| 8052 |
|
| 8053 |
if ((p->sig == SIG_FXOLS) || (p->sig == SIG_FXOKS) || (p->sig == SIG_FXOGS)) |
| 8054 |
{ |
| 8055 |
|
| 8056 |
dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_RINGOFF); |
| 8057 |
dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_RING); |
| 8058 |
save_conference(p->oprpeer); |
| 8059 |
tone_zone_play_tone(p->oprpeer->subs[SUB_REAL].dfd, DAHDI_TONE_RINGTONE); |
| 8060 |
ast_verb(4, "Operator recall, channel %d ringing back channel %d\n", p->oprpeer->channel, p->channel); |
| 8061 |
} |
| 8062 |
break; |
| 8063 |
} |
| 8064 |
switch (p->sig) { |
| 8065 |
case SIG_FXOLS: |
| 8066 |
case SIG_FXOGS: |
| 8067 |
case SIG_FXOKS: |
| 8068 |
|
| 8069 |
if (idx == SUB_REAL) { |
| 8070 |
|
| 8071 |
if (p->subs[SUB_CALLWAIT].owner) { |
| 8072 |
|
| 8073 |
swap_subs(p, SUB_CALLWAIT, SUB_REAL); |
| 8074 |
ast_verb(3, "Channel %d still has (callwait) call, ringing phone\n", p->channel); |
| 8075 |
unalloc_sub(p, SUB_CALLWAIT); |
| 8076 |
#if 0 |
| 8077 |
p->subs[idx].needanswer = 0; |
| 8078 |
p->subs[idx].needringing = 0; |
| 8079 |
#endif |
| 8080 |
p->callwaitingrepeat = 0; |
| 8081 |
p->cidcwexpire = 0; |
| 8082 |
p->cid_suppress_expire = 0; |
| 8083 |
p->owner = NULL; |
| 8084 |
|
| 8085 |
if (ast_channel_state(p->subs[SUB_REAL].owner) != AST_STATE_UP) |
| 8086 |
p->dialing = 1; |
| 8087 |
dahdi_ring_phone(p); |
| 8088 |
} else if (p->subs[SUB_THREEWAY].owner) { |
| 8089 |
unsigned int mssinceflash; |
| 8090 |
|
| 8091 |
|
| 8092 |
while (p->subs[SUB_THREEWAY].owner && ast_channel_trylock(p->subs[SUB_THREEWAY].owner)) { |
| 8093 |
|
| 8094 |
DLA_UNLOCK(&p->lock); |
| 8095 |
CHANNEL_DEADLOCK_AVOIDANCE(ast); |
| 8096 |
|
| 8097 |
|
| 8098 |
|
| 8099 |
DLA_LOCK(&p->lock); |
| 8100 |
if (p->owner != ast) { |
| 8101 |
ast_log(LOG_WARNING, "This isn't good...\n"); |
| 8102 |
return NULL; |
| 8103 |
} |
| 8104 |
} |
| 8105 |
if (!p->subs[SUB_THREEWAY].owner) { |
| 8106 |
ast_log(LOG_NOTICE, "Whoa, threeway disappeared kinda randomly.\n"); |
| 8107 |
return NULL; |
| 8108 |
} |
| 8109 |
mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime); |
| 8110 |
ast_debug(1, "Last flash was %u ms ago\n", mssinceflash); |
| 8111 |
if (mssinceflash < MIN_MS_SINCE_FLASH) { |
| 8112 |
|
| 8113 |
|
| 8114 |
if (p->subs[SUB_THREEWAY].owner) |
| 8115 |
ast_queue_hangup_with_cause(p->subs[SUB_THREEWAY].owner, AST_CAUSE_NO_ANSWER); |
| 8116 |
ast_channel_softhangup_internal_flag_add(p->subs[SUB_THREEWAY].owner, AST_SOFTHANGUP_DEV); |
| 8117 |
ast_debug(1, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel); |
| 8118 |
ast_channel_unlock(p->subs[SUB_THREEWAY].owner); |
| 8119 |
} else if ((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) { |
| 8120 |
if (p->transfer) { |
| 8121 |
|
| 8122 |
p->subs[SUB_REAL].inthreeway = 0; |
| 8123 |
p->subs[SUB_THREEWAY].inthreeway = 0; |
| 8124 |
|
| 8125 |
if (!p->transfertobusy && ast_channel_state(ast) == AST_STATE_BUSY) { |
| 8126 |
ast_channel_unlock(p->subs[SUB_THREEWAY].owner); |
| 8127 |
|
| 8128 |
swap_subs(p, SUB_THREEWAY, SUB_REAL); |
| 8129 |
p->owner = NULL; |
| 8130 |
|
| 8131 |
dahdi_ring_phone(p); |
| 8132 |
} else if (!attempt_transfer(p)) { |
| 8133 |
|
| 8134 |
|
| 8135 |
|
| 8136 |
|
| 8137 |
|
| 8138 |
break; |
| 8139 |
} |
| 8140 |
} else { |
| 8141 |
ast_channel_softhangup_internal_flag_add(p->subs[SUB_THREEWAY].owner, AST_SOFTHANGUP_DEV); |
| 8142 |
if (p->subs[SUB_THREEWAY].owner) |
| 8143 |
ast_channel_unlock(p->subs[SUB_THREEWAY].owner); |
| 8144 |
} |
| 8145 |
} else { |
| 8146 |
ast_channel_unlock(p->subs[SUB_THREEWAY].owner); |
| 8147 |
|
| 8148 |
swap_subs(p, SUB_THREEWAY, SUB_REAL); |
| 8149 |
p->owner = NULL; |
| 8150 |
|
| 8151 |
dahdi_ring_phone(p); |
| 8152 |
} |
| 8153 |
} |
| 8154 |
} else { |
| 8155 |
ast_log(LOG_WARNING, "Got a hangup and my index is %d?\n", idx); |
| 8156 |
} |
| 8157 |
|
| 8158 |
default: |
| 8159 |
dahdi_ec_disable(p); |
| 8160 |
return NULL; |
| 8161 |
} |
| 8162 |
break; |
| 8163 |
case DAHDI_EVENT_RINGOFFHOOK: |
| 8164 |
if (p->inalarm) break; |
| 8165 |
if (p->oprmode < 0) |
| 8166 |
{ |
| 8167 |
if ((p->sig == SIG_FXOLS) || (p->sig == SIG_FXOKS) || (p->sig == SIG_FXOGS)) |
| 8168 |
{ |
| 8169 |
|
| 8170 |
dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_RINGOFF); |
| 8171 |
tone_zone_play_tone(p->oprpeer->subs[SUB_REAL].dfd, -1); |
| 8172 |
restore_conference(p->oprpeer); |
| 8173 |
ast_debug(1, "Operator recall by channel %d for channel %d complete\n", p->oprpeer->channel, p->channel); |
| 8174 |
} |
| 8175 |
break; |
| 8176 |
} |
| 8177 |
if (p->radio) |
| 8178 |
{ |
| 8179 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 8180 |
p->subs[idx].f.subclass.integer = AST_CONTROL_RADIO_KEY; |
| 8181 |
break; |
| 8182 |
} |
| 8183 |
|
| 8184 |
|
| 8185 |
if (((mysig == SIG_E911) || (mysig == SIG_FGC_CAMA) || (mysig == SIG_FGC_CAMAMF)) && (ast_channel_state(ast) == AST_STATE_DIALING_OFFHOOK)) { |
| 8186 |
c = strchr(p->dialdest, '/'); |
| 8187 |
if (c) |
| 8188 |
c++; |
| 8189 |
else |
| 8190 |
c = p->dialdest; |
| 8191 |
|
| 8192 |
if (*c) { |
| 8193 |
int numchars = snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c); |
| 8194 |
if (numchars >= sizeof(p->dop.dialstr)) { |
| 8195 |
ast_log(LOG_WARNING, "Dial string '%s' truncated\n", c); |
| 8196 |
} |
| 8197 |
} else { |
| 8198 |
ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr)); |
| 8199 |
} |
| 8200 |
|
| 8201 |
if (strlen(p->dop.dialstr) > 4) { |
| 8202 |
memset(p->echorest, 'w', sizeof(p->echorest) - 1); |
| 8203 |
strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2); |
| 8204 |
p->echorest[sizeof(p->echorest) - 1] = '\0'; |
| 8205 |
p->echobreak = 1; |
| 8206 |
p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0'; |
| 8207 |
} else |
| 8208 |
p->echobreak = 0; |
| 8209 |
if (dahdi_dial_str(p, p->dop.op, p->dop.dialstr)) { |
| 8210 |
x = DAHDI_ONHOOK; |
| 8211 |
ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x); |
| 8212 |
return NULL; |
| 8213 |
} |
| 8214 |
p->dialing = 1; |
| 8215 |
return &p->subs[idx].f; |
| 8216 |
} |
| 8217 |
switch (p->sig) { |
| 8218 |
case SIG_FXOLS: |
| 8219 |
case SIG_FXOGS: |
| 8220 |
case SIG_FXOKS: |
| 8221 |
switch (ast_channel_state(ast)) { |
| 8222 |
case AST_STATE_RINGING: |
| 8223 |
dahdi_ec_enable(p); |
| 8224 |
dahdi_train_ec(p); |
| 8225 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 8226 |
p->subs[idx].f.subclass.integer = AST_CONTROL_ANSWER; |
| 8227 |
|
| 8228 |
p->subs[SUB_REAL].needringing = 0; |
| 8229 |
dahdi_set_hook(p->subs[idx].dfd, DAHDI_OFFHOOK); |
| 8230 |
ast_debug(1, "channel %d answered\n", p->channel); |
| 8231 |
|
| 8232 |
|
| 8233 |
ast_free(p->cidspill); |
| 8234 |
p->cidspill = NULL; |
| 8235 |
restore_conference(p); |
| 8236 |
|
| 8237 |
p->dialing = 0; |
| 8238 |
p->callwaitcas = 0; |
| 8239 |
if (p->confirmanswer) { |
| 8240 |
|
| 8241 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 8242 |
p->subs[idx].f.subclass.integer = 0; |
| 8243 |
} else if (!ast_strlen_zero(p->dop.dialstr)) { |
| 8244 |
|
| 8245 |
res = dahdi_dial_str(p, p->dop.op, p->dop.dialstr); |
| 8246 |
if (res) { |
| 8247 |
p->dop.dialstr[0] = '\0'; |
| 8248 |
return NULL; |
| 8249 |
} else { |
| 8250 |
ast_debug(1, "Sent FXO deferred digit string: %s\n", p->dop.dialstr); |
| 8251 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 8252 |
p->subs[idx].f.subclass.integer = 0; |
| 8253 |
p->dialing = 1; |
| 8254 |
} |
| 8255 |
p->dop.dialstr[0] = '\0'; |
| 8256 |
ast_setstate(ast, AST_STATE_DIALING); |
| 8257 |
} else |
| 8258 |
ast_setstate(ast, AST_STATE_UP); |
| 8259 |
return &p->subs[idx].f; |
| 8260 |
case AST_STATE_DOWN: |
| 8261 |
ast_setstate(ast, AST_STATE_RING); |
| 8262 |
ast_channel_rings_set(ast, 1); |
| 8263 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 8264 |
p->subs[idx].f.subclass.integer = AST_CONTROL_OFFHOOK; |
| 8265 |
ast_debug(1, "channel %d picked up\n", p->channel); |
| 8266 |
return &p->subs[idx].f; |
| 8267 |
case AST_STATE_UP: |
| 8268 |
|
| 8269 |
dahdi_set_hook(p->subs[idx].dfd, DAHDI_OFFHOOK); |
| 8270 |
|
| 8271 |
ast_queue_unhold(p->owner); |
| 8272 |
p->subs[idx].needunhold = 1; |
| 8273 |
break; |
| 8274 |
case AST_STATE_RESERVED: |
| 8275 |
|
| 8276 |
if (has_voicemail(p)) |
| 8277 |
res = tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_STUTTER); |
| 8278 |
else |
| 8279 |
res = tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_DIALTONE); |
| 8280 |
break; |
| 8281 |
default: |
| 8282 |
ast_log(LOG_WARNING, "FXO phone off hook in weird state %u??\n", ast_channel_state(ast)); |
| 8283 |
} |
| 8284 |
break; |
| 8285 |
case SIG_FXSLS: |
| 8286 |
case SIG_FXSGS: |
| 8287 |
case SIG_FXSKS: |
| 8288 |
if (ast_channel_state(ast) == AST_STATE_RING) { |
| 8289 |
p->ringt = p->ringt_base; |
| 8290 |
} |
| 8291 |
|
| 8292 |
|
| 8293 |
|
| 8294 |
ast_debug(1, "Setting IDLE polarity due " |
| 8295 |
"to ring. Old polarity was %d\n", |
| 8296 |
p->polarity); |
| 8297 |
p->polarity = POLARITY_IDLE; |
| 8298 |
|
| 8299 |
|
| 8300 |
case SIG_EM: |
| 8301 |
case SIG_EM_E1: |
| 8302 |
case SIG_EMWINK: |
| 8303 |
case SIG_FEATD: |
| 8304 |
case SIG_FEATDMF: |
| 8305 |
case SIG_FEATDMF_TA: |
| 8306 |
case SIG_E911: |
| 8307 |
case SIG_FGC_CAMA: |
| 8308 |
case SIG_FGC_CAMAMF: |
| 8309 |
case SIG_FEATB: |
| 8310 |
case SIG_SF: |
| 8311 |
case SIG_SFWINK: |
| 8312 |
case SIG_SF_FEATD: |
| 8313 |
case SIG_SF_FEATDMF: |
| 8314 |
case SIG_SF_FEATB: |
| 8315 |
if (ast_channel_state(ast) == AST_STATE_PRERING) |
| 8316 |
ast_setstate(ast, AST_STATE_RING); |
| 8317 |
if ((ast_channel_state(ast) == AST_STATE_DOWN) || (ast_channel_state(ast) == AST_STATE_RING)) { |
| 8318 |
ast_debug(1, "Ring detected\n"); |
| 8319 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 8320 |
p->subs[idx].f.subclass.integer = AST_CONTROL_RING; |
| 8321 |
} else if (p->outgoing && ((ast_channel_state(ast) == AST_STATE_RINGING) || (ast_channel_state(ast) == AST_STATE_DIALING))) { |
| 8322 |
ast_debug(1, "Line answered\n"); |
| 8323 |
if (p->confirmanswer) { |
| 8324 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 8325 |
p->subs[idx].f.subclass.integer = 0; |
| 8326 |
} else { |
| 8327 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 8328 |
p->subs[idx].f.subclass.integer = AST_CONTROL_ANSWER; |
| 8329 |
ast_setstate(ast, AST_STATE_UP); |
| 8330 |
} |
| 8331 |
} else if (ast_channel_state(ast) != AST_STATE_RING) |
| 8332 |
ast_log(LOG_WARNING, "Ring/Off-hook in strange state %u on channel %d\n", ast_channel_state(ast), p->channel); |
| 8333 |
break; |
| 8334 |
default: |
| 8335 |
ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig); |
| 8336 |
} |
| 8337 |
break; |
| 8338 |
case DAHDI_EVENT_RINGBEGIN: |
| 8339 |
switch (p->sig) { |
| 8340 |
case SIG_FXSLS: |
| 8341 |
case SIG_FXSGS: |
| 8342 |
case SIG_FXSKS: |
| 8343 |
if (ast_channel_state(ast) == AST_STATE_RING) { |
| 8344 |
p->ringt = p->ringt_base; |
| 8345 |
} |
| 8346 |
break; |
| 8347 |
} |
| 8348 |
break; |
| 8349 |
case DAHDI_EVENT_RINGERON: |
| 8350 |
break; |
| 8351 |
case DAHDI_EVENT_NOALARM: |
| 8352 |
switch (p->sig) { |
| 8353 |
#if defined(HAVE_PRI) |
| 8354 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 8355 |
sig_pri_chan_alarm_notify(p->sig_pvt, 1); |
| 8356 |
break; |
| 8357 |
#endif |
| 8358 |
#if defined(HAVE_SS7) |
| 8359 |
case SIG_SS7: |
| 8360 |
sig_ss7_set_alarm(p->sig_pvt, 0); |
| 8361 |
break; |
| 8362 |
#endif |
| 8363 |
default: |
| 8364 |
p->inalarm = 0; |
| 8365 |
break; |
| 8366 |
} |
| 8367 |
handle_clear_alarms(p); |
| 8368 |
break; |
| 8369 |
case DAHDI_EVENT_WINKFLASH: |
| 8370 |
if (p->inalarm) break; |
| 8371 |
if (p->radio) break; |
| 8372 |
if (p->oprmode < 0) break; |
| 8373 |
if (p->oprmode > 1) |
| 8374 |
{ |
| 8375 |
struct dahdi_params par; |
| 8376 |
|
| 8377 |
memset(&par, 0, sizeof(par)); |
| 8378 |
if (ioctl(p->oprpeer->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par) != -1) |
| 8379 |
{ |
| 8380 |
if (!par.rxisoffhook) |
| 8381 |
{ |
| 8382 |
|
| 8383 |
dahdi_set_hook(p->oprpeer->subs[SUB_REAL].dfd, DAHDI_RINGOFF); |
| 8384 |
dahdi_set_hook(p->oprpeer->subs[SUB_REAL].dfd, DAHDI_RING); |
| 8385 |
save_conference(p); |
| 8386 |
tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_RINGTONE); |
| 8387 |
ast_verb(4, "Operator flash recall, channel %d ringing back channel %d\n", p->oprpeer->channel, p->channel); |
| 8388 |
} |
| 8389 |
} |
| 8390 |
break; |
| 8391 |
} |
| 8392 |
|
| 8393 |
p->flashtime = ast_tvnow(); |
| 8394 |
switch (mysig) { |
| 8395 |
case SIG_FXOLS: |
| 8396 |
case SIG_FXOGS: |
| 8397 |
case SIG_FXOKS: |
| 8398 |
ast_debug(1, "Winkflash, index: %d, normal: %d, callwait: %d, thirdcall: %d\n", |
| 8399 |
idx, p->subs[SUB_REAL].dfd, p->subs[SUB_CALLWAIT].dfd, p->subs[SUB_THREEWAY].dfd); |
| 8400 |
|
| 8401 |
|
| 8402 |
ast_free(p->cidspill); |
| 8403 |
p->cidspill = NULL; |
| 8404 |
restore_conference(p); |
| 8405 |
p->callwaitcas = 0; |
| 8406 |
|
| 8407 |
if (idx != SUB_REAL) { |
| 8408 |
ast_log(LOG_WARNING, "Got flash hook with index %d on channel %d?!?\n", idx, p->channel); |
| 8409 |
goto winkflashdone; |
| 8410 |
} |
| 8411 |
|
| 8412 |
if (p->subs[SUB_CALLWAIT].owner) { |
| 8413 |
|
| 8414 |
swap_subs(p, SUB_REAL, SUB_CALLWAIT); |
| 8415 |
tone_zone_play_tone(p->subs[SUB_REAL].dfd, -1); |
| 8416 |
p->owner = p->subs[SUB_REAL].owner; |
| 8417 |
ast_debug(1, "Making %s the new owner\n", ast_channel_name(p->owner)); |
| 8418 |
if (ast_channel_state(p->owner) == AST_STATE_RINGING) { |
| 8419 |
ast_setstate(p->owner, AST_STATE_UP); |
| 8420 |
p->subs[SUB_REAL].needanswer = 1; |
| 8421 |
} |
| 8422 |
p->callwaitingrepeat = 0; |
| 8423 |
p->cidcwexpire = 0; |
| 8424 |
p->cid_suppress_expire = 0; |
| 8425 |
|
| 8426 |
if (!p->subs[SUB_CALLWAIT].inthreeway) { |
| 8427 |
ast_queue_hold(p->subs[SUB_CALLWAIT].owner, p->mohsuggest); |
| 8428 |
} |
| 8429 |
p->subs[SUB_CALLWAIT].needhold = 1; |
| 8430 |
ast_queue_hold(p->subs[SUB_REAL].owner, p->mohsuggest); |
| 8431 |
p->subs[SUB_REAL].needunhold = 1; |
| 8432 |
} else if (!p->subs[SUB_THREEWAY].owner) { |
| 8433 |
if (!p->threewaycalling) { |
| 8434 |
|
| 8435 |
p->subs[SUB_REAL].needflash = 1; |
| 8436 |
goto winkflashdone; |
| 8437 |
} else if (!check_for_conference(p)) { |
| 8438 |
ast_callid callid = 0; |
| 8439 |
int callid_created; |
| 8440 |
char cid_num[256]; |
| 8441 |
char cid_name[256]; |
| 8442 |
|
| 8443 |
cid_num[0] = 0; |
| 8444 |
cid_name[0] = 0; |
| 8445 |
if (p->dahditrcallerid && p->owner) { |
| 8446 |
if (ast_channel_caller(p->owner)->id.number.valid |
| 8447 |
&& ast_channel_caller(p->owner)->id.number.str) { |
| 8448 |
ast_copy_string(cid_num, ast_channel_caller(p->owner)->id.number.str, |
| 8449 |
sizeof(cid_num)); |
| 8450 |
} |
| 8451 |
if (ast_channel_caller(p->owner)->id.name.valid |
| 8452 |
&& ast_channel_caller(p->owner)->id.name.str) { |
| 8453 |
ast_copy_string(cid_name, ast_channel_caller(p->owner)->id.name.str, |
| 8454 |
sizeof(cid_name)); |
| 8455 |
} |
| 8456 |
} |
| 8457 |
|
| 8458 |
|
| 8459 |
if (!((ast_channel_pbx(ast)) || |
| 8460 |
(ast_channel_state(ast) == AST_STATE_UP) || |
| 8461 |
(ast_channel_state(ast) == AST_STATE_RING))) { |
| 8462 |
ast_debug(1, "Flash when call not up or ringing\n"); |
| 8463 |
goto winkflashdone; |
| 8464 |
} |
| 8465 |
if (alloc_sub(p, SUB_THREEWAY)) { |
| 8466 |
ast_log(LOG_WARNING, "Unable to allocate three-way subchannel\n"); |
| 8467 |
goto winkflashdone; |
| 8468 |
} |
| 8469 |
callid_created = ast_callid_threadstorage_auto(&callid); |
| 8470 |
|
| 8471 |
|
| 8472 |
|
| 8473 |
|
| 8474 |
|
| 8475 |
|
| 8476 |
ast_mutex_unlock(&p->lock); |
| 8477 |
ast_channel_unlock(ast); |
| 8478 |
chan = dahdi_new(p, AST_STATE_RESERVED, 0, SUB_THREEWAY, 0, NULL, NULL, callid); |
| 8479 |
ast_channel_lock(ast); |
| 8480 |
ast_mutex_lock(&p->lock); |
| 8481 |
if (p->dahditrcallerid) { |
| 8482 |
if (!p->origcid_num) |
| 8483 |
p->origcid_num = ast_strdup(p->cid_num); |
| 8484 |
if (!p->origcid_name) |
| 8485 |
p->origcid_name = ast_strdup(p->cid_name); |
| 8486 |
ast_copy_string(p->cid_num, cid_num, sizeof(p->cid_num)); |
| 8487 |
ast_copy_string(p->cid_name, cid_name, sizeof(p->cid_name)); |
| 8488 |
} |
| 8489 |
|
| 8490 |
swap_subs(p, SUB_THREEWAY, SUB_REAL); |
| 8491 |
|
| 8492 |
dahdi_ec_disable(p); |
| 8493 |
res = tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_DIALRECALL); |
| 8494 |
if (res) |
| 8495 |
ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel); |
| 8496 |
p->owner = chan; |
| 8497 |
if (!chan) { |
| 8498 |
ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", p->channel); |
| 8499 |
} else if (ast_pthread_create_detached(&threadid, NULL, analog_ss_thread, chan)) { |
| 8500 |
ast_log(LOG_WARNING, "Unable to start simple switch on channel %d\n", p->channel); |
| 8501 |
res = tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_CONGESTION); |
| 8502 |
dahdi_ec_enable(p); |
| 8503 |
ast_hangup(chan); |
| 8504 |
} else { |
| 8505 |
ast_verb(3, "Started three way call on channel %d\n", p->channel); |
| 8506 |
|
| 8507 |
|
| 8508 |
ast_queue_hold(p->subs[SUB_THREEWAY].owner, p->mohsuggest); |
| 8509 |
p->subs[SUB_THREEWAY].needhold = 1; |
| 8510 |
} |
| 8511 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 8512 |
} |
| 8513 |
} else { |
| 8514 |
|
| 8515 |
if (p->subs[SUB_THREEWAY].inthreeway) { |
| 8516 |
|
| 8517 |
ast_debug(1, "Got flash with three way call up, dropping last call on %d\n", p->channel); |
| 8518 |
|
| 8519 |
if ((ast_channel_state(p->subs[SUB_REAL].owner) != AST_STATE_UP) && (ast_channel_state(p->subs[SUB_THREEWAY].owner) == AST_STATE_UP)) { |
| 8520 |
|
| 8521 |
swap_subs(p, SUB_THREEWAY, SUB_REAL); |
| 8522 |
p->owner = p->subs[SUB_REAL].owner; |
| 8523 |
} |
| 8524 |
|
| 8525 |
ast_verb(3, "Dropping three-way call on %s\n", ast_channel_name(p->subs[SUB_THREEWAY].owner)); |
| 8526 |
ast_channel_softhangup_internal_flag_add(p->subs[SUB_THREEWAY].owner, AST_SOFTHANGUP_DEV); |
| 8527 |
p->subs[SUB_REAL].inthreeway = 0; |
| 8528 |
p->subs[SUB_THREEWAY].inthreeway = 0; |
| 8529 |
} else { |
| 8530 |
|
| 8531 |
if (((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) && |
| 8532 |
(p->transfertobusy || (ast_channel_state(ast) != AST_STATE_BUSY))) { |
| 8533 |
int otherindex = SUB_THREEWAY; |
| 8534 |
|
| 8535 |
ast_verb(3, "Building conference call with %s and %s\n", |
| 8536 |
ast_channel_name(p->subs[SUB_THREEWAY].owner), |
| 8537 |
ast_channel_name(p->subs[SUB_REAL].owner)); |
| 8538 |
|
| 8539 |
p->subs[SUB_THREEWAY].inthreeway = 1; |
| 8540 |
p->subs[SUB_REAL].inthreeway = 1; |
| 8541 |
if (ast_channel_state(ast) == AST_STATE_UP) { |
| 8542 |
swap_subs(p, SUB_THREEWAY, SUB_REAL); |
| 8543 |
otherindex = SUB_REAL; |
| 8544 |
} |
| 8545 |
if (p->subs[otherindex].owner) { |
| 8546 |
ast_queue_unhold(p->subs[otherindex].owner); |
| 8547 |
} |
| 8548 |
p->subs[otherindex].needunhold = 1; |
| 8549 |
p->owner = p->subs[SUB_REAL].owner; |
| 8550 |
} else { |
| 8551 |
ast_verb(3, "Dumping incomplete call on %s\n", ast_channel_name(p->subs[SUB_THREEWAY].owner)); |
| 8552 |
swap_subs(p, SUB_THREEWAY, SUB_REAL); |
| 8553 |
ast_channel_softhangup_internal_flag_add(p->subs[SUB_THREEWAY].owner, AST_SOFTHANGUP_DEV); |
| 8554 |
p->owner = p->subs[SUB_REAL].owner; |
| 8555 |
if (p->subs[SUB_REAL].owner) { |
| 8556 |
ast_queue_unhold(p->subs[SUB_REAL].owner); |
| 8557 |
} |
| 8558 |
p->subs[SUB_REAL].needunhold = 1; |
| 8559 |
dahdi_ec_enable(p); |
| 8560 |
} |
| 8561 |
} |
| 8562 |
} |
| 8563 |
winkflashdone: |
| 8564 |
dahdi_conf_update(p); |
| 8565 |
break; |
| 8566 |
case SIG_EM: |
| 8567 |
case SIG_EM_E1: |
| 8568 |
case SIG_FEATD: |
| 8569 |
case SIG_SF: |
| 8570 |
case SIG_SFWINK: |
| 8571 |
case SIG_SF_FEATD: |
| 8572 |
case SIG_FXSLS: |
| 8573 |
case SIG_FXSGS: |
| 8574 |
if (p->dialing) |
| 8575 |
ast_debug(1, "Ignoring wink on channel %d\n", p->channel); |
| 8576 |
else |
| 8577 |
ast_debug(1, "Got wink in weird state %u on channel %d\n", ast_channel_state(ast), p->channel); |
| 8578 |
break; |
| 8579 |
case SIG_FEATDMF_TA: |
| 8580 |
switch (p->whichwink) { |
| 8581 |
case 0: |
| 8582 |
ast_debug(1, "ANI2 set to '%d' and ANI is '%s'\n", ast_channel_caller(p->owner)->ani2, |
| 8583 |
S_COR(ast_channel_caller(p->owner)->ani.number.valid, |
| 8584 |
ast_channel_caller(p->owner)->ani.number.str, "")); |
| 8585 |
snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%d%s#", |
| 8586 |
ast_channel_caller(p->owner)->ani2, |
| 8587 |
S_COR(ast_channel_caller(p->owner)->ani.number.valid, |
| 8588 |
ast_channel_caller(p->owner)->ani.number.str, "")); |
| 8589 |
break; |
| 8590 |
case 1: |
| 8591 |
ast_copy_string(p->dop.dialstr, p->finaldial, sizeof(p->dop.dialstr)); |
| 8592 |
break; |
| 8593 |
case 2: |
| 8594 |
ast_log(LOG_WARNING, "Received unexpected wink on channel of type SIG_FEATDMF_TA\n"); |
| 8595 |
return NULL; |
| 8596 |
} |
| 8597 |
p->whichwink++; |
| 8598 |
|
| 8599 |
case SIG_FEATDMF: |
| 8600 |
case SIG_E911: |
| 8601 |
case SIG_FGC_CAMAMF: |
| 8602 |
case SIG_FGC_CAMA: |
| 8603 |
case SIG_FEATB: |
| 8604 |
case SIG_SF_FEATDMF: |
| 8605 |
case SIG_SF_FEATB: |
| 8606 |
case SIG_EMWINK: |
| 8607 |
|
| 8608 |
if (!ast_strlen_zero(p->dop.dialstr)) { |
| 8609 |
res = dahdi_dial_str(p, p->dop.op, p->dop.dialstr); |
| 8610 |
if (res) { |
| 8611 |
p->dop.dialstr[0] = '\0'; |
| 8612 |
return NULL; |
| 8613 |
} else |
| 8614 |
ast_debug(1, "Sent deferred digit string: %s\n", p->dop.dialstr); |
| 8615 |
} |
| 8616 |
p->dop.dialstr[0] = '\0'; |
| 8617 |
break; |
| 8618 |
default: |
| 8619 |
ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig); |
| 8620 |
} |
| 8621 |
break; |
| 8622 |
case DAHDI_EVENT_HOOKCOMPLETE: |
| 8623 |
if (p->inalarm) break; |
| 8624 |
if ((p->radio || (p->oprmode < 0))) break; |
| 8625 |
if (p->waitingfordt.tv_sec) break; |
| 8626 |
switch (mysig) { |
| 8627 |
case SIG_FXSLS: |
| 8628 |
case SIG_FXSGS: |
| 8629 |
case SIG_FXSKS: |
| 8630 |
case SIG_EM: |
| 8631 |
case SIG_EM_E1: |
| 8632 |
case SIG_EMWINK: |
| 8633 |
case SIG_FEATD: |
| 8634 |
case SIG_SF: |
| 8635 |
case SIG_SFWINK: |
| 8636 |
case SIG_SF_FEATD: |
| 8637 |
if (!ast_strlen_zero(p->dop.dialstr)) { |
| 8638 |
res = dahdi_dial_str(p, p->dop.op, p->dop.dialstr); |
| 8639 |
if (res) { |
| 8640 |
p->dop.dialstr[0] = '\0'; |
| 8641 |
return NULL; |
| 8642 |
} else |
| 8643 |
ast_debug(1, "Sent deferred digit string: %s\n", p->dop.dialstr); |
| 8644 |
} |
| 8645 |
p->dop.dialstr[0] = '\0'; |
| 8646 |
p->dop.op = DAHDI_DIAL_OP_REPLACE; |
| 8647 |
break; |
| 8648 |
case SIG_FEATDMF: |
| 8649 |
case SIG_FEATDMF_TA: |
| 8650 |
case SIG_E911: |
| 8651 |
case SIG_FGC_CAMA: |
| 8652 |
case SIG_FGC_CAMAMF: |
| 8653 |
case SIG_FEATB: |
| 8654 |
case SIG_SF_FEATDMF: |
| 8655 |
case SIG_SF_FEATB: |
| 8656 |
ast_debug(1, "Got hook complete in MF FGD, waiting for wink now on channel %d\n",p->channel); |
| 8657 |
break; |
| 8658 |
default: |
| 8659 |
break; |
| 8660 |
} |
| 8661 |
break; |
| 8662 |
case DAHDI_EVENT_POLARITY: |
| 8663 |
|
| 8664 |
|
| 8665 |
|
| 8666 |
|
| 8667 |
|
| 8668 |
|
| 8669 |
if (p->polarity == POLARITY_IDLE) { |
| 8670 |
p->polarity = POLARITY_REV; |
| 8671 |
if (p->answeronpolarityswitch && |
| 8672 |
((ast_channel_state(ast) == AST_STATE_DIALING) || |
| 8673 |
(ast_channel_state(ast) == AST_STATE_RINGING))) { |
| 8674 |
ast_debug(1, "Answering on polarity switch!\n"); |
| 8675 |
ast_setstate(p->owner, AST_STATE_UP); |
| 8676 |
if (p->hanguponpolarityswitch) { |
| 8677 |
p->polaritydelaytv = ast_tvnow(); |
| 8678 |
} |
| 8679 |
} else |
| 8680 |
ast_debug(1, "Ignore switch to REVERSED Polarity on channel %d, state %u\n", p->channel, ast_channel_state(ast)); |
| 8681 |
} |
| 8682 |
|
| 8683 |
|
| 8684 |
if (p->hanguponpolarityswitch && |
| 8685 |
(p->polarityonanswerdelay > 0) && |
| 8686 |
(p->polarity == POLARITY_REV) && |
| 8687 |
((ast_channel_state(ast) == AST_STATE_UP) || (ast_channel_state(ast) == AST_STATE_RING)) ) { |
| 8688 |
|
| 8689 |
ast_debug(1, "Polarity Reversal event occurred - DEBUG 1: channel %d, state %u, pol= %d, aonp= %d, honp= %d, pdelay= %d, tv= %" PRIi64 "\n", p->channel, ast_channel_state(ast), p->polarity, p->answeronpolarityswitch, p->hanguponpolarityswitch, p->polarityonanswerdelay, ast_tvdiff_ms(ast_tvnow(), p->polaritydelaytv) ); |
| 8690 |
|
| 8691 |
if (ast_tvdiff_ms(ast_tvnow(), p->polaritydelaytv) > p->polarityonanswerdelay) { |
| 8692 |
ast_debug(1, "Polarity Reversal detected and now Hanging up on channel %d\n", p->channel); |
| 8693 |
ast_softhangup(p->owner, AST_SOFTHANGUP_EXPLICIT); |
| 8694 |
p->polarity = POLARITY_IDLE; |
| 8695 |
} else |
| 8696 |
ast_debug(1, "Polarity Reversal detected but NOT hanging up (too close to answer event) on channel %d, state %u\n", p->channel, ast_channel_state(ast)); |
| 8697 |
|
| 8698 |
} else { |
| 8699 |
p->polarity = POLARITY_IDLE; |
| 8700 |
ast_debug(1, "Ignoring Polarity switch to IDLE on channel %d, state %u\n", p->channel, ast_channel_state(ast)); |
| 8701 |
} |
| 8702 |
|
| 8703 |
ast_debug(1, "Polarity Reversal event occurred - DEBUG 2: channel %d, state %u, pol= %d, aonp= %d, honp= %d, pdelay= %d, tv= %" PRIi64 "\n", p->channel, ast_channel_state(ast), p->polarity, p->answeronpolarityswitch, p->hanguponpolarityswitch, p->polarityonanswerdelay, ast_tvdiff_ms(ast_tvnow(), p->polaritydelaytv) ); |
| 8704 |
break; |
| 8705 |
default: |
| 8706 |
ast_debug(1, "Dunno what to do with event %d on channel %d\n", res, p->channel); |
| 8707 |
} |
| 8708 |
return &p->subs[idx].f; |
| 8709 |
} |
| 8710 |
|
| 8711 |
static struct ast_frame *__dahdi_exception(struct ast_channel *ast) |
| 8712 |
{ |
| 8713 |
int res; |
| 8714 |
int idx; |
| 8715 |
struct ast_frame *f; |
| 8716 |
int usedindex = -1; |
| 8717 |
struct dahdi_pvt *p = ast_channel_tech_pvt(ast); |
| 8718 |
|
| 8719 |
if ((idx = dahdi_get_index(ast, p, 0)) < 0) { |
| 8720 |
idx = SUB_REAL; |
| 8721 |
} |
| 8722 |
|
| 8723 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 8724 |
p->subs[idx].f.datalen = 0; |
| 8725 |
p->subs[idx].f.samples = 0; |
| 8726 |
p->subs[idx].f.mallocd = 0; |
| 8727 |
p->subs[idx].f.offset = 0; |
| 8728 |
p->subs[idx].f.subclass.integer = 0; |
| 8729 |
p->subs[idx].f.delivery = ast_tv(0,0); |
| 8730 |
p->subs[idx].f.src = "dahdi_exception"; |
| 8731 |
p->subs[idx].f.data.ptr = NULL; |
| 8732 |
|
| 8733 |
|
| 8734 |
if ((!p->owner) && (!(p->radio || (p->oprmode < 0)))) { |
| 8735 |
|
| 8736 |
|
| 8737 |
|
| 8738 |
|
| 8739 |
|
| 8740 |
if (p->fake_event) { |
| 8741 |
res = p->fake_event; |
| 8742 |
p->fake_event = 0; |
| 8743 |
} else |
| 8744 |
res = dahdi_get_event(p->subs[SUB_REAL].dfd); |
| 8745 |
|
| 8746 |
if ((res != DAHDI_EVENT_RINGEROFF) && (res != DAHDI_EVENT_RINGERON) && |
| 8747 |
(res != DAHDI_EVENT_HOOKCOMPLETE)) { |
| 8748 |
ast_debug(1, "Restoring owner of channel %d on event %d\n", p->channel, res); |
| 8749 |
p->owner = p->subs[SUB_REAL].owner; |
| 8750 |
if (p->owner) { |
| 8751 |
ast_queue_unhold(p->owner); |
| 8752 |
} |
| 8753 |
p->subs[SUB_REAL].needunhold = 1; |
| 8754 |
} |
| 8755 |
switch (res) { |
| 8756 |
case DAHDI_EVENT_ONHOOK: |
| 8757 |
dahdi_ec_disable(p); |
| 8758 |
if (p->owner) { |
| 8759 |
ast_verb(3, "Channel %s still has call, ringing phone\n", ast_channel_name(p->owner)); |
| 8760 |
dahdi_ring_phone(p); |
| 8761 |
p->callwaitingrepeat = 0; |
| 8762 |
p->cidcwexpire = 0; |
| 8763 |
p->cid_suppress_expire = 0; |
| 8764 |
} else |
| 8765 |
ast_log(LOG_WARNING, "Absorbed on hook, but nobody is left!?!?\n"); |
| 8766 |
dahdi_conf_update(p); |
| 8767 |
break; |
| 8768 |
case DAHDI_EVENT_RINGOFFHOOK: |
| 8769 |
dahdi_ec_enable(p); |
| 8770 |
dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK); |
| 8771 |
if (p->owner && (ast_channel_state(p->owner) == AST_STATE_RINGING)) { |
| 8772 |
p->subs[SUB_REAL].needanswer = 1; |
| 8773 |
p->dialing = 0; |
| 8774 |
} |
| 8775 |
break; |
| 8776 |
case DAHDI_EVENT_HOOKCOMPLETE: |
| 8777 |
case DAHDI_EVENT_RINGERON: |
| 8778 |
case DAHDI_EVENT_RINGEROFF: |
| 8779 |
|
| 8780 |
break; |
| 8781 |
case DAHDI_EVENT_WINKFLASH: |
| 8782 |
p->flashtime = ast_tvnow(); |
| 8783 |
if (p->owner) { |
| 8784 |
ast_verb(3, "Channel %d flashed to other channel %s\n", p->channel, ast_channel_name(p->owner)); |
| 8785 |
if (ast_channel_state(p->owner) != AST_STATE_UP) { |
| 8786 |
|
| 8787 |
usedindex = dahdi_get_index(p->owner, p, 0); |
| 8788 |
if (usedindex > -1) { |
| 8789 |
p->subs[usedindex].needanswer = 1; |
| 8790 |
} |
| 8791 |
ast_setstate(p->owner, AST_STATE_UP); |
| 8792 |
} |
| 8793 |
p->callwaitingrepeat = 0; |
| 8794 |
p->cidcwexpire = 0; |
| 8795 |
p->cid_suppress_expire = 0; |
| 8796 |
ast_queue_unhold(p->owner); |
| 8797 |
p->subs[SUB_REAL].needunhold = 1; |
| 8798 |
} else |
| 8799 |
ast_log(LOG_WARNING, "Absorbed on hook, but nobody is left!?!?\n"); |
| 8800 |
dahdi_conf_update(p); |
| 8801 |
break; |
| 8802 |
default: |
| 8803 |
ast_log(LOG_WARNING, "Don't know how to absorb event %s\n", event2str(res)); |
| 8804 |
} |
| 8805 |
f = &p->subs[idx].f; |
| 8806 |
return f; |
| 8807 |
} |
| 8808 |
if (!(p->radio || (p->oprmode < 0))) |
| 8809 |
ast_debug(1, "Exception on %d, channel %d\n", ast_channel_fd(ast, 0), p->channel); |
| 8810 |
|
| 8811 |
if (ast != p->owner) { |
| 8812 |
if (p->owner) { |
| 8813 |
ast_log(LOG_WARNING, "We're %s, not %s\n", ast_channel_name(ast), ast_channel_name(p->owner)); |
| 8814 |
} |
| 8815 |
f = &p->subs[idx].f; |
| 8816 |
return f; |
| 8817 |
} |
| 8818 |
|
| 8819 |
f = dahdi_handle_event(ast); |
| 8820 |
if (!f) { |
| 8821 |
const char *name = ast_strdupa(ast_channel_name(ast)); |
| 8822 |
|
| 8823 |
|
| 8824 |
ast_mutex_unlock(&p->lock); |
| 8825 |
ast_channel_unlock(ast); |
| 8826 |
ast_set_hangupsource(ast, name, 0); |
| 8827 |
ast_channel_lock(ast); |
| 8828 |
ast_mutex_lock(&p->lock); |
| 8829 |
} |
| 8830 |
return f; |
| 8831 |
} |
| 8832 |
|
| 8833 |
static struct ast_frame *dahdi_exception(struct ast_channel *ast) |
| 8834 |
{ |
| 8835 |
struct dahdi_pvt *p = ast_channel_tech_pvt(ast); |
| 8836 |
struct ast_frame *f; |
| 8837 |
ast_mutex_lock(&p->lock); |
| 8838 |
if (dahdi_analog_lib_handles(p->sig, p->radio, p->oprmode)) { |
| 8839 |
struct analog_pvt *analog_p = p->sig_pvt; |
| 8840 |
f = analog_exception(analog_p, ast); |
| 8841 |
} else { |
| 8842 |
f = __dahdi_exception(ast); |
| 8843 |
} |
| 8844 |
ast_mutex_unlock(&p->lock); |
| 8845 |
return f; |
| 8846 |
} |
| 8847 |
|
| 8848 |
static struct ast_frame *dahdi_read(struct ast_channel *ast) |
| 8849 |
{ |
| 8850 |
struct dahdi_pvt *p; |
| 8851 |
int res; |
| 8852 |
int idx; |
| 8853 |
void *readbuf; |
| 8854 |
struct ast_frame *f; |
| 8855 |
|
| 8856 |
|
| 8857 |
|
| 8858 |
|
| 8859 |
|
| 8860 |
|
| 8861 |
p = ast_channel_tech_pvt(ast); |
| 8862 |
while (ast_mutex_trylock(&p->lock)) { |
| 8863 |
CHANNEL_DEADLOCK_AVOIDANCE(ast); |
| 8864 |
|
| 8865 |
|
| 8866 |
|
| 8867 |
|
| 8868 |
|
| 8869 |
|
| 8870 |
|
| 8871 |
|
| 8872 |
|
| 8873 |
|
| 8874 |
|
| 8875 |
|
| 8876 |
if (ast_channel_tech_pvt(ast) != p) { |
| 8877 |
|
| 8878 |
return &ast_null_frame; |
| 8879 |
} |
| 8880 |
} |
| 8881 |
|
| 8882 |
idx = dahdi_get_index(ast, p, 0); |
| 8883 |
|
| 8884 |
|
| 8885 |
if (idx < 0) { |
| 8886 |
ast_log(LOG_WARNING, "We don't exist?\n"); |
| 8887 |
ast_mutex_unlock(&p->lock); |
| 8888 |
return NULL; |
| 8889 |
} |
| 8890 |
|
| 8891 |
if ((p->radio || (p->oprmode < 0)) && p->inalarm) { |
| 8892 |
ast_mutex_unlock(&p->lock); |
| 8893 |
return NULL; |
| 8894 |
} |
| 8895 |
|
| 8896 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 8897 |
p->subs[idx].f.datalen = 0; |
| 8898 |
p->subs[idx].f.samples = 0; |
| 8899 |
p->subs[idx].f.mallocd = 0; |
| 8900 |
p->subs[idx].f.offset = 0; |
| 8901 |
p->subs[idx].f.subclass.integer = 0; |
| 8902 |
p->subs[idx].f.delivery = ast_tv(0,0); |
| 8903 |
p->subs[idx].f.src = "dahdi_read"; |
| 8904 |
p->subs[idx].f.data.ptr = NULL; |
| 8905 |
|
| 8906 |
|
| 8907 |
if ((p->radio || (p->oprmode < 0)) && (!p->firstradio)) |
| 8908 |
{ |
| 8909 |
struct dahdi_params ps; |
| 8910 |
|
| 8911 |
memset(&ps, 0, sizeof(ps)); |
| 8912 |
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &ps) < 0) { |
| 8913 |
ast_mutex_unlock(&p->lock); |
| 8914 |
return NULL; |
| 8915 |
} |
| 8916 |
p->firstradio = 1; |
| 8917 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 8918 |
if (ps.rxisoffhook) |
| 8919 |
{ |
| 8920 |
p->subs[idx].f.subclass.integer = AST_CONTROL_RADIO_KEY; |
| 8921 |
} |
| 8922 |
else |
| 8923 |
{ |
| 8924 |
p->subs[idx].f.subclass.integer = AST_CONTROL_RADIO_UNKEY; |
| 8925 |
} |
| 8926 |
ast_mutex_unlock(&p->lock); |
| 8927 |
return &p->subs[idx].f; |
| 8928 |
} |
| 8929 |
if (p->ringt > 0) { |
| 8930 |
if (!(--p->ringt)) { |
| 8931 |
ast_mutex_unlock(&p->lock); |
| 8932 |
return NULL; |
| 8933 |
} |
| 8934 |
} |
| 8935 |
|
| 8936 |
#ifdef HAVE_OPENR2 |
| 8937 |
if (p->mfcr2) { |
| 8938 |
openr2_chan_process_event(p->r2chan); |
| 8939 |
if (OR2_DIR_FORWARD == openr2_chan_get_direction(p->r2chan)) { |
| 8940 |
struct ast_frame fr = { AST_FRAME_CONTROL, { AST_CONTROL_PROGRESS } }; |
| 8941 |
|
| 8942 |
|
| 8943 |
if (p->mfcr2_call_accepted && |
| 8944 |
!p->mfcr2_progress_sent && |
| 8945 |
ast_channel_state(ast) == AST_STATE_RINGING) { |
| 8946 |
ast_debug(1, "Enqueuing progress frame after R2 accept in chan %d\n", p->channel); |
| 8947 |
ast_queue_frame(p->owner, &fr); |
| 8948 |
p->mfcr2_progress_sent = 1; |
| 8949 |
} |
| 8950 |
} |
| 8951 |
} |
| 8952 |
#endif |
| 8953 |
|
| 8954 |
if (p->subs[idx].needringing) { |
| 8955 |
|
| 8956 |
p->subs[idx].needringing = 0; |
| 8957 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 8958 |
p->subs[idx].f.subclass.integer = AST_CONTROL_RINGING; |
| 8959 |
ast_setstate(ast, AST_STATE_RINGING); |
| 8960 |
ast_mutex_unlock(&p->lock); |
| 8961 |
return &p->subs[idx].f; |
| 8962 |
} |
| 8963 |
|
| 8964 |
if (p->subs[idx].needbusy) { |
| 8965 |
|
| 8966 |
p->subs[idx].needbusy = 0; |
| 8967 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 8968 |
p->subs[idx].f.subclass.integer = AST_CONTROL_BUSY; |
| 8969 |
ast_mutex_unlock(&p->lock); |
| 8970 |
return &p->subs[idx].f; |
| 8971 |
} |
| 8972 |
|
| 8973 |
if (p->subs[idx].needcongestion) { |
| 8974 |
|
| 8975 |
p->subs[idx].needcongestion = 0; |
| 8976 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 8977 |
p->subs[idx].f.subclass.integer = AST_CONTROL_CONGESTION; |
| 8978 |
ast_mutex_unlock(&p->lock); |
| 8979 |
return &p->subs[idx].f; |
| 8980 |
} |
| 8981 |
|
| 8982 |
if (p->subs[idx].needanswer) { |
| 8983 |
|
| 8984 |
p->subs[idx].needanswer = 0; |
| 8985 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 8986 |
p->subs[idx].f.subclass.integer = AST_CONTROL_ANSWER; |
| 8987 |
ast_mutex_unlock(&p->lock); |
| 8988 |
return &p->subs[idx].f; |
| 8989 |
} |
| 8990 |
#ifdef HAVE_OPENR2 |
| 8991 |
if (p->mfcr2 && openr2_chan_get_read_enabled(p->r2chan)) { |
| 8992 |
|
| 8993 |
|
| 8994 |
|
| 8995 |
|
| 8996 |
ast_mutex_unlock(&p->lock); |
| 8997 |
return &ast_null_frame; |
| 8998 |
} |
| 8999 |
#endif |
| 9000 |
|
| 9001 |
if (p->subs[idx].needflash) { |
| 9002 |
|
| 9003 |
p->subs[idx].needflash = 0; |
| 9004 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 9005 |
p->subs[idx].f.subclass.integer = AST_CONTROL_FLASH; |
| 9006 |
ast_mutex_unlock(&p->lock); |
| 9007 |
return &p->subs[idx].f; |
| 9008 |
} |
| 9009 |
|
| 9010 |
if (p->subs[idx].needhold) { |
| 9011 |
|
| 9012 |
p->subs[idx].needhold = 0; |
| 9013 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 9014 |
p->subs[idx].f.subclass.integer = AST_CONTROL_HOLD; |
| 9015 |
ast_mutex_unlock(&p->lock); |
| 9016 |
ast_debug(1, "Sending hold on '%s'\n", ast_channel_name(ast)); |
| 9017 |
return &p->subs[idx].f; |
| 9018 |
} |
| 9019 |
|
| 9020 |
if (p->subs[idx].needunhold) { |
| 9021 |
|
| 9022 |
p->subs[idx].needunhold = 0; |
| 9023 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 9024 |
p->subs[idx].f.subclass.integer = AST_CONTROL_UNHOLD; |
| 9025 |
ast_mutex_unlock(&p->lock); |
| 9026 |
ast_debug(1, "Sending unhold on '%s'\n", ast_channel_name(ast)); |
| 9027 |
return &p->subs[idx].f; |
| 9028 |
} |
| 9029 |
|
| 9030 |
|
| 9031 |
|
| 9032 |
|
| 9033 |
|
| 9034 |
if (p->fake_event && p->owner == ast) { |
| 9035 |
if (dahdi_analog_lib_handles(p->sig, p->radio, p->oprmode)) { |
| 9036 |
struct analog_pvt *analog_p = p->sig_pvt; |
| 9037 |
|
| 9038 |
f = analog_exception(analog_p, ast); |
| 9039 |
} else { |
| 9040 |
f = __dahdi_exception(ast); |
| 9041 |
} |
| 9042 |
ast_mutex_unlock(&p->lock); |
| 9043 |
return f; |
| 9044 |
} |
| 9045 |
|
| 9046 |
if (ast_format_cmp(ast_channel_rawreadformat(ast), ast_format_slin) == AST_FORMAT_CMP_EQUAL) { |
| 9047 |
if (!p->subs[idx].linear) { |
| 9048 |
p->subs[idx].linear = 1; |
| 9049 |
res = dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear); |
| 9050 |
if (res) |
| 9051 |
ast_log(LOG_WARNING, "Unable to set channel %d (index %d) to linear mode.\n", p->channel, idx); |
| 9052 |
} |
| 9053 |
} else { |
| 9054 |
if (p->subs[idx].linear) { |
| 9055 |
p->subs[idx].linear = 0; |
| 9056 |
res = dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear); |
| 9057 |
if (res) |
| 9058 |
ast_log(LOG_WARNING, "Unable to set channel %d (index %d) to companded mode.\n", p->channel, idx); |
| 9059 |
} |
| 9060 |
} |
| 9061 |
readbuf = ((unsigned char *)p->subs[idx].buffer) + AST_FRIENDLY_OFFSET; |
| 9062 |
CHECK_BLOCKING(ast); |
| 9063 |
res = read(p->subs[idx].dfd, readbuf, p->subs[idx].linear ? READ_SIZE * 2 : READ_SIZE); |
| 9064 |
ast_clear_flag(ast_channel_flags(ast), AST_FLAG_BLOCKING); |
| 9065 |
|
| 9066 |
if (res < 0) { |
| 9067 |
f = NULL; |
| 9068 |
if (res == -1) { |
| 9069 |
if (errno == EAGAIN) { |
| 9070 |
|
| 9071 |
ast_mutex_unlock(&p->lock); |
| 9072 |
return &p->subs[idx].f; |
| 9073 |
} else if (errno == ELAST) { |
| 9074 |
if (dahdi_analog_lib_handles(p->sig, p->radio, p->oprmode)) { |
| 9075 |
struct analog_pvt *analog_p = p->sig_pvt; |
| 9076 |
f = analog_exception(analog_p, ast); |
| 9077 |
} else { |
| 9078 |
f = __dahdi_exception(ast); |
| 9079 |
} |
| 9080 |
} else |
| 9081 |
ast_log(LOG_WARNING, "dahdi_rec: %s\n", strerror(errno)); |
| 9082 |
} |
| 9083 |
ast_mutex_unlock(&p->lock); |
| 9084 |
return f; |
| 9085 |
} |
| 9086 |
if (res != (p->subs[idx].linear ? READ_SIZE * 2 : READ_SIZE)) { |
| 9087 |
ast_debug(1, "Short read (%d/%d), must be an event...\n", res, p->subs[idx].linear ? READ_SIZE * 2 : READ_SIZE); |
| 9088 |
if (dahdi_analog_lib_handles(p->sig, p->radio, p->oprmode)) { |
| 9089 |
struct analog_pvt *analog_p = p->sig_pvt; |
| 9090 |
f = analog_exception(analog_p, ast); |
| 9091 |
} else { |
| 9092 |
f = __dahdi_exception(ast); |
| 9093 |
} |
| 9094 |
ast_mutex_unlock(&p->lock); |
| 9095 |
return f; |
| 9096 |
} |
| 9097 |
if (p->tdd) { |
| 9098 |
int c; |
| 9099 |
|
| 9100 |
c = tdd_feed(p->tdd,readbuf,READ_SIZE); |
| 9101 |
if (c < 0) { |
| 9102 |
ast_debug(1,"tdd_feed failed\n"); |
| 9103 |
ast_mutex_unlock(&p->lock); |
| 9104 |
return NULL; |
| 9105 |
} |
| 9106 |
if (c) { |
| 9107 |
p->subs[idx].f.subclass.integer = 0; |
| 9108 |
p->subs[idx].f.frametype = AST_FRAME_TEXT; |
| 9109 |
p->subs[idx].f.mallocd = 0; |
| 9110 |
p->subs[idx].f.offset = AST_FRIENDLY_OFFSET; |
| 9111 |
p->subs[idx].f.data.ptr = p->subs[idx].buffer + AST_FRIENDLY_OFFSET; |
| 9112 |
p->subs[idx].f.datalen = 1; |
| 9113 |
*((char *) p->subs[idx].f.data.ptr) = c; |
| 9114 |
ast_mutex_unlock(&p->lock); |
| 9115 |
return &p->subs[idx].f; |
| 9116 |
} |
| 9117 |
} |
| 9118 |
if (idx == SUB_REAL) { |
| 9119 |
|
| 9120 |
if (p->cidcwexpire) { |
| 9121 |
if (!--p->cidcwexpire) { |
| 9122 |
|
| 9123 |
ast_verb(3, "CPE does not support Call Waiting Caller*ID.\n"); |
| 9124 |
restore_conference(p); |
| 9125 |
} |
| 9126 |
} |
| 9127 |
if (p->cid_suppress_expire) { |
| 9128 |
--p->cid_suppress_expire; |
| 9129 |
} |
| 9130 |
if (p->callwaitingrepeat) { |
| 9131 |
if (!--p->callwaitingrepeat) { |
| 9132 |
|
| 9133 |
++p->callwaitrings; |
| 9134 |
dahdi_callwait(ast); |
| 9135 |
} |
| 9136 |
} |
| 9137 |
} |
| 9138 |
if (p->subs[idx].linear) { |
| 9139 |
p->subs[idx].f.datalen = READ_SIZE * 2; |
| 9140 |
} else |
| 9141 |
p->subs[idx].f.datalen = READ_SIZE; |
| 9142 |
|
| 9143 |
|
| 9144 |
if ((p->owner == ast) && p->cidspill) { |
| 9145 |
send_callerid(p); |
| 9146 |
} |
| 9147 |
|
| 9148 |
p->subs[idx].f.frametype = AST_FRAME_VOICE; |
| 9149 |
p->subs[idx].f.subclass.format = ast_channel_rawreadformat(ast); |
| 9150 |
p->subs[idx].f.samples = READ_SIZE; |
| 9151 |
p->subs[idx].f.mallocd = 0; |
| 9152 |
p->subs[idx].f.offset = AST_FRIENDLY_OFFSET; |
| 9153 |
p->subs[idx].f.data.ptr = p->subs[idx].buffer + AST_FRIENDLY_OFFSET / sizeof(p->subs[idx].buffer[0]); |
| 9154 |
#if 0 |
| 9155 |
ast_debug(1, "Read %d of voice on %s\n", p->subs[idx].f.datalen, ast->name); |
| 9156 |
#endif |
| 9157 |
if ((p->dialing && !p->waitingfordt.tv_sec) || p->radio || |
| 9158 |
(idx && (ast_channel_state(ast) != AST_STATE_UP)) || |
| 9159 |
((idx == SUB_CALLWAIT) && !p->subs[SUB_CALLWAIT].inthreeway) |
| 9160 |
) { |
| 9161 |
|
| 9162 |
|
| 9163 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 9164 |
p->subs[idx].f.subclass.integer = 0; |
| 9165 |
p->subs[idx].f.samples = 0; |
| 9166 |
p->subs[idx].f.mallocd = 0; |
| 9167 |
p->subs[idx].f.offset = 0; |
| 9168 |
p->subs[idx].f.data.ptr = NULL; |
| 9169 |
p->subs[idx].f.datalen= 0; |
| 9170 |
} |
| 9171 |
if (p->dsp && (!p->ignoredtmf || p->callwaitcas || p->busydetect || p->callprogress || p->waitingfordt.tv_sec || p->dialtone_detect) && !idx) { |
| 9172 |
|
| 9173 |
int mute; |
| 9174 |
|
| 9175 |
if ((p->dsp_features & DSP_FEATURE_FAX_DETECT) |
| 9176 |
&& p->faxdetect_timeout |
| 9177 |
&& p->faxdetect_timeout <= ast_channel_get_up_time(ast)) { |
| 9178 |
p->dsp_features &= ~DSP_FEATURE_FAX_DETECT; |
| 9179 |
ast_dsp_set_features(p->dsp, p->dsp_features); |
| 9180 |
ast_debug(1, "Channel driver fax CNG detection timeout on %s\n", |
| 9181 |
ast_channel_name(ast)); |
| 9182 |
} |
| 9183 |
|
| 9184 |
f = ast_dsp_process(ast, p->dsp, &p->subs[idx].f); |
| 9185 |
|
| 9186 |
|
| 9187 |
mute = ast_dsp_was_muted(p->dsp); |
| 9188 |
if (p->muting != mute) { |
| 9189 |
p->muting = mute; |
| 9190 |
dahdi_confmute(p, mute); |
| 9191 |
} |
| 9192 |
|
| 9193 |
if (f) { |
| 9194 |
if ((p->dsp_features & DSP_FEATURE_WAITDIALTONE) && (p->dialtone_detect > 0) |
| 9195 |
&& !p->outgoing && ast_channel_state(ast) == AST_STATE_UP) { |
| 9196 |
if (++p->dialtone_scanning_time_elapsed >= p->dialtone_detect) { |
| 9197 |
p->dsp_features &= ~DSP_FEATURE_WAITDIALTONE; |
| 9198 |
ast_dsp_set_features(p->dsp, p->dsp_features); |
| 9199 |
} |
| 9200 |
} |
| 9201 |
if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_BUSY)) { |
| 9202 |
if ((ast_channel_state(ast) == AST_STATE_UP) && !p->outgoing) { |
| 9203 |
|
| 9204 |
|
| 9205 |
|
| 9206 |
|
| 9207 |
ast_frfree(f); |
| 9208 |
f = NULL; |
| 9209 |
} |
| 9210 |
} else if (p->dialtone_detect && !p->outgoing && f->frametype == AST_FRAME_VOICE) { |
| 9211 |
if ((ast_dsp_get_tstate(p->dsp) == DSP_TONE_STATE_DIALTONE) && (ast_dsp_get_tcount(p->dsp) > 9)) { |
| 9212 |
|
| 9213 |
ast_frfree(f); |
| 9214 |
f = NULL; |
| 9215 |
} |
| 9216 |
} else if (f->frametype == AST_FRAME_DTMF_BEGIN |
| 9217 |
|| f->frametype == AST_FRAME_DTMF_END) { |
| 9218 |
#ifdef HAVE_PRI |
| 9219 |
if (dahdi_sig_pri_lib_handles(p->sig) |
| 9220 |
&& ((struct sig_pri_chan *) p->sig_pvt)->call_level < SIG_PRI_CALL_LEVEL_PROCEEDING |
| 9221 |
&& p->pri |
| 9222 |
&& ((!p->outgoing && (p->pri->overlapdial & DAHDI_OVERLAPDIAL_INCOMING)) |
| 9223 |
|| (p->outgoing && (p->pri->overlapdial & DAHDI_OVERLAPDIAL_OUTGOING)))) { |
| 9224 |
|
| 9225 |
ast_debug(1, "Absorbing inband %s DTMF digit: 0x%02X '%c' on %s\n", |
| 9226 |
f->frametype == AST_FRAME_DTMF_BEGIN ? "begin" : "end", |
| 9227 |
(unsigned)f->subclass.integer, f->subclass.integer, ast_channel_name(ast)); |
| 9228 |
|
| 9229 |
f->frametype = AST_FRAME_NULL; |
| 9230 |
f->subclass.integer = 0; |
| 9231 |
} |
| 9232 |
#endif |
| 9233 |
|
| 9234 |
p->pulsedial = 0; |
| 9235 |
} else if (p->waitingfordt.tv_sec) { |
| 9236 |
if (ast_tvdiff_ms(ast_tvnow(), p->waitingfordt) >= p->waitfordialtoneduration) { |
| 9237 |
p->waitingfordt.tv_sec = 0; |
| 9238 |
ast_log(LOG_NOTICE, "Never saw dialtone on channel %d\n", p->channel); |
| 9239 |
ast_frfree(f); |
| 9240 |
f = NULL; |
| 9241 |
} else if (f->frametype == AST_FRAME_VOICE) { |
| 9242 |
f->frametype = AST_FRAME_NULL; |
| 9243 |
f->subclass.integer = 0; |
| 9244 |
if ((ast_dsp_get_tstate(p->dsp) == DSP_TONE_STATE_DIALTONE || ast_dsp_get_tstate(p->dsp) == DSP_TONE_STATE_RINGING) && ast_dsp_get_tcount(p->dsp) > 9) { |
| 9245 |
p->waitingfordt.tv_sec = 0; |
| 9246 |
p->dsp_features &= ~DSP_FEATURE_WAITDIALTONE; |
| 9247 |
ast_dsp_set_features(p->dsp, p->dsp_features); |
| 9248 |
ast_debug(1, "Got 10 samples of dialtone!\n"); |
| 9249 |
if (!ast_strlen_zero(p->dop.dialstr)) { |
| 9250 |
res = dahdi_dial_str(p, p->dop.op, p->dop.dialstr); |
| 9251 |
if (res) { |
| 9252 |
p->dop.dialstr[0] = '\0'; |
| 9253 |
ast_mutex_unlock(&p->lock); |
| 9254 |
ast_frfree(f); |
| 9255 |
return NULL; |
| 9256 |
} else { |
| 9257 |
ast_debug(1, "Sent deferred digit string: %s\n", p->dop.dialstr); |
| 9258 |
p->dialing = 1; |
| 9259 |
p->dop.dialstr[0] = '\0'; |
| 9260 |
p->dop.op = DAHDI_DIAL_OP_REPLACE; |
| 9261 |
ast_setstate(ast, AST_STATE_DIALING); |
| 9262 |
} |
| 9263 |
} |
| 9264 |
} |
| 9265 |
} |
| 9266 |
} |
| 9267 |
} |
| 9268 |
} else |
| 9269 |
f = &p->subs[idx].f; |
| 9270 |
|
| 9271 |
if (f) { |
| 9272 |
struct analog_pvt *analog_p = p->sig_pvt; |
| 9273 |
switch (f->frametype) { |
| 9274 |
case AST_FRAME_DTMF_BEGIN: |
| 9275 |
case AST_FRAME_DTMF_END: |
| 9276 |
if (dahdi_analog_lib_handles(p->sig, p->radio, p->oprmode)) { |
| 9277 |
analog_handle_dtmf(p->sig_pvt, ast, idx, &f); |
| 9278 |
} else { |
| 9279 |
dahdi_handle_dtmf(ast, idx, &f); |
| 9280 |
} |
| 9281 |
if (!(analog_p->dialmode == ANALOG_DIALMODE_BOTH || analog_p->dialmode == ANALOG_DIALMODE_DTMF)) { |
| 9282 |
if (f->frametype == AST_FRAME_DTMF_END) { |
| 9283 |
ast_debug(1, "Dropping DTMF digit '%c' because tone dialing is disabled\n", f->subclass.integer); |
| 9284 |
} |
| 9285 |
f->frametype = AST_FRAME_NULL; |
| 9286 |
f->subclass.integer = 0; |
| 9287 |
} |
| 9288 |
break; |
| 9289 |
case AST_FRAME_VOICE: |
| 9290 |
if (p->cidspill || p->cid_suppress_expire) { |
| 9291 |
|
| 9292 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 9293 |
p->subs[idx].f.subclass.integer = 0; |
| 9294 |
p->subs[idx].f.samples = 0; |
| 9295 |
p->subs[idx].f.mallocd = 0; |
| 9296 |
p->subs[idx].f.offset = 0; |
| 9297 |
p->subs[idx].f.data.ptr = NULL; |
| 9298 |
p->subs[idx].f.datalen= 0; |
| 9299 |
} |
| 9300 |
break; |
| 9301 |
default: |
| 9302 |
break; |
| 9303 |
} |
| 9304 |
} |
| 9305 |
|
| 9306 |
ast_mutex_unlock(&p->lock); |
| 9307 |
return f; |
| 9308 |
} |
| 9309 |
|
| 9310 |
static int my_dahdi_write(struct dahdi_pvt *p, unsigned char *buf, int len, int idx, int linear) |
| 9311 |
{ |
| 9312 |
int sent=0; |
| 9313 |
int size; |
| 9314 |
int res; |
| 9315 |
int fd; |
| 9316 |
fd = p->subs[idx].dfd; |
| 9317 |
while (len) { |
| 9318 |
size = len; |
| 9319 |
if (size > (linear ? READ_SIZE * 2 : READ_SIZE)) |
| 9320 |
size = (linear ? READ_SIZE * 2 : READ_SIZE); |
| 9321 |
res = write(fd, buf, size); |
| 9322 |
if (res != size) { |
| 9323 |
ast_debug(1, "Write returned %d (%s) on channel %d\n", res, strerror(errno), p->channel); |
| 9324 |
return sent; |
| 9325 |
} |
| 9326 |
len -= size; |
| 9327 |
buf += size; |
| 9328 |
} |
| 9329 |
return sent; |
| 9330 |
} |
| 9331 |
|
| 9332 |
static int dahdi_write(struct ast_channel *ast, struct ast_frame *frame) |
| 9333 |
{ |
| 9334 |
struct dahdi_pvt *p; |
| 9335 |
int res; |
| 9336 |
int idx; |
| 9337 |
|
| 9338 |
|
| 9339 |
if (frame->frametype != AST_FRAME_VOICE) { |
| 9340 |
if (frame->frametype != AST_FRAME_IMAGE) { |
| 9341 |
ast_log(LOG_WARNING, "Don't know what to do with frame type '%u'\n", |
| 9342 |
frame->frametype); |
| 9343 |
} |
| 9344 |
return 0; |
| 9345 |
} |
| 9346 |
|
| 9347 |
|
| 9348 |
if (!frame->data.ptr || !frame->datalen) { |
| 9349 |
return 0; |
| 9350 |
} |
| 9351 |
|
| 9352 |
p = ast_channel_tech_pvt(ast); |
| 9353 |
ast_mutex_lock(&p->lock); |
| 9354 |
|
| 9355 |
idx = dahdi_get_index(ast, p, 0); |
| 9356 |
if (idx < 0) { |
| 9357 |
ast_mutex_unlock(&p->lock); |
| 9358 |
ast_log(LOG_WARNING, "%s doesn't really exist?\n", ast_channel_name(ast)); |
| 9359 |
return -1; |
| 9360 |
} |
| 9361 |
|
| 9362 |
if (p->sig == SIG_FXOLS || p->sig == SIG_FXOKS || p->sig == SIG_FXOGS) { |
| 9363 |
struct analog_pvt *analog_p = p->sig_pvt; |
| 9364 |
if (analog_p->callwaitingdeluxepending) { |
| 9365 |
unsigned int mssinceflash = ast_tvdiff_ms(ast_tvnow(), analog_p->flashtime); |
| 9366 |
if (mssinceflash >= 1000) { |
| 9367 |
|
| 9368 |
|
| 9369 |
|
| 9370 |
|
| 9371 |
|
| 9372 |
analog_p->callwaitingdeluxepending = 0; |
| 9373 |
analog_callwaiting_deluxe(analog_p, 0); |
| 9374 |
} |
| 9375 |
ast_mutex_unlock(&p->lock); |
| 9376 |
|
| 9377 |
ast_debug(5, "Dropping frame since Call Waiting Deluxe pending on %s\n", ast_channel_name(ast)); |
| 9378 |
return 0; |
| 9379 |
} |
| 9380 |
} |
| 9381 |
|
| 9382 |
if (p->dialing) { |
| 9383 |
ast_mutex_unlock(&p->lock); |
| 9384 |
ast_debug(5, "Dropping frame since I'm still dialing on %s...\n", |
| 9385 |
ast_channel_name(ast)); |
| 9386 |
return 0; |
| 9387 |
} |
| 9388 |
if (!p->owner) { |
| 9389 |
ast_mutex_unlock(&p->lock); |
| 9390 |
ast_debug(5, "Dropping frame since there is no active owner on %s...\n", |
| 9391 |
ast_channel_name(ast)); |
| 9392 |
return 0; |
| 9393 |
} |
| 9394 |
if (p->cidspill) { |
| 9395 |
ast_mutex_unlock(&p->lock); |
| 9396 |
ast_debug(5, "Dropping frame since I've still got a callerid spill on %s...\n", |
| 9397 |
ast_channel_name(ast)); |
| 9398 |
return 0; |
| 9399 |
} |
| 9400 |
|
| 9401 |
if (ast_format_cmp(frame->subclass.format, ast_format_slin) == AST_FORMAT_CMP_EQUAL) { |
| 9402 |
if (!p->subs[idx].linear) { |
| 9403 |
p->subs[idx].linear = 1; |
| 9404 |
res = dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear); |
| 9405 |
if (res) |
| 9406 |
ast_log(LOG_WARNING, "Unable to set linear mode on channel %d\n", p->channel); |
| 9407 |
} |
| 9408 |
res = my_dahdi_write(p, (unsigned char *)frame->data.ptr, frame->datalen, idx, 1); |
| 9409 |
} else if (ast_format_cmp(frame->subclass.format, ast_format_ulaw) == AST_FORMAT_CMP_EQUAL |
| 9410 |
|| ast_format_cmp(frame->subclass.format, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) { |
| 9411 |
|
| 9412 |
if (p->subs[idx].linear) { |
| 9413 |
p->subs[idx].linear = 0; |
| 9414 |
res = dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear); |
| 9415 |
if (res) |
| 9416 |
ast_log(LOG_WARNING, "Unable to set companded mode on channel %d\n", p->channel); |
| 9417 |
} |
| 9418 |
res = my_dahdi_write(p, (unsigned char *)frame->data.ptr, frame->datalen, idx, 0); |
| 9419 |
} else { |
| 9420 |
ast_mutex_unlock(&p->lock); |
| 9421 |
ast_log(LOG_WARNING, "Cannot handle frames in %s format\n", |
| 9422 |
ast_format_get_name(frame->subclass.format)); |
| 9423 |
return -1; |
| 9424 |
} |
| 9425 |
ast_mutex_unlock(&p->lock); |
| 9426 |
if (res < 0) { |
| 9427 |
ast_log(LOG_WARNING, "write failed: %s\n", strerror(errno)); |
| 9428 |
return -1; |
| 9429 |
} |
| 9430 |
return 0; |
| 9431 |
} |
| 9432 |
|
| 9433 |
static int dahdi_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen) |
| 9434 |
{ |
| 9435 |
struct dahdi_pvt *p = ast_channel_tech_pvt(chan); |
| 9436 |
int res=-1; |
| 9437 |
int idx; |
| 9438 |
int func = DAHDI_FLASH; |
| 9439 |
|
| 9440 |
ast_mutex_lock(&p->lock); |
| 9441 |
ast_debug(1, "Requested indication %d on channel %s\n", condition, ast_channel_name(chan)); |
| 9442 |
switch (p->sig) { |
| 9443 |
#if defined(HAVE_PRI) |
| 9444 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 9445 |
res = sig_pri_indicate(p->sig_pvt, chan, condition, data, datalen); |
| 9446 |
ast_mutex_unlock(&p->lock); |
| 9447 |
return res; |
| 9448 |
#endif |
| 9449 |
#if defined(HAVE_SS7) |
| 9450 |
case SIG_SS7: |
| 9451 |
res = sig_ss7_indicate(p->sig_pvt, chan, condition, data, datalen); |
| 9452 |
ast_mutex_unlock(&p->lock); |
| 9453 |
return res; |
| 9454 |
#endif |
| 9455 |
default: |
| 9456 |
break; |
| 9457 |
} |
| 9458 |
#ifdef HAVE_OPENR2 |
| 9459 |
if (p->mfcr2 && !p->mfcr2_call_accepted) { |
| 9460 |
ast_mutex_unlock(&p->lock); |
| 9461 |
|
| 9462 |
|
| 9463 |
return 0; |
| 9464 |
} |
| 9465 |
#endif |
| 9466 |
idx = dahdi_get_index(chan, p, 0); |
| 9467 |
if (idx == SUB_REAL) { |
| 9468 |
switch (condition) { |
| 9469 |
case AST_CONTROL_BUSY: |
| 9470 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_BUSY); |
| 9471 |
break; |
| 9472 |
case AST_CONTROL_RINGING: |
| 9473 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_RINGTONE); |
| 9474 |
|
| 9475 |
if (ast_channel_state(chan) != AST_STATE_UP) { |
| 9476 |
if ((ast_channel_state(chan) != AST_STATE_RING) || |
| 9477 |
((p->sig != SIG_FXSKS) && |
| 9478 |
(p->sig != SIG_FXSLS) && |
| 9479 |
(p->sig != SIG_FXSGS))) { |
| 9480 |
|
| 9481 |
|
| 9482 |
ast_setstate(chan, AST_STATE_RING); |
| 9483 |
} |
| 9484 |
} |
| 9485 |
break; |
| 9486 |
case AST_CONTROL_INCOMPLETE: |
| 9487 |
ast_debug(1, "Received AST_CONTROL_INCOMPLETE on %s\n", ast_channel_name(chan)); |
| 9488 |
|
| 9489 |
res = 0; |
| 9490 |
break; |
| 9491 |
case AST_CONTROL_PROCEEDING: |
| 9492 |
ast_debug(1, "Received AST_CONTROL_PROCEEDING on %s\n", ast_channel_name(chan)); |
| 9493 |
|
| 9494 |
res = 0; |
| 9495 |
break; |
| 9496 |
case AST_CONTROL_PROGRESS: |
| 9497 |
ast_debug(1, "Received AST_CONTROL_PROGRESS on %s\n", ast_channel_name(chan)); |
| 9498 |
|
| 9499 |
res = 0; |
| 9500 |
break; |
| 9501 |
case AST_CONTROL_CONGESTION: |
| 9502 |
|
| 9503 |
switch (ast_channel_hangupcause(chan)) { |
| 9504 |
case AST_CAUSE_USER_BUSY: |
| 9505 |
case AST_CAUSE_NORMAL_CLEARING: |
| 9506 |
case 0: |
| 9507 |
|
| 9508 |
ast_channel_hangupcause_set(chan, AST_CAUSE_CONGESTION); |
| 9509 |
break; |
| 9510 |
default: |
| 9511 |
break; |
| 9512 |
} |
| 9513 |
break; |
| 9514 |
case AST_CONTROL_HOLD: |
| 9515 |
ast_moh_start(chan, data, p->mohinterpret); |
| 9516 |
break; |
| 9517 |
case AST_CONTROL_UNHOLD: |
| 9518 |
ast_moh_stop(chan); |
| 9519 |
break; |
| 9520 |
case AST_CONTROL_RADIO_KEY: |
| 9521 |
if (p->radio) |
| 9522 |
res = dahdi_set_hook(p->subs[idx].dfd, DAHDI_OFFHOOK); |
| 9523 |
res = 0; |
| 9524 |
break; |
| 9525 |
case AST_CONTROL_RADIO_UNKEY: |
| 9526 |
if (p->radio) |
| 9527 |
res = dahdi_set_hook(p->subs[idx].dfd, DAHDI_RINGOFF); |
| 9528 |
res = 0; |
| 9529 |
break; |
| 9530 |
case AST_CONTROL_FLASH: |
| 9531 |
|
| 9532 |
if (ISTRUNK(p) && (p->sig != SIG_PRI)) { |
| 9533 |
|
| 9534 |
p->dop.dialstr[0] = '\0'; |
| 9535 |
if ((ioctl(p->subs[SUB_REAL].dfd,DAHDI_HOOK,&func) == -1) && (errno != EINPROGRESS)) { |
| 9536 |
ast_log(LOG_WARNING, "Unable to flash external trunk on channel %s: %s\n", |
| 9537 |
ast_channel_name(chan), strerror(errno)); |
| 9538 |
} else |
| 9539 |
res = 0; |
| 9540 |
} else |
| 9541 |
res = 0; |
| 9542 |
break; |
| 9543 |
case AST_CONTROL_SRCUPDATE: |
| 9544 |
res = 0; |
| 9545 |
break; |
| 9546 |
case -1: |
| 9547 |
res = tone_zone_play_tone(p->subs[idx].dfd, -1); |
| 9548 |
break; |
| 9549 |
} |
| 9550 |
} else { |
| 9551 |
res = 0; |
| 9552 |
} |
| 9553 |
ast_mutex_unlock(&p->lock); |
| 9554 |
return res; |
| 9555 |
} |
| 9556 |
|
| 9557 |
#if defined(HAVE_PRI) |
| 9558 |
static struct ast_str *create_channel_name(struct dahdi_pvt *i, int is_outgoing, char *address) |
| 9559 |
#else |
| 9560 |
static struct ast_str *create_channel_name(struct dahdi_pvt *i) |
| 9561 |
#endif |
| 9562 |
{ |
| 9563 |
struct ast_str *chan_name; |
| 9564 |
int x, y; |
| 9565 |
|
| 9566 |
|
| 9567 |
if (!(chan_name = ast_str_create(32))) { |
| 9568 |
return NULL; |
| 9569 |
} |
| 9570 |
if (i->channel == CHAN_PSEUDO) { |
| 9571 |
ast_str_set(&chan_name, 0, "pseudo-%ld", ast_random()); |
| 9572 |
#if defined(HAVE_PRI) |
| 9573 |
} else if (i->pri) { |
| 9574 |
ast_mutex_lock(&i->pri->lock); |
| 9575 |
y = ++i->pri->new_chan_seq; |
| 9576 |
if (is_outgoing) { |
| 9577 |
ast_str_set(&chan_name, 0, "i%d/%s-%x", i->pri->span, address, (unsigned)y); |
| 9578 |
address[0] = '\0'; |
| 9579 |
} else if (ast_strlen_zero(i->cid_subaddr)) { |
| 9580 |
|
| 9581 |
ast_str_set(&chan_name, 0, "i%d/%s-%x", i->pri->span, i->cid_num, (unsigned)y); |
| 9582 |
} else { |
| 9583 |
|
| 9584 |
ast_str_set(&chan_name, 0, "i%d/%s:%s-%x", i->pri->span, i->cid_num, |
| 9585 |
i->cid_subaddr, (unsigned)y); |
| 9586 |
} |
| 9587 |
ast_mutex_unlock(&i->pri->lock); |
| 9588 |
#endif |
| 9589 |
} else { |
| 9590 |
y = 1; |
| 9591 |
do { |
| 9592 |
ast_str_set(&chan_name, 0, "%d-%d", i->channel, y); |
| 9593 |
for (x = 0; x < 3; ++x) { |
| 9594 |
if (i->subs[x].owner && !strcasecmp(ast_str_buffer(chan_name), |
| 9595 |
ast_channel_name(i->subs[x].owner) + 6)) { |
| 9596 |
break; |
| 9597 |
} |
| 9598 |
} |
| 9599 |
++y; |
| 9600 |
} while (x < 3); |
| 9601 |
} |
| 9602 |
return chan_name; |
| 9603 |
} |
| 9604 |
|
| 9605 |
static struct ast_channel *dahdi_new_callid_clean(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, ast_callid callid, int callid_created) |
| 9606 |
{ |
| 9607 |
struct ast_channel *new_channel = dahdi_new(i, state, startpbx, idx, law, assignedids, requestor, callid); |
| 9608 |
|
| 9609 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 9610 |
|
| 9611 |
return new_channel; |
| 9612 |
} |
| 9613 |
|
| 9614 |
static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, ast_callid callid) |
| 9615 |
{ |
| 9616 |
struct ast_channel *tmp; |
| 9617 |
struct ast_format_cap *caps; |
| 9618 |
struct ast_format *deflaw; |
| 9619 |
int x; |
| 9620 |
int features; |
| 9621 |
struct ast_str *chan_name; |
| 9622 |
struct ast_variable *v; |
| 9623 |
char *dashptr; |
| 9624 |
char device_name[AST_CHANNEL_NAME]; |
| 9625 |
|
| 9626 |
if (i->subs[idx].owner) { |
| 9627 |
ast_log(LOG_WARNING, "Channel %d already has a %s call\n", i->channel,subnames[idx]); |
| 9628 |
return NULL; |
| 9629 |
} |
| 9630 |
|
| 9631 |
#if defined(HAVE_PRI) |
| 9632 |
|
| 9633 |
|
| 9634 |
|
| 9635 |
|
| 9636 |
chan_name = create_channel_name(i, i->outgoing, i->dnid); |
| 9637 |
#else |
| 9638 |
chan_name = create_channel_name(i); |
| 9639 |
#endif |
| 9640 |
if (!chan_name) { |
| 9641 |
return NULL; |
| 9642 |
} |
| 9643 |
|
| 9644 |
caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT); |
| 9645 |
if (!caps) { |
| 9646 |
ast_free(chan_name); |
| 9647 |
return NULL; |
| 9648 |
} |
| 9649 |
|
| 9650 |
tmp = ast_channel_alloc(0, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, assignedids, requestor, i->amaflags, "DAHDI/%s", ast_str_buffer(chan_name)); |
| 9651 |
ast_free(chan_name); |
| 9652 |
if (!tmp) { |
| 9653 |
ao2_ref(caps, -1); |
| 9654 |
return NULL; |
| 9655 |
} |
| 9656 |
|
| 9657 |
ast_channel_stage_snapshot(tmp); |
| 9658 |
|
| 9659 |
if (callid) { |
| 9660 |
ast_channel_callid_set(tmp, callid); |
| 9661 |
} |
| 9662 |
|
| 9663 |
ast_channel_tech_set(tmp, &dahdi_tech); |
| 9664 |
#if defined(HAVE_PRI) |
| 9665 |
if (i->pri) { |
| 9666 |
ast_cc_copy_config_params(i->cc_params, i->pri->cc_params); |
| 9667 |
} |
| 9668 |
#endif |
| 9669 |
ast_channel_cc_params_init(tmp, i->cc_params); |
| 9670 |
if (law) { |
| 9671 |
i->law = law; |
| 9672 |
if (law == DAHDI_LAW_ALAW) { |
| 9673 |
deflaw = ast_format_alaw; |
| 9674 |
} else { |
| 9675 |
deflaw = ast_format_ulaw; |
| 9676 |
} |
| 9677 |
} else { |
| 9678 |
switch (i->sig) { |
| 9679 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 9680 |
|
| 9681 |
i->law = (i->law_default == DAHDI_LAW_ALAW) |
| 9682 |
? DAHDI_LAW_ALAW : DAHDI_LAW_MULAW; |
| 9683 |
break; |
| 9684 |
default: |
| 9685 |
i->law = i->law_default; |
| 9686 |
break; |
| 9687 |
} |
| 9688 |
if (i->law_default == DAHDI_LAW_ALAW) { |
| 9689 |
deflaw = ast_format_alaw; |
| 9690 |
} else { |
| 9691 |
deflaw = ast_format_ulaw; |
| 9692 |
} |
| 9693 |
} |
| 9694 |
ast_channel_set_fd(tmp, 0, i->subs[idx].dfd); |
| 9695 |
ast_format_cap_append(caps, deflaw, 0); |
| 9696 |
ast_channel_nativeformats_set(tmp, caps); |
| 9697 |
ao2_ref(caps, -1); |
| 9698 |
|
| 9699 |
ast_channel_set_rawreadformat(tmp, deflaw); |
| 9700 |
ast_channel_set_readformat(tmp, deflaw); |
| 9701 |
ast_channel_set_rawwriteformat(tmp, deflaw); |
| 9702 |
ast_channel_set_writeformat(tmp, deflaw); |
| 9703 |
i->subs[idx].linear = 0; |
| 9704 |
dahdi_setlinear(i->subs[idx].dfd, i->subs[idx].linear); |
| 9705 |
features = 0; |
| 9706 |
if (idx == SUB_REAL) { |
| 9707 |
if (i->busydetect && CANBUSYDETECT(i)) |
| 9708 |
features |= DSP_FEATURE_BUSY_DETECT; |
| 9709 |
if ((i->callprogress & CALLPROGRESS_PROGRESS) && CANPROGRESSDETECT(i)) |
| 9710 |
features |= DSP_FEATURE_CALL_PROGRESS; |
| 9711 |
if ((i->waitfordialtone || i->dialtone_detect) && CANPROGRESSDETECT(i)) |
| 9712 |
features |= DSP_FEATURE_WAITDIALTONE; |
| 9713 |
if ((!i->outgoing && (i->callprogress & CALLPROGRESS_FAX_INCOMING)) || |
| 9714 |
(i->outgoing && (i->callprogress & CALLPROGRESS_FAX_OUTGOING))) { |
| 9715 |
features |= DSP_FEATURE_FAX_DETECT; |
| 9716 |
} |
| 9717 |
x = DAHDI_TONEDETECT_ON | DAHDI_TONEDETECT_MUTE; |
| 9718 |
if (ioctl(i->subs[idx].dfd, DAHDI_TONEDETECT, &x)) { |
| 9719 |
i->hardwaredtmf = 0; |
| 9720 |
features |= DSP_FEATURE_DIGIT_DETECT; |
| 9721 |
} else if (NEED_MFDETECT(i)) { |
| 9722 |
i->hardwaredtmf = 1; |
| 9723 |
features |= DSP_FEATURE_DIGIT_DETECT; |
| 9724 |
} |
| 9725 |
} |
| 9726 |
if (features) { |
| 9727 |
if (i->dsp) { |
| 9728 |
ast_debug(1, "Already have a dsp on %s?\n", ast_channel_name(tmp)); |
| 9729 |
} else { |
| 9730 |
if (i->channel != CHAN_PSEUDO) |
| 9731 |
i->dsp = ast_dsp_new(); |
| 9732 |
else |
| 9733 |
i->dsp = NULL; |
| 9734 |
if (i->dsp) { |
| 9735 |
i->dsp_features = features; |
| 9736 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 9737 |
|
| 9738 |
if (i->outgoing && (dahdi_sig_pri_lib_handles(i->sig) || (i->sig == SIG_SS7))) { |
| 9739 |
|
| 9740 |
|
| 9741 |
i->dsp_features = features & ~DSP_PROGRESS_TALK; |
| 9742 |
features = 0; |
| 9743 |
} |
| 9744 |
#endif |
| 9745 |
ast_dsp_set_features(i->dsp, features); |
| 9746 |
ast_dsp_set_digitmode(i->dsp, DSP_DIGITMODE_DTMF | i->dtmfrelax); |
| 9747 |
if (!ast_strlen_zero(progzone)) |
| 9748 |
ast_dsp_set_call_progress_zone(i->dsp, progzone); |
| 9749 |
if (i->busydetect && CANBUSYDETECT(i)) { |
| 9750 |
ast_dsp_set_busy_count(i->dsp, i->busycount); |
| 9751 |
ast_dsp_set_busy_pattern(i->dsp, &i->busy_cadence); |
| 9752 |
} |
| 9753 |
} |
| 9754 |
} |
| 9755 |
} |
| 9756 |
|
| 9757 |
i->dialtone_scanning_time_elapsed = 0; |
| 9758 |
|
| 9759 |
if (state == AST_STATE_RING) |
| 9760 |
ast_channel_rings_set(tmp, 1); |
| 9761 |
ast_channel_tech_pvt_set(tmp, i); |
| 9762 |
if ((i->sig == SIG_FXOKS) || (i->sig == SIG_FXOGS) || (i->sig == SIG_FXOLS)) { |
| 9763 |
|
| 9764 |
ast_channel_callgroup_set(tmp, i->callgroup); |
| 9765 |
ast_channel_pickupgroup_set(tmp, i->pickupgroup); |
| 9766 |
ast_channel_named_callgroups_set(tmp, i->named_callgroups); |
| 9767 |
ast_channel_named_pickupgroups_set(tmp, i->named_pickupgroups); |
| 9768 |
} |
| 9769 |
if (!ast_strlen_zero(i->parkinglot)) |
| 9770 |
ast_channel_parkinglot_set(tmp, i->parkinglot); |
| 9771 |
if (!ast_strlen_zero(i->language)) |
| 9772 |
ast_channel_language_set(tmp, i->language); |
| 9773 |
if (!i->owner) |
| 9774 |
i->owner = tmp; |
| 9775 |
if (!ast_strlen_zero(i->accountcode)) |
| 9776 |
ast_channel_accountcode_set(tmp, i->accountcode); |
| 9777 |
if (i->amaflags) |
| 9778 |
ast_channel_amaflags_set(tmp, i->amaflags); |
| 9779 |
i->subs[idx].owner = tmp; |
| 9780 |
ast_channel_context_set(tmp, i->context); |
| 9781 |
if (!dahdi_analog_lib_handles(i->sig, i->radio, i->oprmode)) { |
| 9782 |
ast_channel_call_forward_set(tmp, i->call_forward); |
| 9783 |
} |
| 9784 |
|
| 9785 |
if (!i->adsi) |
| 9786 |
ast_channel_adsicpe_set(tmp, AST_ADSI_UNAVAILABLE); |
| 9787 |
if (!ast_strlen_zero(i->exten)) |
| 9788 |
ast_channel_exten_set(tmp, i->exten); |
| 9789 |
if (!ast_strlen_zero(i->rdnis)) { |
| 9790 |
ast_channel_redirecting(tmp)->from.number.valid = 1; |
| 9791 |
ast_channel_redirecting(tmp)->from.number.str = ast_strdup(i->rdnis); |
| 9792 |
} |
| 9793 |
if (!ast_strlen_zero(i->dnid)) { |
| 9794 |
ast_channel_dialed(tmp)->number.str = ast_strdup(i->dnid); |
| 9795 |
} |
| 9796 |
|
| 9797 |
|
| 9798 |
|
| 9799 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 9800 |
if (!ast_strlen_zero(i->cid_ani)) { |
| 9801 |
ast_channel_caller(tmp)->ani.number.valid = 1; |
| 9802 |
ast_channel_caller(tmp)->ani.number.str = ast_strdup(i->cid_ani); |
| 9803 |
} else if (!ast_strlen_zero(i->cid_num)) { |
| 9804 |
ast_channel_caller(tmp)->ani.number.valid = 1; |
| 9805 |
ast_channel_caller(tmp)->ani.number.str = ast_strdup(i->cid_num); |
| 9806 |
} |
| 9807 |
#else |
| 9808 |
if (!ast_strlen_zero(i->cid_num)) { |
| 9809 |
ast_channel_caller(tmp)->ani.number.valid = 1; |
| 9810 |
ast_channel_caller(tmp)->ani.number.str = ast_strdup(i->cid_num); |
| 9811 |
} |
| 9812 |
#endif |
| 9813 |
ast_channel_caller(tmp)->id.name.presentation = i->callingpres; |
| 9814 |
ast_channel_caller(tmp)->id.number.presentation = i->callingpres; |
| 9815 |
ast_channel_caller(tmp)->id.number.plan = i->cid_ton; |
| 9816 |
ast_channel_caller(tmp)->ani2 = i->cid_ani2; |
| 9817 |
ast_channel_caller(tmp)->id.tag = ast_strdup(i->cid_tag); |
| 9818 |
|
| 9819 |
i->fake_event = 0; |
| 9820 |
|
| 9821 |
dahdi_confmute(i, 0); |
| 9822 |
i->muting = 0; |
| 9823 |
|
| 9824 |
ast_jb_configure(tmp, &global_jbconf); |
| 9825 |
|
| 9826 |
|
| 9827 |
ast_copy_string(device_name, ast_channel_name(tmp), sizeof(device_name)); |
| 9828 |
dashptr = strrchr(device_name, '-'); |
| 9829 |
if (dashptr) { |
| 9830 |
*dashptr = '\0'; |
| 9831 |
} |
| 9832 |
ast_set_flag(ast_channel_flags(tmp), AST_FLAG_DISABLE_DEVSTATE_CACHE); |
| 9833 |
ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, AST_DEVSTATE_NOT_CACHABLE, device_name); |
| 9834 |
|
| 9835 |
for (v = i->vars ; v ; v = v->next) |
| 9836 |
pbx_builtin_setvar_helper(tmp, v->name, v->value); |
| 9837 |
|
| 9838 |
ast_channel_stage_snapshot_done(tmp); |
| 9839 |
|
| 9840 |
ast_channel_unlock(tmp); |
| 9841 |
|
| 9842 |
ast_module_ref(ast_module_info->self); |
| 9843 |
|
| 9844 |
dahdi_ami_channel_event(i, tmp); |
| 9845 |
if (startpbx) { |
| 9846 |
#ifdef HAVE_OPENR2 |
| 9847 |
if (i->mfcr2call) { |
| 9848 |
pbx_builtin_setvar_helper(tmp, "MFCR2_CATEGORY", openr2_proto_get_category_string(i->mfcr2_recvd_category)); |
| 9849 |
} |
| 9850 |
#endif |
| 9851 |
if (ast_pbx_start(tmp)) { |
| 9852 |
ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(tmp)); |
| 9853 |
ast_hangup(tmp); |
| 9854 |
return NULL; |
| 9855 |
} |
| 9856 |
} |
| 9857 |
return tmp; |
| 9858 |
} |
| 9859 |
|
| 9860 |
|
| 9861 |
static int my_getsigstr(struct ast_channel *chan, char *str, const char *term, int ms) |
| 9862 |
{ |
| 9863 |
char c; |
| 9864 |
|
| 9865 |
*str = 0; |
| 9866 |
for (;;) |
| 9867 |
{ |
| 9868 |
|
| 9869 |
c = ast_waitfordigit(chan, ms); |
| 9870 |
|
| 9871 |
if (c < 1) |
| 9872 |
return c; |
| 9873 |
*str++ = c; |
| 9874 |
*str = 0; |
| 9875 |
if (strchr(term, c)) |
| 9876 |
return 1; |
| 9877 |
} |
| 9878 |
} |
| 9879 |
|
| 9880 |
static int dahdi_wink(struct dahdi_pvt *p, int idx) |
| 9881 |
{ |
| 9882 |
int j; |
| 9883 |
dahdi_set_hook(p->subs[idx].dfd, DAHDI_WINK); |
| 9884 |
for (;;) |
| 9885 |
{ |
| 9886 |
|
| 9887 |
j = DAHDI_IOMUX_SIGEVENT; |
| 9888 |
|
| 9889 |
if (ioctl(p->subs[idx].dfd,DAHDI_IOMUX,&j) == -1) return(-1); |
| 9890 |
|
| 9891 |
if (j & DAHDI_IOMUX_SIGEVENT) break; |
| 9892 |
} |
| 9893 |
|
| 9894 |
if (ioctl(p->subs[idx].dfd,DAHDI_GETEVENT,&j) == -1) return(-1); |
| 9895 |
return 0; |
| 9896 |
} |
| 9897 |
|
| 9898 |
static void publish_dnd_state(int channel, const char *status) |
| 9899 |
{ |
| 9900 |
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); |
| 9901 |
RAII_VAR(struct ast_str *, dahdichan, ast_str_create(32), ast_free); |
| 9902 |
if (!dahdichan) { |
| 9903 |
return; |
| 9904 |
} |
| 9905 |
|
| 9906 |
ast_str_set(&dahdichan, 0, "%d", channel); |
| 9907 |
|
| 9908 |
body = ast_json_pack("{s: s, s: s}", |
| 9909 |
"DAHDIChannel", ast_str_buffer(dahdichan), |
| 9910 |
"Status", status); |
| 9911 |
if (!body) { |
| 9912 |
return; |
| 9913 |
} |
| 9914 |
|
| 9915 |
ast_manager_publish_event("DNDState", EVENT_FLAG_SYSTEM, body); |
| 9916 |
} |
| 9917 |
|
| 9918 |
|
| 9919 |
|
| 9920 |
|
| 9921 |
|
| 9922 |
|
| 9923 |
|
| 9924 |
|
| 9925 |
|
| 9926 |
|
| 9927 |
static int dahdi_dnd(struct dahdi_pvt *dahdichan, int flag) |
| 9928 |
{ |
| 9929 |
if (dahdi_analog_lib_handles(dahdichan->sig, dahdichan->radio, dahdichan->oprmode)) { |
| 9930 |
return analog_dnd(dahdichan->sig_pvt, flag); |
| 9931 |
} |
| 9932 |
|
| 9933 |
if (flag == -1) { |
| 9934 |
return dahdichan->dnd; |
| 9935 |
} |
| 9936 |
|
| 9937 |
|
| 9938 |
dahdichan->dnd = flag; |
| 9939 |
ast_verb(3, "%s DND on channel %d\n", |
| 9940 |
flag? "Enabled" : "Disabled", |
| 9941 |
dahdichan->channel); |
| 9942 |
publish_dnd_state(dahdichan->channel, flag ? "enabled" : "disabled"); |
| 9943 |
return 0; |
| 9944 |
} |
| 9945 |
|
| 9946 |
static int canmatch_featurecode(const char *pickupexten, const char *exten) |
| 9947 |
{ |
| 9948 |
int extlen = strlen(exten); |
| 9949 |
|
| 9950 |
if (!extlen) { |
| 9951 |
return 1; |
| 9952 |
} |
| 9953 |
|
| 9954 |
if (extlen < strlen(pickupexten) && !strncmp(pickupexten, exten, extlen)) { |
| 9955 |
return 1; |
| 9956 |
} |
| 9957 |
|
| 9958 |
if (exten[0] == '*' && extlen < 3) { |
| 9959 |
if (extlen == 1) { |
| 9960 |
return 1; |
| 9961 |
} |
| 9962 |
|
| 9963 |
switch (exten[1]) { |
| 9964 |
case '6': |
| 9965 |
case '7': |
| 9966 |
case '8': |
| 9967 |
return 1; |
| 9968 |
} |
| 9969 |
} |
| 9970 |
return 0; |
| 9971 |
} |
| 9972 |
|
| 9973 |
static void *analog_ss_thread(void *data) |
| 9974 |
{ |
| 9975 |
struct ast_channel *chan = data; |
| 9976 |
struct dahdi_pvt *p = ast_channel_tech_pvt(chan); |
| 9977 |
char exten[AST_MAX_EXTENSION] = ""; |
| 9978 |
char exten2[AST_MAX_EXTENSION] = ""; |
| 9979 |
unsigned char buf[256]; |
| 9980 |
char dtmfcid[300]; |
| 9981 |
char dtmfbuf[300]; |
| 9982 |
struct callerid_state *cs = NULL; |
| 9983 |
char *name = NULL, *number = NULL; |
| 9984 |
int distMatches; |
| 9985 |
int curRingData[3]; |
| 9986 |
int receivedRingT; |
| 9987 |
int counter1; |
| 9988 |
int counter; |
| 9989 |
int samples = 0; |
| 9990 |
struct ast_smdi_md_message *smdi_msg = NULL; |
| 9991 |
int flags = 0; |
| 9992 |
int i; |
| 9993 |
int timeout; |
| 9994 |
int getforward = 0; |
| 9995 |
char *s1, *s2; |
| 9996 |
int len = 0; |
| 9997 |
int res; |
| 9998 |
int idx; |
| 9999 |
RAII_VAR(struct ast_features_pickup_config *, pickup_cfg, NULL, ao2_cleanup); |
| 10000 |
const char *pickupexten; |
| 10001 |
|
| 10002 |
ast_mutex_lock(&ss_thread_lock); |
| 10003 |
ss_thread_count++; |
| 10004 |
ast_mutex_unlock(&ss_thread_lock); |
| 10005 |
|
| 10006 |
|
| 10007 |
|
| 10008 |
if (!p) { |
| 10009 |
ast_log(LOG_WARNING, "Channel became a zombie before simple switch could be started (%s)\n", ast_channel_name(chan)); |
| 10010 |
ast_hangup(chan); |
| 10011 |
goto quit; |
| 10012 |
} |
| 10013 |
ast_verb(3, "Starting simple switch on '%s'\n", ast_channel_name(chan)); |
| 10014 |
idx = dahdi_get_index(chan, p, 1); |
| 10015 |
if (idx < 0) { |
| 10016 |
ast_log(LOG_WARNING, "Huh?\n"); |
| 10017 |
ast_hangup(chan); |
| 10018 |
goto quit; |
| 10019 |
} |
| 10020 |
|
| 10021 |
ast_channel_lock(chan); |
| 10022 |
pickup_cfg = ast_get_chan_features_pickup_config(chan); |
| 10023 |
if (!pickup_cfg) { |
| 10024 |
ast_log(LOG_ERROR, "Unable to retrieve pickup configuration options. Unable to detect call pickup extension\n"); |
| 10025 |
pickupexten = ""; |
| 10026 |
} else { |
| 10027 |
pickupexten = ast_strdupa(pickup_cfg->pickupexten); |
| 10028 |
} |
| 10029 |
ast_channel_unlock(chan); |
| 10030 |
|
| 10031 |
if (p->dsp) |
| 10032 |
ast_dsp_digitreset(p->dsp); |
| 10033 |
switch (p->sig) { |
| 10034 |
case SIG_FEATD: |
| 10035 |
case SIG_FEATDMF: |
| 10036 |
case SIG_FEATDMF_TA: |
| 10037 |
case SIG_E911: |
| 10038 |
case SIG_FGC_CAMAMF: |
| 10039 |
case SIG_FEATB: |
| 10040 |
case SIG_EMWINK: |
| 10041 |
case SIG_SF_FEATD: |
| 10042 |
case SIG_SF_FEATDMF: |
| 10043 |
case SIG_SF_FEATB: |
| 10044 |
case SIG_SFWINK: |
| 10045 |
if (dahdi_wink(p, idx)) |
| 10046 |
goto quit; |
| 10047 |
|
| 10048 |
case SIG_EM: |
| 10049 |
case SIG_EM_E1: |
| 10050 |
case SIG_SF: |
| 10051 |
case SIG_FGC_CAMA: |
| 10052 |
res = tone_zone_play_tone(p->subs[idx].dfd, -1); |
| 10053 |
if (p->dsp) |
| 10054 |
ast_dsp_digitreset(p->dsp); |
| 10055 |
|
| 10056 |
if (p->dsp) { |
| 10057 |
if (NEED_MFDETECT(p)) |
| 10058 |
ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MF | p->dtmfrelax); |
| 10059 |
else |
| 10060 |
ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax); |
| 10061 |
} |
| 10062 |
memset(dtmfbuf, 0, sizeof(dtmfbuf)); |
| 10063 |
|
| 10064 |
if (!p->immediate) |
| 10065 |
|
| 10066 |
res = ast_waitfordigit(chan, 5000); |
| 10067 |
else |
| 10068 |
res = 0; |
| 10069 |
if (res > 0) { |
| 10070 |
|
| 10071 |
dtmfbuf[0] = res; |
| 10072 |
switch (p->sig) { |
| 10073 |
case SIG_FEATD: |
| 10074 |
case SIG_SF_FEATD: |
| 10075 |
res = my_getsigstr(chan, dtmfbuf + 1, "*", 3000); |
| 10076 |
if (res > 0) |
| 10077 |
res = my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000); |
| 10078 |
if ((res < 1) && (p->dsp)) ast_dsp_digitreset(p->dsp); |
| 10079 |
break; |
| 10080 |
case SIG_FEATDMF_TA: |
| 10081 |
res = my_getsigstr(chan, dtmfbuf + 1, "#", 3000); |
| 10082 |
if ((res < 1) && (p->dsp)) ast_dsp_digitreset(p->dsp); |
| 10083 |
if (dahdi_wink(p, idx)) goto quit; |
| 10084 |
dtmfbuf[0] = 0; |
| 10085 |
|
| 10086 |
res = ast_waitfordigit(chan, 5000); |
| 10087 |
if (res <= 0) break; |
| 10088 |
dtmfbuf[0] = res; |
| 10089 |
|
| 10090 |
case SIG_FEATDMF: |
| 10091 |
case SIG_E911: |
| 10092 |
case SIG_FGC_CAMAMF: |
| 10093 |
case SIG_SF_FEATDMF: |
| 10094 |
res = my_getsigstr(chan, dtmfbuf + 1, "#", 3000); |
| 10095 |
|
| 10096 |
if ((p->sig == SIG_FEATDMF) && (dtmfbuf[1] != '0') && (strlen(dtmfbuf) != 14)) |
| 10097 |
{ |
| 10098 |
if (dahdi_wink(p, idx)) goto quit; |
| 10099 |
dtmfbuf[0] = 0; |
| 10100 |
|
| 10101 |
res = ast_waitfordigit(chan, 5000); |
| 10102 |
if (res <= 0) break; |
| 10103 |
dtmfbuf[0] = res; |
| 10104 |
res = my_getsigstr(chan, dtmfbuf + 1, "#", 3000); |
| 10105 |
} |
| 10106 |
if (res > 0) { |
| 10107 |
|
| 10108 |
if (p->sig == SIG_E911) |
| 10109 |
dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK); |
| 10110 |
res = my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "#", 3000); |
| 10111 |
} |
| 10112 |
if ((res < 1) && (p->dsp)) ast_dsp_digitreset(p->dsp); |
| 10113 |
break; |
| 10114 |
case SIG_FEATB: |
| 10115 |
case SIG_SF_FEATB: |
| 10116 |
res = my_getsigstr(chan, dtmfbuf + 1, "#", 3000); |
| 10117 |
if ((res < 1) && (p->dsp)) ast_dsp_digitreset(p->dsp); |
| 10118 |
break; |
| 10119 |
case SIG_EMWINK: |
| 10120 |
|
| 10121 |
|
| 10122 |
|
| 10123 |
|
| 10124 |
if (res == '*') { |
| 10125 |
res = my_getsigstr(chan, dtmfbuf + 1, "*", 3000); |
| 10126 |
if (res > 0) |
| 10127 |
res = my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000); |
| 10128 |
if ((res < 1) && (p->dsp)) ast_dsp_digitreset(p->dsp); |
| 10129 |
break; |
| 10130 |
} |
| 10131 |
default: |
| 10132 |
|
| 10133 |
len = 1; |
| 10134 |
dtmfbuf[len] = '\0'; |
| 10135 |
while ((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) { |
| 10136 |
if (ast_exists_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) { |
| 10137 |
timeout = p->matchdigit_timeout; |
| 10138 |
} else { |
| 10139 |
timeout = p->interdigit_timeout; |
| 10140 |
} |
| 10141 |
res = ast_waitfordigit(chan, timeout); |
| 10142 |
if (res < 0) { |
| 10143 |
ast_debug(1, "waitfordigit returned < 0...\n"); |
| 10144 |
ast_hangup(chan); |
| 10145 |
goto quit; |
| 10146 |
} else if (res) { |
| 10147 |
dtmfbuf[len++] = res; |
| 10148 |
dtmfbuf[len] = '\0'; |
| 10149 |
} else { |
| 10150 |
break; |
| 10151 |
} |
| 10152 |
} |
| 10153 |
break; |
| 10154 |
} |
| 10155 |
} |
| 10156 |
if (res == -1) { |
| 10157 |
ast_log(LOG_WARNING, "getdtmf on channel %d: %s\n", p->channel, strerror(errno)); |
| 10158 |
ast_hangup(chan); |
| 10159 |
goto quit; |
| 10160 |
} else if (res < 0) { |
| 10161 |
ast_debug(1, "Got hung up before digits finished\n"); |
| 10162 |
ast_hangup(chan); |
| 10163 |
goto quit; |
| 10164 |
} |
| 10165 |
|
| 10166 |
if (p->sig == SIG_FGC_CAMA) { |
| 10167 |
char anibuf[100]; |
| 10168 |
|
| 10169 |
if (ast_safe_sleep(chan,1000) == -1) { |
| 10170 |
ast_hangup(chan); |
| 10171 |
goto quit; |
| 10172 |
} |
| 10173 |
dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK); |
| 10174 |
ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MF | p->dtmfrelax); |
| 10175 |
res = my_getsigstr(chan, anibuf, "#", 10000); |
| 10176 |
if ((res > 0) && (strlen(anibuf) > 2)) { |
| 10177 |
if (anibuf[strlen(anibuf) - 1] == '#') |
| 10178 |
anibuf[strlen(anibuf) - 1] = 0; |
| 10179 |
ast_set_callerid(chan, anibuf + 2, NULL, anibuf + 2); |
| 10180 |
} |
| 10181 |
ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax); |
| 10182 |
} |
| 10183 |
|
| 10184 |
ast_copy_string(exten, dtmfbuf, sizeof(exten)); |
| 10185 |
if (ast_strlen_zero(exten)) |
| 10186 |
ast_copy_string(exten, "s", sizeof(exten)); |
| 10187 |
if (p->sig == SIG_FEATD || p->sig == SIG_EMWINK) { |
| 10188 |
|
| 10189 |
if (exten[0] == '*') { |
| 10190 |
char *stringp=NULL; |
| 10191 |
ast_copy_string(exten2, exten, sizeof(exten2)); |
| 10192 |
|
| 10193 |
stringp=exten2 +1; |
| 10194 |
s1 = strsep(&stringp, "*"); |
| 10195 |
s2 = strsep(&stringp, "*"); |
| 10196 |
if (s2) { |
| 10197 |
if (!ast_strlen_zero(p->cid_num)) |
| 10198 |
ast_set_callerid(chan, p->cid_num, NULL, p->cid_num); |
| 10199 |
else |
| 10200 |
ast_set_callerid(chan, s1, NULL, s1); |
| 10201 |
ast_copy_string(exten, s2, sizeof(exten)); |
| 10202 |
} else |
| 10203 |
ast_copy_string(exten, s1, sizeof(exten)); |
| 10204 |
} else if (p->sig == SIG_FEATD) |
| 10205 |
ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel); |
| 10206 |
} |
| 10207 |
if ((p->sig == SIG_FEATDMF) || (p->sig == SIG_FEATDMF_TA)) { |
| 10208 |
if (exten[0] == '*') { |
| 10209 |
char *stringp=NULL; |
| 10210 |
ast_copy_string(exten2, exten, sizeof(exten2)); |
| 10211 |
|
| 10212 |
stringp=exten2 +1; |
| 10213 |
s1 = strsep(&stringp, "#"); |
| 10214 |
s2 = strsep(&stringp, "#"); |
| 10215 |
if (s2) { |
| 10216 |
if (!ast_strlen_zero(p->cid_num)) |
| 10217 |
ast_set_callerid(chan, p->cid_num, NULL, p->cid_num); |
| 10218 |
else |
| 10219 |
if (*(s1 + 2)) |
| 10220 |
ast_set_callerid(chan, s1 + 2, NULL, s1 + 2); |
| 10221 |
ast_copy_string(exten, s2 + 1, sizeof(exten)); |
| 10222 |
} else |
| 10223 |
ast_copy_string(exten, s1 + 2, sizeof(exten)); |
| 10224 |
} else |
| 10225 |
ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel); |
| 10226 |
} |
| 10227 |
if ((p->sig == SIG_E911) || (p->sig == SIG_FGC_CAMAMF)) { |
| 10228 |
if (exten[0] == '*') { |
| 10229 |
char *stringp=NULL; |
| 10230 |
ast_copy_string(exten2, exten, sizeof(exten2)); |
| 10231 |
|
| 10232 |
stringp=exten2 +1; |
| 10233 |
s1 = strsep(&stringp, "#"); |
| 10234 |
s2 = strsep(&stringp, "#"); |
| 10235 |
if (s2 && (*(s2 + 1) == '0')) { |
| 10236 |
if (*(s2 + 2)) |
| 10237 |
ast_set_callerid(chan, s2 + 2, NULL, s2 + 2); |
| 10238 |
} |
| 10239 |
if (s1) ast_copy_string(exten, s1, sizeof(exten)); |
| 10240 |
else ast_copy_string(exten, "911", sizeof(exten)); |
| 10241 |
} else |
| 10242 |
ast_log(LOG_WARNING, "Got a non-E911/FGC CAMA input on channel %d. Assuming E&M Wink instead\n", p->channel); |
| 10243 |
} |
| 10244 |
if (p->sig == SIG_FEATB) { |
| 10245 |
if (exten[0] == '*') { |
| 10246 |
char *stringp=NULL; |
| 10247 |
ast_copy_string(exten2, exten, sizeof(exten2)); |
| 10248 |
|
| 10249 |
stringp=exten2 +1; |
| 10250 |
s1 = strsep(&stringp, "#"); |
| 10251 |
ast_copy_string(exten, exten2 + 1, sizeof(exten)); |
| 10252 |
} else |
| 10253 |
ast_log(LOG_WARNING, "Got a non-Feature Group B input on channel %d. Assuming E&M Wink instead\n", p->channel); |
| 10254 |
} |
| 10255 |
if ((p->sig == SIG_FEATDMF) || (p->sig == SIG_FEATDMF_TA)) { |
| 10256 |
dahdi_wink(p, idx); |
| 10257 |
|
| 10258 |
|
| 10259 |
|
| 10260 |
if (ast_safe_sleep(chan, 100)) { |
| 10261 |
ast_hangup(chan); |
| 10262 |
goto quit; |
| 10263 |
} |
| 10264 |
} |
| 10265 |
dahdi_ec_enable(p); |
| 10266 |
if (NEED_MFDETECT(p)) { |
| 10267 |
if (p->dsp) { |
| 10268 |
if (!p->hardwaredtmf) |
| 10269 |
ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax); |
| 10270 |
else { |
| 10271 |
ast_dsp_free(p->dsp); |
| 10272 |
p->dsp = NULL; |
| 10273 |
} |
| 10274 |
} |
| 10275 |
} |
| 10276 |
|
| 10277 |
if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1, |
| 10278 |
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) { |
| 10279 |
ast_channel_exten_set(chan, exten); |
| 10280 |
if (p->dsp) ast_dsp_digitreset(p->dsp); |
| 10281 |
res = ast_pbx_run(chan); |
| 10282 |
if (res) { |
| 10283 |
ast_log(LOG_WARNING, "PBX exited non-zero\n"); |
| 10284 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION); |
| 10285 |
} |
| 10286 |
goto quit; |
| 10287 |
} else { |
| 10288 |
ast_verb(2, "Unknown extension '%s' in context '%s' requested\n", exten, ast_channel_context(chan)); |
| 10289 |
sleep(2); |
| 10290 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_INFO); |
| 10291 |
if (res < 0) |
| 10292 |
ast_log(LOG_WARNING, "Unable to start special tone on %d\n", p->channel); |
| 10293 |
else |
| 10294 |
sleep(1); |
| 10295 |
res = ast_streamfile(chan, "ss-noservice", ast_channel_language(chan)); |
| 10296 |
if (res >= 0) |
| 10297 |
ast_waitstream(chan, ""); |
| 10298 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION); |
| 10299 |
ast_hangup(chan); |
| 10300 |
goto quit; |
| 10301 |
} |
| 10302 |
break; |
| 10303 |
case SIG_FXOLS: |
| 10304 |
case SIG_FXOGS: |
| 10305 |
case SIG_FXOKS: |
| 10306 |
|
| 10307 |
timeout = p->firstdigit_timeout; |
| 10308 |
|
| 10309 |
|
| 10310 |
if (p->subs[SUB_THREEWAY].owner) |
| 10311 |
timeout = INT_MAX; |
| 10312 |
while (len < AST_MAX_EXTENSION-1) { |
| 10313 |
int is_exten_parking = 0; |
| 10314 |
|
| 10315 |
|
| 10316 |
|
| 10317 |
if (p->immediate) |
| 10318 |
res = 's'; |
| 10319 |
else |
| 10320 |
res = ast_waitfordigit(chan, timeout); |
| 10321 |
timeout = 0; |
| 10322 |
if (res < 0) { |
| 10323 |
ast_debug(1, "waitfordigit returned < 0...\n"); |
| 10324 |
res = tone_zone_play_tone(p->subs[idx].dfd, -1); |
| 10325 |
ast_hangup(chan); |
| 10326 |
goto quit; |
| 10327 |
} else if (res) { |
| 10328 |
ast_debug(1,"waitfordigit returned '%c' (%d), timeout = %d\n", res, res, timeout); |
| 10329 |
exten[len++]=res; |
| 10330 |
exten[len] = '\0'; |
| 10331 |
} |
| 10332 |
if (!ast_ignore_pattern(ast_channel_context(chan), exten)) { |
| 10333 |
tone_zone_play_tone(p->subs[idx].dfd, -1); |
| 10334 |
} else { |
| 10335 |
tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALTONE); |
| 10336 |
} |
| 10337 |
if (ast_parking_provider_registered()) { |
| 10338 |
is_exten_parking = ast_parking_is_exten_park(ast_channel_context(chan), exten); |
| 10339 |
} |
| 10340 |
if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num) && !is_exten_parking) { |
| 10341 |
if (!res || !ast_matchmore_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num)) { |
| 10342 |
if (getforward) { |
| 10343 |
|
| 10344 |
ast_copy_string(p->call_forward, exten, sizeof(p->call_forward)); |
| 10345 |
ast_verb(3, "Setting call forward to '%s' on channel %d\n", p->call_forward, p->channel); |
| 10346 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL); |
| 10347 |
if (res) |
| 10348 |
break; |
| 10349 |
usleep(500000); |
| 10350 |
res = tone_zone_play_tone(p->subs[idx].dfd, -1); |
| 10351 |
sleep(1); |
| 10352 |
memset(exten, 0, sizeof(exten)); |
| 10353 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALTONE); |
| 10354 |
len = 0; |
| 10355 |
getforward = 0; |
| 10356 |
} else { |
| 10357 |
res = tone_zone_play_tone(p->subs[idx].dfd, -1); |
| 10358 |
ast_channel_lock(chan); |
| 10359 |
ast_channel_exten_set(chan, exten); |
| 10360 |
if (!ast_strlen_zero(p->cid_num)) { |
| 10361 |
if (!p->hidecallerid) |
| 10362 |
ast_set_callerid(chan, p->cid_num, NULL, p->cid_num); |
| 10363 |
else |
| 10364 |
ast_set_callerid(chan, NULL, NULL, p->cid_num); |
| 10365 |
} |
| 10366 |
if (!ast_strlen_zero(p->cid_name)) { |
| 10367 |
if (!p->hidecallerid) |
| 10368 |
ast_set_callerid(chan, NULL, p->cid_name, NULL); |
| 10369 |
} |
| 10370 |
ast_setstate(chan, AST_STATE_RING); |
| 10371 |
ast_channel_unlock(chan); |
| 10372 |
dahdi_ec_enable(p); |
| 10373 |
res = ast_pbx_run(chan); |
| 10374 |
if (res) { |
| 10375 |
ast_log(LOG_WARNING, "PBX exited non-zero\n"); |
| 10376 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION); |
| 10377 |
} |
| 10378 |
goto quit; |
| 10379 |
} |
| 10380 |
} else { |
| 10381 |
|
| 10382 |
|
| 10383 |
timeout = p->matchdigit_timeout; |
| 10384 |
} |
| 10385 |
} else if (res == 0) { |
| 10386 |
ast_debug(1, "not enough digits (and no ambiguous match)...\n"); |
| 10387 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION); |
| 10388 |
dahdi_wait_event(p->subs[idx].dfd); |
| 10389 |
ast_hangup(chan); |
| 10390 |
goto quit; |
| 10391 |
} else if (p->callwaiting && !strcmp(exten, "*70")) { |
| 10392 |
ast_verb(3, "Disabling call waiting on %s\n", ast_channel_name(chan)); |
| 10393 |
|
| 10394 |
p->callwaiting = 0; |
| 10395 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL); |
| 10396 |
if (res) { |
| 10397 |
ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n", |
| 10398 |
ast_channel_name(chan), strerror(errno)); |
| 10399 |
} |
| 10400 |
len = 0; |
| 10401 |
ioctl(p->subs[idx].dfd,DAHDI_CONFDIAG,&len); |
| 10402 |
memset(exten, 0, sizeof(exten)); |
| 10403 |
timeout = p->firstdigit_timeout; |
| 10404 |
|
| 10405 |
} else if (!strcmp(exten, pickupexten)) { |
| 10406 |
|
| 10407 |
|
| 10408 |
|
| 10409 |
|
| 10410 |
if (idx == SUB_REAL) { |
| 10411 |
|
| 10412 |
if (p->subs[SUB_THREEWAY].owner) { |
| 10413 |
|
| 10414 |
|
| 10415 |
alloc_sub(p, SUB_CALLWAIT); |
| 10416 |
swap_subs(p, SUB_CALLWAIT, SUB_THREEWAY); |
| 10417 |
unalloc_sub(p, SUB_THREEWAY); |
| 10418 |
} |
| 10419 |
dahdi_ec_enable(p); |
| 10420 |
if (ast_pickup_call(chan)) { |
| 10421 |
ast_debug(1, "No call pickup possible...\n"); |
| 10422 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION); |
| 10423 |
dahdi_wait_event(p->subs[idx].dfd); |
| 10424 |
} |
| 10425 |
ast_hangup(chan); |
| 10426 |
goto quit; |
| 10427 |
} else { |
| 10428 |
ast_log(LOG_WARNING, "Huh? Got *8# on call not on real\n"); |
| 10429 |
ast_hangup(chan); |
| 10430 |
goto quit; |
| 10431 |
} |
| 10432 |
|
| 10433 |
} else if (!p->hidecallerid && !strcmp(exten, "*67")) { |
| 10434 |
ast_verb(3, "Disabling Caller*ID on %s\n", ast_channel_name(chan)); |
| 10435 |
|
| 10436 |
p->hidecallerid = 1; |
| 10437 |
ast_party_number_free(&ast_channel_caller(chan)->id.number); |
| 10438 |
ast_party_number_init(&ast_channel_caller(chan)->id.number); |
| 10439 |
ast_party_name_free(&ast_channel_caller(chan)->id.name); |
| 10440 |
ast_party_name_init(&ast_channel_caller(chan)->id.name); |
| 10441 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL); |
| 10442 |
if (res) { |
| 10443 |
ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n", |
| 10444 |
ast_channel_name(chan), strerror(errno)); |
| 10445 |
} |
| 10446 |
len = 0; |
| 10447 |
memset(exten, 0, sizeof(exten)); |
| 10448 |
timeout = p->firstdigit_timeout; |
| 10449 |
} else if (p->callreturn && !strcmp(exten, "*69")) { |
| 10450 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL); |
| 10451 |
break; |
| 10452 |
} else if (!strcmp(exten, "*78")) { |
| 10453 |
dahdi_dnd(p, 1); |
| 10454 |
|
| 10455 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL); |
| 10456 |
getforward = 0; |
| 10457 |
memset(exten, 0, sizeof(exten)); |
| 10458 |
len = 0; |
| 10459 |
} else if (!strcmp(exten, "*79")) { |
| 10460 |
dahdi_dnd(p, 0); |
| 10461 |
|
| 10462 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL); |
| 10463 |
getforward = 0; |
| 10464 |
memset(exten, 0, sizeof(exten)); |
| 10465 |
len = 0; |
| 10466 |
} else if (p->cancallforward && !strcmp(exten, "*72")) { |
| 10467 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL); |
| 10468 |
getforward = 1; |
| 10469 |
memset(exten, 0, sizeof(exten)); |
| 10470 |
len = 0; |
| 10471 |
} else if (p->cancallforward && !strcmp(exten, "*73")) { |
| 10472 |
ast_verb(3, "Cancelling call forwarding on channel %d\n", p->channel); |
| 10473 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL); |
| 10474 |
memset(p->call_forward, 0, sizeof(p->call_forward)); |
| 10475 |
getforward = 0; |
| 10476 |
memset(exten, 0, sizeof(exten)); |
| 10477 |
len = 0; |
| 10478 |
} else if ((p->transfer || p->canpark) && is_exten_parking |
| 10479 |
&& p->subs[SUB_THREEWAY].owner) { |
| 10480 |
struct ast_bridge_channel *bridge_channel; |
| 10481 |
|
| 10482 |
|
| 10483 |
|
| 10484 |
|
| 10485 |
|
| 10486 |
ast_channel_lock(p->subs[SUB_THREEWAY].owner); |
| 10487 |
bridge_channel = ast_channel_get_bridge_channel(p->subs[SUB_THREEWAY].owner); |
| 10488 |
ast_channel_unlock(p->subs[SUB_THREEWAY].owner); |
| 10489 |
if (bridge_channel) { |
| 10490 |
if (!ast_parking_blind_transfer_park(bridge_channel, ast_channel_context(chan), exten, NULL, NULL)) { |
| 10491 |
|
| 10492 |
|
| 10493 |
|
| 10494 |
|
| 10495 |
ast_mutex_lock(&p->lock); |
| 10496 |
p->owner = p->subs[SUB_THREEWAY].owner; |
| 10497 |
swap_subs(p, SUB_THREEWAY, SUB_REAL); |
| 10498 |
ast_mutex_unlock(&p->lock); |
| 10499 |
|
| 10500 |
ast_verb(3, "%s: Parked call\n", ast_channel_name(chan)); |
| 10501 |
ast_hangup(chan); |
| 10502 |
ao2_ref(bridge_channel, -1); |
| 10503 |
goto quit; |
| 10504 |
} |
| 10505 |
ao2_ref(bridge_channel, -1); |
| 10506 |
} |
| 10507 |
break; |
| 10508 |
} else if (p->hidecallerid && !strcmp(exten, "*82")) { |
| 10509 |
ast_verb(3, "Enabling Caller*ID on %s\n", ast_channel_name(chan)); |
| 10510 |
|
| 10511 |
p->hidecallerid = 0; |
| 10512 |
ast_set_callerid(chan, p->cid_num, p->cid_name, NULL); |
| 10513 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL); |
| 10514 |
if (res) { |
| 10515 |
ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n", |
| 10516 |
ast_channel_name(chan), strerror(errno)); |
| 10517 |
} |
| 10518 |
len = 0; |
| 10519 |
memset(exten, 0, sizeof(exten)); |
| 10520 |
timeout = p->firstdigit_timeout; |
| 10521 |
} else if (!strcmp(exten, "*0")) { |
| 10522 |
struct ast_channel *nbridge = |
| 10523 |
p->subs[SUB_THREEWAY].owner; |
| 10524 |
struct dahdi_pvt *pbridge = NULL; |
| 10525 |
RAII_VAR(struct ast_channel *, bridged, nbridge ? ast_channel_bridge_peer(nbridge) : NULL, ast_channel_cleanup); |
| 10526 |
|
| 10527 |
|
| 10528 |
if (nbridge && bridged) { |
| 10529 |
pbridge = ast_channel_tech_pvt(bridged); |
| 10530 |
} |
| 10531 |
if (nbridge && pbridge && |
| 10532 |
(ast_channel_tech(nbridge) == &dahdi_tech) && |
| 10533 |
(ast_channel_tech(bridged) == &dahdi_tech) && |
| 10534 |
ISTRUNK(pbridge)) { |
| 10535 |
int func = DAHDI_FLASH; |
| 10536 |
|
| 10537 |
p->dop.dialstr[0] = '\0'; |
| 10538 |
|
| 10539 |
if ((ioctl(pbridge->subs[SUB_REAL].dfd,DAHDI_HOOK,&func) == -1) && (errno != EINPROGRESS)) { |
| 10540 |
ast_log(LOG_WARNING, "Unable to flash external trunk on channel %s: %s\n", |
| 10541 |
ast_channel_name(nbridge), strerror(errno)); |
| 10542 |
} |
| 10543 |
swap_subs(p, SUB_REAL, SUB_THREEWAY); |
| 10544 |
unalloc_sub(p, SUB_THREEWAY); |
| 10545 |
p->owner = p->subs[SUB_REAL].owner; |
| 10546 |
ast_queue_unhold(p->subs[SUB_REAL].owner); |
| 10547 |
ast_hangup(chan); |
| 10548 |
goto quit; |
| 10549 |
} else { |
| 10550 |
tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION); |
| 10551 |
dahdi_wait_event(p->subs[idx].dfd); |
| 10552 |
tone_zone_play_tone(p->subs[idx].dfd, -1); |
| 10553 |
swap_subs(p, SUB_REAL, SUB_THREEWAY); |
| 10554 |
unalloc_sub(p, SUB_THREEWAY); |
| 10555 |
p->owner = p->subs[SUB_REAL].owner; |
| 10556 |
ast_hangup(chan); |
| 10557 |
goto quit; |
| 10558 |
} |
| 10559 |
} else if (!ast_canmatch_extension(chan, ast_channel_context(chan), exten, 1, |
| 10560 |
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL)) |
| 10561 |
&& !canmatch_featurecode(pickupexten, exten)) { |
| 10562 |
ast_debug(1, "Can't match %s from '%s' in context %s\n", exten, |
| 10563 |
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, "<Unknown Caller>"), |
| 10564 |
ast_channel_context(chan)); |
| 10565 |
break; |
| 10566 |
} |
| 10567 |
if (!timeout) |
| 10568 |
timeout = p->interdigit_timeout; |
| 10569 |
if (len && !ast_ignore_pattern(ast_channel_context(chan), exten)) |
| 10570 |
tone_zone_play_tone(p->subs[idx].dfd, -1); |
| 10571 |
} |
| 10572 |
break; |
| 10573 |
case SIG_FXSLS: |
| 10574 |
case SIG_FXSGS: |
| 10575 |
case SIG_FXSKS: |
| 10576 |
|
| 10577 |
if (p->use_smdi && p->smdi_iface) { |
| 10578 |
smdi_msg = ast_smdi_md_message_wait(p->smdi_iface, SMDI_MD_WAIT_TIMEOUT); |
| 10579 |
|
| 10580 |
if (smdi_msg != NULL) { |
| 10581 |
ast_channel_exten_set(chan, smdi_msg->fwd_st); |
| 10582 |
|
| 10583 |
if (smdi_msg->type == 'B') |
| 10584 |
pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "b"); |
| 10585 |
else if (smdi_msg->type == 'N') |
| 10586 |
pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "u"); |
| 10587 |
|
| 10588 |
ast_debug(1, "Received SMDI message on %s\n", ast_channel_name(chan)); |
| 10589 |
} else { |
| 10590 |
ast_log(LOG_WARNING, "SMDI enabled but no SMDI message present\n"); |
| 10591 |
} |
| 10592 |
} |
| 10593 |
|
| 10594 |
if (p->use_callerid && (p->cid_signalling == CID_SIG_SMDI && smdi_msg)) { |
| 10595 |
number = smdi_msg->calling_st; |
| 10596 |
|
| 10597 |
|
| 10598 |
|
| 10599 |
|
| 10600 |
} else if (p->use_callerid && (ast_channel_state(chan) == AST_STATE_PRERING && |
| 10601 |
(p->cid_start == CID_START_POLARITY || p->cid_start == CID_START_POLARITY_IN || p->cid_start == CID_START_DTMF_NOALERT))) { |
| 10602 |
|
| 10603 |
if (p->cid_signalling == CID_SIG_DTMF) { |
| 10604 |
int k = 0; |
| 10605 |
int off_ms; |
| 10606 |
struct timeval start = ast_tvnow(); |
| 10607 |
int ms; |
| 10608 |
cs = NULL; |
| 10609 |
ast_debug(1, "Receiving DTMF cid on channel %s\n", ast_channel_name(chan)); |
| 10610 |
dahdi_setlinear(p->subs[idx].dfd, 0); |
| 10611 |
|
| 10612 |
|
| 10613 |
|
| 10614 |
|
| 10615 |
|
| 10616 |
|
| 10617 |
ast_channel_lock(chan); |
| 10618 |
ast_set_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY); |
| 10619 |
ast_channel_unlock(chan); |
| 10620 |
off_ms = 4000; |
| 10621 |
for (;;) { |
| 10622 |
struct ast_frame *f; |
| 10623 |
|
| 10624 |
ms = ast_remaining_ms(start, off_ms); |
| 10625 |
res = ast_waitfor(chan, ms); |
| 10626 |
if (res <= 0) { |
| 10627 |
|
| 10628 |
|
| 10629 |
|
| 10630 |
|
| 10631 |
|
| 10632 |
ast_log(LOG_WARNING, "DTMFCID timed out waiting for ring. " |
| 10633 |
"Exiting simple switch\n"); |
| 10634 |
ast_hangup(chan); |
| 10635 |
goto quit; |
| 10636 |
} |
| 10637 |
f = ast_read(chan); |
| 10638 |
if (!f) |
| 10639 |
break; |
| 10640 |
if (f->frametype == AST_FRAME_DTMF) { |
| 10641 |
if (k < ARRAY_LEN(dtmfbuf) - 1) { |
| 10642 |
dtmfbuf[k++] = f->subclass.integer; |
| 10643 |
} |
| 10644 |
ast_debug(1, "CID got digit '%c'\n", f->subclass.integer); |
| 10645 |
start = ast_tvnow(); |
| 10646 |
} |
| 10647 |
ast_frfree(f); |
| 10648 |
if (ast_channel_state(chan) == AST_STATE_RING || |
| 10649 |
ast_channel_state(chan) == AST_STATE_RINGING) |
| 10650 |
break; |
| 10651 |
} |
| 10652 |
ast_channel_lock(chan); |
| 10653 |
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY); |
| 10654 |
ast_channel_unlock(chan); |
| 10655 |
dtmfbuf[k] = '\0'; |
| 10656 |
dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear); |
| 10657 |
|
| 10658 |
ast_debug(1, "CID got string '%s'\n", dtmfbuf); |
| 10659 |
callerid_get_dtmf(dtmfbuf, dtmfcid, &flags); |
| 10660 |
ast_debug(1, "CID is '%s', flags %d\n", dtmfcid, flags); |
| 10661 |
|
| 10662 |
if (!ast_strlen_zero(dtmfcid)) |
| 10663 |
number = dtmfcid; |
| 10664 |
else |
| 10665 |
number = NULL; |
| 10666 |
|
| 10667 |
} else if ((p->cid_signalling == CID_SIG_V23) || (p->cid_signalling == CID_SIG_V23_JP)) { |
| 10668 |
cs = callerid_new(p->cid_signalling); |
| 10669 |
if (cs) { |
| 10670 |
int off_ms; |
| 10671 |
struct timeval start; |
| 10672 |
int ms; |
| 10673 |
samples = 0; |
| 10674 |
#if 1 |
| 10675 |
bump_gains(p); |
| 10676 |
#endif |
| 10677 |
|
| 10678 |
dahdi_setlinear(p->subs[idx].dfd, 0); |
| 10679 |
|
| 10680 |
|
| 10681 |
for (;;) { |
| 10682 |
i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT; |
| 10683 |
if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) { |
| 10684 |
ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno)); |
| 10685 |
callerid_free(cs); |
| 10686 |
ast_hangup(chan); |
| 10687 |
goto quit; |
| 10688 |
} |
| 10689 |
if (i & DAHDI_IOMUX_SIGEVENT) { |
| 10690 |
res = dahdi_get_event(p->subs[idx].dfd); |
| 10691 |
ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res)); |
| 10692 |
if (res == DAHDI_EVENT_NOALARM) { |
| 10693 |
p->inalarm = 0; |
| 10694 |
} |
| 10695 |
|
| 10696 |
if (p->cid_signalling == CID_SIG_V23_JP) { |
| 10697 |
if (res == DAHDI_EVENT_RINGBEGIN) { |
| 10698 |
res = dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK); |
| 10699 |
usleep(1); |
| 10700 |
} |
| 10701 |
} else { |
| 10702 |
res = 0; |
| 10703 |
break; |
| 10704 |
} |
| 10705 |
} else if (i & DAHDI_IOMUX_READ) { |
| 10706 |
res = read(p->subs[idx].dfd, buf, sizeof(buf)); |
| 10707 |
if (res < 0) { |
| 10708 |
if (errno != ELAST) { |
| 10709 |
ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno)); |
| 10710 |
callerid_free(cs); |
| 10711 |
ast_hangup(chan); |
| 10712 |
goto quit; |
| 10713 |
} |
| 10714 |
break; |
| 10715 |
} |
| 10716 |
samples += res; |
| 10717 |
|
| 10718 |
if (p->cid_signalling == CID_SIG_V23_JP) { |
| 10719 |
res = callerid_feed_jp(cs, buf, res, AST_LAW(p)); |
| 10720 |
} else { |
| 10721 |
res = callerid_feed(cs, buf, res, AST_LAW(p)); |
| 10722 |
} |
| 10723 |
if (res < 0) { |
| 10724 |
|
| 10725 |
|
| 10726 |
|
| 10727 |
|
| 10728 |
ast_log(LOG_WARNING, |
| 10729 |
"Failed to decode CallerID on channel '%s'\n", |
| 10730 |
ast_channel_name(chan)); |
| 10731 |
break; |
| 10732 |
} else if (res) |
| 10733 |
break; |
| 10734 |
else if (samples > (8000 * 10)) |
| 10735 |
break; |
| 10736 |
} |
| 10737 |
} |
| 10738 |
if (res == 1) { |
| 10739 |
callerid_get(cs, &name, &number, &flags); |
| 10740 |
ast_log(LOG_NOTICE, "CallerID number: %s, name: %s, flags=%d\n", number, name, flags); |
| 10741 |
} |
| 10742 |
|
| 10743 |
if (p->cid_signalling == CID_SIG_V23_JP) { |
| 10744 |
res = dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_ONHOOK); |
| 10745 |
usleep(1); |
| 10746 |
} |
| 10747 |
|
| 10748 |
|
| 10749 |
start = ast_tvnow(); |
| 10750 |
off_ms = 4000; |
| 10751 |
for (;;) { |
| 10752 |
struct ast_frame *f; |
| 10753 |
|
| 10754 |
ms = ast_remaining_ms(start, off_ms); |
| 10755 |
res = ast_waitfor(chan, ms); |
| 10756 |
if (res <= 0) { |
| 10757 |
ast_log(LOG_WARNING, "CID timed out waiting for ring. " |
| 10758 |
"Exiting simple switch\n"); |
| 10759 |
ast_hangup(chan); |
| 10760 |
goto quit; |
| 10761 |
} |
| 10762 |
if (!(f = ast_read(chan))) { |
| 10763 |
ast_log(LOG_WARNING, "Hangup received waiting for ring. Exiting simple switch\n"); |
| 10764 |
ast_hangup(chan); |
| 10765 |
goto quit; |
| 10766 |
} |
| 10767 |
ast_frfree(f); |
| 10768 |
if (ast_channel_state(chan) == AST_STATE_RING || |
| 10769 |
ast_channel_state(chan) == AST_STATE_RINGING) |
| 10770 |
break; |
| 10771 |
} |
| 10772 |
|
| 10773 |
|
| 10774 |
|
| 10775 |
if (p->usedistinctiveringdetection) { |
| 10776 |
len = 0; |
| 10777 |
distMatches = 0; |
| 10778 |
|
| 10779 |
for (receivedRingT = 0; receivedRingT < ARRAY_LEN(curRingData); receivedRingT++) |
| 10780 |
curRingData[receivedRingT] = 0; |
| 10781 |
receivedRingT = 0; |
| 10782 |
counter = 0; |
| 10783 |
counter1 = 0; |
| 10784 |
|
| 10785 |
if (strcmp(p->context,p->defcontext) != 0) { |
| 10786 |
ast_copy_string(p->context, p->defcontext, sizeof(p->context)); |
| 10787 |
ast_channel_context_set(chan, p->defcontext); |
| 10788 |
} |
| 10789 |
|
| 10790 |
for (;;) { |
| 10791 |
i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT; |
| 10792 |
if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) { |
| 10793 |
ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno)); |
| 10794 |
callerid_free(cs); |
| 10795 |
ast_hangup(chan); |
| 10796 |
goto quit; |
| 10797 |
} |
| 10798 |
if (i & DAHDI_IOMUX_SIGEVENT) { |
| 10799 |
res = dahdi_get_event(p->subs[idx].dfd); |
| 10800 |
ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res)); |
| 10801 |
if (res == DAHDI_EVENT_NOALARM) { |
| 10802 |
p->inalarm = 0; |
| 10803 |
} |
| 10804 |
res = 0; |
| 10805 |
|
| 10806 |
|
| 10807 |
curRingData[receivedRingT] = p->ringt; |
| 10808 |
|
| 10809 |
if (p->ringt < p->ringt_base/2) |
| 10810 |
break; |
| 10811 |
|
| 10812 |
|
| 10813 |
if (++receivedRingT == ARRAY_LEN(curRingData)) |
| 10814 |
break; |
| 10815 |
} else if (i & DAHDI_IOMUX_READ) { |
| 10816 |
res = read(p->subs[idx].dfd, buf, sizeof(buf)); |
| 10817 |
if (res < 0) { |
| 10818 |
if (errno != ELAST) { |
| 10819 |
ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno)); |
| 10820 |
callerid_free(cs); |
| 10821 |
ast_hangup(chan); |
| 10822 |
goto quit; |
| 10823 |
} |
| 10824 |
break; |
| 10825 |
} |
| 10826 |
if (p->ringt > 0) { |
| 10827 |
if (!(--p->ringt)) { |
| 10828 |
res = -1; |
| 10829 |
break; |
| 10830 |
} |
| 10831 |
} |
| 10832 |
} |
| 10833 |
} |
| 10834 |
|
| 10835 |
ast_verb(3, "Detected ring pattern: %d,%d,%d\n",curRingData[0],curRingData[1],curRingData[2]); |
| 10836 |
for (counter = 0; counter < 3; counter++) { |
| 10837 |
|
| 10838 |
|
| 10839 |
distMatches = 0; |
| 10840 |
for (counter1 = 0; counter1 < 3; counter1++) { |
| 10841 |
ast_verb(3, "Ring pattern check range: %d\n", p->drings.ringnum[counter].range); |
| 10842 |
if (p->drings.ringnum[counter].ring[counter1] == -1) { |
| 10843 |
ast_verb(3, "Pattern ignore (-1) detected, so matching pattern %d regardless.\n", |
| 10844 |
curRingData[counter1]); |
| 10845 |
distMatches++; |
| 10846 |
} else if (curRingData[counter1] <= (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range) && |
| 10847 |
curRingData[counter1] >= (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range)) { |
| 10848 |
ast_verb(3, "Ring pattern matched in range: %d to %d\n", |
| 10849 |
(p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range), |
| 10850 |
(p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range)); |
| 10851 |
distMatches++; |
| 10852 |
} |
| 10853 |
} |
| 10854 |
|
| 10855 |
if (distMatches == 3) { |
| 10856 |
|
| 10857 |
ast_copy_string(p->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(p->context)); |
| 10858 |
ast_channel_context_set(chan, S_OR(p->drings.ringContext[counter].contextData, p->defcontext)); |
| 10859 |
ast_verb(3, "Distinctive Ring matched context %s\n",p->context); |
| 10860 |
break; |
| 10861 |
} |
| 10862 |
} |
| 10863 |
} |
| 10864 |
|
| 10865 |
dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear); |
| 10866 |
#if 1 |
| 10867 |
restore_gains(p); |
| 10868 |
#endif |
| 10869 |
} else |
| 10870 |
ast_log(LOG_WARNING, "Unable to get caller ID space\n"); |
| 10871 |
} else { |
| 10872 |
ast_log(LOG_WARNING, "Channel %s in prering " |
| 10873 |
"state, but I have nothing to do. " |
| 10874 |
"Terminating simple switch, should be " |
| 10875 |
"restarted by the actual ring.\n", |
| 10876 |
ast_channel_name(chan)); |
| 10877 |
ast_hangup(chan); |
| 10878 |
goto quit; |
| 10879 |
} |
| 10880 |
} else if (p->use_callerid && p->cid_start == CID_START_RING) { |
| 10881 |
if (p->cid_signalling == CID_SIG_DTMF) { |
| 10882 |
int k = 0; |
| 10883 |
int off_ms; |
| 10884 |
struct timeval start; |
| 10885 |
int ms; |
| 10886 |
cs = NULL; |
| 10887 |
dahdi_setlinear(p->subs[idx].dfd, 0); |
| 10888 |
off_ms = 2000; |
| 10889 |
start = ast_tvnow(); |
| 10890 |
for (;;) { |
| 10891 |
struct ast_frame *f; |
| 10892 |
|
| 10893 |
ms = ast_remaining_ms(start, off_ms); |
| 10894 |
res = ast_waitfor(chan, ms); |
| 10895 |
if (res <= 0) { |
| 10896 |
ast_log(LOG_WARNING, "DTMFCID timed out waiting for ring. " |
| 10897 |
"Exiting simple switch\n"); |
| 10898 |
ast_hangup(chan); |
| 10899 |
goto quit; |
| 10900 |
} |
| 10901 |
f = ast_read(chan); |
| 10902 |
if (!f) { |
| 10903 |
|
| 10904 |
ast_hangup(chan); |
| 10905 |
goto quit; |
| 10906 |
} |
| 10907 |
if (f->frametype == AST_FRAME_DTMF) { |
| 10908 |
dtmfbuf[k++] = f->subclass.integer; |
| 10909 |
ast_debug(1, "CID got digit '%c'\n", f->subclass.integer); |
| 10910 |
start = ast_tvnow(); |
| 10911 |
} |
| 10912 |
ast_frfree(f); |
| 10913 |
|
| 10914 |
if (p->ringt_base == p->ringt) |
| 10915 |
break; |
| 10916 |
} |
| 10917 |
dtmfbuf[k] = '\0'; |
| 10918 |
dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear); |
| 10919 |
|
| 10920 |
callerid_get_dtmf(dtmfbuf, dtmfcid, &flags); |
| 10921 |
ast_debug(1, "CID is '%s', flags %d\n", |
| 10922 |
dtmfcid, flags); |
| 10923 |
|
| 10924 |
if (!ast_strlen_zero(dtmfcid)) |
| 10925 |
number = dtmfcid; |
| 10926 |
else |
| 10927 |
number = NULL; |
| 10928 |
|
| 10929 |
} else { |
| 10930 |
|
| 10931 |
cs = callerid_new(p->cid_signalling); |
| 10932 |
if (cs) { |
| 10933 |
#if 1 |
| 10934 |
bump_gains(p); |
| 10935 |
#endif |
| 10936 |
samples = 0; |
| 10937 |
len = 0; |
| 10938 |
distMatches = 0; |
| 10939 |
|
| 10940 |
for (receivedRingT = 0; receivedRingT < ARRAY_LEN(curRingData); receivedRingT++) |
| 10941 |
curRingData[receivedRingT] = 0; |
| 10942 |
receivedRingT = 0; |
| 10943 |
counter = 0; |
| 10944 |
counter1 = 0; |
| 10945 |
|
| 10946 |
if (strcmp(p->context,p->defcontext) != 0) { |
| 10947 |
ast_copy_string(p->context, p->defcontext, sizeof(p->context)); |
| 10948 |
ast_channel_context_set(chan, p->defcontext); |
| 10949 |
} |
| 10950 |
|
| 10951 |
|
| 10952 |
dahdi_setlinear(p->subs[idx].dfd, 0); |
| 10953 |
for (;;) { |
| 10954 |
i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT; |
| 10955 |
if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) { |
| 10956 |
ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno)); |
| 10957 |
callerid_free(cs); |
| 10958 |
ast_hangup(chan); |
| 10959 |
goto quit; |
| 10960 |
} |
| 10961 |
if (i & DAHDI_IOMUX_SIGEVENT) { |
| 10962 |
res = dahdi_get_event(p->subs[idx].dfd); |
| 10963 |
ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res)); |
| 10964 |
if (res == DAHDI_EVENT_NOALARM) { |
| 10965 |
p->inalarm = 0; |
| 10966 |
} |
| 10967 |
|
| 10968 |
if ( res == DAHDI_EVENT_POLARITY && p->hanguponpolarityswitch && p->polarity == POLARITY_REV) { |
| 10969 |
ast_debug(1, "Hanging up due to polarity reversal on channel %d while detecting callerid\n", p->channel); |
| 10970 |
p->polarity = POLARITY_IDLE; |
| 10971 |
callerid_free(cs); |
| 10972 |
ast_hangup(chan); |
| 10973 |
goto quit; |
| 10974 |
} |
| 10975 |
res = 0; |
| 10976 |
|
| 10977 |
|
| 10978 |
curRingData[receivedRingT] = p->ringt; |
| 10979 |
|
| 10980 |
if (p->ringt < p->ringt_base/2) |
| 10981 |
break; |
| 10982 |
|
| 10983 |
|
| 10984 |
if (++receivedRingT == ARRAY_LEN(curRingData)) |
| 10985 |
break; |
| 10986 |
} else if (i & DAHDI_IOMUX_READ) { |
| 10987 |
res = read(p->subs[idx].dfd, buf, sizeof(buf)); |
| 10988 |
if (res < 0) { |
| 10989 |
if (errno != ELAST) { |
| 10990 |
ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno)); |
| 10991 |
callerid_free(cs); |
| 10992 |
ast_hangup(chan); |
| 10993 |
goto quit; |
| 10994 |
} |
| 10995 |
break; |
| 10996 |
} |
| 10997 |
if (p->ringt > 0) { |
| 10998 |
if (!(--p->ringt)) { |
| 10999 |
res = -1; |
| 11000 |
break; |
| 11001 |
} |
| 11002 |
} |
| 11003 |
samples += res; |
| 11004 |
res = callerid_feed(cs, buf, res, AST_LAW(p)); |
| 11005 |
if (res < 0) { |
| 11006 |
|
| 11007 |
|
| 11008 |
|
| 11009 |
|
| 11010 |
ast_log(LOG_WARNING, |
| 11011 |
"Failed to decode CallerID on channel '%s'\n", |
| 11012 |
ast_channel_name(chan)); |
| 11013 |
break; |
| 11014 |
} else if (res) |
| 11015 |
break; |
| 11016 |
else if (samples > (8000 * 10)) |
| 11017 |
break; |
| 11018 |
} |
| 11019 |
} |
| 11020 |
if (res == 1) { |
| 11021 |
callerid_get(cs, &name, &number, &flags); |
| 11022 |
ast_debug(1, "CallerID number: %s, name: %s, flags=%d\n", number, name, flags); |
| 11023 |
} |
| 11024 |
if (distinctiveringaftercid == 1) { |
| 11025 |
|
| 11026 |
for (receivedRingT = 0; receivedRingT < 3; receivedRingT++) { |
| 11027 |
curRingData[receivedRingT] = 0; |
| 11028 |
} |
| 11029 |
receivedRingT = 0; |
| 11030 |
ast_verb(3, "Detecting post-CID distinctive ring\n"); |
| 11031 |
for (;;) { |
| 11032 |
i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT; |
| 11033 |
if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) { |
| 11034 |
ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno)); |
| 11035 |
callerid_free(cs); |
| 11036 |
ast_hangup(chan); |
| 11037 |
goto quit; |
| 11038 |
} |
| 11039 |
if (i & DAHDI_IOMUX_SIGEVENT) { |
| 11040 |
res = dahdi_get_event(p->subs[idx].dfd); |
| 11041 |
ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res)); |
| 11042 |
if (res == DAHDI_EVENT_NOALARM) { |
| 11043 |
p->inalarm = 0; |
| 11044 |
} |
| 11045 |
res = 0; |
| 11046 |
|
| 11047 |
|
| 11048 |
curRingData[receivedRingT] = p->ringt; |
| 11049 |
|
| 11050 |
if (p->ringt < p->ringt_base/2) |
| 11051 |
break; |
| 11052 |
|
| 11053 |
|
| 11054 |
if (++receivedRingT == ARRAY_LEN(curRingData)) |
| 11055 |
break; |
| 11056 |
} else if (i & DAHDI_IOMUX_READ) { |
| 11057 |
res = read(p->subs[idx].dfd, buf, sizeof(buf)); |
| 11058 |
if (res < 0) { |
| 11059 |
if (errno != ELAST) { |
| 11060 |
ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno)); |
| 11061 |
callerid_free(cs); |
| 11062 |
ast_hangup(chan); |
| 11063 |
goto quit; |
| 11064 |
} |
| 11065 |
break; |
| 11066 |
} |
| 11067 |
if (p->ringt > 0) { |
| 11068 |
if (!(--p->ringt)) { |
| 11069 |
res = -1; |
| 11070 |
break; |
| 11071 |
} |
| 11072 |
} |
| 11073 |
} |
| 11074 |
} |
| 11075 |
} |
| 11076 |
if (p->usedistinctiveringdetection) { |
| 11077 |
|
| 11078 |
ast_verb(3, "Detected ring pattern: %d,%d,%d\n",curRingData[0],curRingData[1],curRingData[2]); |
| 11079 |
|
| 11080 |
for (counter = 0; counter < 3; counter++) { |
| 11081 |
|
| 11082 |
|
| 11083 |
|
| 11084 |
ast_verb(3, "Checking %d,%d,%d\n", |
| 11085 |
p->drings.ringnum[counter].ring[0], |
| 11086 |
p->drings.ringnum[counter].ring[1], |
| 11087 |
p->drings.ringnum[counter].ring[2]); |
| 11088 |
distMatches = 0; |
| 11089 |
for (counter1 = 0; counter1 < 3; counter1++) { |
| 11090 |
ast_verb(3, "Ring pattern check range: %d\n", p->drings.ringnum[counter].range); |
| 11091 |
if (p->drings.ringnum[counter].ring[counter1] == -1) { |
| 11092 |
ast_verb(3, "Pattern ignore (-1) detected, so matching pattern %d regardless.\n", |
| 11093 |
curRingData[counter1]); |
| 11094 |
distMatches++; |
| 11095 |
} |
| 11096 |
else if (curRingData[counter1] <= (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range) && |
| 11097 |
curRingData[counter1] >= (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range)) { |
| 11098 |
ast_verb(3, "Ring pattern matched in range: %d to %d\n", |
| 11099 |
(p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range), |
| 11100 |
(p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range)); |
| 11101 |
distMatches++; |
| 11102 |
} |
| 11103 |
} |
| 11104 |
if (distMatches == 3) { |
| 11105 |
|
| 11106 |
ast_copy_string(p->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(p->context)); |
| 11107 |
ast_channel_context_set(chan, S_OR(p->drings.ringContext[counter].contextData, p->defcontext)); |
| 11108 |
ast_verb(3, "Distinctive Ring matched context %s\n",p->context); |
| 11109 |
break; |
| 11110 |
} |
| 11111 |
} |
| 11112 |
} |
| 11113 |
|
| 11114 |
dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear); |
| 11115 |
#if 1 |
| 11116 |
restore_gains(p); |
| 11117 |
#endif |
| 11118 |
if (res < 0) { |
| 11119 |
ast_log(LOG_WARNING, "CallerID returned with error on channel '%s'\n", ast_channel_name(chan)); |
| 11120 |
} |
| 11121 |
} else |
| 11122 |
ast_log(LOG_WARNING, "Unable to get caller ID space\n"); |
| 11123 |
} |
| 11124 |
} else |
| 11125 |
cs = NULL; |
| 11126 |
|
| 11127 |
if (number) |
| 11128 |
ast_shrink_phone_number(number); |
| 11129 |
ast_set_callerid(chan, number, name, number); |
| 11130 |
|
| 11131 |
ao2_cleanup(smdi_msg); |
| 11132 |
|
| 11133 |
if (cs) |
| 11134 |
callerid_free(cs); |
| 11135 |
|
| 11136 |
my_handle_notify_message(chan, p, flags, -1); |
| 11137 |
|
| 11138 |
ast_channel_lock(chan); |
| 11139 |
ast_setstate(chan, AST_STATE_RING); |
| 11140 |
ast_channel_rings_set(chan, 1); |
| 11141 |
ast_channel_unlock(chan); |
| 11142 |
p->ringt = p->ringt_base; |
| 11143 |
res = ast_pbx_run(chan); |
| 11144 |
if (res) { |
| 11145 |
ast_hangup(chan); |
| 11146 |
ast_log(LOG_WARNING, "PBX exited non-zero\n"); |
| 11147 |
} |
| 11148 |
goto quit; |
| 11149 |
default: |
| 11150 |
ast_log(LOG_WARNING, "Don't know how to handle simple switch with signalling %s on channel %d\n", sig2str(p->sig), p->channel); |
| 11151 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION); |
| 11152 |
if (res < 0) |
| 11153 |
ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel); |
| 11154 |
} |
| 11155 |
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION); |
| 11156 |
if (res < 0) |
| 11157 |
ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel); |
| 11158 |
ast_hangup(chan); |
| 11159 |
quit: |
| 11160 |
ast_mutex_lock(&ss_thread_lock); |
| 11161 |
ss_thread_count--; |
| 11162 |
ast_cond_signal(&ss_thread_complete); |
| 11163 |
ast_mutex_unlock(&ss_thread_lock); |
| 11164 |
return NULL; |
| 11165 |
} |
| 11166 |
|
| 11167 |
struct mwi_thread_data { |
| 11168 |
struct dahdi_pvt *pvt; |
| 11169 |
unsigned char buf[READ_SIZE]; |
| 11170 |
size_t len; |
| 11171 |
}; |
| 11172 |
|
| 11173 |
static int calc_energy(const unsigned char *buf, int len, struct ast_format *law) |
| 11174 |
{ |
| 11175 |
int x; |
| 11176 |
int sum = 0; |
| 11177 |
|
| 11178 |
if (!len) |
| 11179 |
return 0; |
| 11180 |
|
| 11181 |
for (x = 0; x < len; x++) |
| 11182 |
sum += abs(law == ast_format_ulaw ? AST_MULAW(buf[x]) : AST_ALAW(buf[x])); |
| 11183 |
|
| 11184 |
return sum / len; |
| 11185 |
} |
| 11186 |
|
| 11187 |
static void *mwi_thread(void *data) |
| 11188 |
{ |
| 11189 |
struct mwi_thread_data *mtd = data; |
| 11190 |
struct callerid_state *cs; |
| 11191 |
pthread_t threadid; |
| 11192 |
int samples = 0; |
| 11193 |
char *name, *number; |
| 11194 |
int flags; |
| 11195 |
int i, res; |
| 11196 |
unsigned int spill_done = 0; |
| 11197 |
int spill_result = -1; |
| 11198 |
|
| 11199 |
if (!(cs = callerid_new(mtd->pvt->cid_signalling))) { |
| 11200 |
goto quit_no_clean; |
| 11201 |
} |
| 11202 |
|
| 11203 |
callerid_feed(cs, mtd->buf, mtd->len, AST_LAW(mtd->pvt)); |
| 11204 |
|
| 11205 |
bump_gains(mtd->pvt); |
| 11206 |
|
| 11207 |
for (;;) { |
| 11208 |
i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT; |
| 11209 |
if ((res = ioctl(mtd->pvt->subs[SUB_REAL].dfd, DAHDI_IOMUX, &i))) { |
| 11210 |
ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno)); |
| 11211 |
goto quit; |
| 11212 |
} |
| 11213 |
|
| 11214 |
if (i & DAHDI_IOMUX_SIGEVENT) { |
| 11215 |
struct ast_channel *chan; |
| 11216 |
ast_callid callid = 0; |
| 11217 |
int callid_created; |
| 11218 |
|
| 11219 |
|
| 11220 |
|
| 11221 |
|
| 11222 |
res = dahdi_get_event(mtd->pvt->subs[SUB_REAL].dfd); |
| 11223 |
|
| 11224 |
switch (res) { |
| 11225 |
case DAHDI_EVENT_NEONMWI_ACTIVE: |
| 11226 |
case DAHDI_EVENT_NEONMWI_INACTIVE: |
| 11227 |
case DAHDI_EVENT_NONE: |
| 11228 |
case DAHDI_EVENT_BITSCHANGED: |
| 11229 |
break; |
| 11230 |
case DAHDI_EVENT_NOALARM: |
| 11231 |
if (dahdi_analog_lib_handles(mtd->pvt->sig, mtd->pvt->radio, mtd->pvt->oprmode)) { |
| 11232 |
struct analog_pvt *analog_p = mtd->pvt->sig_pvt; |
| 11233 |
|
| 11234 |
analog_p->inalarm = 0; |
| 11235 |
} |
| 11236 |
mtd->pvt->inalarm = 0; |
| 11237 |
handle_clear_alarms(mtd->pvt); |
| 11238 |
break; |
| 11239 |
case DAHDI_EVENT_ALARM: |
| 11240 |
if (dahdi_analog_lib_handles(mtd->pvt->sig, mtd->pvt->radio, mtd->pvt->oprmode)) { |
| 11241 |
struct analog_pvt *analog_p = mtd->pvt->sig_pvt; |
| 11242 |
|
| 11243 |
analog_p->inalarm = 1; |
| 11244 |
} |
| 11245 |
mtd->pvt->inalarm = 1; |
| 11246 |
res = get_alarms(mtd->pvt); |
| 11247 |
handle_alarms(mtd->pvt, res); |
| 11248 |
break; |
| 11249 |
default: |
| 11250 |
callid_created = ast_callid_threadstorage_auto(&callid); |
| 11251 |
ast_log(LOG_NOTICE, "Got event %d (%s)... Passing along to analog_ss_thread\n", res, event2str(res)); |
| 11252 |
callerid_free(cs); |
| 11253 |
|
| 11254 |
restore_gains(mtd->pvt); |
| 11255 |
mtd->pvt->ringt = mtd->pvt->ringt_base; |
| 11256 |
|
| 11257 |
if ((chan = dahdi_new(mtd->pvt, AST_STATE_RING, 0, SUB_REAL, 0, NULL, NULL, callid))) { |
| 11258 |
int result; |
| 11259 |
|
| 11260 |
if (dahdi_analog_lib_handles(mtd->pvt->sig, mtd->pvt->radio, mtd->pvt->oprmode)) { |
| 11261 |
result = analog_ss_thread_start(mtd->pvt->sig_pvt, chan); |
| 11262 |
} else { |
| 11263 |
result = ast_pthread_create_detached(&threadid, NULL, analog_ss_thread, chan); |
| 11264 |
} |
| 11265 |
if (result) { |
| 11266 |
ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", mtd->pvt->channel); |
| 11267 |
res = tone_zone_play_tone(mtd->pvt->subs[SUB_REAL].dfd, DAHDI_TONE_CONGESTION); |
| 11268 |
if (res < 0) |
| 11269 |
ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", mtd->pvt->channel); |
| 11270 |
ast_hangup(chan); |
| 11271 |
} |
| 11272 |
} else { |
| 11273 |
ast_log(LOG_WARNING, "Could not create channel to handle call\n"); |
| 11274 |
} |
| 11275 |
|
| 11276 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 11277 |
goto quit_no_clean; |
| 11278 |
} |
| 11279 |
} else if (i & DAHDI_IOMUX_READ) { |
| 11280 |
if ((res = read(mtd->pvt->subs[SUB_REAL].dfd, mtd->buf, sizeof(mtd->buf))) < 0) { |
| 11281 |
if (errno != ELAST) { |
| 11282 |
ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno)); |
| 11283 |
goto quit; |
| 11284 |
} |
| 11285 |
break; |
| 11286 |
} |
| 11287 |
samples += res; |
| 11288 |
if (!spill_done) { |
| 11289 |
if ((spill_result = callerid_feed(cs, mtd->buf, res, AST_LAW(mtd->pvt))) < 0) { |
| 11290 |
|
| 11291 |
|
| 11292 |
|
| 11293 |
|
| 11294 |
ast_log(LOG_WARNING, "Failed to decode CallerID\n"); |
| 11295 |
break; |
| 11296 |
} else if (spill_result) { |
| 11297 |
spill_done = 1; |
| 11298 |
} |
| 11299 |
} else { |
| 11300 |
|
| 11301 |
|
| 11302 |
|
| 11303 |
if (calc_energy(mtd->buf, res, AST_LAW(mtd->pvt)) <= mwilevel) |
| 11304 |
break; |
| 11305 |
} |
| 11306 |
if (samples > (8000 * 4)) |
| 11307 |
break; |
| 11308 |
} |
| 11309 |
} |
| 11310 |
|
| 11311 |
if (spill_result == 1) { |
| 11312 |
callerid_get(cs, &name, &number, &flags); |
| 11313 |
if (flags & CID_MSGWAITING) { |
| 11314 |
ast_log(LOG_NOTICE, "mwi: Have Messages on channel %d\n", mtd->pvt->channel); |
| 11315 |
notify_message(mtd->pvt->mailbox, 1); |
| 11316 |
} else if (flags & CID_NOMSGWAITING) { |
| 11317 |
ast_log(LOG_NOTICE, "mwi: No Messages on channel %d\n", mtd->pvt->channel); |
| 11318 |
notify_message(mtd->pvt->mailbox, 0); |
| 11319 |
} else { |
| 11320 |
ast_log(LOG_NOTICE, "mwi: Status unknown on channel %d\n", mtd->pvt->channel); |
| 11321 |
} |
| 11322 |
} |
| 11323 |
|
| 11324 |
|
| 11325 |
quit: |
| 11326 |
callerid_free(cs); |
| 11327 |
|
| 11328 |
restore_gains(mtd->pvt); |
| 11329 |
|
| 11330 |
quit_no_clean: |
| 11331 |
mtd->pvt->mwimonitoractive = 0; |
| 11332 |
ast_free(mtd); |
| 11333 |
|
| 11334 |
return NULL; |
| 11335 |
} |
| 11336 |
|
| 11337 |
|
| 11338 |
|
| 11339 |
|
| 11340 |
|
| 11341 |
|
| 11342 |
|
| 11343 |
|
| 11344 |
static int mwi_send_init(struct dahdi_pvt * pvt) |
| 11345 |
{ |
| 11346 |
int x; |
| 11347 |
|
| 11348 |
#ifdef HAVE_DAHDI_LINEREVERSE_VMWI |
| 11349 |
|
| 11350 |
if (pvt->mwisend_rpas) { |
| 11351 |
pvt->mwisend_data.mwisend_current = MWI_SEND_SA; |
| 11352 |
pvt->mwisendactive = 1; |
| 11353 |
} else if (pvt->mwisend_fsk) { |
| 11354 |
pvt->mwisend_data.mwisend_current = MWI_SEND_SPILL; |
| 11355 |
pvt->mwisendactive = 1; |
| 11356 |
} else { |
| 11357 |
pvt->mwisendactive = 0; |
| 11358 |
return 0; |
| 11359 |
} |
| 11360 |
#else |
| 11361 |
if (mwisend_rpas) { |
| 11362 |
pvt->mwisend_data.mwisend_current = MWI_SEND_SA; |
| 11363 |
} else { |
| 11364 |
pvt->mwisend_data.mwisend_current = MWI_SEND_SPILL; |
| 11365 |
} |
| 11366 |
pvt->mwisendactive = 1; |
| 11367 |
#endif |
| 11368 |
|
| 11369 |
if (pvt->cidspill) { |
| 11370 |
ast_log(LOG_WARNING, "cidspill already exists when trying to send FSK MWI\n"); |
| 11371 |
ast_free(pvt->cidspill); |
| 11372 |
pvt->cidspill = NULL; |
| 11373 |
pvt->cidpos = 0; |
| 11374 |
pvt->cidlen = 0; |
| 11375 |
} |
| 11376 |
pvt->cidspill = ast_calloc(1, MAX_CALLERID_SIZE); |
| 11377 |
if (!pvt->cidspill) { |
| 11378 |
pvt->mwisendactive = 0; |
| 11379 |
return -1; |
| 11380 |
} |
| 11381 |
x = DAHDI_FLUSH_BOTH; |
| 11382 |
ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_FLUSH, &x); |
| 11383 |
x = 3000; |
| 11384 |
ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_ONHOOKTRANSFER, &x); |
| 11385 |
#ifdef HAVE_DAHDI_LINEREVERSE_VMWI |
| 11386 |
if (pvt->mwisend_fsk) { |
| 11387 |
#endif |
| 11388 |
pvt->cidlen = ast_callerid_vmwi_generate(pvt->cidspill, has_voicemail(pvt), |
| 11389 |
CID_MWI_TYPE_MDMF_FULL, AST_LAW(pvt), pvt->cid_name, pvt->cid_num, 0); |
| 11390 |
pvt->cidpos = 0; |
| 11391 |
#ifdef HAVE_DAHDI_LINEREVERSE_VMWI |
| 11392 |
} |
| 11393 |
#endif |
| 11394 |
return 0; |
| 11395 |
} |
| 11396 |
|
| 11397 |
static int mwi_send_process_buffer(struct dahdi_pvt * pvt, int num_read) |
| 11398 |
{ |
| 11399 |
struct timeval now; |
| 11400 |
int res; |
| 11401 |
|
| 11402 |
|
| 11403 |
|
| 11404 |
|
| 11405 |
if (MWI_SEND_DONE != pvt->mwisend_data.mwisend_current && !pvt->cidspill) { |
| 11406 |
pvt->mwisend_data.mwisend_current = MWI_SEND_DONE; |
| 11407 |
} else if (MWI_SEND_DONE != pvt->mwisend_data.mwisend_current) { |
| 11408 |
|
| 11409 |
switch ( pvt->mwisend_data.mwisend_current) { |
| 11410 |
case MWI_SEND_SA: |
| 11411 |
|
| 11412 |
res = ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &AS_RP_cadence); |
| 11413 |
if (res) { |
| 11414 |
ast_log(LOG_WARNING, "Unable to set RP-AS ring cadence: %s\n", strerror(errno)); |
| 11415 |
goto quit; |
| 11416 |
} |
| 11417 |
res = dahdi_set_hook(pvt->subs[SUB_REAL].dfd, DAHDI_RING); |
| 11418 |
pvt->mwisend_data.mwisend_current = MWI_SEND_SA_WAIT; |
| 11419 |
break; |
| 11420 |
case MWI_SEND_SA_WAIT: |
| 11421 |
break; |
| 11422 |
case MWI_SEND_PAUSE: |
| 11423 |
#ifdef HAVE_DAHDI_LINEREVERSE_VMWI |
| 11424 |
if (pvt->mwisend_fsk) { |
| 11425 |
#endif |
| 11426 |
gettimeofday(&now, NULL); |
| 11427 |
if ((int)(now.tv_sec - pvt->mwisend_data.pause.tv_sec) * 1000000 + (int)now.tv_usec - (int)pvt->mwisend_data.pause.tv_usec > 500000) { |
| 11428 |
pvt->mwisend_data.mwisend_current = MWI_SEND_SPILL; |
| 11429 |
} |
| 11430 |
#ifdef HAVE_DAHDI_LINEREVERSE_VMWI |
| 11431 |
} else { |
| 11432 |
pvt->mwisend_data.mwisend_current = MWI_SEND_CLEANUP; |
| 11433 |
} |
| 11434 |
#endif |
| 11435 |
break; |
| 11436 |
case MWI_SEND_SPILL: |
| 11437 |
|
| 11438 |
if (0 < num_read) { |
| 11439 |
if (num_read > pvt->cidlen - pvt->cidpos) { |
| 11440 |
num_read = pvt->cidlen - pvt->cidpos; |
| 11441 |
} |
| 11442 |
res = write(pvt->subs[SUB_REAL].dfd, pvt->cidspill + pvt->cidpos, num_read); |
| 11443 |
if (res > 0) { |
| 11444 |
pvt->cidpos += res; |
| 11445 |
if (pvt->cidpos >= pvt->cidlen) { |
| 11446 |
pvt->mwisend_data.mwisend_current = MWI_SEND_CLEANUP; |
| 11447 |
} |
| 11448 |
} else { |
| 11449 |
ast_log(LOG_WARNING, "MWI FSK Send Write failed: %s\n", strerror(errno)); |
| 11450 |
goto quit; |
| 11451 |
} |
| 11452 |
} |
| 11453 |
break; |
| 11454 |
case MWI_SEND_CLEANUP: |
| 11455 |
|
| 11456 |
pvt->mwisend_data.mwisend_current = MWI_SEND_DONE; |
| 11457 |
break; |
| 11458 |
default: |
| 11459 |
|
| 11460 |
goto quit; |
| 11461 |
} |
| 11462 |
} |
| 11463 |
|
| 11464 |
if (MWI_SEND_DONE == pvt->mwisend_data.mwisend_current) { |
| 11465 |
if (pvt->cidspill) { |
| 11466 |
ast_free(pvt->cidspill); |
| 11467 |
pvt->cidspill = NULL; |
| 11468 |
pvt->cidpos = 0; |
| 11469 |
pvt->cidlen = 0; |
| 11470 |
} |
| 11471 |
pvt->mwisendactive = 0; |
| 11472 |
} |
| 11473 |
return 0; |
| 11474 |
quit: |
| 11475 |
if (pvt->cidspill) { |
| 11476 |
ast_free(pvt->cidspill); |
| 11477 |
pvt->cidspill = NULL; |
| 11478 |
pvt->cidpos = 0; |
| 11479 |
pvt->cidlen = 0; |
| 11480 |
} |
| 11481 |
pvt->mwisendactive = 0; |
| 11482 |
return -1; |
| 11483 |
} |
| 11484 |
|
| 11485 |
static int mwi_send_process_event(struct dahdi_pvt * pvt, int event) |
| 11486 |
{ |
| 11487 |
int handled = 0; |
| 11488 |
|
| 11489 |
if (MWI_SEND_DONE != pvt->mwisend_data.mwisend_current) { |
| 11490 |
switch (event) { |
| 11491 |
case DAHDI_EVENT_RINGEROFF: |
| 11492 |
if (pvt->mwisend_data.mwisend_current == MWI_SEND_SA_WAIT) { |
| 11493 |
handled = 1; |
| 11494 |
|
| 11495 |
if (dahdi_set_hook(pvt->subs[SUB_REAL].dfd, DAHDI_RINGOFF) ) { |
| 11496 |
ast_log(LOG_WARNING, "Unable to finish RP-AS: %s mwi send aborted\n", strerror(errno)); |
| 11497 |
ast_free(pvt->cidspill); |
| 11498 |
pvt->cidspill = NULL; |
| 11499 |
pvt->mwisend_data.mwisend_current = MWI_SEND_DONE; |
| 11500 |
pvt->mwisendactive = 0; |
| 11501 |
} else { |
| 11502 |
pvt->mwisend_data.mwisend_current = MWI_SEND_PAUSE; |
| 11503 |
gettimeofday(&pvt->mwisend_data.pause, NULL); |
| 11504 |
} |
| 11505 |
} |
| 11506 |
break; |
| 11507 |
|
| 11508 |
case DAHDI_EVENT_RINGOFFHOOK: |
| 11509 |
if (pvt->cidspill) { |
| 11510 |
ast_free(pvt->cidspill); |
| 11511 |
pvt->cidspill = NULL; |
| 11512 |
pvt->cidpos = 0; |
| 11513 |
pvt->cidlen = 0; |
| 11514 |
} |
| 11515 |
pvt->mwisend_data.mwisend_current = MWI_SEND_DONE; |
| 11516 |
pvt->mwisendactive = 0; |
| 11517 |
break; |
| 11518 |
case DAHDI_EVENT_RINGERON: |
| 11519 |
case DAHDI_EVENT_HOOKCOMPLETE: |
| 11520 |
break; |
| 11521 |
default: |
| 11522 |
break; |
| 11523 |
} |
| 11524 |
} |
| 11525 |
return handled; |
| 11526 |
} |
| 11527 |
|
| 11528 |
|
| 11529 |
static void dahdi_destroy_channel_range(int start, int end) |
| 11530 |
{ |
| 11531 |
struct dahdi_pvt *cur; |
| 11532 |
struct dahdi_pvt *next; |
| 11533 |
int destroyed_first = 0; |
| 11534 |
int destroyed_last = 0; |
| 11535 |
|
| 11536 |
ast_mutex_lock(&iflock); |
| 11537 |
ast_debug(1, "range: %d-%d\n", start, end); |
| 11538 |
for (cur = iflist; cur; cur = next) { |
| 11539 |
next = cur->next; |
| 11540 |
if (cur->channel >= start && cur->channel <= end) { |
| 11541 |
int x = DAHDI_FLASH; |
| 11542 |
|
| 11543 |
if (cur->channel > destroyed_last) { |
| 11544 |
destroyed_last = cur->channel; |
| 11545 |
} |
| 11546 |
if (destroyed_first < 1 || cur->channel < destroyed_first) { |
| 11547 |
destroyed_first = cur->channel; |
| 11548 |
} |
| 11549 |
ast_debug(3, "Destroying %d\n", cur->channel); |
| 11550 |
|
| 11551 |
ioctl(cur->subs[SUB_REAL].dfd, DAHDI_HOOK, &x); |
| 11552 |
|
| 11553 |
destroy_channel(cur, 1); |
| 11554 |
ast_module_unref(ast_module_info->self); |
| 11555 |
} |
| 11556 |
} |
| 11557 |
ast_mutex_unlock(&iflock); |
| 11558 |
if (destroyed_first > start || destroyed_last < end) { |
| 11559 |
ast_debug(1, "Asked to destroy %d-%d, destroyed %d-%d,\n", |
| 11560 |
start, end, destroyed_first, destroyed_last); |
| 11561 |
} |
| 11562 |
} |
| 11563 |
|
| 11564 |
#ifdef HAVE_OPENR2 |
| 11565 |
static void dahdi_r2_destroy_nodev(void) |
| 11566 |
{ |
| 11567 |
struct r2link_entry *cur; |
| 11568 |
AST_LIST_LOCK(&nodev_r2links); |
| 11569 |
AST_LIST_TRAVERSE_SAFE_BEGIN(&nodev_r2links, cur, list) { |
| 11570 |
int i; |
| 11571 |
struct dahdi_mfcr2 *r2 = &cur->mfcr2; |
| 11572 |
ast_debug(3, "About to destroy %d DAHDI channels of MFC/R2 link.\n", r2->numchans); |
| 11573 |
for (i = 0; i < r2->numchans; i++) { |
| 11574 |
int channel; |
| 11575 |
struct dahdi_pvt *pvt = r2->pvts[i]; |
| 11576 |
if (!pvt) { |
| 11577 |
continue; |
| 11578 |
} |
| 11579 |
channel = pvt->channel; |
| 11580 |
ast_debug(3, "About to destroy B-channel %d.\n", channel); |
| 11581 |
dahdi_destroy_channel_range(channel, channel); |
| 11582 |
} |
| 11583 |
ast_debug(3, "Destroying R2 link\n"); |
| 11584 |
AST_LIST_REMOVE(&nodev_r2links, cur, list); |
| 11585 |
if (r2->r2master != AST_PTHREADT_NULL) { |
| 11586 |
pthread_cancel(r2->r2master); |
| 11587 |
pthread_join(r2->r2master, NULL); |
| 11588 |
r2->r2master = AST_PTHREADT_NULL; |
| 11589 |
openr2_context_delete(r2->protocol_context); |
| 11590 |
} |
| 11591 |
ast_free(cur); |
| 11592 |
} |
| 11593 |
AST_LIST_TRAVERSE_SAFE_END; |
| 11594 |
AST_LIST_UNLOCK(&nodev_r2links); |
| 11595 |
} |
| 11596 |
#endif |
| 11597 |
|
| 11598 |
static int setup_dahdi(int reload); |
| 11599 |
static int setup_dahdi_int(int reload, struct dahdi_chan_conf *default_conf, struct dahdi_chan_conf *base_conf, struct dahdi_chan_conf *conf); |
| 11600 |
|
| 11601 |
|
| 11602 |
|
| 11603 |
|
| 11604 |
|
| 11605 |
|
| 11606 |
|
| 11607 |
|
| 11608 |
|
| 11609 |
|
| 11610 |
|
| 11611 |
static int dahdi_create_channel_range(int start, int end) |
| 11612 |
{ |
| 11613 |
struct dahdi_pvt *cur; |
| 11614 |
struct dahdi_chan_conf default_conf = dahdi_chan_conf_default(); |
| 11615 |
struct dahdi_chan_conf base_conf = dahdi_chan_conf_default(); |
| 11616 |
struct dahdi_chan_conf conf = dahdi_chan_conf_default(); |
| 11617 |
int ret = RESULT_FAILURE; |
| 11618 |
|
| 11619 |
ast_debug(1, "channel range caps: %d - %d\n", start, end); |
| 11620 |
ast_mutex_lock(&iflock); |
| 11621 |
for (cur = iflist; cur; cur = cur->next) { |
| 11622 |
if (cur->channel >= start && cur->channel <= end) { |
| 11623 |
ast_log(LOG_ERROR, |
| 11624 |
"channel range %d-%d is occupied\n", |
| 11625 |
start, end); |
| 11626 |
goto out; |
| 11627 |
} |
| 11628 |
} |
| 11629 |
#ifdef HAVE_PRI |
| 11630 |
{ |
| 11631 |
int i, x; |
| 11632 |
for (x = 0; x < NUM_SPANS; x++) { |
| 11633 |
struct dahdi_pri *pri = pris + x; |
| 11634 |
|
| 11635 |
if (!pris[x].pri.pvts[0]) { |
| 11636 |
break; |
| 11637 |
} |
| 11638 |
for (i = 0; i < SIG_PRI_NUM_DCHANS; i++) { |
| 11639 |
int channo = pri->dchannels[i]; |
| 11640 |
|
| 11641 |
if (!channo) { |
| 11642 |
break; |
| 11643 |
} |
| 11644 |
if (!pri->pri.fds[i]) { |
| 11645 |
break; |
| 11646 |
} |
| 11647 |
if (channo >= start && channo <= end) { |
| 11648 |
ast_log(LOG_ERROR, |
| 11649 |
"channel range %d-%d is occupied by span %d\n", |
| 11650 |
start, end, x + 1); |
| 11651 |
goto out; |
| 11652 |
} |
| 11653 |
} |
| 11654 |
} |
| 11655 |
} |
| 11656 |
#endif |
| 11657 |
if (!default_conf.chan.cc_params || !base_conf.chan.cc_params || |
| 11658 |
!conf.chan.cc_params) { |
| 11659 |
goto out; |
| 11660 |
} |
| 11661 |
default_conf.wanted_channels_start = start; |
| 11662 |
base_conf.wanted_channels_start = start; |
| 11663 |
conf.wanted_channels_start = start; |
| 11664 |
default_conf.wanted_channels_end = end; |
| 11665 |
base_conf.wanted_channels_end = end; |
| 11666 |
conf.wanted_channels_end = end; |
| 11667 |
if (setup_dahdi_int(0, &default_conf, &base_conf, &conf) == 0) { |
| 11668 |
ret = RESULT_SUCCESS; |
| 11669 |
} |
| 11670 |
out: |
| 11671 |
ast_cc_config_params_destroy(default_conf.chan.cc_params); |
| 11672 |
ast_cc_config_params_destroy(base_conf.chan.cc_params); |
| 11673 |
ast_cc_config_params_destroy(conf.chan.cc_params); |
| 11674 |
ast_mutex_unlock(&iflock); |
| 11675 |
return ret; |
| 11676 |
} |
| 11677 |
|
| 11678 |
|
| 11679 |
static struct dahdi_pvt *handle_init_event(struct dahdi_pvt *i, int event) |
| 11680 |
{ |
| 11681 |
int res; |
| 11682 |
pthread_t threadid; |
| 11683 |
struct ast_channel *chan; |
| 11684 |
ast_callid callid = 0; |
| 11685 |
int callid_created; |
| 11686 |
|
| 11687 |
|
| 11688 |
|
| 11689 |
switch (event) { |
| 11690 |
case DAHDI_EVENT_NONE: |
| 11691 |
case DAHDI_EVENT_BITSCHANGED: |
| 11692 |
break; |
| 11693 |
case DAHDI_EVENT_WINKFLASH: |
| 11694 |
case DAHDI_EVENT_RINGOFFHOOK: |
| 11695 |
if (i->inalarm) break; |
| 11696 |
if (i->radio) break; |
| 11697 |
|
| 11698 |
switch (i->sig) { |
| 11699 |
case SIG_FXOLS: |
| 11700 |
case SIG_FXOGS: |
| 11701 |
case SIG_FXOKS: |
| 11702 |
res = dahdi_set_hook(i->subs[SUB_REAL].dfd, DAHDI_OFFHOOK); |
| 11703 |
if (res && (errno == EBUSY)) { |
| 11704 |
break; |
| 11705 |
} |
| 11706 |
|
| 11707 |
callid_created = ast_callid_threadstorage_auto(&callid); |
| 11708 |
|
| 11709 |
|
| 11710 |
ast_free(i->cidspill); |
| 11711 |
i->cidspill = NULL; |
| 11712 |
restore_conference(i); |
| 11713 |
|
| 11714 |
if (i->immediate) { |
| 11715 |
dahdi_ec_enable(i); |
| 11716 |
|
| 11717 |
res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, DAHDI_TONE_RINGTONE); |
| 11718 |
chan = dahdi_new(i, AST_STATE_RING, 1, SUB_REAL, 0, NULL, NULL, callid); |
| 11719 |
if (!chan) { |
| 11720 |
ast_log(LOG_WARNING, "Unable to start PBX on channel %d\n", i->channel); |
| 11721 |
res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, DAHDI_TONE_CONGESTION); |
| 11722 |
if (res < 0) |
| 11723 |
ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel); |
| 11724 |
} |
| 11725 |
} else { |
| 11726 |
|
| 11727 |
chan = dahdi_new(i, AST_STATE_RESERVED, 0, SUB_REAL, 0, NULL, NULL, callid); |
| 11728 |
if (chan) { |
| 11729 |
if (has_voicemail(i)) |
| 11730 |
res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, DAHDI_TONE_STUTTER); |
| 11731 |
else |
| 11732 |
res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, DAHDI_TONE_DIALTONE); |
| 11733 |
if (res < 0) |
| 11734 |
ast_log(LOG_WARNING, "Unable to play dialtone on channel %d, do you have defaultzone and loadzone defined?\n", i->channel); |
| 11735 |
if (ast_pthread_create_detached(&threadid, NULL, analog_ss_thread, chan)) { |
| 11736 |
ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel); |
| 11737 |
res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, DAHDI_TONE_CONGESTION); |
| 11738 |
if (res < 0) |
| 11739 |
ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel); |
| 11740 |
ast_hangup(chan); |
| 11741 |
} |
| 11742 |
} else |
| 11743 |
ast_log(LOG_WARNING, "Unable to create channel\n"); |
| 11744 |
} |
| 11745 |
|
| 11746 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 11747 |
break; |
| 11748 |
case SIG_FXSLS: |
| 11749 |
case SIG_FXSGS: |
| 11750 |
case SIG_FXSKS: |
| 11751 |
i->ringt = i->ringt_base; |
| 11752 |
|
| 11753 |
case SIG_EMWINK: |
| 11754 |
case SIG_FEATD: |
| 11755 |
case SIG_FEATDMF: |
| 11756 |
case SIG_FEATDMF_TA: |
| 11757 |
case SIG_E911: |
| 11758 |
case SIG_FGC_CAMA: |
| 11759 |
case SIG_FGC_CAMAMF: |
| 11760 |
case SIG_FEATB: |
| 11761 |
case SIG_EM: |
| 11762 |
case SIG_EM_E1: |
| 11763 |
case SIG_SFWINK: |
| 11764 |
case SIG_SF_FEATD: |
| 11765 |
case SIG_SF_FEATDMF: |
| 11766 |
case SIG_SF_FEATB: |
| 11767 |
case SIG_SF: |
| 11768 |
|
| 11769 |
callid_created = ast_callid_threadstorage_auto(&callid); |
| 11770 |
if (i->cid_start == CID_START_POLARITY_IN) { |
| 11771 |
chan = dahdi_new(i, AST_STATE_PRERING, 0, SUB_REAL, 0, NULL, NULL, callid); |
| 11772 |
} else { |
| 11773 |
chan = dahdi_new(i, AST_STATE_RING, 0, SUB_REAL, 0, NULL, NULL, callid); |
| 11774 |
} |
| 11775 |
|
| 11776 |
if (!chan) { |
| 11777 |
ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel); |
| 11778 |
} else if (ast_pthread_create_detached(&threadid, NULL, analog_ss_thread, chan)) { |
| 11779 |
ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel); |
| 11780 |
res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, DAHDI_TONE_CONGESTION); |
| 11781 |
if (res < 0) { |
| 11782 |
ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel); |
| 11783 |
} |
| 11784 |
ast_hangup(chan); |
| 11785 |
} |
| 11786 |
|
| 11787 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 11788 |
break; |
| 11789 |
default: |
| 11790 |
ast_log(LOG_WARNING, "Don't know how to handle ring/answer with signalling %s on channel %d\n", sig2str(i->sig), i->channel); |
| 11791 |
res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, DAHDI_TONE_CONGESTION); |
| 11792 |
if (res < 0) |
| 11793 |
ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel); |
| 11794 |
return NULL; |
| 11795 |
} |
| 11796 |
break; |
| 11797 |
case DAHDI_EVENT_NOALARM: |
| 11798 |
switch (i->sig) { |
| 11799 |
#if defined(HAVE_PRI) |
| 11800 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 11801 |
ast_mutex_lock(&i->lock); |
| 11802 |
sig_pri_chan_alarm_notify(i->sig_pvt, 1); |
| 11803 |
ast_mutex_unlock(&i->lock); |
| 11804 |
break; |
| 11805 |
#endif |
| 11806 |
#if defined(HAVE_SS7) |
| 11807 |
case SIG_SS7: |
| 11808 |
sig_ss7_set_alarm(i->sig_pvt, 0); |
| 11809 |
break; |
| 11810 |
#endif |
| 11811 |
default: |
| 11812 |
i->inalarm = 0; |
| 11813 |
break; |
| 11814 |
} |
| 11815 |
handle_clear_alarms(i); |
| 11816 |
break; |
| 11817 |
case DAHDI_EVENT_ALARM: |
| 11818 |
switch (i->sig) { |
| 11819 |
#if defined(HAVE_PRI) |
| 11820 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 11821 |
ast_mutex_lock(&i->lock); |
| 11822 |
sig_pri_chan_alarm_notify(i->sig_pvt, 0); |
| 11823 |
ast_mutex_unlock(&i->lock); |
| 11824 |
break; |
| 11825 |
#endif |
| 11826 |
#if defined(HAVE_SS7) |
| 11827 |
case SIG_SS7: |
| 11828 |
sig_ss7_set_alarm(i->sig_pvt, 1); |
| 11829 |
break; |
| 11830 |
#endif |
| 11831 |
default: |
| 11832 |
i->inalarm = 1; |
| 11833 |
break; |
| 11834 |
} |
| 11835 |
res = get_alarms(i); |
| 11836 |
handle_alarms(i, res); |
| 11837 |
|
| 11838 |
case DAHDI_EVENT_ONHOOK: |
| 11839 |
if (i->radio) |
| 11840 |
break; |
| 11841 |
|
| 11842 |
switch (i->sig) { |
| 11843 |
case SIG_FXOLS: |
| 11844 |
case SIG_FXOGS: |
| 11845 |
case SIG_FEATD: |
| 11846 |
case SIG_FEATDMF: |
| 11847 |
case SIG_FEATDMF_TA: |
| 11848 |
case SIG_E911: |
| 11849 |
case SIG_FGC_CAMA: |
| 11850 |
case SIG_FGC_CAMAMF: |
| 11851 |
case SIG_FEATB: |
| 11852 |
case SIG_EM: |
| 11853 |
case SIG_EM_E1: |
| 11854 |
case SIG_EMWINK: |
| 11855 |
case SIG_SF_FEATD: |
| 11856 |
case SIG_SF_FEATDMF: |
| 11857 |
case SIG_SF_FEATB: |
| 11858 |
case SIG_SF: |
| 11859 |
case SIG_SFWINK: |
| 11860 |
case SIG_FXSLS: |
| 11861 |
case SIG_FXSGS: |
| 11862 |
case SIG_FXSKS: |
| 11863 |
case SIG_FXOKS: |
| 11864 |
dahdi_ec_disable(i); |
| 11865 |
|
| 11866 |
#ifdef ZHONE_HACK |
| 11867 |
dahdi_set_hook(i->subs[SUB_REAL].dfd, DAHDI_OFFHOOK); |
| 11868 |
usleep(1); |
| 11869 |
#endif |
| 11870 |
res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, -1); |
| 11871 |
dahdi_set_hook(i->subs[SUB_REAL].dfd, DAHDI_ONHOOK); |
| 11872 |
break; |
| 11873 |
case SIG_SS7: |
| 11874 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 11875 |
dahdi_ec_disable(i); |
| 11876 |
res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, -1); |
| 11877 |
break; |
| 11878 |
default: |
| 11879 |
ast_log(LOG_WARNING, "Don't know how to handle on hook with signalling %s on channel %d\n", sig2str(i->sig), i->channel); |
| 11880 |
res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, -1); |
| 11881 |
return NULL; |
| 11882 |
} |
| 11883 |
break; |
| 11884 |
case DAHDI_EVENT_POLARITY: |
| 11885 |
switch (i->sig) { |
| 11886 |
case SIG_FXSLS: |
| 11887 |
case SIG_FXSKS: |
| 11888 |
case SIG_FXSGS: |
| 11889 |
|
| 11890 |
|
| 11891 |
|
| 11892 |
|
| 11893 |
callid_created = ast_callid_threadstorage_auto(&callid); |
| 11894 |
if (i->hanguponpolarityswitch) |
| 11895 |
i->polarity = POLARITY_REV; |
| 11896 |
if (i->cid_start == CID_START_POLARITY || i->cid_start == CID_START_POLARITY_IN) { |
| 11897 |
i->polarity = POLARITY_REV; |
| 11898 |
ast_verb(2, "Starting post polarity " |
| 11899 |
"CID detection on channel %d\n", |
| 11900 |
i->channel); |
| 11901 |
chan = dahdi_new(i, AST_STATE_PRERING, 0, SUB_REAL, 0, NULL, NULL, callid); |
| 11902 |
if (!chan) { |
| 11903 |
ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel); |
| 11904 |
} else if (ast_pthread_create_detached(&threadid, NULL, analog_ss_thread, chan)) { |
| 11905 |
ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel); |
| 11906 |
ast_hangup(chan); |
| 11907 |
} |
| 11908 |
} |
| 11909 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 11910 |
break; |
| 11911 |
default: |
| 11912 |
ast_log(LOG_WARNING, "handle_init_event detected " |
| 11913 |
"polarity reversal on non-FXO (SIG_FXS) " |
| 11914 |
"interface %d\n", i->channel); |
| 11915 |
} |
| 11916 |
break; |
| 11917 |
case DAHDI_EVENT_REMOVED: |
| 11918 |
ast_log(LOG_NOTICE, |
| 11919 |
"Got DAHDI_EVENT_REMOVED. Destroying channel %d\n", |
| 11920 |
i->channel); |
| 11921 |
return i; |
| 11922 |
case DAHDI_EVENT_NEONMWI_ACTIVE: |
| 11923 |
if (i->mwimonitor_neon) { |
| 11924 |
notify_message(i->mailbox, 1); |
| 11925 |
ast_log(LOG_NOTICE, "NEON MWI set for channel %d, mailbox %s \n", i->channel, i->mailbox); |
| 11926 |
} |
| 11927 |
break; |
| 11928 |
case DAHDI_EVENT_NEONMWI_INACTIVE: |
| 11929 |
if (i->mwimonitor_neon) { |
| 11930 |
notify_message(i->mailbox, 0); |
| 11931 |
ast_log(LOG_NOTICE, "NEON MWI cleared for channel %d, mailbox %s\n", i->channel, i->mailbox); |
| 11932 |
} |
| 11933 |
break; |
| 11934 |
} |
| 11935 |
return NULL; |
| 11936 |
} |
| 11937 |
|
| 11938 |
static void monitor_pfds_clean(void *arg) { |
| 11939 |
struct pollfd **pfds = arg; |
| 11940 |
ast_free(*pfds); |
| 11941 |
} |
| 11942 |
|
| 11943 |
static void *do_monitor(void *data) |
| 11944 |
{ |
| 11945 |
int count, res, res2, spoint, pollres=0; |
| 11946 |
struct dahdi_pvt *i; |
| 11947 |
struct dahdi_pvt *last = NULL; |
| 11948 |
struct dahdi_pvt *doomed; |
| 11949 |
time_t thispass = 0, lastpass = 0; |
| 11950 |
int found; |
| 11951 |
char buf[1024]; |
| 11952 |
struct pollfd *pfds=NULL; |
| 11953 |
int lastalloc = -1; |
| 11954 |
|
| 11955 |
|
| 11956 |
|
| 11957 |
#if 0 |
| 11958 |
if (pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL)) { |
| 11959 |
ast_log(LOG_WARNING, "Unable to set cancel type to asynchronous\n"); |
| 11960 |
return NULL; |
| 11961 |
} |
| 11962 |
ast_debug(1, "Monitor starting...\n"); |
| 11963 |
#endif |
| 11964 |
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); |
| 11965 |
|
| 11966 |
pthread_cleanup_push(monitor_pfds_clean, &pfds); |
| 11967 |
for (;;) { |
| 11968 |
|
| 11969 |
ast_mutex_lock(&iflock); |
| 11970 |
if (!pfds || (lastalloc != ifcount)) { |
| 11971 |
if (pfds) { |
| 11972 |
ast_free(pfds); |
| 11973 |
pfds = NULL; |
| 11974 |
} |
| 11975 |
if (ifcount) { |
| 11976 |
if (!(pfds = ast_calloc(1, ifcount * sizeof(*pfds)))) { |
| 11977 |
ast_mutex_unlock(&iflock); |
| 11978 |
return NULL; |
| 11979 |
} |
| 11980 |
} |
| 11981 |
lastalloc = ifcount; |
| 11982 |
} |
| 11983 |
|
| 11984 |
|
| 11985 |
count = 0; |
| 11986 |
for (i = iflist; i; i = i->next) { |
| 11987 |
ast_mutex_lock(&i->lock); |
| 11988 |
if (pfds && (i->subs[SUB_REAL].dfd > -1) && i->sig && (!i->radio) && !(i->sig & SIG_MFCR2)) { |
| 11989 |
if (dahdi_analog_lib_handles(i->sig, i->radio, i->oprmode)) { |
| 11990 |
struct analog_pvt *p = i->sig_pvt; |
| 11991 |
|
| 11992 |
if (!p) { |
| 11993 |
ast_log(LOG_ERROR, "No sig_pvt?\n"); |
| 11994 |
} else if (!p->owner && !p->subs[SUB_REAL].owner) { |
| 11995 |
|
| 11996 |
pfds[count].fd = i->subs[SUB_REAL].dfd; |
| 11997 |
pfds[count].events = POLLPRI; |
| 11998 |
pfds[count].revents = 0; |
| 11999 |
|
| 12000 |
if (i->cidspill || i->mwisendactive || i->mwimonitor_fsk || |
| 12001 |
(i->cid_start == CID_START_DTMF_NOALERT && (i->sig == SIG_FXSLS || i->sig == SIG_FXSGS || i->sig == SIG_FXSKS))) { |
| 12002 |
pfds[count].events |= POLLIN; |
| 12003 |
} |
| 12004 |
count++; |
| 12005 |
} |
| 12006 |
} else { |
| 12007 |
if (!i->owner && !i->subs[SUB_REAL].owner && !i->mwimonitoractive ) { |
| 12008 |
|
| 12009 |
pfds[count].fd = i->subs[SUB_REAL].dfd; |
| 12010 |
pfds[count].events = POLLPRI; |
| 12011 |
pfds[count].revents = 0; |
| 12012 |
|
| 12013 |
|
| 12014 |
if (i->cidspill || i->mwisendactive || i->mwimonitor_fsk || |
| 12015 |
(i->cid_start == CID_START_DTMF_NOALERT && (i->sig == SIG_FXSLS || i->sig == SIG_FXSGS || i->sig == SIG_FXSKS))) { |
| 12016 |
pfds[count].events |= POLLIN; |
| 12017 |
} |
| 12018 |
count++; |
| 12019 |
} |
| 12020 |
} |
| 12021 |
} |
| 12022 |
ast_mutex_unlock(&i->lock); |
| 12023 |
} |
| 12024 |
|
| 12025 |
ast_mutex_unlock(&iflock); |
| 12026 |
|
| 12027 |
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); |
| 12028 |
pthread_testcancel(); |
| 12029 |
|
| 12030 |
res = poll(pfds, count, 1000); |
| 12031 |
pthread_testcancel(); |
| 12032 |
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); |
| 12033 |
|
| 12034 |
|
| 12035 |
if (res < 0) { |
| 12036 |
if ((errno != EAGAIN) && (errno != EINTR)) |
| 12037 |
ast_log(LOG_WARNING, "poll return %d: %s\n", res, strerror(errno)); |
| 12038 |
continue; |
| 12039 |
} |
| 12040 |
|
| 12041 |
|
| 12042 |
ast_mutex_lock(&iflock); |
| 12043 |
found = 0; |
| 12044 |
spoint = 0; |
| 12045 |
lastpass = thispass; |
| 12046 |
thispass = time(NULL); |
| 12047 |
doomed = NULL; |
| 12048 |
for (i = iflist;; i = i->next) { |
| 12049 |
if (doomed) { |
| 12050 |
dahdi_destroy_channel_range(doomed->channel, doomed->channel); |
| 12051 |
doomed = NULL; |
| 12052 |
} |
| 12053 |
if (!i) { |
| 12054 |
break; |
| 12055 |
} |
| 12056 |
|
| 12057 |
if (thispass != lastpass) { |
| 12058 |
if (!found && ((i == last) || ((i == iflist) && !last))) { |
| 12059 |
last = i; |
| 12060 |
if (last) { |
| 12061 |
struct analog_pvt *analog_p = last->sig_pvt; |
| 12062 |
|
| 12063 |
if (analog_p |
| 12064 |
&& !last->mwisendactive |
| 12065 |
&& (last->sig & __DAHDI_SIG_FXO) |
| 12066 |
&& !analog_p->fxsoffhookstate |
| 12067 |
&& !last->owner |
| 12068 |
&& (!ast_strlen_zero(last->mailbox) || last->mwioverride_active) |
| 12069 |
&& !analog_p->subs[SUB_REAL].owner |
| 12070 |
&& (thispass - analog_p->onhooktime > 3) |
| 12071 |
|
| 12072 |
|
| 12073 |
|
| 12074 |
&& !my_is_off_hook(last)) { |
| 12075 |
res = has_voicemail(last); |
| 12076 |
if (analog_p->msgstate != res) { |
| 12077 |
|
| 12078 |
res2 = ioctl(last->subs[SUB_REAL].dfd, DAHDI_VMWI, &res); |
| 12079 |
if (res2) { |
| 12080 |
|
| 12081 |
ast_debug(3, "Unable to control message waiting led on channel %d: %s\n", last->channel, strerror(errno)); |
| 12082 |
} |
| 12083 |
|
| 12084 |
ast_debug(5, "Initiating MWI FSK spill on channel %d\n", last->channel); |
| 12085 |
if (mwi_send_init(last)) { |
| 12086 |
ast_log(LOG_WARNING, "Unable to initiate mwi send sequence on channel %d\n", last->channel); |
| 12087 |
} |
| 12088 |
analog_p->msgstate = res; |
| 12089 |
found ++; |
| 12090 |
} |
| 12091 |
} |
| 12092 |
last = last->next; |
| 12093 |
} |
| 12094 |
} |
| 12095 |
} |
| 12096 |
if ((i->subs[SUB_REAL].dfd > -1) && i->sig) { |
| 12097 |
if (i->radio && !i->owner) |
| 12098 |
{ |
| 12099 |
res = dahdi_get_event(i->subs[SUB_REAL].dfd); |
| 12100 |
if (res) |
| 12101 |
{ |
| 12102 |
ast_debug(1, "Monitor doohicky got event %s on radio channel %d\n", event2str(res), i->channel); |
| 12103 |
|
| 12104 |
ast_mutex_unlock(&iflock); |
| 12105 |
if (dahdi_analog_lib_handles(i->sig, i->radio, i->oprmode)) |
| 12106 |
doomed = (struct dahdi_pvt *) analog_handle_init_event(i->sig_pvt, dahdievent_to_analogevent(res)); |
| 12107 |
else |
| 12108 |
doomed = handle_init_event(i, res); |
| 12109 |
ast_mutex_lock(&iflock); |
| 12110 |
} |
| 12111 |
continue; |
| 12112 |
} |
| 12113 |
pollres = ast_fdisset(pfds, i->subs[SUB_REAL].dfd, count, &spoint); |
| 12114 |
if (pollres & POLLIN) { |
| 12115 |
if (i->owner || i->subs[SUB_REAL].owner) { |
| 12116 |
#ifdef HAVE_PRI |
| 12117 |
if (!i->pri) |
| 12118 |
#endif |
| 12119 |
ast_log(LOG_WARNING, "Whoa.... I'm owned but found (%d) in read...\n", i->subs[SUB_REAL].dfd); |
| 12120 |
continue; |
| 12121 |
} |
| 12122 |
if (!i->mwimonitor_fsk && !i->mwisendactive && i->cid_start != CID_START_DTMF_NOALERT) { |
| 12123 |
ast_log(LOG_WARNING, "Whoa.... I'm not looking for MWI or sending MWI but am reading (%d)...\n", i->subs[SUB_REAL].dfd); |
| 12124 |
continue; |
| 12125 |
} |
| 12126 |
res = read(i->subs[SUB_REAL].dfd, buf, sizeof(buf)); |
| 12127 |
if (res > 0) { |
| 12128 |
if (i->mwimonitor_fsk) { |
| 12129 |
if (calc_energy((unsigned char *) buf, res, AST_LAW(i)) > mwilevel) { |
| 12130 |
pthread_attr_t attr; |
| 12131 |
pthread_t threadid; |
| 12132 |
struct mwi_thread_data *mtd; |
| 12133 |
|
| 12134 |
pthread_attr_init(&attr); |
| 12135 |
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 12136 |
|
| 12137 |
ast_debug(1, "Maybe some MWI on port %d!\n", i->channel); |
| 12138 |
if ((mtd = ast_calloc(1, sizeof(*mtd)))) { |
| 12139 |
mtd->pvt = i; |
| 12140 |
memcpy(mtd->buf, buf, res); |
| 12141 |
mtd->len = res; |
| 12142 |
i->mwimonitoractive = 1; |
| 12143 |
if (ast_pthread_create_background(&threadid, &attr, mwi_thread, mtd)) { |
| 12144 |
ast_log(LOG_WARNING, "Unable to start mwi thread on channel %d\n", i->channel); |
| 12145 |
i->mwimonitoractive = 0; |
| 12146 |
ast_free(mtd); |
| 12147 |
} |
| 12148 |
} |
| 12149 |
} |
| 12150 |
|
| 12151 |
} else if (i->cid_start == CID_START_DTMF_NOALERT) { |
| 12152 |
int energy; |
| 12153 |
struct timeval now; |
| 12154 |
|
| 12155 |
|
| 12156 |
|
| 12157 |
if (1 == i->dtmfcid_holdoff_state) { |
| 12158 |
gettimeofday(&i->dtmfcid_delay, NULL); |
| 12159 |
i->dtmfcid_holdoff_state = 2; |
| 12160 |
} else if (2 == i->dtmfcid_holdoff_state) { |
| 12161 |
gettimeofday(&now, NULL); |
| 12162 |
if ((int)(now.tv_sec - i->dtmfcid_delay.tv_sec) * 1000000 + (int)now.tv_usec - (int)i->dtmfcid_delay.tv_usec > 500000) { |
| 12163 |
i->dtmfcid_holdoff_state = 0; |
| 12164 |
} |
| 12165 |
} else { |
| 12166 |
energy = calc_energy((unsigned char *) buf, res, AST_LAW(i)); |
| 12167 |
if (!i->mwisendactive && energy > dtmfcid_level) { |
| 12168 |
pthread_t threadid; |
| 12169 |
struct ast_channel *chan; |
| 12170 |
ast_mutex_unlock(&iflock); |
| 12171 |
if (dahdi_analog_lib_handles(i->sig, i->radio, i->oprmode)) { |
| 12172 |
|
| 12173 |
doomed = analog_handle_init_event(i->sig_pvt, ANALOG_EVENT_DTMFCID); |
| 12174 |
i->dtmfcid_holdoff_state = 1; |
| 12175 |
} else { |
| 12176 |
ast_callid callid = 0; |
| 12177 |
int callid_created = ast_callid_threadstorage_auto(&callid); |
| 12178 |
chan = dahdi_new(i, AST_STATE_PRERING, 0, SUB_REAL, 0, NULL, NULL, callid); |
| 12179 |
if (!chan) { |
| 12180 |
ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel); |
| 12181 |
} else { |
| 12182 |
res = ast_pthread_create_detached(&threadid, NULL, analog_ss_thread, chan); |
| 12183 |
if (res) { |
| 12184 |
ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel); |
| 12185 |
ast_hangup(chan); |
| 12186 |
} else { |
| 12187 |
i->dtmfcid_holdoff_state = 1; |
| 12188 |
} |
| 12189 |
} |
| 12190 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 12191 |
} |
| 12192 |
ast_mutex_lock(&iflock); |
| 12193 |
} |
| 12194 |
} |
| 12195 |
} |
| 12196 |
if (i->mwisendactive) { |
| 12197 |
mwi_send_process_buffer(i, res); |
| 12198 |
} |
| 12199 |
} else { |
| 12200 |
ast_log(LOG_WARNING, "Read failed with %d: %s\n", res, strerror(errno)); |
| 12201 |
} |
| 12202 |
} |
| 12203 |
if (pollres & POLLPRI) { |
| 12204 |
if (i->owner || i->subs[SUB_REAL].owner) { |
| 12205 |
#ifdef HAVE_PRI |
| 12206 |
if (!i->pri) |
| 12207 |
#endif |
| 12208 |
ast_log(LOG_WARNING, "Whoa.... I'm owned but found (%d)...\n", i->subs[SUB_REAL].dfd); |
| 12209 |
continue; |
| 12210 |
} |
| 12211 |
res = dahdi_get_event(i->subs[SUB_REAL].dfd); |
| 12212 |
ast_debug(1, "Monitor doohicky got event %s on channel %d\n", event2str(res), i->channel); |
| 12213 |
|
| 12214 |
ast_mutex_unlock(&iflock); |
| 12215 |
if (0 == i->mwisendactive || 0 == mwi_send_process_event(i, res)) { |
| 12216 |
if (dahdi_analog_lib_handles(i->sig, i->radio, i->oprmode)) |
| 12217 |
doomed = (struct dahdi_pvt *) analog_handle_init_event(i->sig_pvt, dahdievent_to_analogevent(res)); |
| 12218 |
else |
| 12219 |
doomed = handle_init_event(i, res); |
| 12220 |
} |
| 12221 |
if (i->doreoriginate && res == DAHDI_EVENT_HOOKCOMPLETE) { |
| 12222 |
|
| 12223 |
|
| 12224 |
|
| 12225 |
|
| 12226 |
i->doreoriginate = 0; |
| 12227 |
|
| 12228 |
|
| 12229 |
if (!my_is_off_hook(i)) { |
| 12230 |
ast_debug(1, "Woah! Went back on hook before reoriginate could happen on channel %d\n", i->channel); |
| 12231 |
} else { |
| 12232 |
ast_verb(3, "Automatic reorigination on channel %d\n", i->channel); |
| 12233 |
res = DAHDI_EVENT_RINGOFFHOOK; |
| 12234 |
if (dahdi_analog_lib_handles(i->sig, i->radio, i->oprmode)) { |
| 12235 |
doomed = (struct dahdi_pvt *) analog_handle_init_event(i->sig_pvt, dahdievent_to_analogevent(res)); |
| 12236 |
} else { |
| 12237 |
doomed = handle_init_event(i, res); |
| 12238 |
} |
| 12239 |
} |
| 12240 |
} |
| 12241 |
ast_mutex_lock(&iflock); |
| 12242 |
} |
| 12243 |
} |
| 12244 |
} |
| 12245 |
ast_mutex_unlock(&iflock); |
| 12246 |
release_doomed_pris(); |
| 12247 |
#ifdef HAVE_OPENR2 |
| 12248 |
dahdi_r2_destroy_nodev(); |
| 12249 |
#endif |
| 12250 |
} |
| 12251 |
|
| 12252 |
pthread_cleanup_pop(1); |
| 12253 |
return NULL; |
| 12254 |
|
| 12255 |
} |
| 12256 |
|
| 12257 |
static int restart_monitor(void) |
| 12258 |
{ |
| 12259 |
|
| 12260 |
if (monitor_thread == AST_PTHREADT_STOP) |
| 12261 |
return 0; |
| 12262 |
ast_mutex_lock(&monlock); |
| 12263 |
if (monitor_thread == pthread_self()) { |
| 12264 |
ast_mutex_unlock(&monlock); |
| 12265 |
ast_log(LOG_WARNING, "Cannot kill myself\n"); |
| 12266 |
return -1; |
| 12267 |
} |
| 12268 |
if (monitor_thread != AST_PTHREADT_NULL) { |
| 12269 |
|
| 12270 |
pthread_kill(monitor_thread, SIGURG); |
| 12271 |
} else { |
| 12272 |
|
| 12273 |
if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) { |
| 12274 |
ast_mutex_unlock(&monlock); |
| 12275 |
ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); |
| 12276 |
return -1; |
| 12277 |
} |
| 12278 |
} |
| 12279 |
ast_mutex_unlock(&monlock); |
| 12280 |
return 0; |
| 12281 |
} |
| 12282 |
|
| 12283 |
#if defined(HAVE_PRI) |
| 12284 |
static int pri_resolve_span(int *span, int channel, int offset, struct dahdi_spaninfo *si) |
| 12285 |
{ |
| 12286 |
int x; |
| 12287 |
int trunkgroup; |
| 12288 |
|
| 12289 |
trunkgroup = pris[*span].mastertrunkgroup; |
| 12290 |
if (trunkgroup) { |
| 12291 |
|
| 12292 |
for (x = 0; x < NUM_SPANS; x++) { |
| 12293 |
if (pris[x].pri.trunkgroup == trunkgroup) { |
| 12294 |
*span = x; |
| 12295 |
return 0; |
| 12296 |
} |
| 12297 |
} |
| 12298 |
ast_log(LOG_WARNING, "Channel %d on span %d configured to use nonexistent trunk group %d\n", channel, *span, trunkgroup); |
| 12299 |
*span = -1; |
| 12300 |
} else { |
| 12301 |
if (pris[*span].pri.trunkgroup) { |
| 12302 |
ast_log(LOG_WARNING, "Unable to use span %d implicitly since it is trunk group %d (please use spanmap)\n", *span, pris[*span].pri.trunkgroup); |
| 12303 |
*span = -1; |
| 12304 |
} else if (pris[*span].mastertrunkgroup) { |
| 12305 |
ast_log(LOG_WARNING, "Unable to use span %d implicitly since it is already part of trunk group %d\n", *span, pris[*span].mastertrunkgroup); |
| 12306 |
*span = -1; |
| 12307 |
} else { |
| 12308 |
if (si->totalchans == 31) { |
| 12309 |
|
| 12310 |
pris[*span].dchannels[0] = 16 + offset; |
| 12311 |
} else if (si->totalchans == 24) { |
| 12312 |
|
| 12313 |
pris[*span].dchannels[0] = 24 + offset; |
| 12314 |
} else if (si->totalchans == 3) { |
| 12315 |
|
| 12316 |
pris[*span].dchannels[0] = 3 + offset; |
| 12317 |
} else { |
| 12318 |
ast_log(LOG_WARNING, "Unable to use span %d, since the D-channel cannot be located (unexpected span size of %d channels)\n", *span, si->totalchans); |
| 12319 |
*span = -1; |
| 12320 |
return 0; |
| 12321 |
} |
| 12322 |
pris[*span].pri.span = *span + 1; |
| 12323 |
} |
| 12324 |
} |
| 12325 |
return 0; |
| 12326 |
} |
| 12327 |
#endif |
| 12328 |
|
| 12329 |
#if defined(HAVE_PRI) |
| 12330 |
static int pri_create_trunkgroup(int trunkgroup, int *channels) |
| 12331 |
{ |
| 12332 |
struct dahdi_spaninfo si; |
| 12333 |
struct dahdi_params p; |
| 12334 |
int fd; |
| 12335 |
int span; |
| 12336 |
int ospan=0; |
| 12337 |
int x,y; |
| 12338 |
for (x = 0; x < NUM_SPANS; x++) { |
| 12339 |
if (pris[x].pri.trunkgroup == trunkgroup) { |
| 12340 |
ast_log(LOG_WARNING, "Trunk group %d already exists on span %d, Primary d-channel %d\n", trunkgroup, x + 1, pris[x].dchannels[0]); |
| 12341 |
return -1; |
| 12342 |
} |
| 12343 |
} |
| 12344 |
for (y = 0; y < SIG_PRI_NUM_DCHANS; y++) { |
| 12345 |
if (!channels[y]) |
| 12346 |
break; |
| 12347 |
memset(&si, 0, sizeof(si)); |
| 12348 |
memset(&p, 0, sizeof(p)); |
| 12349 |
fd = open("/dev/dahdi/channel", O_RDWR); |
| 12350 |
if (fd < 0) { |
| 12351 |
ast_log(LOG_WARNING, "Failed to open channel: %s\n", strerror(errno)); |
| 12352 |
return -1; |
| 12353 |
} |
| 12354 |
x = channels[y]; |
| 12355 |
if (ioctl(fd, DAHDI_SPECIFY, &x)) { |
| 12356 |
ast_log(LOG_WARNING, "Failed to specify channel %d: %s\n", channels[y], strerror(errno)); |
| 12357 |
close(fd); |
| 12358 |
return -1; |
| 12359 |
} |
| 12360 |
if (ioctl(fd, DAHDI_GET_PARAMS, &p)) { |
| 12361 |
ast_log(LOG_WARNING, "Failed to get channel parameters for channel %d: %s\n", channels[y], strerror(errno)); |
| 12362 |
close(fd); |
| 12363 |
return -1; |
| 12364 |
} |
| 12365 |
if (ioctl(fd, DAHDI_SPANSTAT, &si)) { |
| 12366 |
ast_log(LOG_WARNING, "Failed go get span information on channel %d (span %d): %s\n", channels[y], p.spanno, strerror(errno)); |
| 12367 |
close(fd); |
| 12368 |
return -1; |
| 12369 |
} |
| 12370 |
span = p.spanno - 1; |
| 12371 |
if (pris[span].pri.trunkgroup) { |
| 12372 |
ast_log(LOG_WARNING, "Span %d is already provisioned for trunk group %d\n", span + 1, pris[span].pri.trunkgroup); |
| 12373 |
close(fd); |
| 12374 |
return -1; |
| 12375 |
} |
| 12376 |
if (pris[span].pri.pvts[0]) { |
| 12377 |
ast_log(LOG_WARNING, "Span %d is already provisioned with channels (implicit PRI maybe?)\n", span + 1); |
| 12378 |
close(fd); |
| 12379 |
return -1; |
| 12380 |
} |
| 12381 |
if (!y) { |
| 12382 |
pris[span].pri.trunkgroup = trunkgroup; |
| 12383 |
ospan = span; |
| 12384 |
} |
| 12385 |
pris[ospan].dchannels[y] = channels[y]; |
| 12386 |
pris[span].pri.span = span + 1; |
| 12387 |
close(fd); |
| 12388 |
} |
| 12389 |
return 0; |
| 12390 |
} |
| 12391 |
#endif |
| 12392 |
|
| 12393 |
#if defined(HAVE_PRI) |
| 12394 |
static int pri_create_spanmap(int span, int trunkgroup, int logicalspan) |
| 12395 |
{ |
| 12396 |
if (pris[span].mastertrunkgroup) { |
| 12397 |
ast_log(LOG_WARNING, "Span %d is already part of trunk group %d, cannot add to trunk group %d\n", span + 1, pris[span].mastertrunkgroup, trunkgroup); |
| 12398 |
return -1; |
| 12399 |
} |
| 12400 |
pris[span].mastertrunkgroup = trunkgroup; |
| 12401 |
pris[span].prilogicalspan = logicalspan; |
| 12402 |
return 0; |
| 12403 |
} |
| 12404 |
#endif |
| 12405 |
|
| 12406 |
#if defined(HAVE_SS7) |
| 12407 |
static unsigned int parse_pointcode(const char *pcstring) |
| 12408 |
{ |
| 12409 |
unsigned int code1, code2, code3; |
| 12410 |
int numvals; |
| 12411 |
|
| 12412 |
numvals = sscanf(pcstring, "%30d-%30d-%30d", &code1, &code2, &code3); |
| 12413 |
if (numvals == 1) |
| 12414 |
return code1; |
| 12415 |
if (numvals == 3) |
| 12416 |
return (code1 << 16) | (code2 << 8) | code3; |
| 12417 |
|
| 12418 |
return 0; |
| 12419 |
} |
| 12420 |
#endif |
| 12421 |
|
| 12422 |
#if defined(HAVE_SS7) |
| 12423 |
static struct dahdi_ss7 * ss7_resolve_linkset(int linkset) |
| 12424 |
{ |
| 12425 |
if ((linkset < 0) || (linkset >= NUM_SPANS)) |
| 12426 |
return NULL; |
| 12427 |
else |
| 12428 |
return &linksets[linkset - 1]; |
| 12429 |
} |
| 12430 |
#endif |
| 12431 |
|
| 12432 |
#ifdef HAVE_OPENR2 |
| 12433 |
static void dahdi_r2_destroy_links(void) |
| 12434 |
{ |
| 12435 |
struct r2link_entry *cur; |
| 12436 |
|
| 12437 |
|
| 12438 |
AST_LIST_LOCK(&r2links); |
| 12439 |
AST_LIST_TRAVERSE_SAFE_BEGIN(&r2links, cur, list) { |
| 12440 |
ast_debug(3, "MFC/R2 link #%d queued for destruction\n", cur->mfcr2.index); |
| 12441 |
AST_LIST_MOVE_CURRENT(&nodev_r2links, list); |
| 12442 |
} |
| 12443 |
AST_LIST_TRAVERSE_SAFE_END; |
| 12444 |
AST_LIST_UNLOCK(&r2links); |
| 12445 |
|
| 12446 |
dahdi_r2_destroy_nodev(); |
| 12447 |
} |
| 12448 |
|
| 12449 |
|
| 12450 |
#define R2_LINK_CAPACITY 30 |
| 12451 |
static struct r2link_entry *dahdi_r2_get_link(const struct dahdi_chan_conf *conf) |
| 12452 |
{ |
| 12453 |
struct r2link_entry *cur = NULL; |
| 12454 |
|
| 12455 |
|
| 12456 |
|
| 12457 |
|
| 12458 |
AST_LIST_LOCK(&r2links); |
| 12459 |
if (! AST_LIST_EMPTY(&r2links)) { |
| 12460 |
cur = AST_LIST_LAST(&r2links); |
| 12461 |
if (memcmp(&conf->mfcr2, &cur->mfcr2.conf, sizeof(conf->mfcr2))) { |
| 12462 |
ast_debug(3, "Need new R2 link because of: Configuration change\n"); |
| 12463 |
cur = NULL; |
| 12464 |
} else if (cur->mfcr2.numchans == R2_LINK_CAPACITY) { |
| 12465 |
ast_debug(3, "Need new R2 link because of: Capacity (%d)\n", R2_LINK_CAPACITY); |
| 12466 |
cur = NULL; |
| 12467 |
} |
| 12468 |
} |
| 12469 |
if (!cur) { |
| 12470 |
struct r2link_entry *tmp = NULL; |
| 12471 |
int new_idx = r2links_count + 1; |
| 12472 |
int i; |
| 12473 |
for (i = 1; i <= r2links_count; i++) { |
| 12474 |
int i_unused = 1; |
| 12475 |
AST_LIST_TRAVERSE(&r2links, tmp, list) { |
| 12476 |
if (i == tmp->mfcr2.index) { |
| 12477 |
i_unused = 0; |
| 12478 |
break; |
| 12479 |
} |
| 12480 |
} |
| 12481 |
if (i_unused) { |
| 12482 |
new_idx = i; |
| 12483 |
break; |
| 12484 |
} |
| 12485 |
} |
| 12486 |
cur = ast_calloc(1, sizeof(*cur)); |
| 12487 |
if (!cur) { |
| 12488 |
ast_log(LOG_ERROR, "Cannot allocate R2 link!\n"); |
| 12489 |
return NULL; |
| 12490 |
} |
| 12491 |
cur->mfcr2.index = new_idx; |
| 12492 |
cur->mfcr2.r2master = AST_PTHREADT_NULL; |
| 12493 |
r2links_count++; |
| 12494 |
ast_debug(3, "Created new R2 link #%d (now have %d)\n", new_idx, r2links_count); |
| 12495 |
AST_LIST_INSERT_TAIL(&r2links, cur, list); |
| 12496 |
} |
| 12497 |
AST_LIST_UNLOCK(&r2links); |
| 12498 |
return cur; |
| 12499 |
} |
| 12500 |
|
| 12501 |
static int dahdi_r2_set_context(struct dahdi_mfcr2 *r2_link, const struct dahdi_chan_conf *conf) |
| 12502 |
{ |
| 12503 |
char tmplogdir[] = "/tmp"; |
| 12504 |
char logdir[OR2_MAX_PATH]; |
| 12505 |
int threshold = 0; |
| 12506 |
int snres = 0; |
| 12507 |
r2_link->protocol_context = openr2_context_new(NULL, &dahdi_r2_event_iface, |
| 12508 |
&dahdi_r2_transcode_iface, conf->mfcr2.variant, conf->mfcr2.max_ani, |
| 12509 |
conf->mfcr2.max_dnis); |
| 12510 |
if (!r2_link->protocol_context) { |
| 12511 |
return -1; |
| 12512 |
} |
| 12513 |
openr2_context_set_log_level(r2_link->protocol_context, conf->mfcr2.loglevel); |
| 12514 |
openr2_context_set_ani_first(r2_link->protocol_context, conf->mfcr2.get_ani_first); |
| 12515 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1 |
| 12516 |
openr2_context_set_skip_category_request(r2_link->protocol_context, conf->mfcr2.skip_category_request); |
| 12517 |
#endif |
| 12518 |
openr2_context_set_mf_threshold(r2_link->protocol_context, threshold); |
| 12519 |
openr2_context_set_mf_back_timeout(r2_link->protocol_context, conf->mfcr2.mfback_timeout); |
| 12520 |
openr2_context_set_metering_pulse_timeout(r2_link->protocol_context, conf->mfcr2.metering_pulse_timeout); |
| 12521 |
openr2_context_set_double_answer(r2_link->protocol_context, conf->mfcr2.double_answer); |
| 12522 |
openr2_context_set_immediate_accept(r2_link->protocol_context, conf->mfcr2.immediate_accept); |
| 12523 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2 |
| 12524 |
openr2_context_set_dtmf_dialing(r2_link->protocol_context, conf->mfcr2.dtmf_dialing, conf->mfcr2.dtmf_time_on, conf->mfcr2.dtmf_time_off); |
| 12525 |
openr2_context_set_dtmf_detection(r2_link->protocol_context, conf->mfcr2.dtmf_detection); |
| 12526 |
#endif |
| 12527 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3 |
| 12528 |
openr2_context_set_dtmf_detection_end_timeout(r2_link->protocol_context, conf->mfcr2.dtmf_end_timeout); |
| 12529 |
#endif |
| 12530 |
if (ast_strlen_zero(conf->mfcr2.logdir)) { |
| 12531 |
if (openr2_context_set_log_directory(r2_link->protocol_context, tmplogdir)) { |
| 12532 |
ast_log(LOG_ERROR, "Failed setting default MFC/R2 log directory %s\n", tmplogdir); |
| 12533 |
} |
| 12534 |
} else { |
| 12535 |
snres = snprintf(logdir, sizeof(logdir), "%s/%s/%s", ast_config_AST_LOG_DIR, "mfcr2", conf->mfcr2.logdir); |
| 12536 |
if (snres >= sizeof(logdir)) { |
| 12537 |
ast_log(LOG_ERROR, "MFC/R2 logging directory truncated, using %s\n", tmplogdir); |
| 12538 |
if (openr2_context_set_log_directory(r2_link->protocol_context, tmplogdir)) { |
| 12539 |
ast_log(LOG_ERROR, "Failed setting default MFC/R2 log directory %s\n", tmplogdir); |
| 12540 |
} |
| 12541 |
} else { |
| 12542 |
if (openr2_context_set_log_directory(r2_link->protocol_context, logdir)) { |
| 12543 |
ast_log(LOG_ERROR, "Failed setting MFC/R2 log directory %s\n", logdir); |
| 12544 |
} |
| 12545 |
} |
| 12546 |
} |
| 12547 |
if (!ast_strlen_zero(conf->mfcr2.r2proto_file)) { |
| 12548 |
if (openr2_context_configure_from_advanced_file(r2_link->protocol_context, conf->mfcr2.r2proto_file)) { |
| 12549 |
ast_log(LOG_ERROR, "Failed to configure r2context from advanced configuration file %s\n", conf->mfcr2.r2proto_file); |
| 12550 |
} |
| 12551 |
} |
| 12552 |
|
| 12553 |
memcpy(&r2_link->conf, &conf->mfcr2, sizeof(r2_link->conf)); |
| 12554 |
return 0; |
| 12555 |
} |
| 12556 |
#endif |
| 12557 |
|
| 12558 |
|
| 12559 |
|
| 12560 |
|
| 12561 |
|
| 12562 |
|
| 12563 |
static int sigtype_to_signalling(int sigtype) |
| 12564 |
{ |
| 12565 |
return sigtype; |
| 12566 |
} |
| 12567 |
|
| 12568 |
|
| 12569 |
|
| 12570 |
|
| 12571 |
|
| 12572 |
|
| 12573 |
|
| 12574 |
|
| 12575 |
|
| 12576 |
|
| 12577 |
|
| 12578 |
|
| 12579 |
|
| 12580 |
|
| 12581 |
|
| 12582 |
static struct dahdi_pvt *mkintf(int channel, const struct dahdi_chan_conf *conf, int reloading) |
| 12583 |
{ |
| 12584 |
|
| 12585 |
struct dahdi_pvt *tmp; |
| 12586 |
char fn[80]; |
| 12587 |
struct dahdi_bufferinfo bi; |
| 12588 |
|
| 12589 |
int res; |
| 12590 |
#if defined(HAVE_PRI) |
| 12591 |
int span = 0; |
| 12592 |
#endif |
| 12593 |
int here = 0; |
| 12594 |
int x; |
| 12595 |
struct analog_pvt *analog_p = NULL; |
| 12596 |
struct dahdi_params p; |
| 12597 |
#if defined(HAVE_PRI) |
| 12598 |
struct dahdi_spaninfo si; |
| 12599 |
struct sig_pri_chan *pri_chan = NULL; |
| 12600 |
#endif |
| 12601 |
#if defined(HAVE_SS7) |
| 12602 |
struct sig_ss7_chan *ss7_chan = NULL; |
| 12603 |
#endif |
| 12604 |
|
| 12605 |
|
| 12606 |
for (tmp = iflist; tmp; tmp = tmp->next) { |
| 12607 |
if (!tmp->destroy) { |
| 12608 |
if (tmp->channel == channel) { |
| 12609 |
|
| 12610 |
here = 1; |
| 12611 |
break; |
| 12612 |
} |
| 12613 |
if (tmp->channel > channel) { |
| 12614 |
|
| 12615 |
tmp = NULL; |
| 12616 |
break; |
| 12617 |
} |
| 12618 |
} |
| 12619 |
} |
| 12620 |
|
| 12621 |
if (!here && reloading != 1) { |
| 12622 |
tmp = ast_calloc(1, sizeof(*tmp)); |
| 12623 |
if (!tmp) { |
| 12624 |
return NULL; |
| 12625 |
} |
| 12626 |
tmp->cc_params = ast_cc_config_params_init(); |
| 12627 |
if (!tmp->cc_params) { |
| 12628 |
ast_free(tmp); |
| 12629 |
return NULL; |
| 12630 |
} |
| 12631 |
ast_mutex_init(&tmp->lock); |
| 12632 |
ifcount++; |
| 12633 |
for (x = 0; x < 3; x++) |
| 12634 |
tmp->subs[x].dfd = -1; |
| 12635 |
tmp->channel = channel; |
| 12636 |
tmp->priindication_oob = conf->chan.priindication_oob; |
| 12637 |
} |
| 12638 |
|
| 12639 |
if (tmp) { |
| 12640 |
int chan_sig = conf->chan.sig; |
| 12641 |
|
| 12642 |
|
| 12643 |
if (reloading && tmp->vars) { |
| 12644 |
ast_variables_destroy(tmp->vars); |
| 12645 |
tmp->vars = NULL; |
| 12646 |
} |
| 12647 |
|
| 12648 |
if (!here) { |
| 12649 |
|
| 12650 |
if ((channel != CHAN_PSEUDO)) { |
| 12651 |
int count = 0; |
| 12652 |
|
| 12653 |
snprintf(fn, sizeof(fn), "%d", channel); |
| 12654 |
|
| 12655 |
tmp->subs[SUB_REAL].dfd = dahdi_open(fn); |
| 12656 |
|
| 12657 |
while (tmp->subs[SUB_REAL].dfd < 0 && reloading == 2 && count < 1000 && errno != ENXIO) { |
| 12658 |
usleep(1); |
| 12659 |
tmp->subs[SUB_REAL].dfd = dahdi_open(fn); |
| 12660 |
count++; |
| 12661 |
} |
| 12662 |
|
| 12663 |
if (tmp->subs[SUB_REAL].dfd < 0) { |
| 12664 |
ast_log(LOG_ERROR, "Unable to open channel %d: %s\nhere = %d, tmp->channel = %d, channel = %d\n", channel, strerror(errno), here, tmp->channel, channel); |
| 12665 |
destroy_dahdi_pvt(tmp); |
| 12666 |
return NULL; |
| 12667 |
} |
| 12668 |
memset(&p, 0, sizeof(p)); |
| 12669 |
res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &p); |
| 12670 |
if (res < 0) { |
| 12671 |
ast_log(LOG_ERROR, "Unable to get parameters: %s\n", strerror(errno)); |
| 12672 |
destroy_dahdi_pvt(tmp); |
| 12673 |
return NULL; |
| 12674 |
} |
| 12675 |
if (conf->is_sig_auto) |
| 12676 |
chan_sig = sigtype_to_signalling(p.sigtype); |
| 12677 |
if (p.sigtype != (chan_sig & 0x3ffff)) { |
| 12678 |
ast_log(LOG_ERROR, "Signalling requested on channel %d is %s but line is in %s signalling\n", channel, sig2str(chan_sig), sig2str(p.sigtype)); |
| 12679 |
destroy_dahdi_pvt(tmp); |
| 12680 |
return NULL; |
| 12681 |
} |
| 12682 |
tmp->law_default = p.curlaw; |
| 12683 |
tmp->law = p.curlaw; |
| 12684 |
tmp->span = p.spanno; |
| 12685 |
#if defined(HAVE_PRI) |
| 12686 |
span = p.spanno - 1; |
| 12687 |
#endif |
| 12688 |
} else { |
| 12689 |
chan_sig = 0; |
| 12690 |
} |
| 12691 |
tmp->sig = chan_sig; |
| 12692 |
tmp->outsigmod = conf->chan.outsigmod; |
| 12693 |
|
| 12694 |
if (dahdi_analog_lib_handles(chan_sig, tmp->radio, tmp->oprmode)) { |
| 12695 |
analog_p = analog_new(dahdisig_to_analogsig(chan_sig), tmp); |
| 12696 |
if (!analog_p) { |
| 12697 |
destroy_dahdi_pvt(tmp); |
| 12698 |
return NULL; |
| 12699 |
} |
| 12700 |
tmp->sig_pvt = analog_p; |
| 12701 |
} |
| 12702 |
#if defined(HAVE_SS7) |
| 12703 |
if (chan_sig == SIG_SS7) { |
| 12704 |
struct dahdi_ss7 *ss7; |
| 12705 |
int clear = 0; |
| 12706 |
|
| 12707 |
if (ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &clear)) { |
| 12708 |
ast_log(LOG_ERROR, "Unable to set clear mode on clear channel %d of span %d: %s\n", channel, p.spanno, strerror(errno)); |
| 12709 |
destroy_dahdi_pvt(tmp); |
| 12710 |
return NULL; |
| 12711 |
} |
| 12712 |
|
| 12713 |
ss7 = ss7_resolve_linkset(cur_linkset); |
| 12714 |
if (!ss7) { |
| 12715 |
ast_log(LOG_ERROR, "Unable to find linkset %d\n", cur_linkset); |
| 12716 |
destroy_dahdi_pvt(tmp); |
| 12717 |
return NULL; |
| 12718 |
} |
| 12719 |
ss7->ss7.span = cur_linkset; |
| 12720 |
if (cur_cicbeginswith < 0) { |
| 12721 |
ast_log(LOG_ERROR, "Need to set cicbeginswith for the channels!\n"); |
| 12722 |
destroy_dahdi_pvt(tmp); |
| 12723 |
return NULL; |
| 12724 |
} |
| 12725 |
ss7_chan = sig_ss7_chan_new(tmp, &ss7->ss7); |
| 12726 |
if (!ss7_chan) { |
| 12727 |
destroy_dahdi_pvt(tmp); |
| 12728 |
return NULL; |
| 12729 |
} |
| 12730 |
tmp->sig_pvt = ss7_chan; |
| 12731 |
tmp->ss7 = &ss7->ss7; |
| 12732 |
|
| 12733 |
ss7_chan->channel = tmp->channel; |
| 12734 |
ss7_chan->cic = cur_cicbeginswith++; |
| 12735 |
|
| 12736 |
|
| 12737 |
ss7_chan->dpc = cur_defaultdpc; |
| 12738 |
|
| 12739 |
ss7->ss7.pvts[ss7->ss7.numchans++] = ss7_chan; |
| 12740 |
|
| 12741 |
ast_copy_string(ss7->ss7.internationalprefix, conf->ss7.ss7.internationalprefix, sizeof(ss7->ss7.internationalprefix)); |
| 12742 |
ast_copy_string(ss7->ss7.nationalprefix, conf->ss7.ss7.nationalprefix, sizeof(ss7->ss7.nationalprefix)); |
| 12743 |
ast_copy_string(ss7->ss7.subscriberprefix, conf->ss7.ss7.subscriberprefix, sizeof(ss7->ss7.subscriberprefix)); |
| 12744 |
ast_copy_string(ss7->ss7.unknownprefix, conf->ss7.ss7.unknownprefix, sizeof(ss7->ss7.unknownprefix)); |
| 12745 |
ast_copy_string(ss7->ss7.networkroutedprefix, conf->ss7.ss7.networkroutedprefix, sizeof(ss7->ss7.networkroutedprefix)); |
| 12746 |
|
| 12747 |
ss7->ss7.called_nai = conf->ss7.ss7.called_nai; |
| 12748 |
ss7->ss7.calling_nai = conf->ss7.ss7.calling_nai; |
| 12749 |
} |
| 12750 |
#endif |
| 12751 |
#ifdef HAVE_OPENR2 |
| 12752 |
if (chan_sig == SIG_MFCR2) { |
| 12753 |
struct dahdi_mfcr2 *r2_link; |
| 12754 |
struct r2link_entry *r2_le = dahdi_r2_get_link(conf); |
| 12755 |
r2_link = &r2_le->mfcr2; |
| 12756 |
if (!r2_link) { |
| 12757 |
ast_log(LOG_WARNING, "Cannot get another R2 DAHDI context!\n"); |
| 12758 |
destroy_dahdi_pvt(tmp); |
| 12759 |
return NULL; |
| 12760 |
} |
| 12761 |
if (!r2_link->protocol_context && dahdi_r2_set_context(r2_link, conf)) { |
| 12762 |
ast_log(LOG_ERROR, "Cannot create OpenR2 protocol context.\n"); |
| 12763 |
destroy_dahdi_pvt(tmp); |
| 12764 |
return NULL; |
| 12765 |
} |
| 12766 |
if (r2_link->numchans == ARRAY_LEN(r2_link->pvts)) { |
| 12767 |
ast_log(LOG_ERROR, "Cannot add more channels to this link!\n"); |
| 12768 |
destroy_dahdi_pvt(tmp); |
| 12769 |
return NULL; |
| 12770 |
} |
| 12771 |
r2_link->pvts[r2_link->numchans++] = tmp; |
| 12772 |
tmp->r2chan = openr2_chan_new_from_fd(r2_link->protocol_context, |
| 12773 |
tmp->subs[SUB_REAL].dfd, |
| 12774 |
NULL, NULL); |
| 12775 |
if (!tmp->r2chan) { |
| 12776 |
openr2_liberr_t err = openr2_context_get_last_error(r2_link->protocol_context); |
| 12777 |
ast_log(LOG_ERROR, "Cannot create OpenR2 channel: %s\n", openr2_context_error_string(err)); |
| 12778 |
destroy_dahdi_pvt(tmp); |
| 12779 |
return NULL; |
| 12780 |
} |
| 12781 |
r2_link->live_chans++; |
| 12782 |
tmp->mfcr2 = r2_link; |
| 12783 |
if (conf->mfcr2.call_files) { |
| 12784 |
openr2_chan_enable_call_files(tmp->r2chan); |
| 12785 |
} |
| 12786 |
openr2_chan_set_client_data(tmp->r2chan, tmp); |
| 12787 |
|
| 12788 |
openr2_chan_set_logging_func(tmp->r2chan, (openr2_logging_func_t)dahdi_r2_on_chan_log); |
| 12789 |
openr2_chan_set_log_level(tmp->r2chan, conf->mfcr2.loglevel); |
| 12790 |
tmp->mfcr2_category = conf->mfcr2.category; |
| 12791 |
tmp->mfcr2_charge_calls = conf->mfcr2.charge_calls; |
| 12792 |
tmp->mfcr2_allow_collect_calls = conf->mfcr2.allow_collect_calls; |
| 12793 |
tmp->mfcr2_forced_release = conf->mfcr2.forced_release; |
| 12794 |
tmp->mfcr2_accept_on_offer = conf->mfcr2.accept_on_offer; |
| 12795 |
tmp->mfcr2call = 0; |
| 12796 |
tmp->mfcr2_dnis_index = 0; |
| 12797 |
tmp->mfcr2_ani_index = 0; |
| 12798 |
} |
| 12799 |
#endif |
| 12800 |
#ifdef HAVE_PRI |
| 12801 |
if (dahdi_sig_pri_lib_handles(chan_sig)) { |
| 12802 |
int offset; |
| 12803 |
int matchesdchan; |
| 12804 |
int x,y; |
| 12805 |
int myswitchtype = 0; |
| 12806 |
|
| 12807 |
offset = 0; |
| 12808 |
if (ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &offset)) { |
| 12809 |
ast_log(LOG_ERROR, "Unable to set clear mode on clear channel %d of span %d: %s\n", channel, p.spanno, strerror(errno)); |
| 12810 |
destroy_dahdi_pvt(tmp); |
| 12811 |
return NULL; |
| 12812 |
} |
| 12813 |
if (span >= NUM_SPANS) { |
| 12814 |
ast_log(LOG_ERROR, "Channel %d does not lie on a span I know of (%d)\n", channel, span); |
| 12815 |
destroy_dahdi_pvt(tmp); |
| 12816 |
return NULL; |
| 12817 |
} else { |
| 12818 |
si.spanno = 0; |
| 12819 |
if (ioctl(tmp->subs[SUB_REAL].dfd,DAHDI_SPANSTAT,&si) == -1) { |
| 12820 |
ast_log(LOG_ERROR, "Unable to get span status: %s\n", strerror(errno)); |
| 12821 |
destroy_dahdi_pvt(tmp); |
| 12822 |
return NULL; |
| 12823 |
} |
| 12824 |
|
| 12825 |
tmp->logicalspan = pris[span].prilogicalspan; |
| 12826 |
pri_resolve_span(&span, channel, (channel - p.chanpos), &si); |
| 12827 |
if (span < 0) { |
| 12828 |
ast_log(LOG_WARNING, "Channel %d: Unable to find locate channel/trunk group!\n", channel); |
| 12829 |
destroy_dahdi_pvt(tmp); |
| 12830 |
return NULL; |
| 12831 |
} |
| 12832 |
myswitchtype = conf->pri.pri.switchtype; |
| 12833 |
|
| 12834 |
matchesdchan=0; |
| 12835 |
for (x = 0; x < NUM_SPANS; x++) { |
| 12836 |
for (y = 0; y < SIG_PRI_NUM_DCHANS; y++) { |
| 12837 |
if (pris[x].dchannels[y] == tmp->channel) { |
| 12838 |
matchesdchan = 1; |
| 12839 |
break; |
| 12840 |
} |
| 12841 |
} |
| 12842 |
} |
| 12843 |
if (!matchesdchan) { |
| 12844 |
if (pris[span].pri.nodetype && (pris[span].pri.nodetype != conf->pri.pri.nodetype)) { |
| 12845 |
ast_log(LOG_ERROR, "Span %d is already a %s node\n", span + 1, pri_node2str(pris[span].pri.nodetype)); |
| 12846 |
destroy_dahdi_pvt(tmp); |
| 12847 |
return NULL; |
| 12848 |
} |
| 12849 |
if (pris[span].pri.switchtype && (pris[span].pri.switchtype != myswitchtype)) { |
| 12850 |
ast_log(LOG_ERROR, "Span %d is already a %s switch\n", span + 1, pri_switch2str(pris[span].pri.switchtype)); |
| 12851 |
destroy_dahdi_pvt(tmp); |
| 12852 |
return NULL; |
| 12853 |
} |
| 12854 |
if ((pris[span].pri.dialplan) && (pris[span].pri.dialplan != conf->pri.pri.dialplan)) { |
| 12855 |
ast_log(LOG_ERROR, "Span %d is already a %s dialing plan\n", span + 1, pris[span].pri.dialplan == -1 ? "Dynamically set dialplan in ISDN" : pri_plan2str(pris[span].pri.dialplan)); |
| 12856 |
destroy_dahdi_pvt(tmp); |
| 12857 |
return NULL; |
| 12858 |
} |
| 12859 |
if (!ast_strlen_zero(pris[span].pri.idledial) && strcmp(pris[span].pri.idledial, conf->pri.pri.idledial)) { |
| 12860 |
ast_log(LOG_ERROR, "Span %d already has idledial '%s'.\n", span + 1, conf->pri.pri.idledial); |
| 12861 |
destroy_dahdi_pvt(tmp); |
| 12862 |
return NULL; |
| 12863 |
} |
| 12864 |
if (!ast_strlen_zero(pris[span].pri.idleext) && strcmp(pris[span].pri.idleext, conf->pri.pri.idleext)) { |
| 12865 |
ast_log(LOG_ERROR, "Span %d already has idleext '%s'.\n", span + 1, conf->pri.pri.idleext); |
| 12866 |
destroy_dahdi_pvt(tmp); |
| 12867 |
return NULL; |
| 12868 |
} |
| 12869 |
if (pris[span].pri.minunused && (pris[span].pri.minunused != conf->pri.pri.minunused)) { |
| 12870 |
ast_log(LOG_ERROR, "Span %d already has minunused of %d.\n", span + 1, conf->pri.pri.minunused); |
| 12871 |
destroy_dahdi_pvt(tmp); |
| 12872 |
return NULL; |
| 12873 |
} |
| 12874 |
if (pris[span].pri.minidle && (pris[span].pri.minidle != conf->pri.pri.minidle)) { |
| 12875 |
ast_log(LOG_ERROR, "Span %d already has minidle of %d.\n", span + 1, conf->pri.pri.minidle); |
| 12876 |
destroy_dahdi_pvt(tmp); |
| 12877 |
return NULL; |
| 12878 |
} |
| 12879 |
if (pris[span].pri.numchans >= ARRAY_LEN(pris[span].pri.pvts)) { |
| 12880 |
ast_log(LOG_ERROR, "Unable to add channel %d: Too many channels in trunk group %d!\n", channel, |
| 12881 |
pris[span].pri.trunkgroup); |
| 12882 |
destroy_dahdi_pvt(tmp); |
| 12883 |
return NULL; |
| 12884 |
} |
| 12885 |
|
| 12886 |
pri_chan = sig_pri_chan_new(tmp, &pris[span].pri, tmp->logicalspan, p.chanpos, pris[span].mastertrunkgroup); |
| 12887 |
if (!pri_chan) { |
| 12888 |
destroy_dahdi_pvt(tmp); |
| 12889 |
return NULL; |
| 12890 |
} |
| 12891 |
tmp->sig_pvt = pri_chan; |
| 12892 |
tmp->pri = &pris[span].pri; |
| 12893 |
|
| 12894 |
tmp->priexclusive = conf->chan.priexclusive; |
| 12895 |
|
| 12896 |
if (!tmp->pri->cc_params) { |
| 12897 |
tmp->pri->cc_params = ast_cc_config_params_init(); |
| 12898 |
if (!tmp->pri->cc_params) { |
| 12899 |
destroy_dahdi_pvt(tmp); |
| 12900 |
return NULL; |
| 12901 |
} |
| 12902 |
} |
| 12903 |
ast_cc_copy_config_params(tmp->pri->cc_params, |
| 12904 |
conf->chan.cc_params); |
| 12905 |
|
| 12906 |
pris[span].pri.sig = chan_sig; |
| 12907 |
pris[span].pri.nodetype = conf->pri.pri.nodetype; |
| 12908 |
pris[span].pri.switchtype = myswitchtype; |
| 12909 |
pris[span].pri.nsf = conf->pri.pri.nsf; |
| 12910 |
pris[span].pri.dialplan = conf->pri.pri.dialplan; |
| 12911 |
pris[span].pri.localdialplan = conf->pri.pri.localdialplan; |
| 12912 |
pris[span].pri.cpndialplan = conf->pri.pri.cpndialplan; |
| 12913 |
pris[span].pri.pvts[pris[span].pri.numchans++] = tmp->sig_pvt; |
| 12914 |
pris[span].pri.minunused = conf->pri.pri.minunused; |
| 12915 |
pris[span].pri.minidle = conf->pri.pri.minidle; |
| 12916 |
pris[span].pri.overlapdial = conf->pri.pri.overlapdial; |
| 12917 |
pris[span].pri.qsigchannelmapping = conf->pri.pri.qsigchannelmapping; |
| 12918 |
pris[span].pri.discardremoteholdretrieval = conf->pri.pri.discardremoteholdretrieval; |
| 12919 |
#if defined(HAVE_PRI_SERVICE_MESSAGES) |
| 12920 |
pris[span].pri.enable_service_message_support = conf->pri.pri.enable_service_message_support; |
| 12921 |
#endif |
| 12922 |
#ifdef HAVE_PRI_INBANDDISCONNECT |
| 12923 |
pris[span].pri.inbanddisconnect = conf->pri.pri.inbanddisconnect; |
| 12924 |
#endif |
| 12925 |
#if defined(HAVE_PRI_CALL_HOLD) |
| 12926 |
pris[span].pri.hold_disconnect_transfer = |
| 12927 |
conf->pri.pri.hold_disconnect_transfer; |
| 12928 |
#endif |
| 12929 |
#if defined(HAVE_PRI_CCSS) |
| 12930 |
pris[span].pri.cc_ptmp_recall_mode = |
| 12931 |
conf->pri.pri.cc_ptmp_recall_mode; |
| 12932 |
pris[span].pri.cc_qsig_signaling_link_req = |
| 12933 |
conf->pri.pri.cc_qsig_signaling_link_req; |
| 12934 |
pris[span].pri.cc_qsig_signaling_link_rsp = |
| 12935 |
conf->pri.pri.cc_qsig_signaling_link_rsp; |
| 12936 |
#endif |
| 12937 |
#if defined(HAVE_PRI_CALL_WAITING) |
| 12938 |
pris[span].pri.max_call_waiting_calls = |
| 12939 |
conf->pri.pri.max_call_waiting_calls; |
| 12940 |
pris[span].pri.allow_call_waiting_calls = |
| 12941 |
conf->pri.pri.allow_call_waiting_calls; |
| 12942 |
#endif |
| 12943 |
pris[span].pri.transfer = conf->chan.transfer; |
| 12944 |
pris[span].pri.facilityenable = conf->pri.pri.facilityenable; |
| 12945 |
#if defined(HAVE_PRI_L2_PERSISTENCE) |
| 12946 |
pris[span].pri.l2_persistence = conf->pri.pri.l2_persistence; |
| 12947 |
#endif |
| 12948 |
pris[span].pri.colp_send = conf->pri.pri.colp_send; |
| 12949 |
#if defined(HAVE_PRI_AOC_EVENTS) |
| 12950 |
pris[span].pri.aoc_passthrough_flag = conf->pri.pri.aoc_passthrough_flag; |
| 12951 |
pris[span].pri.aoce_delayhangup = conf->pri.pri.aoce_delayhangup; |
| 12952 |
#endif |
| 12953 |
if (chan_sig == SIG_BRI_PTMP) { |
| 12954 |
pris[span].pri.layer1_ignored = conf->pri.pri.layer1_ignored; |
| 12955 |
} else { |
| 12956 |
|
| 12957 |
pris[span].pri.layer1_ignored = 0; |
| 12958 |
} |
| 12959 |
pris[span].pri.append_msn_to_user_tag = conf->pri.pri.append_msn_to_user_tag; |
| 12960 |
pris[span].pri.inband_on_setup_ack = conf->pri.pri.inband_on_setup_ack; |
| 12961 |
pris[span].pri.inband_on_proceeding = conf->pri.pri.inband_on_proceeding; |
| 12962 |
ast_copy_string(pris[span].pri.initial_user_tag, conf->chan.cid_tag, sizeof(pris[span].pri.initial_user_tag)); |
| 12963 |
ast_copy_string(pris[span].pri.msn_list, conf->pri.pri.msn_list, sizeof(pris[span].pri.msn_list)); |
| 12964 |
#if defined(HAVE_PRI_MWI) |
| 12965 |
ast_copy_string(pris[span].pri.mwi_mailboxes, |
| 12966 |
conf->pri.pri.mwi_mailboxes, |
| 12967 |
sizeof(pris[span].pri.mwi_mailboxes)); |
| 12968 |
ast_copy_string(pris[span].pri.mwi_vm_boxes, |
| 12969 |
conf->pri.pri.mwi_vm_boxes, |
| 12970 |
sizeof(pris[span].pri.mwi_vm_boxes)); |
| 12971 |
ast_copy_string(pris[span].pri.mwi_vm_numbers, |
| 12972 |
conf->pri.pri.mwi_vm_numbers, |
| 12973 |
sizeof(pris[span].pri.mwi_vm_numbers)); |
| 12974 |
#endif |
| 12975 |
ast_copy_string(pris[span].pri.idledial, conf->pri.pri.idledial, sizeof(pris[span].pri.idledial)); |
| 12976 |
ast_copy_string(pris[span].pri.idleext, conf->pri.pri.idleext, sizeof(pris[span].pri.idleext)); |
| 12977 |
ast_copy_string(pris[span].pri.internationalprefix, conf->pri.pri.internationalprefix, sizeof(pris[span].pri.internationalprefix)); |
| 12978 |
ast_copy_string(pris[span].pri.nationalprefix, conf->pri.pri.nationalprefix, sizeof(pris[span].pri.nationalprefix)); |
| 12979 |
ast_copy_string(pris[span].pri.localprefix, conf->pri.pri.localprefix, sizeof(pris[span].pri.localprefix)); |
| 12980 |
ast_copy_string(pris[span].pri.privateprefix, conf->pri.pri.privateprefix, sizeof(pris[span].pri.privateprefix)); |
| 12981 |
ast_copy_string(pris[span].pri.unknownprefix, conf->pri.pri.unknownprefix, sizeof(pris[span].pri.unknownprefix)); |
| 12982 |
pris[span].pri.moh_signaling = conf->pri.pri.moh_signaling; |
| 12983 |
pris[span].pri.resetinterval = conf->pri.pri.resetinterval; |
| 12984 |
#if defined(HAVE_PRI_DISPLAY_TEXT) |
| 12985 |
pris[span].pri.display_flags_send = conf->pri.pri.display_flags_send; |
| 12986 |
pris[span].pri.display_flags_receive = conf->pri.pri.display_flags_receive; |
| 12987 |
#endif |
| 12988 |
#if defined(HAVE_PRI_MCID) |
| 12989 |
pris[span].pri.mcid_send = conf->pri.pri.mcid_send; |
| 12990 |
#endif |
| 12991 |
pris[span].pri.force_restart_unavailable_chans = conf->pri.pri.force_restart_unavailable_chans; |
| 12992 |
#if defined(HAVE_PRI_DATETIME_SEND) |
| 12993 |
pris[span].pri.datetime_send = conf->pri.pri.datetime_send; |
| 12994 |
#endif |
| 12995 |
|
| 12996 |
for (x = 0; x < PRI_MAX_TIMERS; x++) { |
| 12997 |
pris[span].pri.pritimers[x] = conf->pri.pri.pritimers[x]; |
| 12998 |
} |
| 12999 |
|
| 13000 |
#if defined(HAVE_PRI_CALL_WAITING) |
| 13001 |
|
| 13002 |
pris[span].pri.ch_cfg.stripmsd = conf->chan.stripmsd; |
| 13003 |
pris[span].pri.ch_cfg.hidecallerid = conf->chan.hidecallerid; |
| 13004 |
pris[span].pri.ch_cfg.hidecalleridname = conf->chan.hidecalleridname; |
| 13005 |
pris[span].pri.ch_cfg.immediate = conf->chan.immediate; |
| 13006 |
pris[span].pri.ch_cfg.priexclusive = conf->chan.priexclusive; |
| 13007 |
pris[span].pri.ch_cfg.priindication_oob = conf->chan.priindication_oob; |
| 13008 |
pris[span].pri.ch_cfg.use_callerid = conf->chan.use_callerid; |
| 13009 |
pris[span].pri.ch_cfg.use_callingpres = conf->chan.use_callingpres; |
| 13010 |
ast_copy_string(pris[span].pri.ch_cfg.context, conf->chan.context, sizeof(pris[span].pri.ch_cfg.context)); |
| 13011 |
ast_copy_string(pris[span].pri.ch_cfg.mohinterpret, conf->chan.mohinterpret, sizeof(pris[span].pri.ch_cfg.mohinterpret)); |
| 13012 |
#endif |
| 13013 |
} else { |
| 13014 |
ast_log(LOG_ERROR, "Channel %d is reserved for D-channel.\n", p.chanpos); |
| 13015 |
destroy_dahdi_pvt(tmp); |
| 13016 |
return NULL; |
| 13017 |
} |
| 13018 |
} |
| 13019 |
} |
| 13020 |
#endif |
| 13021 |
} else { |
| 13022 |
|
| 13023 |
ast_log(LOG_WARNING, "Attempt to configure channel %d with signaling %s ignored because it is already configured to be %s.\n", tmp->channel, dahdi_sig2str(chan_sig), dahdi_sig2str(tmp->sig)); |
| 13024 |
chan_sig = tmp->sig; |
| 13025 |
if (tmp->subs[SUB_REAL].dfd > -1) { |
| 13026 |
memset(&p, 0, sizeof(p)); |
| 13027 |
res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &p); |
| 13028 |
} |
| 13029 |
} |
| 13030 |
|
| 13031 |
switch (chan_sig) { |
| 13032 |
case SIG_FXSKS: |
| 13033 |
case SIG_FXSLS: |
| 13034 |
case SIG_EM: |
| 13035 |
case SIG_EM_E1: |
| 13036 |
case SIG_EMWINK: |
| 13037 |
case SIG_FEATD: |
| 13038 |
case SIG_FEATDMF: |
| 13039 |
case SIG_FEATDMF_TA: |
| 13040 |
case SIG_FEATB: |
| 13041 |
case SIG_E911: |
| 13042 |
case SIG_SF: |
| 13043 |
case SIG_SFWINK: |
| 13044 |
case SIG_FGC_CAMA: |
| 13045 |
case SIG_FGC_CAMAMF: |
| 13046 |
case SIG_SF_FEATD: |
| 13047 |
case SIG_SF_FEATDMF: |
| 13048 |
case SIG_SF_FEATB: |
| 13049 |
p.starttime = 250; |
| 13050 |
break; |
| 13051 |
} |
| 13052 |
|
| 13053 |
if (tmp->radio) { |
| 13054 |
|
| 13055 |
p.channo = channel; |
| 13056 |
p.rxwinktime = 1; |
| 13057 |
p.rxflashtime = 1; |
| 13058 |
p.starttime = 1; |
| 13059 |
p.debouncetime = 5; |
| 13060 |
} else { |
| 13061 |
p.channo = channel; |
| 13062 |
|
| 13063 |
if (conf->timing.prewinktime >= 0) |
| 13064 |
p.prewinktime = conf->timing.prewinktime; |
| 13065 |
if (conf->timing.preflashtime >= 0) |
| 13066 |
p.preflashtime = conf->timing.preflashtime; |
| 13067 |
if (conf->timing.winktime >= 0) |
| 13068 |
p.winktime = conf->timing.winktime; |
| 13069 |
if (conf->timing.flashtime >= 0) |
| 13070 |
p.flashtime = conf->timing.flashtime; |
| 13071 |
if (conf->timing.starttime >= 0) |
| 13072 |
p.starttime = conf->timing.starttime; |
| 13073 |
if (conf->timing.rxwinktime >= 0) |
| 13074 |
p.rxwinktime = conf->timing.rxwinktime; |
| 13075 |
if (conf->timing.rxflashtime >= 0) |
| 13076 |
p.rxflashtime = conf->timing.rxflashtime; |
| 13077 |
if (conf->timing.debouncetime >= 0) |
| 13078 |
p.debouncetime = conf->timing.debouncetime; |
| 13079 |
} |
| 13080 |
|
| 13081 |
|
| 13082 |
if (tmp->subs[SUB_REAL].dfd >= 0) |
| 13083 |
{ |
| 13084 |
res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_SET_PARAMS, &p); |
| 13085 |
if (res < 0) { |
| 13086 |
ast_log(LOG_ERROR, "Unable to set parameters: %s\n", strerror(errno)); |
| 13087 |
destroy_dahdi_pvt(tmp); |
| 13088 |
return NULL; |
| 13089 |
} |
| 13090 |
} |
| 13091 |
#if 1 |
| 13092 |
if (!here && (tmp->subs[SUB_REAL].dfd > -1)) { |
| 13093 |
memset(&bi, 0, sizeof(bi)); |
| 13094 |
res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GET_BUFINFO, &bi); |
| 13095 |
if (!res) { |
| 13096 |
bi.txbufpolicy = conf->chan.buf_policy; |
| 13097 |
bi.rxbufpolicy = conf->chan.buf_policy; |
| 13098 |
bi.numbufs = conf->chan.buf_no; |
| 13099 |
res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_SET_BUFINFO, &bi); |
| 13100 |
if (res < 0) { |
| 13101 |
ast_log(LOG_WARNING, "Unable to set buffer policy on channel %d: %s\n", channel, strerror(errno)); |
| 13102 |
} |
| 13103 |
} else { |
| 13104 |
ast_log(LOG_WARNING, "Unable to check buffer policy on channel %d: %s\n", channel, strerror(errno)); |
| 13105 |
} |
| 13106 |
tmp->buf_policy = conf->chan.buf_policy; |
| 13107 |
tmp->buf_no = conf->chan.buf_no; |
| 13108 |
tmp->usefaxbuffers = conf->chan.usefaxbuffers; |
| 13109 |
tmp->faxbuf_policy = conf->chan.faxbuf_policy; |
| 13110 |
tmp->faxbuf_no = conf->chan.faxbuf_no; |
| 13111 |
|
| 13112 |
|
| 13113 |
|
| 13114 |
|
| 13115 |
tmp->bufsize = bi.bufsize; |
| 13116 |
} |
| 13117 |
#endif |
| 13118 |
tmp->immediate = conf->chan.immediate; |
| 13119 |
tmp->immediatering = conf->chan.immediatering; |
| 13120 |
tmp->transfertobusy = conf->chan.transfertobusy; |
| 13121 |
tmp->permdialmode = conf->chan.permdialmode; |
| 13122 |
if (chan_sig & __DAHDI_SIG_FXS) { |
| 13123 |
tmp->mwimonitor_fsk = conf->chan.mwimonitor_fsk; |
| 13124 |
tmp->mwimonitor_neon = conf->chan.mwimonitor_neon; |
| 13125 |
tmp->mwimonitor_rpas = conf->chan.mwimonitor_rpas; |
| 13126 |
} |
| 13127 |
tmp->ringt_base = ringt_base; |
| 13128 |
tmp->firstradio = 0; |
| 13129 |
if ((chan_sig == SIG_FXOKS) || (chan_sig == SIG_FXOLS) || (chan_sig == SIG_FXOGS)) |
| 13130 |
tmp->permcallwaiting = conf->chan.callwaiting; |
| 13131 |
else |
| 13132 |
tmp->permcallwaiting = 0; |
| 13133 |
|
| 13134 |
tmp->destroy = 0; |
| 13135 |
tmp->drings = conf->chan.drings; |
| 13136 |
|
| 13137 |
|
| 13138 |
if (tmp->drings.ringnum[0].range == 0) |
| 13139 |
tmp->drings.ringnum[0].range = 10; |
| 13140 |
if (tmp->drings.ringnum[1].range == 0) |
| 13141 |
tmp->drings.ringnum[1].range = 10; |
| 13142 |
if (tmp->drings.ringnum[2].range == 0) |
| 13143 |
tmp->drings.ringnum[2].range = 10; |
| 13144 |
|
| 13145 |
tmp->usedistinctiveringdetection = usedistinctiveringdetection; |
| 13146 |
tmp->callwaitingcallerid = conf->chan.callwaitingcallerid; |
| 13147 |
tmp->callwaitingdeluxe = conf->chan.callwaitingdeluxe; |
| 13148 |
tmp->threewaycalling = conf->chan.threewaycalling; |
| 13149 |
tmp->threewaysilenthold = conf->chan.threewaysilenthold; |
| 13150 |
tmp->calledsubscriberheld = conf->chan.calledsubscriberheld; |
| 13151 |
tmp->adsi = conf->chan.adsi; |
| 13152 |
tmp->use_smdi = conf->chan.use_smdi; |
| 13153 |
tmp->permhidecallerid = conf->chan.hidecallerid; |
| 13154 |
tmp->hidecalleridname = conf->chan.hidecalleridname; |
| 13155 |
tmp->callreturn = conf->chan.callreturn; |
| 13156 |
tmp->lastnumredial = conf->chan.lastnumredial; |
| 13157 |
tmp->echocancel = conf->chan.echocancel; |
| 13158 |
tmp->echotraining = conf->chan.echotraining; |
| 13159 |
tmp->pulse = conf->chan.pulse; |
| 13160 |
if (tmp->echocancel.head.tap_length) { |
| 13161 |
tmp->echocanbridged = conf->chan.echocanbridged; |
| 13162 |
} else { |
| 13163 |
if (conf->chan.echocanbridged) |
| 13164 |
ast_log(LOG_NOTICE, "echocancelwhenbridged requires echocancel to be enabled; ignoring\n"); |
| 13165 |
tmp->echocanbridged = 0; |
| 13166 |
} |
| 13167 |
tmp->busydetect = conf->chan.busydetect; |
| 13168 |
tmp->busycount = conf->chan.busycount; |
| 13169 |
tmp->busy_cadence = conf->chan.busy_cadence; |
| 13170 |
tmp->callprogress = conf->chan.callprogress; |
| 13171 |
tmp->waitfordialtone = conf->chan.waitfordialtone; |
| 13172 |
tmp->dialtone_detect = conf->chan.dialtone_detect; |
| 13173 |
tmp->faxdetect_timeout = conf->chan.faxdetect_timeout; |
| 13174 |
tmp->firstdigit_timeout = conf->chan.firstdigit_timeout; |
| 13175 |
tmp->interdigit_timeout = conf->chan.interdigit_timeout; |
| 13176 |
tmp->matchdigit_timeout = conf->chan.matchdigit_timeout; |
| 13177 |
tmp->cancallforward = conf->chan.cancallforward; |
| 13178 |
tmp->dtmfrelax = conf->chan.dtmfrelax; |
| 13179 |
tmp->callwaiting = tmp->permcallwaiting; |
| 13180 |
tmp->hidecallerid = tmp->permhidecallerid; |
| 13181 |
tmp->channel = channel; |
| 13182 |
tmp->stripmsd = conf->chan.stripmsd; |
| 13183 |
tmp->use_callerid = conf->chan.use_callerid; |
| 13184 |
tmp->cid_signalling = conf->chan.cid_signalling; |
| 13185 |
tmp->cid_start = conf->chan.cid_start; |
| 13186 |
tmp->dahditrcallerid = conf->chan.dahditrcallerid; |
| 13187 |
tmp->restrictcid = conf->chan.restrictcid; |
| 13188 |
tmp->use_callingpres = conf->chan.use_callingpres; |
| 13189 |
if (tmp->usedistinctiveringdetection) { |
| 13190 |
if (!tmp->use_callerid) { |
| 13191 |
ast_log(LOG_NOTICE, "Distinctive Ring detect requires 'usecallerid' be on\n"); |
| 13192 |
tmp->use_callerid = 1; |
| 13193 |
} |
| 13194 |
} |
| 13195 |
|
| 13196 |
if (tmp->cid_signalling == CID_SIG_SMDI) { |
| 13197 |
if (!tmp->use_smdi) { |
| 13198 |
ast_log(LOG_WARNING, "SMDI callerid requires SMDI to be enabled, enabling...\n"); |
| 13199 |
tmp->use_smdi = 1; |
| 13200 |
} |
| 13201 |
} |
| 13202 |
if (tmp->use_smdi) { |
| 13203 |
tmp->smdi_iface = ast_smdi_interface_find(conf->smdi_port); |
| 13204 |
if (!(tmp->smdi_iface)) { |
| 13205 |
ast_log(LOG_ERROR, "Invalid SMDI port specified, disabling SMDI support\n"); |
| 13206 |
tmp->use_smdi = 0; |
| 13207 |
} |
| 13208 |
} |
| 13209 |
|
| 13210 |
ast_copy_string(tmp->accountcode, conf->chan.accountcode, sizeof(tmp->accountcode)); |
| 13211 |
tmp->amaflags = conf->chan.amaflags; |
| 13212 |
if (!here) { |
| 13213 |
tmp->confno = -1; |
| 13214 |
tmp->propconfno = -1; |
| 13215 |
} |
| 13216 |
tmp->canpark = conf->chan.canpark; |
| 13217 |
tmp->transfer = conf->chan.transfer; |
| 13218 |
ast_copy_string(tmp->defcontext,conf->chan.context,sizeof(tmp->defcontext)); |
| 13219 |
ast_copy_string(tmp->language, conf->chan.language, sizeof(tmp->language)); |
| 13220 |
ast_copy_string(tmp->mohinterpret, conf->chan.mohinterpret, sizeof(tmp->mohinterpret)); |
| 13221 |
ast_copy_string(tmp->mohsuggest, conf->chan.mohsuggest, sizeof(tmp->mohsuggest)); |
| 13222 |
ast_copy_string(tmp->context, conf->chan.context, sizeof(tmp->context)); |
| 13223 |
ast_copy_string(tmp->description, conf->chan.description, sizeof(tmp->description)); |
| 13224 |
ast_copy_string(tmp->parkinglot, conf->chan.parkinglot, sizeof(tmp->parkinglot)); |
| 13225 |
tmp->cid_ton = 0; |
| 13226 |
if (dahdi_analog_lib_handles(tmp->sig, tmp->radio, tmp->oprmode)) { |
| 13227 |
ast_copy_string(tmp->cid_num, conf->chan.cid_num, sizeof(tmp->cid_num)); |
| 13228 |
ast_copy_string(tmp->cid_name, conf->chan.cid_name, sizeof(tmp->cid_name)); |
| 13229 |
} else { |
| 13230 |
tmp->cid_num[0] = '\0'; |
| 13231 |
tmp->cid_name[0] = '\0'; |
| 13232 |
} |
| 13233 |
#if defined(HAVE_PRI) |
| 13234 |
if (dahdi_sig_pri_lib_handles(tmp->sig)) { |
| 13235 |
tmp->cid_tag[0] = '\0'; |
| 13236 |
} else |
| 13237 |
#endif |
| 13238 |
{ |
| 13239 |
ast_copy_string(tmp->cid_tag, conf->chan.cid_tag, sizeof(tmp->cid_tag)); |
| 13240 |
} |
| 13241 |
tmp->cid_subaddr[0] = '\0'; |
| 13242 |
ast_copy_string(tmp->mailbox, conf->chan.mailbox, sizeof(tmp->mailbox)); |
| 13243 |
if (channel != CHAN_PSEUDO && !ast_strlen_zero(tmp->mailbox)) { |
| 13244 |
|
| 13245 |
|
| 13246 |
|
| 13247 |
|
| 13248 |
tmp->mwi_event_sub = ast_mwi_subscribe_pool(tmp->mailbox, stasis_subscription_cb_noop, NULL); |
| 13249 |
} |
| 13250 |
#ifdef HAVE_DAHDI_LINEREVERSE_VMWI |
| 13251 |
tmp->mwisend_setting = conf->chan.mwisend_setting; |
| 13252 |
tmp->mwisend_fsk = conf->chan.mwisend_fsk; |
| 13253 |
tmp->mwisend_rpas = conf->chan.mwisend_rpas; |
| 13254 |
#endif |
| 13255 |
|
| 13256 |
tmp->group = conf->chan.group; |
| 13257 |
tmp->callgroup = conf->chan.callgroup; |
| 13258 |
tmp->pickupgroup= conf->chan.pickupgroup; |
| 13259 |
ast_unref_namedgroups(tmp->named_callgroups); |
| 13260 |
tmp->named_callgroups = ast_ref_namedgroups(conf->chan.named_callgroups); |
| 13261 |
ast_unref_namedgroups(tmp->named_pickupgroups); |
| 13262 |
tmp->named_pickupgroups = ast_ref_namedgroups(conf->chan.named_pickupgroups); |
| 13263 |
if (conf->chan.vars) { |
| 13264 |
struct ast_variable *v, *tmpvar; |
| 13265 |
for (v = conf->chan.vars ; v ; v = v->next) { |
| 13266 |
if ((tmpvar = ast_variable_new(v->name, v->value, v->file))) { |
| 13267 |
if (ast_variable_list_replace(&tmp->vars, tmpvar)) { |
| 13268 |
tmpvar->next = tmp->vars; |
| 13269 |
tmp->vars = tmpvar; |
| 13270 |
} |
| 13271 |
} |
| 13272 |
} |
| 13273 |
} |
| 13274 |
tmp->hwrxgain_enabled = conf->chan.hwrxgain_enabled; |
| 13275 |
tmp->hwtxgain_enabled = conf->chan.hwtxgain_enabled; |
| 13276 |
tmp->hwrxgain = conf->chan.hwrxgain; |
| 13277 |
tmp->hwtxgain = conf->chan.hwtxgain; |
| 13278 |
tmp->cid_rxgain = conf->chan.cid_rxgain; |
| 13279 |
tmp->rxgain = conf->chan.rxgain; |
| 13280 |
tmp->txgain = conf->chan.txgain; |
| 13281 |
tmp->txdrc = conf->chan.txdrc; |
| 13282 |
tmp->rxdrc = conf->chan.rxdrc; |
| 13283 |
tmp->tonezone = conf->chan.tonezone; |
| 13284 |
if (tmp->subs[SUB_REAL].dfd > -1) { |
| 13285 |
if (tmp->hwrxgain_enabled) { |
| 13286 |
tmp->hwrxgain_enabled = !set_hwgain(tmp->subs[SUB_REAL].dfd, tmp->hwrxgain, 0); |
| 13287 |
} |
| 13288 |
if (tmp->hwtxgain_enabled) { |
| 13289 |
tmp->hwtxgain_enabled = !set_hwgain(tmp->subs[SUB_REAL].dfd, tmp->hwtxgain, 1); |
| 13290 |
} |
| 13291 |
set_actual_gain(tmp->subs[SUB_REAL].dfd, tmp->rxgain, tmp->txgain, tmp->rxdrc, tmp->txdrc, tmp->law); |
| 13292 |
if (tmp->dsp) |
| 13293 |
ast_dsp_set_digitmode(tmp->dsp, DSP_DIGITMODE_DTMF | tmp->dtmfrelax); |
| 13294 |
dahdi_conf_update(tmp); |
| 13295 |
if (!here) { |
| 13296 |
switch (chan_sig) { |
| 13297 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 13298 |
case SIG_SS7: |
| 13299 |
case SIG_MFCR2: |
| 13300 |
break; |
| 13301 |
default: |
| 13302 |
|
| 13303 |
dahdi_set_hook(tmp->subs[SUB_REAL].dfd, DAHDI_ONHOOK); |
| 13304 |
break; |
| 13305 |
} |
| 13306 |
} |
| 13307 |
ioctl(tmp->subs[SUB_REAL].dfd,DAHDI_SETTONEZONE,&tmp->tonezone); |
| 13308 |
if ((res = get_alarms(tmp)) != DAHDI_ALARM_NONE) { |
| 13309 |
|
| 13310 |
switch (tmp->sig) { |
| 13311 |
#ifdef HAVE_PRI |
| 13312 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 13313 |
sig_pri_set_alarm(tmp->sig_pvt, 1); |
| 13314 |
break; |
| 13315 |
#endif |
| 13316 |
#if defined(HAVE_SS7) |
| 13317 |
case SIG_SS7: |
| 13318 |
sig_ss7_set_alarm(tmp->sig_pvt, 1); |
| 13319 |
break; |
| 13320 |
#endif |
| 13321 |
default: |
| 13322 |
|
| 13323 |
analog_p = tmp->sig_pvt; |
| 13324 |
if (analog_p) { |
| 13325 |
analog_p->inalarm = 1; |
| 13326 |
} |
| 13327 |
tmp->inalarm = 1; |
| 13328 |
break; |
| 13329 |
} |
| 13330 |
handle_alarms(tmp, res); |
| 13331 |
} |
| 13332 |
} |
| 13333 |
|
| 13334 |
tmp->polarityonanswerdelay = conf->chan.polarityonanswerdelay; |
| 13335 |
tmp->answeronpolarityswitch = conf->chan.answeronpolarityswitch; |
| 13336 |
tmp->ani_info_digits = conf->chan.ani_info_digits; |
| 13337 |
tmp->ani_wink_time = conf->chan.ani_wink_time; |
| 13338 |
tmp->ani_timeout = conf->chan.ani_timeout; |
| 13339 |
tmp->hanguponpolarityswitch = conf->chan.hanguponpolarityswitch; |
| 13340 |
tmp->reoriginate = conf->chan.reoriginate; |
| 13341 |
tmp->sendcalleridafter = conf->chan.sendcalleridafter; |
| 13342 |
ast_cc_copy_config_params(tmp->cc_params, conf->chan.cc_params); |
| 13343 |
|
| 13344 |
if (!here) { |
| 13345 |
tmp->locallyblocked = 0; |
| 13346 |
tmp->remotelyblocked = 0; |
| 13347 |
switch (tmp->sig) { |
| 13348 |
#if defined(HAVE_PRI) |
| 13349 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 13350 |
tmp->inservice = 1; |
| 13351 |
#if defined(HAVE_PRI_SERVICE_MESSAGES) |
| 13352 |
((struct sig_pri_chan *) tmp->sig_pvt)->service_status = 0; |
| 13353 |
if (chan_sig == SIG_PRI) { |
| 13354 |
char db_chan_name[20]; |
| 13355 |
char db_answer[5]; |
| 13356 |
|
| 13357 |
|
| 13358 |
|
| 13359 |
|
| 13360 |
|
| 13361 |
snprintf(db_chan_name, sizeof(db_chan_name), "%s/%d:%d", dahdi_db, tmp->span, tmp->channel); |
| 13362 |
if (!ast_db_get(db_chan_name, SRVST_DBKEY, db_answer, sizeof(db_answer))) { |
| 13363 |
unsigned *why; |
| 13364 |
|
| 13365 |
why = &((struct sig_pri_chan *) tmp->sig_pvt)->service_status; |
| 13366 |
if (tmp->pri->enable_service_message_support) { |
| 13367 |
char state; |
| 13368 |
|
| 13369 |
sscanf(db_answer, "%1c:%30u", &state, why); |
| 13370 |
|
| 13371 |
|
| 13372 |
*why &= (SRVST_NEAREND | SRVST_FAREND); |
| 13373 |
} |
| 13374 |
if (!*why) { |
| 13375 |
ast_db_del(db_chan_name, SRVST_DBKEY); |
| 13376 |
} |
| 13377 |
} |
| 13378 |
} |
| 13379 |
#endif |
| 13380 |
break; |
| 13381 |
#endif |
| 13382 |
#if defined(HAVE_SS7) |
| 13383 |
case SIG_SS7: |
| 13384 |
tmp->inservice = 0; |
| 13385 |
if (tmp->ss7->flags & LINKSET_FLAG_INITIALHWBLO) { |
| 13386 |
tmp->remotelyblocked |= SS7_BLOCKED_HARDWARE; |
| 13387 |
} |
| 13388 |
break; |
| 13389 |
#endif |
| 13390 |
default: |
| 13391 |
|
| 13392 |
tmp->inservice = 1; |
| 13393 |
break; |
| 13394 |
} |
| 13395 |
} |
| 13396 |
|
| 13397 |
switch (tmp->sig) { |
| 13398 |
#if defined(HAVE_PRI) |
| 13399 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 13400 |
if (pri_chan) { |
| 13401 |
pri_chan->channel = tmp->channel; |
| 13402 |
pri_chan->hidecallerid = tmp->hidecallerid; |
| 13403 |
pri_chan->hidecalleridname = tmp->hidecalleridname; |
| 13404 |
pri_chan->immediate = tmp->immediate; |
| 13405 |
pri_chan->inalarm = tmp->inalarm; |
| 13406 |
pri_chan->priexclusive = tmp->priexclusive; |
| 13407 |
pri_chan->priindication_oob = tmp->priindication_oob; |
| 13408 |
pri_chan->use_callerid = tmp->use_callerid; |
| 13409 |
pri_chan->use_callingpres = tmp->use_callingpres; |
| 13410 |
ast_copy_string(pri_chan->context, tmp->context, |
| 13411 |
sizeof(pri_chan->context)); |
| 13412 |
ast_copy_string(pri_chan->mohinterpret, tmp->mohinterpret, |
| 13413 |
sizeof(pri_chan->mohinterpret)); |
| 13414 |
pri_chan->stripmsd = tmp->stripmsd; |
| 13415 |
} |
| 13416 |
break; |
| 13417 |
#endif |
| 13418 |
#if defined(HAVE_SS7) |
| 13419 |
case SIG_SS7: |
| 13420 |
if (ss7_chan) { |
| 13421 |
ss7_chan->inalarm = tmp->inalarm; |
| 13422 |
ss7_chan->inservice = tmp->inservice; |
| 13423 |
|
| 13424 |
ss7_chan->stripmsd = tmp->stripmsd; |
| 13425 |
ss7_chan->hidecallerid = tmp->hidecallerid; |
| 13426 |
ss7_chan->use_callerid = tmp->use_callerid; |
| 13427 |
ss7_chan->use_callingpres = tmp->use_callingpres; |
| 13428 |
ss7_chan->immediate = tmp->immediate; |
| 13429 |
ss7_chan->locallyblocked = tmp->locallyblocked; |
| 13430 |
ss7_chan->remotelyblocked = tmp->remotelyblocked; |
| 13431 |
ast_copy_string(ss7_chan->context, tmp->context, |
| 13432 |
sizeof(ss7_chan->context)); |
| 13433 |
ast_copy_string(ss7_chan->mohinterpret, tmp->mohinterpret, |
| 13434 |
sizeof(ss7_chan->mohinterpret)); |
| 13435 |
} |
| 13436 |
break; |
| 13437 |
#endif |
| 13438 |
default: |
| 13439 |
|
| 13440 |
analog_p = tmp->sig_pvt; |
| 13441 |
if (analog_p) { |
| 13442 |
analog_p->channel = tmp->channel; |
| 13443 |
analog_p->polarityonanswerdelay = conf->chan.polarityonanswerdelay; |
| 13444 |
analog_p->answeronpolarityswitch = conf->chan.answeronpolarityswitch; |
| 13445 |
analog_p->ani_info_digits = conf->chan.ani_info_digits; |
| 13446 |
analog_p->ani_timeout = conf->chan.ani_timeout; |
| 13447 |
analog_p->ani_wink_time = conf->chan.ani_wink_time; |
| 13448 |
analog_p->hanguponpolarityswitch = conf->chan.hanguponpolarityswitch; |
| 13449 |
analog_p->permcallwaiting = conf->chan.callwaiting; |
| 13450 |
analog_p->calledsubscriberheld = conf->chan.calledsubscriberheld; |
| 13451 |
analog_p->callreturn = conf->chan.callreturn; |
| 13452 |
analog_p->lastnumredial = conf->chan.lastnumredial; |
| 13453 |
analog_p->cancallforward = conf->chan.cancallforward; |
| 13454 |
analog_p->canpark = conf->chan.canpark; |
| 13455 |
analog_p->dahditrcallerid = conf->chan.dahditrcallerid; |
| 13456 |
analog_p->immediate = conf->chan.immediate; |
| 13457 |
analog_p->immediatering = conf->chan.immediatering; |
| 13458 |
analog_p->permhidecallerid = conf->chan.hidecallerid; |
| 13459 |
|
| 13460 |
analog_p->pulse = conf->chan.pulse; |
| 13461 |
analog_p->threewaycalling = conf->chan.threewaycalling; |
| 13462 |
analog_p->transfer = conf->chan.transfer; |
| 13463 |
analog_p->transfertobusy = conf->chan.transfertobusy; |
| 13464 |
analog_p->permdialmode = conf->chan.permdialmode; |
| 13465 |
analog_p->use_callerid = tmp->use_callerid; |
| 13466 |
analog_p->usedistinctiveringdetection = tmp->usedistinctiveringdetection; |
| 13467 |
analog_p->use_smdi = tmp->use_smdi; |
| 13468 |
analog_p->smdi_iface = tmp->smdi_iface; |
| 13469 |
analog_p->outsigmod = ANALOG_SIG_NONE; |
| 13470 |
analog_p->echotraining = conf->chan.echotraining; |
| 13471 |
analog_p->cid_signalling = conf->chan.cid_signalling; |
| 13472 |
analog_p->stripmsd = conf->chan.stripmsd; |
| 13473 |
switch (conf->chan.cid_start) { |
| 13474 |
case CID_START_POLARITY: |
| 13475 |
analog_p->cid_start = ANALOG_CID_START_POLARITY; |
| 13476 |
break; |
| 13477 |
case CID_START_POLARITY_IN: |
| 13478 |
analog_p->cid_start = ANALOG_CID_START_POLARITY_IN; |
| 13479 |
break; |
| 13480 |
case CID_START_DTMF_NOALERT: |
| 13481 |
analog_p->cid_start = ANALOG_CID_START_DTMF_NOALERT; |
| 13482 |
break; |
| 13483 |
default: |
| 13484 |
analog_p->cid_start = ANALOG_CID_START_RING; |
| 13485 |
break; |
| 13486 |
} |
| 13487 |
analog_p->callwaitingcallerid = conf->chan.callwaitingcallerid; |
| 13488 |
analog_p->callwaitingdeluxe = conf->chan.callwaitingdeluxe; |
| 13489 |
analog_p->ringt = conf->chan.ringt; |
| 13490 |
analog_p->ringt_base = ringt_base; |
| 13491 |
analog_p->onhooktime = time(NULL); |
| 13492 |
if (chan_sig & __DAHDI_SIG_FXO) { |
| 13493 |
memset(&p, 0, sizeof(p)); |
| 13494 |
res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &p); |
| 13495 |
if (!res) { |
| 13496 |
analog_p->fxsoffhookstate = p.rxisoffhook; |
| 13497 |
} |
| 13498 |
#ifdef HAVE_DAHDI_LINEREVERSE_VMWI |
| 13499 |
res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_VMWI_CONFIG, &tmp->mwisend_setting); |
| 13500 |
#endif |
| 13501 |
} |
| 13502 |
analog_p->msgstate = -1; |
| 13503 |
|
| 13504 |
ast_copy_string(analog_p->mohsuggest, conf->chan.mohsuggest, sizeof(analog_p->mohsuggest)); |
| 13505 |
ast_copy_string(analog_p->cid_num, conf->chan.cid_num, sizeof(analog_p->cid_num)); |
| 13506 |
ast_copy_string(analog_p->cid_name, conf->chan.cid_name, sizeof(analog_p->cid_name)); |
| 13507 |
|
| 13508 |
analog_config_complete(analog_p); |
| 13509 |
} |
| 13510 |
break; |
| 13511 |
} |
| 13512 |
#if defined(HAVE_PRI) |
| 13513 |
if (tmp->channel == CHAN_PSEUDO) { |
| 13514 |
|
| 13515 |
|
| 13516 |
|
| 13517 |
|
| 13518 |
dahdi_pseudo_parms.buf_no = tmp->buf_no; |
| 13519 |
dahdi_pseudo_parms.buf_policy = tmp->buf_policy; |
| 13520 |
dahdi_pseudo_parms.faxbuf_no = tmp->faxbuf_no; |
| 13521 |
dahdi_pseudo_parms.faxbuf_policy = tmp->faxbuf_policy; |
| 13522 |
} |
| 13523 |
#endif |
| 13524 |
} |
| 13525 |
if (tmp && !here) { |
| 13526 |
|
| 13527 |
dahdi_iflist_insert(tmp); |
| 13528 |
} |
| 13529 |
return tmp; |
| 13530 |
} |
| 13531 |
|
| 13532 |
static int is_group_or_channel_match(struct dahdi_pvt *p, int span, ast_group_t groupmatch, int *groupmatched, int channelmatch, int *channelmatched) |
| 13533 |
{ |
| 13534 |
#if defined(HAVE_PRI) |
| 13535 |
if (0 < span) { |
| 13536 |
|
| 13537 |
if (!p->pri || p->pri->span != span) { |
| 13538 |
return 0; |
| 13539 |
} |
| 13540 |
if (!groupmatch && channelmatch == -1) { |
| 13541 |
|
| 13542 |
*groupmatched = 1; |
| 13543 |
return 1; |
| 13544 |
} |
| 13545 |
} |
| 13546 |
#endif |
| 13547 |
|
| 13548 |
if (groupmatch) { |
| 13549 |
if ((p->group & groupmatch) != groupmatch) |
| 13550 |
|
| 13551 |
return 0; |
| 13552 |
*groupmatched = 1; |
| 13553 |
} |
| 13554 |
|
| 13555 |
if (channelmatch != -1) { |
| 13556 |
if (p->channel != channelmatch) |
| 13557 |
|
| 13558 |
return 0; |
| 13559 |
*channelmatched = 1; |
| 13560 |
} |
| 13561 |
|
| 13562 |
return 1; |
| 13563 |
} |
| 13564 |
|
| 13565 |
static int available(struct dahdi_pvt **pvt, int is_specific_channel) |
| 13566 |
{ |
| 13567 |
struct dahdi_pvt *p = *pvt; |
| 13568 |
|
| 13569 |
if (p->inalarm) |
| 13570 |
return 0; |
| 13571 |
|
| 13572 |
if (dahdi_analog_lib_handles(p->sig, p->radio, p->oprmode)) |
| 13573 |
return analog_available(p->sig_pvt); |
| 13574 |
|
| 13575 |
switch (p->sig) { |
| 13576 |
#if defined(HAVE_PRI) |
| 13577 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 13578 |
{ |
| 13579 |
struct sig_pri_chan *pvt_chan; |
| 13580 |
int res; |
| 13581 |
|
| 13582 |
pvt_chan = p->sig_pvt; |
| 13583 |
res = sig_pri_available(&pvt_chan, is_specific_channel); |
| 13584 |
*pvt = pvt_chan->chan_pvt; |
| 13585 |
return res; |
| 13586 |
} |
| 13587 |
#endif |
| 13588 |
#if defined(HAVE_SS7) |
| 13589 |
case SIG_SS7: |
| 13590 |
return sig_ss7_available(p->sig_pvt); |
| 13591 |
#endif |
| 13592 |
default: |
| 13593 |
break; |
| 13594 |
} |
| 13595 |
|
| 13596 |
if (p->locallyblocked || p->remotelyblocked) { |
| 13597 |
return 0; |
| 13598 |
} |
| 13599 |
|
| 13600 |
|
| 13601 |
if (!p->owner) { |
| 13602 |
#ifdef HAVE_OPENR2 |
| 13603 |
|
| 13604 |
if (p->mfcr2) { |
| 13605 |
if (p->mfcr2call) { |
| 13606 |
return 0; |
| 13607 |
} else { |
| 13608 |
return 1; |
| 13609 |
} |
| 13610 |
} |
| 13611 |
#endif |
| 13612 |
return 1; |
| 13613 |
} |
| 13614 |
|
| 13615 |
return 0; |
| 13616 |
} |
| 13617 |
|
| 13618 |
#if defined(HAVE_PRI) |
| 13619 |
#if defined(HAVE_PRI_CALL_WAITING) |
| 13620 |
|
| 13621 |
|
| 13622 |
|
| 13623 |
|
| 13624 |
|
| 13625 |
|
| 13626 |
|
| 13627 |
|
| 13628 |
|
| 13629 |
|
| 13630 |
static void my_pri_init_config(void *priv, struct sig_pri_span *pri) |
| 13631 |
{ |
| 13632 |
struct dahdi_pvt *pvt = priv; |
| 13633 |
|
| 13634 |
pvt->stripmsd = pri->ch_cfg.stripmsd; |
| 13635 |
pvt->hidecallerid = pri->ch_cfg.hidecallerid; |
| 13636 |
pvt->hidecalleridname = pri->ch_cfg.hidecalleridname; |
| 13637 |
pvt->immediate = pri->ch_cfg.immediate; |
| 13638 |
pvt->priexclusive = pri->ch_cfg.priexclusive; |
| 13639 |
pvt->priindication_oob = pri->ch_cfg.priindication_oob; |
| 13640 |
pvt->use_callerid = pri->ch_cfg.use_callerid; |
| 13641 |
pvt->use_callingpres = pri->ch_cfg.use_callingpres; |
| 13642 |
ast_copy_string(pvt->context, pri->ch_cfg.context, sizeof(pvt->context)); |
| 13643 |
ast_copy_string(pvt->mohinterpret, pri->ch_cfg.mohinterpret, sizeof(pvt->mohinterpret)); |
| 13644 |
} |
| 13645 |
#endif |
| 13646 |
#endif |
| 13647 |
|
| 13648 |
#if defined(HAVE_PRI) |
| 13649 |
|
| 13650 |
|
| 13651 |
|
| 13652 |
|
| 13653 |
|
| 13654 |
|
| 13655 |
|
| 13656 |
|
| 13657 |
|
| 13658 |
|
| 13659 |
|
| 13660 |
|
| 13661 |
static int dahdi_new_pri_nobch_channel(struct sig_pri_span *pri) |
| 13662 |
{ |
| 13663 |
int pvt_idx; |
| 13664 |
int res; |
| 13665 |
unsigned idx; |
| 13666 |
struct dahdi_pvt *pvt; |
| 13667 |
struct sig_pri_chan *chan; |
| 13668 |
struct dahdi_bufferinfo bi; |
| 13669 |
|
| 13670 |
static int nobch_channel = CHAN_PSEUDO; |
| 13671 |
|
| 13672 |
|
| 13673 |
for (pvt_idx = 0; pvt_idx < pri->numchans; ++pvt_idx) { |
| 13674 |
if (!pri->pvts[pvt_idx]) { |
| 13675 |
break; |
| 13676 |
} |
| 13677 |
} |
| 13678 |
if (pri->numchans == pvt_idx) { |
| 13679 |
if (ARRAY_LEN(pri->pvts) <= pvt_idx) { |
| 13680 |
ast_log(LOG_ERROR, "Unable to add a no-B-channel interface!\n"); |
| 13681 |
return -1; |
| 13682 |
} |
| 13683 |
|
| 13684 |
|
| 13685 |
pri->pvts[pvt_idx] = NULL; |
| 13686 |
++pri->numchans; |
| 13687 |
} |
| 13688 |
|
| 13689 |
pvt = ast_calloc(1, sizeof(*pvt)); |
| 13690 |
if (!pvt) { |
| 13691 |
return -1; |
| 13692 |
} |
| 13693 |
pvt->cc_params = ast_cc_config_params_init(); |
| 13694 |
if (!pvt->cc_params) { |
| 13695 |
ast_free(pvt); |
| 13696 |
return -1; |
| 13697 |
} |
| 13698 |
ast_mutex_init(&pvt->lock); |
| 13699 |
for (idx = 0; idx < ARRAY_LEN(pvt->subs); ++idx) { |
| 13700 |
pvt->subs[idx].dfd = -1; |
| 13701 |
} |
| 13702 |
pvt->buf_no = dahdi_pseudo_parms.buf_no; |
| 13703 |
pvt->buf_policy = dahdi_pseudo_parms.buf_policy; |
| 13704 |
pvt->faxbuf_no = dahdi_pseudo_parms.faxbuf_no; |
| 13705 |
pvt->faxbuf_policy = dahdi_pseudo_parms.faxbuf_policy; |
| 13706 |
|
| 13707 |
chan = sig_pri_chan_new(pvt, pri, 0, 0, 0); |
| 13708 |
if (!chan) { |
| 13709 |
destroy_dahdi_pvt(pvt); |
| 13710 |
return -1; |
| 13711 |
} |
| 13712 |
chan->no_b_channel = 1; |
| 13713 |
|
| 13714 |
|
| 13715 |
|
| 13716 |
|
| 13717 |
|
| 13718 |
|
| 13719 |
pvt->law_default = DAHDI_LAW_ALAW; |
| 13720 |
|
| 13721 |
pvt->sig = pri->sig; |
| 13722 |
pvt->outsigmod = -1; |
| 13723 |
pvt->pri = pri; |
| 13724 |
pvt->sig_pvt = chan; |
| 13725 |
pri->pvts[pvt_idx] = chan; |
| 13726 |
|
| 13727 |
pvt->subs[SUB_REAL].dfd = dahdi_open("/dev/dahdi/pseudo"); |
| 13728 |
if (pvt->subs[SUB_REAL].dfd < 0) { |
| 13729 |
ast_log(LOG_ERROR, "Unable to open no B channel interface pseudo channel: %s\n", |
| 13730 |
strerror(errno)); |
| 13731 |
destroy_dahdi_pvt(pvt); |
| 13732 |
return -1; |
| 13733 |
} |
| 13734 |
memset(&bi, 0, sizeof(bi)); |
| 13735 |
res = ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_GET_BUFINFO, &bi); |
| 13736 |
if (!res) { |
| 13737 |
pvt->bufsize = bi.bufsize; |
| 13738 |
bi.txbufpolicy = pvt->buf_policy; |
| 13739 |
bi.rxbufpolicy = pvt->buf_policy; |
| 13740 |
bi.numbufs = pvt->buf_no; |
| 13741 |
res = ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_SET_BUFINFO, &bi); |
| 13742 |
if (res < 0) { |
| 13743 |
ast_log(LOG_WARNING, |
| 13744 |
"Unable to set buffer policy on no B channel interface: %s\n", |
| 13745 |
strerror(errno)); |
| 13746 |
} |
| 13747 |
} else |
| 13748 |
ast_log(LOG_WARNING, |
| 13749 |
"Unable to check buffer policy on no B channel interface: %s\n", |
| 13750 |
strerror(errno)); |
| 13751 |
|
| 13752 |
--nobch_channel; |
| 13753 |
if (CHAN_PSEUDO < nobch_channel) { |
| 13754 |
nobch_channel = CHAN_PSEUDO - 1; |
| 13755 |
} |
| 13756 |
pvt->channel = nobch_channel; |
| 13757 |
pvt->span = pri->span; |
| 13758 |
chan->channel = pvt->channel; |
| 13759 |
|
| 13760 |
dahdi_nobch_insert(pri, pvt); |
| 13761 |
|
| 13762 |
return pvt_idx; |
| 13763 |
} |
| 13764 |
#endif |
| 13765 |
|
| 13766 |
|
| 13767 |
|
| 13768 |
|
| 13769 |
|
| 13770 |
|
| 13771 |
static struct dahdi_pvt *duplicate_pseudo(struct dahdi_pvt *src) |
| 13772 |
{ |
| 13773 |
struct dahdi_pvt *p; |
| 13774 |
struct dahdi_bufferinfo bi; |
| 13775 |
int res; |
| 13776 |
|
| 13777 |
p = ast_malloc(sizeof(*p)); |
| 13778 |
if (!p) { |
| 13779 |
return NULL; |
| 13780 |
} |
| 13781 |
*p = *src; |
| 13782 |
|
| 13783 |
|
| 13784 |
p->cc_params = ast_cc_config_params_init(); |
| 13785 |
if (!p->cc_params) { |
| 13786 |
ast_free(p); |
| 13787 |
return NULL; |
| 13788 |
} |
| 13789 |
ast_cc_copy_config_params(p->cc_params, src->cc_params); |
| 13790 |
|
| 13791 |
p->which_iflist = DAHDI_IFLIST_NONE; |
| 13792 |
p->next = NULL; |
| 13793 |
p->prev = NULL; |
| 13794 |
ast_mutex_init(&p->lock); |
| 13795 |
p->subs[SUB_REAL].dfd = dahdi_open("/dev/dahdi/pseudo"); |
| 13796 |
if (p->subs[SUB_REAL].dfd < 0) { |
| 13797 |
ast_log(LOG_ERROR, "Unable to dup channel: %s\n", strerror(errno)); |
| 13798 |
destroy_dahdi_pvt(p); |
| 13799 |
return NULL; |
| 13800 |
} |
| 13801 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_BUFINFO, &bi); |
| 13802 |
if (!res) { |
| 13803 |
bi.txbufpolicy = src->buf_policy; |
| 13804 |
bi.rxbufpolicy = src->buf_policy; |
| 13805 |
bi.numbufs = src->buf_no; |
| 13806 |
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SET_BUFINFO, &bi); |
| 13807 |
if (res < 0) { |
| 13808 |
ast_log(LOG_WARNING, "Unable to set buffer policy on dup channel: %s\n", strerror(errno)); |
| 13809 |
} |
| 13810 |
} else |
| 13811 |
ast_log(LOG_WARNING, "Unable to check buffer policy on dup channel: %s\n", strerror(errno)); |
| 13812 |
p->destroy = 1; |
| 13813 |
dahdi_iflist_insert(p); |
| 13814 |
return p; |
| 13815 |
} |
| 13816 |
|
| 13817 |
struct dahdi_starting_point { |
| 13818 |
|
| 13819 |
ast_group_t groupmatch; |
| 13820 |
|
| 13821 |
int channelmatch; |
| 13822 |
|
| 13823 |
int rr_starting_point; |
| 13824 |
|
| 13825 |
int span; |
| 13826 |
|
| 13827 |
int cadence; |
| 13828 |
|
| 13829 |
char opt; |
| 13830 |
|
| 13831 |
char backwards; |
| 13832 |
|
| 13833 |
char roundrobin; |
| 13834 |
}; |
| 13835 |
static struct dahdi_pvt *determine_starting_point(const char *data, struct dahdi_starting_point *param) |
| 13836 |
{ |
| 13837 |
char *dest; |
| 13838 |
char *s; |
| 13839 |
int x; |
| 13840 |
int res = 0; |
| 13841 |
struct dahdi_pvt *p; |
| 13842 |
char *subdir = NULL; |
| 13843 |
AST_DECLARE_APP_ARGS(args, |
| 13844 |
AST_APP_ARG(group); |
| 13845 |
|
| 13846 |
|
| 13847 |
AST_APP_ARG(other); |
| 13848 |
); |
| 13849 |
|
| 13850 |
|
| 13851 |
|
| 13852 |
|
| 13853 |
|
| 13854 |
|
| 13855 |
|
| 13856 |
|
| 13857 |
|
| 13858 |
|
| 13859 |
|
| 13860 |
|
| 13861 |
|
| 13862 |
|
| 13863 |
|
| 13864 |
|
| 13865 |
|
| 13866 |
|
| 13867 |
|
| 13868 |
|
| 13869 |
|
| 13870 |
|
| 13871 |
|
| 13872 |
|
| 13873 |
if (data) { |
| 13874 |
dest = ast_strdupa(data); |
| 13875 |
} else { |
| 13876 |
ast_log(LOG_WARNING, "Channel requested with no data\n"); |
| 13877 |
return NULL; |
| 13878 |
} |
| 13879 |
AST_NONSTANDARD_APP_ARGS(args, dest, '/'); |
| 13880 |
if (!args.argc || ast_strlen_zero(args.group)) { |
| 13881 |
ast_log(LOG_WARNING, "No channel/group specified\n"); |
| 13882 |
return NULL; |
| 13883 |
} |
| 13884 |
|
| 13885 |
|
| 13886 |
memset(param, 0, sizeof(*param)); |
| 13887 |
param->channelmatch = -1; |
| 13888 |
|
| 13889 |
if (strchr(args.group, '!') != NULL) { |
| 13890 |
char *prev = args.group; |
| 13891 |
while ((s = strchr(prev, '!')) != NULL) { |
| 13892 |
*s++ = '/'; |
| 13893 |
prev = s; |
| 13894 |
} |
| 13895 |
*(prev - 1) = '\0'; |
| 13896 |
subdir = args.group; |
| 13897 |
args.group = prev; |
| 13898 |
} else if (args.group[0] == 'i') { |
| 13899 |
|
| 13900 |
res = sscanf(args.group + 1, "%30d", &x); |
| 13901 |
if (res < 1) { |
| 13902 |
ast_log(LOG_WARNING, "Unable to determine ISDN span for data %s\n", data); |
| 13903 |
return NULL; |
| 13904 |
} |
| 13905 |
param->span = x; |
| 13906 |
|
| 13907 |
|
| 13908 |
s = strchr(args.group, '-'); |
| 13909 |
if (!s) { |
| 13910 |
|
| 13911 |
return iflist; |
| 13912 |
} |
| 13913 |
args.group = s + 1; |
| 13914 |
res = 0; |
| 13915 |
} |
| 13916 |
if (toupper(args.group[0]) == 'G' || toupper(args.group[0])=='R') { |
| 13917 |
|
| 13918 |
s = args.group + 1; |
| 13919 |
res = sscanf(s, "%30d%1c%30d", &x, ¶m->opt, ¶m->cadence); |
| 13920 |
if (res < 1) { |
| 13921 |
ast_log(LOG_WARNING, "Unable to determine group for data %s\n", data); |
| 13922 |
return NULL; |
| 13923 |
} |
| 13924 |
param->groupmatch = ((ast_group_t) 1 << x); |
| 13925 |
|
| 13926 |
if (toupper(args.group[0]) == 'G') { |
| 13927 |
if (args.group[0] == 'G') { |
| 13928 |
param->backwards = 1; |
| 13929 |
p = ifend; |
| 13930 |
} else |
| 13931 |
p = iflist; |
| 13932 |
} else { |
| 13933 |
if (ARRAY_LEN(round_robin) <= x) { |
| 13934 |
ast_log(LOG_WARNING, "Round robin index %d out of range for data %s\n", |
| 13935 |
x, data); |
| 13936 |
return NULL; |
| 13937 |
} |
| 13938 |
if (args.group[0] == 'R') { |
| 13939 |
param->backwards = 1; |
| 13940 |
p = round_robin[x] ? round_robin[x]->prev : ifend; |
| 13941 |
if (!p) |
| 13942 |
p = ifend; |
| 13943 |
} else { |
| 13944 |
p = round_robin[x] ? round_robin[x]->next : iflist; |
| 13945 |
if (!p) |
| 13946 |
p = iflist; |
| 13947 |
} |
| 13948 |
param->roundrobin = 1; |
| 13949 |
param->rr_starting_point = x; |
| 13950 |
} |
| 13951 |
} else { |
| 13952 |
s = args.group; |
| 13953 |
if (!strcasecmp(s, "pseudo")) { |
| 13954 |
|
| 13955 |
x = CHAN_PSEUDO; |
| 13956 |
param->channelmatch = x; |
| 13957 |
} else { |
| 13958 |
res = sscanf(s, "%30d%1c%30d", &x, ¶m->opt, ¶m->cadence); |
| 13959 |
if (res < 1) { |
| 13960 |
ast_log(LOG_WARNING, "Unable to determine channel for data %s\n", data); |
| 13961 |
return NULL; |
| 13962 |
} else { |
| 13963 |
param->channelmatch = x; |
| 13964 |
} |
| 13965 |
} |
| 13966 |
if (subdir) { |
| 13967 |
char path[PATH_MAX]; |
| 13968 |
struct stat stbuf; |
| 13969 |
|
| 13970 |
snprintf(path, sizeof(path), "/dev/dahdi/%s/%d", |
| 13971 |
subdir, param->channelmatch); |
| 13972 |
if (stat(path, &stbuf) < 0) { |
| 13973 |
ast_log(LOG_WARNING, "stat(%s) failed: %s\n", |
| 13974 |
path, strerror(errno)); |
| 13975 |
return NULL; |
| 13976 |
} |
| 13977 |
if (!S_ISCHR(stbuf.st_mode)) { |
| 13978 |
ast_log(LOG_ERROR, "%s: Not a character device file\n", |
| 13979 |
path); |
| 13980 |
return NULL; |
| 13981 |
} |
| 13982 |
param->channelmatch = minor(stbuf.st_rdev); |
| 13983 |
} |
| 13984 |
|
| 13985 |
p = iflist; |
| 13986 |
} |
| 13987 |
|
| 13988 |
if (param->opt == 'r' && res < 3) { |
| 13989 |
ast_log(LOG_WARNING, "Distinctive ring missing identifier in '%s'\n", data); |
| 13990 |
param->opt = '\0'; |
| 13991 |
} |
| 13992 |
|
| 13993 |
return p; |
| 13994 |
} |
| 13995 |
|
| 13996 |
static struct ast_channel *dahdi_request(const char *type, struct ast_format_cap *cap, |
| 13997 |
const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, |
| 13998 |
const char *data, int *cause) |
| 13999 |
{ |
| 14000 |
int callwait = 0; |
| 14001 |
struct dahdi_pvt *p; |
| 14002 |
struct ast_channel *tmp = NULL; |
| 14003 |
struct dahdi_pvt *exitpvt; |
| 14004 |
int channelmatched = 0; |
| 14005 |
int foundowner = 0; |
| 14006 |
int groupmatched = 0; |
| 14007 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 14008 |
int transcapdigital = 0; |
| 14009 |
#endif |
| 14010 |
struct dahdi_starting_point start; |
| 14011 |
ast_callid callid = 0; |
| 14012 |
int callid_created = ast_callid_threadstorage_auto(&callid); |
| 14013 |
|
| 14014 |
ast_mutex_lock(&iflock); |
| 14015 |
p = determine_starting_point(data, &start); |
| 14016 |
if (!p) { |
| 14017 |
|
| 14018 |
ast_mutex_unlock(&iflock); |
| 14019 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 14020 |
return NULL; |
| 14021 |
} |
| 14022 |
|
| 14023 |
|
| 14024 |
exitpvt = p; |
| 14025 |
while (p && !tmp) { |
| 14026 |
if (start.roundrobin) |
| 14027 |
round_robin[start.rr_starting_point] = p; |
| 14028 |
|
| 14029 |
if (p->owner) { |
| 14030 |
foundowner++; |
| 14031 |
} |
| 14032 |
|
| 14033 |
if (is_group_or_channel_match(p, start.span, start.groupmatch, &groupmatched, start.channelmatch, &channelmatched) |
| 14034 |
&& available(&p, channelmatched)) { |
| 14035 |
ast_debug(1, "Using channel %d\n", p->channel); |
| 14036 |
|
| 14037 |
callwait = (p->owner != NULL); |
| 14038 |
#ifdef HAVE_OPENR2 |
| 14039 |
if (p->mfcr2) { |
| 14040 |
ast_mutex_lock(&p->lock); |
| 14041 |
if (p->mfcr2call) { |
| 14042 |
ast_mutex_unlock(&p->lock); |
| 14043 |
ast_debug(1, "Yay!, someone just beat us in the race for channel %d.\n", p->channel); |
| 14044 |
goto next; |
| 14045 |
} |
| 14046 |
p->mfcr2call = 1; |
| 14047 |
ast_mutex_unlock(&p->lock); |
| 14048 |
} |
| 14049 |
#endif |
| 14050 |
if (p->channel == CHAN_PSEUDO) { |
| 14051 |
p = duplicate_pseudo(p); |
| 14052 |
if (!p) { |
| 14053 |
break; |
| 14054 |
} |
| 14055 |
} |
| 14056 |
|
| 14057 |
p->distinctivering = 0; |
| 14058 |
|
| 14059 |
switch (start.opt) { |
| 14060 |
case '\0': |
| 14061 |
|
| 14062 |
break; |
| 14063 |
case 'c': |
| 14064 |
|
| 14065 |
p->confirmanswer = 1; |
| 14066 |
break; |
| 14067 |
case 'r': |
| 14068 |
|
| 14069 |
p->distinctivering = start.cadence; |
| 14070 |
break; |
| 14071 |
case 'd': |
| 14072 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 14073 |
|
| 14074 |
transcapdigital = AST_TRANS_CAP_DIGITAL; |
| 14075 |
#endif |
| 14076 |
break; |
| 14077 |
default: |
| 14078 |
ast_log(LOG_WARNING, "Unknown option '%c' in '%s'\n", start.opt, data); |
| 14079 |
break; |
| 14080 |
} |
| 14081 |
|
| 14082 |
p->outgoing = 1; |
| 14083 |
if (dahdi_analog_lib_handles(p->sig, p->radio, p->oprmode)) { |
| 14084 |
tmp = analog_request(p->sig_pvt, &callwait, requestor); |
| 14085 |
#ifdef HAVE_PRI |
| 14086 |
} else if (dahdi_sig_pri_lib_handles(p->sig)) { |
| 14087 |
|
| 14088 |
|
| 14089 |
|
| 14090 |
|
| 14091 |
|
| 14092 |
ast_mutex_lock(&p->lock); |
| 14093 |
ast_mutex_unlock(&p->lock); |
| 14094 |
|
| 14095 |
sig_pri_extract_called_num_subaddr(p->sig_pvt, data, p->dnid, |
| 14096 |
sizeof(p->dnid)); |
| 14097 |
tmp = sig_pri_request(p->sig_pvt, SIG_PRI_DEFLAW, assignedids, requestor, transcapdigital); |
| 14098 |
#endif |
| 14099 |
#if defined(HAVE_SS7) |
| 14100 |
} else if (p->sig == SIG_SS7) { |
| 14101 |
tmp = sig_ss7_request(p->sig_pvt, SIG_SS7_DEFLAW, assignedids, requestor, transcapdigital); |
| 14102 |
#endif |
| 14103 |
} else { |
| 14104 |
tmp = dahdi_new(p, AST_STATE_RESERVED, 0, p->owner ? SUB_CALLWAIT : SUB_REAL, 0, assignedids, requestor, callid); |
| 14105 |
} |
| 14106 |
if (!tmp) { |
| 14107 |
p->outgoing = 0; |
| 14108 |
#if defined(HAVE_PRI) |
| 14109 |
switch (p->sig) { |
| 14110 |
case SIG_PRI_LIB_HANDLE_CASES: |
| 14111 |
#if defined(HAVE_PRI_CALL_WAITING) |
| 14112 |
if (((struct sig_pri_chan *) p->sig_pvt)->is_call_waiting) { |
| 14113 |
((struct sig_pri_chan *) p->sig_pvt)->is_call_waiting = 0; |
| 14114 |
ast_atomic_fetchadd_int(&p->pri->num_call_waiting_calls, -1); |
| 14115 |
} |
| 14116 |
#endif |
| 14117 |
|
| 14118 |
|
| 14119 |
|
| 14120 |
|
| 14121 |
((struct sig_pri_chan *) p->sig_pvt)->allocated = 0; |
| 14122 |
break; |
| 14123 |
default: |
| 14124 |
break; |
| 14125 |
} |
| 14126 |
#endif |
| 14127 |
} else { |
| 14128 |
snprintf(p->dialstring, sizeof(p->dialstring), "DAHDI/%s", data); |
| 14129 |
} |
| 14130 |
break; |
| 14131 |
} |
| 14132 |
#ifdef HAVE_OPENR2 |
| 14133 |
next: |
| 14134 |
#endif |
| 14135 |
if (start.backwards) { |
| 14136 |
p = p->prev; |
| 14137 |
if (!p) |
| 14138 |
p = ifend; |
| 14139 |
} else { |
| 14140 |
p = p->next; |
| 14141 |
if (!p) |
| 14142 |
p = iflist; |
| 14143 |
} |
| 14144 |
|
| 14145 |
if (p == exitpvt) |
| 14146 |
break; |
| 14147 |
} |
| 14148 |
ast_mutex_unlock(&iflock); |
| 14149 |
restart_monitor(); |
| 14150 |
if (cause && !tmp) { |
| 14151 |
if (callwait || (channelmatched && foundowner)) { |
| 14152 |
*cause = AST_CAUSE_BUSY; |
| 14153 |
} else if (groupmatched) { |
| 14154 |
*cause = AST_CAUSE_CONGESTION; |
| 14155 |
} else { |
| 14156 |
|
| 14157 |
|
| 14158 |
|
| 14159 |
|
| 14160 |
} |
| 14161 |
} |
| 14162 |
|
| 14163 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 14164 |
return tmp; |
| 14165 |
} |
| 14166 |
|
| 14167 |
|
| 14168 |
|
| 14169 |
|
| 14170 |
|
| 14171 |
|
| 14172 |
|
| 14173 |
|
| 14174 |
|
| 14175 |
|
| 14176 |
|
| 14177 |
static int dahdi_devicestate(const char *data) |
| 14178 |
{ |
| 14179 |
#if defined(HAVE_PRI) |
| 14180 |
const char *device; |
| 14181 |
unsigned span; |
| 14182 |
int res; |
| 14183 |
|
| 14184 |
device = data; |
| 14185 |
|
| 14186 |
if (*device != 'I') { |
| 14187 |
|
| 14188 |
return AST_DEVICE_UNKNOWN; |
| 14189 |
} |
| 14190 |
res = sscanf(device, "I%30u", &span); |
| 14191 |
if (res != 1 || !span || NUM_SPANS < span) { |
| 14192 |
|
| 14193 |
return AST_DEVICE_UNKNOWN; |
| 14194 |
} |
| 14195 |
device = strchr(device, '/'); |
| 14196 |
if (!device) { |
| 14197 |
|
| 14198 |
return AST_DEVICE_UNKNOWN; |
| 14199 |
} |
| 14200 |
|
| 14201 |
|
| 14202 |
|
| 14203 |
|
| 14204 |
|
| 14205 |
#if defined(THRESHOLD_DEVSTATE_PLACEHOLDER) |
| 14206 |
++device; |
| 14207 |
if (!strcmp(device, "congestion")) |
| 14208 |
#endif |
| 14209 |
{ |
| 14210 |
return pris[span - 1].pri.congestion_devstate; |
| 14211 |
} |
| 14212 |
#if defined(THRESHOLD_DEVSTATE_PLACEHOLDER) |
| 14213 |
else if (!strcmp(device, "threshold")) { |
| 14214 |
return pris[span - 1].pri.threshold_devstate; |
| 14215 |
} |
| 14216 |
return AST_DEVICE_UNKNOWN; |
| 14217 |
#endif |
| 14218 |
#else |
| 14219 |
return AST_DEVICE_UNKNOWN; |
| 14220 |
#endif |
| 14221 |
} |
| 14222 |
|
| 14223 |
|
| 14224 |
|
| 14225 |
|
| 14226 |
|
| 14227 |
|
| 14228 |
|
| 14229 |
|
| 14230 |
|
| 14231 |
|
| 14232 |
|
| 14233 |
|
| 14234 |
|
| 14235 |
|
| 14236 |
|
| 14237 |
|
| 14238 |
|
| 14239 |
static int dahdi_cc_callback(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback) |
| 14240 |
{ |
| 14241 |
struct dahdi_pvt *p; |
| 14242 |
struct dahdi_pvt *exitpvt; |
| 14243 |
struct dahdi_starting_point start; |
| 14244 |
int groupmatched = 0; |
| 14245 |
int channelmatched = 0; |
| 14246 |
|
| 14247 |
ast_mutex_lock(&iflock); |
| 14248 |
p = determine_starting_point(dest, &start); |
| 14249 |
if (!p) { |
| 14250 |
ast_mutex_unlock(&iflock); |
| 14251 |
return -1; |
| 14252 |
} |
| 14253 |
exitpvt = p; |
| 14254 |
for (;;) { |
| 14255 |
if (is_group_or_channel_match(p, start.span, start.groupmatch, &groupmatched, start.channelmatch, &channelmatched)) { |
| 14256 |
|
| 14257 |
struct ast_str *device_name; |
| 14258 |
char *dash; |
| 14259 |
const char *monitor_type; |
| 14260 |
char dialstring[AST_CHANNEL_NAME]; |
| 14261 |
char full_device_name[AST_CHANNEL_NAME]; |
| 14262 |
|
| 14263 |
switch (ast_get_cc_monitor_policy(p->cc_params)) { |
| 14264 |
case AST_CC_MONITOR_NEVER: |
| 14265 |
break; |
| 14266 |
case AST_CC_MONITOR_NATIVE: |
| 14267 |
case AST_CC_MONITOR_ALWAYS: |
| 14268 |
case AST_CC_MONITOR_GENERIC: |
| 14269 |
#if defined(HAVE_PRI) |
| 14270 |
if (dahdi_sig_pri_lib_handles(p->sig)) { |
| 14271 |
|
| 14272 |
|
| 14273 |
|
| 14274 |
|
| 14275 |
snprintf(full_device_name, sizeof(full_device_name), |
| 14276 |
"DAHDI/I%d/congestion", p->pri->span); |
| 14277 |
} else |
| 14278 |
#endif |
| 14279 |
{ |
| 14280 |
#if defined(HAVE_PRI) |
| 14281 |
device_name = create_channel_name(p, 1, ""); |
| 14282 |
#else |
| 14283 |
device_name = create_channel_name(p); |
| 14284 |
#endif |
| 14285 |
snprintf(full_device_name, sizeof(full_device_name), "DAHDI/%s", |
| 14286 |
device_name ? ast_str_buffer(device_name) : ""); |
| 14287 |
ast_free(device_name); |
| 14288 |
|
| 14289 |
|
| 14290 |
|
| 14291 |
|
| 14292 |
|
| 14293 |
dash = strrchr(full_device_name, '-'); |
| 14294 |
if (dash) { |
| 14295 |
*dash = '\0'; |
| 14296 |
} |
| 14297 |
} |
| 14298 |
snprintf(dialstring, sizeof(dialstring), "DAHDI/%s", dest); |
| 14299 |
|
| 14300 |
|
| 14301 |
|
| 14302 |
|
| 14303 |
|
| 14304 |
|
| 14305 |
|
| 14306 |
monitor_type = AST_CC_GENERIC_MONITOR_TYPE; |
| 14307 |
callback(inbound, |
| 14308 |
#if defined(HAVE_PRI) |
| 14309 |
p->pri ? p->pri->cc_params : p->cc_params, |
| 14310 |
#else |
| 14311 |
p->cc_params, |
| 14312 |
#endif |
| 14313 |
monitor_type, full_device_name, dialstring, NULL); |
| 14314 |
break; |
| 14315 |
} |
| 14316 |
} |
| 14317 |
p = start.backwards ? p->prev : p->next; |
| 14318 |
if (!p) { |
| 14319 |
p = start.backwards ? ifend : iflist; |
| 14320 |
} |
| 14321 |
if (p == exitpvt) { |
| 14322 |
break; |
| 14323 |
} |
| 14324 |
} |
| 14325 |
ast_mutex_unlock(&iflock); |
| 14326 |
return 0; |
| 14327 |
} |
| 14328 |
|
| 14329 |
#if defined(HAVE_SS7) |
| 14330 |
static void dahdi_ss7_message(struct ss7 *ss7, char *s) |
| 14331 |
{ |
| 14332 |
int i; |
| 14333 |
|
| 14334 |
if (ss7) { |
| 14335 |
for (i = 0; i < NUM_SPANS; i++) { |
| 14336 |
if (linksets[i].ss7.ss7 == ss7) { |
| 14337 |
ast_verbose_callid(0, "[%d] %s", i + 1, s); |
| 14338 |
return; |
| 14339 |
} |
| 14340 |
} |
| 14341 |
} |
| 14342 |
ast_verbose_callid(0, "%s", s); |
| 14343 |
} |
| 14344 |
#endif |
| 14345 |
|
| 14346 |
#if defined(HAVE_SS7) |
| 14347 |
static void dahdi_ss7_error(struct ss7 *ss7, char *s) |
| 14348 |
{ |
| 14349 |
int i; |
| 14350 |
|
| 14351 |
if (ss7) { |
| 14352 |
for (i = 0; i < NUM_SPANS; i++) { |
| 14353 |
if (linksets[i].ss7.ss7 == ss7) { |
| 14354 |
ast_log_callid(LOG_ERROR, 0, "[%d] %s", i + 1, s); |
| 14355 |
return; |
| 14356 |
} |
| 14357 |
} |
| 14358 |
} |
| 14359 |
ast_log_callid(LOG_ERROR, 0, "%s", s); |
| 14360 |
} |
| 14361 |
#endif |
| 14362 |
|
| 14363 |
#if defined(HAVE_OPENR2) |
| 14364 |
static void *mfcr2_monitor(void *data) |
| 14365 |
{ |
| 14366 |
struct dahdi_mfcr2 *mfcr2 = data; |
| 14367 |
struct dahdi_pvt *pvt; |
| 14368 |
|
| 14369 |
|
| 14370 |
|
| 14371 |
|
| 14372 |
|
| 14373 |
|
| 14374 |
struct pollfd pollers[ARRAY_LEN(mfcr2->pvts)]; |
| 14375 |
int res = 0; |
| 14376 |
int i = 0; |
| 14377 |
int oldstate = 0; |
| 14378 |
int quit_loop = 0; |
| 14379 |
int maxsleep = 20; |
| 14380 |
int was_idle = 0; |
| 14381 |
int pollsize = 0; |
| 14382 |
|
| 14383 |
|
| 14384 |
for (i = 0; i < mfcr2->numchans; i++) { |
| 14385 |
pvt = mfcr2->pvts[i]; |
| 14386 |
if (!pvt) { |
| 14387 |
continue; |
| 14388 |
} |
| 14389 |
openr2_chan_set_idle(pvt->r2chan); |
| 14390 |
openr2_chan_handle_cas(pvt->r2chan); |
| 14391 |
} |
| 14392 |
while (1) { |
| 14393 |
|
| 14394 |
|
| 14395 |
pollsize = 0; |
| 14396 |
for (i = 0; i < mfcr2->numchans; i++) { |
| 14397 |
pollers[i].revents = 0; |
| 14398 |
pollers[i].events = 0; |
| 14399 |
pvt = mfcr2->pvts[i]; |
| 14400 |
if (!pvt) { |
| 14401 |
continue; |
| 14402 |
} |
| 14403 |
if (pvt->owner) { |
| 14404 |
continue; |
| 14405 |
} |
| 14406 |
if (mfcr2->nodev) { |
| 14407 |
continue; |
| 14408 |
} |
| 14409 |
if (!pvt->r2chan) { |
| 14410 |
ast_debug(1, "Wow, no r2chan on channel %d\n", pvt->channel); |
| 14411 |
quit_loop = 1; |
| 14412 |
break; |
| 14413 |
} |
| 14414 |
openr2_chan_enable_read(pvt->r2chan); |
| 14415 |
pollers[i].events = POLLIN | POLLPRI; |
| 14416 |
pollers[i].fd = pvt->subs[SUB_REAL].dfd; |
| 14417 |
pollsize++; |
| 14418 |
} |
| 14419 |
if (quit_loop) { |
| 14420 |
break; |
| 14421 |
} |
| 14422 |
if (pollsize == 0) { |
| 14423 |
if (!was_idle) { |
| 14424 |
ast_debug(1, "Monitor thread going idle since everybody has an owner\n"); |
| 14425 |
was_idle = 1; |
| 14426 |
} |
| 14427 |
poll(NULL, 0, maxsleep); |
| 14428 |
continue; |
| 14429 |
} |
| 14430 |
was_idle = 0; |
| 14431 |
|
| 14432 |
|
| 14433 |
pthread_testcancel(); |
| 14434 |
res = poll(pollers, mfcr2->numchans, maxsleep); |
| 14435 |
pthread_testcancel(); |
| 14436 |
if ((res < 0) && (errno != EINTR)) { |
| 14437 |
ast_log(LOG_ERROR, "going out, poll failed: %s\n", strerror(errno)); |
| 14438 |
break; |
| 14439 |
} |
| 14440 |
|
| 14441 |
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); |
| 14442 |
for (i = 0; i < mfcr2->numchans; i++) { |
| 14443 |
pvt = mfcr2->pvts[i]; |
| 14444 |
if (!pvt) { |
| 14445 |
continue; |
| 14446 |
} |
| 14447 |
if (pollers[i].revents & POLLPRI || pollers[i].revents & POLLIN) { |
| 14448 |
openr2_chan_process_event(pvt->r2chan); |
| 14449 |
} |
| 14450 |
} |
| 14451 |
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate); |
| 14452 |
} |
| 14453 |
ast_log(LOG_NOTICE, "Quitting MFC/R2 monitor thread\n"); |
| 14454 |
return 0; |
| 14455 |
} |
| 14456 |
#endif |
| 14457 |
|
| 14458 |
#if defined(HAVE_PRI) |
| 14459 |
static void dahdi_pri_message(struct pri *pri, char *s) |
| 14460 |
{ |
| 14461 |
int x; |
| 14462 |
int y; |
| 14463 |
int dchan = -1; |
| 14464 |
int span = -1; |
| 14465 |
int dchancount = 0; |
| 14466 |
|
| 14467 |
if (pri) { |
| 14468 |
for (x = 0; x < NUM_SPANS; x++) { |
| 14469 |
for (y = 0; y < SIG_PRI_NUM_DCHANS; y++) { |
| 14470 |
if (pris[x].pri.dchans[y]) { |
| 14471 |
dchancount++; |
| 14472 |
} |
| 14473 |
|
| 14474 |
if (pris[x].pri.dchans[y] == pri) { |
| 14475 |
dchan = y; |
| 14476 |
} |
| 14477 |
} |
| 14478 |
if (dchan >= 0) { |
| 14479 |
span = x; |
| 14480 |
break; |
| 14481 |
} |
| 14482 |
dchancount = 0; |
| 14483 |
} |
| 14484 |
if (-1 < span) { |
| 14485 |
if (1 < dchancount) { |
| 14486 |
ast_verbose_callid(0, "[PRI Span: %d D-Channel: %d] %s", span + 1, dchan, s); |
| 14487 |
} else { |
| 14488 |
ast_verbose_callid(0, "PRI Span: %d %s", span + 1, s); |
| 14489 |
} |
| 14490 |
} else { |
| 14491 |
ast_verbose_callid(0, "PRI Span: ? %s", s); |
| 14492 |
} |
| 14493 |
} else { |
| 14494 |
ast_verbose_callid(0, "PRI Span: ? %s", s); |
| 14495 |
} |
| 14496 |
|
| 14497 |
ast_mutex_lock(&pridebugfdlock); |
| 14498 |
|
| 14499 |
if (pridebugfd >= 0) { |
| 14500 |
if (write(pridebugfd, s, strlen(s)) < 0) { |
| 14501 |
ast_log_callid(LOG_WARNING, 0, "write() failed: %s\n", strerror(errno)); |
| 14502 |
} |
| 14503 |
} |
| 14504 |
|
| 14505 |
ast_mutex_unlock(&pridebugfdlock); |
| 14506 |
} |
| 14507 |
#endif |
| 14508 |
|
| 14509 |
#if defined(HAVE_PRI) |
| 14510 |
static void dahdi_pri_error(struct pri *pri, char *s) |
| 14511 |
{ |
| 14512 |
int x; |
| 14513 |
int y; |
| 14514 |
int dchan = -1; |
| 14515 |
int span = -1; |
| 14516 |
int dchancount = 0; |
| 14517 |
|
| 14518 |
if (pri) { |
| 14519 |
for (x = 0; x < NUM_SPANS; x++) { |
| 14520 |
for (y = 0; y < SIG_PRI_NUM_DCHANS; y++) { |
| 14521 |
if (pris[x].pri.dchans[y]) { |
| 14522 |
dchancount++; |
| 14523 |
} |
| 14524 |
|
| 14525 |
if (pris[x].pri.dchans[y] == pri) { |
| 14526 |
dchan = y; |
| 14527 |
} |
| 14528 |
} |
| 14529 |
if (dchan >= 0) { |
| 14530 |
span = x; |
| 14531 |
break; |
| 14532 |
} |
| 14533 |
dchancount = 0; |
| 14534 |
} |
| 14535 |
if (-1 < span) { |
| 14536 |
if (1 < dchancount) { |
| 14537 |
ast_log_callid(LOG_ERROR, 0, "[PRI Span: %d D-Channel: %d] %s", span + 1, dchan, s); |
| 14538 |
} else { |
| 14539 |
ast_log_callid(LOG_ERROR, 0, "PRI Span: %d %s", span + 1, s); |
| 14540 |
} |
| 14541 |
} else { |
| 14542 |
ast_log_callid(LOG_ERROR, 0, "PRI Span: ? %s", s); |
| 14543 |
} |
| 14544 |
} else { |
| 14545 |
ast_log_callid(LOG_ERROR, 0, "PRI Span: ? %s", s); |
| 14546 |
} |
| 14547 |
|
| 14548 |
ast_mutex_lock(&pridebugfdlock); |
| 14549 |
|
| 14550 |
if (pridebugfd >= 0) { |
| 14551 |
if (write(pridebugfd, s, strlen(s)) < 0) { |
| 14552 |
ast_log_callid(LOG_WARNING, 0, "write() failed: %s\n", strerror(errno)); |
| 14553 |
} |
| 14554 |
} |
| 14555 |
|
| 14556 |
ast_mutex_unlock(&pridebugfdlock); |
| 14557 |
} |
| 14558 |
#endif |
| 14559 |
|
| 14560 |
#if defined(HAVE_PRI) |
| 14561 |
static int prepare_pri(struct dahdi_pri *pri) |
| 14562 |
{ |
| 14563 |
int i, res, x; |
| 14564 |
struct dahdi_params p; |
| 14565 |
struct dahdi_bufferinfo bi; |
| 14566 |
struct dahdi_spaninfo si; |
| 14567 |
|
| 14568 |
for (i = 0; i < SIG_PRI_NUM_DCHANS; i++) { |
| 14569 |
if (!pri->dchannels[i]) |
| 14570 |
break; |
| 14571 |
if (pri->pri.fds[i] >= 0) { |
| 14572 |
|
| 14573 |
break; |
| 14574 |
} |
| 14575 |
pri->pri.fds[i] = open("/dev/dahdi/channel", O_RDWR); |
| 14576 |
if ((pri->pri.fds[i] < 0)) { |
| 14577 |
ast_log(LOG_ERROR, "Unable to open D-channel (fd=%d) (%s)\n", |
| 14578 |
pri->pri.fds[i], strerror(errno)); |
| 14579 |
return -1; |
| 14580 |
} |
| 14581 |
x = pri->dchannels[i]; |
| 14582 |
res = ioctl(pri->pri.fds[i], DAHDI_SPECIFY, &x); |
| 14583 |
if (res) { |
| 14584 |
dahdi_close_pri_fd(pri, i); |
| 14585 |
ast_log(LOG_ERROR, "Unable to SPECIFY channel %d (%s)\n", x, strerror(errno)); |
| 14586 |
return -1; |
| 14587 |
} |
| 14588 |
memset(&p, 0, sizeof(p)); |
| 14589 |
res = ioctl(pri->pri.fds[i], DAHDI_GET_PARAMS, &p); |
| 14590 |
if (res) { |
| 14591 |
dahdi_close_pri_fd(pri, i); |
| 14592 |
ast_log(LOG_ERROR, "Unable to get parameters for D-channel %d (%s)\n", x, strerror(errno)); |
| 14593 |
return -1; |
| 14594 |
} |
| 14595 |
if ((p.sigtype != DAHDI_SIG_HDLCFCS) && (p.sigtype != DAHDI_SIG_HARDHDLC)) { |
| 14596 |
dahdi_close_pri_fd(pri, i); |
| 14597 |
ast_log(LOG_ERROR, "D-channel %d is not in HDLC/FCS mode.\n", x); |
| 14598 |
return -1; |
| 14599 |
} |
| 14600 |
memset(&si, 0, sizeof(si)); |
| 14601 |
res = ioctl(pri->pri.fds[i], DAHDI_SPANSTAT, &si); |
| 14602 |
if (res) { |
| 14603 |
dahdi_close_pri_fd(pri, i); |
| 14604 |
ast_log(LOG_ERROR, "Unable to get span state for D-channel %d (%s)\n", x, strerror(errno)); |
| 14605 |
} |
| 14606 |
if (!si.alarms) { |
| 14607 |
pri_event_noalarm(&pri->pri, i, 1); |
| 14608 |
} else { |
| 14609 |
pri_event_alarm(&pri->pri, i, 1); |
| 14610 |
} |
| 14611 |
memset(&bi, 0, sizeof(bi)); |
| 14612 |
bi.txbufpolicy = DAHDI_POLICY_IMMEDIATE; |
| 14613 |
bi.rxbufpolicy = DAHDI_POLICY_IMMEDIATE; |
| 14614 |
bi.numbufs = 32; |
| 14615 |
bi.bufsize = 1024; |
| 14616 |
if (ioctl(pri->pri.fds[i], DAHDI_SET_BUFINFO, &bi)) { |
| 14617 |
ast_log(LOG_ERROR, "Unable to set appropriate buffering on channel %d: %s\n", x, strerror(errno)); |
| 14618 |
dahdi_close_pri_fd(pri, i); |
| 14619 |
return -1; |
| 14620 |
} |
| 14621 |
pri->pri.dchan_logical_span[i] = pris[p.spanno - 1].prilogicalspan; |
| 14622 |
} |
| 14623 |
return 0; |
| 14624 |
} |
| 14625 |
#endif |
| 14626 |
|
| 14627 |
#if defined(HAVE_PRI) |
| 14628 |
static char *complete_span_helper(const char *line, const char *word, int pos, int state, int rpos) |
| 14629 |
{ |
| 14630 |
int which, span; |
| 14631 |
char *ret = NULL; |
| 14632 |
|
| 14633 |
if (pos != rpos) |
| 14634 |
return ret; |
| 14635 |
|
| 14636 |
for (which = span = 0; span < NUM_SPANS; span++) { |
| 14637 |
if (pris[span].pri.pri && ++which > state) { |
| 14638 |
if (ast_asprintf(&ret, "%d", span + 1) < 0) { |
| 14639 |
ret = NULL; |
| 14640 |
} |
| 14641 |
break; |
| 14642 |
} |
| 14643 |
} |
| 14644 |
return ret; |
| 14645 |
} |
| 14646 |
#endif |
| 14647 |
|
| 14648 |
#if defined(HAVE_PRI) |
| 14649 |
static char *complete_span_4(const char *line, const char *word, int pos, int state) |
| 14650 |
{ |
| 14651 |
return complete_span_helper(line,word,pos,state,3); |
| 14652 |
} |
| 14653 |
#endif |
| 14654 |
|
| 14655 |
#if defined(HAVE_PRI) |
| 14656 |
static char *handle_pri_set_debug_file(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 14657 |
{ |
| 14658 |
int myfd; |
| 14659 |
switch (cmd) { |
| 14660 |
case CLI_INIT: |
| 14661 |
e->command = "pri set debug file"; |
| 14662 |
e->usage = "Usage: pri set debug file [output-file]\n" |
| 14663 |
" Sends PRI debug output to the specified output file\n"; |
| 14664 |
return NULL; |
| 14665 |
case CLI_GENERATE: |
| 14666 |
return NULL; |
| 14667 |
} |
| 14668 |
if (a->argc < 5) |
| 14669 |
return CLI_SHOWUSAGE; |
| 14670 |
|
| 14671 |
if (ast_strlen_zero(a->argv[4])) |
| 14672 |
return CLI_SHOWUSAGE; |
| 14673 |
|
| 14674 |
myfd = open(a->argv[4], O_CREAT|O_WRONLY, AST_FILE_MODE); |
| 14675 |
if (myfd < 0) { |
| 14676 |
ast_cli(a->fd, "Unable to open '%s' for writing\n", a->argv[4]); |
| 14677 |
return CLI_SUCCESS; |
| 14678 |
} |
| 14679 |
|
| 14680 |
ast_mutex_lock(&pridebugfdlock); |
| 14681 |
|
| 14682 |
if (pridebugfd >= 0) |
| 14683 |
close(pridebugfd); |
| 14684 |
|
| 14685 |
pridebugfd = myfd; |
| 14686 |
ast_copy_string(pridebugfilename,a->argv[4],sizeof(pridebugfilename)); |
| 14687 |
ast_mutex_unlock(&pridebugfdlock); |
| 14688 |
ast_cli(a->fd, "PRI debug output will be sent to '%s'\n", a->argv[4]); |
| 14689 |
return CLI_SUCCESS; |
| 14690 |
} |
| 14691 |
#endif |
| 14692 |
|
| 14693 |
#if defined(HAVE_PRI) |
| 14694 |
static int action_pri_debug_file_set(struct mansession *s, const struct message *m) |
| 14695 |
{ |
| 14696 |
const char *output_file = astman_get_header(m, "File"); |
| 14697 |
int myfd; |
| 14698 |
|
| 14699 |
if (ast_strlen_zero(output_file)) { |
| 14700 |
astman_send_error(s, m, "Action must define a 'File'"); |
| 14701 |
} |
| 14702 |
|
| 14703 |
myfd = open(output_file, O_CREAT|O_WRONLY, AST_FILE_MODE); |
| 14704 |
if (myfd < 0) { |
| 14705 |
astman_send_error(s, m, "Unable to open requested file for writing"); |
| 14706 |
return 0; |
| 14707 |
} |
| 14708 |
|
| 14709 |
ast_mutex_lock(&pridebugfdlock); |
| 14710 |
|
| 14711 |
if (pridebugfd >= 0) { |
| 14712 |
close(pridebugfd); |
| 14713 |
} |
| 14714 |
|
| 14715 |
pridebugfd = myfd; |
| 14716 |
ast_copy_string(pridebugfilename, output_file, sizeof(pridebugfilename)); |
| 14717 |
ast_mutex_unlock(&pridebugfdlock); |
| 14718 |
astman_send_ack(s, m, "PRI debug output will now be sent to requested file."); |
| 14719 |
|
| 14720 |
return 0; |
| 14721 |
} |
| 14722 |
#endif |
| 14723 |
|
| 14724 |
#if defined(HAVE_PRI) |
| 14725 |
static int action_pri_debug_file_unset(struct mansession *s, const struct message *m) |
| 14726 |
{ |
| 14727 |
ast_mutex_lock(&pridebugfdlock); |
| 14728 |
|
| 14729 |
if (pridebugfd >= 0) { |
| 14730 |
close(pridebugfd); |
| 14731 |
} |
| 14732 |
|
| 14733 |
pridebugfd = -1; |
| 14734 |
|
| 14735 |
ast_mutex_unlock(&pridebugfdlock); |
| 14736 |
|
| 14737 |
astman_send_ack(s, m, "PRI Debug output to file disabled"); |
| 14738 |
return 0; |
| 14739 |
} |
| 14740 |
#endif |
| 14741 |
|
| 14742 |
#if defined(HAVE_PRI) |
| 14743 |
static char *handle_pri_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 14744 |
{ |
| 14745 |
int span; |
| 14746 |
int x; |
| 14747 |
int debugmask = 0; |
| 14748 |
int level = 0; |
| 14749 |
switch (cmd) { |
| 14750 |
case CLI_INIT: |
| 14751 |
e->command = "pri set debug {on|off|hex|intense|0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15} span"; |
| 14752 |
e->usage = |
| 14753 |
"Usage: pri set debug {<level>|on|off|hex|intense} span <span>\n" |
| 14754 |
" Enables debugging on a given PRI span\n" |
| 14755 |
" Level is a bitmap of the following values:\n" |
| 14756 |
" 1 General debugging incl. state changes\n" |
| 14757 |
" 2 Decoded Q.931 messages\n" |
| 14758 |
" 4 Decoded Q.921 messages\n" |
| 14759 |
" 8 Raw hex dumps of Q.921 frames\n" |
| 14760 |
" on - equivalent to 3\n" |
| 14761 |
" hex - equivalent to 8\n" |
| 14762 |
" intense - equivalent to 15\n"; |
| 14763 |
return NULL; |
| 14764 |
case CLI_GENERATE: |
| 14765 |
return complete_span_4(a->line, a->word, a->pos, a->n); |
| 14766 |
} |
| 14767 |
if (a->argc < 6) { |
| 14768 |
return CLI_SHOWUSAGE; |
| 14769 |
} |
| 14770 |
|
| 14771 |
if (!strcasecmp(a->argv[3], "on")) { |
| 14772 |
level = 3; |
| 14773 |
} else if (!strcasecmp(a->argv[3], "off")) { |
| 14774 |
level = 0; |
| 14775 |
} else if (!strcasecmp(a->argv[3], "intense")) { |
| 14776 |
level = 15; |
| 14777 |
} else if (!strcasecmp(a->argv[3], "hex")) { |
| 14778 |
level = 8; |
| 14779 |
} else { |
| 14780 |
level = atoi(a->argv[3]); |
| 14781 |
} |
| 14782 |
span = atoi(a->argv[5]); |
| 14783 |
if ((span < 1) || (span > NUM_SPANS)) { |
| 14784 |
ast_cli(a->fd, "Invalid span %s. Should be a number %d to %d\n", a->argv[5], 1, NUM_SPANS); |
| 14785 |
return CLI_SUCCESS; |
| 14786 |
} |
| 14787 |
if (!pris[span-1].pri.pri) { |
| 14788 |
ast_cli(a->fd, "No PRI running on span %d\n", span); |
| 14789 |
return CLI_SUCCESS; |
| 14790 |
} |
| 14791 |
|
| 14792 |
if (level & 1) debugmask |= SIG_PRI_DEBUG_NORMAL; |
| 14793 |
if (level & 2) debugmask |= PRI_DEBUG_Q931_DUMP; |
| 14794 |
if (level & 4) debugmask |= PRI_DEBUG_Q921_DUMP; |
| 14795 |
if (level & 8) debugmask |= PRI_DEBUG_Q921_RAW; |
| 14796 |
|
| 14797 |
|
| 14798 |
for (x = 0; x < SIG_PRI_NUM_DCHANS; x++) { |
| 14799 |
if (pris[span - 1].pri.dchans[x]) { |
| 14800 |
pri_set_debug(pris[span - 1].pri.dchans[x], debugmask); |
| 14801 |
} |
| 14802 |
} |
| 14803 |
if (level == 0) { |
| 14804 |
|
| 14805 |
ast_mutex_lock(&pridebugfdlock); |
| 14806 |
if (0 <= pridebugfd) { |
| 14807 |
close(pridebugfd); |
| 14808 |
pridebugfd = -1; |
| 14809 |
ast_cli(a->fd, "Disabled PRI debug output to file '%s'\n", |
| 14810 |
pridebugfilename); |
| 14811 |
} |
| 14812 |
ast_mutex_unlock(&pridebugfdlock); |
| 14813 |
} |
| 14814 |
pris[span - 1].pri.debug = (level) ? 1 : 0; |
| 14815 |
ast_cli(a->fd, "%s debugging on span %d\n", (level) ? "Enabled" : "Disabled", span); |
| 14816 |
return CLI_SUCCESS; |
| 14817 |
} |
| 14818 |
#endif |
| 14819 |
|
| 14820 |
#if defined(HAVE_PRI) |
| 14821 |
static int action_pri_debug_set(struct mansession *s, const struct message *m) |
| 14822 |
{ |
| 14823 |
const char *level = astman_get_header(m, "Level"); |
| 14824 |
const char *span = astman_get_header(m, "Span"); |
| 14825 |
int level_val; |
| 14826 |
int span_val; |
| 14827 |
int x; |
| 14828 |
int debugmask = 0; |
| 14829 |
|
| 14830 |
if (ast_strlen_zero(level)) { |
| 14831 |
astman_send_error(s, m, "'Level' was not specified"); |
| 14832 |
return 0; |
| 14833 |
} |
| 14834 |
|
| 14835 |
if (ast_strlen_zero(span)) { |
| 14836 |
astman_send_error(s, m, "'Span' was not specified"); |
| 14837 |
return 0; |
| 14838 |
} |
| 14839 |
|
| 14840 |
if (!strcasecmp(level, "on")) { |
| 14841 |
level_val = 3; |
| 14842 |
} else if (!strcasecmp(level, "off")) { |
| 14843 |
level_val = 0; |
| 14844 |
} else if (!strcasecmp(level, "intense")) { |
| 14845 |
level_val = 15; |
| 14846 |
} else if (!strcasecmp(level, "hex")) { |
| 14847 |
level_val = 8; |
| 14848 |
} else { |
| 14849 |
if (sscanf(level, "%30d", &level_val) != 1) { |
| 14850 |
astman_send_error(s, m, "Invalid value for 'Level'"); |
| 14851 |
return 0; |
| 14852 |
} |
| 14853 |
} |
| 14854 |
|
| 14855 |
if (sscanf(span, "%30d", &span_val) != 1) { |
| 14856 |
astman_send_error(s, m, "Invalid value for 'Span'"); |
| 14857 |
} |
| 14858 |
|
| 14859 |
if ((span_val < 1) || (span_val > NUM_SPANS)) { |
| 14860 |
const char *id = astman_get_header(m, "ActionID"); |
| 14861 |
char id_text[256] = ""; |
| 14862 |
|
| 14863 |
if (!ast_strlen_zero(id)) { |
| 14864 |
snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id); |
| 14865 |
} |
| 14866 |
|
| 14867 |
astman_append(s, "Response: Error\r\n" |
| 14868 |
"%s" |
| 14869 |
"Message: Invalid span '%s' - Should be a number from 1 to %d\r\n" |
| 14870 |
"\r\n", |
| 14871 |
id_text, |
| 14872 |
span, NUM_SPANS); |
| 14873 |
|
| 14874 |
return 0; |
| 14875 |
} |
| 14876 |
|
| 14877 |
if (!pris[span_val-1].pri.pri) { |
| 14878 |
astman_send_error(s, m, "No PRI running on requested span"); |
| 14879 |
return 0; |
| 14880 |
} |
| 14881 |
|
| 14882 |
if (level_val & 1) { |
| 14883 |
debugmask |= SIG_PRI_DEBUG_NORMAL; |
| 14884 |
} |
| 14885 |
if (level_val & 2) { |
| 14886 |
debugmask |= PRI_DEBUG_Q931_DUMP; |
| 14887 |
} |
| 14888 |
if (level_val & 4) { |
| 14889 |
debugmask |= PRI_DEBUG_Q921_DUMP; |
| 14890 |
} |
| 14891 |
if (level_val & 8) { |
| 14892 |
debugmask |= PRI_DEBUG_Q921_RAW; |
| 14893 |
} |
| 14894 |
|
| 14895 |
|
| 14896 |
for (x = 0; x < SIG_PRI_NUM_DCHANS; x++) { |
| 14897 |
if (pris[span_val - 1].pri.dchans[x]) { |
| 14898 |
pri_set_debug(pris[span_val - 1].pri.dchans[x], debugmask); |
| 14899 |
} |
| 14900 |
} |
| 14901 |
|
| 14902 |
pris[span_val - 1].pri.debug = (level_val) ? 1 : 0; |
| 14903 |
astman_send_ack(s, m, "Debug level set for requested span"); |
| 14904 |
|
| 14905 |
return 0; |
| 14906 |
} |
| 14907 |
#endif |
| 14908 |
|
| 14909 |
#if defined(HAVE_PRI) |
| 14910 |
#if defined(HAVE_PRI_SERVICE_MESSAGES) |
| 14911 |
static char *handle_pri_service_generic(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a, int changestatus) |
| 14912 |
{ |
| 14913 |
unsigned *why; |
| 14914 |
int channel; |
| 14915 |
int trunkgroup; |
| 14916 |
int x, y, fd = a->fd; |
| 14917 |
int interfaceid = 0; |
| 14918 |
char db_chan_name[20], db_answer[15]; |
| 14919 |
struct dahdi_pvt *tmp; |
| 14920 |
struct dahdi_pri *pri; |
| 14921 |
|
| 14922 |
if (a->argc < 5 || a->argc > 6) |
| 14923 |
return CLI_SHOWUSAGE; |
| 14924 |
if (strchr(a->argv[4], ':')) { |
| 14925 |
if (sscanf(a->argv[4], "%30d:%30d", &trunkgroup, &channel) != 2) |
| 14926 |
return CLI_SHOWUSAGE; |
| 14927 |
if ((trunkgroup < 1) || (channel < 1)) |
| 14928 |
return CLI_SHOWUSAGE; |
| 14929 |
pri = NULL; |
| 14930 |
for (x=0;x<NUM_SPANS;x++) { |
| 14931 |
if (pris[x].pri.trunkgroup == trunkgroup) { |
| 14932 |
pri = pris + x; |
| 14933 |
break; |
| 14934 |
} |
| 14935 |
} |
| 14936 |
if (!pri) { |
| 14937 |
ast_cli(fd, "No such trunk group %d\n", trunkgroup); |
| 14938 |
return CLI_FAILURE; |
| 14939 |
} |
| 14940 |
} else |
| 14941 |
channel = atoi(a->argv[4]); |
| 14942 |
|
| 14943 |
if (a->argc == 6) |
| 14944 |
interfaceid = atoi(a->argv[5]); |
| 14945 |
|
| 14946 |
|
| 14947 |
for (x = 0; x < NUM_SPANS; x++) { |
| 14948 |
for (y = 0; y < SIG_PRI_NUM_DCHANS; y++) { |
| 14949 |
if (pris[x].dchannels[y] == channel) { |
| 14950 |
pri = pris + x; |
| 14951 |
if (pri->pri.enable_service_message_support) { |
| 14952 |
ast_mutex_lock(&pri->pri.lock); |
| 14953 |
pri_maintenance_service(pri->pri.pri, interfaceid, -1, changestatus); |
| 14954 |
ast_mutex_unlock(&pri->pri.lock); |
| 14955 |
} else { |
| 14956 |
ast_cli(fd, |
| 14957 |
"\n\tThis operation has not been enabled in chan_dahdi.conf, set 'service_message_support=yes' to use this operation.\n" |
| 14958 |
"\tNote only 4ESS, 5ESS, and NI2 switch types are supported.\n\n"); |
| 14959 |
} |
| 14960 |
return CLI_SUCCESS; |
| 14961 |
} |
| 14962 |
} |
| 14963 |
} |
| 14964 |
|
| 14965 |
|
| 14966 |
ast_mutex_lock(&iflock); |
| 14967 |
for (tmp = iflist; tmp; tmp = tmp->next) { |
| 14968 |
if (tmp->pri && tmp->channel == channel) { |
| 14969 |
ast_mutex_unlock(&iflock); |
| 14970 |
ast_mutex_lock(&tmp->pri->lock); |
| 14971 |
if (!tmp->pri->enable_service_message_support) { |
| 14972 |
ast_mutex_unlock(&tmp->pri->lock); |
| 14973 |
ast_cli(fd, |
| 14974 |
"\n\tThis operation has not been enabled in chan_dahdi.conf, set 'service_message_support=yes' to use this operation.\n" |
| 14975 |
"\tNote only 4ESS, 5ESS, and NI2 switch types are supported.\n\n"); |
| 14976 |
return CLI_SUCCESS; |
| 14977 |
} |
| 14978 |
snprintf(db_chan_name, sizeof(db_chan_name), "%s/%d:%d", dahdi_db, tmp->span, channel); |
| 14979 |
why = &((struct sig_pri_chan *) tmp->sig_pvt)->service_status; |
| 14980 |
switch(changestatus) { |
| 14981 |
case 0: |
| 14982 |
|
| 14983 |
ast_db_del(db_chan_name, SRVST_DBKEY); |
| 14984 |
*why &= ~SRVST_NEAREND; |
| 14985 |
if (*why) { |
| 14986 |
snprintf(db_answer, sizeof(db_answer), "%s:%u", SRVST_TYPE_OOS, *why); |
| 14987 |
ast_db_put(db_chan_name, SRVST_DBKEY, db_answer); |
| 14988 |
} else { |
| 14989 |
dahdi_pri_update_span_devstate(tmp->pri); |
| 14990 |
} |
| 14991 |
break; |
| 14992 |
|
| 14993 |
case 2: |
| 14994 |
|
| 14995 |
ast_db_del(db_chan_name, SRVST_DBKEY); |
| 14996 |
*why |= SRVST_NEAREND; |
| 14997 |
snprintf(db_answer, sizeof(db_answer), "%s:%u", SRVST_TYPE_OOS, *why); |
| 14998 |
ast_db_put(db_chan_name, SRVST_DBKEY, db_answer); |
| 14999 |
dahdi_pri_update_span_devstate(tmp->pri); |
| 15000 |
break; |
| 15001 |
|
| 15002 |
|
| 15003 |
default: |
| 15004 |
ast_log(LOG_WARNING, "Unsupported changestatus: '%d'\n", changestatus); |
| 15005 |
break; |
| 15006 |
} |
| 15007 |
pri_maintenance_bservice(tmp->pri->pri, tmp->sig_pvt, changestatus); |
| 15008 |
ast_mutex_unlock(&tmp->pri->lock); |
| 15009 |
return CLI_SUCCESS; |
| 15010 |
} |
| 15011 |
} |
| 15012 |
ast_mutex_unlock(&iflock); |
| 15013 |
|
| 15014 |
ast_cli(fd, "Unable to find given channel %d, possibly not a PRI\n", channel); |
| 15015 |
return CLI_FAILURE; |
| 15016 |
} |
| 15017 |
|
| 15018 |
static char *handle_pri_service_enable_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15019 |
{ |
| 15020 |
switch (cmd) { |
| 15021 |
case CLI_INIT: |
| 15022 |
e->command = "pri service enable channel"; |
| 15023 |
e->usage = |
| 15024 |
"Usage: pri service enable channel <channel> [<interface id>]\n" |
| 15025 |
" Send an AT&T / NFAS / CCS ANSI T1.607 maintenance message\n" |
| 15026 |
" to restore a channel to service, with optional interface id\n" |
| 15027 |
" as agreed upon with remote switch operator\n"; |
| 15028 |
return NULL; |
| 15029 |
case CLI_GENERATE: |
| 15030 |
return NULL; |
| 15031 |
} |
| 15032 |
return handle_pri_service_generic(e, cmd, a, 0); |
| 15033 |
} |
| 15034 |
|
| 15035 |
static char *handle_pri_service_disable_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15036 |
{ |
| 15037 |
switch (cmd) { |
| 15038 |
case CLI_INIT: |
| 15039 |
e->command = "pri service disable channel"; |
| 15040 |
e->usage = |
| 15041 |
"Usage: pri service disable channel <chan num> [<interface id>]\n" |
| 15042 |
" Send an AT&T / NFAS / CCS ANSI T1.607 maintenance message\n" |
| 15043 |
" to remove a channel from service, with optional interface id\n" |
| 15044 |
" as agreed upon with remote switch operator\n"; |
| 15045 |
return NULL; |
| 15046 |
case CLI_GENERATE: |
| 15047 |
return NULL; |
| 15048 |
} |
| 15049 |
return handle_pri_service_generic(e, cmd, a, 2); |
| 15050 |
} |
| 15051 |
#endif |
| 15052 |
#endif |
| 15053 |
|
| 15054 |
#if defined(HAVE_PRI) |
| 15055 |
static char *handle_pri_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15056 |
{ |
| 15057 |
int span; |
| 15058 |
|
| 15059 |
switch (cmd) { |
| 15060 |
case CLI_INIT: |
| 15061 |
e->command = "pri show channels"; |
| 15062 |
e->usage = |
| 15063 |
"Usage: pri show channels\n" |
| 15064 |
" Displays PRI channel information such as the current mapping\n" |
| 15065 |
" of DAHDI B channels to Asterisk channel names and which calls\n" |
| 15066 |
" are on hold or call-waiting. Calls on hold or call-waiting\n" |
| 15067 |
" are not associated with any B channel.\n"; |
| 15068 |
return NULL; |
| 15069 |
case CLI_GENERATE: |
| 15070 |
return NULL; |
| 15071 |
} |
| 15072 |
|
| 15073 |
if (a->argc != 3) |
| 15074 |
return CLI_SHOWUSAGE; |
| 15075 |
|
| 15076 |
sig_pri_cli_show_channels_header(a->fd); |
| 15077 |
for (span = 0; span < NUM_SPANS; ++span) { |
| 15078 |
if (pris[span].pri.pri) { |
| 15079 |
sig_pri_cli_show_channels(a->fd, &pris[span].pri); |
| 15080 |
} |
| 15081 |
} |
| 15082 |
return CLI_SUCCESS; |
| 15083 |
} |
| 15084 |
#endif |
| 15085 |
|
| 15086 |
#if defined(HAVE_PRI) |
| 15087 |
static char *handle_pri_show_spans(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15088 |
{ |
| 15089 |
int span; |
| 15090 |
|
| 15091 |
switch (cmd) { |
| 15092 |
case CLI_INIT: |
| 15093 |
e->command = "pri show spans"; |
| 15094 |
e->usage = |
| 15095 |
"Usage: pri show spans\n" |
| 15096 |
" Displays PRI span information\n"; |
| 15097 |
return NULL; |
| 15098 |
case CLI_GENERATE: |
| 15099 |
return NULL; |
| 15100 |
} |
| 15101 |
|
| 15102 |
if (a->argc != 3) |
| 15103 |
return CLI_SHOWUSAGE; |
| 15104 |
|
| 15105 |
for (span = 0; span < NUM_SPANS; span++) { |
| 15106 |
if (pris[span].pri.pri) { |
| 15107 |
sig_pri_cli_show_spans(a->fd, span + 1, &pris[span].pri); |
| 15108 |
} |
| 15109 |
} |
| 15110 |
return CLI_SUCCESS; |
| 15111 |
} |
| 15112 |
#endif |
| 15113 |
|
| 15114 |
#if defined(HAVE_PRI) |
| 15115 |
#define container_of(ptr, type, member) \ |
| 15116 |
((type *)((char *)(ptr) - offsetof(type, member))) |
| 15117 |
|
| 15118 |
|
| 15119 |
|
| 15120 |
|
| 15121 |
|
| 15122 |
|
| 15123 |
|
| 15124 |
|
| 15125 |
|
| 15126 |
|
| 15127 |
|
| 15128 |
static void pri_destroy_span(struct sig_pri_span *pri) |
| 15129 |
{ |
| 15130 |
int i; |
| 15131 |
int res; |
| 15132 |
int cancel_code; |
| 15133 |
struct dahdi_pri* dahdi_pri; |
| 15134 |
pthread_t master = pri->master; |
| 15135 |
|
| 15136 |
if (!master || (master == AST_PTHREADT_NULL)) { |
| 15137 |
return; |
| 15138 |
} |
| 15139 |
ast_debug(2, "About to destroy DAHDI channels of span %d.\n", pri->span); |
| 15140 |
for (i = 0; i < pri->numchans; i++) { |
| 15141 |
int channel; |
| 15142 |
struct sig_pri_chan *pvt = pri->pvts[i]; |
| 15143 |
|
| 15144 |
if (!pvt) { |
| 15145 |
continue; |
| 15146 |
} |
| 15147 |
channel = pvt->channel; |
| 15148 |
ast_debug(2, "About to destroy B-channel %d.\n", channel); |
| 15149 |
dahdi_destroy_channel_range(channel, channel); |
| 15150 |
} |
| 15151 |
|
| 15152 |
cancel_code = pthread_cancel(master); |
| 15153 |
pthread_kill(master, SIGURG); |
| 15154 |
ast_debug(4, |
| 15155 |
"Waiting to join thread of span %d " |
| 15156 |
"with pid=%p cancel_code=%d\n", |
| 15157 |
pri->span, (void *)master, cancel_code); |
| 15158 |
res = pthread_join(master, NULL); |
| 15159 |
if (res != 0) { |
| 15160 |
ast_log(LOG_NOTICE, "pthread_join failed: %d\n", res); |
| 15161 |
} |
| 15162 |
pri->master = AST_PTHREADT_NULL; |
| 15163 |
|
| 15164 |
|
| 15165 |
dahdi_pri = container_of(pri, struct dahdi_pri, pri); |
| 15166 |
for (i = 0; i < SIG_PRI_NUM_DCHANS; i++) { |
| 15167 |
ast_debug(4, "closing pri_fd %d\n", i); |
| 15168 |
dahdi_close_pri_fd(dahdi_pri, i); |
| 15169 |
dahdi_pri->dchannels[i] = 0; |
| 15170 |
} |
| 15171 |
sig_pri_init_pri(pri); |
| 15172 |
ast_debug(1, "PRI span %d destroyed\n", pri->span); |
| 15173 |
} |
| 15174 |
|
| 15175 |
static char *handle_pri_destroy_span(struct ast_cli_entry *e, int cmd, |
| 15176 |
struct ast_cli_args *a) |
| 15177 |
{ |
| 15178 |
int span; |
| 15179 |
int res; |
| 15180 |
struct sig_pri_span *pri; |
| 15181 |
|
| 15182 |
switch (cmd) { |
| 15183 |
case CLI_INIT: |
| 15184 |
e->command = "pri destroy span"; |
| 15185 |
e->usage = |
| 15186 |
"Usage: pri destroy span <span>\n" |
| 15187 |
" Destroys D-channel of span and its B-channels.\n" |
| 15188 |
" DON'T USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.\n"; |
| 15189 |
return NULL; |
| 15190 |
case CLI_GENERATE: |
| 15191 |
return complete_span_4(a->line, a->word, a->pos, a->n); |
| 15192 |
} |
| 15193 |
|
| 15194 |
if (a->argc < 4) { |
| 15195 |
return CLI_SHOWUSAGE; |
| 15196 |
} |
| 15197 |
res = sscanf(a->argv[3], "%30d", &span); |
| 15198 |
if ((res != 1) || span < 1 || span > NUM_SPANS) { |
| 15199 |
ast_cli(a->fd, |
| 15200 |
"Invalid span '%s'. Should be a number from %d to %d\n", |
| 15201 |
a->argv[3], 1, NUM_SPANS); |
| 15202 |
return CLI_SUCCESS; |
| 15203 |
} |
| 15204 |
pri = &pris[span - 1].pri; |
| 15205 |
if (!pri->pri) { |
| 15206 |
ast_cli(a->fd, "No PRI running on span %d\n", span); |
| 15207 |
return CLI_SUCCESS; |
| 15208 |
} |
| 15209 |
|
| 15210 |
pri_destroy_span(pri); |
| 15211 |
return CLI_SUCCESS; |
| 15212 |
} |
| 15213 |
|
| 15214 |
#endif |
| 15215 |
|
| 15216 |
#if defined(HAVE_PRI) |
| 15217 |
static char *handle_pri_show_span(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15218 |
{ |
| 15219 |
int span; |
| 15220 |
|
| 15221 |
switch (cmd) { |
| 15222 |
case CLI_INIT: |
| 15223 |
e->command = "pri show span"; |
| 15224 |
e->usage = |
| 15225 |
"Usage: pri show span <span>\n" |
| 15226 |
" Displays PRI Information on a given PRI span\n"; |
| 15227 |
return NULL; |
| 15228 |
case CLI_GENERATE: |
| 15229 |
return complete_span_4(a->line, a->word, a->pos, a->n); |
| 15230 |
} |
| 15231 |
|
| 15232 |
if (a->argc < 4) |
| 15233 |
return CLI_SHOWUSAGE; |
| 15234 |
span = atoi(a->argv[3]); |
| 15235 |
if ((span < 1) || (span > NUM_SPANS)) { |
| 15236 |
ast_cli(a->fd, "Invalid span '%s'. Should be a number from %d to %d\n", a->argv[3], 1, NUM_SPANS); |
| 15237 |
return CLI_SUCCESS; |
| 15238 |
} |
| 15239 |
if (!pris[span-1].pri.pri) { |
| 15240 |
ast_cli(a->fd, "No PRI running on span %d\n", span); |
| 15241 |
return CLI_SUCCESS; |
| 15242 |
} |
| 15243 |
|
| 15244 |
sig_pri_cli_show_span(a->fd, pris[span-1].dchannels, &pris[span-1].pri); |
| 15245 |
|
| 15246 |
return CLI_SUCCESS; |
| 15247 |
} |
| 15248 |
#endif |
| 15249 |
|
| 15250 |
#if defined(HAVE_PRI) |
| 15251 |
static char *handle_pri_show_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15252 |
{ |
| 15253 |
int x; |
| 15254 |
int span; |
| 15255 |
int count=0; |
| 15256 |
int debug; |
| 15257 |
|
| 15258 |
switch (cmd) { |
| 15259 |
case CLI_INIT: |
| 15260 |
e->command = "pri show debug"; |
| 15261 |
e->usage = |
| 15262 |
"Usage: pri show debug\n" |
| 15263 |
" Show the debug state of pri spans\n"; |
| 15264 |
return NULL; |
| 15265 |
case CLI_GENERATE: |
| 15266 |
return NULL; |
| 15267 |
} |
| 15268 |
|
| 15269 |
for (span = 0; span < NUM_SPANS; span++) { |
| 15270 |
if (pris[span].pri.pri) { |
| 15271 |
for (x = 0; x < SIG_PRI_NUM_DCHANS; x++) { |
| 15272 |
if (pris[span].pri.dchans[x]) { |
| 15273 |
debug = pri_get_debug(pris[span].pri.dchans[x]); |
| 15274 |
ast_cli(a->fd, "Span %d: Debug: %s\tIntense: %s\n", span+1, (debug&PRI_DEBUG_Q931_STATE)? "Yes" : "No" ,(debug&PRI_DEBUG_Q921_RAW)? "Yes" : "No" ); |
| 15275 |
count++; |
| 15276 |
} |
| 15277 |
} |
| 15278 |
} |
| 15279 |
|
| 15280 |
} |
| 15281 |
ast_mutex_lock(&pridebugfdlock); |
| 15282 |
if (pridebugfd >= 0) |
| 15283 |
ast_cli(a->fd, "Logging PRI debug to file %s\n", pridebugfilename); |
| 15284 |
ast_mutex_unlock(&pridebugfdlock); |
| 15285 |
|
| 15286 |
if (!count) |
| 15287 |
ast_cli(a->fd, "No PRI running\n"); |
| 15288 |
return CLI_SUCCESS; |
| 15289 |
} |
| 15290 |
#endif |
| 15291 |
|
| 15292 |
#if defined(HAVE_PRI) |
| 15293 |
static char *handle_pri_version(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15294 |
{ |
| 15295 |
switch (cmd) { |
| 15296 |
case CLI_INIT: |
| 15297 |
e->command = "pri show version"; |
| 15298 |
e->usage = |
| 15299 |
"Usage: pri show version\n" |
| 15300 |
"Show libpri version information\n"; |
| 15301 |
return NULL; |
| 15302 |
case CLI_GENERATE: |
| 15303 |
return NULL; |
| 15304 |
} |
| 15305 |
|
| 15306 |
ast_cli(a->fd, "libpri version: %s\n", pri_get_version()); |
| 15307 |
|
| 15308 |
return CLI_SUCCESS; |
| 15309 |
} |
| 15310 |
#endif |
| 15311 |
|
| 15312 |
#if defined(HAVE_PRI) |
| 15313 |
static struct ast_cli_entry dahdi_pri_cli[] = { |
| 15314 |
AST_CLI_DEFINE(handle_pri_debug, "Enables PRI debugging on a span"), |
| 15315 |
#if defined(HAVE_PRI_SERVICE_MESSAGES) |
| 15316 |
AST_CLI_DEFINE(handle_pri_service_enable_channel, "Return a channel to service"), |
| 15317 |
AST_CLI_DEFINE(handle_pri_service_disable_channel, "Remove a channel from service"), |
| 15318 |
#endif |
| 15319 |
AST_CLI_DEFINE(handle_pri_show_channels, "Displays PRI channel information"), |
| 15320 |
AST_CLI_DEFINE(handle_pri_show_spans, "Displays PRI span information"), |
| 15321 |
AST_CLI_DEFINE(handle_pri_show_span, "Displays PRI span information"), |
| 15322 |
AST_CLI_DEFINE(handle_pri_destroy_span, "Destroy a PRI span"), |
| 15323 |
AST_CLI_DEFINE(handle_pri_show_debug, "Displays current PRI debug settings"), |
| 15324 |
AST_CLI_DEFINE(handle_pri_set_debug_file, "Sends PRI debug output to the specified file"), |
| 15325 |
AST_CLI_DEFINE(handle_pri_version, "Displays libpri version"), |
| 15326 |
}; |
| 15327 |
#endif |
| 15328 |
|
| 15329 |
#ifdef HAVE_OPENR2 |
| 15330 |
|
| 15331 |
static char *handle_mfcr2_version(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15332 |
{ |
| 15333 |
switch (cmd) { |
| 15334 |
case CLI_INIT: |
| 15335 |
e->command = "mfcr2 show version"; |
| 15336 |
e->usage = |
| 15337 |
"Usage: mfcr2 show version\n" |
| 15338 |
" Shows the version of the OpenR2 library being used.\n"; |
| 15339 |
return NULL; |
| 15340 |
case CLI_GENERATE: |
| 15341 |
return NULL; |
| 15342 |
} |
| 15343 |
ast_cli(a->fd, "OpenR2 version: %s, revision: %s\n", openr2_get_version(), openr2_get_revision()); |
| 15344 |
return CLI_SUCCESS; |
| 15345 |
} |
| 15346 |
|
| 15347 |
static char *handle_mfcr2_show_variants(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15348 |
{ |
| 15349 |
#define FORMAT "%4s %40s\n" |
| 15350 |
int i = 0; |
| 15351 |
int numvariants = 0; |
| 15352 |
const openr2_variant_entry_t *variants; |
| 15353 |
switch (cmd) { |
| 15354 |
case CLI_INIT: |
| 15355 |
e->command = "mfcr2 show variants"; |
| 15356 |
e->usage = |
| 15357 |
"Usage: mfcr2 show variants\n" |
| 15358 |
" Shows the list of MFC/R2 variants supported.\n"; |
| 15359 |
return NULL; |
| 15360 |
case CLI_GENERATE: |
| 15361 |
return NULL; |
| 15362 |
} |
| 15363 |
if (!(variants = openr2_proto_get_variant_list(&numvariants))) { |
| 15364 |
ast_cli(a->fd, "Failed to get list of variants.\n"); |
| 15365 |
return CLI_FAILURE; |
| 15366 |
} |
| 15367 |
ast_cli(a->fd, FORMAT, "Variant Code", "Country"); |
| 15368 |
for (i = 0; i < numvariants; i++) { |
| 15369 |
ast_cli(a->fd, FORMAT, variants[i].name, variants[i].country); |
| 15370 |
} |
| 15371 |
return CLI_SUCCESS; |
| 15372 |
#undef FORMAT |
| 15373 |
} |
| 15374 |
|
| 15375 |
static char *handle_mfcr2_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15376 |
{ |
| 15377 |
#define FORMAT "%4s %4s %-7.7s %-7.7s %-8.8s %-9.9s %-16.16s %-8.8s %-8.8s\n" |
| 15378 |
int filtertype = 0; |
| 15379 |
int targetnum = 0; |
| 15380 |
char channo[5]; |
| 15381 |
char linkno[5]; |
| 15382 |
char anino[5]; |
| 15383 |
char dnisno[5]; |
| 15384 |
struct dahdi_pvt *p; |
| 15385 |
openr2_context_t *r2context; |
| 15386 |
openr2_variant_t r2variant; |
| 15387 |
switch (cmd) { |
| 15388 |
case CLI_INIT: |
| 15389 |
e->command = "mfcr2 show channels [group|context]"; |
| 15390 |
e->usage = |
| 15391 |
"Usage: mfcr2 show channels [group <group> | context <context>]\n" |
| 15392 |
" Shows the DAHDI channels configured with MFC/R2 signaling.\n"; |
| 15393 |
return NULL; |
| 15394 |
case CLI_GENERATE: |
| 15395 |
return NULL; |
| 15396 |
} |
| 15397 |
if (!((a->argc == 3) || (a->argc == 5))) { |
| 15398 |
return CLI_SHOWUSAGE; |
| 15399 |
} |
| 15400 |
if (a->argc == 5) { |
| 15401 |
if (!strcasecmp(a->argv[3], "group")) { |
| 15402 |
targetnum = atoi(a->argv[4]); |
| 15403 |
if ((targetnum < 0) || (targetnum > 63)) |
| 15404 |
return CLI_SHOWUSAGE; |
| 15405 |
targetnum = 1 << targetnum; |
| 15406 |
filtertype = 1; |
| 15407 |
} else if (!strcasecmp(a->argv[3], "context")) { |
| 15408 |
filtertype = 2; |
| 15409 |
} else { |
| 15410 |
return CLI_SHOWUSAGE; |
| 15411 |
} |
| 15412 |
} |
| 15413 |
ast_cli(a->fd, FORMAT, "Chan", "Link#", "Variant", "Max ANI", "Max DNIS", "ANI First", "Immediate Accept", "Tx CAS", "Rx CAS"); |
| 15414 |
ast_mutex_lock(&iflock); |
| 15415 |
for (p = iflist; p; p = p->next) { |
| 15416 |
if (!(p->sig & SIG_MFCR2) || !p->r2chan) { |
| 15417 |
continue; |
| 15418 |
} |
| 15419 |
if (filtertype) { |
| 15420 |
switch(filtertype) { |
| 15421 |
case 1: |
| 15422 |
if (p->group != targetnum) { |
| 15423 |
continue; |
| 15424 |
} |
| 15425 |
break; |
| 15426 |
case 2: |
| 15427 |
if (strcasecmp(p->context, a->argv[4])) { |
| 15428 |
continue; |
| 15429 |
} |
| 15430 |
break; |
| 15431 |
default: |
| 15432 |
; |
| 15433 |
} |
| 15434 |
} |
| 15435 |
r2context = openr2_chan_get_context(p->r2chan); |
| 15436 |
r2variant = openr2_context_get_variant(r2context); |
| 15437 |
snprintf(channo, sizeof(channo), "%d", p->channel); |
| 15438 |
snprintf(linkno, sizeof(linkno), "%d", p->mfcr2->index); |
| 15439 |
snprintf(anino, sizeof(anino), "%d", openr2_context_get_max_ani(r2context)); |
| 15440 |
snprintf(dnisno, sizeof(dnisno), "%d", openr2_context_get_max_dnis(r2context)); |
| 15441 |
ast_cli(a->fd, FORMAT, channo, linkno, openr2_proto_get_variant_string(r2variant), |
| 15442 |
anino, dnisno, openr2_context_get_ani_first(r2context) ? "Yes" : "No", |
| 15443 |
openr2_context_get_immediate_accept(r2context) ? "Yes" : "No", |
| 15444 |
openr2_chan_get_tx_cas_string(p->r2chan), openr2_chan_get_rx_cas_string(p->r2chan)); |
| 15445 |
} |
| 15446 |
ast_mutex_unlock(&iflock); |
| 15447 |
return CLI_SUCCESS; |
| 15448 |
#undef FORMAT |
| 15449 |
} |
| 15450 |
|
| 15451 |
static char *handle_mfcr2_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15452 |
{ |
| 15453 |
struct dahdi_pvt *p = NULL; |
| 15454 |
int channo = 0; |
| 15455 |
char *toklevel = NULL; |
| 15456 |
char *saveptr = NULL; |
| 15457 |
char *logval = NULL; |
| 15458 |
openr2_log_level_t loglevel = OR2_LOG_NOTHING; |
| 15459 |
openr2_log_level_t tmplevel = OR2_LOG_NOTHING; |
| 15460 |
switch (cmd) { |
| 15461 |
case CLI_INIT: |
| 15462 |
e->command = "mfcr2 set debug"; |
| 15463 |
e->usage = |
| 15464 |
"Usage: mfcr2 set debug <loglevel> <channel>\n" |
| 15465 |
" Set a new logging level for the specified channel.\n" |
| 15466 |
" If no channel is specified the logging level will be applied to all channels.\n"; |
| 15467 |
return NULL; |
| 15468 |
case CLI_GENERATE: |
| 15469 |
return NULL; |
| 15470 |
} |
| 15471 |
if (a->argc < 4) { |
| 15472 |
return CLI_SHOWUSAGE; |
| 15473 |
} |
| 15474 |
channo = (a->argc == 5) ? atoi(a->argv[4]) : -1; |
| 15475 |
logval = ast_strdupa(a->argv[3]); |
| 15476 |
toklevel = strtok_r(logval, ",", &saveptr); |
| 15477 |
if (-1 == (tmplevel = openr2_log_get_level(toklevel))) { |
| 15478 |
ast_cli(a->fd, "Invalid MFC/R2 logging level '%s'.\n", a->argv[3]); |
| 15479 |
return CLI_FAILURE; |
| 15480 |
} else if (OR2_LOG_NOTHING == tmplevel) { |
| 15481 |
loglevel = tmplevel; |
| 15482 |
} else { |
| 15483 |
loglevel |= tmplevel; |
| 15484 |
while ((toklevel = strtok_r(NULL, ",", &saveptr))) { |
| 15485 |
if (-1 == (tmplevel = openr2_log_get_level(toklevel))) { |
| 15486 |
ast_cli(a->fd, "Ignoring invalid logging level: '%s'.\n", toklevel); |
| 15487 |
continue; |
| 15488 |
} |
| 15489 |
loglevel |= tmplevel; |
| 15490 |
} |
| 15491 |
} |
| 15492 |
ast_mutex_lock(&iflock); |
| 15493 |
for (p = iflist; p; p = p->next) { |
| 15494 |
if (!(p->sig & SIG_MFCR2) || !p->r2chan) { |
| 15495 |
continue; |
| 15496 |
} |
| 15497 |
if ((channo != -1) && (p->channel != channo )) { |
| 15498 |
continue; |
| 15499 |
} |
| 15500 |
openr2_chan_set_log_level(p->r2chan, loglevel); |
| 15501 |
if (channo != -1) { |
| 15502 |
ast_cli(a->fd, "MFC/R2 debugging set to '%s' for channel %d.\n", a->argv[3], p->channel); |
| 15503 |
break; |
| 15504 |
} |
| 15505 |
} |
| 15506 |
if ((channo != -1) && !p) { |
| 15507 |
ast_cli(a->fd, "MFC/R2 channel %d not found.\n", channo); |
| 15508 |
} |
| 15509 |
if (channo == -1) { |
| 15510 |
ast_cli(a->fd, "MFC/R2 debugging set to '%s' for all channels.\n", a->argv[3]); |
| 15511 |
} |
| 15512 |
ast_mutex_unlock(&iflock); |
| 15513 |
return CLI_SUCCESS; |
| 15514 |
} |
| 15515 |
|
| 15516 |
static char *handle_mfcr2_call_files(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15517 |
{ |
| 15518 |
struct dahdi_pvt *p = NULL; |
| 15519 |
int channo = 0; |
| 15520 |
switch (cmd) { |
| 15521 |
case CLI_INIT: |
| 15522 |
e->command = "mfcr2 call files [on|off]"; |
| 15523 |
e->usage = |
| 15524 |
"Usage: mfcr2 call files [on|off] <channel>\n" |
| 15525 |
" Enable call files creation on the specified channel.\n" |
| 15526 |
" If no channel is specified call files creation policy will be applied to all channels.\n"; |
| 15527 |
return NULL; |
| 15528 |
case CLI_GENERATE: |
| 15529 |
return NULL; |
| 15530 |
} |
| 15531 |
if (a->argc < 4) { |
| 15532 |
return CLI_SHOWUSAGE; |
| 15533 |
} |
| 15534 |
channo = (a->argc == 5) ? atoi(a->argv[4]) : -1; |
| 15535 |
ast_mutex_lock(&iflock); |
| 15536 |
for (p = iflist; p; p = p->next) { |
| 15537 |
if (!(p->sig & SIG_MFCR2) || !p->r2chan) { |
| 15538 |
continue; |
| 15539 |
} |
| 15540 |
if ((channo != -1) && (p->channel != channo )) { |
| 15541 |
continue; |
| 15542 |
} |
| 15543 |
if (ast_true(a->argv[3])) { |
| 15544 |
openr2_chan_enable_call_files(p->r2chan); |
| 15545 |
} else { |
| 15546 |
openr2_chan_disable_call_files(p->r2chan); |
| 15547 |
} |
| 15548 |
if (channo != -1) { |
| 15549 |
if (ast_true(a->argv[3])) { |
| 15550 |
ast_cli(a->fd, "MFC/R2 call files enabled for channel %d.\n", p->channel); |
| 15551 |
} else { |
| 15552 |
ast_cli(a->fd, "MFC/R2 call files disabled for channel %d.\n", p->channel); |
| 15553 |
} |
| 15554 |
break; |
| 15555 |
} |
| 15556 |
} |
| 15557 |
if ((channo != -1) && !p) { |
| 15558 |
ast_cli(a->fd, "MFC/R2 channel %d not found.\n", channo); |
| 15559 |
} |
| 15560 |
if (channo == -1) { |
| 15561 |
if (ast_true(a->argv[3])) { |
| 15562 |
ast_cli(a->fd, "MFC/R2 Call files enabled for all channels.\n"); |
| 15563 |
} else { |
| 15564 |
ast_cli(a->fd, "MFC/R2 Call files disabled for all channels.\n"); |
| 15565 |
} |
| 15566 |
} |
| 15567 |
ast_mutex_unlock(&iflock); |
| 15568 |
return CLI_SUCCESS; |
| 15569 |
} |
| 15570 |
|
| 15571 |
static char *handle_mfcr2_set_idle(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15572 |
{ |
| 15573 |
struct dahdi_pvt *p = NULL; |
| 15574 |
int channo = 0; |
| 15575 |
switch (cmd) { |
| 15576 |
case CLI_INIT: |
| 15577 |
e->command = "mfcr2 set idle"; |
| 15578 |
e->usage = |
| 15579 |
"Usage: mfcr2 set idle <channel>\n" |
| 15580 |
" DON'T USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.\n" |
| 15581 |
" Force the given channel into IDLE state.\n" |
| 15582 |
" If no channel is specified, all channels will be set to IDLE.\n"; |
| 15583 |
return NULL; |
| 15584 |
case CLI_GENERATE: |
| 15585 |
return NULL; |
| 15586 |
} |
| 15587 |
channo = (a->argc == 4) ? atoi(a->argv[3]) : -1; |
| 15588 |
ast_mutex_lock(&iflock); |
| 15589 |
for (p = iflist; p; p = p->next) { |
| 15590 |
if (!(p->sig & SIG_MFCR2) || !p->r2chan) { |
| 15591 |
continue; |
| 15592 |
} |
| 15593 |
if ((channo != -1) && (p->channel != channo )) { |
| 15594 |
continue; |
| 15595 |
} |
| 15596 |
openr2_chan_set_idle(p->r2chan); |
| 15597 |
ast_mutex_lock(&p->lock); |
| 15598 |
p->locallyblocked = 0; |
| 15599 |
p->mfcr2call = 0; |
| 15600 |
ast_mutex_unlock(&p->lock); |
| 15601 |
if (channo != -1) { |
| 15602 |
break; |
| 15603 |
} |
| 15604 |
} |
| 15605 |
if ((channo != -1) && !p) { |
| 15606 |
ast_cli(a->fd, "MFC/R2 channel %d not found.\n", channo); |
| 15607 |
} |
| 15608 |
ast_mutex_unlock(&iflock); |
| 15609 |
return CLI_SUCCESS; |
| 15610 |
} |
| 15611 |
|
| 15612 |
static char *handle_mfcr2_set_blocked(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15613 |
{ |
| 15614 |
struct dahdi_pvt *p = NULL; |
| 15615 |
int channo = 0; |
| 15616 |
switch (cmd) { |
| 15617 |
case CLI_INIT: |
| 15618 |
e->command = "mfcr2 set blocked"; |
| 15619 |
e->usage = |
| 15620 |
"Usage: mfcr2 set blocked <channel>\n" |
| 15621 |
" DON'T USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.\n" |
| 15622 |
" Force the given channel into BLOCKED state.\n" |
| 15623 |
" If no channel is specified, all channels will be set to BLOCKED.\n"; |
| 15624 |
return NULL; |
| 15625 |
case CLI_GENERATE: |
| 15626 |
return NULL; |
| 15627 |
} |
| 15628 |
channo = (a->argc == 4) ? atoi(a->argv[3]) : -1; |
| 15629 |
ast_mutex_lock(&iflock); |
| 15630 |
for (p = iflist; p; p = p->next) { |
| 15631 |
if (!(p->sig & SIG_MFCR2) || !p->r2chan) { |
| 15632 |
continue; |
| 15633 |
} |
| 15634 |
if ((channo != -1) && (p->channel != channo )) { |
| 15635 |
continue; |
| 15636 |
} |
| 15637 |
openr2_chan_set_blocked(p->r2chan); |
| 15638 |
ast_mutex_lock(&p->lock); |
| 15639 |
p->locallyblocked = 1; |
| 15640 |
ast_mutex_unlock(&p->lock); |
| 15641 |
if (channo != -1) { |
| 15642 |
break; |
| 15643 |
} |
| 15644 |
} |
| 15645 |
if ((channo != -1) && !p) { |
| 15646 |
ast_cli(a->fd, "MFC/R2 channel %d not found.\n", channo); |
| 15647 |
} |
| 15648 |
ast_mutex_unlock(&iflock); |
| 15649 |
return CLI_SUCCESS; |
| 15650 |
} |
| 15651 |
|
| 15652 |
static void mfcr2_show_links_of(struct ast_cli_args *a, struct r2links *list_head, const char *title) |
| 15653 |
{ |
| 15654 |
#define FORMAT "%-5s %-10s %-15s %-10s %s\n" |
| 15655 |
AST_LIST_LOCK(list_head); |
| 15656 |
if (! AST_LIST_EMPTY(list_head)) { |
| 15657 |
char index[5]; |
| 15658 |
char live_chans_str[5]; |
| 15659 |
char channel_list[R2_LINK_CAPACITY * 4]; |
| 15660 |
struct r2link_entry *cur; |
| 15661 |
ast_cli(a->fd, "%s\n", title); |
| 15662 |
ast_cli(a->fd, FORMAT, "Index", "Thread", "Dahdi-Device", "Channels", "Channel-List"); |
| 15663 |
AST_LIST_TRAVERSE(list_head, cur, list) { |
| 15664 |
struct dahdi_mfcr2 *mfcr2 = &cur->mfcr2; |
| 15665 |
const char *thread_status = NULL; |
| 15666 |
int i; |
| 15667 |
int len; |
| 15668 |
int inside_range; |
| 15669 |
int channo; |
| 15670 |
int prev_channo; |
| 15671 |
|
| 15672 |
if (mfcr2->r2master == 0L) { |
| 15673 |
thread_status = "zero"; |
| 15674 |
} else if (mfcr2->r2master == AST_PTHREADT_NULL) { |
| 15675 |
thread_status = "none"; |
| 15676 |
} else { |
| 15677 |
thread_status = "created"; |
| 15678 |
} |
| 15679 |
snprintf(index, sizeof(index), "%d", mfcr2->index); |
| 15680 |
snprintf(live_chans_str, sizeof(live_chans_str), "%d", mfcr2->live_chans); |
| 15681 |
channo = 0; |
| 15682 |
prev_channo = 0; |
| 15683 |
inside_range = 0; |
| 15684 |
len = 0; |
| 15685 |
|
| 15686 |
for (i = 0; i < mfcr2->numchans && len < sizeof(channel_list) - 1; i++) { |
| 15687 |
struct dahdi_pvt *p = mfcr2->pvts[i]; |
| 15688 |
if (!p) { |
| 15689 |
continue; |
| 15690 |
} |
| 15691 |
channo = p->channel; |
| 15692 |
|
| 15693 |
if (prev_channo && prev_channo == channo - 1) { |
| 15694 |
prev_channo = channo; |
| 15695 |
inside_range = 1; |
| 15696 |
continue; |
| 15697 |
} |
| 15698 |
if (inside_range) { |
| 15699 |
|
| 15700 |
len += snprintf(channel_list + len, sizeof(channel_list) - len - 1, "-%d,%d", prev_channo, channo); |
| 15701 |
inside_range = 0; |
| 15702 |
} else if (prev_channo) { |
| 15703 |
|
| 15704 |
len += snprintf(channel_list + len, sizeof(channel_list) - len - 1, ",%d", channo); |
| 15705 |
} else { |
| 15706 |
|
| 15707 |
len += snprintf(channel_list + len, sizeof(channel_list) - len - 1, "%d", channo); |
| 15708 |
} |
| 15709 |
prev_channo = channo; |
| 15710 |
} |
| 15711 |
|
| 15712 |
if (inside_range) { |
| 15713 |
|
| 15714 |
len += snprintf(channel_list + len, sizeof(channel_list) - len - 1, "-%d", channo); |
| 15715 |
inside_range = 0; |
| 15716 |
} else if (prev_channo) { |
| 15717 |
|
| 15718 |
len += snprintf(channel_list + len, sizeof(channel_list) - len - 1, ",%d", channo); |
| 15719 |
} |
| 15720 |
|
| 15721 |
ast_cli(a->fd, FORMAT, |
| 15722 |
index, |
| 15723 |
thread_status, |
| 15724 |
(mfcr2->nodev) ? "MISSING" : "OK", |
| 15725 |
live_chans_str, |
| 15726 |
channel_list); |
| 15727 |
} |
| 15728 |
} |
| 15729 |
AST_LIST_UNLOCK(list_head); |
| 15730 |
#undef FORMAT |
| 15731 |
} |
| 15732 |
|
| 15733 |
static char *handle_mfcr2_show_links(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15734 |
{ |
| 15735 |
switch (cmd) { |
| 15736 |
case CLI_INIT: |
| 15737 |
e->command = "mfcr2 show links"; |
| 15738 |
e->usage = |
| 15739 |
"Usage: mfcr2 show links\n" |
| 15740 |
" Shows the DAHDI MFC/R2 links.\n"; |
| 15741 |
return NULL; |
| 15742 |
case CLI_GENERATE: |
| 15743 |
return NULL; |
| 15744 |
} |
| 15745 |
if (a->argc != 3) { |
| 15746 |
return CLI_SHOWUSAGE; |
| 15747 |
} |
| 15748 |
mfcr2_show_links_of(a, &r2links, "Live links\n"); |
| 15749 |
mfcr2_show_links_of(a, &nodev_r2links, "Links to be removed (device missing)\n"); |
| 15750 |
return CLI_SUCCESS; |
| 15751 |
} |
| 15752 |
|
| 15753 |
static char *handle_mfcr2_destroy_link(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15754 |
{ |
| 15755 |
int res; |
| 15756 |
int wanted_link_index; |
| 15757 |
int found_link = 0; |
| 15758 |
struct r2link_entry *cur = NULL; |
| 15759 |
|
| 15760 |
switch (cmd) { |
| 15761 |
case CLI_INIT: |
| 15762 |
e->command = "mfcr2 destroy link"; |
| 15763 |
e->usage = |
| 15764 |
"Usage: mfcr2 destroy link <index-number>\n" |
| 15765 |
" Destroys D-channel of link and its B-channels.\n" |
| 15766 |
" DON'T USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.\n"; |
| 15767 |
return NULL; |
| 15768 |
case CLI_GENERATE: |
| 15769 |
return NULL; |
| 15770 |
} |
| 15771 |
if (a->argc < 4) { |
| 15772 |
return CLI_SHOWUSAGE; |
| 15773 |
} |
| 15774 |
res = sscanf(a->argv[3], "%30d", &wanted_link_index); |
| 15775 |
if ((res != 1) || wanted_link_index < 1) { |
| 15776 |
ast_cli(a->fd, |
| 15777 |
"Invalid link index '%s'. Should be a positive number\n", a->argv[3]); |
| 15778 |
return CLI_SUCCESS; |
| 15779 |
} |
| 15780 |
AST_LIST_LOCK(&r2links); |
| 15781 |
AST_LIST_TRAVERSE_SAFE_BEGIN(&r2links, cur, list) { |
| 15782 |
struct dahdi_mfcr2 *mfcr2 = &cur->mfcr2; |
| 15783 |
if (wanted_link_index == mfcr2->index) { |
| 15784 |
AST_LIST_MOVE_CURRENT(&nodev_r2links, list); |
| 15785 |
r2links_count--; |
| 15786 |
break; |
| 15787 |
} |
| 15788 |
} |
| 15789 |
AST_LIST_TRAVERSE_SAFE_END; |
| 15790 |
AST_LIST_UNLOCK(&r2links); |
| 15791 |
if (! found_link) { |
| 15792 |
ast_cli(a->fd, "No link found with index %d.\n", wanted_link_index); |
| 15793 |
return CLI_FAILURE; |
| 15794 |
} |
| 15795 |
return CLI_SUCCESS; |
| 15796 |
} |
| 15797 |
|
| 15798 |
static struct ast_cli_entry dahdi_mfcr2_cli[] = { |
| 15799 |
AST_CLI_DEFINE(handle_mfcr2_version, "Show OpenR2 library version"), |
| 15800 |
AST_CLI_DEFINE(handle_mfcr2_show_variants, "Show supported MFC/R2 variants"), |
| 15801 |
AST_CLI_DEFINE(handle_mfcr2_show_channels, "Show MFC/R2 channels"), |
| 15802 |
AST_CLI_DEFINE(handle_mfcr2_show_links, "Show MFC/R2 links"), |
| 15803 |
AST_CLI_DEFINE(handle_mfcr2_set_debug, "Set MFC/R2 channel logging level"), |
| 15804 |
AST_CLI_DEFINE(handle_mfcr2_call_files, "Enable/Disable MFC/R2 call files"), |
| 15805 |
AST_CLI_DEFINE(handle_mfcr2_set_idle, "Reset MFC/R2 channel forcing it to IDLE"), |
| 15806 |
AST_CLI_DEFINE(handle_mfcr2_set_blocked, "Reset MFC/R2 channel forcing it to BLOCKED"), |
| 15807 |
AST_CLI_DEFINE(handle_mfcr2_destroy_link, "Destroy given MFC/R2 link"), |
| 15808 |
}; |
| 15809 |
|
| 15810 |
#endif |
| 15811 |
|
| 15812 |
static char *dahdi_destroy_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15813 |
{ |
| 15814 |
int start; |
| 15815 |
int end; |
| 15816 |
switch (cmd) { |
| 15817 |
case CLI_INIT: |
| 15818 |
e->command = "dahdi destroy channels"; |
| 15819 |
e->usage = |
| 15820 |
"Usage: dahdi destroy channels <from_channel> [<to_channel>]\n" |
| 15821 |
" DON'T USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING. Immediately removes a given channel, whether it is in use or not\n"; |
| 15822 |
return NULL; |
| 15823 |
case CLI_GENERATE: |
| 15824 |
return NULL; |
| 15825 |
} |
| 15826 |
if ((a->argc < 4) || a->argc > 5) { |
| 15827 |
return CLI_SHOWUSAGE; |
| 15828 |
} |
| 15829 |
start = atoi(a->argv[3]); |
| 15830 |
if (start < 1) { |
| 15831 |
ast_cli(a->fd, "Invalid starting channel number %s.\n", |
| 15832 |
a->argv[4]); |
| 15833 |
return CLI_FAILURE; |
| 15834 |
} |
| 15835 |
if (a->argc == 5) { |
| 15836 |
end = atoi(a->argv[4]); |
| 15837 |
if (end < 1) { |
| 15838 |
ast_cli(a->fd, "Invalid ending channel number %s.\n", |
| 15839 |
a->argv[4]); |
| 15840 |
return CLI_FAILURE; |
| 15841 |
} |
| 15842 |
} else { |
| 15843 |
end = start; |
| 15844 |
} |
| 15845 |
|
| 15846 |
if (end < start) { |
| 15847 |
ast_cli(a->fd, |
| 15848 |
"range end (%d) is smaller than range start (%d)\n", |
| 15849 |
end, start); |
| 15850 |
return CLI_FAILURE; |
| 15851 |
} |
| 15852 |
dahdi_destroy_channel_range(start, end); |
| 15853 |
return CLI_SUCCESS; |
| 15854 |
} |
| 15855 |
|
| 15856 |
static char *dahdi_create_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 15857 |
{ |
| 15858 |
int start; |
| 15859 |
int end; |
| 15860 |
int ret; |
| 15861 |
|
| 15862 |
switch (cmd) { |
| 15863 |
case CLI_INIT: |
| 15864 |
e->command = "dahdi create channels"; |
| 15865 |
e->usage = "Usage: dahdi create channels <from> [<to>] - a range of channels\n" |
| 15866 |
" dahdi create channels new - add channels not yet created\n" |
| 15867 |
"For ISDN and SS7 the range should include complete spans.\n"; |
| 15868 |
return NULL; |
| 15869 |
case CLI_GENERATE: |
| 15870 |
return NULL; |
| 15871 |
} |
| 15872 |
if ((a->argc < 4) || a->argc > 5) { |
| 15873 |
return CLI_SHOWUSAGE; |
| 15874 |
} |
| 15875 |
if (a->argc == 4 && !strcmp(a->argv[3], "new")) { |
| 15876 |
ret = dahdi_create_channel_range(0, 0); |
| 15877 |
return (RESULT_SUCCESS == ret) ? CLI_SUCCESS : CLI_FAILURE; |
| 15878 |
} |
| 15879 |
start = atoi(a->argv[3]); |
| 15880 |
if (start <= 0) { |
| 15881 |
ast_cli(a->fd, "Invalid starting channel number '%s'.\n", |
| 15882 |
a->argv[3]); |
| 15883 |
return CLI_FAILURE; |
| 15884 |
} |
| 15885 |
if (a->argc == 5) { |
| 15886 |
end = atoi(a->argv[4]); |
| 15887 |
if (end <= 0) { |
| 15888 |
ast_cli(a->fd, "Invalid ending channel number '%s'.\n", |
| 15889 |
a->argv[4]); |
| 15890 |
return CLI_FAILURE; |
| 15891 |
} |
| 15892 |
} else { |
| 15893 |
end = start; |
| 15894 |
} |
| 15895 |
if (end < start) { |
| 15896 |
ast_cli(a->fd, |
| 15897 |
"range end (%d) is smaller than range start (%d)\n", |
| 15898 |
end, start); |
| 15899 |
return CLI_FAILURE; |
| 15900 |
} |
| 15901 |
ret = dahdi_create_channel_range(start, end); |
| 15902 |
return (RESULT_SUCCESS == ret) ? CLI_SUCCESS : CLI_FAILURE; |
| 15903 |
} |
| 15904 |
|
| 15905 |
static void dahdi_softhangup_all(void) |
| 15906 |
{ |
| 15907 |
struct dahdi_pvt *p; |
| 15908 |
retry: |
| 15909 |
ast_mutex_lock(&iflock); |
| 15910 |
for (p = iflist; p; p = p->next) { |
| 15911 |
ast_mutex_lock(&p->lock); |
| 15912 |
if (p->owner && !p->restartpending) { |
| 15913 |
if (ast_channel_trylock(p->owner)) { |
| 15914 |
if (DEBUG_ATLEAST(3)) |
| 15915 |
ast_verbose("Avoiding deadlock\n"); |
| 15916 |
|
| 15917 |
ast_mutex_unlock(&p->lock); |
| 15918 |
ast_mutex_unlock(&iflock); |
| 15919 |
goto retry; |
| 15920 |
} |
| 15921 |
if (DEBUG_ATLEAST(3)) |
| 15922 |
ast_verbose("Softhanging up on %s\n", ast_channel_name(p->owner)); |
| 15923 |
ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_EXPLICIT); |
| 15924 |
p->restartpending = 1; |
| 15925 |
num_restart_pending++; |
| 15926 |
ast_channel_unlock(p->owner); |
| 15927 |
} |
| 15928 |
ast_mutex_unlock(&p->lock); |
| 15929 |
} |
| 15930 |
ast_mutex_unlock(&iflock); |
| 15931 |
} |
| 15932 |
|
| 15933 |
static int dahdi_restart(void) |
| 15934 |
{ |
| 15935 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 15936 |
int i, j; |
| 15937 |
#endif |
| 15938 |
int cancel_code; |
| 15939 |
struct dahdi_pvt *p; |
| 15940 |
|
| 15941 |
ast_mutex_lock(&restart_lock); |
| 15942 |
ast_verb(1, "Destroying channels and reloading DAHDI configuration.\n"); |
| 15943 |
dahdi_softhangup_all(); |
| 15944 |
ast_verb(4, "Initial softhangup of all DAHDI channels complete.\n"); |
| 15945 |
#ifdef HAVE_OPENR2 |
| 15946 |
dahdi_r2_destroy_links(); |
| 15947 |
#endif |
| 15948 |
|
| 15949 |
#if defined(HAVE_PRI) |
| 15950 |
for (i = 0; i < NUM_SPANS; i++) { |
| 15951 |
if (pris[i].pri.master && (pris[i].pri.master != AST_PTHREADT_NULL)) { |
| 15952 |
cancel_code = pthread_cancel(pris[i].pri.master); |
| 15953 |
pthread_kill(pris[i].pri.master, SIGURG); |
| 15954 |
ast_debug(4, "Waiting to join thread of span %d with pid=%p, cancel_code=%d\n", i, (void *) pris[i].pri.master, cancel_code); |
| 15955 |
pthread_join(pris[i].pri.master, NULL); |
| 15956 |
ast_debug(4, "Joined thread of span %d\n", i); |
| 15957 |
} |
| 15958 |
} |
| 15959 |
#endif |
| 15960 |
|
| 15961 |
#if defined(HAVE_SS7) |
| 15962 |
for (i = 0; i < NUM_SPANS; i++) { |
| 15963 |
if (linksets[i].ss7.master && (linksets[i].ss7.master != AST_PTHREADT_NULL)) { |
| 15964 |
cancel_code = pthread_cancel(linksets[i].ss7.master); |
| 15965 |
pthread_kill(linksets[i].ss7.master, SIGURG); |
| 15966 |
ast_debug(4, "Waiting to join thread of span %d with pid=%p, cancel_code=%d\n", i, (void *) linksets[i].ss7.master, cancel_code); |
| 15967 |
pthread_join(linksets[i].ss7.master, NULL); |
| 15968 |
ast_debug(4, "Joined thread of span %d\n", i); |
| 15969 |
} |
| 15970 |
} |
| 15971 |
#endif |
| 15972 |
|
| 15973 |
ast_mutex_lock(&monlock); |
| 15974 |
if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) { |
| 15975 |
cancel_code = pthread_cancel(monitor_thread); |
| 15976 |
pthread_kill(monitor_thread, SIGURG); |
| 15977 |
ast_debug(4, "Waiting to join monitor thread with pid=%p, cancel_code=%d\n", (void *) monitor_thread, cancel_code); |
| 15978 |
pthread_join(monitor_thread, NULL); |
| 15979 |
ast_debug(4, "Joined monitor thread\n"); |
| 15980 |
} |
| 15981 |
monitor_thread = AST_PTHREADT_NULL; |
| 15982 |
|
| 15983 |
ast_mutex_lock(&ss_thread_lock); |
| 15984 |
while (ss_thread_count > 0) { |
| 15985 |
int x = DAHDI_FLASH; |
| 15986 |
ast_debug(3, "Waiting on %d analog_ss_thread(s) to finish\n", ss_thread_count); |
| 15987 |
|
| 15988 |
ast_mutex_lock(&iflock); |
| 15989 |
for (p = iflist; p; p = p->next) { |
| 15990 |
if (p->owner) { |
| 15991 |
|
| 15992 |
ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x); |
| 15993 |
} |
| 15994 |
} |
| 15995 |
ast_mutex_unlock(&iflock); |
| 15996 |
ast_cond_wait(&ss_thread_complete, &ss_thread_lock); |
| 15997 |
} |
| 15998 |
|
| 15999 |
|
| 16000 |
dahdi_softhangup_all(); |
| 16001 |
ast_verb(4, "Final softhangup of all DAHDI channels complete.\n"); |
| 16002 |
destroy_all_channels(); |
| 16003 |
memset(round_robin, 0, sizeof(round_robin)); |
| 16004 |
ast_debug(1, "Channels destroyed. Now re-reading config. %d active channels remaining.\n", ast_active_channels()); |
| 16005 |
|
| 16006 |
ast_mutex_unlock(&monlock); |
| 16007 |
|
| 16008 |
#ifdef HAVE_PRI |
| 16009 |
for (i = 0; i < NUM_SPANS; i++) { |
| 16010 |
for (j = 0; j < SIG_PRI_NUM_DCHANS; j++) |
| 16011 |
dahdi_close_pri_fd(&(pris[i]), j); |
| 16012 |
} |
| 16013 |
|
| 16014 |
memset(pris, 0, sizeof(pris)); |
| 16015 |
for (i = 0; i < NUM_SPANS; i++) { |
| 16016 |
sig_pri_init_pri(&pris[i].pri); |
| 16017 |
} |
| 16018 |
pri_set_error(dahdi_pri_error); |
| 16019 |
pri_set_message(dahdi_pri_message); |
| 16020 |
#endif |
| 16021 |
#if defined(HAVE_SS7) |
| 16022 |
for (i = 0; i < NUM_SPANS; i++) { |
| 16023 |
for (j = 0; j < SIG_SS7_NUM_DCHANS; j++) |
| 16024 |
dahdi_close_ss7_fd(&(linksets[i]), j); |
| 16025 |
} |
| 16026 |
|
| 16027 |
memset(linksets, 0, sizeof(linksets)); |
| 16028 |
for (i = 0; i < NUM_SPANS; i++) { |
| 16029 |
sig_ss7_init_linkset(&linksets[i].ss7); |
| 16030 |
} |
| 16031 |
ss7_set_error(dahdi_ss7_error); |
| 16032 |
ss7_set_message(dahdi_ss7_message); |
| 16033 |
ss7_set_hangup(sig_ss7_cb_hangup); |
| 16034 |
ss7_set_notinservice(sig_ss7_cb_notinservice); |
| 16035 |
ss7_set_call_null(sig_ss7_cb_call_null); |
| 16036 |
#endif |
| 16037 |
|
| 16038 |
if (setup_dahdi(2) != 0) { |
| 16039 |
ast_log(LOG_WARNING, "Reload channels from dahdi config failed!\n"); |
| 16040 |
ast_mutex_unlock(&ss_thread_lock); |
| 16041 |
return 1; |
| 16042 |
} |
| 16043 |
ast_mutex_unlock(&ss_thread_lock); |
| 16044 |
ast_mutex_unlock(&restart_lock); |
| 16045 |
return 0; |
| 16046 |
} |
| 16047 |
|
| 16048 |
static char *dahdi_restart_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 16049 |
{ |
| 16050 |
switch (cmd) { |
| 16051 |
case CLI_INIT: |
| 16052 |
e->command = "dahdi restart"; |
| 16053 |
e->usage = |
| 16054 |
"Usage: dahdi restart\n" |
| 16055 |
" Restarts the DAHDI channels: destroys them all and then\n" |
| 16056 |
" re-reads them from chan_dahdi.conf.\n" |
| 16057 |
" Note that this will STOP any running CALL on DAHDI channels.\n" |
| 16058 |
""; |
| 16059 |
return NULL; |
| 16060 |
case CLI_GENERATE: |
| 16061 |
return NULL; |
| 16062 |
} |
| 16063 |
if (a->argc != 2) |
| 16064 |
return CLI_SHOWUSAGE; |
| 16065 |
|
| 16066 |
if (dahdi_restart() != 0) |
| 16067 |
return CLI_FAILURE; |
| 16068 |
return CLI_SUCCESS; |
| 16069 |
} |
| 16070 |
|
| 16071 |
static int action_dahdirestart(struct mansession *s, const struct message *m) |
| 16072 |
{ |
| 16073 |
if (dahdi_restart() != 0) { |
| 16074 |
astman_send_error(s, m, "Failed rereading DAHDI configuration"); |
| 16075 |
return 1; |
| 16076 |
} |
| 16077 |
astman_send_ack(s, m, "DAHDIRestart: Success"); |
| 16078 |
return 0; |
| 16079 |
} |
| 16080 |
|
| 16081 |
static char *dahdi_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 16082 |
{ |
| 16083 |
#define FORMAT "%7s %4d %-20.20s %-10.10s %-15.15s %-8.8s %-20.20s %-10.10s %-10.10s %-12.12s %-32.32s\n" |
| 16084 |
#define FORMAT2 "%7s %4s %-20.20s %-10.10s %-15.15s %-8.8s %-20.20s %-10.10s %-10.10s %-12.12s %-32.32s\n" |
| 16085 |
ast_group_t targetnum = 0; |
| 16086 |
int filtertype = 0; |
| 16087 |
struct dahdi_pvt *tmp = NULL; |
| 16088 |
char tmps[20]; |
| 16089 |
char blockstr[20]; |
| 16090 |
|
| 16091 |
switch (cmd) { |
| 16092 |
case CLI_INIT: |
| 16093 |
e->command = "dahdi show channels [group|context]"; |
| 16094 |
e->usage = |
| 16095 |
"Usage: dahdi show channels [ group <group> | context <context> ]\n" |
| 16096 |
" Shows a list of available channels with optional filtering\n" |
| 16097 |
" <group> must be a number between 0 and 63\n"; |
| 16098 |
return NULL; |
| 16099 |
case CLI_GENERATE: |
| 16100 |
return NULL; |
| 16101 |
} |
| 16102 |
|
| 16103 |
|
| 16104 |
|
| 16105 |
if (!((a->argc == 3) || (a->argc == 5))) { |
| 16106 |
return CLI_SHOWUSAGE; |
| 16107 |
} |
| 16108 |
|
| 16109 |
if (a->argc == 5) { |
| 16110 |
if (!strcasecmp(a->argv[3], "group")) { |
| 16111 |
targetnum = atoi(a->argv[4]); |
| 16112 |
if (63 < targetnum) { |
| 16113 |
return CLI_SHOWUSAGE; |
| 16114 |
} |
| 16115 |
targetnum = ((ast_group_t) 1) << targetnum; |
| 16116 |
filtertype = 1; |
| 16117 |
} else if (!strcasecmp(a->argv[3], "context")) { |
| 16118 |
filtertype = 2; |
| 16119 |
} |
| 16120 |
} |
| 16121 |
|
| 16122 |
ast_cli(a->fd, FORMAT2, "Chan", "Span", "Signalling", "Extension", "Context", "Language", "MOH Interpret", "Blocked", "In Service", "Alarms", "Description"); |
| 16123 |
ast_mutex_lock(&iflock); |
| 16124 |
for (tmp = iflist; tmp; tmp = tmp->next) { |
| 16125 |
int alm = 0; |
| 16126 |
if (filtertype) { |
| 16127 |
switch(filtertype) { |
| 16128 |
case 1: |
| 16129 |
if (!(tmp->group & targetnum)) { |
| 16130 |
continue; |
| 16131 |
} |
| 16132 |
break; |
| 16133 |
case 2: |
| 16134 |
if (strcasecmp(tmp->context, a->argv[4])) { |
| 16135 |
continue; |
| 16136 |
} |
| 16137 |
break; |
| 16138 |
default: |
| 16139 |
break; |
| 16140 |
} |
| 16141 |
} |
| 16142 |
if (tmp->channel > 0) { |
| 16143 |
snprintf(tmps, sizeof(tmps), "%d", tmp->channel); |
| 16144 |
alm = get_alarms(tmp); |
| 16145 |
} else { |
| 16146 |
ast_copy_string(tmps, "pseudo", sizeof(tmps)); |
| 16147 |
} |
| 16148 |
|
| 16149 |
blockstr[0] = tmp->locallyblocked ? 'L' : ' '; |
| 16150 |
blockstr[1] = tmp->remotelyblocked ? 'R' : ' '; |
| 16151 |
blockstr[2] = '\0'; |
| 16152 |
|
| 16153 |
ast_cli(a->fd, FORMAT, tmps, tmp->span, sig2str(tmp->sig), tmp->exten, tmp->context, tmp->language, tmp->mohinterpret, blockstr, tmp->inservice ? "Yes" : "No", |
| 16154 |
alarm2str(alm), tmp->description); |
| 16155 |
} |
| 16156 |
ast_mutex_unlock(&iflock); |
| 16157 |
return CLI_SUCCESS; |
| 16158 |
#undef FORMAT |
| 16159 |
#undef FORMAT2 |
| 16160 |
} |
| 16161 |
|
| 16162 |
static char *dahdi_show_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 16163 |
{ |
| 16164 |
int channel; |
| 16165 |
struct dahdi_pvt *tmp = NULL; |
| 16166 |
struct dahdi_confinfo ci; |
| 16167 |
struct dahdi_params ps; |
| 16168 |
int x; |
| 16169 |
char hwrxgain[15]; |
| 16170 |
char hwtxgain[15]; |
| 16171 |
|
| 16172 |
switch (cmd) { |
| 16173 |
case CLI_INIT: |
| 16174 |
e->command = "dahdi show channel"; |
| 16175 |
e->usage = |
| 16176 |
"Usage: dahdi show channel <chan num>\n" |
| 16177 |
" Detailed information about a given channel\n"; |
| 16178 |
return NULL; |
| 16179 |
case CLI_GENERATE: |
| 16180 |
return NULL; |
| 16181 |
} |
| 16182 |
|
| 16183 |
if (a->argc != 4) |
| 16184 |
return CLI_SHOWUSAGE; |
| 16185 |
|
| 16186 |
channel = atoi(a->argv[3]); |
| 16187 |
|
| 16188 |
ast_mutex_lock(&iflock); |
| 16189 |
for (tmp = iflist; tmp; tmp = tmp->next) { |
| 16190 |
if (tmp->channel == channel) { |
| 16191 |
ast_cli(a->fd, "Channel: %d\n", tmp->channel); |
| 16192 |
ast_cli(a->fd, "Description: %s\n", tmp->description); |
| 16193 |
ast_cli(a->fd, "File Descriptor: %d\n", tmp->subs[SUB_REAL].dfd); |
| 16194 |
ast_cli(a->fd, "Span: %d\n", tmp->span); |
| 16195 |
ast_cli(a->fd, "Extension: %s\n", tmp->exten); |
| 16196 |
ast_cli(a->fd, "Dialing: %s\n", tmp->dialing ? "yes" : "no"); |
| 16197 |
ast_cli(a->fd, "Context: %s\n", tmp->context); |
| 16198 |
ast_cli(a->fd, "Caller ID: %s\n", tmp->cid_num); |
| 16199 |
ast_cli(a->fd, "Calling TON: %d\n", tmp->cid_ton); |
| 16200 |
#if defined(HAVE_PRI) |
| 16201 |
#if defined(HAVE_PRI_SUBADDR) |
| 16202 |
ast_cli(a->fd, "Caller ID subaddress: %s\n", tmp->cid_subaddr); |
| 16203 |
#endif |
| 16204 |
#endif |
| 16205 |
ast_cli(a->fd, "Caller ID name: %s\n", tmp->cid_name); |
| 16206 |
ast_cli(a->fd, "Mailbox: %s\n", S_OR(tmp->mailbox, "none")); |
| 16207 |
if (tmp->vars) { |
| 16208 |
struct ast_variable *v; |
| 16209 |
ast_cli(a->fd, "Variables:\n"); |
| 16210 |
for (v = tmp->vars ; v ; v = v->next) |
| 16211 |
ast_cli(a->fd, " %s = %s\n", v->name, v->value); |
| 16212 |
} |
| 16213 |
ast_cli(a->fd, "Destroy: %d\n", tmp->destroy); |
| 16214 |
ast_cli(a->fd, "InAlarm: %d\n", tmp->inalarm); |
| 16215 |
ast_cli(a->fd, "Signalling Type: %s\n", sig2str(tmp->sig)); |
| 16216 |
ast_cli(a->fd, "Radio: %d\n", tmp->radio); |
| 16217 |
ast_cli(a->fd, "Owner: %s\n", tmp->owner ? ast_channel_name(tmp->owner) : "<None>"); |
| 16218 |
ast_cli(a->fd, "Real: %s%s%s\n", tmp->subs[SUB_REAL].owner ? ast_channel_name(tmp->subs[SUB_REAL].owner) : "<None>", tmp->subs[SUB_REAL].inthreeway ? " (Confed)" : "", tmp->subs[SUB_REAL].linear ? " (Linear)" : ""); |
| 16219 |
ast_cli(a->fd, "Callwait: %s%s%s\n", tmp->subs[SUB_CALLWAIT].owner ? ast_channel_name(tmp->subs[SUB_CALLWAIT].owner) : "<None>", tmp->subs[SUB_CALLWAIT].inthreeway ? " (Confed)" : "", tmp->subs[SUB_CALLWAIT].linear ? " (Linear)" : ""); |
| 16220 |
ast_cli(a->fd, "Threeway: %s%s%s\n", tmp->subs[SUB_THREEWAY].owner ? ast_channel_name(tmp->subs[SUB_THREEWAY].owner) : "<None>", tmp->subs[SUB_THREEWAY].inthreeway ? " (Confed)" : "", tmp->subs[SUB_THREEWAY].linear ? " (Linear)" : ""); |
| 16221 |
ast_cli(a->fd, "Confno: %d\n", tmp->confno); |
| 16222 |
ast_cli(a->fd, "Propagated Conference: %d\n", tmp->propconfno); |
| 16223 |
ast_cli(a->fd, "Real in conference: %d\n", tmp->inconference); |
| 16224 |
ast_cli(a->fd, "DSP: %s\n", tmp->dsp ? "yes" : "no"); |
| 16225 |
ast_cli(a->fd, "Busy Detection: %s\n", tmp->busydetect ? "yes" : "no"); |
| 16226 |
if (tmp->busydetect) { |
| 16227 |
#if defined(BUSYDETECT_TONEONLY) |
| 16228 |
ast_cli(a->fd, " Busy Detector Helper: BUSYDETECT_TONEONLY\n"); |
| 16229 |
#elif defined(BUSYDETECT_COMPARE_TONE_AND_SILENCE) |
| 16230 |
ast_cli(a->fd, " Busy Detector Helper: BUSYDETECT_COMPARE_TONE_AND_SILENCE\n"); |
| 16231 |
#endif |
| 16232 |
#ifdef BUSYDETECT_DEBUG |
| 16233 |
ast_cli(a->fd, " Busy Detector Debug: Enabled\n"); |
| 16234 |
#endif |
| 16235 |
ast_cli(a->fd, " Busy Count: %d\n", tmp->busycount); |
| 16236 |
ast_cli(a->fd, " Busy Pattern: %d,%d,%d,%d\n", tmp->busy_cadence.pattern[0], tmp->busy_cadence.pattern[1], (tmp->busy_cadence.length == 4) ? tmp->busy_cadence.pattern[2] : 0, (tmp->busy_cadence.length == 4) ? tmp->busy_cadence.pattern[3] : 0); |
| 16237 |
} |
| 16238 |
ast_cli(a->fd, "TDD: %s\n", tmp->tdd ? "yes" : "no"); |
| 16239 |
ast_cli(a->fd, "Relax DTMF: %s\n", tmp->dtmfrelax ? "yes" : "no"); |
| 16240 |
ast_cli(a->fd, "Dialing/CallwaitCAS: %d/%d\n", tmp->dialing, tmp->callwaitcas); |
| 16241 |
ast_cli(a->fd, "Default law: %s\n", tmp->law_default == DAHDI_LAW_MULAW ? "ulaw" : tmp->law_default == DAHDI_LAW_ALAW ? "alaw" : "unknown"); |
| 16242 |
ast_cli(a->fd, "Fax Handled: %s\n", tmp->faxhandled ? "yes" : "no"); |
| 16243 |
ast_cli(a->fd, "Pulse phone: %s\n", tmp->pulsedial ? "yes" : "no"); |
| 16244 |
if (tmp->hwrxgain_enabled) { |
| 16245 |
snprintf(hwrxgain, sizeof(hwrxgain), "%.1f", tmp->hwrxgain); |
| 16246 |
} else { |
| 16247 |
ast_copy_string(hwrxgain, "Disabled", sizeof(hwrxgain)); |
| 16248 |
} |
| 16249 |
if (tmp->hwtxgain_enabled) { |
| 16250 |
snprintf(hwtxgain, sizeof(hwtxgain), "%.1f", tmp->hwtxgain); |
| 16251 |
} else { |
| 16252 |
ast_copy_string(hwtxgain, "Disabled", sizeof(hwtxgain)); |
| 16253 |
} |
| 16254 |
ast_cli(a->fd, "HW Gains (RX/TX): %s/%s\n", hwrxgain, hwtxgain); |
| 16255 |
ast_cli(a->fd, "SW Gains (RX/TX): %.2f/%.2f\n", tmp->rxgain, tmp->txgain); |
| 16256 |
ast_cli(a->fd, "Dynamic Range Compression (RX/TX): %.2f/%.2f\n", tmp->rxdrc, tmp->txdrc); |
| 16257 |
ast_cli(a->fd, "DND: %s\n", dahdi_dnd(tmp, -1) ? "yes" : "no"); |
| 16258 |
ast_cli(a->fd, "Echo Cancellation:\n"); |
| 16259 |
|
| 16260 |
if (tmp->echocancel.head.tap_length) { |
| 16261 |
ast_cli(a->fd, "\t%u taps\n", tmp->echocancel.head.tap_length); |
| 16262 |
for (x = 0; x < tmp->echocancel.head.param_count; x++) { |
| 16263 |
ast_cli(a->fd, "\t\t%s: %dd\n", tmp->echocancel.params[x].name, tmp->echocancel.params[x].value); |
| 16264 |
} |
| 16265 |
ast_cli(a->fd, "\t%scurrently %s\n", tmp->echocanbridged ? "" : "(unless TDM bridged) ", tmp->echocanon ? "ON" : "OFF"); |
| 16266 |
} else { |
| 16267 |
ast_cli(a->fd, "\tnone\n"); |
| 16268 |
} |
| 16269 |
ast_cli(a->fd, "Wait for dialtone: %dms\n", tmp->waitfordialtone); |
| 16270 |
if (tmp->master) |
| 16271 |
ast_cli(a->fd, "Master Channel: %d\n", tmp->master->channel); |
| 16272 |
for (x = 0; x < MAX_SLAVES; x++) { |
| 16273 |
if (tmp->slaves[x]) |
| 16274 |
ast_cli(a->fd, "Slave Channel: %d\n", tmp->slaves[x]->channel); |
| 16275 |
} |
| 16276 |
#ifdef HAVE_OPENR2 |
| 16277 |
if (tmp->mfcr2) { |
| 16278 |
char calldir[OR2_MAX_PATH]; |
| 16279 |
openr2_context_t *r2context = openr2_chan_get_context(tmp->r2chan); |
| 16280 |
openr2_variant_t r2variant = openr2_context_get_variant(r2context); |
| 16281 |
ast_cli(a->fd, "MFC/R2 MF State: %s\n", openr2_chan_get_mf_state_string(tmp->r2chan)); |
| 16282 |
ast_cli(a->fd, "MFC/R2 MF Group: %s\n", openr2_chan_get_mf_group_string(tmp->r2chan)); |
| 16283 |
ast_cli(a->fd, "MFC/R2 State: %s\n", openr2_chan_get_r2_state_string(tmp->r2chan)); |
| 16284 |
ast_cli(a->fd, "MFC/R2 Call State: %s\n", openr2_chan_get_call_state_string(tmp->r2chan)); |
| 16285 |
ast_cli(a->fd, "MFC/R2 Call Files Enabled: %s\n", openr2_chan_get_call_files_enabled(tmp->r2chan) ? "Yes" : "No"); |
| 16286 |
ast_cli(a->fd, "MFC/R2 Variant: %s\n", openr2_proto_get_variant_string(r2variant)); |
| 16287 |
ast_cli(a->fd, "MFC/R2 Max ANI: %d\n", openr2_context_get_max_ani(r2context)); |
| 16288 |
ast_cli(a->fd, "MFC/R2 Max DNIS: %d\n", openr2_context_get_max_dnis(r2context)); |
| 16289 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2 |
| 16290 |
ast_cli(a->fd, "MFC/R2 DTMF Dialing: %s\n", openr2_context_get_dtmf_dialing(r2context, NULL, NULL) ? "Yes" : "No"); |
| 16291 |
ast_cli(a->fd, "MFC/R2 DTMF Detection: %s\n", openr2_context_get_dtmf_detection(r2context) ? "Yes" : "No"); |
| 16292 |
#endif |
| 16293 |
ast_cli(a->fd, "MFC/R2 Get ANI First: %s\n", openr2_context_get_ani_first(r2context) ? "Yes" : "No"); |
| 16294 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1 |
| 16295 |
ast_cli(a->fd, "MFC/R2 Skip Category Request: %s\n", openr2_context_get_skip_category_request(r2context) ? "Yes" : "No"); |
| 16296 |
#endif |
| 16297 |
ast_cli(a->fd, "MFC/R2 Immediate Accept: %s\n", openr2_context_get_immediate_accept(r2context) ? "Yes" : "No"); |
| 16298 |
ast_cli(a->fd, "MFC/R2 Accept on Offer: %s\n", tmp->mfcr2_accept_on_offer ? "Yes" : "No"); |
| 16299 |
ast_cli(a->fd, "MFC/R2 Charge Calls: %s\n", tmp->mfcr2_charge_calls ? "Yes" : "No"); |
| 16300 |
ast_cli(a->fd, "MFC/R2 Allow Collect Calls: %s\n", tmp->mfcr2_allow_collect_calls ? "Yes" : "No"); |
| 16301 |
ast_cli(a->fd, "MFC/R2 Forced Release: %s\n", tmp->mfcr2_forced_release ? "Yes" : "No"); |
| 16302 |
ast_cli(a->fd, "MFC/R2 MF Back Timeout: %dms\n", openr2_context_get_mf_back_timeout(r2context)); |
| 16303 |
ast_cli(a->fd, "MFC/R2 R2 Metering Pulse Timeout: %dms\n", openr2_context_get_metering_pulse_timeout(r2context)); |
| 16304 |
ast_cli(a->fd, "MFC/R2 Rx CAS: %s\n", openr2_chan_get_rx_cas_string(tmp->r2chan)); |
| 16305 |
ast_cli(a->fd, "MFC/R2 Tx CAS: %s\n", openr2_chan_get_tx_cas_string(tmp->r2chan)); |
| 16306 |
ast_cli(a->fd, "MFC/R2 MF Tx Signal: %d\n", openr2_chan_get_tx_mf_signal(tmp->r2chan)); |
| 16307 |
ast_cli(a->fd, "MFC/R2 MF Rx Signal: %d\n", openr2_chan_get_rx_mf_signal(tmp->r2chan)); |
| 16308 |
ast_cli(a->fd, "MFC/R2 Call Files Directory: %s\n", openr2_context_get_log_directory(r2context, calldir, sizeof(calldir))); |
| 16309 |
} |
| 16310 |
#endif |
| 16311 |
#if defined(HAVE_SS7) |
| 16312 |
if (tmp->ss7) { |
| 16313 |
struct sig_ss7_chan *chan = tmp->sig_pvt; |
| 16314 |
|
| 16315 |
ast_cli(a->fd, "CIC: %d\n", chan->cic); |
| 16316 |
} |
| 16317 |
#endif |
| 16318 |
#ifdef HAVE_PRI |
| 16319 |
if (tmp->pri) { |
| 16320 |
struct sig_pri_chan *chan = tmp->sig_pvt; |
| 16321 |
|
| 16322 |
ast_cli(a->fd, "PRI Flags: "); |
| 16323 |
if (chan->resetting != SIG_PRI_RESET_IDLE) { |
| 16324 |
ast_cli(a->fd, "Resetting=%u ", chan->resetting); |
| 16325 |
} |
| 16326 |
if (chan->call) |
| 16327 |
ast_cli(a->fd, "Call "); |
| 16328 |
if (chan->allocated) { |
| 16329 |
ast_cli(a->fd, "Allocated "); |
| 16330 |
} |
| 16331 |
ast_cli(a->fd, "\n"); |
| 16332 |
if (tmp->logicalspan) |
| 16333 |
ast_cli(a->fd, "PRI Logical Span: %d\n", tmp->logicalspan); |
| 16334 |
else |
| 16335 |
ast_cli(a->fd, "PRI Logical Span: Implicit\n"); |
| 16336 |
} |
| 16337 |
#endif |
| 16338 |
memset(&ci, 0, sizeof(ci)); |
| 16339 |
ps.channo = tmp->channel; |
| 16340 |
if (tmp->subs[SUB_REAL].dfd > -1) { |
| 16341 |
memset(&ci, 0, sizeof(ci)); |
| 16342 |
if (!ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GETCONF, &ci)) { |
| 16343 |
ast_cli(a->fd, "Actual Confinfo: Num/%d, Mode/0x%04x\n", ci.confno, (unsigned)ci.confmode); |
| 16344 |
} |
| 16345 |
if (!ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GETCONFMUTE, &x)) { |
| 16346 |
ast_cli(a->fd, "Actual Confmute: %s\n", x ? "Yes" : "No"); |
| 16347 |
} |
| 16348 |
memset(&ps, 0, sizeof(ps)); |
| 16349 |
if (ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &ps) < 0) { |
| 16350 |
ast_log(LOG_WARNING, "Failed to get parameters on channel %d: %s\n", tmp->channel, strerror(errno)); |
| 16351 |
} else { |
| 16352 |
ast_cli(a->fd, "Hookstate (FXS only): %s\n", ps.rxisoffhook ? "Offhook" : "Onhook"); |
| 16353 |
} |
| 16354 |
} |
| 16355 |
ast_mutex_unlock(&iflock); |
| 16356 |
return CLI_SUCCESS; |
| 16357 |
} |
| 16358 |
} |
| 16359 |
ast_mutex_unlock(&iflock); |
| 16360 |
|
| 16361 |
ast_cli(a->fd, "Unable to find given channel %d\n", channel); |
| 16362 |
return CLI_FAILURE; |
| 16363 |
} |
| 16364 |
|
| 16365 |
static char *handle_dahdi_show_cadences(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 16366 |
{ |
| 16367 |
int i, j; |
| 16368 |
switch (cmd) { |
| 16369 |
case CLI_INIT: |
| 16370 |
e->command = "dahdi show cadences"; |
| 16371 |
e->usage = |
| 16372 |
"Usage: dahdi show cadences\n" |
| 16373 |
" Shows all cadences currently defined\n"; |
| 16374 |
return NULL; |
| 16375 |
case CLI_GENERATE: |
| 16376 |
return NULL; |
| 16377 |
} |
| 16378 |
for (i = 0; i < num_cadence; i++) { |
| 16379 |
char output[1024]; |
| 16380 |
char tmp[16], tmp2[64]; |
| 16381 |
snprintf(tmp, sizeof(tmp), "r%d: ", i + 1); |
| 16382 |
term_color(output, tmp, COLOR_GREEN, COLOR_BLACK, sizeof(output)); |
| 16383 |
|
| 16384 |
for (j = 0; j < 16; j++) { |
| 16385 |
if (cadences[i].ringcadence[j] == 0) |
| 16386 |
break; |
| 16387 |
snprintf(tmp, sizeof(tmp), "%d", cadences[i].ringcadence[j]); |
| 16388 |
if (cidrings[i] * 2 - 1 == j) |
| 16389 |
term_color(tmp2, tmp, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp2) - 1); |
| 16390 |
else |
| 16391 |
term_color(tmp2, tmp, COLOR_GREEN, COLOR_BLACK, sizeof(tmp2) - 1); |
| 16392 |
if (j != 0) |
| 16393 |
strncat(output, ",", sizeof(output) - strlen(output) - 1); |
| 16394 |
strncat(output, tmp2, sizeof(output) - strlen(output) - 1); |
| 16395 |
} |
| 16396 |
ast_cli(a->fd,"%s\n",output); |
| 16397 |
} |
| 16398 |
return CLI_SUCCESS; |
| 16399 |
} |
| 16400 |
|
| 16401 |
static void build_alarm_info(char *restrict alarmstr, struct dahdi_spaninfo *spaninfo) |
| 16402 |
{ |
| 16403 |
alarmstr[0] = '\0'; |
| 16404 |
if (spaninfo->alarms > 0) { |
| 16405 |
if (spaninfo->alarms & DAHDI_ALARM_BLUE) { |
| 16406 |
strcat(alarmstr, "BLU/"); |
| 16407 |
} |
| 16408 |
if (spaninfo->alarms & DAHDI_ALARM_YELLOW) { |
| 16409 |
strcat(alarmstr, "YEL/"); |
| 16410 |
} |
| 16411 |
if (spaninfo->alarms & DAHDI_ALARM_RED) { |
| 16412 |
strcat(alarmstr, "RED/"); |
| 16413 |
} |
| 16414 |
if (spaninfo->alarms & DAHDI_ALARM_LOOPBACK) { |
| 16415 |
strcat(alarmstr, "LB/"); |
| 16416 |
} |
| 16417 |
if (spaninfo->alarms & DAHDI_ALARM_RECOVER) { |
| 16418 |
strcat(alarmstr, "REC/"); |
| 16419 |
} |
| 16420 |
if (spaninfo->alarms & DAHDI_ALARM_NOTOPEN) { |
| 16421 |
strcat(alarmstr, "NOP/"); |
| 16422 |
} |
| 16423 |
if (!strlen(alarmstr)) { |
| 16424 |
strcat(alarmstr, "UUU/"); |
| 16425 |
} |
| 16426 |
if (strlen(alarmstr)) { |
| 16427 |
|
| 16428 |
alarmstr[strlen(alarmstr) - 1] = '\0'; |
| 16429 |
} |
| 16430 |
} else { |
| 16431 |
if (spaninfo->numchans) { |
| 16432 |
strcpy(alarmstr, "OK"); |
| 16433 |
} else { |
| 16434 |
strcpy(alarmstr, "UNCONFIGURED"); |
| 16435 |
} |
| 16436 |
} |
| 16437 |
} |
| 16438 |
|
| 16439 |
|
| 16440 |
static char *dahdi_show_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 16441 |
{ |
| 16442 |
#define FORMAT "%4d %-40.40s %-7.7s %-6d %-6d %-6d %-3.3s %-4.4s %-8.8s %s\n" |
| 16443 |
#define FORMAT2 "%4s %-40.40s %-7.7s %-6.6s %-6.6s %-6.6s %-3.3s %-4.4s %-8.8s %s\n" |
| 16444 |
int span; |
| 16445 |
int res; |
| 16446 |
char alarmstr[50]; |
| 16447 |
|
| 16448 |
int ctl; |
| 16449 |
struct dahdi_spaninfo s; |
| 16450 |
|
| 16451 |
switch (cmd) { |
| 16452 |
case CLI_INIT: |
| 16453 |
e->command = "dahdi show status"; |
| 16454 |
e->usage = |
| 16455 |
"Usage: dahdi show status\n" |
| 16456 |
" Shows a list of DAHDI cards with status\n"; |
| 16457 |
return NULL; |
| 16458 |
case CLI_GENERATE: |
| 16459 |
return NULL; |
| 16460 |
} |
| 16461 |
ctl = open("/dev/dahdi/ctl", O_RDWR); |
| 16462 |
if (ctl < 0) { |
| 16463 |
ast_cli(a->fd, "No DAHDI found. Unable to open /dev/dahdi/ctl: %s\n", strerror(errno)); |
| 16464 |
return CLI_FAILURE; |
| 16465 |
} |
| 16466 |
ast_cli(a->fd, FORMAT2, "Span", "Description", "Alarms", "IRQ", "bpviol", "CRC", "Framing", "Coding", "Options", "LBO"); |
| 16467 |
|
| 16468 |
for (span = 1; span < DAHDI_MAX_SPANS; ++span) { |
| 16469 |
s.spanno = span; |
| 16470 |
res = ioctl(ctl, DAHDI_SPANSTAT, &s); |
| 16471 |
if (res) { |
| 16472 |
continue; |
| 16473 |
} |
| 16474 |
build_alarm_info(alarmstr, &s); |
| 16475 |
ast_cli(a->fd, FORMAT, span, s.desc, alarmstr, s.irqmisses, s.bpvcount, s.crc4count, |
| 16476 |
s.lineconfig & DAHDI_CONFIG_D4 ? "D4" : |
| 16477 |
s.lineconfig & DAHDI_CONFIG_ESF ? "ESF" : |
| 16478 |
s.lineconfig & DAHDI_CONFIG_CCS ? "CCS" : |
| 16479 |
"CAS", |
| 16480 |
s.lineconfig & DAHDI_CONFIG_B8ZS ? "B8ZS" : |
| 16481 |
s.lineconfig & DAHDI_CONFIG_HDB3 ? "HDB3" : |
| 16482 |
s.lineconfig & DAHDI_CONFIG_AMI ? "AMI" : |
| 16483 |
"Unknown", |
| 16484 |
s.lineconfig & DAHDI_CONFIG_CRC4 ? |
| 16485 |
s.lineconfig & DAHDI_CONFIG_NOTOPEN ? "CRC4/YEL" : "CRC4" : |
| 16486 |
s.lineconfig & DAHDI_CONFIG_NOTOPEN ? "YEL" : "", |
| 16487 |
lbostr[s.lbo] |
| 16488 |
); |
| 16489 |
} |
| 16490 |
close(ctl); |
| 16491 |
|
| 16492 |
return CLI_SUCCESS; |
| 16493 |
#undef FORMAT |
| 16494 |
#undef FORMAT2 |
| 16495 |
} |
| 16496 |
|
| 16497 |
static char *dahdi_show_version(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 16498 |
{ |
| 16499 |
int pseudo_fd = -1; |
| 16500 |
struct dahdi_versioninfo vi; |
| 16501 |
|
| 16502 |
switch (cmd) { |
| 16503 |
case CLI_INIT: |
| 16504 |
e->command = "dahdi show version"; |
| 16505 |
e->usage = |
| 16506 |
"Usage: dahdi show version\n" |
| 16507 |
" Shows the DAHDI version in use\n"; |
| 16508 |
return NULL; |
| 16509 |
case CLI_GENERATE: |
| 16510 |
return NULL; |
| 16511 |
} |
| 16512 |
if ((pseudo_fd = open("/dev/dahdi/ctl", O_RDONLY)) < 0) { |
| 16513 |
ast_cli(a->fd, "Failed to open control file to get version.\n"); |
| 16514 |
return CLI_SUCCESS; |
| 16515 |
} |
| 16516 |
|
| 16517 |
strcpy(vi.version, "Unknown"); |
| 16518 |
strcpy(vi.echo_canceller, "Unknown"); |
| 16519 |
|
| 16520 |
if (ioctl(pseudo_fd, DAHDI_GETVERSION, &vi)) |
| 16521 |
ast_cli(a->fd, "Failed to get DAHDI version: %s\n", strerror(errno)); |
| 16522 |
else |
| 16523 |
ast_cli(a->fd, "DAHDI Version: %s Echo Canceller: %s\n", vi.version, vi.echo_canceller); |
| 16524 |
|
| 16525 |
close(pseudo_fd); |
| 16526 |
|
| 16527 |
return CLI_SUCCESS; |
| 16528 |
} |
| 16529 |
|
| 16530 |
static char *dahdi_set_hwgain(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 16531 |
{ |
| 16532 |
int channel; |
| 16533 |
float gain; |
| 16534 |
int tx; |
| 16535 |
struct dahdi_pvt *tmp = NULL; |
| 16536 |
|
| 16537 |
switch (cmd) { |
| 16538 |
case CLI_INIT: |
| 16539 |
e->command = "dahdi set hwgain {rx|tx}"; |
| 16540 |
e->usage = |
| 16541 |
"Usage: dahdi set hwgain <rx|tx> <chan#> <gain>\n" |
| 16542 |
" Sets the hardware gain on a given channel and overrides the\n" |
| 16543 |
" value provided at module loadtime. Changes take effect\n" |
| 16544 |
" immediately whether the channel is in use or not.\n" |
| 16545 |
"\n" |
| 16546 |
" <rx|tx> which direction do you want to change (relative to our module)\n" |
| 16547 |
" <chan num> is the channel number relative to the device\n" |
| 16548 |
" <gain> is the gain in dB (e.g. -3.5 for -3.5dB)\n" |
| 16549 |
"\n" |
| 16550 |
" Please note:\n" |
| 16551 |
" * hwgain is only supportable by hardware with analog ports because\n" |
| 16552 |
" hwgain works on the analog side of an analog-digital conversion.\n"; |
| 16553 |
return NULL; |
| 16554 |
case CLI_GENERATE: |
| 16555 |
return NULL; |
| 16556 |
} |
| 16557 |
|
| 16558 |
if (a->argc != 6) |
| 16559 |
return CLI_SHOWUSAGE; |
| 16560 |
|
| 16561 |
if (!strcasecmp("rx", a->argv[3])) |
| 16562 |
tx = 0; |
| 16563 |
else if (!strcasecmp("tx", a->argv[3])) |
| 16564 |
tx = 1; |
| 16565 |
else |
| 16566 |
return CLI_SHOWUSAGE; |
| 16567 |
|
| 16568 |
channel = atoi(a->argv[4]); |
| 16569 |
gain = atof(a->argv[5]); |
| 16570 |
|
| 16571 |
ast_mutex_lock(&iflock); |
| 16572 |
|
| 16573 |
for (tmp = iflist; tmp; tmp = tmp->next) { |
| 16574 |
|
| 16575 |
if (tmp->channel != channel) |
| 16576 |
continue; |
| 16577 |
|
| 16578 |
if (tmp->subs[SUB_REAL].dfd == -1) |
| 16579 |
break; |
| 16580 |
|
| 16581 |
if (set_hwgain(tmp->subs[SUB_REAL].dfd, gain, tx)) { |
| 16582 |
ast_cli(a->fd, "Unable to set the hardware gain for channel %d: %s\n", channel, strerror(errno)); |
| 16583 |
ast_mutex_unlock(&iflock); |
| 16584 |
return CLI_FAILURE; |
| 16585 |
} |
| 16586 |
ast_cli(a->fd, "Hardware %s gain set to %.1f dB on channel %d.\n", |
| 16587 |
tx ? "tx" : "rx", gain, channel); |
| 16588 |
|
| 16589 |
if (tx) { |
| 16590 |
tmp->hwtxgain_enabled = 1; |
| 16591 |
tmp->hwtxgain = gain; |
| 16592 |
} else { |
| 16593 |
tmp->hwrxgain_enabled = 1; |
| 16594 |
tmp->hwrxgain = gain; |
| 16595 |
} |
| 16596 |
break; |
| 16597 |
} |
| 16598 |
|
| 16599 |
ast_mutex_unlock(&iflock); |
| 16600 |
|
| 16601 |
if (tmp) |
| 16602 |
return CLI_SUCCESS; |
| 16603 |
|
| 16604 |
ast_cli(a->fd, "Unable to find given channel %d\n", channel); |
| 16605 |
return CLI_FAILURE; |
| 16606 |
|
| 16607 |
} |
| 16608 |
|
| 16609 |
static char *dahdi_set_swgain(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 16610 |
{ |
| 16611 |
int channel; |
| 16612 |
float gain; |
| 16613 |
int tx; |
| 16614 |
int res; |
| 16615 |
struct dahdi_pvt *tmp = NULL; |
| 16616 |
|
| 16617 |
switch (cmd) { |
| 16618 |
case CLI_INIT: |
| 16619 |
e->command = "dahdi set swgain {rx|tx}"; |
| 16620 |
e->usage = |
| 16621 |
"Usage: dahdi set swgain <rx|tx> <chan#> <gain>\n" |
| 16622 |
" Sets the software gain on a given channel and overrides the\n" |
| 16623 |
" value provided at module loadtime. Changes take effect\n" |
| 16624 |
" immediately whether the channel is in use or not.\n" |
| 16625 |
"\n" |
| 16626 |
" <rx|tx> which direction do you want to change (relative to our module)\n" |
| 16627 |
" <chan num> is the channel number relative to the device\n" |
| 16628 |
" <gain> is the gain in dB (e.g. -3.5 for -3.5dB)\n"; |
| 16629 |
return NULL; |
| 16630 |
case CLI_GENERATE: |
| 16631 |
return NULL; |
| 16632 |
} |
| 16633 |
|
| 16634 |
if (a->argc != 6) |
| 16635 |
return CLI_SHOWUSAGE; |
| 16636 |
|
| 16637 |
if (!strcasecmp("rx", a->argv[3])) |
| 16638 |
tx = 0; |
| 16639 |
else if (!strcasecmp("tx", a->argv[3])) |
| 16640 |
tx = 1; |
| 16641 |
else |
| 16642 |
return CLI_SHOWUSAGE; |
| 16643 |
|
| 16644 |
channel = atoi(a->argv[4]); |
| 16645 |
gain = atof(a->argv[5]); |
| 16646 |
|
| 16647 |
ast_mutex_lock(&iflock); |
| 16648 |
for (tmp = iflist; tmp; tmp = tmp->next) { |
| 16649 |
|
| 16650 |
if (tmp->channel != channel) |
| 16651 |
continue; |
| 16652 |
|
| 16653 |
if (tmp->subs[SUB_REAL].dfd == -1) |
| 16654 |
break; |
| 16655 |
|
| 16656 |
if (tx) |
| 16657 |
res = set_actual_txgain(tmp->subs[SUB_REAL].dfd, gain, tmp->txdrc, tmp->law); |
| 16658 |
else |
| 16659 |
res = set_actual_rxgain(tmp->subs[SUB_REAL].dfd, gain, tmp->rxdrc, tmp->law); |
| 16660 |
|
| 16661 |
if (res) { |
| 16662 |
ast_cli(a->fd, "Unable to set the software gain for channel %d\n", channel); |
| 16663 |
ast_mutex_unlock(&iflock); |
| 16664 |
return CLI_FAILURE; |
| 16665 |
} |
| 16666 |
|
| 16667 |
ast_cli(a->fd, "Software %s gain set to %.2f dB on channel %d.\n", |
| 16668 |
tx ? "tx" : "rx", gain, channel); |
| 16669 |
|
| 16670 |
if (tx) { |
| 16671 |
tmp->txgain = gain; |
| 16672 |
} else { |
| 16673 |
tmp->rxgain = gain; |
| 16674 |
} |
| 16675 |
break; |
| 16676 |
} |
| 16677 |
ast_mutex_unlock(&iflock); |
| 16678 |
|
| 16679 |
if (tmp) |
| 16680 |
return CLI_SUCCESS; |
| 16681 |
|
| 16682 |
ast_cli(a->fd, "Unable to find given channel %d\n", channel); |
| 16683 |
return CLI_FAILURE; |
| 16684 |
|
| 16685 |
} |
| 16686 |
|
| 16687 |
static char *dahdi_set_dnd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 16688 |
{ |
| 16689 |
int channel; |
| 16690 |
int on; |
| 16691 |
struct dahdi_pvt *dahdi_chan = NULL; |
| 16692 |
|
| 16693 |
switch (cmd) { |
| 16694 |
case CLI_INIT: |
| 16695 |
e->command = "dahdi set dnd"; |
| 16696 |
e->usage = |
| 16697 |
"Usage: dahdi set dnd <chan#> <on|off>\n" |
| 16698 |
" Sets/resets DND (Do Not Disturb) mode on a channel.\n" |
| 16699 |
" Changes take effect immediately.\n" |
| 16700 |
" <chan num> is the channel number\n" |
| 16701 |
" <on|off> Enable or disable DND mode?\n" |
| 16702 |
; |
| 16703 |
return NULL; |
| 16704 |
case CLI_GENERATE: |
| 16705 |
return NULL; |
| 16706 |
} |
| 16707 |
|
| 16708 |
if (a->argc != 5) |
| 16709 |
return CLI_SHOWUSAGE; |
| 16710 |
|
| 16711 |
if ((channel = atoi(a->argv[3])) <= 0) { |
| 16712 |
ast_cli(a->fd, "Expected channel number, got '%s'\n", a->argv[3]); |
| 16713 |
return CLI_SHOWUSAGE; |
| 16714 |
} |
| 16715 |
|
| 16716 |
if (ast_true(a->argv[4])) |
| 16717 |
on = 1; |
| 16718 |
else if (ast_false(a->argv[4])) |
| 16719 |
on = 0; |
| 16720 |
else { |
| 16721 |
ast_cli(a->fd, "Expected 'on' or 'off', got '%s'\n", a->argv[4]); |
| 16722 |
return CLI_SHOWUSAGE; |
| 16723 |
} |
| 16724 |
|
| 16725 |
ast_mutex_lock(&iflock); |
| 16726 |
for (dahdi_chan = iflist; dahdi_chan; dahdi_chan = dahdi_chan->next) { |
| 16727 |
if (dahdi_chan->channel != channel) |
| 16728 |
continue; |
| 16729 |
|
| 16730 |
|
| 16731 |
dahdi_dnd(dahdi_chan, on); |
| 16732 |
break; |
| 16733 |
} |
| 16734 |
ast_mutex_unlock(&iflock); |
| 16735 |
|
| 16736 |
if (!dahdi_chan) { |
| 16737 |
ast_cli(a->fd, "Unable to find given channel %d\n", channel); |
| 16738 |
return CLI_FAILURE; |
| 16739 |
} |
| 16740 |
|
| 16741 |
return CLI_SUCCESS; |
| 16742 |
} |
| 16743 |
|
| 16744 |
static char *dahdi_set_mwi(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 16745 |
{ |
| 16746 |
int channel; |
| 16747 |
int on; |
| 16748 |
int override = 1; |
| 16749 |
struct dahdi_pvt *dahdi_chan = NULL; |
| 16750 |
|
| 16751 |
switch (cmd) { |
| 16752 |
case CLI_INIT: |
| 16753 |
e->command = "dahdi set mwi"; |
| 16754 |
e->usage = |
| 16755 |
"Usage: dahdi set mwi <chan#> <on|off|reset>\n" |
| 16756 |
" Sets/unsets MWI (Message Waiting Indicator) manually on a channel.\n" |
| 16757 |
" This may be used regardless of whether the channel is assigned any mailboxes.\n" |
| 16758 |
" When active, this setting will override the voicemail status to set MWI.\n" |
| 16759 |
" Once cleared, the voicemail status will resume control of MWI.\n" |
| 16760 |
" Changes are queued for when the channel is idle and persist until cleared.\n" |
| 16761 |
" <chan num> is the channel number\n" |
| 16762 |
" <on|off|reset> Enable, disable, or reset Message Waiting Indicator override?\n" |
| 16763 |
; |
| 16764 |
return NULL; |
| 16765 |
case CLI_GENERATE: |
| 16766 |
return NULL; |
| 16767 |
} |
| 16768 |
|
| 16769 |
if (a->argc != 5) |
| 16770 |
return CLI_SHOWUSAGE; |
| 16771 |
|
| 16772 |
if ((channel = atoi(a->argv[3])) <= 0) { |
| 16773 |
ast_cli(a->fd, "Expected channel number, got '%s'\n", a->argv[3]); |
| 16774 |
return CLI_SHOWUSAGE; |
| 16775 |
} |
| 16776 |
|
| 16777 |
if (ast_true(a->argv[4])) { |
| 16778 |
on = 1; |
| 16779 |
} else if (ast_false(a->argv[4])) { |
| 16780 |
on = 0; |
| 16781 |
} else if (!strcmp(a->argv[4], "reset")) { |
| 16782 |
override = 0; |
| 16783 |
} else { |
| 16784 |
ast_cli(a->fd, "Expected 'on' or 'off' or 'reset', got '%s'\n", a->argv[4]); |
| 16785 |
return CLI_SHOWUSAGE; |
| 16786 |
} |
| 16787 |
|
| 16788 |
ast_mutex_lock(&iflock); |
| 16789 |
for (dahdi_chan = iflist; dahdi_chan; dahdi_chan = dahdi_chan->next) { |
| 16790 |
if (dahdi_chan->channel != channel) |
| 16791 |
continue; |
| 16792 |
|
| 16793 |
|
| 16794 |
if (override) { |
| 16795 |
dahdi_chan->mwioverride_disposition = on; |
| 16796 |
ast_cli(a->fd, "MWI '%s' queued for channel %d\n", on ? "enable" : "disable", channel); |
| 16797 |
} |
| 16798 |
dahdi_chan->mwioverride_active = override; |
| 16799 |
|
| 16800 |
|
| 16801 |
break; |
| 16802 |
} |
| 16803 |
ast_mutex_unlock(&iflock); |
| 16804 |
|
| 16805 |
if (!dahdi_chan) { |
| 16806 |
ast_cli(a->fd, "Unable to find given channel %d\n", channel); |
| 16807 |
return CLI_FAILURE; |
| 16808 |
} |
| 16809 |
|
| 16810 |
return CLI_SUCCESS; |
| 16811 |
} |
| 16812 |
|
| 16813 |
static struct ast_cli_entry dahdi_cli[] = { |
| 16814 |
AST_CLI_DEFINE(handle_dahdi_show_cadences, "List cadences"), |
| 16815 |
AST_CLI_DEFINE(dahdi_show_channels, "Show active DAHDI channels"), |
| 16816 |
AST_CLI_DEFINE(dahdi_show_channel, "Show information on a channel"), |
| 16817 |
AST_CLI_DEFINE(dahdi_destroy_channels, "Destroy channels"), |
| 16818 |
AST_CLI_DEFINE(dahdi_create_channels, "Create channels"), |
| 16819 |
AST_CLI_DEFINE(dahdi_restart_cmd, "Fully restart DAHDI channels"), |
| 16820 |
AST_CLI_DEFINE(dahdi_show_status, "Show all DAHDI cards status"), |
| 16821 |
AST_CLI_DEFINE(dahdi_show_version, "Show the DAHDI version in use"), |
| 16822 |
AST_CLI_DEFINE(dahdi_set_hwgain, "Set hardware gain on a channel"), |
| 16823 |
AST_CLI_DEFINE(dahdi_set_swgain, "Set software gain on a channel"), |
| 16824 |
AST_CLI_DEFINE(dahdi_set_dnd, "Sets/resets DND (Do Not Disturb) mode on a channel"), |
| 16825 |
AST_CLI_DEFINE(dahdi_set_mwi, "Sets/unsets MWI (Message Waiting Indicator) manually on a channel"), |
| 16826 |
}; |
| 16827 |
|
| 16828 |
#define TRANSFER 0 |
| 16829 |
#define HANGUP 1 |
| 16830 |
|
| 16831 |
static int dahdi_fake_event(struct dahdi_pvt *p, int mode) |
| 16832 |
{ |
| 16833 |
if (p) { |
| 16834 |
switch (mode) { |
| 16835 |
case TRANSFER: |
| 16836 |
p->fake_event = DAHDI_EVENT_WINKFLASH; |
| 16837 |
break; |
| 16838 |
case HANGUP: |
| 16839 |
p->fake_event = DAHDI_EVENT_ONHOOK; |
| 16840 |
break; |
| 16841 |
default: |
| 16842 |
ast_log(LOG_WARNING, "I don't know how to handle transfer event with this: %d on channel %s\n",mode, ast_channel_name(p->owner)); |
| 16843 |
} |
| 16844 |
} |
| 16845 |
return 0; |
| 16846 |
} |
| 16847 |
static struct dahdi_pvt *find_channel(int channel) |
| 16848 |
{ |
| 16849 |
struct dahdi_pvt *p; |
| 16850 |
|
| 16851 |
ast_mutex_lock(&iflock); |
| 16852 |
for (p = iflist; p; p = p->next) { |
| 16853 |
if (p->channel == channel) { |
| 16854 |
break; |
| 16855 |
} |
| 16856 |
} |
| 16857 |
ast_mutex_unlock(&iflock); |
| 16858 |
return p; |
| 16859 |
} |
| 16860 |
|
| 16861 |
|
| 16862 |
|
| 16863 |
|
| 16864 |
|
| 16865 |
|
| 16866 |
|
| 16867 |
|
| 16868 |
|
| 16869 |
|
| 16870 |
static struct dahdi_pvt *find_channel_from_str(const char *channel) |
| 16871 |
{ |
| 16872 |
int chan_num; |
| 16873 |
|
| 16874 |
if (sscanf(channel, "%30d", &chan_num) != 1) { |
| 16875 |
|
| 16876 |
return NULL; |
| 16877 |
} |
| 16878 |
|
| 16879 |
return find_channel(chan_num); |
| 16880 |
} |
| 16881 |
|
| 16882 |
static int print_subchannel(struct dahdi_pvt *p, int subchan, char *buffer, size_t len) |
| 16883 |
{ |
| 16884 |
if (!p->subs[subchan].owner) { |
| 16885 |
return -1; |
| 16886 |
} |
| 16887 |
ast_channel_lock(p->subs[subchan].owner); |
| 16888 |
snprintf(buffer, len, "%s", ast_channel_name(p->subs[subchan].owner)); |
| 16889 |
ast_channel_unlock(p->subs[subchan].owner); |
| 16890 |
return 0; |
| 16891 |
} |
| 16892 |
|
| 16893 |
#define REQUIRE_FXO_SIG() \ |
| 16894 |
if (!(dahdip->sigtype & __DAHDI_SIG_FXO)) { \ |
| 16895 |
ast_log(LOG_WARNING, "DAHDI channel %d is not FXO signalled\n", p->channel); \ |
| 16896 |
return -1; \ |
| 16897 |
} |
| 16898 |
|
| 16899 |
static int dahdichan_read_property(struct dahdi_pvt *p, struct dahdi_params *dahdip, const char *property, char *buffer, size_t len) |
| 16900 |
{ |
| 16901 |
struct analog_pvt *analog_p = p->sig_pvt; |
| 16902 |
|
| 16903 |
|
| 16904 |
if (!strcasecmp(property, "owner")) { |
| 16905 |
return print_subchannel(p, SUB_REAL, buffer, len); |
| 16906 |
} else if (!strcasecmp(property, "callwait")) { |
| 16907 |
return print_subchannel(p, SUB_CALLWAIT, buffer, len); |
| 16908 |
} else if (!strcasecmp(property, "threeway")) { |
| 16909 |
return print_subchannel(p, SUB_THREEWAY, buffer, len); |
| 16910 |
|
| 16911 |
} else if (!strcasecmp(property, "polarity")) { |
| 16912 |
REQUIRE_FXO_SIG(); |
| 16913 |
snprintf(buffer, len, "%d", p->polarity); |
| 16914 |
} else if (!strcasecmp(property, "dnd")) { |
| 16915 |
REQUIRE_FXO_SIG(); |
| 16916 |
snprintf(buffer, len, "%d", analog_p->dnd); |
| 16917 |
} else if (!strcasecmp(property, "callforward")) { |
| 16918 |
REQUIRE_FXO_SIG(); |
| 16919 |
snprintf(buffer, len, "%s", analog_p->call_forward); |
| 16920 |
} else if (!strcasecmp(property, "lastexten")) { |
| 16921 |
REQUIRE_FXO_SIG(); |
| 16922 |
snprintf(buffer, len, "%s", analog_p->lastexten); |
| 16923 |
} else { |
| 16924 |
ast_log(LOG_ERROR, "Unknown DAHDI_CHANNEL property '%s'\n", property); |
| 16925 |
return -1; |
| 16926 |
} |
| 16927 |
return 0; |
| 16928 |
} |
| 16929 |
|
| 16930 |
static int dahdichan_write_property(struct dahdi_pvt *p, struct dahdi_params *dahdip, const char *property, const char *value) |
| 16931 |
{ |
| 16932 |
struct analog_pvt *analog_p = p->sig_pvt; |
| 16933 |
|
| 16934 |
|
| 16935 |
|
| 16936 |
|
| 16937 |
|
| 16938 |
if (!strcasecmp(property, "owner") || !strcasecmp(property, "callwait") || !strcasecmp(property, "threeway")) { |
| 16939 |
ast_log(LOG_ERROR, "DAHDI subchannel names are R/O\n"); |
| 16940 |
return -1; |
| 16941 |
|
| 16942 |
} else if (!strcasecmp(property, "polarity")) { |
| 16943 |
int polarity = atoi(value); |
| 16944 |
REQUIRE_FXO_SIG(); |
| 16945 |
if (polarity != POLARITY_IDLE && polarity != POLARITY_REV) { |
| 16946 |
ast_log(LOG_ERROR, "Invalid polarity: '%s'\n", value); |
| 16947 |
return -1; |
| 16948 |
} |
| 16949 |
my_set_polarity(p, polarity); |
| 16950 |
} else if (!strcasecmp(property, "dnd")) { |
| 16951 |
int dnd = atoi(value); |
| 16952 |
REQUIRE_FXO_SIG(); |
| 16953 |
analog_dnd(analog_p, dnd ? 1 : 0); |
| 16954 |
} else if (!strcasecmp(property, "callforward")) { |
| 16955 |
REQUIRE_FXO_SIG(); |
| 16956 |
if (strlen(value) >= sizeof(analog_p->call_forward) - 1) { |
| 16957 |
ast_log(LOG_ERROR, "Provided call forwarding target '%s' is too long\n", value); |
| 16958 |
} |
| 16959 |
ast_copy_string(analog_p->call_forward, value, sizeof(analog_p->call_forward)); |
| 16960 |
} else if (!strcasecmp(property, "lastexten")) { |
| 16961 |
REQUIRE_FXO_SIG(); |
| 16962 |
if (strlen(value) >= sizeof(analog_p->lastexten) - 1) { |
| 16963 |
ast_log(LOG_ERROR, "Provided lastexten target '%s' is too long\n", value); |
| 16964 |
} |
| 16965 |
ast_copy_string(analog_p->lastexten, value, sizeof(analog_p->lastexten)); |
| 16966 |
} else { |
| 16967 |
ast_log(LOG_ERROR, "Unknown DAHDI_CHANNEL property '%s'\n", property); |
| 16968 |
return -1; |
| 16969 |
} |
| 16970 |
return 0; |
| 16971 |
} |
| 16972 |
#undef REQUIRE_FXO_SIG |
| 16973 |
|
| 16974 |
static int dahdichan_helper(struct ast_channel *chan, char *data, const char *value, char *buffer, size_t buflen) |
| 16975 |
{ |
| 16976 |
char *parse; |
| 16977 |
struct dahdi_pvt *pvt; |
| 16978 |
struct dahdi_params dahdip; |
| 16979 |
int res; |
| 16980 |
AST_DECLARE_APP_ARGS(args, |
| 16981 |
AST_APP_ARG(property); |
| 16982 |
AST_APP_ARG(dahdichan); |
| 16983 |
); |
| 16984 |
|
| 16985 |
parse = ast_strdupa(data); |
| 16986 |
AST_STANDARD_APP_ARGS(args, parse); |
| 16987 |
|
| 16988 |
if (buflen > 0) { |
| 16989 |
*buffer = '\0'; |
| 16990 |
} |
| 16991 |
|
| 16992 |
if (!ast_strlen_zero(args.dahdichan)) { |
| 16993 |
|
| 16994 |
int channo = atoi(args.dahdichan); |
| 16995 |
pvt = find_channel(channo); |
| 16996 |
if (!pvt) { |
| 16997 |
ast_log(LOG_ERROR, "DAHDI channel %d does not exist\n", channo); |
| 16998 |
return -1; |
| 16999 |
} |
| 17000 |
} else { |
| 17001 |
|
| 17002 |
if (!chan || !ast_channel_tech(chan) || strcasecmp(ast_channel_tech(chan)->type, "DAHDI")) { |
| 17003 |
ast_log(LOG_WARNING, "%s is not a DAHDI channel, and no DAHDI channel specified\n", ast_channel_name(chan)); |
| 17004 |
return -1; |
| 17005 |
} |
| 17006 |
pvt = ast_channel_tech_pvt(chan); |
| 17007 |
} |
| 17008 |
|
| 17009 |
memset(&dahdip, 0, sizeof(dahdip)); |
| 17010 |
if (ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &dahdip)) { |
| 17011 |
ast_log(LOG_WARNING, "Unable to get parameters of DAHDI channel %d: %s\n", pvt->channel, strerror(errno)); |
| 17012 |
return -1; |
| 17013 |
} |
| 17014 |
|
| 17015 |
|
| 17016 |
ast_mutex_lock(&pvt->lock); |
| 17017 |
if (value) { |
| 17018 |
res = dahdichan_write_property(pvt, &dahdip, args.property, value); |
| 17019 |
} else { |
| 17020 |
res = dahdichan_read_property(pvt, &dahdip, args.property, buffer, buflen); |
| 17021 |
} |
| 17022 |
ast_mutex_unlock(&pvt->lock); |
| 17023 |
return res; |
| 17024 |
} |
| 17025 |
|
| 17026 |
static int dahdichan_read(struct ast_channel *chan, const char *cmd, char *data, char *buffer, size_t buflen) |
| 17027 |
{ |
| 17028 |
return dahdichan_helper(chan, data, NULL, buffer, buflen); |
| 17029 |
} |
| 17030 |
|
| 17031 |
static int dahdichan_write(struct ast_channel *chan, const char *cmd, char *data, const char *value) |
| 17032 |
{ |
| 17033 |
return dahdichan_helper(chan, data, value, NULL, 0); |
| 17034 |
} |
| 17035 |
|
| 17036 |
static struct ast_custom_function dahdichan_function = { |
| 17037 |
.name = "DAHDI_CHANNEL", |
| 17038 |
.write = dahdichan_write, |
| 17039 |
.read = dahdichan_read, |
| 17040 |
}; |
| 17041 |
|
| 17042 |
|
| 17043 |
|
| 17044 |
static int polarity_read(struct ast_channel *chan, const char *cmd, char *data, char *buffer, size_t buflen) |
| 17045 |
{ |
| 17046 |
struct dahdi_params dahdip; |
| 17047 |
struct dahdi_pvt *pvt = ast_channel_tech_pvt(chan); |
| 17048 |
if (strcasecmp(ast_channel_tech(chan)->type, "DAHDI")) { |
| 17049 |
ast_log(LOG_WARNING, "%s is not a DAHDI channel\n", ast_channel_name(chan)); |
| 17050 |
return -1; |
| 17051 |
} |
| 17052 |
memset(&dahdip, 0, sizeof(dahdip)); |
| 17053 |
if (ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &dahdip)) { |
| 17054 |
ast_log(LOG_WARNING, "Unable to get parameters of DAHDI channel %d: %s\n", pvt->subs[SUB_REAL].dfd, strerror(errno)); |
| 17055 |
return -1; |
| 17056 |
} |
| 17057 |
return dahdichan_read_property(ast_channel_tech_pvt(chan), &dahdip, "polarity", buffer, buflen); |
| 17058 |
} |
| 17059 |
|
| 17060 |
static int polarity_write(struct ast_channel *chan, const char *cmd, char *data, const char *value) |
| 17061 |
{ |
| 17062 |
struct dahdi_params dahdip; |
| 17063 |
struct dahdi_pvt *pvt = ast_channel_tech_pvt(chan); |
| 17064 |
if (strcasecmp(ast_channel_tech(chan)->type, "DAHDI")) { |
| 17065 |
ast_log(LOG_WARNING, "%s is not a DAHDI channel\n", ast_channel_name(chan)); |
| 17066 |
return -1; |
| 17067 |
} |
| 17068 |
memset(&dahdip, 0, sizeof(dahdip)); |
| 17069 |
if (ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &dahdip)) { |
| 17070 |
ast_log(LOG_WARNING, "Unable to get parameters of DAHDI channel %d: %s\n", pvt->subs[SUB_REAL].dfd, strerror(errno)); |
| 17071 |
return -1; |
| 17072 |
} |
| 17073 |
return dahdichan_write_property(ast_channel_tech_pvt(chan), &dahdip, "polarity", value); |
| 17074 |
} |
| 17075 |
|
| 17076 |
static struct ast_custom_function polarity_function = { |
| 17077 |
.name = "POLARITY", |
| 17078 |
.write = polarity_write, |
| 17079 |
.read = polarity_read, |
| 17080 |
}; |
| 17081 |
|
| 17082 |
static int action_dahdidndon(struct mansession *s, const struct message *m) |
| 17083 |
{ |
| 17084 |
struct dahdi_pvt *p; |
| 17085 |
const char *channel = astman_get_header(m, "DAHDIChannel"); |
| 17086 |
|
| 17087 |
if (ast_strlen_zero(channel)) { |
| 17088 |
astman_send_error(s, m, "No channel specified"); |
| 17089 |
return 0; |
| 17090 |
} |
| 17091 |
p = find_channel_from_str(channel); |
| 17092 |
if (!p) { |
| 17093 |
astman_send_error(s, m, "No such channel"); |
| 17094 |
return 0; |
| 17095 |
} |
| 17096 |
dahdi_dnd(p, 1); |
| 17097 |
astman_send_ack(s, m, "DND Enabled"); |
| 17098 |
return 0; |
| 17099 |
} |
| 17100 |
|
| 17101 |
static int action_dahdidndoff(struct mansession *s, const struct message *m) |
| 17102 |
{ |
| 17103 |
struct dahdi_pvt *p; |
| 17104 |
const char *channel = astman_get_header(m, "DAHDIChannel"); |
| 17105 |
|
| 17106 |
if (ast_strlen_zero(channel)) { |
| 17107 |
astman_send_error(s, m, "No channel specified"); |
| 17108 |
return 0; |
| 17109 |
} |
| 17110 |
p = find_channel_from_str(channel); |
| 17111 |
if (!p) { |
| 17112 |
astman_send_error(s, m, "No such channel"); |
| 17113 |
return 0; |
| 17114 |
} |
| 17115 |
dahdi_dnd(p, 0); |
| 17116 |
astman_send_ack(s, m, "DND Disabled"); |
| 17117 |
return 0; |
| 17118 |
} |
| 17119 |
|
| 17120 |
static int action_transfer(struct mansession *s, const struct message *m) |
| 17121 |
{ |
| 17122 |
struct dahdi_pvt *p; |
| 17123 |
const char *channel = astman_get_header(m, "DAHDIChannel"); |
| 17124 |
|
| 17125 |
if (ast_strlen_zero(channel)) { |
| 17126 |
astman_send_error(s, m, "No channel specified"); |
| 17127 |
return 0; |
| 17128 |
} |
| 17129 |
p = find_channel_from_str(channel); |
| 17130 |
if (!p) { |
| 17131 |
astman_send_error(s, m, "No such channel"); |
| 17132 |
return 0; |
| 17133 |
} |
| 17134 |
if (!dahdi_analog_lib_handles(p->sig, 0, 0)) { |
| 17135 |
astman_send_error(s, m, "Channel signaling is not analog"); |
| 17136 |
return 0; |
| 17137 |
} |
| 17138 |
dahdi_fake_event(p,TRANSFER); |
| 17139 |
astman_send_ack(s, m, "DAHDITransfer"); |
| 17140 |
return 0; |
| 17141 |
} |
| 17142 |
|
| 17143 |
static int action_transferhangup(struct mansession *s, const struct message *m) |
| 17144 |
{ |
| 17145 |
struct dahdi_pvt *p; |
| 17146 |
const char *channel = astman_get_header(m, "DAHDIChannel"); |
| 17147 |
|
| 17148 |
if (ast_strlen_zero(channel)) { |
| 17149 |
astman_send_error(s, m, "No channel specified"); |
| 17150 |
return 0; |
| 17151 |
} |
| 17152 |
p = find_channel_from_str(channel); |
| 17153 |
if (!p) { |
| 17154 |
astman_send_error(s, m, "No such channel"); |
| 17155 |
return 0; |
| 17156 |
} |
| 17157 |
if (!dahdi_analog_lib_handles(p->sig, 0, 0)) { |
| 17158 |
astman_send_error(s, m, "Channel signaling is not analog"); |
| 17159 |
return 0; |
| 17160 |
} |
| 17161 |
dahdi_fake_event(p,HANGUP); |
| 17162 |
astman_send_ack(s, m, "DAHDIHangup"); |
| 17163 |
return 0; |
| 17164 |
} |
| 17165 |
|
| 17166 |
static int action_dahdidialoffhook(struct mansession *s, const struct message *m) |
| 17167 |
{ |
| 17168 |
struct dahdi_pvt *p; |
| 17169 |
const char *channel = astman_get_header(m, "DAHDIChannel"); |
| 17170 |
const char *number = astman_get_header(m, "Number"); |
| 17171 |
int i; |
| 17172 |
|
| 17173 |
if (ast_strlen_zero(channel)) { |
| 17174 |
astman_send_error(s, m, "No channel specified"); |
| 17175 |
return 0; |
| 17176 |
} |
| 17177 |
if (ast_strlen_zero(number)) { |
| 17178 |
astman_send_error(s, m, "No number specified"); |
| 17179 |
return 0; |
| 17180 |
} |
| 17181 |
p = find_channel_from_str(channel); |
| 17182 |
if (!p) { |
| 17183 |
astman_send_error(s, m, "No such channel"); |
| 17184 |
return 0; |
| 17185 |
} |
| 17186 |
if (!p->owner) { |
| 17187 |
astman_send_error(s, m, "Channel does not have it's owner"); |
| 17188 |
return 0; |
| 17189 |
} |
| 17190 |
for (i = 0; i < strlen(number); i++) { |
| 17191 |
struct ast_frame f = { AST_FRAME_DTMF, .subclass.integer = number[i] }; |
| 17192 |
dahdi_queue_frame(p, &f); |
| 17193 |
} |
| 17194 |
astman_send_ack(s, m, "DAHDIDialOffhook"); |
| 17195 |
return 0; |
| 17196 |
} |
| 17197 |
|
| 17198 |
static int action_dahdishowchannels(struct mansession *s, const struct message *m) |
| 17199 |
{ |
| 17200 |
struct dahdi_pvt *tmp = NULL; |
| 17201 |
const char *id = astman_get_header(m, "ActionID"); |
| 17202 |
const char *dahdichannel = astman_get_header(m, "DAHDIChannel"); |
| 17203 |
char idText[256]; |
| 17204 |
int channels = 0; |
| 17205 |
int dahdichanquery; |
| 17206 |
|
| 17207 |
if (!dahdichannel || sscanf(dahdichannel, "%30d", &dahdichanquery) != 1) { |
| 17208 |
|
| 17209 |
dahdichanquery = -1; |
| 17210 |
} |
| 17211 |
|
| 17212 |
idText[0] = '\0'; |
| 17213 |
if (!ast_strlen_zero(id)) { |
| 17214 |
snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id); |
| 17215 |
} |
| 17216 |
|
| 17217 |
astman_send_listack(s, m, "DAHDI channel status will follow", "start"); |
| 17218 |
|
| 17219 |
ast_mutex_lock(&iflock); |
| 17220 |
|
| 17221 |
for (tmp = iflist; tmp; tmp = tmp->next) { |
| 17222 |
if (tmp->channel > 0) { |
| 17223 |
int alm; |
| 17224 |
|
| 17225 |
|
| 17226 |
if (dahdichanquery > 0 && tmp->channel != dahdichanquery) |
| 17227 |
continue; |
| 17228 |
|
| 17229 |
alm = get_alarms(tmp); |
| 17230 |
channels++; |
| 17231 |
if (tmp->owner) { |
| 17232 |
|
| 17233 |
astman_append(s, |
| 17234 |
"Event: DAHDIShowChannels\r\n" |
| 17235 |
"DAHDIChannel: %d\r\n" |
| 17236 |
"Channel: %s\r\n" |
| 17237 |
"Uniqueid: %s\r\n" |
| 17238 |
"AccountCode: %s\r\n" |
| 17239 |
"Signalling: %s\r\n" |
| 17240 |
"SignallingCode: %d\r\n" |
| 17241 |
"Context: %s\r\n" |
| 17242 |
"DND: %s\r\n" |
| 17243 |
"Alarm: %s\r\n" |
| 17244 |
"Description: %s\r\n" |
| 17245 |
"%s" |
| 17246 |
"\r\n", |
| 17247 |
tmp->channel, |
| 17248 |
ast_channel_name(tmp->owner), |
| 17249 |
ast_channel_uniqueid(tmp->owner), |
| 17250 |
ast_channel_accountcode(tmp->owner), |
| 17251 |
sig2str(tmp->sig), |
| 17252 |
tmp->sig, |
| 17253 |
tmp->context, |
| 17254 |
dahdi_dnd(tmp, -1) ? "Enabled" : "Disabled", |
| 17255 |
alarm2str(alm), |
| 17256 |
tmp->description, idText); |
| 17257 |
} else { |
| 17258 |
astman_append(s, |
| 17259 |
"Event: DAHDIShowChannels\r\n" |
| 17260 |
"DAHDIChannel: %d\r\n" |
| 17261 |
"Signalling: %s\r\n" |
| 17262 |
"SignallingCode: %d\r\n" |
| 17263 |
"Context: %s\r\n" |
| 17264 |
"DND: %s\r\n" |
| 17265 |
"Alarm: %s\r\n" |
| 17266 |
"Description: %s\r\n" |
| 17267 |
"%s" |
| 17268 |
"\r\n", |
| 17269 |
tmp->channel, sig2str(tmp->sig), tmp->sig, |
| 17270 |
tmp->context, |
| 17271 |
dahdi_dnd(tmp, -1) ? "Enabled" : "Disabled", |
| 17272 |
alarm2str(alm), |
| 17273 |
tmp->description, idText); |
| 17274 |
} |
| 17275 |
} |
| 17276 |
} |
| 17277 |
|
| 17278 |
ast_mutex_unlock(&iflock); |
| 17279 |
|
| 17280 |
astman_send_list_complete_start(s, m, "DAHDIShowChannelsComplete", channels); |
| 17281 |
astman_append(s, "Items: %d\r\n", channels); |
| 17282 |
astman_send_list_complete_end(s); |
| 17283 |
return 0; |
| 17284 |
} |
| 17285 |
|
| 17286 |
static int action_dahdishowstatus(struct mansession *s, const struct message *m) |
| 17287 |
{ |
| 17288 |
const char *id = astman_get_header(m, "ActionID"); |
| 17289 |
int span; |
| 17290 |
int res; |
| 17291 |
char alarmstr[50]; |
| 17292 |
int ctl; |
| 17293 |
char idText[256]; |
| 17294 |
int numspans = 0; |
| 17295 |
struct dahdi_spaninfo spaninfo; |
| 17296 |
|
| 17297 |
ctl = open("/dev/dahdi/ctl", O_RDWR); |
| 17298 |
if (ctl < 0) { |
| 17299 |
astman_send_error(s, m, "No DAHDI detected"); |
| 17300 |
return 0; |
| 17301 |
} |
| 17302 |
|
| 17303 |
idText[0] = '\0'; |
| 17304 |
if (!ast_strlen_zero(id)) { |
| 17305 |
snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id); |
| 17306 |
} |
| 17307 |
astman_send_listack(s, m, "DAHDI span statuses will follow", "start"); |
| 17308 |
|
| 17309 |
for (span = 1; span < DAHDI_MAX_SPANS; ++span) { |
| 17310 |
spaninfo.spanno = span; |
| 17311 |
res = ioctl(ctl, DAHDI_SPANSTAT, &spaninfo); |
| 17312 |
if (res) { |
| 17313 |
continue; |
| 17314 |
} |
| 17315 |
numspans++; |
| 17316 |
build_alarm_info(alarmstr, &spaninfo); |
| 17317 |
astman_append(s, |
| 17318 |
"Event: DAHDIShowStatus\r\n" |
| 17319 |
"Span: %d\r\n" |
| 17320 |
"Description: %s\r\n" |
| 17321 |
"Alarms: %s\r\n" |
| 17322 |
"IRQ: %d\r\n" |
| 17323 |
"bpviol: %d\r\n" |
| 17324 |
"CRC: %d\r\n" |
| 17325 |
"Framing: %s\r\n" |
| 17326 |
"Coding: %s\r\n" |
| 17327 |
"Options: %s\r\n" |
| 17328 |
"LBO: %s\r\n" |
| 17329 |
"%s" |
| 17330 |
"\r\n", |
| 17331 |
span, spaninfo.desc, alarmstr, spaninfo.irqmisses, spaninfo.bpvcount, spaninfo.crc4count, |
| 17332 |
spaninfo.lineconfig & DAHDI_CONFIG_D4 ? "D4" : |
| 17333 |
spaninfo.lineconfig & DAHDI_CONFIG_ESF ? "ESF" : |
| 17334 |
spaninfo.lineconfig & DAHDI_CONFIG_CCS ? "CCS" : |
| 17335 |
"CAS", |
| 17336 |
spaninfo.lineconfig & DAHDI_CONFIG_B8ZS ? "B8ZS" : |
| 17337 |
spaninfo.lineconfig & DAHDI_CONFIG_HDB3 ? "HDB3" : |
| 17338 |
spaninfo.lineconfig & DAHDI_CONFIG_AMI ? "AMI" : |
| 17339 |
"Unk", |
| 17340 |
spaninfo.lineconfig & DAHDI_CONFIG_CRC4 ? |
| 17341 |
spaninfo.lineconfig & DAHDI_CONFIG_NOTOPEN ? "CRC4/YEL" : "CRC4" : |
| 17342 |
spaninfo.lineconfig & DAHDI_CONFIG_NOTOPEN ? "YEL" : "", |
| 17343 |
lbostr[spaninfo.lbo], |
| 17344 |
idText); |
| 17345 |
} |
| 17346 |
close(ctl); |
| 17347 |
|
| 17348 |
astman_send_list_complete_start(s, m, "DAHDIShowStatusComplete", numspans); |
| 17349 |
astman_append(s, "Items: %d\r\n", numspans); |
| 17350 |
astman_send_list_complete_end(s); |
| 17351 |
return 0; |
| 17352 |
} |
| 17353 |
|
| 17354 |
#if defined(HAVE_PRI) |
| 17355 |
static int action_prishowspans(struct mansession *s, const struct message *m) |
| 17356 |
{ |
| 17357 |
int count; |
| 17358 |
int idx; |
| 17359 |
int span_query; |
| 17360 |
struct dahdi_pri *dspan; |
| 17361 |
const char *id = astman_get_header(m, "ActionID"); |
| 17362 |
const char *span_str = astman_get_header(m, "Span"); |
| 17363 |
char action_id[256]; |
| 17364 |
const char *show_cmd = "PRIShowSpans"; |
| 17365 |
|
| 17366 |
|
| 17367 |
if (!ast_strlen_zero(span_str)) { |
| 17368 |
span_query = atoi(span_str); |
| 17369 |
} else { |
| 17370 |
span_query = 0; |
| 17371 |
} |
| 17372 |
|
| 17373 |
if (!ast_strlen_zero(id)) { |
| 17374 |
snprintf(action_id, sizeof(action_id), "ActionID: %s\r\n", id); |
| 17375 |
} else { |
| 17376 |
action_id[0] = '\0'; |
| 17377 |
} |
| 17378 |
|
| 17379 |
astman_send_listack(s, m, "Span status will follow", "start"); |
| 17380 |
|
| 17381 |
count = 0; |
| 17382 |
for (idx = 0; idx < ARRAY_LEN(pris); ++idx) { |
| 17383 |
dspan = &pris[idx]; |
| 17384 |
|
| 17385 |
|
| 17386 |
if (0 < span_query && dspan->pri.span != span_query) { |
| 17387 |
continue; |
| 17388 |
} |
| 17389 |
|
| 17390 |
if (dspan->pri.pri) { |
| 17391 |
count += sig_pri_ami_show_spans(s, show_cmd, &dspan->pri, dspan->dchannels, |
| 17392 |
action_id); |
| 17393 |
} |
| 17394 |
} |
| 17395 |
|
| 17396 |
astman_send_list_complete_start(s, m, "PRIShowSpansComplete", count); |
| 17397 |
astman_append(s, "Items: %d\r\n", count); |
| 17398 |
astman_send_list_complete_end(s); |
| 17399 |
return 0; |
| 17400 |
} |
| 17401 |
#endif |
| 17402 |
|
| 17403 |
#if defined(HAVE_SS7) |
| 17404 |
static int linkset_addsigchan(int sigchan) |
| 17405 |
{ |
| 17406 |
struct dahdi_ss7 *link; |
| 17407 |
int res; |
| 17408 |
int curfd; |
| 17409 |
struct dahdi_params params; |
| 17410 |
struct dahdi_bufferinfo bi; |
| 17411 |
struct dahdi_spaninfo si; |
| 17412 |
|
| 17413 |
if (sigchan < 0) { |
| 17414 |
ast_log(LOG_ERROR, "Invalid sigchan!\n"); |
| 17415 |
return -1; |
| 17416 |
} |
| 17417 |
if (cur_ss7type < 0) { |
| 17418 |
ast_log(LOG_ERROR, "Unspecified or invalid ss7type\n"); |
| 17419 |
return -1; |
| 17420 |
} |
| 17421 |
if (cur_pointcode < 0) { |
| 17422 |
ast_log(LOG_ERROR, "Unspecified pointcode!\n"); |
| 17423 |
return -1; |
| 17424 |
} |
| 17425 |
if (cur_adjpointcode < 0) { |
| 17426 |
ast_log(LOG_ERROR, "Unspecified adjpointcode!\n"); |
| 17427 |
return -1; |
| 17428 |
} |
| 17429 |
if (cur_defaultdpc < 0) { |
| 17430 |
ast_log(LOG_ERROR, "Unspecified defaultdpc!\n"); |
| 17431 |
return -1; |
| 17432 |
} |
| 17433 |
if (cur_networkindicator < 0) { |
| 17434 |
ast_log(LOG_ERROR, "Invalid networkindicator!\n"); |
| 17435 |
return -1; |
| 17436 |
} |
| 17437 |
link = ss7_resolve_linkset(cur_linkset); |
| 17438 |
if (!link) { |
| 17439 |
ast_log(LOG_ERROR, "Invalid linkset number. Must be between 1 and %d\n", NUM_SPANS + 1); |
| 17440 |
return -1; |
| 17441 |
} |
| 17442 |
if (link->ss7.numsigchans >= SIG_SS7_NUM_DCHANS) { |
| 17443 |
ast_log(LOG_ERROR, "Too many sigchans on linkset %d\n", cur_linkset); |
| 17444 |
return -1; |
| 17445 |
} |
| 17446 |
|
| 17447 |
curfd = link->ss7.numsigchans; |
| 17448 |
|
| 17449 |
|
| 17450 |
link->ss7.fds[curfd] = open("/dev/dahdi/channel", O_RDWR, 0600); |
| 17451 |
if (link->ss7.fds[curfd] < 0) { |
| 17452 |
ast_log(LOG_ERROR, "Unable to open SS7 sigchan %d (%s)\n", sigchan, |
| 17453 |
strerror(errno)); |
| 17454 |
return -1; |
| 17455 |
} |
| 17456 |
if (ioctl(link->ss7.fds[curfd], DAHDI_SPECIFY, &sigchan) == -1) { |
| 17457 |
dahdi_close_ss7_fd(link, curfd); |
| 17458 |
ast_log(LOG_ERROR, "Unable to specify SS7 sigchan %d (%s)\n", sigchan, |
| 17459 |
strerror(errno)); |
| 17460 |
return -1; |
| 17461 |
} |
| 17462 |
|
| 17463 |
|
| 17464 |
memset(¶ms, 0, sizeof(params)); |
| 17465 |
res = ioctl(link->ss7.fds[curfd], DAHDI_GET_PARAMS, ¶ms); |
| 17466 |
if (res) { |
| 17467 |
dahdi_close_ss7_fd(link, curfd); |
| 17468 |
ast_log(LOG_ERROR, "Unable to get parameters for sigchan %d (%s)\n", sigchan, |
| 17469 |
strerror(errno)); |
| 17470 |
return -1; |
| 17471 |
} |
| 17472 |
if (params.sigtype != DAHDI_SIG_HDLCFCS |
| 17473 |
&& params.sigtype != DAHDI_SIG_HARDHDLC |
| 17474 |
&& params.sigtype != DAHDI_SIG_MTP2) { |
| 17475 |
dahdi_close_ss7_fd(link, curfd); |
| 17476 |
ast_log(LOG_ERROR, "sigchan %d is not in HDLC/FCS mode.\n", sigchan); |
| 17477 |
return -1; |
| 17478 |
} |
| 17479 |
|
| 17480 |
|
| 17481 |
memset(&bi, 0, sizeof(bi)); |
| 17482 |
bi.txbufpolicy = DAHDI_POLICY_IMMEDIATE; |
| 17483 |
bi.rxbufpolicy = DAHDI_POLICY_IMMEDIATE; |
| 17484 |
bi.numbufs = 32; |
| 17485 |
bi.bufsize = 512; |
| 17486 |
if (ioctl(link->ss7.fds[curfd], DAHDI_SET_BUFINFO, &bi)) { |
| 17487 |
ast_log(LOG_ERROR, "Unable to set appropriate buffering on channel %d: %s\n", |
| 17488 |
sigchan, strerror(errno)); |
| 17489 |
dahdi_close_ss7_fd(link, curfd); |
| 17490 |
return -1; |
| 17491 |
} |
| 17492 |
|
| 17493 |
|
| 17494 |
memset(&si, 0, sizeof(si)); |
| 17495 |
res = ioctl(link->ss7.fds[curfd], DAHDI_SPANSTAT, &si); |
| 17496 |
if (res) { |
| 17497 |
dahdi_close_ss7_fd(link, curfd); |
| 17498 |
ast_log(LOG_ERROR, "Unable to get span state for sigchan %d (%s)\n", sigchan, |
| 17499 |
strerror(errno)); |
| 17500 |
} |
| 17501 |
|
| 17502 |
res = sig_ss7_add_sigchan(&link->ss7, curfd, cur_ss7type, |
| 17503 |
(params.sigtype == DAHDI_SIG_MTP2) |
| 17504 |
? SS7_TRANSPORT_DAHDIMTP2 |
| 17505 |
: SS7_TRANSPORT_DAHDIDCHAN, |
| 17506 |
si.alarms, cur_networkindicator, cur_pointcode, cur_adjpointcode, cur_slc); |
| 17507 |
if (res) { |
| 17508 |
dahdi_close_ss7_fd(link, curfd); |
| 17509 |
return -1; |
| 17510 |
} |
| 17511 |
|
| 17512 |
++link->ss7.numsigchans; |
| 17513 |
|
| 17514 |
return 0; |
| 17515 |
} |
| 17516 |
#endif |
| 17517 |
|
| 17518 |
#if defined(HAVE_SS7) |
| 17519 |
static char *handle_ss7_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 17520 |
{ |
| 17521 |
int span; |
| 17522 |
switch (cmd) { |
| 17523 |
case CLI_INIT: |
| 17524 |
e->command = "ss7 set debug {on|off} linkset"; |
| 17525 |
e->usage = |
| 17526 |
"Usage: ss7 set debug {on|off} linkset <linkset>\n" |
| 17527 |
" Enables debugging on a given SS7 linkset\n"; |
| 17528 |
return NULL; |
| 17529 |
case CLI_GENERATE: |
| 17530 |
return NULL; |
| 17531 |
} |
| 17532 |
|
| 17533 |
if (a->argc < 6) { |
| 17534 |
return CLI_SHOWUSAGE; |
| 17535 |
} |
| 17536 |
|
| 17537 |
span = atoi(a->argv[5]); |
| 17538 |
if ((span < 1) || (span > NUM_SPANS)) { |
| 17539 |
ast_cli(a->fd, "Invalid linkset %s. Should be a number from %d to %d\n", a->argv[5], 1, NUM_SPANS); |
| 17540 |
return CLI_SUCCESS; |
| 17541 |
} |
| 17542 |
if (!linksets[span-1].ss7.ss7) { |
| 17543 |
ast_cli(a->fd, "No SS7 running on linkset %d\n", span); |
| 17544 |
} else { |
| 17545 |
if (!strcasecmp(a->argv[3], "on")) { |
| 17546 |
linksets[span - 1].ss7.debug = 1; |
| 17547 |
ss7_set_debug(linksets[span-1].ss7.ss7, SIG_SS7_DEBUG); |
| 17548 |
ast_cli(a->fd, "Enabled debugging on linkset %d\n", span); |
| 17549 |
} else { |
| 17550 |
linksets[span - 1].ss7.debug = 0; |
| 17551 |
ss7_set_debug(linksets[span-1].ss7.ss7, 0); |
| 17552 |
ast_cli(a->fd, "Disabled debugging on linkset %d\n", span); |
| 17553 |
} |
| 17554 |
} |
| 17555 |
|
| 17556 |
return CLI_SUCCESS; |
| 17557 |
} |
| 17558 |
#endif |
| 17559 |
|
| 17560 |
#if defined(HAVE_SS7) |
| 17561 |
static char *handle_ss7_cic_blocking(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 17562 |
{ |
| 17563 |
int linkset, cic; |
| 17564 |
int blocked, i; |
| 17565 |
int do_block = 0; |
| 17566 |
unsigned int dpc; |
| 17567 |
|
| 17568 |
switch (cmd) { |
| 17569 |
case CLI_INIT: |
| 17570 |
e->command = "ss7 {block|unblock} cic"; |
| 17571 |
e->usage = |
| 17572 |
"Usage: ss7 {block|unblock} cic <linkset> <dpc> <CIC>\n" |
| 17573 |
" Sends a remote {blocking|unblocking} request for the given CIC on the specified linkset\n"; |
| 17574 |
return NULL; |
| 17575 |
case CLI_GENERATE: |
| 17576 |
return NULL; |
| 17577 |
} |
| 17578 |
|
| 17579 |
if (a->argc == 6) { |
| 17580 |
linkset = atoi(a->argv[3]); |
| 17581 |
} else { |
| 17582 |
return CLI_SHOWUSAGE; |
| 17583 |
} |
| 17584 |
|
| 17585 |
if (!strcasecmp(a->argv[1], "block")) { |
| 17586 |
do_block = 1; |
| 17587 |
} else if (strcasecmp(a->argv[1], "unblock")) { |
| 17588 |
return CLI_SHOWUSAGE; |
| 17589 |
} |
| 17590 |
|
| 17591 |
if ((linkset < 1) || (linkset > NUM_SPANS)) { |
| 17592 |
ast_cli(a->fd, "Invalid linkset %s. Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS); |
| 17593 |
return CLI_SUCCESS; |
| 17594 |
} |
| 17595 |
|
| 17596 |
if (!linksets[linkset-1].ss7.ss7) { |
| 17597 |
ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset); |
| 17598 |
return CLI_SUCCESS; |
| 17599 |
} |
| 17600 |
|
| 17601 |
cic = atoi(a->argv[5]); |
| 17602 |
if (cic < 1) { |
| 17603 |
ast_cli(a->fd, "Invalid CIC specified!\n"); |
| 17604 |
return CLI_SUCCESS; |
| 17605 |
} |
| 17606 |
|
| 17607 |
dpc = atoi(a->argv[4]); |
| 17608 |
if (dpc < 1) { |
| 17609 |
ast_cli(a->fd, "Invalid DPC specified!\n"); |
| 17610 |
return CLI_SUCCESS; |
| 17611 |
} |
| 17612 |
|
| 17613 |
for (i = 0; i < linksets[linkset-1].ss7.numchans; i++) { |
| 17614 |
if (linksets[linkset-1].ss7.pvts[i] && linksets[linkset-1].ss7.pvts[i]->cic == cic && linksets[linkset-1].ss7.pvts[i]->dpc == dpc) { |
| 17615 |
blocked = linksets[linkset-1].ss7.pvts[i]->locallyblocked; |
| 17616 |
if (!do_block ^ !(blocked & SS7_BLOCKED_MAINTENANCE)) { |
| 17617 |
if (sig_ss7_cic_blocking(&linksets[linkset-1].ss7, do_block, i) < 0) { |
| 17618 |
ast_cli(a->fd, "Unable to allocate new ss7call\n"); |
| 17619 |
} else { |
| 17620 |
ast_cli(a->fd, "Sent %sblocking request for linkset %d on CIC %d DPC %d\n", (do_block) ? "" : "un", linkset, cic, dpc); |
| 17621 |
} |
| 17622 |
} else if (!do_block && blocked) { |
| 17623 |
ast_cli(a->fd, "CIC %d is hardware locally blocked!\n", cic); |
| 17624 |
} else { |
| 17625 |
ast_cli(a->fd, "CIC %d %s locally blocked\n", cic, do_block ? "already" : "is not"); |
| 17626 |
} |
| 17627 |
return CLI_SUCCESS; |
| 17628 |
} |
| 17629 |
} |
| 17630 |
|
| 17631 |
ast_cli(a->fd, "Invalid CIC specified!\n"); |
| 17632 |
return CLI_SUCCESS; |
| 17633 |
} |
| 17634 |
#endif |
| 17635 |
|
| 17636 |
#if defined(HAVE_SS7) |
| 17637 |
static char *handle_ss7_linkset_mng(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 17638 |
{ |
| 17639 |
int linkset, i; |
| 17640 |
enum { |
| 17641 |
DO_BLOCK, |
| 17642 |
DO_UNBLOCK, |
| 17643 |
DO_RESET, |
| 17644 |
} do_what; |
| 17645 |
|
| 17646 |
switch (cmd) { |
| 17647 |
case CLI_INIT: |
| 17648 |
e->command = "ss7 {reset|block|unblock} linkset"; |
| 17649 |
e->usage = |
| 17650 |
"Usage: ss7 {reset|block|unblock} linkset <linkset number>\n" |
| 17651 |
" Sends a remote {reset|blocking|unblocking} request for all CICs on the given linkset\n"; |
| 17652 |
return NULL; |
| 17653 |
case CLI_GENERATE: |
| 17654 |
return NULL; |
| 17655 |
} |
| 17656 |
|
| 17657 |
if (a->argc == 4) { |
| 17658 |
linkset = atoi(a->argv[3]); |
| 17659 |
} else { |
| 17660 |
return CLI_SHOWUSAGE; |
| 17661 |
} |
| 17662 |
|
| 17663 |
if (!strcasecmp(a->argv[1], "block")) { |
| 17664 |
do_what = DO_BLOCK; |
| 17665 |
} else if (!strcasecmp(a->argv[1], "unblock")) { |
| 17666 |
do_what = DO_UNBLOCK; |
| 17667 |
} else if (!strcasecmp(a->argv[1], "reset")) { |
| 17668 |
do_what = DO_RESET; |
| 17669 |
} else { |
| 17670 |
return CLI_SHOWUSAGE; |
| 17671 |
} |
| 17672 |
|
| 17673 |
if ((linkset < 1) || (linkset > NUM_SPANS)) { |
| 17674 |
ast_cli(a->fd, "Invalid linkset %s. Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS); |
| 17675 |
return CLI_SUCCESS; |
| 17676 |
} |
| 17677 |
|
| 17678 |
if (!linksets[linkset - 1].ss7.ss7) { |
| 17679 |
ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset); |
| 17680 |
return CLI_SUCCESS; |
| 17681 |
} |
| 17682 |
|
| 17683 |
for (i = 0; i < linksets[linkset - 1].ss7.numchans; i++) { |
| 17684 |
|
| 17685 |
if (linksets[linkset - 1].ss7.pvts[i]) { |
| 17686 |
switch (do_what) { |
| 17687 |
case DO_BLOCK: |
| 17688 |
case DO_UNBLOCK: |
| 17689 |
if (sig_ss7_cic_blocking(&linksets[linkset - 1].ss7, do_what == DO_BLOCK, i)) { |
| 17690 |
ast_cli(a->fd, "Sent remote %s request on CIC %d\n", |
| 17691 |
(do_what == DO_BLOCK) ? "blocking" : "unblocking", |
| 17692 |
linksets[linkset - 1].ss7.pvts[i]->cic); |
| 17693 |
} |
| 17694 |
break; |
| 17695 |
case DO_RESET: |
| 17696 |
if (sig_ss7_reset_cic(&linksets[linkset - 1].ss7, |
| 17697 |
linksets[linkset - 1].ss7.pvts[i]->cic, |
| 17698 |
linksets[linkset - 1].ss7.pvts[i]->dpc)) { |
| 17699 |
ast_cli(a->fd, "Sent reset request on CIC %d\n", |
| 17700 |
linksets[linkset - 1].ss7.pvts[i]->cic); |
| 17701 |
} |
| 17702 |
break; |
| 17703 |
} |
| 17704 |
} |
| 17705 |
} |
| 17706 |
|
| 17707 |
return CLI_SUCCESS; |
| 17708 |
} |
| 17709 |
#endif |
| 17710 |
|
| 17711 |
#if defined(HAVE_SS7) |
| 17712 |
static char *handle_ss7_group_blocking(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 17713 |
{ |
| 17714 |
int linkset, cic, range, chanpos; |
| 17715 |
int i, dpc, orient = 0; |
| 17716 |
int do_block = 0; |
| 17717 |
unsigned char state[255]; |
| 17718 |
|
| 17719 |
switch (cmd) { |
| 17720 |
case CLI_INIT: |
| 17721 |
e->command = "ss7 {block|unblock} group"; |
| 17722 |
e->usage = |
| 17723 |
"Usage: ss7 {block|unblock} group <linkset> <dpc> <1st. CIC> <range> [H]\n" |
| 17724 |
" Sends a remote {blocking|unblocking} request for CIC range on the specified linkset\n"; |
| 17725 |
return NULL; |
| 17726 |
case CLI_GENERATE: |
| 17727 |
return NULL; |
| 17728 |
} |
| 17729 |
|
| 17730 |
if (a->argc == 7 || a->argc == 8) { |
| 17731 |
linkset = atoi(a->argv[3]); |
| 17732 |
} else { |
| 17733 |
return CLI_SHOWUSAGE; |
| 17734 |
} |
| 17735 |
|
| 17736 |
if (!strcasecmp(a->argv[1], "block")) { |
| 17737 |
do_block = 1; |
| 17738 |
} else if (strcasecmp(a->argv[1], "unblock")) { |
| 17739 |
return CLI_SHOWUSAGE; |
| 17740 |
} |
| 17741 |
|
| 17742 |
if (a->argc == 8) { |
| 17743 |
if (!strcasecmp(a->argv[7], "H")) { |
| 17744 |
orient = 1; |
| 17745 |
} else { |
| 17746 |
return CLI_SHOWUSAGE; |
| 17747 |
} |
| 17748 |
} |
| 17749 |
|
| 17750 |
if ((linkset < 1) || (linkset > NUM_SPANS)) { |
| 17751 |
ast_cli(a->fd, "Invalid linkset %s. Should be a number %d to %d\n", a->argv[4], 1, NUM_SPANS); |
| 17752 |
return CLI_SUCCESS; |
| 17753 |
} |
| 17754 |
|
| 17755 |
if (!linksets[linkset-1].ss7.ss7) { |
| 17756 |
ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset); |
| 17757 |
return CLI_SUCCESS; |
| 17758 |
} |
| 17759 |
|
| 17760 |
cic = atoi(a->argv[5]); |
| 17761 |
if (cic < 1) { |
| 17762 |
ast_cli(a->fd, "Invalid CIC specified!\n"); |
| 17763 |
return CLI_SUCCESS; |
| 17764 |
} |
| 17765 |
|
| 17766 |
range = atoi(a->argv[6]); |
| 17767 |
|
| 17768 |
if (range < 1 || range > (linksets[linkset - 1].ss7.type == SS7_ANSI ? 24 : 31)) { |
| 17769 |
ast_cli(a->fd, "Invalid range specified!\n"); |
| 17770 |
return CLI_SUCCESS; |
| 17771 |
} |
| 17772 |
|
| 17773 |
dpc = atoi(a->argv[4]); |
| 17774 |
if (dpc < 1) { |
| 17775 |
ast_cli(a->fd, "Invalid DPC specified!\n"); |
| 17776 |
return CLI_SUCCESS; |
| 17777 |
} |
| 17778 |
|
| 17779 |
ast_mutex_lock(&linksets[linkset-1].ss7.lock); |
| 17780 |
if (!sig_ss7_find_cic_range(&linksets[linkset-1].ss7, cic, cic + range, dpc)) { |
| 17781 |
ast_mutex_unlock(&linksets[linkset-1].ss7.lock); |
| 17782 |
ast_cli(a->fd, "Invalid CIC/RANGE\n"); |
| 17783 |
return CLI_SHOWUSAGE; |
| 17784 |
} |
| 17785 |
|
| 17786 |
memset(state, 0, sizeof(state)); |
| 17787 |
for (i = 0; i <= range; ++i) { |
| 17788 |
state[i] = 1; |
| 17789 |
} |
| 17790 |
|
| 17791 |
|
| 17792 |
chanpos = sig_ss7_find_cic(&linksets[linkset-1].ss7, cic, dpc); |
| 17793 |
if (sig_ss7_group_blocking(&linksets[linkset-1].ss7, do_block, chanpos, cic + range, state, orient)) { |
| 17794 |
ast_cli(a->fd, "Unable allocate new ss7call\n"); |
| 17795 |
} else { |
| 17796 |
ast_cli(a->fd, "Sending remote%s %sblocking request linkset %d on CIC %d range %d\n", |
| 17797 |
orient ? " hardware" : "", do_block ? "" : "un", linkset, cic, range); |
| 17798 |
} |
| 17799 |
|
| 17800 |
ast_mutex_unlock(&linksets[linkset-1].ss7.lock); |
| 17801 |
|
| 17802 |
|
| 17803 |
if (linksets[linkset-1].ss7.master != AST_PTHREADT_NULL) { |
| 17804 |
pthread_kill(linksets[linkset-1].ss7.master, SIGURG); |
| 17805 |
} |
| 17806 |
return CLI_SUCCESS; |
| 17807 |
} |
| 17808 |
#endif |
| 17809 |
|
| 17810 |
#if defined(HAVE_SS7) |
| 17811 |
static char *handle_ss7_group_reset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 17812 |
{ |
| 17813 |
int linkset, cic, range; |
| 17814 |
unsigned int dpc; |
| 17815 |
|
| 17816 |
switch (cmd) { |
| 17817 |
case CLI_INIT: |
| 17818 |
e->command = "ss7 reset group"; |
| 17819 |
e->usage = |
| 17820 |
"Usage: ss7 reset group <linkset> <dpc> <1st CIC> <range>\n" |
| 17821 |
" Send a GRS for the given CIC range on the specified linkset\n"; |
| 17822 |
return NULL; |
| 17823 |
case CLI_GENERATE: |
| 17824 |
return NULL; |
| 17825 |
} |
| 17826 |
|
| 17827 |
if (a->argc == 7) { |
| 17828 |
linkset = atoi(a->argv[3]); |
| 17829 |
} else { |
| 17830 |
return CLI_SHOWUSAGE; |
| 17831 |
} |
| 17832 |
|
| 17833 |
if ((linkset < 1) || (linkset > NUM_SPANS)) { |
| 17834 |
ast_cli(a->fd, "Invalid linkset %s. Should be a number %d to %d\n", a->argv[4], 1, NUM_SPANS); |
| 17835 |
return CLI_SUCCESS; |
| 17836 |
} |
| 17837 |
|
| 17838 |
if (!linksets[linkset-1].ss7.ss7) { |
| 17839 |
ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset); |
| 17840 |
return CLI_SUCCESS; |
| 17841 |
} |
| 17842 |
|
| 17843 |
cic = atoi(a->argv[5]); |
| 17844 |
|
| 17845 |
if (cic < 1) { |
| 17846 |
ast_cli(a->fd, "Invalid CIC specified!\n"); |
| 17847 |
return CLI_SUCCESS; |
| 17848 |
} |
| 17849 |
|
| 17850 |
range = atoi(a->argv[6]); |
| 17851 |
if (range < 1 || range > (linksets[linkset - 1].ss7.type == SS7_ANSI ? 24 : 31)) { |
| 17852 |
ast_cli(a->fd, "Invalid range specified!\n"); |
| 17853 |
return CLI_SUCCESS; |
| 17854 |
} |
| 17855 |
|
| 17856 |
dpc = atoi(a->argv[4]); |
| 17857 |
if (dpc < 1) { |
| 17858 |
ast_cli(a->fd, "Invalid DPC specified!\n"); |
| 17859 |
return CLI_SUCCESS; |
| 17860 |
} |
| 17861 |
|
| 17862 |
ast_mutex_lock(&linksets[linkset-1].ss7.lock); |
| 17863 |
if (!sig_ss7_find_cic_range(&linksets[linkset-1].ss7, cic, cic + range, dpc)) { |
| 17864 |
ast_mutex_unlock(&linksets[linkset-1].ss7.lock); |
| 17865 |
ast_cli(a->fd, "Invalid CIC/RANGE\n"); |
| 17866 |
return CLI_SHOWUSAGE; |
| 17867 |
} |
| 17868 |
|
| 17869 |
if (sig_ss7_reset_group(&linksets[linkset-1].ss7, cic, dpc, range)) { |
| 17870 |
ast_cli(a->fd, "Unable to allocate new ss7call\n"); |
| 17871 |
} else { |
| 17872 |
ast_cli(a->fd, "GRS sent ... \n"); |
| 17873 |
} |
| 17874 |
|
| 17875 |
ast_mutex_unlock(&linksets[linkset-1].ss7.lock); |
| 17876 |
|
| 17877 |
|
| 17878 |
if (linksets[linkset-1].ss7.master != AST_PTHREADT_NULL) { |
| 17879 |
pthread_kill(linksets[linkset-1].ss7.master, SIGURG); |
| 17880 |
} |
| 17881 |
return CLI_SUCCESS; |
| 17882 |
} |
| 17883 |
#endif |
| 17884 |
|
| 17885 |
#if defined(HAVE_SS7) |
| 17886 |
static char *handle_ss7_show_calls(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 17887 |
{ |
| 17888 |
int linkset; |
| 17889 |
|
| 17890 |
switch (cmd) { |
| 17891 |
case CLI_INIT: |
| 17892 |
e->command = "ss7 show calls"; |
| 17893 |
e->usage = |
| 17894 |
"Usage: ss7 show calls <linkset>\n" |
| 17895 |
" Show SS7 calls on the specified linkset\n"; |
| 17896 |
return NULL; |
| 17897 |
case CLI_GENERATE: |
| 17898 |
return NULL; |
| 17899 |
} |
| 17900 |
|
| 17901 |
if (a->argc == 4) { |
| 17902 |
linkset = atoi(a->argv[3]); |
| 17903 |
} else { |
| 17904 |
return CLI_SHOWUSAGE; |
| 17905 |
} |
| 17906 |
|
| 17907 |
if ((linkset < 1) || (linkset > NUM_SPANS)) { |
| 17908 |
ast_cli(a->fd, "Invalid linkset %s. Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS); |
| 17909 |
return CLI_SUCCESS; |
| 17910 |
} |
| 17911 |
|
| 17912 |
if (!linksets[linkset-1].ss7.ss7) { |
| 17913 |
ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset); |
| 17914 |
return CLI_SUCCESS; |
| 17915 |
} |
| 17916 |
|
| 17917 |
ast_mutex_lock(&linksets[linkset-1].ss7.lock); |
| 17918 |
isup_show_calls(linksets[linkset-1].ss7.ss7, &ast_cli, a->fd); |
| 17919 |
ast_mutex_unlock(&linksets[linkset-1].ss7.lock); |
| 17920 |
|
| 17921 |
return CLI_SUCCESS; |
| 17922 |
} |
| 17923 |
#endif |
| 17924 |
|
| 17925 |
#if defined(HAVE_SS7) |
| 17926 |
static char *handle_ss7_reset_cic(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 17927 |
{ |
| 17928 |
int linkset, cic, res; |
| 17929 |
unsigned int dpc; |
| 17930 |
|
| 17931 |
switch (cmd) { |
| 17932 |
case CLI_INIT: |
| 17933 |
e->command = "ss7 reset cic"; |
| 17934 |
e->usage = |
| 17935 |
"Usage: ss7 reset cic <linkset> <dpc> <CIC>\n" |
| 17936 |
" Send a RSC for the given CIC on the specified linkset\n"; |
| 17937 |
return NULL; |
| 17938 |
case CLI_GENERATE: |
| 17939 |
return NULL; |
| 17940 |
} |
| 17941 |
|
| 17942 |
if (a->argc == 6) { |
| 17943 |
linkset = atoi(a->argv[3]); |
| 17944 |
} else { |
| 17945 |
return CLI_SHOWUSAGE; |
| 17946 |
} |
| 17947 |
|
| 17948 |
if ((linkset < 1) || (linkset > NUM_SPANS)) { |
| 17949 |
ast_cli(a->fd, "Invalid linkset %s. Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS); |
| 17950 |
return CLI_SUCCESS; |
| 17951 |
} |
| 17952 |
|
| 17953 |
if (!linksets[linkset-1].ss7.ss7) { |
| 17954 |
ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset); |
| 17955 |
return CLI_SUCCESS; |
| 17956 |
} |
| 17957 |
|
| 17958 |
cic = atoi(a->argv[5]); |
| 17959 |
|
| 17960 |
if (cic < 1) { |
| 17961 |
ast_cli(a->fd, "Invalid CIC specified!\n"); |
| 17962 |
return CLI_SUCCESS; |
| 17963 |
} |
| 17964 |
|
| 17965 |
dpc = atoi(a->argv[4]); |
| 17966 |
if (dpc < 1) { |
| 17967 |
ast_cli(a->fd, "Invalid DPC specified!\n"); |
| 17968 |
return CLI_SUCCESS; |
| 17969 |
} |
| 17970 |
|
| 17971 |
res = sig_ss7_reset_cic(&linksets[linkset-1].ss7, cic, dpc); |
| 17972 |
|
| 17973 |
ast_cli(a->fd, "%s RSC for linkset %d on CIC %d DPC %d\n", res ? "Sent" : "Failed", linkset, cic, dpc); |
| 17974 |
|
| 17975 |
return CLI_SUCCESS; |
| 17976 |
} |
| 17977 |
#endif |
| 17978 |
|
| 17979 |
#if defined(HAVE_SS7) |
| 17980 |
static char *handle_ss7_net_mng(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 17981 |
{ |
| 17982 |
int linkset; |
| 17983 |
unsigned int slc; |
| 17984 |
unsigned int arg = 0; |
| 17985 |
const char *res; |
| 17986 |
|
| 17987 |
switch (cmd) { |
| 17988 |
case CLI_INIT: |
| 17989 |
e->command = "ss7 mtp3"; |
| 17990 |
e->usage = |
| 17991 |
"Usage: ss7 mtp3 <linkset> <slc> coo|coa|cbd|cba|eco|eca|tfp|tfa|lin|lun|lia|lua|lid|lfu <arg>\n" |
| 17992 |
" Send a NET MNG message\n" |
| 17993 |
" WARNING!!! WARNING!!! We are not a STP, just for testing/development purposes\n"; |
| 17994 |
return NULL; |
| 17995 |
case CLI_GENERATE: |
| 17996 |
return NULL; |
| 17997 |
} |
| 17998 |
|
| 17999 |
if (a->argc < 5) { |
| 18000 |
return CLI_SHOWUSAGE; |
| 18001 |
} |
| 18002 |
|
| 18003 |
linkset = atoi(a->argv[2]); |
| 18004 |
if ((linkset < 1) || (linkset > NUM_SPANS)) { |
| 18005 |
ast_cli(a->fd, "Invalid linkset %s. Should be a number %d to %d\n", a->argv[2], 1, NUM_SPANS); |
| 18006 |
return CLI_SUCCESS; |
| 18007 |
} |
| 18008 |
if (!linksets[linkset-1].ss7.ss7) { |
| 18009 |
ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset); |
| 18010 |
return CLI_SUCCESS; |
| 18011 |
} |
| 18012 |
|
| 18013 |
slc = atoi(a->argv[3]); |
| 18014 |
|
| 18015 |
if (a->argc == 6) { |
| 18016 |
arg = atoi(a->argv[5]); |
| 18017 |
} |
| 18018 |
|
| 18019 |
ast_mutex_lock(&linksets[linkset-1].ss7.lock); |
| 18020 |
res = mtp3_net_mng(linksets[linkset-1].ss7.ss7, slc, a->argv[4], arg); |
| 18021 |
ast_mutex_unlock(&linksets[linkset-1].ss7.lock); |
| 18022 |
|
| 18023 |
|
| 18024 |
if (linksets[linkset-1].ss7.master != AST_PTHREADT_NULL) { |
| 18025 |
pthread_kill(linksets[linkset-1].ss7.master, SIGURG); |
| 18026 |
} |
| 18027 |
|
| 18028 |
ast_cli(a->fd, "%s", res); |
| 18029 |
|
| 18030 |
return CLI_SUCCESS; |
| 18031 |
} |
| 18032 |
#endif |
| 18033 |
|
| 18034 |
#if defined(HAVE_SS7) |
| 18035 |
static char *handle_ss7_mtp3_restart(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 18036 |
{ |
| 18037 |
int linkset; |
| 18038 |
unsigned int slc = 0; |
| 18039 |
|
| 18040 |
switch (cmd) { |
| 18041 |
case CLI_INIT: |
| 18042 |
e->command = "ss7 restart mtp3"; |
| 18043 |
e->usage = |
| 18044 |
"Usage: ss7 restart mtp3 <linkset> <slc>\n" |
| 18045 |
" Restart link\n"; |
| 18046 |
return NULL; |
| 18047 |
case CLI_GENERATE: |
| 18048 |
return NULL; |
| 18049 |
} |
| 18050 |
|
| 18051 |
if (a->argc < 5) { |
| 18052 |
return CLI_SHOWUSAGE; |
| 18053 |
} |
| 18054 |
|
| 18055 |
linkset = atoi(a->argv[3]); |
| 18056 |
if ((linkset < 1) || (linkset > NUM_SPANS)) { |
| 18057 |
ast_cli(a->fd, "Invalid linkset %s. Should be a number %d to %d\n", a->argv[2], 1, NUM_SPANS); |
| 18058 |
return CLI_SUCCESS; |
| 18059 |
} |
| 18060 |
if (!linksets[linkset-1].ss7.ss7) { |
| 18061 |
ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset); |
| 18062 |
return CLI_SUCCESS; |
| 18063 |
} |
| 18064 |
|
| 18065 |
slc = atoi(a->argv[4]); |
| 18066 |
|
| 18067 |
ast_mutex_lock(&linksets[linkset-1].ss7.lock); |
| 18068 |
mtp3_init_restart(linksets[linkset-1].ss7.ss7, slc); |
| 18069 |
ast_mutex_unlock(&linksets[linkset-1].ss7.lock); |
| 18070 |
|
| 18071 |
|
| 18072 |
if (linksets[linkset-1].ss7.master != AST_PTHREADT_NULL) { |
| 18073 |
pthread_kill(linksets[linkset-1].ss7.master, SIGURG); |
| 18074 |
} |
| 18075 |
|
| 18076 |
return CLI_SUCCESS; |
| 18077 |
} |
| 18078 |
#endif |
| 18079 |
|
| 18080 |
#if defined(HAVE_SS7) |
| 18081 |
static char *handle_ss7_show_linkset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 18082 |
{ |
| 18083 |
int linkset; |
| 18084 |
struct sig_ss7_linkset *ss7; |
| 18085 |
switch (cmd) { |
| 18086 |
case CLI_INIT: |
| 18087 |
e->command = "ss7 show linkset"; |
| 18088 |
e->usage = |
| 18089 |
"Usage: ss7 show linkset <span>\n" |
| 18090 |
" Shows the status of an SS7 linkset.\n"; |
| 18091 |
return NULL; |
| 18092 |
case CLI_GENERATE: |
| 18093 |
return NULL; |
| 18094 |
} |
| 18095 |
|
| 18096 |
if (a->argc < 4) { |
| 18097 |
return CLI_SHOWUSAGE; |
| 18098 |
} |
| 18099 |
|
| 18100 |
linkset = atoi(a->argv[3]); |
| 18101 |
if ((linkset < 1) || (linkset > NUM_SPANS)) { |
| 18102 |
ast_cli(a->fd, "Invalid linkset %s. Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS); |
| 18103 |
return CLI_SUCCESS; |
| 18104 |
} |
| 18105 |
ss7 = &linksets[linkset - 1].ss7; |
| 18106 |
if (!ss7->ss7) { |
| 18107 |
ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset); |
| 18108 |
return CLI_SUCCESS; |
| 18109 |
} |
| 18110 |
|
| 18111 |
ast_cli(a->fd, "SS7 flags: 0x%x\n", ss7->flags); |
| 18112 |
ast_cli(a->fd, "SS7 linkset %d status: %s\n", linkset, (ss7->state == LINKSET_STATE_UP) ? "Up" : "Down"); |
| 18113 |
ast_cli(a->fd, "SS7 calling nai: %i\n", ss7->calling_nai); |
| 18114 |
ast_cli(a->fd, "SS7 called nai: %i\n", ss7->called_nai); |
| 18115 |
ast_cli(a->fd, "SS7 nationalprefix: %s\n", ss7->nationalprefix); |
| 18116 |
ast_cli(a->fd, "SS7 internationalprefix: %s\n", ss7->internationalprefix); |
| 18117 |
ast_cli(a->fd, "SS7 unknownprefix: %s\n", ss7->unknownprefix); |
| 18118 |
ast_cli(a->fd, "SS7 networkroutedprefix: %s\n", ss7->networkroutedprefix); |
| 18119 |
ast_cli(a->fd, "SS7 subscriberprefix: %s\n", ss7->subscriberprefix); |
| 18120 |
ss7_show_linkset(ss7->ss7, &ast_cli, a->fd); |
| 18121 |
|
| 18122 |
return CLI_SUCCESS; |
| 18123 |
} |
| 18124 |
#endif |
| 18125 |
|
| 18126 |
#if defined(HAVE_SS7) |
| 18127 |
static char *handle_ss7_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 18128 |
{ |
| 18129 |
int linkset; |
| 18130 |
|
| 18131 |
switch (cmd) { |
| 18132 |
case CLI_INIT: |
| 18133 |
e->command = "ss7 show channels"; |
| 18134 |
e->usage = |
| 18135 |
"Usage: ss7 show channels\n" |
| 18136 |
" Displays SS7 channel information at a glance.\n"; |
| 18137 |
return NULL; |
| 18138 |
case CLI_GENERATE: |
| 18139 |
return NULL; |
| 18140 |
} |
| 18141 |
|
| 18142 |
if (a->argc != 3) { |
| 18143 |
return CLI_SHOWUSAGE; |
| 18144 |
} |
| 18145 |
|
| 18146 |
sig_ss7_cli_show_channels_header(a->fd); |
| 18147 |
for (linkset = 0; linkset < NUM_SPANS; ++linkset) { |
| 18148 |
if (linksets[linkset].ss7.ss7) { |
| 18149 |
sig_ss7_cli_show_channels(a->fd, &linksets[linkset].ss7); |
| 18150 |
} |
| 18151 |
} |
| 18152 |
return CLI_SUCCESS; |
| 18153 |
} |
| 18154 |
#endif |
| 18155 |
|
| 18156 |
#if defined(HAVE_SS7) |
| 18157 |
static char *handle_ss7_show_cics(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 18158 |
{ |
| 18159 |
#define FORMAT "%5s %5s %6s %12s %-12s\n" |
| 18160 |
#define FORMAT2 "%5i %5i %6i %12s %-12s\n" |
| 18161 |
int i, linkset, dpc = 0; |
| 18162 |
struct sig_ss7_linkset *ss7; |
| 18163 |
char *state; |
| 18164 |
char blocking[12]; |
| 18165 |
|
| 18166 |
switch (cmd) { |
| 18167 |
case CLI_INIT: |
| 18168 |
e->command = "ss7 show cics"; |
| 18169 |
e->usage = |
| 18170 |
"Usage: ss7 show cics <linkset> [dpc]\n" |
| 18171 |
" Shows the cics of an SS7 linkset.\n"; |
| 18172 |
return NULL; |
| 18173 |
case CLI_GENERATE: |
| 18174 |
return NULL; |
| 18175 |
} |
| 18176 |
|
| 18177 |
if (a->argc < 4 || a->argc > 5) { |
| 18178 |
return CLI_SHOWUSAGE; |
| 18179 |
} |
| 18180 |
|
| 18181 |
linkset = atoi(a->argv[3]); |
| 18182 |
|
| 18183 |
if ((linkset < 1) || (linkset > NUM_SPANS)) { |
| 18184 |
ast_cli(a->fd, "Invalid linkset %s. Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS); |
| 18185 |
return CLI_SUCCESS; |
| 18186 |
} |
| 18187 |
|
| 18188 |
if (!linksets[linkset-1].ss7.ss7) { |
| 18189 |
ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset); |
| 18190 |
return CLI_SUCCESS; |
| 18191 |
} |
| 18192 |
ss7 = &linksets[linkset-1].ss7; |
| 18193 |
|
| 18194 |
if (a->argc == 5) { |
| 18195 |
dpc = atoi(a->argv[4]); |
| 18196 |
if (dpc < 1) { |
| 18197 |
ast_cli(a->fd, "Invalid DPC specified!\n"); |
| 18198 |
return CLI_SUCCESS; |
| 18199 |
} |
| 18200 |
} |
| 18201 |
|
| 18202 |
ast_cli(a->fd, FORMAT, "CIC", "DPC", "DAHDI", "STATE", "BLOCKING"); |
| 18203 |
|
| 18204 |
for (i = 0; i < ss7->numchans; i++) { |
| 18205 |
if (!dpc || (ss7->pvts[i] && ss7->pvts[i]->dpc == dpc)) { |
| 18206 |
struct dahdi_pvt *p = ss7->pvts[i]->chan_pvt; |
| 18207 |
|
| 18208 |
if (ss7->pvts[i]->owner) { |
| 18209 |
state = "Used"; |
| 18210 |
} else if (ss7->pvts[i]->ss7call) { |
| 18211 |
state = "Pending"; |
| 18212 |
} else if (!p->inservice) { |
| 18213 |
state = "NotInServ"; |
| 18214 |
} else { |
| 18215 |
state = "Idle"; |
| 18216 |
} |
| 18217 |
|
| 18218 |
if (p->locallyblocked) { |
| 18219 |
strcpy(blocking, "L:"); |
| 18220 |
if (p->locallyblocked & SS7_BLOCKED_MAINTENANCE) { |
| 18221 |
strcat(blocking, "M"); |
| 18222 |
} else { |
| 18223 |
strcat(blocking, " "); |
| 18224 |
} |
| 18225 |
|
| 18226 |
if (p->locallyblocked & SS7_BLOCKED_HARDWARE) { |
| 18227 |
strcat(blocking, "H"); |
| 18228 |
} else { |
| 18229 |
strcat(blocking, " "); |
| 18230 |
} |
| 18231 |
} else { |
| 18232 |
strcpy(blocking, " "); |
| 18233 |
} |
| 18234 |
|
| 18235 |
if (p->remotelyblocked) { |
| 18236 |
strcat(blocking, " R:"); |
| 18237 |
if (p->remotelyblocked & SS7_BLOCKED_MAINTENANCE) { |
| 18238 |
strcat(blocking, "M"); |
| 18239 |
} else { |
| 18240 |
strcat(blocking, " "); |
| 18241 |
} |
| 18242 |
|
| 18243 |
if (p->remotelyblocked & SS7_BLOCKED_HARDWARE) { |
| 18244 |
strcat(blocking, "H"); |
| 18245 |
} else { |
| 18246 |
strcat(blocking, " "); |
| 18247 |
} |
| 18248 |
} |
| 18249 |
|
| 18250 |
ast_cli(a->fd, FORMAT2, ss7->pvts[i]->cic, ss7->pvts[i]->dpc, ss7->pvts[i]->channel, state, blocking); |
| 18251 |
} |
| 18252 |
} |
| 18253 |
|
| 18254 |
return CLI_SUCCESS; |
| 18255 |
#undef FORMAT |
| 18256 |
#undef FORMAT2 |
| 18257 |
} |
| 18258 |
#endif |
| 18259 |
|
| 18260 |
#if defined(HAVE_SS7) |
| 18261 |
static char *handle_ss7_version(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| 18262 |
{ |
| 18263 |
switch (cmd) { |
| 18264 |
case CLI_INIT: |
| 18265 |
e->command = "ss7 show version"; |
| 18266 |
e->usage = |
| 18267 |
"Usage: ss7 show version\n" |
| 18268 |
" Show the libss7 version\n"; |
| 18269 |
return NULL; |
| 18270 |
case CLI_GENERATE: |
| 18271 |
return NULL; |
| 18272 |
} |
| 18273 |
|
| 18274 |
ast_cli(a->fd, "libss7 version: %s\n", ss7_get_version()); |
| 18275 |
|
| 18276 |
return CLI_SUCCESS; |
| 18277 |
} |
| 18278 |
#endif |
| 18279 |
|
| 18280 |
#if defined(HAVE_SS7) |
| 18281 |
static struct ast_cli_entry dahdi_ss7_cli[] = { |
| 18282 |
AST_CLI_DEFINE(handle_ss7_debug, "Enables SS7 debugging on a linkset"), |
| 18283 |
AST_CLI_DEFINE(handle_ss7_cic_blocking, "Blocks/Unblocks the given CIC"), |
| 18284 |
AST_CLI_DEFINE(handle_ss7_linkset_mng, "Resets/Blocks/Unblocks all CICs on a linkset"), |
| 18285 |
AST_CLI_DEFINE(handle_ss7_group_blocking, "Blocks/Unblocks the given CIC range"), |
| 18286 |
AST_CLI_DEFINE(handle_ss7_reset_cic, "Resets the given CIC"), |
| 18287 |
AST_CLI_DEFINE(handle_ss7_group_reset, "Resets the given CIC range"), |
| 18288 |
AST_CLI_DEFINE(handle_ss7_mtp3_restart, "Restart a link"), |
| 18289 |
AST_CLI_DEFINE(handle_ss7_net_mng, "Send an NET MNG message"), |
| 18290 |
AST_CLI_DEFINE(handle_ss7_show_linkset, "Shows the status of a linkset"), |
| 18291 |
AST_CLI_DEFINE(handle_ss7_show_channels, "Displays SS7 channel information"), |
| 18292 |
AST_CLI_DEFINE(handle_ss7_show_calls, "Show ss7 calls"), |
| 18293 |
AST_CLI_DEFINE(handle_ss7_show_cics, "Show cics on a linkset"), |
| 18294 |
AST_CLI_DEFINE(handle_ss7_version, "Displays libss7 version"), |
| 18295 |
}; |
| 18296 |
#endif |
| 18297 |
|
| 18298 |
#if defined(HAVE_PRI) |
| 18299 |
#if defined(HAVE_PRI_CCSS) |
| 18300 |
|
| 18301 |
|
| 18302 |
|
| 18303 |
|
| 18304 |
|
| 18305 |
|
| 18306 |
|
| 18307 |
|
| 18308 |
|
| 18309 |
|
| 18310 |
|
| 18311 |
|
| 18312 |
|
| 18313 |
|
| 18314 |
|
| 18315 |
|
| 18316 |
|
| 18317 |
static int dahdi_pri_cc_agent_init(struct ast_cc_agent *agent, struct ast_channel *chan) |
| 18318 |
{ |
| 18319 |
struct dahdi_pvt *pvt; |
| 18320 |
struct sig_pri_chan *pvt_chan; |
| 18321 |
int res; |
| 18322 |
|
| 18323 |
ast_assert(!strcmp(ast_channel_tech(chan)->type, "DAHDI")); |
| 18324 |
|
| 18325 |
pvt = ast_channel_tech_pvt(chan); |
| 18326 |
if (dahdi_sig_pri_lib_handles(pvt->sig)) { |
| 18327 |
pvt_chan = pvt->sig_pvt; |
| 18328 |
} else { |
| 18329 |
pvt_chan = NULL; |
| 18330 |
} |
| 18331 |
if (!pvt_chan) { |
| 18332 |
return -1; |
| 18333 |
} |
| 18334 |
|
| 18335 |
ast_module_ref(ast_module_info->self); |
| 18336 |
|
| 18337 |
res = sig_pri_cc_agent_init(agent, pvt_chan); |
| 18338 |
if (res) { |
| 18339 |
ast_module_unref(ast_module_info->self); |
| 18340 |
} |
| 18341 |
return res; |
| 18342 |
} |
| 18343 |
#endif |
| 18344 |
#endif |
| 18345 |
|
| 18346 |
#if defined(HAVE_PRI) |
| 18347 |
#if defined(HAVE_PRI_CCSS) |
| 18348 |
|
| 18349 |
|
| 18350 |
|
| 18351 |
|
| 18352 |
|
| 18353 |
|
| 18354 |
|
| 18355 |
|
| 18356 |
|
| 18357 |
|
| 18358 |
|
| 18359 |
static void dahdi_pri_cc_agent_destructor(struct ast_cc_agent *agent) |
| 18360 |
{ |
| 18361 |
sig_pri_cc_agent_destructor(agent); |
| 18362 |
|
| 18363 |
ast_module_unref(ast_module_info->self); |
| 18364 |
} |
| 18365 |
#endif |
| 18366 |
#endif |
| 18367 |
|
| 18368 |
#if defined(HAVE_PRI) |
| 18369 |
#if defined(HAVE_PRI_CCSS) |
| 18370 |
static struct ast_cc_agent_callbacks dahdi_pri_cc_agent_callbacks = { |
| 18371 |
.type = dahdi_pri_cc_type, |
| 18372 |
.init = dahdi_pri_cc_agent_init, |
| 18373 |
.start_offer_timer = sig_pri_cc_agent_start_offer_timer, |
| 18374 |
.stop_offer_timer = sig_pri_cc_agent_stop_offer_timer, |
| 18375 |
.respond = sig_pri_cc_agent_req_rsp, |
| 18376 |
.status_request = sig_pri_cc_agent_status_req, |
| 18377 |
.stop_ringing = sig_pri_cc_agent_stop_ringing, |
| 18378 |
.party_b_free = sig_pri_cc_agent_party_b_free, |
| 18379 |
.start_monitoring = sig_pri_cc_agent_start_monitoring, |
| 18380 |
.callee_available = sig_pri_cc_agent_callee_available, |
| 18381 |
.destructor = dahdi_pri_cc_agent_destructor, |
| 18382 |
}; |
| 18383 |
#endif |
| 18384 |
#endif |
| 18385 |
|
| 18386 |
#if defined(HAVE_PRI) |
| 18387 |
#if defined(HAVE_PRI_CCSS) |
| 18388 |
static struct ast_cc_monitor_callbacks dahdi_pri_cc_monitor_callbacks = { |
| 18389 |
.type = dahdi_pri_cc_type, |
| 18390 |
.request_cc = sig_pri_cc_monitor_req_cc, |
| 18391 |
.suspend = sig_pri_cc_monitor_suspend, |
| 18392 |
.unsuspend = sig_pri_cc_monitor_unsuspend, |
| 18393 |
.status_response = sig_pri_cc_monitor_status_rsp, |
| 18394 |
.cancel_available_timer = sig_pri_cc_monitor_cancel_available_timer, |
| 18395 |
.destructor = sig_pri_cc_monitor_destructor, |
| 18396 |
}; |
| 18397 |
#endif |
| 18398 |
#endif |
| 18399 |
|
| 18400 |
static int __unload_module(void) |
| 18401 |
{ |
| 18402 |
struct dahdi_pvt *p; |
| 18403 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 18404 |
int i, j; |
| 18405 |
#endif |
| 18406 |
|
| 18407 |
#ifdef HAVE_PRI |
| 18408 |
for (i = 0; i < NUM_SPANS; i++) { |
| 18409 |
if (pris[i].pri.master != AST_PTHREADT_NULL) { |
| 18410 |
pthread_cancel(pris[i].pri.master); |
| 18411 |
pthread_kill(pris[i].pri.master, SIGURG); |
| 18412 |
} |
| 18413 |
} |
| 18414 |
ast_cli_unregister_multiple(dahdi_pri_cli, ARRAY_LEN(dahdi_pri_cli)); |
| 18415 |
ast_unregister_application(dahdi_send_keypad_facility_app); |
| 18416 |
#ifdef HAVE_PRI_PROG_W_CAUSE |
| 18417 |
ast_unregister_application(dahdi_send_callrerouting_facility_app); |
| 18418 |
#endif |
| 18419 |
#endif |
| 18420 |
#if defined(HAVE_SS7) |
| 18421 |
for (i = 0; i < NUM_SPANS; i++) { |
| 18422 |
if (linksets[i].ss7.master != AST_PTHREADT_NULL) { |
| 18423 |
pthread_cancel(linksets[i].ss7.master); |
| 18424 |
pthread_kill(linksets[i].ss7.master, SIGURG); |
| 18425 |
} |
| 18426 |
} |
| 18427 |
ast_cli_unregister_multiple(dahdi_ss7_cli, ARRAY_LEN(dahdi_ss7_cli)); |
| 18428 |
#endif |
| 18429 |
#if defined(HAVE_OPENR2) |
| 18430 |
dahdi_r2_destroy_links(); |
| 18431 |
ast_cli_unregister_multiple(dahdi_mfcr2_cli, ARRAY_LEN(dahdi_mfcr2_cli)); |
| 18432 |
ast_unregister_application(dahdi_accept_r2_call_app); |
| 18433 |
#endif |
| 18434 |
|
| 18435 |
ast_custom_function_unregister(&dahdichan_function); |
| 18436 |
ast_custom_function_unregister(&polarity_function); |
| 18437 |
|
| 18438 |
ast_cli_unregister_multiple(dahdi_cli, ARRAY_LEN(dahdi_cli)); |
| 18439 |
ast_manager_unregister("DAHDIDialOffhook"); |
| 18440 |
ast_manager_unregister("DAHDIHangup"); |
| 18441 |
ast_manager_unregister("DAHDITransfer"); |
| 18442 |
ast_manager_unregister("DAHDIDNDoff"); |
| 18443 |
ast_manager_unregister("DAHDIDNDon"); |
| 18444 |
ast_manager_unregister("DAHDIShowChannels"); |
| 18445 |
ast_manager_unregister("DAHDIShowStatus"); |
| 18446 |
ast_manager_unregister("DAHDIRestart"); |
| 18447 |
#if defined(HAVE_PRI) |
| 18448 |
ast_manager_unregister("PRIShowSpans"); |
| 18449 |
ast_manager_unregister("PRIDebugSet"); |
| 18450 |
ast_manager_unregister("PRIDebugFileSet"); |
| 18451 |
ast_manager_unregister("PRIDebugFileUnset"); |
| 18452 |
#endif |
| 18453 |
ast_channel_unregister(&dahdi_tech); |
| 18454 |
|
| 18455 |
|
| 18456 |
ast_mutex_lock(&iflock); |
| 18457 |
for (p = iflist; p; p = p->next) { |
| 18458 |
if (p->owner) |
| 18459 |
ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD); |
| 18460 |
} |
| 18461 |
ast_mutex_unlock(&iflock); |
| 18462 |
|
| 18463 |
ast_mutex_lock(&monlock); |
| 18464 |
if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) { |
| 18465 |
pthread_cancel(monitor_thread); |
| 18466 |
pthread_kill(monitor_thread, SIGURG); |
| 18467 |
pthread_join(monitor_thread, NULL); |
| 18468 |
} |
| 18469 |
monitor_thread = AST_PTHREADT_STOP; |
| 18470 |
ast_mutex_unlock(&monlock); |
| 18471 |
|
| 18472 |
destroy_all_channels(); |
| 18473 |
|
| 18474 |
#if defined(HAVE_PRI) |
| 18475 |
for (i = 0; i < NUM_SPANS; i++) { |
| 18476 |
if (pris[i].pri.master && (pris[i].pri.master != AST_PTHREADT_NULL)) { |
| 18477 |
pthread_join(pris[i].pri.master, NULL); |
| 18478 |
} |
| 18479 |
for (j = 0; j < SIG_PRI_NUM_DCHANS; j++) { |
| 18480 |
dahdi_close_pri_fd(&(pris[i]), j); |
| 18481 |
} |
| 18482 |
sig_pri_stop_pri(&pris[i].pri); |
| 18483 |
} |
| 18484 |
#if defined(HAVE_PRI_CCSS) |
| 18485 |
ast_cc_agent_unregister(&dahdi_pri_cc_agent_callbacks); |
| 18486 |
ast_cc_monitor_unregister(&dahdi_pri_cc_monitor_callbacks); |
| 18487 |
#endif |
| 18488 |
sig_pri_unload(); |
| 18489 |
#endif |
| 18490 |
|
| 18491 |
#if defined(HAVE_SS7) |
| 18492 |
for (i = 0; i < NUM_SPANS; i++) { |
| 18493 |
if (linksets[i].ss7.master && (linksets[i].ss7.master != AST_PTHREADT_NULL)) { |
| 18494 |
pthread_join(linksets[i].ss7.master, NULL); |
| 18495 |
} |
| 18496 |
for (j = 0; j < SIG_SS7_NUM_DCHANS; j++) { |
| 18497 |
dahdi_close_ss7_fd(&(linksets[i]), j); |
| 18498 |
} |
| 18499 |
if (linksets[i].ss7.ss7) { |
| 18500 |
ss7_destroy(linksets[i].ss7.ss7); |
| 18501 |
linksets[i].ss7.ss7 = NULL; |
| 18502 |
} |
| 18503 |
} |
| 18504 |
#endif |
| 18505 |
ast_cond_destroy(&ss_thread_complete); |
| 18506 |
|
| 18507 |
dahdi_native_unload(); |
| 18508 |
|
| 18509 |
ao2_cleanup(dahdi_tech.capabilities); |
| 18510 |
dahdi_tech.capabilities = NULL; |
| 18511 |
STASIS_MESSAGE_TYPE_CLEANUP(dahdichannel_type); |
| 18512 |
return 0; |
| 18513 |
} |
| 18514 |
|
| 18515 |
static int unload_module(void) |
| 18516 |
{ |
| 18517 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 18518 |
int y; |
| 18519 |
#endif |
| 18520 |
#ifdef HAVE_PRI |
| 18521 |
for (y = 0; y < NUM_SPANS; y++) |
| 18522 |
ast_mutex_destroy(&pris[y].pri.lock); |
| 18523 |
#endif |
| 18524 |
#if defined(HAVE_SS7) |
| 18525 |
for (y = 0; y < NUM_SPANS; y++) |
| 18526 |
ast_mutex_destroy(&linksets[y].ss7.lock); |
| 18527 |
#endif |
| 18528 |
return __unload_module(); |
| 18529 |
} |
| 18530 |
|
| 18531 |
static int build_channels(struct dahdi_chan_conf *conf, const char *value, int reload, int lineno) |
| 18532 |
{ |
| 18533 |
char *c, *chan; |
| 18534 |
int x, start, finish; |
| 18535 |
struct dahdi_pvt *tmp; |
| 18536 |
|
| 18537 |
if ((reload == 0) && (conf->chan.sig < 0) && !conf->is_sig_auto) { |
| 18538 |
ast_log(LOG_ERROR, "Signalling must be specified before any channels are.\n"); |
| 18539 |
return -1; |
| 18540 |
} |
| 18541 |
|
| 18542 |
c = ast_strdupa(value); |
| 18543 |
|
| 18544 |
while ((chan = strsep(&c, ","))) { |
| 18545 |
if (sscanf(chan, "%30d-%30d", &start, &finish) == 2) { |
| 18546 |
|
| 18547 |
} else if (sscanf(chan, "%30d", &start)) { |
| 18548 |
|
| 18549 |
finish = start; |
| 18550 |
} else if (!strcasecmp(chan, "pseudo")) { |
| 18551 |
finish = start = CHAN_PSEUDO; |
| 18552 |
} else { |
| 18553 |
ast_log(LOG_ERROR, "Syntax error parsing '%s' at '%s'\n", value, chan); |
| 18554 |
return -1; |
| 18555 |
} |
| 18556 |
if (finish < start) { |
| 18557 |
ast_log(LOG_WARNING, "Silliness: %d < %d\n", start, finish); |
| 18558 |
x = finish; |
| 18559 |
finish = start; |
| 18560 |
start = x; |
| 18561 |
} |
| 18562 |
|
| 18563 |
for (x = start; x <= finish; x++) { |
| 18564 |
if (conf->wanted_channels_start && |
| 18565 |
(x < conf->wanted_channels_start || |
| 18566 |
x > conf->wanted_channels_end) |
| 18567 |
) { |
| 18568 |
continue; |
| 18569 |
} |
| 18570 |
tmp = mkintf(x, conf, reload); |
| 18571 |
|
| 18572 |
if (tmp) { |
| 18573 |
ast_verb(3, "%s channel %d, %s signalling\n", reload ? "Reconfigured" : "Registered", x, sig2str(tmp->sig)); |
| 18574 |
} else { |
| 18575 |
ast_log(LOG_ERROR, "Unable to %s channel '%s'\n", |
| 18576 |
(reload == 1) ? "reconfigure" : "register", value); |
| 18577 |
return -1; |
| 18578 |
} |
| 18579 |
if (x == CHAN_PSEUDO) { |
| 18580 |
has_pseudo = 1; |
| 18581 |
} |
| 18582 |
} |
| 18583 |
} |
| 18584 |
|
| 18585 |
return 0; |
| 18586 |
} |
| 18587 |
|
| 18588 |
|
| 18589 |
|
| 18590 |
#define MAX_CHANLIST_LEN 80 |
| 18591 |
|
| 18592 |
static void process_echocancel(struct dahdi_chan_conf *confp, const char *data, unsigned int line) |
| 18593 |
{ |
| 18594 |
char *parse = ast_strdupa(data); |
| 18595 |
char *params[DAHDI_MAX_ECHOCANPARAMS + 1]; |
| 18596 |
unsigned int param_count; |
| 18597 |
unsigned int x; |
| 18598 |
|
| 18599 |
if (!(param_count = ast_app_separate_args(parse, ',', params, ARRAY_LEN(params)))) |
| 18600 |
return; |
| 18601 |
|
| 18602 |
memset(&confp->chan.echocancel, 0, sizeof(confp->chan.echocancel)); |
| 18603 |
|
| 18604 |
|
| 18605 |
|
| 18606 |
x = ast_strlen_zero(params[0]) ? 0 : atoi(params[0]); |
| 18607 |
|
| 18608 |
if ((x == 32) || (x == 64) || (x == 128) || (x == 256) || (x == 512) || (x == 1024)) |
| 18609 |
confp->chan.echocancel.head.tap_length = x; |
| 18610 |
else if ((confp->chan.echocancel.head.tap_length = ast_true(params[0]))) |
| 18611 |
confp->chan.echocancel.head.tap_length = 128; |
| 18612 |
|
| 18613 |
|
| 18614 |
|
| 18615 |
for (x = 1; x < param_count; x++) { |
| 18616 |
struct { |
| 18617 |
char *name; |
| 18618 |
char *value; |
| 18619 |
} param; |
| 18620 |
|
| 18621 |
if (ast_app_separate_args(params[x], '=', (char **) ¶m, 2) < 1) { |
| 18622 |
ast_log(LOG_WARNING, "Invalid echocancel parameter supplied at line %u: '%s'\n", line, params[x]); |
| 18623 |
continue; |
| 18624 |
} |
| 18625 |
|
| 18626 |
if (ast_strlen_zero(param.name) || (strlen(param.name) > sizeof(confp->chan.echocancel.params[0].name)-1)) { |
| 18627 |
ast_log(LOG_WARNING, "Invalid echocancel parameter supplied at line %u: '%s'\n", line, param.name); |
| 18628 |
continue; |
| 18629 |
} |
| 18630 |
|
| 18631 |
strcpy(confp->chan.echocancel.params[confp->chan.echocancel.head.param_count].name, param.name); |
| 18632 |
|
| 18633 |
if (param.value) { |
| 18634 |
if (sscanf(param.value, "%30d", &confp->chan.echocancel.params[confp->chan.echocancel.head.param_count].value) != 1) { |
| 18635 |
ast_log(LOG_WARNING, "Invalid echocancel parameter value supplied at line %u: '%s'\n", line, param.value); |
| 18636 |
continue; |
| 18637 |
} |
| 18638 |
} |
| 18639 |
confp->chan.echocancel.head.param_count++; |
| 18640 |
} |
| 18641 |
} |
| 18642 |
|
| 18643 |
#if defined(HAVE_PRI) |
| 18644 |
#if defined(HAVE_PRI_DISPLAY_TEXT) |
| 18645 |
|
| 18646 |
|
| 18647 |
|
| 18648 |
|
| 18649 |
|
| 18650 |
|
| 18651 |
|
| 18652 |
|
| 18653 |
|
| 18654 |
static unsigned long dahdi_display_text_option(const char *value) |
| 18655 |
{ |
| 18656 |
char *val_str; |
| 18657 |
char *opt_str; |
| 18658 |
unsigned long options; |
| 18659 |
|
| 18660 |
options = 0; |
| 18661 |
val_str = ast_strdupa(value); |
| 18662 |
|
| 18663 |
for (;;) { |
| 18664 |
opt_str = strsep(&val_str, ","); |
| 18665 |
if (!opt_str) { |
| 18666 |
break; |
| 18667 |
} |
| 18668 |
opt_str = ast_strip(opt_str); |
| 18669 |
if (!*opt_str) { |
| 18670 |
continue; |
| 18671 |
} |
| 18672 |
|
| 18673 |
if (!strcasecmp(opt_str, "block")) { |
| 18674 |
options |= PRI_DISPLAY_OPTION_BLOCK; |
| 18675 |
} else if (!strcasecmp(opt_str, "name_initial")) { |
| 18676 |
options |= PRI_DISPLAY_OPTION_NAME_INITIAL; |
| 18677 |
} else if (!strcasecmp(opt_str, "name_update")) { |
| 18678 |
options |= PRI_DISPLAY_OPTION_NAME_UPDATE; |
| 18679 |
} else if (!strcasecmp(opt_str, "name")) { |
| 18680 |
options |= (PRI_DISPLAY_OPTION_NAME_INITIAL | PRI_DISPLAY_OPTION_NAME_UPDATE); |
| 18681 |
} else if (!strcasecmp(opt_str, "text")) { |
| 18682 |
options |= PRI_DISPLAY_OPTION_TEXT; |
| 18683 |
} |
| 18684 |
} |
| 18685 |
return options; |
| 18686 |
} |
| 18687 |
#endif |
| 18688 |
#endif |
| 18689 |
|
| 18690 |
#if defined(HAVE_PRI) |
| 18691 |
#if defined(HAVE_PRI_DATETIME_SEND) |
| 18692 |
|
| 18693 |
|
| 18694 |
|
| 18695 |
|
| 18696 |
|
| 18697 |
|
| 18698 |
|
| 18699 |
|
| 18700 |
|
| 18701 |
static int dahdi_datetime_send_option(const char *value) |
| 18702 |
{ |
| 18703 |
int option; |
| 18704 |
|
| 18705 |
option = PRI_DATE_TIME_SEND_DEFAULT; |
| 18706 |
|
| 18707 |
if (ast_false(value)) { |
| 18708 |
option = PRI_DATE_TIME_SEND_NO; |
| 18709 |
} else if (!strcasecmp(value, "date")) { |
| 18710 |
option = PRI_DATE_TIME_SEND_DATE; |
| 18711 |
} else if (!strcasecmp(value, "date_hh")) { |
| 18712 |
option = PRI_DATE_TIME_SEND_DATE_HH; |
| 18713 |
} else if (!strcasecmp(value, "date_hhmm")) { |
| 18714 |
option = PRI_DATE_TIME_SEND_DATE_HHMM; |
| 18715 |
} else if (!strcasecmp(value, "date_hhmmss")) { |
| 18716 |
option = PRI_DATE_TIME_SEND_DATE_HHMMSS; |
| 18717 |
} |
| 18718 |
|
| 18719 |
return option; |
| 18720 |
} |
| 18721 |
#endif |
| 18722 |
#endif |
| 18723 |
|
| 18724 |
|
| 18725 |
#define PROC_DAHDI_OPT_NOCHAN (1 << 0) |
| 18726 |
|
| 18727 |
#define PROC_DAHDI_OPT_NOWARN (1 << 1) |
| 18728 |
|
| 18729 |
static void parse_busy_pattern(struct ast_variable *v, struct ast_dsp_busy_pattern *busy_cadence) |
| 18730 |
{ |
| 18731 |
int count_pattern = 0; |
| 18732 |
int norval = 0; |
| 18733 |
const char *temp = NULL; |
| 18734 |
|
| 18735 |
for (; ;) { |
| 18736 |
|
| 18737 |
if (!sscanf(v->value, "%30d", &norval) && count_pattern == 0) { |
| 18738 |
ast_log(LOG_ERROR, "busypattern= expects either busypattern=tonelength,quietlength or busypattern=t1length, q1length, t2length, q2length at line %d.\n", v->lineno); |
| 18739 |
break; |
| 18740 |
} |
| 18741 |
|
| 18742 |
busy_cadence->pattern[count_pattern] = norval; |
| 18743 |
|
| 18744 |
count_pattern++; |
| 18745 |
if (count_pattern == 4) { |
| 18746 |
break; |
| 18747 |
} |
| 18748 |
|
| 18749 |
temp = strchr(v->value, ','); |
| 18750 |
if (temp == NULL) { |
| 18751 |
break; |
| 18752 |
} |
| 18753 |
v->value = temp + 1; |
| 18754 |
} |
| 18755 |
busy_cadence->length = count_pattern; |
| 18756 |
|
| 18757 |
if (count_pattern % 2 != 0) { |
| 18758 |
|
| 18759 |
ast_log(LOG_ERROR, "busypattern= expects either busypattern=tonelength,quietlength or busypattern=t1length, q1length, t2length, q2length at line %d.\n", v->lineno); |
| 18760 |
} |
| 18761 |
|
| 18762 |
} |
| 18763 |
|
| 18764 |
static int process_dahdi(struct dahdi_chan_conf *confp, const char *cat, struct ast_variable *v, int reload, int options) |
| 18765 |
{ |
| 18766 |
struct dahdi_pvt *tmp; |
| 18767 |
int y; |
| 18768 |
struct ast_variable *dahdichan = NULL; |
| 18769 |
|
| 18770 |
|
| 18771 |
user_has_defined_cadences = 0; |
| 18772 |
|
| 18773 |
for (; v; v = v->next) { |
| 18774 |
if (!ast_jb_read_conf(&global_jbconf, v->name, v->value)) |
| 18775 |
continue; |
| 18776 |
|
| 18777 |
|
| 18778 |
if (!strcasecmp(v->name, "channel") || !strcasecmp(v->name, "channels")) { |
| 18779 |
if (options & PROC_DAHDI_OPT_NOCHAN) { |
| 18780 |
ast_log(LOG_WARNING, "Channel '%s' ignored.\n", v->value); |
| 18781 |
continue; |
| 18782 |
} |
| 18783 |
if (build_channels(confp, v->value, reload, v->lineno)) { |
| 18784 |
if (confp->ignore_failed_channels) { |
| 18785 |
ast_log(LOG_WARNING, "Channel '%s' failure ignored: ignore_failed_channels.\n", v->value); |
| 18786 |
continue; |
| 18787 |
} else { |
| 18788 |
return -1; |
| 18789 |
} |
| 18790 |
} |
| 18791 |
ast_debug(1, "Channel '%s' configured.\n", v->value); |
| 18792 |
} else if (!strcasecmp(v->name, "ignore_failed_channels")) { |
| 18793 |
confp->ignore_failed_channels = ast_true(v->value); |
| 18794 |
} else if (!strcasecmp(v->name, "buffers")) { |
| 18795 |
if (parse_buffers_policy(v->value, &confp->chan.buf_no, &confp->chan.buf_policy)) { |
| 18796 |
ast_log(LOG_WARNING, "Using default buffer policy.\n"); |
| 18797 |
confp->chan.buf_no = numbufs; |
| 18798 |
confp->chan.buf_policy = DAHDI_POLICY_IMMEDIATE; |
| 18799 |
} |
| 18800 |
} else if (!strcasecmp(v->name, "faxbuffers")) { |
| 18801 |
if (!parse_buffers_policy(v->value, &confp->chan.faxbuf_no, &confp->chan.faxbuf_policy)) { |
| 18802 |
confp->chan.usefaxbuffers = 1; |
| 18803 |
} |
| 18804 |
} else if (!strcasecmp(v->name, "dahdichan")) { |
| 18805 |
|
| 18806 |
dahdichan = v; |
| 18807 |
} else if (!strcasecmp(v->name, "usedistinctiveringdetection")) { |
| 18808 |
usedistinctiveringdetection = ast_true(v->value); |
| 18809 |
} else if (!strcasecmp(v->name, "distinctiveringaftercid")) { |
| 18810 |
distinctiveringaftercid = ast_true(v->value); |
| 18811 |
} else if (!strcasecmp(v->name, "dring1context")) { |
| 18812 |
ast_copy_string(confp->chan.drings.ringContext[0].contextData,v->value,sizeof(confp->chan.drings.ringContext[0].contextData)); |
| 18813 |
} else if (!strcasecmp(v->name, "dring2context")) { |
| 18814 |
ast_copy_string(confp->chan.drings.ringContext[1].contextData,v->value,sizeof(confp->chan.drings.ringContext[1].contextData)); |
| 18815 |
} else if (!strcasecmp(v->name, "dring3context")) { |
| 18816 |
ast_copy_string(confp->chan.drings.ringContext[2].contextData,v->value,sizeof(confp->chan.drings.ringContext[2].contextData)); |
| 18817 |
} else if (!strcasecmp(v->name, "dring1range")) { |
| 18818 |
confp->chan.drings.ringnum[0].range = atoi(v->value); |
| 18819 |
} else if (!strcasecmp(v->name, "dring2range")) { |
| 18820 |
confp->chan.drings.ringnum[1].range = atoi(v->value); |
| 18821 |
} else if (!strcasecmp(v->name, "dring3range")) { |
| 18822 |
confp->chan.drings.ringnum[2].range = atoi(v->value); |
| 18823 |
} else if (!strcasecmp(v->name, "dring1")) { |
| 18824 |
sscanf(v->value, "%30d,%30d,%30d", &confp->chan.drings.ringnum[0].ring[0], &confp->chan.drings.ringnum[0].ring[1], &confp->chan.drings.ringnum[0].ring[2]); |
| 18825 |
} else if (!strcasecmp(v->name, "dring2")) { |
| 18826 |
sscanf(v->value, "%30d,%30d,%30d", &confp->chan.drings.ringnum[1].ring[0], &confp->chan.drings.ringnum[1].ring[1], &confp->chan.drings.ringnum[1].ring[2]); |
| 18827 |
} else if (!strcasecmp(v->name, "dring3")) { |
| 18828 |
sscanf(v->value, "%30d,%30d,%30d", &confp->chan.drings.ringnum[2].ring[0], &confp->chan.drings.ringnum[2].ring[1], &confp->chan.drings.ringnum[2].ring[2]); |
| 18829 |
} else if (!strcasecmp(v->name, "usecallerid")) { |
| 18830 |
confp->chan.use_callerid = ast_true(v->value); |
| 18831 |
} else if (!strcasecmp(v->name, "cidsignalling")) { |
| 18832 |
if (!strcasecmp(v->value, "bell")) |
| 18833 |
confp->chan.cid_signalling = CID_SIG_BELL; |
| 18834 |
else if (!strcasecmp(v->value, "v23")) |
| 18835 |
confp->chan.cid_signalling = CID_SIG_V23; |
| 18836 |
else if (!strcasecmp(v->value, "dtmf")) |
| 18837 |
confp->chan.cid_signalling = CID_SIG_DTMF; |
| 18838 |
else if (!strcasecmp(v->value, "smdi")) |
| 18839 |
confp->chan.cid_signalling = CID_SIG_SMDI; |
| 18840 |
else if (!strcasecmp(v->value, "v23_jp")) |
| 18841 |
confp->chan.cid_signalling = CID_SIG_V23_JP; |
| 18842 |
else if (ast_true(v->value)) |
| 18843 |
confp->chan.cid_signalling = CID_SIG_BELL; |
| 18844 |
} else if (!strcasecmp(v->name, "cidstart")) { |
| 18845 |
if (!strcasecmp(v->value, "ring")) |
| 18846 |
confp->chan.cid_start = CID_START_RING; |
| 18847 |
else if (!strcasecmp(v->value, "polarity_in")) |
| 18848 |
confp->chan.cid_start = CID_START_POLARITY_IN; |
| 18849 |
else if (!strcasecmp(v->value, "polarity")) |
| 18850 |
confp->chan.cid_start = CID_START_POLARITY; |
| 18851 |
else if (!strcasecmp(v->value, "dtmf")) |
| 18852 |
confp->chan.cid_start = CID_START_DTMF_NOALERT; |
| 18853 |
else if (ast_true(v->value)) |
| 18854 |
confp->chan.cid_start = CID_START_RING; |
| 18855 |
} else if (!strcasecmp(v->name, "threewaycalling")) { |
| 18856 |
confp->chan.threewaycalling = ast_true(v->value); |
| 18857 |
} else if (!strcasecmp(v->name, "threewaysilenthold")) { |
| 18858 |
confp->chan.threewaysilenthold = ast_true(v->value); |
| 18859 |
} else if (!strcasecmp(v->name, "cancallforward")) { |
| 18860 |
confp->chan.cancallforward = ast_true(v->value); |
| 18861 |
} else if (!strcasecmp(v->name, "relaxdtmf")) { |
| 18862 |
if (ast_true(v->value)) |
| 18863 |
confp->chan.dtmfrelax = DSP_DIGITMODE_RELAXDTMF; |
| 18864 |
else |
| 18865 |
confp->chan.dtmfrelax = 0; |
| 18866 |
} else if (!strcasecmp(v->name, "mailbox")) { |
| 18867 |
ast_copy_string(confp->chan.mailbox, v->value, sizeof(confp->chan.mailbox)); |
| 18868 |
} else if (!strcasecmp(v->name, "description")) { |
| 18869 |
ast_copy_string(confp->chan.description, v->value, sizeof(confp->chan.description)); |
| 18870 |
} else if (!strcasecmp(v->name, "hasvoicemail")) { |
| 18871 |
if (ast_true(v->value) && ast_strlen_zero(confp->chan.mailbox)) { |
| 18872 |
|
| 18873 |
|
| 18874 |
|
| 18875 |
|
| 18876 |
if (strchr(cat, '@')) { |
| 18877 |
ast_copy_string(confp->chan.mailbox, cat, sizeof(confp->chan.mailbox)); |
| 18878 |
} else { |
| 18879 |
snprintf(confp->chan.mailbox, sizeof(confp->chan.mailbox), |
| 18880 |
"%s@default", cat); |
| 18881 |
} |
| 18882 |
} |
| 18883 |
} else if (!strcasecmp(v->name, "adsi")) { |
| 18884 |
confp->chan.adsi = ast_true(v->value); |
| 18885 |
} else if (!strcasecmp(v->name, "usesmdi")) { |
| 18886 |
confp->chan.use_smdi = ast_true(v->value); |
| 18887 |
} else if (!strcasecmp(v->name, "smdiport")) { |
| 18888 |
ast_copy_string(confp->smdi_port, v->value, sizeof(confp->smdi_port)); |
| 18889 |
} else if (!strcasecmp(v->name, "transfer")) { |
| 18890 |
confp->chan.transfer = ast_true(v->value); |
| 18891 |
} else if (!strcasecmp(v->name, "canpark")) { |
| 18892 |
confp->chan.canpark = ast_true(v->value); |
| 18893 |
} else if (!strcasecmp(v->name, "echocancelwhenbridged")) { |
| 18894 |
confp->chan.echocanbridged = ast_true(v->value); |
| 18895 |
} else if (!strcasecmp(v->name, "busydetect")) { |
| 18896 |
confp->chan.busydetect = ast_true(v->value); |
| 18897 |
} else if (!strcasecmp(v->name, "busycount")) { |
| 18898 |
confp->chan.busycount = atoi(v->value); |
| 18899 |
} else if (!strcasecmp(v->name, "busypattern")) { |
| 18900 |
parse_busy_pattern(v, &confp->chan.busy_cadence); |
| 18901 |
} else if (!strcasecmp(v->name, "calledsubscriberheld")) { |
| 18902 |
confp->chan.calledsubscriberheld = ast_true(v->value); |
| 18903 |
} else if (!strcasecmp(v->name, "lastnumredial")) { |
| 18904 |
confp->chan.lastnumredial = ast_true(v->value); |
| 18905 |
} else if (!strcasecmp(v->name, "callprogress")) { |
| 18906 |
confp->chan.callprogress &= ~CALLPROGRESS_PROGRESS; |
| 18907 |
if (ast_true(v->value)) |
| 18908 |
confp->chan.callprogress |= CALLPROGRESS_PROGRESS; |
| 18909 |
} else if (!strcasecmp(v->name, "waitfordialtone")) { |
| 18910 |
confp->chan.waitfordialtone = atoi(v->value); |
| 18911 |
} else if (!strcasecmp(v->name, "dialtone_detect")) { |
| 18912 |
if (!strcasecmp(v->value, "always")) { |
| 18913 |
confp->chan.dialtone_detect = -1; |
| 18914 |
} else if (ast_true(v->value)) { |
| 18915 |
confp->chan.dialtone_detect = DEFAULT_DIALTONE_DETECT_TIMEOUT; |
| 18916 |
} else if (ast_false(v->value)) { |
| 18917 |
confp->chan.dialtone_detect = 0; |
| 18918 |
} else { |
| 18919 |
confp->chan.dialtone_detect = ast_strlen_zero(v->value) ? 0 : (8 * atoi(v->value)) / READ_SIZE; |
| 18920 |
} |
| 18921 |
} else if (!strcasecmp(v->name, "faxdetect")) { |
| 18922 |
confp->chan.callprogress &= ~CALLPROGRESS_FAX; |
| 18923 |
if (!strcasecmp(v->value, "incoming")) { |
| 18924 |
confp->chan.callprogress |= CALLPROGRESS_FAX_INCOMING; |
| 18925 |
} else if (!strcasecmp(v->value, "outgoing")) { |
| 18926 |
confp->chan.callprogress |= CALLPROGRESS_FAX_OUTGOING; |
| 18927 |
} else if (!strcasecmp(v->value, "both") || ast_true(v->value)) |
| 18928 |
confp->chan.callprogress |= CALLPROGRESS_FAX_INCOMING | CALLPROGRESS_FAX_OUTGOING; |
| 18929 |
} else if (!strcasecmp(v->name, "faxdetect_timeout")) { |
| 18930 |
if (sscanf(v->value, "%30u", &confp->chan.faxdetect_timeout) != 1) { |
| 18931 |
confp->chan.faxdetect_timeout = 0; |
| 18932 |
} |
| 18933 |
} else if (!strcasecmp(v->name, "firstdigit_timeout")) { |
| 18934 |
if (sscanf(v->value, "%30d", &confp->chan.firstdigit_timeout) != 1 |
| 18935 |
|| confp->chan.firstdigit_timeout <= 0) { |
| 18936 |
confp->chan.firstdigit_timeout = ANALOG_FIRST_DIGIT_TIMEOUT; |
| 18937 |
} |
| 18938 |
} else if (!strcasecmp(v->name, "interdigit_timeout")) { |
| 18939 |
if (sscanf(v->value, "%30d", &confp->chan.interdigit_timeout) != 1 |
| 18940 |
|| confp->chan.interdigit_timeout <= 0) { |
| 18941 |
confp->chan.interdigit_timeout = ANALOG_INTER_DIGIT_TIMEOUT; |
| 18942 |
} |
| 18943 |
} else if (!strcasecmp(v->name, "matchdigit_timeout")) { |
| 18944 |
if (sscanf(v->value, "%30d", &confp->chan.matchdigit_timeout) != 1 |
| 18945 |
|| confp->chan.matchdigit_timeout <= 0) { |
| 18946 |
confp->chan.matchdigit_timeout = ANALOG_MATCH_DIGIT_TIMEOUT; |
| 18947 |
} |
| 18948 |
} else if (!strcasecmp(v->name, "echocancel")) { |
| 18949 |
process_echocancel(confp, v->value, v->lineno); |
| 18950 |
} else if (!strcasecmp(v->name, "echotraining")) { |
| 18951 |
if (sscanf(v->value, "%30d", &y) == 1) { |
| 18952 |
if ((y < 10) || (y > 4000)) { |
| 18953 |
ast_log(LOG_WARNING, "Echo training time must be within the range of 10 to 4000 ms at line %d.\n", v->lineno); |
| 18954 |
} else { |
| 18955 |
confp->chan.echotraining = y; |
| 18956 |
} |
| 18957 |
} else if (ast_true(v->value)) { |
| 18958 |
confp->chan.echotraining = 400; |
| 18959 |
} else |
| 18960 |
confp->chan.echotraining = 0; |
| 18961 |
} else if (!strcasecmp(v->name, "hidecallerid")) { |
| 18962 |
confp->chan.hidecallerid = ast_true(v->value); |
| 18963 |
} else if (!strcasecmp(v->name, "hidecalleridname")) { |
| 18964 |
confp->chan.hidecalleridname = ast_true(v->value); |
| 18965 |
} else if (!strcasecmp(v->name, "pulsedial")) { |
| 18966 |
confp->chan.pulse = ast_true(v->value); |
| 18967 |
} else if (!strcasecmp(v->name, "callreturn")) { |
| 18968 |
confp->chan.callreturn = ast_true(v->value); |
| 18969 |
} else if (!strcasecmp(v->name, "callwaiting")) { |
| 18970 |
confp->chan.callwaiting = ast_true(v->value); |
| 18971 |
} else if (!strcasecmp(v->name, "callwaitingcallerid")) { |
| 18972 |
confp->chan.callwaitingcallerid = ast_true(v->value); |
| 18973 |
} else if (!strcasecmp(v->name, "callwaitingdeluxe")) { |
| 18974 |
confp->chan.callwaitingdeluxe = ast_true(v->value); |
| 18975 |
} else if (!strcasecmp(v->name, "context")) { |
| 18976 |
ast_copy_string(confp->chan.context, v->value, sizeof(confp->chan.context)); |
| 18977 |
} else if (!strcasecmp(v->name, "language")) { |
| 18978 |
ast_copy_string(confp->chan.language, v->value, sizeof(confp->chan.language)); |
| 18979 |
} else if (!strcasecmp(v->name, "progzone")) { |
| 18980 |
ast_copy_string(progzone, v->value, sizeof(progzone)); |
| 18981 |
} else if (!strcasecmp(v->name, "mohinterpret") |
| 18982 |
||!strcasecmp(v->name, "musiconhold") || !strcasecmp(v->name, "musicclass")) { |
| 18983 |
ast_copy_string(confp->chan.mohinterpret, v->value, sizeof(confp->chan.mohinterpret)); |
| 18984 |
} else if (!strcasecmp(v->name, "mohsuggest")) { |
| 18985 |
ast_copy_string(confp->chan.mohsuggest, v->value, sizeof(confp->chan.mohsuggest)); |
| 18986 |
} else if (!strcasecmp(v->name, "parkinglot")) { |
| 18987 |
ast_copy_string(confp->chan.parkinglot, v->value, sizeof(confp->chan.parkinglot)); |
| 18988 |
} else if (!strcasecmp(v->name, "stripmsd")) { |
| 18989 |
ast_log(LOG_NOTICE, "Configuration option \"%s\" has been deprecated. Please use dialplan instead\n", v->name); |
| 18990 |
confp->chan.stripmsd = atoi(v->value); |
| 18991 |
} else if (!strcasecmp(v->name, "jitterbuffers")) { |
| 18992 |
numbufs = atoi(v->value); |
| 18993 |
} else if (!strcasecmp(v->name, "group")) { |
| 18994 |
confp->chan.group = ast_get_group(v->value); |
| 18995 |
} else if (!strcasecmp(v->name, "callgroup")) { |
| 18996 |
if (!((confp->chan.sig == SIG_FXOKS) || (confp->chan.sig == SIG_FXOGS) || (confp->chan.sig == SIG_FXOLS))) { |
| 18997 |
ast_log(LOG_WARNING, "Only FXO signalled channels may belong to a call group\n"); |
| 18998 |
} |
| 18999 |
if (!strcasecmp(v->value, "none")) |
| 19000 |
confp->chan.callgroup = 0; |
| 19001 |
else |
| 19002 |
confp->chan.callgroup = ast_get_group(v->value); |
| 19003 |
} else if (!strcasecmp(v->name, "pickupgroup")) { |
| 19004 |
if (!((confp->chan.sig == SIG_FXOKS) || (confp->chan.sig == SIG_FXOGS) || (confp->chan.sig == SIG_FXOLS))) { |
| 19005 |
ast_log(LOG_WARNING, "Only FXO signalled channels may belong to a pickup group\n"); |
| 19006 |
} |
| 19007 |
if (!strcasecmp(v->value, "none")) |
| 19008 |
confp->chan.pickupgroup = 0; |
| 19009 |
else |
| 19010 |
confp->chan.pickupgroup = ast_get_group(v->value); |
| 19011 |
} else if (!strcasecmp(v->name, "namedcallgroup")) { |
| 19012 |
if (!((confp->chan.sig == SIG_FXOKS) || (confp->chan.sig == SIG_FXOGS) || (confp->chan.sig == SIG_FXOLS))) { |
| 19013 |
ast_log(LOG_WARNING, "Only FXO signalled channels may belong to a named call group\n"); |
| 19014 |
} |
| 19015 |
confp->chan.named_callgroups = ast_get_namedgroups(v->value); |
| 19016 |
} else if (!strcasecmp(v->name, "namedpickupgroup")) { |
| 19017 |
if (!((confp->chan.sig == SIG_FXOKS) || (confp->chan.sig == SIG_FXOGS) || (confp->chan.sig == SIG_FXOLS))) { |
| 19018 |
ast_log(LOG_WARNING, "Only FXO signalled channels may belong to a named pickup group\n"); |
| 19019 |
} |
| 19020 |
confp->chan.named_pickupgroups = ast_get_namedgroups(v->value); |
| 19021 |
} else if (!strcasecmp(v->name, "setvar")) { |
| 19022 |
if (v->value) { |
| 19023 |
char *varval = NULL; |
| 19024 |
struct ast_variable *tmpvar; |
| 19025 |
char varname[strlen(v->value) + 1]; |
| 19026 |
strcpy(varname, v->value); |
| 19027 |
if ((varval = strchr(varname, '='))) { |
| 19028 |
*varval++ = '\0'; |
| 19029 |
if ((tmpvar = ast_variable_new(varname, varval, ""))) { |
| 19030 |
if (ast_variable_list_replace(&confp->chan.vars, tmpvar)) { |
| 19031 |
tmpvar->next = confp->chan.vars; |
| 19032 |
confp->chan.vars = tmpvar; |
| 19033 |
} |
| 19034 |
} |
| 19035 |
} |
| 19036 |
} |
| 19037 |
} else if (!strcasecmp(v->name, "immediate")) { |
| 19038 |
confp->chan.immediate = ast_true(v->value); |
| 19039 |
} else if (!strcasecmp(v->name, "immediatering")) { |
| 19040 |
confp->chan.immediatering = ast_true(v->value); |
| 19041 |
} else if (!strcasecmp(v->name, "transfertobusy")) { |
| 19042 |
confp->chan.transfertobusy = ast_true(v->value); |
| 19043 |
} else if (!strcasecmp(v->name, "dialmode")) { |
| 19044 |
if (!strcasecmp(v->value, "pulse")) { |
| 19045 |
confp->chan.permdialmode = ANALOG_DIALMODE_PULSE; |
| 19046 |
} else if (!strcasecmp(v->value, "dtmf") || !strcasecmp(v->value, "tone")) { |
| 19047 |
confp->chan.permdialmode = ANALOG_DIALMODE_DTMF; |
| 19048 |
} else if (!strcasecmp(v->value, "none")) { |
| 19049 |
confp->chan.permdialmode = ANALOG_DIALMODE_NONE; |
| 19050 |
} else { |
| 19051 |
confp->chan.permdialmode = ANALOG_DIALMODE_BOTH; |
| 19052 |
} |
| 19053 |
} else if (!strcasecmp(v->name, "mwimonitor")) { |
| 19054 |
confp->chan.mwimonitor_neon = 0; |
| 19055 |
confp->chan.mwimonitor_fsk = 0; |
| 19056 |
confp->chan.mwimonitor_rpas = 0; |
| 19057 |
if (strcasestr(v->value, "fsk")) { |
| 19058 |
confp->chan.mwimonitor_fsk = 1; |
| 19059 |
} |
| 19060 |
if (strcasestr(v->value, "rpas")) { |
| 19061 |
confp->chan.mwimonitor_rpas = 1; |
| 19062 |
} |
| 19063 |
if (strcasestr(v->value, "neon")) { |
| 19064 |
confp->chan.mwimonitor_neon = 1; |
| 19065 |
} |
| 19066 |
|
| 19067 |
if (ast_true(v->value)) { |
| 19068 |
confp->chan.mwimonitor_fsk = 1; |
| 19069 |
} |
| 19070 |
} else if (!strcasecmp(v->name, "hwrxgain")) { |
| 19071 |
confp->chan.hwrxgain_enabled = 0; |
| 19072 |
if (strcasecmp(v->value, "disabled")) { |
| 19073 |
if (sscanf(v->value, "%30f", &confp->chan.hwrxgain) == 1) { |
| 19074 |
confp->chan.hwrxgain_enabled = 1; |
| 19075 |
} else { |
| 19076 |
ast_log(LOG_WARNING, "Invalid hwrxgain: %s at line %d.\n", v->value, v->lineno); |
| 19077 |
} |
| 19078 |
} |
| 19079 |
} else if (!strcasecmp(v->name, "hwtxgain")) { |
| 19080 |
confp->chan.hwtxgain_enabled = 0; |
| 19081 |
if (strcasecmp(v->value, "disabled")) { |
| 19082 |
if (sscanf(v->value, "%30f", &confp->chan.hwtxgain) == 1) { |
| 19083 |
confp->chan.hwtxgain_enabled = 1; |
| 19084 |
} else { |
| 19085 |
ast_log(LOG_WARNING, "Invalid hwtxgain: %s at line %d.\n", v->value, v->lineno); |
| 19086 |
} |
| 19087 |
} |
| 19088 |
} else if (!strcasecmp(v->name, "cid_rxgain")) { |
| 19089 |
if (sscanf(v->value, "%30f", &confp->chan.cid_rxgain) != 1) { |
| 19090 |
ast_log(LOG_WARNING, "Invalid cid_rxgain: %s at line %d.\n", v->value, v->lineno); |
| 19091 |
} |
| 19092 |
} else if (!strcasecmp(v->name, "rxgain")) { |
| 19093 |
if (sscanf(v->value, "%30f", &confp->chan.rxgain) != 1) { |
| 19094 |
ast_log(LOG_WARNING, "Invalid rxgain: %s at line %d.\n", v->value, v->lineno); |
| 19095 |
} |
| 19096 |
} else if (!strcasecmp(v->name, "txgain")) { |
| 19097 |
if (sscanf(v->value, "%30f", &confp->chan.txgain) != 1) { |
| 19098 |
ast_log(LOG_WARNING, "Invalid txgain: %s at line %d.\n", v->value, v->lineno); |
| 19099 |
} |
| 19100 |
} else if (!strcasecmp(v->name, "txdrc")) { |
| 19101 |
if (sscanf(v->value, "%f", &confp->chan.txdrc) != 1) { |
| 19102 |
ast_log(LOG_WARNING, "Invalid txdrc: %s\n", v->value); |
| 19103 |
} |
| 19104 |
} else if (!strcasecmp(v->name, "rxdrc")) { |
| 19105 |
if (sscanf(v->value, "%f", &confp->chan.rxdrc) != 1) { |
| 19106 |
ast_log(LOG_WARNING, "Invalid rxdrc: %s\n", v->value); |
| 19107 |
} |
| 19108 |
} else if (!strcasecmp(v->name, "tonezone")) { |
| 19109 |
if (sscanf(v->value, "%30d", &confp->chan.tonezone) != 1) { |
| 19110 |
ast_log(LOG_WARNING, "Invalid tonezone: %s at line %d.\n", v->value, v->lineno); |
| 19111 |
} |
| 19112 |
} else if (!strcasecmp(v->name, "callerid")) { |
| 19113 |
if (!strcasecmp(v->value, "asreceived")) { |
| 19114 |
confp->chan.cid_num[0] = '\0'; |
| 19115 |
confp->chan.cid_name[0] = '\0'; |
| 19116 |
} else { |
| 19117 |
ast_callerid_split(v->value, confp->chan.cid_name, sizeof(confp->chan.cid_name), confp->chan.cid_num, sizeof(confp->chan.cid_num)); |
| 19118 |
} |
| 19119 |
} else if (!strcasecmp(v->name, "fullname")) { |
| 19120 |
ast_copy_string(confp->chan.cid_name, v->value, sizeof(confp->chan.cid_name)); |
| 19121 |
} else if (!strcasecmp(v->name, "cid_number")) { |
| 19122 |
ast_copy_string(confp->chan.cid_num, v->value, sizeof(confp->chan.cid_num)); |
| 19123 |
} else if (!strcasecmp(v->name, "cid_tag")) { |
| 19124 |
ast_copy_string(confp->chan.cid_tag, v->value, sizeof(confp->chan.cid_tag)); |
| 19125 |
} else if (!strcasecmp(v->name, "useincomingcalleridondahditransfer")) { |
| 19126 |
confp->chan.dahditrcallerid = ast_true(v->value); |
| 19127 |
} else if (!strcasecmp(v->name, "restrictcid")) { |
| 19128 |
confp->chan.restrictcid = ast_true(v->value); |
| 19129 |
} else if (!strcasecmp(v->name, "usecallingpres")) { |
| 19130 |
confp->chan.use_callingpres = ast_true(v->value); |
| 19131 |
} else if (!strcasecmp(v->name, "accountcode")) { |
| 19132 |
ast_copy_string(confp->chan.accountcode, v->value, sizeof(confp->chan.accountcode)); |
| 19133 |
} else if (!strcasecmp(v->name, "amaflags")) { |
| 19134 |
y = ast_channel_string2amaflag(v->value); |
| 19135 |
if (y < 0) |
| 19136 |
ast_log(LOG_WARNING, "Invalid AMA flags: %s at line %d.\n", v->value, v->lineno); |
| 19137 |
else |
| 19138 |
confp->chan.amaflags = y; |
| 19139 |
} else if (!strcasecmp(v->name, "polarityonanswerdelay")) { |
| 19140 |
confp->chan.polarityonanswerdelay = atoi(v->value); |
| 19141 |
} else if (!strcasecmp(v->name, "answeronpolarityswitch")) { |
| 19142 |
confp->chan.answeronpolarityswitch = ast_true(v->value); |
| 19143 |
} else if (!strcasecmp(v->name, "ani_info_digits")) { |
| 19144 |
confp->chan.ani_info_digits = atoi(v->value); |
| 19145 |
} else if (!strcasecmp(v->name, "ani_wink_time")) { |
| 19146 |
confp->chan.ani_wink_time = atoi(v->value); |
| 19147 |
} else if (!strcasecmp(v->name, "ani_timeout")) { |
| 19148 |
confp->chan.ani_timeout = atoi(v->value); |
| 19149 |
} else if (!strcasecmp(v->name, "hanguponpolarityswitch")) { |
| 19150 |
confp->chan.hanguponpolarityswitch = ast_true(v->value); |
| 19151 |
} else if (!strcasecmp(v->name, "autoreoriginate")) { |
| 19152 |
confp->chan.reoriginate = ast_true(v->value); |
| 19153 |
} else if (!strcasecmp(v->name, "sendcalleridafter")) { |
| 19154 |
confp->chan.sendcalleridafter = atoi(v->value); |
| 19155 |
} else if (!strcasecmp(v->name, "mwimonitornotify")) { |
| 19156 |
ast_copy_string(mwimonitornotify, v->value, sizeof(mwimonitornotify)); |
| 19157 |
} else if (ast_cc_is_config_param(v->name)) { |
| 19158 |
ast_cc_set_param(confp->chan.cc_params, v->name, v->value); |
| 19159 |
} else if (!strcasecmp(v->name, "mwisendtype")) { |
| 19160 |
#ifndef HAVE_DAHDI_LINEREVERSE_VMWI |
| 19161 |
if (!strcasecmp(v->value, "rpas")) { |
| 19162 |
mwisend_rpas = 1; |
| 19163 |
} else { |
| 19164 |
mwisend_rpas = 0; |
| 19165 |
} |
| 19166 |
#else |
| 19167 |
|
| 19168 |
memset(&confp->chan.mwisend_setting, 0, sizeof(confp->chan.mwisend_setting)); |
| 19169 |
if (strcasestr(v->value, "nofsk")) { |
| 19170 |
confp->chan.mwisend_fsk = 0; |
| 19171 |
} else { |
| 19172 |
confp->chan.mwisend_fsk = 1; |
| 19173 |
} |
| 19174 |
if (strcasestr(v->value, "rpas")) { |
| 19175 |
confp->chan.mwisend_rpas = 1; |
| 19176 |
} else { |
| 19177 |
confp->chan.mwisend_rpas = 0; |
| 19178 |
} |
| 19179 |
if (strcasestr(v->value, "lrev")) { |
| 19180 |
confp->chan.mwisend_setting.vmwi_type |= DAHDI_VMWI_LREV; |
| 19181 |
} |
| 19182 |
if (strcasestr(v->value, "hvdc")) { |
| 19183 |
confp->chan.mwisend_setting.vmwi_type |= DAHDI_VMWI_HVDC; |
| 19184 |
} |
| 19185 |
if ( (strcasestr(v->value, "neon")) || (strcasestr(v->value, "hvac")) ) { |
| 19186 |
confp->chan.mwisend_setting.vmwi_type |= DAHDI_VMWI_HVAC; |
| 19187 |
} |
| 19188 |
#endif |
| 19189 |
} else if (reload != 1) { |
| 19190 |
if (!strcasecmp(v->name, "signalling") || !strcasecmp(v->name, "signaling")) { |
| 19191 |
int orig_radio = confp->chan.radio; |
| 19192 |
int orig_outsigmod = confp->chan.outsigmod; |
| 19193 |
int orig_auto = confp->is_sig_auto; |
| 19194 |
|
| 19195 |
confp->chan.radio = 0; |
| 19196 |
confp->chan.outsigmod = -1; |
| 19197 |
confp->is_sig_auto = 0; |
| 19198 |
if (!strcasecmp(v->value, "em")) { |
| 19199 |
confp->chan.sig = SIG_EM; |
| 19200 |
} else if (!strcasecmp(v->value, "em_e1")) { |
| 19201 |
confp->chan.sig = SIG_EM_E1; |
| 19202 |
} else if (!strcasecmp(v->value, "em_w")) { |
| 19203 |
confp->chan.sig = SIG_EMWINK; |
| 19204 |
} else if (!strcasecmp(v->value, "fxs_ls")) { |
| 19205 |
confp->chan.sig = SIG_FXSLS; |
| 19206 |
} else if (!strcasecmp(v->value, "fxs_gs")) { |
| 19207 |
confp->chan.sig = SIG_FXSGS; |
| 19208 |
} else if (!strcasecmp(v->value, "fxs_ks")) { |
| 19209 |
confp->chan.sig = SIG_FXSKS; |
| 19210 |
} else if (!strcasecmp(v->value, "fxo_ls")) { |
| 19211 |
confp->chan.sig = SIG_FXOLS; |
| 19212 |
} else if (!strcasecmp(v->value, "fxo_gs")) { |
| 19213 |
confp->chan.sig = SIG_FXOGS; |
| 19214 |
} else if (!strcasecmp(v->value, "fxo_ks")) { |
| 19215 |
confp->chan.sig = SIG_FXOKS; |
| 19216 |
} else if (!strcasecmp(v->value, "fxs_rx")) { |
| 19217 |
confp->chan.sig = SIG_FXSKS; |
| 19218 |
confp->chan.radio = 1; |
| 19219 |
} else if (!strcasecmp(v->value, "fxo_rx")) { |
| 19220 |
confp->chan.sig = SIG_FXOLS; |
| 19221 |
confp->chan.radio = 1; |
| 19222 |
} else if (!strcasecmp(v->value, "fxs_tx")) { |
| 19223 |
confp->chan.sig = SIG_FXSLS; |
| 19224 |
confp->chan.radio = 1; |
| 19225 |
} else if (!strcasecmp(v->value, "fxo_tx")) { |
| 19226 |
confp->chan.sig = SIG_FXOGS; |
| 19227 |
confp->chan.radio = 1; |
| 19228 |
} else if (!strcasecmp(v->value, "em_rx")) { |
| 19229 |
confp->chan.sig = SIG_EM; |
| 19230 |
confp->chan.radio = 1; |
| 19231 |
} else if (!strcasecmp(v->value, "em_tx")) { |
| 19232 |
confp->chan.sig = SIG_EM; |
| 19233 |
confp->chan.radio = 1; |
| 19234 |
} else if (!strcasecmp(v->value, "em_rxtx")) { |
| 19235 |
confp->chan.sig = SIG_EM; |
| 19236 |
confp->chan.radio = 2; |
| 19237 |
} else if (!strcasecmp(v->value, "em_txrx")) { |
| 19238 |
confp->chan.sig = SIG_EM; |
| 19239 |
confp->chan.radio = 2; |
| 19240 |
} else if (!strcasecmp(v->value, "sf")) { |
| 19241 |
confp->chan.sig = SIG_SF; |
| 19242 |
} else if (!strcasecmp(v->value, "sf_w")) { |
| 19243 |
confp->chan.sig = SIG_SFWINK; |
| 19244 |
} else if (!strcasecmp(v->value, "sf_featd")) { |
| 19245 |
confp->chan.sig = SIG_FEATD; |
| 19246 |
} else if (!strcasecmp(v->value, "sf_featdmf")) { |
| 19247 |
confp->chan.sig = SIG_FEATDMF; |
| 19248 |
} else if (!strcasecmp(v->value, "sf_featb")) { |
| 19249 |
confp->chan.sig = SIG_SF_FEATB; |
| 19250 |
} else if (!strcasecmp(v->value, "sf")) { |
| 19251 |
confp->chan.sig = SIG_SF; |
| 19252 |
} else if (!strcasecmp(v->value, "sf_rx")) { |
| 19253 |
confp->chan.sig = SIG_SF; |
| 19254 |
confp->chan.radio = 1; |
| 19255 |
} else if (!strcasecmp(v->value, "sf_tx")) { |
| 19256 |
confp->chan.sig = SIG_SF; |
| 19257 |
confp->chan.radio = 1; |
| 19258 |
} else if (!strcasecmp(v->value, "sf_rxtx")) { |
| 19259 |
confp->chan.sig = SIG_SF; |
| 19260 |
confp->chan.radio = 2; |
| 19261 |
} else if (!strcasecmp(v->value, "sf_txrx")) { |
| 19262 |
confp->chan.sig = SIG_SF; |
| 19263 |
confp->chan.radio = 2; |
| 19264 |
} else if (!strcasecmp(v->value, "featd")) { |
| 19265 |
confp->chan.sig = SIG_FEATD; |
| 19266 |
} else if (!strcasecmp(v->value, "featdmf")) { |
| 19267 |
confp->chan.sig = SIG_FEATDMF; |
| 19268 |
} else if (!strcasecmp(v->value, "featdmf_ta")) { |
| 19269 |
confp->chan.sig = SIG_FEATDMF_TA; |
| 19270 |
} else if (!strcasecmp(v->value, "e911")) { |
| 19271 |
confp->chan.sig = SIG_E911; |
| 19272 |
} else if (!strcasecmp(v->value, "fgccama")) { |
| 19273 |
confp->chan.sig = SIG_FGC_CAMA; |
| 19274 |
} else if (!strcasecmp(v->value, "fgccamamf")) { |
| 19275 |
confp->chan.sig = SIG_FGC_CAMAMF; |
| 19276 |
} else if (!strcasecmp(v->value, "featb")) { |
| 19277 |
confp->chan.sig = SIG_FEATB; |
| 19278 |
#ifdef HAVE_PRI |
| 19279 |
} else if (!strcasecmp(v->value, "pri_net")) { |
| 19280 |
confp->chan.sig = SIG_PRI; |
| 19281 |
confp->pri.pri.nodetype = PRI_NETWORK; |
| 19282 |
} else if (!strcasecmp(v->value, "pri_cpe")) { |
| 19283 |
confp->chan.sig = SIG_PRI; |
| 19284 |
confp->pri.pri.nodetype = PRI_CPE; |
| 19285 |
} else if (!strcasecmp(v->value, "bri_cpe")) { |
| 19286 |
confp->chan.sig = SIG_BRI; |
| 19287 |
confp->pri.pri.nodetype = PRI_CPE; |
| 19288 |
} else if (!strcasecmp(v->value, "bri_net")) { |
| 19289 |
confp->chan.sig = SIG_BRI; |
| 19290 |
confp->pri.pri.nodetype = PRI_NETWORK; |
| 19291 |
} else if (!strcasecmp(v->value, "bri_cpe_ptmp")) { |
| 19292 |
confp->chan.sig = SIG_BRI_PTMP; |
| 19293 |
confp->pri.pri.nodetype = PRI_CPE; |
| 19294 |
} else if (!strcasecmp(v->value, "bri_net_ptmp")) { |
| 19295 |
#if defined(HAVE_PRI_CALL_HOLD) |
| 19296 |
confp->chan.sig = SIG_BRI_PTMP; |
| 19297 |
confp->pri.pri.nodetype = PRI_NETWORK; |
| 19298 |
#else |
| 19299 |
ast_log(LOG_WARNING, "How cool would it be if someone implemented this mode! For now, sucks for you. (line %d)\n", v->lineno); |
| 19300 |
#endif |
| 19301 |
#endif |
| 19302 |
#if defined(HAVE_SS7) |
| 19303 |
} else if (!strcasecmp(v->value, "ss7")) { |
| 19304 |
confp->chan.sig = SIG_SS7; |
| 19305 |
#endif |
| 19306 |
#ifdef HAVE_OPENR2 |
| 19307 |
} else if (!strcasecmp(v->value, "mfcr2")) { |
| 19308 |
confp->chan.sig = SIG_MFCR2; |
| 19309 |
#endif |
| 19310 |
} else if (!strcasecmp(v->value, "auto")) { |
| 19311 |
confp->is_sig_auto = 1; |
| 19312 |
} else { |
| 19313 |
confp->chan.outsigmod = orig_outsigmod; |
| 19314 |
confp->chan.radio = orig_radio; |
| 19315 |
confp->is_sig_auto = orig_auto; |
| 19316 |
ast_log(LOG_ERROR, "Unknown signalling method '%s' at line %d.\n", v->value, v->lineno); |
| 19317 |
} |
| 19318 |
} else if (!strcasecmp(v->name, "outsignalling") || !strcasecmp(v->name, "outsignaling")) { |
| 19319 |
if (!strcasecmp(v->value, "em")) { |
| 19320 |
confp->chan.outsigmod = SIG_EM; |
| 19321 |
} else if (!strcasecmp(v->value, "em_e1")) { |
| 19322 |
confp->chan.outsigmod = SIG_EM_E1; |
| 19323 |
} else if (!strcasecmp(v->value, "em_w")) { |
| 19324 |
confp->chan.outsigmod = SIG_EMWINK; |
| 19325 |
} else if (!strcasecmp(v->value, "sf")) { |
| 19326 |
confp->chan.outsigmod = SIG_SF; |
| 19327 |
} else if (!strcasecmp(v->value, "sf_w")) { |
| 19328 |
confp->chan.outsigmod = SIG_SFWINK; |
| 19329 |
} else if (!strcasecmp(v->value, "sf_featd")) { |
| 19330 |
confp->chan.outsigmod = SIG_FEATD; |
| 19331 |
} else if (!strcasecmp(v->value, "sf_featdmf")) { |
| 19332 |
confp->chan.outsigmod = SIG_FEATDMF; |
| 19333 |
} else if (!strcasecmp(v->value, "sf_featb")) { |
| 19334 |
confp->chan.outsigmod = SIG_SF_FEATB; |
| 19335 |
} else if (!strcasecmp(v->value, "sf")) { |
| 19336 |
confp->chan.outsigmod = SIG_SF; |
| 19337 |
} else if (!strcasecmp(v->value, "featd")) { |
| 19338 |
confp->chan.outsigmod = SIG_FEATD; |
| 19339 |
} else if (!strcasecmp(v->value, "featdmf")) { |
| 19340 |
confp->chan.outsigmod = SIG_FEATDMF; |
| 19341 |
} else if (!strcasecmp(v->value, "featdmf_ta")) { |
| 19342 |
confp->chan.outsigmod = SIG_FEATDMF_TA; |
| 19343 |
} else if (!strcasecmp(v->value, "e911")) { |
| 19344 |
confp->chan.outsigmod = SIG_E911; |
| 19345 |
} else if (!strcasecmp(v->value, "fgccama")) { |
| 19346 |
confp->chan.outsigmod = SIG_FGC_CAMA; |
| 19347 |
} else if (!strcasecmp(v->value, "fgccamamf")) { |
| 19348 |
confp->chan.outsigmod = SIG_FGC_CAMAMF; |
| 19349 |
} else if (!strcasecmp(v->value, "featb")) { |
| 19350 |
confp->chan.outsigmod = SIG_FEATB; |
| 19351 |
} else { |
| 19352 |
ast_log(LOG_ERROR, "Unknown signalling method '%s' at line %d.\n", v->value, v->lineno); |
| 19353 |
} |
| 19354 |
#ifdef HAVE_PRI |
| 19355 |
} else if (!strcasecmp(v->name, "pridialplan")) { |
| 19356 |
if (!strcasecmp(v->value, "national")) { |
| 19357 |
confp->pri.pri.dialplan = PRI_NATIONAL_ISDN + 1; |
| 19358 |
} else if (!strcasecmp(v->value, "unknown")) { |
| 19359 |
confp->pri.pri.dialplan = PRI_UNKNOWN + 1; |
| 19360 |
} else if (!strcasecmp(v->value, "private")) { |
| 19361 |
confp->pri.pri.dialplan = PRI_PRIVATE + 1; |
| 19362 |
} else if (!strcasecmp(v->value, "international")) { |
| 19363 |
confp->pri.pri.dialplan = PRI_INTERNATIONAL_ISDN + 1; |
| 19364 |
} else if (!strcasecmp(v->value, "local")) { |
| 19365 |
confp->pri.pri.dialplan = PRI_LOCAL_ISDN + 1; |
| 19366 |
} else if (!strcasecmp(v->value, "dynamic")) { |
| 19367 |
confp->pri.pri.dialplan = -1; |
| 19368 |
} else if (!strcasecmp(v->value, "redundant")) { |
| 19369 |
confp->pri.pri.dialplan = -2; |
| 19370 |
} else { |
| 19371 |
ast_log(LOG_WARNING, "Unknown PRI dialplan '%s' at line %d.\n", v->value, v->lineno); |
| 19372 |
} |
| 19373 |
} else if (!strcasecmp(v->name, "prilocaldialplan")) { |
| 19374 |
if (!strcasecmp(v->value, "national")) { |
| 19375 |
confp->pri.pri.localdialplan = PRI_NATIONAL_ISDN + 1; |
| 19376 |
} else if (!strcasecmp(v->value, "unknown")) { |
| 19377 |
confp->pri.pri.localdialplan = PRI_UNKNOWN + 1; |
| 19378 |
} else if (!strcasecmp(v->value, "private")) { |
| 19379 |
confp->pri.pri.localdialplan = PRI_PRIVATE + 1; |
| 19380 |
} else if (!strcasecmp(v->value, "international")) { |
| 19381 |
confp->pri.pri.localdialplan = PRI_INTERNATIONAL_ISDN + 1; |
| 19382 |
} else if (!strcasecmp(v->value, "local")) { |
| 19383 |
confp->pri.pri.localdialplan = PRI_LOCAL_ISDN + 1; |
| 19384 |
} else if (!strcasecmp(v->value, "from_channel")) { |
| 19385 |
confp->pri.pri.localdialplan = 0; |
| 19386 |
} else if (!strcasecmp(v->value, "dynamic")) { |
| 19387 |
confp->pri.pri.localdialplan = -1; |
| 19388 |
} else if (!strcasecmp(v->value, "redundant")) { |
| 19389 |
confp->pri.pri.localdialplan = -2; |
| 19390 |
} else { |
| 19391 |
ast_log(LOG_WARNING, "Unknown PRI localdialplan '%s' at line %d.\n", v->value, v->lineno); |
| 19392 |
} |
| 19393 |
} else if (!strcasecmp(v->name, "pricpndialplan")) { |
| 19394 |
if (!strcasecmp(v->value, "national")) { |
| 19395 |
confp->pri.pri.cpndialplan = PRI_NATIONAL_ISDN + 1; |
| 19396 |
} else if (!strcasecmp(v->value, "unknown")) { |
| 19397 |
confp->pri.pri.cpndialplan = PRI_UNKNOWN + 1; |
| 19398 |
} else if (!strcasecmp(v->value, "private")) { |
| 19399 |
confp->pri.pri.cpndialplan = PRI_PRIVATE + 1; |
| 19400 |
} else if (!strcasecmp(v->value, "international")) { |
| 19401 |
confp->pri.pri.cpndialplan = PRI_INTERNATIONAL_ISDN + 1; |
| 19402 |
} else if (!strcasecmp(v->value, "local")) { |
| 19403 |
confp->pri.pri.cpndialplan = PRI_LOCAL_ISDN + 1; |
| 19404 |
} else if (!strcasecmp(v->value, "from_channel")) { |
| 19405 |
confp->pri.pri.cpndialplan = 0; |
| 19406 |
} else if (!strcasecmp(v->value, "dynamic")) { |
| 19407 |
confp->pri.pri.cpndialplan = -1; |
| 19408 |
} else if (!strcasecmp(v->value, "redundant")) { |
| 19409 |
confp->pri.pri.cpndialplan = -2; |
| 19410 |
} else { |
| 19411 |
ast_log(LOG_WARNING, "Unknown PRI cpndialplan '%s' at line %d.\n", v->value, v->lineno); |
| 19412 |
} |
| 19413 |
} else if (!strcasecmp(v->name, "switchtype")) { |
| 19414 |
if (!strcasecmp(v->value, "national")) |
| 19415 |
confp->pri.pri.switchtype = PRI_SWITCH_NI2; |
| 19416 |
else if (!strcasecmp(v->value, "ni1")) |
| 19417 |
confp->pri.pri.switchtype = PRI_SWITCH_NI1; |
| 19418 |
else if (!strcasecmp(v->value, "dms100")) |
| 19419 |
confp->pri.pri.switchtype = PRI_SWITCH_DMS100; |
| 19420 |
else if (!strcasecmp(v->value, "4ess")) |
| 19421 |
confp->pri.pri.switchtype = PRI_SWITCH_ATT4ESS; |
| 19422 |
else if (!strcasecmp(v->value, "5ess")) |
| 19423 |
confp->pri.pri.switchtype = PRI_SWITCH_LUCENT5E; |
| 19424 |
else if (!strcasecmp(v->value, "euroisdn")) |
| 19425 |
confp->pri.pri.switchtype = PRI_SWITCH_EUROISDN_E1; |
| 19426 |
else if (!strcasecmp(v->value, "qsig")) |
| 19427 |
confp->pri.pri.switchtype = PRI_SWITCH_QSIG; |
| 19428 |
else { |
| 19429 |
ast_log(LOG_ERROR, "Unknown switchtype '%s' at line %d.\n", v->value, v->lineno); |
| 19430 |
return -1; |
| 19431 |
} |
| 19432 |
} else if (!strcasecmp(v->name, "msn")) { |
| 19433 |
ast_copy_string(confp->pri.pri.msn_list, v->value, |
| 19434 |
sizeof(confp->pri.pri.msn_list)); |
| 19435 |
} else if (!strcasecmp(v->name, "nsf")) { |
| 19436 |
if (!strcasecmp(v->value, "sdn")) |
| 19437 |
confp->pri.pri.nsf = PRI_NSF_SDN; |
| 19438 |
else if (!strcasecmp(v->value, "megacom")) |
| 19439 |
confp->pri.pri.nsf = PRI_NSF_MEGACOM; |
| 19440 |
else if (!strcasecmp(v->value, "tollfreemegacom")) |
| 19441 |
confp->pri.pri.nsf = PRI_NSF_TOLL_FREE_MEGACOM; |
| 19442 |
else if (!strcasecmp(v->value, "accunet")) |
| 19443 |
confp->pri.pri.nsf = PRI_NSF_ACCUNET; |
| 19444 |
else if (!strcasecmp(v->value, "none")) |
| 19445 |
confp->pri.pri.nsf = PRI_NSF_NONE; |
| 19446 |
else { |
| 19447 |
ast_log(LOG_WARNING, "Unknown network-specific facility '%s' at line %d.\n", v->value, v->lineno); |
| 19448 |
confp->pri.pri.nsf = PRI_NSF_NONE; |
| 19449 |
} |
| 19450 |
} else if (!strcasecmp(v->name, "priindication")) { |
| 19451 |
if (!strcasecmp(v->value, "outofband")) |
| 19452 |
confp->chan.priindication_oob = 1; |
| 19453 |
else if (!strcasecmp(v->value, "inband")) |
| 19454 |
confp->chan.priindication_oob = 0; |
| 19455 |
else |
| 19456 |
ast_log(LOG_WARNING, "'%s' is not a valid pri indication value, should be 'inband' or 'outofband' at line %d.\n", |
| 19457 |
v->value, v->lineno); |
| 19458 |
} else if (!strcasecmp(v->name, "priexclusive")) { |
| 19459 |
confp->chan.priexclusive = ast_true(v->value); |
| 19460 |
} else if (!strcasecmp(v->name, "internationalprefix")) { |
| 19461 |
ast_copy_string(confp->pri.pri.internationalprefix, v->value, sizeof(confp->pri.pri.internationalprefix)); |
| 19462 |
} else if (!strcasecmp(v->name, "nationalprefix")) { |
| 19463 |
ast_copy_string(confp->pri.pri.nationalprefix, v->value, sizeof(confp->pri.pri.nationalprefix)); |
| 19464 |
} else if (!strcasecmp(v->name, "localprefix")) { |
| 19465 |
ast_copy_string(confp->pri.pri.localprefix, v->value, sizeof(confp->pri.pri.localprefix)); |
| 19466 |
} else if (!strcasecmp(v->name, "privateprefix")) { |
| 19467 |
ast_copy_string(confp->pri.pri.privateprefix, v->value, sizeof(confp->pri.pri.privateprefix)); |
| 19468 |
} else if (!strcasecmp(v->name, "unknownprefix")) { |
| 19469 |
ast_copy_string(confp->pri.pri.unknownprefix, v->value, sizeof(confp->pri.pri.unknownprefix)); |
| 19470 |
} else if (!strcasecmp(v->name, "resetinterval")) { |
| 19471 |
if (!strcasecmp(v->value, "never")) |
| 19472 |
confp->pri.pri.resetinterval = -1; |
| 19473 |
else if (atoi(v->value) >= 60) |
| 19474 |
confp->pri.pri.resetinterval = atoi(v->value); |
| 19475 |
else |
| 19476 |
ast_log(LOG_WARNING, "'%s' is not a valid reset interval, should be >= 60 seconds or 'never' at line %d.\n", |
| 19477 |
v->value, v->lineno); |
| 19478 |
} else if (!strcasecmp(v->name, "force_restart_unavailable_chans")) { |
| 19479 |
confp->pri.pri.force_restart_unavailable_chans = ast_true(v->value); |
| 19480 |
} else if (!strcasecmp(v->name, "minunused")) { |
| 19481 |
confp->pri.pri.minunused = atoi(v->value); |
| 19482 |
} else if (!strcasecmp(v->name, "minidle")) { |
| 19483 |
confp->pri.pri.minidle = atoi(v->value); |
| 19484 |
} else if (!strcasecmp(v->name, "idleext")) { |
| 19485 |
ast_copy_string(confp->pri.pri.idleext, v->value, sizeof(confp->pri.pri.idleext)); |
| 19486 |
} else if (!strcasecmp(v->name, "idledial")) { |
| 19487 |
ast_copy_string(confp->pri.pri.idledial, v->value, sizeof(confp->pri.pri.idledial)); |
| 19488 |
} else if (!strcasecmp(v->name, "overlapdial")) { |
| 19489 |
if (ast_true(v->value)) { |
| 19490 |
confp->pri.pri.overlapdial = DAHDI_OVERLAPDIAL_BOTH; |
| 19491 |
} else if (!strcasecmp(v->value, "incoming")) { |
| 19492 |
confp->pri.pri.overlapdial = DAHDI_OVERLAPDIAL_INCOMING; |
| 19493 |
} else if (!strcasecmp(v->value, "outgoing")) { |
| 19494 |
confp->pri.pri.overlapdial = DAHDI_OVERLAPDIAL_OUTGOING; |
| 19495 |
} else if (!strcasecmp(v->value, "both") || ast_true(v->value)) { |
| 19496 |
confp->pri.pri.overlapdial = DAHDI_OVERLAPDIAL_BOTH; |
| 19497 |
} else { |
| 19498 |
confp->pri.pri.overlapdial = DAHDI_OVERLAPDIAL_NONE; |
| 19499 |
} |
| 19500 |
#ifdef HAVE_PRI_PROG_W_CAUSE |
| 19501 |
} else if (!strcasecmp(v->name, "qsigchannelmapping")) { |
| 19502 |
if (!strcasecmp(v->value, "logical")) { |
| 19503 |
confp->pri.pri.qsigchannelmapping = DAHDI_CHAN_MAPPING_LOGICAL; |
| 19504 |
} else if (!strcasecmp(v->value, "physical")) { |
| 19505 |
confp->pri.pri.qsigchannelmapping = DAHDI_CHAN_MAPPING_PHYSICAL; |
| 19506 |
} else { |
| 19507 |
confp->pri.pri.qsigchannelmapping = DAHDI_CHAN_MAPPING_PHYSICAL; |
| 19508 |
} |
| 19509 |
#endif |
| 19510 |
} else if (!strcasecmp(v->name, "discardremoteholdretrieval")) { |
| 19511 |
confp->pri.pri.discardremoteholdretrieval = ast_true(v->value); |
| 19512 |
#if defined(HAVE_PRI_SERVICE_MESSAGES) |
| 19513 |
} else if (!strcasecmp(v->name, "service_message_support")) { |
| 19514 |
|
| 19515 |
if ((confp->pri.pri.switchtype == PRI_SWITCH_ATT4ESS |
| 19516 |
|| confp->pri.pri.switchtype == PRI_SWITCH_LUCENT5E |
| 19517 |
|| confp->pri.pri.switchtype == PRI_SWITCH_NI2) && ast_true(v->value)) { |
| 19518 |
confp->pri.pri.enable_service_message_support = 1; |
| 19519 |
} else { |
| 19520 |
confp->pri.pri.enable_service_message_support = 0; |
| 19521 |
} |
| 19522 |
#endif |
| 19523 |
#ifdef HAVE_PRI_INBANDDISCONNECT |
| 19524 |
} else if (!strcasecmp(v->name, "inbanddisconnect")) { |
| 19525 |
confp->pri.pri.inbanddisconnect = ast_true(v->value); |
| 19526 |
#endif |
| 19527 |
} else if (!strcasecmp(v->name, "pritimer")) { |
| 19528 |
#ifdef PRI_GETSET_TIMERS |
| 19529 |
char tmp[20]; |
| 19530 |
char *timerc; |
| 19531 |
char *c; |
| 19532 |
int timer; |
| 19533 |
int timeridx; |
| 19534 |
|
| 19535 |
ast_copy_string(tmp, v->value, sizeof(tmp)); |
| 19536 |
c = tmp; |
| 19537 |
timerc = strsep(&c, ","); |
| 19538 |
if (!ast_strlen_zero(timerc) && !ast_strlen_zero(c)) { |
| 19539 |
timeridx = pri_timer2idx(timerc); |
| 19540 |
timer = atoi(c); |
| 19541 |
if (timeridx < 0 || PRI_MAX_TIMERS <= timeridx) { |
| 19542 |
ast_log(LOG_WARNING, |
| 19543 |
"'%s' is not a valid ISDN timer at line %d.\n", timerc, |
| 19544 |
v->lineno); |
| 19545 |
} else if (!timer) { |
| 19546 |
ast_log(LOG_WARNING, |
| 19547 |
"'%s' is not a valid value for ISDN timer '%s' at line %d.\n", |
| 19548 |
c, timerc, v->lineno); |
| 19549 |
} else { |
| 19550 |
confp->pri.pri.pritimers[timeridx] = timer; |
| 19551 |
} |
| 19552 |
} else { |
| 19553 |
ast_log(LOG_WARNING, |
| 19554 |
"'%s' is not a valid ISDN timer configuration string at line %d.\n", |
| 19555 |
v->value, v->lineno); |
| 19556 |
} |
| 19557 |
#endif |
| 19558 |
} else if (!strcasecmp(v->name, "facilityenable")) { |
| 19559 |
confp->pri.pri.facilityenable = ast_true(v->value); |
| 19560 |
#if defined(HAVE_PRI_AOC_EVENTS) |
| 19561 |
} else if (!strcasecmp(v->name, "aoc_enable")) { |
| 19562 |
confp->pri.pri.aoc_passthrough_flag = 0; |
| 19563 |
if (strchr(v->value, 's') || strchr(v->value, 'S')) { |
| 19564 |
confp->pri.pri.aoc_passthrough_flag |= SIG_PRI_AOC_GRANT_S; |
| 19565 |
} |
| 19566 |
if (strchr(v->value, 'd') || strchr(v->value, 'D')) { |
| 19567 |
confp->pri.pri.aoc_passthrough_flag |= SIG_PRI_AOC_GRANT_D; |
| 19568 |
} |
| 19569 |
if (strchr(v->value, 'e') || strchr(v->value, 'E')) { |
| 19570 |
confp->pri.pri.aoc_passthrough_flag |= SIG_PRI_AOC_GRANT_E; |
| 19571 |
} |
| 19572 |
} else if (!strcasecmp(v->name, "aoce_delayhangup")) { |
| 19573 |
confp->pri.pri.aoce_delayhangup = ast_true(v->value); |
| 19574 |
#endif |
| 19575 |
#if defined(HAVE_PRI_CALL_HOLD) |
| 19576 |
} else if (!strcasecmp(v->name, "hold_disconnect_transfer")) { |
| 19577 |
confp->pri.pri.hold_disconnect_transfer = ast_true(v->value); |
| 19578 |
#endif |
| 19579 |
} else if (!strcasecmp(v->name, "moh_signaling") |
| 19580 |
|| !strcasecmp(v->name, "moh_signalling")) { |
| 19581 |
if (!strcasecmp(v->value, "moh")) { |
| 19582 |
confp->pri.pri.moh_signaling = SIG_PRI_MOH_SIGNALING_MOH; |
| 19583 |
} else if (!strcasecmp(v->value, "notify")) { |
| 19584 |
confp->pri.pri.moh_signaling = SIG_PRI_MOH_SIGNALING_NOTIFY; |
| 19585 |
#if defined(HAVE_PRI_CALL_HOLD) |
| 19586 |
} else if (!strcasecmp(v->value, "hold")) { |
| 19587 |
confp->pri.pri.moh_signaling = SIG_PRI_MOH_SIGNALING_HOLD; |
| 19588 |
#endif |
| 19589 |
} else { |
| 19590 |
confp->pri.pri.moh_signaling = SIG_PRI_MOH_SIGNALING_MOH; |
| 19591 |
} |
| 19592 |
#if defined(HAVE_PRI_CCSS) |
| 19593 |
} else if (!strcasecmp(v->name, "cc_ptmp_recall_mode")) { |
| 19594 |
if (!strcasecmp(v->value, "global")) { |
| 19595 |
confp->pri.pri.cc_ptmp_recall_mode = 0; |
| 19596 |
} else if (!strcasecmp(v->value, "specific")) { |
| 19597 |
confp->pri.pri.cc_ptmp_recall_mode = 1; |
| 19598 |
} else { |
| 19599 |
confp->pri.pri.cc_ptmp_recall_mode = 1; |
| 19600 |
} |
| 19601 |
} else if (!strcasecmp(v->name, "cc_qsig_signaling_link_req")) { |
| 19602 |
if (!strcasecmp(v->value, "release")) { |
| 19603 |
confp->pri.pri.cc_qsig_signaling_link_req = 0; |
| 19604 |
} else if (!strcasecmp(v->value, "retain")) { |
| 19605 |
confp->pri.pri.cc_qsig_signaling_link_req = 1; |
| 19606 |
} else if (!strcasecmp(v->value, "do_not_care")) { |
| 19607 |
confp->pri.pri.cc_qsig_signaling_link_req = 2; |
| 19608 |
} else { |
| 19609 |
confp->pri.pri.cc_qsig_signaling_link_req = 1; |
| 19610 |
} |
| 19611 |
} else if (!strcasecmp(v->name, "cc_qsig_signaling_link_rsp")) { |
| 19612 |
if (!strcasecmp(v->value, "release")) { |
| 19613 |
confp->pri.pri.cc_qsig_signaling_link_rsp = 0; |
| 19614 |
} else if (!strcasecmp(v->value, "retain")) { |
| 19615 |
confp->pri.pri.cc_qsig_signaling_link_rsp = 1; |
| 19616 |
} else { |
| 19617 |
confp->pri.pri.cc_qsig_signaling_link_rsp = 1; |
| 19618 |
} |
| 19619 |
#endif |
| 19620 |
#if defined(HAVE_PRI_CALL_WAITING) |
| 19621 |
} else if (!strcasecmp(v->name, "max_call_waiting_calls")) { |
| 19622 |
confp->pri.pri.max_call_waiting_calls = atoi(v->value); |
| 19623 |
if (confp->pri.pri.max_call_waiting_calls < 0) { |
| 19624 |
|
| 19625 |
confp->pri.pri.max_call_waiting_calls = 0; |
| 19626 |
} |
| 19627 |
} else if (!strcasecmp(v->name, "allow_call_waiting_calls")) { |
| 19628 |
confp->pri.pri.allow_call_waiting_calls = ast_true(v->value); |
| 19629 |
#endif |
| 19630 |
#if defined(HAVE_PRI_MWI) |
| 19631 |
} else if (!strcasecmp(v->name, "mwi_mailboxes")) { |
| 19632 |
ast_copy_string(confp->pri.pri.mwi_mailboxes, v->value, |
| 19633 |
sizeof(confp->pri.pri.mwi_mailboxes)); |
| 19634 |
} else if (!strcasecmp(v->name, "mwi_vm_boxes")) { |
| 19635 |
ast_copy_string(confp->pri.pri.mwi_vm_boxes, v->value, |
| 19636 |
sizeof(confp->pri.pri.mwi_vm_boxes)); |
| 19637 |
} else if (!strcasecmp(v->name, "mwi_vm_numbers")) { |
| 19638 |
ast_copy_string(confp->pri.pri.mwi_vm_numbers, v->value, |
| 19639 |
sizeof(confp->pri.pri.mwi_vm_numbers)); |
| 19640 |
#endif |
| 19641 |
} else if (!strcasecmp(v->name, "append_msn_to_cid_tag")) { |
| 19642 |
confp->pri.pri.append_msn_to_user_tag = ast_true(v->value); |
| 19643 |
} else if (!strcasecmp(v->name, "inband_on_setup_ack")) { |
| 19644 |
confp->pri.pri.inband_on_setup_ack = ast_true(v->value); |
| 19645 |
} else if (!strcasecmp(v->name, "inband_on_proceeding")) { |
| 19646 |
confp->pri.pri.inband_on_proceeding = ast_true(v->value); |
| 19647 |
#if defined(HAVE_PRI_DISPLAY_TEXT) |
| 19648 |
} else if (!strcasecmp(v->name, "display_send")) { |
| 19649 |
confp->pri.pri.display_flags_send = dahdi_display_text_option(v->value); |
| 19650 |
} else if (!strcasecmp(v->name, "display_receive")) { |
| 19651 |
confp->pri.pri.display_flags_receive = dahdi_display_text_option(v->value); |
| 19652 |
#endif |
| 19653 |
#if defined(HAVE_PRI_MCID) |
| 19654 |
} else if (!strcasecmp(v->name, "mcid_send")) { |
| 19655 |
confp->pri.pri.mcid_send = ast_true(v->value); |
| 19656 |
#endif |
| 19657 |
#if defined(HAVE_PRI_DATETIME_SEND) |
| 19658 |
} else if (!strcasecmp(v->name, "datetime_send")) { |
| 19659 |
confp->pri.pri.datetime_send = dahdi_datetime_send_option(v->value); |
| 19660 |
#endif |
| 19661 |
} else if (!strcasecmp(v->name, "layer1_presence")) { |
| 19662 |
if (!strcasecmp(v->value, "required")) { |
| 19663 |
confp->pri.pri.layer1_ignored = 0; |
| 19664 |
} else if (!strcasecmp(v->value, "ignore")) { |
| 19665 |
confp->pri.pri.layer1_ignored = 1; |
| 19666 |
} else { |
| 19667 |
|
| 19668 |
confp->pri.pri.layer1_ignored = 0; |
| 19669 |
} |
| 19670 |
#if defined(HAVE_PRI_L2_PERSISTENCE) |
| 19671 |
} else if (!strcasecmp(v->name, "layer2_persistence")) { |
| 19672 |
if (!strcasecmp(v->value, "keep_up")) { |
| 19673 |
confp->pri.pri.l2_persistence = PRI_L2_PERSISTENCE_KEEP_UP; |
| 19674 |
} else if (!strcasecmp(v->value, "leave_down")) { |
| 19675 |
confp->pri.pri.l2_persistence = PRI_L2_PERSISTENCE_LEAVE_DOWN; |
| 19676 |
} else { |
| 19677 |
confp->pri.pri.l2_persistence = PRI_L2_PERSISTENCE_DEFAULT; |
| 19678 |
} |
| 19679 |
#endif |
| 19680 |
} else if (!strcasecmp(v->name, "colp_send")) { |
| 19681 |
if (!strcasecmp(v->value, "block")) { |
| 19682 |
confp->pri.pri.colp_send = SIG_PRI_COLP_BLOCK; |
| 19683 |
} else if (!strcasecmp(v->value, "connect")) { |
| 19684 |
confp->pri.pri.colp_send = SIG_PRI_COLP_CONNECT; |
| 19685 |
} else if (!strcasecmp(v->value, "update")) { |
| 19686 |
confp->pri.pri.colp_send = SIG_PRI_COLP_UPDATE; |
| 19687 |
} else { |
| 19688 |
confp->pri.pri.colp_send = SIG_PRI_COLP_UPDATE; |
| 19689 |
} |
| 19690 |
#endif |
| 19691 |
#if defined(HAVE_SS7) |
| 19692 |
} else if (!strcasecmp(v->name, "ss7type")) { |
| 19693 |
if (!strcasecmp(v->value, "itu")) { |
| 19694 |
cur_ss7type = SS7_ITU; |
| 19695 |
} else if (!strcasecmp(v->value, "ansi")) { |
| 19696 |
cur_ss7type = SS7_ANSI; |
| 19697 |
} else { |
| 19698 |
ast_log(LOG_WARNING, "'%s' is an unknown ss7 switch type at line %d.!\n", v->value, v->lineno); |
| 19699 |
} |
| 19700 |
} else if (!strcasecmp(v->name, "slc")) { |
| 19701 |
cur_slc = atoi(v->value); |
| 19702 |
} else if (!strcasecmp(v->name, "linkset")) { |
| 19703 |
cur_linkset = atoi(v->value); |
| 19704 |
} else if (!strcasecmp(v->name, "pointcode")) { |
| 19705 |
cur_pointcode = parse_pointcode(v->value); |
| 19706 |
} else if (!strcasecmp(v->name, "adjpointcode")) { |
| 19707 |
cur_adjpointcode = parse_pointcode(v->value); |
| 19708 |
} else if (!strcasecmp(v->name, "defaultdpc")) { |
| 19709 |
cur_defaultdpc = parse_pointcode(v->value); |
| 19710 |
} else if (!strcasecmp(v->name, "cicbeginswith")) { |
| 19711 |
cur_cicbeginswith = atoi(v->value); |
| 19712 |
} else if (!strcasecmp(v->name, "networkindicator")) { |
| 19713 |
if (!strcasecmp(v->value, "national")) { |
| 19714 |
cur_networkindicator = SS7_NI_NAT; |
| 19715 |
} else if (!strcasecmp(v->value, "national_spare")) { |
| 19716 |
cur_networkindicator = SS7_NI_NAT_SPARE; |
| 19717 |
} else if (!strcasecmp(v->value, "international")) { |
| 19718 |
cur_networkindicator = SS7_NI_INT; |
| 19719 |
} else if (!strcasecmp(v->value, "international_spare")) { |
| 19720 |
cur_networkindicator = SS7_NI_INT_SPARE; |
| 19721 |
} else { |
| 19722 |
cur_networkindicator = -1; |
| 19723 |
} |
| 19724 |
} else if (!strcasecmp(v->name, "ss7_internationalprefix")) { |
| 19725 |
ast_copy_string(confp->ss7.ss7.internationalprefix, v->value, sizeof(confp->ss7.ss7.internationalprefix)); |
| 19726 |
} else if (!strcasecmp(v->name, "ss7_nationalprefix")) { |
| 19727 |
ast_copy_string(confp->ss7.ss7.nationalprefix, v->value, sizeof(confp->ss7.ss7.nationalprefix)); |
| 19728 |
} else if (!strcasecmp(v->name, "ss7_subscriberprefix")) { |
| 19729 |
ast_copy_string(confp->ss7.ss7.subscriberprefix, v->value, sizeof(confp->ss7.ss7.subscriberprefix)); |
| 19730 |
} else if (!strcasecmp(v->name, "ss7_unknownprefix")) { |
| 19731 |
ast_copy_string(confp->ss7.ss7.unknownprefix, v->value, sizeof(confp->ss7.ss7.unknownprefix)); |
| 19732 |
} else if (!strcasecmp(v->name, "ss7_networkroutedprefix")) { |
| 19733 |
ast_copy_string(confp->ss7.ss7.networkroutedprefix, v->value, sizeof(confp->ss7.ss7.networkroutedprefix)); |
| 19734 |
} else if (!strcasecmp(v->name, "ss7_called_nai")) { |
| 19735 |
if (!strcasecmp(v->value, "national")) { |
| 19736 |
confp->ss7.ss7.called_nai = SS7_NAI_NATIONAL; |
| 19737 |
} else if (!strcasecmp(v->value, "international")) { |
| 19738 |
confp->ss7.ss7.called_nai = SS7_NAI_INTERNATIONAL; |
| 19739 |
} else if (!strcasecmp(v->value, "subscriber")) { |
| 19740 |
confp->ss7.ss7.called_nai = SS7_NAI_SUBSCRIBER; |
| 19741 |
} else if (!strcasecmp(v->value, "unknown")) { |
| 19742 |
confp->ss7.ss7.called_nai = SS7_NAI_UNKNOWN; |
| 19743 |
} else if (!strcasecmp(v->value, "dynamic")) { |
| 19744 |
confp->ss7.ss7.called_nai = SS7_NAI_DYNAMIC; |
| 19745 |
} else { |
| 19746 |
ast_log(LOG_WARNING, "Unknown SS7 called_nai '%s' at line %d.\n", v->value, v->lineno); |
| 19747 |
} |
| 19748 |
} else if (!strcasecmp(v->name, "ss7_calling_nai")) { |
| 19749 |
if (!strcasecmp(v->value, "national")) { |
| 19750 |
confp->ss7.ss7.calling_nai = SS7_NAI_NATIONAL; |
| 19751 |
} else if (!strcasecmp(v->value, "international")) { |
| 19752 |
confp->ss7.ss7.calling_nai = SS7_NAI_INTERNATIONAL; |
| 19753 |
} else if (!strcasecmp(v->value, "subscriber")) { |
| 19754 |
confp->ss7.ss7.calling_nai = SS7_NAI_SUBSCRIBER; |
| 19755 |
} else if (!strcasecmp(v->value, "unknown")) { |
| 19756 |
confp->ss7.ss7.calling_nai = SS7_NAI_UNKNOWN; |
| 19757 |
} else if (!strcasecmp(v->value, "dynamic")) { |
| 19758 |
confp->ss7.ss7.calling_nai = SS7_NAI_DYNAMIC; |
| 19759 |
} else { |
| 19760 |
ast_log(LOG_WARNING, "Unknown SS7 calling_nai '%s' at line %d.\n", v->value, v->lineno); |
| 19761 |
} |
| 19762 |
} else if (!strcasecmp(v->name, "sigchan")) { |
| 19763 |
int sigchan, res; |
| 19764 |
sigchan = atoi(v->value); |
| 19765 |
res = linkset_addsigchan(sigchan); |
| 19766 |
if (res < 0) { |
| 19767 |
return -1; |
| 19768 |
} |
| 19769 |
} else if (!strcasecmp(v->name, "ss7_explicitacm")) { |
| 19770 |
struct dahdi_ss7 *link; |
| 19771 |
link = ss7_resolve_linkset(cur_linkset); |
| 19772 |
if (!link) { |
| 19773 |
ast_log(LOG_ERROR, "Invalid linkset number. Must be between 1 and %d\n", NUM_SPANS + 1); |
| 19774 |
return -1; |
| 19775 |
} |
| 19776 |
if (ast_true(v->value)) { |
| 19777 |
link->ss7.flags |= LINKSET_FLAG_EXPLICITACM; |
| 19778 |
} else { |
| 19779 |
link->ss7.flags &= ~LINKSET_FLAG_EXPLICITACM; |
| 19780 |
} |
| 19781 |
} else if (!strcasecmp(v->name, "ss7_autoacm")) { |
| 19782 |
struct dahdi_ss7 *link; |
| 19783 |
link = ss7_resolve_linkset(cur_linkset); |
| 19784 |
if (!link) { |
| 19785 |
ast_log(LOG_ERROR, "Invalid linkset number. Must be between 1 and %d\n", NUM_SPANS + 1); |
| 19786 |
return -1; |
| 19787 |
} |
| 19788 |
if (ast_true(v->value)) { |
| 19789 |
link->ss7.flags |= LINKSET_FLAG_AUTOACM; |
| 19790 |
} else { |
| 19791 |
link->ss7.flags &= ~LINKSET_FLAG_AUTOACM; |
| 19792 |
} |
| 19793 |
} else if (!strcasecmp(v->name, "ss7_initialhwblo")) { |
| 19794 |
struct dahdi_ss7 *link; |
| 19795 |
link = ss7_resolve_linkset(cur_linkset); |
| 19796 |
if (!link) { |
| 19797 |
ast_log(LOG_ERROR, "Invalid linkset number. Must be between 1 and %d\n", NUM_SPANS + 1); |
| 19798 |
return -1; |
| 19799 |
} |
| 19800 |
if (ast_true(v->value)) { |
| 19801 |
link->ss7.flags |= LINKSET_FLAG_INITIALHWBLO; |
| 19802 |
} else { |
| 19803 |
link->ss7.flags &= ~LINKSET_FLAG_INITIALHWBLO; |
| 19804 |
} |
| 19805 |
} else if (!strcasecmp(v->name, "ss7_use_echocontrol")) { |
| 19806 |
struct dahdi_ss7 *link; |
| 19807 |
link = ss7_resolve_linkset(cur_linkset); |
| 19808 |
if (!link) { |
| 19809 |
ast_log(LOG_ERROR, "Invalid linkset number. Must be between 1 and %d\n", NUM_SPANS + 1); |
| 19810 |
return -1; |
| 19811 |
} |
| 19812 |
if (ast_true(v->value)) { |
| 19813 |
link->ss7.flags |= LINKSET_FLAG_USEECHOCONTROL; |
| 19814 |
} else { |
| 19815 |
link->ss7.flags &= ~LINKSET_FLAG_USEECHOCONTROL; |
| 19816 |
} |
| 19817 |
} else if (!strcasecmp(v->name, "ss7_default_echocontrol")) { |
| 19818 |
struct dahdi_ss7 *link; |
| 19819 |
link = ss7_resolve_linkset(cur_linkset); |
| 19820 |
if (!link) { |
| 19821 |
ast_log(LOG_ERROR, "Invalid linkset number. Must be between 1 and %d\n", NUM_SPANS + 1); |
| 19822 |
return -1; |
| 19823 |
} |
| 19824 |
if (ast_true(v->value)) { |
| 19825 |
link->ss7.flags |= LINKSET_FLAG_DEFAULTECHOCONTROL; |
| 19826 |
} else { |
| 19827 |
link->ss7.flags &= ~LINKSET_FLAG_DEFAULTECHOCONTROL; |
| 19828 |
} |
| 19829 |
} else if (!strncasecmp(v->name, "isup_timer.", 11)) { |
| 19830 |
struct dahdi_ss7 *link; |
| 19831 |
link = ss7_resolve_linkset(cur_linkset); |
| 19832 |
if (!link) { |
| 19833 |
ast_log(LOG_ERROR, "Invalid linkset number. Must be between 1 and %d\n", NUM_SPANS + 1); |
| 19834 |
return -1; |
| 19835 |
} |
| 19836 |
if (!link->ss7.ss7) { |
| 19837 |
ast_log(LOG_ERROR, "Please specify isup timers after sigchan!\n"); |
| 19838 |
|
| 19839 |
} else if (!ss7_set_isup_timer(link->ss7.ss7, (char*) strstr(v->name, ".") + 1, atoi(v->value))) { |
| 19840 |
ast_log(LOG_ERROR, "Invalid isup timer %s\n", v->name); |
| 19841 |
} |
| 19842 |
} else if (!strncasecmp(v->name, "mtp3_timer.", 11)) { |
| 19843 |
struct dahdi_ss7 *link; |
| 19844 |
link = ss7_resolve_linkset(cur_linkset); |
| 19845 |
if (!link) { |
| 19846 |
ast_log(LOG_ERROR, "Invalid linkset number. Must be between 1 and %d\n", NUM_SPANS + 1); |
| 19847 |
return -1; |
| 19848 |
} |
| 19849 |
if (!link->ss7.ss7) { |
| 19850 |
ast_log(LOG_ERROR, "Please specify mtp3 timers after sigchan!\n"); |
| 19851 |
|
| 19852 |
} else if (!ss7_set_mtp3_timer(link->ss7.ss7, (char*) strstr(v->name, ".") + 1, atoi(v->value))) { |
| 19853 |
ast_log(LOG_ERROR, "Invalid mtp3 timer %s\n", v->name); |
| 19854 |
} |
| 19855 |
} else if (!strcasecmp(v->name, "inr_if_no_calling")) { |
| 19856 |
struct dahdi_ss7 *link; |
| 19857 |
link = ss7_resolve_linkset(cur_linkset); |
| 19858 |
if (!link) { |
| 19859 |
ast_log(LOG_ERROR, "Invalid linkset number. Must be between 1 and %d\n", NUM_SPANS + 1); |
| 19860 |
return -1; |
| 19861 |
} |
| 19862 |
if (!link->ss7.ss7) { |
| 19863 |
ast_log(LOG_ERROR, "Please specify inr_if_no_calling after sigchan!\n"); |
| 19864 |
} else if (ast_true(v->value)) { |
| 19865 |
ss7_set_flags(link->ss7.ss7, SS7_INR_IF_NO_CALLING); |
| 19866 |
} else { |
| 19867 |
ss7_clear_flags(link->ss7.ss7, SS7_INR_IF_NO_CALLING); |
| 19868 |
} |
| 19869 |
} else if (!strcasecmp(v->name, "non_isdn_access")) { |
| 19870 |
struct dahdi_ss7 *link; |
| 19871 |
link = ss7_resolve_linkset(cur_linkset); |
| 19872 |
if (!link) { |
| 19873 |
ast_log(LOG_ERROR, "Invalid linkset number. Must be between 1 and %d\n", NUM_SPANS + 1); |
| 19874 |
return -1; |
| 19875 |
} |
| 19876 |
if (!link->ss7.ss7) { |
| 19877 |
ast_log(LOG_ERROR, "Please specify non_isdn_access after sigchan!\n"); |
| 19878 |
} else if (ast_true(v->value)) { |
| 19879 |
ss7_clear_flags(link->ss7.ss7, SS7_ISDN_ACCESS_INDICATOR); |
| 19880 |
} else { |
| 19881 |
ss7_set_flags(link->ss7.ss7, SS7_ISDN_ACCESS_INDICATOR); |
| 19882 |
} |
| 19883 |
} else if (!strcasecmp(v->name, "sls_shift")) { |
| 19884 |
struct dahdi_ss7 *link; |
| 19885 |
int sls_shift = atoi(v->value); |
| 19886 |
|
| 19887 |
if (sls_shift < 0 || sls_shift > 7) { |
| 19888 |
ast_log(LOG_ERROR, "Invalid sls_shift value. Must be between 0 and 7\n"); |
| 19889 |
return -1; |
| 19890 |
} |
| 19891 |
|
| 19892 |
link = ss7_resolve_linkset(cur_linkset); |
| 19893 |
if (!link) { |
| 19894 |
ast_log(LOG_ERROR, "Invalid linkset number. Must be between 1 and %d\n", NUM_SPANS + 1); |
| 19895 |
return -1; |
| 19896 |
} |
| 19897 |
if (!link->ss7.ss7) { |
| 19898 |
ast_log(LOG_ERROR, "Please specify sls_shift after sigchan!\n"); |
| 19899 |
} else { |
| 19900 |
ss7_set_sls_shift(link->ss7.ss7, sls_shift); |
| 19901 |
} |
| 19902 |
} else if (!strcasecmp(v->name, "cause_location")) { |
| 19903 |
struct dahdi_ss7 *link; |
| 19904 |
int cause_location = atoi(v->value); |
| 19905 |
|
| 19906 |
if (cause_location < 0 || cause_location > 15) { |
| 19907 |
ast_log(LOG_ERROR, "Invalid cause_location value. Must be between 0 and 15\n"); |
| 19908 |
return -1; |
| 19909 |
} |
| 19910 |
link = ss7_resolve_linkset(cur_linkset); |
| 19911 |
if (!link) { |
| 19912 |
ast_log(LOG_ERROR, "Invalid linkset number. Must be between 1 and %d\n", NUM_SPANS + 1); |
| 19913 |
return -1; |
| 19914 |
} |
| 19915 |
if (!link->ss7.ss7) { |
| 19916 |
ast_log(LOG_ERROR, "Please specify cause_location after sigchan!\n"); |
| 19917 |
} else { |
| 19918 |
ss7_set_cause_location(link->ss7.ss7, cause_location); |
| 19919 |
} |
| 19920 |
#endif |
| 19921 |
#ifdef HAVE_OPENR2 |
| 19922 |
} else if (!strcasecmp(v->name, "mfcr2_advanced_protocol_file")) { |
| 19923 |
ast_copy_string(confp->mfcr2.r2proto_file, v->value, sizeof(confp->mfcr2.r2proto_file)); |
| 19924 |
ast_log(LOG_WARNING, "MFC/R2 Protocol file '%s' will be used, you only should use this if you *REALLY KNOW WHAT YOU ARE DOING*.\n", confp->mfcr2.r2proto_file); |
| 19925 |
} else if (!strcasecmp(v->name, "mfcr2_logdir")) { |
| 19926 |
ast_copy_string(confp->mfcr2.logdir, v->value, sizeof(confp->mfcr2.logdir)); |
| 19927 |
} else if (!strcasecmp(v->name, "mfcr2_variant")) { |
| 19928 |
confp->mfcr2.variant = openr2_proto_get_variant(v->value); |
| 19929 |
if (OR2_VAR_UNKNOWN == confp->mfcr2.variant) { |
| 19930 |
ast_log(LOG_WARNING, "Unknown MFC/R2 variant '%s' at line %d, defaulting to ITU.\n", v->value, v->lineno); |
| 19931 |
confp->mfcr2.variant = OR2_VAR_ITU; |
| 19932 |
} |
| 19933 |
} else if (!strcasecmp(v->name, "mfcr2_mfback_timeout")) { |
| 19934 |
confp->mfcr2.mfback_timeout = atoi(v->value); |
| 19935 |
if (!confp->mfcr2.mfback_timeout) { |
| 19936 |
ast_log(LOG_WARNING, "MF timeout of 0? hum, I will protect you from your ignorance. Setting default.\n"); |
| 19937 |
confp->mfcr2.mfback_timeout = -1; |
| 19938 |
} else if (confp->mfcr2.mfback_timeout > 0 && confp->mfcr2.mfback_timeout < 500) { |
| 19939 |
ast_log(LOG_WARNING, "MF timeout less than 500ms is not recommended, you have been warned!\n"); |
| 19940 |
} |
| 19941 |
} else if (!strcasecmp(v->name, "mfcr2_metering_pulse_timeout")) { |
| 19942 |
confp->mfcr2.metering_pulse_timeout = atoi(v->value); |
| 19943 |
if (confp->mfcr2.metering_pulse_timeout > 500) { |
| 19944 |
ast_log(LOG_WARNING, "Metering pulse timeout greater than 500ms is not recommended, you have been warned!\n"); |
| 19945 |
} |
| 19946 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2 |
| 19947 |
} else if (!strcasecmp(v->name, "mfcr2_dtmf_detection")) { |
| 19948 |
confp->mfcr2.dtmf_detection = ast_true(v->value) ? 1 : 0; |
| 19949 |
} else if (!strcasecmp(v->name, "mfcr2_dtmf_dialing")) { |
| 19950 |
confp->mfcr2.dtmf_dialing = ast_true(v->value) ? 1 : 0; |
| 19951 |
} else if (!strcasecmp(v->name, "mfcr2_dtmf_time_on")) { |
| 19952 |
confp->mfcr2.dtmf_time_on = atoi(v->value); |
| 19953 |
} else if (!strcasecmp(v->name, "mfcr2_dtmf_time_off")) { |
| 19954 |
confp->mfcr2.dtmf_time_off = atoi(v->value); |
| 19955 |
#endif |
| 19956 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3 |
| 19957 |
} else if (!strcasecmp(v->name, "mfcr2_dtmf_end_timeout")) { |
| 19958 |
confp->mfcr2.dtmf_end_timeout = atoi(v->value); |
| 19959 |
#endif |
| 19960 |
} else if (!strcasecmp(v->name, "mfcr2_get_ani_first")) { |
| 19961 |
confp->mfcr2.get_ani_first = ast_true(v->value) ? 1 : 0; |
| 19962 |
} else if (!strcasecmp(v->name, "mfcr2_double_answer")) { |
| 19963 |
confp->mfcr2.double_answer = ast_true(v->value) ? 1 : 0; |
| 19964 |
} else if (!strcasecmp(v->name, "mfcr2_charge_calls")) { |
| 19965 |
confp->mfcr2.charge_calls = ast_true(v->value) ? 1 : 0; |
| 19966 |
} else if (!strcasecmp(v->name, "mfcr2_accept_on_offer")) { |
| 19967 |
confp->mfcr2.accept_on_offer = ast_true(v->value) ? 1 : 0; |
| 19968 |
} else if (!strcasecmp(v->name, "mfcr2_allow_collect_calls")) { |
| 19969 |
confp->mfcr2.allow_collect_calls = ast_true(v->value) ? 1 : 0; |
| 19970 |
} else if (!strcasecmp(v->name, "mfcr2_forced_release")) { |
| 19971 |
confp->mfcr2.forced_release = ast_true(v->value) ? 1 : 0; |
| 19972 |
} else if (!strcasecmp(v->name, "mfcr2_immediate_accept")) { |
| 19973 |
confp->mfcr2.immediate_accept = ast_true(v->value) ? 1 : 0; |
| 19974 |
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1 |
| 19975 |
} else if (!strcasecmp(v->name, "mfcr2_skip_category")) { |
| 19976 |
confp->mfcr2.skip_category_request = ast_true(v->value) ? 1 : 0; |
| 19977 |
#endif |
| 19978 |
} else if (!strcasecmp(v->name, "mfcr2_call_files")) { |
| 19979 |
confp->mfcr2.call_files = ast_true(v->value) ? 1 : 0; |
| 19980 |
} else if (!strcasecmp(v->name, "mfcr2_max_ani")) { |
| 19981 |
confp->mfcr2.max_ani = atoi(v->value); |
| 19982 |
if (confp->mfcr2.max_ani >= AST_MAX_EXTENSION) { |
| 19983 |
confp->mfcr2.max_ani = AST_MAX_EXTENSION - 1; |
| 19984 |
} |
| 19985 |
} else if (!strcasecmp(v->name, "mfcr2_max_dnis")) { |
| 19986 |
confp->mfcr2.max_dnis = atoi(v->value); |
| 19987 |
if (confp->mfcr2.max_dnis >= AST_MAX_EXTENSION) { |
| 19988 |
confp->mfcr2.max_dnis = AST_MAX_EXTENSION - 1; |
| 19989 |
} |
| 19990 |
} else if (!strcasecmp(v->name, "mfcr2_category")) { |
| 19991 |
confp->mfcr2.category = openr2_proto_get_category(v->value); |
| 19992 |
if (OR2_CALLING_PARTY_CATEGORY_UNKNOWN == confp->mfcr2.category) { |
| 19993 |
confp->mfcr2.category = OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER; |
| 19994 |
ast_log(LOG_WARNING, "Invalid MFC/R2 caller category '%s' at line %d. Using national subscriber as default.\n", |
| 19995 |
v->value, v->lineno); |
| 19996 |
} |
| 19997 |
} else if (!strcasecmp(v->name, "mfcr2_logging")) { |
| 19998 |
openr2_log_level_t tmplevel; |
| 19999 |
char *clevel; |
| 20000 |
char *logval; |
| 20001 |
char copy[strlen(v->value) + 1]; |
| 20002 |
strcpy(copy, v->value); |
| 20003 |
logval = copy; |
| 20004 |
while (logval) { |
| 20005 |
clevel = strsep(&logval,","); |
| 20006 |
if (-1 == (tmplevel = openr2_log_get_level(clevel))) { |
| 20007 |
ast_log(LOG_WARNING, "Ignoring invalid logging level: '%s' at line %d.\n", clevel, v->lineno); |
| 20008 |
continue; |
| 20009 |
} |
| 20010 |
confp->mfcr2.loglevel |= tmplevel; |
| 20011 |
} |
| 20012 |
#endif |
| 20013 |
} else if (!strcasecmp(v->name, "cadence")) { |
| 20014 |
|
| 20015 |
int element_count, c[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; |
| 20016 |
int i; |
| 20017 |
struct dahdi_ring_cadence new_cadence; |
| 20018 |
int cid_location = -1; |
| 20019 |
int firstcadencepos = 0; |
| 20020 |
char original_args[80]; |
| 20021 |
int cadence_is_ok = 1; |
| 20022 |
|
| 20023 |
ast_copy_string(original_args, v->value, sizeof(original_args)); |
| 20024 |
|
| 20025 |
element_count = sscanf(v->value, "%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d", &c[0], &c[1], &c[2], &c[3], &c[4], &c[5], &c[6], &c[7], &c[8], &c[9], &c[10], &c[11], &c[12], &c[13], &c[14], &c[15]); |
| 20026 |
|
| 20027 |
|
| 20028 |
if (element_count % 2 == 1) { |
| 20029 |
ast_log(LOG_ERROR, "Must be a silence duration for each ring duration: %s at line %d.\n", original_args, v->lineno); |
| 20030 |
cadence_is_ok = 0; |
| 20031 |
} |
| 20032 |
|
| 20033 |
|
| 20034 |
if (element_count > ARRAY_LEN(c)) { |
| 20035 |
element_count = ARRAY_LEN(c); |
| 20036 |
} |
| 20037 |
|
| 20038 |
|
| 20039 |
for (i = 0; i < element_count; i++) { |
| 20040 |
if (c[i] == 0) { |
| 20041 |
ast_log(LOG_ERROR, "Ring or silence duration cannot be zero: %s at line %d.\n", original_args, v->lineno); |
| 20042 |
cadence_is_ok = 0; |
| 20043 |
break; |
| 20044 |
} else if (c[i] < 0) { |
| 20045 |
if (i % 2 == 1) { |
| 20046 |
|
| 20047 |
if (cid_location == -1) { |
| 20048 |
cid_location = i; |
| 20049 |
c[i] *= -1; |
| 20050 |
} else { |
| 20051 |
ast_log(LOG_ERROR, "CID location specified twice: %s at line %d.\n", original_args, v->lineno); |
| 20052 |
cadence_is_ok = 0; |
| 20053 |
break; |
| 20054 |
} |
| 20055 |
} else { |
| 20056 |
if (firstcadencepos == 0) { |
| 20057 |
firstcadencepos = i; |
| 20058 |
|
| 20059 |
} else { |
| 20060 |
ast_log(LOG_ERROR, "First cadence position specified twice: %s at line %d.\n", original_args, v->lineno); |
| 20061 |
cadence_is_ok = 0; |
| 20062 |
break; |
| 20063 |
} |
| 20064 |
} |
| 20065 |
} |
| 20066 |
} |
| 20067 |
|
| 20068 |
|
| 20069 |
for (i = 0; i < 16; i++) { |
| 20070 |
new_cadence.ringcadence[i] = c[i]; |
| 20071 |
} |
| 20072 |
|
| 20073 |
if (cadence_is_ok) { |
| 20074 |
|
| 20075 |
if (element_count < 2) { |
| 20076 |
ast_log(LOG_ERROR, "Minimum cadence is ring,pause: %s at line %d.\n", original_args, v->lineno); |
| 20077 |
} else { |
| 20078 |
if (cid_location == -1) { |
| 20079 |
|
| 20080 |
cid_location = 1; |
| 20081 |
} else { |
| 20082 |
|
| 20083 |
cid_location = (cid_location + 1) / 2; |
| 20084 |
} |
| 20085 |
|
| 20086 |
if (!user_has_defined_cadences++) |
| 20087 |
|
| 20088 |
num_cadence = 0; |
| 20089 |
if ((num_cadence+1) >= NUM_CADENCE_MAX) |
| 20090 |
ast_log(LOG_ERROR, "Already %d cadences; can't add another: %s at line %d.\n", NUM_CADENCE_MAX, original_args, v->lineno); |
| 20091 |
else { |
| 20092 |
cadences[num_cadence] = new_cadence; |
| 20093 |
cidrings[num_cadence++] = cid_location; |
| 20094 |
ast_verb(3, "cadence 'r%d' added: %s\n",num_cadence,original_args); |
| 20095 |
} |
| 20096 |
} |
| 20097 |
} |
| 20098 |
} else if (!strcasecmp(v->name, "ringtimeout")) { |
| 20099 |
ringt_base = (atoi(v->value) * 8) / READ_SIZE; |
| 20100 |
} else if (!strcasecmp(v->name, "prewink")) { |
| 20101 |
confp->timing.prewinktime = atoi(v->value); |
| 20102 |
} else if (!strcasecmp(v->name, "preflash")) { |
| 20103 |
confp->timing.preflashtime = atoi(v->value); |
| 20104 |
} else if (!strcasecmp(v->name, "wink")) { |
| 20105 |
confp->timing.winktime = atoi(v->value); |
| 20106 |
} else if (!strcasecmp(v->name, "flash")) { |
| 20107 |
confp->timing.flashtime = atoi(v->value); |
| 20108 |
} else if (!strcasecmp(v->name, "start")) { |
| 20109 |
confp->timing.starttime = atoi(v->value); |
| 20110 |
} else if (!strcasecmp(v->name, "rxwink")) { |
| 20111 |
confp->timing.rxwinktime = atoi(v->value); |
| 20112 |
} else if (!strcasecmp(v->name, "rxflash")) { |
| 20113 |
confp->timing.rxflashtime = atoi(v->value); |
| 20114 |
} else if (!strcasecmp(v->name, "debounce")) { |
| 20115 |
confp->timing.debouncetime = atoi(v->value); |
| 20116 |
} else if (!strcasecmp(v->name, "toneduration")) { |
| 20117 |
int toneduration; |
| 20118 |
int ctlfd; |
| 20119 |
int res; |
| 20120 |
struct dahdi_dialparams dps; |
| 20121 |
|
| 20122 |
ctlfd = open("/dev/dahdi/ctl", O_RDWR); |
| 20123 |
if (ctlfd == -1) { |
| 20124 |
ast_log(LOG_ERROR, "Unable to open /dev/dahdi/ctl to set toneduration at line %d.\n", v->lineno); |
| 20125 |
return -1; |
| 20126 |
} |
| 20127 |
|
| 20128 |
toneduration = atoi(v->value); |
| 20129 |
if (toneduration > -1) { |
| 20130 |
memset(&dps, 0, sizeof(dps)); |
| 20131 |
|
| 20132 |
dps.dtmf_tonelen = dps.mfv1_tonelen = toneduration; |
| 20133 |
res = ioctl(ctlfd, DAHDI_SET_DIALPARAMS, &dps); |
| 20134 |
if (res < 0) { |
| 20135 |
ast_log(LOG_ERROR, "Invalid tone duration: %d ms at line %d: %s\n", toneduration, v->lineno, strerror(errno)); |
| 20136 |
close(ctlfd); |
| 20137 |
return -1; |
| 20138 |
} |
| 20139 |
} |
| 20140 |
close(ctlfd); |
| 20141 |
} else if (!strcasecmp(v->name, "defaultcic")) { |
| 20142 |
ast_copy_string(defaultcic, v->value, sizeof(defaultcic)); |
| 20143 |
} else if (!strcasecmp(v->name, "defaultozz")) { |
| 20144 |
ast_copy_string(defaultozz, v->value, sizeof(defaultozz)); |
| 20145 |
} else if (!strcasecmp(v->name, "mwilevel")) { |
| 20146 |
mwilevel = atoi(v->value); |
| 20147 |
} else if (!strcasecmp(v->name, "dtmfcidlevel")) { |
| 20148 |
dtmfcid_level = atoi(v->value); |
| 20149 |
} else if (!strcasecmp(v->name, "reportalarms")) { |
| 20150 |
if (!strcasecmp(v->value, "all")) |
| 20151 |
report_alarms = REPORT_CHANNEL_ALARMS | REPORT_SPAN_ALARMS; |
| 20152 |
if (!strcasecmp(v->value, "none")) |
| 20153 |
report_alarms = 0; |
| 20154 |
else if (!strcasecmp(v->value, "channels")) |
| 20155 |
report_alarms = REPORT_CHANNEL_ALARMS; |
| 20156 |
else if (!strcasecmp(v->value, "spans")) |
| 20157 |
report_alarms = REPORT_SPAN_ALARMS; |
| 20158 |
} |
| 20159 |
} else if (!(options & PROC_DAHDI_OPT_NOWARN) ) |
| 20160 |
ast_log(LOG_NOTICE, "Ignoring any changes to '%s' (on reload) at line %d.\n", v->name, v->lineno); |
| 20161 |
} |
| 20162 |
|
| 20163 |
if (dahdichan) { |
| 20164 |
|
| 20165 |
if (build_channels(confp, dahdichan->value, reload, dahdichan->lineno)) { |
| 20166 |
if (confp->ignore_failed_channels) { |
| 20167 |
ast_log(LOG_WARNING, |
| 20168 |
"Dahdichan '%s' failure ignored: ignore_failed_channels.\n", |
| 20169 |
dahdichan->value); |
| 20170 |
} else { |
| 20171 |
return -1; |
| 20172 |
} |
| 20173 |
} |
| 20174 |
} |
| 20175 |
|
| 20176 |
|
| 20177 |
|
| 20178 |
|
| 20179 |
|
| 20180 |
if (confp->chan.vars) { |
| 20181 |
ast_variables_destroy(confp->chan.vars); |
| 20182 |
confp->chan.vars = NULL; |
| 20183 |
} |
| 20184 |
|
| 20185 |
|
| 20186 |
for (tmp = iflist, y=-1; tmp; tmp = tmp->next) { |
| 20187 |
if (!tmp->destroy && tmp->span != y) { |
| 20188 |
tmp->manages_span_alarms = 1; |
| 20189 |
y = tmp->span; |
| 20190 |
} else { |
| 20191 |
tmp->manages_span_alarms = 0; |
| 20192 |
} |
| 20193 |
} |
| 20194 |
|
| 20195 |
|
| 20196 |
|
| 20197 |
if (!has_pseudo && reload != 1 && !(options & PROC_DAHDI_OPT_NOCHAN)) { |
| 20198 |
|
| 20199 |
|
| 20200 |
|
| 20201 |
|
| 20202 |
struct dahdi_chan_conf conf = dahdi_chan_conf_default(); |
| 20203 |
|
| 20204 |
if (conf.chan.cc_params) { |
| 20205 |
tmp = mkintf(CHAN_PSEUDO, &conf, reload); |
| 20206 |
} else { |
| 20207 |
tmp = NULL; |
| 20208 |
} |
| 20209 |
if (tmp) { |
| 20210 |
ast_verb(3, "Automatically generated pseudo channel\n"); |
| 20211 |
has_pseudo = 1; |
| 20212 |
} else { |
| 20213 |
ast_log(LOG_WARNING, "Unable to register pseudo channel!\n"); |
| 20214 |
} |
| 20215 |
ast_cc_config_params_destroy(conf.chan.cc_params); |
| 20216 |
} |
| 20217 |
|
| 20218 |
|
| 20219 |
confp->chan.named_callgroups = ast_unref_namedgroups(confp->chan.named_callgroups); |
| 20220 |
confp->chan.named_pickupgroups = ast_unref_namedgroups(confp->chan.named_pickupgroups); |
| 20221 |
|
| 20222 |
return 0; |
| 20223 |
} |
| 20224 |
|
| 20225 |
|
| 20226 |
|
| 20227 |
|
| 20228 |
|
| 20229 |
|
| 20230 |
|
| 20231 |
|
| 20232 |
|
| 20233 |
static void deep_copy_dahdi_chan_conf(struct dahdi_chan_conf *dest, const struct dahdi_chan_conf *src) |
| 20234 |
{ |
| 20235 |
struct ast_cc_config_params *cc_params; |
| 20236 |
|
| 20237 |
cc_params = dest->chan.cc_params; |
| 20238 |
*dest = *src; |
| 20239 |
dest->chan.cc_params = cc_params; |
| 20240 |
ast_cc_copy_config_params(dest->chan.cc_params, src->chan.cc_params); |
| 20241 |
} |
| 20242 |
|
| 20243 |
|
| 20244 |
|
| 20245 |
|
| 20246 |
|
| 20247 |
|
| 20248 |
|
| 20249 |
|
| 20250 |
|
| 20251 |
|
| 20252 |
|
| 20253 |
|
| 20254 |
|
| 20255 |
static int setup_dahdi_int(int reload, struct dahdi_chan_conf *default_conf, struct dahdi_chan_conf *base_conf, struct dahdi_chan_conf *conf) |
| 20256 |
{ |
| 20257 |
struct ast_config *cfg; |
| 20258 |
struct ast_config *ucfg; |
| 20259 |
struct ast_variable *v; |
| 20260 |
struct ast_flags config_flags = { reload == 1 ? CONFIG_FLAG_FILEUNCHANGED : 0 }; |
| 20261 |
const char *chans; |
| 20262 |
const char *cat; |
| 20263 |
int res; |
| 20264 |
|
| 20265 |
#ifdef HAVE_PRI |
| 20266 |
const char *c; |
| 20267 |
int spanno; |
| 20268 |
int i; |
| 20269 |
int logicalspan; |
| 20270 |
int trunkgroup; |
| 20271 |
int dchannels[SIG_PRI_NUM_DCHANS]; |
| 20272 |
#endif |
| 20273 |
int have_cfg_now; |
| 20274 |
static int had_cfg_before = 1; |
| 20275 |
|
| 20276 |
cfg = ast_config_load(config, config_flags); |
| 20277 |
have_cfg_now = !!cfg; |
| 20278 |
if (!cfg) { |
| 20279 |
|
| 20280 |
if (had_cfg_before) { |
| 20281 |
ast_log(LOG_ERROR, "Unable to load config %s\n", config); |
| 20282 |
ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED); |
| 20283 |
} |
| 20284 |
cfg = ast_config_new(); |
| 20285 |
if (!cfg) { |
| 20286 |
return 0; |
| 20287 |
} |
| 20288 |
ucfg = ast_config_load("users.conf", config_flags); |
| 20289 |
if (ucfg == CONFIG_STATUS_FILEUNCHANGED) { |
| 20290 |
ast_config_destroy(cfg); |
| 20291 |
return 0; |
| 20292 |
} |
| 20293 |
if (ucfg == CONFIG_STATUS_FILEINVALID) { |
| 20294 |
ast_log(LOG_ERROR, "File users.conf cannot be parsed. Aborting.\n"); |
| 20295 |
ast_config_destroy(cfg); |
| 20296 |
return 0; |
| 20297 |
} |
| 20298 |
} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) { |
| 20299 |
ucfg = ast_config_load("users.conf", config_flags); |
| 20300 |
if (ucfg == CONFIG_STATUS_FILEUNCHANGED) { |
| 20301 |
return 0; |
| 20302 |
} |
| 20303 |
if (ucfg == CONFIG_STATUS_FILEINVALID) { |
| 20304 |
ast_log(LOG_ERROR, "File users.conf cannot be parsed. Aborting.\n"); |
| 20305 |
return 0; |
| 20306 |
} |
| 20307 |
ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED); |
| 20308 |
cfg = ast_config_load(config, config_flags); |
| 20309 |
have_cfg_now = !!cfg; |
| 20310 |
if (!cfg) { |
| 20311 |
if (had_cfg_before) { |
| 20312 |
|
| 20313 |
ast_log(LOG_ERROR, "Bad. Unable to load config %s\n", config); |
| 20314 |
ast_config_destroy(ucfg); |
| 20315 |
return 0; |
| 20316 |
} |
| 20317 |
cfg = ast_config_new(); |
| 20318 |
if (!cfg) { |
| 20319 |
ast_config_destroy(ucfg); |
| 20320 |
return 0; |
| 20321 |
} |
| 20322 |
} else if (cfg == CONFIG_STATUS_FILEINVALID) { |
| 20323 |
ast_log(LOG_ERROR, "File %s cannot be parsed. Aborting.\n", config); |
| 20324 |
ast_config_destroy(ucfg); |
| 20325 |
return 0; |
| 20326 |
} |
| 20327 |
} else if (cfg == CONFIG_STATUS_FILEINVALID) { |
| 20328 |
ast_log(LOG_ERROR, "File %s cannot be parsed. Aborting.\n", config); |
| 20329 |
return 0; |
| 20330 |
} else { |
| 20331 |
ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED); |
| 20332 |
ucfg = ast_config_load("users.conf", config_flags); |
| 20333 |
if (ucfg == CONFIG_STATUS_FILEINVALID) { |
| 20334 |
ast_log(LOG_ERROR, "File users.conf cannot be parsed. Aborting.\n"); |
| 20335 |
ast_config_destroy(cfg); |
| 20336 |
return 0; |
| 20337 |
} |
| 20338 |
} |
| 20339 |
had_cfg_before = have_cfg_now; |
| 20340 |
|
| 20341 |
|
| 20342 |
ast_mutex_lock(&iflock); |
| 20343 |
#ifdef HAVE_PRI |
| 20344 |
if (reload != 1) { |
| 20345 |
|
| 20346 |
v = ast_variable_browse(cfg, "trunkgroups"); |
| 20347 |
while (v) { |
| 20348 |
if (!strcasecmp(v->name, "trunkgroup")) { |
| 20349 |
trunkgroup = atoi(v->value); |
| 20350 |
if (trunkgroup > 0) { |
| 20351 |
if ((c = strchr(v->value, ','))) { |
| 20352 |
i = 0; |
| 20353 |
memset(dchannels, 0, sizeof(dchannels)); |
| 20354 |
while (c && (i < SIG_PRI_NUM_DCHANS)) { |
| 20355 |
dchannels[i] = atoi(c + 1); |
| 20356 |
if (dchannels[i] < 0) { |
| 20357 |
ast_log(LOG_WARNING, "D-channel for trunk group %d must be a positive number at line %d of chan_dahdi.conf\n", trunkgroup, v->lineno); |
| 20358 |
} else |
| 20359 |
i++; |
| 20360 |
c = strchr(c + 1, ','); |
| 20361 |
} |
| 20362 |
if (i) { |
| 20363 |
if (pri_create_trunkgroup(trunkgroup, dchannels)) { |
| 20364 |
ast_log(LOG_WARNING, "Unable to create trunk group %d with Primary D-channel %d at line %d of chan_dahdi.conf\n", trunkgroup, dchannels[0], v->lineno); |
| 20365 |
} else |
| 20366 |
ast_verb(2, "Created trunk group %d with Primary D-channel %d and %d backup%s\n", trunkgroup, dchannels[0], i - 1, (i == 1) ? "" : "s"); |
| 20367 |
} else |
| 20368 |
ast_log(LOG_WARNING, "Trunk group %d lacks any valid D-channels at line %d of chan_dahdi.conf\n", trunkgroup, v->lineno); |
| 20369 |
} else |
| 20370 |
ast_log(LOG_WARNING, "Trunk group %d lacks a primary D-channel at line %d of chan_dahdi.conf\n", trunkgroup, v->lineno); |
| 20371 |
} else |
| 20372 |
ast_log(LOG_WARNING, "Trunk group identifier must be a positive integer at line %d of chan_dahdi.conf\n", v->lineno); |
| 20373 |
} else if (!strcasecmp(v->name, "spanmap")) { |
| 20374 |
spanno = atoi(v->value); |
| 20375 |
if (spanno > 0) { |
| 20376 |
if ((c = strchr(v->value, ','))) { |
| 20377 |
trunkgroup = atoi(c + 1); |
| 20378 |
if (trunkgroup > 0) { |
| 20379 |
if ((c = strchr(c + 1, ','))) |
| 20380 |
logicalspan = atoi(c + 1); |
| 20381 |
else |
| 20382 |
logicalspan = 0; |
| 20383 |
if (logicalspan >= 0) { |
| 20384 |
if (pri_create_spanmap(spanno - 1, trunkgroup, logicalspan)) { |
| 20385 |
ast_log(LOG_WARNING, "Failed to map span %d to trunk group %d (logical span %d)\n", spanno, trunkgroup, logicalspan); |
| 20386 |
} else |
| 20387 |
ast_verb(2, "Mapped span %d to trunk group %d (logical span %d)\n", spanno, trunkgroup, logicalspan); |
| 20388 |
} else |
| 20389 |
ast_log(LOG_WARNING, "Logical span must be a positive number, or '0' (for unspecified) at line %d of chan_dahdi.conf\n", v->lineno); |
| 20390 |
} else |
| 20391 |
ast_log(LOG_WARNING, "Trunk group must be a positive number at line %d of chan_dahdi.conf\n", v->lineno); |
| 20392 |
} else |
| 20393 |
ast_log(LOG_WARNING, "Missing trunk group for span map at line %d of chan_dahdi.conf\n", v->lineno); |
| 20394 |
} else |
| 20395 |
ast_log(LOG_WARNING, "Span number must be a positive integer at line %d of chan_dahdi.conf\n", v->lineno); |
| 20396 |
} else { |
| 20397 |
ast_log(LOG_NOTICE, "Ignoring unknown keyword '%s' in trunkgroups\n", v->name); |
| 20398 |
} |
| 20399 |
v = v->next; |
| 20400 |
} |
| 20401 |
} |
| 20402 |
#endif |
| 20403 |
|
| 20404 |
|
| 20405 |
memcpy(&global_jbconf, &default_jbconf, sizeof(global_jbconf)); |
| 20406 |
|
| 20407 |
mwimonitornotify[0] = '\0'; |
| 20408 |
|
| 20409 |
v = ast_variable_browse(cfg, "channels"); |
| 20410 |
if ((res = process_dahdi(base_conf, |
| 20411 |
"" , |
| 20412 |
v, reload, 0))) { |
| 20413 |
ast_mutex_unlock(&iflock); |
| 20414 |
ast_config_destroy(cfg); |
| 20415 |
if (ucfg) { |
| 20416 |
ast_config_destroy(ucfg); |
| 20417 |
} |
| 20418 |
return res; |
| 20419 |
} |
| 20420 |
|
| 20421 |
|
| 20422 |
for (cat = ast_category_browse(cfg, NULL); cat ; cat = ast_category_browse(cfg, cat)) { |
| 20423 |
|
| 20424 |
|
| 20425 |
|
| 20426 |
if (!strcasecmp(cat, "general") || |
| 20427 |
!strcasecmp(cat, "trunkgroups") || |
| 20428 |
!strcasecmp(cat, "globals") || |
| 20429 |
!strcasecmp(cat, "channels")) { |
| 20430 |
continue; |
| 20431 |
} |
| 20432 |
|
| 20433 |
chans = ast_variable_retrieve(cfg, cat, "dahdichan"); |
| 20434 |
if (ast_strlen_zero(chans)) { |
| 20435 |
|
| 20436 |
continue; |
| 20437 |
} |
| 20438 |
|
| 20439 |
|
| 20440 |
deep_copy_dahdi_chan_conf(conf, base_conf); |
| 20441 |
|
| 20442 |
if ((res = process_dahdi(conf, cat, ast_variable_browse(cfg, cat), reload, PROC_DAHDI_OPT_NOCHAN))) { |
| 20443 |
ast_mutex_unlock(&iflock); |
| 20444 |
ast_config_destroy(cfg); |
| 20445 |
if (ucfg) { |
| 20446 |
ast_config_destroy(ucfg); |
| 20447 |
} |
| 20448 |
return res; |
| 20449 |
} |
| 20450 |
} |
| 20451 |
|
| 20452 |
ast_config_destroy(cfg); |
| 20453 |
|
| 20454 |
if (ucfg) { |
| 20455 |
|
| 20456 |
deep_copy_dahdi_chan_conf(base_conf, default_conf); |
| 20457 |
process_dahdi(base_conf, |
| 20458 |
"" , |
| 20459 |
ast_variable_browse(ucfg, "general"), 1, 0); |
| 20460 |
|
| 20461 |
for (cat = ast_category_browse(ucfg, NULL); cat ; cat = ast_category_browse(ucfg, cat)) { |
| 20462 |
if (!strcasecmp(cat, "general")) { |
| 20463 |
continue; |
| 20464 |
} |
| 20465 |
|
| 20466 |
chans = ast_variable_retrieve(ucfg, cat, "dahdichan"); |
| 20467 |
if (ast_strlen_zero(chans)) { |
| 20468 |
|
| 20469 |
continue; |
| 20470 |
} |
| 20471 |
|
| 20472 |
|
| 20473 |
deep_copy_dahdi_chan_conf(conf, base_conf); |
| 20474 |
|
| 20475 |
if ((res = process_dahdi(conf, cat, ast_variable_browse(ucfg, cat), reload, PROC_DAHDI_OPT_NOCHAN | PROC_DAHDI_OPT_NOWARN))) { |
| 20476 |
ast_config_destroy(ucfg); |
| 20477 |
ast_mutex_unlock(&iflock); |
| 20478 |
return res; |
| 20479 |
} |
| 20480 |
} |
| 20481 |
ast_config_destroy(ucfg); |
| 20482 |
} |
| 20483 |
ast_mutex_unlock(&iflock); |
| 20484 |
|
| 20485 |
#ifdef HAVE_PRI |
| 20486 |
if (reload != 1) { |
| 20487 |
int x; |
| 20488 |
for (x = 0; x < NUM_SPANS; x++) { |
| 20489 |
if (pris[x].pri.pvts[0] && |
| 20490 |
pris[x].pri.master == AST_PTHREADT_NULL) { |
| 20491 |
prepare_pri(pris + x); |
| 20492 |
if (sig_pri_start_pri(&pris[x].pri)) { |
| 20493 |
ast_log(LOG_ERROR, "Unable to start D-channel on span %d\n", x + 1); |
| 20494 |
return -1; |
| 20495 |
} else |
| 20496 |
ast_verb(2, "Starting D-Channel on span %d\n", x + 1); |
| 20497 |
} |
| 20498 |
} |
| 20499 |
} |
| 20500 |
#endif |
| 20501 |
#if defined(HAVE_SS7) |
| 20502 |
if (reload != 1) { |
| 20503 |
int x; |
| 20504 |
for (x = 0; x < NUM_SPANS; x++) { |
| 20505 |
if (linksets[x].ss7.ss7) { |
| 20506 |
if (ast_pthread_create(&linksets[x].ss7.master, NULL, ss7_linkset, &linksets[x].ss7)) { |
| 20507 |
ast_log(LOG_ERROR, "Unable to start SS7 linkset on span %d\n", x + 1); |
| 20508 |
return -1; |
| 20509 |
} else |
| 20510 |
ast_verb(2, "Starting SS7 linkset on span %d\n", x + 1); |
| 20511 |
} |
| 20512 |
} |
| 20513 |
} |
| 20514 |
#endif |
| 20515 |
#ifdef HAVE_OPENR2 |
| 20516 |
if (reload != 1) { |
| 20517 |
struct r2link_entry *cur; |
| 20518 |
int x = 0; |
| 20519 |
AST_LIST_LOCK(&r2links); |
| 20520 |
AST_LIST_TRAVERSE(&r2links, cur, list) { |
| 20521 |
struct dahdi_mfcr2 *r2 = &cur->mfcr2; |
| 20522 |
if (r2->r2master == AST_PTHREADT_NULL) { |
| 20523 |
if (ast_pthread_create(&r2->r2master, NULL, mfcr2_monitor, r2)) { |
| 20524 |
ast_log(LOG_ERROR, "Unable to start R2 monitor on channel group %d\n", x + 1); |
| 20525 |
return -1; |
| 20526 |
} else { |
| 20527 |
ast_verb(2, "Starting R2 monitor on channel group %d\n", x + 1); |
| 20528 |
} |
| 20529 |
x++; |
| 20530 |
} |
| 20531 |
} |
| 20532 |
AST_LIST_UNLOCK(&r2links); |
| 20533 |
} |
| 20534 |
#endif |
| 20535 |
|
| 20536 |
restart_monitor(); |
| 20537 |
return 0; |
| 20538 |
} |
| 20539 |
|
| 20540 |
|
| 20541 |
|
| 20542 |
|
| 20543 |
|
| 20544 |
|
| 20545 |
|
| 20546 |
|
| 20547 |
|
| 20548 |
|
| 20549 |
static int setup_dahdi(int reload) |
| 20550 |
{ |
| 20551 |
int res; |
| 20552 |
struct dahdi_chan_conf default_conf = dahdi_chan_conf_default(); |
| 20553 |
struct dahdi_chan_conf base_conf = dahdi_chan_conf_default(); |
| 20554 |
struct dahdi_chan_conf conf = dahdi_chan_conf_default(); |
| 20555 |
|
| 20556 |
if (default_conf.chan.cc_params && base_conf.chan.cc_params && conf.chan.cc_params) { |
| 20557 |
res = setup_dahdi_int(reload, &default_conf, &base_conf, &conf); |
| 20558 |
} else { |
| 20559 |
res = -1; |
| 20560 |
} |
| 20561 |
ast_cc_config_params_destroy(default_conf.chan.cc_params); |
| 20562 |
ast_cc_config_params_destroy(base_conf.chan.cc_params); |
| 20563 |
ast_cc_config_params_destroy(conf.chan.cc_params); |
| 20564 |
|
| 20565 |
return res; |
| 20566 |
} |
| 20567 |
|
| 20568 |
|
| 20569 |
|
| 20570 |
|
| 20571 |
|
| 20572 |
|
| 20573 |
|
| 20574 |
|
| 20575 |
|
| 20576 |
|
| 20577 |
|
| 20578 |
static int load_module(void) |
| 20579 |
{ |
| 20580 |
int res; |
| 20581 |
#if defined(HAVE_PRI) || defined(HAVE_SS7) |
| 20582 |
int y; |
| 20583 |
#endif |
| 20584 |
|
| 20585 |
if (STASIS_MESSAGE_TYPE_INIT(dahdichannel_type)) { |
| 20586 |
return AST_MODULE_LOAD_DECLINE; |
| 20587 |
} |
| 20588 |
|
| 20589 |
if (!(dahdi_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) { |
| 20590 |
return AST_MODULE_LOAD_DECLINE; |
| 20591 |
} |
| 20592 |
ast_format_cap_append(dahdi_tech.capabilities, ast_format_slin, 0); |
| 20593 |
ast_format_cap_append(dahdi_tech.capabilities, ast_format_ulaw, 0); |
| 20594 |
ast_format_cap_append(dahdi_tech.capabilities, ast_format_alaw, 0); |
| 20595 |
|
| 20596 |
if (dahdi_native_load(&dahdi_tech)) { |
| 20597 |
ao2_ref(dahdi_tech.capabilities, -1); |
| 20598 |
return AST_MODULE_LOAD_DECLINE; |
| 20599 |
} |
| 20600 |
|
| 20601 |
#ifdef HAVE_PRI |
| 20602 |
memset(pris, 0, sizeof(pris)); |
| 20603 |
for (y = 0; y < NUM_SPANS; y++) { |
| 20604 |
sig_pri_init_pri(&pris[y].pri); |
| 20605 |
} |
| 20606 |
pri_set_error(dahdi_pri_error); |
| 20607 |
pri_set_message(dahdi_pri_message); |
| 20608 |
ast_register_application_xml(dahdi_send_keypad_facility_app, dahdi_send_keypad_facility_exec); |
| 20609 |
#ifdef HAVE_PRI_PROG_W_CAUSE |
| 20610 |
ast_register_application_xml(dahdi_send_callrerouting_facility_app, dahdi_send_callrerouting_facility_exec); |
| 20611 |
#endif |
| 20612 |
#if defined(HAVE_PRI_CCSS) |
| 20613 |
if (ast_cc_agent_register(&dahdi_pri_cc_agent_callbacks) |
| 20614 |
|| ast_cc_monitor_register(&dahdi_pri_cc_monitor_callbacks)) { |
| 20615 |
__unload_module(); |
| 20616 |
return AST_MODULE_LOAD_DECLINE; |
| 20617 |
} |
| 20618 |
#endif |
| 20619 |
if (sig_pri_load( |
| 20620 |
#if defined(HAVE_PRI_CCSS) |
| 20621 |
dahdi_pri_cc_type |
| 20622 |
#else |
| 20623 |
NULL |
| 20624 |
#endif |
| 20625 |
)) { |
| 20626 |
__unload_module(); |
| 20627 |
return AST_MODULE_LOAD_DECLINE; |
| 20628 |
} |
| 20629 |
#endif |
| 20630 |
#if defined(HAVE_SS7) |
| 20631 |
memset(linksets, 0, sizeof(linksets)); |
| 20632 |
for (y = 0; y < NUM_SPANS; y++) { |
| 20633 |
sig_ss7_init_linkset(&linksets[y].ss7); |
| 20634 |
} |
| 20635 |
ss7_set_error(dahdi_ss7_error); |
| 20636 |
ss7_set_message(dahdi_ss7_message); |
| 20637 |
ss7_set_hangup(sig_ss7_cb_hangup); |
| 20638 |
ss7_set_notinservice(sig_ss7_cb_notinservice); |
| 20639 |
ss7_set_call_null(sig_ss7_cb_call_null); |
| 20640 |
#endif |
| 20641 |
res = setup_dahdi(0); |
| 20642 |
|
| 20643 |
if (res) { |
| 20644 |
__unload_module(); |
| 20645 |
return AST_MODULE_LOAD_DECLINE; |
| 20646 |
} |
| 20647 |
if (ast_channel_register(&dahdi_tech)) { |
| 20648 |
ast_log(LOG_ERROR, "Unable to register channel class 'DAHDI'\n"); |
| 20649 |
__unload_module(); |
| 20650 |
return AST_MODULE_LOAD_DECLINE; |
| 20651 |
} |
| 20652 |
#ifdef HAVE_PRI |
| 20653 |
ast_cli_register_multiple(dahdi_pri_cli, ARRAY_LEN(dahdi_pri_cli)); |
| 20654 |
#endif |
| 20655 |
#if defined(HAVE_SS7) |
| 20656 |
ast_cli_register_multiple(dahdi_ss7_cli, ARRAY_LEN(dahdi_ss7_cli)); |
| 20657 |
#endif |
| 20658 |
#ifdef HAVE_OPENR2 |
| 20659 |
ast_cli_register_multiple(dahdi_mfcr2_cli, ARRAY_LEN(dahdi_mfcr2_cli)); |
| 20660 |
ast_register_application_xml(dahdi_accept_r2_call_app, dahdi_accept_r2_call_exec); |
| 20661 |
#endif |
| 20662 |
|
| 20663 |
ast_custom_function_register(&dahdichan_function); |
| 20664 |
ast_custom_function_register(&polarity_function); |
| 20665 |
|
| 20666 |
ast_cli_register_multiple(dahdi_cli, ARRAY_LEN(dahdi_cli)); |
| 20667 |
memset(round_robin, 0, sizeof(round_robin)); |
| 20668 |
ast_manager_register_xml("DAHDITransfer", 0, action_transfer); |
| 20669 |
ast_manager_register_xml("DAHDIHangup", 0, action_transferhangup); |
| 20670 |
ast_manager_register_xml("DAHDIDialOffhook", 0, action_dahdidialoffhook); |
| 20671 |
ast_manager_register_xml("DAHDIDNDon", 0, action_dahdidndon); |
| 20672 |
ast_manager_register_xml("DAHDIDNDoff", 0, action_dahdidndoff); |
| 20673 |
ast_manager_register_xml("DAHDIShowChannels", 0, action_dahdishowchannels); |
| 20674 |
ast_manager_register_xml("DAHDIShowStatus", 0, action_dahdishowstatus); |
| 20675 |
ast_manager_register_xml("DAHDIRestart", 0, action_dahdirestart); |
| 20676 |
#if defined(HAVE_PRI) |
| 20677 |
ast_manager_register_xml("PRIShowSpans", 0, action_prishowspans); |
| 20678 |
ast_manager_register_xml("PRIDebugSet", 0, action_pri_debug_set); |
| 20679 |
ast_manager_register_xml("PRIDebugFileSet", EVENT_FLAG_SYSTEM, action_pri_debug_file_set); |
| 20680 |
ast_manager_register_xml("PRIDebugFileUnset", 0, action_pri_debug_file_unset); |
| 20681 |
#endif |
| 20682 |
|
| 20683 |
ast_cond_init(&ss_thread_complete, NULL); |
| 20684 |
|
| 20685 |
return res; |
| 20686 |
} |
| 20687 |
|
| 20688 |
static int dahdi_sendtext(struct ast_channel *c, const char *text) |
| 20689 |
{ |
| 20690 |
#define END_SILENCE_LEN 400 |
| 20691 |
#define HEADER_MS 50 |
| 20692 |
#define TRAILER_MS 5 |
| 20693 |
#define HEADER_LEN ((HEADER_MS + TRAILER_MS) * 8) |
| 20694 |
#define ASCII_BYTES_PER_CHAR 80 |
| 20695 |
|
| 20696 |
unsigned char *buf,*mybuf; |
| 20697 |
struct dahdi_pvt *p = ast_channel_tech_pvt(c); |
| 20698 |
struct pollfd fds[1]; |
| 20699 |
int size,res,fd,len,x; |
| 20700 |
int bytes=0; |
| 20701 |
int idx; |
| 20702 |
|
| 20703 |
|
| 20704 |
|
| 20705 |
|
| 20706 |
|
| 20707 |
|
| 20708 |
|
| 20709 |
float cr = 1.0; |
| 20710 |
float ci = 0.0; |
| 20711 |
float scont = 0.0; |
| 20712 |
|
| 20713 |
if (!text[0]) { |
| 20714 |
return(0); |
| 20715 |
} |
| 20716 |
idx = dahdi_get_index(c, p, 0); |
| 20717 |
if (idx < 0) { |
| 20718 |
ast_log(LOG_WARNING, "Huh? I don't exist?\n"); |
| 20719 |
return -1; |
| 20720 |
} |
| 20721 |
if ((!p->tdd) && (!p->mate)) { |
| 20722 |
#if defined(HAVE_PRI) |
| 20723 |
#if defined(HAVE_PRI_DISPLAY_TEXT) |
| 20724 |
ast_mutex_lock(&p->lock); |
| 20725 |
if (dahdi_sig_pri_lib_handles(p->sig)) { |
| 20726 |
sig_pri_sendtext(p->sig_pvt, text); |
| 20727 |
} |
| 20728 |
ast_mutex_unlock(&p->lock); |
| 20729 |
#endif |
| 20730 |
#endif |
| 20731 |
return(0); |
| 20732 |
} |
| 20733 |
if (p->mate) |
| 20734 |
buf = ast_malloc(((strlen(text) + 1) * ASCII_BYTES_PER_CHAR) + END_SILENCE_LEN + HEADER_LEN); |
| 20735 |
else |
| 20736 |
buf = ast_malloc(((strlen(text) + 1) * TDD_BYTES_PER_CHAR) + END_SILENCE_LEN); |
| 20737 |
if (!buf) |
| 20738 |
return -1; |
| 20739 |
mybuf = buf; |
| 20740 |
if (p->mate) { |
| 20741 |
|
| 20742 |
struct ast_format *codec = AST_LAW(p); |
| 20743 |
|
| 20744 |
for (x = 0; x < HEADER_MS; x++) { |
| 20745 |
PUT_CLID_MARKMS; |
| 20746 |
} |
| 20747 |
|
| 20748 |
for (x = 0; text[x]; x++) { |
| 20749 |
PUT_CLID(text[x]); |
| 20750 |
} |
| 20751 |
for (x = 0; x < TRAILER_MS; x++) { |
| 20752 |
PUT_CLID_MARKMS; |
| 20753 |
} |
| 20754 |
len = bytes; |
| 20755 |
buf = mybuf; |
| 20756 |
} else { |
| 20757 |
len = tdd_generate(p->tdd, buf, text); |
| 20758 |
if (len < 1) { |
| 20759 |
ast_log(LOG_ERROR, "TDD generate (len %d) failed!!\n", (int)strlen(text)); |
| 20760 |
ast_free(mybuf); |
| 20761 |
return -1; |
| 20762 |
} |
| 20763 |
} |
| 20764 |
memset(buf + len, 0x7f, END_SILENCE_LEN); |
| 20765 |
len += END_SILENCE_LEN; |
| 20766 |
fd = p->subs[idx].dfd; |
| 20767 |
while (len) { |
| 20768 |
if (ast_check_hangup(c)) { |
| 20769 |
ast_free(mybuf); |
| 20770 |
return -1; |
| 20771 |
} |
| 20772 |
size = len; |
| 20773 |
if (size > READ_SIZE) |
| 20774 |
size = READ_SIZE; |
| 20775 |
fds[0].fd = fd; |
| 20776 |
fds[0].events = POLLOUT | POLLPRI; |
| 20777 |
fds[0].revents = 0; |
| 20778 |
res = poll(fds, 1, -1); |
| 20779 |
if (!res) { |
| 20780 |
ast_debug(1, "poll (for write) ret. 0 on channel %d\n", p->channel); |
| 20781 |
continue; |
| 20782 |
} |
| 20783 |
|
| 20784 |
if (fds[0].revents & POLLPRI) { |
| 20785 |
ast_free(mybuf); |
| 20786 |
return -1; |
| 20787 |
} |
| 20788 |
if (!(fds[0].revents & POLLOUT)) { |
| 20789 |
ast_debug(1, "write fd not ready on channel %d\n", p->channel); |
| 20790 |
continue; |
| 20791 |
} |
| 20792 |
res = write(fd, buf, size); |
| 20793 |
if (res != size) { |
| 20794 |
if (res == -1) { |
| 20795 |
ast_free(mybuf); |
| 20796 |
return -1; |
| 20797 |
} |
| 20798 |
ast_debug(1, "Write returned %d (%s) on channel %d\n", res, strerror(errno), p->channel); |
| 20799 |
break; |
| 20800 |
} |
| 20801 |
len -= size; |
| 20802 |
buf += size; |
| 20803 |
} |
| 20804 |
ast_free(mybuf); |
| 20805 |
return(0); |
| 20806 |
} |
| 20807 |
|
| 20808 |
|
| 20809 |
static int reload(void) |
| 20810 |
{ |
| 20811 |
int res = 0; |
| 20812 |
|
| 20813 |
res = setup_dahdi(1); |
| 20814 |
if (res) { |
| 20815 |
ast_log(LOG_WARNING, "Reload of chan_dahdi.so is unsuccessful!\n"); |
| 20816 |
return -1; |
| 20817 |
} |
| 20818 |
return 0; |
| 20819 |
} |
| 20820 |
|
| 20821 |
|
| 20822 |
|
| 20823 |
|
| 20824 |
|
| 20825 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, tdesc, |
| 20826 |
.support_level = AST_MODULE_SUPPORT_CORE, |
| 20827 |
.load = load_module, |
| 20828 |
.unload = unload_module, |
| 20829 |
.reload = reload, |
| 20830 |
.load_pri = AST_MODPRI_CHANNEL_DRIVER, |
| 20831 |
.requires = "ccss", |
| 20832 |
.optional_modules = "res_smdi", |
| 20833 |
); |