2 /*****************************************************************************\
6 **---------------------------------------------------------------------------**
7 ** Copyright: Andreas Eversberg **
9 ** information elements encode and decode **
11 \*****************************************************************************/
14 the pointer of enc_ie_* always points to the IE itself
15 if qi is not NULL (TE-mode), offset is set
19 static void strnncpy(unsigned char *dest, unsigned char *src, int len, int dst_len)
23 UNCPY((char *)dest, (char *)src, len);
30 void Pdss1::enc_ie_complete(struct l3_msg *l3m, int complete)
32 void Pdss1::enc_ie_complete(unsigned char **ntmode, msg_t *msg, int complete)
37 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
40 if (complete<0 || complete>1)
42 PERROR("complete(%d) is out of range.\n", complete);
48 add_trace("complete", NULL, NULL);
55 qi->sending_complete.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
58 l3m->sending_complete++;
64 void Pdss1::dec_ie_complete(struct l3_msg *l3m, int *complete)
66 void Pdss1::dec_ie_complete(unsigned char *p, Q931_info_t *qi, int *complete)
73 if (qi->sending_complete.off)
77 unsigned char *p = l3m->sending_complete;
83 add_trace("complete", NULL, NULL);
89 void Pdss1::enc_ie_bearer(struct l3_msg *l3m, int coding, int capability, int mode, int rate, int multi, int user)
91 void Pdss1::enc_ie_bearer(unsigned char **ntmode, msg_t *msg, int coding, int capability, int mode, int rate, int multi, int user)
98 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
102 if (coding<0 || coding>3)
104 PERROR("coding(%d) is out of range.\n", coding);
107 if (capability<0 || capability>31)
109 PERROR("capability(%d) is out of range.\n", capability);
112 if (mode<0 || mode>3)
114 PERROR("mode(%d) is out of range.\n", mode);
117 if (rate<0 || rate>31)
119 PERROR("rate(%d) is out of range.\n", rate);
124 PERROR("multi(%d) is out of range.\n", multi);
129 PERROR("user L1(%d) is out of range.\n", user);
132 if (rate!=24 && multi>=0)
134 PERROR("multi(%d) is only possible if rate(%d) would be 24.\n", multi, rate);
138 add_trace("bearer", "coding", "%d", coding);
139 add_trace("bearer", "capability", "%d", capability);
140 add_trace("bearer", "mode", "%d", mode);
141 add_trace("bearer", "rate", "%d", rate);
142 add_trace("bearer", "multi", "%d", multi);
143 add_trace("bearer", "user", "%d", user);
145 l = 2 + (multi>=0) + (user>=0);
147 p = msg_put(msg, l+2);
151 qi->bearer_capability.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
155 p[2] = 0x80 + (coding<<5) + capability;
156 p[3] = 0x80 + (mode<<5) + rate;
160 p[4+(multi>=0)] = 0xa0 + user;
162 add_layer3_ie(l3m, p[0], p[1], p+2);
167 void Pdss1::dec_ie_bearer(struct l3_msg *l3m, int *coding, int *capability, int *mode, int *rate, int *multi, int *user)
169 void Pdss1::dec_ie_bearer(unsigned char *p, Q931_info_t *qi, int *coding, int *capability, int *mode, int *rate, int *multi, int *user)
183 if (qi->bearer_capability.off)
184 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->bearer_capability.off + 1;
187 unsigned char *p = l3m->bearer_capability;
193 add_trace("bearer", "error", "IE too short (len=%d)", p[0]);
197 *coding = (p[1]&0x60) >> 5;
198 *capability = p[1] & 0x1f;
201 *mode = (p[2]&0x60) >> 5;
204 if (p[0]>=3 && *rate==0x18)
206 *multi = p[3] & 0x7f;
215 add_trace("bearer", "coding", "%d", *coding);
216 add_trace("bearer", "capability", "%d", *capability);
217 add_trace("bearer", "mode", "%d", *mode);
218 add_trace("bearer", "rate", "%d", *rate);
219 add_trace("bearer", "multi", "%d", *multi);
220 add_trace("bearer", "user", "%d", *user);
226 void Pdss1::enc_ie_hlc(struct l3_msg *l3m, int coding, int interpretation, int presentation, int hlc, int exthlc)
228 void Pdss1::enc_ie_hlc(unsigned char **ntmode, msg_t *msg, int coding, int interpretation, int presentation, int hlc, int exthlc)
232 unsigned char p[256];
235 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
239 if (coding<0 || coding>3)
241 PERROR("coding(%d) is out of range.\n", coding);
244 if (interpretation<0 || interpretation>7)
246 PERROR("interpretation(%d) is out of range.\n", interpretation);
249 if (presentation<0 || presentation>3)
251 PERROR("presentation(%d) is out of range.\n", presentation);
254 if (hlc<0 || hlc>127)
256 PERROR("hlc(%d) is out of range.\n", hlc);
261 PERROR("hlc(%d) is out of range.\n", exthlc);
265 add_trace("hlc", "coding", "%d", coding);
266 add_trace("hlc", "interpretation", "%d", interpretation);
267 add_trace("hlc", "presentation", "%d", presentation);
268 add_trace("hlc", "hlc", "%d", hlc);
270 add_trace("hlc", "exthlc", "%d", exthlc);
274 p = msg_put(msg, l+2);
278 qi->hlc.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
282 p[2] = 0x80 + (coding<<5) + (interpretation<<2) + presentation;
286 p[4] = 0x80 + exthlc;
290 add_layer3_ie(l3m, p[0], p[1], p+2);
295 void Pdss1::dec_ie_hlc(struct l3_msg *l3m, int *coding, int *interpretation, int *presentation, int *hlc, int *exthlc)
297 void Pdss1::dec_ie_hlc(unsigned char *p, Q931_info_t *qi, int *coding, int *interpretation, int *presentation, int *hlc, int *exthlc)
301 *interpretation = -1;
311 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->hlc.off + 1;
314 unsigned char *p = l3m->hlc;
320 add_trace("hlc", "error", "IE too short (len=%d)", p[0]);
324 *coding = (p[1]&0x60) >> 5;
325 *interpretation = (p[1]&0x1c) >> 2;
326 *presentation = p[1] & 0x03;
330 *exthlc = p[3] & 0x7f;
333 add_trace("hlc", "coding", "%d", *coding);
334 add_trace("hlc", "interpretation", "%d", *interpretation);
335 add_trace("hlc", "presentation", "%d", *presentation);
336 add_trace("hlc", "hlc", "%d", *hlc);
338 add_trace("hlc", "exthlc", "%d", *exthlc);
344 void Pdss1::enc_ie_call_id(struct l3_msg *l3m, unsigned char *callid, int callid_len)
346 void Pdss1::enc_ie_call_id(unsigned char **ntmode, msg_t *msg, unsigned char *callid, int callid_len)
350 unsigned char p[256];
353 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
360 if (!callid || callid_len<=0)
366 PERROR("callid_len(%d) is out of range.\n", callid_len);
371 while(i < callid_len)
373 UPRINT(buffer+(i*3), " %02x", callid[i]);
377 add_trace("callid", NULL, "%s", buffer[0]?buffer+1:"<none>");
381 p = msg_put(msg, l+2);
385 qi->call_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
389 memcpy(p+2, callid, callid_len);
391 add_layer3_ie(l3m, p[0], p[1], p+2);
396 void Pdss1::dec_ie_call_id(struct l3_msg *l3m, unsigned char *callid, int *callid_len)
398 void Pdss1::dec_ie_call_id(unsigned char *p, Q931_info_t *qi, unsigned char *callid, int *callid_len)
411 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->call_id.off + 1;
414 unsigned char *p = l3m->call_id;
420 add_trace("callid", "error", "IE too long (len=%d)", p[0]);
425 memcpy(callid, p+1, *callid_len);
428 while(i < *callid_len)
430 UPRINT(buffer+(i*3), " %02x", callid[i]);
434 add_trace("callid", NULL, "%s", buffer[0]?buffer+1:"<none>");
440 void Pdss1::enc_ie_called_pn(struct l3_msg *l3m, int type, int plan, unsigned char *number)
442 void Pdss1::enc_ie_called_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, unsigned char *number)
446 unsigned char p[256];
449 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
453 if (type<0 || type>7)
455 PERROR("type(%d) is out of range.\n", type);
458 if (plan<0 || plan>15)
460 PERROR("plan(%d) is out of range.\n", plan);
465 PERROR("number is not given.\n");
469 add_trace("called_pn", "type", "%d", type);
470 add_trace("called_pn", "plan", "%d", plan);
471 add_trace("called_pn", "number", "%s", number);
473 l = 1+strlen((char *)number);
475 p = msg_put(msg, l+2);
479 qi->called_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
483 p[2] = 0x80 + (type<<4) + plan;
484 UNCPY((char *)p+3, (char *)number, strlen((char *)number));
486 add_layer3_ie(l3m, p[0], p[1], p+2);
491 void Pdss1::dec_ie_called_pn(struct l3_msg *l3m, int *type, int *plan, unsigned char *number, int number_len)
493 void Pdss1::dec_ie_called_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, unsigned char *number, int number_len)
504 if (qi->called_nr.off)
505 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->called_nr.off + 1;
508 unsigned char *p = l3m->called_nr;
514 add_trace("called_pn", "error", "IE too short (len=%d)", p[0]);
518 *type = (p[1]&0x70) >> 4;
520 strnncpy(number, p+2, p[0]-1, number_len);
522 add_trace("called_pn", "type", "%d", *type);
523 add_trace("called_pn", "plan", "%d", *plan);
524 add_trace("called_pn", "number", "%s", number);
530 void Pdss1::enc_ie_calling_pn(struct l3_msg *l3m, int type, int plan, int present, int screen, unsigned char *number)
532 void Pdss1::enc_ie_calling_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, unsigned char *number)
536 unsigned char p[256];
539 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
543 if (type<0 || type>7)
545 PERROR("type(%d) is out of range.\n", type);
548 if (plan<0 || plan>15)
550 PERROR("plan(%d) is out of range.\n", plan);
555 PERROR("present(%d) is out of range.\n", present);
558 if (present >= 0) if (screen<0 || screen>3)
560 PERROR("screen(%d) is out of range.\n", screen);
564 add_trace("calling_pn", "type", "%d", type);
565 add_trace("calling_pn", "plan", "%d", plan);
566 add_trace("calling_pn", "present", "%d", present);
567 add_trace("calling_pn", "screen", "%d", screen);
568 add_trace("calling_pn", "number", "%s", number);
571 if (number) if (number[0])
572 l += strlen((char *)number);
576 p = msg_put(msg, l+2);
580 qi->calling_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
582 p[0] = IE_CALLING_PN;
586 p[2] = 0x00 + (type<<4) + plan;
587 p[3] = 0x80 + (present<<5) + screen;
588 if (number) if (number[0])
589 UNCPY((char *)p+4, (char *)number, strlen((char *)number));
592 p[2] = 0x80 + (type<<4) + plan;
593 if (number) if (number[0])
594 UNCPY((char *)p+3, (char *)number, strlen((char *)number));
597 add_layer3_ie(l3m, p[0], p[1], p+2);
602 void Pdss1::dec_ie_calling_pn(struct l3_msg *l3m, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len)
604 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)
617 if (qi->calling_nr.off)
618 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->calling_nr.off + 1;
621 unsigned char *p = l3m->calling_nr;
627 add_trace("calling_pn", "error", "IE too short (len=%d)", p[0]);
631 *type = (p[1]&0x70) >> 4;
637 add_trace("calling_pn", "error", "IE too short (len=%d)", p[0]);
640 *present = (p[2]&0x60) >> 5;
641 *screen = p[2] & 0x3;
642 strnncpy(number, p+3, p[0]-2, number_len);
645 strnncpy(number, p+2, p[0]-1, number_len);
648 add_trace("calling_pn", "type", "%d", *type);
649 add_trace("calling_pn", "plan", "%d", *plan);
650 add_trace("calling_pn", "present", "%d", *present);
651 add_trace("calling_pn", "screen", "%d", *screen);
652 add_trace("calling_pn", "number", "%s", number);
656 /* IE_CONNECTED_PN */
658 void Pdss1::enc_ie_connected_pn(struct l3_msg *l3m, int type, int plan, int present, int screen, unsigned char *number)
660 void Pdss1::enc_ie_connected_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, unsigned char *number)
664 unsigned char p[256];
667 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
671 if (type<0 || type>7)
673 PERROR("type(%d) is out of range.\n", type);
676 if (plan<0 || plan>15)
678 PERROR("plan(%d) is out of range.\n", plan);
683 PERROR("present(%d) is out of range.\n", present);
686 if (present >= 0) if (screen<0 || screen>3)
688 PERROR("screen(%d) is out of range.\n", screen);
692 add_trace("connect_pn", "type", "%d", type);
693 add_trace("connect_pn", "plan", "%d", plan);
694 add_trace("connect_pn", "present", "%d", present);
695 add_trace("connect_pn", "screen", "%d", screen);
696 add_trace("connect_pn", "number", "%s", number);
699 if (number) if (number[0])
700 l += strlen((char *)number);
704 p = msg_put(msg, l+2);
708 qi->connected_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
710 p[0] = IE_CONNECT_PN;
714 p[2] = 0x00 + (type<<4) + plan;
715 p[3] = 0x80 + (present<<5) + screen;
716 if (number) if (number[0])
717 UNCPY((char *)p+4, (char *)number, strlen((char *)number));
720 p[2] = 0x80 + (type<<4) + plan;
721 if (number) if (number[0])
722 UNCPY((char *)p+3, (char *)number, strlen((char *)number));
725 add_layer3_ie(l3m, p[0], p[1], p+2);
730 void Pdss1::dec_ie_connected_pn(struct l3_msg *l3m, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len)
732 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)
745 if (qi->connected_nr.off)
746 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->connected_nr.off + 1;
749 unsigned char *p = l3m->connected_nr;
755 add_trace("connect_pn", "error", "IE too short (len=%d)", p[0]);
759 *type = (p[1]&0x70) >> 4;
765 add_trace("connect_pn", "error", "IE too short (len=%d)", p[0]);
768 *present = (p[2]&0x60) >> 5;
769 *screen = p[2] & 0x3;
770 strnncpy(number, p+3, p[0]-2, number_len);
773 strnncpy(number, p+2, p[0]-1, number_len);
776 add_trace("connect_pn", "type", "%d", *type);
777 add_trace("connect_pn", "plan", "%d", *plan);
778 add_trace("connect_pn", "present", "%d", *present);
779 add_trace("connect_pn", "screen", "%d", *screen);
780 add_trace("connect_pn", "number", "%s", number);
786 void Pdss1::enc_ie_cause(struct l3_msg *l3m, int location, int cause)
788 void Pdss1::enc_ie_cause(unsigned char **ntmode, msg_t *msg, int location, int cause)
792 unsigned char p[256];
795 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
799 if (location<0 || location>7)
801 PERROR("location(%d) is out of range.\n", location);
804 if (cause<0 || cause>127)
806 PERROR("cause(%d) is out of range.\n", cause);
810 add_trace("cause", "location", "%d", location);
811 add_trace("cause", "value", "%d", cause);
815 p = msg_put(msg, l+2);
819 qi->cause.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
823 p[2] = 0x80 + location;
826 add_layer3_ie(l3m, p[0], p[1], p+2);
830 void enc_ie_cause_standalone(struct l3_msg *l3m, int location, int cause)
832 void enc_ie_cause_standalone(unsigned char **ntmode, msg_t *msg, int location, int cause)
836 unsigned char p[256];
838 unsigned char *p = msg_put(msg, 4);
839 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
843 qi->cause.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
847 p[2] = 0x80 + location;
850 add_layer3_ie(l3m, p[0], p[1], p+2);
856 void Pdss1::dec_ie_cause(struct l3_msg *l3m, int *location, int *cause)
858 void Pdss1::dec_ie_cause(unsigned char *p, Q931_info_t *qi, int *location, int *cause)
869 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->cause.off + 1;
872 unsigned char *p = l3m->cause;
878 add_trace("cause", "error", "IE too short (len=%d)", p[0]);
882 *location = p[1] & 0x0f;
883 *cause = p[2] & 0x7f;
885 add_trace("cause", "location", "%d", *location);
886 add_trace("cause", "value", "%d", *cause);
892 void Pdss1::enc_ie_channel_id(struct l3_msg *l3m, int exclusive, int channel)
894 void Pdss1::enc_ie_channel_id(unsigned char **ntmode, msg_t *msg, int exclusive, int channel)
898 unsigned char p[256];
901 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
904 int pri = p_m_mISDNport->pri;
906 if (exclusive<0 || exclusive>1)
908 PERROR("exclusive(%d) is out of range.\n", exclusive);
911 if ((channel<=0 && channel!=CHANNEL_NO && channel!=CHANNEL_ANY)
912 || (!pri && channel>2)
913 || (pri && channel>127)
914 || (pri && channel==16))
916 PERROR("channel(%d) is out of range.\n", channel);
920 add_trace("channel_id", "exclusive", "%d", exclusive);
924 add_trace("channel_id", "channel", "any channel");
927 add_trace("channel_id", "channel", "no channel");
930 add_trace("channel_id", "channel", "%d", channel);
938 p = msg_put(msg, l+2);
942 qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
944 p[0] = IE_CHANNEL_ID;
946 if (channel == CHANNEL_NO)
948 else if (channel == CHANNEL_ANY)
950 p[2] = 0x80 + (exclusive<<3) + channel;
952 add_layer3_ie(l3m, p[0], p[1], p+2);
957 if (channel == CHANNEL_NO) /* no channel */
958 return; /* IE not present */
959 if (channel == CHANNEL_ANY) /* any channel */
963 p = msg_put(msg, l+2);
967 qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
969 p[0] = IE_CHANNEL_ID;
971 p[2] = 0x80 + 0x20 + 0x03;
973 add_layer3_ie(l3m, p[0], p[1], p+2);
979 p = msg_put(msg, l+2);
983 qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
985 p[0] = IE_CHANNEL_ID;
987 p[2] = 0x80 + 0x20 + (exclusive<<3) + 0x01;
988 p[3] = 0x80 + 3; /* CCITT, Number, B-type */
989 p[4] = 0x80 + channel;
991 add_layer3_ie(l3m, p[0], p[1], p+2);
997 void Pdss1::dec_ie_channel_id(struct l3_msg *l3m, int *exclusive, int *channel)
999 void Pdss1::dec_ie_channel_id(unsigned char *p, Q931_info_t *qi, int *exclusive, int *channel)
1002 int pri = p_m_mISDNport->pri;
1007 #ifndef SOCKET_MISDN
1011 if (qi->channel_id.off)
1012 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->channel_id.off + 1;
1015 unsigned char *p = l3m->channel_id;
1021 add_trace("channel_id", "error", "IE too short (len=%d)", p[0]);
1027 add_trace("channel_id", "error", "refering to channels of other interfaces is not supported");
1032 add_trace("channel_id", "error", "using d-channel is not supported");
1036 *exclusive = (p[1]&0x08) >> 3;
1042 add_trace("channel_id", "error", "extended channel ID with non PRI interface");
1045 *channel = p[1] & 0x03;
1047 *channel = CHANNEL_ANY;
1048 else if (*channel == 0)
1049 *channel = CHANNEL_NO;
1056 add_trace("channel_id", "error", "IE too short for PRI (len=%d)", p[0]);
1061 add_trace("channel_id", "error", "basic channel ID with PRI interface");
1064 if ((p[1]&0x03) == 0x00)
1067 *channel = CHANNEL_NO;
1070 if ((p[1]&0x03) == 0x03)
1073 *channel = CHANNEL_ANY;
1078 add_trace("channel_id", "error", "IE too short for PRI with channel (len=%d)", p[0]);
1083 add_trace("channel_id", "error", "channel map not supported");
1086 *channel = p[3] & 0x7f;
1087 if (*channel<1 | *channel==16)
1089 add_trace("channel_id", "error", "PRI interface channel out of range (%d)", *channel);
1094 add_trace("channel_id", "exclusive", "%d", *exclusive);
1098 add_trace("channel_id", "channel", "any channel");
1101 add_trace("channel_id", "channel", "no channel");
1104 add_trace("channel_id", "channel", "%d", *channel);
1111 void Pdss1::enc_ie_date(struct l3_msg *l3m, time_t ti, int no_seconds)
1113 void Pdss1::enc_ie_date(unsigned char **ntmode, msg_t *msg, time_t ti, int no_seconds)
1117 unsigned char p[256];
1120 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1126 tm = localtime(&ti);
1129 PERROR("localtime() returned NULL.\n");
1133 add_trace("date", "day", "%d.%d.%d", tm->tm_mday, tm->tm_mon+1, tm->tm_year%100);
1134 add_trace("date", "time", "%d:%d:%d", tm->tm_hour, tm->tm_min, tm->tm_sec);
1136 l = 5 + (!no_seconds);
1137 #ifndef SOCKET_MISDN
1138 p = msg_put(msg, l+2);
1142 qi->date.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1146 p[2] = tm->tm_year % 100;
1147 p[3] = tm->tm_mon + 1;
1154 add_layer3_ie(l3m, p[0], p[1], p+2);
1161 void Pdss1::enc_ie_display(struct l3_msg *l3m, unsigned char *display)
1163 void Pdss1::enc_ie_display(unsigned char **ntmode, msg_t *msg, unsigned char *display)
1167 unsigned char p[256];
1170 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1176 PERROR("display text not given.\n");
1180 if (strlen((char *)display) > 80)
1182 PERROR("display text too long (max 80 chars), cutting.\n");
1186 add_trace("display", NULL, "%s", display);
1188 l = strlen((char *)display);
1189 #ifndef SOCKET_MISDN
1190 p = msg_put(msg, l+2);
1194 qi->display.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1198 UNCPY((char *)p+2, (char *)display, strlen((char *)display));
1200 add_layer3_ie(l3m, p[0], p[1], p+2);
1205 void Pdss1::dec_ie_display(struct l3_msg *l3m, unsigned char *display, int display_len)
1207 void Pdss1::dec_ie_display(unsigned char *p, Q931_info_t *qi, unsigned char *display, int display_len)
1212 #ifndef SOCKET_MISDN
1216 if (qi->display.off)
1217 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->display.off + 1;
1220 unsigned char *p = l3m->display;
1226 add_trace("display", "error", "IE too short (len=%d)", p[0]);
1230 strnncpy(display, p+1, p[0], display_len);
1232 add_trace("display", NULL, "%s", display);
1238 void Pdss1::enc_ie_keypad(struct l3_msg *l3m, unsigned char *keypad)
1240 void Pdss1::enc_ie_keypad(unsigned char **ntmode, msg_t *msg, unsigned char *keypad)
1244 unsigned char p[256];
1247 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1253 PERROR("keypad info not given.\n");
1257 add_trace("keypad", NULL, "%s", keypad);
1259 l = strlen((char *)keypad);
1260 #ifndef SOCKET_MISDN
1261 p = msg_put(msg, l+2);
1265 qi->keypad.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1269 UNCPY((char *)p+2, (char *)keypad, strlen((char *)keypad));
1271 add_layer3_ie(l3m, p[0], p[1], p+2);
1276 void Pdss1::dec_ie_keypad(struct l3_msg *l3m, unsigned char *keypad, int keypad_len)
1278 void Pdss1::dec_ie_keypad(unsigned char *p, Q931_info_t *qi, unsigned char *keypad, int keypad_len)
1283 #ifndef SOCKET_MISDN
1288 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->keypad.off + 1;
1291 unsigned char *p = l3m->keypad;
1297 add_trace("keypad", "error", "IE too short (len=%d)", p[0]);
1301 strnncpy(keypad, p+1, p[0], keypad_len);
1303 add_trace("keypad", NULL, "%s", keypad);
1309 void Pdss1::enc_ie_notify(struct l3_msg *l3m, int notify)
1311 void Pdss1::enc_ie_notify(unsigned char **ntmode, msg_t *msg, int notify)
1315 unsigned char p[256];
1318 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1322 if (notify<0 || notify>0x7f)
1324 PERROR("notify(%d) is out of range.\n", notify);
1328 add_trace("notify", NULL, "%d", notify);
1331 #ifndef SOCKET_MISDN
1332 p = msg_put(msg, l+2);
1336 qi->notify.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1340 p[2] = 0x80 + notify;
1342 add_layer3_ie(l3m, p[0], p[1], p+2);
1347 void Pdss1::dec_ie_notify(struct l3_msg *l3m, int *notify)
1349 void Pdss1::dec_ie_notify(unsigned char *p, Q931_info_t *qi, int *notify)
1354 #ifndef SOCKET_MISDN
1359 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->notify.off + 1;
1362 unsigned char *p = l3m->notify;
1368 add_trace("notify", "error", "IE too short (len=%d)", p[0]);
1372 *notify = p[1] & 0x7f;
1374 add_trace("notify", NULL, "%d", *notify);
1380 void Pdss1::enc_ie_progress(struct l3_msg *l3m, int coding, int location, int progress)
1382 void Pdss1::enc_ie_progress(unsigned char **ntmode, msg_t *msg, int coding, int location, int progress)
1386 unsigned char p[256];
1389 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1393 if (coding<0 || coding>0x03)
1395 PERROR("coding(%d) is out of range.\n", coding);
1398 if (location<0 || location>0x0f)
1400 PERROR("location(%d) is out of range.\n", location);
1403 if (progress<0 || progress>0x7f)
1405 PERROR("progress(%d) is out of range.\n", progress);
1409 add_trace("progress", "codeing", "%d", coding);
1410 add_trace("progress", "location", "%d", location);
1411 add_trace("progress", "indicator", "%d", progress);
1414 #ifndef SOCKET_MISDN
1415 p = msg_put(msg, l+2);
1419 qi->progress.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1423 p[2] = 0x80 + (coding<<5) + location;
1424 p[3] = 0x80 + progress;
1426 add_layer3_ie(l3m, p[0], p[1], p+2);
1431 void Pdss1::dec_ie_progress(struct l3_msg *l3m, int *coding, int *location, int *progress)
1433 void Pdss1::dec_ie_progress(unsigned char *p, Q931_info_t *qi, int *coding, int *location, int *progress)
1440 #ifndef SOCKET_MISDN
1444 if (qi->progress.off)
1445 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->progress.off + 1;
1448 unsigned char *p = l3m->progress;
1454 add_trace("progress", "error", "IE too short (len=%d)", p[0]);
1458 *coding = (p[1]&0x60) >> 5;
1459 *location = p[1] & 0x0f;
1460 *progress = p[2] & 0x7f;
1462 add_trace("progress", "codeing", "%d", *coding);
1463 add_trace("progress", "location", "%d", *location);
1464 add_trace("progress", "indicator", "%d", *progress);
1468 /* IE_REDIR_NR (redirecting = during MT_SETUP) */
1470 void Pdss1::enc_ie_redir_nr(struct l3_msg *l3m, int type, int plan, int present, int screen, int reason, unsigned char *number)
1472 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)
1476 unsigned char p[256];
1479 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1483 if (type<0 || type>7)
1485 PERROR("type(%d) is out of range.\n", type);
1488 if (plan<0 || plan>15)
1490 PERROR("plan(%d) is out of range.\n", plan);
1495 PERROR("present(%d) is out of range.\n", present);
1498 if (present >= 0) if (screen<0 || screen>3)
1500 PERROR("screen(%d) is out of range.\n", screen);
1505 PERROR("reason(%d) is out of range.\n", reason);
1509 add_trace("redir'ing", "type", "%d", type);
1510 add_trace("redir'ing", "plan", "%d", plan);
1511 add_trace("redir'ing", "present", "%d", present);
1512 add_trace("redir'ing", "screen", "%d", screen);
1513 add_trace("redir'ing", "reason", "%d", reason);
1514 add_trace("redir'ing", "number", "%s", number);
1518 l += strlen((char *)number);
1525 #ifndef SOCKET_MISDN
1526 p = msg_put(msg, l+2);
1530 qi->redirect_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1538 p[2] = 0x00 + (type<<4) + plan;
1539 p[3] = 0x00 + (present<<5) + screen;
1540 p[4] = 0x80 + reason;
1542 UNCPY((char *)p+5, (char *)number, strlen((char *)number));
1545 p[2] = 0x00 + (type<<4) + plan;
1546 p[3] = 0x80 + (present<<5) + screen;
1548 UNCPY((char *)p+4, (char *)number, strlen((char *)number));
1552 p[2] = 0x80 + (type<<4) + plan;
1553 if (number) if (number[0])
1554 UNCPY((char *)p+3, (char *)number, strlen((char *)number));
1557 add_layer3_ie(l3m, p[0], p[1], p+2);
1562 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)
1564 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)
1574 #ifndef SOCKET_MISDN
1578 if (qi->redirect_nr.off)
1579 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redirect_nr.off + 1;
1582 unsigned char *p = l3m->redirect_nr;
1588 add_trace("redir'ing", "error", "IE too short (len=%d)", p[0]);
1592 *type = (p[1]&0x70) >> 4;
1596 *present = (p[2]&0x60) >> 5;
1597 *screen = p[2] & 0x3;
1600 *reason = p[3] & 0x0f;
1601 strnncpy(number, p+4, p[0]-3, number_len);
1604 strnncpy(number, p+3, p[0]-2, number_len);
1608 strnncpy(number, p+2, p[0]-1, number_len);
1611 add_trace("redir'ing", "type", "%d", *type);
1612 add_trace("redir'ing", "plan", "%d", *plan);
1613 add_trace("redir'ing", "present", "%d", *present);
1614 add_trace("redir'ing", "screen", "%d", *screen);
1615 add_trace("redir'ing", "reason", "%d", *reason);
1616 add_trace("redir'ing", "number", "%s", number);
1620 /* IE_REDIR_DN (redirection = during MT_NOTIFY) */
1622 void Pdss1::enc_ie_redir_dn(struct l3_msg *l3m, int type, int plan, int present, unsigned char *number)
1624 void Pdss1::enc_ie_redir_dn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, unsigned char *number)
1628 unsigned char p[256];
1631 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1635 if (type<0 || type>7)
1637 PERROR("type(%d) is out of range.\n", type);
1640 if (plan<0 || plan>15)
1642 PERROR("plan(%d) is out of range.\n", plan);
1647 PERROR("present(%d) is out of range.\n", present);
1651 add_trace("redir'tion", "type", "%d", type);
1652 add_trace("redir'tion", "plan", "%d", plan);
1653 add_trace("redir'tion", "present", "%d", present);
1654 add_trace("redir'tion", "number", "%s", number);
1658 l += strlen((char *)number);
1661 #ifndef SOCKET_MISDN
1662 p = msg_put(msg, l+2);
1666 qi->redirect_dn.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1672 p[2] = 0x00 + (type<<4) + plan;
1673 p[3] = 0x80 + (present<<5);
1675 UNCPY((char *)p+4, (char *)number, strlen((char *)number));
1678 p[2] = 0x80 + (type<<4) + plan;
1680 UNCPY((char *)p+3, (char *)number, strlen((char *)number));
1683 add_layer3_ie(l3m, p[0], p[1], p+2);
1688 void Pdss1::dec_ie_redir_dn(struct l3_msg *l3m, int *type, int *plan, int *present, unsigned char *number, int number_len)
1690 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)
1698 #ifndef SOCKET_MISDN
1702 if (qi->redirect_dn.off)
1703 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redirect_dn.off + 1;
1706 unsigned char *p = l3m->redirect_dn;
1712 add_trace("redir'tion", "error", "IE too short (len=%d)", p[0]);
1716 *type = (p[1]&0x70) >> 4;
1720 *present = (p[2]&0x60) >> 5;
1721 strnncpy(number, p+3, p[0]-2, number_len);
1724 strnncpy(number, p+2, p[0]-1, number_len);
1727 add_trace("redir'tion", "type", "%d", *type);
1728 add_trace("redir'tion", "plan", "%d", *plan);
1729 add_trace("redir'tion", "present", "%d", *present);
1730 add_trace("redir'tion", "number", "%s", number);
1736 void Pdss1::enc_ie_facility(struct l3_msg *l3m, unsigned char *facility, int facility_len)
1738 void Pdss1::enc_ie_facility(unsigned char **ntmode, msg_t *msg, unsigned char *facility, int facility_len)
1742 unsigned char p[256];
1745 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1752 if (!facility || facility_len<=0)
1758 while(i < facility_len)
1760 UPRINT(buffer+(i*3), " %02x", facility[i]);
1764 add_trace("facility", NULL, "%s", buffer+1);
1767 #ifndef SOCKET_MISDN
1768 p = msg_put(msg, l+2);
1772 qi->facility.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1776 memcpy(p+2, facility, facility_len);
1778 add_layer3_ie(l3m, p[0], p[1], p+2);
1783 void Pdss1::dec_ie_facility(struct l3_msg *l3m, unsigned char *facility, int *facility_len)
1785 void Pdss1::dec_ie_facility(unsigned char *p, Q931_info_t *qi, unsigned char *facility, int *facility_len)
1793 #ifndef SOCKET_MISDN
1797 if (qi->facility.off)
1798 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->facility.off + 1;
1801 unsigned char *p = l3m->facility;
1806 *facility_len = p[0];
1807 memcpy(facility, p+1, *facility_len);
1810 while(i < *facility_len)
1812 UPRINT(debug+(i*3), " %02x", facility[i]);
1817 add_trace("facility", NULL, "%s", debug[0]?debug+1:"<none>");
1822 void Pdss1::dec_facility_centrex(struct l3_msg *l3m, unsigned char *cnip, int cnip_len)
1824 void Pdss1::dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned char *cnip, int cnip_len)
1827 unsigned char centrex[256];
1829 int facility_len = 0;
1834 dec_ie_facility(l3m, centrex, &facility_len);
1836 dec_ie_facility(p, qi, centrex, &facility_len);
1838 if (facility_len >= 2)
1840 if (centrex[i++] != CENTREX_FAC)
1842 if (centrex[i++] != CENTREX_ID)
1846 /* loop sub IEs of facility */
1847 while(facility_len > i+1)
1849 if (centrex[i+1]+i+1 > facility_len)
1851 PERROR("short read of centrex facility.\n");
1857 strnncpy(cnip, ¢rex[i+2], centrex[i+1], cnip_len);
1858 add_trace("facility", "cnip", "%s", cnip);
1863 while(j < centrex[i+1])
1865 UPRINT(debug+(j*3), " %02x", centrex[i+1+j]);
1868 add_trace("facility", "CENTREX", "unknown=0x%02x len=%d%s\n", centrex[i], centrex[i+1], debug);
1870 i += 1+centrex[i+1];
1877 void Pdss1::enc_ie_useruser(struct l3_msg *l3m, int protocol, unsigned char *user, int user_len)
1879 void Pdss1::enc_ie_useruser(unsigned char **ntmode, msg_t *msg, int protocol, unsigned char *user, int user_len)
1883 unsigned char p[256];
1886 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1893 if (protocol<0 || protocol>127)
1895 PERROR("protocol(%d) is out of range.\n", protocol);
1898 if (!user || user_len<=0)
1906 UPRINT(buffer+(i*3), " %02x", user[i]);
1910 add_trace("useruser", "protocol", "%d", protocol);
1911 add_trace("useruser", "value", "%s", buffer);
1914 #ifndef SOCKET_MISDN
1915 p = msg_put(msg, l+3);
1919 qi->useruser.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1921 p[0] = IE_USER_USER;
1923 p[2] = 0x80 + protocol;
1924 memcpy(p+3, user, user_len);
1926 add_layer3_ie(l3m, p[0], p[1], p+2);
1931 void Pdss1::dec_ie_useruser(struct l3_msg *l3m, int *protocol, unsigned char *user, int *user_len)
1933 void Pdss1::dec_ie_useruser(unsigned char *p, Q931_info_t *qi, int *protocol, unsigned char *user, int *user_len)
1942 #ifndef SOCKET_MISDN
1946 if (qi->useruser.off)
1947 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->useruser.off + 1;
1950 unsigned char *p = l3m->useruser;
1959 memcpy(user, p+2, (*user_len<=128)?*(user_len):128); /* clip to 128 maximum */
1962 while(i < *user_len)
1964 UPRINT(buffer+(i*3), " %02x", user[i]);
1969 add_trace("useruser", "protocol", "%d", *protocol);
1970 add_trace("useruser", "value", "%s", buffer);