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);
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 PERROR("IE too short (%d).\n", p[0]);
820 PERROR("refering to channels of other interfaces is not supported.\n");
825 PERROR("using d-channel is not supported.\n");
829 *exclusive = (p[1]&0x08) >> 3;
835 PERROR("extended channel ID with non PRI interface.\n");
838 *channel = p[1] & 0x03;
840 *channel = CHANNEL_ANY;
841 else if (*channel == 0)
842 *channel = CHANNEL_NO;
848 PERROR("IE too short for PRI (%d).\n", p[0]);
853 PERROR("basic channel ID with PRI interface.\n");
856 if ((p[1]&0x03) == 0x00)
859 *channel = CHANNEL_NO;
862 if ((p[1]&0x03) == 0x03)
865 *channel = CHANNEL_ANY;
870 PERROR("%s: ERROR: IE too short for PRI with channel(%d).\n", __FUNCTION__, p[0]);
875 PERROR("channel map not supported.\n");
878 *channel = p[3] & 0x7f;
879 if (*channel<1 | *channel==16)
881 PERROR("PRI interface channel out of range (%d).\n", *channel);
886 add_trace("channel_id", "exclusive", "%d", *exclusive);
890 add_trace("channel_id", "channel", "any channel");
893 add_trace("channel_id", "channel", "no channel");
896 add_trace("channel_id", "channel", "%d", *channel);
902 void Pdss1::enc_ie_date(unsigned char **ntmode, msg_t *msg, time_t ti, int no_seconds)
905 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
913 PERROR("localtime() returned NULL.\n");
917 add_trace("date", "day", "%d.%d.%d", tm->tm_mday, tm->tm_mon+1, tm->tm_year%100);
918 add_trace("date", "time", "%d:%d:%d", tm->tm_hour, tm->tm_min, tm->tm_sec);
920 l = 5 + (!no_seconds);
921 p = msg_put(msg, l+2);
925 qi->date.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
928 p[2] = tm->tm_year % 100;
929 p[3] = tm->tm_mon + 1;
939 void Pdss1::enc_ie_display(unsigned char **ntmode, msg_t *msg, unsigned char *display)
942 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
947 PERROR("display text not given.\n");
951 if (strlen((char *)display) > 80)
953 PERROR("display text too long (max 80 chars), cutting.\n");
957 add_trace("display", NULL, "%s", display);
959 l = strlen((char *)display);
960 p = msg_put(msg, l+2);
964 qi->display.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
967 UNCPY((char *)p+2, (char *)display, strlen((char *)display));
970 void Pdss1::dec_ie_display(unsigned char *p, Q931_info_t *qi, unsigned char *display, int display_len)
978 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->display.off + 1;
984 PERROR("IE too short (%d).\n", p[0]);
988 strnncpy(display, p+1, p[0], display_len);
990 add_trace("display", NULL, "%s", display);
995 void Pdss1::enc_ie_keypad(unsigned char **ntmode, msg_t *msg, unsigned char *keypad)
998 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1003 PERROR("keypad info not given.\n");
1007 add_trace("keypad", NULL, "%s", keypad);
1009 l = strlen((char *)keypad);
1010 p = msg_put(msg, l+2);
1014 qi->keypad.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1017 UNCPY((char *)p+2, (char *)keypad, strlen((char *)keypad));
1020 void Pdss1::dec_ie_keypad(unsigned char *p, Q931_info_t *qi, unsigned char *keypad, int keypad_len)
1028 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->keypad.off + 1;
1034 PERROR("IE too short (%d).\n", p[0]);
1038 strnncpy(keypad, p+1, p[0], keypad_len);
1040 add_trace("keypad", NULL, "%s", keypad);
1045 void Pdss1::enc_ie_notify(unsigned char **ntmode, msg_t *msg, int notify)
1048 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1051 if (notify<0 || notify>0x7f)
1053 PERROR("notify(%d) is out of range.\n", notify);
1057 add_trace("notify", NULL, "%d", notify);
1060 p = msg_put(msg, l+2);
1064 qi->notify.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1067 p[2] = 0x80 + notify;
1070 void Pdss1::dec_ie_notify(unsigned char *p, Q931_info_t *qi, int *notify)
1078 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->notify.off + 1;
1084 PERROR("IE too short (%d).\n", p[0]);
1088 *notify = p[1] & 0x7f;
1090 add_trace("notify", NULL, "%d", *notify);
1095 void Pdss1::enc_ie_progress(unsigned char **ntmode, msg_t *msg, int coding, int location, int progress)
1098 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1101 if (coding<0 || coding>0x03)
1103 PERROR("coding(%d) is out of range.\n", coding);
1106 if (location<0 || location>0x0f)
1108 PERROR("location(%d) is out of range.\n", location);
1111 if (progress<0 || progress>0x7f)
1113 PERROR("progress(%d) is out of range.\n", progress);
1117 add_trace("progress", "codeing", "%d", coding);
1118 add_trace("progress", "location", "%d", location);
1119 add_trace("progress", "indicator", "%d", progress);
1122 p = msg_put(msg, l+2);
1126 qi->progress.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1129 p[2] = 0x80 + (coding<<5) + location;
1130 p[3] = 0x80 + progress;
1133 void Pdss1::dec_ie_progress(unsigned char *p, Q931_info_t *qi, int *coding, int *location, int *progress)
1142 if (qi->progress.off)
1143 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->progress.off + 1;
1149 PERROR("IE too short (%d).\n", p[0]);
1153 *coding = (p[1]&0x60) >> 5;
1154 *location = p[1] & 0x0f;
1155 *progress = p[2] & 0x7f;
1157 add_trace("progress", "codeing", "%d", *coding);
1158 add_trace("progress", "location", "%d", *location);
1159 add_trace("progress", "indicator", "%d", *progress);
1163 /* IE_REDIR_NR (redirecting = during MT_SETUP) */
1164 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)
1167 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1170 if (type<0 || type>7)
1172 PERROR("type(%d) is out of range.\n", type);
1175 if (plan<0 || plan>15)
1177 PERROR("plan(%d) is out of range.\n", plan);
1182 PERROR("present(%d) is out of range.\n", present);
1185 if (present >= 0) if (screen<0 || screen>3)
1187 PERROR("screen(%d) is out of range.\n", screen);
1192 PERROR("reason(%d) is out of range.\n", reason);
1196 add_trace("redir'ing", "type", "%d", type);
1197 add_trace("redir'ing", "plan", "%d", plan);
1198 add_trace("redir'ing", "present", "%d", present);
1199 add_trace("redir'ing", "screen", "%d", screen);
1200 add_trace("redir'ing", "reason", "%d", reason);
1201 add_trace("redir'ing", "number", "%s", number);
1205 l += strlen((char *)number);
1212 p = msg_put(msg, l+2);
1216 qi->redirect_nr.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1223 p[2] = 0x00 + (type<<4) + plan;
1224 p[3] = 0x00 + (present<<5) + screen;
1225 p[4] = 0x80 + reason;
1227 UNCPY((char *)p+5, (char *)number, strlen((char *)number));
1230 p[2] = 0x00 + (type<<4) + plan;
1231 p[3] = 0x80 + (present<<5) + screen;
1233 UNCPY((char *)p+4, (char *)number, strlen((char *)number));
1237 p[2] = 0x80 + (type<<4) + plan;
1238 if (number) if (number[0])
1239 UNCPY((char *)p+3, (char *)number, strlen((char *)number));
1243 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)
1255 if (qi->redirect_nr.off)
1256 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redirect_nr.off + 1;
1262 PERROR("IE too short (%d).\n", p[0]);
1266 *type = (p[1]&0x70) >> 4;
1270 *present = (p[2]&0x60) >> 5;
1271 *screen = p[2] & 0x3;
1274 *reason = p[3] & 0x0f;
1275 strnncpy(number, p+4, p[0]-3, number_len);
1278 strnncpy(number, p+3, p[0]-2, number_len);
1282 strnncpy(number, p+2, p[0]-1, number_len);
1285 add_trace("redir'ing", "type", "%d", *type);
1286 add_trace("redir'ing", "plan", "%d", *plan);
1287 add_trace("redir'ing", "present", "%d", *present);
1288 add_trace("redir'ing", "screen", "%d", *screen);
1289 add_trace("redir'ing", "reason", "%d", *reason);
1290 add_trace("redir'ing", "number", "%s", number);
1294 /* IE_REDIR_DN (redirection = during MT_NOTIFY) */
1295 void Pdss1::enc_ie_redir_dn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, unsigned char *number)
1298 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1301 if (type<0 || type>7)
1303 PERROR("type(%d) is out of range.\n", type);
1306 if (plan<0 || plan>15)
1308 PERROR("plan(%d) is out of range.\n", plan);
1313 PERROR("present(%d) is out of range.\n", present);
1317 add_trace("redir'tion", "type", "%d", type);
1318 add_trace("redir'tion", "plan", "%d", plan);
1319 add_trace("redir'tion", "present", "%d", present);
1320 add_trace("redir'tion", "number", "%s", number);
1324 l += strlen((char *)number);
1327 p = msg_put(msg, l+2);
1331 qi->redirect_dn.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1336 p[2] = 0x00 + (type<<4) + plan;
1337 p[3] = 0x80 + (present<<5);
1339 UNCPY((char *)p+4, (char *)number, strlen((char *)number));
1342 p[2] = 0x80 + (type<<4) + plan;
1344 UNCPY((char *)p+3, (char *)number, strlen((char *)number));
1348 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)
1358 if (qi->redirect_dn.off)
1359 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redirect_dn.off + 1;
1365 PERROR("IE too short (%d).\n", p[0]);
1369 *type = (p[1]&0x70) >> 4;
1373 *present = (p[2]&0x60) >> 5;
1374 strnncpy(number, p+3, p[0]-2, number_len);
1377 strnncpy(number, p+2, p[0]-1, number_len);
1380 add_trace("redir'tion", "type", "%d", *type);
1381 add_trace("redir'tion", "plan", "%d", *plan);
1382 add_trace("redir'tion", "present", "%d", *present);
1383 add_trace("redir'tion", "number", "%s", number);
1388 void Pdss1::enc_ie_facility(unsigned char **ntmode, msg_t *msg, unsigned char *facility, int facility_len)
1391 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1397 if (!facility || facility_len<=0)
1403 while(i < facility_len)
1405 UPRINT(buffer+(i*3), " %02x", facility[i]);
1409 add_trace("facility", NULL, "%s", buffer+1);
1412 p = msg_put(msg, l+2);
1416 qi->facility.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1419 memcpy(p+2, facility, facility_len);
1422 void Pdss1::dec_ie_facility(unsigned char *p, Q931_info_t *qi, unsigned char *facility, int *facility_len)
1432 if (qi->facility.off)
1433 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->facility.off + 1;
1438 *facility_len = p[0];
1439 memcpy(facility, p+1, *facility_len);
1442 while(i < *facility_len)
1444 UPRINT(debug+(i*3), " %02x", facility[i]);
1449 add_trace("facility", NULL, "%s", debug[0]?debug+1:"<none>");
1453 /* facility for siemens CENTEX (known parts implemented only) */
1454 void Pdss1::enc_facility_centrex(unsigned char **ntmode, msg_t *msg, unsigned char *cnip, int setup)
1456 unsigned char centrex[256];
1462 /* centrex facility */
1463 centrex[i++] = CENTREX_FAC;
1464 centrex[i++] = CENTREX_ID;
1467 if (strlen((char *)cnip) > 15)
1469 PDEBUG(DEBUG_PORT, "%s: CNIP/CONP text too long (max 13 chars), cutting.\n");
1472 // dunno what the 8 bytes mean
1475 centrex[i++] = 0x17;
1476 centrex[i++] = 0x02;
1477 centrex[i++] = 0x02;
1478 centrex[i++] = 0x44;
1479 centrex[i++] = 0x18;
1480 centrex[i++] = 0x02;
1481 centrex[i++] = 0x01;
1482 centrex[i++] = 0x09;
1485 centrex[i++] = 0x18;
1486 centrex[i++] = 0x02;
1487 centrex[i++] = 0x02;
1488 centrex[i++] = 0x81;
1489 centrex[i++] = 0x09;
1490 centrex[i++] = 0x02;
1491 centrex[i++] = 0x01;
1492 centrex[i++] = 0x0a;
1495 centrex[i++] = 0x80;
1496 centrex[i++] = strlen((char *)cnip);
1497 UCPY((char *)(¢rex[i]), (char *)cnip);
1498 i += strlen((char *)cnip);
1499 add_trace("facility", "cnip", "%s", cnip);
1501 /* encode facility */
1502 enc_ie_facility(ntmode, msg, centrex, i);
1505 void Pdss1::dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned char *cnip, int cnip_len)
1507 unsigned char centrex[256];
1509 int facility_len = 0;
1513 dec_ie_facility(p, qi, centrex, &facility_len);
1514 if (facility_len >= 2)
1516 if (centrex[i++] != CENTREX_FAC)
1518 if (centrex[i++] != CENTREX_ID)
1522 /* loop sub IEs of facility */
1523 while(facility_len > i+1)
1525 if (centrex[i+1]+i+1 > facility_len)
1527 PERROR("short read of centrex facility.\n");
1533 strnncpy(cnip, ¢rex[i+2], centrex[i+1], cnip_len);
1534 add_trace("facility", "cnip", "%s", cnip);
1539 while(j < centrex[i+1])
1541 UPRINT(debug+(j*3), " %02x", centrex[i+1+j]);
1544 add_trace("facility", "CENTREX", "unknown=0x%02x len=%d%s\n", centrex[i], centrex[i+1], debug);
1546 i += 1+centrex[i+1];
1552 void Pdss1::enc_ie_useruser(unsigned char **ntmode, msg_t *msg, int protocol, unsigned char *user, int user_len)
1555 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1561 if (protocol<0 || protocol>127)
1563 PERROR("protocol(%d) is out of range.\n", protocol);
1566 if (!user || user_len<=0)
1574 UPRINT(buffer+(i*3), " %02x", user[i]);
1578 add_trace("useruser", "protocol", "%d", protocol);
1579 add_trace("useruser", "value", "%s", buffer);
1582 p = msg_put(msg, l+3);
1586 qi->useruser.off = p - (unsigned char *)qi - sizeof(Q931_info_t);
1587 p[0] = IE_USER_USER;
1589 p[2] = 0x80 + protocol;
1590 memcpy(p+3, user, user_len);
1593 void Pdss1::dec_ie_useruser(unsigned char *p, Q931_info_t *qi, int *protocol, unsigned char *user, int *user_len)
1604 if (qi->useruser.off)
1605 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->useruser.off + 1;
1614 memcpy(user, p+2, (*user_len<=128)?*(user_len):128); /* clip to 128 maximum */
1617 while(i < *user_len)
1619 UPRINT(buffer+(i*3), " %02x", user[i]);
1624 add_trace("useruser", "protocol", "%d", *protocol);
1625 add_trace("useruser", "value", "%s", buffer);