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 (unified diff)

r4723r5220
1111 isdn_lib_intern.h isdn_msg_parser.c misdn_config.c
1212
1313
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\"
1515 chan_misdn_la_LIBADD = @MISDN_LDFLAGS@ -lisdnnet -lmISDN ${top_builddir}/corelib/libcallweaver.la
1616 chan_misdn_la_LDFLAGS = -module -avoid-version -no-undefined
1717 endif WANT_CHAN_MISDN

callweaver/branches/srtp_tls/channels/misdn/VERSION (unified diff)

r2596r5220
1 0.4.0-rc28
1 0.3.1-rc37c

callweaver/branches/srtp_tls/channels/misdn/chan_misdn.c (unified diff)

r4739r5220
5656 #include "callweaver/translate.h"
5757 #include "callweaver/config.h"
5858 #include "callweaver/file.h"
59 #include "callweaver/phone_no_utils.h"
59 #include "callweaver/callerid.h"
6060 #include "callweaver/indications.h"
6161 #include "callweaver/app.h"
6262 #include "callweaver/features.h"
63 #include "callweaver/term.h"
6463 #include "callweaver/sched.h"
64 #include "callweaver/phone_no_utils.h"
65 #include "chan_misdn_config.h"
66 #include "isdn_lib.h"
6567
66 #include <chan_misdn_config.h>
67 #include <isdn_lib.h>
68
6968 char global_tracefile[BUFFERSIZE+1];
7069
7170 static struct cw_frame nullframe = { CW_FRAME_NULL, };
7271
72 static int g_config_initialized=0;
73
7374 struct misdn_jb{
7475 int size;
7576 int upper_threshold;
------
99100 of data. */
100101 int misdn_jb_empty(struct misdn_jb *jb, char *data, int len);
101102
102 /* get the level of the buffer */
103 int misdn_jb_get_level(struct misdn_jb *jb);
104103
104
105
106 /* BEGIN: chan_misdn.h */
107
108 cw_mutex_t release_lock;
109
110
105111 enum misdn_chan_state {
106 MISDN_NOTHING, /*!< at beginning */
112 MISDN_NOTHING=0, /*!< at beginning */
107113 MISDN_WAITING4DIGS, /*!< when waiting for infos */
108114 MISDN_EXTCANTMATCH, /*!< when callweaver couldnt match our ext */
115 MISDN_INCOMING_SETUP, /*!< for incoming setups*/
109116 MISDN_DIALING, /*!< when pbx_start */
110117 MISDN_PROGRESS, /*!< we got a progress */
111118 MISDN_PROCEEDING, /*!< we got a progress */
------
120127 MISDN_BRIDGED, /*!< when bridged */
121128 MISDN_CLEANING, /*!< when hangup from * but we were connected before */
122129 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 */
124131 /* misdn_hangup */
125132 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 */
127134
128135 };
129136
130 #define ORG_AST 1
137 #define ORG_CW 1
131138 #define ORG_MISDN 2
132139
140 struct hold_info {
141 int port;
142 int channel;
143 };
144
133145 struct chan_list {
134146
147 cw_mutex_t lock;
148
135149 char allowed_bearers[BUFFERSIZE+1];
136150
137151 enum misdn_chan_state state;
------
139153 int need_hangup;
140154 int need_busy;
141155
156 int noautorespond_on_setup;
157
142158 int orginator;
143159
144160 int norxtone;
------
153169 int pipe[2];
154170 char cw_rd_buf[4096];
155171 struct cw_frame frame;
172
156173 char framedata[160];
157174 int framepos;
158175
159 int faxdetect; /* 0:no 1:yes 2:yes+nojump */
160 int faxdetect_timeout;
161 struct timeval faxdetect_tv;
176 int faxdetect;
162177 int faxhandled;
163178
164179 int cw_dsp;
------
166181 int jb_len;
167182 int jb_upper_threshold;
168183 struct misdn_jb *jb;
169
170 struct misdn_jb *jb_rx;
171
184
172185 struct cw_dsp *dsp;
173186 struct cw_trans_pvt *trans;
174187
175 struct cw_channel * ast;
188 struct cw_channel * cw;
176189
177190 int dummy;
178191
179192 struct misdn_bchannel *bc;
180 struct misdn_bchannel *holded_bc;
181193
194 struct hold_info hold_info;
195
182196 unsigned int l3id;
183197 int addr;
184198
------
188202 int dropped_frame_cnt;
189203
190204 int far_alerting;
205
206 int nttimeout;
207
191208 int other_pid;
192209 struct chan_list *other_ch;
193210
------
220237
221238
222239
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);
224241
225242
226243
------
248265 }
249266 struct robin_list *new = (struct robin_list *)calloc(1, sizeof(struct robin_list));
250267 new->group = strndup(group, strlen(group));
251 new->channel = 1;
268 new->port = 0;
269 new->channel = 0;
252270 if (robin) {
253271 new->next = robin;
254272 robin->prev = new;
------
265283 static void chan_misdn_log(int level, int port, char *tmpl, ...);
266284
267285 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 );
269287
288 static void hangup_chan(struct chan_list *ch);
270289 static int pbx_start_chan(struct chan_list *ch);
271290
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)
274293 #define CW_LOAD_CFG cw_config_load
275294 #define CW_DESTROY_CFG cw_config_destroy
276295
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
279298
280 #include "callweaver/strings.h"
299 #include <callweaver/strings.h>
281300
282301 /* #define MISDN_DEBUG 1 */
283302
------
288307
289308 static int usecnt=0;
290309
291 static char **misdn_key_vector=NULL;
292 static int misdn_key_vector_size=0;
293
294310 /* Only alaw and mulaw is allowed for now */
295311 static int prefformat = CW_FORMAT_ALAW ; /* CW_FORMAT_SLINEAR ; CW_FORMAT_ULAW | */
296312
------
300316 static int *misdn_debug_only;
301317 static int max_ports;
302318
303 static int *misdn_in_calls;
304 static int *misdn_out_calls;
305
306
307319 struct chan_list dummy_cl;
308320
309321 struct chan_list *cl_te=NULL;
------
312324 static enum event_response_e
313325 cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data);
314326
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);
316328
317329 static void cl_queue_chan(struct chan_list **list, struct chan_list *chan);
318330 static void cl_dequeue_chan(struct chan_list **list, struct chan_list *chan);
------
329341 static int stop_bc_tones(struct chan_list *cl);
330342 static void release_chan(struct misdn_bchannel *bc);
331343
344 static int misdn_check_l2l1(struct cw_channel *chan, int argc, char **argv);
332345 static int misdn_set_opt_exec(struct cw_channel *chan, int argc, char **argv);
333346 static int misdn_facility_exec(struct cw_channel *chan, int argc, char **argv);
334347
335348 int chan_misdn_jb_empty(struct misdn_bchannel *bc, char *buf, int len);
336349
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
340353 static int update_ec_config(struct misdn_bchannel *bc);
354 #endif
341355
342
343 void trigger_read(struct chan_list *ch, char *data, int len);
344
345356 /*************** Helpers *****************/
346357
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)
348359 {
349360 struct chan_list *tmp;
350361
351362 for (tmp=cl_te; tmp; tmp = tmp->next) {
352 if ( tmp->ast == ast ) return tmp;
363 if ( tmp->cw == cw ) return tmp;
353364 }
354365
355366 return NULL;
------
360371 struct chan_list *tmp;
361372
362373 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;
364375 }
365376
366377 return NULL;
------
419430 {
420431 switch (bc->fac_type) {
421432 case FACILITY_CALLDEFLECT:
422 chan_misdn_log(0,bc->port," --> calldeflect: %s\n",
433 chan_misdn_log(2,bc->port," --> calldeflect: %s\n",
423434 bc->fac.calldeflect_nr);
424435 break;
425436 case FACILITY_CENTREX:
426 chan_misdn_log(0,bc->port," --> centrex: %s\n",
437 chan_misdn_log(2,bc->port," --> centrex: %s\n",
427438 bc->fac.cnip);
428439 break;
429440 default:
430 chan_misdn_log(0,bc->port," --> unknown\n");
441 chan_misdn_log(2,bc->port," --> unknown\n");
431442
432443 }
433444 }
------
455466 return cw_sched_add_variable(misdn_tasks, timeout, callback, data, variable);
456467 }
457468
469 #if 0
458470 static int misdn_tasks_add (int timeout, cw_sched_cb callback, void *data)
459471 {
460472 return _misdn_tasks_add_variable(timeout, callback, data, 0);
461473 }
474 #endif
462475
463476 static int misdn_tasks_add_variable (int timeout, cw_sched_cb callback, void *data)
464477 {
------
470483 cw_sched_del(misdn_tasks, task_id);
471484 }
472485
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
480486 static int misdn_overlap_dial_task (void *data)
481487 {
482488 struct timeval tv_end, tv_now;
------
502508 if (diff <= 100) {
503509 /* if we are 100ms near the timeout, we are satisfied.. */
504510 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)) {
506512 ch->state=MISDN_DIALING;
507513 if (pbx_start_chan(ch) < 0) {
508514 chan_misdn_log(-1, ch->bc->port, "cw_pbx_start returned < 0 in misdn_overlap_dial_task\n");
------
511517 } else {
512518 misdn_overlap_dial_task_disconnect:
513519 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);
518523 }
519524 ch->overlap_dial_task = -1;
520525 return 0;
------
522527 return diff;
523528 }
524529
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 )
526531 {
527532 static const char* dtmf_tones[] = {
528533 "!941+1336/100,!0/100", /* 0 */
------
541546 "!941+1633/100,!0/100", /* D */
542547 "!941+1209/100,!0/100", /* * */
543548 "!941+1477/100,!0/100" }; /* # */
544 struct cw_channel *chan=cl->ast;
549 struct cw_channel *chan=cl->cw;
545550
546551 if (digit >= '0' && digit <='9')
547552 cw_playtones_start(chan,0,dtmf_tones[digit-'0'], 0);
------
554559 else {
555560 /* not handled */
556561 cw_log(LOG_DEBUG, "Unable to handle DTMF tone '%c' for '%s'\n", digit, chan->name);
562
563
557564 }
558 return 0;
559565 }
560566 /*** CLI HANDLING ***/
561567 static int misdn_set_debug(int fd, int argc, char *argv[])
------
622628 return 0;
623629 }
624630
625
626631 static int misdn_port_block(int fd, int argc, char *argv[])
627632 {
628633 int port;
629
634
630635 if (argc != 4)
631636 return RESULT_SHOWUSAGE;
632637
------
666671 return 0;
667672 }
668673
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
669688 static int misdn_port_up (int fd, int argc, char *argv[])
670689 {
671690 int port;
------
683702 static int misdn_port_down (int fd, int argc, char *argv[])
684703 {
685704 int port;
686
705
687706 if (argc != 4)
688707 return RESULT_SHOWUSAGE;
689708
------
694713 return 0;
695714 }
696715
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];
704716
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
720717 static int misdn_show_config (int fd, int argc, char *argv[])
721718 {
722719 char buffer[BUFFERSIZE];
723720 enum misdn_cfg_elements elem;
724721 int linebreak;
722
725723 int onlyport = -1;
726 int ok = 0;
727
728724 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 }
757725 if (!sscanf(argv[3], "%d", &onlyport) || onlyport < 0) {
758726 cw_cli(fd, "Unknown option: %s\n", argv[3]);
759727 return RESULT_SHOWUSAGE;
------
786754 if (misdn_cfg_is_port_valid(onlyport)) {
787755 cw_cli(fd, "[PORT %d]\n", onlyport);
788756 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);
790758 cw_cli(fd, "%-36s%s", buffer, !(linebreak % 2) ? "\n" : "");
791759 }
792760 cw_cli(fd, "\n");
------
806774 {MISDN_NOTHING,"NOTHING"}, /* at beginning */
807775 {MISDN_WAITING4DIGS,"WAITING4DIGS"}, /* when waiting for infos */
808776 {MISDN_EXTCANTMATCH,"EXTCANTMATCH"}, /* when callweaver couldnt match our ext */
777 {MISDN_INCOMING_SETUP,"INCOMING SETUP"}, /* when pbx_start */
809778 {MISDN_DIALING,"DIALING"}, /* when pbx_start */
810779 {MISDN_PROGRESS,"PROGRESS"}, /* when pbx_start */
811780 {MISDN_PROCEEDING,"PROCEEDING"}, /* when pbx_start */
------
822791 {MISDN_HUNGUP_FROM_MISDN,"HUNGUP_FROM_MISDN"}, /* when DISCONNECT/RELEASE/REL_COMP cam from misdn */
823792 {MISDN_HOLDED,"HOLDED"}, /* when DISCONNECT/RELEASE/REL_COMP cam from misdn */
824793 {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 */
826795 /* misdn_hangup */
827796 };
828797
------
844813
845814
846815
847 void reload_config(void)
816 static void reload_config(void)
848817 {
849818 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 }
850824
851825 free_robin_list();
852826 misdn_cfg_reload();
------
869843
870844 static void print_bc_info (int fd, struct chan_list* help, struct misdn_bchannel* bc)
871845 {
872 struct cw_channel *ast=help->ast;
846 struct cw_channel *cw=help->cw;
873847 cw_cli(fd,
874848 "* Pid:%d Prt:%d Ch:%d Mode:%s Org:%s dad:%s oad:%s rad:%s ctx:%s state:%s\n",
875849
876850 bc->pid, bc->port, bc->channel,
877851 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,
881855 bc->rad,
882 ast?ast->context:NULL,
856 cw?cw->context:NULL,
883857 misdn_get_ch_state(help)
884858 );
885859 if (misdn_debug[bc->port] > 0)
886860 cw_cli(fd,
887 " --> astname: %s\n"
861 " --> cwname: %s\n"
888862 " --> ch_l3id: %x\n"
889863 " --> ch_addr: %x\n"
890864 " --> bc_addr: %x\n"
------
893867 " --> activated: %d\n"
894868 " --> state: %s\n"
895869 " --> capability: %s\n"
870 #ifdef MISDN_1_2
871 " --> pipeline: %s\n"
872 #else
896873 " --> 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"
903874 #endif
904875 " --> 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,
907878 help->l3id,
908879 help->addr,
909880 bc->addr,
------
913884 bc->active,
914885 bc_state2str(bc->bc_state),
915886 bearer2str(bc->capability),
887 #ifdef MISDN_1_2
888 bc->pipeline,
889 #else
916890 bc->ec_enable,
891 #endif
917892
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
925893 help->norxtone,help->notxtone,
926 bc->holded, help->holded_bc?1:0
894 bc->holded
927895 );
928896
929897 }
------
936904
937905 for (;help; help=help->next) {
938906 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);
941909 if (bc) {
942910 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);
946911 } 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 }
948924 }
949925 }
950926
951
927 misdn_dump_chanlist();
952928 return 0;
953929 }
954930
------
961937
962938 for (;help; help=help->next) {
963939 struct misdn_bchannel *bc=help->bc;
964 struct cw_channel *ast=help->ast;
940 struct cw_channel *cw=help->cw;
965941
966 if (bc && ast) {
967 if (!strcasecmp(ast->name,argv[3])) {
942 if (bc && cw) {
943 if (!strcasecmp(cw->name,argv[3])) {
968944 print_bc_info(fd, help, bc);
969945 break;
970946 }
------
1001977 cw_cli(fd," %s Debug:%d%s\n", buf, misdn_debug[port], misdn_debug_only[port]?"(only)":"");
1002978 }
1003979
1004 return 0;
1005 }
1006980
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
1020981 return 0;
1021982
1022983 }
1023984
1024
1025985 static int misdn_show_port (int fd, int argc, char *argv[])
1026986 {
1027987 int port;
------
10691029 return 0;
10701030 }
10711031
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
10721053 static int misdn_send_digit (int fd, int argc, char *argv[])
10731054 {
10741055 char *channame;
------
10951076 for (i=0; i<msglen; i++) {
10961077 cw_cli(fd, "Sending: %c\n",msg[i]);
10971078 send_digit_to_chan(tmp, msg[i]);
1098 /* res = cw_safe_sleep(tmp->ast, 250); */
1079 /* res = cw_safe_sleep(tmp->cw, 250); */
10991080 usleep(250000);
1100 /* res = cw_waitfor(tmp->ast,100); */
1081 /* res = cw_waitfor(tmp->cw,100); */
11011082 }
11021083 #else
11031084 int res;
1104 res = cw_dtmf_stream(tmp->ast,NULL,msg,250);
1085 res = cw_dtmf_stream(tmp->cw,NULL,msg,250);
11051086 #endif
11061087 }
11071088 }
------
11311112 tmp->toggle_ec=tmp->toggle_ec?0:1;
11321113
11331114 if (tmp->toggle_ec) {
1115 #ifdef MISDN_1_2
1116 update_pipeline_config(tmp->bc);
1117 #else
11341118 update_ec_config(tmp->bc);
1119 #endif
11351120 manager_ec_enable(tmp->bc);
11361121 } else {
11371122 manager_ec_disable(tmp->bc);
------
12171202 return NULL;
12181203 }
12191204
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
12641205 static struct cw_cli_entry cli_send_cd =
12651206 { {"misdn","send","calldeflect", NULL},
12661207 misdn_send_cd,
------
12691210 complete_ch
12701211 };
12711212
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
12721221 static struct cw_cli_entry cli_send_digit =
12731222 { {"misdn","send","digit", NULL},
12741223 misdn_send_digit,
------
13011250 { {"misdn","show","config", NULL},
13021251 misdn_show_config,
13031252 "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"
13071254 };
13081255
13091256 static struct cw_cli_entry cli_reload =
------
13571304 "Usage: misdn restart port\n"
13581305 };
13591306
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
13601314 static struct cw_cli_entry cli_port_up =
13611315 { {"misdn","port","up", NULL},
13621316 misdn_port_up,
------
13801334 "Usage: misdn show stacks\n"
13811335 };
13821336
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
13911337 static struct cw_cli_entry cli_show_port =
13921338 { {"misdn","show","port", NULL},
13931339 misdn_show_port,
------
14091355 "Sets CryptDebuglevel of chan_misdn, at the moment, level={1,2}",
14101356 "Usage: misdn set crypt debug <level>\n"
14111357 };
1358
14121359 /*** CLI END ***/
14131360
1414
14151361 static int update_config (struct chan_list *ch, int orig)
14161362 {
14171363 if (!ch) {
------
14191365 return -1;
14201366 }
14211367
1422 struct cw_channel *ast=ch->ast;
1368 struct cw_channel *cw=ch->cw;
14231369 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");
14261372 return -1;
14271373 }
14281374
14291375 int port=bc->port;
14301376
1431 chan_misdn_log(1,port,"update_config: Getting Config\n");
1377 chan_misdn_log(7,port,"update_config: Getting Config\n");
14321378
1433
14341379 int hdlc=0;
14351380 misdn_cfg_get( port, MISDN_CFG_HDLC, &hdlc, sizeof(int));
14361381
------
14541399
14551400 if ( (pres + screen) < 0 ) {
14561401
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);
14581403
1459 switch (ast->cid.cid_pres & 0x60){
1404 switch (cw->cid.cid_pres & 0x60){
14601405
14611406 case CW_PRES_RESTRICTED:
14621407 bc->pres=1;
------
14741419 chan_misdn_log(2, port, " --> PRES: Allowed (0x0)\n");
14751420 }
14761421
1477 switch (ast->cid.cid_pres & 0x3){
1422 switch (cw->cid.cid_pres & 0x3){
14781423
14791424 case CW_PRES_USER_NUMBER_UNSCREENED:
14801425 bc->screen=0;
------
15411486 }
15421487
15431488 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);
15461489
1547 if (!ch->jb || !ch->jb_rx)
1490 if (!ch->jb )
15481491 bc->nojitter=1;
15491492 }
15501493 }
------
15721515 }
15731516 }
15741517
1518 #ifdef MISDN_1_2
1519 static int update_pipeline_config(struct misdn_bchannel *bc)
1520 {
1521 int ec;
15751522
1523 misdn_cfg_get(bc->port, MISDN_CFG_PIPELINE, bc->pipeline, sizeof(bc->pipeline));
15761524
1525 if (*bc->pipeline)
1526 return 0;
15771527
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
15781537 static int update_ec_config(struct misdn_bchannel *bc)
15791538 {
15801539 int ec;
------
15881547 bc->ec_enable=1;
15891548 bc->ec_deftaps=ec;
15901549 }
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
15991550
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
16131551 return 0;
16141552 }
1553 #endif
16151554
1616
16171555 static int read_config(struct chan_list *ch, int orig) {
16181556
16191557 if (!ch) {
------
16211559 return -1;
16221560 }
16231561
1624 struct cw_channel *ast=ch->ast;
1562 struct cw_channel *cw=ch->cw;
16251563 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");
16281566 return -1;
16291567 }
16301568
------
16351573 char lang[BUFFERSIZE+1];
16361574
16371575 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));
16391577
16401578 char musicclass[BUFFERSIZE+1];
16411579
16421580 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));
16441582
16451583 misdn_cfg_get( port, MISDN_CFG_TXGAIN, &bc->txgain, sizeof(int));
16461584 misdn_cfg_get( port, MISDN_CFG_RXGAIN, &bc->rxgain, sizeof(int));
------
16501588 misdn_cfg_get( port, MISDN_CFG_SENDDTMF, &bc->send_dtmf, sizeof(int));
16511589
16521590 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));
16531592
1593 misdn_cfg_get( port, MISDN_CFG_NOAUTORESPOND_ON_SETUP, &ch->noautorespond_on_setup, sizeof(int));
1594
16541595 misdn_cfg_get( port, MISDN_CFG_FAR_ALERTING, &ch->far_alerting, sizeof(int));
16551596
16561597 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
16611600 int hdlc=0;
16621601 misdn_cfg_get( port, MISDN_CFG_HDLC, &hdlc, sizeof(int));
16631602
------
16811620
16821621 misdn_cfg_get( bc->port, MISDN_CFG_CONTEXT, ch->context, sizeof(ch->context));
16831622
1684 cw_copy_string (ast->context,ch->context,sizeof(ast->context));
1623 cw_copy_string (cw->context,ch->context,sizeof(cw->context));
16851624
1625 #ifdef MISDN_1_2
1626 update_pipeline_config(bc);
1627 #else
16861628 update_ec_config(bc);
1629 #endif
16871630
16881631 {
16891632 int eb3;
------
17021645 misdn_cfg_get(port, MISDN_CFG_CALLGROUP, &cg, sizeof(cg));
17031646
17041647 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;
17071650 }
17081651
1709 if ( orig == ORG_AST) {
1652 if ( orig == ORG_CW) {
17101653 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 }
17181654
17191655 {
17201656 char callerid[BUFFERSIZE+1];
------
17401676
17411677 ch->overlap_dial = 0;
17421678 } 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 }
17491679
17501680 misdn_cfg_get( port, MISDN_CFG_CPNDIALPLAN, &bc->cpnnumplan, sizeof(int));
17511681 debug_numplan(port, bc->cpnnumplan,"CTON");
------
18001730 strcpy(bc->dad,tmp);
18011731 }
18021732
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));
18051735 }
18061736
1807 cw_set_callerid(ast, bc->oad, NULL, bc->oad);
1737 cw_set_callerid(cw, bc->oad, NULL, bc->oad);
18081738
18091739 if ( !cw_strlen_zero(bc->rad) )
1810 ast->cid.cid_rdnis=strdup(bc->rad);
1740 cw->cid.cid_rdnis=strdup(bc->rad);
18111741
18121742 misdn_cfg_get(bc->port, MISDN_CFG_OVERLAP_DIAL, &ch->overlap_dial, sizeof(ch->overlap_dial));
18131743 cw_mutex_init(&ch->overlap_tv_lock);
------
18151745
18161746 ch->overlap_dial_task = -1;
18171747
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
18281748 return 0;
18291749 }
18301750
18311751
18321752 /*****************************/
1833 /*** AST Indications Start ***/
1753 /*** CW Indications Start ***/
18341754 /*****************************/
18351755
1836 static int misdn_call(struct cw_channel *ast, char *dest, int timeout)
1756 static int misdn_call(struct cw_channel *cw, char *dest)
18371757 {
18381758 int port=0;
18391759 int r;
1840 struct chan_list *ch=MISDN_CALLWEAVER_TECH_PVT(ast);
1760 struct chan_list *ch=MISDN_CALLWEAVER_TECH_PVT(cw);
18411761 struct misdn_bchannel *newbc;
1842 char *opts=NULL, *ext,*tokb;
1762 char *opts=NULL, *ext;
18431763 char dest_cp[256];
18441764
18451765 {
18461766 strncpy(dest_cp,dest,sizeof(dest_cp)-1);
18471767 dest_cp[sizeof(dest_cp)]=0;
1848
1849 ext=strtok_r(dest_cp,"/",&tokb);
1850
1768
1769 ext=dest_cp;
1770 strsep(&ext,"/");
18511771 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<