chan_lcr: this fixes hanging with app_rxfax and a race condition
[lcr.git] / dss1.cpp
index 75f4a85..fea2e29 100644 (file)
--- a/dss1.cpp
+++ b/dss1.cpp
@@ -23,7 +23,7 @@ extern unsigned int mt_assign_pid;
 /*
  * constructor
  */
-Pdss1::Pdss1(int type, struct mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive) : PmISDN(type, mISDNport, portname, settings, channel, exclusive)
+Pdss1::Pdss1(int type, struct mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive, int mode) : PmISDN(type, mISDNport, portname, settings, channel, exclusive, mode)
 {
        p_callerinfo.itype = (mISDNport->ifport->interface->extension)?INFO_ITYPE_ISDN_EXTENSION:INFO_ITYPE_ISDN;
        p_m_d_ntmode = mISDNport->ntmode;
@@ -326,13 +326,22 @@ int Pdss1::hunt_bchannel(int channel, int exclusive)
                /* exclusive channel requests must be in the list */
                if (exclusive)
                {
+                       /* no exclusive channel */
                        if (!channel)
                        {
                                add_trace("conclusion", NULL, "exclusively requested channel not in list");
                                end_trace();
                                return(-6); // channel unacceptable
                        }
-                       i = selchannel->channel-1-(selchannel->channel>=17);
+                       /* get index for channel */
+                       i = channel-1-(channel>=17);
+                       if (i < 0 || i >= p_m_mISDNport->b_num || channel == 16)
+                       {
+                               add_trace("conclusion", NULL, "exclusively requested channel outside interface range");
+                               end_trace();
+                               return(-6); // channel unacceptable
+                       }
+                       /* check if busy */
                        if (p_m_mISDNport->b_port[i] == NULL)
                                goto use_channel;
                        add_trace("conclusion", NULL, "exclusively requested channel is busy");
@@ -343,7 +352,12 @@ int Pdss1::hunt_bchannel(int channel, int exclusive)
                /* requested channels in list will be used */
                if (channel)
                {
-                       i = selchannel->channel-1-(selchannel->channel>=17);
+                       /* get index for channel */
+                       i = channel-1-(channel>=17);
+                       if (i < 0 || i >= p_m_mISDNport->b_num || channel == 16)
+                       {
+                               add_trace("info", NULL, "requested channel %d outside interface range", channel);
+                       } else /* if inside range (else) check if available */
                        if (p_m_mISDNport->b_port[i] == NULL)
                                goto use_channel;
                }
@@ -655,6 +669,15 @@ void Pdss1::setup_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
                break;
        }
 
+       /* set bchannel mode */
+       if (p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED
+        || p_capainfo.bearer_capa==INFO_BC_DATARESTRICTED
+        || p_capainfo.bearer_capa==INFO_BC_VIDEO)
+               p_capainfo.source_mode = B_MODE_HDLC;
+       else
+               p_capainfo.source_mode = B_MODE_TRANSPARENT;
+       p_m_b_mode = p_capainfo.source_mode;
+
        /* hunt channel */
        ret = channel = hunt_bchannel(channel, exclusive);
        if (ret < 0)
@@ -1179,14 +1202,17 @@ void Pdss1::release_complete_ind(unsigned int cmd, unsigned int pid, struct l3_m
        
        l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_IND, DIRECTION_IN);
        /* in case layer 2 is down during setup, we send cause 27 loc 5 */
-       if (p_state == PORT_STATE_OUT_SETUP && !p_m_mISDNport->l1link)
+       if (p_state == PORT_STATE_OUT_SETUP && p_m_mISDNport->l1link == 0)
        {
                cause = 27;
                location = 5;
        } else
        {
                dec_ie_cause(l3m, &location, &cause);
-               add_trace("layer 1", NULL, (p_m_mISDNport->l1link)?"up":"down");
+               if (p_m_mISDNport->l1link < 0)
+                       add_trace("layer 1", NULL, "unknown");
+               else
+                       add_trace("layer 1", NULL, (p_m_mISDNport->l1link)?"up":"down");
        }
        end_trace();
        if (location == LOCATION_PRIVATE_LOCAL)
@@ -1518,6 +1544,7 @@ void Pdss1::resume_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
        if (ret < 0)
                goto no_channel;
 
+// mode (if hdlc parked) to be done. never mind, this is almost never requested
        /* open channel */
        ret = seize_bchannel(channel, 1);
        if (ret < 0)
@@ -2262,6 +2289,14 @@ void Pdss1::message_overlap(unsigned int epoint_id, int message_id, union parame
 {
        l3_msg *l3m;
 
+       /* in case of sending complete, we proceed */
+       if (p_dialinginfo.sending_complete)
+       {
+               PDEBUG(DEBUG_ISDN, "sending proceeding instead of setup_acknowledge, because address is complete.\n");
+               message_proceeding(epoint_id, message_id, param);
+               return;
+       }
+
        /* sending setup_acknowledge */
        l3m = create_l3msg();
        l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_REQ, DIRECTION_OUT);
@@ -2867,18 +2902,18 @@ int stack2manager(struct mISDNport *mISDNport, unsigned int cmd, unsigned int pi
        switch(cmd)
        {
                case MT_SETUP:
-               /* creating port object */
+               /* creating port object, transparent until setup with hdlc */
                SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
-               if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
+               if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
 
                        FATAL("Cannot create Port instance.\n");
                pdss1->message_isdn(cmd, pid, l3m);
                break;
 
                case MT_RESUME:
-               /* creating port object */
+               /* creating port object, transparent until setup with hdlc */
                SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
-               if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
+               if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
                        FATAL("Cannot create Port instance.\n");
                pdss1->message_isdn(cmd, pid, l3m);
                break;