35 #include <mISDNuser/mISDNlib.h> 36 #include <mISDNuser/isdn_net.h> 37 #include <mISDNuser/l3dss1.h> 38 #include <mISDNuser/net_l3.h> 43 #define MISDN_IE_DEBG 0 46 static void strnncpy(
char *dest,
const char *src,
size_t len,
size_t dst_len)
50 strncpy(dest, src, len);
59 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
61 if (complete<0 || complete>1)
63 printf(
"%s: ERROR: complete(%d) is out of range.\n", __FUNCTION__, complete);
77 qi->QI_ELEMENT(sending_complete) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
88 if (qi->QI_ELEMENT(sending_complete))
103 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
106 if (coding<0 || coding>3)
108 printf(
"%s: ERROR: coding(%d) is out of range.\n", __FUNCTION__, coding);
111 if (capability<0 || capability>31)
113 printf(
"%s: ERROR: capability(%d) is out of range.\n", __FUNCTION__, capability);
116 if (mode<0 || mode>3)
118 printf(
"%s: ERROR: mode(%d) is out of range.\n", __FUNCTION__, mode);
121 if (rate<0 || rate>31)
123 printf(
"%s: ERROR: rate(%d) is out of range.\n", __FUNCTION__, rate);
128 printf(
"%s: ERROR: multi(%d) is out of range.\n", __FUNCTION__, multi);
133 printf(
"%s: ERROR: user L1(%d) is out of range.\n", __FUNCTION__, rate);
136 if (rate!=24 && multi>=0)
138 printf(
"%s: WARNING: multi(%d) is only possible if rate(%d) would be 24.\n", __FUNCTION__, multi, rate);
142 if (
MISDN_IE_DEBG) printf(
" coding=%d capability=%d mode=%d rate=%d multi=%d user=%d\n", coding, capability, mode, rate, multi, user);
144 l = 2 + (multi>=0) + (user>=0);
145 p = msg_put(msg, l+2);
149 qi->QI_ELEMENT(bearer_capability) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
152 p[2] = 0x80 + (coding<<5) + capability;
153 p[3] = 0x80 + (mode<<5) + rate;
157 p[4+(multi>=0)] = 0xa0 + user;
160 static void dec_ie_bearer(
unsigned char *p, Q931_info_t *qi,
int *coding,
int *capability,
int *mode,
int *rate,
int *multi,
int *
user,
161 int *async,
int *urate,
int *stopbits,
int *dbits,
int *parity,
int nt,
struct misdn_bchannel *
bc)
180 if (qi->QI_ELEMENT(llc)) {
182 p = (
unsigned char *)qi +
sizeof(Q931_info_t) + qi->QI_ELEMENT(llc) + 1;
185 if (qi->QI_ELEMENT(bearer_capability))
186 p = (
unsigned char *)qi +
sizeof(Q931_info_t) + qi->QI_ELEMENT(bearer_capability) + 1;
193 printf(
"%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
197 *coding = (p[1]&0x60) >> 5;
198 *capability = p[1] & 0x1f;
206 *mode = (p[octet]&0x60) >> 5;
207 *rate = p[octet] & 0x1f;
216 *multi = p[octet++] & 0x7f;
223 if ((p[octet] & 0x60) == 0x20) {
224 *user = p[octet] & 0x1f;
229 if (p[octet++] & 0x80)
232 *async = !!(p[octet] & 0x40);
234 *urate = p[octet] & 0x1f;
239 if (p[octet++] & 0x80)
247 if (p[octet++] & 0x80)
255 if (~p[octet++] & 0x80)
260 *stopbits = (p[octet] & 0x60) >> 5;
261 *dbits = (p[octet] & 0x18) >> 3;
262 *parity = p[octet] & 7;
268 if (
MISDN_IE_DEBG) printf(
" coding=%d capability=%d mode=%d rate=%d multi=%d user=%d async=%d urate=%d stopbits=%d dbits=%d parity=%d\n", *coding, *capability, *mode, *rate, *multi, *user, *async, *urate, *stopbits, *dbits, *parity);
274 static void enc_ie_call_id(
unsigned char **ntmode, msg_t *msg,
char *callid,
int callid_len,
int nt,
struct misdn_bchannel *
bc)
277 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
283 if (!callid || callid_len<=0)
289 printf(
"%s: ERROR: callid_len(%d) is out of range.\n", __FUNCTION__, callid_len);
294 while(i < callid_len)
296 if (
MISDN_IE_DEBG) printf(debug+(i*3),
" %02hhx", (
unsigned char)callid[i]);
303 p = msg_put(msg, l+2);
307 qi->QI_ELEMENT(call_id) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
310 memcpy(p+2, callid, callid_len);
315 static void dec_ie_call_id(
unsigned char *p, Q931_info_t *qi,
char *callid,
int *callid_len,
int nt,
struct misdn_bchannel *bc)
325 if (qi->QI_ELEMENT(call_id))
326 p = (
unsigned char *)qi +
sizeof(Q931_info_t) + qi->QI_ELEMENT(call_id) + 1;
332 printf(
"%s: ERROR: IE too long (%d).\n", __FUNCTION__, p[0]);
337 memcpy(callid, p+1, *callid_len);
340 while(i < *callid_len)
342 if (
MISDN_IE_DEBG) printf(debug+(i*3),
" %02hhx", (
unsigned char)callid[i]);
354 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
357 if (type<0 || type>7)
359 printf(
"%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type);
362 if (plan<0 || plan>15)
364 printf(
"%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan);
369 printf(
"%s: ERROR: number is not given.\n", __FUNCTION__);
373 if (
MISDN_IE_DEBG) printf(
" type=%d plan=%d number='%s'\n", type, plan, number);
375 l = 1+strlen((
char *)number);
376 p = msg_put(msg, l+2);
380 qi->QI_ELEMENT(called_nr) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
383 p[2] = 0x80 + (type<<4) + plan;
384 strncpy((
char *)p+3, (
char *)number, strlen((
char *)number));
396 if (qi->QI_ELEMENT(called_nr))
397 p = (
unsigned char *)qi +
sizeof(Q931_info_t) + qi->QI_ELEMENT(called_nr) + 1;
403 printf(
"%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
407 *type = (p[1]&0x70) >> 4;
409 strnncpy(number, (
char *)p+2, p[0]-1, number_len);
411 if (
MISDN_IE_DEBG) printf(
" type=%d plan=%d number='%s'\n", *type, *plan, number);
419 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
422 if (type<0 || type>7)
424 printf(
"%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type);
427 if (plan<0 || plan>15)
429 printf(
"%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan);
434 printf(
"%s: ERROR: present(%d) is out of range.\n", __FUNCTION__, present);
437 if (present >= 0)
if (screen<0 || screen>3)
439 printf(
"%s: ERROR: screen(%d) is out of range.\n", __FUNCTION__, screen);
443 if (
MISDN_IE_DEBG) printf(
" type=%d plan=%d present=%d screen=%d number='%s'\n", type, plan, present, screen, number);
446 if (number)
if (number[0])
447 l += strlen((
char *)number);
450 p = msg_put(msg, l+2);
454 qi->QI_ELEMENT(calling_nr) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
455 p[0] = IE_CALLING_PN;
459 p[2] = 0x00 + (type<<4) + plan;
460 p[3] = 0x80 + (present<<5) + screen;
461 if (number)
if (number[0])
462 strncpy((
char *)p+4, (
char *)number, strlen((
char *)number));
465 p[2] = 0x80 + (type<<4) + plan;
466 if (number)
if (number[0])
467 strncpy((
char *)p+3, (
char *)number, strlen((
char *)number));
482 if (qi->QI_ELEMENT(calling_nr))
483 p = (
unsigned char *)qi +
sizeof(Q931_info_t) + qi->QI_ELEMENT(calling_nr) + 1;
489 printf(
"%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
493 *type = (p[1]&0x70) >> 4;
499 printf(
"%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
502 *present = (p[2]&0x60) >> 5;
503 *screen = p[2] & 0x3;
504 strnncpy(number, (
char *)p+3, p[0]-2, number_len);
507 strnncpy(number, (
char *)p+2, p[0]-1, number_len);
513 if (
MISDN_IE_DEBG) printf(
" type=%d plan=%d present=%d screen=%d number='%s'\n", *type, *plan, *present, *screen, number);
521 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
524 if (type<0 || type>7)
526 printf(
"%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type);
529 if (plan<0 || plan>15)
531 printf(
"%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan);
536 printf(
"%s: ERROR: present(%d) is out of range.\n", __FUNCTION__, present);
539 if (present >= 0)
if (screen<0 || screen>3)
541 printf(
"%s: ERROR: screen(%d) is out of range.\n", __FUNCTION__, screen);
545 if (
MISDN_IE_DEBG) printf(
" type=%d plan=%d present=%d screen=%d number='%s'\n", type, plan, present, screen, number);
548 if (number)
if (number[0])
549 l += strlen((
char *)number);
552 p = msg_put(msg, l+2);
556 qi->QI_ELEMENT(connected_nr) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
557 p[0] = IE_CONNECT_PN;
561 p[2] = 0x00 + (type<<4) + plan;
562 p[3] = 0x80 + (present<<5) + screen;
563 if (number)
if (number[0])
564 strncpy((
char *)p+4, (
char *)number, strlen((
char *)number));
567 p[2] = 0x80 + (type<<4) + plan;
568 if (number)
if (number[0])
569 strncpy((
char *)p+3, (
char *)number, strlen((
char *)number));
584 if (qi->QI_ELEMENT(connected_nr))
585 p = (
unsigned char *)qi +
sizeof(Q931_info_t) + qi->QI_ELEMENT(connected_nr) + 1;
591 printf(
"%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
595 *type = (p[1]&0x70) >> 4;
601 printf(
"%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
604 *present = (p[2]&0x60) >> 5;
605 *screen = p[2] & 0x3;
606 strnncpy(number, (
char *)p+3, p[0]-2, number_len);
609 strnncpy(number, (
char *)p+2, p[0]-1, number_len);
612 if (
MISDN_IE_DEBG) printf(
" type=%d plan=%d present=%d screen=%d number='%s'\n", *type, *plan, *present, *screen, number);
620 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
623 if (location<0 || location>7)
625 printf(
"%s: ERROR: location(%d) is out of range.\n", __FUNCTION__, location);
628 if (cause<0 || cause>127)
630 printf(
"%s: ERROR: cause(%d) is out of range.\n", __FUNCTION__, cause);
634 if (
MISDN_IE_DEBG) printf(
" location=%d cause=%d\n", location, cause);
637 p = msg_put(msg, l+2);
641 qi->QI_ELEMENT(cause) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
644 p[2] = 0x80 + location;
649 static void enc_ie_cause_standalone(
unsigned char **ntmode, msg_t *msg,
int location,
int cause,
int nt,
struct misdn_bchannel *bc)
651 unsigned char *p = msg_put(msg, 4);
652 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
656 qi->QI_ELEMENT(cause) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
659 p[2] = 0x80 + location;
672 if (qi->QI_ELEMENT(cause))
673 p = (
unsigned char *)qi +
sizeof(Q931_info_t) + qi->QI_ELEMENT(cause) + 1;
679 printf(
"%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
683 *location = p[1] & 0x0f;
684 *cause = p[2] & 0x7f;
686 if (
MISDN_IE_DEBG) printf(
" location=%d cause=%d\n", *location, *cause);
694 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
699 if (exclusive<0 || exclusive>1)
701 printf(
"%s: ERROR: exclusive(%d) is out of range.\n", __FUNCTION__, exclusive);
705 || (!pri && (channel>2 && channel<0xff))
706 || (pri && (channel>31 && channel<0xff))
707 || (pri && channel==16))
709 printf(
"%s: ERROR: channel(%d) is out of range.\n", __FUNCTION__, channel);
720 p = msg_put(msg, l+2);
724 qi->QI_ELEMENT(channel_id) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
725 p[0] = IE_CHANNEL_ID;
729 p[2] = 0x80 + (exclusive<<3) + channel;
740 p = msg_put(msg, l+2);
744 qi->QI_ELEMENT(channel_id) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
745 p[0] = IE_CHANNEL_ID;
747 p[2] = 0x80 + 0x20 + 0x03;
752 p = msg_put(msg, l+2);
756 qi->QI_ELEMENT(channel_id) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
757 p[0] = IE_CHANNEL_ID;
759 p[2] = 0x80 + 0x20 + (exclusive<<3) + 0x01;
761 p[4] = 0x80 + channel;
777 if (qi->QI_ELEMENT(channel_id))
778 p = (
unsigned char *)qi +
sizeof(Q931_info_t) + qi->QI_ELEMENT(channel_id) + 1;
784 printf(
"%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
790 printf(
"%s: ERROR: refering to channels of other interfaces is not supported.\n", __FUNCTION__);
795 printf(
"%s: ERROR: using d-channel is not supported.\n", __FUNCTION__);
799 *exclusive = (p[1]&0x08) >> 3;
805 printf(
"%s: ERROR: extended channel ID with non PRI interface.\n", __FUNCTION__);
808 *channel = p[1] & 0x03;
816 printf(
"%s: ERROR: IE too short for PRI (%d).\n", __FUNCTION__, p[0]);
821 printf(
"%s: ERROR: basic channel ID with PRI interface.\n", __FUNCTION__);
824 if ((p[1]&0x03) == 0x00)
830 if ((p[1]&0x03) == 0x03)
838 printf(
"%s: ERROR: IE too short for PRI with channel(%d).\n", __FUNCTION__, p[0]);
843 printf(
"%s: ERROR: channel map not supported.\n", __FUNCTION__);
846 *channel = p[3] & 0x7f;
847 if ( (*channel<1) | (*channel==16) | (*channel>31))
849 printf(
"%s: ERROR: PRI interface channel out of range (%d).\n", __FUNCTION__, *channel);
855 if (
MISDN_IE_DEBG) printf(
" exclusive=%d channel=%d\n", *exclusive, *channel);
863 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
865 struct timeval tv = { ti, 0 };
872 p = msg_put(msg, l+2);
876 qi->QI_ELEMENT(date) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
891 Q931_info_t *qi = (Q931_info_t *) (msg->data + mISDN_HEADER_LEN);
896 printf(
"%s: ERROR: display text not given.\n", __FUNCTION__);
904 printf(
"%s: WARNING: display text too long (max %d chars), cutting.\n", __FUNCTION__, l);
910 p = msg_put(msg, l + 2);
914 qi->QI_ELEMENT(display) = p - (
unsigned char *) qi -
sizeof(Q931_info_t);
917 strncpy((
char *) p + 2, display, l);
921 static void dec_ie_display(
unsigned char *p, Q931_info_t *qi,
char *display,
size_t display_len,
int nt,
struct misdn_bchannel *bc)
928 if (qi->QI_ELEMENT(display))
929 p = (
unsigned char *)qi +
sizeof(Q931_info_t) + qi->QI_ELEMENT(display) + 1;
935 printf(
"%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
939 strnncpy(display, (
char *)p+1, p[0], display_len);
950 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
955 printf(
"%s: ERROR: keypad info not given.\n", __FUNCTION__);
962 p = msg_put(msg, l+2);
966 qi->QI_ELEMENT(keypad) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
969 strncpy((
char *)p+2, keypad, strlen(keypad));
980 if (qi->QI_ELEMENT(keypad))
981 p = (
unsigned char *)qi +
sizeof(Q931_info_t) + qi->QI_ELEMENT(keypad) + 1;
987 printf(
"%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
991 strnncpy(keypad, (
char *)p+1, p[0], keypad_len);
1001 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1004 if (notify<0 || notify>0x7f)
1006 printf(
"%s: ERROR: notify(%d) is out of range.\n", __FUNCTION__, notify);
1013 p = msg_put(msg, l+2);
1017 qi->QI_ELEMENT(notify) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
1020 p[2] = 0x80 + notify;
1030 if (qi->QI_ELEMENT(notify))
1031 p = (
unsigned char *)qi +
sizeof(Q931_info_t) + qi->QI_ELEMENT(notify) + 1;
1037 printf(
"%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
1041 *notify = p[1] & 0x7f;
1051 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1054 if (coding<0 || coding>0x03)
1056 printf(
"%s: ERROR: coding(%d) is out of range.\n", __FUNCTION__, coding);
1059 if (location<0 || location>0x0f)
1061 printf(
"%s: ERROR: location(%d) is out of range.\n", __FUNCTION__, location);
1066 printf(
"%s: ERROR: progress(%d) is out of range.\n", __FUNCTION__, progress);
1070 if (
MISDN_IE_DEBG) printf(
" coding=%d location=%d progress=%d\n", coding, location, progress);
1073 p = msg_put(msg, l+2);
1077 qi->QI_ELEMENT(progress) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
1080 p[2] = 0x80 + (coding<<5) + location;
1081 p[3] = 0x80 + progress;
1094 if (qi->QI_ELEMENT(progress))
1095 p = (
unsigned char *)qi +
sizeof(Q931_info_t) + qi->QI_ELEMENT(progress) + 1;
1101 printf(
"%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
1105 *coding = (p[1]&0x60) >> 5;
1106 *location = p[1] & 0x0f;
1107 *progress = p[2] & 0x7f;
1109 if (
MISDN_IE_DEBG) printf(
" coding=%d location=%d progress=%d\n", *coding, *location, *progress);
1117 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1120 if (type<0 || type>7)
1122 printf(
"%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type);
1125 if (plan<0 || plan>15)
1127 printf(
"%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan);
1132 printf(
"%s: ERROR: present(%d) is out of range.\n", __FUNCTION__, present);
1135 if (present >= 0)
if (screen<0 || screen>3)
1137 printf(
"%s: ERROR: screen(%d) is out of range.\n", __FUNCTION__, screen);
1142 printf(
"%s: ERROR: reason(%d) is out of range.\n", __FUNCTION__, reason);
1146 if (
MISDN_IE_DEBG) printf(
" type=%d plan=%d present=%d screen=%d readon=%d number='%s'\n", type, plan, present, screen, reason, number);
1150 l += strlen((
char *)number);
1157 p = msg_put(msg, l+2);
1161 qi->QI_ELEMENT(redirect_nr) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
1168 p[2] = 0x00 + (type<<4) + plan;
1169 p[3] = 0x00 + (present<<5) + screen;
1170 p[4] = 0x80 + reason;
1172 strncpy((
char *)p+5, (
char *)number, strlen((
char *)number));
1175 p[2] = 0x00 + (type<<4) + plan;
1176 p[3] = 0x80 + (present<<5) + screen;
1178 strncpy((
char *)p+4, (
char *)number, strlen((
char *)number));
1182 p[2] = 0x80 + (type<<4) + plan;
1183 if (number)
if (number[0])
1184 strncpy((
char *)p+3, (
char *)number, strlen((
char *)number));
1188 static void dec_ie_redir_nr(
unsigned char *p, Q931_info_t *qi,
int *
type,
int *plan,
int *present,
int *screen,
int *reason,
char *
number,
size_t number_len,
int nt,
struct misdn_bchannel *bc)
1200 if (qi->QI_ELEMENT(redirect_nr))
1201 p = (
unsigned char *)qi +
sizeof(Q931_info_t) + qi->QI_ELEMENT(redirect_nr) + 1;
1207 printf(
"%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
1211 *type = (p[1]&0x70) >> 4;
1215 *present = (p[2]&0x60) >> 5;
1216 *screen = p[2] & 0x3;
1219 *reason = p[3] & 0x0f;
1220 strnncpy(number, (
char *)p+4, p[0]-3, number_len);
1223 strnncpy(number, (
char *)p+3, p[0]-2, number_len);
1227 strnncpy(number, (
char *)p+2, p[0]-1, number_len);
1230 if (
MISDN_IE_DEBG) printf(
" type=%d plan=%d present=%d screen=%d reason=%d number='%s'\n", *type, *plan, *present, *screen, *reason, number);
1238 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1241 if (type<0 || type>7)
1243 printf(
"%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type);
1246 if (plan<0 || plan>15)
1248 printf(
"%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan);
1253 printf(
"%s: ERROR: present(%d) is out of range.\n", __FUNCTION__, present);
1257 if (
MISDN_IE_DEBG) printf(
" type=%d plan=%d present=%d number='%s'\n", type, plan, present, number);
1261 l += strlen((
char *)number);
1264 p = msg_put(msg, l+2);
1268 qi->QI_ELEMENT(redirect_dn) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
1274 p[2] = 0x00 + (type<<4) + plan;
1275 p[3] = 0x80 + (present<<5);
1277 strncpy((
char *)p+4, (
char *)number, strlen((
char *)number));
1280 p[2] = 0x80 + (type<<4) + plan;
1282 strncpy((
char *)p+3, (
char *)number, strlen((
char *)number));
1296 if (qi->QI_ELEMENT(redirect_dn))
1297 p = (
unsigned char *)qi +
sizeof(Q931_info_t) + qi->QI_ELEMENT(redirect_dn) + 1;
1303 printf(
"%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);
1307 *type = (p[1]&0x70) >> 4;
1311 *present = (p[2]&0x60) >> 5;
1312 strnncpy(number, (
char *)p+3, p[0]-2, number_len);
1315 strnncpy(number, (
char *)p+2, p[0]-1, number_len);
1318 if (
MISDN_IE_DEBG) printf(
" type=%d plan=%d present=%d number='%s'\n", *type, *plan, *present, number);
1327 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1330 if (protocol<0 || protocol>127)
1332 printf(
"%s: ERROR: protocol(%d) is out of range.\n", __FUNCTION__, protocol);
1335 if (!user || user_len<=0)
1344 for (i = 0; i < user_len; ++i) {
1345 sprintf(debug + (i * 3),
" %02hhx", (
unsigned char)user[i]);
1348 printf(
" protocol=%d user-user%s\n", protocol, debug);
1352 p = msg_put(msg, l+3);
1356 qi->QI_ELEMENT(useruser) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
1357 p[0] = IE_USER_USER;
1360 memcpy(p+3, user, user_len);
1373 if (qi->QI_ELEMENT(useruser))
1374 p = (
unsigned char *)qi +
sizeof(Q931_info_t) + qi->QI_ELEMENT(useruser) + 1;
1383 memcpy(user, p+2, (*user_len<=128)?*(user_len):128);
1389 for (i = 0; i < *user_len; ++i) {
1390 sprintf(debug + (i * 3),
" %02hhx", (
unsigned char)user[i]);
1393 printf(
" protocol=%d user-user%s\n", *protocol, debug);
1402 Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
1405 p = msg_put(msg, 3);
1409 qi->QI_ELEMENT(restart_ind) = p - (
unsigned char *)qi -
sizeof(Q931_info_t);
1410 p[0] = IE_RESTART_IND;
static void enc_ie_useruser(unsigned char **ntmode, msg_t *msg, int protocol, char *user, int user_len, int nt, struct misdn_bchannel *bc)
static void enc_ie_notify(unsigned char **ntmode, msg_t *msg, int notify, int nt, struct misdn_bchannel *bc)
static void enc_ie_calling_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, char *number, int nt, struct misdn_bchannel *bc)
Asterisk main include file. File version handling, generic pbx functions.
static void dec_ie_calling_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, char *number, size_t number_len, int nt, struct misdn_bchannel *bc)
static void dec_ie_keypad(unsigned char *p, Q931_info_t *qi, char *keypad, size_t keypad_len, int nt, struct misdn_bchannel *bc)
static void dec_ie_complete(unsigned char *p, Q931_info_t *qi, int *complete, int nt, struct misdn_bchannel *bc)
static int debug
Global debug status.
static void enc_ie_connected_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, char *number, int nt, struct misdn_bchannel *bc)
static void enc_ie_restart_ind(unsigned char **ntmode, msg_t *msg, unsigned char rind, int nt, struct misdn_bchannel *bc)
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
B channel control structure.
static void enc_ie_called_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, char *number, int nt, struct misdn_bchannel *bc)
static void enc_ie_channel_id(unsigned char **ntmode, msg_t *msg, int exclusive, int channel, int nt, struct misdn_bchannel *bc)
static void enc_ie_keypad(unsigned char **ntmode, msg_t *msg, char *keypad, int nt, struct misdn_bchannel *bc)
int pri
TRUE if ISDN-PRI (ISDN-BRI otherwise)
Custom localtime functions for multiple timezones.
static void dec_ie_bearer(unsigned char *p, Q931_info_t *qi, int *coding, int *capability, int *mode, int *rate, int *multi, int *user, int *async, int *urate, int *stopbits, int *dbits, int *parity, int nt, struct misdn_bchannel *bc)
static void dec_ie_progress(unsigned char *p, Q931_info_t *qi, int *coding, int *location, int *progress, int nt, struct misdn_bchannel *bc)
static void strnncpy(char *dest, const char *src, size_t len, size_t dst_len)
static void enc_ie_redir_dn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, char *number, int nt, struct misdn_bchannel *bc)
static void dec_ie_called_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, char *number, size_t number_len, int nt, struct misdn_bchannel *bc)
static void dec_ie_useruser(unsigned char *p, Q931_info_t *qi, int *protocol, char *user, int *user_len, int nt, struct misdn_bchannel *bc)
static void dec_ie_connected_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, char *number, size_t number_len, int nt, struct misdn_bchannel *bc)
struct misdn_stack * get_stack_by_bc(struct misdn_bchannel *bc)
static void dec_ie_cause(unsigned char *p, Q931_info_t *qi, int *location, int *cause, int nt, struct misdn_bchannel *bc)
static void enc_ie_redir_nr(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, int reason, char *number, int nt, struct misdn_bchannel *bc)
static void dec_ie_notify(unsigned char *p, Q931_info_t *qi, int *notify, int nt, struct misdn_bchannel *bc)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void dec_ie_redir_nr(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, int *reason, char *number, size_t number_len, int nt, struct misdn_bchannel *bc)
static void enc_ie_complete(unsigned char **ntmode, msg_t *msg, int complete, int nt, struct misdn_bchannel *bc)
static void enc_ie_display(unsigned char **ntmode, msg_t *msg, char *display, int nt, struct misdn_bchannel *bc)
int nt
TRUE if NT side of protocol (TE otherwise)
structure to hold users read from users.conf
static void enc_ie_bearer(unsigned char **ntmode, msg_t *msg, int coding, int capability, int mode, int rate, int multi, int user, int nt, struct misdn_bchannel *bc)
static void enc_ie_date(unsigned char **ntmode, msg_t *msg, time_t ti, int nt, struct misdn_bchannel *bc)
static void dec_ie_redir_dn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, char *number, size_t number_len, int nt, struct misdn_bchannel *bc)
static void enc_ie_cause(unsigned char **ntmode, msg_t *msg, int location, int cause, int nt, struct misdn_bchannel *bc)
static void enc_ie_progress(unsigned char **ntmode, msg_t *msg, int coding, int location, int progress, int nt, struct misdn_bchannel *bc)
static void dec_ie_channel_id(unsigned char *p, Q931_info_t *qi, int *exclusive, int *channel, int nt, struct misdn_bchannel *bc)