2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2004 - 2006, Christian Richter
6 * Christian Richter <crich@beronet.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
23 * \brief the chan_misdn channel driver for Asterisk
25 * \author Christian Richter <crich@beronet.com>
27 * \extref MISDN http://www.misdn.org/
29 * \ingroup channel_drivers
33 <depend>isdnnet</depend>
34 <depend>misdn</depend>
35 <depend>suppserv</depend>
39 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
42 #include <sys/socket.h>
44 #include <arpa/inet.h>
46 #include <sys/ioctl.h>
49 #include <semaphore.h>
51 #include "asterisk/channel.h"
52 #include "asterisk/config.h"
53 #include "asterisk/module.h"
54 #include "asterisk/pbx.h"
55 #include "asterisk/io.h"
56 #include "asterisk/frame.h"
57 #include "asterisk/translate.h"
58 #include "asterisk/cli.h"
59 #include "asterisk/musiconhold.h"
60 #include "asterisk/dsp.h"
61 #include "asterisk/file.h"
62 #include "asterisk/callerid.h"
63 #include "asterisk/indications.h"
64 #include "asterisk/app.h"
65 #include "asterisk/features.h"
66 #include "asterisk/term.h"
67 #include "asterisk/sched.h"
68 #include "asterisk/stringfields.h"
69 #include "asterisk/abstract_jb.h"
70 #include "asterisk/causes.h"
72 #include "chan_misdn_config.h"
75 char global_tracefile[BUFFERSIZE + 1];
77 static int g_config_initialized = 0;
93 /*! \brief allocates the jb-structure and initialise the elements*/
94 struct misdn_jb *misdn_jb_init(int size, int upper_threshold);
96 /*! \brief frees the data and destroys the given jitterbuffer struct */
97 void misdn_jb_destroy(struct misdn_jb *jb);
99 /*! \brief fills the jitterbuffer with len data returns < 0 if there was an
100 error (bufferoverun). */
101 int misdn_jb_fill(struct misdn_jb *jb, const char *data, int len);
103 /*! \brief gets len bytes out of the jitterbuffer if available, else only the
104 available data is returned and the return value indicates the number
106 int misdn_jb_empty(struct misdn_jb *jb, char *data, int len);
108 static char *complete_ch(struct ast_cli_args *a);
109 static char *complete_debug_port(struct ast_cli_args *a);
110 static char *complete_show_config(struct ast_cli_args *a);
112 /* BEGIN: chan_misdn.h */
114 ast_mutex_t release_lock;
116 enum misdn_chan_state {
117 MISDN_NOTHING=0, /*!< at beginning */
118 MISDN_WAITING4DIGS, /*!< when waiting for infos */
119 MISDN_EXTCANTMATCH, /*!< when asterisk couldnt match our ext */
120 MISDN_INCOMING_SETUP, /*!< for incoming setups*/
121 MISDN_DIALING, /*!< when pbx_start */
122 MISDN_PROGRESS, /*!< we got a progress */
123 MISDN_PROCEEDING, /*!< we got a progress */
124 MISDN_CALLING, /*!< when misdn_call is called */
125 MISDN_CALLING_ACKNOWLEDGE, /*!< when we get SETUP_ACK */
126 MISDN_ALERTING, /*!< when Alerting */
127 MISDN_BUSY, /*!< when BUSY */
128 MISDN_CONNECTED, /*!< when connected */
129 MISDN_PRECONNECTED, /*!< when connected */
130 MISDN_DISCONNECTED, /*!< when connected */
131 MISDN_RELEASED, /*!< when connected */
132 MISDN_BRIDGED, /*!< when bridged */
133 MISDN_CLEANING, /*!< when hangup from * but we were connected before */
134 MISDN_HUNGUP_FROM_MISDN, /*!< when DISCONNECT/RELEASE/REL_COMP cam from misdn */
135 MISDN_HUNGUP_FROM_AST, /*!< when DISCONNECT/RELEASE/REL_COMP came out of */
137 MISDN_HOLDED, /*!< if this chan is holded */
138 MISDN_HOLD_DISCONNECT, /*!< if this chan is holded */
152 char allowed_bearers[BUFFERSIZE + 1];
154 enum misdn_chan_state state;
155 int need_queue_hangup;
160 int noautorespond_on_setup;
167 int incoming_early_audio;
172 char ast_rd_buf[4096];
173 struct ast_frame frame;
175 int faxdetect; /*!< 0:no 1:yes 2:yes+nojump */
176 int faxdetect_timeout;
177 struct timeval faxdetect_tv;
183 int jb_upper_threshold;
187 struct ast_trans_pvt *trans;
189 struct ast_channel * ast;
193 struct misdn_bchannel *bc;
195 struct hold_info hold_info;
200 char context[BUFFERSIZE];
203 int dropped_frame_cnt;
210 struct chan_list *other_ch;
212 const struct ind_tone_zone_sound *ts;
215 int overlap_dial_task;
216 ast_mutex_t overlap_tv_lock;
217 struct timeval overlap_tv;
219 struct chan_list *peer;
220 struct chan_list *next;
221 struct chan_list *prev;
222 struct chan_list *first;
227 void export_ch(struct ast_channel *chan, struct misdn_bchannel *bc, struct chan_list *ch);
228 void import_ch(struct ast_channel *chan, struct misdn_bchannel *bc, struct chan_list *ch);
234 struct robin_list *next;
235 struct robin_list *prev;
237 static struct robin_list *robin = NULL;
241 static struct ast_frame *process_ast_dsp(struct chan_list *tmp, struct ast_frame *frame);
245 static inline void free_robin_list_r (struct robin_list *r)
249 free_robin_list_r(r->next);
256 static void free_robin_list ( void )
258 free_robin_list_r(robin);
262 static struct robin_list* get_robin_position (char *group)
264 struct robin_list *new;
265 struct robin_list *iter = robin;
266 for (; iter; iter = iter->next) {
267 if (!strcasecmp(iter->group, group))
270 new = ast_calloc(1, sizeof(*new));
271 new->group = strndup(group, strlen(group));
282 /*! \brief the main schedule context for stuff like l1 watcher, overlap dial, ... */
283 static struct sched_context *misdn_tasks = NULL;
284 static pthread_t misdn_tasks_thread;
286 static int *misdn_ports;
288 static void chan_misdn_log(int level, int port, char *tmpl, ...)
289 __attribute__ ((format (printf, 3, 4)));
291 static struct ast_channel *misdn_new(struct chan_list *cl, int state, char *exten, char *callerid, int format, int port, int c);
292 static void send_digit_to_chan(struct chan_list *cl, char digit );
294 static void hangup_chan(struct chan_list *ch);
295 static int pbx_start_chan(struct chan_list *ch);
297 #define MISDN_ASTERISK_TECH_PVT(ast) ast->tech_pvt
298 #define MISDN_ASTERISK_PVT(ast) 1
300 #include "asterisk/strings.h"
302 /* #define MISDN_DEBUG 1 */
304 static const char misdn_type[] = "mISDN";
306 static int tracing = 0 ;
308 /*! \brief Only alaw and mulaw is allowed for now */
309 static int prefformat = AST_FORMAT_ALAW ; /* AST_FORMAT_SLINEAR ; AST_FORMAT_ULAW | */
311 static int *misdn_debug;
312 static int *misdn_debug_only;
313 static int max_ports;
315 static int *misdn_in_calls;
316 static int *misdn_out_calls;
319 struct chan_list dummy_cl;
321 struct chan_list *cl_te=NULL;
322 ast_mutex_t cl_te_lock;
324 static enum event_response_e
325 cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data);
327 static void send_cause2ast(struct ast_channel *ast, struct misdn_bchannel*bc, struct chan_list *ch);
329 static void cl_queue_chan(struct chan_list **list, struct chan_list *chan);
330 static void cl_dequeue_chan(struct chan_list **list, struct chan_list *chan);
331 static struct chan_list *find_chan_by_bc(struct chan_list *list, struct misdn_bchannel *bc);
332 static struct chan_list *find_chan_by_pid(struct chan_list *list, int pid);
336 static int dialtone_indicate(struct chan_list *cl);
337 static int hanguptone_indicate(struct chan_list *cl);
338 static int stop_indicate(struct chan_list *cl);
340 static int start_bc_tones(struct chan_list *cl);
341 static int stop_bc_tones(struct chan_list *cl);
342 static void release_chan(struct misdn_bchannel *bc);
344 static int misdn_check_l2l1(struct ast_channel *chan, void *data);
345 static int misdn_set_opt_exec(struct ast_channel *chan, void *data);
346 static int misdn_facility_exec(struct ast_channel *chan, void *data);
348 int chan_misdn_jb_empty(struct misdn_bchannel *bc, char *buf, int len);
351 void debug_numplan(int port, int numplan, char *type);
354 int add_out_calls(int port);
355 int add_in_calls(int port);
359 static int update_pipeline_config(struct misdn_bchannel *bc);
361 static int update_ec_config(struct misdn_bchannel *bc);
369 int chan_misdn_jb_empty ( struct misdn_bchannel *bc, char *buf, int len);
371 /*************** Helpers *****************/
373 static struct chan_list * get_chan_by_ast(struct ast_channel *ast)
375 struct chan_list *tmp;
377 for (tmp=cl_te; tmp; tmp = tmp->next) {
378 if ( tmp->ast == ast ) return tmp;
384 static struct chan_list * get_chan_by_ast_name(char *name)
386 struct chan_list *tmp;
388 for (tmp=cl_te; tmp; tmp = tmp->next) {
389 if ( tmp->ast && strcmp(tmp->ast->name,name) == 0) return tmp;
397 struct allowed_bearers {
403 struct allowed_bearers allowed_bearers_array[]={
404 {INFO_CAPABILITY_SPEECH,1,"speech"},
405 {INFO_CAPABILITY_AUDIO_3_1K,2,"3_1khz"},
406 {INFO_CAPABILITY_DIGITAL_UNRESTRICTED,4,"digital_unrestricted"},
407 {INFO_CAPABILITY_DIGITAL_RESTRICTED,8,"digital_restriced"},
408 {INFO_CAPABILITY_VIDEO,16,"video"}
411 static char *bearer2str(int cap) {
412 static char *bearers[]={
422 case INFO_CAPABILITY_SPEECH:
425 case INFO_CAPABILITY_AUDIO_3_1K:
428 case INFO_CAPABILITY_DIGITAL_UNRESTRICTED:
431 case INFO_CAPABILITY_DIGITAL_RESTRICTED:
434 case INFO_CAPABILITY_VIDEO:
444 static void print_facility(struct FacParm *fac, struct misdn_bchannel *bc)
446 switch (fac->Function) {
447 #ifdef HAVE_MISDN_FAC_RESULT
449 chan_misdn_log(0, bc->port," --> Received RESULT Operation\n");
452 #ifdef HAVE_MISDN_FAC_ERROR
454 chan_misdn_log(0, bc->port," --> Received Error Operation\n");
455 chan_misdn_log(0, bc->port," --> Value:%d Error:%s\n",fac->u.ERROR.errorValue, fac->u.ERROR.error);
459 chan_misdn_log(1,bc->port," --> calldeflect to: %s, screened: %s\n", fac->u.CDeflection.DeflectedToNumber,
460 fac->u.CDeflection.PresentationAllowed ? "yes" : "no");
462 case Fac_AOCDCurrency:
463 if (fac->u.AOCDcur.chargeNotAvailable)
464 chan_misdn_log(1,bc->port," --> AOCD currency: charge not available\n");
465 else if (fac->u.AOCDcur.freeOfCharge)
466 chan_misdn_log(1,bc->port," --> AOCD currency: free of charge\n");
467 else if (fac->u.AOCDchu.billingId >= 0)
468 chan_misdn_log(1,bc->port," --> AOCD currency: currency:%s amount:%d multiplier:%d typeOfChargingInfo:%s billingId:%d\n",
469 fac->u.AOCDcur.currency, fac->u.AOCDcur.currencyAmount, fac->u.AOCDcur.multiplier,
470 (fac->u.AOCDcur.typeOfChargingInfo == 0) ? "subTotal" : "total", fac->u.AOCDcur.billingId);
472 chan_misdn_log(1,bc->port," --> AOCD currency: currency:%s amount:%d multiplier:%d typeOfChargingInfo:%s\n",
473 fac->u.AOCDcur.currency, fac->u.AOCDcur.currencyAmount, fac->u.AOCDcur.multiplier,
474 (fac->u.AOCDcur.typeOfChargingInfo == 0) ? "subTotal" : "total");
476 case Fac_AOCDChargingUnit:
477 if (fac->u.AOCDchu.chargeNotAvailable)
478 chan_misdn_log(1,bc->port," --> AOCD charging unit: charge not available\n");
479 else if (fac->u.AOCDchu.freeOfCharge)
480 chan_misdn_log(1,bc->port," --> AOCD charging unit: free of charge\n");
481 else if (fac->u.AOCDchu.billingId >= 0)
482 chan_misdn_log(1,bc->port," --> AOCD charging unit: recordedUnits:%d typeOfChargingInfo:%s billingId:%d\n",
483 fac->u.AOCDchu.recordedUnits, (fac->u.AOCDchu.typeOfChargingInfo == 0) ? "subTotal" : "total", fac->u.AOCDchu.billingId);
485 chan_misdn_log(1,bc->port," --> AOCD charging unit: recordedUnits:%d typeOfChargingInfo:%s\n",
486 fac->u.AOCDchu.recordedUnits, (fac->u.AOCDchu.typeOfChargingInfo == 0) ? "subTotal" : "total");
490 chan_misdn_log(1,bc->port," --> unknown facility\n");
494 static void print_bearer(struct misdn_bchannel *bc)
497 chan_misdn_log(2, bc->port, " --> Bearer: %s\n",bearer2str(bc->capability));
500 case INFO_CODEC_ALAW:
501 chan_misdn_log(2, bc->port, " --> Codec: Alaw\n");
503 case INFO_CODEC_ULAW:
504 chan_misdn_log(2, bc->port, " --> Codec: Ulaw\n");
509 static void export_aoc_vars(int originator, struct ast_channel *ast, struct misdn_bchannel *bc)
513 if (!bc->AOCD_need_export || !ast)
516 if (originator == ORG_AST) {
517 ast = ast_bridged_channel(ast);
522 switch (bc->AOCDtype) {
523 case Fac_AOCDCurrency:
524 pbx_builtin_setvar_helper(ast, "AOCD_Type", "currency");
525 if (bc->AOCD.currency.chargeNotAvailable)
526 pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "no");
528 pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "yes");
529 if (bc->AOCD.currency.freeOfCharge)
530 pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "yes");
532 pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "no");
533 if (snprintf(buf, sizeof(buf), "%d %s", bc->AOCD.currency.currencyAmount * bc->AOCD.currency.multiplier, bc->AOCD.currency.currency) < sizeof(buf)) {
534 pbx_builtin_setvar_helper(ast, "AOCD_Amount", buf);
535 if (bc->AOCD.currency.billingId >= 0 && snprintf(buf, sizeof(buf), "%d", bc->AOCD.currency.billingId) < sizeof(buf))
536 pbx_builtin_setvar_helper(ast, "AOCD_BillingId", buf);
541 case Fac_AOCDChargingUnit:
542 pbx_builtin_setvar_helper(ast, "AOCD_Type", "charging_unit");
543 if (bc->AOCD.chargingUnit.chargeNotAvailable)
544 pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "no");
546 pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "yes");
547 if (bc->AOCD.chargingUnit.freeOfCharge)
548 pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "yes");
550 pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "no");
551 if (snprintf(buf, sizeof(buf), "%d", bc->AOCD.chargingUnit.recordedUnits) < sizeof(buf)) {
552 pbx_builtin_setvar_helper(ast, "AOCD_RecordedUnits", buf);
553 if (bc->AOCD.chargingUnit.billingId >= 0 && snprintf(buf, sizeof(buf), "%d", bc->AOCD.chargingUnit.billingId) < sizeof(buf))
554 pbx_builtin_setvar_helper(ast, "AOCD_BillingId", buf);
563 bc->AOCD_need_export = 0;
566 /*************** Helpers END *************/
568 static void sighandler(int sig)
571 static void* misdn_tasks_thread_func (void *data)
576 sa.sa_handler = sighandler;
577 sa.sa_flags = SA_NODEFER;
578 sigemptyset(&sa.sa_mask);
579 sigaddset(&sa.sa_mask, SIGUSR1);
580 sigaction(SIGUSR1, &sa, NULL);
582 sem_post((sem_t *)data);
585 wait = ast_sched_wait(misdn_tasks);
588 if (poll(NULL, 0, wait) < 0)
589 chan_misdn_log(4, 0, "Waking up misdn_tasks thread\n");
590 ast_sched_runq(misdn_tasks);
595 static void misdn_tasks_init (void)
600 if (sem_init(&blocker, 0, 0)) {
601 perror("chan_misdn: Failed to initialize semaphore!");
605 chan_misdn_log(4, 0, "Starting misdn_tasks thread\n");
607 misdn_tasks = sched_context_create();
608 pthread_create(&misdn_tasks_thread, NULL, misdn_tasks_thread_func, &blocker);
610 while (sem_wait(&blocker) && --i);
611 sem_destroy(&blocker);
614 static void misdn_tasks_destroy (void)
617 chan_misdn_log(4, 0, "Killing misdn_tasks thread\n");
618 if ( pthread_cancel(misdn_tasks_thread) == 0 ) {
619 cb_log(4, 0, "Joining misdn_tasks thread\n");
620 pthread_join(misdn_tasks_thread, NULL);
622 sched_context_destroy(misdn_tasks);
626 static inline void misdn_tasks_wakeup (void)
628 pthread_kill(misdn_tasks_thread, SIGUSR1);
631 static inline int _misdn_tasks_add_variable (int timeout, ast_sched_cb callback, const void *data, int variable)
638 task_id = ast_sched_add_variable(misdn_tasks, timeout, callback, data, variable);
639 misdn_tasks_wakeup();
644 static int misdn_tasks_add (int timeout, ast_sched_cb callback, const void *data)
646 return _misdn_tasks_add_variable(timeout, callback, data, 0);
649 static int misdn_tasks_add_variable (int timeout, ast_sched_cb callback, const void *data)
651 return _misdn_tasks_add_variable(timeout, callback, data, 1);
654 static void misdn_tasks_remove (int task_id)
656 AST_SCHED_DEL(misdn_tasks, task_id);
659 static int misdn_l1_task (const void *data)
661 misdn_lib_isdn_l1watcher(*(int *)data);
662 chan_misdn_log(5, *(int *)data, "L1watcher timeout\n");
666 static int misdn_overlap_dial_task (const void *data)
668 struct timeval tv_end, tv_now;
670 struct chan_list *ch = (struct chan_list *)data;
672 chan_misdn_log(4, ch->bc->port, "overlap dial task, chan_state: %d\n", ch->state);
674 if (ch->state != MISDN_WAITING4DIGS) {
675 ch->overlap_dial_task = -1;
679 ast_mutex_lock(&ch->overlap_tv_lock);
680 tv_end = ch->overlap_tv;
681 ast_mutex_unlock(&ch->overlap_tv_lock);
683 tv_end.tv_sec += ch->overlap_dial;
684 tv_now = ast_tvnow();
686 diff = ast_tvdiff_ms(tv_end, tv_now);
689 char *dad=ch->bc->dad, sexten[]="s";
690 /* if we are 100ms near the timeout, we are satisfied.. */
693 if (ast_strlen_zero(ch->bc->dad)) {
695 strcpy(ch->ast->exten, sexten);
698 if (ast_exists_extension(ch->ast, ch->context, dad, 1, ch->bc->oad)) {
699 ch->state=MISDN_DIALING;
700 if (pbx_start_chan(ch) < 0) {
701 chan_misdn_log(-1, ch->bc->port, "ast_pbx_start returned < 0 in misdn_overlap_dial_task\n");
702 goto misdn_overlap_dial_task_disconnect;
705 misdn_overlap_dial_task_disconnect:
706 hanguptone_indicate(ch);
708 ch->state=MISDN_CLEANING;
709 misdn_lib_send_event(ch->bc, EVENT_DISCONNECT);
711 ch->overlap_dial_task = -1;
717 static void send_digit_to_chan(struct chan_list *cl, char digit )
719 static const char* dtmf_tones[] = {
720 "!941+1336/100,!0/100", /* 0 */
721 "!697+1209/100,!0/100", /* 1 */
722 "!697+1336/100,!0/100", /* 2 */
723 "!697+1477/100,!0/100", /* 3 */
724 "!770+1209/100,!0/100", /* 4 */
725 "!770+1336/100,!0/100", /* 5 */
726 "!770+1477/100,!0/100", /* 6 */
727 "!852+1209/100,!0/100", /* 7 */
728 "!852+1336/100,!0/100", /* 8 */
729 "!852+1477/100,!0/100", /* 9 */
730 "!697+1633/100,!0/100", /* A */
731 "!770+1633/100,!0/100", /* B */
732 "!852+1633/100,!0/100", /* C */
733 "!941+1633/100,!0/100", /* D */
734 "!941+1209/100,!0/100", /* * */
735 "!941+1477/100,!0/100" }; /* # */
736 struct ast_channel *chan=cl->ast;
738 if (digit >= '0' && digit <='9')
739 ast_playtones_start(chan,0,dtmf_tones[digit-'0'], 0);
740 else if (digit >= 'A' && digit <= 'D')
741 ast_playtones_start(chan,0,dtmf_tones[digit-'A'+10], 0);
742 else if (digit == '*')
743 ast_playtones_start(chan,0,dtmf_tones[14], 0);
744 else if (digit == '#')
745 ast_playtones_start(chan,0,dtmf_tones[15], 0);
748 ast_debug(1, "Unable to handle DTMF tone '%c' for '%s'\n", digit, chan->name);
752 /*** CLI HANDLING ***/
753 static char *handle_cli_misdn_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
759 e->command = "misdn set debug";
761 "Usage: misdn set debug <level> [only] | [port <port> [only]]\n"
762 " Set the debug level of the mISDN channel.\n";
765 return complete_debug_port(a);
768 if (a->argc < 4 || a->argc > 7)
769 return CLI_SHOWUSAGE;
771 level = atoi(a->argv[3]);
779 if (strncasecmp(a->argv[4], "only", strlen(a->argv[4])))
780 return CLI_SHOWUSAGE;
785 for (i = 0; i <= max_ports; i++) {
786 misdn_debug[i] = level;
787 misdn_debug_only[i] = only;
789 ast_cli(a->fd, "changing debug level for all ports to %d%s\n",misdn_debug[0], only?" (only)":"");
796 if (strncasecmp(a->argv[4], "port", strlen(a->argv[4])))
797 return CLI_SHOWUSAGE;
798 port = atoi(a->argv[5]);
799 if (port <= 0 || port > max_ports) {
802 ast_cli(a->fd, "port number not valid! no ports available so you won't get lucky with any number here...\n");
805 ast_cli(a->fd, "port number not valid! only port 1 is availble.\n");
808 ast_cli(a->fd, "port number not valid! only ports 1 to %d are available.\n", max_ports);
813 if (strncasecmp(a->argv[6], "only", strlen(a->argv[6])))
814 return CLI_SHOWUSAGE;
816 misdn_debug_only[port] = 1;
818 misdn_debug_only[port] = 0;
819 misdn_debug[port] = level;
820 ast_cli(a->fd, "changing debug level to %d%s for port %d\n", misdn_debug[port], misdn_debug_only[port]?" (only)":"", port);
827 static char *handle_cli_misdn_set_crypt_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
831 e->command = "misdn set crypt debug";
833 "Usage: misdn set crypt debug <level>\n"
834 " Set the crypt debug level of the mISDN channel. Level\n"
835 " must be 1 or 2.\n";
842 return CLI_SHOWUSAGE;
844 /* Is this supposed to not do anything? */
849 static char *handle_cli_misdn_port_block(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
853 e->command = "misdn port block";
855 "Usage: misdn port block <port>\n"
856 " Block the specified port by <port>.\n";
863 return CLI_SHOWUSAGE;
865 misdn_lib_port_block(atoi(a->argv[3]));
870 static char *handle_cli_misdn_port_unblock(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
874 e->command = "misdn port unblock";
876 "Usage: misdn port unblock <port>\n"
877 " Unblock the port specified by <port>.\n";
884 return CLI_SHOWUSAGE;
886 misdn_lib_port_unblock(atoi(a->argv[3]));
891 static char *handle_cli_misdn_restart_port(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
895 e->command = "misdn restart port";
897 "Usage: misdn restart port <port>\n"
898 " Restart the given port.\n";
905 return CLI_SHOWUSAGE;
907 misdn_lib_port_restart(atoi(a->argv[3]));
912 static char *handle_cli_misdn_restart_pid(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
916 e->command = "misdn restart pid";
918 "Usage: misdn restart pid <pid>\n"
919 " Restart the given pid\n";
926 return CLI_SHOWUSAGE;
928 misdn_lib_pid_restart(atoi(a->argv[3]));
933 static char *handle_cli_misdn_port_up(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
937 e->command = "misdn port up";
939 "Usage: misdn port up <port>\n"
940 " Try to establish L1 on the given port.\n";
947 return CLI_SHOWUSAGE;
949 misdn_lib_get_port_up(atoi(a->argv[3]));
954 static char *handle_cli_misdn_port_down(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
958 e->command = "misdn port down";
960 "Usage: misdn port down <port>\n"
961 " Try to deacivate the L1 on the given port.\n";
968 return CLI_SHOWUSAGE;
970 misdn_lib_get_port_down(atoi(a->argv[3]));
975 static inline void show_config_description(int fd, enum misdn_cfg_elements elem)
977 char section[BUFFERSIZE];
978 char name[BUFFERSIZE];
979 char desc[BUFFERSIZE];
980 char def[BUFFERSIZE];
981 char tmp[BUFFERSIZE];
983 misdn_cfg_get_name(elem, tmp, sizeof(tmp));
984 term_color(name, tmp, COLOR_BRWHITE, 0, sizeof(tmp));
985 misdn_cfg_get_desc(elem, desc, sizeof(desc), def, sizeof(def));
987 if (elem < MISDN_CFG_LAST)
988 term_color(section, "PORTS SECTION", COLOR_YELLOW, 0, sizeof(section));
990 term_color(section, "GENERAL SECTION", COLOR_YELLOW, 0, sizeof(section));
993 ast_cli(fd, "[%s] %s (Default: %s)\n\t%s\n", section, name, def, desc);
995 ast_cli(fd, "[%s] %s\n\t%s\n", section, name, desc);
1000 static char *handle_cli_misdn_show_config(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1002 char buffer[BUFFERSIZE];
1003 enum misdn_cfg_elements elem;
1010 e->command = "misdn show config";
1012 "Usage: misdn show config [<port> | description <config element> | descriptions [general|ports]]\n"
1013 " Use 0 for <port> to only print the general config.\n";
1016 return complete_show_config(a);
1020 if (!strcmp(a->argv[3], "description")) {
1022 enum misdn_cfg_elements elem = misdn_cfg_get_elem(a->argv[4]);
1023 if (elem == MISDN_CFG_FIRST)
1024 ast_cli(a->fd, "Unknown element: %s\n", a->argv[4]);
1026 show_config_description(a->fd, elem);
1029 return CLI_SHOWUSAGE;
1030 } else if (!strcmp(a->argv[3], "descriptions")) {
1031 if ((a->argc == 4) || ((a->argc == 5) && !strcmp(a->argv[4], "general"))) {
1032 for (elem = MISDN_GEN_FIRST + 1; elem < MISDN_GEN_LAST; ++elem) {
1033 show_config_description(a->fd, elem);
1034 ast_cli(a->fd, "\n");
1038 if ((a->argc == 4) || ((a->argc == 5) && !strcmp(a->argv[4], "ports"))) {
1039 for (elem = MISDN_CFG_FIRST + 1; elem < MISDN_CFG_LAST - 1 /* the ptp hack, remove the -1 when ptp is gone */; ++elem) {
1040 show_config_description(a->fd, elem);
1041 ast_cli(a->fd, "\n");
1045 return ok ? CLI_SUCCESS : CLI_SHOWUSAGE;
1046 } else if (!sscanf(a->argv[3], "%d", &onlyport) || onlyport < 0) {
1047 ast_cli(a->fd, "Unknown option: %s\n", a->argv[3]);
1048 return CLI_SHOWUSAGE;
1050 } else if (a->argc == 3 || onlyport == 0) {
1051 ast_cli(a->fd, "mISDN General-Config:\n");
1052 for (elem = MISDN_GEN_FIRST + 1, linebreak = 1; elem < MISDN_GEN_LAST; elem++, linebreak++) {
1053 misdn_cfg_get_config_string(0, elem, buffer, sizeof(buffer));
1054 ast_cli(a->fd, "%-36s%s", buffer, !(linebreak % 2) ? "\n" : "");
1056 ast_cli(a->fd, "\n");
1060 int port = misdn_cfg_get_next_port(0);
1061 for (; port > 0; port = misdn_cfg_get_next_port(port)) {
1062 ast_cli(a->fd, "\n[PORT %d]\n", port);
1063 for (elem = MISDN_CFG_FIRST + 1, linebreak = 1; elem < MISDN_CFG_LAST; elem++, linebreak++) {
1064 misdn_cfg_get_config_string(port, elem, buffer, sizeof(buffer));
1065 ast_cli(a->fd, "%-36s%s", buffer, !(linebreak % 2) ? "\n" : "");
1067 ast_cli(a->fd, "\n");
1072 if (misdn_cfg_is_port_valid(onlyport)) {
1073 ast_cli(a->fd, "[PORT %d]\n", onlyport);
1074 for (elem = MISDN_CFG_FIRST + 1, linebreak = 1; elem < MISDN_CFG_LAST; elem++, linebreak++) {
1075 misdn_cfg_get_config_string(onlyport, elem, buffer, sizeof(buffer));
1076 ast_cli(a->fd, "%-36s%s", buffer, !(linebreak % 2) ? "\n" : "");
1078 ast_cli(a->fd, "\n");
1080 ast_cli(a->fd, "Port %d is not active!\n", onlyport);
1087 struct state_struct {
1088 enum misdn_chan_state state;
1092 static struct state_struct state_array[] = {
1093 {MISDN_NOTHING,"NOTHING"}, /* at beginning */
1094 {MISDN_WAITING4DIGS,"WAITING4DIGS"}, /* when waiting for infos */
1095 {MISDN_EXTCANTMATCH,"EXTCANTMATCH"}, /* when asterisk couldnt match our ext */
1096 {MISDN_INCOMING_SETUP,"INCOMING SETUP"}, /* when pbx_start */
1097 {MISDN_DIALING,"DIALING"}, /* when pbx_start */
1098 {MISDN_PROGRESS,"PROGRESS"}, /* when pbx_start */
1099 {MISDN_PROCEEDING,"PROCEEDING"}, /* when pbx_start */
1100 {MISDN_CALLING,"CALLING"}, /* when misdn_call is called */
1101 {MISDN_CALLING_ACKNOWLEDGE,"CALLING_ACKNOWLEDGE"}, /* when misdn_call is called */
1102 {MISDN_ALERTING,"ALERTING"}, /* when Alerting */
1103 {MISDN_BUSY,"BUSY"}, /* when BUSY */
1104 {MISDN_CONNECTED,"CONNECTED"}, /* when connected */
1105 {MISDN_PRECONNECTED,"PRECONNECTED"}, /* when connected */
1106 {MISDN_DISCONNECTED,"DISCONNECTED"}, /* when connected */
1107 {MISDN_RELEASED,"RELEASED"}, /* when connected */
1108 {MISDN_BRIDGED,"BRIDGED"}, /* when bridged */
1109 {MISDN_CLEANING,"CLEANING"}, /* when hangup from * but we were connected before */
1110 {MISDN_HUNGUP_FROM_MISDN,"HUNGUP_FROM_MISDN"}, /* when DISCONNECT/RELEASE/REL_COMP cam from misdn */
1111 {MISDN_HOLDED,"HOLDED"}, /* when DISCONNECT/RELEASE/REL_COMP cam from misdn */
1112 {MISDN_HOLD_DISCONNECT,"HOLD_DISCONNECT"}, /* when DISCONNECT/RELEASE/REL_COMP cam from misdn */
1113 {MISDN_HUNGUP_FROM_AST,"HUNGUP_FROM_AST"} /* when DISCONNECT/RELEASE/REL_COMP came out of */
1117 static const char *misdn_get_ch_state(struct chan_list *p)
1120 static char state[8];
1122 if( !p) return NULL;
1124 for (i = 0; i < sizeof(state_array) / sizeof(struct state_struct); i++) {
1125 if (state_array[i].state == p->state)
1126 return state_array[i].txt;
1129 snprintf(state, sizeof(state), "%d", p->state) ;
1136 static void reload_config(void)
1140 if (!g_config_initialized) {
1141 ast_log(LOG_WARNING, "chan_misdn is not initialized properly, still reloading ?\n");
1147 misdn_cfg_update_ptp();
1148 misdn_cfg_get(0, MISDN_GEN_TRACEFILE, global_tracefile, sizeof(global_tracefile));
1149 misdn_cfg_get(0, MISDN_GEN_DEBUG, &cfg_debug, sizeof(cfg_debug));
1151 for (i = 0; i <= max_ports; i++) {
1152 misdn_debug[i] = cfg_debug;
1153 misdn_debug_only[i] = 0;
1157 static char *handle_cli_misdn_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1161 e->command = "misdn reload";
1163 "Usage: misdn reload\n"
1164 " Reload internal mISDN config, read from the config\n"
1172 return CLI_SHOWUSAGE;
1174 ast_cli(a->fd, "Reloading mISDN configuration\n");
1179 static void print_bc_info (int fd, struct chan_list *help, struct misdn_bchannel *bc)
1181 struct ast_channel *ast = help->ast;
1183 "* Pid:%d Prt:%d Ch:%d Mode:%s Org:%s dad:%s oad:%s rad:%s ctx:%s state:%s\n",
1185 bc->pid, bc->port, bc->channel,
1186 bc->nt ? "NT" : "TE",
1187 help->originator == ORG_AST ? "*" : "I",
1188 ast ? ast->exten : NULL,
1189 ast ? ast->cid.cid_num : NULL,
1191 ast ? ast->context : NULL,
1192 misdn_get_ch_state(help)
1194 if (misdn_debug[bc->port] > 0)
1196 " --> astname: %s\n"
1197 " --> ch_l3id: %x\n"
1198 " --> ch_addr: %x\n"
1199 " --> bc_addr: %x\n"
1200 " --> bc_l3id: %x\n"
1201 " --> display: %s\n"
1202 " --> activated: %d\n"
1204 " --> capability: %s\n"
1206 " --> pipeline: %s\n"
1208 " --> echo_cancel: %d\n"
1210 " --> notone : rx %d tx:%d\n"
1211 " --> bc_hold: %d\n",
1216 bc ? bc->l3_id : -1,
1220 bc_state2str(bc->bc_state),
1221 bearer2str(bc->capability),
1228 help->norxtone, help->notxtone,
1234 static char *handle_cli_misdn_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1236 struct chan_list *help = NULL;
1240 e->command = "misdn show channels";
1242 "Usage: misdn show channels\n"
1243 " Show the internal mISDN channel list\n";
1250 return CLI_SHOWUSAGE;
1254 ast_cli(a->fd, "Channel List: %p\n", cl_te);
1256 for (; help; help = help->next) {
1257 struct misdn_bchannel *bc = help->bc;
1258 struct ast_channel *ast = help->ast;
1261 ast_cli(a->fd, "chan_list obj. with l3id:%x has no bc and no ast Leg\n", help->l3id);
1264 ast_cli(a->fd, "bc with pid:%d has no Ast Leg\n", bc->pid);
1268 if (misdn_debug[0] > 2)
1269 ast_cli(a->fd, "Bc:%p Ast:%p\n", bc, ast);
1271 print_bc_info(a->fd, help, bc);
1273 if (help->state == MISDN_HOLDED) {
1274 ast_cli(a->fd, "ITS A HOLDED BC:\n");
1275 ast_cli(a->fd, " --> l3_id: %x\n"
1276 " --> dad:%s oad:%s\n"
1277 " --> hold_port: %d\n"
1278 " --> hold_channel: %d\n",
1282 help->hold_info.port,
1283 help->hold_info.channel
1286 ast_cli(a->fd, "* Channel in unknown STATE !!! Exten:%s, Callerid:%s\n", ast->exten, ast->cid.cid_num);
1291 misdn_dump_chanlist();
1296 static char *handle_cli_misdn_show_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1298 struct chan_list *help = NULL;
1302 e->command = "misdn show channel";
1304 "Usage: misdn show channel <channel>\n"
1305 " Show an internal mISDN channel\n.";
1308 return complete_ch(a);
1312 return CLI_SHOWUSAGE;
1316 for (; help; help = help->next) {
1317 struct misdn_bchannel *bc = help->bc;
1318 struct ast_channel *ast = help->ast;
1321 if (!strcasecmp(ast->name, a->argv[3])) {
1322 print_bc_info(a->fd, help, bc);
1334 static char *handle_cli_misdn_set_tics(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1338 e->command = "misdn set tics";
1340 "Usage: misdn set tics <value>\n";
1347 return CLI_SHOWUSAGE;
1349 MAXTICS = atoi(a->argv[3]);
1354 static char *handle_cli_misdn_show_stacks(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1360 e->command = "misdn show stacks";
1362 "Usage: misdn show stacks\n"
1363 " Show internal mISDN stack_list.\n";
1370 return CLI_SHOWUSAGE;
1372 ast_cli(a->fd, "BEGIN STACK_LIST:\n");
1373 for (port = misdn_cfg_get_next_port(0); port > 0;
1374 port = misdn_cfg_get_next_port(port)) {
1376 get_show_stack_details(port, buf);
1377 ast_cli(a->fd," %s Debug:%d%s\n", buf, misdn_debug[port], misdn_debug_only[port] ? "(only)" : "");
1383 static char *handle_cli_misdn_show_ports_stats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1389 e->command = "misdn show ports stats";
1391 "Usage: misdn show ports stats\n"
1392 " Show mISDNs channel's call statistics per port.\n";
1399 return CLI_SHOWUSAGE;
1401 ast_cli(a->fd, "Port\tin_calls\tout_calls\n");
1402 for (port = misdn_cfg_get_next_port(0); port > 0;
1403 port = misdn_cfg_get_next_port(port)) {
1404 ast_cli(a->fd, "%d\t%d\t\t%d\n", port, misdn_in_calls[port], misdn_out_calls[port]);
1406 ast_cli(a->fd, "\n");
1411 static char *handle_cli_misdn_show_port(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1418 e->command = "misdn show port";
1420 "Usage: misdn show port <port>\n"
1421 " Show detailed information for given port.\n";
1428 return CLI_SHOWUSAGE;
1430 port = atoi(a->argv[3]);
1432 ast_cli(a->fd, "BEGIN STACK_LIST:\n");
1433 get_show_stack_details(port, buf);
1434 ast_cli(a->fd, " %s Debug:%d%s\n", buf, misdn_debug[port], misdn_debug_only[port] ? "(only)" : "");
1439 static char *handle_cli_misdn_send_facility(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1443 struct chan_list *tmp;
1446 struct misdn_bchannel dummy, *bc=&dummy;
1450 e->command = "misdn send facility";
1451 e->usage = "Usage: misdn send facility <type> <channel|port> \"<args>\" \n"
1452 "\t type is one of:\n"
1453 "\t - calldeflect\n"
1455 "\t - CFDeactivate\n";
1459 return complete_ch(a);
1463 return CLI_SHOWUSAGE;
1465 if (strstr(a->argv[3], "calldeflect")) {
1467 ast_verbose("calldeflect requires 1 arg: ToNumber\n\n");
1470 channame = a->argv[4];
1473 ast_verbose("Sending Calldeflection (%s) to %s\n", nr, channame);
1474 tmp = get_chan_by_ast_name(channame);
1476 ast_verbose("Sending CD with nr %s to %s failed: Channel does not exist.\n",nr, channame);
1480 if (strlen(nr) >= 15) {
1481 ast_verbose("Sending CD with nr %s to %s failed: Number too long (up to 15 digits are allowed).\n",nr, channame);
1484 tmp->bc->fac_out.Function = Fac_CD;
1485 ast_copy_string((char *)tmp->bc->fac_out.u.CDeflection.DeflectedToNumber, nr, sizeof(tmp->bc->fac_out.u.CDeflection.DeflectedToNumber));
1486 misdn_lib_send_event(tmp->bc, EVENT_FACILITY);
1487 } else if (strstr(a->argv[3],"CFActivate")) {
1489 ast_verbose("CFActivate requires 2 args: 1.FromNumber, 2.ToNumber\n\n");
1492 port = atoi(a->argv[4]);
1493 served_nr = a->argv[5];
1496 misdn_make_dummy(bc, port, 0, misdn_lib_port_is_nt(port), 0);
1498 ast_verbose("Sending CFActivate Port:(%d) FromNr. (%s) to Nr. (%s)\n", port, served_nr, nr);
1500 bc->fac_out.Function = Fac_CFActivate;
1501 bc->fac_out.u.CFActivate.BasicService = 0; //All Services
1502 bc->fac_out.u.CFActivate.Procedure = 0; //Unconditional
1503 ast_copy_string((char *)bc->fac_out.u.CFActivate.ServedUserNumber, served_nr, sizeof(bc->fac_out.u.CFActivate.ServedUserNumber));
1504 ast_copy_string((char *)bc->fac_out.u.CFActivate.ForwardedToNumber, nr, sizeof(bc->fac_out.u.CFActivate.ForwardedToNumber));
1506 misdn_lib_send_event(bc, EVENT_FACILITY);
1507 } else if (strstr(a->argv[3],"CFDeactivate")) {
1510 ast_verbose("CFActivate requires 1 arg: FromNumber\n\n");
1513 port = atoi(a->argv[4]);
1514 served_nr = a->argv[5];
1516 misdn_make_dummy(bc, port, 0, misdn_lib_port_is_nt(port), 0);
1517 ast_verbose("Sending CFDeactivate Port:(%d) FromNr. (%s)\n", port, served_nr);
1519 bc->fac_out.Function = Fac_CFDeactivate;
1520 bc->fac_out.u.CFDeactivate.BasicService = 0; //All Services
1521 bc->fac_out.u.CFDeactivate.Procedure = 0; //Unconditional
1523 ast_copy_string((char *)bc->fac_out.u.CFActivate.ServedUserNumber, served_nr, sizeof(bc->fac_out.u.CFActivate.ServedUserNumber));
1524 misdn_lib_send_event(bc, EVENT_FACILITY);
1530 static char *handle_cli_misdn_send_restart(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1534 e->command = "misdn send restart";
1536 "Usage: misdn send restart [port [channel]]\n"
1537 " Send a restart for every bchannel on the given port.\n";
1543 if (a->argc < 4 || a->argc > 5)
1544 return CLI_SHOWUSAGE;
1547 misdn_lib_send_restart(atoi(a->argv[3]), atoi(a->argv[4]));
1549 misdn_lib_send_restart(atoi(a->argv[3]), -1);
1554 static char *handle_cli_misdn_send_digit(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1558 struct chan_list *tmp;
1563 e->command = "misdn send digit";
1565 "Usage: misdn send digit <channel> \"<msg>\" \n"
1566 " Send <digit> to <channel> as DTMF Tone\n"
1567 " when channel is a mISDN channel\n";
1570 return complete_ch(a);
1574 return CLI_SHOWUSAGE;
1576 channame = a->argv[3];
1578 msglen = strlen(msg);
1580 ast_cli(a->fd, "Sending %s to %s\n", msg, channame);
1582 tmp = get_chan_by_ast_name(channame);
1584 ast_cli(a->fd, "Sending %s to %s failed Channel does not exist\n", msg, channame);
1588 for (i = 0; i < msglen; i++) {
1589 ast_cli(a->fd, "Sending: %c\n", msg[i]);
1590 send_digit_to_chan(tmp, msg[i]);
1591 /* res = ast_safe_sleep(tmp->ast, 250); */
1593 /* res = ast_waitfor(tmp->ast,100); */
1596 ast_dtmf_stream(tmp->ast, NULL, msg, 250);
1602 static char *handle_cli_misdn_toggle_echocancel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1605 struct chan_list *tmp;
1609 e->command = "misdn toggle echocancel";
1611 "Usage: misdn toggle echocancel <channel>\n"
1612 " Toggle EchoCancel on mISDN Channel.\n";
1615 return complete_ch(a);
1619 return CLI_SHOWUSAGE;
1621 channame = a->argv[3];
1623 ast_cli(a->fd, "Toggling EchoCancel on %s\n", channame);
1625 tmp = get_chan_by_ast_name(channame);
1627 ast_cli(a->fd, "Toggling EchoCancel %s failed Channel does not exist\n", channame);
1631 tmp->toggle_ec = tmp->toggle_ec?0:1;
1633 if (tmp->toggle_ec) {
1635 update_pipeline_config(tmp->bc);
1637 update_ec_config(tmp->bc);
1639 manager_ec_enable(tmp->bc);
1641 manager_ec_disable(tmp->bc);
1647 static char *handle_cli_misdn_send_display(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1651 struct chan_list *tmp;
1655 e->command = "misdn send display";
1657 "Usage: misdn send display <channel> \"<msg>\" \n"
1658 " Send <msg> to <channel> as Display Message\n"
1659 " when channel is a mISDN channel\n";
1662 return complete_ch(a);
1666 return CLI_SHOWUSAGE;
1668 channame = a->argv[3];
1671 ast_cli(a->fd, "Sending %s to %s\n", msg, channame);
1672 tmp = get_chan_by_ast_name(channame);
1674 if (tmp && tmp->bc) {
1675 ast_copy_string(tmp->bc->display, msg, sizeof(tmp->bc->display));
1676 misdn_lib_send_event(tmp->bc, EVENT_INFORMATION);
1678 ast_cli(a->fd, "No such channel %s\n", channame);
1685 static char *complete_ch(struct ast_cli_args *a)
1687 return ast_complete_channels(a->line, a->word, a->pos, a->n, 3);
1690 static char *complete_debug_port (struct ast_cli_args *a)
1697 if (a->word[0] == 'p')
1698 return ast_strdup("port");
1699 else if (a->word[0] == 'o')
1700 return ast_strdup("only");
1703 if (a->word[0] == 'o')
1704 return ast_strdup("only");
1710 static char *complete_show_config(struct ast_cli_args *a)
1712 char buffer[BUFFERSIZE];
1713 enum misdn_cfg_elements elem;
1714 int wordlen = strlen(a->word);
1720 if ((!strncmp(a->word, "description", wordlen)) && (++which > a->n))
1721 return ast_strdup("description");
1722 if ((!strncmp(a->word, "descriptions", wordlen)) && (++which > a->n))
1723 return ast_strdup("descriptions");
1724 if ((!strncmp(a->word, "0", wordlen)) && (++which > a->n))
1725 return ast_strdup("0");
1726 while ((port = misdn_cfg_get_next_port(port)) != -1) {
1727 snprintf(buffer, sizeof(buffer), "%d", port);
1728 if ((!strncmp(a->word, buffer, wordlen)) && (++which > a->n)) {
1729 return ast_strdup(buffer);
1734 if (strstr(a->line, "description ")) {
1735 for (elem = MISDN_CFG_FIRST + 1; elem < MISDN_GEN_LAST; ++elem) {
1736 if ((elem == MISDN_CFG_LAST) || (elem == MISDN_GEN_FIRST))
1738 misdn_cfg_get_name(elem, buffer, sizeof(buffer));
1739 if (!wordlen || !strncmp(a->word, buffer, wordlen)) {
1741 return ast_strdup(buffer);
1744 } else if (strstr(a->line, "descriptions ")) {
1745 if ((!wordlen || !strncmp(a->word, "general", wordlen)) && (++which > a->n))
1746 return ast_strdup("general");
1747 if ((!wordlen || !strncmp(a->word, "ports", wordlen)) && (++which > a->n))
1748 return ast_strdup("ports");
1755 static struct ast_cli_entry chan_misdn_clis[] = {
1756 AST_CLI_DEFINE(handle_cli_misdn_port_block, "Block the given port"),
1757 AST_CLI_DEFINE(handle_cli_misdn_port_down, "Try to deacivate the L1 on the given port"),
1758 AST_CLI_DEFINE(handle_cli_misdn_port_unblock, "Unblock the given port"),
1759 AST_CLI_DEFINE(handle_cli_misdn_port_up, "Try to establish L1 on the given port"),
1760 AST_CLI_DEFINE(handle_cli_misdn_reload, "Reload internal mISDN config, read from the config file"),
1761 AST_CLI_DEFINE(handle_cli_misdn_restart_pid, "Restart the given pid"),
1762 AST_CLI_DEFINE(handle_cli_misdn_restart_port, "Restart the given port"),
1763 AST_CLI_DEFINE(handle_cli_misdn_show_channel, "Show an internal mISDN channel"),
1764 AST_CLI_DEFINE(handle_cli_misdn_show_channels, "Show the internal mISDN channel list"),
1765 AST_CLI_DEFINE(handle_cli_misdn_show_config, "Show internal mISDN config, read from the config file"),
1766 AST_CLI_DEFINE(handle_cli_misdn_show_port, "Show detailed information for given port"),
1767 AST_CLI_DEFINE(handle_cli_misdn_show_ports_stats, "Show mISDNs channel's call statistics per port"),
1768 AST_CLI_DEFINE(handle_cli_misdn_show_stacks, "Show internal mISDN stack_list"),
1769 AST_CLI_DEFINE(handle_cli_misdn_send_facility, "Sends a Facility Message to the mISDN Channel"),
1770 AST_CLI_DEFINE(handle_cli_misdn_send_digit, "Send DTMF digit to mISDN Channel"),
1771 AST_CLI_DEFINE(handle_cli_misdn_send_display, "Send Text to mISDN Channel"),
1772 AST_CLI_DEFINE(handle_cli_misdn_send_restart, "Send a restart for every bchannel on the given port"),
1773 AST_CLI_DEFINE(handle_cli_misdn_set_crypt_debug, "Set CryptDebuglevel of chan_misdn, at the moment, level={1,2}"),
1774 AST_CLI_DEFINE(handle_cli_misdn_set_debug, "Set Debuglevel of chan_misdn"),
1775 AST_CLI_DEFINE(handle_cli_misdn_set_tics, "???"),
1776 AST_CLI_DEFINE(handle_cli_misdn_toggle_echocancel, "Toggle EchoCancel on mISDN Channel"),
1779 static int update_config(struct chan_list *ch, int orig)
1781 struct ast_channel *ast;
1782 struct misdn_bchannel *bc;
1787 ast_log(LOG_WARNING, "Cannot configure without chanlist\n");
1793 if (! ast || ! bc) {
1794 ast_log(LOG_WARNING, "Cannot configure without ast || bc\n");
1800 chan_misdn_log(7, port, "update_config: Getting Config\n");
1802 misdn_cfg_get(port, MISDN_CFG_HDLC, &hdlc, sizeof(int));
1805 switch (bc->capability) {
1806 case INFO_CAPABILITY_DIGITAL_UNRESTRICTED:
1807 case INFO_CAPABILITY_DIGITAL_RESTRICTED:
1808 chan_misdn_log(1, bc->port, " --> CONF HDLC\n");
1815 misdn_cfg_get(port, MISDN_CFG_PRES, &pres, sizeof(pres));
1816 misdn_cfg_get(port, MISDN_CFG_SCREEN, &screen, sizeof(screen));
1817 chan_misdn_log(2, port, " --> pres: %d screen: %d\n", pres, screen);
1819 if ( (pres + screen) < 0 ) {
1821 chan_misdn_log(2, port, " --> pres: %x\n", ast->cid.cid_pres);
1823 switch (ast->cid.cid_pres & 0x60) {
1825 case AST_PRES_RESTRICTED:
1827 chan_misdn_log(2, port, " --> PRES: Restricted (0x1)\n");
1829 case AST_PRES_UNAVAILABLE:
1831 chan_misdn_log(2, port, " --> PRES: Unavailable (0x2)\n");
1835 chan_misdn_log(2, port, " --> PRES: Allowed (0x0)\n");
1838 switch (ast->cid.cid_pres & 0x3) {
1840 case AST_PRES_USER_NUMBER_UNSCREENED:
1842 chan_misdn_log(2, port, " --> SCREEN: Unscreened (0x0)\n");
1844 case AST_PRES_USER_NUMBER_PASSED_SCREEN:
1846 chan_misdn_log(2, port, " --> SCREEN: Passed Screen (0x1)\n");
1848 case AST_PRES_USER_NUMBER_FAILED_SCREEN:
1850 chan_misdn_log(2, port, " --> SCREEN: Failed Screen (0x2)\n");
1852 case AST_PRES_NETWORK_NUMBER:
1854 chan_misdn_log(2, port, " --> SCREEN: Network Nr. (0x3)\n");
1858 chan_misdn_log(2, port, " --> SCREEN: Unscreened (0x0)\n");
1861 bc->screen = screen;
1869 static void config_jitterbuffer(struct chan_list *ch)
1871 struct misdn_bchannel *bc = ch->bc;
1872 int len = ch->jb_len, threshold = ch->jb_upper_threshold;
1874 chan_misdn_log(5, bc->port, "config_jb: Called\n");
1877 chan_misdn_log(1, bc->port, "config_jb: Deactivating Jitterbuffer\n");
1880 if (len <= 100 || len > 8000) {
1881 chan_misdn_log(0, bc->port, "config_jb: Jitterbuffer out of Bounds, setting to 1000\n");
1885 if ( threshold > len ) {
1886 chan_misdn_log(0, bc->port, "config_jb: Jitterbuffer Threshold > Jitterbuffer setting to Jitterbuffer -1\n");
1890 cb_log(0, bc->port, "config_jb: We've got a Jitterbuffer Already on this port.\n");
1891 misdn_jb_destroy(ch->jb);
1895 ch->jb=misdn_jb_init(len, threshold);
1903 void debug_numplan(int port, int numplan, char *type)
1906 case NUMPLAN_INTERNATIONAL:
1907 chan_misdn_log(2, port, " --> %s: International\n", type);
1909 case NUMPLAN_NATIONAL:
1910 chan_misdn_log(2, port, " --> %s: National\n", type);
1912 case NUMPLAN_SUBSCRIBER:
1913 chan_misdn_log(2, port, " --> %s: Subscriber\n", type);
1915 case NUMPLAN_UNKNOWN:
1916 chan_misdn_log(2, port, " --> %s: Unknown\n", type);
1918 /* Maybe we should cut off the prefix if present ? */
1920 chan_misdn_log(0, port, " --> !!!! Wrong dialplan setting, please see the misdn.conf sample file\n ");
1927 static int update_pipeline_config(struct misdn_bchannel *bc)
1931 misdn_cfg_get(bc->port, MISDN_CFG_PIPELINE, bc->pipeline, sizeof(bc->pipeline));
1936 misdn_cfg_get(bc->port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(ec));
1938 ast_copy_string(bc->pipeline, "mg2ec", sizeof(bc->pipeline));
1940 snprintf(bc->pipeline, sizeof(bc->pipeline), "mg2ec(deftaps=%d)", ec);
1945 static int update_ec_config(struct misdn_bchannel *bc)
1948 int port = bc->port;
1950 misdn_cfg_get(port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(ec));
1954 } else if (ec > 1) {
1956 bc->ec_deftaps = ec;
1964 static int read_config(struct chan_list *ch, int orig)
1966 struct ast_channel *ast;
1967 struct misdn_bchannel *bc;
1969 char lang[BUFFERSIZE + 1], localmusicclass[BUFFERSIZE + 1], faxdetect[BUFFERSIZE + 1];
1970 char buf[256], buf2[256];
1974 ast_log(LOG_WARNING, "Cannot configure without chanlist\n");
1980 if (! ast || ! bc) {
1981 ast_log(LOG_WARNING, "Cannot configure without ast || bc\n");
1986 chan_misdn_log(1, port, "read_config: Getting Config\n");
1988 misdn_cfg_get(port, MISDN_CFG_LANGUAGE, lang, sizeof(lang));
1989 ast_string_field_set(ast, language, lang);
1991 misdn_cfg_get(port, MISDN_CFG_MUSICCLASS, localmusicclass, sizeof(localmusicclass));
1992 ast_string_field_set(ast, musicclass, localmusicclass);
1994 misdn_cfg_get(port, MISDN_CFG_TXGAIN, &bc->txgain, sizeof(bc->txgain));
1995 misdn_cfg_get(port, MISDN_CFG_RXGAIN, &bc->rxgain, sizeof(bc->rxgain));
1997 misdn_cfg_get(port, MISDN_CFG_INCOMING_EARLY_AUDIO, &ch->incoming_early_audio, sizeof(ch->incoming_early_audio));
1999 misdn_cfg_get(port, MISDN_CFG_SENDDTMF, &bc->send_dtmf, sizeof(bc->send_dtmf));
2001 misdn_cfg_get( port, MISDN_CFG_ASTDTMF, &ch->ast_dsp, sizeof(int));
2007 misdn_cfg_get(port, MISDN_CFG_NEED_MORE_INFOS, &bc->need_more_infos, sizeof(bc->need_more_infos));
2008 misdn_cfg_get(port, MISDN_CFG_NTTIMEOUT, &ch->nttimeout, sizeof(ch->nttimeout));
2010 misdn_cfg_get(port, MISDN_CFG_NOAUTORESPOND_ON_SETUP, &ch->noautorespond_on_setup, sizeof(ch->noautorespond_on_setup));
2012 misdn_cfg_get(port, MISDN_CFG_FAR_ALERTING, &ch->far_alerting, sizeof(ch->far_alerting));
2014 misdn_cfg_get(port, MISDN_CFG_ALLOWED_BEARERS, &ch->allowed_bearers, sizeof(ch->allowed_bearers));
2016 misdn_cfg_get(port, MISDN_CFG_FAXDETECT, faxdetect, sizeof(faxdetect));
2018 misdn_cfg_get(port, MISDN_CFG_HDLC, &hdlc, sizeof(hdlc));
2021 switch (bc->capability) {
2022 case INFO_CAPABILITY_DIGITAL_UNRESTRICTED:
2023 case INFO_CAPABILITY_DIGITAL_RESTRICTED:
2024 chan_misdn_log(1, bc->port, " --> CONF HDLC\n");
2030 /*Initialize new Jitterbuffer*/
2031 misdn_cfg_get(port, MISDN_CFG_JITTERBUFFER, &ch->jb_len, sizeof(ch->jb_len));
2032 misdn_cfg_get(port, MISDN_CFG_JITTERBUFFER_UPPER_THRESHOLD, &ch->jb_upper_threshold, sizeof(ch->jb_upper_threshold));
2034 config_jitterbuffer(ch);
2036 misdn_cfg_get(bc->port, MISDN_CFG_CONTEXT, ch->context, sizeof(ch->context));
2038 ast_copy_string(ast->context, ch->context, sizeof(ast->context));
2041 update_pipeline_config(bc);
2043 update_ec_config(bc);
2046 misdn_cfg_get(bc->port, MISDN_CFG_EARLY_BCONNECT, &bc->early_bconnect, sizeof(bc->early_bconnect));
2048 misdn_cfg_get(port, MISDN_CFG_PICKUPGROUP, &pg, sizeof(pg));
2049 misdn_cfg_get(port, MISDN_CFG_CALLGROUP, &cg, sizeof(cg));
2051 chan_misdn_log(5, port, " --> * CallGrp:%s PickupGrp:%s\n", ast_print_group(buf, sizeof(buf), cg), ast_print_group(buf2, sizeof(buf2), pg));
2052 ast->pickupgroup = pg;
2053 ast->callgroup = cg;
2055 if (orig == ORG_AST) {
2056 char callerid[BUFFERSIZE + 1];
2058 misdn_cfg_get(port, MISDN_CFG_TE_CHOOSE_CHANNEL, &(bc->te_choose_channel), sizeof(bc->te_choose_channel));
2060 if (strstr(faxdetect, "outgoing") || strstr(faxdetect, "both")) {
2061 if (strstr(faxdetect, "nojump"))
2067 misdn_cfg_get(port, MISDN_CFG_CALLERID, callerid, sizeof(callerid));
2068 if ( ! ast_strlen_zero(callerid) ) {
2069 chan_misdn_log(1, port, " --> * Setting Cid to %s\n", callerid);
2070 ast_copy_string(bc->oad, callerid, sizeof(bc->oad));
2073 misdn_cfg_get(port, MISDN_CFG_DIALPLAN, &bc->dnumplan, sizeof(bc->dnumplan));
2074 misdn_cfg_get(port, MISDN_CFG_LOCALDIALPLAN, &bc->onumplan, sizeof(bc->onumplan));
2075 misdn_cfg_get(port, MISDN_CFG_CPNDIALPLAN, &bc->cpnnumplan, sizeof(bc->cpnnumplan));
2076 debug_numplan(port, bc->dnumplan, "TON");
2077 debug_numplan(port, bc->onumplan, "LTON");
2078 debug_numplan(port, bc->cpnnumplan, "CTON");
2080 ch->overlap_dial = 0;
2081 } else { /** ORIGINATOR MISDN **/
2082 char prefix[BUFFERSIZE + 1] = "";
2084 if (strstr(faxdetect, "incoming") || strstr(faxdetect, "both")) {
2085 if (strstr(faxdetect, "nojump"))
2091 misdn_cfg_get(port, MISDN_CFG_CPNDIALPLAN, &bc->cpnnumplan, sizeof(bc->cpnnumplan));
2092 debug_numplan(port, bc->cpnnumplan, "CTON");
2094 switch (bc->onumplan) {
2095 case NUMPLAN_INTERNATIONAL:
2096 misdn_cfg_get(bc->port, MISDN_CFG_INTERNATPREFIX, prefix, sizeof(prefix));
2099 case NUMPLAN_NATIONAL:
2100 misdn_cfg_get(bc->port, MISDN_CFG_NATPREFIX, prefix, sizeof(prefix));
2106 ast_copy_string(buf, bc->oad, sizeof(buf));
2107 snprintf(bc->oad, sizeof(bc->oad), "%s%s", prefix, buf);
2109 if (!ast_strlen_zero(bc->dad)) {
2110 ast_copy_string(bc->orig_dad, bc->dad, sizeof(bc->orig_dad));
2113 if ( ast_strlen_zero(bc->dad) && !ast_strlen_zero(bc->keypad)) {
2114 ast_copy_string(bc->dad, bc->keypad, sizeof(bc->dad));
2119 switch (bc->dnumplan) {
2120 case NUMPLAN_INTERNATIONAL:
2121 misdn_cfg_get(bc->port, MISDN_CFG_INTERNATPREFIX, prefix, sizeof(prefix));
2123 case NUMPLAN_NATIONAL:
2124 misdn_cfg_get(bc->port, MISDN_CFG_NATPREFIX, prefix, sizeof(prefix));
2130 ast_copy_string(buf, bc->dad, sizeof(buf));
2131 snprintf(bc->dad, sizeof(bc->dad), "%s%s", prefix, buf);
2133 if (strcmp(bc->dad, ast->exten)) {
2134 ast_copy_string(ast->exten, bc->dad, sizeof(ast->exten));
2137 ast_set_callerid(ast, bc->oad, NULL, bc->oad);
2139 if ( !ast_strlen_zero(bc->rad) ) {
2140 if (ast->cid.cid_rdnis)
2141 ast_free(ast->cid.cid_rdnis);
2142 ast->cid.cid_rdnis = ast_strdup(bc->rad);
2145 misdn_cfg_get(bc->port, MISDN_CFG_OVERLAP_DIAL, &ch->overlap_dial, sizeof(ch->overlap_dial));
2146 ast_mutex_init(&ch->overlap_tv_lock);
2147 } /* ORIG MISDN END */
2149 ch->overlap_dial_task = -1;
2151 if (ch->faxdetect || ch->ast_dsp) {
2152 misdn_cfg_get(port, MISDN_CFG_FAXDETECT_TIMEOUT, &ch->faxdetect_timeout, sizeof(ch->faxdetect_timeout));
2154 ch->dsp = ast_dsp_new();
2157 ast_dsp_set_features(ch->dsp, DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_FAX_DETECT);
2159 ast_dsp_set_features(ch->dsp, DSP_FEATURE_DIGIT_DETECT );
2162 ch->trans = ast_translator_build_path(AST_FORMAT_SLINEAR, AST_FORMAT_ALAW);
2165 /* AOCD initialization */
2166 bc->AOCDtype = Fac_None;
2172 /*****************************/
2173 /*** AST Indications Start ***/
2174 /*****************************/
2176 static int misdn_call(struct ast_channel *ast, char *dest, int timeout)
2182 struct chan_list *ch = MISDN_ASTERISK_TECH_PVT(ast);
2183 struct misdn_bchannel *newbc;
2184 char *opts = NULL, *ext, *tokb;
2185 char *dest_cp = ast_strdupa(dest);
2187 ext = strtok_r(dest_cp, "/", &tokb);
2190 ext = strtok_r(NULL, "/", &tokb);
2192 opts = strtok_r(NULL, "/", &tokb);
2194 chan_misdn_log(0, 0, "misdn_call: No Extension given!\n");
2200 ast_log(LOG_WARNING, " --> ! misdn_call called on ast_channel *ast where ast == NULL\n");
2204 if (((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) || !dest ) {
2205 ast_log(LOG_WARNING, " --> ! misdn_call called on %s, neither down nor reserved (or dest==NULL)\n", ast->name);
2206 ast->hangupcause = AST_CAUSE_NORMAL_TEMPORARY_FAILURE;
2207 ast_setstate(ast, AST_STATE_DOWN);
2212 ast_log(LOG_WARNING, " --> ! misdn_call called on %s, neither down nor reserved (or dest==NULL)\n", ast->name);
2213 ast->hangupcause = AST_CAUSE_NORMAL_TEMPORARY_FAILURE;
2214 ast_setstate(ast, AST_STATE_DOWN);
2221 ast_log(LOG_WARNING, " --> ! misdn_call called on %s, neither down nor reserved (or dest==NULL)\n", ast->name);
2222 ast->hangupcause = AST_CAUSE_NORMAL_TEMPORARY_FAILURE;
2223 ast_setstate(ast, AST_STATE_DOWN);
2229 if ((exceed = add_out_calls(port))) {
2231 snprintf(tmp, sizeof(tmp), "%d", exceed);
2232 pbx_builtin_setvar_helper(ast, "MAX_OVERFLOW", tmp);
2236 chan_misdn_log(1, port, "* CALL: %s\n", dest);
2238 chan_misdn_log(2, port, " --> * dad:%s tech:%s ctx:%s\n", ast->exten, ast->name, ast->context);
2240 chan_misdn_log(3, port, " --> * adding2newbc ext %s\n", ast->exten);
2242 ast_copy_string(ast->exten, ext, sizeof(ast->exten));
2243 ast_copy_string(newbc->dad, ext, sizeof(newbc->dad));
2246 ast_copy_string(newbc->rad, S_OR(ast->cid.cid_rdnis, ""), sizeof(newbc->rad));
2248 chan_misdn_log(3, port, " --> * adding2newbc callerid %s\n", ast->cid.cid_num);
2249 if (ast_strlen_zero(newbc->oad) && !ast_strlen_zero(ast->cid.cid_num)) {
2250 ast_copy_string(newbc->oad, ast->cid.cid_num, sizeof(newbc->oad));
2253 newbc->capability = ast->transfercapability;
2254 pbx_builtin_setvar_helper(ast, "TRANSFERCAPABILITY", ast_transfercapability2str(newbc->capability));
2255 if ( ast->transfercapability == INFO_CAPABILITY_DIGITAL_UNRESTRICTED) {
2256 chan_misdn_log(2, port, " --> * Call with flag Digital\n");
2259 /* update screening and presentation */
2260 update_config(ch, ORG_AST);
2262 /* fill in some ies from channel vary*/
2263 import_ch(ast, newbc, ch);
2265 /* Finally The Options Override Everything */
2267 misdn_set_opt_exec(ast, opts);
2269 chan_misdn_log(2, port, "NO OPTS GIVEN\n");
2271 /*check for bridging*/
2272 misdn_cfg_get(0, MISDN_GEN_BRIDGING, &bridging, sizeof(bridging));
2273 if (bridging && ch->other_ch) {
2275 chan_misdn_log(1, port, "Disabling EC (aka Pipeline) on both Sides\n");
2276 *ch->bc->pipeline = 0;
2277 *ch->other_ch->bc->pipeline = 0;
2279 chan_misdn_log(1, port, "Disabling EC on both Sides\n");
2280 ch->bc->ec_enable = 0;
2281 ch->other_ch->bc->ec_enable = 0;
2285 r = misdn_lib_send_event( newbc, EVENT_SETUP );
2287 /** we should have l3id after sending setup **/
2288 ch->l3id = newbc->l3_id;
2290 if ( r == -ENOCHAN ) {
2291 chan_misdn_log(0, port, " --> * Theres no Channel at the moment .. !\n");
2292 chan_misdn_log(1, port, " --> * SEND: State Down pid:%d\n", newbc ? newbc->pid : -1);
2293 ast->hangupcause = AST_CAUSE_NORMAL_CIRCUIT_CONGESTION;
2294 ast_setstate(ast, AST_STATE_DOWN);
2298 chan_misdn_log(2, port, " --> * SEND: State Dialing pid:%d\n", newbc ? newbc->pid : 1);
2300 ast_setstate(ast, AST_STATE_DIALING);
2301 ast->hangupcause = AST_CAUSE_NORMAL_CLEARING;
2306 ch->state = MISDN_CALLING;
2312 static int misdn_answer(struct ast_channel *ast)
2314 struct chan_list *p;
2317 if (!ast || ! (p = MISDN_ASTERISK_TECH_PVT(ast)) ) return -1;
2319 chan_misdn_log(1, p ? (p->bc ? p->bc->port : 0) : 0, "* ANSWER:\n");
2322 ast_log(LOG_WARNING, " --> Channel not connected ??\n");
2323 ast_queue_hangup(ast);
2327 chan_misdn_log(1, 0, " --> Got Answer, but theres no bc obj ??\n");
2329 ast_queue_hangup(ast);
2332 tmp = pbx_builtin_getvar_helper(p->ast, "CRYPT_KEY");
2334 if (!ast_strlen_zero(tmp)) {
2335 chan_misdn_log(1, p->bc->port, " --> Connection will be BF crypted\n");
2336 ast_copy_string(p->bc->crypt_key, tmp, sizeof(p->bc->crypt_key));
2338 chan_misdn_log(3, p->bc->port, " --> Connection is without BF encryption\n");
2341 tmp = pbx_builtin_getvar_helper(ast, "MISDN_DIGITAL_TRANS");
2342 if (!ast_strlen_zero(tmp) && ast_true(tmp)) {
2343 chan_misdn_log(1, p->bc->port, " --> Connection is transparent digital\n");
2346 p->bc->nojitter = 1;
2349 p->state = MISDN_CONNECTED;
2352 if ( ast_strlen_zero(p->bc->cad) ) {
2353 chan_misdn_log(2,p->bc->port," --> empty cad using dad\n");
2354 ast_copy_string(p->bc->cad, p->bc->dad, sizeof(p->bc->cad));
2357 misdn_lib_send_event( p->bc, EVENT_CONNECT);
2363 static int misdn_digit_begin(struct ast_channel *chan, char digit)
2365 /* XXX Modify this callback to support Asterisk controlling the length of DTMF */
2369 static int misdn_digit_end(struct ast_channel *ast, char digit, unsigned int duration)
2371 struct chan_list *p;
2372 struct misdn_bchannel *bc;
2373 char buf[2] = { digit, 0 };
2375 if (!ast || ! (p=MISDN_ASTERISK_TECH_PVT(ast))) return -1;
2378 chan_misdn_log(1, bc ? bc->port : 0, "* IND : Digit %c\n", digit);
2381 ast_log(LOG_WARNING, " --> !! Got Digit Event withut having bchannel Object\n");
2385 switch (p->state ) {
2387 if (strlen(bc->infos_pending) < sizeof(bc->infos_pending) - 1)
2388 strncat(bc->infos_pending, buf, sizeof(bc->infos_pending) - strlen(bc->infos_pending) - 1);
2390 case MISDN_CALLING_ACKNOWLEDGE:
2391 ast_copy_string(bc->info_dad, buf, sizeof(bc->info_dad));
2392 if (strlen(bc->dad) < sizeof(bc->dad) - 1)
2393 strncat(bc->dad, buf, sizeof(bc->dad) - strlen(bc->dad) - 1);
2394 ast_copy_string(p->ast->exten, bc->dad, sizeof(p->ast->exten));
2395 misdn_lib_send_event( bc, EVENT_INFORMATION);
2398 /* Do not send Digits in CONNECTED State, when
2399 * the other side is too mISDN. */
2403 if ( bc->send_dtmf )
2404 send_digit_to_chan(p,digit);
2412 static int misdn_fixup(struct ast_channel *oldast, struct ast_channel *ast)
2414 struct chan_list *p;
2416 if (!ast || ! (p=MISDN_ASTERISK_TECH_PVT(ast) )) return -1;
2418 chan_misdn_log(1, p->bc ? p->bc->port : 0, "* IND: Got Fixup State:%s L3id:%x\n", misdn_get_ch_state(p), p->l3id);
2427 static int misdn_indication(struct ast_channel *ast, int cond, const void *data, size_t datalen)
2429 struct chan_list *p;
2431 if (!ast || ! (p=MISDN_ASTERISK_TECH_PVT(ast))) {
2432 ast_log(LOG_WARNING, "Returned -1 in misdn_indication\n");
2437 chan_misdn_log(1, 0, "* IND : Indication from %s\n", ast->exten);
2438 ast_log(LOG_WARNING, "Private Pointer but no bc ?\n");
2442 chan_misdn_log(5, p->bc->port, "* IND : Indication [%d] from %s\n", cond, ast->exten);
2445 case AST_CONTROL_BUSY:
2446 chan_misdn_log(1, p->bc->port, "* IND :\tbusy pid:%d\n", p->bc ? p->bc->pid : -1);
2447 ast_setstate(ast, AST_STATE_BUSY);
2449 p->bc->out_cause = AST_CAUSE_USER_BUSY;
2450 if (p->state != MISDN_CONNECTED) {
2452 misdn_lib_send_event( p->bc, EVENT_DISCONNECT);
2454 chan_misdn_log(-1, p->bc->port, " --> !! Got Busy in Connected State !?! ast:%s\n", ast->name);
2457 case AST_CONTROL_RING:
2458 chan_misdn_log(1, p->bc->port, "* IND :\tring pid:%d\n", p->bc ? p->bc->pid : -1);
2460 case AST_CONTROL_RINGING:
2461 chan_misdn_log(1, p->bc->port, "* IND :\tringing pid:%d\n", p->bc ? p->bc->pid : -1);
2463 case MISDN_ALERTING:
2464 chan_misdn_log(2, p->bc->port, " --> * IND :\tringing pid:%d but I was Ringing before, so ignoreing it\n", p->bc ? p->bc->pid : -1);
2466 case MISDN_CONNECTED:
2467 chan_misdn_log(2, p->bc->port, " --> * IND :\tringing pid:%d but Connected, so just send TONE_ALERTING without state changes \n", p->bc ? p->bc->pid : -1);
2470 p->state = MISDN_ALERTING;
2471 chan_misdn_log(2, p->bc->port, " --> * IND :\tringing pid:%d\n", p->bc ? p->bc->pid : -1);
2472 misdn_lib_send_event( p->bc, EVENT_ALERTING);
2474 if (p->other_ch && p->other_ch->bc) {
2475 if (misdn_inband_avail(p->other_ch->bc)) {
2476 chan_misdn_log(2, p->bc->port, " --> other End is mISDN and has inband info available\n");
2480 if (!p->other_ch->bc->nt) {
2481 chan_misdn_log(2, p->bc->port, " --> other End is mISDN TE so it has inband info for sure (?)\n");
2486 chan_misdn_log(3, p->bc->port, " --> * SEND: State Ring pid:%d\n", p->bc ? p->bc->pid : -1);
2487 ast_setstate(ast, AST_STATE_RINGING);
2489 if ( !p->bc->nt && (p->originator == ORG_MISDN) && !p->incoming_early_audio )
2490 chan_misdn_log(2, p->bc->port, " --> incoming_early_audio off\n");
2495 case AST_CONTROL_ANSWER:
2496 chan_misdn_log(1, p->bc->port, " --> * IND :\tanswer pid:%d\n", p->bc ? p->bc->pid : -1);
2499 case AST_CONTROL_TAKEOFFHOOK:
2500 chan_misdn_log(1, p->bc->port, " --> *\ttakeoffhook pid:%d\n", p->bc ? p->bc->pid : -1);
2502 case AST_CONTROL_OFFHOOK:
2503 chan_misdn_log(1, p->bc->port, " --> *\toffhook pid:%d\n", p->bc ? p->bc->pid : -1);
2505 case AST_CONTROL_FLASH:
2506 chan_misdn_log(1, p->bc->port, " --> *\tflash pid:%d\n", p->bc ? p->bc->pid : -1);
2508 case AST_CONTROL_PROGRESS:
2509 chan_misdn_log(1, p->bc->port, " --> * IND :\tprogress pid:%d\n", p->bc ? p->bc->pid : -1);
2510 misdn_lib_send_event( p->bc, EVENT_PROGRESS);
2512 case AST_CONTROL_PROCEEDING:
2513 chan_misdn_log(1, p->bc->port, " --> * IND :\tproceeding pid:%d\n", p->bc ? p->bc->pid : -1);
2514 misdn_lib_send_event( p->bc, EVENT_PROCEEDING);
2516 case AST_CONTROL_CONGESTION:
2517 chan_misdn_log(1, p->bc->port, " --> * IND :\tcongestion pid:%d\n", p->bc ? p->bc->pid : -1);
2519 p->bc->out_cause = AST_CAUSE_SWITCH_CONGESTION;
2521 misdn_lib_send_event( p->bc, EVENT_DISCONNECT);
2524 hanguptone_indicate(p);
2528 chan_misdn_log(1, p->bc->port, " --> * IND :\t-1! (stop indication) pid:%d\n", p->bc ? p->bc->pid : -1);
2532 if (p->state == MISDN_CONNECTED)
2535 case AST_CONTROL_HOLD:
2536 chan_misdn_log(1, p->bc->port, " --> *\tHOLD pid:%d\n", p->bc ? p->bc->pid : -1);
2538 case AST_CONTROL_UNHOLD:
2539 chan_misdn_log(1, p->bc->port, " --> *\tUNHOLD pid:%d\n", p->bc ? p->bc->pid : -1);
2542 chan_misdn_log(1, p->bc->port, " --> * Unknown Indication:%d pid:%d\n", cond, p->bc ? p->bc->pid : -1);
2548 static int misdn_hangup(struct ast_channel *ast)
2550 struct chan_list *p;
2551 struct misdn_bchannel *bc = NULL;
2552 const char *varcause = NULL;
2554 ast_debug(1, "misdn_hangup(%s)\n", ast->name);
2556 if (!ast || ! (p=MISDN_ASTERISK_TECH_PVT(ast) ) ) return -1;
2559 chan_misdn_log(3, 0, "misdn_hangup called, without chan_list obj.\n");
2566 const char *tmp=pbx_builtin_getvar_helper(ast,"MISDN_USERUSER");
2568 ast_log(LOG_NOTICE, "MISDN_USERUSER: %s\n", tmp);
2569 strcpy(bc->uu, tmp);
2570 bc->uulen=strlen(bc->uu);
2574 MISDN_ASTERISK_TECH_PVT(ast) = NULL;
2577 if (ast->_state == AST_STATE_RESERVED ||
2578 p->state == MISDN_NOTHING ||
2579 p->state == MISDN_HOLDED ||
2580 p->state == MISDN_HOLD_DISCONNECT ) {
2583 /* between request and call */
2584 ast_debug(1, "State Reserved (or nothing) => chanIsAvail\n");
2585 MISDN_ASTERISK_TECH_PVT(ast) = NULL;
2587 ast_mutex_lock(&release_lock);
2588 cl_dequeue_chan(&cl_te, p);
2592 ast_mutex_unlock(&release_lock);
2595 misdn_lib_release(bc);
2601 ast_log(LOG_WARNING, "Hangup with private but no bc ? state:%s l3id:%x\n", misdn_get_ch_state(p), p->l3id);
2607 p->need_queue_hangup = 0;
2614 bc->out_cause = ast->hangupcause ? ast->hangupcause : AST_CAUSE_NORMAL_CLEARING;
2616 if ( (varcause = pbx_builtin_getvar_helper(ast, "HANGUPCAUSE")) ||
2617 (varcause = pbx_builtin_getvar_helper(ast, "PRI_CAUSE"))) {
2618 int tmpcause = atoi(varcause);
2619 bc->out_cause = tmpcause ? tmpcause : AST_CAUSE_NORMAL_CLEARING;
2622 chan_misdn_log(1, bc->port, "* IND : HANGUP\tpid:%d ctx:%s dad:%s oad:%s State:%s\n", p->bc ? p->bc->pid : -1, ast->context, ast->exten, ast->cid.cid_num, misdn_get_ch_state(p));
2623 chan_misdn_log(3, bc->port, " --> l3id:%x\n", p->l3id);
2624 chan_misdn_log(3, bc->port, " --> cause:%d\n", bc->cause);
2625 chan_misdn_log(2, bc->port, " --> out_cause:%d\n", bc->out_cause);
2626 chan_misdn_log(2, bc->port, " --> state:%s\n", misdn_get_ch_state(p));
2629 case MISDN_INCOMING_SETUP:
2631 p->state = MISDN_CLEANING;
2632 /* This is the only place in misdn_hangup, where we
2633 * can call release_chan, else it might create lot's of trouble
2635 ast_log(LOG_NOTICE, "release channel, in CALLING/INCOMING_SETUP state.. no other events happened\n");
2637 misdn_lib_send_event( bc, EVENT_RELEASE_COMPLETE);
2642 hanguptone_indicate(p);
2644 p->state=MISDN_CLEANING;
2645 if (bc->need_disconnect)
2646 misdn_lib_send_event( bc, EVENT_DISCONNECT);
2648 case MISDN_CALLING_ACKNOWLEDGE:
2650 hanguptone_indicate(p);
2652 if (bc->need_disconnect)
2653 misdn_lib_send_event( bc, EVENT_DISCONNECT);
2656 case MISDN_ALERTING:
2657 case MISDN_PROGRESS:
2658 case MISDN_PROCEEDING:
2659 if (p->originator != ORG_AST)
2660 hanguptone_indicate(p);
2662 /*p->state=MISDN_CLEANING;*/
2663 if (bc->need_disconnect)
2664 misdn_lib_send_event( bc, EVENT_DISCONNECT);
2666 case MISDN_CONNECTED:
2667 case MISDN_PRECONNECTED:
2668 /* Alerting or Disconect */
2671 hanguptone_indicate(p);
2672 p->bc->progress_indicator = 8;
2674 if (bc->need_disconnect)
2675 misdn_lib_send_event( bc, EVENT_DISCONNECT);
2677 /*p->state=MISDN_CLEANING;*/
2679 case MISDN_DISCONNECTED:
2680 if (bc->need_release)
2681 misdn_lib_send_event( bc, EVENT_RELEASE);
2682 p->state = MISDN_CLEANING; /* MISDN_HUNGUP_FROM_AST; */
2685 case MISDN_RELEASED:
2686 case MISDN_CLEANING:
2687 p->state = MISDN_CLEANING;
2693 case MISDN_HOLD_DISCONNECT:
2694 /* need to send release here */
2695 chan_misdn_log(1, bc->port, " --> cause %d\n", bc->cause);
2696 chan_misdn_log(1, bc->port, " --> out_cause %d\n", bc->out_cause);
2699 if (bc->need_release)
2700 misdn_lib_send_event(bc, EVENT_RELEASE);
2701 p->state = MISDN_CLEANING;
2706 if (bc->need_release)
2707 misdn_lib_send_event(bc, EVENT_RELEASE);
2708 p->state = MISDN_CLEANING;
2710 if (bc->need_disconnect)
2711 misdn_lib_send_event(bc, EVENT_DISCONNECT);
2715 p->state = MISDN_CLEANING;
2717 chan_misdn_log(3, bc->port, " --> Channel: %s hanguped new state:%s\n", ast->name, misdn_get_ch_state(p));
2723 static struct ast_frame *process_ast_dsp(struct chan_list *tmp, struct ast_frame *frame)
2725 struct ast_frame *f,*f2;
2728 f2 = ast_translate(tmp->trans, frame, 0);
2729 f = ast_dsp_process(tmp->ast, tmp->dsp, f2);
2731 chan_misdn_log(0, tmp->bc->port, "No T-Path found\n");
2735 if (!f || (f->frametype != AST_FRAME_DTMF))
2738 ast_debug(1, "Detected inband DTMF digit: %c\n", f->subclass);
2740 if (tmp->faxdetect && (f->subclass == 'f')) {
2741 /* Fax tone -- Handle and return NULL */
2742 if (!tmp->faxhandled) {
2743 struct ast_channel *ast = tmp->ast;
2745 chan_misdn_log(0, tmp->bc->port, "Fax detected, preparing %s for fax transfer.\n", ast->name);
2746 tmp->bc->rxgain = 0;
2747 isdn_lib_update_rxgain(tmp->bc);
2748 tmp->bc->txgain = 0;
2749 isdn_lib_update_txgain(tmp->bc);
2751 *tmp->bc->pipeline = 0;
2753 tmp->bc->ec_enable = 0;
2755 isdn_lib_update_ec(tmp->bc);
2756 isdn_lib_stop_dtmf(tmp->bc);
2757 switch (tmp->faxdetect) {
2759 if (strcmp(ast->exten, "fax")) {
2761 char context_tmp[BUFFERSIZE];
2762 misdn_cfg_get(tmp->bc->port, MISDN_CFG_FAXDETECT_CONTEXT, &context_tmp, sizeof(context_tmp));
2763 context = ast_strlen_zero(context_tmp) ? (ast_strlen_zero(ast->macrocontext) ? ast->context : ast->macrocontext) : context_tmp;
2764 if (ast_exists_extension(ast, context, "fax", 1, ast->cid.cid_num)) {
2765 ast_verb(3, "Redirecting %s to fax extension (context:%s)\n", ast->name, context);
2766 /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
2767 pbx_builtin_setvar_helper(ast,"FAXEXTEN",ast->exten);
2768 if (ast_async_goto(ast, context, "fax", 1))
2769 ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast->name, context);
2771 ast_log(LOG_NOTICE, "Fax detected, but no fax extension ctx:%s exten:%s\n", context, ast->exten);
2773 ast_debug(1, "Already in a fax extension, not redirecting\n");
2777 ast_verb(3, "Not redirecting %s to fax extension, nojump is set.\n", ast->name);
2781 ast_debug(1, "Fax already handled\n");
2785 if (tmp->ast_dsp && (f->subclass != 'f')) {
2786 chan_misdn_log(2, tmp->bc->port, " --> * SEND: DTMF (AST_DSP) :%c\n", f->subclass);
2793 static struct ast_frame *misdn_read(struct ast_channel *ast)
2795 struct chan_list *tmp;
2801 chan_misdn_log(1, 0, "misdn_read called without ast\n");
2804 if (!(tmp = MISDN_ASTERISK_TECH_PVT(ast))) {
2805 chan_misdn_log(1, 0, "misdn_read called without ast->pvt\n");
2809 if (!tmp->bc && !(tmp->state == MISDN_HOLDED)) {
2810 chan_misdn_log(1, 0, "misdn_read called without bc\n");
2818 FD_SET(tmp->pipe[0],&rrfs);
2820 t=select(FD_SETSIZE,&rrfs,NULL, NULL,&tv);
2823 chan_misdn_log(3, tmp->bc->port, "read Select Timed out\n");
2828 chan_misdn_log(-1, tmp->bc->port, "Select Error (err=%s)\n",strerror(errno));
2832 if (FD_ISSET(tmp->pipe[0],&rrfs)) {
2833 len=read(tmp->pipe[0],tmp->ast_rd_buf,sizeof(tmp->ast_rd_buf));
2836 /* we hangup here, since our pipe is closed */
2837 chan_misdn_log(2,tmp->bc->port,"misdn_read: Pipe closed, hanging up\n");
2845 tmp->frame.frametype = AST_FRAME_VOICE;
2846 tmp->frame.subclass = AST_FORMAT_ALAW;
2847 tmp->frame.datalen = len;
2848 tmp->frame.samples = len;
2849 tmp->frame.mallocd = 0;
2850 tmp->frame.offset = 0;
2851 tmp->frame.delivery = ast_tv(0,0);
2852 tmp->frame.src = NULL;
2853 tmp->frame.data = tmp->ast_rd_buf;
2855 if (tmp->faxdetect && !tmp->faxhandled) {
2856 if (tmp->faxdetect_timeout) {
2857 if (ast_tvzero(tmp->faxdetect_tv)) {
2858 tmp->faxdetect_tv = ast_tvnow();
2859 chan_misdn_log(2, tmp->bc->port, "faxdetect: starting detection with timeout: %ds ...\n", tmp->faxdetect_timeout);
2860 return process_ast_dsp(tmp, &tmp->frame);
2862 struct timeval tv_now = ast_tvnow();
2863 int diff = ast_tvdiff_ms(tv_now, tmp->faxdetect_tv);
2864 if (diff <= (tmp->faxdetect_timeout * 1000)) {
2865 chan_misdn_log(5, tmp->bc->port, "faxdetect: detecting ...\n");
2866 return process_ast_dsp(tmp, &tmp->frame);
2868 chan_misdn_log(2, tmp->bc->port, "faxdetect: stopping detection (time ran out) ...\n");
2874 chan_misdn_log(5, tmp->bc->port, "faxdetect: detecting ... (no timeout)\n");
2875 return process_ast_dsp(tmp, &tmp->frame);
2879 return process_ast_dsp(tmp, &tmp->frame);
2886 static int misdn_write(struct ast_channel *ast, struct ast_frame *frame)
2888 struct chan_list *ch;
2891 if (!ast || ! (ch = MISDN_ASTERISK_TECH_PVT(ast)) ) return -1;
2893 if (ch->state == MISDN_HOLDED) {
2894 chan_misdn_log(7, 0, "misdn_write: Returning because holded\n");
2899 ast_log(LOG_WARNING, "private but no bc\n");
2904 chan_misdn_log(7, ch->bc->port, "misdn_write: Returning because notxone\n");
2909 if (!frame->subclass) {
2910 chan_misdn_log(4, ch->bc->port, "misdn_write: * prods us\n");
2914 if (!(frame->subclass & prefformat)) {
2916 chan_misdn_log(-1, ch->bc->port, "Got Unsupported Frame with Format:%d\n", frame->subclass);
2921 if (!frame->samples ) {
2922 chan_misdn_log(4, ch->bc->port, "misdn_write: zero write\n");
2924 if (!strcmp(frame->src,"ast_prod")) {
2925 chan_misdn_log(1, ch->bc->port, "misdn_write: state (%s) prodded.\n", misdn_get_ch_state(ch));
2928 chan_misdn_log(4, ch->bc->port, "Starting Playtones\n");
2929 misdn_lib_tone_generator_start(ch->bc);
2937 if ( ! ch->bc->addr ) {
2938 chan_misdn_log(8, ch->bc->port, "misdn_write: no addr for bc dropping:%d\n", frame->samples);
2944 int i, max = 5 > frame->samples ? frame->samples : 5;
2946 ast_debug(1, "write2mISDN %p %d bytes: ", p, frame->samples);
2948 for (i = 0; i < max ; i++)
2949 ast_debug(1, "%2.2x ", ((char*) frame->data)[i]);
2953 switch (ch->bc->bc_state) {
2954 case BCHAN_ACTIVATED:
2958 if (!ch->dropped_frame_cnt)
2959 chan_misdn_log(5, ch->bc->port, "BC not active (nor bridged) droping: %d frames addr:%x exten:%s cid:%s ch->state:%s bc_state:%d l3id:%x\n", frame->samples, ch->bc->addr, ast->exten, ast->cid.cid_num, misdn_get_ch_state( ch), ch->bc->bc_state, ch->bc->l3_id);
2961 ch->dropped_frame_cnt++;
2962 if (ch->dropped_frame_cnt > 100) {
2963 ch->dropped_frame_cnt = 0;
2964 chan_misdn_log(5, ch->bc->port, "BC not active (nor bridged) droping: %d frames addr:%x dropped > 100 frames!\n", frame->samples, ch->bc->addr);
2971 chan_misdn_log(9, ch->bc->port, "Sending :%d bytes 2 MISDN\n", frame->samples);
2972 if ( !ch->bc->nojitter && misdn_cap_is_speech(ch->bc->capability) ) {
2973 /* Buffered Transmit (triggert by read from isdn side)*/
2974 if (misdn_jb_fill(ch->jb, frame->data, frame->samples) < 0) {
2976 cb_log(0, ch->bc->port, "Misdn Jitterbuffer Overflow.\n");
2980 /*transmit without jitterbuffer*/
2981 i=misdn_lib_tx2misdn_frm(ch->bc, frame->data, frame->samples);
2990 static enum ast_bridge_result misdn_bridge (struct ast_channel *c0,
2991 struct ast_channel *c1, int flags,
2992 struct ast_frame **fo,
2993 struct ast_channel **rc,
2997 struct chan_list *ch1, *ch2;
2998 struct ast_channel *carr[2], *who;
3000 struct ast_frame *f;
3004 ch1 = get_chan_by_ast(c0);
3005 ch2 = get_chan_by_ast(c1);
3013 misdn_cfg_get(ch1->bc->port, MISDN_CFG_BRIDGING, &p1_b, sizeof(p1_b));
3014 misdn_cfg_get(ch2->bc->port, MISDN_CFG_BRIDGING, &p2_b, sizeof(p2_b));
3016 if (! p1_b || ! p2_b) {
3017 ast_log(LOG_NOTICE, "Falling back to Asterisk bridging\n");
3018 return AST_BRIDGE_FAILED;
3021 misdn_cfg_get(0, MISDN_GEN_BRIDGING, &bridging, sizeof(bridging));
3023 /* trying to make a mISDN_dsp conference */
3024 chan_misdn_log(1, ch1->bc->port, "I SEND: Making conference with Number:%d\n", ch1->bc->pid + 1);
3025 misdn_lib_bridge(ch1->bc, ch2->bc);
3028 ast_verb(3, "Native bridging %s and %s\n", c0->name, c1->name);
3030 chan_misdn_log(1, ch1->bc->port, "* Making Native Bridge between %s and %s\n", ch1->bc->oad, ch2->bc->oad);
3032 if (! (flags & AST_BRIDGE_DTMF_CHANNEL_0) )
3033 ch1->ignore_dtmf = 1;
3035 if (! (flags & AST_BRIDGE_DTMF_CHANNEL_1) )
3036 ch2->ignore_dtmf = 1;
3040 who = ast_waitfor_n(carr, 2, &to);
3043 ast_log(LOG_NOTICE, "misdn_bridge: empty read, breaking out\n");
3048 if (!f || f->frametype == AST_FRAME_CONTROL) {
3052 chan_misdn_log(4, ch1->bc->port, "Read Null Frame\n");
3054 chan_misdn_log(4, ch1->bc->port, "Read Frame Controll class:%d\n", f->subclass);
3062 if ( f->frametype == AST_FRAME_DTMF ) {
3063 chan_misdn_log(1, 0, "Read DTMF %d from %s\n", f->subclass, who->exten);
3071 if (f->frametype == AST_FRAME_VOICE) {
3072 chan_misdn_log(1, ch1->bc->port, "I SEND: Splitting conference with Number:%d\n", ch1->bc->pid +1);
3086 chan_misdn_log(1, ch1->bc->port, "I SEND: Splitting conference with Number:%d\n", ch1->bc->pid + 1);
3088 misdn_lib_split_bridge(ch1->bc, ch2->bc);
3090 return AST_BRIDGE_COMPLETE;
3093 /** AST INDICATIONS END **/
3095 static int dialtone_indicate(struct chan_list *cl)
3097 const struct ind_tone_zone_sound *ts = NULL;
3098 struct ast_channel *ast = cl->ast;
3102 chan_misdn_log(0, cl->bc->port, "No Ast in dialtone_indicate\n");
3106 misdn_cfg_get(cl->bc->port, MISDN_CFG_NODIALTONE, &nd, sizeof(nd));
3109 chan_misdn_log(1, cl->bc->port, "Not sending Dialtone, because config wants it\n");
3113 chan_misdn_log(3, cl->bc->port, " --> Dial\n");
3114 ts = ast_get_indication_tone(ast->zone, "dial");
3120 /* This prods us in misdn_write */
3121 ast_playtones_start(ast, 0, ts->data, 0);
3127 static int hanguptone_indicate(struct chan_list *cl)
3129 misdn_lib_send_tone(cl->bc, TONE_HANGUP);
3133 static int stop_indicate(struct chan_list *cl)
3135 struct ast_channel *ast = cl->ast;
3138 chan_misdn_log(0, cl->bc->port, "No Ast in stop_indicate\n");
3142 chan_misdn_log(3, cl->bc->port, " --> None\n");
3143 misdn_lib_tone_generator_stop(cl->bc);
3144 ast_playtones_stop(ast);
3147 /*ast_deactivate_generator(ast);*/
3153 static int start_bc_tones(struct chan_list* cl)
3155 misdn_lib_tone_generator_stop(cl->bc);
3161 static int stop_bc_tones(struct chan_list *cl)
3172 static struct chan_list *init_chan_list(int orig)
3174 struct chan_list *cl;
3176 cl = ast_calloc(1, sizeof(*cl));