fixed trace bug
[lcr.git] / dss1.cpp
index 59309b6..06bb203 100644 (file)
--- a/dss1.cpp
+++ b/dss1.cpp
@@ -16,7 +16,7 @@
 extern "C" {
 }
 #include <q931.h>
-extern unsigned long mt_assign_pid;
+extern unsigned int mt_assign_pid;
 
 #include "ie.cpp"
 
@@ -73,7 +73,7 @@ static struct l3_msg *create_l3msg(void)
  * return: <0: error, call is released, -cause is given
  *         0: ok, nothing to do
  */
-int Pdss1::received_first_reply_to_setup(unsigned long cmd, int channel, int exclusive)
+int Pdss1::received_first_reply_to_setup(unsigned int cmd, int channel, int exclusive)
 {
        int ret;
        l3_msg *l3m;
@@ -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;
                }
@@ -460,6 +474,7 @@ void Pdss1::setup_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
        dec_ie_channel_id(l3m, &exclusive, &channel);
        dec_ie_hlc(l3m, &hlc_coding, &hlc_interpretation, &hlc_presentation, &hlc_hlc, &hlc_exthlc);
        dec_ie_bearer(l3m, &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
+       dec_ie_display(l3m, (unsigned char *)p_dialinginfo.display, sizeof(p_dialinginfo.display));
        end_trace();
 
        /* if blocked, release call with MT_RELEASE_COMPLETE */
@@ -709,12 +724,13 @@ void Pdss1::setup_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
 void Pdss1::information_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
 {
        int type, plan;
-       unsigned char keypad[32] = "";
+       unsigned char keypad[32] = "", display[128] = "";
        struct lcr_msg *message;
 
        l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_IND, DIRECTION_IN);
        dec_ie_called_pn(l3m, &type, &plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
        dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
+       dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
        dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
        end_trace();
 
@@ -734,6 +750,7 @@ void Pdss1::information_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l
                p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
                break;
        }
+       SCAT(p_dialinginfo.display, (char *)display);
        message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
        memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
        message_put(message);
@@ -947,6 +964,7 @@ void Pdss1::connect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
        l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_IND, DIRECTION_IN);
        dec_ie_channel_id(l3m, &exclusive, &channel);
        dec_ie_connected_pn(l3m, &type, &plan, &present, &screen, (unsigned char *)p_connectinfo.id, sizeof(p_connectinfo.id));
+       dec_ie_display(l3m, (unsigned char *)p_connectinfo.display, sizeof(p_connectinfo.display));
        /* te-mode: CONP (connected name identification presentation) */
        if (!p_m_d_ntmode)
                dec_facility_centrex(l3m, (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
@@ -1036,10 +1054,12 @@ void Pdss1::disconnect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3
        int location, cause;
        int coding, proglocation, progress;
        struct lcr_msg *message;
+       unsigned char display[128] = "";
 
        l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
        dec_ie_progress(l3m, &coding, &proglocation, &progress);
        dec_ie_cause(l3m, &location, &cause);
+       dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
        end_trace();
 
        if (cause < 0)
@@ -1065,6 +1085,7 @@ void Pdss1::disconnect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3
                        message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
                        message->param.disconnectinfo.cause = cause;
                        message->param.disconnectinfo.location = location;
+                       SCAT(message->param.disconnectinfo.display, (char *)display);
                        message_put(message);
                        /* remove epoint */
                        free_epointlist(p_epointlist);
@@ -1082,6 +1103,7 @@ void Pdss1::disconnect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3
                message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
                message->param.disconnectinfo.location = location;
                message->param.disconnectinfo.cause = cause;
+               SCAT(message->param.disconnectinfo.display, (char *)display);
                message_put(message);
        }
        while(INACTIVE_EPOINT(p_epointlist))
@@ -1089,6 +1111,7 @@ void Pdss1::disconnect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3
                message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
                message->param.disconnectinfo.location = location;
                message->param.disconnectinfo.cause = cause;
+               SCAT(message->param.disconnectinfo.display, (char *)display);
                message_put(message);
                /* remove epoint */
                free_epointid(INACTIVE_EPOINT(p_epointlist));
@@ -1125,9 +1148,11 @@ void Pdss1::release_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
 {
        int location, cause;
        struct lcr_msg *message;
+       unsigned char display[128] = "";
 
        l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_IND, DIRECTION_IN);
        dec_ie_cause(l3m, &location, &cause);
+       dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
        end_trace();
 
        if (cause < 0)
@@ -1141,6 +1166,7 @@ void Pdss1::release_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
                message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
                message->param.disconnectinfo.cause = cause;
                message->param.disconnectinfo.location = location;
+               SCAT(message->param.disconnectinfo.display, (char *)display);
                message_put(message);
                /* remove epoint */
                free_epointlist(p_epointlist);
@@ -1150,6 +1176,15 @@ void Pdss1::release_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
        p_m_delete = 1;
 }
 
+/* CC_RESTART INDICATION */
+void Pdss1::restart_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
+{
+       l1l2l3_trace_header(p_m_mISDNport, this, L3_RESTART_IND, DIRECTION_IN);
+       end_trace();
+
+       // L3 process is not toucht. (not even by network stack)
+}
+
 /* CC_RELEASE_COMPLETE INDICATION (a reject) */
 void Pdss1::release_complete_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
 {
@@ -1158,14 +1193,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)
@@ -1201,10 +1239,12 @@ void Pdss1::notify_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
        struct lcr_msg *message;
        int notify, type, plan, present;
        unsigned char notifyid[sizeof(message->param.notifyinfo.id)];
+       unsigned char display[128] = "";
 
        l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_IND, DIRECTION_IN);
        dec_ie_notify(l3m, &notify);
        dec_ie_redir_dn(l3m, &type, &plan, &present, notifyid, sizeof(notifyid));
+       dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
        end_trace();
 
        if (!ACTIVE_EPOINT(p_epointlist))
@@ -1248,6 +1288,7 @@ void Pdss1::notify_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
                message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
                break;
        }
+       SCAT(message->param.notifyinfo.display, (char *)display);
        message->param.notifyinfo.isdn_port = p_m_portnum;
        message_put(message);
 }
@@ -1691,6 +1732,10 @@ void Pdss1::message_isdn(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
                release_complete_ind(cmd, pid, l3m);
                break;
 
+               case MT_RESTART:
+               restart_ind(cmd, pid, l3m);
+               break;
+
                case MT_NOTIFY:
                notify_ind(cmd, pid, l3m);
                break;
@@ -1827,7 +1872,7 @@ int Pdss1::handler(void)
  * handles all messages from endpoint
  */
 /* MESSAGE_INFORMATION */
-void Pdss1::message_information(unsigned long epoint_id, int message_id, union parameter *param)
+void Pdss1::message_information(unsigned int epoint_id, int message_id, union parameter *param)
 {
        l3_msg *l3m;
 
@@ -1836,6 +1881,8 @@ void Pdss1::message_information(unsigned long epoint_id, int message_id, union p
                l3m = create_l3msg();
                l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
                enc_ie_called_pn(l3m, 0, 1, (unsigned char *)param->information.id);
+               if (p_m_d_ntmode)
+                       enc_ie_display(l3m, (unsigned char *)param->information.display);
                end_trace();
                p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
        }
@@ -1846,7 +1893,7 @@ void Pdss1::message_information(unsigned long epoint_id, int message_id, union p
 int newteid = 0;
 
 /* MESSAGE_SETUP */
-void Pdss1::message_setup(unsigned long epoint_id, int message_id, union parameter *param)
+void Pdss1::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
 {
        l3_msg *l3m;
        int ret;
@@ -2118,7 +2165,7 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet
 }
 
 /* MESSAGE_FACILITY */
-void Pdss1::message_facility(unsigned long epoint_id, int message_id, union parameter *param)
+void Pdss1::message_facility(unsigned int epoint_id, int message_id, union parameter *param)
 {
        l3_msg *l3m;
 
@@ -2135,7 +2182,7 @@ void Pdss1::message_facility(unsigned long epoint_id, int message_id, union para
 }
 
 /* MESSAGE_NOTIFY */
-void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parameter *param)
+void Pdss1::message_notify(unsigned int epoint_id, int message_id, union parameter *param)
 {
        l3_msg *l3m;
        int notify;
@@ -2228,10 +2275,18 @@ void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parame
 }
 
 /* MESSAGE_OVERLAP */
-void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union parameter *param)
+void Pdss1::message_overlap(unsigned int epoint_id, int message_id, union parameter *param)
 {
        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);
@@ -2251,7 +2306,7 @@ void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union param
 }
 
 /* MESSAGE_PROCEEDING */
-void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union parameter *param)
+void Pdss1::message_proceeding(unsigned int epoint_id, int message_id, union parameter *param)
 {
        l3_msg *l3m;
 
@@ -2274,7 +2329,7 @@ void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union pa
 }
 
 /* MESSAGE_ALERTING */
-void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union parameter *param)
+void Pdss1::message_alerting(unsigned int epoint_id, int message_id, union parameter *param)
 {
        l3_msg *l3m;
 
@@ -2290,7 +2345,8 @@ void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union para
                if (p_capainfo.bearer_capa==INFO_BC_SPEECH
                 || p_capainfo.bearer_capa==INFO_BC_AUDIO
                 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
-               enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
+               if (p_m_mISDNport->tones)
+                       enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
                end_trace();
                p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
                new_state(PORT_STATE_IN_PROCEEDING);
@@ -2315,7 +2371,7 @@ void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union para
 }
 
 /* MESSAGE_CONNECT */
-void Pdss1::message_connect(unsigned long epoint_id, int message_id, union parameter *param)
+void Pdss1::message_connect(unsigned int epoint_id, int message_id, union parameter *param)
 {
        l3_msg *l3m;
        int type, plan, present, screen;
@@ -2329,11 +2385,6 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param
                l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
                /* channel information */
                enc_ie_channel_id(l3m, 1, p_m_b_channel);
-//             /* progress information */
-//             if (p_capainfo.bearer_capa==INFO_BC_SPEECH
-//              || p_capainfo.bearer_capa==INFO_BC_AUDIO
-//              || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
-//             enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
                end_trace();
                p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
                new_state(PORT_STATE_IN_PROCEEDING);
@@ -2437,7 +2488,7 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param
 }
 
 /* MESSAGE_DISCONNECT */
-void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union parameter *param)
+void Pdss1::message_disconnect(unsigned int epoint_id, int message_id, union parameter *param)
 {
        l3_msg *l3m;
        struct lcr_msg *message;
@@ -2480,6 +2531,7 @@ if (/*     ||*/ p_state==PORT_STATE_OUT_SETUP)
                if (p_capainfo.bearer_capa==INFO_BC_SPEECH
                 || p_capainfo.bearer_capa==INFO_BC_AUDIO
                 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
+               if (p_m_mISDNport->tones)
                        enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
                end_trace();
                p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
@@ -2508,7 +2560,7 @@ if (/*     ||*/ p_state==PORT_STATE_OUT_SETUP)
 }
 
 /* MESSAGE_RELEASE */
-void Pdss1::message_release(unsigned long epoint_id, int message_id, union parameter *param)
+void Pdss1::message_release(unsigned int epoint_id, int message_id, union parameter *param)
 {
        l3_msg *l3m;
        class Endpoint *epoint;
@@ -2541,8 +2593,6 @@ void Pdss1::message_release(unsigned long epoint_id, int message_id, union param
         */
        if (p_state==PORT_STATE_IN_SETUP
         || p_state==PORT_STATE_OUT_SETUP)
-// // NOTE: a bug in mISDNuser (see disconnect_req_out !!!)
-//      || p_state==PORT_STATE_OUT_DISCO)
        {
 //#warning remove me
 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
@@ -2576,6 +2626,7 @@ wirklich erst proceeding?:
                if (p_capainfo.bearer_capa==INFO_BC_SPEECH
                 || p_capainfo.bearer_capa==INFO_BC_AUDIO
                 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
+               if (p_m_mISDNport->tones)
                        enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
                end_trace();
                p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
@@ -2613,7 +2664,7 @@ wirklich erst proceeding?:
 /*
  * endpoint sends messages to the port
  */
-int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
+int Pdss1::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
 {
        struct lcr_msg *message;