backup
[lcr.git] / dss1.cpp
index cbfc822..c1feb73 100644 (file)
--- a/dss1.cpp
+++ b/dss1.cpp
@@ -45,7 +45,6 @@ Pdss1::Pdss1(int type, mISDNport *mISDNport, char *portname, struct port_setting
        p_m_d_collect_cause = CAUSE_NOUSER;
        p_m_d_collect_location = LOCATION_PRIVATE_LOCAL;
 
-
        PDEBUG(DEBUG_ISDN, "Created new mISDNPort(%s). Currently %d objects use, %s port #%d\n", portname, mISDNport->use, (mISDNport->ntmode)?"NT":"TE", p_m_portnum);
 }
 
@@ -137,7 +136,6 @@ msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */
        exit(-1);
 }
 
-
 /* isdn messaging */
 static struct isdn_message {
        char *name;
@@ -145,30 +143,30 @@ static struct isdn_message {
 } isdn_message[] = {
        {"TIMEOUT", CC_TIMEOUT},
        {"SETUP", CC_SETUP},
-       {"SETUP_ACKNOWLEDGE", CC_SETUP_ACKNOWLEDGE},
+       {"SETUP_ACK", CC_SETUP_ACKNOWLEDGE},
        {"PROCEEDING", CC_PROCEEDING},
        {"ALERTING", CC_ALERTING},
        {"CONNECT", CC_CONNECT},
-       {"CONNECT RESPONSE", CC_CONNECT},
-       {"CONNECT_ACKNOWLEDGE", CC_CONNECT_ACKNOWLEDGE},
+       {"CONNECT RES", CC_CONNECT},
+       {"CONNECT_ACK", CC_CONNECT_ACKNOWLEDGE},
        {"DISCONNECT", CC_DISCONNECT},
        {"RELEASE", CC_RELEASE},
-       {"RELEASE_COMPLETE", CC_RELEASE_COMPLETE},
+       {"RELEASE_COMP", CC_RELEASE_COMPLETE},
        {"INFORMATION", CC_INFORMATION},
        {"PROGRESS", CC_PROGRESS},
        {"NOTIFY", CC_NOTIFY},
        {"SUSPEND", CC_SUSPEND},
-       {"SUSPEND_ACKNOWLEDGE", CC_SUSPEND_ACKNOWLEDGE},
-       {"SUSPEND_REJECT", CC_SUSPEND_REJECT},
+       {"SUSPEND_ACK", CC_SUSPEND_ACKNOWLEDGE},
+       {"SUSPEND_REJ", CC_SUSPEND_REJECT},
        {"RESUME", CC_RESUME},
-       {"RESUME_ACKNOWLEDGE", CC_RESUME_ACKNOWLEDGE},
-       {"RESUME_REJECTE", CC_RESUME_REJECT},
+       {"RESUME_ACK", CC_RESUME_ACKNOWLEDGE},
+       {"RESUME_REJ", CC_RESUME_REJECT},
        {"HOLD", CC_HOLD},
-       {"HOLD_ACKNOWLEDGE", CC_HOLD_ACKNOWLEDGE},
-       {"HOLD_REJECT", CC_HOLD_REJECT},
+       {"HOLD_ACK", CC_HOLD_ACKNOWLEDGE},
+       {"HOLD_REJ", CC_HOLD_REJECT},
        {"RETRIEVE", CC_RETRIEVE},
-       {"RETRIEVE_ACKNOWLEDGE", CC_RETRIEVE_ACKNOWLEDGE},
-       {"RETRIEVE_REJECTE", CC_RETRIEVE_REJECT},
+       {"RETRIEVE_ACK", CC_RETRIEVE_ACKNOWLEDGE},
+       {"RETRIEVE_REJ", CC_RETRIEVE_REJECT},
        {"FACILITY", CC_FACILITY},
        {"STATUS", CC_STATUS},
        {"RESTART", CC_RESTART},
@@ -179,34 +177,60 @@ static struct isdn_message {
 };
 
 static char *isdn_prim[4] = {
-       "REQUEST",
-       "CONFIRM",
-       "INDICATION",
-       "RESPONSE",
+       " REQUEST",
+       " CONFIRM",
+       " INDICATION",
+       " RESPONSE",
 };
 
 
 /*
- * show message to debug
+ * isdn trace header
  */
-void Pdss1::isdn_show_send_message(unsigned long prim, msg_t *msg)
+void Pdss1::l3_trace_header(unsigned long prim, int direction_out)
 {
        int i;
-       char *msgtext = "<<UNKNOWN MESSAGE>>";
-       char *primtext;
+       char msgtext[64] = "<<UNKNOWN MESSAGE>>";
 
+       /* select message and primitive text */
        i = 0;
        while(isdn_message[i].name)
        {
                if (isdn_message[i].value == (prim&0xffffff00))
                {
-                       msgtext = isdn_message[i].name;
+                       SCPY(msgtext, isdn_message[i].name);
                        break;
                }
                i++;
        }
-       primtext = isdn_prim[prim&0x00000003];
-       printisdn(">>> outgoing prim: %s %s (0x%x)\n", msgtext, primtext, prim);
+       SCAT(msgtext, isdn_prim[prim&0x00000003]);
+
+       /* add direction */
+       if (direction && (prim&0xffffff00)!=CC_NEW_CR && (prim&0xffffff00)!=CC_RELEASE_CR)
+       {
+               if (p_m_ntmode)
+               {
+                       if (direction == DIRECTION_OUT)
+                               SCAT(msgtext, " N->U");
+                       else
+                               SCAT(msgtext, " N<-U");
+               } else
+               {
+                       if (direction == DIRECTION_OUT)
+                               SCAT(msgtext, " U->N");
+                       else
+                               SCAT(msgtext, " U<-N");
+               }
+       }
+
+       /* init trace with given values */
+       start_trace(p_m_mISDNport->portnum,
+                   p_m_mISDNport->ifport->interface,
+                   nationalize(p_callerinfo.id, p_callerinfo.ntype),
+                   p_dialinginfo.number,
+                   direction,
+                   CATEGORY_L3,
+                   msgtext);
 }
 
 
@@ -223,7 +247,7 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex
        RELEASE_COMPLETE_t *release_complete;
        msg_t *dmsg;
 
-       /* corret exclusive to 0, if no explicit channel was given */
+       /* correct exclusive to 0, if no explicit channel was given */
        if (exclusive<0 || channel<=0)
                exclusive = 0;
        
@@ -236,14 +260,29 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex
                if (p_state != PORT_STATE_OUT_SETUP)
                        return(0);
 
+               start_trace(p_m_mISDNport->portnum,
+                           p_m_mISDNport->ifport->interface,
+                           nationalize(p_callerinfo.id, p_callerinfo.ntype),
+                           p_dialinginfo.number,
+                           DIRECTION_OUT,
+                           CATEGORY_CH,
+                           "CHANNEL SELECTION (first reply to setup)");
+               add_trace("channel", "request", "%d (forced)", p_m_b_channel);
+               add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
+
                /* if give channel not accepted or not equal */
                if (channel!=-1 && p_m_b_channel!=channel)
                {
-                       PDEBUG(DEBUG_BCHANNEL, "- our forced channel %d was not accepted\n", p_m_b_channel);
+                       add_trace("conclusion", NULL, "forced channel not accepted");
+                       end_trace();
                        ret = -44;
                        goto channelerror;
                }
 
+               add_trace("conclusion", NULL, "channel was accepted");
+               add_trace("connect", "channel", "%d", p_m_b_channel);
+               end_trace();
+
                /* activate our exclusive channel */
                bchannel_activate(p_m_mISDNport, p_m_b_index);
        } else
@@ -255,10 +294,22 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex
                if (p_state != PORT_STATE_OUT_SETUP)
                        return(0);
 
+               start_trace(p_m_mISDNport->portnum,
+                           p_m_mISDNport->ifport->interface,
+                           nationalize(p_callerinfo.id, p_callerinfo.ntype),
+                           p_dialinginfo.number,
+                           DIRECTION_OUT,
+                           CATEGORY_CH,
+                           "CHANNEL SELECTION (first reply to setup)");
+               add_trace("channel", "request", "%d (suggest)", p_m_b_channel);
+               add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
+
                /* if channel was accepted as given */
                if (channel==-1 || p_m_b_channel==channel)
                {
-                       PDEBUG(DEBUG_BCHANNEL, "- our suggested channel %d was accpted\n", p_m_b_channel);
+                       add_trace("conclusion", NULL, "channel was accepted as given");
+                       add_trace("connect", "channel", "%d", p_m_b_channel);
+                       end_trace();
                        p_m_b_exclusive = 1; // we are done
                        bchannel_activate(p_m_mISDNport, p_m_b_index);
                        return(0);
@@ -267,20 +318,24 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex
                /* if channel value is faulty */
                if (channel <= 0)
                {
-                       PDEBUG(DEBUG_BCHANNEL, "- our suggested channel %d was replied with no channel value.\n", p_m_b_channel);
+                       add_trace("conclusion", NULL, "illegal reply");
+                       end_trace();
                        ret = -111; // protocol error
                        goto channelerror;
                }
 
                /* if channel was not accepted, try to get it */
-               PDEBUG(DEBUG_BCHANNEL, "- our suggested channel %d was not accepted, but %d was given.\n", p_m_b_channel, channel);
                ret = seize_bchannel(channel, 1); // exclusively
+               add_trace("channel", "available", ret<0?"no":"yes");
                if (ret < 0)
                {
-                       PDEBUG(DEBUG_BCHANNEL, "- the replied channel %d is not available (cause %d).\n", channel, -ret);
+                       add_trace("conclusion", NULL, "replied channel not available");
+                       end_trace();
                        goto channelerror;
                }
-               PDEBUG(DEBUG_BCHANNEL, "- we accepted channel %d.\n", channel);
+               add_trace("conclusion", NULL, "replied channel accepted");
+               add_trace("connect", "channel", "%d", p_m_b_channel);
+               end_trace();
 
                /* activate channel given by remote */
                bchannel_activate(p_m_mISDNport, p_m_b_index);
@@ -293,23 +348,36 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex
                if (p_state != PORT_STATE_OUT_SETUP)
                        return(0);
 
-               /* if no channel was given */
+               start_trace(p_m_mISDNport->portnum,
+                           p_m_mISDNport->ifport->interface,
+                           nationalize(p_callerinfo.id, p_callerinfo.ntype),
+                           p_dialinginfo.number,
+                           DIRECTION_OUT,
+                           CATEGORY_CH,
+                           "CHANNEL SELECTION (first reply to setup)");
+               add_trace("channel", "request", "any");
+               add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
+               /* if no channel was replied */
                if (channel <= 0)
                {
-                       PDEBUG(DEBUG_BCHANNEL, "- our channel request was not replied by a channel.\n", p_m_b_channel);
+                       add_trace("conclusion", NULL, "no channel, protocol error");
+                       end_trace();
                        ret = -111; // protocol error
                        goto channelerror;
                }
 
                /* we will see, if our received channel is available */
-               PDEBUG(DEBUG_BCHANNEL, "- our channel request was replied with channel %d.\n", channel);
                ret = seize_bchannel(channel, 1); // exclusively
+               add_trace("channel", "available", ret<0?"no":"yes");
                if (ret < 0)
                {
-                       PDEBUG(DEBUG_BCHANNEL, "- the replied channel %d is not available (cause %d).\n", channel, -ret);
+                       add_trace("conclusion", NULL, "replied channel not available");
+                       end_trace();
                        goto channelerror;
                }
-               PDEBUG(DEBUG_BCHANNEL, "- we accepted channel %d.\n", channel);
+               add_trace("conclusion", NULL, "replied channel accepted");
+               add_trace("connect", "channel", "%d", p_m_b_channel);
+               end_trace();
 
                /* activate channel given by remote */
                bchannel_activate(p_m_mISDNport, p_m_b_index);
@@ -320,18 +388,30 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex
                /* if not the first reply, but a connect, we are forced */
                if (prim==(CC_CONNECT | INDICATION) && p_state!=PORT_STATE_OUT_SETUP)
                {
+                       start_trace(p_m_mISDNport->portnum,
+                                   p_m_mISDNport->ifport->interface,
+                                   nationalize(p_callerinfo.id, p_callerinfo.ntype),
+                                   p_dialinginfo.number,
+                                   DIRECTION_OUT,
+                                   CATEGORY_CH,
+                                   "CHANNEL SELECTION (connect)");
+                       add_trace("channel", "request", "no-channel");
+                       add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":"");
                        if (channel > 0)
                        {
-                               PDEBUG(DEBUG_BCHANNEL, "- while call-waiting, we get a channel inside connect message, so we use it.\n", p_m_b_channel);
                                goto use_from_connect;
                        }
-                       PDEBUG(DEBUG_BCHANNEL, "- there is no channel inside connect message during call-waiting, so we request one.\n", p_m_b_channel);
                        ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
+                       add_trace("channel", "available", ret<0?"no":"yes");
                        if (ret < 0)
                        {
-                               PDEBUG(DEBUG_BCHANNEL, "- during call-waiting, we got a connect, but no available channel (cause=%d).\n", -ret);
+                               add_trace("conclusion", NULL, "no channel available during call-waiting");
+                               end_trace();
                                goto channelerror;
                        }
+                       add_trace("conclusion", NULL, "using channel %d", p_m_b_channel);
+                       add_trace("connect", "channel", "%d", p_m_b_channel);
+                       end_trace();
                        p_m_b_exclusive = 1; // we are done
 
                        /* activate channel given by remote */
@@ -343,23 +423,36 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex
                if (p_state != PORT_STATE_OUT_SETUP)
                        return(0);
 
+               start_trace(p_m_mISDNport->portnum,
+                           p_m_mISDNport->ifport->interface,
+                           nationalize(p_callerinfo.id, p_callerinfo.ntype),
+                           p_dialinginfo.number,
+                           DIRECTION_OUT,
+                           CATEGORY_CH,
+                           "CHANNEL SELECTION (first reply to setup)");
+               add_trace("channel", "request", "no-channel");
+               add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
                /* if first reply has no channel, we are done */
                if (channel <= 0)
                {
-                       PDEBUG(DEBUG_BCHANNEL, "- while call-waiting, we got no channel as first reply, this is good.\n");
+                       add_trace("conclusion", NULL, "no channel until connect");
+                       end_trace();
                        return(0);
                }
 
                /* we will see, if our received channel is available */
-               PDEBUG(DEBUG_BCHANNEL, "- our during call-waiting, we get channel %d as first reply.\n", channel);
                use_from_connect:
                ret = seize_bchannel(channel, exclusive);
-               if (ret <= 0)
+               add_trace("channel", "available", ret<0?"no":"yes");
+               if (ret < 0)
                {
-                       PDEBUG(DEBUG_BCHANNEL, "- the given channel %d is not available (cause %d).\n", channel, -ret);
+                       add_trace("conclusion", NULL, "replied channel not available");
+                       end_trace();
                        goto channelerror;
                }
-               PDEBUG(DEBUG_BCHANNEL, "- we accepted channel %d.\n", channel);
+               add_trace("conclusion", NULL, "replied channel accepted");
+               add_trace("connect", "channel", "%d", p_m_b_channel);
+               end_trace();
                p_m_b_exclusive = 1; // we are done
 
                /* activate channel given by remote */
@@ -369,10 +462,11 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex
 
        channelerror:
        dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
-       isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
+       l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
 
        release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
        enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
+       end_trace();
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        new_state(PORT_STATE_RELEASE);
        p_m_delete = 1;
@@ -399,6 +493,43 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
        class Endpoint *epoint;
        struct message *message;
 
+       /* callref from nt-lib */
+       if (p_m_d_ntmode)
+       {
+               /* nt-library now gives us the id via CC_SETUP */
+               if (dinfo&(~0xff) == 0xff00)
+               {
+                       PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
+                       exit(-1);
+               }
+               l3_trace_header(CC_NEW_CR | INDICATION, DIRECTION_IN);
+               if (p_m_d_l3id)
+                       add_trace("callref", "old", "0x%x", p_m_d_l3id);
+               add_trace("callref", "new", "0x%x", dinfo);
+               end_trace();
+               if (p_m_d_l3id&(~0xff) == 0xff00)
+                       p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
+               p_m_d_l3id = dinfo;
+               p_m_d_ces = setup->ces;
+       }
+
+       l3_trace_header(prim, DIRECTION_IN);
+       dec_ie_calling_pn(setup->CALLING_PN, (Q931_info_t *)((unsigned long)data+headerlen), &calling_type, &calling_plan, &calling_present, &calling_screen, (unsigned char *)p_callerinfo.id, sizeof(p_callerinfo.id));
+       dec_ie_called_pn(setup->CALLED_PN, (Q931_info_t *)((unsigned long)data+headerlen), &called_type, &called_plan, (unsigned char *)p_dialinginfo.number, sizeof(p_dialinginfo.number));
+       dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
+#ifdef CENTREX
+       /* te-mode: CNIP (calling name identification presentation) */
+       if (!p_m_d_ntmode)
+               dec_facility_centrex(setup->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
+#endif
+       dec_ie_useruser(setup->USER_USER, (Q931_info_t *)((unsigned long)data+headerlen), &useruser_protocol, useruser, &useruser_len);
+       dec_ie_complete(setup->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
+       dec_ie_redir_nr(setup->REDIR_NR, (Q931_info_t *)((unsigned long)data+headerlen), &redir_type, &redir_plan, &redir_present, &redir_screen, &redir_reason, (unsigned char *)p_redirinfo.id, sizeof(p_redirinfo.id));
+       dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
+       dec_ie_hlc(setup->HLC, (Q931_info_t *)((unsigned long)data+headerlen), &hlc_coding, &interpretation, &presentation, &hlc, &exthlc);
+       dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &bearer_coding, &capability, &mode, &rate, &multi, &user);
+       end_trace();
+
        /* if blocked, release call */
        if (p_m_mISDNport->ifport->block)
        {
@@ -406,17 +537,18 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
 
                printlog("---  port#%d is blocked.\n", mISDNport->ifport->portnum);
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
+               l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
+               add_trace("reason", NULL, "port blocked");
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                new_state(PORT_STATE_RELEASE);
                p_m_delete = 1;
                return;
        }
-       
-       /* caller information */
-       dec_ie_calling_pn(setup->CALLING_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, &screen, (unsigned char *)p_callerinfo.id, sizeof(p_callerinfo.id));
+
+       /* caller info */
        switch (present)
        {
                case 1:
@@ -459,9 +591,9 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
                break;
        }
        p_callerinfo.isdn_port = p_m_portnum;
+       SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
+
        /* dialing information */
-       dec_ie_called_pn(setup->CALLED_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, (unsigned char *)p_dialinginfo.number, sizeof(p_dialinginfo.number));
-       dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
        SCAT(p_dialinginfo.number, (char *)keypad);
        switch (type)
        {
@@ -478,19 +610,6 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
                p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
                break;
        }
-#ifdef CENTREX
-       /* te-mode: CNIP (calling name identification presentation) */
-       if (!p_m_d_ntmode)
-               dec_facility_centrex(setup->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
-#endif
-
-       /* uus */ 
-       dec_ie_useruser(setup->USER_USER, (Q931_info_t *)((unsigned long)data+headerlen), &useruser_protocol, useruser, &useruser_len);
-
-       /* sending complete */
-       dec_ie_complete(setup->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
-       /* redirecting number */
-       dec_ie_redir_nr(setup->REDIR_NR, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, &screen, &reason, (unsigned char *)p_redirinfo.id, sizeof(p_redirinfo.id));
        switch (present)
        {
                case 1:
@@ -554,8 +673,8 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
                break;
        }
        p_redirinfo.isdn_port = p_m_portnum;
+
        /* bearer capability */
-       dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &capability, &mode, &rate, &multi, &user);
        switch (capability)
        {
                case -1:
@@ -586,7 +705,6 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
        }
 
        /* hlc */
-       dec_ie_hlc(setup->HLC, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &interpretation, &presentation, &hlc, &exthlc);
        switch (hlc)
        {
                case -1:
@@ -606,73 +724,39 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
                break;
        }
 
-       /* channel_id */
-       dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
+       /* process channel */
+       start_trace(p_m_mISDNport->portnum,
+                   p_m_mISDNport->ifport->interface,
+                   nationalize(p_callerinfo.id, p_callerinfo.ntype),
+                   p_dialinginfo.number,
+                   DIRECTION_IN,
+                   CATEGORY_CH,
+                   "CHANNEL SELECTION (setup)");
        if (exclusive<0)
                exclusive = 0;
+       if (channel == CHANNEL_NO)
+               add_trace("channel", "request", "no-channel");
+       else
+               add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
        if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN)
-               PDEBUG(DEBUG_BCHANNEL, "- no channel is given by the network, causing to fail, since CW is not possible for external lines\n");
+       {
+               add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
+               end_trace();
+               ret = -6; // channel unacceptable
+               goto no_channel;
+       }
        if (channel <= 0) /* not given, no channel, whatever.. */
                channel = CHANNEL_ANY; /* any channel */
        if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan..
        {
-               printlog("---  port#%d all channels are used/reserved.\n", ifport->portnum);
+               add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved);
+               add_trace("conclusion", NULL, "all channels are reserved");
+               end_trace();
                ret = -34; // no channel
                goto no_channel;
        }
-       if (channel == CHANNE_ANY)
-       {
-               PDEBUG(DEBUG_BCHANNEL, "- any channel is assumed from the %s, so we need to return the a channel from our list\n", (p_m_d_ntmode)?"user":"network");
-               /* check for any channel form selection list */
-               channel = 0;
-               selchannel = ifport->channel_in;
-               while(selchannel)
-               {
-                       switch(selchannel->channel)
-                       {
-                               case CHANNEL_FREE: /* free channel */
-                               if (mISDNport->b_inuse >= mISDNport->b_num)
-                                       break; /* all channel in use or reserverd */
-                               /* find channel */
-                               i = 0;
-                               while(i < mISDNport->b_num)
-                               {
-                                       if (mISDNport->b_port[i] == NULL)
-                                       {
-                                               channel = i+1+(i>=15);
-                                               printlog("---  port#%d no channel given, so selecting free channel %d\n", ifport->portnum, channel);
-                                               break;
-                                       }
-                                       i++;
-                               }
-                               break;
-
-                               default:
-                               if (selchannel->channel<1 || selchannel->channel==16)
-                                       break; /* invalid channels */
-                               i = selchannel->channel-1-(selchannel->channel>=17);
-                               if (i >= mISDNport->b_num)
-                                       break; /* channel not in port */
-                               if (mISDNport->b_port[i] == NULL)
-                               {
-                                       channel = selchannel->channel;
-                                       printlog("---  port#%d no channel given, so selecting channel %d from list\n", ifport->portnum, channel);
-                                       break;
-                               }
-                               break;
-                       }
-                       if (channel)
-                               break; /* found channel */
-                       selchannel = selchannel->next;
-               }
-               if (!channel)
-               {
-                       printlog("---  port#%d no channel found.\n", ifport->portnum);
-                       ret = -34; // no channel
-                       goto no_channel;
-               }
-               goto use_channel;
-       }
+       if (channel == CHANNEL_ANY)
+               goto get_from_list;
        if (channel > 0)
        {
                /* check for given channel in selection list */
@@ -691,19 +775,16 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
                {
                        if (!channel)
                        {
-                               PDEBUG(DEBUG_BCHANNEL, "- exclusive channel %d is selected, but not in list of incomming channel.\n", channel);
-                               printlog("---  port#%d channel %d given exclusively, it is accepted.\n", ifport->portnum, channel);
+                               add_trace("conclusion", NULL, "exclusively requested channel not in list");
+                               end_trace();
                                ret = 6; // unacceptable
                                goto no_channel;
                        }
-                       PDEBUG(DEBUG_BCHANNEL, "- exclusive channel %d is selected, as in list of incomming channels.\n", channel);
                        i = selchannel->channel-1-(selchannel->channel>=17);
                        if (mISDNport->b_port[i] == NULL)
-                       {
-                               printlog("---  port#%d channel %d given exclusively, it is accepted and free.\n", ifport->portnum, channel);
                                goto use_channel;
-                       }
-                       printlog("---  port#%d channel %d given exclusively, it is accepted, but busy.\n", ifport->portnum, channel);
+                       add_trace("conclusion", NULL, "exclusively requested channel is busy");
+                       end_trace();
                        ret = 6; // unacceptable
                        goto no_channel;
                }
@@ -711,18 +792,13 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
                /* requested channels in list will be used */
                if (channel)
                {
-                       PDEBUG(DEBUG_BCHANNEL, "- channel %d given, found in list.\n", channel);
                        i = selchannel->channel-1-(selchannel->channel>=17);
                        if (mISDNport->b_port[i] == NULL)
-                       {
-                               printlog("---  port#%d channel %d given, it is accepted and free.\n", ifport->portnum, channel);
                                goto use_channel;
-                       }
                }
 
                /* if channel is not available or not in list, it must be searched */
-               PDEBUG(DEBUG_BCHANNEL, "- channel %d given, but not in list of incomming channels.\n", channel);
-
+               get_from_list:
                /* check for first free channel in list */
                channel = 0;
                selchannel = ifport->channel_in;
@@ -731,6 +807,7 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
                        switch(selchannel->channel)
                        {
                                case CHANNEL_FREE: /* free channel */
+                               add_trace("hunting", "channel", "free");
                                if (mISDNport->b_inuse >= mISDNport->b_num)
                                        break; /* all channel in use or reserverd */
                                /* find channel */
@@ -740,7 +817,6 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
                                        if (mISDNport->b_port[i] == NULL)
                                        {
                                                channel = i+1+(i>=15);
-                                               printlog("---  port#%d requested channel was not in list, so using free channel %d from list.\n", ifport->portnum, channel);
                                                break;
                                        }
                                        i++;
@@ -748,6 +824,7 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
                                break;
 
                                default:
+                               add_trace("hunting", "channel", "%d", selchannel->channel);
                                if (selchannel->channel<1 || selchannel->channel==16)
                                        break; /* invalid channels */
                                i = selchannel->channel-1-(selchannel->channel>=17);
@@ -756,7 +833,6 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
                                if (mISDNport->b_port[i] == NULL)
                                {
                                        channel = selchannel->channel;
-                                       printlog("---  port#%d requested channel was not in list, so using free channel %d from list.\n", ifport->portnum, channel);
                                        break;
                                }
                                break;
@@ -767,7 +843,8 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
                }
                if (!channel)
                {
-                       printlog("---  port#%d no channel found.\n", ifport->portnum);
+                       add_trace("conclusion", NULL, "no channel available");
+                       end_trace();
                        ret = 6; // unacceptable
                        goto no_channel;
                }
@@ -778,20 +855,24 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
        ret = seize_bchannel(channel, 1);
        if (ret < 0)
        {
+               add_trace("conclusion", NULL, "channel not available");
+               end_trace();
                no_channel:
-               PDEBUG(DEBUG_BCHANNEL, "- channel is not available (cause=%d), so we send a release_complete.\n", -ret);
                RELEASE_COMPLETE_t *release_complete;
 
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
+               l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                new_state(PORT_STATE_RELEASE);
                p_m_delete = 1;
                return;
        }
-       PDEBUG(DEBUG_BCHANNEL, "- channel is available, we open channel %d.\n", ret);
+       add_trace("conclusion", NULL, "channel available");
+       add_trace("connect", "channel", "%d", p_m_b_channel);
+       end_trace();
        bchannel_activate(p_m_mISDNport, p_m_b_index);
 
        /* create endpoint */
@@ -805,9 +886,10 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
                RELEASE_COMPLETE_t *release_complete;
 
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
+               l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 41); /* temporary failure */
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                new_state(PORT_STATE_RELEASE);
                p_m_delete = 1;
@@ -823,29 +905,10 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
                PERROR("no memory for epointlist\n");
                exit(-1);
        }
-       if (p_m_d_ntmode)
-       {
-               /* nt-library now gives us the id via CC_SETUP */
-               if (dinfo&(~0xff) == 0xff00)
-               {
-                       PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
-                       exit(-1);
-               }
-               printisdn("    l3id 0x%x changes to 0x%x\n", p_m_d_l3id, dinfo);
-               if (p_m_d_l3id&(~0xff) == 0xff00)
-                       p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
-               p_m_d_l3id = dinfo;
-               p_m_d_ces = setup->ces;
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) nt-mode gives us new l3id via setup ind: 0x%x\n", p_name, p_m_d_l3id);
-       }
-
        /* send setup message to endpoit */
-       PDEBUG(DEBUG_ISDN, "Pdss1(%s) setup: %s->%s\n", p_name, p_callerinfo.id, p_dialinginfo.number);
        message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
        message->param.setup.isdn_port = p_m_portnum;
        message->param.setup.port_type = p_type;
-       p_callerinfo.isdn_port = p_m_portnum;
-       SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);;
        memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
        memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
        memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
@@ -867,9 +930,12 @@ void Pdss1::information_ind(unsigned long prim, unsigned long dinfo, void *data)
        unsigned char keypad[32] = "";
        struct message *message;
 
-       /* dialing information */
+       l3_trace_header(prim, DIRECTION_IN);
        dec_ie_called_pn(information->CALLED_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, (unsigned char *)p_dialinginfo.number, sizeof(p_dialinginfo.number));
        dec_ie_keypad(information->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
+       dec_ie_complete(information->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
+       end_trace();
+
        SCAT(p_dialinginfo.number, (char *)keypad);
        switch (type)
        {
@@ -886,9 +952,6 @@ void Pdss1::information_ind(unsigned long prim, unsigned long dinfo, void *data)
                p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
                break;
        }
-       /* sending complete */
-       dec_ie_complete(information->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);;
-       PDEBUG(DEBUG_ISDN, "Pdss1(%s) more digits: %s\n", p_name,p_dialinginfo.number);
        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);
@@ -906,9 +969,12 @@ void Pdss1::setup_acknowledge_ind(unsigned long prim, unsigned long dinfo, void
        int ret;
        struct message *message;
 
-       /* channel_id */
+       l3_trace_header(prim, DIRECTION_IN);
        dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
        dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
+       end_trace();
+
+       /* process channel */
        ret = received_first_reply_to_setup(prim, exclusive, channel);
        if (ret < 0)
        {
@@ -920,6 +986,7 @@ void Pdss1::setup_acknowledge_ind(unsigned long prim, unsigned long dinfo, void
                p_m_delete = 1;
                return;
        }
+
        message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
        message_put(message);
 
@@ -938,9 +1005,13 @@ void Pdss1::proceeding_ind(unsigned long prim, unsigned long dinfo, void *data)
        int notify = -1, type, plan, present;
        char redir[32];
 
-       /* channel id */
+       l3_trace_header(prim, DIRECTION_IN);
        dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
        dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
+       dec_ie_notify(NULL/*proceeding->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), &notify);
+       dec_ie_redir_dn(proceeding->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
+       end_trace();
+
        ret = received_first_reply_to_setup(prim, exclusive, channel);
        if (ret < 0)
        {
@@ -957,12 +1028,10 @@ void Pdss1::proceeding_ind(unsigned long prim, unsigned long dinfo, void *data)
 
        new_state(PORT_STATE_OUT_PROCEEDING);
        
-       dec_ie_notify(NULL/*proceeding->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), &notify);
        if (notify >= 0)
                notify |= 0x80;
        else
                notify = 0;
-       dec_ie_redir_dn(proceeding->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
        if (type >= 0 || notify)
        {
                if (!notify && type >= 0)
@@ -1019,9 +1088,14 @@ void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data)
        int notify = -1, type, plan, present;
        char redir[32];
 
-       /* channel id */
+       l3_trace_header(prim, DIRECTION_IN);
        dec_ie_channel_id(alerting->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
        dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
+       dec_ie_notify(NULL/*alerting->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), &notify);
+       dec_ie_redir_dn(alerting->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
+       end_trace();
+
+       /* process channel */
        ret = received_first_reply_to_setup(prim, exclusive, channel);
        if (ret < 0)
        {
@@ -1038,12 +1112,10 @@ void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data)
 
        new_state(PORT_STATE_OUT_ALERTING);
 
-       dec_ie_notify(NULL/*alerting->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), &notify);
        if (notify >= 0)
                notify |= 0x80;
        else
                notify = 0;
-       dec_ie_redir_dn(alerting->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
        if (type >= 0 || notify)
        {
                if (!notify && type >= 0)
@@ -1098,15 +1170,22 @@ void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
        msg_t *dmsg;
        struct message *message;
        int bchannel_before;
+       CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
 
        if (p_m_d_ntmode)
                p_m_d_ces = connect->ces;
 
-       /* NOTE: we do not check the connected channel, since we
-        * ready sent a channel to the remote side
-        */
-       /* channel id */
+       l3_trace_header(prim, DIRECTION_IN);
        dec_ie_channel_id(connect->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
+       dec_ie_connected_pn(connect->CONNECT_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, &screen, (unsigned char *)p_connectinfo.id, sizeof(p_connectinfo.id));
+#ifdef CENTREX
+       /* te-mode: CONP (connected name identification presentation) */
+       if (!p_m_d_ntmode)
+               dec_facility_centrex(connect->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
+#endif
+       end_trace();
+
+       /* select channel */
        bchannel_before = p_m_b_channel;
        ret = received_first_reply_to_setup(prim, exclusive, channel);
        if (ret < 0)
@@ -1119,8 +1198,8 @@ void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
                p_m_delete = 1;
                return;
        }
+
        /* connect information */
-       dec_ie_connected_pn(connect->CONNECT_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, &screen, (unsigned char *)p_connectinfo.id, sizeof(p_connectinfo.id));
        switch (present)
        {
                case 1:
@@ -1162,23 +1241,18 @@ void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
                break;
        }
        p_connectinfo.isdn_port = p_m_portnum;
-#ifdef CENTREX
-       /* te-mode: CONP (connected name identification presentation) */
-       if (!p_m_d_ntmode)
-               dec_facility_centrex(connect->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
-#endif
-       /* send connect acknowledge */
-       CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
+       SCPY(p_connectingo.interface, p_m_mISDNport->ifport->interface->name);
 
+       /* send connect acknowledge */
        dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode);
-       isdn_show_send_message(CC_CONNECT | RESPONSE, dmsg);
+       l3_trace_header(CC_CONNECT | RESPONSE, DIRECTION_OUT);
        connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
        /* if we had no bchannel before, we send it now */
        if (!bchannel_before && p_m_b_channel)
                enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
+       end_trace();
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
 
-       PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect (to '%s' COLP: '%s')\n", p_name, p_dialinginfo.number, p_connectinfo.id);
        message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
        memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
        message_put(message);
@@ -1195,9 +1269,11 @@ void Pdss1::disconnect_ind(unsigned long prim, unsigned long dinfo, void *data)
        int coding, proglocation, progress;
        struct message *message;
 
-       /* cause */
+       l3_trace_header(prim, DIRECTION_IN);
        dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &proglocation, &progress);
        dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
+       end_trace();
+
        if (cause < 0)
                cause = 16;
 
@@ -1207,11 +1283,12 @@ void Pdss1::disconnect_ind(unsigned long prim, unsigned long dinfo, void *data)
                RELEASE_t *release;
                msg_t *dmsg;
 
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) send release because remote disconnects AND provides no patterns (earlyb).\n", p_name);
                dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, dinfo, sizeof(RELEASE_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_RELEASE | REQUEST, dmsg);
                release = (RELEASE_t *)(dmsg->data + headerlen);
+               l3_trace_header(CC_RELEASE | REQUEST, DIRECTION_OUT);
                enc_ie_cause(&release->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
+               add_trace("reason", NULL, "no remote patterns");
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
 
                /* sending release to endpoint */
@@ -1257,10 +1334,16 @@ void Pdss1::disconnect_ind_i(unsigned long prim, unsigned long dinfo, void *data
        int location, cause;
 
        /* cause */
+       l3_trace_header(prim, DIRECTION_IN);
+       if (p_m_d_collect_cause > 0)
+       {
+               add_trace("old-cause", "location", "%d", p_m_d_collect_location);
+               add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
+       }
        dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
+       end_trace();
 
        /* collect cause */
-       PDEBUG(DEBUG_ISDN, "PORT(%d) collecting cause %d location %d.\n", p_serial, cause, location);
        if (cause == CAUSE_REJECTED) /* call rejected */
        {
                p_m_d_collect_cause = CAUSE_REJECTED;
@@ -1286,7 +1369,8 @@ void Pdss1::disconnect_ind_i(unsigned long prim, unsigned long dinfo, void *data
                p_m_d_collect_cause = cause;
                p_m_d_collect_location = location;
        }
-       PDEBUG(DEBUG_ISDN, "PORT(%d) new multipoint cause %d location %d.\n", p_serial, p_m_d_collect_cause, p_m_d_collect_location);
+       add_trace("new-cause", "location", "%d", p_m_d_collect_location);
+       add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
 
 }
 
@@ -1299,8 +1383,10 @@ void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
        int location, cause;
        struct message *message;
 
-       /* cause */
+       l3_trace_header(prim, DIRECTION_IN);
        dec_ie_cause(release->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
+       end_trace();
+
        if (cause < 0)
                cause = 16;
 
@@ -1322,9 +1408,10 @@ void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
                RELEASE_COMPLETE_t *release_complete;
 
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
+               l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        }
 
@@ -1340,8 +1427,10 @@ void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void *
        int location, cause;
        struct message *message;
 
-       /* cause */
+       l3_trace_header(prim, DIRECTION_IN);
        dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
+       end_trace();
+
        if (cause < 0)
                cause = 16;
 
@@ -1356,7 +1445,6 @@ void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void *
                free_epointlist(p_epointlist);
        }
 
-       PDEBUG(DEBUG_ISDN, "Pdss1(%s) release_complete (cause %d)\n", p_name, cause);
        new_state(PORT_STATE_RELEASE);
        p_m_delete = 1;
 }
@@ -1366,6 +1454,8 @@ void Pdss1::t312_timeout(unsigned long prim, unsigned long dinfo, void *data)
 {
        struct message *message;
 
+       // trace is done at message_isdn()
+       
        /* sending release to endpoint */
        while(p_epointlist)
        {
@@ -1377,7 +1467,6 @@ void Pdss1::t312_timeout(unsigned long prim, unsigned long dinfo, void *data)
                free_epointlist(p_epointlist);
        }
 
-       PDEBUG(DEBUG_ISDN, "Pdss1(%s) t312_timeout (collected cause %d location %d)\n", p_name, p_m_d_collect_cause, p_m_d_collect_location);
        new_state(PORT_STATE_RELEASE);
        p_m_delete = 1;
 }
@@ -1390,20 +1479,20 @@ void Pdss1::notify_ind(unsigned long prim, unsigned long dinfo, void *data)
        struct message *message;
        int notify, type, plan, present;
 
+       l3_trace_header(prim, DIRECTION_IN);
+       dec_ie_notify(notifying->NOTIFY, (Q931_info_t *)((unsigned long)data+headerlen), &notify);
+       dec_ie_redir_dn(notifying->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)message->param.notifyinfo.id, sizeof(message->param.notifyinfo.id));
+       end_trace();
+
        if (!ACTIVE_EPOINT(p_epointlist))
-       {
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) there is no active endpoint to notify to.\n", p_name);
                return;
-       }
        /* notification indicator */
-       dec_ie_notify(notifying->NOTIFY, (Q931_info_t *)((unsigned long)data+headerlen), &notify);
        if (notify < 0)
                return;
        notify |= 0x80;
        message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
        message->param.notifyinfo.notify = notify;
        /* redirection number */
-       dec_ie_redir_dn(notifying->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)message->param.notifyinfo.id, sizeof(message->param.notifyinfo.id));
        switch (present)
        {
                case 1:
@@ -1451,15 +1540,17 @@ void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
        msg_t *dmsg;
 //     class Endpoint *epoint;
 
+       l3_trace_header(prim, DIRECTION_IN);
+       end_trace();
+
        if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
        {
-
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) there is no endpoint to notify hold OR we are already on hold, so we reject.\n", p_name);
-
                dmsg = create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, dinfo, sizeof(HOLD_REJECT_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_HOLD_REJECT | REQUEST, dmsg);
                hold_reject = (HOLD_REJECT_t *)(dmsg->data + headerlen);
+               l3_trace_header(CC_HOLD_REJECT | REQUEST, DIRECTION_OUT);
                enc_ie_cause(&hold_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
+               add_trace("reason", NULL, "no endpoint");
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
 
                return;
@@ -1472,7 +1563,17 @@ void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
        message_put(message);
 
        /* deactivate bchannel */
+       start_trace(p_m_mISDNport->portnum,
+                   p_m_mISDNport->ifport->interface,
+                   nationalize(p_callerinfo.id, p_callerinfo.ntype),
+                   p_dialinginfo.number,
+                   DIRECTION_OUT,
+                   CATEGORY_CH,
+                   "CHANNEL RELEASE (hold)");
+       add_trace("disconnect", "channel", "%d", p_m_b_channel);
+       end_trace();
        free_bchannel();
+prüfen, ob bei allen alloc_bchannel/free_bchannel ein trace erfolgt
 
        /* set hold state */
        p_m_hold = 1;
@@ -1487,8 +1588,9 @@ void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
 
        /* acknowledge hold */
        dmsg = create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, dinfo, sizeof(HOLD_ACKNOWLEDGE_t), p_m_d_ntmode);
-       isdn_show_send_message(CC_HOLD_ACKNOWLEDGE | REQUEST, dmsg);
        hold_acknowledge = (HOLD_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
+       l3_trace_header(CC_HOLD_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
+       end_trace();
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
 }
 
@@ -1505,16 +1607,20 @@ void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
        msg_t *dmsg;
        int ret;
 
+       l3_trace_header(prim, DIRECTION_IN);
+       dec_ie_channel_id(retrieve->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
+       end_trace();
+
        if (!p_m_hold)
        {
                cause = 101; /* incompatible state */
                reject:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) we are not on hold, so we reject (cazse %d).\n", p_name, cause);
 
                dmsg = create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, dinfo, sizeof(RETRIEVE_REJECT_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_RETRIEVE_REJECT | REQUEST, dmsg);
                retrieve_reject = (RETRIEVE_REJECT_t *)(dmsg->data + headerlen);
+               l3_trace_header(CC_RETRIEVE_REJECT | REQUEST, DIRECTION_OUT);
                enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
 
                return;
@@ -1526,24 +1632,45 @@ void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
        message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
        message_put(message);
 
+
+
+mach den channel-kram, wie beim setup
+
+
+
+
+
+
+
+
+       
        /* channel_id */
-       dec_ie_channel_id(retrieve->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
+       start_trace(p_m_mISDNport->portnum,
+                   p_m_mISDNport->ifport->interface,
+                   nationalize(p_callerinfo.id, p_callerinfo.ntype),
+                   p_dialinginfo.number,
+                   DIRECTION_IN,
+                   CATEGORY_CH,
+                   "CHANNEL SELECTION (retrieve)");
        if (exclusive<0)
                exclusive = 0;
+alle channels richtig convertieren 
        if (channel < 0)
                channel = -1; /* any channel */
        if (channel == ANY_CHANNEL)
                channel = -1; /* any channel */
+       if (channel == CHANNEL_NO)
+               add_trace("channel", "request", "no-channel");
+       else
+               add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
        /* debug */
-       if (channel < 0)
-               PDEBUG(DEBUG_BCHANNEL, "- any channel is selected the %s, so we need to return the selected channel\n", (p_m_d_ntmode)?"user":"network");
-       if (channel==0 && (p_type==PORT_TYPE_DSS1_TE_IN||p_type==PORT_TYPE_DSS1_TE_OUT))
-               PDEBUG(DEBUG_BCHANNEL, "- no channel is given by the network, causing to fail, since CW is not possible for external lines\n");
-       if (channel >= 0)
-               if (exclusive)
-                       PDEBUG(DEBUG_BCHANNEL, "- exclusive channel(%d) is selected.\n", channel);
-               else
-                       PDEBUG(DEBUG_BCHANNEL, "- channel(%d) given, but we select a different channel if not available.\n", channel);
+       if (channel==CHANNEL_NO && (p_type==PORT_TYPE_DSS1_TE_IN||p_type==PORT_TYPE_DSS1_TE_OUT))
+       {
+               add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
+               end_trace();
+               cause = 6;
+               goto reject;
+       }
        /* open channel */
        ret = alloc_bchannel(channel, exclusive);
        if (ret < 0)
@@ -1553,16 +1680,31 @@ void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
                goto reject;
        }
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+       
        /* set hold state */
        p_m_hold = 0;
        p_m_timeout = 0;
 
        /* acknowledge retrieve */
        dmsg = create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, dinfo, sizeof(RETRIEVE_ACKNOWLEDGE_t), p_m_d_ntmode);
-       isdn_show_send_message(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, dmsg);
        retrieve_acknowledge = (RETRIEVE_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
-       /* channel information */
+       l3_trace_header(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
        enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
+       end_trace();
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
 }
 
@@ -1580,22 +1722,24 @@ void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
        msg_t *dmsg;
        int ret = -31; /* normal, unspecified */
 
+       l3_trace_header(prim, DIRECTION_IN);
+       dec_ie_call_id(suspend->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
+       end_trace();
+
        if (!ACTIVE_EPOINT(p_epointlist))
        {
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) there is no endpoint to notify suspend, so we reject.\n", p_name);
-
                reject:
                dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, dinfo, sizeof(SUSPEND_REJECT_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_SUSPEND_REJECT | REQUEST, dmsg);
                suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + headerlen);
+               l3_trace_header(CC_SUSPEND_REJECT | REQUEST, DIRECTION_OUT);
                enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
 
                return;
        }
 
        /* call id */
-       dec_ie_call_id(suspend->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
        if (len<0) len = 0;
 
        /* check if call id is in use */
@@ -1607,7 +1751,6 @@ void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
                        if (epoint->ep_park_len == len)
                        if (!memcmp(epoint->ep_park_callid, callid, len))
                        {
-                               PDEBUG(DEBUG_ISDN, "Pdss1(%s) call id is in use, so we reject.\n", p_name);
                                ret = -84; /* call id in use */
                                goto reject;
                        }
@@ -1622,6 +1765,15 @@ void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
        message_put(message);
 
        /* deactivate bchannel */
+       start_trace(p_m_mISDNport->portnum,
+                   p_m_mISDNport->ifport->interface,
+                   nationalize(p_callerinfo.id, p_callerinfo.ntype),
+                   p_dialinginfo.number,
+                   DIRECTION_OUT,
+                   CATEGORY_CH,
+                   "CHANNEL RELEASE (suspend)");
+       add_trace("disconnect", "channel", "%d", p_m_b_channel);
+       end_trace();
        free_bchannel();
 
        /* sending suspend to endpoint */
@@ -1637,8 +1789,9 @@ void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
 
        /* sending SUSPEND_ACKNOWLEDGE */
        dmsg = create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, dinfo, sizeof(SUSPEND_ACKNOWLEDGE_t), p_m_d_ntmode);
-       isdn_show_send_message(CC_SUSPEND_ACKNOWLEDGE | REQUEST, dmsg);
        suspend_acknowledge = (SUSPEND_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
+       l3_trace_header(CC_SUSPEND_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
+       end_trace();
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
 
        new_state(PORT_STATE_RELEASE);
@@ -1660,6 +1813,30 @@ void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
        struct message *message;
        int ret;
 
+       /* callref from nt-lib */
+       if (p_m_d_ntmode)
+       {
+               /* nt-library now gives us the id via CC_RESUME */
+               if (dinfo&(~0xff) == 0xff00)
+               {
+                       PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
+                       exit(-1);
+               }
+               l3_trace_header(CC_NEW_CR | INDICATION, DIRECTION_IN);
+               if (p_m_d_l3id)
+                       add_trace("callref", "old", "0x%x", p_m_d_l3id);
+               add_trace("callref", "new", "0x%x", dinfo);
+               end_trace();
+               if (p_m_d_l3id&(~0xff) == 0xff00)
+                       p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
+               p_m_d_l3id = dinfo;
+               p_m_d_ces = setup->ces;
+       }
+
+       l3_trace_header(prim, DIRECTION_IN);
+       dec_ie_call_id(resume->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
+       end_trace();
+
        /* if blocked, release call */
        if (p_m_mISDNport->ifport->block)
        {
@@ -1671,30 +1848,30 @@ void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
        }
 
        /* call id */
-       dec_ie_call_id(resume->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
        if (len<0) len = 0;
 
        /* channel_id */
        exclusive = 0;
        channel = -1; /* any channel */
-       PDEBUG(DEBUG_BCHANNEL, "- any channel is selected the %s, so we need to return the selected channel\n", (p_m_d_ntmode)?"user":"network");
-       /* open channel */
-       ret = alloc_bchannel(channel, exclusive);
+
+       /* hunt channel */
+       ret = hunt_bchannel(channel, exclusive);
        if (ret < 0)
        {
-               PDEBUG(DEBUG_BCHANNEL, "- channel is not available (cause=%d), so we send a RESUME_REJECT.\n", -ret);
-
                reject:
                dmsg = create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, dinfo, sizeof(RESUME_REJECT_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_RESUME_REJECT | REQUEST, dmsg);
                resume_reject = (RESUME_REJECT_t *)(dmsg->data + headerlen);
+               l3_trace_header(CC_RESUME_REJECT | REQUEST, DIRECTION_OUT);
                enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
+               if (ret == -27)
+                       add_trace("reason", NULL, "port blocked");
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                new_state(PORT_STATE_RELEASE);
                p_m_delete = 1;
                return;
        }
-       PDEBUG(DEBUG_BCHANNEL, "- channel is available, we selected channel %d.\n", ret);
+
        /* create endpoint */
        if (p_epointlist)
        {
@@ -1715,10 +1892,7 @@ void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
                epoint = epoint->next;
        }
        if (!epoint)
-       {
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) no suspended call, so we reject with cause %d.\n", p_name, ret);
                goto reject;
-       }
 
        if (!(epointlist_new(epoint->ep_serial)))
        {
@@ -1730,23 +1904,6 @@ void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
                PERROR("no memory for portlist\n");
                exit(-1);
        }
-       if (p_m_d_ntmode)
-       {
-               /* nt-library now gives us the id via CC_RESUME */
-               if (dinfo&(~0xff) == 0xff00)
-               {
-                       PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
-                       exit(-1);
-               }
-               printisdn("    l3id 0x%x changes to 0x%x\n", p_m_d_l3id, dinfo);
-               if (p_m_d_l3id&(~0xff) == 0xff00)
-                       p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
-               p_m_d_l3id = dinfo;
-               p_m_d_ces = resume->ces;
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s: nt-mode gives us new l3id via resume ind: 0x%x\n", p_name, p_m_d_l3id);
-       }
-
-       PDEBUG(DEBUG_ISDN, "Pdss1(%s) resume\n", p_name);
        message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
        message_put(message);
 
@@ -1758,10 +1915,10 @@ void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
 
        /* sending RESUME_ACKNOWLEDGE */
        dmsg = create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, dinfo, sizeof(RESUME_ACKNOWLEDGE_t), p_m_d_ntmode);
-       isdn_show_send_message(CC_RESUME_ACKNOWLEDGE | REQUEST, dmsg);
        resume_acknowledge = (RESUME_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
-       /* channel information */
+       l3_trace_header(CC_RESUME_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
        enc_ie_channel_id(&resume_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
+       end_trace();
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
 
        new_state(PORT_STATE_CONNECT);
@@ -1777,12 +1934,14 @@ void Pdss1::facility_ind(unsigned long prim, unsigned long dinfo, void *data)
        int facil_len;
        struct message *message;
 
-       /* facility */
+       l3_trace_header(prim, DIRECTION_IN);
        dec_ie_facility(facility->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), facil, &facil_len);
+       end_trace();
+
+       /* facility */
        if (facil_len<=0)
                return;
 
-       PDEBUG(DEBUG_ISDN, "Pdss1(%s) facility\n", p_name);
        message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
        message->param.facilityinfo.len = facil_len;
        memcpy(message->param.facilityinfo.data, facil, facil_len);
@@ -1796,119 +1955,94 @@ void Pdss1::facility_ind(unsigned long prim, unsigned long dinfo, void *data)
  */
 void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data)
 {
-       char *msgtext = "<<UNKNOWN MESSAGE>>";
-       char *primtext;
        int i;
        int new_l3id;
+       int timer_hex=0;
 
-       i = 0;
-       while(isdn_message[i].name)
-       {
-               if (isdn_message[i].value == (prim&0xffffff00))
-               {
-                       msgtext = isdn_message[i].name;
-                       break;
-               }
-               i++;
-       }
-       primtext = isdn_prim[prim&0x00000003];
-       printisdn("<<< incoming prim: %s %s (0x%x)\n", msgtext, primtext, prim);
        switch (prim)
        {
                case CC_TIMEOUT | INDICATION:
+               l3_trace_header(prim, DIRECTION_IN);
                if (p_m_d_ntmode)
                {
                        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
-                       int t = *((int *)(((char *)data)+headerlen));
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) timeout (t%x in NT-mode)\n", p_name, t);
-                       if (t == 0x312)
-                               t312_timeout(prim, dinfo, data);
-               } else {
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) timeout (ignoring)\n", p_name);
+                       timer_hex = *((int *)(((char *)data)+headerlen));
                }
+               if (timer_hex)
+                       add_trace("timer", NULL, "%x", timer_hex);
+               end_trace();
+               if (timer_hex==0x312 && p_m_d_ntmode)
+                       t312_timeout(prim, dinfo, data);
                break;
 
                case CC_SETUP | INDICATION:
-               PDEBUG((DEBUG_BCHANNEL|DEBUG_ISDN), "Pdss1(%s) setup\n", p_name);
                if (p_state != PORT_STATE_IDLE)
-               {
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup again, IGNORING.\n", p_name);
                        break;
-               }
                setup_ind(prim, dinfo, data);
                break;
 
                case CC_SETUP | CONFIRM:
                if (p_m_d_ntmode)
                {
+                       l3_trace_header(CC_NEW_CR | INDICATION, DIRECTION_IN);
+                       add_trace("callref", "old", "0x%x", p_m_d_l3id);
                        /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
-                       if ((p_m_d_l3id&0xff00) == 0xff00)
-                       {
-//                             p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
-//                             printisdn("    procid 0x%x freed\n", p_m_d_l3id&0xff);
-                               printisdn("    procid 0x%x still in use\n", p_m_d_l3id&0xff);
-                       } else
-                       {
-                               printisdn("    strange setup-procid 0x%x\n", p_m_d_l3id);
-                       }
+                       if ((p_m_d_l3id&0xff00) != 0xff00)
+                               PERROR("    strange setup-procid 0x%x\n", p_m_d_l3id);
                        p_m_d_l3id = *((int *)(((u_char *)data)+ mISDNUSER_HEAD_SIZE));
-                       printisdn("    l3id changes to 0x%x\n", p_m_d_l3id);
+                       add_trace("callref", "new", "0x%x", p_m_d_l3id);
+                       end_trace();
                }
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) setup confirm (l3id=0x%x)\n", p_name, p_m_d_l3id);
+               end_trace;
                break;
 
                case CC_INFORMATION | INDICATION:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) information\n", p_name);
                information_ind(prim, dinfo, data);
                break;
 
                case CC_SETUP_ACKNOWLEDGE | INDICATION:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) setup acknowledge\n", p_name);
                if (p_state != PORT_STATE_OUT_SETUP)
                {
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
+                       PERROR("Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
                        break;
                }
                setup_acknowledge_ind(prim, dinfo, data);
                break;
 
                case CC_PROCEEDING | INDICATION:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) proceeding\n", p_name);
                if (p_state != PORT_STATE_OUT_SETUP
                 && p_state != PORT_STATE_OUT_OVERLAP)
                {
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
+                       PERROR("Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
                        break;
                }
                proceeding_ind(prim, dinfo, data);
                break;
 
                case CC_ALERTING | INDICATION:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) alerting\n", p_name);
                if (p_state != PORT_STATE_OUT_SETUP
                 && p_state != PORT_STATE_OUT_OVERLAP
                 && p_state != PORT_STATE_OUT_PROCEEDING)
                {
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
+                       PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
                        break;
                }
                alerting_ind(prim, dinfo, data);
                break;
 
                case CC_CONNECT | INDICATION:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect\n", p_name);
                if (p_state != PORT_STATE_OUT_SETUP
                 && p_state != PORT_STATE_OUT_OVERLAP
                 && p_state != PORT_STATE_OUT_PROCEEDING
                 && p_state != PORT_STATE_OUT_ALERTING)
                {
-                       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);
+                       PERROR("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(prim, dinfo, data);
                if (p_m_d_notify_pending)
                {
-                       PDEBUG(DEBUG_ISDN, "received or connect, so we send pending notify message.\n");
+                       /* send pending notify message during connect */
                        message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
                        message_free(p_m_d_notify_pending);
                        p_m_d_notify_pending = NULL;
@@ -1917,12 +2051,11 @@ void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data)
 
                case CC_CONNECT_ACKNOWLEDGE | INDICATION:
                case CC_CONNECT | CONFIRM:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect_acknowlege.\n", p_name);
                if (p_state == PORT_STATE_CONNECT_WAITING)
                        new_state(PORT_STATE_CONNECT);
                if (p_m_d_notify_pending)
                {
-                       PDEBUG(DEBUG_ISDN, "received or connect-ack, so we send pending notify message.\n");
+                       /* send pending notify message during connect-ack */
                        message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
                        message_free(p_m_d_notify_pending);
                        p_m_d_notify_pending = NULL;
@@ -1930,66 +2063,53 @@ void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data)
                break;
 
                case CC_DISCONNECT | INDICATION:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) disconnect\n", p_name);
                disconnect_ind(prim, dinfo, data);
                break;
 
                case CC_RELEASE | CONFIRM:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) release confirm\n", p_name);
                case CC_RELEASE | INDICATION:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) release\n", p_name);
                release_ind(prim, dinfo, data);
                break;
 
                case CC_RELEASE_COMPLETE | INDICATION:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) release_complete.\n", p_name);
                release_complete_ind(prim, dinfo, data);
                break;
 
                case CC_RELEASE_COMPLETE | CONFIRM:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) release_complete (confirm).\n", p_name);
                break;
 
                case CC_NOTIFY | INDICATION:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) notify\n", p_name);
                notify_ind(prim, dinfo, data);
                break;
 
                case CC_HOLD | INDICATION:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) hold\n", p_name);
                hold_ind(prim, dinfo, data);
                break;
 
                case CC_RETRIEVE | INDICATION:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) retrieve\n", p_name);
                retrieve_ind(prim, dinfo, data);
                break;
 
                case CC_SUSPEND | INDICATION:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) suspend\n", p_name);
                suspend_ind(prim, dinfo, data);
                break;
 
                case CC_RESUME | INDICATION:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) resume\n", p_name);
                resume_ind(prim, dinfo, data);
                break;
 
                case CC_FACILITY | INDICATION:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) facility\n", p_name);
                facility_ind(prim, dinfo, data);
                break;
 
                case CC_RELEASE_CR | INDICATION:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) call ref is released (l3id=0x%x)\n", p_name, p_m_d_l3id);
-               printisdn("    process 0x%x released\n", p_m_d_l3id);
+               l3_trace_header(CC_RELEASE_CR | INDICATION, DIRECTION_IN);
+               add_trace("callref", NULL, "0x%x", p_m_d_l3id);
+               end_trace();
                if (p_m_d_ntmode)
                {
                        if ((p_m_d_l3id&0xff00) == 0xff00)
-                       {
                                p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
-                               printisdn("    procid 0x%x freed\n", p_m_d_l3id&0xff);
-                       }
                }
                p_m_d_l3id = 0;
                p_m_delete = 1;
@@ -2007,32 +2127,32 @@ void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data)
                        /* remove epoint */
                        free_epointlist(p_epointlist);
 
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) release due to breakdown of l3-process.\n", p_name);
                        new_state(PORT_STATE_RELEASE);
                }
                break;
 
                case CC_NEW_CR | INDICATION:
+               l3_trace_header(prim, DIRECTION_IN);
+               if (p_m_d_l3id)
+                       add_trace("callref", "old", "0x%x", p_m_d_l3id);
                if (p_m_d_ntmode)
                {
                        new_l3id = *((int *)(((u_char *)data+mISDNUSER_HEAD_SIZE)));
-                       printisdn("    process 0x%x received\n", new_l3id);
                        if (((new_l3id&0xff00)!=0xff00) && ((p_m_d_l3id&0xff00)==0xff00))
-                       {
                                p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
-                               printisdn("    procid 0x%x freed\n", p_m_d_l3id&0xff);
-                       }
                } else
                {
                        new_l3id = dinfo;
-                       printisdn("    process 0x%x received\n", new_l3id);
                }
                p_m_d_l3id = new_l3id;
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) call ref is created (l3id=0x%x)\n", p_name, p_m_d_l3id);
+               add_trace("callref", "new", "0x%x", p_m_d_l3id);
+               end_trace();
                break;
 
                default:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) unhandled prim: 0x%x\n", p_name, prim);
+               l3_trace_header(prim, DIRECTION_IN);
+               add_trace("unhandled", "prim", "0x%x", prim);
+               end_trace();
        }
 }
 
@@ -2051,14 +2171,6 @@ void Pdss1::new_state(int state)
                }
                if (state != p_state)
                {
-#if 0
-                       if (state == PORT_STATE_OUT_SETUP
-                        || state == PORT_STATE_OUT_OVERLAP)
-                       {
-                               p_m_timeout = 8;
-                               time(&p_m_timer);
-                       }
-#endif
                        if (state == PORT_STATE_IN_SETUP
                         || state == PORT_STATE_IN_OVERLAP)
                        {
@@ -2100,15 +2212,19 @@ void Pdss1::new_state(int state)
  */
 int Pdss1::handler(void)
 {
+       int ret;
+
+       if ((ret = Port::handler()))
+               return(ret);
+
        /* handle destruction */
        if (p_m_delete && p_m_d_l3id==0)
        {
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) doing pending release.\n", p_name);
                delete this;
                return(-1);
        }
 
-       return(PmISDN::handler());
+       return(0);
 }
 
 
@@ -2125,9 +2241,10 @@ void Pdss1::message_information(unsigned long epoint_id, int message_id, union p
        if (param->information.number[0]) /* only if we have something to dial */
        {
                dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg);
+               l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
                information = (INFORMATION_t *)(dmsg->data + headerlen);
                enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.number);
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        }
        new_state(p_state);
@@ -2178,10 +2295,11 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet
                {
                        /* sending information */
                        dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
-                       isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg);
                        information = (INFORMATION_t *)(dmsg->data + headerlen);
+                       l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
                        if (p_m_d_ntmode)
                                enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
+                       end_trace();
                        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                        return;
                }
@@ -2217,6 +2335,7 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet
                channel = CHANNEL_NO;
 
        /* creating l3id */
+       l3_trace_header(CC_NEW_CR | REQUEST, DIRECTION_OUT);
        if (p_m_d_ntmode)
        {
                i = 0;
@@ -2230,8 +2349,8 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet
                {
                        struct message *message;
 
-                       printisdn("    no free process id\n");
-                       PDEBUG(DEBUG_ISDN, "no more free process ID for port.\n");
+                       add_trace("callref", NULL, "no free id");
+                       end_trace();
                        message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
                        message->param.disconnectinfo.cause = 47;
                        message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
@@ -2241,9 +2360,7 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet
                        return;
                }
                p_m_mISDNport->procids[i] = 1;
-               printisdn("    procid 0x%x allocated\n", i);
                p_m_d_l3id = 0xff00 | i;
-               printisdn("    l3id is now 0x%x\n", p_m_d_l3id);
        } else
        {
                iframe_t ncr;
@@ -2256,16 +2373,17 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet
                ncr.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
                ncr.dinfo = p_m_d_l3id;
                ncr.len = 0;
-               isdn_show_send_message(CC_NEW_CR | REQUEST, NULL);
                /* send message */
                mISDN_write(mISDNdevice, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
 //             if (!dmsg)
 //                     goto nomem;
        }
+       add_trace("callref", "new", "0x%x", p_m_d_l3id);
+       end_trace();
 
        /* preparing setup message */
        dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode);
-       isdn_show_send_message(CC_SETUP | REQUEST, dmsg);
+       l3_trace_header(CC_SETUP | REQUEST, DIRECTION_OUT);
        setup = (SETUP_t *)(dmsg->data + headerlen);
        /* channel information */
        if (channel >= 0) /* it should */
@@ -2431,6 +2549,7 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet
        if (p_callerinfo.name[0] && p_m_d_ntmode)
                enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
 #endif
+       end_trace();
 
        /* send setup message now */
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
@@ -2449,13 +2568,12 @@ void Pdss1::message_facility(unsigned long epoint_id, int message_id, union para
        if (!p_m_d_ntmode)
                return;
 
-       PDEBUG(DEBUG_ISDN, "Pdss1(%s) sending facility message\n", p_name);
-
        /* sending facility */
        dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode);
-       isdn_show_send_message(CC_FACILITY | REQUEST, dmsg);
        facility = (FACILITY_t *)(dmsg->data + headerlen);
+       l3_trace_header(CC_FACILITY | REQUEST, DIRECTION_OUT);
        enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
+       end_trace();
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
 }
 
@@ -2469,7 +2587,6 @@ void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parame
        int plan, type = -1, present;
        msg_t *dmsg;
 
-       PDEBUG(DEBUG_ISDN, "Pdss1(%s) sending information message\n", p_name);
        if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
                notify = param->notifyinfo.notify & 0x7f;
        else
@@ -2518,7 +2635,7 @@ void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parame
 
        if (notify<0 && !param->notifyinfo.display[0])
        {
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) nothing to notify, nothing to display\n", p_name);
+               /* nothing to notify, nothing to display */
                return;
        }
 
@@ -2527,7 +2644,6 @@ void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parame
                if (p_state!=PORT_STATE_CONNECT)
                {
                        /* queue notification */
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) queueing notification because isdn port is not active state.\n", p_name);
                        if (p_m_d_notify_pending)
                                message_free(p_m_d_notify_pending);
                        p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
@@ -2536,23 +2652,25 @@ void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parame
                {
                        /* sending notification */
                        dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode);
-                       isdn_show_send_message(CC_NOTIFY | REQUEST, dmsg);
                        notification = (NOTIFY_t *)(dmsg->data + headerlen);
+                       l3_trace_header(CC_NOTIFY | REQUEST, DIRECTION_OUT);
                        enc_ie_notify(&notification->NOTIFY, dmsg, notify);
                        /* sending redirection number only in ntmode */
                        if (type >= 0 && p_m_d_ntmode)
                                enc_ie_redir_dn(&notification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id);
                        if (param->notifyinfo.display[0] && p_m_d_ntmode)
                                enc_ie_display(&notification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
+                       end_trace();
                        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                }
        } else if (p_m_d_ntmode)
        {
                /* sending information */
                dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg);
                information = (INFORMATION_t *)(dmsg->data + headerlen);
+               l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
                enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        }
 }
@@ -2566,8 +2684,8 @@ void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union param
 
        /* sending setup_acknowledge */
        dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode);
-       isdn_show_send_message(CC_SETUP_ACKNOWLEDGE | REQUEST, dmsg);
        setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
+       l3_trace_header(CC_SETUP_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
        /* channel information */
        if (p_state == PORT_STATE_IN_SETUP)
                enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
@@ -2577,6 +2695,7 @@ void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union param
         || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
        if (p_m_mISDNport->is_tones)
                enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+       end_trace();
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
 
        new_state(PORT_STATE_IN_OVERLAP);
@@ -2591,8 +2710,8 @@ void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union pa
 
        /* sending proceeding */
        dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
-       isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg);
        proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
+       l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
        /* channel information */
        if (p_state == PORT_STATE_IN_SETUP)
                enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
@@ -2602,6 +2721,7 @@ void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union pa
         || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
        if (p_m_mISDNport->is_tones)
                enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+       end_trace();
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
 
        new_state(PORT_STATE_IN_PROCEEDING);
@@ -2621,8 +2741,8 @@ void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union para
 
                /* sending proceeding */
                dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg);
                proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
+               l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
                /* channel information */
                enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
                /* progress information */
@@ -2630,14 +2750,15 @@ void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union para
                 || p_capainfo.bearer_capa==INFO_BC_AUDIO
                 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
                enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                new_state(PORT_STATE_IN_PROCEEDING);
        }
 
        /* sending alerting */
        dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode);
-       isdn_show_send_message(CC_ALERTING | REQUEST, dmsg);
        alerting = (ALERTING_t *)(dmsg->data + headerlen);
+       l3_trace_header(CC_ALERTING | REQUEST, DIRECTION_OUT);
        /* channel information */
        if (p_state == PORT_STATE_IN_SETUP)
                enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel);
@@ -2647,6 +2768,7 @@ void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union para
         || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
        if (p_m_mISDNport->is_tones)
                enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+       end_trace();
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
 
        new_state(PORT_STATE_IN_ALERTING);
@@ -2669,8 +2791,8 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param
 
                /* sending proceeding */
                dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg);
                proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
+               l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
                /* channel information */
                enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
 //             /* progress information */
@@ -2678,6 +2800,7 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param
 //              || p_capainfo.bearer_capa==INFO_BC_AUDIO
 //              || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
 //             enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                new_state(PORT_STATE_IN_PROCEEDING);
        }
@@ -2691,24 +2814,25 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param
        {
                /* sending information */
                dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg);
                information = (INFORMATION_t *)(dmsg->data + headerlen);
+               l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
                if (p_m_d_ntmode)
                        enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                return;
        }
 
        if (p_state!=PORT_STATE_IN_SETUP && p_state!=PORT_STATE_IN_OVERLAP && p_state!=PORT_STATE_IN_PROCEEDING && p_state!=PORT_STATE_IN_ALERTING)
        {
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect command only possible in setup, proceeding or alerting state.\n", p_name);
+               /* connect command only possible in setup, proceeding or alerting state */
                return;
        }
 
        /* preparing connect message */
        dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode);
-       isdn_show_send_message(CC_CONNECT | REQUEST, dmsg);
        connect = (CONNECT_t *)(dmsg->data + headerlen);
+       l3_trace_header(CC_CONNECT | REQUEST, DIRECTION_OUT);
        /* connect information */
        plan = 1;
        switch (p_connectinfo.ntype)
@@ -2769,6 +2893,7 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param
                epoint = find_epoint_id(epoint_id);
                enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds);
        }
+       end_trace();
        /* finally send message */
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
 
@@ -2805,12 +2930,13 @@ void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union pa
                }
                /* sending release */
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
+               l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
                /* send cause */
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
-               new_state(PORT_STATE_RELEASE);
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+               new_state(PORT_STATE_RELEASE);
                p_m_delete = 1;
                return;
        }
@@ -2822,8 +2948,8 @@ void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union pa
 
                /* sending proceeding */
                dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg);
                proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
+               l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
                /* channel information */
                enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
                /* progress information */
@@ -2831,14 +2957,15 @@ void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union pa
                 || p_capainfo.bearer_capa==INFO_BC_AUDIO
                 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
                        enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                new_state(PORT_STATE_IN_PROCEEDING);
        }
 
        /* sending disconnect */
        dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
-       isdn_show_send_message(CC_DISCONNECT | REQUEST, dmsg);
        disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
+       l3_trace_header(CC_DISCONNECT | REQUEST, DIRECTION_OUT);
        /* progress information */
        if (p_capainfo.bearer_capa==INFO_BC_SPEECH
         || p_capainfo.bearer_capa==INFO_BC_AUDIO
@@ -2852,8 +2979,9 @@ void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union pa
                p = param->disconnectinfo.display;
        if (p) if (*p && p_m_d_ntmode)
                enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
-       new_state(PORT_STATE_OUT_DISCONNECT);
+       end_trace();
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+       new_state(PORT_STATE_OUT_DISCONNECT);
 }
 
 /* MESSAGE_RELEASE */
@@ -2873,22 +3001,23 @@ void Pdss1::message_release(unsigned long epoint_id, int message_id, union param
        {
                /* sending release */
                dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_RELEASE | REQUEST, dmsg);
                release = (RELEASE_t *)(dmsg->data + headerlen);
+               l3_trace_header(CC_RELEASE | REQUEST, DIRECTION_OUT);
                /* send cause */
                enc_ie_cause(&release->CAUSE, dmsg, (p_m_d_ntmode && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
-               new_state(PORT_STATE_RELEASE);
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+               new_state(PORT_STATE_RELEASE);
                /* remove epoint */
                remove_endpoint:
                free_epointid(epoint_id);
+               l3_trace_header(CC_RELEASE_CR | REQUEST, DIRECTION_OUT);
+               add_trace("callref", "new", "0x%x", p_m_d_l3id);
+               end_trace();
                if (p_m_d_ntmode)
                {
                        if ((p_m_d_l3id&0xff00) == 0xff00)
-                       {
                                p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
-                               printisdn("    procid 0x%x freed\n", p_m_d_l3id&0xff);
-                       }
                }
                p_m_d_l3id = 0;
                p_m_delete = 1;
@@ -2902,12 +3031,13 @@ void Pdss1::message_release(unsigned long epoint_id, int message_id, union param
        {
                /* sending release */
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
-               isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
+               l3_trace_header(CC_RELEASE | REQUEST, DIRECTION_OUT);
                /* send cause */
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
-               new_state(PORT_STATE_RELEASE);
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+               new_state(PORT_STATE_RELEASE);
                goto remove_endpoint;
        }
 
@@ -2919,6 +3049,7 @@ void Pdss1::message_release(unsigned long epoint_id, int message_id, union param
                /* sending proceeding */
                dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
                proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
+               l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
                /* channel information */
                enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
                /* progress information */
@@ -2926,13 +3057,14 @@ void Pdss1::message_release(unsigned long epoint_id, int message_id, union param
                 || p_capainfo.bearer_capa==INFO_BC_AUDIO
                 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
                        enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+               end_trace();
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        }
 
        /* sending disconnect */
        dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
-       isdn_show_send_message(CC_DISCONNECT | REQUEST, dmsg);
        disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
+       l3_trace_header(CC_DISCONNECT | REQUEST, DIRECTION_OUT);
        /* progress information */
        if (p_capainfo.bearer_capa==INFO_BC_SPEECH
         || p_capainfo.bearer_capa==INFO_BC_AUDIO
@@ -2947,16 +3079,9 @@ void Pdss1::message_release(unsigned long epoint_id, int message_id, union param
                p = param->disconnectinfo.display;
        if (p) if (*p && p_m_d_ntmode)
                enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
-#if 0
-       /* sending release */
-       dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
-       isdn_show_send_message(CC_RELEASE | REQUEST, dmsg);
-       release = (RELEASE_t *)(dmsg->data + headerlen);
-       /* send cause */
-       enc_ie_cause(&release->CAUSE, dmsg, (p_m_d_ntmode && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
-#endif
-       new_state(PORT_STATE_RELEASE);
+       end_trace();
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+       new_state(PORT_STATE_RELEASE);
        free_epointid(epoint_id);
 //     p_m_delete = 1;
 }
@@ -2975,14 +3100,12 @@ int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union paramet
        switch(message_id)
        {
                case MESSAGE_INFORMATION: /* overlap dialing */
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) received dialing info '%s'.\n", p_name, param->information.number);
                if (p_type==PORT_TYPE_DSS1_NT_OUT
                 && p_state!=PORT_STATE_OUT_OVERLAP
                 && p_state!=PORT_STATE_CONNECT
                 && p_state!=PORT_STATE_OUT_DISCONNECT
                 && p_state!=PORT_STATE_IN_DISCONNECT)
                {
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) (internal outgoing) ignoring information, invalid state.\n", p_name);
                        break;
                }
                if (p_type==PORT_TYPE_DSS1_TE_OUT
@@ -2993,8 +3116,6 @@ int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union paramet
                 && p_state!=PORT_STATE_OUT_DISCONNECT
                 && p_state!=PORT_STATE_IN_DISCONNECT)
                {
-                       if (options.deb & DEBUG_ISDN)
-                               PERROR("Pdss1(%s) (external outgoing) ignoring information, invalid state.\n", p_name);
                        break;
                }
                if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
@@ -3006,14 +3127,12 @@ int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union paramet
                 && p_state!=PORT_STATE_OUT_DISCONNECT
                 && p_state!=PORT_STATE_IN_DISCONNECT)
                {
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) (incoming) ignoring information, invalid state.\n", p_name);
                        break;
                }
                message_information(epoint_id, message_id, param);
                break;
 
                case MESSAGE_SETUP: /* dial-out command received from epoint */
-               PDEBUG((DEBUG_ISDN | DEBUG_BCHANNEL), "Pdss1(%s) isdn port received setup from '%s' to '%s'\n", p_name, param->setup.callerinfo.id, param->setup.dialinginfo.number);
                if (p_state!=PORT_STATE_IDLE
                 && p_state!=PORT_STATE_CONNECT)
                {
@@ -3054,64 +3173,53 @@ int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union paramet
                break;
 
                case MESSAGE_NOTIFY: /* display and notifications */
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received notification: display='%s' notify=%d phone=%s\n", p_name, p_callerinfo.id, param->notifyinfo.display, param->notifyinfo.notify, param->notifyinfo.id);
                message_notify(epoint_id, message_id, param);
                break;
 
                case MESSAGE_FACILITY: /* facility message */
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received facility.\n", p_name, p_callerinfo.id);
                message_facility(epoint_id, message_id, param);
                break;
 
                case MESSAGE_OVERLAP: /* more information is needed */
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received setup acknowledge\n", p_name, p_callerinfo.id);
                if (p_state!=PORT_STATE_IN_SETUP)
                {
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring setup acknowledge because isdn port is not incoming setup state.\n", p_name);
                        break;
                }
                message_overlap(epoint_id, message_id, param);
                break;
 
                case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received proceeding\n", p_name, p_callerinfo.id);
                if (p_state!=PORT_STATE_IN_SETUP
                 && p_state!=PORT_STATE_IN_OVERLAP)
                {
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: proceeding command not possible in current state.\n", p_name);
                        break;
                }
                message_proceeding(epoint_id, message_id, param);
                break;
 
                case MESSAGE_ALERTING: /* call of endpoint is ringing */
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received alerting\n", p_name, p_callerinfo.id);
                if (p_state!=PORT_STATE_IN_SETUP
                 && p_state!=PORT_STATE_IN_OVERLAP
                 && p_state!=PORT_STATE_IN_PROCEEDING)
                {
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: alerting command not possible in current state.\n", p_name);
                        break;
                }
                message_alerting(epoint_id, message_id, param);
                break;
 
                case MESSAGE_CONNECT: /* call of endpoint is connected */
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received connect\n", p_name, p_callerinfo.id);
                if (p_state!=PORT_STATE_IN_SETUP
                 && p_state!=PORT_STATE_IN_OVERLAP
                 && p_state!=PORT_STATE_IN_PROCEEDING
                 && p_state!=PORT_STATE_IN_ALERTING
                 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
                {
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: connect command not possible in current state.\n", p_name);
                        break;
                }
                message_connect(epoint_id, message_id, param);
                break;
 
                case MESSAGE_DISCONNECT: /* call has been disconnected */
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received disconnect cause=%d\n", p_name, p_callerinfo.id, param->disconnectinfo.cause);
                if (p_state!=PORT_STATE_IN_SETUP
                 && p_state!=PORT_STATE_IN_OVERLAP
                 && p_state!=PORT_STATE_IN_PROCEEDING
@@ -3123,24 +3231,21 @@ int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union paramet
                 && p_state!=PORT_STATE_CONNECT
                 && p_state!=PORT_STATE_CONNECT_WAITING)
                {
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: disconnect command not possible in current state.\n", p_name);
                        break;
                }
                message_disconnect(epoint_id, message_id, param);
                break;
 
                case MESSAGE_RELEASE: /* release isdn port */
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received release cause=%d\n", p_name, p_callerinfo.id, param->disconnectinfo.cause);
                if (p_state==PORT_STATE_RELEASE)
                {
-                       PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: release command not possible in RELEASE state.\n", p_name);
                        break;
                }
                message_release(epoint_id, message_id, param);
                break;
 
                default:
-               PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message);
+               PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message);
        }
 
        return(1);
@@ -3259,7 +3364,7 @@ int stack2manager_nt(void *dat, void *arg)
                        RELEASE_COMPLETE_t *release_complete;
                        msg_t *dmsg;
 
-                       fprintf(stderr, "FATAL ERROR: cannot create port object.\n");
+                       PERROR("FATAL ERROR: cannot create port object.\n");
                        dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, hh->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode);
                        release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN);
                        enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
@@ -3277,7 +3382,7 @@ int stack2manager_nt(void *dat, void *arg)
                        SUSPEND_REJECT_t *suspend_reject;
                        msg_t *dmsg;
 
-                       fprintf(stderr, "FATAL ERROR: cannot create port object.\n");
+                       PERROR("FATAL ERROR: cannot create port object.\n");
                        dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, hh->dinfo, sizeof(SUSPEND_REJECT_t), mISDNport->ntmode);
                        suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + mISDN_HEADER_LEN);
                        enc_ie_cause_standalone(mISDNport->ntmode?&suspend_reject->CAUSE:NULL, dmsg, (mISDNport->ntmode)?1:0, 47);
@@ -3288,14 +3393,14 @@ int stack2manager_nt(void *dat, void *arg)
                break;
 
                case CC_RELEASE_CR | INDICATION:
-               PDEBUG(DEBUG_ISDN, "%s: unhandled message from stack: call ref released (l3id=0x%x)\n", __FUNCTION__, hh->dinfo);
+               PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", hh->dinfo);
                break;
 
                case CC_DISCONNECT | INDICATION:
 
                // fall throug
                default:
-               PDEBUG(DEBUG_ISDN, "%s: unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", __FUNCTION__, hh->prim, hh->dinfo, msg->len);
+               PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
                return(-EINVAL);
        }
        free_msg(msg);
@@ -3322,7 +3427,6 @@ int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg)
                if (port->p_type == PORT_TYPE_DSS1_TE_IN || port->p_type == PORT_TYPE_DSS1_TE_OUT)
                {
                        pdss1 = (class Pdss1 *)port;
-//PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", frm->dinfo, pdss1->p_m_d_l3id);
                        /* check out correct stack */
                        if (pdss1->p_m_mISDNport == mISDNport)
                        /* check out correct id */
@@ -3353,7 +3457,7 @@ int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg)
                        RELEASE_COMPLETE_t *release_complete;
                        msg_t *dmsg;
 
-                       fprintf(stderr, "FATAL ERROR: cannot create port object.\n");
+                       PERROR("FATAL ERROR: cannot create port object.\n");
                        dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, frm->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode);
                        release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN);
                        enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
@@ -3369,11 +3473,11 @@ int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg)
 
        if (frm->prim == (CC_RELEASE_CR | INDICATION))
        {
-               PDEBUG(DEBUG_ISDN, "unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo);
+               PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo);
                free_msg(msg);
                return(0);
        }
-       PDEBUG(DEBUG_ISDN, "unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
+       PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
        return(-EINVAL);
 }