hi, it's my first callweaver patch. Hope it`s working. It is to make chan_misdn ready to use mISDN1.2 mISDN1.2 has the open source echo canceller, thats why i wanted to use chan_misdn with mISDN1.2

--
Kristijan

diff -Naur callweaver-RC-1.1.99.20080202/channels/misdn/chan_misdn.c 
CW-misdn/chan_misdn.c
--- callweaver-RC-1.1.99.20080202/channels/misdn/chan_misdn.c   2008-01-03 
00:40:02.000000000 +0100
+++ CW-misdn/chan_misdn.c       2008-02-03 18:28:20.000000000 +0100
@@ -337,8 +337,11 @@
 int add_out_calls(int port);
 int add_in_calls(int port);
 
+#ifdef MISDN_1_2
+static int update_pipeline_config(struct misdn_bchannel *bc);
+#else
 static int update_ec_config(struct misdn_bchannel *bc);
-
+#endif
 
 void trigger_read(struct chan_list *ch, char *data, int len);
 
@@ -893,7 +896,12 @@
                        "  --> activated: %d\n"
                        "  --> state: %s\n"
                        "  --> capability: %s\n"
+#ifdef MISDN_1_2
+                       "  --> pipeline: %s\n"
+#else
                        "  --> echo_cancel: %d\n"
+#endif
+
 #ifdef WITH_BEROEC
                        "  --> bnec_tail: %d\n"
                        "  --> bnec_nlp: %d\n"
@@ -913,7 +921,11 @@
                        bc->active,
                        bc_state2str(bc->bc_state),
                        bearer2str(bc->capability),
+#ifdef MISDN_1_2
+                       bc->pipeline,
+#else
                        bc->ec_enable,
+#endif
 
 #ifdef WITH_BEROEC
                        bc->bnec_tail,
@@ -1131,7 +1143,11 @@
                        tmp->toggle_ec=tmp->toggle_ec?0:1;
 
                        if (tmp->toggle_ec) {
+#ifdef MISDN_1_2
+                               update_pipeline_config(tmp->bc);
+#else
                                update_ec_config(tmp->bc);
+#endif
                                manager_ec_enable(tmp->bc);
                        } else {
                                manager_ec_disable(tmp->bc);
@@ -1573,8 +1589,25 @@
 }
 
 
+#ifdef MISDN_1_2
+static int update_pipeline_config(struct misdn_bchannel *bc)
+{
+       int ec;
 
+       misdn_cfg_get(bc->port, MISDN_CFG_PIPELINE, bc->pipeline, 
sizeof(bc->pipeline));
+
+       if (*bc->pipeline)
+               return 0;
 
+       misdn_cfg_get(bc->port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(int));
+       if (ec == 1)
+               snprintf(bc->pipeline, sizeof(bc->pipeline) - 1, "mg2ec");
+       else if (ec > 1)
+               snprintf(bc->pipeline, sizeof(bc->pipeline) - 1, 
"mg2ec(deftaps=%d)", ec);
+
+       return 0;
+}
+#else
 static int update_ec_config(struct misdn_bchannel *bc)
 {
        int ec;
@@ -1612,7 +1645,7 @@
 #endif
        return 0;
 }
-
+#endif
 
 static int read_config(struct chan_list *ch, int orig) {
 
@@ -1682,8 +1715,11 @@
        misdn_cfg_get( bc->port, MISDN_CFG_CONTEXT, ch->context, 
sizeof(ch->context));
        
        opbx_copy_string (ast->context,ch->context,sizeof(ast->context));       
-
+#ifdef MISDN_1_2
+       update_pipeline_config(bc);
+#else
        update_ec_config(bc);
+#endif
 
        {
                int eb3;
@@ -2591,16 +2627,28 @@
                misdn_cfg_get( ch1->bc->port, MISDN_CFG_ECHOCANCELWHENBRIDGED, 
&ecwb, sizeof(int));
                misdn_cfg_get( ch1->bc->port, MISDN_CFG_ECHOCANCEL, &ec, 
sizeof(int));
                if ( !ecwb && ec ) {
+#ifdef MISDN_1_2
+                       chan_misdn_log(2, ch1->bc->port, "Disabling EC (aka 
Pipeline) on both Sides\n");
+                       *ch1->bc->pipeline=0;
+                       *ch1->other_ch->bc->pipeline=0;
+#else
                        chan_misdn_log(2, ch1->bc->port, "Disabling Echo 
Cancellor when Bridged\n");
                        ch1->bc->ec_enable=0;
                        manager_ec_disable(ch1->bc);
+#endif
                }
                misdn_cfg_get( ch2->bc->port, MISDN_CFG_ECHOCANCELWHENBRIDGED, 
&ecwb, sizeof(int));
                misdn_cfg_get( ch2->bc->port, MISDN_CFG_ECHOCANCEL, &ec, 
sizeof(int));
                if ( !ecwb && ec) {
+#ifdef MISDN_1_2
+                       chan_misdn_log(2, ch2->bc->port, "Disabling EC (aka 
Pipeline) on both Sides\n");
+                       *ch2->bc->pipeline=0;
+                       *ch2->other_ch->bc->pipeline=0;
+#else
                        chan_misdn_log(2, ch2->bc->port, "Disabling Echo 
Cancellor when Bridged\n");
                        ch2->bc->ec_enable=0;
-                       manager_ec_disable(ch2->bc); 
+                       manager_ec_disable(ch2->bc);
+#endif
                }
                
                /* trying to make a mISDN_dsp conference */
@@ -3094,7 +3142,11 @@
                        isdn_lib_update_rxgain(tmp->bc);
                        tmp->bc->txgain = 0;
                        isdn_lib_update_txgain(tmp->bc);
+#ifdef MISDN_1_2
+                       *tmp->bc->pipeline = 0;         
+#else
                        tmp->bc->ec_enable = 0;
+#endif
                        isdn_lib_update_ec(tmp->bc);
                        isdn_lib_stop_dtmf(tmp->bc);
                        switch (tmp->faxdetect) {
@@ -4860,18 +4912,22 @@
                        
                        if (neglect) {
                                chan_misdn_log(1, ch->bc->port, " --> 
disabled\n");
+#ifdef MISDN_1_2
+                               *ch->bc->pipeline=0;
+#else
                                ch->bc->ec_enable=0;
-
-#ifdef WITH_BEROEC
-                               ch->bc->bnec_tail=0;
 #endif
                        } else {
+#ifdef MISDN_1_2
+                               update_pipeline_config(ch->bc);
+#else
                                ch->bc->ec_enable=1;
                                ch->bc->orig=ch->orginator;
                                tok++;
-                               if (tok) {
+                               if (*tok) {
                                        ch->bc->ec_deftaps=atoi(tok);
                                }
+#endif
                        }
                        
                        break;
@@ -4881,7 +4937,9 @@
                        
                        if (strlen(tok) > 1 && tok[1]=='1') {
                                chan_misdn_log(1, ch->bc->port, "SETOPT: HDLC 
\n");
-                               ch->bc->hdlc=1;
+                               if (!ch->bc->hdlc) {
+                                       ch->bc->hdlc=1;
+                               }
                        }  
                        ch->bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED;
                        break;
diff -Naur callweaver-RC-1.1.99.20080202/channels/misdn/chan_misdn_config.h 
CW-misdn/chan_misdn_config.h
--- callweaver-RC-1.1.99.20080202/channels/misdn/chan_misdn_config.h    
2007-09-23 19:36:25.000000000 +0200
+++ CW-misdn/chan_misdn_config.h        2008-02-02 21:47:53.000000000 +0100
@@ -1,7 +1,7 @@
 /*
  * Chan_Misdn -- Channel Driver for CallWeaver
  *
- * Interface to mISDN
+ * Interface to mISDN_1_1 AND mISDN_1_2
  *
  * Copyright (C) 2004, Christian Richter
  *
@@ -52,6 +52,9 @@
        MISDN_CFG_INCOMING_EARLY_AUDIO,      /* int (bool) */
        MISDN_CFG_ECHOCANCEL,          /* int */
        MISDN_CFG_ECHOCANCELWHENBRIDGED,  /* int (bool) */
+#ifdef MISDN_1_2
+       MISDN_CFG_PIPELINE,            /* char[] */
+#endif
 #ifdef WITH_ECHOTRAINGING
        MISDN_CFG_ECHOTRAINING,        /* int (bool) */
 #endif
diff -Naur callweaver-RC-1.1.99.20080202/channels/misdn/isdn_lib.c 
CW-misdn/isdn_lib.c
--- callweaver-RC-1.1.99.20080202/channels/misdn/isdn_lib.c     2007-09-23 
19:36:25.000000000 +0200
+++ CW-misdn/isdn_lib.c 2008-02-03 03:42:36.000000000 +0100
@@ -1,7 +1,7 @@
 /*
  * Chan_Misdn -- Channel Driver for CallWeaver
  *
- * Interface to mISDN
+ * Interface to mISDN_1_1 and mISDN_1_2
  *
  * Copyright (C) 2004, Christian Richter
  *
@@ -579,13 +579,16 @@
 
        bc->early_bconnect = 1;
        
+#ifdef MISDN_1_2
+       *bc->pipeline = 0;
+#else
        bc->ec_enable = 0;
        bc->ec_deftaps = 128;
-       bc->ec_whenbridged = 0;
 
 #ifdef EC_TRAIN
        bc->ec_training = 1;
 #endif
+#endif
        
        bc->orig=0;
   
@@ -1187,6 +1190,7 @@
                stack->nt=1;
                break;
 
+#ifndef MISDN_1_2
        case ISDN_PID_L0_TE_U:
                break;
        case ISDN_PID_L0_NT_U:
@@ -1195,6 +1199,7 @@
                break;
        case ISDN_PID_L0_NT_UP2:
                break;
+#endif
        case ISDN_PID_L0_TE_E1:
                cb_log(8, port, "TE S2M Stack\n");
                stack->nt=0;
@@ -4035,10 +4040,15 @@
 
 void isdn_lib_update_ec (struct misdn_bchannel *bc)
 {
+#ifdef MISDN_1_2
+       if (bc->pipeline)
+#else
        if (bc->ec_enable)
+#endif
                manager_ec_enable(bc);
        else
                manager_ec_disable(bc);
+
 }
 
 void isdn_lib_stop_dtmf (struct misdn_bchannel *bc)
@@ -4219,7 +4229,12 @@
        }       
        return ;
 #endif
-
+#ifdef MISDN_1_2
+       if (*bc->pipeline) {
+               cb_log(3, stack?stack->port:0,"Sending Control PIPELINE_CFG 
%s\n",bc->pipeline);
+               manager_ph_control_block(bc, PIPELINE_CFG, bc->pipeline, 
strlen(bc->pipeline) + 1);
+       }
+#else
        if (bc->ec_enable) {
                cb_log(1, stack?stack->port:0,"Sending Control ECHOCAN_ON 
taps:%d training:%d\n",bc->ec_deftaps, bc->ec_training);
        
@@ -4249,6 +4264,7 @@
                
                manager_ph_control_block(bc,  ECHOCAN_ON,  ec_arr, 
sizeof(ec_arr));
        }
+#endif
 }
 
 
@@ -4270,11 +4286,14 @@
        bc->ec=NULL;
        return;
 #endif
-
+#ifdef MISDN_1_2
+       manager_ph_control_block(bc, PIPELINE_CFG, "", 0);
+#else
        if ( bc->ec_enable) {
                cb_log(1, stack?stack->port:0, "Sending Control ECHOCAN_OFF\n");
                manager_ph_control(bc,  ECHOCAN_OFF, 0);
        }
+#endif
 }
 
 struct misdn_stack* get_misdn_stack() {
diff -Naur callweaver-RC-1.1.99.20080202/channels/misdn/isdn_lib.h 
CW-misdn/isdn_lib.h
--- callweaver-RC-1.1.99.20080202/channels/misdn/isdn_lib.h     2007-09-23 
19:36:25.000000000 +0200
+++ CW-misdn/isdn_lib.h 2008-02-02 21:50:46.000000000 +0100
@@ -1,7 +1,7 @@
 /*
  * Chan_Misdn -- Channel Driver for CallWeaver
  *
- * Interface to mISDN
+ * Interface to mISDN_1_1 and mISDN_1_2
  *
  * Copyright (C) 2004, Christian Richter
  *
@@ -347,10 +347,13 @@
   
        /** list stuf **/
 
+#ifdef MISDN_1_2
+       char pipeline[128];
+#else
        int ec_enable;
        int ec_deftaps;
-       int ec_whenbridged;
        int ec_training;
+#endif
 
 #ifdef WITH_BEROEC
        beroec_t *ec;
diff -Naur callweaver-RC-1.1.99.20080202/channels/misdn/misdn_config.c 
CW-misdn/misdn_config.c
--- callweaver-RC-1.1.99.20080202/channels/misdn/misdn_config.c 2007-09-23 
19:36:25.000000000 +0200
+++ CW-misdn/misdn_config.c     2008-02-02 22:10:22.000000000 +0100
@@ -229,6 +229,9 @@
                "\tA value of zero turns echocancellation off.\n"
                "\n"
                "\tPossible values are: 0,32,64,128,256,yes(=128),no(=0)" },
+#ifdef MISDN_1_2
+       { "pipeline", MISDN_CFG_PIPELINE, MISDN_CTYPE_STR, NO_DEFAULT, NONE },
+#endif
        { "echocancelwhenbridged", MISDN_CFG_ECHOCANCELWHENBRIDGED, 
MISDN_CTYPE_BOOL, "no", NONE,
                "This disables echocancellation when the call is bridged 
between\n"
                "\tmISDN channels" },
@@ -974,6 +977,38 @@
 
 void misdn_cfg_update_ptp (void)
 {
+#ifndef MISDN_1_2
+       char misdn_init[BUFFERSIZE];
+       char line[BUFFERSIZE];
+       FILE *fp;
+       char *tok, *p, *end;
+       int port;
+
+       misdn_cfg_get(0, MISDN_GEN_MISDN_INIT, &misdn_init, sizeof(misdn_init));
+
+       if (misdn_init) {
+               fp = fopen(misdn_init, "r");
+               if (fp) {
+                       while(fgets(line, sizeof(line), fp)) {
+                               if (!strncmp(line, "nt_ptp", 6)) {
+                                       for (tok = strtok_r(line,",=", &p);
+                                                tok;
+                                                tok = strtok_r(NULL,",=", &p)) 
{
+                                               port = strtol(tok, &end, 10);
+                                               if (end != tok && 
misdn_cfg_is_port_valid(port)) {
+                                                       misdn_cfg_lock();
+                                                       ptp[port] = 1;
+                                                       misdn_cfg_unlock();
+                                               }
+                                       }
+                               }
+                       }
+                       fclose(fp);
+               } else {
+                       opbx_log(LOG_WARNING,"Couldn't open %s: %s\n", 
misdn_init, strerror(errno));
+               }
+       }
+#else
        char misdn_init[BUFFERSIZE];
        char line[BUFFERSIZE];
        FILE *fp;
@@ -1004,6 +1039,7 @@
                        opbx_log(LOG_WARNING,"Couldn't open %s: %s\n", 
misdn_init, strerror(errno));
                }
        }
+#endif
 }
 
 static void _fill_defaults (void)
_______________________________________________
Callweaver-dev mailing list
[email protected]
http://lists.callweaver.org/mailman/listinfo/callweaver-dev

Reply via email to