error inside information elements are now reported inside trace and main log,
[lcr.git] / ie.cpp
diff --git a/ie.cpp b/ie.cpp
index b27920f..1c70514 100644 (file)
--- a/ie.cpp
+++ b/ie.cpp
@@ -151,7 +151,7 @@ void Pdss1::dec_ie_bearer(unsigned char *p, Q931_info_t *qi, int *coding, int *c
                return;
        if (p[0] < 2)
        {
-               PERROR("IE too short (%d).\n", p[0]);
+               add_trace("bearer", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
@@ -257,7 +257,7 @@ void Pdss1::dec_ie_hlc(unsigned char *p, Q931_info_t *qi, int *coding, int *inte
                return;
        if (p[0] < 2)
        {
-               PERROR("IE too short (%d).\n", p[0]);
+               add_trace("hlc", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
@@ -336,7 +336,7 @@ void Pdss1::dec_ie_call_id(unsigned char *p, Q931_info_t *qi, unsigned char *cal
                return;
        if (p[0] > 8)
        {
-               PERROR("IE too long (%d).\n", p[0]);
+               add_trace("callid", "error", "IE too long (len=%d)", p[0]);
                return;
        }
 
@@ -409,7 +409,7 @@ void Pdss1::dec_ie_called_pn(unsigned char *p, Q931_info_t *qi, int *type, int *
                return;
        if (p[0] < 2)
        {
-               PERROR("IE too short (%d).\n", p[0]);
+               add_trace("called_pn", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
@@ -501,7 +501,7 @@ void Pdss1::dec_ie_calling_pn(unsigned char *p, Q931_info_t *qi, int *type, int
                return;
        if (p[0] < 1)
        {
-               PERROR("IE too short (%d).\n", p[0]);
+               add_trace("calling_pn", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
@@ -511,7 +511,7 @@ void Pdss1::dec_ie_calling_pn(unsigned char *p, Q931_info_t *qi, int *type, int
        {
                if (p[0] < 2)
                {
-                       PERROR("IE too short (%d).\n", p[0]);
+                       add_trace("calling_pn", "error", "IE too short (len=%d)", p[0]);
                        return;
                }
                *present = (p[2]&0x60) >> 5;
@@ -608,7 +608,7 @@ void Pdss1::dec_ie_connected_pn(unsigned char *p, Q931_info_t *qi, int *type, in
                return;
        if (p[0] < 1)
        {
-               PERROR("IE too short (%d).\n", p[0]);
+               add_trace("connect_pn", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
@@ -618,7 +618,7 @@ void Pdss1::dec_ie_connected_pn(unsigned char *p, Q931_info_t *qi, int *type, in
        {
                if (p[0] < 2)
                {
-                       PERROR("IE too short (%d).\n", p[0]);
+                       add_trace("connect_pn", "error", "IE too short (len=%d)", p[0]);
                        return;
                }
                *present = (p[2]&0x60) >> 5;
@@ -699,7 +699,7 @@ void Pdss1::dec_ie_cause(unsigned char *p, Q931_info_t *qi, int *location, int *
                return;
        if (p[0] < 2)
        {
-               PERROR("IE too short (%d).\n", p[0]);
+               add_trace("cause", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
@@ -734,7 +734,17 @@ void Pdss1::enc_ie_channel_id(unsigned char **ntmode, msg_t *msg, int exclusive,
        }
 
        add_trace("channel_id", "exclusive", "%d", exclusive);
-       add_trace("channel_id", "channel", "%d", channel);
+       switch(channel)
+       {
+               case CHANNEL_ANY:
+               add_trace("channel_id", "channel", "any channel");
+               break;
+               case CHANNEL_NO:
+               add_trace("channel_id", "channel", "no channel");
+               break;
+               default:
+               add_trace("channel_id", "channel", "%d", channel);
+       }
 
        if (!pri)
        {
@@ -801,18 +811,18 @@ void Pdss1::dec_ie_channel_id(unsigned char *p, Q931_info_t *qi, int *exclusive,
                return;
        if (p[0] < 1)
        {
-               PERROR("IE too short (%d).\n", p[0]);
+               add_trace("channel_id", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
        if (p[1] & 0x40)
        {
-               PERROR("refering to channels of other interfaces is not supported.\n");
+               add_trace("channel_id", "error", "refering to channels of other interfaces is not supported");
                return;
        }
        if (p[1] & 0x04)
        {
-               PERROR("using d-channel is not supported.\n");
+               add_trace("channel_id", "error", "using d-channel is not supported");
                return;
        }
 
@@ -822,7 +832,7 @@ void Pdss1::dec_ie_channel_id(unsigned char *p, Q931_info_t *qi, int *exclusive,
                /* BRI */
                if (p[1] & 0x20)
                {
-                       PERROR("extended channel ID with non PRI interface.\n");
+                       add_trace("channel_id", "error", "extended channel ID with non PRI interface");
                        return;
                }
                *channel = p[1] & 0x03;
@@ -835,12 +845,13 @@ void Pdss1::dec_ie_channel_id(unsigned char *p, Q931_info_t *qi, int *exclusive,
                /* PRI */
                if (p[0] < 1)
                {
-                       PERROR("IE too short for PRI (%d).\n", p[0]);
+
+                       add_trace("channel_id", "error", "IE too short for PRI (len=%d)", p[0]);
                        return;
                }
                if (!(p[1] & 0x20))
                {
-                       PERROR("basic channel ID with PRI interface.\n");
+                       add_trace("channel_id", "error", "basic channel ID with PRI interface");
                        return;
                }
                if ((p[1]&0x03) == 0x00)
@@ -857,24 +868,34 @@ void Pdss1::dec_ie_channel_id(unsigned char *p, Q931_info_t *qi, int *exclusive,
                }
                if (p[0] < 3)
                {
-                       PERROR("%s: ERROR: IE too short for PRI with channel(%d).\n", __FUNCTION__, p[0]);
+                       add_trace("channel_id", "error", "IE too short for PRI with channel (len=%d)", p[0]);
                        return;
                }
                if (p[2] & 0x10)
                {
-                       PERROR("channel map not supported.\n");
+                       add_trace("channel_id", "error", "channel map not supported");
                        return;
                }
                *channel = p[3] & 0x7f;
                if (*channel<1 | *channel==16)
                {
-                       PERROR("PRI interface channel out of range (%d).\n", *channel);
+                       add_trace("channel_id", "error", "PRI interface channel out of range (%d)", *channel);
                        return;
                }
        }
 
        add_trace("channel_id", "exclusive", "%d", *exclusive);
-       add_trace("channel_id", "channel", "%d", *channel);
+       switch(*channel)
+       {
+               case CHANNEL_ANY:
+               add_trace("channel_id", "channel", "any channel");
+               break;
+               case CHANNEL_NO:
+               add_trace("channel_id", "channel", "no channel");
+               break;
+               default:
+               add_trace("channel_id", "channel", "%d", *channel);
+       }
 }
 
 
@@ -961,7 +982,7 @@ void Pdss1::dec_ie_display(unsigned char *p, Q931_info_t *qi, unsigned char *dis
                return;
        if (p[0] < 1)
        {
-               PERROR("IE too short (%d).\n", p[0]);
+               add_trace("display", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
@@ -1011,7 +1032,7 @@ void Pdss1::dec_ie_keypad(unsigned char *p, Q931_info_t *qi, unsigned char *keyp
                return;
        if (p[0] < 1)
        {
-               PERROR("IE too short (%d).\n", p[0]);
+               add_trace("keypad", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
@@ -1061,7 +1082,7 @@ void Pdss1::dec_ie_notify(unsigned char *p, Q931_info_t *qi, int *notify)
                return;
        if (p[0] < 1)
        {
-               PERROR("IE too short (%d).\n", p[0]);
+               add_trace("notify", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
@@ -1126,7 +1147,7 @@ void Pdss1::dec_ie_progress(unsigned char *p, Q931_info_t *qi, int *coding, int
                return;
        if (p[0] < 1)
        {
-               PERROR("IE too short (%d).\n", p[0]);
+               add_trace("progress", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
@@ -1239,7 +1260,7 @@ void Pdss1::dec_ie_redir_nr(unsigned char *p, Q931_info_t *qi, int *type, int *p
                return;
        if (p[0] < 1)
        {
-               PERROR("IE too short (%d).\n", p[0]);
+               add_trace("redir'ing", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
@@ -1342,7 +1363,7 @@ void Pdss1::dec_ie_redir_dn(unsigned char *p, Q931_info_t *qi, int *type, int *p
                return;
        if (p[0] < 1)
        {
-               PERROR("IE too short (%d).\n", p[0]);
+               add_trace("redir'tion", "error", "IE too short (len=%d)", p[0]);
                return;
        }
 
@@ -1430,58 +1451,6 @@ void Pdss1::dec_ie_facility(unsigned char *p, Q931_info_t *qi, unsigned char *fa
 }
 
 
-/* facility for siemens CENTEX (known parts implemented only) */
-void Pdss1::enc_facility_centrex(unsigned char **ntmode, msg_t *msg, unsigned char *cnip, int setup)
-{
-       unsigned char centrex[256];
-       int i = 0;
-
-       if (!cnip)
-               return;
-
-       /* centrex facility */
-       centrex[i++] = CENTREX_FAC;
-       centrex[i++] = CENTREX_ID;
-
-       /* cnip */
-       if (strlen((char *)cnip) > 15)
-       {
-               PDEBUG(DEBUG_PORT, "%s: CNIP/CONP text too long (max 13 chars), cutting.\n");
-               cnip[15] = '\0';
-       }
-       // dunno what the 8 bytes mean
-       if (setup)
-       {
-               centrex[i++] = 0x17;
-               centrex[i++] = 0x02;
-               centrex[i++] = 0x02;
-               centrex[i++] = 0x44;
-               centrex[i++] = 0x18;
-               centrex[i++] = 0x02;
-               centrex[i++] = 0x01;
-               centrex[i++] = 0x09;
-       } else
-       {
-               centrex[i++] = 0x18;
-               centrex[i++] = 0x02;
-               centrex[i++] = 0x02;
-               centrex[i++] = 0x81;
-               centrex[i++] = 0x09;
-               centrex[i++] = 0x02;
-               centrex[i++] = 0x01;
-               centrex[i++] = 0x0a;
-       }
-
-       centrex[i++] = 0x80;
-       centrex[i++] = strlen((char *)cnip);
-       UCPY((char *)(&centrex[i]), (char *)cnip);
-       i += strlen((char *)cnip);
-       add_trace("facility", "cnip", "%s", cnip);
-
-       /* encode facility */
-       enc_ie_facility(ntmode, msg, centrex, i);
-}
-
 void Pdss1::dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned char *cnip, int cnip_len)
 {
        unsigned char centrex[256];
@@ -1521,7 +1490,7 @@ void Pdss1::dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned cha
                                UPRINT(debug+(j*3), " %02x", centrex[i+1+j]);
                                i++;
                        }
-                       add_trace("facility", "CENTREX", "unknown=0x%2x len=%d%s\n", centrex[i], centrex[i+1], debug);
+                       add_trace("facility", "CENTREX", "unknown=0x%02x len=%d%s\n", centrex[i], centrex[i+1], debug);
                }
                i += 1+centrex[i+1];
        }