some minor fixes
[lcr.git] / dss1.cpp
index 06b1098..2df2645 100644 (file)
--- a/dss1.cpp
+++ b/dss1.cpp
@@ -1180,14 +1180,10 @@ void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
        struct lcr_msg *message;
        int bchannel_before;
 
+#ifndef SOCKET_MISDN
        if (p_m_d_ntmode)
-       {
-#ifdef SOCKET_MISDN
-               p_m_d_ces = pid >> 16;
-#else
                p_m_d_ces = connect->ces;
 #endif
-       }
 
        l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_IND, DIRECTION_IN);
 #ifdef SOCKET_MISDN
@@ -2203,7 +2199,7 @@ void Pdss1::message_isdn(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
                case MT_SETUP_ACKNOWLEDGE:
                if (p_state != PORT_STATE_OUT_SETUP)
                {
-                       PERROR("Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
+                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
                        break;
                }
                setup_acknowledge_ind(cmd, pid, l3m);
@@ -2213,7 +2209,7 @@ void Pdss1::message_isdn(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
                if (p_state != PORT_STATE_OUT_SETUP
                 && p_state != PORT_STATE_OUT_OVERLAP)
                {
-                       PERROR("Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
+                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
                        break;
                }
                proceeding_ind(cmd, pid, l3m);
@@ -2224,7 +2220,7 @@ void Pdss1::message_isdn(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
                 && p_state != PORT_STATE_OUT_OVERLAP
                 && p_state != PORT_STATE_OUT_PROCEEDING)
                {
-                       PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
+                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
                        break;
                }
                alerting_ind(cmd, pid, l3m);
@@ -2236,7 +2232,7 @@ void Pdss1::message_isdn(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
                 && p_state != PORT_STATE_OUT_PROCEEDING
                 && p_state != PORT_STATE_OUT_ALERTING)
                {
-                       PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
+                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
                        break;
                }
                connect_ind(cmd, pid, l3m);
@@ -4054,15 +4050,23 @@ int stack2manager(struct mISDNport *mISDNport, unsigned int cmd, unsigned int pi
        while(port)
        {
                /* are we ISDN ? */
-               if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
+               if ((port->p_type & PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
                {
                        pdss1 = (class Pdss1 *)port;
                        /* check out correct stack and id */
-                       if (pdss1->p_m_mISDNport == mISDNport
-                        && (pdss1->p_m_d_l3id & MISDN_PID_CRVAL_MASK) == (pid & MISDN_PID_CRVAL_MASK))
+                       if (pdss1->p_m_mISDNport == mISDNport)
                        {
-                               /* found port, the message belongs to */
-                               break;
+                               if (pdss1->p_m_d_l3id & MISDN_PID_CR_FLAG)
+                               {
+                                       /* local callref, so match value only */
+                                       if ((pdss1->p_m_d_l3id & MISDN_PID_CRVAL_MASK) == (pid & MISDN_PID_CRVAL_MASK))
+                                               break; // found
+                               } else
+                               {
+                                       /* remote callref, ref + channel id */
+                                       if (pdss1->p_m_d_l3id == pid)
+                                               break; // found
+                               }
                        }
                }
                port = port->next;
@@ -4080,6 +4084,8 @@ int stack2manager(struct mISDNport *mISDNport, unsigned int cmd, unsigned int pi
                        if ((pdss1->p_m_d_l3id&MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER)
                                PERROR("    strange setup-procid 0x%x\n", pdss1->p_m_d_l3id);
                        pdss1->p_m_d_l3id = pid;
+                       if (port->p_state == PORT_STATE_CONNECT)
+                               pdss1->p_m_d_ces = pid >> 16;
                        add_trace("callref", "new", "0x%x", pdss1->p_m_d_l3id);
                        end_trace();
                        return(0);
@@ -4099,9 +4105,15 @@ int stack2manager(struct mISDNport *mISDNport, unsigned int cmd, unsigned int pi
                        if (cmd == MT_RELEASE_COMPLETE)
                                return(0);
                }
-               /* if process id and layer 3 id matches */
-//             if (pid == pdss1->p_m_d_l3id)
-                       pdss1->message_isdn(cmd, pid, l3m);
+               /* if we have child pid and got different child pid message, ignore */
+               if (mISDNport->ntmode
+                && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
+                && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
+                && pid != pdss1->p_m_d_l3id)
+                       return(0);
+
+               /* process message */
+               pdss1->message_isdn(cmd, pid, l3m);
                return(0);
        }