Disabled layer2-hold from CCITT#5 interfaces
[lcr.git] / mISDN.cpp
index 087963c..75a1b62 100644 (file)
--- a/mISDN.cpp
+++ b/mISDN.cpp
@@ -11,9 +11,6 @@
 
 #include "main.h"
 #include "myisdn.h"
-
-#include <mISDN/mISDNcompat.h>
-int __af_isdn = MISDN_AF_ISDN;
 #include <mISDN/q931.h>
 
 #undef offsetof
@@ -40,7 +37,9 @@ struct mISDNport *mISDNport_first;
 unsigned char mISDN_rand[256];
 int mISDN_rand_count = 0;
 
+#ifdef OLD_MT_ASSIGN
 unsigned int mt_assign_pid = ~0;
+#endif
 
 int mISDNsocket = -1;
 static int upqueue_pipe[2];
@@ -50,9 +49,21 @@ int upqueue_avail = 0;
 static int mISDN_upqueue(struct lcr_fd *fd, unsigned int what, void *instance, int i);
 static int mISDN_timeout(struct lcr_timer *timer, void *instance, int i);
 
+static int my_mISDNlib_debug(const char *file, int line, const char *func, int level, const char *fmt, va_list va)
+{
+        int ret = 0;
+
+        if (debug_fp > 0)
+               ret = vfprintf(debug_fp, fmt, va);
+       return ret;
+}
+
+static struct mi_ext_fn_s myfn;
+
 int mISDN_initialize(void)
 {
        char filename[256];
+       int ver;
 
        /* try to open raw socket to check kernel */
        mISDNsocket = socket(PF_ISDN, SOCK_RAW, ISDN_P_BASE);
@@ -62,7 +73,10 @@ int mISDN_initialize(void)
        }
 
        /* init mlayer3 */
-       init_layer3(4); // buffer of 4
+       // set debug printout function
+       myfn.prt_debug = my_mISDNlib_debug;
+
+       ver = init_layer3(4, &myfn); // buffer of 4
 
        /* open debug, if enabled and not only stack debugging */
        if (options.deb) {
@@ -70,11 +84,10 @@ int mISDN_initialize(void)
                debug_fp = fopen(filename, "a");
        }
 
-       if (options.deb & DEBUG_STACK) {
-               SPRINT(filename, "%s/debug_mISDN.log", LOG_DIR);
-               mISDN_debug_init(0xfffffeff, filename, filename, filename);
-       } else
-               mISDN_debug_init(0, NULL, NULL, NULL);
+       if (options.deb & DEBUG_STACK)
+               mISDN_set_debug_level(0xfffffeff);
+       else
+               mISDN_set_debug_level(0);
 
        if (pipe(upqueue_pipe) < 0)
                FATAL("Failed to open pipe\n");
@@ -89,8 +102,6 @@ void mISDN_deinitialize(void)
 {
        cleanup_layer3();
 
-       mISDN_debug_close();
-
        if (debug_fp)
                fclose(debug_fp);
        debug_fp = NULL;
@@ -1113,7 +1124,7 @@ void message_bchannel_from_remote(class JoinRemote *joinremote, int type, unsign
                chan_trace_header(mISDNport, isdnport, "MESSAGE_BCHANNEL (from remote application)", DIRECTION_NONE);
                add_trace("type", NULL, "export request");
                end_trace();
-               isdnport->p_m_remote_ref = joinremote->j_serial;
+               isdnport->p_m_remote_ref = joinremote->j_remote_ref;
                isdnport->p_m_remote_id = joinremote->j_remote_id;
                if (mISDNport && i>=0) {
                        bchannel_event(mISDNport, i, B_EVENT_EXPORTREQUEST);
@@ -1367,7 +1378,11 @@ void PmISDN::bchannel_receive(struct mISDNhead *hh, unsigned char *data, int len
                if ((cont&(~DTMF_TONE_MASK)) == DTMF_TONE_VAL) {
                        chan_trace_header(p_m_mISDNport, this, "BCHANNEL control", DIRECTION_IN);
                        add_trace("DTMF", NULL, "%c", cont & DTMF_TONE_MASK);
+                       if (!p_m_dtmf)
+                               add_trace("info", NULL, "DTMF is disabled");
                        end_trace();
+                       if (!p_m_dtmf)
+                               return;
                        message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DTMF);
                        message->param.dtmf = cont & DTMF_TONE_MASK;
                        PDEBUG(DEBUG_PORT, "PmISDN(%s) PH_CONTROL INDICATION  DTMF digit '%c'\n", p_name, message->param.dtmf);
@@ -1945,7 +1960,7 @@ static int l2establish_timeout(struct lcr_timer *timer, void *instance, int i)
        struct mISDNport *mISDNport = (struct mISDNport *)instance;
 
        if (!mISDNport->isloopback && mISDNport->l2hold && (mISDNport->ptp || !mISDNport->ntmode)) {
-//             PDEBUG(DEBUG_ISDN, "the L2 establish timer expired, we try to establish the link portnum=%d.\n", mISDNport->portnum);
+               PDEBUG(DEBUG_ISDN, "the L2 establish timer expired, we try to establish the link portnum=%d.\n", mISDNport->portnum);
                mISDNport->ml3->to_layer3(mISDNport->ml3, MT_L2ESTABLISH, 0, NULL);
                schedule_timer(&mISDNport->l2establish, 5, 0); /* 5 seconds */
        }
@@ -2032,6 +2047,7 @@ int do_layer3(struct mlayer3 *ml3, unsigned int cmd, unsigned int pid, struct l3
        struct mISDNport *mISDNport = (struct mISDNport *)ml3->priv;
        struct mbuffer *mb;
 
+#ifdef OLD_MT_ASSIGN
        /* special MT_ASSIGN handling:
         *
         * if we request a PID from mlayer, we always do it while lcr is locked.
@@ -2049,6 +2065,7 @@ int do_layer3(struct mlayer3 *ml3, unsigned int cmd, unsigned int pid, struct l3
                mt_assign_pid = pid;
                return(0);
        }
+#endif
        /* queue message, create, if required */
        if (!l3m) {
                l3m = alloc_l3_msg();
@@ -2289,7 +2306,7 @@ struct mISDNport *mISDNport_open(struct interface_port *ifport)
        if (ss5) {
                /* try to keep interface enabled */
                l1hold = 1;
-               l2hold = 1;
+               l2hold = 0;
        }
        /* set l2hold */
        switch (l2hold) {