Added display of current active TEI values (L2) at lcradmin.
[lcr.git] / mISDN.cpp
index 97f7b3e..2cbd39f 100644 (file)
--- a/mISDN.cpp
+++ b/mISDN.cpp
@@ -64,14 +64,14 @@ int mISDN_initialize(void)
        /* open debug, if enabled and not only stack debugging */
        if (options.deb)
        {
-               SPRINT(filename, "%s/debug.log", INSTALL_DATA);
+               SPRINT(filename, "%s/debug.log", LOG_DIR);
                debug_fp = fopen(filename, "a");
        }
 
        if (options.deb & DEBUG_STACK)
        {
-               SPRINT(filename, "%s/debug_mISDN.log", INSTALL_DATA);
-               mISDN_debug_init(0xffffffff, filename, filename, filename);
+               SPRINT(filename, "%s/debug_mISDN.log", LOG_DIR);
+               mISDN_debug_init(0xfffffeff, filename, filename, filename);
        } else
                mISDN_debug_init(0, NULL, NULL, NULL);
 
@@ -221,7 +221,7 @@ static struct isdn_message {
        {"PH_DEACTIVATE", L1_DEACTIVATE_REQ},
        {"DL_ESTABLISH", L2_ESTABLISH_REQ},
        {"DL_RELEASE", L2_RELEASE_REQ},
-       {"UNKNOWN", L3_UNKNOWN},
+       {"UNKNOWN", L3_UNKNOWN_REQ},
        {"MT_TIMEOUT", L3_TIMEOUT_REQ},
        {"MT_SETUP", L3_SETUP_REQ},
        {"MT_SETUP_ACK", L3_SETUP_ACKNOWLEDGE_REQ},
@@ -270,6 +270,7 @@ void l1l2l3_trace_header(struct mISDNport *mISDNport, class PmISDN *port, unsign
        i = 0;
        while(isdn_message[i].name)
        {
+//             if (msg == L3_NOTIFY_REQ) printf("val = %x %s\n", isdn_message[i].value, isdn_message[i].name);
                if (isdn_message[i].value == (msg&0xffffff00))
                {
                        SCPY(msgtext, isdn_message[i].name);
@@ -406,7 +407,7 @@ static int _bchannel_create(struct mISDNport *mISDNport, int i)
        ret = bind(mISDNport->b_socket[i], (struct sockaddr *)&addr, sizeof(addr));
        if (ret < 0)
        {
-               PERROR("Error: Failed to bind bchannel-socket for index %d with mISDN-DSP layer. Did you load mISDN_dsp.ko?\n", i);
+               PERROR("Error: Failed to bind bchannel-socket for index %d with mISDN-DSP layer (errno=%d). Did you load mISDN_dsp.ko?\n", i, errno);
                close(mISDNport->b_socket[i]);
                mISDNport->b_socket[i] = -1;
                return(0);
@@ -1534,7 +1535,7 @@ void PmISDN::set_echotest(int echo)
  */
 void PmISDN::set_tone(const char *dir, const char *tone)
 {
-       int id;
+       int id = TONE_OFF;
 
        if (!tone)
                tone = "";
@@ -1560,11 +1561,9 @@ void PmISDN::set_tone(const char *dir, const char *tone)
                Port::set_tone(dir, tone);
                return;
        }
-       if (p_tone_dir[0])
-               goto nodsp;
 
        /* now we USE dsp-tone, convert name */
-       else if (!strcmp(tone, "dialtone"))
+       if (!strcmp(tone, "dialtone"))
        {
                switch(options.dsptones) {
                case DSP_AMERICAN: id = TONE_AMERICAN_DIALTONE; break;
@@ -1954,15 +1953,21 @@ int mISDN_handler(void)
                        switch(l3m->type)
                        {
                                case MPH_ACTIVATE_IND:
-                               l1l2l3_trace_header(mISDNport, NULL, L1_ACTIVATE_IND, DIRECTION_IN);
-                               end_trace();
-                               mISDNport->l1link = 1;
+                               if (mISDNport->l1link != 1)
+                               {
+                                       l1l2l3_trace_header(mISDNport, NULL, L1_ACTIVATE_IND, DIRECTION_IN);
+                                       end_trace();
+                                       mISDNport->l1link = 1;
+                               }
                                break;
        
                                case MPH_DEACTIVATE_IND:
-                               l1l2l3_trace_header(mISDNport, NULL, L1_DEACTIVATE_IND, DIRECTION_IN);
-                               end_trace();
-                               mISDNport->l1link = 0;
+                               if (mISDNport->l1link != 0)
+                               {
+                                       l1l2l3_trace_header(mISDNport, NULL, L1_DEACTIVATE_IND, DIRECTION_IN);
+                                       end_trace();
+                                       mISDNport->l1link = 0;
+                               }
                                break;
 
                                case MPH_INFORMATION_IND:
@@ -2000,6 +2005,9 @@ int mISDN_handler(void)
                                l1l2l3_trace_header(mISDNport, NULL, L2_ESTABLISH_IND, DIRECTION_IN);
                                add_trace("tei", NULL, "%d", l3m->pid);
                                end_trace();
+                               mISDNport->l2link = 1;
+                               if (l3m->pid < 128)
+                                       mISDNport->l2mask[l3m->pid >> 3] |= (1 << (l3m->pid & 7));
                                if ((!mISDNport->ntmode || mISDNport->ptp) && l3m->pid < 127)
                                {
                                        if (mISDNport->l2establish)
@@ -2007,20 +2015,23 @@ int mISDN_handler(void)
                                                mISDNport->l2establish = 0;
                                                PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
                                        }
-                                       mISDNport->l2link = 1;
                                }
                                break;
 
                                case MT_L2RELEASE:
+                               if (l3m->pid < 128)
+                                       mISDNport->l2mask[l3m->pid >> 3] &= ~(1 << (l3m->pid & 7));
                                if (!mISDNport->l2establish)
                                {
                                        l1l2l3_trace_header(mISDNport, NULL, L2_RELEASE_IND, DIRECTION_IN);
                                        add_trace("tei", NULL, "%d", l3m->pid);
                                        end_trace();
+                                       /* down if not nt-ptmp */ 
+                                       if (!mISDNport->ntmode || mISDNport->ptp)
+                                               mISDNport->l2link = 0;
                                }
                                if ((!mISDNport->ntmode || mISDNport->ptp) && l3m->pid < 127)
                                {
-                                       mISDNport->l2link = 0;
                                        if (!mISDNport->l2establish && mISDNport->l2hold)
                                        {
                                                PDEBUG(DEBUG_ISDN, "set timer and establish.\n");
@@ -2117,7 +2128,7 @@ int do_layer3(struct mlayer3 *ml3, unsigned int cmd, unsigned int pid, struct l3
 /*
  * global function to add a new card (port)
  */
-struct mISDNport *mISDNport_open(int port, char *portname, int ptp, int force_nt, int l2hold, struct interface *interface)
+struct mISDNport *mISDNport_open(int port, char *portname, int ptp, int force_nt, int te_special, int l1hold, int l2hold, struct interface *interface)
 {
        int ret;
        struct mISDNport *mISDNport, **mISDNportp;
@@ -2160,7 +2171,7 @@ struct mISDNport *mISDNport_open(int port, char *portname, int ptp, int force_nt
                }
                if (port == cnt)
                {
-                       PERROR_RUNTIME("Port name '%s' no found, use 'misdn_info' tool to list all existing ports.\n", portname);
+                       PERROR_RUNTIME("Port name '%s' not found, use 'misdn_info' tool to list all existing ports.\n", portname);
                        return(NULL);
                }
                // note: 'port' has still the port number
@@ -2270,6 +2281,7 @@ struct mISDNport *mISDNport_open(int port, char *portname, int ptp, int force_nt
                mISDNportp = &((*mISDNportp)->next);
        mISDNport = (struct mISDNport *)MALLOC(sizeof(struct mISDNport));
        mISDNport->l1link = -1;
+       mISDNport->l2link = -1;
        pmemuse++;
        *mISDNportp = mISDNport;
 
@@ -2302,6 +2314,8 @@ struct mISDNport *mISDNport_open(int port, char *portname, int ptp, int force_nt
               prop |= (1 << MISDN_FLG_PTP);
        if (nt) // supports hold/retrieve on nt-mode
               prop |= (1 << MISDN_FLG_NET_HOLD);
+       if (l1hold) // supports layer 1 hold
+              prop |= (1 << MISDN_FLG_L1_HOLD);
        if (l2hold) // supports layer 2 hold
               prop |= (1 << MISDN_FLG_L2_HOLD);
        /* queue must be initializes, because l3-thread may send messages during open_layer3() */
@@ -2344,8 +2358,10 @@ struct mISDNport *mISDNport_open(int port, char *portname, int ptp, int force_nt
        mISDNport->b_num = devinfo.nrbchan;
        mISDNport->portnum = port;
        mISDNport->ntmode = nt;
+       mISDNport->tespecial = te_special;
        mISDNport->pri = pri;
        mISDNport->ptp = ptp;
+       mISDNport->l1hold = l1hold;
        mISDNport->l2hold = l2hold;
        PDEBUG(DEBUG_ISDN, "Port has %d b-channels.\n", mISDNport->b_num);
        i = 0;
@@ -2366,8 +2382,9 @@ struct mISDNport *mISDNport_open(int port, char *portname, int ptp, int force_nt
                time(&mISDNport->l2establish);
        }
 
-       /* initially, we assume that the link is down, exept for nt-ptmp */
-       mISDNport->l2link = (mISDNport->ntmode && !mISDNport->ptp)?1:0;
+       /* for nt-mode ptmp the link is always up */
+       if (mISDNport->ntmode && !mISDNport->ptp)
+               mISDNport->l2link = 1;
 
        PDEBUG(DEBUG_BCHANNEL, "using 'mISDN_dsp.o' module\n");