socket api work
authorSuper User <root@isdn.jolly.ten>
Mon, 24 Mar 2008 10:13:44 +0000 (11:13 +0100)
committerSuper User <root@isdn.jolly.ten>
Mon, 24 Mar 2008 10:13:44 +0000 (11:13 +0100)
modified:   apppbx.cpp
modified:   cause.c
modified:   dss1.cpp
modified:   dss1.h
modified:   ie.cpp
modified:   interface.c
modified:   mISDN.cpp
modified:   mISDN.h
modified:   main.c
modified:   main.h
modified:   message.c
modified:   options.c
modified:   port.cpp
modified:   q931.h
modified:   route.c
modified:   socket_server.c
modified:   tones.c

17 files changed:
apppbx.cpp
cause.c
dss1.cpp
dss1.h
ie.cpp
interface.c
mISDN.cpp
mISDN.h
main.c
main.h
message.c
options.c
port.cpp
q931.h
route.c
socket_server.c
tones.c

index 077aae5..bf89388 100644 (file)
@@ -2845,7 +2845,7 @@ void EndpointAppPBX::join_facility(struct port_list *portlist, int message_type,
 {
        struct message *message;
 
 {
        struct message *message;
 
-       if (!e_ext.facility)
+       if (!e_ext.facility && e_ext.number[0])
        {
                return;
        }
        {
                return;
        }
diff --git a/cause.c b/cause.c
index 825daaa..46b870b 100644 (file)
--- a/cause.c
+++ b/cause.c
@@ -9,9 +9,6 @@
 **                                                                           **
 \*****************************************************************************/ 
 
 **                                                                           **
 \*****************************************************************************/ 
 
-#include "stdio.h"
-#include "sys/types.h"
-#include "string.h"
 #include "main.h"
 
 struct isdn_cause isdn_cause[128] = {
 #include "main.h"
 
 struct isdn_cause isdn_cause[128] = {
index ead7b56..9e7a230 100644 (file)
--- a/dss1.cpp
+++ b/dss1.cpp
@@ -71,8 +71,19 @@ Pdss1::~Pdss1()
 /*
  * create layer 3 message
  */
 /*
  * create layer 3 message
  */
+#ifdef SOCKET_MISDN
+static struct l3_msg *create_l3msg(void)
+#else
 static msg_t *create_l3msg(int prim, int mt, int dinfo, int size, int ntmode)
 static msg_t *create_l3msg(int prim, int mt, int dinfo, int size, int ntmode)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       struct l3_msg *l3m;
+
+       l3m = alloc_l3_msg();
+       if (l3m)
+               return(l3m);
+#else
        msg_t *dmsg;
        Q931_info_t *qi;
        iframe_t *frm;
        msg_t *dmsg;
        Q931_info_t *qi;
        iframe_t *frm;
@@ -101,11 +112,13 @@ static msg_t *create_l3msg(int prim, int mt, int dinfo, int size, int ntmode)
                        return(dmsg);
                }
        }
                        return(dmsg);
                }
        }
+#endif
 
        FATAL("Cannot allocate memory, system overloaded.\n");
        exit(0); // make gcc happy
 }
 
 
        FATAL("Cannot allocate memory, system overloaded.\n");
        exit(0); // make gcc happy
 }
 
+#ifndef SOCKET_MISDN
 msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */
 {
        msg_t *dmsg;
 msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */
 {
        msg_t *dmsg;
@@ -117,6 +130,7 @@ msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */
        FATAL("Cannot allocate memory, system overloaded.\n");
        exit(0); // make gcc happy
 }
        FATAL("Cannot allocate memory, system overloaded.\n");
        exit(0); // make gcc happy
 }
+#endif
 
 /*
  * if we received a first reply to the setup message,
 
 /*
  * if we received a first reply to the setup message,
@@ -127,9 +141,13 @@ msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */
 int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int exclusive)
 {
        int ret;
 int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int exclusive)
 {
        int ret;
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        RELEASE_COMPLETE_t *release_complete;
        msg_t *dmsg;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        RELEASE_COMPLETE_t *release_complete;
        msg_t *dmsg;
+#endif
 
        /* correct exclusive to 0, if no explicit channel was given */
        if (exclusive<0 || channel<=0)
 
        /* correct exclusive to 0, if no explicit channel was given */
        if (exclusive<0 || channel<=0)
@@ -315,12 +333,28 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex
        return(0);
 
        channelerror:
        return(0);
 
        channelerror:
+       /*
+        * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
+        * in response to the setup reply
+        */
+#ifdef SOCKET_MISDN
+       l3m = create_l3msg();
+#else
        dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
        release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
        dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
        release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
+#endif
        l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
        l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
+#ifdef SOCKET_MISDN
+       enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
+#else
        enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
        enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
+#endif
        end_trace();
        end_trace();
+#ifdef SOCKET_MISDN
+       p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE_COMPLETE, l3m);
+#else
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
        new_state(PORT_STATE_RELEASE);
        p_m_delete = 1;
        return(-34); /* to epoint: no channel available */
        new_state(PORT_STATE_RELEASE);
        p_m_delete = 1;
        return(-34); /* to epoint: no channel available */
@@ -462,8 +496,13 @@ use_channel:
 /* CC_SETUP INDICATION */
 void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
 {
 /* CC_SETUP INDICATION */
 void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
+       msg_t *dmsg;
        SETUP_t *setup = (SETUP_t *)((unsigned long)data + headerlen);
        SETUP_t *setup = (SETUP_t *)((unsigned long)data + headerlen);
+#endif
        int calling_type, calling_plan, calling_present, calling_screen;
        int called_type, called_plan;
        int redir_type, redir_plan, redir_present, redir_screen, redir_reason;
        int calling_type, calling_plan, calling_present, calling_screen;
        int called_type, called_plan;
        int redir_type, redir_plan, redir_present, redir_screen, redir_reason;
@@ -471,7 +510,6 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
        int bearer_coding, bearer_capability, bearer_mode, bearer_rate, bearer_multi, bearer_user;
        int exclusive, channel;
        int ret;
        int bearer_coding, bearer_capability, bearer_mode, bearer_rate, bearer_multi, bearer_user;
        int exclusive, channel;
        int ret;
-       msg_t *dmsg;
        unsigned char keypad[32] = "";
        unsigned char useruser[128];
        int useruser_len = 0, useruser_protocol;
        unsigned char keypad[32] = "";
        unsigned char useruser[128];
        int useruser_len = 0, useruser_protocol;
@@ -510,18 +548,30 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
        dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
        end_trace();
 
        dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
        end_trace();
 
-       /* if blocked, release call */
+       /* if blocked, release call with MT_RELEASE_COMPLETE */
        if (p_m_mISDNport->ifport->block)
        {
                RELEASE_COMPLETE_t *release_complete;
 
        if (p_m_mISDNport->ifport->block)
        {
                RELEASE_COMPLETE_t *release_complete;
 
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
+#ifdef SOCKET_MISDN
+               enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
+#else
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
+#endif
                add_trace("reason", NULL, "port blocked");
                end_trace();
                add_trace("reason", NULL, "port blocked");
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE_COMPLETE, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
                new_state(PORT_STATE_RELEASE);
                p_m_delete = 1;
                return;
                new_state(PORT_STATE_RELEASE);
                p_m_delete = 1;
                return;
@@ -715,14 +765,29 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
        if (ret < 0)
        {
                no_channel:
        if (ret < 0)
        {
                no_channel:
+               /*
+                * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
+                * in response to the setup
+                */
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                RELEASE_COMPLETE_t *release_complete;
                RELEASE_COMPLETE_t *release_complete;
-
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
+#ifdef SOCKET_MISDN
+               enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
+#else
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
+#endif
                end_trace();
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE_COMPLETE, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
                new_state(PORT_STATE_RELEASE);
                p_m_delete = 1;
                return;
                new_state(PORT_STATE_RELEASE);
                p_m_delete = 1;
                return;
@@ -996,15 +1061,19 @@ void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data)
 /* CC_CONNECT INDICATION */
 void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
 {
 /* CC_CONNECT INDICATION */
 void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
+       msg_t *dmsg;
        CONNECT_t *connect = (CONNECT_t *)((unsigned long)data + headerlen);
        CONNECT_t *connect = (CONNECT_t *)((unsigned long)data + headerlen);
+       CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
+#endif
        int exclusive, channel;
        int type, plan, present, screen;
        int ret;
        int exclusive, channel;
        int type, plan, present, screen;
        int ret;
-       msg_t *dmsg;
        struct message *message;
        int bchannel_before;
        struct message *message;
        int bchannel_before;
-       CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
 
        if (p_m_d_ntmode)
                p_m_d_ces = connect->ces;
 
        if (p_m_d_ntmode)
                p_m_d_ces = connect->ces;
@@ -1079,14 +1148,26 @@ void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
        if (p_m_d_ntmode)
        {
                /* send connect acknowledge */
        if (p_m_d_ntmode)
        {
                /* send connect acknowledge */
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode);
                connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
                dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode);
                connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | RESPONSE, DIRECTION_OUT);
                /* if we had no bchannel before, we send it now */
                if (!bchannel_before && p_m_b_channel)
                l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | RESPONSE, DIRECTION_OUT);
                /* if we had no bchannel before, we send it now */
                if (!bchannel_before && p_m_b_channel)
+#ifdef SOCKET_MISDN
+                       enc_ie_channel_id(l3m, 1, p_m_b_channel);
+#else
                        enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
                        enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
+#endif
                end_trace();
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_CONNECT, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
        }
        
        message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
        }
        
        message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
@@ -1118,16 +1199,32 @@ void Pdss1::disconnect_ind(unsigned long prim, unsigned long dinfo, void *data)
        /* release if remote sends us no tones */
        if (!p_m_mISDNport->earlyb)
        {
        /* release if remote sends us no tones */
        if (!p_m_mISDNport->earlyb)
        {
-               RELEASE_t *release;
+#ifdef SOCKET_MISDN
+               l3_msg *l3m;
+#else
                msg_t *dmsg;
                msg_t *dmsg;
+               RELEASE_t *release;
+#endif
 
 
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, dinfo, sizeof(RELEASE_t), p_m_d_ntmode);
                release = (RELEASE_t *)(dmsg->data + headerlen);
                dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, dinfo, sizeof(RELEASE_t), p_m_d_ntmode);
                release = (RELEASE_t *)(dmsg->data + headerlen);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
+#ifdef SOCKET_MISDN
+               enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
+#else
                enc_ie_cause(&release->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
                enc_ie_cause(&release->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
+#endif
                add_trace("reason", NULL, "no remote patterns");
                end_trace();
                add_trace("reason", NULL, "no remote patterns");
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
 
                /* sending release to endpoint */
                while(p_epointlist)
 
                /* sending release to endpoint */
                while(p_epointlist)
@@ -1193,9 +1290,13 @@ void Pdss1::disconnect_ind_i(unsigned long prim, unsigned long dinfo, void *data
 /* CC_RELEASE INDICATION */
 void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
 {
 /* CC_RELEASE INDICATION */
 void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
-       RELEASE_t *release = (RELEASE_t *)((unsigned long)data + headerlen);
        msg_t *dmsg;
        msg_t *dmsg;
+       RELEASE_t *release = (RELEASE_t *)((unsigned long)data + headerlen);
+#endif
        int location, cause;
        struct message *message;
 
        int location, cause;
        struct message *message;
 
@@ -1225,12 +1326,24 @@ void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
                /* sending release complete */
                RELEASE_COMPLETE_t *release_complete;
 
                /* sending release complete */
                RELEASE_COMPLETE_t *release_complete;
 
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
+#ifdef SOCKET_MISDN
+               enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
+#else
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
+#endif
                end_trace();
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE_COMPLETE, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
        }
 
        new_state(PORT_STATE_RELEASE);
        }
 
        new_state(PORT_STATE_RELEASE);
@@ -1361,12 +1474,16 @@ void Pdss1::notify_ind(unsigned long prim, unsigned long dinfo, void *data)
 /* CC_HOLD INDICATION */
 void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
 {
 /* CC_HOLD INDICATION */
 void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
 {
+       struct message *message;
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
+       msg_t *dmsg;
 //     HOLD_t *hold = (HOLD_t *)((unsigned long)data + headerlen);
 //     HOLD_t *hold = (HOLD_t *)((unsigned long)data + headerlen);
-       struct message *message;
        HOLD_REJECT_t *hold_reject;
        HOLD_ACKNOWLEDGE_t *hold_acknowledge;
        HOLD_REJECT_t *hold_reject;
        HOLD_ACKNOWLEDGE_t *hold_acknowledge;
-       msg_t *dmsg;
+#endif
 //     class Endpoint *epoint;
 
        l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
 //     class Endpoint *epoint;
 
        l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
@@ -1374,13 +1491,25 @@ void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
 
        if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
        {
 
        if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
        {
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                dmsg = create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, dinfo, sizeof(HOLD_REJECT_t), p_m_d_ntmode);
                hold_reject = (HOLD_REJECT_t *)(dmsg->data + headerlen);
                dmsg = create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, dinfo, sizeof(HOLD_REJECT_t), p_m_d_ntmode);
                hold_reject = (HOLD_REJECT_t *)(dmsg->data + headerlen);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_REJECT | REQUEST, DIRECTION_OUT);
                l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_REJECT | REQUEST, DIRECTION_OUT);
+#ifdef SOCKET_MISDN
+               enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
+#else
                enc_ie_cause(&hold_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
                enc_ie_cause(&hold_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
+#endif
                add_trace("reason", NULL, "no endpoint");
                end_trace();
                add_trace("reason", NULL, "no endpoint");
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_HOLD_REJECT, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
 
                return;
        }
 
                return;
        }
@@ -1409,24 +1538,36 @@ void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
 #endif
 
        /* acknowledge hold */
 #endif
 
        /* acknowledge hold */
+#ifdef SOCKET_MISDN
+       l3m = create_l3msg();
+#else
        dmsg = create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, dinfo, sizeof(HOLD_ACKNOWLEDGE_t), p_m_d_ntmode);
        hold_acknowledge = (HOLD_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
        dmsg = create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, dinfo, sizeof(HOLD_ACKNOWLEDGE_t), p_m_d_ntmode);
        hold_acknowledge = (HOLD_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
+#endif
        l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
        end_trace();
        l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
        end_trace();
+#ifdef SOCKET_MISDN
+       p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_HOLD_ACKNOWLEDGE, l3m);
+#else
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
 }
 
 
 /* CC_RETRIEVE INDICATION */
 void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
 {
 }
 
 
 /* CC_RETRIEVE INDICATION */
 void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
+       msg_t *dmsg;
        RETRIEVE_t *retrieve = (RETRIEVE_t *)((unsigned long)data + headerlen);
        RETRIEVE_REJECT_t *retrieve_reject;
        RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
        RETRIEVE_t *retrieve = (RETRIEVE_t *)((unsigned long)data + headerlen);
        RETRIEVE_REJECT_t *retrieve_reject;
        RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
+#endif
        struct message *message;
        int channel, exclusive, cause;
        struct message *message;
        int channel, exclusive, cause;
-       msg_t *dmsg;
        int ret;
 
        l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
        int ret;
 
        l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
@@ -1438,12 +1579,24 @@ void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
                cause = 101; /* incompatible state */
                reject:
 
                cause = 101; /* incompatible state */
                reject:
 
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                dmsg = create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, dinfo, sizeof(RETRIEVE_REJECT_t), p_m_d_ntmode);
                retrieve_reject = (RETRIEVE_REJECT_t *)(dmsg->data + headerlen);
                dmsg = create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, dinfo, sizeof(RETRIEVE_REJECT_t), p_m_d_ntmode);
                retrieve_reject = (RETRIEVE_REJECT_t *)(dmsg->data + headerlen);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_REJECT | REQUEST, DIRECTION_OUT);
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_REJECT | REQUEST, DIRECTION_OUT);
+#ifdef SOCKET_MISDN
+               enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
+#else
                enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
                enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
+#endif
                end_trace();
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RETRIEVE_REJECT, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
 
                return;
        }
 
                return;
        }
@@ -1474,26 +1627,42 @@ void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
        p_m_timeout = 0;
 
        /* acknowledge retrieve */
        p_m_timeout = 0;
 
        /* acknowledge retrieve */
+#ifdef SOCKET_MISDN
+       l3m = create_l3msg();
+#else
        dmsg = create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, dinfo, sizeof(RETRIEVE_ACKNOWLEDGE_t), p_m_d_ntmode);
        retrieve_acknowledge = (RETRIEVE_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
        dmsg = create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, dinfo, sizeof(RETRIEVE_ACKNOWLEDGE_t), p_m_d_ntmode);
        retrieve_acknowledge = (RETRIEVE_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
+#endif
        l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
        l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
+#ifdef SOCKET_MISDN
+       enc_ie_channel_id(l3m, 1, p_m_b_channel);
+#else
        enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
        enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
+#endif
        end_trace();
        end_trace();
+#ifdef SOCKET_MISDN
+       p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RETRIEVE_ACKNOWLEDGE, l3m);
+#else
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
 }
 
 /* CC_SUSPEND INDICATION */
 void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
 {
 }
 
 /* CC_SUSPEND INDICATION */
 void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
+       msg_t *dmsg;
        SUSPEND_t *suspend = (SUSPEND_t *)((unsigned long)data + headerlen);
        SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
        SUSPEND_REJECT_t *suspend_reject;
        SUSPEND_t *suspend = (SUSPEND_t *)((unsigned long)data + headerlen);
        SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
        SUSPEND_REJECT_t *suspend_reject;
+#endif
        struct message *message;
        class Endpoint *epoint;
        unsigned char callid[8];
        int len;
        struct message *message;
        class Endpoint *epoint;
        unsigned char callid[8];
        int len;
-       msg_t *dmsg;
        int ret = -31; /* normal, unspecified */
 
        l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
        int ret = -31; /* normal, unspecified */
 
        l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
@@ -1503,12 +1672,24 @@ void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
        if (!ACTIVE_EPOINT(p_epointlist))
        {
                reject:
        if (!ACTIVE_EPOINT(p_epointlist))
        {
                reject:
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, dinfo, sizeof(SUSPEND_REJECT_t), p_m_d_ntmode);
                suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + headerlen);
                dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, dinfo, sizeof(SUSPEND_REJECT_t), p_m_d_ntmode);
                suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + headerlen);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_REJECT | REQUEST, DIRECTION_OUT);
                l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_REJECT | REQUEST, DIRECTION_OUT);
+#ifdef SOCKET_MISDN
+               enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
+#else
                enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
                enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
+#endif
                end_trace();
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_SUSPEND_REJECT, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
 
                return;
        }
 
                return;
        }
@@ -1556,11 +1737,19 @@ void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
        }
 
        /* sending SUSPEND_ACKNOWLEDGE */
        }
 
        /* sending SUSPEND_ACKNOWLEDGE */
+#ifdef SOCKET_MISDN
+       l3m = create_l3msg();
+#else
        dmsg = create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, dinfo, sizeof(SUSPEND_ACKNOWLEDGE_t), p_m_d_ntmode);
        suspend_acknowledge = (SUSPEND_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
        dmsg = create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, dinfo, sizeof(SUSPEND_ACKNOWLEDGE_t), p_m_d_ntmode);
        suspend_acknowledge = (SUSPEND_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
+#endif
        l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
        end_trace();
        l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
        end_trace();
+#ifdef SOCKET_MISDN
+       p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_SUSPEND_ACKNOWLEDGE, l3m);
+#else
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
 
        new_state(PORT_STATE_RELEASE);
        p_m_delete = 1;
 
        new_state(PORT_STATE_RELEASE);
        p_m_delete = 1;
@@ -1569,14 +1758,18 @@ void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
 /* CC_RESUME INDICATION */
 void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
 {
 /* CC_RESUME INDICATION */
 void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
+       msg_t *dmsg;
        RESUME_t *resume = (RESUME_t *)((unsigned long)data + headerlen);
        RESUME_REJECT_t *resume_reject;
        RESUME_ACKNOWLEDGE_t *resume_acknowledge;
        RESUME_t *resume = (RESUME_t *)((unsigned long)data + headerlen);
        RESUME_REJECT_t *resume_reject;
        RESUME_ACKNOWLEDGE_t *resume_acknowledge;
+#endif
        unsigned char callid[8];
        int len;
        int channel, exclusive;
        unsigned char callid[8];
        int len;
        int channel, exclusive;
-       msg_t *dmsg;
        class Endpoint *epoint;
        struct message *message;
        int ret;
        class Endpoint *epoint;
        struct message *message;
        int ret;
@@ -1627,14 +1820,26 @@ void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
        {
                no_channel:
                reject:
        {
                no_channel:
                reject:
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                dmsg = create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, dinfo, sizeof(RESUME_REJECT_t), p_m_d_ntmode);
                resume_reject = (RESUME_REJECT_t *)(dmsg->data + headerlen);
                dmsg = create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, dinfo, sizeof(RESUME_REJECT_t), p_m_d_ntmode);
                resume_reject = (RESUME_REJECT_t *)(dmsg->data + headerlen);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_REJECT | REQUEST, DIRECTION_OUT);
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_REJECT | REQUEST, DIRECTION_OUT);
+#ifdef SOCKET_MISDN
+               enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
+#else
                enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
                enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
+#endif
                if (ret == -27)
                        add_trace("reason", NULL, "port blocked");
                end_trace();
                if (ret == -27)
                        add_trace("reason", NULL, "port blocked");
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RESUME_REJECT, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
                new_state(PORT_STATE_RELEASE);
                p_m_delete = 1;
                return;
                new_state(PORT_STATE_RELEASE);
                p_m_delete = 1;
                return;
@@ -1673,12 +1878,24 @@ void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
        message_put(message);
 
        /* sending RESUME_ACKNOWLEDGE */
        message_put(message);
 
        /* sending RESUME_ACKNOWLEDGE */
+#ifdef SOCKET_MISDN
+       l3m = create_l3msg();
+#else
        dmsg = create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, dinfo, sizeof(RESUME_ACKNOWLEDGE_t), p_m_d_ntmode);
        resume_acknowledge = (RESUME_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
        dmsg = create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, dinfo, sizeof(RESUME_ACKNOWLEDGE_t), p_m_d_ntmode);
        resume_acknowledge = (RESUME_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
+#endif
        l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
        l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
+#ifdef SOCKET_MISDN
+       enc_ie_channel_id(l3m, 1, p_m_b_channel);
+#else
        enc_ie_channel_id(&resume_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
        enc_ie_channel_id(&resume_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
+#endif
        end_trace();
        end_trace();
+#ifdef SOCKET_MISDN
+       p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RESUME_ACKNOWDGE, l3m);
+#else
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
 
        new_state(PORT_STATE_CONNECT);
 }
 
        new_state(PORT_STATE_CONNECT);
 }
@@ -1996,18 +2213,34 @@ int Pdss1::handler(void)
 /* MESSAGE_INFORMATION */
 void Pdss1::message_information(unsigned long epoint_id, int message_id, union parameter *param)
 {
 /* MESSAGE_INFORMATION */
 void Pdss1::message_information(unsigned long epoint_id, int message_id, union parameter *param)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
-       INFORMATION_t *information;
        msg_t *dmsg;
        msg_t *dmsg;
+       INFORMATION_t *information;
+#endif
 
        if (param->information.id[0]) /* only if we have something to dial */
        {
 
        if (param->information.id[0]) /* only if we have something to dial */
        {
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
                information = (INFORMATION_t *)(dmsg->data + headerlen);
                dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
                information = (INFORMATION_t *)(dmsg->data + headerlen);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
                l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
+#ifdef SOCKET_MISDN
+               enc_ie_called_pn(l3m, 0, 1, (unsigned char *)param->information.id);
+#else
                enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.id);
                enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.id);
+#endif
                end_trace();
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_INFORMATION, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
        }
        new_state(p_state);
 }
        }
        new_state(p_state);
 }
@@ -2018,10 +2251,14 @@ int newteid = 0;
 /* MESSAGE_SETUP */
 void Pdss1::message_setup(unsigned long epoint_id, int message_id, union parameter *param)
 {
 /* MESSAGE_SETUP */
 void Pdss1::message_setup(unsigned long epoint_id, int message_id, union parameter *param)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
+       msg_t *dmsg;
        INFORMATION_t *information;
        SETUP_t *setup;
        INFORMATION_t *information;
        SETUP_t *setup;
-       msg_t *dmsg;
+#endif
        int plan, type, screen, present, reason;
        int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
        int channel, exclusive;
        int plan, type, screen, present, reason;
        int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
        int channel, exclusive;
@@ -2060,13 +2297,25 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet
                if (p_callerinfo.display[0])
                {
                        /* sending information */
                if (p_callerinfo.display[0])
                {
                        /* sending information */
+#ifdef SOCKET_MISDN
+                       l3m = create_l3msg();
+#else
                        dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
                        information = (INFORMATION_t *)(dmsg->data + headerlen);
                        dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
                        information = (INFORMATION_t *)(dmsg->data + headerlen);
+#endif
                        l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
                        if (p_m_d_ntmode)
                        l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
                        if (p_m_d_ntmode)
+#ifdef SOCKET_MISDN
+                               enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
+#else
                                enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
                                enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
+#endif
                        end_trace();
                        end_trace();
+#ifdef SOCKET_MISDN
+                       p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_INFORMATION, l3m);
+#else
                        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
                        return;
                }
        }
                        return;
                }
        }
@@ -2142,13 +2391,21 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet
        end_trace();
 
        /* preparing setup message */
        end_trace();
 
        /* preparing setup message */
+#ifdef SOCKET_MISDN
+       l3m = create_l3msg();
+#else
        dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode);
        setup = (SETUP_t *)(dmsg->data + headerlen);
        dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode);
        setup = (SETUP_t *)(dmsg->data + headerlen);
+#endif
        l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP | REQUEST, DIRECTION_OUT);
        /* channel information */
        if (channel >= 0) /* it should */
        {
        l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP | REQUEST, DIRECTION_OUT);
        /* channel information */
        if (channel >= 0) /* it should */
        {
+#ifdef SOCKET_MISDN
+               enc_ie_channel_id(l3m, exclusive, channel);
+#else
                enc_ie_channel_id(&setup->CHANNEL_ID, dmsg, exclusive, channel);
                enc_ie_channel_id(&setup->CHANNEL_ID, dmsg, exclusive, channel);
+#endif
        }
        /* caller information */
        plan = 1;
        }
        /* caller information */
        plan = 1;
@@ -2189,19 +2446,35 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet
                break;
        }
        if (type >= 0)
                break;
        }
        if (type >= 0)
+#ifdef SOCKET_MISDN
+               enc_ie_calling_pn(l3m, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
+#else
                enc_ie_calling_pn(&setup->CALLING_PN, dmsg, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
                enc_ie_calling_pn(&setup->CALLING_PN, dmsg, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
+#endif
        /* dialing information */
        if (p_dialinginfo.id[0]) /* only if we have something to dial */
        {
        /* dialing information */
        if (p_dialinginfo.id[0]) /* only if we have something to dial */
        {
+#ifdef SOCKET_MISDN
+               enc_ie_called_pn(l3m, 0, 1, (unsigned char *)p_dialinginfo.id);
+#else
                enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.id);
                enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.id);
+#endif
        }
        /* sending complete */
        if (p_dialinginfo.sending_complete)
        }
        /* sending complete */
        if (p_dialinginfo.sending_complete)
+#ifdef SOCKET_MISDN
+               enc_ie_complete(l3m, 1);
+#else
                enc_ie_complete(&setup->COMPLETE, dmsg, 1);
                enc_ie_complete(&setup->COMPLETE, dmsg, 1);
+#endif
        /* sending user-user */
        if (param->setup.useruser.len)
        {
        /* sending user-user */
        if (param->setup.useruser.len)
        {
+#ifdef SOCKET_MISDN
+               enc_ie_useruser(l3m, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
+#else
                enc_ie_useruser(&setup->USER_USER, dmsg, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
                enc_ie_useruser(&setup->USER_USER, dmsg, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
+#endif
        }
        /* redirecting number */
        plan = 1;
        }
        /* redirecting number */
        plan = 1;
@@ -2271,7 +2544,11 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet
        }
        /* sending redirecting number only in ntmode */
        if (type >= 0 && p_m_d_ntmode)
        }
        /* sending redirecting number only in ntmode */
        if (type >= 0 && p_m_d_ntmode)
+#ifdef SOCKET_MISDN
+               enc_ie_redir_nr(l3m, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
+#else
                enc_ie_redir_nr(&setup->REDIR_NR, dmsg, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
                enc_ie_redir_nr(&setup->REDIR_NR, dmsg, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
+#endif
        /* bearer capability */
 //printf("hlc=%d\n",p_capainfo.hlc);
        coding = 0;
        /* bearer capability */
 //printf("hlc=%d\n",p_capainfo.hlc);
        coding = 0;
@@ -2287,7 +2564,11 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet
                user = p_capainfo.bearer_info1 & 0x7f;
                break;
        }
                user = p_capainfo.bearer_info1 & 0x7f;
                break;
        }
+#ifdef SOCKET_MISDN
+       enc_ie_bearer(l3m, coding, capability, mode, rate, -1, user);
+#else
        enc_ie_bearer(&setup->BEARER, dmsg, coding, capability, mode, rate, -1, user);
        enc_ie_bearer(&setup->BEARER, dmsg, coding, capability, mode, rate, -1, user);
+#endif
        /* hlc */
        if (p_capainfo.hlc)
        {
        /* hlc */
        if (p_capainfo.hlc)
        {
@@ -2298,19 +2579,31 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet
                exthlc = -1;
                if (p_capainfo.exthlc)
                        exthlc = p_capainfo.exthlc & 0x7f;
                exthlc = -1;
                if (p_capainfo.exthlc)
                        exthlc = p_capainfo.exthlc & 0x7f;
+#ifdef SOCKET_MISDN
+               enc_ie_hlc(l3m, coding, interpretation, presentation, hlc, exthlc);
+#else
                enc_ie_hlc(&setup->HLC, dmsg, coding, interpretation, presentation, hlc, exthlc);
                enc_ie_hlc(&setup->HLC, dmsg, coding, interpretation, presentation, hlc, exthlc);
+#endif
        }
 
        /* display */
        if (p_callerinfo.display[0] && p_m_d_ntmode)
        }
 
        /* display */
        if (p_callerinfo.display[0] && p_m_d_ntmode)
+#ifdef SOCKET_MISDN
+               enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
+#else
                enc_ie_display(&setup->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
                enc_ie_display(&setup->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
+#endif
        /* nt-mode: CNIP (calling name identification presentation) */
 //     if (p_callerinfo.name[0] && p_m_d_ntmode)
 //             enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
        end_trace();
 
        /* send setup message now */
        /* nt-mode: CNIP (calling name identification presentation) */
 //     if (p_callerinfo.name[0] && p_m_d_ntmode)
 //             enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
        end_trace();
 
        /* send setup message now */
+#ifdef SOCKET_MISDN
+       p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_SETUP, l3m);
+#else
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
 
        new_state(PORT_STATE_OUT_SETUP);
 }
 
        new_state(PORT_STATE_OUT_SETUP);
 }
@@ -2318,32 +2611,52 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet
 /* MESSAGE_FACILITY */
 void Pdss1::message_facility(unsigned long epoint_id, int message_id, union parameter *param)
 {
 /* MESSAGE_FACILITY */
 void Pdss1::message_facility(unsigned long epoint_id, int message_id, union parameter *param)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
-       FACILITY_t *facility;
        msg_t *dmsg;
        msg_t *dmsg;
+       FACILITY_t *facility;
+#endif
 
        /* facility will not be sent to external lines */
        if (!p_m_d_ntmode)
                return;
 
        /* sending facility */
 
        /* facility will not be sent to external lines */
        if (!p_m_d_ntmode)
                return;
 
        /* sending facility */
+#ifdef SOCKET_MISDN
+       l3m = create_l3msg();
+#else
        dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode);
        facility = (FACILITY_t *)(dmsg->data + headerlen);
        dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode);
        facility = (FACILITY_t *)(dmsg->data + headerlen);
+#endif
        l1l2l3_trace_header(p_m_mISDNport, this, CC_FACILITY | REQUEST, DIRECTION_OUT);
        l1l2l3_trace_header(p_m_mISDNport, this, CC_FACILITY | REQUEST, DIRECTION_OUT);
+#ifdef SOCKET_MISDN
+       enc_ie_facility(l3m, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
+#else
        enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
        enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
+#endif
        end_trace();
        end_trace();
+#ifdef SOCKET_MISDN
+       p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_FACILITY, l3m);
+#else
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
 }
 
 /* MESSAGE_NOTIFY */
 void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parameter *param)
 {
 }
 
 /* MESSAGE_NOTIFY */
 void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parameter *param)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
+       msg_t *dmsg;
        INFORMATION_t *information;
        NOTIFY_t *notification;
        INFORMATION_t *information;
        NOTIFY_t *notification;
+#endif
        int notify;
        int plan, type = -1, present;
        int notify;
        int plan, type = -1, present;
-       msg_t *dmsg;
 
        if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
                notify = param->notifyinfo.notify & 0x7f;
 
        if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
                notify = param->notifyinfo.notify & 0x7f;
@@ -2409,52 +2722,104 @@ void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parame
                } else
                {
                        /* sending notification */
                } else
                {
                        /* sending notification */
+#ifdef SOCKET_MISDN
+                       l3m = create_l3msg();
+#else
                        dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode);
                        notification = (NOTIFY_t *)(dmsg->data + headerlen);
                        dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode);
                        notification = (NOTIFY_t *)(dmsg->data + headerlen);
+#endif
                        l1l2l3_trace_header(p_m_mISDNport, this, CC_NOTIFY | REQUEST, DIRECTION_OUT);
                        l1l2l3_trace_header(p_m_mISDNport, this, CC_NOTIFY | REQUEST, DIRECTION_OUT);
+#ifdef SOCKET_MISDN
+                       enc_ie_notify(l3m, notify);
+#else
                        enc_ie_notify(&notification->NOTIFY, dmsg, notify);
                        enc_ie_notify(&notification->NOTIFY, dmsg, notify);
+#endif
                        /* sending redirection number only in ntmode */
                        if (type >= 0 && p_m_d_ntmode)
                        /* sending redirection number only in ntmode */
                        if (type >= 0 && p_m_d_ntmode)
+#ifdef SOCKET_MISDN
+                               enc_ie_redir_dn(l3m, type, plan, present, (unsigned char *)param->notifyinfo.id);
+#else
                                enc_ie_redir_dn(&notification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id);
                                enc_ie_redir_dn(&notification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id);
+#endif
                        if (param->notifyinfo.display[0] && p_m_d_ntmode)
                        if (param->notifyinfo.display[0] && p_m_d_ntmode)
+#ifdef SOCKET_MISDN
+                               enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
+#else
                                enc_ie_display(&notification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
                                enc_ie_display(&notification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
+#endif
                        end_trace();
                        end_trace();
+#ifdef SOCKET_MISDN
+                       p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_NOTIFICATION, l3m);
+#else
                        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
                }
        } else if (p_m_d_ntmode)
        {
                /* sending information */
                }
        } else if (p_m_d_ntmode)
        {
                /* sending information */
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
                information = (INFORMATION_t *)(dmsg->data + headerlen);
                dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
                information = (INFORMATION_t *)(dmsg->data + headerlen);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
                l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
+#ifdef SOCKET_MISDN
+               enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
+#else
                enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
                enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
+#endif
                end_trace();
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_INFORMATION, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
        }
 }
 
 /* MESSAGE_OVERLAP */
 void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union parameter *param)
 {
        }
 }
 
 /* MESSAGE_OVERLAP */
 void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union parameter *param)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
-       SETUP_ACKNOWLEDGE_t *setup_acknowledge;
        msg_t *dmsg;
        msg_t *dmsg;
+       SETUP_ACKNOWLEDGE_t *setup_acknowledge;
+#endif
 
        /* sending setup_acknowledge */
 
        /* sending setup_acknowledge */
+#ifdef SOCKET_MISDN
+       l3m = create_l3msg();
+#else
        dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode);
        setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
        dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode);
        setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
+#endif
        l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
        /* channel information */
        if (p_state == PORT_STATE_IN_SETUP)
        l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
        /* channel information */
        if (p_state == PORT_STATE_IN_SETUP)
+#ifdef SOCKET_MISDN
+               enc_ie_channel_id(l3m, 1, p_m_b_channel);
+#else
                enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
                enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
+#endif
        /* progress information */
        if (p_capainfo.bearer_capa==INFO_BC_SPEECH
         || p_capainfo.bearer_capa==INFO_BC_AUDIO
         || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
        if (p_m_mISDNport->tones)
        /* progress information */
        if (p_capainfo.bearer_capa==INFO_BC_SPEECH
         || p_capainfo.bearer_capa==INFO_BC_AUDIO
         || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
        if (p_m_mISDNport->tones)
+#ifdef SOCKET_MISDN
+               enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
+#else
                enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
                enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+#endif
        end_trace();
        end_trace();
+#ifdef SOCKET_MISDN
+       p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_SETUP_ACKNOWLEDGE, l3m);
+#else
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
 
        new_state(PORT_STATE_IN_OVERLAP);
 }
 
        new_state(PORT_STATE_IN_OVERLAP);
 }
@@ -2462,25 +2827,45 @@ void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union param
 /* MESSAGE_PROCEEDING */
 void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union parameter *param)
 {
 /* MESSAGE_PROCEEDING */
 void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union parameter *param)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
-       CALL_PROCEEDING_t *proceeding;
        msg_t *dmsg;
        msg_t *dmsg;
+       CALL_PROCEEDING_t *proceeding;
+#endif
 
        /* sending proceeding */
 
        /* sending proceeding */
+#ifdef SOCKET_MISDN
+       l3m = create_l3msg();
+#else
        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);
        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);
+#endif
        l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
        /* channel information */
        if (p_state == PORT_STATE_IN_SETUP)
        l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
        /* channel information */
        if (p_state == PORT_STATE_IN_SETUP)
+#ifdef SOCKET_MISDN
+               enc_ie_channel_id(l3m, 1, p_m_b_channel);
+#else
                enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
                enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
+#endif
        /* progress information */
        if (p_capainfo.bearer_capa==INFO_BC_SPEECH
         || p_capainfo.bearer_capa==INFO_BC_AUDIO
         || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
        if (p_m_mISDNport->tones)
        /* progress information */
        if (p_capainfo.bearer_capa==INFO_BC_SPEECH
         || p_capainfo.bearer_capa==INFO_BC_AUDIO
         || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
        if (p_m_mISDNport->tones)
+#ifdef SOCKET_MISDN
+               enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
+#else
                enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
                enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+#endif
        end_trace();
        end_trace();
+#ifdef SOCKET_MISDN
+       p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_PROCEEDING, l3m);
+#else
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
 
        new_state(PORT_STATE_IN_PROCEEDING);
 }
 
        new_state(PORT_STATE_IN_PROCEEDING);
 }
@@ -2488,9 +2873,13 @@ void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union pa
 /* MESSAGE_ALERTING */
 void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union parameter *param)
 {
 /* MESSAGE_ALERTING */
 void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union parameter *param)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
-       ALERTING_t *alerting;
        msg_t *dmsg;
        msg_t *dmsg;
+       ALERTING_t *alerting;
+#endif
 
        /* NT-MODE in setup state we must send PROCEEDING first */
        if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
 
        /* NT-MODE in setup state we must send PROCEEDING first */
        if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
@@ -2498,36 +2887,68 @@ void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union para
                CALL_PROCEEDING_t *proceeding;
 
                /* sending proceeding */
                CALL_PROCEEDING_t *proceeding;
 
                /* sending proceeding */
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                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);
                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);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
                /* channel information */
                l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
                /* channel information */
+#ifdef SOCKET_MISDN
+               enc_ie_channel_id(l3m, 1, p_m_b_channel);
+#else
                enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
                enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
+#endif
                /* progress information */
                if (p_capainfo.bearer_capa==INFO_BC_SPEECH
                 || p_capainfo.bearer_capa==INFO_BC_AUDIO
                 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
                /* progress information */
                if (p_capainfo.bearer_capa==INFO_BC_SPEECH
                 || p_capainfo.bearer_capa==INFO_BC_AUDIO
                 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
+#ifdef SOCKET_MISDN
+               enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
+#else
                enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
                enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+#endif
                end_trace();
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_PROCEEDING, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
                new_state(PORT_STATE_IN_PROCEEDING);
        }
 
        /* sending alerting */
                new_state(PORT_STATE_IN_PROCEEDING);
        }
 
        /* sending alerting */
+#ifdef SOCKET_MISDN
+       l3m = create_l3msg();
+#else
        dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode);
        alerting = (ALERTING_t *)(dmsg->data + headerlen);
        dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode);
        alerting = (ALERTING_t *)(dmsg->data + headerlen);
+#endif
        l1l2l3_trace_header(p_m_mISDNport, this, CC_ALERTING | REQUEST, DIRECTION_OUT);
        /* channel information */
        if (p_state == PORT_STATE_IN_SETUP)
        l1l2l3_trace_header(p_m_mISDNport, this, CC_ALERTING | REQUEST, DIRECTION_OUT);
        /* channel information */
        if (p_state == PORT_STATE_IN_SETUP)
+#ifdef SOCKET_MISDN
+               enc_ie_channel_id(l3m, 1, p_m_b_channel);
+#else
                enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel);
                enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel);
+#endif
        /* progress information */
        if (p_capainfo.bearer_capa==INFO_BC_SPEECH
         || p_capainfo.bearer_capa==INFO_BC_AUDIO
         || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
        if (p_m_mISDNport->tones)
        /* progress information */
        if (p_capainfo.bearer_capa==INFO_BC_SPEECH
         || p_capainfo.bearer_capa==INFO_BC_AUDIO
         || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
        if (p_m_mISDNport->tones)
+#ifdef SOCKET_MISDN
+               enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
+#else
                enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
                enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+#endif
        end_trace();
        end_trace();
+#ifdef SOCKET_MISDN
+       p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_ALERTING, l3m);
+#else
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
 
        new_state(PORT_STATE_IN_ALERTING);
 }
 
        new_state(PORT_STATE_IN_ALERTING);
 }
@@ -2535,11 +2956,15 @@ void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union para
 /* MESSAGE_CONNECT */
 void Pdss1::message_connect(unsigned long epoint_id, int message_id, union parameter *param)
 {
 /* MESSAGE_CONNECT */
 void Pdss1::message_connect(unsigned long epoint_id, int message_id, union parameter *param)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
+       msg_t *dmsg;
        INFORMATION_t *information;
        CONNECT_t *connect;
        INFORMATION_t *information;
        CONNECT_t *connect;
+#endif
        int type, plan, present, screen;
        int type, plan, present, screen;
-       msg_t *dmsg;
        class Endpoint *epoint;
 
        /* NT-MODE in setup state we must send PROCEEDING first */
        class Endpoint *epoint;
 
        /* NT-MODE in setup state we must send PROCEEDING first */
@@ -2548,18 +2973,34 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param
                CALL_PROCEEDING_t *proceeding;
 
                /* sending proceeding */
                CALL_PROCEEDING_t *proceeding;
 
                /* sending proceeding */
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                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);
                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);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
                /* channel information */
                l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
                /* channel information */
+#ifdef SOCKET_MISDN
+               enc_ie_channel_id(l3m, 1, p_m_b_channel);
+#else
                enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
                enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
+#endif
 //             /* progress information */
 //             if (p_capainfo.bearer_capa==INFO_BC_SPEECH
 //              || p_capainfo.bearer_capa==INFO_BC_AUDIO
 //              || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
 //             /* progress information */
 //             if (p_capainfo.bearer_capa==INFO_BC_SPEECH
 //              || p_capainfo.bearer_capa==INFO_BC_AUDIO
 //              || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
+#ifdef SOCKET_MISDN
+//             enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
+#else
 //             enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
 //             enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+#endif
                end_trace();
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_PROCEEDING, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
                new_state(PORT_STATE_IN_PROCEEDING);
        }
 
                new_state(PORT_STATE_IN_PROCEEDING);
        }
 
@@ -2573,13 +3014,25 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param
        if (p_connectinfo.display[0])
        {
                /* sending information */
        if (p_connectinfo.display[0])
        {
                /* sending information */
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
                information = (INFORMATION_t *)(dmsg->data + headerlen);
                dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
                information = (INFORMATION_t *)(dmsg->data + headerlen);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
                if (p_m_d_ntmode)
                l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
                if (p_m_d_ntmode)
+#ifdef SOCKET_MISDN
+                       enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
+#else
                        enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
                        enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
+#endif
                end_trace();
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_INFORMATION, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
                return;
        }
 
                return;
        }
 
@@ -2590,8 +3043,12 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param
        }
 
        /* preparing connect message */
        }
 
        /* preparing connect message */
+#ifdef SOCKET_MISDN
+       l3m = create_l3msg();
+#else
        dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode);
        connect = (CONNECT_t *)(dmsg->data + headerlen);
        dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode);
        connect = (CONNECT_t *)(dmsg->data + headerlen);
+#endif
        l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | REQUEST, DIRECTION_OUT);
        /* connect information */
        plan = 1;
        l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | REQUEST, DIRECTION_OUT);
        /* connect information */
        plan = 1;
@@ -2638,10 +3095,18 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param
                break;
        }
        if (type >= 0)
                break;
        }
        if (type >= 0)
+#ifdef SOCKET_MISDN
+               enc_ie_connected_pn(l3m, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
+#else
                enc_ie_connected_pn(&connect->CONNECT_PN, dmsg, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
                enc_ie_connected_pn(&connect->CONNECT_PN, dmsg, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
+#endif
        /* display */
        if (p_connectinfo.display[0] && p_m_d_ntmode)
        /* display */
        if (p_connectinfo.display[0] && p_m_d_ntmode)
+#ifdef SOCKET_MISDN
+               enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
+#else
                enc_ie_display(&connect->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
                enc_ie_display(&connect->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
+#endif
        /* nt-mode: CONP (connected name identification presentation) */
 //     if (p_connectinfo.name[0] && p_m_d_ntmode)
 //             enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
        /* nt-mode: CONP (connected name identification presentation) */
 //     if (p_connectinfo.name[0] && p_m_d_ntmode)
 //             enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
@@ -2649,11 +3114,19 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param
        if (p_m_d_ntmode)
        {
                epoint = find_epoint_id(epoint_id);
        if (p_m_d_ntmode)
        {
                epoint = find_epoint_id(epoint_id);
+#ifdef SOCKET_MISDN
+               enc_ie_date(l3m, now, p_settings.no_seconds);
+#else
                enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds);
                enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds);
+#endif
        }
        end_trace();
        /* finally send message */
        }
        end_trace();
        /* finally send message */
+#ifdef SOCKET_MISDN
+       p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_CONNECT, l3m);
+#else
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
 
        if (p_m_d_ntmode)
                new_state(PORT_STATE_CONNECT);
 
        if (p_m_d_ntmode)
                new_state(PORT_STATE_CONNECT);
@@ -2665,10 +3138,14 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param
 /* MESSAGE_DISCONNECT */
 void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union parameter *param)
 {
 /* MESSAGE_DISCONNECT */
 void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union parameter *param)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
+       msg_t *dmsg;
        DISCONNECT_t *disconnect;
        RELEASE_COMPLETE_t *release_complete;
        DISCONNECT_t *disconnect;
        RELEASE_COMPLETE_t *release_complete;
-       msg_t *dmsg;
+#endif
        struct message *message;
        char *p = NULL;
 
        struct message *message;
        char *p = NULL;
 
@@ -2687,13 +3164,25 @@ if (/*   ||*/ p_state==PORT_STATE_OUT_SETUP)
                        free_epointlist(p_epointlist);
                }
                /* sending release */
                        free_epointlist(p_epointlist);
                }
                /* sending release */
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
                /* send cause */
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
                /* send cause */
+#ifdef SOCKET_MISDN
+               enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
+#else
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
+#endif
                end_trace();
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE_COMPLETE, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
                new_state(PORT_STATE_RELEASE);
                p_m_delete = 1;
                return;
                new_state(PORT_STATE_RELEASE);
                p_m_delete = 1;
                return;
@@ -2705,51 +3194,91 @@ if (/*   ||*/ p_state==PORT_STATE_OUT_SETUP)
                CALL_PROCEEDING_t *proceeding;
 
                /* sending proceeding */
                CALL_PROCEEDING_t *proceeding;
 
                /* sending proceeding */
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                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);
                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);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
                /* channel information */
                l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
                /* channel information */
+#ifdef SOCKET_MISDN
+               enc_ie_channel_id(l3m, 1, p_m_b_channel);
+#else
                enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
                enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
+#endif
                /* progress information */
                if (p_capainfo.bearer_capa==INFO_BC_SPEECH
                 || p_capainfo.bearer_capa==INFO_BC_AUDIO
                 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
                /* progress information */
                if (p_capainfo.bearer_capa==INFO_BC_SPEECH
                 || p_capainfo.bearer_capa==INFO_BC_AUDIO
                 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
+#ifdef SOCKET_MISDN
+                       enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
+#else
                        enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
                        enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+#endif
                end_trace();
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_PROCEEDING, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
                new_state(PORT_STATE_IN_PROCEEDING);
        }
 
        /* sending disconnect */
                new_state(PORT_STATE_IN_PROCEEDING);
        }
 
        /* sending disconnect */
+#ifdef SOCKET_MISDN
+       l3m = create_l3msg();
+#else
        dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
        disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
        dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
        disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
+#endif
        l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT);
        /* progress information */
        if (p_capainfo.bearer_capa==INFO_BC_SPEECH
         || p_capainfo.bearer_capa==INFO_BC_AUDIO
         || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
        if (p_m_mISDNport->tones)
        l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT);
        /* progress information */
        if (p_capainfo.bearer_capa==INFO_BC_SPEECH
         || p_capainfo.bearer_capa==INFO_BC_AUDIO
         || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
        if (p_m_mISDNport->tones)
+#ifdef SOCKET_MISDN
+               enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
+#else
                enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
                enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+#endif
        /* send cause */
        /* send cause */
+#ifdef SOCKET_MISDN
+       enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
+#else
        enc_ie_cause(&disconnect->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
        enc_ie_cause(&disconnect->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
+#endif
        /* send display */
        if (param->disconnectinfo.display[0])
                p = param->disconnectinfo.display;
        if (p) if (*p && p_m_d_ntmode)
        /* send display */
        if (param->disconnectinfo.display[0])
                p = param->disconnectinfo.display;
        if (p) if (*p && p_m_d_ntmode)
+#ifdef SOCKET_MISDN
+               enc_ie_display(l3m, (unsigned char *)p);
+#else
                enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
                enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
+#endif
        end_trace();
        end_trace();
+#ifdef SOCKET_MISDN
+       p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_DISCONNECT, l3m);
+#else
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
        new_state(PORT_STATE_OUT_DISCONNECT);
 }
 
 /* MESSAGE_RELEASE */
 void Pdss1::message_release(unsigned long epoint_id, int message_id, union parameter *param)
 {
        new_state(PORT_STATE_OUT_DISCONNECT);
 }
 
 /* MESSAGE_RELEASE */
 void Pdss1::message_release(unsigned long epoint_id, int message_id, union parameter *param)
 {
+#ifdef SOCKET_MISDN
+       l3_msg *l3m;
+#else
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
+       msg_t *dmsg;
        RELEASE_t *release;
        RELEASE_COMPLETE_t *release_complete;
        DISCONNECT_t *disconnect;
        RELEASE_t *release;
        RELEASE_COMPLETE_t *release_complete;
        DISCONNECT_t *disconnect;
-       msg_t *dmsg;
+#endif
        class Endpoint *epoint;
        char *p = NULL;
 
        class Endpoint *epoint;
        char *p = NULL;
 
@@ -2761,13 +3290,25 @@ void Pdss1::message_release(unsigned long epoint_id, int message_id, union param
         || p_state == PORT_STATE_OUT_DISCONNECT)
        {
                /* sending release */
         || p_state == PORT_STATE_OUT_DISCONNECT)
        {
                /* sending release */
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
                release = (RELEASE_t *)(dmsg->data + headerlen);
                dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
                release = (RELEASE_t *)(dmsg->data + headerlen);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
                /* send cause */
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
                /* send cause */
+#ifdef SOCKET_MISDN
+               enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
+#else
                enc_ie_cause(&release->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
                enc_ie_cause(&release->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
+#endif
                end_trace();
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
                new_state(PORT_STATE_RELEASE);
                /* remove epoint */
                free_epointid(epoint_id);
                new_state(PORT_STATE_RELEASE);
                /* remove epoint */
                free_epointid(epoint_id);
@@ -2787,13 +3328,25 @@ void Pdss1::message_release(unsigned long epoint_id, int message_id, union param
 //#warning remove me
 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
                /* sending release complete */
 //#warning remove me
 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
                /* sending release complete */
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
                release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
                /* send cause */
                l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
                /* send cause */
+#ifdef SOCKET_MISDN
+               enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
+#else
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
                enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
+#endif
                end_trace();
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE_COMPLETE, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
                new_state(PORT_STATE_RELEASE);
                /* remove epoint */
                free_epointid(epoint_id);
                new_state(PORT_STATE_RELEASE);
                /* remove epoint */
                free_epointid(epoint_id);
@@ -2822,41 +3375,77 @@ wirklich erst proceeding?:
                CALL_PROCEEDING_t *proceeding;
 
                /* sending proceeding */
                CALL_PROCEEDING_t *proceeding;
 
                /* sending proceeding */
+#ifdef SOCKET_MISDN
+               l3m = create_l3msg();
+#else
                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);
                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);
+#endif
                l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
                /* channel information */
                l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
                /* channel information */
+#ifdef SOCKET_MISDN
+               enc_ie_channel_id(l3m, 1, p_m_b_channel);
+#else
                enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
                enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
+#endif
                /* progress information */
                if (p_capainfo.bearer_capa==INFO_BC_SPEECH
                 || p_capainfo.bearer_capa==INFO_BC_AUDIO
                 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
                /* progress information */
                if (p_capainfo.bearer_capa==INFO_BC_SPEECH
                 || p_capainfo.bearer_capa==INFO_BC_AUDIO
                 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
+#ifdef SOCKET_MISDN
+                       enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
+#else
                        enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
                        enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+#endif
                end_trace();
                end_trace();
+#ifdef SOCKET_MISDN
+               p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_PROCEEDING, l3m);
+#else
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
                msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
        }
 #endif
 
        /* sending disconnect */
        }
 #endif
 
        /* sending disconnect */
+#ifdef SOCKET_MISDN
+       l3m = create_l3msg();
+#else
        dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
        disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
        dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
        disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
+#endif
        l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT);
        /* progress information */
        if (p_capainfo.bearer_capa==INFO_BC_SPEECH
         || p_capainfo.bearer_capa==INFO_BC_AUDIO
         || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
        if (p_m_mISDNport->tones)
        l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT);
        /* progress information */
        if (p_capainfo.bearer_capa==INFO_BC_SPEECH
         || p_capainfo.bearer_capa==INFO_BC_AUDIO
         || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
        if (p_m_mISDNport->tones)
+#ifdef SOCKET_MISDN
+               enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
+#else
                enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
                enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
+#endif
        /* send cause */
        /* send cause */
+#ifdef SOCKET_MISDN
+       enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
+#else
        enc_ie_cause(&disconnect->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
        enc_ie_cause(&disconnect->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
+#endif
        /* send display */
        epoint = find_epoint_id(epoint_id);
        if (param->disconnectinfo.display[0])
                p = param->disconnectinfo.display;
        if (p) if (*p && p_m_d_ntmode)
        /* send display */
        epoint = find_epoint_id(epoint_id);
        if (param->disconnectinfo.display[0])
                p = param->disconnectinfo.display;
        if (p) if (*p && p_m_d_ntmode)
+#ifdef SOCKET_MISDN
+               enc_ie_display(l3m, (unsigned char *)p);
+#else
                enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
                enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
+#endif
        end_trace();
        end_trace();
+#ifdef SOCKET_MISDN
+       p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_DISCONNECT, l3m);
+#else
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
        msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
+#endif
        new_state(PORT_STATE_OUT_DISCONNECT);
        /* remove epoint */
        free_epointid(epoint_id);
        new_state(PORT_STATE_OUT_DISCONNECT);
        /* remove epoint */
        free_epointid(epoint_id);
diff --git a/dss1.h b/dss1.h
index 49121fa..7dba2d9 100644 (file)
--- a/dss1.h
+++ b/dss1.h
@@ -29,7 +29,7 @@ class Pdss1 : public PmISDN
        int p_m_d_collect_location;
 
        void new_state(int state);              /* set new state */
        int p_m_d_collect_location;
 
        void new_state(int state);              /* set new state */
-       void isdn_show_send_message(unsigned long prim, msg_t *msg);
+//     void isdn_show_send_message(unsigned long prim, msg_t *msg);
        int received_first_reply_to_setup(unsigned long prim, int channel, int exclusive);
        int hunt_bchannel(int exclusive, int channel);
        void information_ind(unsigned long prim, unsigned long dinfo, void *data);
        int received_first_reply_to_setup(unsigned long prim, int channel, int exclusive);
        int hunt_bchannel(int exclusive, int channel);
        void information_ind(unsigned long prim, unsigned long dinfo, void *data);
@@ -61,6 +61,44 @@ class Pdss1 : public PmISDN
        void message_release(unsigned long epoint_id, int message_id, union parameter *param);
 
        /* IE conversion */
        void message_release(unsigned long epoint_id, int message_id, union parameter *param);
 
        /* IE conversion */
+#ifdef SOCKET_MISDN
+       void enc_ie_complete(struct l3_msg *l3m, int complete);
+       void dec_ie_complete(struct l3_msg *l3m, int *complete);
+       void enc_ie_bearer(struct l3_msg *l3m, int coding, int capability, int mode, int rate, int multi, int user);
+       void dec_ie_bearer(struct l3_msg *l3m, int *coding, int *capability, int *mode, int *rate, int *multi, int *user);
+       void enc_ie_call_id(struct l3_msg *l3m, unsigned char *callid, int callid_len);
+       void dec_ie_call_id(struct l3_msg *l3m, unsigned char *callid, int *callid_len);
+       void enc_ie_called_pn(struct l3_msg *l3m, int type, int plan, unsigned char *number);
+       void dec_ie_called_pn(struct l3_msg *l3m, int *type, int *plan, unsigned char *number, int number_len);
+       void enc_ie_calling_pn(struct l3_msg *l3m, int type, int plan, int present, int screen, unsigned char *number);
+       void dec_ie_calling_pn(struct l3_msg *l3m, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len);
+       void enc_ie_connected_pn(struct l3_msg *l3m, int type, int plan, int present, int screen, unsigned char *number);
+       void dec_ie_connected_pn(struct l3_msg *l3m, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len);
+       void enc_ie_cause(struct l3_msg *l3m, int location, int cause);
+       void dec_ie_cause(struct l3_msg *l3m, int *location, int *cause);
+       void enc_ie_channel_id(struct l3_msg *l3m, int exclusive, int channel);
+       void dec_ie_channel_id(struct l3_msg *l3m, int *exclusive, int *channel);
+       void enc_ie_date(struct l3_msg *l3m, time_t ti, int seconds);
+       void enc_ie_display(struct l3_msg *l3m, unsigned char *display);
+       void dec_ie_display(struct l3_msg *l3m, unsigned char *display, int display_len);
+       void enc_ie_keypad(struct l3_msg *l3m, unsigned char *keypad);
+       void dec_ie_keypad(struct l3_msg *l3m, unsigned char *keypad, int keypad_len);
+       void enc_ie_notify(struct l3_msg *l3m, int notify);
+       void dec_ie_notify(struct l3_msg *l3m, int *notify);
+       void enc_ie_progress(struct l3_msg *l3m, int coding, int location, int progress);
+       void dec_ie_progress(struct l3_msg *l3m, int *coding, int *location, int *progress);
+       void enc_ie_hlc(struct l3_msg *l3m, int coding, int interpretation, int presentation, int hlc, int exthlc);
+       void dec_ie_hlc(struct l3_msg *l3m, int *coding, int *interpretation, int *presentation, int *hlc, int *exthlc);
+       void enc_ie_redir_nr(struct l3_msg *l3m, int type, int plan, int present, int screen, int reason, unsigned char *number);
+       void dec_ie_redir_nr(struct l3_msg *l3m, int *type, int *plan, int *present, int *screen, int *reason, unsigned char *number, int number_len);
+       void enc_ie_redir_dn(struct l3_msg *l3m, int type, int plan, int present, unsigned char *number);
+       void dec_ie_redir_dn(struct l3_msg *l3m, int *type, int *plan, int *present, unsigned char *number, int number_len);
+       void enc_ie_facility(struct l3_msg *l3m, unsigned char *facility, int facility_len);
+       void dec_ie_facility(struct l3_msg *l3m, unsigned char *facility, int *facility_len);
+       void dec_facility_centrex(struct l3_msg *l3m, unsigned char *cnip, int cnip_len);
+       void enc_ie_useruser(struct l3_msg *l3m, int protocol, unsigned char *user, int user_len);
+       void dec_ie_useruser(struct l3_msg *l3m, int *protocol, unsigned char *user, int *user_len);
+#else
        void enc_ie_complete(unsigned char **ntmode, msg_t *msg, int complete);
        void dec_ie_complete(unsigned char *p, Q931_info_t *qi, int *complete);
        void enc_ie_bearer(unsigned char **ntmode, msg_t *msg, int coding, int capability, int mode, int rate, int multi, int user);
        void enc_ie_complete(unsigned char **ntmode, msg_t *msg, int complete);
        void dec_ie_complete(unsigned char *p, Q931_info_t *qi, int *complete);
        void enc_ie_bearer(unsigned char **ntmode, msg_t *msg, int coding, int capability, int mode, int rate, int multi, int user);
@@ -97,6 +135,7 @@ class Pdss1 : public PmISDN
        void dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned char *cnip, int cnip_len);
        void enc_ie_useruser(unsigned char **ntmode, msg_t *msg, int protocol, unsigned char *user, int user_len);
        void dec_ie_useruser(unsigned char *p, Q931_info_t *qi, int *protocol, unsigned char *user, int *user_len);
        void dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned char *cnip, int cnip_len);
        void enc_ie_useruser(unsigned char **ntmode, msg_t *msg, int protocol, unsigned char *user, int user_len);
        void dec_ie_useruser(unsigned char *p, Q931_info_t *qi, int *protocol, unsigned char *user, int *user_len);
+#endif
 
 };
 
 
 };
 
diff --git a/ie.cpp b/ie.cpp
index 1c70514..236e49a 100644 (file)
--- a/ie.cpp
+++ b/ie.cpp
@@ -26,10 +26,16 @@ static void strnncpy(unsigned char *dest, unsigned char *src, int len, int dst_l
 
 
 /* IE_COMPLETE */
 
 
 /* IE_COMPLETE */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_complete(struct l3_msg *l3m, int complete)
+#else
 void Pdss1::enc_ie_complete(unsigned char **ntmode, msg_t *msg, int complete)
 void Pdss1::enc_ie_complete(unsigned char **ntmode, msg_t *msg, int complete)
+#endif
 {
 {
+#ifndef SOCKET_MISDN
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
 
        if (complete<0 || complete>1)
        {
 
        if (complete<0 || complete>1)
        {
@@ -40,6 +46,7 @@ void Pdss1::enc_ie_complete(unsigned char **ntmode, msg_t *msg, int complete)
        if (complete)
        {
                add_trace("complete", NULL, NULL);
        if (complete)
        {
                add_trace("complete", NULL, NULL);
+#ifndef SOCKET_MISDN
                p = msg_put(msg, 1);
                if (p_m_d_ntmode)
                {
                p = msg_put(msg, 1);
                if (p_m_d_ntmode)
                {
@@ -47,17 +54,28 @@ void Pdss1::enc_ie_complete(unsigned char **ntmode, msg_t *msg, int complete)
                } else
                        qi->sending_complete.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
                p[0] = IE_COMPLETE;
                } else
                        qi->sending_complete.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
                p[0] = IE_COMPLETE;
+#else
+               l3m->sending_complete++;
+#endif
        }
 }
 
        }
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_complete(struct l3_msg *l3m, int *complete)
+#else
 void Pdss1::dec_ie_complete(unsigned char *p, Q931_info_t *qi, int *complete)
 void Pdss1::dec_ie_complete(unsigned char *p, Q931_info_t *qi, int *complete)
+#endif
 {
        *complete = 0;
 {
        *complete = 0;
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                if (qi->sending_complete.off)
                        *complete = 1;
        } else
        if (!p_m_d_ntmode)
        {
                if (qi->sending_complete.off)
                        *complete = 1;
        } else
+#else
+       unsigned char *p = l3m->sending_complete;
+#endif
        if (p)
                *complete = 1;
 
        if (p)
                *complete = 1;
 
@@ -67,10 +85,18 @@ void Pdss1::dec_ie_complete(unsigned char *p, Q931_info_t *qi, int *complete)
 
 
 /* IE_BEARER */
 
 
 /* IE_BEARER */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_bearer(struct l3_msg *l3m, int coding, int capability, int mode, int rate, int multi, int user)
+#else
 void Pdss1::enc_ie_bearer(unsigned char **ntmode, msg_t *msg, int coding, int capability, int mode, int rate, int multi, int user)
 void Pdss1::enc_ie_bearer(unsigned char **ntmode, msg_t *msg, int coding, int capability, int mode, int rate, int multi, int user)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        if (coding<0 || coding>3)
        int l;
 
        if (coding<0 || coding>3)
@@ -117,11 +143,13 @@ void Pdss1::enc_ie_bearer(unsigned char **ntmode, msg_t *msg, int coding, int ca
        add_trace("bearer", "user", "%d", user);
 
        l = 2 + (multi>=0) + (user>=0);
        add_trace("bearer", "user", "%d", user);
 
        l = 2 + (multi>=0) + (user>=0);
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->bearer_capability.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->bearer_capability.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_BEARER;
        p[1] = l;
        p[2] = 0x80 + (coding<<5) + capability;
        p[0] = IE_BEARER;
        p[1] = l;
        p[2] = 0x80 + (coding<<5) + capability;
@@ -130,9 +158,16 @@ void Pdss1::enc_ie_bearer(unsigned char **ntmode, msg_t *msg, int coding, int ca
                p[4] = 0x80 + multi;
        if (user >= 0)
                p[4+(multi>=0)] = 0xa0 + user;
                p[4] = 0x80 + multi;
        if (user >= 0)
                p[4+(multi>=0)] = 0xa0 + user;
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_bearer(struct l3_msg *l3m, int *coding, int *capability, int *mode, int *rate, int *multi, int *user)
+#else
 void Pdss1::dec_ie_bearer(unsigned char *p, Q931_info_t *qi, int *coding, int *capability, int *mode, int *rate, int *multi, int *user)
 void Pdss1::dec_ie_bearer(unsigned char *p, Q931_info_t *qi, int *coding, int *capability, int *mode, int *rate, int *multi, int *user)
+#endif
 {
        *coding = -1;
        *capability = -1;
 {
        *coding = -1;
        *capability = -1;
@@ -141,12 +176,16 @@ void Pdss1::dec_ie_bearer(unsigned char *p, Q931_info_t *qi, int *coding, int *c
        *multi = -1;
        *user = -1;
 
        *multi = -1;
        *user = -1;
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->bearer_capability.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->bearer_capability.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->bearer_capability.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->bearer_capability.off + 1;
        }
+#else
+       unsigned char *p = l3m->bearer_capability;
+#endif
        if (!p)
                return;
        if (p[0] < 2)
        if (!p)
                return;
        if (p[0] < 2)
@@ -183,10 +222,18 @@ void Pdss1::dec_ie_bearer(unsigned char *p, Q931_info_t *qi, int *coding, int *c
 
 
 /* IE_HLC */
 
 
 /* IE_HLC */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_hlc(struct l3_msg *l3m, int coding, int interpretation, int presentation, int hlc, int exthlc)
+#else
 void Pdss1::enc_ie_hlc(unsigned char **ntmode, msg_t *msg, int coding, int interpretation, int presentation, int hlc, int exthlc)
 void Pdss1::enc_ie_hlc(unsigned char **ntmode, msg_t *msg, int coding, int interpretation, int presentation, int hlc, int exthlc)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        if (coding<0 || coding>3)
        int l;
 
        if (coding<0 || coding>3)
@@ -223,11 +270,13 @@ void Pdss1::enc_ie_hlc(unsigned char **ntmode, msg_t *msg, int coding, int inter
                add_trace("hlc", "exthlc", "%d", exthlc);
 
        l = 2 + (exthlc>=0);
                add_trace("hlc", "exthlc", "%d", exthlc);
 
        l = 2 + (exthlc>=0);
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->hlc.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->hlc.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_HLC;
        p[1] = l;
        p[2] = 0x80 + (coding<<5) + (interpretation<<2) + presentation;
        p[0] = IE_HLC;
        p[1] = l;
        p[2] = 0x80 + (coding<<5) + (interpretation<<2) + presentation;
@@ -237,9 +286,16 @@ void Pdss1::enc_ie_hlc(unsigned char **ntmode, msg_t *msg, int coding, int inter
                p[4] = 0x80 + exthlc;
        } else
                p[3] = 0x80 + hlc;
                p[4] = 0x80 + exthlc;
        } else
                p[3] = 0x80 + hlc;
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_hlc(struct l3_msg *l3m, int *coding, int *interpretation, int *presentation, int *hlc, int *exthlc)
+#else
 void Pdss1::dec_ie_hlc(unsigned char *p, Q931_info_t *qi, int *coding, int *interpretation, int *presentation, int *hlc, int *exthlc)
 void Pdss1::dec_ie_hlc(unsigned char *p, Q931_info_t *qi, int *coding, int *interpretation, int *presentation, int *hlc, int *exthlc)
+#endif
 {
        *coding = -1;
        *interpretation = -1;
 {
        *coding = -1;
        *interpretation = -1;
@@ -247,12 +303,16 @@ void Pdss1::dec_ie_hlc(unsigned char *p, Q931_info_t *qi, int *coding, int *inte
        *hlc = -1;
        *exthlc = -1;
 
        *hlc = -1;
        *exthlc = -1;
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->hlc.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->hlc.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->hlc.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->hlc.off + 1;
        }
+#else
+       unsigned char *p = l3m->hlc;
+#endif
        if (!p)
                return;
        if (p[0] < 2)
        if (!p)
                return;
        if (p[0] < 2)
@@ -280,10 +340,18 @@ void Pdss1::dec_ie_hlc(unsigned char *p, Q931_info_t *qi, int *coding, int *inte
 
 
 /* IE_CALL_ID */
 
 
 /* IE_CALL_ID */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_call_id(struct l3_msg *l3m, unsigned char *callid, int callid_len)
+#else
 void Pdss1::enc_ie_call_id(unsigned char **ntmode, msg_t *msg, unsigned char *callid, int callid_len)
 void Pdss1::enc_ie_call_id(unsigned char **ntmode, msg_t *msg, unsigned char *callid, int callid_len)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        char buffer[25];
        int l;
 
        char buffer[25];
@@ -309,29 +377,42 @@ void Pdss1::enc_ie_call_id(unsigned char **ntmode, msg_t *msg, unsigned char *ca
        add_trace("callid", NULL, "%s", buffer[0]?buffer+1:"<none>");
 
        l = callid_len;
        add_trace("callid", NULL, "%s", buffer[0]?buffer+1:"<none>");
 
        l = callid_len;
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->call_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->call_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_CALL_ID;
        p[1] = l;
        memcpy(p+2, callid, callid_len);
        p[0] = IE_CALL_ID;
        p[1] = l;
        memcpy(p+2, callid, callid_len);
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_call_id(struct l3_msg *l3m, unsigned char *callid, int *callid_len)
+#else
 void Pdss1::dec_ie_call_id(unsigned char *p, Q931_info_t *qi, unsigned char *callid, int *callid_len)
 void Pdss1::dec_ie_call_id(unsigned char *p, Q931_info_t *qi, unsigned char *callid, int *callid_len)
+#endif
 {
        char buffer[25];
        int i;
 
        *callid_len = -1;
 
 {
        char buffer[25];
        int i;
 
        *callid_len = -1;
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->call_id.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->call_id.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->call_id.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->call_id.off + 1;
        }
+#else
+       unsigned char *p = l3m->call_id;
+#endif
        if (!p)
                return;
        if (p[0] > 8)
        if (!p)
                return;
        if (p[0] > 8)
@@ -355,10 +436,18 @@ void Pdss1::dec_ie_call_id(unsigned char *p, Q931_info_t *qi, unsigned char *cal
 
 
 /* IE_CALLED_PN */
 
 
 /* IE_CALLED_PN */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_called_pn(struct l3_msg *l3m, int type, int plan, unsigned char *number)
+#else
 void Pdss1::enc_ie_called_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, unsigned char *number)
 void Pdss1::enc_ie_called_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, unsigned char *number)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        if (type<0 || type>7)
        int l;
 
        if (type<0 || type>7)
@@ -382,29 +471,42 @@ void Pdss1::enc_ie_called_pn(unsigned char **ntmode, msg_t *msg, int type, int p
        add_trace("called_pn", "number", "%s", number);
 
        l = 1+strlen((char *)number);
        add_trace("called_pn", "number", "%s", number);
 
        l = 1+strlen((char *)number);
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->called_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->called_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_CALLED_PN;
        p[1] = l;
        p[2] = 0x80 + (type<<4) + plan;
        UNCPY((char *)p+3, (char *)number, strlen((char *)number));
        p[0] = IE_CALLED_PN;
        p[1] = l;
        p[2] = 0x80 + (type<<4) + plan;
        UNCPY((char *)p+3, (char *)number, strlen((char *)number));
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_called_pn(struct l3_msg *l3m, int *type, int *plan, unsigned char *number, int number_len)
+#else
 void Pdss1::dec_ie_called_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, unsigned char *number, int number_len)
 void Pdss1::dec_ie_called_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, unsigned char *number, int number_len)
+#endif
 {
        *type = -1;
        *plan = -1;
        *number = '\0';
 
 {
        *type = -1;
        *plan = -1;
        *number = '\0';
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->called_nr.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->called_nr.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->called_nr.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->called_nr.off + 1;
        }
+#else
+       unsigned char *p = l3m->called_nr;
+#endif
        if (!p)
                return;
        if (p[0] < 2)
        if (!p)
                return;
        if (p[0] < 2)
@@ -424,10 +526,18 @@ void Pdss1::dec_ie_called_pn(unsigned char *p, Q931_info_t *qi, int *type, int *
 
 
 /* IE_CALLING_PN */
 
 
 /* IE_CALLING_PN */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_calling_pn(struct l3_msg *l3m, int type, int plan, int present, int screen, unsigned char *number)
+#else
 void Pdss1::enc_ie_calling_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, unsigned char *number)
 void Pdss1::enc_ie_calling_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, unsigned char *number)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        if (type<0 || type>7)
        int l;
 
        if (type<0 || type>7)
@@ -462,11 +572,13 @@ void Pdss1::enc_ie_calling_pn(unsigned char **ntmode, msg_t *msg, int type, int
                l += strlen((char *)number);
        if (present >= 0)
                l += 1;
                l += strlen((char *)number);
        if (present >= 0)
                l += 1;
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->calling_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->calling_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_CALLING_PN;
        p[1] = l;
        if (present >= 0)
        p[0] = IE_CALLING_PN;
        p[1] = l;
        if (present >= 0)
@@ -481,9 +593,16 @@ void Pdss1::enc_ie_calling_pn(unsigned char **ntmode, msg_t *msg, int type, int
                if (number) if (number[0])
                        UNCPY((char *)p+3, (char *)number, strlen((char *)number));
        }
                if (number) if (number[0])
                        UNCPY((char *)p+3, (char *)number, strlen((char *)number));
        }
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_calling_pn(struct l3_msg *l3m, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len)
+#else
 void Pdss1::dec_ie_calling_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len)
 void Pdss1::dec_ie_calling_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len)
+#endif
 {
        *type = -1;
        *plan = -1;
 {
        *type = -1;
        *plan = -1;
@@ -491,12 +610,16 @@ void Pdss1::dec_ie_calling_pn(unsigned char *p, Q931_info_t *qi, int *type, int
        *screen = -1;
        *number = '\0';
 
        *screen = -1;
        *number = '\0';
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->calling_nr.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->calling_nr.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->calling_nr.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->calling_nr.off + 1;
        }
+#else
+       unsigned char *p = l3m->calling_nr;
+#endif
        if (!p)
                return;
        if (p[0] < 1)
        if (!p)
                return;
        if (p[0] < 1)
@@ -531,10 +654,18 @@ void Pdss1::dec_ie_calling_pn(unsigned char *p, Q931_info_t *qi, int *type, int
 
 
 /* IE_CONNECTED_PN */
 
 
 /* IE_CONNECTED_PN */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_connected_pn(struct l3_msg *l3m, int type, int plan, int present, int screen, unsigned char *number)
+#else
 void Pdss1::enc_ie_connected_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, unsigned char *number)
 void Pdss1::enc_ie_connected_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, unsigned char *number)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        if (type<0 || type>7)
        int l;
 
        if (type<0 || type>7)
@@ -569,11 +700,13 @@ void Pdss1::enc_ie_connected_pn(unsigned char **ntmode, msg_t *msg, int type, in
                l += strlen((char *)number);
        if (present >= 0)
                l += 1;
                l += strlen((char *)number);
        if (present >= 0)
                l += 1;
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->connected_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->connected_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_CONNECT_PN;
        p[1] = l;
        if (present >= 0)
        p[0] = IE_CONNECT_PN;
        p[1] = l;
        if (present >= 0)
@@ -588,9 +721,16 @@ void Pdss1::enc_ie_connected_pn(unsigned char **ntmode, msg_t *msg, int type, in
                if (number) if (number[0])
                        UNCPY((char *)p+3, (char *)number, strlen((char *)number));
        }
                if (number) if (number[0])
                        UNCPY((char *)p+3, (char *)number, strlen((char *)number));
        }
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_connected_pn(struct l3_msg *l3m, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len)
+#else
 void Pdss1::dec_ie_connected_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len)
 void Pdss1::dec_ie_connected_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len)
+#endif
 {
        *type = -1;
        *plan = -1;
 {
        *type = -1;
        *plan = -1;
@@ -598,12 +738,16 @@ void Pdss1::dec_ie_connected_pn(unsigned char *p, Q931_info_t *qi, int *type, in
        *screen = -1;
        *number = '\0';
 
        *screen = -1;
        *number = '\0';
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->connected_nr.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->connected_nr.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->connected_nr.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->connected_nr.off + 1;
        }
+#else
+       unsigned char *p = l3m->connected_nr;
+#endif
        if (!p)
                return;
        if (p[0] < 1)
        if (!p)
                return;
        if (p[0] < 1)
@@ -638,10 +782,18 @@ void Pdss1::dec_ie_connected_pn(unsigned char *p, Q931_info_t *qi, int *type, in
 
 
 /* IE_CAUSE */
 
 
 /* IE_CAUSE */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_cause(struct l3_msg *l3m, int location, int cause)
+#else
 void Pdss1::enc_ie_cause(unsigned char **ntmode, msg_t *msg, int location, int cause)
 void Pdss1::enc_ie_cause(unsigned char **ntmode, msg_t *msg, int location, int cause)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        if (location<0 || location>7)
        int l;
 
        if (location<0 || location>7)
@@ -659,42 +811,66 @@ void Pdss1::enc_ie_cause(unsigned char **ntmode, msg_t *msg, int location, int c
        add_trace("cause", "value", "%d", cause);
 
        l = 2;
        add_trace("cause", "value", "%d", cause);
 
        l = 2;
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->cause.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->cause.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_CAUSE;
        p[1] = l;
        p[2] = 0x80 + location;
        p[3] = 0x80 + cause;
        p[0] = IE_CAUSE;
        p[1] = l;
        p[2] = 0x80 + location;
        p[3] = 0x80 + cause;
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 }
+#ifdef SOCKET_MISDN
+void enc_ie_cause_standalone(struct l3_msg *l3m, int location, int cause)
+#else
 void enc_ie_cause_standalone(unsigned char **ntmode, msg_t *msg, int location, int cause)
 void enc_ie_cause_standalone(unsigned char **ntmode, msg_t *msg, int location, int cause)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p = msg_put(msg, 4);
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        if (ntmode)
                *ntmode = p+1;
        else
                qi->cause.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        unsigned char *p = msg_put(msg, 4);
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        if (ntmode)
                *ntmode = p+1;
        else
                qi->cause.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_CAUSE;
        p[1] = 2;
        p[2] = 0x80 + location;
        p[3] = 0x80 + cause;
        p[0] = IE_CAUSE;
        p[1] = 2;
        p[2] = 0x80 + location;
        p[3] = 0x80 + cause;
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 
 }
 
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_cause(struct l3_msg *l3m, int *location, int *cause)
+#else
 void Pdss1::dec_ie_cause(unsigned char *p, Q931_info_t *qi, int *location, int *cause)
 void Pdss1::dec_ie_cause(unsigned char *p, Q931_info_t *qi, int *location, int *cause)
+#endif
 {
        *location = -1;
        *cause = -1;
 
 {
        *location = -1;
        *cause = -1;
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->cause.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->cause.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->cause.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->cause.off + 1;
        }
+#else
+       unsigned char *p = l3m->cause;
+#endif
        if (!p)
                return;
        if (p[0] < 2)
        if (!p)
                return;
        if (p[0] < 2)
@@ -712,10 +888,18 @@ void Pdss1::dec_ie_cause(unsigned char *p, Q931_info_t *qi, int *location, int *
 
 
 /* IE_CHANNEL_ID */
 
 
 /* IE_CHANNEL_ID */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_channel_id(struct l3_msg *l3m, int exclusive, int channel)
+#else
 void Pdss1::enc_ie_channel_id(unsigned char **ntmode, msg_t *msg, int exclusive, int channel)
 void Pdss1::enc_ie_channel_id(unsigned char **ntmode, msg_t *msg, int exclusive, int channel)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
        int pri = p_m_mISDNport->pri;
 
        int l;
        int pri = p_m_mISDNport->pri;
 
@@ -750,11 +934,13 @@ void Pdss1::enc_ie_channel_id(unsigned char **ntmode, msg_t *msg, int exclusive,
        {
                /* BRI */
                l = 1;
        {
                /* BRI */
                l = 1;
+#ifndef SOCKET_MISDN
                p = msg_put(msg, l+2);
                if (p_m_d_ntmode)
                        *ntmode = p+1;
                else
                        qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
                p = msg_put(msg, l+2);
                if (p_m_d_ntmode)
                        *ntmode = p+1;
                else
                        qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
                p[0] = IE_CHANNEL_ID;
                p[1] = l;
                if (channel == CHANNEL_NO)
                p[0] = IE_CHANNEL_ID;
                p[1] = l;
                if (channel == CHANNEL_NO)
@@ -762,6 +948,9 @@ void Pdss1::enc_ie_channel_id(unsigned char **ntmode, msg_t *msg, int exclusive,
                else if (channel == CHANNEL_ANY)
                        channel = 3;
                p[2] = 0x80 + (exclusive<<3) + channel;
                else if (channel == CHANNEL_ANY)
                        channel = 3;
                p[2] = 0x80 + (exclusive<<3) + channel;
+#ifdef SOCKET_MISDN
+               add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
        } else
        {
                /* PRI */
        } else
        {
                /* PRI */
@@ -770,43 +959,61 @@ void Pdss1::enc_ie_channel_id(unsigned char **ntmode, msg_t *msg, int exclusive,
                if (channel == CHANNEL_ANY) /* any channel */
                {
                        l = 1;
                if (channel == CHANNEL_ANY) /* any channel */
                {
                        l = 1;
+#ifndef SOCKET_MISDN
                        p = msg_put(msg, l+2);
                        if (p_m_d_ntmode)
                                *ntmode = p+1;
                        else
                                qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
                        p = msg_put(msg, l+2);
                        if (p_m_d_ntmode)
                                *ntmode = p+1;
                        else
                                qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
                        p[0] = IE_CHANNEL_ID;
                        p[1] = l;
                        p[2] = 0x80 + 0x20 + 0x03;
                        p[0] = IE_CHANNEL_ID;
                        p[1] = l;
                        p[2] = 0x80 + 0x20 + 0x03;
+#ifdef SOCKET_MISDN
+                       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
                        return; /* end */
                }
                l = 3;
                        return; /* end */
                }
                l = 3;
+#ifndef SOCKET_MISDN
                p = msg_put(msg, l+2);
                if (p_m_d_ntmode)
                        *ntmode = p+1;
                else
                        qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
                p = msg_put(msg, l+2);
                if (p_m_d_ntmode)
                        *ntmode = p+1;
                else
                        qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
                p[0] = IE_CHANNEL_ID;
                p[1] = l;
                p[2] = 0x80 + 0x20 + (exclusive<<3) + 0x01;
                p[3] = 0x80 + 3; /* CCITT, Number, B-type */
                p[4] = 0x80 + channel;
                p[0] = IE_CHANNEL_ID;
                p[1] = l;
                p[2] = 0x80 + 0x20 + (exclusive<<3) + 0x01;
                p[3] = 0x80 + 3; /* CCITT, Number, B-type */
                p[4] = 0x80 + channel;
+#ifdef SOCKET_MISDN
+               add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
        }
 }
 
        }
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_channel_id(struct l3_msg *l3m, int *exclusive, int *channel)
+#else
 void Pdss1::dec_ie_channel_id(unsigned char *p, Q931_info_t *qi, int *exclusive, int *channel)
 void Pdss1::dec_ie_channel_id(unsigned char *p, Q931_info_t *qi, int *exclusive, int *channel)
+#endif
 {
        int pri = p_m_mISDNport->pri;
 
        *exclusive = -1;
        *channel = -1;
 
 {
        int pri = p_m_mISDNport->pri;
 
        *exclusive = -1;
        *channel = -1;
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->channel_id.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->channel_id.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->channel_id.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->channel_id.off + 1;
        }
+#else
+       unsigned char *p = l3m->channel_id;
+#endif
        if (!p)
                return;
        if (p[0] < 1)
        if (!p)
                return;
        if (p[0] < 1)
@@ -900,10 +1107,18 @@ void Pdss1::dec_ie_channel_id(unsigned char *p, Q931_info_t *qi, int *exclusive,
 
 
 /* IE_DATE */
 
 
 /* IE_DATE */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_date(struct l3_msg *l3m, time_t ti, int no_seconds)
+#else
 void Pdss1::enc_ie_date(unsigned char **ntmode, msg_t *msg, time_t ti, int no_seconds)
 void Pdss1::enc_ie_date(unsigned char **ntmode, msg_t *msg, time_t ti, int no_seconds)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        struct tm *tm;
        int l;
 
        struct tm *tm;
@@ -919,11 +1134,13 @@ void Pdss1::enc_ie_date(unsigned char **ntmode, msg_t *msg, time_t ti, int no_se
        add_trace("date", "time", "%d:%d:%d", tm->tm_hour, tm->tm_min, tm->tm_sec);
 
        l = 5 + (!no_seconds);
        add_trace("date", "time", "%d:%d:%d", tm->tm_hour, tm->tm_min, tm->tm_sec);
 
        l = 5 + (!no_seconds);
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->date.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->date.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_DATE;
        p[1] = l;
        p[2] = tm->tm_year % 100;
        p[0] = IE_DATE;
        p[1] = l;
        p[2] = tm->tm_year % 100;
@@ -933,14 +1150,25 @@ void Pdss1::enc_ie_date(unsigned char **ntmode, msg_t *msg, time_t ti, int no_se
        p[6] = tm->tm_min;
        if (!no_seconds)
                p[7] = tm->tm_sec;
        p[6] = tm->tm_min;
        if (!no_seconds)
                p[7] = tm->tm_sec;
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 
 /* IE_DISPLAY */
 }
 
 
 /* IE_DISPLAY */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_display(struct l3_msg *l3m, unsigned char *display)
+#else
 void Pdss1::enc_ie_display(unsigned char **ntmode, msg_t *msg, unsigned char *display)
 void Pdss1::enc_ie_display(unsigned char **ntmode, msg_t *msg, unsigned char *display)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        if (!display[0])
        int l;
 
        if (!display[0])
@@ -958,26 +1186,39 @@ void Pdss1::enc_ie_display(unsigned char **ntmode, msg_t *msg, unsigned char *di
        add_trace("display", NULL, "%s", display);
 
        l = strlen((char *)display);
        add_trace("display", NULL, "%s", display);
 
        l = strlen((char *)display);
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->display.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->display.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_DISPLAY;
        p[1] = l;
        UNCPY((char *)p+2, (char *)display, strlen((char *)display));
        p[0] = IE_DISPLAY;
        p[1] = l;
        UNCPY((char *)p+2, (char *)display, strlen((char *)display));
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_display(struct l3_msg *l3m, unsigned char *display, int display_len)
+#else
 void Pdss1::dec_ie_display(unsigned char *p, Q931_info_t *qi, unsigned char *display, int display_len)
 void Pdss1::dec_ie_display(unsigned char *p, Q931_info_t *qi, unsigned char *display, int display_len)
+#endif
 {
        *display = '\0';
 
 {
        *display = '\0';
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->display.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->display.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->display.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->display.off + 1;
        }
+#else
+       unsigned char *p = l3m->display;
+#endif
        if (!p)
                return;
        if (p[0] < 1)
        if (!p)
                return;
        if (p[0] < 1)
@@ -993,10 +1234,18 @@ void Pdss1::dec_ie_display(unsigned char *p, Q931_info_t *qi, unsigned char *dis
 
 
 /* IE_KEYPAD */
 
 
 /* IE_KEYPAD */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_keypad(struct l3_msg *l3m, unsigned char *keypad)
+#else
 void Pdss1::enc_ie_keypad(unsigned char **ntmode, msg_t *msg, unsigned char *keypad)
 void Pdss1::enc_ie_keypad(unsigned char **ntmode, msg_t *msg, unsigned char *keypad)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        if (!keypad[0])
        int l;
 
        if (!keypad[0])
@@ -1008,26 +1257,39 @@ void Pdss1::enc_ie_keypad(unsigned char **ntmode, msg_t *msg, unsigned char *key
        add_trace("keypad", NULL, "%s", keypad);
 
        l = strlen((char *)keypad);
        add_trace("keypad", NULL, "%s", keypad);
 
        l = strlen((char *)keypad);
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->keypad.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->keypad.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_KEYPAD;
        p[1] = l;
        UNCPY((char *)p+2, (char *)keypad, strlen((char *)keypad));
        p[0] = IE_KEYPAD;
        p[1] = l;
        UNCPY((char *)p+2, (char *)keypad, strlen((char *)keypad));
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_keypad(struct l3_msg *l3m, unsigned char *keypad, int keypad_len)
+#else
 void Pdss1::dec_ie_keypad(unsigned char *p, Q931_info_t *qi, unsigned char *keypad, int keypad_len)
 void Pdss1::dec_ie_keypad(unsigned char *p, Q931_info_t *qi, unsigned char *keypad, int keypad_len)
+#endif
 {
        *keypad = '\0';
 
 {
        *keypad = '\0';
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->keypad.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->keypad.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->keypad.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->keypad.off + 1;
        }
+#else
+       unsigned char *p = l3m->keypad;
+#endif
        if (!p)
                return;
        if (p[0] < 1)
        if (!p)
                return;
        if (p[0] < 1)
@@ -1043,10 +1305,18 @@ void Pdss1::dec_ie_keypad(unsigned char *p, Q931_info_t *qi, unsigned char *keyp
 
 
 /* IE_NOTIFY */
 
 
 /* IE_NOTIFY */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_notify(struct l3_msg *l3m, int notify)
+#else
 void Pdss1::enc_ie_notify(unsigned char **ntmode, msg_t *msg, int notify)
 void Pdss1::enc_ie_notify(unsigned char **ntmode, msg_t *msg, int notify)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        if (notify<0 || notify>0x7f)
        int l;
 
        if (notify<0 || notify>0x7f)
@@ -1058,26 +1328,39 @@ void Pdss1::enc_ie_notify(unsigned char **ntmode, msg_t *msg, int notify)
        add_trace("notify", NULL, "%d", notify);
 
        l = 1;
        add_trace("notify", NULL, "%d", notify);
 
        l = 1;
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->notify.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->notify.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_NOTIFY;
        p[1] = l;
        p[2] = 0x80 + notify;
        p[0] = IE_NOTIFY;
        p[1] = l;
        p[2] = 0x80 + notify;
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_notify(struct l3_msg *l3m, int *notify)
+#else
 void Pdss1::dec_ie_notify(unsigned char *p, Q931_info_t *qi, int *notify)
 void Pdss1::dec_ie_notify(unsigned char *p, Q931_info_t *qi, int *notify)
+#endif
 {
        *notify = -1;
 
 {
        *notify = -1;
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->notify.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->notify.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->notify.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->notify.off + 1;
        }
+#else
+       unsigned char *p = l3m->notify;
+#endif
        if (!p)
                return;
        if (p[0] < 1)
        if (!p)
                return;
        if (p[0] < 1)
@@ -1093,10 +1376,18 @@ void Pdss1::dec_ie_notify(unsigned char *p, Q931_info_t *qi, int *notify)
 
 
 /* IE_PROGRESS */
 
 
 /* IE_PROGRESS */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_progress(struct l3_msg *l3m, int coding, int location, int progress)
+#else
 void Pdss1::enc_ie_progress(unsigned char **ntmode, msg_t *msg, int coding, int location, int progress)
 void Pdss1::enc_ie_progress(unsigned char **ntmode, msg_t *msg, int coding, int location, int progress)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        if (coding<0 || coding>0x03)
        int l;
 
        if (coding<0 || coding>0x03)
@@ -1120,29 +1411,42 @@ void Pdss1::enc_ie_progress(unsigned char **ntmode, msg_t *msg, int coding, int
        add_trace("progress", "indicator", "%d", progress);
 
        l = 2;
        add_trace("progress", "indicator", "%d", progress);
 
        l = 2;
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->progress.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->progress.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_PROGRESS;
        p[1] = l;
        p[2] = 0x80 + (coding<<5) + location;
        p[3] = 0x80 + progress;
        p[0] = IE_PROGRESS;
        p[1] = l;
        p[2] = 0x80 + (coding<<5) + location;
        p[3] = 0x80 + progress;
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_progress(struct l3_msg *l3m, int *coding, int *location, int *progress)
+#else
 void Pdss1::dec_ie_progress(unsigned char *p, Q931_info_t *qi, int *coding, int *location, int *progress)
 void Pdss1::dec_ie_progress(unsigned char *p, Q931_info_t *qi, int *coding, int *location, int *progress)
+#endif
 {
        *coding = -1;
        *location = -1;
        *progress = -1;
 
 {
        *coding = -1;
        *location = -1;
        *progress = -1;
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->progress.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->progress.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->progress.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->progress.off + 1;
        }
+#else
+       unsigned char *p = l3m->progress;
+#endif
        if (!p)
                return;
        if (p[0] < 1)
        if (!p)
                return;
        if (p[0] < 1)
@@ -1162,10 +1466,18 @@ void Pdss1::dec_ie_progress(unsigned char *p, Q931_info_t *qi, int *coding, int
 
 
 /* IE_REDIR_NR (redirecting = during MT_SETUP) */
 
 
 /* IE_REDIR_NR (redirecting = during MT_SETUP) */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_redir_nr(struct l3_msg *l3m, int type, int plan, int present, int screen, int reason, unsigned char *number)
+#else
 void Pdss1::enc_ie_redir_nr(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, int reason, unsigned char *number)
 void Pdss1::enc_ie_redir_nr(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, int reason, unsigned char *number)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        if (type<0 || type>7)
        int l;
 
        if (type<0 || type>7)
@@ -1210,11 +1522,13 @@ void Pdss1::enc_ie_redir_nr(unsigned char **ntmode, msg_t *msg, int type, int pl
                if (reason >= 0)
                        l += 1;
        }
                if (reason >= 0)
                        l += 1;
        }
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->redirect_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->redirect_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_REDIR_NR;
        p[1] = l;
        if (present >= 0)
        p[0] = IE_REDIR_NR;
        p[1] = l;
        if (present >= 0)
@@ -1239,9 +1553,16 @@ void Pdss1::enc_ie_redir_nr(unsigned char **ntmode, msg_t *msg, int type, int pl
                if (number) if (number[0])
                        UNCPY((char *)p+3, (char *)number, strlen((char *)number));
        }
                if (number) if (number[0])
                        UNCPY((char *)p+3, (char *)number, strlen((char *)number));
        }
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_redir_nr(struct l3_msg *l3m, int *type, int *plan, int *present, int *screen, int *reason, unsigned char *number, int number_len)
+#else
 void Pdss1::dec_ie_redir_nr(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, int *reason, unsigned char *number, int number_len)
 void Pdss1::dec_ie_redir_nr(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, int *reason, unsigned char *number, int number_len)
+#endif
 {
        *type = -1;
        *plan = -1;
 {
        *type = -1;
        *plan = -1;
@@ -1250,12 +1571,16 @@ void Pdss1::dec_ie_redir_nr(unsigned char *p, Q931_info_t *qi, int *type, int *p
        *reason = -1;
        *number = '\0';
 
        *reason = -1;
        *number = '\0';
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->redirect_nr.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redirect_nr.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->redirect_nr.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redirect_nr.off + 1;
        }
+#else
+       unsigned char *p = l3m->redirect_nr;
+#endif
        if (!p)
                return;
        if (p[0] < 1)
        if (!p)
                return;
        if (p[0] < 1)
@@ -1293,10 +1618,18 @@ void Pdss1::dec_ie_redir_nr(unsigned char *p, Q931_info_t *qi, int *type, int *p
 
 
 /* IE_REDIR_DN (redirection = during MT_NOTIFY) */
 
 
 /* IE_REDIR_DN (redirection = during MT_NOTIFY) */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_redir_dn(struct l3_msg *l3m, int type, int plan, int present, unsigned char *number)
+#else
 void Pdss1::enc_ie_redir_dn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, unsigned char *number)
 void Pdss1::enc_ie_redir_dn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, unsigned char *number)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        if (type<0 || type>7)
        int l;
 
        if (type<0 || type>7)
@@ -1325,11 +1658,13 @@ void Pdss1::enc_ie_redir_dn(unsigned char **ntmode, msg_t *msg, int type, int pl
                l += strlen((char *)number);
        if (present >= 0)
                l += 1;
                l += strlen((char *)number);
        if (present >= 0)
                l += 1;
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->redirect_dn.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->redirect_dn.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_REDIR_DN;
        p[1] = l;
        if (present >= 0)
        p[0] = IE_REDIR_DN;
        p[1] = l;
        if (present >= 0)
@@ -1344,21 +1679,32 @@ void Pdss1::enc_ie_redir_dn(unsigned char **ntmode, msg_t *msg, int type, int pl
                if (number)
                        UNCPY((char *)p+3, (char *)number, strlen((char *)number));
        }
                if (number)
                        UNCPY((char *)p+3, (char *)number, strlen((char *)number));
        }
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_redir_dn(struct l3_msg *l3m, int *type, int *plan, int *present, unsigned char *number, int number_len)
+#else
 void Pdss1::dec_ie_redir_dn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, unsigned char *number, int number_len)
 void Pdss1::dec_ie_redir_dn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, unsigned char *number, int number_len)
+#endif
 {
        *type = -1;
        *plan = -1;
        *present = -1;
        *number = '\0';
 
 {
        *type = -1;
        *plan = -1;
        *present = -1;
        *number = '\0';
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->redirect_dn.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redirect_dn.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->redirect_dn.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redirect_dn.off + 1;
        }
+#else
+       unsigned char *p = l3m->redirect_dn;
+#endif
        if (!p)
                return;
        if (p[0] < 1)
        if (!p)
                return;
        if (p[0] < 1)
@@ -1386,10 +1732,18 @@ void Pdss1::dec_ie_redir_dn(unsigned char *p, Q931_info_t *qi, int *type, int *p
 
 
 /* IE_FACILITY */
 
 
 /* IE_FACILITY */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_facility(struct l3_msg *l3m, unsigned char *facility, int facility_len)
+#else
 void Pdss1::enc_ie_facility(unsigned char **ntmode, msg_t *msg, unsigned char *facility, int facility_len)
 void Pdss1::enc_ie_facility(unsigned char **ntmode, msg_t *msg, unsigned char *facility, int facility_len)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        char buffer[768];
        int l;
 
        char buffer[768];
@@ -1410,29 +1764,42 @@ void Pdss1::enc_ie_facility(unsigned char **ntmode, msg_t *msg, unsigned char *f
        add_trace("facility", NULL, "%s", buffer+1);
 
        l = facility_len;
        add_trace("facility", NULL, "%s", buffer+1);
 
        l = facility_len;
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->facility.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+2);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->facility.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_FACILITY;
        p[1] = l;
        memcpy(p+2, facility, facility_len);
        p[0] = IE_FACILITY;
        p[1] = l;
        memcpy(p+2, facility, facility_len);
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_facility(struct l3_msg *l3m, unsigned char *facility, int *facility_len)
+#else
 void Pdss1::dec_ie_facility(unsigned char *p, Q931_info_t *qi, unsigned char *facility, int *facility_len)
 void Pdss1::dec_ie_facility(unsigned char *p, Q931_info_t *qi, unsigned char *facility, int *facility_len)
+#endif
 {
        char debug[768];
        int i;
 
        *facility_len = 0;
 
 {
        char debug[768];
        int i;
 
        *facility_len = 0;
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->facility.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->facility.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->facility.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->facility.off + 1;
        }
+#else
+       unsigned char *p = l3m->facility;
+#endif
        if (!p)
                return;
 
        if (!p)
                return;
 
@@ -1451,7 +1818,11 @@ void Pdss1::dec_ie_facility(unsigned char *p, Q931_info_t *qi, unsigned char *fa
 }
 
 
 }
 
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_facility_centrex(struct l3_msg *l3m, unsigned char *cnip, int cnip_len)
+#else
 void Pdss1::dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned char *cnip, int cnip_len)
 void Pdss1::dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned char *cnip, int cnip_len)
+#endif
 {
        unsigned char centrex[256];
        char debug[768];
 {
        unsigned char centrex[256];
        char debug[768];
@@ -1459,7 +1830,11 @@ void Pdss1::dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned cha
        int i = 0, j;
        *cnip = '\0';
 
        int i = 0, j;
        *cnip = '\0';
 
+#ifdef SOCKET_MISDN
+       dec_ie_facility(l3m, centrex, &facility_len);
+#else
        dec_ie_facility(p, qi, centrex, &facility_len);
        dec_ie_facility(p, qi, centrex, &facility_len);
+#endif
        if (facility_len >= 2)
        {
                if (centrex[i++] != CENTREX_FAC)
        if (facility_len >= 2)
        {
                if (centrex[i++] != CENTREX_FAC)
@@ -1498,10 +1873,18 @@ void Pdss1::dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned cha
 
 
 /* IE_USERUSER */
 
 
 /* IE_USERUSER */
+#ifdef SOCKET_MISDN
+void Pdss1::enc_ie_useruser(struct l3_msg *l3m, int protocol, unsigned char *user, int user_len)
+#else
 void Pdss1::enc_ie_useruser(unsigned char **ntmode, msg_t *msg, int protocol, unsigned char *user, int user_len)
 void Pdss1::enc_ie_useruser(unsigned char **ntmode, msg_t *msg, int protocol, unsigned char *user, int user_len)
+#endif
 {
 {
+#ifdef SOCKET_MISDN
+       unsigned char p[256];
+#else
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
        unsigned char *p;
        Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+#endif
        int l;
 
        char buffer[768];
        int l;
 
        char buffer[768];
@@ -1528,18 +1911,27 @@ void Pdss1::enc_ie_useruser(unsigned char **ntmode, msg_t *msg, int protocol, un
        add_trace("useruser", "value", "%s", buffer);
 
        l = user_len;
        add_trace("useruser", "value", "%s", buffer);
 
        l = user_len;
+#ifndef SOCKET_MISDN
        p = msg_put(msg, l+3);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->useruser.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
        p = msg_put(msg, l+3);
        if (p_m_d_ntmode)
                *ntmode = p+1;
        else
                qi->useruser.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
+#endif
        p[0] = IE_USER_USER;
        p[1] = l;
        p[2] = 0x80 + protocol;
        memcpy(p+3, user, user_len);
        p[0] = IE_USER_USER;
        p[1] = l;
        p[2] = 0x80 + protocol;
        memcpy(p+3, user, user_len);
+#ifdef SOCKET_MISDN
+       add_layer3_ie(l3m, p[0], p[1], p+2);
+#endif
 }
 
 }
 
+#ifdef SOCKET_MISDN
+void Pdss1::dec_ie_useruser(struct l3_msg *l3m, int *protocol, unsigned char *user, int *user_len)
+#else
 void Pdss1::dec_ie_useruser(unsigned char *p, Q931_info_t *qi, int *protocol, unsigned char *user, int *user_len)
 void Pdss1::dec_ie_useruser(unsigned char *p, Q931_info_t *qi, int *protocol, unsigned char *user, int *user_len)
+#endif
 {
        char buffer[768];
        int i;
 {
        char buffer[768];
        int i;
@@ -1547,12 +1939,16 @@ void Pdss1::dec_ie_useruser(unsigned char *p, Q931_info_t *qi, int *protocol, un
        *user_len = 0;
        *protocol = -1;
 
        *user_len = 0;
        *protocol = -1;
 
+#ifndef SOCKET_MISDN
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->useruser.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->useruser.off + 1;
        }
        if (!p_m_d_ntmode)
        {
                p = NULL;
                if (qi->useruser.off)
                        p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->useruser.off + 1;
        }
+#else
+       unsigned char *p = l3m->useruser;
+#endif
        if (!p)
                return;
 
        if (!p)
                return;
 
index f7f5a3d..aa55f36 100644 (file)
@@ -9,9 +9,6 @@
 **                                                                           **
 \*****************************************************************************/ 
 
 **                                                                           **
 \*****************************************************************************/ 
 
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
 #include "main.h"
 
 struct interface *interface_first = NULL; /* first interface is current list */
 #include "main.h"
 
 struct interface *interface_first = NULL; /* first interface is current list */
index 1583211..75cdadf 100644 (file)
--- a/mISDN.cpp
+++ b/mISDN.cpp
@@ -96,18 +96,19 @@ int mISDN_initialize(void)
                return(-1);
        }
 
                return(-1);
        }
 
-       /* initialize stuff of the NT lib */
+       /* open debug, if enabled and not only stack debugging */
+       if (options.deb && (options.deb != DEBUG_STACK))
+       {
+               SPRINT(debug_log, "%s/debug.log", INSTALL_DATA);
+               debug_fp = fopen(debug_log, "a");
+       }
+
        if (options.deb & DEBUG_STACK)
        {
        if (options.deb & DEBUG_STACK)
        {
-               global_debug = 0xffffffff & ~DBGM_MSG;
-//             global_debug = DBGM_L3DATA;
+               SPRINT(debug_stack, "%s/debug_mISDN.log", INSTALL_DATA);
+               mISDN_debug_init(DBGM_ALL, debug_stack, debug_stack, debug_stack);
        } else
        } else
-               global_debug = DBGM_MAN;
-       SPRINT(debug_log, "%s/debug.log", INSTALL_DATA);
-       if (options.deb & DEBUG_LOG)
-               mISDN_debug_init(global_debug, debug_log, debug_log, debug_log);
-       else
-               mISDN_debug_init(global_debug, NULL, NULL, NULL);
+               mISDN_debug_init(0, NULL, NULL, NULL);
 
        /* init mlayer3 */
        init_layer3(4); // buffer of 4
 
        /* init mlayer3 */
        init_layer3(4); // buffer of 4
@@ -121,6 +122,10 @@ void mISDN_deinitialize(void)
 
        mISDN_debug_close();
 
 
        mISDN_debug_close();
 
+       if (debug_fp)
+               fclose(debug_fp);
+       debug_fp = NULL;
+
        if (mISDNsocket > -1)
                close(mISDNsocket);
 }
        if (mISDNsocket > -1)
                close(mISDNsocket);
 }
@@ -182,6 +187,7 @@ void mISDN_deinitialize(void)
        unsigned char buff[1025];
 
        debug_close();
        unsigned char buff[1025];
 
        debug_close();
+       global_debug = 0;
 
        if (mISDNdevice >= 0)
        {
 
        if (mISDNdevice >= 0)
        {
@@ -2473,6 +2479,15 @@ int mISDN_handler(void)
        if (!mISDNport)
        {
                PERROR("message belongs to no mISDNport: prim(0x%x) addr(0x%x) msg->len(%d)\n", frm->prim, frm->addr, msg->len);
        if (!mISDNport)
        {
                PERROR("message belongs to no mISDNport: prim(0x%x) addr(0x%x) msg->len(%d)\n", frm->prim, frm->addr, msg->len);
+               // show a list of all mISDNports and their address
+#if 0
+               mISDNport = mISDNport_first;
+               while(mISDNport)
+               {
+                       PERROR(" port %s  %x -> %x\n", mISDNport->name, (frm->addr&MASTER_ID_MASK), (unsigned int)(mISDNport->upper_id&MASTER_ID_MASK));
+                       mISDNport = mISDNport->next;
+               } 
+#endif
                goto out;
        }
 
                goto out;
        }
 
diff --git a/mISDN.h b/mISDN.h
index 836947c..b14ea68 100644 (file)
--- a/mISDN.h
+++ b/mISDN.h
@@ -85,13 +85,18 @@ void mISDNport_close_all(void);
 void mISDNport_close(struct mISDNport *mISDNport);
 void mISDN_port_reorder(void);
 int mISDN_handler(void);
 void mISDNport_close(struct mISDNport *mISDNport);
 void mISDN_port_reorder(void);
 int mISDN_handler(void);
+#ifdef SOCKET_MISDN
+void enc_ie_cause_standalone(struct l3_msg *l3m, int location, int cause);
+int stack2manager_te(struct mISDNport *mISDNport,l3_msg *l3m);
+#else
 void enc_ie_cause_standalone(unsigned char **ntmode, msg_t *msg, int location, int cause);
 void enc_ie_cause_standalone(unsigned char **ntmode, msg_t *msg, int location, int cause);
+int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg);
+msg_t *create_l2msg(int prim, int dinfo, int size);
+#endif
 void ph_control(struct mISDNport *mISDNport, class PmISDN *isdnport, unsigned long handle, unsigned long c1, unsigned long c2, char *trace_name, int trace_value);
 void ph_control_block(struct mISDNport *mISDNport, unsigned long handle, unsigned long c1, void *c2, int c2_len, char *trace_name, int trace_value);
 void ph_control(struct mISDNport *mISDNport, class PmISDN *isdnport, unsigned long handle, unsigned long c1, unsigned long c2, char *trace_name, int trace_value);
 void ph_control_block(struct mISDNport *mISDNport, unsigned long handle, unsigned long c1, void *c2, int c2_len, char *trace_name, int trace_value);
-msg_t *create_l2msg(int prim, int dinfo, int size);
 void setup_queue(struct mISDNport *mISDNport, int link);
 int stack2manager_nt(void *dat, void *arg);
 void setup_queue(struct mISDNport *mISDNport, int link);
 int stack2manager_nt(void *dat, void *arg);
-int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg);
 void chan_trace_header(struct mISDNport *mISDNport, class PmISDN *port, char *msgtext, int direction);
 void l1l2l3_trace_header(struct mISDNport *mISDNport, class PmISDN *port, unsigned long prim, int direction);
 void bchannel_event(struct mISDNport *mISDNport, int i, int event);
 void chan_trace_header(struct mISDNport *mISDNport, class PmISDN *port, char *msgtext, int direction);
 void l1l2l3_trace_header(struct mISDNport *mISDNport, class PmISDN *port, unsigned long prim, int direction);
 void bchannel_event(struct mISDNport *mISDNport, int i, int event);
@@ -104,7 +109,11 @@ class PmISDN : public Port
        public:
        PmISDN(int type, struct mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive);
        ~PmISDN();
        public:
        PmISDN(int type, struct mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive);
        ~PmISDN();
+#ifdef SOCKET_MISDN
+       void bchannel_receive(unsigned char *frm, int len);
+#else
        void bchannel_receive(iframe_t *frm);
        void bchannel_receive(iframe_t *frm);
+#endif
        int handler(void);
        void transmit(unsigned char *buffer, int length);
        int message_epoint(unsigned long epoint_id, int message, union parameter *param);
        int handler(void);
        void transmit(unsigned char *buffer, int length);
        int message_epoint(unsigned long epoint_id, int message, union parameter *param);
diff --git a/main.c b/main.c
index 09d6a6f..24c0039 100644 (file)
--- a/main.c
+++ b/main.c
@@ -9,21 +9,6 @@
 **                                                                           **
 \*****************************************************************************/ 
 
 **                                                                           **
 \*****************************************************************************/ 
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <signal.h>
-#include <stdarg.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/file.h>
-#include <errno.h>
-#include <sys/mman.h>
-#include <sys/resource.h>
 #include "main.h"
 
 MESSAGES
 #include "main.h"
 
 MESSAGES
@@ -41,7 +26,11 @@ struct timezone now_tz;
                now_tm = localtime(&now); \
        }
 
                now_tm = localtime(&now); \
        }
 
+#ifdef SOCKET_MISDN
+FILE *debug_fp = NULL;
+#else
 int global_debug = 0;
 int global_debug = 0;
+#endif
 int quit=0;
 
 #if 0
 int quit=0;
 
 #if 0
@@ -82,8 +71,13 @@ void debug(const char *function, int line, char *prefix, char *buffer)
                last_debug = debug_count;
                if (!nooutput)
                        printf("\033[34m--------------------- %04d.%02d.%02d %02d:%02d:%02d %06d\033[36m\n", now_tm->tm_year+1900, now_tm->tm_mon+1, now_tm->tm_mday, now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec, debug_count%1000000);
                last_debug = debug_count;
                if (!nooutput)
                        printf("\033[34m--------------------- %04d.%02d.%02d %02d:%02d:%02d %06d\033[36m\n", now_tm->tm_year+1900, now_tm->tm_mon+1, now_tm->tm_mday, now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec, debug_count%1000000);
+#ifdef SOCKET_MISDN
+               if (debug_fp)
+                       fprintf(debug_fp, "--------------------- %04d.%02d.%02d %02d:%02d:%02d %06d\n", now_tm->tm_year+1900, now_tm->tm_mon+1, now_tm->tm_mday, now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec, debug_count%1000000);
+#else
                if (options.deb&DEBUG_LOG && global_debug)
                        dprint(DBGM_MAN, 0, "--------------------- %04d.%02d.%02d %02d:%02d:%02d %06d\n", now_tm->tm_year+1900, now_tm->tm_mon+1, now_tm->tm_mday, now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec, debug_count%1000000);
                if (options.deb&DEBUG_LOG && global_debug)
                        dprint(DBGM_MAN, 0, "--------------------- %04d.%02d.%02d %02d:%02d:%02d %06d\n", now_tm->tm_year+1900, now_tm->tm_mon+1, now_tm->tm_mday, now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec, debug_count%1000000);
+#endif
        }
 
        if (!nooutput)
        }
 
        if (!nooutput)
@@ -96,14 +90,26 @@ void debug(const char *function, int line, char *prefix, char *buffer)
                        printf("%s", buffer);
        }
 
                        printf("%s", buffer);
        }
 
+#ifdef SOCKET_MISDN
+       if (debug_fp)
+#else
        if (options.deb&DEBUG_LOG && global_debug)
        if (options.deb&DEBUG_LOG && global_debug)
+#endif
        {
                if (debug_newline)
                {
                        if (function)
        {
                if (debug_newline)
                {
                        if (function)
+#ifdef SOCKET_MISDN
+                               fprintf(debug_fp, "%s%s(in %s() line %d): %s", prefix?prefix:"", prefix?" ":"", function, line, buffer);
+#else
                                dprint(DBGM_MAN, 0, "%s%s(in %s() line %d): %s", prefix?prefix:"", prefix?" ":"", function, line, buffer);
                                dprint(DBGM_MAN, 0, "%s%s(in %s() line %d): %s", prefix?prefix:"", prefix?" ":"", function, line, buffer);
+#endif
                        else
                        else
+#ifdef SOCKET_MISDN
+                               fprintf(debug_fp, "%s%s: %s", prefix?prefix:"", prefix?" ":"", buffer);
+#else
                                dprint(DBGM_MAN, 0, "%s%s: %s", prefix?prefix:"", prefix?" ":"", buffer);
                                dprint(DBGM_MAN, 0, "%s%s: %s", prefix?prefix:"", prefix?" ":"", buffer);
+#endif
                }
        }
 
                }
        }
 
@@ -739,7 +745,6 @@ free:
 
        /* deinitialize mISDN */
        mISDN_deinitialize();
 
        /* deinitialize mISDN */
        mISDN_deinitialize();
-       global_debug = 0;
 
        /* display memory leak */
 #define MEMCHECK(a, b) \
 
        /* display memory leak */
 #define MEMCHECK(a, b) \
diff --git a/main.h b/main.h
index 61ffc80..42387b0 100644 (file)
--- a/main.h
+++ b/main.h
@@ -9,6 +9,27 @@
 **                                                                           **
 \*****************************************************************************/ 
 
 **                                                                           **
 \*****************************************************************************/ 
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+#include <time.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <pthread.h>
+#include <dirent.h>
+#include <math.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <sys/mman.h>
+#include <sys/resource.h>
+
 #define NAME           "LCR"
 
 #define DEFAULT_ENDPOINT_APP EndpointAppPBX
 #define NAME           "LCR"
 
 #define DEFAULT_ENDPOINT_APP EndpointAppPBX
@@ -26,7 +47,11 @@ extern int classuse;
 extern int fduse;
 extern int fhuse;
 
 extern int fduse;
 extern int fhuse;
 
+#ifdef SOCKET_MISDN
+extern FILE *debug_fp;
+#else
 extern int global_debug;
 extern int global_debug;
+#endif
 
 #define PDEBUG(mask, fmt, arg...) _printdebug(__FUNCTION__, __LINE__, mask, fmt, ## arg)
 #define PERROR(fmt, arg...) _printerror(__FUNCTION__, __LINE__, fmt, ## arg)
 
 #define PDEBUG(mask, fmt, arg...) _printdebug(__FUNCTION__, __LINE__, mask, fmt, ## arg)
 #define PERROR(fmt, arg...) _printerror(__FUNCTION__, __LINE__, fmt, ## arg)
@@ -103,13 +128,6 @@ void debug(const char *function, int line, char *prefix, char *buffer);
  #define BUDETECT      ;
 #endif
 
  #define BUDETECT      ;
 #endif
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <time.h>
-#include <sys/time.h>
-//#include <asm/bitops.h>
 #ifdef __cplusplus
 extern "C" {
 #endif
 #ifdef __cplusplus
 extern "C" {
 #endif
index eab2978..e3195e3 100644 (file)
--- a/message.c
+++ b/message.c
@@ -9,9 +9,6 @@
 **                                                                           **
 \*****************************************************************************/ 
 
 **                                                                           **
 \*****************************************************************************/ 
 
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
 #include "main.h"
 
 MESSAGES
 #include "main.h"
 
 MESSAGES
index 16813f6..db6c9fc 100644 (file)
--- a/options.c
+++ b/options.c
@@ -9,9 +9,6 @@
 **                                                                           **
 \*****************************************************************************/ 
 
 **                                                                           **
 \*****************************************************************************/ 
 
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
 #include "main.h"
 
 struct options options = {
 #include "main.h"
 
 struct options options = {
index d254d0c..d0cc5ba 100644 (file)
--- a/port.cpp
+++ b/port.cpp
@@ -45,15 +45,6 @@ Functions:
    
 */
 
    
 */
 
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <math.h>
 #include "main.h"
 
 #define SHORT_MIN -32768
 #include "main.h"
 
 #define SHORT_MIN -32768
diff --git a/q931.h b/q931.h
index ec1a44f..3d41f1b 100644 (file)
--- a/q931.h
+++ b/q931.h
@@ -8,6 +8,7 @@
 ** information elements support header                                       **
 **                                                                           **
 \*****************************************************************************/ 
 ** information elements support header                                       **
 **                                                                           **
 \*****************************************************************************/ 
+#ifndef SOCKET_MISDN
 
 #define MT_ALERTING             0x01
 #define MT_CALL_PROCEEDING      0x02
 
 #define MT_ALERTING             0x01
 #define MT_CALL_PROCEEDING      0x02
@@ -85,6 +86,8 @@
 #define IE_CONGESTION   0xb0
 #define IE_REPEAT       0xd0
 
 #define IE_CONGESTION   0xb0
 #define IE_REPEAT       0xd0
 
+#endif
+
 #define CENTREX_FAC    0x88
 #define CENTREX_ID     0xa1
 
 #define CENTREX_FAC    0x88
 #define CENTREX_ID     0xa1
 
diff --git a/route.c b/route.c
index f33c648..e322774 100644 (file)
--- a/route.c
+++ b/route.c
@@ -9,10 +9,6 @@
 **                                                                           **
 \*****************************************************************************/ 
 
 **                                                                           **
 \*****************************************************************************/ 
 
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
 #include "main.h"
 
 
 #include "main.h"
 
 
index 2624ad7..5ad827f 100644 (file)
@@ -16,7 +16,6 @@
 //#include <sys/stat.h>
 //#include <unistd.h>
 //#include <signal.h>
 //#include <sys/stat.h>
 //#include <unistd.h>
 //#include <signal.h>
-//#include <stdarg.h>
 //#include <fcntl.h>
 #include <sys/ioctl.h>
 //#include <sys/file.h>
 //#include <fcntl.h>
 #include <sys/ioctl.h>
 //#include <sys/file.h>
diff --git a/tones.c b/tones.c
index 783c83b..6b558dd 100644 (file)
--- a/tones.c
+++ b/tones.c
@@ -9,15 +9,6 @@
 **                                                                           **
 \*****************************************************************************/ 
 
 **                                                                           **
 \*****************************************************************************/ 
 
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <errno.h>
 #include "main.h"
 
 /* 
 #include "main.h"
 
 /*