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 PERROR("IE too short (%d).\n", 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 PERROR("IE too short (%d).\n", 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 PERROR("IE too long (%d).\n", 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 PERROR("IE too short (%d).\n", 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 PERROR("IE too short (%d).\n", p[0]);
508 *type = (p[1]&0x70) >> 4;
514 PERROR("IE too short (%d).\n", 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 PERROR("IE too short (%d).\n", p[0]);
615 *type = (p[1]&0x70) >> 4;
621 PERROR("IE too short (%d).\n", 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 PERROR("IE too short (%d).\n", 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);
737 add_trace("channel_id", "channel", "%d", channel);
743 p = msg_put(msg, l+2);
747 qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
748 p[0] = IE_CHANNEL_ID;
750 if (channel == CHANNEL_NO)
752 else if (channel == CHANNEL_ANY)
754 p[2] = 0x80 + (exclusive<<3) + channel;
758 if (channel == CHANNEL_NO) /* no channel */
759 return; /* IE not present */
760 if (channel == CHANNEL_ANY) /* any channel */
763 p = msg_put(msg, l+2);
767 qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
768 p[0] = IE_CHANNEL_ID;
770 p[2] = 0x80 + 0x20 + 0x03;
774 p = msg_put(msg, l+2);
778 qi->channel_id.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
779 p[0] = IE_CHANNEL_ID;
781 p[2] = 0x80 + 0x20 + (exclusive<<3) + 0x01;
782 p[3] = 0x80 + 3; /* CCITT, Number, B-type */
783 p[4] = 0x80 + channel;
787 void Pdss1::dec_ie_channel_id(unsigned char *p, Q931_info_t *qi, int *exclusive, int *channel)
789 int pri = p_m_mISDNport->pri;
797 if (qi->channel_id.off)
798 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->channel_id.off + 1;
804 PERROR("IE too short (%d).\n", p[0]);
810 PERROR("refering to channels of other interfaces is not supported.\n");
815 PERROR("using d-channel is not supported.\n");
819 *exclusive = (p[1]&0x08) >> 3;
825 PERROR("extended channel ID with non PRI interface.\n");
828 *channel = p[1] & 0x03;
830 *channel = CHANNEL_ANY;
831 else if (*channel == 0)
832 *channel = CHANNEL_NO;
838 PERROR("IE too short for PRI (%d).\n", p[0]);
843 PERROR("basic channel ID with PRI interface.\n");
846 if ((p[1]&0x03) == 0x00)
849 *channel = CHANNEL_NO;
852 if ((p[1]&0x03) == 0x03)
855 *channel = CHANNEL_ANY;
860 PERROR("%s: ERROR: IE too short for PRI with channel(%d).\n", __FUNCTION__, p[0]);
865 PERROR("channel map not supported.\n");
868 *channel = p[3] & 0x7f;
869 if (*channel<1 | *channel==16)
871 PERROR("PRI interface channel out of range (%d).\n", *channel);
876 add_trace("channel_id", "exclusive", "%d", *exclusive);
877 add_trace("channel_id", "channel", "%d", *channel);
882 void Pdss1::enc_ie_date(unsigned char **ntmode, msg_t *msg, time_t ti, int no_seconds)
885 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
893 PERROR("localtime() returned NULL.\n");
897 add_trace("date", "day", "%d.%d.%d", tm->tm_mday, tm->tm_mon+1, tm->tm_year%100);
898 add_trace("date", "time", "%d:%d:%d", tm->tm_hour, tm->tm_min, tm->tm_sec);
900 l = 5 + (!no_seconds);
901 p = msg_put(msg, l+2);
905 qi->date.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
908 p[2] = tm->tm_year % 100;
909 p[3] = tm->tm_mon + 1;
919 void Pdss1::enc_ie_display(unsigned char **ntmode, msg_t *msg, unsigned char *display)
922 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
927 PERROR("display text not given.\n");
931 if (strlen((char *)display) > 80)
933 PERROR("display text too long (max 80 chars), cutting.\n");
937 add_trace("display", NULL, "%s", display);
939 l = strlen((char *)display);
940 p = msg_put(msg, l+2);
944 qi->display.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
947 UNCPY((char *)p+2, (char *)display, strlen((char *)display));
950 void Pdss1::dec_ie_display(unsigned char *p, Q931_info_t *qi, unsigned char *display, int display_len)
958 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->display.off + 1;
964 PERROR("IE too short (%d).\n", p[0]);
968 strnncpy(display, p+1, p[0], display_len);
970 add_trace("display", NULL, "%s", display);
975 void Pdss1::enc_ie_keypad(unsigned char **ntmode, msg_t *msg, unsigned char *keypad)
978 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
983 PERROR("keypad info not given.\n");
987 add_trace("keypad", NULL, "%s", keypad);
989 l = strlen((char *)keypad);
990 p = msg_put(msg, l+2);
994 qi->keypad.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
997 UNCPY((char *)p+2, (char *)keypad, strlen((char *)keypad));
1000 void Pdss1::dec_ie_keypad(unsigned char *p, Q931_info_t *qi, unsigned char *keypad, int keypad_len)
1008 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->keypad.off + 1;
1014 PERROR("IE too short (%d).\n", p[0]);
1018 strnncpy(keypad, p+1, p[0], keypad_len);
1020 add_trace("keypad", NULL, "%s", keypad);
1025 void Pdss1::enc_ie_notify(unsigned char **ntmode, msg_t *msg, int notify)
1028 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1031 if (notify<0 || notify>0x7f)
1033 PERROR("notify(%d) is out of range.\n", notify);
1037 add_trace("notify", NULL, "%d", notify);
1040 p = msg_put(msg, l+2);
1044 qi->notify.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1047 p[2] = 0x80 + notify;
1050 void Pdss1::dec_ie_notify(unsigned char *p, Q931_info_t *qi, int *notify)
1058 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->notify.off + 1;
1064 PERROR("IE too short (%d).\n", p[0]);
1068 *notify = p[1] & 0x7f;
1070 add_trace("notify", NULL, "%d", *notify);
1075 void Pdss1::enc_ie_progress(unsigned char **ntmode, msg_t *msg, int coding, int location, int progress)
1078 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1081 if (coding<0 || coding>0x03)
1083 PERROR("coding(%d) is out of range.\n", coding);
1086 if (location<0 || location>0x0f)
1088 PERROR("location(%d) is out of range.\n", location);
1091 if (progress<0 || progress>0x7f)
1093 PERROR("progress(%d) is out of range.\n", progress);
1097 add_trace("progress", "codeing", "%d", coding);
1098 add_trace("progress", "location", "%d", location);
1099 add_trace("progress", "indicator", "%d", progress);
1102 p = msg_put(msg, l+2);
1106 qi->progress.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1109 p[2] = 0x80 + (coding<<5) + location;
1110 p[3] = 0x80 + progress;
1113 void Pdss1::dec_ie_progress(unsigned char *p, Q931_info_t *qi, int *coding, int *location, int *progress)
1122 if (qi->progress.off)
1123 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->progress.off + 1;
1129 PERROR("IE too short (%d).\n", p[0]);
1133 *coding = (p[1]&0x60) >> 5;
1134 *location = p[1] & 0x0f;
1135 *progress = p[2] & 0x7f;
1137 add_trace("progress", "codeing", "%d", *coding);
1138 add_trace("progress", "location", "%d", *location);
1139 add_trace("progress", "indicator", "%d", *progress);
1143 /* IE_REDIR_NR (redirecting = during MT_SETUP) */
1144 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)
1147 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1150 if (type<0 || type>7)
1152 PERROR("type(%d) is out of range.\n", type);
1155 if (plan<0 || plan>15)
1157 PERROR("plan(%d) is out of range.\n", plan);
1162 PERROR("present(%d) is out of range.\n", present);
1165 if (present >= 0) if (screen<0 || screen>3)
1167 PERROR("screen(%d) is out of range.\n", screen);
1172 PERROR("reason(%d) is out of range.\n", reason);
1176 add_trace("redir'ing", "type", "%d", type);
1177 add_trace("redir'ing", "plan", "%d", plan);
1178 add_trace("redir'ing", "present", "%d", present);
1179 add_trace("redir'ing", "screen", "%d", screen);
1180 add_trace("redir'ing", "reason", "%d", reason);
1181 add_trace("redir'ing", "number", "%s", number);
1185 l += strlen((char *)number);
1192 p = msg_put(msg, l+2);
1196 qi->redirect_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1203 p[2] = 0x00 + (type<<4) + plan;
1204 p[3] = 0x00 + (present<<5) + screen;
1205 p[4] = 0x80 + reason;
1207 UNCPY((char *)p+5, (char *)number, strlen((char *)number));
1210 p[2] = 0x00 + (type<<4) + plan;
1211 p[3] = 0x80 + (present<<5) + screen;
1213 UNCPY((char *)p+4, (char *)number, strlen((char *)number));
1217 p[2] = 0x80 + (type<<4) + plan;
1218 if (number) if (number[0])
1219 UNCPY((char *)p+3, (char *)number, strlen((char *)number));
1223 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)
1235 if (qi->redirect_nr.off)
1236 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redirect_nr.off + 1;
1242 PERROR("IE too short (%d).\n", p[0]);
1246 *type = (p[1]&0x70) >> 4;
1250 *present = (p[2]&0x60) >> 5;
1251 *screen = p[2] & 0x3;
1254 *reason = p[3] & 0x0f;
1255 strnncpy(number, p+4, p[0]-3, number_len);
1258 strnncpy(number, p+3, p[0]-2, number_len);
1262 strnncpy(number, p+2, p[0]-1, number_len);
1265 add_trace("redir'ing", "type", "%d", *type);
1266 add_trace("redir'ing", "plan", "%d", *plan);
1267 add_trace("redir'ing", "present", "%d", *present);
1268 add_trace("redir'ing", "screen", "%d", *screen);
1269 add_trace("redir'ing", "reason", "%d", *reason);
1270 add_trace("redir'ing", "number", "%s", number);
1274 /* IE_REDIR_DN (redirection = during MT_NOTIFY) */
1275 void Pdss1::enc_ie_redir_dn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, unsigned char *number)
1278 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1281 if (type<0 || type>7)
1283 PERROR("type(%d) is out of range.\n", type);
1286 if (plan<0 || plan>15)
1288 PERROR("plan(%d) is out of range.\n", plan);
1293 PERROR("present(%d) is out of range.\n", present);
1297 add_trace("redir'tion", "type", "%d", type);
1298 add_trace("redir'tion", "plan", "%d", plan);
1299 add_trace("redir'tion", "present", "%d", present);
1300 add_trace("redir'tion", "number", "%s", number);
1304 l += strlen((char *)number);
1307 p = msg_put(msg, l+2);
1311 qi->redirect_dn.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1316 p[2] = 0x00 + (type<<4) + plan;
1317 p[3] = 0x80 + (present<<5);
1319 UNCPY((char *)p+4, (char *)number, strlen((char *)number));
1322 p[2] = 0x80 + (type<<4) + plan;
1324 UNCPY((char *)p+3, (char *)number, strlen((char *)number));
1328 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)
1338 if (qi->redirect_dn.off)
1339 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redirect_dn.off + 1;
1345 PERROR("IE too short (%d).\n", p[0]);
1349 *type = (p[1]&0x70) >> 4;
1353 *present = (p[2]&0x60) >> 5;
1354 strnncpy(number, p+3, p[0]-2, number_len);
1357 strnncpy(number, p+2, p[0]-1, number_len);
1360 add_trace("redir'tion", "type", "%d", *type);
1361 add_trace("redir'tion", "plan", "%d", *plan);
1362 add_trace("redir'tion", "present", "%d", *present);
1363 add_trace("redir'tion", "number", "%s", number);
1368 void Pdss1::enc_ie_facility(unsigned char **ntmode, msg_t *msg, unsigned char *facility, int facility_len)
1371 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1377 if (!facility || facility_len<=0)
1383 while(i < facility_len)
1385 UPRINT(buffer+(i*3), " %02x", facility[i]);
1389 add_trace("facility", NULL, "%s", buffer+1);
1392 p = msg_put(msg, l+2);
1396 qi->facility.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1399 memcpy(p+2, facility, facility_len);
1402 void Pdss1::dec_ie_facility(unsigned char *p, Q931_info_t *qi, unsigned char *facility, int *facility_len)
1412 if (qi->facility.off)
1413 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->facility.off + 1;
1418 *facility_len = p[0];
1419 memcpy(facility, p+1, *facility_len);
1422 while(i < *facility_len)
1424 UPRINT(debug+(i*3), " %02x", facility[i]);
1429 add_trace("facility", NULL, "%s", debug[0]?debug+1:"<none>");
1433 /* facility for siemens CENTEX (known parts implemented only) */
1434 void Pdss1::enc_facility_centrex(unsigned char **ntmode, msg_t *msg, unsigned char *cnip, int setup)
1436 unsigned char centrex[256];
1442 /* centrex facility */
1443 centrex[i++] = CENTREX_FAC;
1444 centrex[i++] = CENTREX_ID;
1447 if (strlen((char *)cnip) > 15)
1449 PDEBUG(DEBUG_PORT, "%s: CNIP/CONP text too long (max 13 chars), cutting.\n");
1452 // dunno what the 8 bytes mean
1455 centrex[i++] = 0x17;
1456 centrex[i++] = 0x02;
1457 centrex[i++] = 0x02;
1458 centrex[i++] = 0x44;
1459 centrex[i++] = 0x18;
1460 centrex[i++] = 0x02;
1461 centrex[i++] = 0x01;
1462 centrex[i++] = 0x09;
1465 centrex[i++] = 0x18;
1466 centrex[i++] = 0x02;
1467 centrex[i++] = 0x02;
1468 centrex[i++] = 0x81;
1469 centrex[i++] = 0x09;
1470 centrex[i++] = 0x02;
1471 centrex[i++] = 0x01;
1472 centrex[i++] = 0x0a;
1475 centrex[i++] = 0x80;
1476 centrex[i++] = strlen((char *)cnip);
1477 UCPY((char *)(¢rex[i]), (char *)cnip);
1478 i += strlen((char *)cnip);
1479 add_trace("facility", "cnip", "%s", cnip);
1481 /* encode facility */
1482 enc_ie_facility(ntmode, msg, centrex, i);
1485 void Pdss1::dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned char *cnip, int cnip_len)
1487 unsigned char centrex[256];
1489 int facility_len = 0;
1493 dec_ie_facility(p, qi, centrex, &facility_len);
1494 if (facility_len >= 2)
1496 if (centrex[i++] != CENTREX_FAC)
1498 if (centrex[i++] != CENTREX_ID)
1502 /* loop sub IEs of facility */
1503 while(facility_len > i+1)
1505 if (centrex[i+1]+i+1 > facility_len)
1507 PERROR("short read of centrex facility.\n");
1513 strnncpy(cnip, ¢rex[i+2], centrex[i+1], cnip_len);
1514 add_trace("facility", "cnip", "%s", cnip);
1519 while(j < centrex[i+1])
1521 UPRINT(debug+(j*3), " %02x", centrex[i+1+j]);
1524 add_trace("facility", "CENTREX", "unknown=0x%2x len=%d%s\n", centrex[i], centrex[i+1], debug);
1526 i += 1+centrex[i+1];
1532 void Pdss1::enc_ie_useruser(unsigned char **ntmode, msg_t *msg, int protocol, unsigned char *user, int user_len)
1535 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1541 if (protocol<0 || protocol>127)
1543 PERROR("protocol(%d) is out of range.\n", protocol);
1546 if (!user || user_len<=0)
1554 UPRINT(buffer+(i*3), " %02x", user[i]);
1558 add_trace("useruser", "protocol", "%d", protocol);
1559 add_trace("useruser", "value", "%s", buffer);
1562 p = msg_put(msg, l+3);
1566 qi->useruser.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1567 p[0] = IE_USER_USER;
1569 p[2] = 0x80 + protocol;
1570 memcpy(p+3, user, user_len);
1573 void Pdss1::dec_ie_useruser(unsigned char *p, Q931_info_t *qi, int *protocol, unsigned char *user, int *user_len)
1584 if (qi->useruser.off)
1585 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->useruser.off + 1;
1594 memcpy(user, p+2, (*user_len<=128)?*(user_len):128); /* clip to 128 maximum */
1597 while(i < *user_len)
1599 UPRINT(buffer+(i*3), " %02x", user[i]);
1604 add_trace("useruser", "protocol", "%d", *protocol);
1605 add_trace("useruser", "value", "%s", buffer);