fixup
[lcr.git] / ie.cpp
diff --git a/ie.cpp b/ie.cpp
index 236e49a..7509440 100644 (file)
--- a/ie.cpp
+++ b/ie.cpp
@@ -26,56 +26,25 @@ static void strnncpy(unsigned char *dest, unsigned char *src, int len, int dst_l
 
 
 /* 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)
-#endif
 {
-#ifndef SOCKET_MISDN
-       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) {
                PERROR("complete(%d) is out of range.\n", complete);
                return;
        }
 
-       if (complete)
-       {
+       if (complete) {
                add_trace("complete", NULL, NULL);
-#ifndef SOCKET_MISDN
-               p = msg_put(msg, 1);
-               if (p_m_d_ntmode)
-               {
-                       *ntmode = p;
-               } 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)
-#endif
 {
        *complete = 0;
-#ifndef SOCKET_MISDN
-       if (!p_m_d_ntmode)
-       {
-               if (qi->sending_complete.off)
-                       *complete = 1;
-       } else
-#else
-       unsigned char *p = l3m->sending_complete;
-#endif
+       // special case: p is not a pointer, it's a value
+       unsigned char p = l3m->sending_complete;
        if (p)
                *complete = 1;
 
@@ -85,52 +54,36 @@ void Pdss1::dec_ie_complete(unsigned char *p, Q931_info_t *qi, int *complete)
 
 
 /* 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)
-#endif
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
-       if (coding<0 || coding>3)
-       {
+       if (coding<0 || coding>3) {
                PERROR("coding(%d) is out of range.\n", coding);
                return;
        }
-       if (capability<0 || capability>31)
-       {
+       if (capability<0 || capability>31) {
                PERROR("capability(%d) is out of range.\n", capability);
                return;
        }
-       if (mode<0 || mode>3)
-       {
+       if (mode<0 || mode>3) {
                PERROR("mode(%d) is out of range.\n", mode);
                return;
        }
-       if (rate<0 || rate>31)
-       {
+       if (rate<0 || rate>31) {
                PERROR("rate(%d) is out of range.\n", rate);
                return;
        }
-       if (multi>127)
-       {
+       if (multi>127) {
                PERROR("multi(%d) is out of range.\n", multi);
                return;
        }
-       if (user>31)
-       {
+       if (user>31) {
                PERROR("user L1(%d) is out of range.\n", user);
                return;
        }
-       if (rate!=24 && multi>=0)
-       {
+       if (rate!=24 && multi>=0) {
                PERROR("multi(%d) is only possible if rate(%d) would be 24.\n", multi, rate);
                multi = -1;
        }
@@ -143,13 +96,6 @@ 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);
-#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);
-#endif
        p[0] = IE_BEARER;
        p[1] = l;
        p[2] = 0x80 + (coding<<5) + capability;
@@ -158,16 +104,10 @@ 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;
-#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)
-#endif
 {
        *coding = -1;
        *capability = -1;
@@ -176,38 +116,25 @@ void Pdss1::dec_ie_bearer(unsigned char *p, Q931_info_t *qi, int *coding, int *c
        *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;
-       }
-#else
        unsigned char *p = l3m->bearer_capability;
-#endif
        if (!p)
                return;
-       if (p[0] < 2)
-       {
+       if (p[0] < 2) {
                add_trace("bearer", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
        *coding = (p[1]&0x60) >> 5;
        *capability = p[1] & 0x1f;
-       if (p[0]>=2)
-       {
+       if (p[0]>=2) {
                *mode = (p[2]&0x60) >> 5;
                *rate = p[2] & 0x1f;
        }
-       if (p[0]>=3 && *rate==0x18)
-       {
+       if (p[0]>=3 && *rate==0x18) {
                *multi = p[3] & 0x7f;
                if (p[0]>=4)
                        *user = p[4] & 0x1f;
-       } else
-       {
+       } else {
                if (p[0]>=3)
                        *user = p[3] & 0x1f;
        }
@@ -222,42 +149,28 @@ void Pdss1::dec_ie_bearer(unsigned char *p, Q931_info_t *qi, int *coding, int *c
 
 
 /* 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)
-#endif
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
-       if (coding<0 || coding>3)
-       {
+       if (coding<0 || coding>3) {
                PERROR("coding(%d) is out of range.\n", coding);
                return;
        }
-       if (interpretation<0 || interpretation>7)
-       {
+       if (interpretation<0 || interpretation>7) {
                PERROR("interpretation(%d) is out of range.\n", interpretation);
                return;
        }
-       if (presentation<0 || presentation>3)
-       {
+       if (presentation<0 || presentation>3) {
                PERROR("presentation(%d) is out of range.\n", presentation);
                return;
        }
-       if (hlc<0 || hlc>127)
-       {
+       if (hlc<0 || hlc>127) {
                PERROR("hlc(%d) is out of range.\n", hlc);
                return;
        }
-       if (exthlc>127)
-       {
+       if (exthlc>127) {
                PERROR("hlc(%d) is out of range.\n", exthlc);
                return;
        }
@@ -270,32 +183,18 @@ 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);
-#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);
-#endif
        p[0] = IE_HLC;
        p[1] = l;
        p[2] = 0x80 + (coding<<5) + (interpretation<<2) + presentation;
-       if (exthlc >= 0)
-       {
+       if (exthlc >= 0) {
                p[3] = 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)
-#endif
 {
        *coding = -1;
        *interpretation = -1;
@@ -303,20 +202,10 @@ void Pdss1::dec_ie_hlc(unsigned char *p, Q931_info_t *qi, int *coding, int *inte
        *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;
-       }
-#else
        unsigned char *p = l3m->hlc;
-#endif
        if (!p)
                return;
-       if (p[0] < 2)
-       {
+       if (p[0] < 2) {
                add_trace("hlc", "error", "IE too short (len=%d)", p[0]);
                return;
        }
@@ -325,8 +214,7 @@ void Pdss1::dec_ie_hlc(unsigned char *p, Q931_info_t *qi, int *coding, int *inte
        *interpretation = (p[1]&0x1c) >> 2;
        *presentation = p[1] & 0x03;
        *hlc = p[2] & 0x7f;
-       if (p[0]>=3)
-       {
+       if (p[0]>=3) {
                *exthlc = p[3] & 0x7f;
        }
 
@@ -340,36 +228,24 @@ void Pdss1::dec_ie_hlc(unsigned char *p, Q931_info_t *qi, int *coding, int *inte
 
 
 /* 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)
-#endif
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
        char buffer[25];
        int i;
 
-       if (!callid || callid_len<=0)
-       {
+       if (!callid || callid_len<=0) {
                return;
        }
-       if (callid_len > 8)
-       {
+       if (callid_len > 8) {
                PERROR("callid_len(%d) is out of range.\n", callid_len);
                return;
        }
 
        i = 0;
-       while(i < callid_len)
-       {
+       while(i < callid_len) {
                UPRINT(buffer+(i*3), " %02x", callid[i]);
                i++;
        }
@@ -377,46 +253,23 @@ 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;
-#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);
-#endif
        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)
-#endif
 {
        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;
-       }
-#else
        unsigned char *p = l3m->call_id;
-#endif
        if (!p)
                return;
-       if (p[0] > 8)
-       {
+       if (p[0] > 8) {
                add_trace("callid", "error", "IE too long (len=%d)", p[0]);
                return;
        }
@@ -425,8 +278,7 @@ void Pdss1::dec_ie_call_id(unsigned char *p, Q931_info_t *qi, unsigned char *cal
        memcpy(callid, p+1, *callid_len);
 
        i = 0;
-       while(i < *callid_len)
-       {
+       while(i < *callid_len) {
                UPRINT(buffer+(i*3), " %02x", callid[i]);
                i++;
        }
@@ -436,81 +288,48 @@ void Pdss1::dec_ie_call_id(unsigned char *p, Q931_info_t *qi, unsigned char *cal
 
 
 /* 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)
-#endif
+void Pdss1::enc_ie_called_pn(struct l3_msg *l3m, int type, int plan, unsigned char *number, int number_len)
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
-       if (type<0 || type>7)
-       {
+       if (type<0 || type>7) {
                PERROR("type(%d) is out of range.\n", type);
                return;
        }
-       if (plan<0 || plan>15)
-       {
+       if (plan<0 || plan>15) {
                PERROR("plan(%d) is out of range.\n", plan);
                return;
        }
-       if (!number[0])
-       {
+       if (!number[0]) {
                PERROR("number is not given.\n");
                return;
        }
 
        add_trace("called_pn", "type", "%d", type);
        add_trace("called_pn", "plan", "%d", plan);
-       add_trace("called_pn", "number", "%s", number);
+       UNCPY((char *)p, (char *)number, number_len);
+       p[number_len] = '\0';
+       add_trace("called_pn", "number", "%s", p);
 
-       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);
-#endif
+       l = 1+number_len;
        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
+       UNCPY((char *)p+3, (char *)number, number_len);
        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)
-#endif
 {
        *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;
-       }
-#else
        unsigned char *p = l3m->called_nr;
-#endif
        if (!p)
                return;
-       if (p[0] < 2)
-       {
+       if (p[0] < 2) {
                add_trace("called_pn", "error", "IE too short (len=%d)", p[0]);
                return;
        }
@@ -526,37 +345,24 @@ void Pdss1::dec_ie_called_pn(unsigned char *p, Q931_info_t *qi, int *type, int *
 
 
 /* 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)
-#endif
+void Pdss1::enc_ie_calling_pn(struct l3_msg *l3m, int type, int plan, int present, int screen, unsigned char *number, int type2, int plan2, int present2, int screen2, unsigned char *number2)
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
-       if (type<0 || type>7)
-       {
+       if (type<0 || type>7) {
                PERROR("type(%d) is out of range.\n", type);
                return;
        }
-       if (plan<0 || plan>15)
-       {
+       if (plan<0 || plan>15) {
                PERROR("plan(%d) is out of range.\n", plan);
                return;
        }
-       if (present>3)
-       {
+       if (present>3) {
                PERROR("present(%d) is out of range.\n", present);
                return;
        }
-       if (present >= 0) if (screen<0 || screen>3)
-       {
+       if (present >= 0) if (screen<0 || screen>3) {
                PERROR("screen(%d) is out of range.\n", screen);
                return;
        }
@@ -572,76 +378,101 @@ void Pdss1::enc_ie_calling_pn(unsigned char **ntmode, msg_t *msg, int type, int
                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);
-#endif
        p[0] = IE_CALLING_PN;
        p[1] = l;
-       if (present >= 0)
-       {
+       if (present >= 0) {
                p[2] = 0x00 + (type<<4) + plan;
                p[3] = 0x80 + (present<<5) + screen;
                if (number) if (number[0])
                        UNCPY((char *)p+4, (char *)number, strlen((char *)number));
-       } else
-       {
+       } else {
                p[2] = 0x80 + (type<<4) + plan;
                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
+
+       /* second calling party number */
+       if (type2 < 0)
+               return;
+       
+       if (type2>7) {
+               PERROR("type2(%d) is out of range.\n", type2);
+               return;
+       }
+       if (plan2<0 || plan2>15) {
+               PERROR("plan2(%d) is out of range.\n", plan2);
+               return;
+       }
+       if (present2>3) {
+               PERROR("present2(%d) is out of range.\n", present2);
+               return;
+       }
+       if (present2 >= 0) if (screen2<0 || screen2>3) {
+               PERROR("screen2(%d) is out of range.\n", screen2);
+               return;
+       }
+
+       add_trace("call_pn 2", "type", "%d", type2);
+       add_trace("call_pn 2", "plan", "%d", plan2);
+       add_trace("call_pn 2", "present", "%d", present2);
+       add_trace("call_pn 2", "screen", "%d", screen2);
+       add_trace("call_pn 2", "number", "%s", number2);
+
+       l = 1;
+       if (number2) if (number2[0])
+               l += strlen((char *)number2);
+       if (present2 >= 0)
+               l += 1;
+       p[0] = IE_CALLING_PN;
+       p[1] = l;
+       if (present2 >= 0) {
+               p[2] = 0x00 + (type2<<4) + plan2;
+               p[3] = 0x80 + (present2<<5) + screen2;
+               if (number2) if (number2[0])
+                       UNCPY((char *)p+4, (char *)number2, strlen((char *)number2));
+       } else {
+               p[2] = 0x80 + (type2<<4) + plan2;
+               if (number2) if (number2[0])
+                       UNCPY((char *)p+3, (char *)number2, strlen((char *)number2));
+       }
+       add_layer3_ie(l3m, p[0], p[1], p+2);
 }
 
-#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)
-#endif
+void Pdss1::dec_ie_calling_pn(struct l3_msg *l3m, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len, int *type2, int *plan2, int *present2, int *screen2, unsigned char *number2, int number_len2)
 {
        *type = -1;
        *plan = -1;
        *present = -1;
        *screen = -1;
        *number = '\0';
+       *type2 = -1;
+       *plan2 = -1;
+       *present2 = -1;
+       *screen2 = -1;
+       *number2 = '\0';
+       unsigned int numextra = sizeof(l3m->extra) / sizeof(struct m_extie);
+       unsigned int i;
 
-#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;
-       }
-#else
        unsigned char *p = l3m->calling_nr;
-#endif
        if (!p)
                return;
-       if (p[0] < 1)
-       {
+       if (p[0] < 1) {
                add_trace("calling_pn", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
        *type = (p[1]&0x70) >> 4;
        *plan = p[1] & 0xf;
-       if (!(p[1] & 0x80))
-       {
-               if (p[0] < 2)
-               {
+       if (!(p[1] & 0x80)) {
+               if (p[0] < 2) {
                        add_trace("calling_pn", "error", "IE too short (len=%d)", p[0]);
                        return;
                }
                *present = (p[2]&0x60) >> 5;
                *screen = p[2] & 0x3;
                strnncpy(number, p+3, p[0]-2, number_len);
-       } else
-       {
+       } else {
                strnncpy(number, p+2, p[0]-1, number_len);
        }
 
@@ -650,41 +481,67 @@ void Pdss1::dec_ie_calling_pn(unsigned char *p, Q931_info_t *qi, int *type, int
        add_trace("calling_pn", "present", "%d", *present);
        add_trace("calling_pn", "screen", "%d", *screen);
        add_trace("calling_pn", "number", "%s", number);
+
+       /* second calling party number */
+       p = NULL;
+       i = 0;
+       while(i < numextra) {
+               if (!l3m->extra[i].val)
+                       break;
+               if (l3m->extra[i].ie == IE_CALLING_PN) {
+                       p = l3m->extra[i].val;
+                       break;
+               }
+               i++;
+       }
+       if (!p)
+               return;
+       if (p[0] < 1) {
+               add_trace("calling_pn2", "error", "IE too short (len=%d)", p[0]);
+               return;
+       }
+
+       *type2 = (p[1]&0x70) >> 4;
+       *plan2 = p[1] & 0xf;
+       if (!(p[1] & 0x80)) {
+               if (p[0] < 2) {
+                       add_trace("calling_pn2", "error", "IE too short (len=%d)", p[0]);
+                       return;
+               }
+               *present2 = (p[2]&0x60) >> 5;
+               *screen2 = p[2] & 0x3;
+               strnncpy(number2, p+3, p[0]-2, number_len2);
+       } else {
+               strnncpy(number2, p+2, p[0]-1, number_len2);
+       }
+
+       add_trace("call_pn 2", "type", "%d", *type2);
+       add_trace("call_pn 2", "plan", "%d", *plan2);
+       add_trace("call_pn 2", "present", "%d", *present2);
+       add_trace("call_pn 2", "screen", "%d", *screen2);
+       add_trace("call_pn 2", "number", "%s", number2);
 }
 
 
 /* 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)
-#endif
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
-       if (type<0 || type>7)
-       {
+       if (type<0 || type>7) {
                PERROR("type(%d) is out of range.\n", type);
                return;
        }
-       if (plan<0 || plan>15)
-       {
+       if (plan<0 || plan>15) {
                PERROR("plan(%d) is out of range.\n", plan);
                return;
        }
-       if (present>3)
-       {
+       if (present>3) {
                PERROR("present(%d) is out of range.\n", present);
                return;
        }
-       if (present >= 0) if (screen<0 || screen>3)
-       {
+       if (present >= 0) if (screen<0 || screen>3) {
                PERROR("screen(%d) is out of range.\n", screen);
                return;
        }
@@ -700,37 +557,22 @@ void Pdss1::enc_ie_connected_pn(unsigned char **ntmode, msg_t *msg, int type, in
                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);
-#endif
        p[0] = IE_CONNECT_PN;
        p[1] = l;
-       if (present >= 0)
-       {
+       if (present >= 0) {
                p[2] = 0x00 + (type<<4) + plan;
                p[3] = 0x80 + (present<<5) + screen;
                if (number) if (number[0])
                        UNCPY((char *)p+4, (char *)number, strlen((char *)number));
-       } else
-       {
+       } else {
                p[2] = 0x80 + (type<<4) + plan;
                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)
-#endif
 {
        *type = -1;
        *plan = -1;
@@ -738,38 +580,25 @@ void Pdss1::dec_ie_connected_pn(unsigned char *p, Q931_info_t *qi, int *type, in
        *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;
-       }
-#else
        unsigned char *p = l3m->connected_nr;
-#endif
        if (!p)
                return;
-       if (p[0] < 1)
-       {
+       if (p[0] < 1) {
                add_trace("connect_pn", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
        *type = (p[1]&0x70) >> 4;
        *plan = p[1] & 0xf;
-       if (!(p[1] & 0x80))
-       {
-               if (p[0] < 2)
-               {
+       if (!(p[1] & 0x80)) {
+               if (p[0] < 2) {
                        add_trace("connect_pn", "error", "IE too short (len=%d)", p[0]);
                        return;
                }
                *present = (p[2]&0x60) >> 5;
                *screen = p[2] & 0x3;
                strnncpy(number, p+3, p[0]-2, number_len);
-       } else
-       {
+       } else {
                strnncpy(number, p+2, p[0]-1, number_len);
        }
 
@@ -782,27 +611,16 @@ void Pdss1::dec_ie_connected_pn(unsigned char *p, Q931_info_t *qi, int *type, in
 
 
 /* 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)
-#endif
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
-       if (location<0 || location>7)
-       {
+       if (location<0 || location>10) {
                PERROR("location(%d) is out of range.\n", location);
                return;
        }
-       if (cause<0 || cause>127)
-       {
+       if (cause<0 || cause>127) {
                PERROR("cause(%d) is out of range.\n", cause);
                return;
        }
@@ -811,70 +629,32 @@ void Pdss1::enc_ie_cause(unsigned char **ntmode, msg_t *msg, int location, int c
        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);
-#endif
        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)
-#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);
-#endif
        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)
-#endif
 {
        *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;
-       }
-#else
        unsigned char *p = l3m->cause;
-#endif
        if (!p)
                return;
-       if (p[0] < 2)
-       {
+       if (p[0] < 2) {
                add_trace("cause", "error", "IE too short (len=%d)", p[0]);
                return;
        }
@@ -888,38 +668,26 @@ void Pdss1::dec_ie_cause(unsigned char *p, Q931_info_t *qi, int *location, int *
 
 
 /* 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)
-#endif
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
        int pri = p_m_mISDNport->pri;
 
-       if (exclusive<0 || exclusive>1)
-       {
+       if (exclusive<0 || exclusive>1) {
                PERROR("exclusive(%d) is out of range.\n", exclusive);
                return;
        }
        if ((channel<=0 && channel!=CHANNEL_NO && channel!=CHANNEL_ANY)
         || (!pri && channel>2)
         || (pri && channel>127)
-        || (pri && channel==16))
-       {
+        || (pri && channel==16)) {
                PERROR("channel(%d) is out of range.\n", channel);
                return;
        }
 
        add_trace("channel_id", "exclusive", "%d", exclusive);
-       switch(channel)
-       {
+       switch(channel) {
                case CHANNEL_ANY:
                add_trace("channel_id", "channel", "any channel");
                break;
@@ -930,17 +698,9 @@ void Pdss1::enc_ie_channel_id(unsigned char **ntmode, msg_t *msg, int exclusive,
                add_trace("channel_id", "channel", "%d", channel);
        }
 
-       if (!pri)
-       {
+       if (!pri) {
                /* 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);
-#endif
                p[0] = IE_CHANNEL_ID;
                p[1] = l;
                if (channel == CHANNEL_NO)
@@ -948,97 +708,59 @@ 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;
-#ifdef SOCKET_MISDN
                add_layer3_ie(l3m, p[0], p[1], p+2);
-#endif
-       } else
-       {
+       } else {
                /* PRI */
-               if (channel == CHANNEL_NO) /* no channel */
-                       return; /* IE not present */
-               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;
+               if (channel == CHANNEL_NO || channel == CHANNEL_ANY) {
+                       if (channel == CHANNEL_NO)
+                               channel = 0;
                        else
-                               qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
-#endif
+                               channel = 3;
+                       l = 1;
                        p[0] = IE_CHANNEL_ID;
                        p[1] = l;
-                       p[2] = 0x80 + 0x20 + 0x03;
-#ifdef SOCKET_MISDN
+                       p[2] = 0x80 + 0x20 + channel;
                        add_layer3_ie(l3m, p[0], p[1], p+2);
-#endif
                        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);
-#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;
-#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)
-#endif
 {
        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;
-       }
-#else
        unsigned char *p = l3m->channel_id;
-#endif
        if (!p)
                return;
-       if (p[0] < 1)
-       {
+       if (p[0] < 1) {
                add_trace("channel_id", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
-       if (p[1] & 0x40)
-       {
+       if (p[1] & 0x40) {
                add_trace("channel_id", "error", "refering to channels of other interfaces is not supported");
                return;
        }
-       if (p[1] & 0x04)
-       {
+       if (p[1] & 0x04) {
                add_trace("channel_id", "error", "using d-channel is not supported");
                return;
        }
 
        *exclusive = (p[1]&0x08) >> 3;
-       if (!pri)
-       {
+       if (!pri) {
                /* BRI */
-               if (p[1] & 0x20)
-               {
+               if (p[1] & 0x20) {
                        add_trace("channel_id", "error", "extended channel ID with non PRI interface");
                        return;
                }
@@ -1047,53 +769,44 @@ void Pdss1::dec_ie_channel_id(unsigned char *p, Q931_info_t *qi, int *exclusive,
                        *channel = CHANNEL_ANY;
                else if (*channel == 0)
                        *channel = CHANNEL_NO;
-       } else
-       {
+       } else {
                /* PRI */
-               if (p[0] < 1)
-               {
+               if (p[0] < 1) {
 
                        add_trace("channel_id", "error", "IE too short for PRI (len=%d)", p[0]);
                        return;
                }
-               if (!(p[1] & 0x20))
-               {
+               if (!(p[1] & 0x20)) {
                        add_trace("channel_id", "error", "basic channel ID with PRI interface");
                        return;
                }
-               if ((p[1]&0x03) == 0x00)
-               {
+               if ((p[1]&0x03) == 0x00) {
                        /* no channel */
                        *channel = CHANNEL_NO;
                        return;
                }
-               if ((p[1]&0x03) == 0x03)
-               {
+               if ((p[1]&0x03) == 0x03) {
                        /* any channel */
                        *channel = CHANNEL_ANY;
                        return;
                }
-               if (p[0] < 3)
-               {
+               if (p[0] < 3) {
                        add_trace("channel_id", "error", "IE too short for PRI with channel (len=%d)", p[0]);
                        return;
                }
-               if (p[2] & 0x10)
-               {
+               if (p[2] & 0x10) {
                        add_trace("channel_id", "error", "channel map not supported");
                        return;
                }
                *channel = p[3] & 0x7f;
-               if (*channel<1 | *channel==16)
-               {
+               if ((*channel<1) || (*channel==16)) {
                        add_trace("channel_id", "error", "PRI interface channel out of range (%d)", *channel);
                        return;
                }
        }
 
        add_trace("channel_id", "exclusive", "%d", *exclusive);
-       switch(*channel)
-       {
+       switch(*channel) {
                case CHANNEL_ANY:
                add_trace("channel_id", "channel", "any channel");
                break;
@@ -1107,25 +820,15 @@ void Pdss1::dec_ie_channel_id(unsigned char *p, Q931_info_t *qi, int *exclusive,
 
 
 /* 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)
-#endif
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
        struct tm *tm;
 
        tm = localtime(&ti);
-       if (!tm)
-       {
+       if (!tm) {
                PERROR("localtime() returned NULL.\n");
                return;
        }
@@ -1134,13 +837,6 @@ 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);
-#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);
-#endif
        p[0] = IE_DATE;
        p[1] = l;
        p[2] = tm->tm_year % 100;
@@ -1150,35 +846,22 @@ 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;
-#ifdef SOCKET_MISDN
        add_layer3_ie(l3m, p[0], p[1], p+2);
-#endif
 }
 
 
 /* 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)
-#endif
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
-       if (!display[0])
-       {
+       if (!display[0]) {
                PERROR("display text not given.\n");
                return;
        }
 
-       if (strlen((char *)display) > 80)
-       {
+       if (strlen((char *)display) > 80) {
                PERROR("display text too long (max 80 chars), cutting.\n");
                display[80] = '\0';
        }
@@ -1186,43 +869,20 @@ void Pdss1::enc_ie_display(unsigned char **ntmode, msg_t *msg, unsigned char *di
        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);
-#endif
        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)
-#endif
 {
        *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;
-       }
-#else
        unsigned char *p = l3m->display;
-#endif
        if (!p)
                return;
-       if (p[0] < 1)
-       {
+       if (p[0] < 1) {
                add_trace("display", "error", "IE too short (len=%d)", p[0]);
                return;
        }
@@ -1234,22 +894,12 @@ void Pdss1::dec_ie_display(unsigned char *p, Q931_info_t *qi, unsigned char *dis
 
 
 /* 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)
-#endif
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
-       if (!keypad[0])
-       {
+       if (!keypad[0]) {
                PERROR("keypad info not given.\n");
                return;
        }
@@ -1257,43 +907,20 @@ void Pdss1::enc_ie_keypad(unsigned char **ntmode, msg_t *msg, unsigned char *key
        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);
-#endif
        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)
-#endif
 {
        *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;
-       }
-#else
        unsigned char *p = l3m->keypad;
-#endif
        if (!p)
                return;
-       if (p[0] < 1)
-       {
+       if (p[0] < 1) {
                add_trace("keypad", "error", "IE too short (len=%d)", p[0]);
                return;
        }
@@ -1305,22 +932,12 @@ void Pdss1::dec_ie_keypad(unsigned char *p, Q931_info_t *qi, unsigned char *keyp
 
 
 /* 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)
-#endif
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
-       if (notify<0 || notify>0x7f)
-       {
+       if (notify<0 || notify>0x7f) {
                PERROR("notify(%d) is out of range.\n", notify);
                return;
        }
@@ -1328,43 +945,20 @@ void Pdss1::enc_ie_notify(unsigned char **ntmode, msg_t *msg, int notify)
        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);
-#endif
        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)
-#endif
 {
        *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;
-       }
-#else
        unsigned char *p = l3m->notify;
-#endif
        if (!p)
                return;
-       if (p[0] < 1)
-       {
+       if (p[0] < 1) {
                add_trace("notify", "error", "IE too short (len=%d)", p[0]);
                return;
        }
@@ -1376,32 +970,20 @@ void Pdss1::dec_ie_notify(unsigned char *p, Q931_info_t *qi, int *notify)
 
 
 /* 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)
-#endif
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
-       if (coding<0 || coding>0x03)
-       {
+       if (coding<0 || coding>0x03) {
                PERROR("coding(%d) is out of range.\n", coding);
                return;
        }
-       if (location<0 || location>0x0f)
-       {
+       if (location<0 || location>0x0f) {
                PERROR("location(%d) is out of range.\n", location);
                return;
        }
-       if (progress<0 || progress>0x7f)
-       {
+       if (progress<0 || progress>0x7f) {
                PERROR("progress(%d) is out of range.\n", progress);
                return;
        }
@@ -1411,46 +993,23 @@ void Pdss1::enc_ie_progress(unsigned char **ntmode, msg_t *msg, int coding, int
        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);
-#endif
        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)
-#endif
 {
        *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;
-       }
-#else
        unsigned char *p = l3m->progress;
-#endif
        if (!p)
                return;
-       if (p[0] < 1)
-       {
+       if (p[0] < 1) {
                add_trace("progress", "error", "IE too short (len=%d)", p[0]);
                return;
        }
@@ -1466,42 +1025,28 @@ void Pdss1::dec_ie_progress(unsigned char *p, Q931_info_t *qi, int *coding, int
 
 
 /* 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)
-#endif
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
-       if (type<0 || type>7)
-       {
+       if (type<0 || type>7) {
                PERROR("type(%d) is out of range.\n", type);
                return;
        }
-       if (plan<0 || plan>15)
-       {
+       if (plan<0 || plan>15) {
                PERROR("plan(%d) is out of range.\n", plan);
                return;
        }
-       if (present > 3)
-       {
+       if (present > 3) {
                PERROR("present(%d) is out of range.\n", present);
                return;
        }
-       if (present >= 0) if (screen<0 || screen>3)
-       {
+       if (present >= 0) if (screen<0 || screen>3) {
                PERROR("screen(%d) is out of range.\n", screen);
                return;
        }
-       if (reason > 0x0f)
-       {
+       if (reason > 0x0f) {
                PERROR("reason(%d) is out of range.\n", reason);
                return;
        }
@@ -1516,53 +1061,35 @@ void Pdss1::enc_ie_redir_nr(unsigned char **ntmode, msg_t *msg, int type, int pl
        l = 1;
        if (number)
                l += strlen((char *)number);
-       if (present >= 0)
-       {
+       if (present >= 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);
-#endif
        p[0] = IE_REDIR_NR;
        p[1] = l;
-       if (present >= 0)
-       {
-               if (reason >= 0)
-               {
+       if (present >= 0) {
+               if (reason >= 0) {
                        p[2] = 0x00 + (type<<4) + plan;
                        p[3] = 0x00 + (present<<5) + screen;
                        p[4] = 0x80 + reason;
                        if (number)
                                UNCPY((char *)p+5, (char *)number, strlen((char *)number));
-               } else
-               {
+               } else {
                        p[2] = 0x00 + (type<<4) + plan;
                        p[3] = 0x80 + (present<<5) + screen;
                        if (number)
                                UNCPY((char *)p+4, (char *)number, strlen((char *)number));
                }
-       } else
-       {
+       } else {
                p[2] = 0x80 + (type<<4) + plan;
                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)
-#endif
 {
        *type = -1;
        *plan = -1;
@@ -1571,40 +1098,26 @@ void Pdss1::dec_ie_redir_nr(unsigned char *p, Q931_info_t *qi, int *type, int *p
        *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;
-       }
-#else
-       unsigned char *p = l3m->redirect_nr;
-#endif
+       unsigned char *p = l3m->redirecting_nr;
        if (!p)
                return;
-       if (p[0] < 1)
-       {
+       if (p[0] < 1) {
                add_trace("redir'ing", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
        *type = (p[1]&0x70) >> 4;
        *plan = p[1] & 0xf;
-       if (!(p[1] & 0x80))
-       {
+       if (!(p[1] & 0x80)) {
                *present = (p[2]&0x60) >> 5;
                *screen = p[2] & 0x3;
-               if (!(p[2] & 0x80))
-               {
+               if (!(p[2] & 0x80)) {
                        *reason = p[3] & 0x0f;
                        strnncpy(number, p+4, p[0]-3, number_len);
-               } else
-               {
+               } else {
                        strnncpy(number, p+3, p[0]-2, number_len);
                }
-       } else
-       {
+       } else {
                strnncpy(number, p+2, p[0]-1, number_len);
        }
 
@@ -1618,32 +1131,20 @@ void Pdss1::dec_ie_redir_nr(unsigned char *p, Q931_info_t *qi, int *type, int *p
 
 
 /* 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)
-#endif
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
-       if (type<0 || type>7)
-       {
+       if (type<0 || type>7) {
                PERROR("type(%d) is out of range.\n", type);
                return;
        }
-       if (plan<0 || plan>15)
-       {
+       if (plan<0 || plan>15) {
                PERROR("plan(%d) is out of range.\n", plan);
                return;
        }
-       if (present > 3)
-       {
+       if (present > 3) {
                PERROR("present(%d) is out of range.\n", present);
                return;
        }
@@ -1658,69 +1159,42 @@ 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;
-#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);
-#endif
        p[0] = IE_REDIR_DN;
        p[1] = l;
-       if (present >= 0)
-       {
+       if (present >= 0) {
                p[2] = 0x00 + (type<<4) + plan;
                p[3] = 0x80 + (present<<5);
                if (number)
                        UNCPY((char *)p+4, (char *)number, strlen((char *)number));
-       } else
-       {
+       } else {
                p[2] = 0x80 + (type<<4) + plan;
                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)
-#endif
 {
        *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;
-       }
-#else
-       unsigned char *p = l3m->redirect_dn;
-#endif
+       unsigned char *p = l3m->redirection_nr;
        if (!p)
                return;
-       if (p[0] < 1)
-       {
+       if (p[0] < 1) {
                add_trace("redir'tion", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
        *type = (p[1]&0x70) >> 4;
        *plan = p[1] & 0xf;
-       if (!(p[1] & 0x80))
-       {
+       if (!(p[1] & 0x80)) {
                *present = (p[2]&0x60) >> 5;
                strnncpy(number, p+3, p[0]-2, number_len);
-       } else
-       {
+       } else {
                strnncpy(number, p+2, p[0]-1, number_len);
        }
 
@@ -1732,31 +1206,20 @@ void Pdss1::dec_ie_redir_dn(unsigned char *p, Q931_info_t *qi, int *type, int *p
 
 
 /* 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)
-#endif
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
        char buffer[768];
        int i;
 
-       if (!facility || facility_len<=0)
-       {
+       if (!facility || facility_len<=0) {
                return;
        }
 
        i = 0;
-       while(i < facility_len)
-       {
+       while(i < facility_len) {
                UPRINT(buffer+(i*3), " %02x", facility[i]);
                i++;
        }
@@ -1764,42 +1227,20 @@ void Pdss1::enc_ie_facility(unsigned char **ntmode, msg_t *msg, unsigned char *f
        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);
-#endif
        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)
-#endif
 {
        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;
-       }
-#else
        unsigned char *p = l3m->facility;
-#endif
        if (!p)
                return;
 
@@ -1807,8 +1248,7 @@ void Pdss1::dec_ie_facility(unsigned char *p, Q931_info_t *qi, unsigned char *fa
        memcpy(facility, p+1, *facility_len);
 
        i = 0;
-       while(i < *facility_len)
-       {
+       while(i < *facility_len) {
                UPRINT(debug+(i*3), " %02x", facility[i]);
                i++;
        }
@@ -1818,11 +1258,7 @@ 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)
-#endif
 {
        unsigned char centrex[256];
        char debug[768];
@@ -1830,13 +1266,8 @@ void Pdss1::dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned cha
        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);
-#endif
-       if (facility_len >= 2)
-       {
+       if (facility_len >= 2) {
                if (centrex[i++] != CENTREX_FAC)
                        return;
                if (centrex[i++] != CENTREX_ID)
@@ -1844,15 +1275,12 @@ void Pdss1::dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned cha
        }
 
        /* loop sub IEs of facility */
-       while(facility_len > i+1)
-       {
-               if (centrex[i+1]+i+1 > facility_len)
-               {
+       while(facility_len > i+1) {
+               if (centrex[i+1]+i+1 > facility_len) {
                        PERROR("short read of centrex facility.\n");
                        return;
                }
-               switch(centrex[i])
-               {
+               switch(centrex[i]) {
                        case 0x80:
                        strnncpy(cnip, &centrex[i+2], centrex[i+1], cnip_len);
                        add_trace("facility", "cnip", "%s", cnip);
@@ -1860,8 +1288,7 @@ void Pdss1::dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned cha
 
                        default:
                        j = 0;
-                       while(j < centrex[i+1])
-                       {
+                       while(j < centrex[i+1]) {
                                UPRINT(debug+(j*3), " %02x", centrex[i+1+j]);
                                i++;
                        }
@@ -1873,36 +1300,24 @@ void Pdss1::dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned cha
 
 
 /* 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)
-#endif
 {
-#ifdef SOCKET_MISDN
        unsigned char p[256];
-#else
-       unsigned char *p;
-       Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-#endif
        int l;
 
        char buffer[768];
        int i;
 
-       if (protocol<0 || protocol>127)
-       {
+       if (protocol<0 || protocol>127) {
                PERROR("protocol(%d) is out of range.\n", protocol);
                return;
        }
-       if (!user || user_len<=0)
-       {
+       if (!user || user_len<=0) {
                return;
        }
 
        i = 0;
-       while(i < user_len)
-       {
+       while(i < user_len) {
                UPRINT(buffer+(i*3), " %02x", user[i]);
                i++;
        }
@@ -1911,27 +1326,14 @@ void Pdss1::enc_ie_useruser(unsigned char **ntmode, msg_t *msg, int protocol, un
        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);
-#endif
        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)
-#endif
 {
        char buffer[768];
        int i;
@@ -1939,16 +1341,7 @@ void Pdss1::dec_ie_useruser(unsigned char *p, Q931_info_t *qi, int *protocol, un
        *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;
-       }
-#else
        unsigned char *p = l3m->useruser;
-#endif
        if (!p)
                return;
 
@@ -1959,8 +1352,7 @@ void Pdss1::dec_ie_useruser(unsigned char *p, Q931_info_t *qi, int *protocol, un
        memcpy(user, p+2, (*user_len<=128)?*(user_len):128); /* clip to 128 maximum */
 
        i = 0;
-       while(i < *user_len)
-       {
+       while(i < *user_len) {
                UPRINT(buffer+(i*3), " %02x", user[i]);
                i++;
        }