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);
29 void Pdss1::enc_ie_complete(unsigned char **ntmode, msg_t *msg, int complete)
32 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
34 if (complete<0 || complete>1)
36 PERROR("complete(%d) is out of range.\n", complete);
42 add_trace("complete", NULL, NULL);
48 qi->sending_complete.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
53 void Pdss1::dec_ie_complete(unsigned char *p, Q931_info_t *qi, int *complete)
58 if (qi->sending_complete.off)
65 add_trace("complete", NULL, NULL);
70 void Pdss1::enc_ie_bearer(unsigned char **ntmode, msg_t *msg, int coding, int capability, int mode, int rate, int multi, int user)
73 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
76 if (coding<0 || coding>3)
78 PERROR("coding(%d) is out of range.\n", coding);
81 if (capability<0 || capability>31)
83 PERROR("capability(%d) is out of range.\n", capability);
88 PERROR("mode(%d) is out of range.\n", mode);
91 if (rate<0 || rate>31)
93 PERROR("rate(%d) is out of range.\n", rate);
98 PERROR("multi(%d) is out of range.\n", multi);
103 PERROR("user L1(%d) is out of range.\n", user);
106 if (rate!=24 && multi>=0)
108 PERROR("multi(%d) is only possible if rate(%d) would be 24.\n", multi, rate);
112 add_trace("bearer", "coding", "%d", coding);
113 add_trace("bearer", "capability", "%d", capability);
114 add_trace("bearer", "mode", "%d", mode);
115 add_trace("bearer", "rate", "%d", rate);
116 add_trace("bearer", "multi", "%d", multi);
117 add_trace("bearer", "user", "%d", user);
119 l = 2 + (multi>=0) + (user>=0);
120 p = msg_put(msg, l+2);
124 qi->bearer_capability.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
127 p[2] = 0x80 + (coding<<5) + capability;
128 p[3] = 0x80 + (mode<<5) + rate;
132 p[4+(multi>=0)] = 0xa0 + user;
135 void Pdss1::dec_ie_bearer(unsigned char *p, Q931_info_t *qi, int *coding, int *capability, int *mode, int *rate, int *multi, int *user)
147 if (qi->bearer_capability.off)
148 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->bearer_capability.off + 1;
154 add_trace("bearer", "error", "IE too short (len=%d)", p[0]);
158 *coding = (p[1]&0x60) >> 5;
159 *capability = p[1] & 0x1f;
162 *mode = (p[2]&0x60) >> 5;
165 if (p[0]>=3 && *rate==0x18)
167 *multi = p[3] & 0x7f;
176 add_trace("bearer", "coding", "%d", *coding);
177 add_trace("bearer", "capability", "%d", *capability);
178 add_trace("bearer", "mode", "%d", *mode);
179 add_trace("bearer", "rate", "%d", *rate);
180 add_trace("bearer", "multi", "%d", *multi);
181 add_trace("bearer", "user", "%d", *user);
186 void Pdss1::enc_ie_hlc(unsigned char **ntmode, msg_t *msg, int coding, int interpretation, int presentation, int hlc, int exthlc)
189 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
192 if (coding<0 || coding>3)
194 PERROR("coding(%d) is out of range.\n", coding);
197 if (interpretation<0 || interpretation>7)
199 PERROR("interpretation(%d) is out of range.\n", interpretation);
202 if (presentation<0 || presentation>3)
204 PERROR("presentation(%d) is out of range.\n", presentation);
207 if (hlc<0 || hlc>127)
209 PERROR("hlc(%d) is out of range.\n", hlc);
214 PERROR("hlc(%d) is out of range.\n", exthlc);
218 add_trace("hlc", "coding", "%d", coding);
219 add_trace("hlc", "interpretation", "%d", interpretation);
220 add_trace("hlc", "presentation", "%d", presentation);
221 add_trace("hlc", "hlc", "%d", hlc);
223 add_trace("hlc", "exthlc", "%d", exthlc);
226 p = msg_put(msg, l+2);
230 qi->hlc.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
233 p[2] = 0x80 + (coding<<5) + (interpretation<<2) + presentation;
237 p[4] = 0x80 + exthlc;
242 void Pdss1::dec_ie_hlc(unsigned char *p, Q931_info_t *qi, int *coding, int *interpretation, int *presentation, int *hlc, int *exthlc)
245 *interpretation = -1;
254 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->hlc.off + 1;
260 add_trace("hlc", "error", "IE too short (len=%d)", p[0]);
264 *coding = (p[1]&0x60) >> 5;
265 *interpretation = (p[1]&0x1c) >> 2;
266 *presentation = p[1] & 0x03;
270 *exthlc = p[3] & 0x7f;
273 add_trace("hlc", "coding", "%d", *coding);
274 add_trace("hlc", "interpretation", "%d", *interpretation);
275 add_trace("hlc", "presentation", "%d", *presentation);
276 add_trace("hlc", "hlc", "%d", *hlc);
278 add_trace("hlc", "exthlc", "%d", *exthlc);
283 void Pdss1::enc_ie_call_id(unsigned char **ntmode, msg_t *msg, unsigned char *callid, int callid_len)
286 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
292 if (!callid || callid_len<=0)
298 PERROR("callid_len(%d) is out of range.\n", callid_len);
303 while(i < callid_len)
305 UPRINT(buffer+(i*3), " %02x", callid[i]);
309 add_trace("callid", NULL, "%s", buffer[0]?buffer+1:"<none>");
312 p = msg_put(msg, l+2);
316 qi->call_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
319 memcpy(p+2, callid, callid_len);
322 void Pdss1::dec_ie_call_id(unsigned char *p, Q931_info_t *qi, unsigned char *callid, int *callid_len)
333 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->call_id.off + 1;
339 add_trace("callid", "error", "IE too long (len=%d)", p[0]);
344 memcpy(callid, p+1, *callid_len);
347 while(i < *callid_len)
349 UPRINT(buffer+(i*3), " %02x", callid[i]);
353 add_trace("callid", NULL, "%s", buffer[0]?buffer+1:"<none>");
358 void Pdss1::enc_ie_called_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, unsigned char *number)
361 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
364 if (type<0 || type>7)
366 PERROR("type(%d) is out of range.\n", type);
369 if (plan<0 || plan>15)
371 PERROR("plan(%d) is out of range.\n", plan);
376 PERROR("number is not given.\n");
380 add_trace("called_pn", "type", "%d", type);
381 add_trace("called_pn", "plan", "%d", plan);
382 add_trace("called_pn", "number", "%s", number);
384 l = 1+strlen((char *)number);
385 p = msg_put(msg, l+2);
389 qi->called_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
392 p[2] = 0x80 + (type<<4) + plan;
393 UNCPY((char *)p+3, (char *)number, strlen((char *)number));
396 void Pdss1::dec_ie_called_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, unsigned char *number, int number_len)
405 if (qi->called_nr.off)
406 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->called_nr.off + 1;
412 add_trace("called_pn", "error", "IE too short (len=%d)", p[0]);
416 *type = (p[1]&0x70) >> 4;
418 strnncpy(number, p+2, p[0]-1, number_len);
420 add_trace("called_pn", "type", "%d", *type);
421 add_trace("called_pn", "plan", "%d", *plan);
422 add_trace("called_pn", "number", "%s", number);
427 void Pdss1::enc_ie_calling_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, unsigned char *number)
430 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
433 if (type<0 || type>7)
435 PERROR("type(%d) is out of range.\n", type);
438 if (plan<0 || plan>15)
440 PERROR("plan(%d) is out of range.\n", plan);
445 PERROR("present(%d) is out of range.\n", present);
448 if (present >= 0) if (screen<0 || screen>3)
450 PERROR("screen(%d) is out of range.\n", screen);
454 add_trace("calling_pn", "type", "%d", type);
455 add_trace("calling_pn", "plan", "%d", plan);
456 add_trace("calling_pn", "present", "%d", present);
457 add_trace("calling_pn", "screen", "%d", screen);
458 add_trace("calling_pn", "number", "%s", number);
461 if (number) if (number[0])
462 l += strlen((char *)number);
465 p = msg_put(msg, l+2);
469 qi->calling_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
470 p[0] = IE_CALLING_PN;
474 p[2] = 0x00 + (type<<4) + plan;
475 p[3] = 0x80 + (present<<5) + screen;
476 if (number) if (number[0])
477 UNCPY((char *)p+4, (char *)number, strlen((char *)number));
480 p[2] = 0x80 + (type<<4) + plan;
481 if (number) if (number[0])
482 UNCPY((char *)p+3, (char *)number, strlen((char *)number));
486 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)
497 if (qi->calling_nr.off)
498 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->calling_nr.off + 1;
504 add_trace("calling_pn", "error", "IE too short (len=%d)", p[0]);
508 *type = (p[1]&0x70) >> 4;
514 add_trace("calling_pn", "error", "IE too short (len=%d)", p[0]);
517 *present = (p[2]&0x60) >> 5;
518 *screen = p[2] & 0x3;
519 strnncpy(number, p+3, p[0]-2, number_len);
522 strnncpy(number, p+2, p[0]-1, number_len);
525 add_trace("calling_pn", "type", "%d", *type);
526 add_trace("calling_pn", "plan", "%d", *plan);
527 add_trace("calling_pn", "present", "%d", *present);
528 add_trace("calling_pn", "screen", "%d", *screen);
529 add_trace("calling_pn", "number", "%s", number);
533 /* IE_CONNECTED_PN */
534 void Pdss1::enc_ie_connected_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, unsigned char *number)
537 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
540 if (type<0 || type>7)
542 PERROR("type(%d) is out of range.\n", type);
545 if (plan<0 || plan>15)
547 PERROR("plan(%d) is out of range.\n", plan);
552 PERROR("present(%d) is out of range.\n", present);
555 if (present >= 0) if (screen<0 || screen>3)
557 PERROR("screen(%d) is out of range.\n", screen);
561 add_trace("connect_pn", "type", "%d", type);
562 add_trace("connect_pn", "plan", "%d", plan);
563 add_trace("connect_pn", "present", "%d", present);
564 add_trace("connect_pn", "screen", "%d", screen);
565 add_trace("connect_pn", "number", "%s", number);
568 if (number) if (number[0])
569 l += strlen((char *)number);
572 p = msg_put(msg, l+2);
576 qi->connected_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
577 p[0] = IE_CONNECT_PN;
581 p[2] = 0x00 + (type<<4) + plan;
582 p[3] = 0x80 + (present<<5) + screen;
583 if (number) if (number[0])
584 UNCPY((char *)p+4, (char *)number, strlen((char *)number));
587 p[2] = 0x80 + (type<<4) + plan;
588 if (number) if (number[0])
589 UNCPY((char *)p+3, (char *)number, strlen((char *)number));
593 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)
604 if (qi->connected_nr.off)
605 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->connected_nr.off + 1;
611 add_trace("connect_pn", "error", "IE too short (len=%d)", p[0]);
615 *type = (p[1]&0x70) >> 4;
621 add_trace("connect_pn", "error", "IE too short (len=%d)", p[0]);
624 *present = (p[2]&0x60) >> 5;
625 *screen = p[2] & 0x3;
626 strnncpy(number, p+3, p[0]-2, number_len);
629 strnncpy(number, p+2, p[0]-1, number_len);
632 add_trace("connect_pn", "type", "%d", *type);
633 add_trace("connect_pn", "plan", "%d", *plan);
634 add_trace("connect_pn", "present", "%d", *present);
635 add_trace("connect_pn", "screen", "%d", *screen);
636 add_trace("connect_pn", "number", "%s", number);
641 void Pdss1::enc_ie_cause(unsigned char **ntmode, msg_t *msg, int location, int cause)
644 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
647 if (location<0 || location>7)
649 PERROR("location(%d) is out of range.\n", location);
652 if (cause<0 || cause>127)
654 PERROR("cause(%d) is out of range.\n", cause);
658 add_trace("cause", "location", "%d", location);
659 add_trace("cause", "value", "%d", cause);
662 p = msg_put(msg, l+2);
666 qi->cause.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
669 p[2] = 0x80 + location;
672 void enc_ie_cause_standalone(unsigned char **ntmode, msg_t *msg, int location, int cause)
674 unsigned char *p = msg_put(msg, 4);
675 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
679 qi->cause.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
682 p[2] = 0x80 + location;
687 void Pdss1::dec_ie_cause(unsigned char *p, Q931_info_t *qi, int *location, int *cause)
696 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->cause.off + 1;
702 add_trace("cause", "error", "IE too short (len=%d)", p[0]);
706 *location = p[1] & 0x0f;
707 *cause = p[2] & 0x7f;
709 add_trace("cause", "location", "%d", *location);
710 add_trace("cause", "value", "%d", *cause);
715 void Pdss1::enc_ie_channel_id(unsigned char **ntmode, msg_t *msg, int exclusive, int channel)
718 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
720 int pri = p_m_mISDNport->pri;
722 if (exclusive<0 || exclusive>1)
724 PERROR("exclusive(%d) is out of range.\n", exclusive);
727 if ((channel<=0 && channel!=CHANNEL_NO && channel!=CHANNEL_ANY)
728 || (!pri && channel>2)
729 || (pri && channel>127)
730 || (pri && channel==16))
732 PERROR("channel(%d) is out of range.\n", channel);
736 add_trace("channel_id", "exclusive", "%d", exclusive);
740 add_trace("channel_id", "channel", "any channel");
743 add_trace("channel_id", "channel", "no channel");
746 add_trace("channel_id", "channel", "%d", channel);
753 p = msg_put(msg, l+2);
757 qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
758 p[0] = IE_CHANNEL_ID;
760 if (channel == CHANNEL_NO)
762 else if (channel == CHANNEL_ANY)
764 p[2] = 0x80 + (exclusive<<3) + channel;
768 if (channel == CHANNEL_NO) /* no channel */
769 return; /* IE not present */
770 if (channel == CHANNEL_ANY) /* any channel */
773 p = msg_put(msg, l+2);
777 qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
778 p[0] = IE_CHANNEL_ID;
780 p[2] = 0x80 + 0x20 + 0x03;
784 p = msg_put(msg, l+2);
788 qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
789 p[0] = IE_CHANNEL_ID;
791 p[2] = 0x80 + 0x20 + (exclusive<<3) + 0x01;
792 p[3] = 0x80 + 3; /* CCITT, Number, B-type */
793 p[4] = 0x80 + channel;
797 void Pdss1::dec_ie_channel_id(unsigned char *p, Q931_info_t *qi, int *exclusive, int *channel)
799 int pri = p_m_mISDNport->pri;
807 if (qi->channel_id.off)
808 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->channel_id.off + 1;
814 add_trace("channel_id", "error", "IE too short (len=%d)", p[0]);
820 add_trace("channel_id", "error", "refering to channels of other interfaces is not supported");
825 add_trace("channel_id", "error", "using d-channel is not supported");
829 *exclusive = (p[1]&0x08) >> 3;
835 add_trace("channel_id", "error", "extended channel ID with non PRI interface");
838 *channel = p[1] & 0x03;
840 *channel = CHANNEL_ANY;
841 else if (*channel == 0)
842 *channel = CHANNEL_NO;
849 add_trace("channel_id", "error", "IE too short for PRI (len=%d)", p[0]);
854 add_trace("channel_id", "error", "basic channel ID with PRI interface");
857 if ((p[1]&0x03) == 0x00)
860 *channel = CHANNEL_NO;
863 if ((p[1]&0x03) == 0x03)
866 *channel = CHANNEL_ANY;
871 add_trace("channel_id", "error", "IE too short for PRI with channel (len=%d)", p[0]);
876 add_trace("channel_id", "error", "channel map not supported");
879 *channel = p[3] & 0x7f;
880 if (*channel<1 | *channel==16)
882 add_trace("channel_id", "error", "PRI interface channel out of range (%d)", *channel);
887 add_trace("channel_id", "exclusive", "%d", *exclusive);
891 add_trace("channel_id", "channel", "any channel");
894 add_trace("channel_id", "channel", "no channel");
897 add_trace("channel_id", "channel", "%d", *channel);
903 void Pdss1::enc_ie_date(unsigned char **ntmode, msg_t *msg, time_t ti, int no_seconds)
906 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
914 PERROR("localtime() returned NULL.\n");
918 add_trace("date", "day", "%d.%d.%d", tm->tm_mday, tm->tm_mon+1, tm->tm_year%100);
919 add_trace("date", "time", "%d:%d:%d", tm->tm_hour, tm->tm_min, tm->tm_sec);
921 l = 5 + (!no_seconds);
922 p = msg_put(msg, l+2);
926 qi->date.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
929 p[2] = tm->tm_year % 100;
930 p[3] = tm->tm_mon + 1;
940 void Pdss1::enc_ie_display(unsigned char **ntmode, msg_t *msg, unsigned char *display)
943 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
948 PERROR("display text not given.\n");
952 if (strlen((char *)display) > 80)
954 PERROR("display text too long (max 80 chars), cutting.\n");
958 add_trace("display", NULL, "%s", display);
960 l = strlen((char *)display);
961 p = msg_put(msg, l+2);
965 qi->display.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
968 UNCPY((char *)p+2, (char *)display, strlen((char *)display));
971 void Pdss1::dec_ie_display(unsigned char *p, Q931_info_t *qi, unsigned char *display, int display_len)
979 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->display.off + 1;
985 add_trace("display", "error", "IE too short (len=%d)", p[0]);
989 strnncpy(display, p+1, p[0], display_len);
991 add_trace("display", NULL, "%s", display);
996 void Pdss1::enc_ie_keypad(unsigned char **ntmode, msg_t *msg, unsigned char *keypad)
999 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1004 PERROR("keypad info not given.\n");
1008 add_trace("keypad", NULL, "%s", keypad);
1010 l = strlen((char *)keypad);
1011 p = msg_put(msg, l+2);
1015 qi->keypad.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1018 UNCPY((char *)p+2, (char *)keypad, strlen((char *)keypad));
1021 void Pdss1::dec_ie_keypad(unsigned char *p, Q931_info_t *qi, unsigned char *keypad, int keypad_len)
1029 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->keypad.off + 1;
1035 add_trace("keypad", "error", "IE too short (len=%d)", p[0]);
1039 strnncpy(keypad, p+1, p[0], keypad_len);
1041 add_trace("keypad", NULL, "%s", keypad);
1046 void Pdss1::enc_ie_notify(unsigned char **ntmode, msg_t *msg, int notify)
1049 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1052 if (notify<0 || notify>0x7f)
1054 PERROR("notify(%d) is out of range.\n", notify);
1058 add_trace("notify", NULL, "%d", notify);
1061 p = msg_put(msg, l+2);
1065 qi->notify.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1068 p[2] = 0x80 + notify;
1071 void Pdss1::dec_ie_notify(unsigned char *p, Q931_info_t *qi, int *notify)
1079 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->notify.off + 1;
1085 add_trace("notify", "error", "IE too short (len=%d)", p[0]);
1089 *notify = p[1] & 0x7f;
1091 add_trace("notify", NULL, "%d", *notify);
1096 void Pdss1::enc_ie_progress(unsigned char **ntmode, msg_t *msg, int coding, int location, int progress)
1099 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1102 if (coding<0 || coding>0x03)
1104 PERROR("coding(%d) is out of range.\n", coding);
1107 if (location<0 || location>0x0f)
1109 PERROR("location(%d) is out of range.\n", location);
1112 if (progress<0 || progress>0x7f)
1114 PERROR("progress(%d) is out of range.\n", progress);
1118 add_trace("progress", "codeing", "%d", coding);
1119 add_trace("progress", "location", "%d", location);
1120 add_trace("progress", "indicator", "%d", progress);
1123 p = msg_put(msg, l+2);
1127 qi->progress.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1130 p[2] = 0x80 + (coding<<5) + location;
1131 p[3] = 0x80 + progress;
1134 void Pdss1::dec_ie_progress(unsigned char *p, Q931_info_t *qi, int *coding, int *location, int *progress)
1143 if (qi->progress.off)
1144 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->progress.off + 1;
1150 add_trace("progress", "error", "IE too short (len=%d)", p[0]);
1154 *coding = (p[1]&0x60) >> 5;
1155 *location = p[1] & 0x0f;
1156 *progress = p[2] & 0x7f;
1158 add_trace("progress", "codeing", "%d", *coding);
1159 add_trace("progress", "location", "%d", *location);
1160 add_trace("progress", "indicator", "%d", *progress);
1164 /* IE_REDIR_NR (redirecting = during MT_SETUP) */
1165 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)
1168 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1171 if (type<0 || type>7)
1173 PERROR("type(%d) is out of range.\n", type);
1176 if (plan<0 || plan>15)
1178 PERROR("plan(%d) is out of range.\n", plan);
1183 PERROR("present(%d) is out of range.\n", present);
1186 if (present >= 0) if (screen<0 || screen>3)
1188 PERROR("screen(%d) is out of range.\n", screen);
1193 PERROR("reason(%d) is out of range.\n", reason);
1197 add_trace("redir'ing", "type", "%d", type);
1198 add_trace("redir'ing", "plan", "%d", plan);
1199 add_trace("redir'ing", "present", "%d", present);
1200 add_trace("redir'ing", "screen", "%d", screen);
1201 add_trace("redir'ing", "reason", "%d", reason);
1202 add_trace("redir'ing", "number", "%s", number);
1206 l += strlen((char *)number);
1213 p = msg_put(msg, l+2);
1217 qi->redirect_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1224 p[2] = 0x00 + (type<<4) + plan;
1225 p[3] = 0x00 + (present<<5) + screen;
1226 p[4] = 0x80 + reason;
1228 UNCPY((char *)p+5, (char *)number, strlen((char *)number));
1231 p[2] = 0x00 + (type<<4) + plan;
1232 p[3] = 0x80 + (present<<5) + screen;
1234 UNCPY((char *)p+4, (char *)number, strlen((char *)number));
1238 p[2] = 0x80 + (type<<4) + plan;
1239 if (number) if (number[0])
1240 UNCPY((char *)p+3, (char *)number, strlen((char *)number));
1244 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)
1256 if (qi->redirect_nr.off)
1257 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redirect_nr.off + 1;
1263 add_trace("redir'ing", "error", "IE too short (len=%d)", p[0]);
1267 *type = (p[1]&0x70) >> 4;
1271 *present = (p[2]&0x60) >> 5;
1272 *screen = p[2] & 0x3;
1275 *reason = p[3] & 0x0f;
1276 strnncpy(number, p+4, p[0]-3, number_len);
1279 strnncpy(number, p+3, p[0]-2, number_len);
1283 strnncpy(number, p+2, p[0]-1, number_len);
1286 add_trace("redir'ing", "type", "%d", *type);
1287 add_trace("redir'ing", "plan", "%d", *plan);
1288 add_trace("redir'ing", "present", "%d", *present);
1289 add_trace("redir'ing", "screen", "%d", *screen);
1290 add_trace("redir'ing", "reason", "%d", *reason);
1291 add_trace("redir'ing", "number", "%s", number);
1295 /* IE_REDIR_DN (redirection = during MT_NOTIFY) */
1296 void Pdss1::enc_ie_redir_dn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, unsigned char *number)
1299 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1302 if (type<0 || type>7)
1304 PERROR("type(%d) is out of range.\n", type);
1307 if (plan<0 || plan>15)
1309 PERROR("plan(%d) is out of range.\n", plan);
1314 PERROR("present(%d) is out of range.\n", present);
1318 add_trace("redir'tion", "type", "%d", type);
1319 add_trace("redir'tion", "plan", "%d", plan);
1320 add_trace("redir'tion", "present", "%d", present);
1321 add_trace("redir'tion", "number", "%s", number);
1325 l += strlen((char *)number);
1328 p = msg_put(msg, l+2);
1332 qi->redirect_dn.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1337 p[2] = 0x00 + (type<<4) + plan;
1338 p[3] = 0x80 + (present<<5);
1340 UNCPY((char *)p+4, (char *)number, strlen((char *)number));
1343 p[2] = 0x80 + (type<<4) + plan;
1345 UNCPY((char *)p+3, (char *)number, strlen((char *)number));
1349 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)
1359 if (qi->redirect_dn.off)
1360 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redirect_dn.off + 1;
1366 add_trace("redir'tion", "error", "IE too short (len=%d)", p[0]);
1370 *type = (p[1]&0x70) >> 4;
1374 *present = (p[2]&0x60) >> 5;
1375 strnncpy(number, p+3, p[0]-2, number_len);
1378 strnncpy(number, p+2, p[0]-1, number_len);
1381 add_trace("redir'tion", "type", "%d", *type);
1382 add_trace("redir'tion", "plan", "%d", *plan);
1383 add_trace("redir'tion", "present", "%d", *present);
1384 add_trace("redir'tion", "number", "%s", number);
1389 void Pdss1::enc_ie_facility(unsigned char **ntmode, msg_t *msg, unsigned char *facility, int facility_len)
1392 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1398 if (!facility || facility_len<=0)
1404 while(i < facility_len)
1406 UPRINT(buffer+(i*3), " %02x", facility[i]);
1410 add_trace("facility", NULL, "%s", buffer+1);
1413 p = msg_put(msg, l+2);
1417 qi->facility.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1420 memcpy(p+2, facility, facility_len);
1423 void Pdss1::dec_ie_facility(unsigned char *p, Q931_info_t *qi, unsigned char *facility, int *facility_len)
1433 if (qi->facility.off)
1434 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->facility.off + 1;
1439 *facility_len = p[0];
1440 memcpy(facility, p+1, *facility_len);
1443 while(i < *facility_len)
1445 UPRINT(debug+(i*3), " %02x", facility[i]);
1450 add_trace("facility", NULL, "%s", debug[0]?debug+1:"<none>");
1454 void Pdss1::dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned char *cnip, int cnip_len)
1456 unsigned char centrex[256];
1458 int facility_len = 0;
1462 dec_ie_facility(p, qi, centrex, &facility_len);
1463 if (facility_len >= 2)
1465 if (centrex[i++] != CENTREX_FAC)
1467 if (centrex[i++] != CENTREX_ID)
1471 /* loop sub IEs of facility */
1472 while(facility_len > i+1)
1474 if (centrex[i+1]+i+1 > facility_len)
1476 PERROR("short read of centrex facility.\n");
1482 strnncpy(cnip, ¢rex[i+2], centrex[i+1], cnip_len);
1483 add_trace("facility", "cnip", "%s", cnip);
1488 while(j < centrex[i+1])
1490 UPRINT(debug+(j*3), " %02x", centrex[i+1+j]);
1493 add_trace("facility", "CENTREX", "unknown=0x%02x len=%d%s\n", centrex[i], centrex[i+1], debug);
1495 i += 1+centrex[i+1];
1501 void Pdss1::enc_ie_useruser(unsigned char **ntmode, msg_t *msg, int protocol, unsigned char *user, int user_len)
1504 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1510 if (protocol<0 || protocol>127)
1512 PERROR("protocol(%d) is out of range.\n", protocol);
1515 if (!user || user_len<=0)
1523 UPRINT(buffer+(i*3), " %02x", user[i]);
1527 add_trace("useruser", "protocol", "%d", protocol);
1528 add_trace("useruser", "value", "%s", buffer);
1531 p = msg_put(msg, l+3);
1535 qi->useruser.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1536 p[0] = IE_USER_USER;
1538 p[2] = 0x80 + protocol;
1539 memcpy(p+3, user, user_len);
1542 void Pdss1::dec_ie_useruser(unsigned char *p, Q931_info_t *qi, int *protocol, unsigned char *user, int *user_len)
1553 if (qi->useruser.off)
1554 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->useruser.off + 1;
1563 memcpy(user, p+2, (*user_len<=128)?*(user_len):128); /* clip to 128 maximum */
1566 while(i < *user_len)
1568 UPRINT(buffer+(i*3), " %02x", user[i]);
1573 add_trace("useruser", "protocol", "%d", *protocol);
1574 add_trace("useruser", "value", "%s", buffer);