Changeset 5220
chan_misdn update to rc 37c
Committed by:
wildzero-cw
Date:
Nov 03 2008 * 01:06 (2 months ago)
Affected files:
callweaver/branches/srtp_tls/channels/misdn/Makefile.am (diff)
callweaver/branches/srtp_tls/channels/misdn/VERSION (diff)
callweaver/branches/srtp_tls/channels/misdn/chan_misdn.c (diff)
callweaver/branches/srtp_tls/channels/misdn/chan_misdn_config.h (diff)
callweaver/branches/srtp_tls/channels/misdn/fac.c (diff)
callweaver/branches/srtp_tls/channels/misdn/fac.h (diff)
callweaver/branches/srtp_tls/channels/misdn/ie.c (diff)
callweaver/branches/srtp_tls/channels/misdn/isdn_lib.c (diff)
callweaver/branches/srtp_tls/channels/misdn/isdn_lib.h (diff)
callweaver/branches/srtp_tls/channels/misdn/isdn_lib_intern.h (diff)
callweaver/branches/srtp_tls/channels/misdn/isdn_msg_parser.c (diff)
callweaver/branches/srtp_tls/channels/misdn/misdn_config.c (diff)
callweaver/branches/srtp_tls/channels/misdn/Makefile.am (unified diff)
| r4723 | r5220 | |
|---|---|---|
| 11 | 11 | isdn_lib_intern.h isdn_msg_parser.c misdn_config.c |
| 12 | 12 | |
| 13 | 13 | |
| 14 | chan_misdn_la_CFLAGS = $(AM_CFLAGS) @MISDN_CFLAGS@ -D_GNU_SOURCE -DCHAN_MISDN_VERSION=\"0.4.0-rc28\" | |
| 14 | chan_misdn_la_CFLAGS = $(AM_CFLAGS) @MISDN_CFLAGS@ -D_GNU_SOURCE -DCHAN_MISDN_VERSION=\"0.3.1-rc37c\" | |
| 15 | 15 | chan_misdn_la_LIBADD = @MISDN_LDFLAGS@ -lisdnnet -lmISDN ${top_builddir}/corelib/libcallweaver.la |
| 16 | 16 | chan_misdn_la_LDFLAGS = -module -avoid-version -no-undefined |
| 17 | 17 | endif WANT_CHAN_MISDN |
callweaver/branches/srtp_tls/channels/misdn/VERSION (unified diff)
| r2596 | r5220 | |
|---|---|---|
| 1 | 0.4.0-rc28 | |
| 1 | 0.3.1-rc37c |
callweaver/branches/srtp_tls/channels/misdn/chan_misdn.c (unified diff)
| r4739 | r5220 | |
|---|---|---|
| 56 | 56 | #include "callweaver/translate.h" |
| 57 | 57 | #include "callweaver/config.h" |
| 58 | 58 | #include "callweaver/file.h" |
| 59 | #include "callweaver/phone_no_utils.h" | |
| 59 | #include "callweaver/callerid.h" | |
| 60 | 60 | #include "callweaver/indications.h" |
| 61 | 61 | #include "callweaver/app.h" |
| 62 | 62 | #include "callweaver/features.h" |
| 63 | #include "callweaver/term.h" | |
| 64 | 63 | #include "callweaver/sched.h" |
| 64 | #include "callweaver/phone_no_utils.h" | |
| 65 | #include "chan_misdn_config.h" | |
| 66 | #include "isdn_lib.h" | |
| 65 | 67 | |
| 66 | #include <chan_misdn_config.h> | |
| 67 | #include <isdn_lib.h> | |
| 68 | ||
| 69 | 68 | char global_tracefile[BUFFERSIZE+1]; |
| 70 | 69 | |
| 71 | 70 | static struct cw_frame nullframe = { CW_FRAME_NULL, }; |
| 72 | 71 | |
| 72 | static int g_config_initialized=0; | |
| 73 | ||
| 73 | 74 | struct misdn_jb{ |
| 74 | 75 | int size; |
| 75 | 76 | int upper_threshold; |
| --- | --- | |
| 99 | 100 | of data. */ |
| 100 | 101 | int misdn_jb_empty(struct misdn_jb *jb, char *data, int len); |
| 101 | 102 | |
| 102 | /* get the level of the buffer */ | |
| 103 | int misdn_jb_get_level(struct misdn_jb *jb); | |
| 104 | 103 | |
| 104 | ||
| 105 | ||
| 106 | /* BEGIN: chan_misdn.h */ | |
| 107 | ||
| 108 | cw_mutex_t release_lock; | |
| 109 | ||
| 110 | ||
| 105 | 111 | enum misdn_chan_state { |
| 106 | MISDN_NOTHING, /*!< at beginning */ | |
| 112 | MISDN_NOTHING=0, /*!< at beginning */ | |
| 107 | 113 | MISDN_WAITING4DIGS, /*!< when waiting for infos */ |
| 108 | 114 | MISDN_EXTCANTMATCH, /*!< when callweaver couldnt match our ext */ |
| 115 | MISDN_INCOMING_SETUP, /*!< for incoming setups*/ | |
| 109 | 116 | MISDN_DIALING, /*!< when pbx_start */ |
| 110 | 117 | MISDN_PROGRESS, /*!< we got a progress */ |
| 111 | 118 | MISDN_PROCEEDING, /*!< we got a progress */ |
| --- | --- | |
| 120 | 127 | MISDN_BRIDGED, /*!< when bridged */ |
| 121 | 128 | MISDN_CLEANING, /*!< when hangup from * but we were connected before */ |
| 122 | 129 | MISDN_HUNGUP_FROM_MISDN, /*!< when DISCONNECT/RELEASE/REL_COMP cam from misdn */ |
| 123 | MISDN_HUNGUP_FROM_AST, /*!< when DISCONNECT/RELEASE/REL_COMP came out of */ | |
| 130 | MISDN_HUNGUP_FROM_CW, /*!< when DISCONNECT/RELEASE/REL_COMP came out of */ | |
| 124 | 131 | /* misdn_hangup */ |
| 125 | 132 | MISDN_HOLDED, /*!< if this chan is holded */ |
| 126 | MISDN_HOLD_DISCONNECT /*!< if this chan is holded */ | |
| 133 | MISDN_HOLD_DISCONNECT, /*!< if this chan is holded */ | |
| 127 | 134 | |
| 128 | 135 | }; |
| 129 | 136 | |
| 130 | #define ORG_AST 1 | |
| 137 | #define ORG_CW 1 | |
| 131 | 138 | #define ORG_MISDN 2 |
| 132 | 139 | |
| 140 | struct hold_info { | |
| 141 | int port; | |
| 142 | int channel; | |
| 143 | }; | |
| 144 | ||
| 133 | 145 | struct chan_list { |
| 134 | 146 | |
| 147 | cw_mutex_t lock; | |
| 148 | ||
| 135 | 149 | char allowed_bearers[BUFFERSIZE+1]; |
| 136 | 150 | |
| 137 | 151 | enum misdn_chan_state state; |
| --- | --- | |
| 139 | 153 | int need_hangup; |
| 140 | 154 | int need_busy; |
| 141 | 155 | |
| 156 | int noautorespond_on_setup; | |
| 157 | ||
| 142 | 158 | int orginator; |
| 143 | 159 | |
| 144 | 160 | int norxtone; |
| --- | --- | |
| 153 | 169 | int pipe[2]; |
| 154 | 170 | char cw_rd_buf[4096]; |
| 155 | 171 | struct cw_frame frame; |
| 172 | ||
| 156 | 173 | char framedata[160]; |
| 157 | 174 | int framepos; |
| 158 | 175 | |
| 159 | int faxdetect; /* 0:no 1:yes 2:yes+nojump */ | |
| 160 | int faxdetect_timeout; | |
| 161 | struct timeval faxdetect_tv; | |
| 176 | int faxdetect; | |
| 162 | 177 | int faxhandled; |
| 163 | 178 | |
| 164 | 179 | int cw_dsp; |
| --- | --- | |
| 166 | 181 | int jb_len; |
| 167 | 182 | int jb_upper_threshold; |
| 168 | 183 | struct misdn_jb *jb; |
| 169 | ||
| 170 | struct misdn_jb *jb_rx; | |
| 171 | ||
| 184 | ||
| 172 | 185 | struct cw_dsp *dsp; |
| 173 | 186 | struct cw_trans_pvt *trans; |
| 174 | 187 | |
| 175 | struct cw_channel * ast; | |
| 188 | struct cw_channel * cw; | |
| 176 | 189 | |
| 177 | 190 | int dummy; |
| 178 | 191 | |
| 179 | 192 | struct misdn_bchannel *bc; |
| 180 | struct misdn_bchannel *holded_bc; | |
| 181 | 193 | |
| 194 | struct hold_info hold_info; | |
| 195 | ||
| 182 | 196 | unsigned int l3id; |
| 183 | 197 | int addr; |
| 184 | 198 | |
| --- | --- | |
| 188 | 202 | int dropped_frame_cnt; |
| 189 | 203 | |
| 190 | 204 | int far_alerting; |
| 205 | ||
| 206 | int nttimeout; | |
| 207 | ||
| 191 | 208 | int other_pid; |
| 192 | 209 | struct chan_list *other_ch; |
| 193 | 210 | |
| --- | --- | |
| 220 | 237 | |
| 221 | 238 | |
| 222 | 239 | |
| 223 | struct cw_frame *process_cw_dsp(struct chan_list *tmp, struct cw_frame *frame); | |
| 240 | static struct cw_frame *process_cw_dsp(struct chan_list *tmp, struct cw_frame *frame); | |
| 224 | 241 | |
| 225 | 242 | |
| 226 | 243 | |
| --- | --- | |
| 248 | 265 | } |
| 249 | 266 | struct robin_list *new = (struct robin_list *)calloc(1, sizeof(struct robin_list)); |
| 250 | 267 | new->group = strndup(group, strlen(group)); |
| 251 | new->channel = 1; | |
| 268 | new->port = 0; | |
| 269 | new->channel = 0; | |
| 252 | 270 | if (robin) { |
| 253 | 271 | new->next = robin; |
| 254 | 272 | robin->prev = new; |
| --- | --- | |
| 265 | 283 | static void chan_misdn_log(int level, int port, char *tmpl, ...); |
| 266 | 284 | |
| 267 | 285 | static struct cw_channel *misdn_new(struct chan_list *cl, int state, char *exten, char *callerid, int format, int port, int c); |
| 268 | static int send_digit_to_chan(struct chan_list *cl, char digit ); | |
| 286 | static void send_digit_to_chan(struct chan_list *cl, char digit ); | |
| 269 | 287 | |
| 288 | static void hangup_chan(struct chan_list *ch); | |
| 270 | 289 | static int pbx_start_chan(struct chan_list *ch); |
| 271 | 290 | |
| 272 | #define CW_CID_P(ast) ast->cid.cid_num | |
| 273 | #define CW_BRIDGED_P(ast) cw_bridged_channel(ast) | |
| 291 | #define CW_CID_P(cw) cw->cid.cid_num | |
| 292 | #define CW_BRIDGED_P(cw) cw_bridged_channel(cw) | |
| 274 | 293 | #define CW_LOAD_CFG cw_config_load |
| 275 | 294 | #define CW_DESTROY_CFG cw_config_destroy |
| 276 | 295 | |
| 277 | #define MISDN_CALLWEAVER_TECH_PVT(ast) ast->tech_pvt | |
| 278 | #define MISDN_CALLWEAVER_PVT(ast) 1 | |
| 296 | #define MISDN_CALLWEAVER_TECH_PVT(cw) cw->tech_pvt | |
| 297 | #define MISDN_CALLWEAVER_PVT(cw) 1 | |
| 279 | 298 | |
| 280 | #include "callweaver/strings.h" | |
| 299 | #include <callweaver/strings.h> | |
| 281 | 300 | |
| 282 | 301 | /* #define MISDN_DEBUG 1 */ |
| 283 | 302 | |
| --- | --- | |
| 288 | 307 | |
| 289 | 308 | static int usecnt=0; |
| 290 | 309 | |
| 291 | static char **misdn_key_vector=NULL; | |
| 292 | static int misdn_key_vector_size=0; | |
| 293 | ||
| 294 | 310 | /* Only alaw and mulaw is allowed for now */ |
| 295 | 311 | static int prefformat = CW_FORMAT_ALAW ; /* CW_FORMAT_SLINEAR ; CW_FORMAT_ULAW | */ |
| 296 | 312 | |
| --- | --- | |
| 300 | 316 | static int *misdn_debug_only; |
| 301 | 317 | static int max_ports; |
| 302 | 318 | |
| 303 | static int *misdn_in_calls; | |
| 304 | static int *misdn_out_calls; | |
| 305 | ||
| 306 | ||
| 307 | 319 | struct chan_list dummy_cl; |
| 308 | 320 | |
| 309 | 321 | struct chan_list *cl_te=NULL; |
| --- | --- | |
| 312 | 324 | static enum event_response_e |
| 313 | 325 | cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data); |
| 314 | 326 | |
| 315 | static void send_cause2ast(struct cw_channel *ast, struct misdn_bchannel*bc, struct chan_list *ch); | |
| 327 | static void send_cause2cw(struct cw_channel *cw, struct misdn_bchannel*bc, struct chan_list *ch); | |
| 316 | 328 | |
| 317 | 329 | static void cl_queue_chan(struct chan_list **list, struct chan_list *chan); |
| 318 | 330 | static void cl_dequeue_chan(struct chan_list **list, struct chan_list *chan); |
| --- | --- | |
| 329 | 341 | static int stop_bc_tones(struct chan_list *cl); |
| 330 | 342 | static void release_chan(struct misdn_bchannel *bc); |
| 331 | 343 | |
| 344 | static int misdn_check_l2l1(struct cw_channel *chan, int argc, char **argv); | |
| 332 | 345 | static int misdn_set_opt_exec(struct cw_channel *chan, int argc, char **argv); |
| 333 | 346 | static int misdn_facility_exec(struct cw_channel *chan, int argc, char **argv); |
| 334 | 347 | |
| 335 | 348 | int chan_misdn_jb_empty(struct misdn_bchannel *bc, char *buf, int len); |
| 336 | 349 | |
| 337 | int add_out_calls(int port); | |
| 338 | int add_in_calls(int port); | |
| 339 | ||
| 350 | #ifdef MISDN_1_2 | |
| 351 | static int update_pipeline_config(struct misdn_bchannel *bc); | |
| 352 | #else | |
| 340 | 353 | static int update_ec_config(struct misdn_bchannel *bc); |
| 354 | #endif | |
| 341 | 355 | |
| 342 | ||
| 343 | void trigger_read(struct chan_list *ch, char *data, int len); | |
| 344 | ||
| 345 | 356 | /*************** Helpers *****************/ |
| 346 | 357 | |
| 347 | static struct chan_list * get_chan_by_ast(struct cw_channel *ast) | |
| 358 | static struct chan_list * get_chan_by_cw(struct cw_channel *cw) | |
| 348 | 359 | { |
| 349 | 360 | struct chan_list *tmp; |
| 350 | 361 | |
| 351 | 362 | for (tmp=cl_te; tmp; tmp = tmp->next) { |
| 352 | if ( tmp->ast == ast ) return tmp; | |
| 363 | if ( tmp->cw == cw ) return tmp; | |
| 353 | 364 | } |
| 354 | 365 | |
| 355 | 366 | return NULL; |
| --- | --- | |
| 360 | 371 | struct chan_list *tmp; |
| 361 | 372 | |
| 362 | 373 | for (tmp=cl_te; tmp; tmp = tmp->next) { |
| 363 | if ( tmp->ast && strcmp(tmp->ast->name,name) == 0) return tmp; | |
| 374 | if ( tmp->cw && strcmp(tmp->cw->name,name) == 0) return tmp; | |
| 364 | 375 | } |
| 365 | 376 | |
| 366 | 377 | return NULL; |
| --- | --- | |
| 419 | 430 | { |
| 420 | 431 | switch (bc->fac_type) { |
| 421 | 432 | case FACILITY_CALLDEFLECT: |
| 422 | chan_misdn_log(0,bc->port," --> calldeflect: %s\n", | |
| 433 | chan_misdn_log(2,bc->port," --> calldeflect: %s\n", | |
| 423 | 434 | bc->fac.calldeflect_nr); |
| 424 | 435 | break; |
| 425 | 436 | case FACILITY_CENTREX: |
| 426 | chan_misdn_log(0,bc->port," --> centrex: %s\n", | |
| 437 | chan_misdn_log(2,bc->port," --> centrex: %s\n", | |
| 427 | 438 | bc->fac.cnip); |
| 428 | 439 | break; |
| 429 | 440 | default: |
| 430 | chan_misdn_log(0,bc->port," --> unknown\n"); | |
| 441 | chan_misdn_log(2,bc->port," --> unknown\n"); | |
| 431 | 442 | |
| 432 | 443 | } |
| 433 | 444 | } |
| --- | --- | |
| 455 | 466 | return cw_sched_add_variable(misdn_tasks, timeout, callback, data, variable); |
| 456 | 467 | } |
| 457 | 468 | |
| 469 | #if 0 | |
| 458 | 470 | static int misdn_tasks_add (int timeout, cw_sched_cb callback, void *data) |
| 459 | 471 | { |
| 460 | 472 | return _misdn_tasks_add_variable(timeout, callback, data, 0); |
| 461 | 473 | } |
| 474 | #endif | |
| 462 | 475 | |
| 463 | 476 | static int misdn_tasks_add_variable (int timeout, cw_sched_cb callback, void *data) |
| 464 | 477 | { |
| --- | --- | |
| 470 | 483 | cw_sched_del(misdn_tasks, task_id); |
| 471 | 484 | } |
| 472 | 485 | |
| 473 | static int misdn_l1_task (void *data) | |
| 474 | { | |
| 475 | misdn_lib_isdn_l1watcher((int)data); | |
| 476 | chan_misdn_log(5, (int)data, "L1watcher timeout\n"); | |
| 477 | return 1; | |
| 478 | } | |
| 479 | ||
| 480 | 486 | static int misdn_overlap_dial_task (void *data) |
| 481 | 487 | { |
| 482 | 488 | struct timeval tv_end, tv_now; |
| --- | --- | |
| 502 | 508 | if (diff <= 100) { |
| 503 | 509 | /* if we are 100ms near the timeout, we are satisfied.. */ |
| 504 | 510 | stop_indicate(ch); |
| 505 | if (cw_exists_extension(ch->ast, ch->context, ch->bc->dad, 1, ch->bc->oad)) { | |
| 511 | if (cw_exists_extension(ch->cw, ch->context, ch->bc->dad, 1, ch->bc->oad)) { | |
| 506 | 512 | ch->state=MISDN_DIALING; |
| 507 | 513 | if (pbx_start_chan(ch) < 0) { |
| 508 | 514 | chan_misdn_log(-1, ch->bc->port, "cw_pbx_start returned < 0 in misdn_overlap_dial_task\n"); |
| --- | --- | |
| 511 | 517 | } else { |
| 512 | 518 | misdn_overlap_dial_task_disconnect: |
| 513 | 519 | hanguptone_indicate(ch); |
| 514 | if (ch->bc->nt) | |
| 515 | misdn_lib_send_event(ch->bc, EVENT_RELEASE_COMPLETE ); | |
| 516 | else | |
| 517 | misdn_lib_send_event(ch->bc, EVENT_RELEASE); | |
| 520 | ch->bc->out_cause=1; | |
| 521 | ch->state=MISDN_CLEANING; | |
| 522 | misdn_lib_send_event(ch->bc, EVENT_DISCONNECT); | |
| 518 | 523 | } |
| 519 | 524 | ch->overlap_dial_task = -1; |
| 520 | 525 | return 0; |
| --- | --- | |
| 522 | 527 | return diff; |
| 523 | 528 | } |
| 524 | 529 | |
| 525 | static int send_digit_to_chan(struct chan_list *cl, char digit ) | |
| 530 | static void send_digit_to_chan(struct chan_list *cl, char digit ) | |
| 526 | 531 | { |
| 527 | 532 | static const char* dtmf_tones[] = { |
| 528 | 533 | "!941+1336/100,!0/100", /* 0 */ |
| --- | --- | |
| 541 | 546 | "!941+1633/100,!0/100", /* D */ |
| 542 | 547 | "!941+1209/100,!0/100", /* * */ |
| 543 | 548 | "!941+1477/100,!0/100" }; /* # */ |
| 544 | struct cw_channel *chan=cl->ast; | |
| 549 | struct cw_channel *chan=cl->cw; | |
| 545 | 550 | |
| 546 | 551 | if (digit >= '0' && digit <='9') |
| 547 | 552 | cw_playtones_start(chan,0,dtmf_tones[digit-'0'], 0); |
| --- | --- | |
| 554 | 559 | else { |
| 555 | 560 | /* not handled */ |
| 556 | 561 | cw_log(LOG_DEBUG, "Unable to handle DTMF tone '%c' for '%s'\n", digit, chan->name); |
| 562 | ||
| 563 | ||
| 557 | 564 | } |
| 558 | return 0; | |
| 559 | 565 | } |
| 560 | 566 | /*** CLI HANDLING ***/ |
| 561 | 567 | static int misdn_set_debug(int fd, int argc, char *argv[]) |
| --- | --- | |
| 622 | 628 | return 0; |
| 623 | 629 | } |
| 624 | 630 | |
| 625 | ||
| 626 | 631 | static int misdn_port_block(int fd, int argc, char *argv[]) |
| 627 | 632 | { |
| 628 | 633 | int port; |
| 629 | ||
| 634 | ||
| 630 | 635 | if (argc != 4) |
| 631 | 636 | return RESULT_SHOWUSAGE; |
| 632 | 637 | |
| --- | --- | |
| 666 | 671 | return 0; |
| 667 | 672 | } |
| 668 | 673 | |
| 674 | static int misdn_restart_pid (int fd, int argc, char *argv[]) | |
| 675 | { | |
| 676 | int pid; | |
| 677 | ||
| 678 | if (argc != 4) | |
| 679 | return RESULT_SHOWUSAGE; | |
| 680 | ||
| 681 | pid = atoi(argv[3]); | |
| 682 | ||
| 683 | misdn_lib_pid_restart(pid); | |
| 684 | ||
| 685 | return 0; | |
| 686 | } | |
| 687 | ||
| 669 | 688 | static int misdn_port_up (int fd, int argc, char *argv[]) |
| 670 | 689 | { |
| 671 | 690 | int port; |
| --- | --- | |
| 683 | 702 | static int misdn_port_down (int fd, int argc, char *argv[]) |
| 684 | 703 | { |
| 685 | 704 | int port; |
| 686 | ||
| 705 | ||
| 687 | 706 | if (argc != 4) |
| 688 | 707 | return RESULT_SHOWUSAGE; |
| 689 | 708 | |
| --- | --- | |
| 694 | 713 | return 0; |
| 695 | 714 | } |
| 696 | 715 | |
| 697 | static inline void show_config_description (int fd, enum misdn_cfg_elements elem) | |
| 698 | { | |
| 699 | char section[BUFFERSIZE]; | |
| 700 | char name[BUFFERSIZE]; | |
| 701 | char desc[BUFFERSIZE]; | |
| 702 | char def[BUFFERSIZE]; | |
| 703 | char tmp[BUFFERSIZE]; | |
| 704 | 716 | |
| 705 | misdn_cfg_get_name(elem, tmp, sizeof(tmp)); | |
| 706 | cw_term_color(name, tmp, COLOR_BRWHITE, 0, sizeof(tmp)); | |
| 707 | misdn_cfg_get_desc(elem, desc, sizeof(desc), def, sizeof(def)); | |
| 708 | ||
| 709 | if (elem < MISDN_CFG_LAST) | |
| 710 | cw_term_color(section, "PORTS SECTION", COLOR_YELLOW, 0, sizeof(section)); | |
| 711 | else | |
| 712 | cw_term_color(section, "GENERAL SECTION", COLOR_YELLOW, 0, sizeof(section)); | |
| 713 | ||
| 714 | if (*def) | |
| 715 | cw_cli(fd, "[%s] %s (Default: %s)\n\t%s\n", section, name, def, desc); | |
| 716 | else | |
| 717 | cw_cli(fd, "[%s] %s\n\t%s\n", section, name, desc); | |
| 718 | } | |
| 719 | ||
| 720 | 717 | static int misdn_show_config (int fd, int argc, char *argv[]) |
| 721 | 718 | { |
| 722 | 719 | char buffer[BUFFERSIZE]; |
| 723 | 720 | enum misdn_cfg_elements elem; |
| 724 | 721 | int linebreak; |
| 722 | ||
| 725 | 723 | int onlyport = -1; |
| 726 | int ok = 0; | |
| 727 | ||
| 728 | 724 | if (argc >= 4) { |
| 729 | if (!strcmp(argv[3], "description")) { | |
| 730 | if (argc == 5) { | |
| 731 | enum misdn_cfg_elements elem = misdn_cfg_get_elem (argv[4]); | |
| 732 | if (elem == MISDN_CFG_FIRST) | |
| 733 | cw_cli(fd, "Unknown element: %s\n", argv[4]); | |
| 734 | else | |
| 735 | show_config_description(fd, elem); | |
| 736 | return 0; | |
| 737 | } | |
| 738 | return RESULT_SHOWUSAGE; | |
| 739 | } | |
| 740 | if (!strcmp(argv[3], "descriptions")) { | |
| 741 | if ((argc == 4) || ((argc == 5) && !strcmp(argv[4], "general"))) { | |
| 742 | for (elem = MISDN_GEN_FIRST + 1; elem < MISDN_GEN_LAST; ++elem) { | |
| 743 | show_config_description(fd, elem); | |
| 744 | cw_cli(fd, "\n"); | |
| 745 | } | |
| 746 | ok = 1; | |
| 747 | } | |
| 748 | if ((argc == 4) || ((argc == 5) && !strcmp(argv[4], "ports"))) { | |
| 749 | for (elem = MISDN_CFG_FIRST + 1; elem < MISDN_CFG_LAST - 1 /* the ptp hack, remove the -1 when ptp is gone */; ++elem) { | |
| 750 | show_config_description(fd, elem); | |
| 751 | cw_cli(fd, "\n"); | |
| 752 | } | |
| 753 | ok = 1; | |
| 754 | } | |
| 755 | return ok ? 0 : RESULT_SHOWUSAGE; | |
| 756 | } | |
| 757 | 725 | if (!sscanf(argv[3], "%d", &onlyport) || onlyport < 0) { |
| 758 | 726 | cw_cli(fd, "Unknown option: %s\n", argv[3]); |
| 759 | 727 | return RESULT_SHOWUSAGE; |
| --- | --- | |
| 786 | 754 | if (misdn_cfg_is_port_valid(onlyport)) { |
| 787 | 755 | cw_cli(fd, "[PORT %d]\n", onlyport); |
| 788 | 756 | for (elem = MISDN_CFG_FIRST + 1, linebreak = 1; elem < MISDN_CFG_LAST; elem++, linebreak++) { |
| 789 | misdn_cfg_get_config_string(onlyport, elem, buffer, BUFFERSIZE); | |
| 757 | misdn_cfg_get_config_string( onlyport, elem, buffer, BUFFERSIZE); | |
| 790 | 758 | cw_cli(fd, "%-36s%s", buffer, !(linebreak % 2) ? "\n" : ""); |
| 791 | 759 | } |
| 792 | 760 | cw_cli(fd, "\n"); |
| --- | --- | |
| 806 | 774 | {MISDN_NOTHING,"NOTHING"}, /* at beginning */ |
| 807 | 775 | {MISDN_WAITING4DIGS,"WAITING4DIGS"}, /* when waiting for infos */ |
| 808 | 776 | {MISDN_EXTCANTMATCH,"EXTCANTMATCH"}, /* when callweaver couldnt match our ext */ |
| 777 | {MISDN_INCOMING_SETUP,"INCOMING SETUP"}, /* when pbx_start */ | |
| 809 | 778 | {MISDN_DIALING,"DIALING"}, /* when pbx_start */ |
| 810 | 779 | {MISDN_PROGRESS,"PROGRESS"}, /* when pbx_start */ |
| 811 | 780 | {MISDN_PROCEEDING,"PROCEEDING"}, /* when pbx_start */ |
| --- | --- | |
| 822 | 791 | {MISDN_HUNGUP_FROM_MISDN,"HUNGUP_FROM_MISDN"}, /* when DISCONNECT/RELEASE/REL_COMP cam from misdn */ |
| 823 | 792 | {MISDN_HOLDED,"HOLDED"}, /* when DISCONNECT/RELEASE/REL_COMP cam from misdn */ |
| 824 | 793 | {MISDN_HOLD_DISCONNECT,"HOLD_DISCONNECT"}, /* when DISCONNECT/RELEASE/REL_COMP cam from misdn */ |
| 825 | {MISDN_HUNGUP_FROM_AST,"HUNGUP_FROM_AST"} /* when DISCONNECT/RELEASE/REL_COMP came out of */ | |
| 794 | {MISDN_HUNGUP_FROM_CW,"HUNGUP_FROM_CW"} /* when DISCONNECT/RELEASE/REL_COMP came out of */ | |
| 826 | 795 | /* misdn_hangup */ |
| 827 | 796 | }; |
| 828 | 797 | |
| --- | --- | |
| 844 | 813 | |
| 845 | 814 | |
| 846 | 815 | |
| 847 | void reload_config(void) | |
| 816 | static void reload_config(void) | |
| 848 | 817 | { |
| 849 | 818 | int i, cfg_debug; |
| 819 | ||
| 820 | if (!g_config_initialized) { | |
| 821 | cw_log(LOG_WARNING, "chan_misdn is not initialized properly, still reloading ?\n"); | |
| 822 | return ; | |
| 823 | } | |
| 850 | 824 | |
| 851 | 825 | free_robin_list(); |
| 852 | 826 | misdn_cfg_reload(); |
| --- | --- | |
| 869 | 843 | |
| 870 | 844 | static void print_bc_info (int fd, struct chan_list* help, struct misdn_bchannel* bc) |
| 871 | 845 | { |
| 872 | struct cw_channel *ast=help->ast; | |
| 846 | struct cw_channel *cw=help->cw; | |
| 873 | 847 | cw_cli(fd, |
| 874 | 848 | "* Pid:%d Prt:%d Ch:%d Mode:%s Org:%s dad:%s oad:%s rad:%s ctx:%s state:%s\n", |
| 875 | 849 | |
| 876 | 850 | bc->pid, bc->port, bc->channel, |
| 877 | 851 | bc->nt?"NT":"TE", |
| 878 | help->orginator == ORG_AST?"*":"I", | |
| 879 | ast?ast->exten:NULL, | |
| 880 | ast?CW_CID_P(ast):NULL, | |
| 852 | help->orginator == ORG_CW?"*":"I", | |
| 853 | cw?cw->exten:NULL, | |
| 854 | cw?CW_CID_P(cw):NULL, | |
| 881 | 855 | bc->rad, |
| 882 | ast?ast->context:NULL, | |
| 856 | cw?cw->context:NULL, | |
| 883 | 857 | misdn_get_ch_state(help) |
| 884 | 858 | ); |
| 885 | 859 | if (misdn_debug[bc->port] > 0) |
| 886 | 860 | cw_cli(fd, |
| 887 | " --> astname: %s\n" | |
| 861 | " --> cwname: %s\n" | |
| 888 | 862 | " --> ch_l3id: %x\n" |
| 889 | 863 | " --> ch_addr: %x\n" |
| 890 | 864 | " --> bc_addr: %x\n" |
| --- | --- | |
| 893 | 867 | " --> activated: %d\n" |
| 894 | 868 | " --> state: %s\n" |
| 895 | 869 | " --> capability: %s\n" |
| 870 | #ifdef MISDN_1_2 | |
| 871 | " --> pipeline: %s\n" | |
| 872 | #else | |
| 896 | 873 | " --> echo_cancel: %d\n" |
| 897 | #ifdef WITH_BEROEC | |
| 898 | " --> bnec_tail: %d\n" | |
| 899 | " --> bnec_nlp: %d\n" | |
| 900 | " --> bnec_ah: %d\n" | |
| 901 | " --> bnec_td: %d\n" | |
| 902 | " --> bnec_zerocoeff: %d\n" | |
| 903 | 874 | #endif |
| 904 | 875 | " --> notone : rx %d tx:%d\n" |
| 905 | " --> bc_hold: %d holded_bc :%d\n", | |
| 906 | help->ast->name, | |
| 876 | " --> bc_hold: %d\n", | |
| 877 | help->cw->name, | |
| 907 | 878 | help->l3id, |
| 908 | 879 | help->addr, |
| 909 | 880 | bc->addr, |
| --- | --- | |
| 913 | 884 | bc->active, |
| 914 | 885 | bc_state2str(bc->bc_state), |
| 915 | 886 | bearer2str(bc->capability), |
| 887 | #ifdef MISDN_1_2 | |
| 888 | bc->pipeline, | |
| 889 | #else | |
| 916 | 890 | bc->ec_enable, |
| 891 | #endif | |
| 917 | 892 | |
| 918 | #ifdef WITH_BEROEC | |
| 919 | bc->bnec_tail, | |
| 920 | bc->bnec_nlp, | |
| 921 | bc->bnec_ah, | |
| 922 | bc->bnec_td, | |
| 923 | bc->bnec_zero, | |
| 924 | #endif | |
| 925 | 893 | help->norxtone,help->notxtone, |
| 926 | bc->holded, help->holded_bc?1:0 | |
| 894 | bc->holded | |
| 927 | 895 | ); |
| 928 | 896 | |
| 929 | 897 | } |
| --- | --- | |
| 936 | 904 | |
| 937 | 905 | for (;help; help=help->next) { |
| 938 | 906 | struct misdn_bchannel *bc=help->bc; |
| 939 | struct cw_channel *ast=help->ast; | |
| 940 | if (misdn_debug[0] > 2) cw_cli(fd, "Bc:%p Opbx:%p\n", bc, ast); | |
| 907 | struct cw_channel *cw=help->cw; | |
| 908 | if (misdn_debug[0] > 2) cw_cli(fd, "Bc:%p Ast:%p\n", bc, cw); | |
| 941 | 909 | if (bc) { |
| 942 | 910 | print_bc_info(fd, help, bc); |
| 943 | } else if ( (bc=help->holded_bc) ) { | |
| 944 | chan_misdn_log(0, 0, "ITS A HOLDED BC:\n"); | |
| 945 | print_bc_info(fd, help, bc); | |
| 946 | 911 | } else { |
| 947 | cw_cli(fd,"* Channel in unknown STATE !!! Exten:%s, Callerid:%s\n", ast->exten, CW_CID_P(ast)); | |
| 912 | if (help->state == MISDN_HOLDED) { | |
| 913 | cw_cli(fd, "ITS A HOLDED BC:\n"); | |
| 914 | cw_cli(fd, " --> l3_id: %x\n" | |
| 915 | " --> dad:%s oad:%s\n" | |
| 916 | ||
| 917 | ,help->l3id | |
| 918 | ,cw->exten | |
| 919 | ,CW_CID_P(cw) | |
| 920 | ); | |
| 921 | } else { | |
| 922 | cw_cli(fd,"* Channel in unknown STATE !!! Exten:%s, Callerid:%s\n", cw->exten, CW_CID_P(cw)); | |
| 923 | } | |
| 948 | 924 | } |
| 949 | 925 | } |
| 950 | 926 | |
| 951 | ||
| 927 | misdn_dump_chanlist(); | |
| 952 | 928 | return 0; |
| 953 | 929 | } |
| 954 | 930 | |
| --- | --- | |
| 961 | 937 | |
| 962 | 938 | for (;help; help=help->next) { |
| 963 | 939 | struct misdn_bchannel *bc=help->bc; |
| 964 | struct cw_channel *ast=help->ast; | |
| 940 | struct cw_channel *cw=help->cw; | |
| 965 | 941 | |
| 966 | if (bc && ast) { | |
| 967 | if (!strcasecmp(ast->name,argv[3])) { | |
| 942 | if (bc && cw) { | |
| 943 | if (!strcasecmp(cw->name,argv[3])) { | |
| 968 | 944 | print_bc_info(fd, help, bc); |
| 969 | 945 | break; |
| 970 | 946 | } |
| --- | --- | |
| 1001 | 977 | cw_cli(fd," %s Debug:%d%s\n", buf, misdn_debug[port], misdn_debug_only[port]?"(only)":""); |
| 1002 | 978 | } |
| 1003 | 979 | |
| 1004 | return 0; | |
| 1005 | } | |
| 1006 | 980 | |
| 1007 | ||
| 1008 | static int misdn_show_ports_stats (int fd, int argc, char *argv[]) | |
| 1009 | { | |
| 1010 | int port; | |
| 1011 | ||
| 1012 | cw_cli(fd, "Port\tin_calls\tout_calls\n"); | |
| 1013 | ||
| 1014 | for (port=misdn_cfg_get_next_port(0); port > 0; | |
| 1015 | port=misdn_cfg_get_next_port(port)) { | |
| 1016 | cw_cli(fd,"%d\t%d\t\t%d\n",port,misdn_in_calls[port],misdn_out_calls[port]); | |
| 1017 | } | |
| 1018 | cw_cli(fd,"\n"); | |
| 1019 | ||
| 1020 | 981 | return 0; |
| 1021 | 982 | |
| 1022 | 983 | } |
| 1023 | 984 | |
| 1024 | ||
| 1025 | 985 | static int misdn_show_port (int fd, int argc, char *argv[]) |
| 1026 | 986 | { |
| 1027 | 987 | int port; |
| --- | --- | |
| 1069 | 1029 | return 0; |
| 1070 | 1030 | } |
| 1071 | 1031 | |
| 1032 | static int misdn_send_restart(int fd, int argc, char *argv[]) | |
| 1033 | { | |
| 1034 | int port; | |
| 1035 | int channel; | |
| 1036 | ||
| 1037 | if ( (argc < 4) || (argc > 5) ) | |
| 1038 | return RESULT_SHOWUSAGE; | |
| 1039 | ||
| 1040 | port = atoi(argv[3]); | |
| 1041 | ||
| 1042 | if (argc==5) { | |
| 1043 | channel = atoi(argv[4]); | |
| 1044 | misdn_lib_send_restart(port, channel); | |
| 1045 | } else | |
| 1046 | misdn_lib_send_restart(port, -1 ); | |
| 1047 | ||
| 1048 | return 0; | |
| 1049 | } | |
| 1050 | ||
| 1051 | ||
| 1052 | ||
| 1072 | 1053 | static int misdn_send_digit (int fd, int argc, char *argv[]) |
| 1073 | 1054 | { |
| 1074 | 1055 | char *channame; |
| --- | --- | |
| 1095 | 1076 | for (i=0; i<msglen; i++) { |
| 1096 | 1077 | cw_cli(fd, "Sending: %c\n",msg[i]); |
| 1097 | 1078 | send_digit_to_chan(tmp, msg[i]); |
| 1098 | /* res = cw_safe_sleep(tmp->ast, 250); */ | |
| 1079 | /* res = cw_safe_sleep(tmp->cw, 250); */ | |
| 1099 | 1080 | usleep(250000); |
| 1100 | /* res = cw_waitfor(tmp->ast,100); */ | |
| 1081 | /* res = cw_waitfor(tmp->cw,100); */ | |
| 1101 | 1082 | } |
| 1102 | 1083 | #else |
| 1103 | 1084 | int res; |
| 1104 | res = cw_dtmf_stream(tmp->ast,NULL,msg,250); | |
| 1085 | res = cw_dtmf_stream(tmp->cw,NULL,msg,250); | |
| 1105 | 1086 | #endif |
| 1106 | 1087 | } |
| 1107 | 1088 | } |
| --- | --- | |
| 1131 | 1112 | tmp->toggle_ec=tmp->toggle_ec?0:1; |
| 1132 | 1113 | |
| 1133 | 1114 | if (tmp->toggle_ec) { |
| 1115 | #ifdef MISDN_1_2 | |
| 1116 | update_pipeline_config(tmp->bc); | |
| 1117 | #else | |
| 1134 | 1118 | update_ec_config(tmp->bc); |
| 1119 | #endif | |
| 1135 | 1120 | manager_ec_enable(tmp->bc); |
| 1136 | 1121 | } else { |
| 1137 | 1122 | manager_ec_disable(tmp->bc); |
| --- | --- | |
| 1217 | 1202 | return NULL; |
| 1218 | 1203 | } |
| 1219 | 1204 | |
| 1220 | static char *complete_show_config (char *line, char *word, int pos, int state) | |
| 1221 | { | |
| 1222 | char buffer[BUFFERSIZE]; | |
| 1223 | enum misdn_cfg_elements elem; | |
| 1224 | int wordlen = strlen(word); | |
| 1225 | int which = 0; | |
| 1226 | int port = 0; | |
| 1227 | ||
| 1228 | switch (pos) { | |
| 1229 | case 3: if ((!strncmp(word, "description", wordlen)) && (++which > state)) | |
| 1230 | return strdup("description"); | |
| 1231 | if ((!strncmp(word, "descriptions", wordlen)) && (++which > state)) | |
| 1232 | return strdup("descriptions"); | |
| 1233 | if ((!strncmp(word, "0", wordlen)) && (++which > state)) | |
| 1234 | return strdup("0"); | |
| 1235 | while ((port = misdn_cfg_get_next_port(port)) != -1) { | |
| 1236 | snprintf(buffer, sizeof(buffer), "%d", port); | |
| 1237 | if ((!strncmp(word, buffer, wordlen)) && (++which > state)) { | |
| 1238 | return strdup(buffer); | |
| 1239 | } | |
| 1240 | } | |
| 1241 | break; | |
| 1242 | case 4: | |
| 1243 | if (strstr(line, "description ")) { | |
| 1244 | for (elem = MISDN_CFG_FIRST + 1; elem < MISDN_GEN_LAST; ++elem) { | |
| 1245 | if ((elem == MISDN_CFG_LAST) || (elem == MISDN_GEN_FIRST)) | |
| 1246 | continue; | |
| 1247 | misdn_cfg_get_name(elem, buffer, BUFFERSIZE); | |
| 1248 | if (!wordlen || !strncmp(word, buffer, wordlen)) { | |
| 1249 | if (++which > state) | |
| 1250 | return strdup(buffer); | |
| 1251 | } | |
| 1252 | } | |
| 1253 | } else if (strstr(line, "descriptions ")) { | |
| 1254 | if ((!wordlen || !strncmp(word, "general", wordlen)) && (++which > state)) | |
| 1255 | return strdup("general"); | |
| 1256 | if ((!wordlen || !strncmp(word, "ports", wordlen)) && (++which > state)) | |
| 1257 | return strdup("ports"); | |
| 1258 | } | |
| 1259 | break; | |
| 1260 | } | |
| 1261 | return NULL; | |
| 1262 | } | |
| 1263 | ||
| 1264 | 1205 | static struct cw_cli_entry cli_send_cd = |
| 1265 | 1206 | { {"misdn","send","calldeflect", NULL}, |
| 1266 | 1207 | misdn_send_cd, |
| --- | --- | |
| 1269 | 1210 | complete_ch |
| 1270 | 1211 | }; |
| 1271 | 1212 | |
| 1213 | static struct cw_cli_entry cli_send_restart= | |
| 1214 | { {"misdn","send","restart", NULL}, | |
| 1215 | misdn_send_restart, | |
| 1216 | "Sends a restart for every bchannel on the given port", | |
| 1217 | "Usage: misdn send restart <port>\n" | |
| 1218 | }; | |
| 1219 | ||
| 1220 | ||
| 1272 | 1221 | static struct cw_cli_entry cli_send_digit = |
| 1273 | 1222 | { {"misdn","send","digit", NULL}, |
| 1274 | 1223 | misdn_send_digit, |
| --- | --- | |
| 1301 | 1250 | { {"misdn","show","config", NULL}, |
| 1302 | 1251 | misdn_show_config, |
| 1303 | 1252 | "Shows internal mISDN config, read from cfg-file", |
| 1304 | "Usage: misdn show config [<port> | description <config element> | descriptions [general|ports]]\n" | |
| 1305 | " Use 0 for <port> to only print the general config.\n", | |
| 1306 | complete_show_config | |
| 1253 | "Usage: misdn show config [port | 0]\n use 0 to only print the general config.\n" | |
| 1307 | 1254 | }; |
| 1308 | 1255 | |
| 1309 | 1256 | static struct cw_cli_entry cli_reload = |
| --- | --- | |
| 1357 | 1304 | "Usage: misdn restart port\n" |
| 1358 | 1305 | }; |
| 1359 | 1306 | |
| 1307 | static struct cw_cli_entry cli_restart_pid = | |
| 1308 | { {"misdn","restart","pid", NULL}, | |
| 1309 | misdn_restart_pid, | |
| 1310 | "Restarts the given pid", | |
| 1311 | "Usage: misdn restart pid\n" | |
| 1312 | }; | |
| 1313 | ||
| 1360 | 1314 | static struct cw_cli_entry cli_port_up = |
| 1361 | 1315 | { {"misdn","port","up", NULL}, |
| 1362 | 1316 | misdn_port_up, |
| --- | --- | |
| 1380 | 1334 | "Usage: misdn show stacks\n" |
| 1381 | 1335 | }; |
| 1382 | 1336 | |
| 1383 | static struct cw_cli_entry cli_show_ports_stats = | |
| 1384 | { {"misdn","show","ports","stats", NULL}, | |
| 1385 | misdn_show_ports_stats, | |
| 1386 | "Shows chan_misdns call statistics per port", | |
| 1387 | "Usage: misdn show port stats\n" | |
| 1388 | }; | |
| 1389 | ||
| 1390 | ||
| 1391 | 1337 | static struct cw_cli_entry cli_show_port = |
| 1392 | 1338 | { {"misdn","show","port", NULL}, |
| 1393 | 1339 | misdn_show_port, |
| --- | --- | |
| 1409 | 1355 | "Sets CryptDebuglevel of chan_misdn, at the moment, level={1,2}", |
| 1410 | 1356 | "Usage: misdn set crypt debug <level>\n" |
| 1411 | 1357 | }; |
| 1358 | ||
| 1412 | 1359 | /*** CLI END ***/ |
| 1413 | 1360 | |
| 1414 | ||
| 1415 | 1361 | static int update_config (struct chan_list *ch, int orig) |
| 1416 | 1362 | { |
| 1417 | 1363 | if (!ch) { |
| --- | --- | |
| 1419 | 1365 | return -1; |
| 1420 | 1366 | } |
| 1421 | 1367 | |
| 1422 | struct cw_channel *ast=ch->ast; | |
| 1368 | struct cw_channel *cw=ch->cw; | |
| 1423 | 1369 | struct misdn_bchannel *bc=ch->bc; |
| 1424 | if (! ast || ! bc ) { | |
| 1425 | cw_log(LOG_WARNING, "Cannot configure without ast || bc\n"); | |
| 1370 | if (! cw || ! bc ) { | |
| 1371 | cw_log(LOG_WARNING, "Cannot configure without cw || bc\n"); | |
| 1426 | 1372 | return -1; |
| 1427 | 1373 | } |
| 1428 | 1374 | |
| 1429 | 1375 | int port=bc->port; |
| 1430 | 1376 | |
| 1431 | chan_misdn_log(1,port,"update_config: Getting Config\n"); | |
| 1377 | chan_misdn_log(7,port,"update_config: Getting Config\n"); | |
| 1432 | 1378 | |
| 1433 | ||
| 1434 | 1379 | int hdlc=0; |
| 1435 | 1380 | misdn_cfg_get( port, MISDN_CFG_HDLC, &hdlc, sizeof(int)); |
| 1436 | 1381 | |
| --- | --- | |
| 1454 | 1399 | |
| 1455 | 1400 | if ( (pres + screen) < 0 ) { |
| 1456 | 1401 | |
| 1457 | chan_misdn_log(2,port," --> pres: %x\n", ast->cid.cid_pres); | |
| 1402 | chan_misdn_log(2,port," --> pres: %x\n", cw->cid.cid_pres); | |
| 1458 | 1403 | |
| 1459 | switch (ast->cid.cid_pres & 0x60){ | |
| 1404 | switch (cw->cid.cid_pres & 0x60){ | |
| 1460 | 1405 | |
| 1461 | 1406 | case CW_PRES_RESTRICTED: |
| 1462 | 1407 | bc->pres=1; |
| --- | --- | |
| 1474 | 1419 | chan_misdn_log(2, port, " --> PRES: Allowed (0x0)\n"); |
| 1475 | 1420 | } |
| 1476 | 1421 | |
| 1477 | switch (ast->cid.cid_pres & 0x3){ | |
| 1422 | switch (cw->cid.cid_pres & 0x3){ | |
| 1478 | 1423 | |
| 1479 | 1424 | case CW_PRES_USER_NUMBER_UNSCREENED: |
| 1480 | 1425 | bc->screen=0; |
| --- | --- | |
| 1541 | 1486 | } |
| 1542 | 1487 | |
| 1543 | 1488 | ch->jb=misdn_jb_init(len, threshold); |
| 1544 | ch->jb_rx=misdn_jb_init(len, threshold); | |
| 1545 | //ch->jb_rx=misdn_jb_init(len, threshold); | |
| 1546 | 1489 | |
| 1547 | if (!ch->jb || !ch->jb_rx) | |
| 1490 | if (!ch->jb ) | |
| 1548 | 1491 | bc->nojitter=1; |
| 1549 | 1492 | } |
| 1550 | 1493 | } |
| --- | --- | |
| 1572 | 1515 | } |
| 1573 | 1516 | } |
| 1574 | 1517 | |
| 1518 | #ifdef MISDN_1_2 | |
| 1519 | static int update_pipeline_config(struct misdn_bchannel *bc) | |
| 1520 | { | |
| 1521 | int ec; | |
| 1575 | 1522 | |
| 1523 | misdn_cfg_get(bc->port, MISDN_CFG_PIPELINE, bc->pipeline, sizeof(bc->pipeline)); | |
| 1576 | 1524 | |
| 1525 | if (*bc->pipeline) | |
| 1526 | return 0; | |
| 1577 | 1527 | |
| 1528 | misdn_cfg_get(bc->port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(int)); | |
| 1529 | if (ec == 1) | |
| 1530 | snprintf(bc->pipeline, sizeof(bc->pipeline) - 1, "mg2ec"); | |
| 1531 | else if (ec > 1) | |
| 1532 | snprintf(bc->pipeline, sizeof(bc->pipeline) - 1, "mg2ec(deftaps=%d)", ec); | |
| 1533 | ||
| 1534 | return 0; | |
| 1535 | } | |
| 1536 | #else | |
| 1578 | 1537 | static int update_ec_config(struct misdn_bchannel *bc) |
| 1579 | 1538 | { |
| 1580 | 1539 | int ec; |
| --- | --- | |
| 1588 | 1547 | bc->ec_enable=1; |
| 1589 | 1548 | bc->ec_deftaps=ec; |
| 1590 | 1549 | } |
| 1591 | #ifdef WITH_ECHOTRAINING | |
| 1592 | int ectr; | |
| 1593 | misdn_cfg_get( port, MISDN_CFG_ECHOTRAINING, &ectr, sizeof(int)); | |
| 1594 | ||
| 1595 | if ( ectr >= 0 ) { | |
| 1596 | bc->ec_training=ectr; | |
| 1597 | } | |
| 1598 | #endif | |
| 1599 | 1550 | |
| 1600 | #ifdef WITH_BEROEC | |
| 1601 | misdn_cfg_get(port, MISDN_CFG_BNECHOCANCEL,&bc->bnec_tail, sizeof(int)); | |
| 1602 | misdn_cfg_get(port, MISDN_CFG_BNEC_ANTIHOWL, &bc->bnec_ah, sizeof(int)); | |
| 1603 | misdn_cfg_get(port, MISDN_CFG_BNEC_NLP, &bc->bnec_nlp, sizeof(int)); | |
| 1604 | misdn_cfg_get(port, MISDN_CFG_BNEC_TD, &bc->bnec_td, sizeof(int)); | |
| 1605 | misdn_cfg_get(port, MISDN_CFG_BNEC_ADAPT, &bc->bnec_adapt, sizeof(int)); | |
| 1606 | misdn_cfg_get(port, MISDN_CFG_BNEC_ZEROCOEFF, &bc->bnec_zero, sizeof(int)); | |
| 1607 | ||
| 1608 | if (bc->bnec_tail && bc->ec_enable) { | |
| 1609 | cw_log(LOG_WARNING,"Are you sure you wan't to mix BNEC with Zapec ? This might cause bad audio quality!\n"); | |
| 1610 | bc->ec_enable=0; | |
| 1611 | } | |
| 1612 | #endif | |
| 1613 | 1551 | return 0; |
| 1614 | 1552 | } |
| 1553 | #endif | |
| 1615 | 1554 | |
| 1616 | ||
| 1617 | 1555 | static int read_config(struct chan_list *ch, int orig) { |
| 1618 | 1556 | |
| 1619 | 1557 | if (!ch) { |
| --- | --- | |
| 1621 | 1559 | return -1; |
| 1622 | 1560 | } |
| 1623 | 1561 | |
| 1624 | struct cw_channel *ast=ch->ast; | |
| 1562 | struct cw_channel *cw=ch->cw; | |
| 1625 | 1563 | struct misdn_bchannel *bc=ch->bc; |
| 1626 | if (! ast || ! bc ) { | |
| 1627 | cw_log(LOG_WARNING, "Cannot configure without ast || bc\n"); | |
| 1564 | if (! cw || ! bc ) { | |
| 1565 | cw_log(LOG_WARNING, "Cannot configure without cw || bc\n"); | |
| 1628 | 1566 | return -1; |
| 1629 | 1567 | } |
| 1630 | 1568 | |
| --- | --- | |
| 1635 | 1573 | char lang[BUFFERSIZE+1]; |
| 1636 | 1574 | |
| 1637 | 1575 | misdn_cfg_get( port, MISDN_CFG_LANGUAGE, lang, BUFFERSIZE); |
| 1638 | cw_copy_string(ast->language, lang, sizeof(ast->language)); | |
| 1576 | cw_copy_string(cw->language, lang, sizeof(cw->language)); | |
| 1639 | 1577 | |
| 1640 | 1578 | char musicclass[BUFFERSIZE+1]; |
| 1641 | 1579 | |
| 1642 | 1580 | misdn_cfg_get( port, MISDN_CFG_MUSICCLASS, musicclass, BUFFERSIZE); |
| 1643 | cw_copy_string(ast->musicclass, musicclass, sizeof(ast->musicclass)); | |
| 1581 | cw_copy_string(cw->musicclass, musicclass, sizeof(cw->musicclass)); | |
| 1644 | 1582 | |
| 1645 | 1583 | misdn_cfg_get( port, MISDN_CFG_TXGAIN, &bc->txgain, sizeof(int)); |
| 1646 | 1584 | misdn_cfg_get( port, MISDN_CFG_RXGAIN, &bc->rxgain, sizeof(int)); |
| --- | --- | |
| 1650 | 1588 | misdn_cfg_get( port, MISDN_CFG_SENDDTMF, &bc->send_dtmf, sizeof(int)); |
| 1651 | 1589 | |
| 1652 | 1590 | misdn_cfg_get( port, MISDN_CFG_NEED_MORE_INFOS, &bc->need_more_infos, sizeof(int)); |
| 1591 | misdn_cfg_get( port, MISDN_CFG_NTTIMEOUT, &ch->nttimeout, sizeof(int)); | |
| 1653 | 1592 | |
| 1593 | misdn_cfg_get( port, MISDN_CFG_NOAUTORESPOND_ON_SETUP, &ch->noautorespond_on_setup, sizeof(int)); | |
| 1594 | ||
| 1654 | 1595 | misdn_cfg_get( port, MISDN_CFG_FAR_ALERTING, &ch->far_alerting, sizeof(int)); |
| 1655 | 1596 | |
| 1656 | 1597 | misdn_cfg_get( port, MISDN_CFG_ALLOWED_BEARERS, &ch->allowed_bearers, BUFFERSIZE); |
| 1657 | ||
| 1658 | char faxdetect[BUFFERSIZE+1]; | |
| 1659 | misdn_cfg_get( port, MISDN_CFG_FAXDETECT, faxdetect, BUFFERSIZE); | |
| 1660 | ||
| 1598 | ||
| 1599 | ||
| 1661 | 1600 | int hdlc=0; |
| 1662 | 1601 | misdn_cfg_get( port, MISDN_CFG_HDLC, &hdlc, sizeof(int)); |
| 1663 | 1602 | |
| --- | --- | |
| 1681 | 1620 | |
| 1682 | 1621 | misdn_cfg_get( bc->port, MISDN_CFG_CONTEXT, ch->context, sizeof(ch->context)); |
| 1683 | 1622 | |
| 1684 | cw_copy_string (ast->context,ch->context,sizeof(ast->context)); | |
| 1623 | cw_copy_string (cw->context,ch->context,sizeof(cw->context)); | |
| 1685 | 1624 | |
| 1625 | #ifdef MISDN_1_2 | |
| 1626 | update_pipeline_config(bc); | |
| 1627 | #else | |
| 1686 | 1628 | update_ec_config(bc); |
| 1629 | #endif | |
| 1687 | 1630 | |
| 1688 | 1631 | { |
| 1689 | 1632 | int eb3; |
| --- | --- | |
| 1702 | 1645 | misdn_cfg_get(port, MISDN_CFG_CALLGROUP, &cg, sizeof(cg)); |
| 1703 | 1646 | |
| 1704 | 1647 | chan_misdn_log(5, port, " --> * CallGrp:%s PickupGrp:%s\n",cw_print_group(buf,sizeof(buf),cg),cw_print_group(buf,sizeof(buf),pg)); |
| 1705 | ast->pickupgroup=pg; | |
| 1706 | ast->callgroup=cg; | |
| 1648 | cw->pickupgroup=pg; | |
| 1649 | cw->callgroup=cg; | |
| 1707 | 1650 | } |
| 1708 | 1651 | |
| 1709 | if ( orig == ORG_AST) { | |
| 1652 | if ( orig == ORG_CW) { | |
| 1710 | 1653 | misdn_cfg_get( port, MISDN_CFG_TE_CHOOSE_CHANNEL, &(bc->te_choose_channel), sizeof(int)); |
| 1711 | ||
| 1712 | if (strstr(faxdetect, "outgoing") || strstr(faxdetect, "both")) { | |
| 1713 | if (strstr(faxdetect, "nojump")) | |
| 1714 | ch->faxdetect=2; | |
| 1715 | else | |
| 1716 | ch->faxdetect=1; | |
| 1717 | } | |
| 1718 | 1654 | |
| 1719 | 1655 | { |
| 1720 | 1656 | char callerid[BUFFERSIZE+1]; |
| --- | --- | |
| 1740 | 1676 | |
| 1741 | 1677 | ch->overlap_dial = 0; |
| 1742 | 1678 | } else { /** ORIGINATOR MISDN **/ |
| 1743 | if (strstr(faxdetect, "incoming") || strstr(faxdetect, "both")) { | |
| 1744 | if (strstr(faxdetect, "nojump")) | |
| 1745 | ch->faxdetect=2; | |
| 1746 | else | |
| 1747 | ch->faxdetect=1; | |
| 1748 | } | |
| 1749 | 1679 | |
| 1750 | 1680 | misdn_cfg_get( port, MISDN_CFG_CPNDIALPLAN, &bc->cpnnumplan, sizeof(int)); |
| 1751 | 1681 | debug_numplan(port, bc->cpnnumplan,"CTON"); |
| --- | --- | |
| 1800 | 1730 | strcpy(bc->dad,tmp); |
| 1801 | 1731 | } |
| 1802 | 1732 | |
| 1803 | if ( strcmp(bc->dad,ast->exten)) { | |
| 1804 | cw_copy_string(ast->exten, bc->dad, sizeof(ast->exten)); | |
| 1733 | if ( strcmp(bc->dad,cw->exten)) { | |
| 1734 | cw_copy_string(cw->exten, bc->dad, sizeof(cw->exten)); | |
| 1805 | 1735 | } |
| 1806 | 1736 | |
| 1807 | cw_set_callerid(ast, bc->oad, NULL, bc->oad); | |
| 1737 | cw_set_callerid(cw, bc->oad, NULL, bc->oad); | |
| 1808 | 1738 | |
| 1809 | 1739 | if ( !cw_strlen_zero(bc->rad) ) |
| 1810 | ast->cid.cid_rdnis=strdup(bc->rad); | |
| 1740 | cw->cid.cid_rdnis=strdup(bc->rad); | |
| 1811 | 1741 | |
| 1812 | 1742 | misdn_cfg_get(bc->port, MISDN_CFG_OVERLAP_DIAL, &ch->overlap_dial, sizeof(ch->overlap_dial)); |
| 1813 | 1743 | cw_mutex_init(&ch->overlap_tv_lock); |
| --- | --- | |
| 1815 | 1745 | |
| 1816 | 1746 | ch->overlap_dial_task = -1; |
| 1817 | 1747 | |
| 1818 | if (ch->faxdetect) { | |
| 1819 | misdn_cfg_get( port, MISDN_CFG_FAXDETECT_TIMEOUT, &ch->faxdetect_timeout, sizeof(ch->faxdetect_timeout)); | |
| 1820 | if (!ch->dsp) | |
| 1821 | ch->dsp = cw_dsp_new(); | |
| 1822 | if (ch->dsp) | |
| 1823 | cw_dsp_set_features(ch->dsp, DSP_FEATURE_DTMF_DETECT | DSP_FEATURE_FAX_CNG_DETECT); | |
| 1824 | if (!ch->trans) | |
| 1825 | ch->trans=cw_translator_build_path(CW_FORMAT_SLINEAR, 8000, CW_FORMAT_ALAW, 8000); | |
| 1826 | } | |
| 1827 | ||
| 1828 | 1748 | return 0; |
| 1829 | 1749 | } |
| 1830 | 1750 | |
| 1831 | 1751 | |
| 1832 | 1752 | /*****************************/ |
| 1833 | /*** AST Indications Start ***/ | |
| 1753 | /*** CW Indications Start ***/ | |
| 1834 | 1754 | /*****************************/ |
| 1835 | 1755 | |
| 1836 | static int misdn_call(struct cw_channel *ast, char *dest, int timeout) | |
| 1756 | static int misdn_call(struct cw_channel *cw, char *dest) | |
| 1837 | 1757 | { |
| 1838 | 1758 | int port=0; |
| 1839 | 1759 | int r; |
| 1840 | struct chan_list *ch=MISDN_CALLWEAVER_TECH_PVT(ast); | |
| 1760 | struct chan_list *ch=MISDN_CALLWEAVER_TECH_PVT(cw); | |
| 1841 | 1761 | struct misdn_bchannel *newbc; |
| 1842 | char *opts=NULL, *ext,*tokb; | |
| 1762 | char *opts=NULL, *ext; | |
| 1843 | 1763 | char dest_cp[256]; |
| 1844 | 1764 | |
| 1845 | 1765 | { |
| 1846 | 1766 | strncpy(dest_cp,dest,sizeof(dest_cp)-1); |
| 1847 | 1767 | dest_cp[sizeof(dest_cp)]=0; |
| 1848 | ||
| 1849 | ext=strtok_r(dest_cp,"/",&tokb); | |
| 1850 | ||
| 1768 | ||
| 1769 | ext=dest_cp; | |
| 1770 | strsep(&ext,"/"); | |
| 1851 | 1771 | if (ext) { |
| 1852 | ext=strtok_r(NULL,"/",&tokb); | |
| 1853 | if (ext) { | |
| 1854 | opts=strtok_r(NULL,"/",&tokb); | |
| 1855 | } else { | |
| 1856 | chan_misdn_log(0,0,"misdn_call: No Extension given!\n"); | |
| 1857 | < |
![Home changeset 5220 [home]](/images/logo.png?1180520111)