1 diff -urN libpri-1.2.3.orig/Makefile libpri-1.2.3/Makefile
2 --- libpri-1.2.3.orig/Makefile 2006-04-30 17:17:47.000000000 +0200
3 +++ libpri-1.2.3/Makefile 2006-06-09 10:18:25.000000000 +0200
5 # Uncomment if you want libpri to count number of Q921/Q931 sent/received
6 #LIBPRI_COUNTERS=-DLIBPRI_COUNTERS
8 +# Uncomment if you want libpri to always keep layer 2 up
9 +#LAYER2ALWAYSUP=-DLAYER2ALWAYSUP
13 OSARCH=$(shell uname -s)
15 DYNAMIC_LIBRARY=libpri.so.1.0
16 STATIC_OBJS=copy_string.o pri.o q921.o prisched.o q931.o pri_facility.o
17 DYNAMIC_OBJS=copy_string.lo pri.lo q921.lo prisched.lo q931.lo pri_facility.lo
18 -CFLAGS=-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -g $(ALERTING) $(LIBPRI_COUNTERS)
19 +CFLAGS=-Wall -Wstrict-prototypes -Wmissing-prototypes -g $(ALERTING) $(LIBPRI_COUNTERS) $(LAYER2ALWAYSUP) -DRELAX_TRB
20 INSTALL_PREFIX=$(DESTDIR)
22 SOFLAGS = -Wl,-hlibpri.so.1.0
23 diff -urN libpri-1.2.3.orig/README libpri-1.2.3/README
24 --- libpri-1.2.3.orig/README 2006-02-15 18:59:38.000000000 +0100
25 +++ libpri-1.2.3/README 2006-01-18 12:28:07.000000000 +0100
27 -libpri: An implementation of Primary Rate ISDN
29 -Written by Mark Spencer <markster@digium.com>
30 +libpri: An implementation of Primate Rate ISDN (and BRI ISDN)
32 +Written by Mark Spencer <markster@linux-support.net>
33 +Modified for BRI support by Klaus-Peter Junghanns <kpj@junghanns.net>
38 based on the Bellcore specification SR-NWT-002343 for National ISDN. As of
39 May 12, 2001, it has been tested work with NI-2, Nortel DMS-100, and
40 Lucent 5E Custom protocols on switches from Nortel and Lucent.
41 +The BRI and euroISDN modifications are based on ETS 300 102-1.
43 What is the license for libpri?
44 ===============================
48 If you wish to use libpri in an application for which the GPL is not
49 -appropriate (e.g. a proprietary embedded system), licenses for libpri
50 -under more flexible terms can be readily obtained through Digium, Inc.
52 +appropriate (e.g. a proprietary embedded system), then you have to use
53 +a non-standard compliant version without BRI support.
56 How do I report bugs or contribute?
57 diff -urN libpri-1.2.3.orig/TODO libpri-1.2.3/TODO
58 --- libpri-1.2.3.orig/TODO 2005-11-29 19:39:18.000000000 +0100
59 +++ libpri-1.2.3/TODO 2006-01-18 12:28:07.000000000 +0100
65 --- Support unnumbered information frames
69 --- Implement the 11 missing Q.931 timers
70 +-- Locking Shift IE (you did that already, didnt you??)
71 +-- Implement the 10 missing Q.931 timers
73 diff -urN libpri-1.2.3.orig/libpri.h libpri-1.2.3/libpri.h
74 --- libpri-1.2.3.orig/libpri.h 2006-04-27 18:08:39.000000000 +0200
75 +++ libpri-1.2.3/libpri.h 2006-06-06 14:28:32.000000000 +0200
78 * Copyright (C) 2001, Linux Support Services, Inc.
79 * All Rights Reserved.
80 + * Copyright (C) 2003-2006 Junghanns.NET GmbH
81 + * Klaus-Peter Junghanns <kpj@junghanns.net>
83 * This program is free software; you can redistribute it and/or modify
84 * it under the terms of the GNU General Public License as published by
89 -#define PRI_NETWORK 1
90 +#define PRI_NETWORK 1 /* PTP modes, default for PRI */
92 +#define BRI_NETWORK_PTMP 3 /* PTMP modes, default for BRI */
93 +#define BRI_CPE_PTMP 4
94 +#define BRI_NETWORK 5 /* PTP modes */
98 #define PRI_DEBUG_Q921_RAW (1 << 0) /* Show raw HDLC frames */
100 #define PRI_EVENT_NOTIFY 16 /* Notification received */
101 #define PRI_EVENT_PROGRESS 17 /* When we get CALL_PROCEEDING or PROGRESS */
102 #define PRI_EVENT_KEYPAD_DIGIT 18 /* When we receive during ACTIVE state */
103 +#define PRI_EVENT_HOLD_REQ 19 /* R */
104 +#define PRI_EVENT_RETRIEVE_REQ 20
105 +#define PRI_EVENT_SUSPEND_REQ 21 /* park */
106 +#define PRI_EVENT_RESUME_REQ 22 /* unpark */
107 +#define PRI_EVENT_DISPLAY_RECEIVED 23
108 +#define PRI_EVENT_FACILITY 24 /* Facility */
111 #define PRI_STATE_DOWN 0
112 @@ -250,11 +262,13 @@
113 #define PRI_NSF_ATT_MULTIQUEST 0xF0
114 #define PRI_NSF_CALL_REDIRECTION_SERVICE 0xF7
116 +typedef struct q921_call q921_call;
117 typedef struct q931_call q931_call;
119 typedef struct pri_event_generic {
120 /* Events with no additional information fall in this category */
125 typedef struct pri_event_error {
126 @@ -273,18 +287,19 @@
131 char useruserinfo[260]; /* User->User info */
135 typedef struct pri_event_answer {
138 + int tei; /* belongs to this tei */
143 char useruserinfo[260]; /* User->User info */
147 typedef struct pri_event_facname {
148 @@ -302,32 +317,37 @@
150 int channel; /* Channel requested */
151 int callingpres; /* Presentation of Calling CallerID */
152 - int callingplanani; /* Dialing plan of Calling entity ANI */
153 + int callingpresuser; /* Presentation of Calling CallerID */
154 int callingplan; /* Dialing plan of Calling entity */
155 - char callingani[256]; /* Calling ANI */
156 - char callingnum[256]; /* Calling number */
157 + int callingplanuser; /* Dialing plan of Calling entity */
158 + int callingplanani; /* Dialing plan of Calling entity ANI */
159 + char callingnum[256]; /* Calling number, network provided */
160 + char callingani[256]; /* Calling number, user provided */
161 char callingname[256]; /* Calling name (if provided) */
162 int calledplan; /* Dialing plan of Called number */
163 int ani2; /* ANI II */
164 char callednum[256]; /* Called number */
165 - char redirectingnum[256]; /* Redirecting number */
166 - char redirectingname[256]; /* Redirecting name */
167 - int redirectingreason; /* Reason for redirect */
168 + char redirectingnum[256]; /* Redirecting number */
169 + char redirectingname[256]; /* Redirecting name */
170 + int redirectingreason; /* Reason for redirect */
171 int callingplanrdnis; /* Dialing plan of Redirecting Number */
172 - char useruserinfo[260]; /* User->User info */
173 + char useruserinfo[260]; /* User->User info */
174 int flexible; /* Are we flexible with our channel selection? */
175 int cref; /* Call Reference Number */
176 int ctype; /* Call type (see PRI_TRANS_CAP_* */
177 - int layer1; /* User layer 1 */
178 + int layer1; /* User layer 1 */
179 int complete; /* Have we seen "Complete" i.e. no more number? */
180 q931_call *call; /* Opaque call pointer */
181 - char callingsubaddr[256]; /* Calling parties subaddress */
182 + int tei; /* belongs to this tei */
183 + char callingsubaddr[256]; /* Calling parties subaddress */
186 char origcalledname[256];
187 char origcallednum[256];
188 int callingplanorigcalled; /* Dialing plan of Originally Called Number */
189 int origredirectingreason;
190 + char lowlayercompat[16];
191 + char highlayercompat[4];
194 typedef struct pri_event_hangup {
196 int channel; /* Channel requested */
200 + int inband_progress;
201 q931_call *call; /* Opaque call pointer */
202 long aoc_units; /* Advise of Charge number of charged units */
203 char useruserinfo[260]; /* User->User info */
204 @@ -375,20 +397,80 @@
206 } pri_event_keypad_digit;
208 +typedef struct pri_event_hold_req {
214 +} pri_event_hold_req;
216 +/* euroisdn faciltiy fun */
217 +typedef struct pri_event_facility_req {
223 + char forwardnum[256]; /* Redirection destination */
225 +} pri_event_facility_req;
227 +typedef struct pri_event_retrieve_req {
233 +} pri_event_retrieve_req;
235 +typedef struct pri_event_suspend_req {
242 +} pri_event_suspend_req;
244 +typedef struct pri_event_resume_req {
251 +} pri_event_resume_req;
253 +typedef struct pri_event_display {
259 +} pri_event_display;
264 pri_event_generic gen; /* Generic view */
265 pri_event_restart restart; /* Restart view */
266 pri_event_error err; /* Error view */
267 pri_event_facname facname; /* Caller*ID Name on Facility */
268 + pri_event_facility_req facility; /* sservices */
269 pri_event_ring ring; /* Ring */
270 pri_event_hangup hangup; /* Hang up */
271 pri_event_ringing ringing; /* Ringing */
272 - pri_event_ringing answer; /* Answer */
273 + pri_event_answer answer; /* Answer */
274 pri_event_restart_ack restartack; /* Restart Acknowledge */
275 pri_event_proceeding proceeding; /* Call proceeding & Progress */
276 pri_event_setup_ack setup_ack; /* SETUP_ACKNOWLEDGE structure */
277 pri_event_notify notify; /* Notification */
278 + pri_event_hold_req hold_req;
279 + pri_event_retrieve_req retrieve_req;
280 + pri_event_suspend_req suspend_req;
281 + pri_event_resume_req resume_req;
282 + pri_event_display display;
283 pri_event_keypad_digit digit; /* Digits that come during a call */
287 channel operating in HDLC mode with FCS computed by the fd's driver. Also it
288 must be NON-BLOCKING! Frames received on the fd should include FCS. Nodetype
289 must be one of PRI_NETWORK or PRI_CPE. switchtype should be PRI_SWITCH_* */
290 -extern struct pri *pri_new(int fd, int nodetype, int switchtype);
291 +extern struct pri *pri_new(int fd, int nodetype, int switchtype, int span);
293 +extern void pri_shutdown(struct pri *pri);
295 /* Create D-channel just as above with user defined I/O callbacks and data */
296 extern struct pri *pri_new_cb(int fd, int nodetype, int switchtype, pri_io_cb io_read, pri_io_cb io_write, void *userdata);
298 /* Enable transmission support of Facility IEs on the pri */
299 extern void pri_facility_enable(struct pri *pri);
301 +/* Set file descriptor for debugging to a file */
302 +extern void pri_set_debug_fd(struct pri *pri, int fd);
304 /* Run PRI on the given D-channel, taking care of any events that
305 need to be handled. If block is set, it will block until an event
306 occurs which needs to be handled */
308 /* Send a digit in overlap mode */
309 extern int pri_information(struct pri *pri, q931_call *call, char digit);
311 +/* Send a INFO msg with display ie */
312 +extern int pri_information_display(struct pri *pri, q931_call *call, char *display);
314 +/* add a display ie to a call, so it can be sent with the next message */
315 +extern int pri_add_display(struct pri *pri, q931_call *call, char *display);
317 /* Answer the incomplete(call without called number) call on the given channel.
318 Set non-isdn to non-zero if you are not connecting to ISDN equipment */
319 extern int pri_need_more_info(struct pri *pri, q931_call *call, int channel, int nonisdn);
321 Set non-isdn to non-zero if you are not connecting to ISDN equipment */
322 extern int pri_answer(struct pri *pri, q931_call *call, int channel, int nonisdn);
324 +extern int pri_deflect(struct pri *pri, q931_call *call, char *destination);
326 +/* Ack a HOLD_REQ */
327 +extern int pri_hold_acknowledge(struct pri *pri, q931_call *call);
329 +/* Reject a HOLD_REQ */
330 +extern int pri_hold_reject(struct pri *pri, q931_call *call);
332 +/* Ack a RETRIEVE_REQ */
333 +extern int pri_retrieve_acknowledge(struct pri *pri, q931_call *call, int channel);
335 +/* Reject a RETRIEVE_REQ */
336 +extern int pri_retrieve_reject(struct pri *pri, q931_call *call);
338 +/* Ack a SUSPEND_REQ */
339 +extern int pri_suspend_acknowledge(struct pri *pri, q931_call *call, char *display);
341 +/* Reject a SUSPEND_REQ */
342 +extern int pri_suspend_reject(struct pri *pri, q931_call *call, char *display);
344 +/* Reject a RESUME_REQ */
345 +extern int pri_resume_reject(struct pri *pri, q931_call *call, char *display);
347 +/* Ack a RESUME_REQ */
348 +extern int pri_resume_acknowledge(struct pri *pri, q931_call *call, int channel, char *display);
350 +/* Send a Facility Message */
351 +extern int pri_facility(struct pri *pri, q931_call *call, int operation, char *arguments);
353 /* Set CRV reference for GR-303 calls */
356 @@ -479,14 +601,14 @@
358 /* backwards compatibility for those who don't use asterisk with libpri */
359 #define pri_release(a,b,c) \
361 + pri_hangup(a,b,c, -1)
363 #define pri_disconnect(a,b,c) \
365 + pri_hangup(a,b,c, -1)
369 -extern int pri_hangup(struct pri *pri, q931_call *call, int cause);
370 +extern int pri_hangup(struct pri *pri, q931_call *call, int cause, int aocunits);
372 #define PRI_DESTROYCALL
373 extern void pri_destroycall(struct pri *pri, q931_call *call);
374 @@ -519,14 +641,13 @@
375 extern void pri_sr_free(struct pri_sr *sr);
377 extern int pri_sr_set_channel(struct pri_sr *sr, int channel, int exclusive, int nonisdn);
378 -extern int pri_sr_set_bearer(struct pri_sr *sr, int transmode, int userl1);
379 +extern int pri_sr_set_bearer(struct pri_sr *sr, int transmode, int userl1, char *llc);
380 extern int pri_sr_set_called(struct pri_sr *sr, char *called, int calledplan, int complete);
381 extern int pri_sr_set_caller(struct pri_sr *sr, char *caller, char *callername, int callerplan, int callerpres);
382 extern int pri_sr_set_redirecting(struct pri_sr *sr, char *num, int plan, int pres, int reason);
383 #define PRI_USER_USER_TX
384 /* Set the user user field. Warning! don't send binary data accross this field */
385 extern void pri_sr_set_useruser(struct pri_sr *sr, char *userchars);
387 extern void pri_call_set_useruser(q931_call *sr, char *userchars);
389 extern int pri_setup(struct pri *pri, q931_call *call, struct pri_sr *req);
392 /* Override message and error stuff */
393 #define PRI_NEW_SET_API
394 -extern void pri_set_message(void (*__pri_error)(struct pri *pri, char *));
395 -extern void pri_set_error(void (*__pri_error)(struct pri *pri, char *));
396 +extern void pri_set_message(void (*__pri_error)(char *, int span));
397 +extern void pri_set_error(void (*__pri_error)(char *, int span));
399 /* Set overlap mode */
400 #define PRI_SET_OVERLAPDIAL
401 diff -urN libpri-1.2.3.orig/pri.c libpri-1.2.3/pri.c
402 --- libpri-1.2.3.orig/pri.c 2005-11-29 19:39:18.000000000 +0100
403 +++ libpri-1.2.3/pri.c 2006-06-09 10:17:29.000000000 +0200
406 * libpri: An implementation of Primary Rate ISDN
408 - * Written by Mark Spencer <markster@digium.com>
409 + * Written by Mark Spencer <markster@linux-suppot.net>
411 - * Copyright (C) 2001-2005, Digium
412 - * All Rights Reserved.
413 + * This program is confidential ( <- I dont think so! )
415 - * This program is free software; you can redistribute it and/or modify
416 - * it under the terms of the GNU General Public License as published by
417 - * the Free Software Foundation; either version 2 of the License, or
418 - * (at your option) any later version.
420 - * This program is distributed in the hope that it will be useful,
421 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
422 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
423 - * GNU General Public License for more details.
425 - * You should have received a copy of the GNU General Public License
426 - * along with this program; if not, write to the Free Software
427 - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
428 + * Copyright (C) 2001, Linux Support Services, Inc.
429 + * All Rights Reserved.
430 + * Copyright (C) 2003-2006 Junghanns.NET GmbH
431 + * Klaus-Peter Junghanns <kpj@junghanns.net>
443 + case BRI_NETWORK_PTMP:
444 + return "Network (PtMP)";
446 + return "CPE (PtMP)";
448 return "Invalid value";
454 -static struct pri *__pri_new(int fd, int node, int switchtype, struct pri *master, pri_io_cb rd, pri_io_cb wr, void *userdata)
455 +static struct pri *__pri_new(int fd, int node, int switchtype, struct pri *master, pri_io_cb rd, pri_io_cb wr, void *userdata, int span)
458 p = malloc(sizeof(struct pri));
461 p->callpool = &p->localpool;
462 pri_default_timers(p, switchtype);
465 #ifdef LIBPRI_COUNTERS
469 p->protodisc = GR303_PROTOCOL_DISCRIMINATOR;
470 p->sapi = Q921_SAPI_GR303_EOC;
471 p->tei = Q921_TEI_GR303_EOC_OPS;
472 - p->subchannel = __pri_new(-1, node, PRI_SWITCH_GR303_EOC_PATH, p, NULL, NULL, NULL);
473 + p->subchannel = __pri_new(-1, node, PRI_SWITCH_GR303_EOC_PATH, p, NULL, NULL, NULL, span);
474 if (!p->subchannel) {
478 p->protodisc = GR303_PROTOCOL_DISCRIMINATOR;
479 p->sapi = Q921_SAPI_GR303_TMC_CALLPROC;
480 p->tei = Q921_TEI_GR303_TMC_CALLPROC;
481 - p->subchannel = __pri_new(-1, node, PRI_SWITCH_GR303_TMC_SWITCHING, p, NULL, NULL, NULL);
482 + p->subchannel = __pri_new(-1, node, PRI_SWITCH_GR303_TMC_SWITCHING, p, NULL, NULL, NULL, span);
483 if (!p->subchannel) {
488 /* Start Q.921 layer, Wait if we're the network */
490 - q921_start(p, p->localtype == PRI_CPE);
491 + q921_start(p, p->localtype == PRI_CPE, 0);
495 @@ -262,15 +262,16 @@
497 /* Restart Q.921 layer */
500 - q921_start(pri, pri->localtype == PRI_CPE);
501 +// XXX q921_reset(pri);
502 +// q921_start(pri, pri->localtype == PRI_CPE);
507 -struct pri *pri_new(int fd, int nodetype, int switchtype)
509 +struct pri *pri_new(int fd, int nodetype, int switchtype, int span)
511 - return __pri_new(fd, nodetype, switchtype, NULL, __pri_read, __pri_write, NULL);
512 + return __pri_new(fd, nodetype, switchtype, NULL, __pri_read, __pri_write, NULL, span);
515 struct pri *pri_new_cb(int fd, int nodetype, int switchtype, pri_io_cb io_read, pri_io_cb io_write, void *userdata)
517 io_read = __pri_read;
519 io_write = __pri_write;
520 - return __pri_new(fd, nodetype, switchtype, NULL, io_read, io_write, userdata);
521 + return __pri_new(fd, nodetype, switchtype, NULL, io_read, io_write, userdata, -1);
524 void *pri_get_userdata(struct pri *pri)
529 +void pri_set_debug_fd(struct pri *pri, int fd)
534 + if (pri->subchannel)
535 + pri_set_debug_fd(pri->subchannel, fd);
538 int pri_acknowledge(struct pri *pri, q931_call *call, int channel, int info)
542 return q931_notify(pri, call, channel, info);
545 +int pri_information_display(struct pri *pri, q931_call *call, char *display)
549 + return q931_information_display(pri, call, display);
552 +int pri_add_display(struct pri *pri, q931_call *call, char *display)
556 + return q931_add_display(pri, call, display);
560 void pri_destroycall(struct pri *pri, q931_call *call)
564 return q931_connect(pri, call, channel, nonisdn);
567 +int pri_hold_acknowledge(struct pri *pri, q931_call *call)
571 + return q931_hold_acknowledge(pri, call);
574 +int pri_hold_reject(struct pri *pri, q931_call *call)
578 + return q931_hold_reject(pri, call);
581 +int pri_retrieve_acknowledge(struct pri *pri, q931_call *call, int channel)
585 + return q931_retrieve_acknowledge(pri, call, channel);
588 +int pri_retrieve_reject(struct pri *pri, q931_call *call)
592 + return q931_retrieve_reject(pri, call);
595 +int pri_suspend_acknowledge(struct pri *pri, q931_call *call, char *display)
599 + return q931_suspend_acknowledge(pri, call, display);
602 +int pri_suspend_reject(struct pri *pri, q931_call *call, char *display)
606 + return q931_suspend_reject(pri, call, display);
609 +int pri_resume_reject(struct pri *pri, q931_call *call, char *display)
613 + return q931_resume_reject(pri, call, display);
616 +int pri_resume_acknowledge(struct pri *pri, q931_call *call, int channel, char *display)
620 + return q931_resume_acknowledge(pri, call, channel, display);
623 +int pri_facility(struct pri *pri, q931_call *call, int operation, char *arguments)
627 +// return q931_facility(pri, call, operation, arguments);
628 + return q931_facility(pri, call);
631 +int pri_deflect(struct pri *pri, q931_call *call, char *destination)
633 + add_call_deflection_facility_ie(pri, call, destination);
634 + return q931_facility(pri, call);
638 /* deprecated routines, use pri_hangup */
639 int pri_release(struct pri *pri, q931_call *call, int cause)
640 @@ -541,14 +636,35 @@
644 -int pri_hangup(struct pri *pri, q931_call *call, int cause)
645 +int pri_hangup(struct pri *pri, q931_call *call, int cause, int aocunits)
651 /* normal clear cause */
653 - return q931_hangup(pri, call, cause);
654 + if ((cause == 34 || cause == 44 || cause == 82 || cause == 1 || cause == 81 || cause == 17) && (call->ourcallstate == Q931_CALL_STATE_ACTIVE)) {
655 + pri_error(pri, "Cause code %d not allowed when disconnecting an active call. Changing to cause 16.\n", cause);
659 + if (aocunits > -1) {
660 + call->aoc_units = aocunits;
663 + if (pri->localtype == BRI_NETWORK_PTMP) {
664 + res = q921_hangup(pri, call, 127);
666 + // q921_setup might give a HANGUP_ACK, if nobody got the call
667 + q931_hangup(pri, call, cause);
670 + return q931_hangup(pri, call, cause);
673 + return q931_hangup(pri, call, cause);
677 int pri_reset(struct pri *pri, int channel)
678 @@ -688,15 +804,15 @@
679 return q931_setup(pri, c, &req);
682 -static void (*__pri_error)(struct pri *pri, char *stuff);
683 -static void (*__pri_message)(struct pri *pri, char *stuff);
684 +static void (*__pri_error)(char *stuff,int span);
685 +static void (*__pri_message)(char *stuff,int span);
687 -void pri_set_message(void (*func)(struct pri *pri, char *stuff))
688 +void pri_set_message(void (*func)(char *stuff,int span))
690 __pri_message = func;
693 -void pri_set_error(void (*func)(struct pri *pri, char *stuff))
694 +void pri_set_error(void (*func)(char *stuff,int span))
698 @@ -708,10 +824,14 @@
700 vsnprintf(tmp, sizeof(tmp), fmt, ap);
703 - __pri_message(pri, tmp);
705 - fputs(tmp, stdout);
706 + if (__pri_message && pri) {
707 + if (pri->debugfd >= 0)
708 + write(pri->debugfd, tmp, strlen(tmp));
710 + __pri_message(tmp, pri->span);
712 + fputs(tmp, stdout);
716 void pri_error(struct pri *pri, char *fmt, ...)
717 @@ -721,10 +841,14 @@
719 vsnprintf(tmp, sizeof(tmp), fmt, ap);
722 - __pri_error(pri, tmp);
724 - fputs(tmp, stderr);
725 + if (__pri_error && pri) {
726 + if (pri->debugfd >= 0)
727 + write(pri->debugfd, tmp, strlen(tmp));
729 + __pri_error(tmp, pri->span);
731 + fputs(tmp, stderr);
735 /* Set overlap mode */
736 @@ -765,11 +889,13 @@
738 len += sprintf(buf + len, "Q921 Outstanding: %d\n", q921outstanding);
740 - len += sprintf(buf + len, "Window Length: %d/%d\n", pri->windowlen, pri->window);
741 - len += sprintf(buf + len, "Sentrej: %d\n", pri->sentrej);
742 - len += sprintf(buf + len, "SolicitFbit: %d\n", pri->solicitfbit);
743 - len += sprintf(buf + len, "Retrans: %d\n", pri->retrans);
744 - len += sprintf(buf + len, "Busy: %d\n", pri->busy);
745 + if (pri->localtype != BRI_NETWORK_PTMP) {
746 + len += sprintf(buf + len, "Window Length: %d/%d\n", pri->windowlen[0], pri->window[0]);
747 + len += sprintf(buf + len, "Sentrej: %d\n", pri->sentrej[0]);
748 + len += sprintf(buf + len, "SolicitFbit: %d\n", pri->solicitfbit[0]);
749 + len += sprintf(buf + len, "Retrans: %d\n", pri->retrans[0]);
750 + len += sprintf(buf + len, "Busy: %d\n", pri->busy[0]);
752 len += sprintf(buf + len, "Overlap Dial: %d\n", pri->overlapdial);
753 len += sprintf(buf + len, "T200 Timer: %d\n", pri->timers[PRI_TIMER_T200]);
754 len += sprintf(buf + len, "T203 Timer: %d\n", pri->timers[PRI_TIMER_T203]);
756 len += sprintf(buf + len, "T313 Timer: %d\n", pri->timers[PRI_TIMER_T313]);
757 len += sprintf(buf + len, "N200 Counter: %d\n", pri->timers[PRI_TIMER_N200]);
763 @@ -819,10 +946,11 @@
767 -int pri_sr_set_bearer(struct pri_sr *sr, int transmode, int userl1)
768 +int pri_sr_set_bearer(struct pri_sr *sr, int transmode, int userl1, char *llc)
770 sr->transmode = transmode;
777 sr->redirectingreason = reason;
781 +void pri_shutdown(struct pri *pri)
783 +#ifndef LAYER2ALWAYSUP
784 + if ((pri->localtype == BRI_NETWORK) || (pri->localtype == BRI_CPE) || (pri->localtype == BRI_CPE_PTMP)) {
785 + q921_reset(pri, pri->tei, 1);
789 diff -urN libpri-1.2.3.orig/pri_facility.c libpri-1.2.3/pri_facility.c
790 --- libpri-1.2.3.orig/pri_facility.c 2006-02-14 00:06:02.000000000 +0100
791 +++ libpri-1.2.3/pri_facility.c 2006-06-06 14:26:01.000000000 +0200
794 - * libpri: An implementation of Primary Rate ISDN
796 - * Written by Matthew Fredrickson <creslin@digium.com>
798 - * Copyright (C) 2004-2005, Digium
799 - * All Rights Reserved.
801 - * This program is free software; you can redistribute it and/or modify
802 - * it under the terms of the GNU General Public License as published by
803 - * the Free Software Foundation; either version 2 of the License, or
804 - * (at your option) any later version.
806 - * This program is distributed in the hope that it will be useful,
807 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
808 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
809 - * GNU General Public License for more details.
811 - * You should have received a copy of the GNU General Public License
812 - * along with this program; if not, write to the Free Software
813 - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
817 + This file and it's contents are licensed under the terms and conditions
818 + of the GNU Public License. See http://www.gnu.org for details.
820 + Routines for dealing with facility messages and their respective
823 + by Matthew Fredrickson <creslin@digium.com>
824 + Copyright (C) 2004-2005 Digium, Inc
826 + Copyright (C) 2005-2006 Junghanns.NET GmbH
827 + Klaus-Peter Junghanns <kpj@junghanns.net>
834 if (datalen > buflen) {
837 + memcpy(namebuf, comp->data, datalen);
839 - memcpy(namebuf, comp->data, datalen);
844 int asn1_string_encode(unsigned char asn1_type, void *data, int len, int max_len, void *src, int src_len)
845 @@ -305,12 +296,55 @@
856 +static int rose_cd_destination_decode(struct pri *pri, q931_call *call, unsigned char *data, int len)
858 + unsigned char *vdata = data;
859 + struct rose_component *comp1 = NULL, *comp2 = NULL;
860 + int pos1 = 0, pos2, sublen2;
862 + if (pri->debug & PRI_DEBUG_AOC)
863 + dump_apdu (pri, data, len);
866 + GET_COMPONENT(comp1, pos1, vdata, len);
867 + CHECK_COMPONENT(comp1, ASN1_SEQUENCE, "!! Invalid CD destination argument. Expected Sequence (0x30) but Received 0x%02X\n");
868 + SUB_COMPONENT(comp1, pos1);
869 + GET_COMPONENT(comp1, pos1, vdata, len);
870 + switch (comp1->type) {
871 + case (ASN1_SEQUENCE | ASN1_CONSTRUCTOR):
872 + sublen2 = comp1->len;
875 + SUB_COMPONENT(comp2, pos2);
877 + GET_COMPONENT(comp2, pos2, vdata, len);
878 + switch (comp2->type) {
879 + case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0):
880 + memcpy(call->redirectingnum, comp2->data, comp2->len);
881 + call->redirectingnum[comp2->len] = '\0';
885 + pri_message(pri, "!! Don't know how to handle 0x%02X in CD destination argument\n", comp2->type);
887 + NEXT_COMPONENT(comp2, pos2);
888 + } while (pos2 < sublen2);
891 + pri_message(pri, "!! Invalid CD destination argument. Expected Sequence (0x30) or Object Identifier (0x81/0x01) but received 0x%02X\n", comp1->type);
893 + NEXT_COMPONENT(comp1, pos1);
894 + } while (pos1 < len);
899 static int rose_address_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberunscreened *value)
902 @@ -375,11 +409,10 @@
903 pri_message(pri, "!! Unknown Party number component received 0x%X\n", comp->type);
906 - ASN1_FIXUP_LEN(comp, res);
907 NEXT_COMPONENT(comp, i);
909 pri_message(pri, "!! not all information is handled from Address component\n");
916 static int rose_presented_number_unscreened_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberunscreened *value)
920 struct rose_component *comp = NULL;
921 unsigned char *vdata = data;
925 case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_0): /* [0] presentationAllowedNumber */
926 value->pres = PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
927 - size = rose_address_decode(pri, call, comp->data, comp->len, value);
928 - ASN1_FIXUP_LEN(comp, size);
930 + return rose_address_decode(pri, call, comp->data, comp->len, value) + 2;
931 case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1): /* [1] IMPLICIT presentationRestricted */
932 if (comp->len != 0) { /* must be NULL */
933 pri_error(pri, "!! Invalid PresentationRestricted component received (len != 0)\n");
936 case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_3): /* [3] presentationRestrictedNumber */
937 value->pres = PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
938 - size = rose_address_decode(pri, call, comp->data, comp->len, value) + 2;
939 - ASN1_FIXUP_LEN(comp, size);
941 + return rose_address_decode(pri, call, comp->data, comp->len, value) + 2;
943 pri_message(pri, "Invalid PresentedNumberUnscreened component 0x%X\n", comp->type);
949 -static int rose_diverting_leg_information2_decode(struct pri *pri, q931_call *call, struct rose_component *sequence, int len)
950 +static int rose_diverting_leg_information2_decode(struct pri *pri, q931_call *call, unsigned char *data, int len)
953 int diversion_counter;
955 struct addressingdataelements_presentednumberunscreened divertingnr;
956 struct addressingdataelements_presentednumberunscreened originalcallednr;
957 struct rose_component *comp = NULL;
958 - unsigned char *vdata = sequence->data;
959 + unsigned char *vdata = data;
963 - if (sequence->type != (ASN1_CONSTRUCTOR | ASN1_SEQUENCE)) { /* Constructed Sequence */
964 - pri_message(pri, "Invalid DivertingLegInformation2Type argument\n");
968 - if (sequence->len == ASN1_LEN_INDEF) {
969 - len -= 4; /* For the 2 extra characters at the end
970 - * and two characters of header */
975 /* diversionCounter stuff */
976 GET_COMPONENT(comp, i, vdata, len);
977 @@ -477,20 +493,18 @@
979 if(pri->debug & PRI_DEBUG_APDU)
980 pri_message(pri, " Redirection reason: %d, total diversions: %d\n", diversion_reason, diversion_counter);
981 - pri_message(NULL, "Length of message is %d\n", len);
983 for(; i < len; NEXT_COMPONENT(comp, i)) {
984 GET_COMPONENT(comp, i, vdata, len);
985 - switch(comp->type) {
986 - case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0):
987 + switch(comp->type & ASN1_TYPE_MASK) {
989 call->origredirectingreason = redirectingreason_for_q931(pri, comp->data[0]);
990 if (pri->debug & PRI_DEBUG_APDU)
991 pri_message(pri, " Received reason for original redirection %d\n", call->origredirectingreason);
993 - case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_1):
994 + case ASN1_TAG_1: /* divertingnr: presentednumberunscreened */
995 res = rose_presented_number_unscreened_decode(pri, call, comp->data, comp->len, &divertingnr);
996 /* TODO: Fix indefinite length form hacks */
997 - ASN1_FIXUP_LEN(comp, res);
1001 @@ -499,43 +513,33 @@
1002 pri_message(pri, " ton = %d, pres = %d, npi = %d\n", divertingnr.ton, divertingnr.pres, divertingnr.npi);
1005 - case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_2):
1006 + case ASN1_TAG_2: /* originalCalledNr: PresentedNumberUnscreened */
1007 res = rose_presented_number_unscreened_decode(pri, call, comp->data, comp->len, &originalcallednr);
1010 - ASN1_FIXUP_LEN(comp, res);
1012 if (pri->debug & PRI_DEBUG_APDU) {
1013 pri_message(pri, " Received originalcallednr '%s'\n", originalcallednr.partyaddress);
1014 pri_message(pri, " ton = %d, pres = %d, npi = %d\n", originalcallednr.ton, originalcallednr.pres, originalcallednr.npi);
1017 - case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_3):
1018 - res = asn1_name_decode(comp->data, comp->len, redirectingname, sizeof(redirectingname));
1021 - ASN1_FIXUP_LEN(comp, res);
1024 + comp->len = asn1_name_decode(comp->data, comp->len, redirectingname, sizeof(redirectingname));
1025 if (pri->debug & PRI_DEBUG_APDU)
1026 pri_message(pri, " Received RedirectingName '%s'\n", redirectingname);
1028 - case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_4):
1029 - res = asn1_name_decode(comp->data, comp->len, origcalledname, sizeof(origcalledname));
1032 - ASN1_FIXUP_LEN(comp, res);
1035 + comp->len = asn1_name_decode(comp->data, comp->len, origcalledname, sizeof(origcalledname));
1036 if (pri->debug & PRI_DEBUG_APDU)
1037 pri_message(pri, " Received Originally Called Name '%s'\n", origcalledname);
1040 - if (comp->type == 0 && comp->len == 0) {
1041 - break; /* Found termination characters */
1043 pri_message(pri, "!! Invalid DivertingLegInformation2 component received 0x%X\n", comp->type);
1048 + return -1; /* Aborted before */
1050 if (divertingnr.pres >= 0) {
1051 call->redirectingplan = divertingnr.npi;
1052 @@ -548,15 +552,19 @@
1053 call->origcalledpres = originalcallednr.pres;
1054 libpri_copy_string(call->origcallednum, originalcallednr.partyaddress, sizeof(call->origcallednum));
1056 - libpri_copy_string(call->redirectingname, redirectingname, sizeof(call->redirectingname));
1057 - libpri_copy_string(call->origcalledname, origcalledname, sizeof(call->origcalledname));
1058 + if (strlen(redirectingname) > 0) {
1059 + libpri_copy_string(call->redirectingname, redirectingname, sizeof(call->redirectingname));
1061 + if (strlen(origcalledname) > 0) {
1062 + libpri_copy_string(call->origcalledname, origcalledname, sizeof(call->origcalledname));
1072 static int rose_diverting_leg_information2_encode(struct pri *pri, q931_call *call)
1074 int i = 0, j, compsp = 0;
1075 @@ -694,6 +702,64 @@
1079 +/* Call deflection */
1080 +int add_call_deflection_facility_ie(struct pri *pri, q931_call *c, char *destination) {
1081 + int i = 0, j, compsp = 0;
1082 + struct rose_component *comp, *compstk[10];
1083 + unsigned char buffer[256];
1085 + buffer[i++] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_ROSE);
1087 + ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer, i);
1088 + ASN1_PUSH(compstk, compsp, comp);
1090 + ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, get_invokeid(pri));
1091 + ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, ROSE_CALLDEFLECTION);
1093 + /* Argument sequence */
1094 + ASN1_ADD_SIMPLE(comp, (ASN1_CONSTRUCTOR | ASN1_SEQUENCE), buffer, i);
1095 + ASN1_PUSH(compstk, compsp, comp);
1098 + ASN1_ADD_SIMPLE(comp, (ASN1_CONSTRUCTOR | ASN1_SEQUENCE), buffer, i);
1099 + ASN1_PUSH(compstk, compsp, comp);
1101 +#ifndef CD_UNLIKE_IN_CAPI
1102 + /* arg.address.PartyNumber */
1105 + j = asn1_string_encode((ASN1_CONTEXT_SPECIFIC|ASN1_TAG_0), &buffer[i], sizeof(buffer)-i, 20, destination, strlen(destination));
1106 + if (j<0) return -1;
1109 + /* using PublicPartyNumber instead */
1110 + ASN1_ADD_SIMPLE(comp, (ASN1_CONSTRUCTOR | ASN1_SEQUENCE | ASN1_CONTEXT_SPECIFIC| ASN1_TAG_1), buffer, i);
1111 + ASN1_PUSH(compstk, compsp, comp);
1112 + /* ToN: unknown */
1113 + ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, 0);
1114 + j = asn1_string_encode(0x80, &buffer[i], sizeof(buffer)-i, 20, destination, strlen(destination));
1115 + if(j<0) return -1;
1117 + /* close PublicPartyNumber */
1118 + ASN1_FIXUP(compstk, compsp, buffer, i);
1121 + /* close Address */
1122 + ASN1_FIXUP(compstk, compsp, buffer, i);
1125 + ASN1_ADD_BYTECOMP(comp, ASN1_BOOLEAN, buffer, i, 0);
1127 + /* Fix length of stacked components */
1128 + while(compsp > 0) {
1129 + ASN1_FIXUP(compstk, compsp, buffer, i);
1131 + if (pri_call_apdu_queue(c, Q931_FACILITY, buffer, i, NULL, NULL))
1137 /* Sending callername information functions */
1138 static int add_callername_facility_ies(struct pri *pri, q931_call *c, int cpe)
1140 @@ -936,7 +1002,7 @@
1141 CHECK_COMPONENT(comp, ASN1_ENUMERATED, "!! Invalid AOC Charging Request argument. Expected Enumerated (0x0A) but Received 0x%02X\n");
1142 ASN1_GET_INTEGER(comp, chargingcase);
1143 if (chargingcase >= 0 && chargingcase <= 2) {
1144 - if (pri->debug & PRI_DEBUG_APDU)
1145 +// if (pri->debug & PRI_DEBUG_APDU)
1146 pri_message(pri, "Channel %d/%d, Call %d - received AOC charging request - charging case: %i\n",
1147 call->ds1no, call->channelno, call->cr, chargingcase);
1149 @@ -1054,7 +1120,7 @@
1153 -static int aoc_aoce_charging_unit_encode(struct pri *pri, q931_call *c, long chargedunits)
1154 +int aoc_aoce_charging_unit_encode(struct pri *pri, q931_call *c, long chargedunits, int msgtype)
1156 /* sample data: [ 91 a1 12 02 02 3a 78 02 01 24 30 09 30 07 a1 05 30 03 02 01 01 ] */
1157 int i = 0, res = 0, compsp = 0;
1158 @@ -1108,18 +1174,20 @@
1159 dump_apdu (pri, buffer, i);
1161 /* code below is untested */
1162 - res = pri_call_apdu_queue(c, Q931_FACILITY, buffer, i, NULL, NULL);
1163 + res = pri_call_apdu_queue(c, msgtype, buffer, i, NULL, NULL);
1165 pri_message(pri, "Could not queue ADPU in facility message\n");
1169 - /* Remember that if we queue a facility IE for a facility message we
1170 - * have to explicitly send the facility message ourselves */
1171 - res = q931_facility(c->pri, c);
1173 + if (msgtype == Q931_FACILITY) {
1174 + /* Remember that if we queue a facility IE for a facility message we
1175 + * have to explicitly send the facility message ourselves */
1176 + res = q931_facility(c->pri, c);
1178 pri_message(pri, "Could not schedule facility message for call %d\n", c->cr);
1184 @@ -1152,13 +1220,15 @@
1185 NEXT_COMPONENT(comp, i);
1187 /* No argument - return with error */
1189 + if ((i >= len) && (operation_tag != ROSE_EXPLICIT_CALL_TRANSFER))
1192 - /* Arguement Tag */
1193 - GET_COMPONENT(comp, i, vdata, len);
1196 + if (operation_tag != ROSE_EXPLICIT_CALL_TRANSFER) {
1197 + /* Arguement Tag */
1198 + GET_COMPONENT(comp, i, vdata, len);
1203 if (pri->debug & PRI_DEBUG_APDU)
1204 pri_message(pri, " [ Handling operation %d ]\n", operation_tag);
1205 @@ -1182,7 +1252,11 @@
1206 case ROSE_DIVERTING_LEG_INFORMATION2:
1207 if (pri->debug & PRI_DEBUG_APDU)
1208 pri_message(pri, " Handle DivertingLegInformation2\n");
1209 - return rose_diverting_leg_information2_decode(pri, call, comp, len-i);
1210 + if (comp->type != (ASN1_CONSTRUCTOR | ASN1_SEQUENCE)) { /* Constructed Sequence */
1211 + pri_message(pri, "Invalid DivertingLegInformation2Type argument\n");
1214 + return rose_diverting_leg_information2_decode(pri, call, comp->data, comp->len);
1215 case ROSE_AOC_NO_CHARGING_INFO_AVAILABLE:
1216 if (pri->debug & PRI_DEBUG_APDU) {
1217 pri_message(pri, "ROSE %i: AOC No Charging Info Available - not handled!", operation_tag);
1218 @@ -1210,6 +1284,7 @@
1221 case ROSE_AOC_AOCD_CHARGING_UNIT:
1222 +// return aoc_aoce_charging_unit_decode(pri, call, (u_int8_t *)comp, comp->len + 2);
1223 if (pri->debug & PRI_DEBUG_APDU) {
1224 pri_message(pri, "ROSE %i: AOC-D Charging Unit - not handled!", operation_tag);
1225 dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
1226 @@ -1224,7 +1299,7 @@
1227 case ROSE_AOC_AOCE_CHARGING_UNIT:
1228 return aoc_aoce_charging_unit_decode(pri, call, (u_int8_t *)comp, comp->len + 2);
1229 if (0) { /* the following function is currently not used - just to make the compiler happy */
1230 - aoc_aoce_charging_unit_encode(pri, call, call->aoc_units); /* use this function to forward the aoc-e on a bridged channel */
1231 + aoc_aoce_charging_unit_encode(pri, call, call->aoc_units, 1); /* use this function to forward the aoc-e on a bridged channel */
1234 case ROSE_AOC_IDENTIFICATION_OF_CHARGE:
1235 @@ -1233,6 +1308,22 @@
1236 dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
1239 + case ROSE_CALLDEFLECTION:
1240 + call->facility = operation_tag;
1241 + return rose_cd_destination_decode(pri, call, (u_int8_t *)comp, comp->len + 2);
1243 + case ROSE_EXPLICIT_CALL_TRANSFER:
1244 + call->facility = operation_tag;
1245 + if (pri->debug & PRI_DEBUG_APDU) {
1246 + pri_message(pri, "ROSE %i: received ECT execute!", operation_tag);
1249 + case ROSE_MALICIOUS_CID:
1250 +// call->facility = operation_tag;
1251 +// if (pri->debug & PRI_DEBUG_APDU) {
1252 + pri_message(pri, "ROSE %i: received MALICIOUS CID!", operation_tag);
1256 if (pri->debug & PRI_DEBUG_APDU) {
1257 pri_message(pri, "!! Unable to handle ROSE operation %d", operation_tag);
1258 diff -urN libpri-1.2.3.orig/pri_facility.h libpri-1.2.3/pri_facility.h
1259 --- libpri-1.2.3.orig/pri_facility.h 2005-11-29 19:39:18.000000000 +0100
1260 +++ libpri-1.2.3/pri_facility.h 2006-04-15 21:35:05.000000000 +0200
1262 /* Operation ID values */
1263 /* Q.952 ROSE operations (Diverting) */
1264 #define ROSE_DIVERTING_LEG_INFORMATION1 18
1265 -#define ROSE_DIVERTING_LEG_INFORMATION2 0x15
1266 +#define ROSE_DIVERTING_LEG_INFORMATION2 15
1267 #define ROSE_DIVERTING_LEG_INFORMATION3 19
1268 /* Q.956 ROSE operations (Advice Of Charge) */
1269 #define ROSE_AOC_NO_CHARGING_INFO_AVAILABLE 26
1271 #define ROSE_AOC_IDENTIFICATION_OF_CHARGE 37
1272 /* Q.SIG operations */
1273 #define SS_CNID_CALLINGNAME 0
1274 -#define SS_DIVERTING_LEG_INFORMATION2 21
1275 +#define SS_DIVERTING_LEG_INFORMATION2 22
1276 #define SS_MWI_ACTIVATE 80
1277 #define SS_MWI_DEACTIVATE 81
1278 #define SS_MWI_INTERROGATE 82
1280 +#define ROSE_CALLDEFLECTION 0x0D
1281 +#define ROSE_EXPLICIT_CALL_TRANSFER 0x06
1282 +#define ROSE_MALICIOUS_CID 0x31
1284 /* ROSE definitions and data structures */
1285 #define INVOKE_IDENTIFIER 0x02
1286 #define INVOKE_LINKED_IDENTIFIER 0x80
1287 @@ -180,12 +184,6 @@
1288 (variable) = ((variable) << 8) | (component)->data[comp_idx]; \
1291 -#define ASN1_FIXUP_LEN(component, size) \
1293 - if ((component)->len == ASN1_LEN_INDEF) \
1297 #define ASN1_ADD_SIMPLE(component, comptype, ptr, idx) \
1299 (component) = (struct rose_component *)&((ptr)[(idx)]); \
1301 /* Adds the "standard" ADPUs to a call */
1302 extern int pri_call_add_standard_apdus(struct pri *pri, q931_call *call);
1304 +extern int add_call_deflection_facility_ie(struct pri *pri, q931_call *c, char *destination);
1306 +extern int aoc_aoce_charging_unit_encode(struct pri *pri, q931_call *c, long chargedunits, int send_facility_message);
1308 #endif /* _PRI_FACILITY_H */
1309 diff -urN libpri-1.2.3.orig/pri_internal.h libpri-1.2.3/pri_internal.h
1310 --- libpri-1.2.3.orig/pri_internal.h 2005-11-29 19:39:18.000000000 +0100
1311 +++ libpri-1.2.3/pri_internal.h 2006-04-15 21:57:19.000000000 +0200
1314 * Copyright (C) 2001, Linux Support Services, Inc.
1315 * All Rights Reserved.
1316 + * Copyright (C) 2003-2006 Junghanns.NET GmbH
1317 + * Klaus-Peter Junghanns <kpj@junghanns.net>
1319 * This program is free software; you can redistribute it and/or modify
1320 * it under the terms of the GNU General Public License as published by
1323 struct timeval when;
1324 void (*callback)(void *data);
1325 + void (*callback2)(void *data, int);
1335 /* No more than 128 scheduled events */
1336 +/* XXX is this sufficient for nfs ??? */
1337 #define MAX_SCHED 128
1339 +/* this can be freely configured to support more devices .... ok, 63 would be max! */
1340 +#define Q921_MAX_TEIS 16
1342 +/* dynamically allocated TEIs start here */
1343 +#define Q921_TEI_BASE 64
1345 #define MAX_TIMERS 32
1349 struct pri *master; /* Master channel if appropriate */
1350 struct pri_sched pri_sched[MAX_SCHED]; /* Scheduled events */
1351 int debug; /* Debug stuff */
1353 int state; /* State of D-channel */
1354 int switchtype; /* Switch type */
1355 int nsf; /* Network-Specific Facility (if any) */
1361 - int window; /* Max window size */
1362 - int windowlen; /* Fullness of window */
1363 - int v_s; /* Next N(S) for transmission */
1364 - int v_a; /* Last acknowledged frame */
1365 - int v_r; /* Next frame expected to be received */
1366 - int v_na; /* What we've told our peer we've acknowledged */
1367 - int solicitfbit; /* Have we sent an I or S frame with the F-bit set? */
1368 - int retrans; /* Retransmissions */
1369 - int sentrej; /* Are we in reject state */
1371 + int q921_state[Q921_MAX_TEIS];
1374 + /* TEI registry */
1375 + char q921_teis[Q921_MAX_TEIS];
1377 + char q921_tei_check[Q921_MAX_TEIS];
1378 + unsigned short q921_tei_check_ri[Q921_MAX_TEIS];
1382 + int busy[Q921_MAX_TEIS]; /* Peer is busy */
1384 + int window[Q921_MAX_TEIS]; /* Max window size */
1385 + int windowlen[Q921_MAX_TEIS]; /* Fullness of window */
1386 + int v_s[Q921_MAX_TEIS]; /* Next N(S) for transmission */
1387 + int v_a[Q921_MAX_TEIS]; /* Last acknowledged frame */
1388 + int v_r[Q921_MAX_TEIS]; /* Next frame expected to be received */
1389 + int v_na[Q921_MAX_TEIS]; /* What we've told our peer we've acknowledged */
1390 + int solicitfbit[Q921_MAX_TEIS]; /* Have we sent an I or S frame with the F-bit set? */
1391 + int retrans[Q921_MAX_TEIS]; /* Retransmissions */
1392 + int sabme_retrans[Q921_MAX_TEIS]; /* Retransmissions */
1394 + int sentrej[Q921_MAX_TEIS]; /* Are we in reject state */
1396 + /* Various timers */
1397 + int sabme_timer[Q921_MAX_TEIS];
1398 + int t203_timer[Q921_MAX_TEIS];
1399 + int t202_timer[Q921_MAX_TEIS];
1401 + int t201_timer[Q921_MAX_TEIS];
1402 + int t200_timer[Q921_MAX_TEIS];
1405 int cref; /* Next call reference value */
1407 - int busy; /* Peer is busy */
1409 - /* Various timers */
1410 - int sabme_timer; /* SABME retransmit */
1411 - int t203_timer; /* Max idle time */
1412 - int t200_timer; /* T-200 retransmission timer */
1413 /* All ISDN Timer values */
1414 int timers[MAX_TIMERS];
1418 pri_event ev; /* Static event thingy */
1420 - /* Q.921 Re-transmission queue */
1421 - struct q921_frame *txqueue;
1422 + /* Q.921 (Re)transmission queue */
1423 + struct q921_frame *txqueue[Q921_MAX_TEIS];
1426 q931_call **callpool;
1429 unsigned char last_invoke; /* Last ROSE invoke ID */
1430 unsigned char sendfacility;
1432 + int span; /* our fellow pri lives on this zaptel span */
1441 + int callerplanani;
1446 int redirectingreason;
1452 /* Internal switch types */
1453 @@ -167,8 +202,13 @@
1455 int alive; /* Whether or not the call is alive */
1456 int acked; /* Whether setup has been acked or not */
1457 + int con_acked; /* Whether CONNECT has been CONNECT_ACKNOWLEDGEd or not */
1458 int sendhangupack; /* Whether or not to send a hangup ack */
1459 int proc; /* Whether we've sent a call proceeding / alerting */
1460 + int alert; /* Whether we've sent an alerting */
1463 + q921_call *phones;
1465 int ri; /* Restart Indicator (Restart Indicator IE) */
1467 @@ -202,15 +242,18 @@
1470 int callerpres; /* Caller presentation */
1471 - char callerani[256]; /* Caller */
1472 - char callernum[256];
1473 + int callerplanuser;
1474 + int callerpresuser; /* Caller presentation */
1475 + char callernum[256]; /* Calling Number (network provided) */
1476 + char callerani[256]; /* Calling Number, (user provided) */
1478 char callername[256];
1480 - char digitbuf[64]; /* Buffer for digits that come in KEYPAD_FACILITY */
1481 + char digitbuf[64]; /* Buffer for digits that come in KEYPAD_FACILITY */
1483 int ani2; /* ANI II */
1488 char callednum[256]; /* Called Number */
1489 int complete; /* no more digits coming */
1490 @@ -225,23 +268,36 @@
1491 char redirectingnum[256]; /* Number of redirecting party */
1492 char redirectingname[256]; /* Name of redirecting party */
1497 /* Filled in cases of multiple diversions */
1500 - int origredirectingreason; /* Original reason for redirect (in cases of multiple redirects) */
1501 + int origredirectingreason; /* Original reason for redirect (in cases of multiple redirects) */
1502 char origcalledname[256]; /* Original name of person being called */
1503 - char origcallednum[256]; /* Orignal number of person being called */
1504 + char origcallednum[256]; /* Orignal number of person being called */
1506 - int useruserprotocoldisc;
1507 + int useruserprotocoldisc;
1508 char useruserinfo[256];
1509 char callingsubaddr[256]; /* Calling parties sub address */
1511 + char callid[10]; /* call identity for SUSPEND/RESUME */
1512 + char digits[256]; /* additional digits received via info msgs (cpn or keypad) */
1513 + char display[256]; /* display ie received in info msgs or for sending */
1515 + /* euroisdn facility fun */
1516 + int facility; /* FACILTIY received */
1519 long aoc_units; /* Advice of Charge Units */
1521 + char llc[16]; /* low layer compatibility */
1522 struct apdu_event *apdus; /* APDU queue for call */
1525 extern int pri_schedule_event(struct pri *pri, int ms, void (*function)(void *data), void *data);
1526 +extern int pri_schedule_event2(struct pri *pri, int ms, void (*function)(void *data, int data2), void *data, int data2);
1528 extern pri_event *pri_schedule_run(struct pri *pri);
1531 extern pri_event *pri_mkerror(struct pri *pri, char *errstr);
1533 extern void pri_message(struct pri *pri, char *fmt, ...);
1536 extern void pri_error(struct pri *pri, char *fmt, ...);
1538 void libpri_copy_string(char *dst, const char *src, size_t size);
1539 diff -urN libpri-1.2.3.orig/pri_q921.h libpri-1.2.3/pri_q921.h
1540 --- libpri-1.2.3.orig/pri_q921.h 2005-11-29 19:39:18.000000000 +0100
1541 +++ libpri-1.2.3/pri_q921.h 2006-04-15 21:57:24.000000000 +0200
1544 * Copyright (C) 2001, Linux Support Services, Inc.
1545 * All Rights Reserved.
1546 + * Copyright (C) 2003-2006 Junghanns.NET GmbH
1547 + * Klaus-Peter Junghanns <kpj@junghanns.net>
1549 * This program is free software; you can redistribute it and/or modify
1550 * it under the terms of the GNU General Public License as published by
1552 #define Q921_FRAMETYPE_S 0x1
1554 #define Q921_TEI_GROUP 127
1555 +#define Q921_TEI_ID_REQUEST 0x1
1556 +#define Q921_TEI_ID_ASSIGNED 0x2
1557 +#define Q921_TEI_ID_DENIED 0x3
1558 +#define Q921_TEI_ID_CHK_REQ 0x4
1559 +#define Q921_TEI_ID_CHK_RES 0x5
1560 +#define Q921_TEI_ID_REMOVE 0x6
1561 +#define Q921_TEI_ID_VERIFY 0x7
1562 #define Q921_TEI_GR303_EOC_PATH 0
1563 #define Q921_TEI_GR303_EOC_OPS 4
1564 #define Q921_TEI_GR303_TMC_SWITCHING 0
1565 @@ -164,12 +173,14 @@
1566 extern void q921_dump(struct pri *pri, q921_h *h, int len, int showraw, int txrx);
1568 /* Bring up the D-channel */
1569 -extern void q921_start(struct pri *pri, int now);
1570 +extern void q921_start(struct pri *pri, int now, int tei);
1572 -extern void q921_reset(struct pri *pri);
1573 +extern void q921_reset(struct pri *pri, int tei, int discard);
1575 extern pri_event *q921_receive(struct pri *pri, q921_h *h, int len);
1577 -extern int q921_transmit_iframe(struct pri *pri, void *buf, int len, int cr);
1578 +extern int q921_transmit_uframe(struct pri *pri, void *buf, int len, int cr, int tei);
1580 +extern int q921_transmit_iframe(struct pri *pri, void *buf, int len, int cr, int tei);
1583 diff -urN libpri-1.2.3.orig/pri_q931.h libpri-1.2.3/pri_q931.h
1584 --- libpri-1.2.3.orig/pri_q931.h 2005-11-29 19:39:18.000000000 +0100
1585 +++ libpri-1.2.3/pri_q931.h 2006-04-15 21:57:29.000000000 +0200
1588 * Copyright (C) 2001, Linux Support Services, Inc.
1589 * All Rights Reserved.
1590 + * Copyright (C) 2003-2006 Junghanns.NET GmbH
1591 + * Klaus-Peter Junghanns <kpj@junghanns.net>
1593 * This program is free software; you can redistribute it and/or modify
1594 * it under the terms of the GNU General Public License as published by
1595 @@ -190,6 +192,10 @@
1596 #define Q931_IE_CODESET(x) ((x) >> 8)
1597 #define Q931_IE_IE(x) ((x) & 0xff)
1598 #define Q931_FULL_IE(codeset, ie) (((codeset) << 8) | ((ie) & 0xff))
1599 +#define Q931_IE_MAX_LEN 257
1602 +#define Q931_COLP 0x4c
1604 #define Q931_DISPLAY 0x28
1605 #define Q931_IE_SEGMENTED_MSG 0x00
1607 #define Q931_IE_USER_USER 0x7E
1608 #define Q931_IE_ESCAPE_FOR_EXT 0x7F
1610 +#define Q931_IE_SPECIAL 0x02
1613 /* Call state stuff */
1614 #define Q931_CALL_STATE_NULL 0
1617 #define Q931_SENDING_COMPLETE 0xa1
1619 -extern int q931_receive(struct pri *pri, q931_h *h, int len);
1620 +extern int q931_receive(struct pri *pri, q931_h *h, int len, int tei);
1622 extern int q931_alerting(struct pri *pri, q931_call *call, int channel, int info);
1624 @@ -257,6 +265,10 @@
1626 extern int q931_information(struct pri *pri, q931_call *call, char digit);
1628 +extern int q931_information_display(struct pri *pri, q931_call *call, char *display);
1630 +extern int q931_add_display(struct pri *pri, q931_call *call, char *display);
1632 extern int q931_connect(struct pri *pri, q931_call *call, int channel, int nonisdn);
1634 extern int q931_release(struct pri *pri, q931_call *call, int cause);
1635 @@ -265,6 +277,10 @@
1637 extern int q931_hangup(struct pri *pri, q931_call *call, int cause);
1639 +extern int q921_hangup(struct pri *pri, q931_call *c, int tei);
1641 +extern int q921_handle_hangup(struct pri *pri, q931_call *c, int tei);
1643 extern int q931_restart(struct pri *pri, int channel);
1645 extern int q931_facility(struct pri *pri, q931_call *call);
1646 @@ -279,5 +295,23 @@
1647 extern void q931_dump(struct pri *pri, q931_h *h, int len, int txrx);
1649 extern void __q931_destroycall(struct pri *pri, q931_call *c);
1651 +extern int q931_hold_acknowledge(struct pri *pri, q931_call *c);
1653 +extern int q931_hold_reject(struct pri *pri, q931_call *c);
1655 +extern int q931_retrieve_acknowledge(struct pri *pri, q931_call *c, int channel);
1657 +extern int q931_retrieve_reject(struct pri *pri, q931_call *c);
1659 +extern int q931_suspend_acknowledge(struct pri *pri, q931_call *c, char *display);
1661 +extern int q931_suspend_reject(struct pri *pri, q931_call *c, char *display);
1663 +extern int q931_resume_reject(struct pri *pri, q931_call *c, char *display);
1665 +extern int q931_resume_acknowledge(struct pri *pri, q931_call *c, int channel, char *display);
1667 +//extern int q931_facility(struct pri *pri, q931_call *c, int operation, char *arguments);
1670 diff -urN libpri-1.2.3.orig/pri_timers.h libpri-1.2.3/pri_timers.h
1671 --- libpri-1.2.3.orig/pri_timers.h 2005-11-29 19:39:18.000000000 +0100
1672 +++ libpri-1.2.3/pri_timers.h 2006-01-18 12:28:07.000000000 +0100
1675 /* -1 means we dont currently support the timer/counter */
1676 #define PRI_TIMERS_DEFAULT { 3, /* N200 */ \
1685 + 2000, /* T201 */ \
1686 + 5000, /* T202 */ \
1692 + 4000, /* T303 */ \
1696 diff -urN libpri-1.2.3.orig/pridump.c libpri-1.2.3/pridump.c
1697 --- libpri-1.2.3.orig/pridump.c 2005-11-29 19:39:18.000000000 +0100
1698 +++ libpri-1.2.3/pridump.c 2006-01-18 12:28:07.000000000 +0100
1701 * libpri: An implementation of Primary Rate ISDN
1703 - * Written by Mark Spencer <markster@digium.com>
1704 + * Written by Mark Spencer <markster@linux-support.net>
1706 - * Copyright (C) 2001-2005, Digium
1707 + * Copyright (C) 2001, Linux Support Services, Inc.
1708 * All Rights Reserved.
1710 * This program is free software; you can redistribute it and/or modify
1711 diff -urN libpri-1.2.3.orig/prisched.c libpri-1.2.3/prisched.c
1712 --- libpri-1.2.3.orig/prisched.c 2005-11-29 19:39:18.000000000 +0100
1713 +++ libpri-1.2.3/prisched.c 2006-04-15 21:57:42.000000000 +0200
1716 * libpri: An implementation of Primary Rate ISDN
1718 - * Written by Mark Spencer <markster@digium.com>
1719 + * Written by Mark Spencer <markster@linux-support.net>
1721 - * Copyright (C) 2001-2005, Digium
1722 + * Copyright (C) 2001, Linux Support Services, Inc.
1723 * All Rights Reserved.
1724 + * Copyright (C) 2003-2006 Junghanns.NET GmbH
1725 + * Klaus-Peter Junghanns <kpj@junghanns.net>
1727 * This program is free software; you can redistribute it and/or modify
1728 * it under the terms of the GNU General Public License as published by
1736 #include "pri_internal.h"
1740 static int maxsched = 0;
1744 for (x=1;x<MAX_SCHED;x++)
1745 - if (!pri->pri_sched[x].callback)
1746 + if ((!pri->pri_sched[x].callback2) && (!pri->pri_sched[x].callback))
1748 if (x == MAX_SCHED) {
1749 pri_error(pri, "No more room in scheduler\n");
1752 pri->pri_sched[x].when = tv;
1753 pri->pri_sched[x].callback = function;
1754 + pri->pri_sched[x].callback2 = NULL;
1755 pri->pri_sched[x].data = data;
1756 + pri->pri_sched[x].hasdata2 = 0;
1757 + pri->pri_sched[x].data2 = 0;
1761 +int pri_schedule_event2(struct pri *pri, int ms, void (*function)(void *data, int data2), void *data, int data2)
1764 + struct timeval tv;
1765 + for (x=1;x<MAX_SCHED;x++)
1766 + if ((!pri->pri_sched[x].callback2) && (!pri->pri_sched[x].callback))
1768 + if (x == MAX_SCHED) {
1769 + pri_error(pri, "No more room in scheduler\n");
1774 + gettimeofday(&tv, NULL);
1775 + tv.tv_sec += ms / 1000;
1776 + tv.tv_usec += (ms % 1000) * 1000;
1777 + if (tv.tv_usec > 1000000) {
1778 + tv.tv_usec -= 1000000;
1781 + pri->pri_sched[x].when = tv;
1782 + pri->pri_sched[x].callback = NULL;
1783 + pri->pri_sched[x].callback2 = function;
1784 + pri->pri_sched[x].data = data;
1785 + pri->pri_sched[x].hasdata2 = 1;
1786 + pri->pri_sched[x].data2 = data2;
1791 if (pri->subchannel)
1792 closest = pri_schedule_next(pri->subchannel);
1793 for (x=1;x<MAX_SCHED;x++) {
1794 - if (pri->pri_sched[x].callback &&
1795 + if ((pri->pri_sched[x].callback || pri->pri_sched[x].callback2) &&
1796 (!closest || (closest->tv_sec > pri->pri_sched[x].when.tv_sec) ||
1797 ((closest->tv_sec == pri->pri_sched[x].when.tv_sec) &&
1798 (closest->tv_usec > pri->pri_sched[x].when.tv_usec))))
1799 @@ -76,26 +109,38 @@
1801 static pri_event *__pri_schedule_run(struct pri *pri, struct timeval *tv)
1804 - void (*callback)(void *);
1807 + void (*callback)(void *);
1808 + void (*callback2)(void *, int);
1813 if (pri->subchannel) {
1814 if ((e = __pri_schedule_run(pri->subchannel, tv))) {
1818 for (x=1;x<MAX_SCHED;x++) {
1819 - if (pri->pri_sched[x].callback &&
1820 + if ((pri->pri_sched[x].callback || pri->pri_sched[x].callback2) &&
1821 ((pri->pri_sched[x].when.tv_sec < tv->tv_sec) ||
1822 ((pri->pri_sched[x].when.tv_sec == tv->tv_sec) &&
1823 (pri->pri_sched[x].when.tv_usec <= tv->tv_usec)))) {
1825 callback = pri->pri_sched[x].callback;
1826 + callback2 = pri->pri_sched[x].callback2;
1827 data = pri->pri_sched[x].data;
1828 + data2 = pri->pri_sched[x].data2;
1829 pri->pri_sched[x].callback = NULL;
1830 + pri->pri_sched[x].callback2 = NULL;
1831 pri->pri_sched[x].data = NULL;
1833 + pri->pri_sched[x].data2 = 0;
1834 + if (pri->pri_sched[x].hasdata2 == 1) {
1835 + pri->pri_sched[x].hasdata2 = 0;
1836 + callback2(data, data2);
1844 if ((id >= MAX_SCHED) || (id < 0))
1845 pri_error(pri, "Asked to delete sched id %d???\n", id);
1846 pri->pri_sched[id].callback = NULL;
1847 + pri->pri_sched[id].callback2 = NULL;
1850 diff -urN libpri-1.2.3.orig/pritest.c libpri-1.2.3/pritest.c
1851 --- libpri-1.2.3.orig/pritest.c 2005-11-29 19:39:18.000000000 +0100
1852 +++ libpri-1.2.3/pritest.c 2006-01-18 12:28:07.000000000 +0100
1855 * libpri: An implementation of Primary Rate ISDN
1857 - * Written by Mark Spencer <markster@digium.com>
1858 + * Written by Mark Spencer <markster@linux-support.net>
1860 - * Copyright (C) 2001-2005, Digium
1861 + * Copyright (C) 2001, Linux Support Services, Inc.
1862 * All Rights Reserved.
1864 * This program is free software; you can redistribute it and/or modify
1866 #define PRI_DEF_NODETYPE PRI_CPE
1867 #define PRI_DEF_SWITCHTYPE PRI_SWITCH_NI2
1869 -#define MAX_CHAN 32
1870 -#define DCHANNEL_TIMESLOT 16
1872 +#define DCHANNEL_TIMESLOT 3
1875 static int offset = 0;
1877 static void do_channel(ZAP *z)
1879 /* This is the part that runs on a given channel */
1880 - zap_playf(z, "raw.ulaw", 0);
1881 + zap_playf(z, "raw.alaw", 0);
1887 if (!strcasecmp(node, "network"))
1889 + if (!strcasecmp(node, "bri_cpe_ptmp"))
1890 + return BRI_CPE_PTMP;
1891 + if (!strcasecmp(node, "bri_network_ptmp"))
1892 + return BRI_NETWORK_PTMP;
1893 + if (!strcasecmp(node, "bri_cpe"))
1895 + if (!strcasecmp(node, "bri_network"))
1896 + return BRI_NETWORK;
1900 @@ -285,6 +293,10 @@
1904 + case PRI_EVENT_HANGUP_REQ:
1905 + printf("-- Hanging up channel %d\n", e->hangup.channel);
1906 + hangup_channel(e->hangup.channel);
1909 fprintf(stderr, "--!! Unknown PRI event %d\n", e->e);
1911 diff -urN libpri-1.2.3.orig/q921.c libpri-1.2.3/q921.c
1912 --- libpri-1.2.3.orig/q921.c 2005-12-06 22:35:50.000000000 +0100
1913 +++ libpri-1.2.3/q921.c 2006-06-15 14:55:46.000000000 +0200
1916 * libpri: An implementation of Primary Rate ISDN
1918 - * Written by Mark Spencer <markster@digium.com>
1919 + * Written by Mark Spencer <markster@linux-support.net>
1921 - * Copyright (C) 2001-2005, Digium
1922 + * Copyright (C) 2001, Linux Support Services, Inc.
1923 * All Rights Reserved.
1924 + * Copyright (C) 2003-2006 Junghanns.NET GmbH
1925 + * Klaus-Peter Junghanns <kpj@junghanns.net>
1927 * This program is free software; you can redistribute it and/or modify
1928 * it under the terms of the GNU General Public License as published by
1930 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1939 (hf).h.tei = (pri)->tei; \
1942 -static void reschedule_t203(struct pri *pri);
1943 +static void reschedule_t203(struct pri *pri, int tei);
1944 +static void q921_flush_txqueue(struct pri *pri, int tei, int devnull);
1946 -static void q921_discard_retransmissions(struct pri *pri)
1947 +static void q921_discard_retransmissions(struct pri *pri, int tei)
1949 struct q921_frame *f, *p;
1951 + int teio = tei - Q921_TEI_BASE;
1952 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
1954 + f = pri->txqueue[teio];
1965 - pri->txqueue = NULL;
1966 + pri->txqueue[teio] = NULL;
1969 static int q921_transmit(struct pri *pri, q921_h *h, int len)
1971 pri_error(pri, "Short write: %d/%d (%s)\n", res, len + 2, strerror(errno));
1974 - reschedule_t203(pri);
1975 + if (pri->localtype == BRI_CPE_PTMP) {
1976 + reschedule_t203(pri, pri->tei);
1977 + } else if (h->h.tei != Q921_TEI_GROUP) {
1978 + reschedule_t203(pri, h->h.tei);
1983 -static void q921_send_ua(struct pri *pri, int pfbit)
1984 +static void q921_send_ua(struct pri *pri, int pfbit, int tei)
1989 h.u.m2 = 0; /* M2 = 0 */
1990 h.u.p_f = pfbit; /* Final bit on */
1991 h.u.ft = Q921_FRAMETYPE_U;
1993 switch(pri->localtype) {
1996 @@ -107,6 +118,19 @@
2000 + case BRI_NETWORK_PTMP:
2003 + case BRI_CPE_PTMP:
2004 + h.h.tei = pri->tei;
2014 pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype);
2016 @@ -116,18 +140,359 @@
2017 q921_transmit(pri, &h, 3);
2020 -static void q921_send_sabme_now(void *vpri);
2022 +static void q921_send_disconnect(struct pri *pri, int pfbit, int tei) {
2024 + Q921_INIT(pri, h);
2028 + h.u.ft = Q921_FRAMETYPE_U;
2030 + switch(pri->localtype) {
2037 + case BRI_NETWORK_PTMP:
2040 + case BRI_CPE_PTMP:
2041 + h.h.tei = pri->tei;
2051 + pri_error(pri, "Don't know how to disconnect on a type %d node\n", pri->localtype);
2054 + if (pri->debug & PRI_DEBUG_Q921_STATE)
2055 + pri_message(pri, "Sending Disconnect\n");
2056 + q921_transmit(pri, &h, 3);
2060 -static void q921_send_sabme(void *vpri, int now)
2061 +static void q921_send_dm(struct pri *pri, int pfbit, int tei)
2064 + Q921_INIT(pri, h);
2065 + h.u.m3 = 0; /* M3 = 0 */
2066 + h.u.m2 = 3; /* M2 = 3 */
2067 + h.u.p_f = pfbit; /* Final bit on */
2068 + h.u.ft = Q921_FRAMETYPE_U;
2070 + switch(pri->localtype) {
2077 + case BRI_NETWORK_PTMP:
2080 + case BRI_CPE_PTMP:
2081 + h.h.tei = pri->tei;
2091 + pri_error(pri, "Don't know how to DM on a type %d node\n", pri->localtype);
2094 + if (pri->debug & PRI_DEBUG_Q921_STATE)
2095 + pri_message(pri, "Sending DM\n");
2096 + q921_transmit(pri, &h, 3);
2099 +static void q921_send_teireq(void *vpri) {
2100 + struct pri *pri = vpri;
2101 + unsigned short ri=0x6464;
2105 + if (pri->localtype != BRI_CPE_PTMP) {
2106 + pri_error(pri, "TEI req for non-ptmp???\n");
2109 + if (pri->t202_timer[0]) {
2110 + pri_schedule_del(pri, pri->t202_timer[0]);
2111 + pri->t202_timer[0] = 0;
2113 + if (pri->sabme_retrans[0]++ > (pri->timers[PRI_TIMER_N202])) {
2114 + /* delete txqueue */
2115 + q921_flush_txqueue(pri, 0, 1);
2116 + /* N202 retransmissions, activation of layer 2 failed, tell upper layer, start again */
2118 + pri->ev.gen.e = PRI_EVENT_DCHAN_DOWN;
2119 + pri->ev.gen.tei = 0;
2120 + pri->sabme_retrans[0] = 0;
2121 + /* dont try again, they are gone */
2125 + pri->t202_timer[0] = pri_schedule_event(pri, pri->timers[PRI_TIMER_T202], q921_send_teireq, pri);
2128 + f = malloc(sizeof(q921_u) + 5 + 2);
2129 + memset(f,0x0,sizeof(q921_u) + 5 + 2);
2131 + f->h.sapi = Q921_SAPI_LAYER2_MANAGEMENT;
2132 + f->h.tei = Q921_TEI_GROUP;
2138 + f->ft = Q921_FRAMETYPE_U;
2140 + f->data[1] = ri >> 8;
2141 + f->data[2] = ri & 0xff;
2142 + f->data[3] = Q921_TEI_ID_REQUEST;
2143 + f->data[4] = 0xff;
2144 + if (pri->debug & PRI_DEBUG_Q921_STATE)
2145 + pri_message(pri, "Sending TEI Request ri=%d\n",ri);
2146 + q921_transmit(pri,(q921_h *)&(f->h),8);
2150 +static void q921_send_teiassign(struct pri *pri,int ri,int tei) {
2153 + if (pri->localtype != BRI_NETWORK_PTMP) {
2154 + pri_error(pri, "TEI assign for non-ptmp???\n");
2158 + f = malloc(sizeof(q921_u) + 5 + 2);
2159 + memset(f,0x0,sizeof(q921_u) + 5 + 2);
2161 + f->h.sapi = Q921_SAPI_LAYER2_MANAGEMENT;
2162 + f->h.tei = Q921_TEI_GROUP;
2168 + f->ft = Q921_FRAMETYPE_U;
2170 + f->data[1] = ri >> 8;
2171 + f->data[2] = ri & 0xff;
2172 + f->data[3] = Q921_TEI_ID_ASSIGNED;
2173 + f->data[4] = (tei << 1) | 0x1;
2174 + if (pri->debug & PRI_DEBUG_Q921_STATE)
2175 + pri_message(pri, "Sending TEI assign ri=%d tei=%d\n",ri,tei);
2176 + q921_transmit(pri,(q921_h *)&(f->h),8);
2179 + pri_error(pri, "q921_send_teiassign: failed to malloc f!\n");
2183 +static void q921_send_teichkresp(struct pri *pri,int tei) {
2185 + unsigned short ri=0x6464;
2188 + if (pri->localtype != BRI_CPE_PTMP) {
2189 + pri_error(pri, "TEI check response for non-ptmp???\n");
2193 + f = malloc(sizeof(q921_u) + 5 + 2);
2194 + memset(f,0x0,sizeof(q921_u) + 5 + 2);
2196 + f->h.sapi = Q921_SAPI_LAYER2_MANAGEMENT;
2197 + f->h.tei = Q921_TEI_GROUP;
2198 + f->h.c_r = 0; // command u->n
2203 + f->ft = Q921_FRAMETYPE_U;
2205 + f->data[1] = ri >> 8;
2206 + f->data[2] = ri & 0xff;
2207 + f->data[3] = Q921_TEI_ID_CHK_RES;
2208 + f->data[4] = (tei << 1) | 0x1;
2209 + if (pri->debug & PRI_DEBUG_Q921_STATE)
2210 + pri_message(pri, "Sending TEI check resp ri=%d tei=%d\n",ri,tei);
2211 + q921_transmit(pri,(q921_h *)&(f->h),8);
2216 +static void q921_send_teichkreq(struct pri *pri,int tei) {
2218 + unsigned short ri=0x6464;
2221 + if (pri->localtype != BRI_NETWORK_PTMP) {
2222 + pri_error(pri, "TEI check response for non-ptmp???\n");
2226 + f = malloc(sizeof(q921_u) + 5 + 2);
2227 + memset(f,0x0,sizeof(q921_u) + 5 + 2);
2229 + f->h.sapi = Q921_SAPI_LAYER2_MANAGEMENT;
2230 + f->h.tei = Q921_TEI_GROUP;
2231 + f->h.c_r = 1; // command u->n
2236 + f->ft = Q921_FRAMETYPE_U;
2240 + f->data[3] = Q921_TEI_ID_CHK_REQ;
2241 + f->data[4] = (tei << 1) | 0x1;
2242 + if (pri->debug & PRI_DEBUG_Q921_STATE)
2243 + pri_message(pri, "Sending TEI check request ri=%d tei=%d\n",ri,tei);
2244 + q921_transmit(pri,(q921_h *)&(f->h),8);
2249 +static void q921_send_teiverify(struct pri *pri,int tei) {
2252 + if ((pri->localtype != BRI_CPE) && (pri->localtype != BRI_CPE_PTMP)) {
2253 + pri_error(pri, "TEI verify for non-ptmp???\n");
2257 + f = malloc(sizeof(q921_u) + 5 + 2);
2258 + memset(f,0x0,sizeof(q921_u) + 5 + 2);
2260 + f->h.sapi = Q921_SAPI_LAYER2_MANAGEMENT;
2261 + f->h.tei = Q921_TEI_GROUP;
2262 + f->h.c_r = 0; // command u->n
2267 + f->ft = Q921_FRAMETYPE_U;
2271 + f->data[3] = Q921_TEI_ID_VERIFY;
2272 + f->data[4] = (tei << 1) | 0x1;
2273 + if (pri->debug & PRI_DEBUG_Q921_STATE)
2274 + pri_message(pri, "Sending TEI verify tei=%d\n", tei);
2275 + q921_transmit(pri,(q921_h *)&(f->h),8);
2280 + static void q921_send_teiremove(struct pri *pri, int tei) {
2282 + unsigned short ri=0x6464;
2285 + if (pri->localtype != BRI_NETWORK_PTMP) {
2286 + pri_error(pri, "TEI remove for non-ptmp???\n");
2290 + f = malloc(sizeof(q921_u) + 5 + 2);
2291 + memset(f,0x0,sizeof(q921_u) + 5 + 2);
2293 + f->h.sapi = Q921_SAPI_LAYER2_MANAGEMENT;
2294 + f->h.tei = Q921_TEI_GROUP;
2300 + f->ft = Q921_FRAMETYPE_U;
2302 + f->data[1] = ri >> 8;
2303 + f->data[2] = ri & 0xff;
2304 + f->data[3] = Q921_TEI_ID_REMOVE;
2305 + f->data[4] = (tei << 1) | 0x1;
2306 + if (pri->debug & PRI_DEBUG_Q921_STATE)
2307 + pri_message(pri, "Sending TEI remove tei=%d\n",tei);
2308 + q921_transmit(pri,(q921_h *)&(f->h),8);
2313 + static void q921_send_teidenied(struct pri *pri, int ri, int tei) {
2316 + if (pri->localtype != BRI_NETWORK_PTMP) {
2317 + pri_error(pri, "TEI ID denied for non-ptmp???\n");
2321 + f = malloc(sizeof(q921_u) + 5 + 2);
2322 + memset(f,0x0,sizeof(q921_u) + 5 + 2);
2324 + f->h.sapi = Q921_SAPI_LAYER2_MANAGEMENT;
2325 + f->h.tei = Q921_TEI_GROUP;
2331 + f->ft = Q921_FRAMETYPE_U;
2333 + f->data[1] = ri >> 8;
2334 + f->data[2] = ri & 0xff;
2335 + f->data[3] = Q921_TEI_ID_DENIED;
2336 + f->data[4] = (tei << 1) | 0x1;
2337 + if (pri->debug & PRI_DEBUG_Q921_STATE)
2338 + pri_message(pri, "Sending TEI ID denied tei=%d\n",tei);
2339 + q921_transmit(pri,(q921_h *)&(f->h),8);
2345 +static void q921_send_sabme_now(void *vpri, int tei);
2347 +static void q921_send_sabme(void *vpri, int now, int tei)
2349 struct pri *pri = vpri;
2351 - pri_schedule_del(pri, pri->sabme_timer);
2352 - pri->sabme_timer = 0;
2353 - pri->sabme_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], q921_send_sabme_now, pri);
2354 + int teio=tei - Q921_TEI_BASE;
2355 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
2357 + if (pri->sabme_timer[teio]) {
2358 + pri_schedule_del(pri, pri->sabme_timer[teio]);
2359 + pri->sabme_timer[teio] = 0;
2361 + pri->sabme_timer[teio] = pri_schedule_event2(pri, pri->timers[PRI_TIMER_T200], q921_send_sabme_now, pri, tei);
2364 + if (pri->sabme_retrans[teio]++ > (pri->timers[PRI_TIMER_N202])) {
2365 + /* delete txqueue */
2366 + q921_flush_txqueue(pri, tei, 1);
2367 + /* N202 retransmissions, activation of layer 2 failed, tell upper layer, start again */
2369 + pri->ev.gen.e = PRI_EVENT_DCHAN_DOWN;
2370 + pri->ev.gen.tei = tei;
2371 + pri->sabme_retrans[teio] = 0;
2372 + /* dont try again, they are gone */
2378 h.u.m3 = 3; /* M3 = 3 */
2379 h.u.m2 = 3; /* M2 = 3 */
2380 h.u.p_f = 1; /* Poll bit set */
2381 @@ -139,25 +504,42 @@
2385 + case BRI_NETWORK_PTMP:
2388 + case BRI_CPE_PTMP:
2390 + h.h.tei = pri->tei;
2399 - pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype);
2400 + pri_error(pri, "Don't know how to send SABME on a type %d node\n", pri->localtype);
2403 if (pri->debug & PRI_DEBUG_Q921_STATE)
2404 pri_message(pri, "Sending Set Asynchronous Balanced Mode Extended\n");
2405 q921_transmit(pri, &h, 3);
2406 - pri->q921_state = Q921_AWAITING_ESTABLISH;
2407 + pri->q921_state[teio] = Q921_AWAITING_ESTABLISH;
2410 -static void q921_send_sabme_now(void *vpri)
2411 +static void q921_send_sabme_now(void *vpri, int tei)
2413 - q921_send_sabme(vpri, 1);
2414 + q921_send_sabme(vpri, 1, tei);
2417 -static int q921_ack_packet(struct pri *pri, int num)
2420 +static int q921_ack_packet(struct pri *pri, int num, int tei)
2422 struct q921_frame *f, *prev = NULL;
2424 + int teio=tei - Q921_TEI_BASE;
2425 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
2426 + f = pri->txqueue[teio];
2428 if (f->h.n_s == num) {
2429 /* Cancel each packet as necessary */
2430 @@ -165,26 +547,26 @@
2432 prev->next = f->next;
2434 - pri->txqueue = f->next;
2435 + pri->txqueue[teio] = f->next;
2436 if (pri->debug & PRI_DEBUG_Q921_STATE)
2437 - pri_message(pri, "-- ACKing packet %d, new txqueue is %d (-1 means empty)\n", f->h.n_s, pri->txqueue ? pri->txqueue->h.n_s : -1);
2438 + pri_message(pri, "-- ACKing packet %d, new txqueue is %d (-1 means empty)\n", f->h.n_s, pri->txqueue[teio] ? pri->txqueue[teio]->h.n_s : -1);
2441 + pri->v_a[teio] = num;
2443 /* Reset retransmission counter if we actually acked something */
2445 + pri->retrans[teio] = 0;
2446 /* Decrement window size */
2448 + pri->windowlen[teio]--;
2449 /* Search for something to send */
2451 + f = pri->txqueue[teio];
2453 if (!f->transmitted) {
2454 /* Send it now... */
2455 if (pri->debug & PRI_DEBUG_Q921_STATE)
2456 pri_message(pri, "-- Finally transmitting %d, since window opened up\n", f->h.n_s);
2459 - f->h.n_r = pri->v_r;
2460 + pri->windowlen[teio]++;
2461 + f->h.n_r = pri->v_r[teio];
2462 q921_transmit(pri, (q921_h *)(&f->h), f->len);
2465 @@ -198,77 +580,136 @@
2469 -static void t203_expire(void *);
2470 -static void t200_expire(void *);
2471 -static pri_event *q921_dchannel_down(struct pri *pri);
2472 +static void t203_expire(void *, int tei);
2473 +static void t200_expire(void *, int tei);
2474 +static pri_event *q921_dchannel_down(struct pri *pri, int tei);
2476 +static void reschedule_t203(struct pri *pri, int tei)
2478 + int teio=tei - Q921_TEI_BASE;
2479 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
2480 + if (pri->t203_timer[teio]) {
2481 + pri_schedule_del(pri, pri->t203_timer[teio]);
2482 + pri->t203_timer[teio] = 0;
2483 + if (pri->q921_state[teio] != Q921_LINK_CONNECTION_RELEASED) {
2484 + if (pri->debug & PRI_DEBUG_Q921_STATE)
2485 + pri_message(pri, "-- Restarting T203 counter\n");
2486 + /* Nothing to transmit, start the T203 counter instead */
2487 + pri->t203_timer[teio] = pri_schedule_event2(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri, tei);
2492 -static void reschedule_t203(struct pri *pri)
2493 +static void q921_flush_txqueue(struct pri *pri, int tei, int devnull)
2495 - if (pri->t203_timer) {
2496 - pri_schedule_del(pri, pri->t203_timer);
2497 - if (pri->debug & PRI_DEBUG_Q921_STATE)
2498 - pri_message(pri, "-- Restarting T203 counter\n");
2499 - /* Nothing to transmit, start the T203 counter instead */
2500 - pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri);
2501 + struct q921_frame *f, *tmp = NULL;
2502 + int teio=tei - Q921_TEI_BASE;
2503 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
2504 + f = pri->txqueue[teio];
2506 + /* nothing to send */
2509 + /* transmit all i-frames that were queued up while we were waiting for layer 2 to rise */
2517 + if (pri->localtype == BRI_CPE_PTMP) {
2518 + /* update TEI, it might have changed */
2519 + f->h.h.tei = pri->tei;
2521 + q921_transmit(pri, (q921_h *)&f->h, f->len);
2528 + pri->txqueue[teio] = NULL;
2529 + pri->v_s[teio] = 0;
2531 + if (pri->t200_timer[teio]) {
2532 + pri_schedule_del(pri, pri->t200_timer[teio]);
2533 + pri->t200_timer[teio] = 0;
2535 + if (pri->t203_timer[teio]) {
2536 + pri_schedule_del(pri, pri->t203_timer[teio]);
2537 + pri->t203_timer[teio] = 0;
2539 + pri->t200_timer[teio] = pri_schedule_event2(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri, tei);
2543 -static pri_event *q921_ack_rx(struct pri *pri, int ack)
2544 +static pri_event *q921_ack_rx(struct pri *pri, int ack, int tei)
2549 + int teio=tei - Q921_TEI_BASE;
2550 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
2551 /* Make sure the ACK was within our window */
2552 - for (x=pri->v_a; (x != pri->v_s) && (x != ack); Q921_INC(x));
2553 + for (x=pri->v_a[teio]; (x != pri->v_s[teio]) && (x != ack); Q921_INC(x));
2555 /* ACK was outside of our window --- ignore */
2556 - pri_error(pri, "ACK received for '%d' outside of window of '%d' to '%d', restarting\n", ack, pri->v_a, pri->v_s);
2557 - ev = q921_dchannel_down(pri);
2558 - q921_start(pri, 1);
2559 + pri_error(pri, "ACK received for '%d' outside of window of '%d' to '%d', restarting\n", ack, pri->v_a[teio], pri->v_s[teio]);
2560 + ev = q921_dchannel_down(pri, tei);
2561 + q921_start(pri, 1, tei);
2565 /* Cancel each packet as necessary */
2566 if (pri->debug & PRI_DEBUG_Q921_STATE)
2567 - pri_message(pri, "-- ACKing all packets from %d to (but not including) %d\n", pri->v_a, ack);
2568 - for (x=pri->v_a; x != ack; Q921_INC(x))
2569 - cnt += q921_ack_packet(pri, x);
2570 - if (!pri->txqueue) {
2571 + pri_message(pri, "-- ACKing all packets from %d to (but not including) %d\n", pri->v_a[teio], ack);
2572 + for (x=pri->v_a[teio]; x != ack; Q921_INC(x))
2573 + cnt += q921_ack_packet(pri, x, tei);
2574 + if (!pri->txqueue[teio]) {
2575 + /* Something was ACK'd. Stop T200 counter */
2576 + if (pri->t200_timer[teio]) {
2577 + pri_schedule_del(pri, pri->t200_timer[teio]);
2578 + pri->t200_timer[teio] = 0;
2580 if (pri->debug & PRI_DEBUG_Q921_STATE)
2581 pri_message(pri, "-- Since there was nothing left, stopping T200 counter\n");
2582 - /* Something was ACK'd. Stop T200 counter */
2583 - pri_schedule_del(pri, pri->t200_timer);
2584 - pri->t200_timer = 0;
2586 - if (pri->t203_timer) {
2587 + if (pri->t203_timer[teio]) {
2588 + pri_schedule_del(pri, pri->t203_timer[teio]);
2589 + pri->t203_timer[teio] = 0;
2590 if (pri->debug & PRI_DEBUG_Q921_STATE)
2591 pri_message(pri, "-- Stopping T203 counter since we got an ACK\n");
2592 - pri_schedule_del(pri, pri->t203_timer);
2593 - pri->t203_timer = 0;
2595 - if (pri->txqueue) {
2596 + if (pri->txqueue[teio]) {
2597 /* Something left to transmit, Start the T200 counter again if we stopped it */
2598 + if (pri->t200_timer[teio]) {
2599 + pri_schedule_del(pri, pri->t200_timer[teio]);
2600 + pri->t200_timer[teio] = 0;
2602 if (pri->debug & PRI_DEBUG_Q921_STATE)
2603 - pri_message(pri, "-- Something left to transmit (%d), restarting T200 counter\n", pri->txqueue->h.n_s);
2604 - if (!pri->t200_timer)
2605 - pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
2606 + pri_message(pri, "-- Something left to transmit (%d), restarting T200 counter\n", pri->txqueue[teio]->h.n_s);
2607 + pri->t200_timer[teio] = pri_schedule_event2(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri, tei);
2610 if (pri->debug & PRI_DEBUG_Q921_STATE)
2611 pri_message(pri, "-- Nothing left, starting T203 counter\n");
2612 /* Nothing to transmit, start the T203 counter instead */
2613 - pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri);
2614 + pri->t203_timer[teio] = pri_schedule_event2(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri, tei);
2619 -static void q921_reject(struct pri *pri, int pf)
2620 +static void q921_reject(struct pri *pri, int pf, int tei)
2623 + int teio=tei - Q921_TEI_BASE;
2624 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
2626 h.s.x0 = 0; /* Always 0 */
2627 h.s.ss = 2; /* Reject */
2628 h.s.ft = 1; /* Frametype (01) */
2629 - h.s.n_r = pri->v_r; /* Where to start retransmission */
2630 + h.s.n_r = pri->v_r[teio]; /* Where to start retransmission */
2632 switch(pri->localtype) {
2634 @@ -277,23 +718,38 @@
2638 + case BRI_NETWORK_PTMP:
2641 + case BRI_CPE_PTMP:
2652 - pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype);
2653 + pri_error(pri, "Don't know how to REJECT on a type %d node\n", pri->localtype);
2656 if (pri->debug & PRI_DEBUG_Q921_STATE)
2657 - pri_message(pri, "Sending Reject (%d)\n", pri->v_r);
2659 + pri_message(pri, "Sending Reject (%d)\n", pri->v_r[teio]);
2660 + pri->sentrej[teio] = 1;
2661 q921_transmit(pri, &h, 4);
2664 -static void q921_rr(struct pri *pri, int pbit, int cmd) {
2665 +static void q921_rr(struct pri *pri, int pbit, int cmd, int tei) {
2667 + int teio=tei - Q921_TEI_BASE;
2668 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
2670 h.s.x0 = 0; /* Always 0 */
2671 h.s.ss = 0; /* Receive Ready */
2672 h.s.ft = 1; /* Frametype (01) */
2673 - h.s.n_r = pri->v_r; /* N/R */
2674 + h.s.n_r = pri->v_r[teio]; /* N/R */
2675 h.s.p_f = pbit; /* Poll/Final set appropriately */
2676 switch(pri->localtype) {
2678 @@ -308,81 +764,192 @@
2682 + case BRI_NETWORK_PTMP:
2689 + case BRI_CPE_PTMP:
2709 - pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype);
2710 + pri_error(pri, "Don't know how to RR on a type %d node\n", pri->localtype);
2713 - pri->v_na = pri->v_r; /* Make a note that we've already acked this */
2714 + pri->v_na[teio] = pri->v_r[teio]; /* Make a note that we've already acked this */
2715 if (pri->debug & PRI_DEBUG_Q921_STATE)
2716 - pri_message(pri, "Sending Receiver Ready (%d)\n", pri->v_r);
2717 + pri_message(pri, "Sending Receiver Ready (%d)\n", pri->v_r[teio]);
2718 q921_transmit(pri, &h, 4);
2721 -static void t200_expire(void *vpri)
2722 +static void t200_expire(void *vpri, int tei)
2724 struct pri *pri = vpri;
2725 - if (pri->txqueue) {
2726 + int teio=tei - Q921_TEI_BASE;
2727 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
2728 + if (pri->txqueue[teio]) {
2729 /* Retransmit first packet in the queue, setting the poll bit */
2730 if (pri->debug & PRI_DEBUG_Q921_STATE)
2731 pri_message(pri, "-- T200 counter expired, What to do...\n");
2732 - /* Force Poll bit */
2733 - pri->txqueue->h.p_f = 1;
2735 - pri->txqueue->h.n_r = pri->v_r;
2736 - pri->v_na = pri->v_r;
2737 - pri->solicitfbit = 1;
2739 + if (pri->txqueue[teio]->transmitted) {
2740 + /* Force Poll bit, if this is a retransmission */
2741 + pri->txqueue[teio]->h.p_f = 1;
2742 + pri->solicitfbit[teio] = 1;
2744 + pri->txqueue[teio]->h.n_r = pri->v_r[teio];
2745 + pri->v_na[teio] = pri->v_r[teio];
2746 + pri->retrans[teio]++;
2748 /* Up to three retransmissions */
2749 - if (pri->retrans < pri->timers[PRI_TIMER_N200]) {
2750 + if ((pri->retrans[teio] + 1) <= pri->timers[PRI_TIMER_N200]) {
2751 /* Reschedule t200_timer */
2752 if (pri->debug & PRI_DEBUG_Q921_STATE)
2753 - pri_message(pri, "-- Retransmitting %d bytes\n", pri->txqueue->len);
2755 - q921_rr(pri, 1, 1);
2757 - if (!pri->txqueue->transmitted)
2758 + pri_message(pri, "-- Retransmitting %d bytes\n", pri->txqueue[teio]->len);
2759 + if (pri->busy[teio]) {
2760 + // pri_message(pri, "-- q921_rr(pri, 1, 1) \n", tei);
2761 + q921_rr(pri, 1, 1, tei);
2763 + if (!pri->txqueue[teio]->transmitted)
2764 pri_error(pri, "!! Not good - head of queue has not been transmitted yet\n");
2765 - q921_transmit(pri, (q921_h *)&pri->txqueue->h, pri->txqueue->len);
2766 + q921_transmit(pri, (q921_h *)&pri->txqueue[teio]->h, pri->txqueue[teio]->len);
2768 + pri->txqueue[teio]->transmitted++;
2770 if (pri->debug & PRI_DEBUG_Q921_STATE)
2771 - pri_message(pri, "-- Rescheduling retransmission (%d)\n", pri->retrans);
2772 - pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
2773 + pri_message(pri, "-- Rescheduling retransmission (%d)\n", pri->retrans[teio]);
2774 + pri->t200_timer[teio] = pri_schedule_event2(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri, tei);
2776 if (pri->debug & PRI_DEBUG_Q921_STATE)
2777 pri_message(pri, "-- Timeout occured, restarting PRI\n");
2778 - pri->q921_state = Q921_LINK_CONNECTION_RELEASED;
2779 - pri->t200_timer = 0;
2780 - q921_dchannel_down(pri);
2781 - q921_start(pri, 1);
2782 + pri->q921_state[teio] = Q921_LINK_CONNECTION_RELEASED;
2783 + pri->t200_timer[teio] = 0;
2784 + q921_dchannel_down(pri, tei);
2785 + q921_start(pri, 1, tei);
2788 - } else if (pri->solicitfbit) {
2789 + } else if (pri->solicitfbit[teio]) {
2790 if (pri->debug & PRI_DEBUG_Q921_STATE)
2791 pri_message(pri, "-- Retrying poll with f-bit\n");
2793 - if (pri->retrans < pri->timers[PRI_TIMER_N200]) {
2794 - pri->solicitfbit = 1;
2795 - q921_rr(pri, 1, 1);
2796 - pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
2797 + pri->retrans[teio]++;
2798 + if (pri->retrans[teio] < pri->timers[PRI_TIMER_N200]) {
2799 + pri->solicitfbit[teio] = 1;
2800 + q921_rr(pri, 1, 1, tei);
2801 + pri->t200_timer[teio] = pri_schedule_event2(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri, tei);
2803 if (pri->debug & PRI_DEBUG_Q921_STATE)
2804 pri_message(pri, "-- Timeout occured, restarting PRI\n");
2805 - pri->q921_state = Q921_LINK_CONNECTION_RELEASED;
2806 - pri->t200_timer = 0;
2807 - q921_dchannel_down(pri);
2808 - q921_start(pri, 1);
2809 + pri->q921_state[teio] = Q921_LINK_CONNECTION_RELEASED;
2810 + pri->t200_timer[teio] = 0;
2811 + q921_dchannel_down(pri, tei);
2812 + q921_start(pri, 1, tei);
2816 pri_error(pri, "T200 counter expired, nothing to send...\n");
2817 - pri->t200_timer = 0;
2818 + pri->t200_timer[teio] = 0;
2819 + if (pri->busy[teio]) {
2820 + if ((pri->retrans[teio] + 1) <= pri->timers[PRI_TIMER_N200]) {
2822 + pri->t200_timer[teio] = pri_schedule_event2(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri, tei);
2823 + pri->retrans[teio]++;
2824 + q921_rr(pri, 1, 1, tei);
2826 + q921_reset(pri, tei, 1);
2827 + q921_start(pri, 1, tei);
2833 -int q921_transmit_iframe(struct pri *pri, void *buf, int len, int cr)
2834 +int q921_transmit_uframe(struct pri *pri, void *buf, int len, int cr, int tei)
2837 + uf = malloc(sizeof(q921_u) + len + 2);
2838 + memset(uf,0,sizeof(q921_u) + len + 2);
2846 + uf->ft = Q921_FRAMETYPE_U;
2847 + switch(pri->localtype) {
2854 + case BRI_NETWORK_PTMP:
2857 + case BRI_CPE_PTMP:
2867 + pri_error(pri, "Don't know how to send U frames on a type %d node\n", pri->localtype);
2870 + memcpy(uf->data,buf,len);
2871 + q921_transmit(pri, (q921_h*)&(uf->h), 3+len);
2877 +int q921_transmit_iframe(struct pri *pri, void *buf, int len, int cr, int tei)
2879 q921_frame *f, *prev=NULL;
2880 - for (f=pri->txqueue; f; f = f->next) prev = f;
2881 + int teio=tei - Q921_TEI_BASE;
2882 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
2883 + if ((pri->q921_state[teio] == Q921_LINK_CONNECTION_RELEASED) && (!pri->sabme_timer[teio])) {
2884 + if (pri->localtype == BRI_CPE_PTMP) {
2885 + if (pri->tei > 0) {
2886 + /* p2p datalink is down */
2887 + pri->sabme_retrans[teio] = 0;
2888 + q921_send_sabme_now(pri, pri->tei);
2889 + if (pri->debug & PRI_DEBUG_Q921_STATE)
2890 + pri_message(pri, "Reactivating layer 2\n");
2893 + if (pri->debug & PRI_DEBUG_Q921_STATE)
2894 + pri_message(pri, "reactivating layer 2, sending tei req\n");
2895 + q921_send_teireq(pri);
2897 + } else if ((pri->localtype == BRI_CPE) || (pri->localtype == BRI_NETWORK)) {
2898 + /* p2p datalink is down */
2899 + pri->sabme_retrans[teio] = 0;
2900 + q921_send_sabme_now(pri, pri->tei);
2901 + if (pri->debug & PRI_DEBUG_Q921_STATE)
2902 + pri_message(pri, "Reactivating layer 2\n");
2905 + for (f=pri->txqueue[teio]; f; f = f->next) prev = f;
2906 f = malloc(sizeof(q921_frame) + len + 2);
2908 memset(f,0,sizeof(q921_frame) + len + 2);
2909 @@ -400,47 +967,80 @@
2913 + case BRI_NETWORK_PTMP:
2920 + case BRI_CPE_PTMP:
2921 + f->h.h.tei = pri->tei;
2943 memcpy(f->h.data, buf, len);
2944 - f->h.n_s = pri->v_s;
2945 - f->h.n_r = pri->v_r;
2947 - pri->v_na = pri->v_r;
2948 + f->h.n_s = pri->v_s[teio];
2949 + f->h.n_r = pri->v_r[teio];
2951 + pri->v_na[teio] = pri->v_r[teio];
2958 - /* Immediately transmit unless we're in a recovery state, or the window
2959 - size is too big */
2960 - if (!pri->retrans && !pri->busy) {
2961 - if (pri->windowlen < pri->window) {
2963 + pri->txqueue[teio] = f;
2965 + if ((pri->q921_state[teio] != Q921_LINK_CONNECTION_ESTABLISHED) && ((pri->localtype == BRI_CPE_PTMP) || (pri->localtype == BRI_CPE) || (pri->localtype == BRI_NETWORK))){
2966 + /* no p2p datalink, yet. queue up the iframes... */
2967 + if (pri->debug & PRI_DEBUG_Q921_STATE)
2968 + pri_message(pri, "Layer 3 transmit waiting for layer 2\n");
2970 + /* Immediately transmit unless we're in a recovery state, or the window
2971 + size is too big */
2972 + if (!pri->retrans[teio] && !pri->busy[teio]) {
2973 + if (pri->windowlen[teio] < pri->window[teio]) {
2974 + pri->windowlen[teio]++;
2975 q921_transmit(pri, (q921_h *)(&f->h), f->len);
2978 if (pri->debug & PRI_DEBUG_Q921_STATE)
2979 pri_message(pri, "Delaying transmission of %d, window is %d/%d long\n",
2980 - f->h.n_s, pri->windowlen, pri->window);
2981 + f->h.n_s, pri->windowlen[teio], pri->window[teio]);
2984 - if (pri->t203_timer) {
2986 + if (pri->t203_timer[teio]) {
2987 + pri_schedule_del(pri, pri->t203_timer[teio]);
2988 + pri->t203_timer[teio] = 0;
2989 if (pri->debug & PRI_DEBUG_Q921_STATE)
2990 pri_message(pri, "Stopping T_203 timer\n");
2991 - pri_schedule_del(pri, pri->t203_timer);
2992 - pri->t203_timer = 0;
2994 - if (!pri->t200_timer) {
2996 + if (!pri->t200_timer[teio]) {
2997 if (pri->debug & PRI_DEBUG_Q921_STATE)
2998 pri_message(pri, "Starting T_200 timer\n");
2999 - pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
3001 + pri->t200_timer[teio] = pri_schedule_event2(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri, tei);
3003 if (pri->debug & PRI_DEBUG_Q921_STATE)
3004 - pri_message(pri, "T_200 timer already going (%d)\n", pri->t200_timer);
3005 + pri_message(pri, "T_200 timer already going (%d)\n", pri->t200_timer[teio]);
3009 pri_error(pri, "!! Out of memory for Q.921 transmit\n");
3010 @@ -449,49 +1049,86 @@
3014 -static void t203_expire(void *vpri)
3015 +static void t203_expire(void *vpri, int tei)
3017 - struct pri *pri = vpri;
3018 - if (pri->q921_state == Q921_LINK_CONNECTION_ESTABLISHED) {
3019 - if (pri->debug & PRI_DEBUG_Q921_STATE)
3020 + struct pri *pri = vpri;
3021 + int teio=tei - Q921_TEI_BASE;
3022 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
3024 + if (pri->q921_state[teio] == Q921_LINK_CONNECTION_ESTABLISHED) {
3025 + if (pri->debug & PRI_DEBUG_Q921_STATE)
3026 pri_message(pri, "T203 counter expired, sending RR and scheduling T203 again\n");
3027 - /* Solicit an F-bit in the other's RR */
3028 - pri->solicitfbit = 1;
3030 - q921_rr(pri, 1, 1);
3031 - /* Start timer T200 to resend our RR if we don't get it */
3032 - pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
3033 + /* Solicit an F-bit in the other's RR */
3034 + pri->solicitfbit[teio] = 1;
3035 + pri->retrans[teio] = 0;
3036 + q921_rr(pri, 1, 1, tei);
3037 + /* Start timer T200 to resend our RR if we don't get it */
3038 + pri->t203_timer[teio] = pri_schedule_event2(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri, tei);
3040 + if (pri->debug & PRI_DEBUG_Q921_STATE)
3041 + pri_message(pri, "T203 counter expired in weird state %d\n", pri->q921_state[teio]);
3042 + pri->t203_timer[teio] = 0;
3046 +static void q921_start_tei(struct pri *pri, int tei);
3049 +static void t201_expire(void *vpri, int tei)
3051 + struct pri *pri = vpri;
3052 + int teio=tei - Q921_TEI_BASE;
3054 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
3055 + if (tei == Q921_TEI_GROUP) {
3056 + for (i=0;i<Q921_MAX_TEIS;i++) {
3057 + if (pri->q921_tei_check[i] == 1) {
3058 + pri->q921_tei_check[i] = 0;
3059 + q921_start_tei(pri, Q921_TEI_BASE + i);
3063 - if (pri->debug & PRI_DEBUG_Q921_STATE)
3064 - pri_message(pri, "T203 counter expired in weird state %d\n", pri->q921_state);
3065 - pri->t203_timer = 0;
3066 + if (pri->q921_tei_check[teio] == 1) {
3067 + pri->q921_tei_check[teio] = 0;
3068 + q921_start_tei(pri, tei);
3071 + pri->t201_timer[teio] = 0;
3074 static pri_event *q921_handle_iframe(struct pri *pri, q921_i *i, int len)
3078 + int teio= i->h.tei - Q921_TEI_BASE;
3079 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
3080 +// pri_error(pri, "q921_handle_iframe: i->n_s %d pri->v_r[%d] %d \n", i->n_s, teio, pri->v_r[teio]);
3081 /* Make sure this is a valid packet */
3082 - if (i->n_s == pri->v_r) {
3083 + if (i->n_s == pri->v_r[teio]) {
3084 /* Increment next expected I-frame */
3085 - Q921_INC(pri->v_r);
3086 + Q921_INC(pri->v_r[teio]);
3087 /* Handle their ACK */
3089 - ev = q921_ack_rx(pri, i->n_r);
3090 + pri->sentrej[teio] = 0;
3091 + ev = q921_ack_rx(pri, i->n_r, i->h.tei);
3093 + pri_error(pri, "q921_handle_iframe: ev = %d \n", ev->e);
3098 /* If the Poll/Final bit is set, immediate send the RR */
3099 - q921_rr(pri, 1, 0);
3100 - } else if (pri->busy) {
3101 - q921_rr(pri, 0, 0);
3102 + q921_rr(pri, 1, 0, i->h.tei);
3103 + } else if (pri->busy[teio]) {
3104 + q921_rr(pri, 0, 0, i->h.tei);
3105 + } else if (pri->t200_timer[teio] && pri->retrans[teio]) {
3106 + pri_error(pri, "q921_handle_iframe: sending RR \n");
3107 + q921_rr(pri, 0, 0, i->h.tei);
3109 /* Receive Q.931 data */
3110 - res = q931_receive(pri, (q931_h *)i->data, len - 4);
3111 + res = q931_receive(pri, (q931_h *)i->data, len - 4, i->h.tei);
3112 /* Send an RR if one wasn't sent already */
3113 - if (pri->v_na != pri->v_r)
3114 - q921_rr(pri, 0, 0);
3115 + if (pri->v_na[teio] != pri->v_r[teio])
3116 + q921_rr(pri, 0, 0, i->h.tei);
3120 @@ -500,10 +1137,10 @@
3122 /* If we haven't already sent a reject, send it now, otherwise
3123 we are obliged to RR */
3124 - if (!pri->sentrej)
3125 - q921_reject(pri, i->p_f);
3126 + if (!pri->sentrej[teio])
3127 + q921_reject(pri, i->p_f, i->h.tei);
3129 - q921_rr(pri, 1, 0);
3130 + q921_rr(pri, 1, 0, i->h.tei);
3134 @@ -641,75 +1278,152 @@
3138 -static pri_event *q921_dchannel_up(struct pri *pri)
3139 +static void q921_tei_recovery(struct pri *pri, int tei) {
3141 + int teio=tei - Q921_TEI_BASE;
3142 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
3143 + for (i=0;i<Q921_MAX_TEIS;i++) {
3144 + if ((i + Q921_TEI_BASE == tei) || (tei == Q921_TEI_GROUP)) {
3145 + pri->q921_tei_check[i] = 1;
3148 + q921_send_teichkreq(pri, tei);
3149 + if (!pri->t201_timer[teio]) {
3150 + pri->t201_timer[teio] = pri_schedule_event2(pri, pri->timers[PRI_TIMER_T201], t201_expire, pri, tei);
3154 +static void q921_invoke_tei_recovery(void *vpri, int tei) {
3155 + struct pri *pri = vpri;
3156 + q921_tei_recovery(pri, tei);
3160 +static pri_event *q921_dchannel_up(struct pri *pri, int tei)
3162 - /* Reset counters, etc */
3164 + // we treat this as MFE
3165 + int teio=tei - Q921_TEI_BASE;
3166 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
3168 + if (((pri->localtype == BRI_CPE_PTMP) || (pri->localtype == BRI_CPE) || (pri->localtype == BRI_NETWORK)) && (pri->txqueue[teio])) {
3169 + /* Reset counters, etc */
3170 + q921_reset(pri, tei, 0);
3172 + /* Reset counters, discard frames, etc */
3173 + q921_reset(pri, tei, 1);
3176 /* Stop any SABME retransmissions */
3177 - pri_schedule_del(pri, pri->sabme_timer);
3178 - pri->sabme_timer = 0;
3179 + if (pri->sabme_timer[teio]) {
3180 + pri_schedule_del(pri, pri->sabme_timer[teio]);
3181 + pri->sabme_timer[teio] = 0;
3184 + if (pri->t202_timer[teio]) {
3185 + pri_schedule_del(pri, pri->t202_timer[teio]);
3186 + pri->t202_timer[teio] = 0;
3189 /* Reset any rejects */
3191 + pri->sentrej[teio] = 0;
3193 /* Go into connection established state */
3194 - pri->q921_state = Q921_LINK_CONNECTION_ESTABLISHED;
3196 - /* Start the T203 timer */
3197 - pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri);
3198 + pri->q921_state[teio] = Q921_LINK_CONNECTION_ESTABLISHED;
3200 - /* Report event that D-Channel is now up */
3201 - pri->ev.gen.e = PRI_EVENT_DCHAN_UP;
3203 + if (((pri->localtype == BRI_CPE_PTMP) || (pri->localtype == BRI_CPE) || (pri->localtype == BRI_NETWORK)) && (pri->txqueue[teio])) {
3204 + /* transmit queued iframes ans start T200 (handled by flush_txqueue) */
3205 + q921_flush_txqueue(pri, tei, 0);
3206 + /* dont upset upper layers if we reactivate layer 2 */
3209 + /* Start the T203 timer */
3210 + pri->t203_timer[teio] = pri_schedule_event2(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri, tei);
3212 + /* Report event that D-Channel is now up */
3213 + pri->ev.gen.e = PRI_EVENT_DCHAN_UP;
3214 + pri->ev.gen.tei = tei;
3219 -static pri_event *q921_dchannel_down(struct pri *pri)
3220 +static pri_event *q921_dchannel_down(struct pri *pri, int tei)
3222 + int teio=tei - Q921_TEI_BASE;
3223 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
3225 + pri->q921_state[teio] = Q921_LINK_CONNECTION_RELEASED;
3227 /* Reset counters, reset sabme timer etc */
3229 + if (pri->localtype == BRI_NETWORK_PTMP) {
3230 + if (pri->t203_timer[teio]) {
3231 + pri_schedule_del(pri, pri->t203_timer[teio]);
3232 + pri->t203_timer[teio] = 0;
3233 + if (pri->debug & PRI_DEBUG_Q921_STATE) {
3234 + pri_message(pri, "Stopping T_203 timer for TEI %d\n", tei);
3239 + q921_reset(pri, tei, 1);
3241 - /* Report event that D-Channel is now up */
3242 + /* Report event that D-Channel is now down */
3243 pri->ev.gen.e = PRI_EVENT_DCHAN_DOWN;
3244 + pri->ev.gen.tei = tei;
3248 -void q921_reset(struct pri *pri)
3249 +void q921_reset(struct pri *pri, int tei, int discard)
3251 + int teio=tei - Q921_TEI_BASE;
3252 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
3253 /* Having gotten a SABME we MUST reset our entire state */
3258 - pri->window = pri->timers[PRI_TIMER_K];
3259 - pri->windowlen = 0;
3260 - pri_schedule_del(pri, pri->sabme_timer);
3261 - pri_schedule_del(pri, pri->t203_timer);
3262 - pri_schedule_del(pri, pri->t200_timer);
3263 - pri->sabme_timer = 0;
3264 - pri->t203_timer = 0;
3265 - pri->t200_timer = 0;
3267 - pri->solicitfbit = 0;
3268 - pri->q921_state = Q921_LINK_CONNECTION_RELEASED;
3272 + pri->v_s[teio] = 0;
3274 + pri->v_a[teio] = 0;
3275 + pri->v_r[teio] = 0;
3276 + pri->v_na[teio] = 0;
3277 + pri->window[teio] = pri->timers[PRI_TIMER_K];
3278 + pri->windowlen[teio] = 0;
3279 + pri_schedule_del(pri, pri->sabme_timer[teio]);
3280 + pri_schedule_del(pri, pri->t203_timer[teio]);
3281 + pri_schedule_del(pri, pri->t200_timer[teio]);
3282 + pri->sabme_timer[teio] = 0;
3283 + pri->t203_timer[teio] = 0;
3284 + pri->t200_timer[teio] = 0;
3285 + pri_schedule_del(pri, pri->t202_timer[teio]);
3286 + pri->t202_timer[teio] = 0;
3287 + pri_schedule_del(pri, pri->t201_timer[teio]);
3288 + pri->t201_timer[teio] = 0;
3289 + pri->busy[teio] = 0;
3290 + pri->solicitfbit[teio] = 0;
3291 + pri->q921_state[teio] = Q921_LINK_CONNECTION_RELEASED;
3292 + pri->retrans[teio] = 0;
3293 + pri->sabme_retrans[teio] = 0;
3294 + pri->sentrej[teio] = 0;
3296 - /* Discard anything waiting to go out */
3297 - q921_discard_retransmissions(pri);
3299 + /* Discard anything waiting to go out */
3300 + q921_discard_retransmissions(pri, tei);
3305 static pri_event *__q921_receive_qualified(struct pri *pri, q921_h *h, int len)
3312 + int teio=h->h.tei - Q921_TEI_BASE;
3313 + if (((teio < 0) || (teio > Q921_MAX_TEIS)) || (pri->localtype != BRI_NETWORK_PTMP)) { teio=0; }
3315 switch(h->h.data[0] & Q921_FRAMETYPE_MASK) {
3318 - if (pri->q921_state != Q921_LINK_CONNECTION_ESTABLISHED) {
3319 - pri_error(pri, "!! Got I-frame while link state %d\n", pri->q921_state);
3320 + if (pri->q921_state[teio] != Q921_LINK_CONNECTION_ESTABLISHED) {
3321 + pri_error(pri, "!! Got I-frame while link state %d\n", pri->q921_state[teio]);
3324 /* Informational frame */
3325 @@ -720,8 +1434,10 @@
3326 return q921_handle_iframe(pri, &h->i, len);
3329 - if (pri->q921_state != Q921_LINK_CONNECTION_ESTABLISHED) {
3330 + if (pri->q921_state[teio] != Q921_LINK_CONNECTION_ESTABLISHED) {
3331 pri_error(pri, "!! Got S-frame while link down\n");
3332 + q921_send_dm(pri, 1, h->h.tei);
3333 + q921_reset(pri, h->h.tei, 1);
3337 @@ -731,80 +1447,128 @@
3340 /* Receiver Ready */
3342 + pri->busy[teio] = 0;
3343 /* Acknowledge frames as necessary */
3344 - ev = q921_ack_rx(pri, h->s.n_r);
3345 + ev = q921_ack_rx(pri, h->s.n_r, h->h.tei);
3349 - /* If it's a p/f one then send back a RR in return with the p/f bit set */
3350 - if (pri->solicitfbit) {
3351 + /* If it's a p/f one then send back a RR in return with the p/f bit set */
3352 +// pri_error(pri, "-- h->s.pf %d pri->solicitfbit[teio] %d\n", h->s.p_f, pri->solicitfbit[teio]);
3353 + if (pri->solicitfbit[teio]) {
3354 if (pri->debug & PRI_DEBUG_Q921_STATE)
3355 pri_message(pri, "-- Got RR response to our frame\n");
3357 - if (pri->debug & PRI_DEBUG_Q921_STATE)
3358 + if (pri->txqueue[teio]) {
3359 + q921_flush_txqueue(pri, pri->tei, 0);
3361 + if (pri->debug & PRI_DEBUG_Q921_STATE)
3362 pri_message(pri, "-- Unsolicited RR with P/F bit, responding\n");
3363 - q921_rr(pri, 1, 0);
3364 + q921_rr(pri, 1, 0, h->h.tei);
3367 - pri->solicitfbit = 0;
3368 + pri->solicitfbit[teio] = 0;
3372 /* Receiver not ready */
3373 if (pri->debug & PRI_DEBUG_Q921_STATE)
3374 pri_message(pri, "-- Got receiver not ready\n");
3376 - /* Send RR if poll bit set */
3377 - q921_rr(pri, h->s.p_f, 0);
3378 + if ((pri->localtype != PRI_NETWORK) && (pri->localtype != BRI_NETWORK) && (pri->localtype != BRI_NETWORK_PTMP)) {
3379 + if (h->s.p_f && h->s.h.c_r) {
3380 +// if (!pri->t200_timer[teio]) {
3381 + /* Send RR if poll bit set */
3382 + q921_rr(pri, h->s.p_f, 0, h->h.tei);
3386 + if (h->s.p_f && (!h->s.h.c_r)) {
3387 +// if (!pri->t200_timer[teio]) {
3388 + /* Send RR if poll bit set */
3389 + q921_rr(pri, h->s.p_f, 0, h->h.tei);
3393 + pri->busy[teio] = 1;
3394 + if (pri->t200_timer[teio]) {
3395 + pri_schedule_del(pri, pri->t200_timer[teio]);
3396 + pri->t200_timer[teio] = 0;
3400 + pri->t200_timer[teio] = pri_schedule_event2(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri, h->h.tei);
3403 /* Just retransmit */
3404 if (pri->debug & PRI_DEBUG_Q921_STATE)
3405 pri_message(pri, "-- Got reject requesting packet %d... Retransmitting.\n", h->s.n_r);
3407 - /* If it has the poll bit set, send an appropriate supervisory response */
3408 - q921_rr(pri, 1, 0);
3412 + q921_ack_rx(pri, h->s.n_r, h->h.tei);
3413 + /* Reset t200 timer if it was somehow going */
3414 + if (pri->t200_timer[teio]) {
3415 + pri_schedule_del(pri, pri->t200_timer[teio]);
3416 + pri->t200_timer[teio] = 0;
3418 /* Resend the proper I-frame */
3419 - for(f=pri->txqueue;f;f=f->next) {
3420 + for(f=pri->txqueue[teio];f;f=f->next) {
3421 +// pri_error(pri, "!! frame n_s %d transmitted %d (searching for %d)!\n", f->h.n_s, f->transmitted, h->s.n_r);
3422 if ((sendnow || (f->h.n_s == h->s.n_r)) && f->transmitted) {
3423 /* Matches the request, or follows in our window, and has
3424 already been transmitted. */
3426 - pri_error(pri, "!! Got reject for frame %d, retransmitting frame %d now, updating n_r!\n", h->s.n_r, f->h.n_s);
3427 - f->h.n_r = pri->v_r;
3428 - q921_transmit(pri, (q921_h *)(&f->h), f->len);
3430 + /* multiframe established */
3431 + f->transmitted = 0;
3432 + f->h.n_r = pri->v_r[teio];
3434 + if (pri->busy[teio]) {
3435 + pri->busy[teio] = 0;
3440 + pri_error(pri, "!! Got reject for frame %d, retransmitting frame %d now, updating n_r!\n", h->s.n_r, f->h.n_s);
3441 + q921_transmit(pri, (q921_h *)(&f->h), f->len);
3447 - if (pri->txqueue) {
3448 - /* This should never happen */
3449 - if (!h->s.p_f || h->s.n_r) {
3450 + if (pri->txqueue[teio]) {
3452 + q921_rr(pri, 1, 0, h->h.tei);
3453 + } else if (!h->s.p_f || h->s.n_r) {
3454 pri_error(pri, "!! Got reject for frame %d, but we only have others!\n", h->s.n_r);
3457 /* Hrm, we have nothing to send, but have been REJ'd. Reset v_a, v_s, etc */
3458 - pri_error(pri, "!! Got reject for frame %d, but we have nothing -- resetting!\n", h->s.n_r);
3459 - pri->v_a = h->s.n_r;
3460 - pri->v_s = h->s.n_r;
3461 - /* Reset t200 timer if it was somehow going */
3462 - if (pri->t200_timer) {
3463 - pri_schedule_del(pri, pri->t200_timer);
3464 - pri->t200_timer = 0;
3466 +/* pri_error(pri, "!! Got reject for frame %d, but we have nothing -- resetting!\n", h->s.n_r);
3467 + pri->v_a[teio] = h->s.n_r;
3468 + pri->v_s[teio] = h->s.n_r; */
3469 /* Reset and restart t203 timer */
3470 - if (pri->t203_timer)
3471 - pri_schedule_del(pri, pri->t203_timer);
3472 - pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri);
3473 + if (pri->t203_timer[teio])
3474 + pri_schedule_del(pri, pri->t203_timer[teio]);
3475 + pri->t203_timer[teio] = pri_schedule_event2(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri, tei);
3476 + pri->solicitfbit[teio] = 0;
3481 + /* If it has the poll bit set (and an iframe was retransmitted), send an appropriate supervisory response */
3482 +// q921_rr(pri, 1, 0, h->h.tei);
3483 + /* Reset t200 timer if it was somehow going */
3484 + if (pri->t200_timer[teio]) {
3485 + pri_schedule_del(pri, pri->t200_timer[teio]);
3486 + pri->t200_timer[teio] = 0;
3488 + /* Reset and restart t203 timer */
3489 + pri->solicitfbit[teio] = 0;
3490 + if (pri->t203_timer[teio])
3491 + pri_schedule_del(pri, pri->t203_timer[teio]);
3492 + pri->t203_timer[teio] = pri_schedule_event2(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri, h->h.tei);
3497 pri_error(pri, "!! XXX Unknown Supervisory frame ss=0x%02x,pf=%02xnr=%02x vs=%02x, va=%02x XXX\n", h->s.ss, h->s.p_f, h->s.n_r,
3498 - pri->v_s, pri->v_a);
3499 + pri->v_s[teio], pri->v_a[teio]);
3503 @@ -821,8 +1585,16 @@
3504 if (pri->debug & PRI_DEBUG_Q921_STATE)
3505 pri_message(pri, "-- Got DM Mode from peer.\n");
3506 /* Disconnected mode, try again after T200 */
3507 - ev = q921_dchannel_down(pri);
3508 - q921_start(pri, 0);
3509 + ev = q921_dchannel_down(pri, h->h.tei);
3510 + if ((pri->localtype == BRI_CPE_PTMP) || (pri->localtype == BRI_CPE) || (pri->localtype == BRI_NETWORK)) {
3511 + /* release layer 2 */
3512 + // pri_error(pri, "got DM, restarting layer 2.\n");
3514 + q921_start(pri, 0, h->h.tei);
3516 + if ((pri->localtype == PRI_NETWORK) || (pri->localtype == PRI_CPE)){
3517 + q921_start(pri, 0, h->h.tei);
3522 @@ -830,21 +1602,148 @@
3523 pri_message(pri, "-- Ignoring unsolicited DM with p/f set to 0\n");
3525 /* Requesting that we start */
3526 - q921_start(pri, 0);
3527 + q921_start(pri, 0, h->h.tei);
3531 - } else if (!h->u.m2) {
3532 - pri_message(pri, "XXX Unnumbered Information not implemented XXX\n");
3533 + } else if (h->u.m2 == 0) {
3534 + if (h->u.ft == 3) {
3535 + switch (h->u.data[0]) { /* Management Entity Identifier */
3537 + /* TEI Procedure */
3538 + switch (h->u.data[3]) {
3539 + case Q921_TEI_ID_VERIFY:
3540 + if (pri->localtype != BRI_NETWORK_PTMP)
3542 + if (pri->debug & PRI_DEBUG_Q921_STATE)
3543 + pri_message(pri, "got TEI verify for TEI = %d\n",h->u.data[4] >> 1);
3545 + case Q921_TEI_ID_ASSIGNED:
3546 + if (pri->localtype != BRI_CPE_PTMP)
3548 + if (pri->tei == (h->u.data[4] >> 1)) {
3549 + // TEI already assgined, CHECK_TEI or REMOVE_TEI
3550 + pri_error(pri, "Double assgined TEI!\n");
3552 + if (pri->ri == ((unsigned short) (h->u.data[1] << 8) + h->u.data[2])) {
3553 + if (pri->t202_timer[0]) {
3554 + pri_schedule_del(pri, pri->t202_timer[0]);
3555 + pri->t202_timer[0] = 0;
3557 + pri->tei = h->u.data[4] >> 1;
3559 + if (pri->debug & PRI_DEBUG_Q921_STATE)
3560 + pri_message(pri, "received TEI assign TEI = %d ri=%d\n",pri->tei,(unsigned short) (h->u.data[1] << 8) + h->u.data[2]);
3561 + pri->sabme_retrans[teio] = 0;
3562 + q921_send_sabme_now(pri, pri->tei);
3565 + case Q921_TEI_ID_REMOVE:
3566 + pri_error(pri, "TEI remove TEI = %d\n",(h->u.data[4] >> 1));
3567 + if (pri->localtype != BRI_CPE_PTMP)
3569 + if (((h->u.data[4] >> 1) == Q921_TEI_GROUP) || (pri->tei == (h->u.data[4] >> 1))){
3570 + if (pri->debug & PRI_DEBUG_Q921_STATE)
3571 + pri_message(pri, "received TEI remove TEI = %d\n",pri->tei);
3575 + q921_reset(pri, 0, 1);
3576 + q921_send_teireq(pri);
3579 + case Q921_TEI_ID_REQUEST:
3580 + if (pri->localtype != BRI_NETWORK_PTMP)
3583 + tei = h->u.data[4] >> 1;
3584 + if (tei != Q921_TEI_GROUP) {
3585 + pri_message(pri, "got TEI request for unavailable TEI..\n");
3586 + q921_send_teidenied(pri,((unsigned int)(h->u.data[1] << 8) + h->u.data[2]),h->u.data[4] >> 1);
3590 + for (tei=0;tei<Q921_MAX_TEIS;tei++) {
3591 + if (pri->q921_teis[tei] == 0) {
3592 + pri->q921_teis[tei] = 1;
3596 + if (tei < Q921_MAX_TEIS) {
3597 + q921_send_teiassign(pri,((unsigned int)(h->u.data[1] << 8) + h->u.data[2]),tei + Q921_TEI_BASE);
3599 + pri_error(pri, "no TEI available. starting TEI recovery procedure. dont worry!\n");
3600 + q921_tei_recovery(pri, 127);
3604 + case Q921_TEI_ID_CHK_REQ:
3605 + if (pri->localtype != BRI_CPE_PTMP)
3607 + if ((((h->u.data[4] >> 1) == Q921_TEI_GROUP) || ((h->u.data[4] >> 1) == 0) || ((h->u.data[4] >> 1) == pri->tei)) && (pri->tei > 0)) {
3608 + pri_message(pri, "received TEI check request for TEI = %d\n",h->u.data[4] >> 1);
3609 + q921_send_teichkresp(pri, pri->tei);
3612 + case Q921_TEI_ID_CHK_RES:
3613 + if (pri->localtype != BRI_NETWORK_PTMP)
3615 + teio = (h->u.data[4] >> 1) - Q921_TEI_BASE;
3616 + if ((teio < 0) || (teio >= Q921_MAX_TEIS)) break;
3617 + if (pri->q921_tei_check[teio] == 1) {
3618 + pri->q921_tei_check_ri[teio] = (h->u.data[1] << 8) + h->u.data[2];
3619 + pri->q921_tei_check[teio] = 0;
3622 + pri_error(pri, "double assgined tei for tei %d teio %d\n", h->u.data[4] >> 1, teio);
3623 + pri->q921_tei_check[teio] = 0;
3624 + q921_start_tei(pri, h->u.data[4] >> 1);
3628 + pri_message(pri, "Ri = %d TEI msg = %x TEI = %x\n", (h->u.data[1] << 8) + h->u.data[2], h->u.data[3], h->u.data[4] >> 1);
3631 + case Q931_PROTOCOL_DISCRIMINATOR:
3632 + if ((pri->localtype == BRI_CPE_PTMP) || (pri->localtype == BRI_CPE)){
3633 + res = q931_receive(pri, (q931_h *)h->u.data, len-3, h->h.tei);
3634 + /* Send an RR if one wasn't sent already */
3635 + if (pri->v_na[teio] != pri->v_r[teio])
3636 + q921_rr(pri, 0, 0, pri->tei);
3640 + if (res & Q931_RES_HAVEEVENT)
3646 + pri_message(pri, "XXX Unnumbered Information not implemented XXX\n");
3651 if (pri->debug & PRI_DEBUG_Q921_STATE)
3652 pri_message(pri, "-- Got Disconnect from peer.\n");
3653 + if (pri->q921_state[teio] != Q921_LINK_CONNECTION_ESTABLISHED) {
3654 + q921_send_dm(pri, 1, h->h.tei);
3658 - q921_send_ua(pri, h->u.p_f);
3659 - ev = q921_dchannel_down(pri);
3660 - q921_start(pri, 0);
3661 + q921_send_ua(pri, h->u.p_f, h->h.tei);
3662 + ev = q921_dchannel_down(pri, h->h.tei);
3663 +#ifndef LAYER2ALWAYSUP
3664 + if ((pri->localtype == BRI_CPE_PTMP) || (pri->localtype == BRI_CPE) || (pri->localtype == BRI_NETWORK)) {
3665 + /* release layer 2 */
3668 + if ((pri->localtype == PRI_NETWORK) || (pri->localtype == PRI_CPE)){
3670 + q921_start(pri, 0, 0);
3671 +#ifndef LAYER2ALWAYSUP
3677 @@ -866,17 +1765,28 @@
3680 /* Send Unnumbered Acknowledgement */
3681 - q921_send_ua(pri, h->u.p_f);
3682 - return q921_dchannel_up(pri);
3683 + q921_send_ua(pri, h->u.p_f, h->h.tei);
3684 + return q921_dchannel_up(pri, h->h.tei);
3685 } else if (h->u.m2 == 0) {
3687 - if (pri->q921_state == Q921_AWAITING_ESTABLISH) {
3688 + if (pri->q921_state[teio] == Q921_AWAITING_ESTABLISH) {
3689 if (pri->debug & PRI_DEBUG_Q921_STATE) {
3690 pri_message(pri, "-- Got UA from %s peer Link up.\n", h->h.c_r ? "cpe" : "network");
3692 - return q921_dchannel_up(pri);
3694 - pri_error(pri, "!! Got a UA, but i'm in state %d\n", pri->q921_state);
3695 + return q921_dchannel_up(pri, h->h.tei);
3697 + pri_error(pri, "!! Got a UA, but i'm in state %d\n", pri->q921_state[teio]);
3698 + if ((pri->localtype == BRI_CPE_PTMP) || (pri->localtype == BRI_CPE)) {
3699 + q921_reset(pri, h->h.tei, 1);
3700 + q921_send_teiverify(pri, h->h.tei);
3703 + // q921_send_dm(pri, 1, h->h.tei);
3705 + q921_reset(pri, h->h.tei, 1);
3710 pri_error(pri, "!! Weird frame received (m3=3, m2 = %d)\n", h->u.m2);
3712 @@ -901,19 +1811,42 @@
3716 - if (!pri->master && pri->debug & PRI_DEBUG_Q921_DUMP)
3717 - q921_dump(pri, h, len, pri->debug & PRI_DEBUG_Q921_RAW, 0);
3719 /* Check some reject conditions -- Start by rejecting improper ea's */
3720 if (h->h.ea1 || !(h->h.ea2))
3722 + if ((pri->localtype == PRI_CPE) || (pri->localtype == PRI_NETWORK)) {
3723 + /* Check for broadcasts - not yet handled (for PRI) */
3724 + if (h->h.tei == Q921_TEI_GROUP) {
3727 + } else if ((pri->localtype == BRI_CPE) || (pri->localtype == BRI_CPE_PTMP)) {
3728 + if ((h->h.tei != pri->tei) && (h->h.tei != Q921_TEI_GROUP)) {
3731 + } else if (pri->localtype == BRI_NETWORK_PTMP) {
3732 + /* discard anything from a strange TEI (strange == not assigned by us or the broadcast tei) */
3733 + if (((h->h.tei < Q921_TEI_BASE) || (h->h.tei > Q921_TEI_BASE + Q921_MAX_TEIS)) && (h->h.tei != Q921_TEI_GROUP)) {
3734 + if (pri->debug & PRI_DEBUG_Q921_DUMP)
3735 + pri_message(pri, "Received a Q.921 message from strange/unassigned TEI %d.\n");
3738 + if ((pri->q921_teis[h->h.tei - Q921_TEI_BASE] != 1) && (h->h.tei != Q921_TEI_GROUP)) {
3739 + if (pri->debug & PRI_DEBUG_Q921_DUMP)
3740 + pri_message(pri, "Received a Q.921 message from unassigned TEI %d.. Sending DM and assigning.\n", h->h.tei);
3742 + q921_send_dm(pri, 1, h->h.tei);
3743 + pri->q921_teis[h->h.tei - Q921_TEI_BASE] = 1;
3748 + if (!pri->master && pri->debug & PRI_DEBUG_Q921_DUMP)
3749 + q921_dump(pri, h, len, pri->debug & PRI_DEBUG_Q921_RAW, 0);
3751 - /* Check for broadcasts - not yet handled */
3752 - if (h->h.tei == Q921_TEI_GROUP)
3755 + if (pri->localtype != BRI_NETWORK_PTMP) {
3756 /* Check for SAPIs we don't yet handle */
3757 - if ((h->h.sapi != pri->sapi) || (h->h.tei != pri->tei)) {
3758 + if (((h->h.sapi != pri->sapi) && (h->h.sapi != Q921_SAPI_LAYER2_MANAGEMENT)) || ((h->h.tei != pri->tei) && (h->h.tei != Q921_TEI_GROUP) )) {
3759 #ifdef PROCESS_SUBCHANNELS
3760 /* If it's not us, try any subchannels we have */
3761 if (pri->subchannel)
3762 @@ -921,10 +1854,16 @@
3769 ev = __q921_receive_qualified(pri, h, len);
3770 - reschedule_t203(pri);
3773 + if (pri->localtype == BRI_CPE_PTMP) {
3774 + reschedule_t203(pri, pri->tei);
3776 + reschedule_t203(pri, h->h.tei);
3781 @@ -938,14 +1877,58 @@
3785 -void q921_start(struct pri *pri, int now)
3786 +static void q921_start_tei(struct pri *pri, int tei)
3788 - if (pri->q921_state != Q921_LINK_CONNECTION_RELEASED) {
3789 - pri_error(pri, "!! q921_start: Not in 'Link Connection Released' state\n");
3791 + int teio=tei - Q921_TEI_BASE;
3792 + if (pri->localtype != BRI_NETWORK_PTMP) { return; }
3793 + if (((teio < 0) || (teio > Q921_MAX_TEIS))) { teio=0; }
3794 + pri->q921_teis[teio] = 0;
3795 + q921_send_teiremove(pri, tei);
3796 + q921_reset(pri,tei,1);
3799 +void q921_start(struct pri *pri, int now, int tei)
3802 +/* if (pri->q921_state != Q921_LINK_CONNECTION_RELEASED) {
3803 + pri_error(pri, "!! q921_start: Not in 'Link Connection Released' state\n");
3806 + /* Reset our interface */
3807 + if (pri->localtype != BRI_NETWORK_PTMP) {
3808 + q921_reset(pri,0,1);
3810 + /* Do the SABME XXX Maybe we should implement T_WAIT? XXX */
3811 + if ((pri->localtype == PRI_NETWORK) || (pri->localtype == PRI_CPE) || (pri->localtype == BRI_NETWORK) || (pri->localtype == BRI_CPE)) {
3812 + pri->sabme_retrans[0] = 0;
3813 + q921_send_sabme(pri, now, 0);
3816 + if (pri->localtype == BRI_NETWORK_PTMP) {
3818 + // initial start or complete restart
3819 + q921_send_teiremove(pri, 127);
3821 + for (i=0;i<Q921_MAX_TEIS;i++) {
3822 + q921_start_tei(pri,Q921_TEI_BASE+i);
3824 + /* clean up those TEIs */
3825 +// pri_schedule_event2(pri, 10000, q921_invoke_tei_recovery, pri, 127 );
3826 + } else if ((tei >= Q921_TEI_BASE) && (tei < Q921_TEI_BASE + Q921_MAX_TEIS)){
3827 + // restart of a single p2p datalink
3828 + q921_start_tei(pri,tei);
3831 + if (pri->localtype == BRI_CPE_PTMP){
3834 + /* let's get a TEI */
3835 + q921_send_teireq(pri);
3838 + /* save the planet by recycling */
3839 + pri->sabme_retrans[0] = 0;
3840 + q921_send_sabme(pri, now, tei);
3843 - /* Reset our interface */
3845 - /* Do the SABME XXX Maybe we should implement T_WAIT? XXX */
3846 - q921_send_sabme(pri, now);
3848 diff -urN libpri-1.2.3.orig/q931.c libpri-1.2.3/q931.c
3849 --- libpri-1.2.3.orig/q931.c 2006-04-27 18:08:39.000000000 +0200
3850 +++ libpri-1.2.3/q931.c 2006-06-13 10:53:33.000000000 +0200
3853 * libpri: An implementation of Primary Rate ISDN
3855 - * Written by Mark Spencer <markster@digium.com>
3856 + * Written by Mark Spencer <markster@linux-support.net>
3858 - * Copyright (C) 2001-2005, Digium
3859 + * Copyright (C) 2001, Linux Support Services, Inc.
3860 * All Rights Reserved.
3861 + * Copyright (C) 2003-2006 Junghanns.NET GmbH
3862 + * Klaus-Peter Junghanns <kpj@junghanns.net>
3864 * This program is free software; you can redistribute it and/or modify
3865 * it under the terms of the GNU General Public License as published by
3867 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
3874 #include "pri_internal.h"
3883 @@ -205,6 +208,14 @@
3884 #define LOC_INTERNATIONAL_NETWORK 0x7
3885 #define LOC_NETWORK_BEYOND_INTERWORKING 0xa
3895 static char *ie2str(int ie);
3896 static char *msg2str(int msg);
3899 static void call_init(struct q931_call *c)
3901 memset(c, 0, sizeof(*c));
3904 c->sendhangupack = 0;
3905 c->forceinvert = -1;
3906 @@ -253,8 +265,16 @@
3911 + c->t303running = 0;
3914 c->ourcallstate = Q931_CALL_STATE_NULL;
3915 c->peercallstate = Q931_CALL_STATE_NULL;
3918 + c->causecode = -1;
3922 static char *binary(int b, int len) {
3923 @@ -272,14 +292,17 @@
3927 -#ifdef NO_BRI_SUPPORT
3928 - if (!ie->data[0] & 0x20) {
3929 - pri_error(pri, "!! Not PRI type!?\n");
3931 + if ((pri->localtype != PRI_CPE) && (pri->localtype != PRI_NETWORK)) {
3932 + // pri_error(pri, "!! BRI type %d!?\n",ie->data[0] & 0x03);
3933 + call->channelno = ie->data[0] & 0x03;
3934 + if (call->channelno == 3) {
3935 + call->channelno = -1; // any channel
3940 #ifndef NOAUTO_CHANNEL_SELECTION_SUPPORT
3941 - switch (ie->data[0] & 3) {
3942 + if ((pri->localtype == PRI_NETWORK) || (pri->localtype == PRI_CPE)) {
3943 + switch (ie->data[0] & 3) {
3945 call->justsignalling = 1;
3949 pri_error(pri, "!! Unexpected Channel selection %d\n", ie->data[0] & 3);
3954 if (ie->data[0] & 0x08)
3955 @@ -349,10 +373,16 @@
3958 /* Start with standard stuff */
3959 - if (pri->switchtype == PRI_SWITCH_GR303_TMC)
3960 + if (pri->switchtype == PRI_SWITCH_GR303_TMC) {
3961 ie->data[pos] = 0x69;
3964 + if ((pri->localtype == PRI_NETWORK) || (pri->localtype == PRI_CPE)) {
3965 ie->data[pos] = 0xa1;
3968 + ie->data[pos] = 0x80;
3971 /* Add exclusive flag if necessary */
3972 if (call->chanflags & FLAG_EXCLUSIVE)
3973 ie->data[pos] |= 0x08;
3977 if ((call->channelno > -1) || (call->slotmap != -1)) {
3978 + if ((pri->localtype == PRI_NETWORK) || (pri->localtype == PRI_CPE)) {
3979 /* We'll have the octet 8.2 and 8.3's present */
3980 ie->data[pos++] = 0x83;
3981 if (call->channelno > -1) {
3982 @@ -384,11 +415,43 @@
3983 ie->data[pos++] = (call->slotmap & 0xff);
3989 + // pri_error(pri, "channelno %d, ds1no %d data %d\n",call->channelno,call->ds1no,ie->data[pos-1]);
3990 + if (pri->localtype == BRI_CPE_PTMP) {
3991 + if (msgtype == Q931_SETUP) {
3992 + // network, you decide!
3993 + if (call->channelno > -1) {
3994 + // ie->data[pos-1] = 0x83;
3995 + ie->data[pos-1] = 0x80 | call->channelno;
3998 + if (call->channelno > -1) {
3999 + ie->data[pos-1] |= call->channelno;
4003 + if (call->channelno > -1) {
4004 + ie->data[pos-1] |= call->channelno;
4010 + if (pri->localtype == BRI_CPE) {
4011 + ie->data[pos++] = 0x80 | 3;
4016 if (call->ds1no > 0) {
4020 + if (msgtype == Q931_RESTART_ACKNOWLEDGE) {
4021 + /* restart complete interface! */
4024 pri_error(pri, "!! No channel map, no channel, and no ds1? What am I supposed to identify?\n");
4027 @@ -734,9 +797,13 @@
4028 return code2str(pres, press, sizeof(press) / sizeof(press[0]));
4031 -static void q931_get_number(unsigned char *num, int maxlen, unsigned char *src, int len)
4032 +static void q931_get_number(char *num, int maxlen, unsigned char *src, int len)
4034 - if ((len < 0) || (len > maxlen - 1)) {
4036 + pri_error(NULL, "q931_get_number received invalid len = %d\n", len);
4039 + if (len > maxlen - 1) {
4043 @@ -746,50 +813,75 @@
4045 static FUNC_DUMP(dump_called_party_number)
4047 - unsigned char cnum[256];
4049 - q931_get_number(cnum, sizeof(cnum), ie->data + 1, len - 3);
4050 - pri_message(pri, "%c Called Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d) '%s' ]\n",
4051 - prefix, len, ie->data[0] >> 7, ton2str((ie->data[0] >> 4) & 0x07), (ie->data[0] >> 4) & 0x07, npi2str(ie->data[0] & 0x0f), ie->data[0] & 0x0f, cnum);
4054 + q931_get_number(cnum, sizeof(cnum), ie->data + 1, len - 3);
4055 + pri_message(pri, "%c Called Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d) '%s' ]\n",
4056 + prefix, len, ie->data[0] >> 7, ton2str((ie->data[0] >> 4) & 0x07), (ie->data[0] >> 4) & 0x07, npi2str(ie->data[0] & 0x0f), ie->data[0] & 0x0f, cnum);
4058 + pri_error(pri, "Called Number (len=%2d) too short.\n", len);
4062 static FUNC_DUMP(dump_called_party_subaddr)
4064 - unsigned char cnum[256];
4065 - q931_get_number(cnum, sizeof(cnum), ie->data + 1, len - 3);
4066 - pri_message(pri, "%c Called Sub-Address (len=%2d) [ Ext: %d Type: %s (%d) O: %d '%s' ]\n",
4067 - prefix, len, ie->data[0] >> 7,
4068 - subaddrtype2str((ie->data[0] & 0x70) >> 4), (ie->data[0] & 0x70) >> 4,
4069 - (ie->data[0] & 0x08) >> 3, cnum);
4072 + q931_get_number(cnum, sizeof(cnum), ie->data + 1, len - 3);
4073 + pri_message(pri, "%c Called Sub-Address (len=%2d) [ Ext: %d Type: %s (%d) O: %d '%s' ]\n",
4074 + prefix, len, ie->data[0] >> 7,
4075 + subaddrtype2str((ie->data[0] & 0x70) >> 4), (ie->data[0] & 0x70) >> 4,
4076 + (ie->data[0] & 0x08) >> 3, cnum);
4078 + pri_error(pri, "Called Party Subaddress (len=%2d) too short.\n", len);
4082 static FUNC_DUMP(dump_calling_party_number)
4084 - unsigned char cnum[256];
4085 - if (ie->data[0] & 0x80)
4086 - q931_get_number(cnum, sizeof(cnum), ie->data + 1, len - 3);
4088 - q931_get_number(cnum, sizeof(cnum), ie->data + 2, len - 4);
4089 - pri_message(pri, "%c Calling Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d)\n", prefix, len, ie->data[0] >> 7, ton2str((ie->data[0] >> 4) & 0x07), (ie->data[0] >> 4) & 0x07, npi2str(ie->data[0] & 0x0f), ie->data[0] & 0x0f);
4090 - if (ie->data[0] & 0x80)
4091 - pri_message(pri, "%c Presentation: %s (%d) '%s' ]\n", prefix, pri_pres2str(0), 0, cnum);
4093 - pri_message(pri, "%c Presentation: %s (%d) '%s' ]\n", prefix, pri_pres2str(ie->data[1] & 0x7f), ie->data[1] & 0x7f, cnum);
4095 + if ((ie->data[0] & 0x80) && (len >= 3)) {
4096 + q931_get_number(cnum, sizeof(cnum), ie->data + 1, len - 3);
4097 + pri_message(pri, "%c Calling Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d)\n", prefix, len, ie->data[0] >> 7, ton2str((ie->data[0] >> 4) & 0x07), (ie->data[0] >> 4) & 0x07, npi2str(ie->data[0] & 0x0f), ie->data[0] & 0x0f);
4098 + pri_message(pri, "%c Presentation: %s (%d) '%s' ]\n", prefix, pri_pres2str(0), 0, cnum);
4099 + } else if (len >= 4) {
4100 + q931_get_number(cnum, sizeof(cnum), ie->data + 2, len - 4);
4101 + pri_message(pri, "%c Calling Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d)\n", prefix, len, ie->data[0] >> 7, ton2str((ie->data[0] >> 4) & 0x07), (ie->data[0] >> 4) & 0x07, npi2str(ie->data[0] & 0x0f), ie->data[0] & 0x0f);
4102 + pri_message(pri, "%c Presentation: %s (%d) '%s' ]\n", prefix, pri_pres2str(ie->data[1] & 0x7f), ie->data[1] & 0x7f, cnum);
4104 + pri_error(pri, "Calling Party Number (len=%2d) too short.\n", len);
4108 static FUNC_DUMP(dump_calling_party_subaddr)
4110 - unsigned char cnum[256];
4111 - q931_get_number(cnum, sizeof(cnum), ie->data + 1, len - 3);
4112 - pri_message(pri, "%c Calling Sub-Address (len=%2d) [ Ext: %d Type: %s (%d) O: %d '%s' ]\n",
4113 - prefix, len, ie->data[0] >> 7,
4114 - subaddrtype2str((ie->data[0] & 0x70) >> 4), (ie->data[0] & 0x70) >> 4,
4115 - (ie->data[0] & 0x08) >> 3, cnum);
4118 + q931_get_number(cnum, sizeof(cnum), ie->data + 1, len - 3);
4119 + pri_message(pri, "%c Calling Sub-Address (len=%2d) [ Ext: %d Type: %s (%d) O: %d '%s' ]\n",
4120 + prefix, len, ie->data[0] >> 7,
4121 + subaddrtype2str((ie->data[0] & 0x70) >> 4), (ie->data[0] & 0x70) >> 4,
4122 + (ie->data[0] & 0x08) >> 3, cnum);
4124 + pri_error(pri, "Calling Party Subaddress (len=%2d) too short.\n", len);
4128 +static FUNC_DUMP(dump_colp)
4132 + q931_get_number(cnum, sizeof(cnum), ie->data + 2, len - 4);
4133 + pri_message(pri, "%c COLP (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d)\n", prefix, len, ie->data[0] >> 7, ton2str((ie->data[0] >> 4) & 0x07), (ie->data[0] >> 4) & 0x07, npi2str(ie->data[0] & 0x0f), ie->data[0] & 0x0f);
4134 + pri_message(pri, "%c Presentation: %s (%d) '%s' ]\n", prefix, pri_pres2str(ie->data[1] & 0x7f), ie->data[1] & 0x7f, cnum);
4136 + pri_error(pri, "COLP (len=%2d) too short.\n", len);
4140 static FUNC_DUMP(dump_redirecting_number)
4142 - unsigned char cnum[256];
4145 /* To follow Q.931 (4.5.1), we must search for start of octet 4 by
4146 walking through all bytes until one with ext bit (8) set to 1 */
4147 @@ -810,13 +902,17 @@
4150 while(!(ie->data[i++]& 0x80));
4151 - q931_get_number(cnum, sizeof(cnum), ie->data + i, ie->len - i);
4152 - pri_message(pri, " '%s' ]\n", cnum);
4153 + if ((ie->len - i) >= 0) {
4154 + q931_get_number(cnum, sizeof(cnum), ie->data + i, ie->len - i);
4155 + pri_message(pri, " '%s' ]\n", cnum);
4157 + pri_error(pri, "Redirecting Number (len=%2d) too short.\n", len);
4161 static FUNC_DUMP(dump_connected_number)
4163 - unsigned char cnum[256];
4166 /* To follow Q.931 (4.5.1), we must search for start of octet 4 by
4167 walking through all bytes until one with ext bit (8) set to 1 */
4168 @@ -833,8 +929,12 @@
4171 while(!(ie->data[i++]& 0x80));
4172 - q931_get_number(cnum, sizeof(cnum), ie->data + i, ie->len - i);
4173 - pri_message(pri, " '%s' ]\n", cnum);
4174 + if ((ie->len - i) >= 0) {
4175 + q931_get_number(cnum, sizeof(cnum), ie->data + i, ie->len - i);
4176 + pri_message(pri, " '%s' ]\n", cnum);
4178 + pri_error(pri, "Connected Number (len=%2d) too short.\n", len);
4186 while(!(ie->data[i++] & 0x80));
4187 - q931_get_number((unsigned char *) call->redirectingnum, sizeof(call->redirectingnum), ie->data + i, ie->len - i);
4188 + q931_get_number(call->redirectingnum, sizeof(call->redirectingnum), ie->data + i, ie->len - i);
4196 - if (call->redirectingnum && *call->redirectingnum) {
4197 + if (call->redirectingnum && strlen(call->redirectingnum)) {
4198 ie->data[0] = call->redirectingplan;
4199 ie->data[1] = call->redirectingpres;
4200 ie->data[2] = (call->redirectingreason & 0x0f) | 0x80;
4201 @@ -878,67 +978,90 @@
4203 static FUNC_DUMP(dump_redirecting_subaddr)
4205 - unsigned char cnum[256];
4206 - q931_get_number(cnum, sizeof(cnum), ie->data + 2, len - 4);
4207 - pri_message(pri, "%c Redirecting Sub-Address (len=%2d) [ Ext: %d Type: %s (%d) O: %d '%s' ]\n",
4208 - prefix, len, ie->data[0] >> 7,
4209 - subaddrtype2str((ie->data[0] & 0x70) >> 4), (ie->data[0] & 0x70) >> 4,
4210 - (ie->data[0] & 0x08) >> 3, cnum);
4213 + q931_get_number(cnum, sizeof(cnum), ie->data + 2, len - 4);
4214 + pri_message(pri, "%c Redirecting Sub-Address (len=%2d) [ Ext: %d Type: %s (%d) O: %d '%s' ]\n",
4215 + prefix, len, ie->data[0] >> 7,
4216 + subaddrtype2str((ie->data[0] & 0x70) >> 4), (ie->data[0] & 0x70) >> 4,
4217 + (ie->data[0] & 0x08) >> 3, cnum);
4219 + pri_error(pri, "Redirecting Subaddress (len=%2d) too short.\n", len);
4223 static FUNC_RECV(receive_calling_party_subaddr)
4225 /* copy digits to call->callingsubaddr */
4226 - q931_get_number((unsigned char *) call->callingsubaddr, sizeof(call->callingsubaddr), ie->data + 1, len - 3);
4228 + q931_get_number(call->callingsubaddr, sizeof(call->callingsubaddr), ie->data + 1, len - 3);
4230 + pri_error(call->pri, "Calling Party Subaddress (len=%2d) too short.\n", len);
4235 static FUNC_RECV(receive_called_party_number)
4237 - /* copy digits to call->callednum */
4238 - q931_get_number((unsigned char *) call->callednum, sizeof(call->callednum), ie->data + 1, len - 3);
4239 - call->calledplan = ie->data[0] & 0x7f;
4240 + /* copy digits to call->callednum or call->digits */
4242 + if (msgtype == Q931_INFORMATION) {
4243 + q931_get_number(call->digits, sizeof(call->digits), ie->data + 1, len - 3);
4245 + q931_get_number(call->callednum, sizeof(call->callednum), ie->data + 1, len - 3);
4247 + call->calledplan = ie->data[0] & 0x7f;
4249 + pri_error(call->pri, "Called Party Number (len=%2d) too short.\n", len);
4254 static FUNC_SEND(transmit_called_party_number)
4256 ie->data[0] = 0x80 | call->calledplan;
4257 - if (*call->callednum)
4258 + if (strlen(call->callednum))
4259 memcpy(ie->data + 1, call->callednum, strlen(call->callednum));
4260 return strlen(call->callednum) + 3;
4263 static FUNC_RECV(receive_calling_party_number)
4268 - if (ie->data[0] & 0x80) {
4269 - data = ie->data + 1;
4271 - call->callerpres = 0; /* PI presentation allowed SI user-provided, not screened */
4273 - data = ie->data + 2;
4275 - call->callerpres = ie->data[1] & 0x7f;
4278 - if (call->callerpres == PRES_ALLOWED_NETWORK_NUMBER ||
4279 - call->callerpres == PRES_PROHIB_NETWORK_NUMBER) {
4280 - q931_get_number((u_int8_t *)call->callerani, sizeof(call->callerani), data, length);
4281 - call->callerplanani = ie->data[0] & 0x7f;
4283 - if (!*call->callernum) { /*Copy ANI to CallerID if CallerID is not already set */
4284 - libpri_copy_string(call->callernum, call->callerani, sizeof(call->callernum));
4285 - call->callerplan = call->callerplanani;
4289 - q931_get_number((u_int8_t *)call->callernum, sizeof(call->callernum), data, length);
4290 - call->callerplan = ie->data[0] & 0x7f;
4293 + if (strlen(call->callernum)) {
4294 + call->callerplanuser = ie->data[0] & 0x7f;
4296 + call->callerplan = ie->data[0] & 0x7f;
4299 + if (ie->data[0] & 0x80) {
4301 + if (strlen(call->callernum)) {
4302 + // got A NUM already (this is not 100% correct, but the network should do it this way to protect bad implementations
4303 + q931_get_number(call->callerani, sizeof(call->callerani), ie->data + 1, len - 3);
4304 + call->callerpresuser = 0; /* PI presentation allowed
4305 + SI user-provided, not screened */
4307 + q931_get_number(call->callernum, sizeof(call->callernum), ie->data + 1, len - 3);
4308 + call->callerpres = 0; /* PI presentation allowed
4309 + SI user-provided, not screened */
4312 + pri_error(call->pri, "Calling Party Number (len=%2d) too short.\n", len);
4316 + if (strlen(call->callernum)) {
4317 + q931_get_number(call->callerani, sizeof(call->callerani), ie->data + 2, len - 4);
4318 + call->callerpresuser = ie->data[1] & 0x7f;
4320 + q931_get_number(call->callernum, sizeof(call->callernum), ie->data + 2, len - 4);
4321 + call->callerpres = ie->data[1] & 0x7f;
4324 + pri_error(call->pri, "Calling Party Number (len=%2d) too short.\n", len);
4330 @@ -946,7 +1069,7 @@
4332 ie->data[0] = call->callerplan;
4333 ie->data[1] = 0x80 | call->callerpres;
4334 - if (*call->callernum)
4335 + if (strlen(call->callernum))
4336 memcpy(ie->data + 2, call->callernum, strlen(call->callernum));
4337 return strlen(call->callernum) + 4;
4339 @@ -964,11 +1087,89 @@
4340 static FUNC_RECV(receive_user_user)
4342 call->useruserprotocoldisc = ie->data[0] & 0xff;
4343 - if (call->useruserprotocoldisc == 4) /* IA5 */
4344 - q931_get_number((unsigned char *) call->useruserinfo, sizeof(call->useruserinfo), ie->data + 1, len - 3);
4345 + if (call->useruserprotocoldisc == 4) { /* IA5 */
4347 + q931_get_number(call->useruserinfo, sizeof(call->useruserinfo), ie->data + 1, len - 3);
4349 + pri_error(call->pri, "User-User Information (len=%2d) too short.\n", len);
4355 +static FUNC_RECV(receive_call_identity)
4358 + q931_get_number(call->callid, sizeof(call->callid), ie->data, len - 2);
4360 + pri_error(call->pri, "Call Identity (len=%2d) too short.\n", len);
4365 +static FUNC_SEND(transmit_call_identity)
4367 + if (strlen(call->callid))
4368 + memcpy(ie->data , call->callid, strlen(call->callid));
4369 + return strlen(call->callednum) + 3;
4372 +static FUNC_RECV(receive_high_layer_compat)
4377 +static FUNC_SEND(transmit_high_layer_compat)
4379 + if (call->transcapability != PRI_TRANS_CAP_RESTRICTED_DIGITAL && call->transcapability != PRI_TRANS_CAP_DIGITAL && call->transcapability != PRI_TRANS_CAP_DIGITAL_W_TONES) {
4380 + ie->data[0] = 0x91;
4381 + ie->data[1] = 0x81;
4387 +static FUNC_DUMP(dump_high_layer_compat)
4390 + pri_message(pri, "%c High-layer compatibilty (len=%2d) [ ", prefix, len);
4391 + for (x=0;x<ie->len;x++)
4392 + pri_message(pri, "0x%02X ", ie->data[x]);
4393 + pri_message(pri, " ]\n");
4397 +static FUNC_RECV(receive_low_layer_compat)
4401 + pri_error(pri, "%d bytes LLC too long\n", len);
4404 + pri_error(pri, "copying %d bytes LLC \n", len);
4405 + call->llc[0] = len;
4406 + memcpy(call->llc+1, ie->data, len);
4412 +static FUNC_SEND(transmit_low_layer_compat)
4414 + if (call->llc[0] == 0) return 0;
4415 + memcpy(ie->data, call->llc + 1, call->llc[0]);
4416 + return call->llc[0] + 2;
4419 +static FUNC_DUMP(dump_low_layer_compat)
4422 + pri_message(pri, "%c Low-layer compatibilty (len=%2d) [ ", prefix, len);
4423 + for (x=0;x<ie->len;x++)
4424 + pri_message(pri, "0x%02X ", ie->data[x]);
4425 + pri_message(pri, " ]\n");
4428 static FUNC_SEND(transmit_user_user)
4430 int datalen = strlen(call->useruserinfo);
4431 @@ -1050,22 +1251,41 @@
4435 - q931_get_number((unsigned char *) call->callername, sizeof(call->callername), data, len - 2);
4436 + if (msgtype == Q931_SETUP) {
4437 + /* we treat display IEs in the SETUP msg as callername */
4439 + q931_get_number(call->callername, sizeof(call->callername), data, len - 2);
4441 + pri_error(call->pri, "Display (len=%2d) too short.\n", len);
4444 + /* in other msgs we will pass it as text to chan_zap */
4446 + q931_get_number(call->display, sizeof(call->display), data, len - 2);
4448 + pri_error(call->pri, "Display (len=%2d) too short.\n", len);
4454 static FUNC_SEND(transmit_display)
4457 - if ((pri->switchtype != PRI_SWITCH_NI1) && (pri->switchtype != PRI_SWITCH_QSIG)
4458 - && *call->callername) {
4459 + int cpe = pri->localtype == BRI_CPE || pri->localtype == BRI_CPE_PTMP || pri->localtype == PRI_CPE;
4460 + if ((pri->switchtype != PRI_SWITCH_NI1) && (pri->switchtype != PRI_SWITCH_QSIG) && strlen(call->callername) && !cpe) {
4462 if(pri->switchtype != PRI_SWITCH_EUROISDN_E1) {
4466 - memcpy(ie->data + i, call->callername, strlen(call->callername));
4467 - return 2 + i + strlen(call->callername);
4468 + if (msgtype == Q931_SETUP_ACKNOWLEDGE) {
4469 + memcpy(ie->data + i, call->display, strlen(call->display));
4470 + return 2 + i + strlen(call->display);
4472 + memcpy(ie->data + i, call->callername, strlen(call->callername));
4473 + return 2 + i + strlen(call->callername);
4478 @@ -1112,6 +1332,111 @@
4483 + static FUNC_RECV(receive_facility_kpj)
4485 + unsigned char cpt_tag, cp_len, invoke_id_tag, invoke_id_len, operation_value_len, operation_value_tag;
4486 + unsigned char arg_len = 0;
4487 + unsigned char pos = 0;
4488 + short invoke_id = 0, operation_value = 0;
4489 + if ((ie->data[pos++] & 0x1F) == 0x11) {
4490 + /* service discriminator == supplementary services */
4491 + cpt_tag = ie->data[pos++] & 0x1F;
4492 + cp_len = ie->data[pos++];
4493 + switch (cpt_tag) {
4494 + case 1: /* invoke */
4495 + invoke_id_tag = ie->data[pos++];
4496 + if (invoke_id_tag != 0x02) {
4497 + // pri_error(call->pri, "invoke id tag != 0x02\n");
4500 + invoke_id_len = ie->data[pos++]; // 4
4501 + while (invoke_id_len > 0) {
4502 + invoke_id = (invoke_id << 8) | (ie->data[pos++] & 0xFF);
4505 + operation_value_tag = ie->data[pos++];
4506 + if (operation_value_tag != 0x02) {
4507 + // pri_error(call->pri, "operation value tag != 0x02\n");
4510 + operation_value_len = ie->data[pos++];
4511 + while (operation_value_len > 0) {
4512 + operation_value = (operation_value << 8) | (ie->data[pos++] & 0xFF);
4513 + operation_value_len--;
4515 + arg_len = ie->len - pos;
4516 + switch (operation_value) {
4517 + case 0x06: /* ECT execute */
4518 + call->facility = operation_value;
4520 + case 0x0D: /* call deflection */
4521 + call->facility = operation_value;
4524 + if (arg_len > 0) {
4526 + q931_get_number(call->redirectingnum, sizeof(call->redirectingnum), ie->data + pos, arg_len);
4528 + /* now retrieve the number */
4530 + case 0x22: /* AOC-D */
4532 + case 0x24: /* AOC-E */
4536 + case 2: /* return result */
4538 + case 3: /* return error */
4540 + case 4: /* reject */
4544 + /* OLD DIRTY ULAW HACK */
4545 + if (ie->len < 14) {
4546 + pri_error(call->pri, "!! Facility message shorter than 14 bytes\n");
4549 + if (ie->data[13] + 14 == ie->len) {
4550 + q931_get_number(call->callername, sizeof(call->callername) - 1, ie->data + 14, ie->len - 14);
4552 + call->facility = 0x0;
4557 + static FUNC_SEND(transmit_facility_kpj)
4561 + if (call->aoc && (pri->switchtype == PRI_SWITCH_EUROISDN_E1) && ((pri->localtype == BRI_NETWORK) || (pri->localtype == BRI_NETWORK_PTMP) || (pri->localtype == PRI_NETWORK))) {
4562 + ie->data[0] = 0x90; /* PP remote operations */
4563 + ie->data[i++] = 0x00; /* component tag */
4564 + ie->data[i++] = 0x02; /* invoke id tag */
4565 + ie->data[i++] = 0x02; /* invoke id len */
4566 + ie->data[i++] = 0x34; /* invoke id */
4567 + ie->data[i++] = 0x56; /* invoke id */
4568 + ie->data[i++] = 0x02; /* operation value tag */
4569 + ie->data[i++] = 0x01; /* operation value len */
4570 + switch (msgtype) {
4572 + ie->data[i++] = 0x26; /* operation value AOC-S */
4574 + case Q931_DISCONNECT:
4575 + ie->data[i++] = 0x24; /* operation value AOC-E */
4578 + ie->data[i++] = 0x22; /* operation value AOC-D */
4587 static FUNC_SEND(transmit_facility)
4589 struct apdu_event *tmp;
4590 @@ -1138,6 +1463,182 @@
4595 +static FUNC_SEND(transmit_facility)
4597 + int i = 0, j, first_i, compsp = 0;
4598 + struct rose_component *comp, *compstk[10];
4599 + unsigned char namelen = strlen(call->callername);
4601 + if ((pri->switchtype == PRI_SWITCH_NI2) && (namelen > 15))
4602 + namelen = 15; /* According to GR-1367, for NI2 switches it can't be > 15 characters */
4603 + if ((namelen > 0) && ((pri->switchtype == PRI_SWITCH_QSIG) ||
4604 + ((pri->switchtype == PRI_SWITCH_NI2) && (pri->localtype == PRI_NETWORK)))) {
4607 + ie->data[i] = 0x80 | Q932_PROTOCOL_EXTENSIONS;
4609 + /* Interpretation component */
4610 + ASN1_ADD_BYTECOMP(comp, COMP_TYPE_INTERPRETATION, ie->data, i, 0x00 /* Discard unrecognized invokes */);
4613 + ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, ie->data, i);
4614 + ASN1_PUSH(compstk, compsp, comp);
4616 + /* Invoke component contents */
4618 + ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, ie->data, i, ++pri->last_invoke);
4620 + /* Operation Tag */
4621 + ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, ie->data, i, SS_CNID_CALLINGNAME);
4623 + /* Arugement Tag */
4624 + j = asn1_string_encode(ROSE_NAME_PRESENTATION_ALLOWED_SIMPLE, &ie->data[i], len - i, 15, call->callername, namelen);
4631 + /* Fix length of stacked components */
4632 + while(compsp > 0) {
4633 + ASN1_FIXUP(compstk, compsp, ie->data, i);
4637 + if (/*(pri->switchtype == PRI_SWITCH_EUROISDN_E1) &&*/ call->redirectingnum && strlen(call->redirectingnum)) {
4638 + if (!(first_i = i)) {
4639 + /* Add protocol information header */
4640 + ie->data[i++] = 0x80 | Q932_PROTOCOL_ROSE;
4643 + /* ROSE invoke component */
4644 + ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, ie->data, i);
4645 + ASN1_PUSH(compstk, compsp, comp);
4647 + /* ROSE invokeId component */
4648 + ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, ie->data, i, ++pri->last_invoke);
4650 + /* ROSE operationId component */
4651 + ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, ie->data, i, ROSE_DIVERTING_LEG_INFORMATION2);
4653 + /* ROSE ARGUMENT component */
4654 + ASN1_ADD_SIMPLE(comp, 0x30, ie->data, i);
4655 + ASN1_PUSH(compstk, compsp, comp);
4657 + /* ROSE DivertingLegInformation2.diversionCounter component */
4658 + /* Always is 1 because other isn't available in the current design */
4659 + ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, ie->data, i, 1);
4661 + /* ROSE DivertingLegInformation2.diversionReason component */
4662 + ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, ie->data, i, redirectingreason_from_q931(pri, call->redirectingreason));
4664 + /* ROSE DivertingLegInformation2.divertingNr component */
4665 + ASN1_ADD_SIMPLE(comp, 0xA1, ie->data, i);
4666 + ASN1_PUSH(compstk, compsp, comp);
4668 + /* Redirecting information always not screened */
4669 + switch(call->redirectingpres) {
4670 + case PRES_ALLOWED_USER_NUMBER_NOT_SCREENED:
4671 + case PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN:
4672 + if (call->redirectingnum && strlen(call->redirectingnum)) {
4673 + ASN1_ADD_SIMPLE(comp, 0xA0, ie->data, i);
4674 + ASN1_PUSH(compstk, compsp, comp);
4676 + /* NPI of redirected number is not supported in the current design */
4677 + ASN1_ADD_SIMPLE(comp, 0xA1, ie->data, i);
4678 + ASN1_PUSH(compstk, compsp, comp);
4680 + ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, ie->data, i, typeofnumber_from_q931(pri, call->redirectingplan >> 4));
4682 + j = asn1_string_encode(ASN1_NUMERICSTRING, &ie->data[i], len - i, 20, call->redirectingnum, strlen(call->redirectingnum));
4688 + ASN1_FIXUP(compstk, compsp, ie->data, i);
4689 + ASN1_FIXUP(compstk, compsp, ie->data, i);
4692 + /* fall through */
4693 + case PRES_PROHIB_USER_NUMBER_PASSED_SCREEN:
4694 + case PRES_PROHIB_USER_NUMBER_NOT_SCREENED:
4695 + ASN1_ADD_SIMPLE(comp, 0x81, ie->data, i);
4697 + /* Don't know how to handle this */
4698 + case PRES_ALLOWED_NETWORK_NUMBER:
4699 + case PRES_PROHIB_NETWORK_NUMBER:
4700 + case PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN:
4701 + case PRES_PROHIB_USER_NUMBER_FAILED_SCREEN:
4702 + ASN1_ADD_SIMPLE(comp, 0x81, ie->data, i);
4705 + pri_message(pri, "!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres);
4706 + case PRES_NUMBER_NOT_AVAILABLE:
4707 + ASN1_ADD_SIMPLE(comp, 0x82, ie->data, i);
4710 + ASN1_FIXUP(compstk, compsp, ie->data, i);
4712 + /* ROSE DivertingLegInformation2.originalCalledNr component */
4713 + /* This information isn't supported by current design - duplicate divertingNr */
4714 + ASN1_ADD_SIMPLE(comp, 0xA2, ie->data, i);
4715 + ASN1_PUSH(compstk, compsp, comp);
4717 + /* Redirecting information always not screened */
4718 + switch(call->redirectingpres) {
4719 + case PRES_ALLOWED_USER_NUMBER_NOT_SCREENED:
4720 + case PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN:
4721 + if (call->redirectingnum && strlen(call->redirectingnum)) {
4722 + ASN1_ADD_SIMPLE(comp, 0xA0, ie->data, i);
4723 + ASN1_PUSH(compstk, compsp, comp);
4725 + ASN1_ADD_SIMPLE(comp, 0xA1, ie->data, i);
4726 + ASN1_PUSH(compstk, compsp, comp);
4728 + ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, ie->data, i, typeofnumber_from_q931(pri, call->redirectingplan >> 4));
4730 + j = asn1_string_encode(ASN1_NUMERICSTRING, &ie->data[i], len - i, 20, call->redirectingnum, strlen(call->redirectingnum));
4736 + ASN1_FIXUP(compstk, compsp, ie->data, i);
4737 + ASN1_FIXUP(compstk, compsp, ie->data, i);
4740 + /* fall through */
4741 + case PRES_PROHIB_USER_NUMBER_PASSED_SCREEN:
4742 + case PRES_PROHIB_USER_NUMBER_NOT_SCREENED:
4743 + ASN1_ADD_SIMPLE(comp, 0x81, ie->data, i);
4745 + /* Don't know how to handle this */
4746 + case PRES_ALLOWED_NETWORK_NUMBER:
4747 + case PRES_PROHIB_NETWORK_NUMBER:
4748 + case PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN:
4749 + case PRES_PROHIB_USER_NUMBER_FAILED_SCREEN:
4750 + ASN1_ADD_SIMPLE(comp, 0x81, ie->data, i);
4753 + pri_message(pri, "!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres);
4754 + case PRES_NUMBER_NOT_AVAILABLE:
4755 + ASN1_ADD_SIMPLE(comp, 0x82, ie->data, i);
4758 + ASN1_FIXUP(compstk, compsp, ie->data, i);
4760 + /* Fix length of stacked components */
4761 + while(compsp > 0) {
4762 + ASN1_FIXUP(compstk, compsp, ie->data, i);
4766 + return (i ? i+2 : 0);
4770 static FUNC_RECV(receive_facility)
4773 @@ -1346,6 +1847,7 @@
4774 pri_message(pri, " ]\n");
4778 static FUNC_DUMP(dump_time_date)
4780 pri_message(pri, "%c Time Date (len=%2d) [ ", prefix, len);
4781 @@ -1366,7 +1868,7 @@
4783 static FUNC_DUMP(dump_keypad_facility)
4786 + char tmp[64] = "";
4788 if (ie->len == 0 || ie->len > sizeof(tmp))
4790 @@ -1377,28 +1879,49 @@
4792 static FUNC_RECV(receive_keypad_facility)
4800 if (ie->len > (sizeof(call->digitbuf) - 1))
4801 - mylen = (sizeof(call->digitbuf) - 1);
4802 + mylen = sizeof(call->digitbuf) - 1;
4806 - memcpy(call->digitbuf, ie->data, mylen);
4807 + strncpy(call->digitbuf, (char *) ie->data, mylen);
4809 - call->digitbuf[mylen] = 0;
4810 + /* I must be really neurotic */
4811 + call->digitbuf[sizeof(call->digitbuf)-1] = '\0';
4816 +static FUNC_RECV(receive_time_date)
4821 +static FUNC_SEND(transmit_time_date) {
4823 + struct tm *timedate;
4825 + timedate = localtime(&now);
4826 + ie->data[0] = timedate->tm_year - 100; // 1900+
4827 + ie->data[1] = timedate->tm_mon + 1;
4828 + ie->data[2] = timedate->tm_mday;
4829 + ie->data[3] = timedate->tm_hour;
4830 + ie->data[4] = timedate->tm_min;
4836 static FUNC_DUMP(dump_display)
4839 char *buf = malloc(len + 1);
4844 if ((x < ie->len) && (ie->data[x] & 0x80)) {
4845 @@ -1413,7 +1936,7 @@
4849 -static void dump_ie_data(unsigned char *c, int len)
4850 +static void dump_ie_data(struct pri *pri, unsigned char *c, int len)
4852 char tmp[1024] = "";
4854 @@ -1423,7 +1946,7 @@
4855 ((*c >= 'a') && (*c <= 'z')) ||
4856 ((*c >= '0') && (*c <= '9'))) {
4859 + if (strlen(tmp)) {
4863 @@ -1435,7 +1958,7 @@
4868 + if (strlen(tmp)) {
4872 @@ -1448,14 +1971,14 @@
4876 - pri_message(NULL, tmp);
4877 + pri_message(pri, tmp);
4880 static FUNC_DUMP(dump_facility)
4882 pri_message(pri, "%c Facility (len=%2d, codeset=%d) [ ", prefix, len, Q931_IE_CODESET(full_ie));
4883 - dump_ie_data(ie->data, ie->len);
4884 - pri_message(NULL, " ]\n");
4885 + dump_ie_data(pri, ie->data, ie->len);
4886 + pri_message(pri, " ]\n");
4889 static FUNC_DUMP(dump_network_spec_fac)
4890 @@ -1465,7 +1988,7 @@
4891 pri_message(pri, code2str(ie->data[1], facilities, sizeof(facilities) / sizeof(facilities[0])));
4894 - dump_ie_data(ie->data, ie->len);
4895 + dump_ie_data(pri, ie->data, ie->len);
4896 pri_message(pri, " ]\n");
4899 @@ -1932,8 +2455,8 @@
4900 { 1, Q931_REDIRECTING_SUBADDR, "Redirecting Subaddress", dump_redirecting_subaddr },
4901 { 0, Q931_TRANSIT_NET_SELECT, "Transit Network Selection" },
4902 { 1, Q931_RESTART_INDICATOR, "Restart Indicator", dump_restart_indicator, receive_restart_indicator, transmit_restart_indicator },
4903 - { 0, Q931_LOW_LAYER_COMPAT, "Low-layer Compatibility" },
4904 - { 0, Q931_HIGH_LAYER_COMPAT, "High-layer Compatibility" },
4905 + { 0, Q931_LOW_LAYER_COMPAT, "Low-layer Compatibility" , dump_low_layer_compat, receive_low_layer_compat, transmit_low_layer_compat },
4906 + { 1, Q931_HIGH_LAYER_COMPAT, "High-layer Compatibility" , dump_high_layer_compat, receive_high_layer_compat, transmit_high_layer_compat },
4907 { 1, Q931_PACKET_SIZE, "Packet Size" },
4908 { 1, Q931_IE_FACILITY, "Facility" , dump_facility, receive_facility, transmit_facility },
4909 { 1, Q931_IE_REDIRECTION_NUMBER, "Redirection Number" },
4910 @@ -1942,11 +2465,11 @@
4911 { 1, Q931_IE_INFO_REQUEST, "Feature Request" },
4912 { 1, Q931_IE_FEATURE_IND, "Feature Indication" },
4913 { 1, Q931_IE_SEGMENTED_MSG, "Segmented Message" },
4914 - { 1, Q931_IE_CALL_IDENTITY, "Call Identity", dump_call_identity },
4915 + { 1, Q931_IE_CALL_IDENTITY, "Call Identity", dump_call_identity, receive_call_identity, transmit_call_identity },
4916 { 1, Q931_IE_ENDPOINT_ID, "Endpoint Identification" },
4917 { 1, Q931_IE_NOTIFY_IND, "Notification Indicator", dump_notify, receive_notify, transmit_notify },
4918 { 1, Q931_DISPLAY, "Display", dump_display, receive_display, transmit_display },
4919 - { 1, Q931_IE_TIME_DATE, "Date/Time", dump_time_date },
4920 + { 1, Q931_IE_TIME_DATE, "Date/Time", dump_time_date, receive_time_date, transmit_time_date },
4921 { 1, Q931_IE_KEYPAD_FACILITY, "Keypad Facility", dump_keypad_facility, receive_keypad_facility },
4922 { 0, Q931_IE_SIGNAL, "Signal", dump_signal },
4923 { 1, Q931_IE_SWITCHHOOK, "Switch-hook" },
4924 @@ -1954,6 +2477,7 @@
4925 { 1, Q931_IE_ESCAPE_FOR_EXT, "Escape for Extension" },
4926 { 1, Q931_IE_CALL_STATUS, "Call Status" },
4927 { 1, Q931_IE_CHANGE_STATUS, "Change Status" },
4928 + { 1, Q931_COLP, "Connect Line ID Presentation", dump_colp},
4929 { 1, Q931_IE_CONNECTED_ADDR, "Connected Number", dump_connected_number },
4930 { 1, Q931_IE_CONNECTED_NUM, "Connected Number", dump_connected_number },
4931 { 1, Q931_IE_ORIGINAL_CALLED_NUMBER, "Original Called Number", dump_redirecting_number, receive_redirecting_number, transmit_redirecting_number },
4932 @@ -2024,7 +2548,7 @@
4934 if ((ie->ie & 0x80) != 0)
4941 @@ -2054,10 +2578,10 @@
4946 + /* if (cr & 0x80) {
4953 pri_error(NULL, "Call Reference Length not supported: %d\n", h->crlen);
4954 @@ -2071,14 +2595,14 @@
4955 int full_ie = Q931_FULL_IE(codeset, ie->ie);
4958 - pri_message(NULL, "%c [", prefix);
4959 - pri_message(NULL, "%02x", ie->ie);
4960 + pri_message(pri, "%c [", prefix);
4961 + pri_message(pri, "%02x", ie->ie);
4962 if (!(ie->ie & 0x80)) {
4963 - pri_message(NULL, " %02x", ielen(ie)-2);
4964 + pri_message(pri, " %02x", ielen(ie)-2);
4965 for (x = 0; x + 2 < ielen(ie); ++x)
4966 - pri_message(NULL, " %02x", ie->data[x]);
4967 + pri_message(pri, " %02x", ie->data[x]);
4969 - pri_message(NULL, "]\n");
4970 + pri_message(pri, "]\n");
4972 /* Special treatment for shifts */
4973 if((full_ie & 0xf0) == Q931_LOCKING_SHIFT)
4974 @@ -2098,14 +2622,46 @@
4975 pri_error(pri, "!! %c Unknown IE %d (len = %d)\n", prefix, base_ie, ielen(ie));
4978 -static q931_call *q931_getcall(struct pri *pri, int cr)
4979 +static q921_call *q921_getcall(struct pri *pri, struct q931_call *c, int tei)
4984 + if (cur->tei == tei) {
4989 + /* No call exists, make a new one */
4990 + if (pri->debug & PRI_DEBUG_Q921_STATE)
4991 + pri_message(pri, "-- Making new q921 call for cref %d tei %d\n", c->cr, tei);
4992 + cur = malloc(sizeof(struct q921_call));
4993 + memset(cur, 0, sizeof(cur));
4996 + cur->channel = -1;
4997 + cur->next = c->phones;
5002 +static q931_call *q931_getcall(struct pri *pri, int cr, int tei)
5004 q931_call *cur, *prev;
5005 cur = *pri->callpool;
5008 - if (cur->cr == cr)
5010 + if ((pri->localtype == BRI_NETWORK_PTMP) && (tei >= 0)) {
5011 + // hmm...ok, we might be the 1st responding to the setup
5012 + // or it is really our call
5013 + if ((cur->cr == cr) && ((cur->tei == tei) || (cur->tei == 127)))
5015 + // or we might not be the 1st responding, then we need to clone
5016 + // the call struct to hangup properly
5018 + if (cur->cr == cr)
5024 @@ -2118,6 +2674,7 @@
5025 /* Call reference */
5029 /* Append to end of list */
5032 @@ -2133,24 +2690,42 @@
5034 cur = *pri->callpool;
5036 - if (pri->cref > 32767)
5038 + if ((pri->localtype == PRI_NETWORK) || (pri->localtype == PRI_CPE)) {
5039 + if (pri->cref > 32767)
5043 + if (pri->cref > 255)
5047 - if (cur->cr == (0x8000 | pri->cref))
5049 + if ((pri->localtype == PRI_NETWORK) || (pri->localtype == PRI_CPE)) {
5050 + if (cur->cr == (0x8000 | pri->cref))
5053 + // BRIs have only 1 bye cref
5054 + if (cur->cr == (0x80 | pri->cref))
5060 - return q931_getcall(pri, pri->cref | 0x8000);
5061 + if ((pri->localtype == PRI_NETWORK) || (pri->localtype == PRI_CPE)) {
5062 + return q931_getcall(pri, pri->cref | 0x8000, 0);
5065 + return q931_getcall(pri, pri->cref | 0x80, 0);
5069 -static void q931_destroy(struct pri *pri, int cr, q931_call *c)
5070 +static void q931_destroy(struct pri *pri, int cr, q931_call *c, int tei)
5072 q931_call *cur, *prev;
5074 cur = *pri->callpool;
5076 - if ((c && (cur == c)) || (!c && (cur->cr == cr))) {
5077 +// if ((c && (cur == c)) || (!c && (cur->cr == cr))) {
5078 + if ((c && (cur == c)) || (!c && ((cur->cr == cr) && ((pri->localtype != BRI_NETWORK_PTMP) || (cur->tei == tei))))) {
5080 prev->next = cur->next;
5082 @@ -2159,6 +2734,8 @@
5083 pri_message(pri, "NEW_HANGUP DEBUG: Destroying the call, ourstate %s, peerstate %s\n",callstate2str(cur->ourcallstate),callstate2str(cur->peercallstate));
5084 if (cur->retranstimer)
5085 pri_schedule_del(pri, cur->retranstimer);
5086 + if (cur->t303timer)
5087 + pri_schedule_del(pri, cur->t303timer);
5088 pri_call_apdu_queue_cleanup(cur);
5091 @@ -2169,16 +2746,16 @@
5092 pri_error(pri, "Can't destroy call %d!\n", cr);
5095 -static void q931_destroycall(struct pri *pri, int cr)
5096 +static void q931_destroycall(struct pri *pri, int cr, int tei)
5098 - return q931_destroy(pri, cr, NULL);
5099 + return q931_destroy(pri, cr, NULL, tei);
5103 void __q931_destroycall(struct pri *pri, q931_call *c)
5106 - q931_destroy(pri,0, c);
5107 + q931_destroy(pri,0, c, c->tei);
5111 @@ -2290,6 +2867,10 @@
5114 int full_ie = Q931_FULL_IE(codeset, ie->ie);
5115 + if (ielen(ie) > Q931_IE_MAX_LEN) {
5116 + pri_error(pri, "!! Invalid IE length %d (len = %d)\n", full_ie, ielen(ie));
5119 if (pri->debug & PRI_DEBUG_Q931_STATE)
5120 pri_message(pri, "-- Processing IE %d (cs%d, %s)\n", ie->ie, codeset, ie2str(full_ie));
5121 for (x=0;x<sizeof(ies) / sizeof(ies[0]);x++) {
5122 @@ -2307,21 +2888,36 @@
5126 -static void init_header(struct pri *pri, q931_call *call, unsigned char *buf, q931_h **hb, q931_mh **mhb, int *len)
5127 +static void init_header(struct pri *pri, q931_call *call, unsigned char *buf, q931_h **hb, q931_mh **mhb, int *len, int briflag)
5129 /* Returns header and message header and modifies length in place */
5130 q931_h *h = (q931_h *)buf;
5131 - q931_mh * mh = (q931_mh *)(h->contents + 2);
5133 h->pd = pri->protodisc;
5134 h->x0 = 0; /* Reserved 0 */
5135 - h->crlen = 2; /* Two bytes of Call Reference. Invert the top bit to make it from our sense */
5136 - if (call->cr || call->forceinvert) {
5138 + if (briflag == 1) {
5139 + mh = (q931_mh *)(h->contents + 1);
5140 + h->crlen = 1; /* One bytes of Call Reference. Invert the top bit to make it from our sense */
5141 + if (call->cr || call->forceinvert) {
5142 + h->crv[0] = (call->cr ^ 0x80);
5144 + /* Unless of course this has no call reference */
5149 + mh = (q931_mh *)(h->contents + 2);
5150 + h->crlen = 2; /* Two bytes of Call Reference. Invert the top bit to make it from our sense */
5151 + if (call->cr || call->forceinvert) {
5152 h->crv[0] = ((call->cr ^ 0x8000) & 0xff00) >> 8;
5153 h->crv[1] = (call->cr & 0xff);
5156 /* Unless of course this has no call reference */
5162 if (pri->subchannel) {
5163 /* On GR-303, top bit is always 0 */
5164 @@ -2330,13 +2926,23 @@
5172 -static int q931_xmit(struct pri *pri, q931_h *h, int len, int cr)
5173 +static int q931_xmit(struct pri *pri, q931_h *h, int len, int cr, int tei)
5175 - q921_transmit_iframe(pri, h, len, cr);
5177 + if (pri->localtype == BRI_NETWORK_PTMP) {
5178 + mh = (q931_mh *)(h->contents + 1);
5179 + if (mh->msg == Q931_SETUP) {
5180 + q921_transmit_uframe(pri, h, len, cr, tei);
5182 + q921_transmit_iframe(pri, h, len, cr, tei);
5184 + } else if (pri->localtype == BRI_CPE_PTMP) {
5185 + q921_transmit_iframe(pri, h, len, cr, pri->tei);
5187 + q921_transmit_iframe(pri, h, len, cr, tei);
5189 /* The transmit operation might dump the q921 header, so logging the q931
5190 message body after the transmit puts the sections of the message in the
5191 right order in the log */
5192 @@ -2362,7 +2968,11 @@
5194 memset(buf, 0, sizeof(buf));
5196 - init_header(pri, c, buf, &h, &mh, &len);
5197 + if ((pri->localtype == PRI_NETWORK) || (pri->localtype == PRI_CPE)) {
5198 + init_header(pri, c, buf, &h, &mh, &len, 0);
5200 + init_header(pri, c, buf, &h, &mh, &len, 1);
5205 @@ -2397,11 +3007,34 @@
5207 /* Invert the logic */
5208 len = sizeof(buf) - len;
5209 - q931_xmit(pri, h, len, 1);
5210 + if (pri->localtype == BRI_CPE_PTMP) {
5211 + q931_xmit(pri, h, len, 1, pri->tei);
5213 + q931_xmit(pri, h, len, 1, c->tei);
5219 +static int facility_ies[] = { Q931_IE_FACILITY, -1 };
5222 +int q931_facility_kpj(struct pri *pri, q931_call *c, int operation, char *arguments)
5224 + switch (operation) {
5225 + case 0x26: c->aoc = 1;
5227 + case 0x24: c->aoc = 1;
5229 + case 0x22: c->aoc = 1;
5234 + return send_message(pri, c, Q931_FACILITY, facility_ies);
5238 static int status_ies[] = { Q931_CAUSE, Q931_CALL_STATE, -1 };
5240 static int q931_status(struct pri *pri, q931_call *c, int cause)
5241 @@ -2439,17 +3072,45 @@
5242 return send_message(pri, c, Q931_INFORMATION, information_ies);
5245 +static int information_display_ies[] = { Q931_DISPLAY, -1 };
5247 +int q931_information_display(struct pri *pri, q931_call *c, char *display)
5251 + if (!display) return -1;
5252 + strncpy(temp, c->callername, sizeof(temp));
5253 + strncpy(c->callername, display, sizeof(c->callername));
5254 + res = send_message(pri, c, Q931_INFORMATION, information_display_ies);
5255 + strncpy(c->callername, temp, sizeof(c->callername));
5259 +int q931_add_display(struct pri *pri, q931_call *c, char *display)
5261 + strncpy(c->display, display, sizeof(c->display));
5265 +/* static int information_special_ies[] = { Q931_IE_SPECIAL, -1 };
5266 +static int q931_information_special(struct pri *pri, q931_call *c)
5268 + return send_message(pri, c, Q931_FACILITY, information_special_ies);
5273 static int restart_ack_ies[] = { Q931_CHANNEL_IDENT, Q931_RESTART_INDICATOR, -1 };
5275 static int restart_ack(struct pri *pri, q931_call *c)
5277 c->ourcallstate = Q931_CALL_STATE_NULL;
5278 c->peercallstate = Q931_CALL_STATE_NULL;
5279 + c->chanflags &= ~FLAG_PREFERRED;
5280 + c->chanflags |= FLAG_EXCLUSIVE;
5281 return send_message(pri, c, Q931_RESTART_ACKNOWLEDGE, restart_ack_ies);
5284 -static int facility_ies[] = { Q931_IE_FACILITY, -1 };
5286 int q931_facility(struct pri*pri, q931_call *c)
5288 return send_message(pri, c, Q931_FACILITY, facility_ies);
5289 @@ -2463,7 +3124,6 @@
5290 if ((info > 0x2) || (info < 0x00))
5295 c->notify = info & 0x7F;
5297 @@ -2506,6 +3166,8 @@
5299 int q931_call_proceeding(struct pri *pri, q931_call *c, int channel, int info)
5301 + // never send two PROCEEDINGs!
5302 + if (c->proc > 0) return 0;
5304 c->ds1no = (channel & 0xff00) >> 8;
5305 c->ds1explicit = (channel & 0x10000) >> 16;
5306 @@ -2532,8 +3194,12 @@
5307 static int alerting_ies[] = { -1 };
5310 +static int alerting_BRI_ies[] = { -1 };
5312 int q931_alerting(struct pri *pri, q931_call *c, int channel, int info)
5314 + // never send two ALERTINGs!
5315 + if (c->alert > 0) return 0;
5317 q931_call_proceeding(pri, c, channel, 0);
5319 @@ -2544,14 +3210,130 @@
5320 c->progressmask = 0;
5321 c->ourcallstate = Q931_CALL_STATE_CALL_RECEIVED;
5322 c->peercallstate = Q931_CALL_STATE_CALL_DELIVERED;
5325 + if ((pri->localtype == PRI_NETWORK) || (pri->localtype == PRI_CPE)) {
5326 + return send_message(pri, c, Q931_ALERTING, alerting_ies);
5328 + if ((pri->localtype == BRI_NETWORK) || (pri->localtype == BRI_NETWORK_PTMP)) {
5329 + return send_message(pri, c, Q931_ALERTING, alerting_ies);
5331 + /* no PROGRESS_INDICATOR for BRI please */
5332 + return send_message(pri, c, Q931_ALERTING, alerting_BRI_ies);
5337 +static int hold_acknowledge_ies[] = { -1 };
5339 +int q931_hold_acknowledge(struct pri *pri, q931_call *c)
5341 + return send_message(pri, c, Q931_HOLD_ACKNOWLEDGE, hold_acknowledge_ies);
5344 +static int hold_reject_ies[] = { Q931_CAUSE, -1 };
5346 +int q931_hold_reject(struct pri *pri, q931_call *c)
5349 + c->causecode = CODE_CCITT;
5350 + c->causeloc = LOC_PRIV_NET_LOCAL_USER;
5351 + return send_message(pri, c, Q931_HOLD_REJECT, hold_reject_ies);
5354 +static int retrieve_acknowledge_ies[] = { Q931_CHANNEL_IDENT, -1 };
5356 +int q931_retrieve_acknowledge(struct pri *pri, q931_call *c, int channel)
5359 + c->channelno = channel;
5360 + c->chanflags &= ~FLAG_PREFERRED;
5361 + c->chanflags |= FLAG_EXCLUSIVE;
5362 + return send_message(pri, c, Q931_RETRIEVE_ACKNOWLEDGE, retrieve_acknowledge_ies);
5365 +static int retrieve_reject_ies[] = { -1 };
5367 +int q931_retrieve_reject(struct pri *pri, q931_call *c)
5369 + return send_message(pri, c, Q931_RETRIEVE_REJECT, retrieve_reject_ies);
5372 +static int suspend_acknowledge_ies[] = { Q931_DISPLAY, -1 };
5374 +int q931_suspend_acknowledge(struct pri *pri, q931_call *c, char *display)
5376 + char tempcallername[256];
5378 + c->ourcallstate = Q931_CALL_STATE_NULL;
5379 + c->peercallstate = Q931_CALL_STATE_NULL;
5380 + strncpy(tempcallername,c->callername,sizeof(tempcallername));
5381 + strncpy(c->callername,display,sizeof(c->callername));
5382 + res = send_message(pri, c, Q931_SUSPEND_ACKNOWLEDGE, suspend_acknowledge_ies);
5383 + strncpy(c->callername,tempcallername,sizeof(c->callername));
5384 + __q931_destroycall(pri, c);
5388 +static int suspend_reject_ies[] = { Q931_DISPLAY, Q931_CAUSE, -1 };
5390 +int q931_suspend_reject(struct pri *pri, q931_call *c, char *display)
5392 + char tempcallername[256];
5394 + strncpy(tempcallername,c->callername,sizeof(tempcallername));
5395 + strncpy(c->callername,display,sizeof(c->callername));
5397 + c->causecode = CODE_CCITT;
5398 + c->causeloc = LOC_PRIV_NET_LOCAL_USER;
5399 + res = send_message(pri, c, Q931_SUSPEND_REJECT, suspend_reject_ies);
5400 + strncpy(c->callername,tempcallername,sizeof(c->callername));
5404 +static int resume_reject_ies[] = { Q931_CAUSE, Q931_DISPLAY, -1 };
5406 +int q931_resume_reject(struct pri *pri, q931_call *c, char *display)
5408 + char tempcallername[256];
5411 + c->causecode = CODE_CCITT;
5412 + c->causeloc = LOC_PRIV_NET_LOCAL_USER;
5413 + strncpy(tempcallername,c->callername,sizeof(tempcallername));
5414 + strncpy(c->callername,display,sizeof(c->callername));
5415 + res = send_message(pri, c, Q931_RESUME_REJECT, resume_reject_ies);
5416 + strncpy(c->callername,tempcallername,sizeof(c->callername));
5420 +static int resume_acknowledge_ies[] = { Q931_CHANNEL_IDENT, Q931_DISPLAY, -1 };
5422 +int q931_resume_acknowledge(struct pri *pri, q931_call *c, int channel, char *display)
5424 + char tempcallername[256];
5427 + c->channelno = channel;
5428 + c->chanflags &= ~FLAG_PREFERRED;
5429 + c->chanflags |= FLAG_EXCLUSIVE;
5431 - return send_message(pri, c, Q931_ALERTING, alerting_ies);
5432 + c->ourcallstate = Q931_CALL_STATE_ACTIVE;
5433 + c->peercallstate = Q931_CALL_STATE_ACTIVE;
5434 + strncpy(tempcallername,c->callername,sizeof(tempcallername));
5435 + strncpy(c->callername,display,sizeof(c->callername));
5436 + res = send_message(pri, c, Q931_RESUME_ACKNOWLEDGE, resume_acknowledge_ies);
5437 + strncpy(c->callername,tempcallername,sizeof(c->callername));
5441 -static int connect_ies[] = { Q931_CHANNEL_IDENT, Q931_PROGRESS_INDICATOR, -1 };
5443 +static int connect_ies[] = { Q931_CHANNEL_IDENT, Q931_PROGRESS_INDICATOR, Q931_DISPLAY, -1 };
5444 +static int connect_NET_ies[] = { Q931_CHANNEL_IDENT, Q931_PROGRESS_INDICATOR, Q931_IE_TIME_DATE, -1 };
5446 int q931_setup_ack(struct pri *pri, q931_call *c, int channel, int nonisdn)
5448 + int network = pri->localtype == PRI_NETWORK || pri->localtype == BRI_NETWORK || pri->localtype == BRI_NETWORK_PTMP;
5450 c->ds1no = (channel & 0xff00) >> 8;
5451 c->ds1explicit = (channel & 0x10000) >> 16;
5452 @@ -2566,12 +3348,40 @@
5453 c->progressmask = PRI_PROG_CALLED_NOT_ISDN;
5455 c->progressmask = 0;
5456 +c->progressmask = PRI_PROG_INBAND_AVAILABLE;
5457 c->ourcallstate = Q931_CALL_STATE_OVERLAP_RECEIVING;
5458 c->peercallstate = Q931_CALL_STATE_OVERLAP_SENDING;
5461 + c->progloc = LOC_PRIV_NET_LOCAL_USER;
5462 + c->progcode = CODE_CCITT;
5463 + c->progressmask = Q931_PROG_INBAND_AVAILABLE;
5465 return send_message(pri, c, Q931_SETUP_ACKNOWLEDGE, connect_ies);
5468 +static void pri_setup_response_timeout(void *data)
5470 + struct q931_call *c = data;
5471 + struct pri *pri = NULL;
5476 + c->cause = PRI_CAUSE_NO_USER_RESPONSE;
5477 + if (pri->debug & PRI_DEBUG_Q931_STATE)
5478 + pri_message(pri, "No response to SETUP message\n");
5480 + pri->ev.e = PRI_EVENT_HANGUP;
5481 + pri->ev.hangup.channel = c->channelno;
5482 + pri->ev.hangup.cref = c->cr;
5483 + pri->ev.hangup.aoc_units = -1;
5484 +// pri->ev.hangup.cause = c->cause;
5485 + pri->ev.hangup.cause = PRI_CAUSE_SWITCH_CONGESTION;
5486 + pri->ev.hangup.call = c;
5487 + q931_hangup(pri, c, c->cause);
5490 static void pri_connect_timeout(void *data)
5492 struct q931_call *c = data;
5493 @@ -2624,6 +3434,7 @@
5495 int q931_connect(struct pri *pri, q931_call *c, int channel, int nonisdn)
5497 + int network = pri->localtype == PRI_NETWORK || pri->localtype == BRI_NETWORK || pri->localtype == BRI_NETWORK_PTMP;
5499 c->ds1no = (channel & 0xff00) >> 8;
5500 c->ds1explicit = (channel & 0x10000) >> 16;
5501 @@ -2638,22 +3449,37 @@
5502 c->progressmask = PRI_PROG_CALLED_NOT_ISDN;
5504 c->progressmask = 0;
5505 - c->ourcallstate = Q931_CALL_STATE_CONNECT_REQUEST;
5507 + /* WE decide when the call is up and active */
5508 + c->ourcallstate = Q931_CALL_STATE_ACTIVE;
5510 + c->ourcallstate = Q931_CALL_STATE_CONNECT_REQUEST;
5512 c->peercallstate = Q931_CALL_STATE_ACTIVE;
5516 if (c->retranstimer)
5517 pri_schedule_del(pri, c->retranstimer);
5518 c->retranstimer = 0;
5519 - if ((pri->localtype == PRI_CPE) && (!pri->subchannel))
5520 + if (!network && (!pri->subchannel)) {
5521 + /* make sure that CPEs get a CONNECT_ACKNOWLEDGE */
5522 c->retranstimer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T313], pri_connect_timeout, c);
5523 - return send_message(pri, c, Q931_CONNECT, connect_ies);
5525 + if ((pri->localtype != PRI_CPE) && (pri->localtype != BRI_CPE) && (pri->localtype != BRI_CPE_PTMP)) {
5526 + // networks may send datetime
5527 + return send_message(pri, c, Q931_CONNECT, connect_NET_ies);
5529 + return send_message(pri, c, Q931_CONNECT, connect_ies);
5533 +static int release_aoce_ies[] = { Q931_CAUSE, Q931_IE_USER_USER, Q931_IE_FACILITY, -1 };
5534 static int release_ies[] = { Q931_CAUSE, Q931_IE_USER_USER, -1 };
5536 int q931_release(struct pri *pri, q931_call *c, int cause)
5538 + int network = pri->localtype == PRI_NETWORK || pri->localtype == BRI_NETWORK || pri->localtype == BRI_NETWORK_PTMP;
5539 c->ourcallstate = Q931_CALL_STATE_RELEASE_REQUEST;
5540 /* c->peercallstate stays the same */
5542 @@ -2669,7 +3495,14 @@
5544 c->retranstimer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T308], pri_release_finaltimeout, c);
5546 - return send_message(pri, c, Q931_RELEASE, release_ies);
5547 + if (network && (c->aoc_units > -1)) {
5548 + /* include FACILITY IE for AOC-E */
5549 + aoc_aoce_charging_unit_encode(pri, c , c->aoc_units, Q931_RELEASE);
5550 + c->aoc_units = -1;
5551 + return send_message(pri, c, Q931_RELEASE, release_aoce_ies);
5553 + return send_message(pri, c, Q931_RELEASE, release_ies);
5556 return send_message(pri, c, Q931_RELEASE_COMPLETE, release_ies); /* Yes, release_ies, not release_complete_ies */
5558 @@ -2681,7 +3514,7 @@
5559 int q931_restart(struct pri *pri, int channel)
5561 struct q931_call *c;
5562 - c = q931_getcall(pri, 0 | 0x8000);
5563 + c = q931_getcall(pri, 0 | 0x8000, 0);
5567 @@ -2698,10 +3531,12 @@
5568 return send_message(pri, c, Q931_RESTART, restart_ies);
5571 +static int disconnect_aoce_ies[] = { Q931_CAUSE, Q931_IE_USER_USER, Q931_IE_FACILITY, -1 };
5572 static int disconnect_ies[] = { Q931_CAUSE, Q931_IE_USER_USER, -1 };
5574 int q931_disconnect(struct pri *pri, q931_call *c, int cause)
5576 + int network = pri->localtype == PRI_NETWORK || pri->localtype == BRI_NETWORK || pri->localtype == BRI_NETWORK_PTMP;
5577 c->ourcallstate = Q931_CALL_STATE_DISCONNECT_REQUEST;
5578 c->peercallstate = Q931_CALL_STATE_DISCONNECT_INDICATION;
5580 @@ -2713,14 +3548,27 @@
5581 if (c->retranstimer)
5582 pri_schedule_del(pri, c->retranstimer);
5583 c->retranstimer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T305], pri_disconnect_timeout, c);
5584 - return send_message(pri, c, Q931_DISCONNECT, disconnect_ies);
5585 + if (network && (c->aoc_units > -1)) {
5586 + /* include FACILITY IE for AOC-E */
5587 + aoc_aoce_charging_unit_encode(pri, c , c->aoc_units, Q931_DISCONNECT);
5588 + c->aoc_units = -1;
5589 + return send_message(pri, c, Q931_DISCONNECT, disconnect_aoce_ies);
5591 + return send_message(pri, c, Q931_DISCONNECT, disconnect_ies);
5597 +//static int setup_ies[] = { Q931_BEARER_CAPABILITY, Q931_CHANNEL_IDENT, Q931_DISPLAY, Q931_PROGRESS_INDICATOR,
5598 +// Q931_IE_SIGNAL, Q931_CALLING_PARTY_NUMBER, Q931_CALLED_PARTY_NUMBER, Q931_SENDING_COMPLETE, -1 };
5600 static int setup_ies[] = { Q931_BEARER_CAPABILITY, Q931_CHANNEL_IDENT, Q931_IE_FACILITY, Q931_PROGRESS_INDICATOR, Q931_NETWORK_SPEC_FAC, Q931_DISPLAY, Q931_IE_USER_USER,
5601 Q931_CALLING_PARTY_NUMBER, Q931_CALLED_PARTY_NUMBER, Q931_REDIRECTING_NUMBER, Q931_SENDING_COMPLETE, Q931_IE_ORIGINATING_LINE_INFO, Q931_IE_GENERIC_DIGITS, -1 };
5603 +static int setup_bri_ies[] = { Q931_BEARER_CAPABILITY, Q931_CHANNEL_IDENT, Q931_IE_FACILITY, Q931_PROGRESS_INDICATOR, Q931_NETWORK_SPEC_FAC, Q931_DISPLAY, Q931_IE_USER_USER,
5604 + Q931_CALLING_PARTY_NUMBER, Q931_CALLED_PARTY_NUMBER, Q931_REDIRECTING_NUMBER, Q931_SENDING_COMPLETE, Q931_IE_ORIGINATING_LINE_INFO, Q931_IE_GENERIC_DIGITS, Q931_HIGH_LAYER_COMPAT, Q931_LOW_LAYER_COMPAT, -1 };
5606 static int gr303_setup_ies[] = { Q931_BEARER_CAPABILITY, Q931_CHANNEL_IDENT, -1 };
5608 static int cis_setup_ies[] = { Q931_BEARER_CAPABILITY, Q931_CHANNEL_IDENT, Q931_IE_FACILITY, Q931_CALLED_PARTY_NUMBER, -1 };
5609 @@ -2728,7 +3576,12 @@
5610 int q931_setup(struct pri *pri, q931_call *c, struct pri_sr *req)
5615 + if (pri->localtype == BRI_NETWORK_PTMP) {
5621 c->transcapability = req->transmode;
5622 c->transmoderate = TRANS_MODE_64_CIRCUIT;
5623 @@ -2753,6 +3606,7 @@
5624 c->chanflags = FLAG_EXCLUSIVE;
5625 else if (c->channelno)
5626 c->chanflags = FLAG_PREFERRED;
5627 + memcpy(c->llc, req->llc, sizeof(c->llc));
5629 libpri_copy_string(c->callernum, req->caller, sizeof(c->callernum));
5630 c->callerplan = req->callerplan;
5631 @@ -2812,14 +3666,19 @@
5632 res = send_message(pri, c, Q931_SETUP, gr303_setup_ies);
5633 else if (c->justsignalling)
5634 res = send_message(pri, c, Q931_SETUP, cis_setup_ies);
5635 + else if (pri->localtype == BRI_NETWORK || pri->localtype == BRI_NETWORK_PTMP)
5636 + res = send_message(pri, c, Q931_SETUP, setup_bri_ies);
5638 res = send_message(pri, c, Q931_SETUP, setup_ies);
5642 /* make sure we call PRI_EVENT_HANGUP_ACK once we send/receive RELEASE_COMPLETE */
5643 c->sendhangupack = 1;
5644 c->ourcallstate = Q931_CALL_STATE_CALL_INITIATED;
5645 c->peercallstate = Q931_CALL_STATE_OVERLAP_SENDING;
5646 + c->t303timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T303], pri_setup_response_timeout, c);
5647 + c->t303running = 1;
5651 @@ -2835,7 +3694,11 @@
5654 c->causecode = CODE_CCITT;
5655 - c->causeloc = LOC_PRIV_NET_LOCAL_USER;
5656 + if ((pri->localtype == PRI_NETWORK) || (pri->localtype == BRI_NETWORK) || (pri->localtype == BRI_NETWORK_PTMP)) {
5657 + c->causeloc = LOC_PRIV_NET_LOCAL_USER;
5659 + c->causeloc = LOC_USER;
5661 /* release_ies has CAUSE in it */
5662 res = send_message(pri, c, Q931_RELEASE_COMPLETE, release_ies);
5664 @@ -2860,6 +3723,117 @@
5668 +/* here we cleanly hangup the phones that responded to our call but didnt get the call */
5669 +int q921_hangup(struct pri *pri, q931_call *c, int tei)
5671 + q921_call *cur,*prev;
5679 + if (pri->localtype != BRI_NETWORK_PTMP){
5682 +// pri_error(pri, "q921_hangup(%d, %d)\n", c->cr, tei);
5687 +// pri_error(pri, "tei %d\n", tei);
5694 + if (cur->tei != tei) {
5695 + c->cause = PRI_CAUSE_NORMAL_CLEARING;
5696 + c->tei = cur->tei;
5697 + if (pri->debug & PRI_DEBUG_Q921_STATE)
5698 + pri_message(pri, "sending RELEASE for TEI %d\n", cur->tei);
5699 + send_message(pri, c, Q931_RELEASE, release_ies);
5712 + if (c->tei == 127) {
5713 + q931_destroycall(pri, c->cr, c->tei);
5714 + // make sure * frees the channel
5715 +/* pri_error(pri, "returning PRI_EVENT_HANGUP_ACK\n");
5716 + res = Q931_RES_HAVEEVENT;
5717 + pri->ev.hangup.channel = c->channelno;
5718 + pri->ev.e = PRI_EVENT_HANGUP_ACK; */
5723 +/* here we handle release_completes from the phones
5724 + because some (elmeg) phones do not send a disconnect
5725 + message when the phone is busy */
5726 +int q921_handle_hangup(struct pri *pri, q931_call *c, int tei)
5728 + q921_call *cur,*match,*prev=NULL;
5735 + if (pri->localtype != BRI_NETWORK_PTMP){
5742 + if (cur->tei == tei) {
5745 + prev->next = cur->next;
5748 + c->phones = cur->next;
5753 + if (cur) cur = cur->next;
5763 + // if all phones have signalled busy AND the timer is not running anymore!
5764 + if ((left==0) && (c->cause == PRI_CAUSE_USER_BUSY) && (c->t303running == 0)) {
5765 + // pri_error(pri, "q921_handle_hangup(%d, %d, %d)\n", c->cr, tei, c->tei);
5766 + // make sure * frees the channel
5767 + res = Q931_RES_HAVEEVENT;
5768 + pri->ev.hangup.cause = PRI_CAUSE_USER_BUSY;
5769 + pri->ev.hangup.channel = c->channelno | (c->ds1no << 8);
5770 + pri->ev.hangup.cref = c->cr;
5771 + pri->ev.hangup.call = c;
5772 + pri->ev.e = PRI_EVENT_HANGUP;
5779 int q931_hangup(struct pri *pri, q931_call *c, int cause)
5782 @@ -2871,7 +3845,7 @@
5783 /* If mandatory IE was missing, insist upon that cause code */
5784 if (c->cause == PRI_CAUSE_MANDATORY_IE_MISSING)
5786 - if (cause == 34 || cause == 44 || cause == 82 || cause == 1 || cause == 81) {
5787 + if (cause == 34 || cause == 44 || cause == 82 || cause == 1 || cause == 81 || cause == 17) {
5788 /* We'll send RELEASE_COMPLETE with these causes */
5791 @@ -2885,7 +3859,7 @@
5792 case Q931_CALL_STATE_NULL:
5793 if (c->peercallstate == Q931_CALL_STATE_NULL)
5794 /* free the resources if we receive or send REL_COMPL */
5795 - q931_destroycall(pri, c->cr);
5796 + q931_destroycall(pri, c->cr, c->tei);
5797 else if (c->peercallstate == Q931_CALL_STATE_RELEASE_REQUEST)
5798 q931_release_complete(pri,c,cause);
5800 @@ -2911,6 +3885,11 @@
5801 /* received SETUP_ACKNOWLEDGE */
5802 /* send DISCONNECT in general */
5803 if (c->peercallstate != Q931_CALL_STATE_NULL && c->peercallstate != Q931_CALL_STATE_DISCONNECT_REQUEST && c->peercallstate != Q931_CALL_STATE_DISCONNECT_INDICATION && c->peercallstate != Q931_CALL_STATE_RELEASE_REQUEST && c->peercallstate != Q931_CALL_STATE_RESTART_REQUEST && c->peercallstate != Q931_CALL_STATE_RESTART) {
5804 + if (pri->localtype == BRI_NETWORK_PTMP) {
5805 + if (c->tei == 127) {
5810 q931_disconnect(pri,c,cause);
5811 else if (release_compl)
5812 @@ -2926,8 +3905,14 @@
5814 case Q931_CALL_STATE_DISCONNECT_INDICATION:
5815 /* received DISCONNECT */
5816 + if (pri->localtype == BRI_NETWORK_PTMP) {
5817 + if (c->tei == 127) {
5821 if (c->peercallstate == Q931_CALL_STATE_DISCONNECT_REQUEST) {
5823 +// pri_error(pri, "sending release to %d\n", c->tei);
5824 q931_release(pri,c,cause);
5827 @@ -2941,19 +3926,17 @@
5828 pri_error(pri, "q931_hangup shouldn't be called in this state, ourstate %s, peerstate %s\n",callstate2str(c->ourcallstate),callstate2str(c->peercallstate));
5831 - pri_error(pri, "We're not yet handling hanging up when our state is %d, contact support@digium.com, ourstate %s, peerstate %s\n",
5833 - callstate2str(c->ourcallstate),
5834 - callstate2str(c->peercallstate));
5835 + pri_error(pri, "We're not yet handling hanging up when our state is %d, contact support@digium.com, ourstate %s, peerstate %s\n",callstate2str(c->ourcallstate),callstate2str(c->peercallstate));
5838 /* we did handle hangup properly at this point */
5842 -int q931_receive(struct pri *pri, q931_h *h, int len)
5843 +int q931_receive(struct pri *pri, q931_h *h, int len, int tei)
5850 @@ -2965,6 +3948,7 @@
5851 int codeset, cur_codeset;
5853 struct apdu_event *cur = NULL;
5854 + int network = pri->localtype == PRI_NETWORK || pri->localtype == BRI_NETWORK || pri->localtype == BRI_NETWORK_PTMP;
5856 memset(last_ie, 0, sizeof(last_ie));
5857 if (pri->debug & PRI_DEBUG_Q931_DUMP)
5858 @@ -2978,13 +3962,13 @@
5859 KLUDGE this by changing byte 4 from a 0xf (SERVICE)
5860 to a 0x7 (SERVICE ACKNOWLEDGE) */
5861 h->raw[h->crlen + 2] -= 0x8;
5862 - q931_xmit(pri, h, len, 1);
5863 + q931_xmit(pri, h, len, 1, tei);
5865 } else if (h->pd != pri->protodisc) {
5866 pri_error(pri, "Warning: unknown/inappropriate protocol discriminator received (%02x/%d)\n", h->pd, h->pd);
5869 - c = q931_getcall(pri, q931_cr(h));
5870 + c = q931_getcall(pri, q931_cr(h), tei);
5872 pri_error(pri, "Unable to locate call %d\n", q931_cr(h));
5874 @@ -3007,6 +3991,7 @@
5876 if (pri->debug & PRI_DEBUG_Q931_STATE)
5877 pri_message(pri, "-- Processing Q.931 Call Setup\n");
5882 @@ -3027,28 +4012,44 @@
5883 c->callername[0] = '\0';
5884 c->callerani[0] = '\0';
5885 c->callerplanani = -1;
5886 - c->redirectingplan = -1;
5887 - c->redirectingpres = -1;
5888 - c->redirectingreason = -1;
5889 - c->origcalledplan = -1;
5890 - c->origcalledpres = -1;
5891 - c->origredirectingreason = -1;
5892 + c->redirectingplan = -1;
5893 + c->redirectingpres = -1;
5894 + c->redirectingreason = -1;
5895 + c->origcalledplan = -1;
5896 + c->origcalledpres = -1;
5897 + c->origredirectingreason = -1;
5898 c->redirectingnum[0] = '\0';
5899 c->origcallednum[0] = '\0';
5900 c->redirectingname[0] = '\0';
5901 c->origcalledname[0] = '\0';
5902 - c->useruserprotocoldisc = -1;
5903 + c->useruserprotocoldisc = -1;
5904 c->useruserinfo[0] = '\0';
5908 - /* Fall through */
5909 + c->digits[0] = '\0';
5910 + c->display[0] = '\0';
5912 + c->progressmask = 0;
5915 + if (c->t303timer) {
5916 + c->t303running = 0;
5917 + pri_schedule_del(pri, c->t303timer);
5919 + c->useruserinfo[0] = '\0';
5925 - c->useruserinfo[0] = '\0';
5927 + c->useruserinfo[0] = '\0';
5928 case Q931_CALL_PROCEEDING:
5929 + if (c->t303timer) {
5930 + c->t303running = 0;
5931 + pri_schedule_del(pri, c->t303timer);
5935 c->progressmask = 0;
5937 @@ -3059,20 +4060,22 @@
5940 case Q931_DISCONNECT:
5942 - c->causecode = -1;
5944 - c->aoc_units = -1;
5945 +// c->aoc_units = -1;
5946 + c->useruserinfo[0] = '\0';
5947 if (c->retranstimer)
5948 pri_schedule_del(pri, c->retranstimer);
5949 c->retranstimer = 0;
5950 - c->useruserinfo[0] = '\0';
5951 + if (c->t303timer) {
5952 + c->t303running = 0;
5953 + pri_schedule_del(pri, c->t303timer);
5957 case Q931_RELEASE_COMPLETE:
5958 if (c->retranstimer)
5959 - pri_schedule_del(pri, c->retranstimer);
5960 + pri_schedule_del(pri, c->retranstimer);
5961 c->retranstimer = 0;
5962 - c->useruserinfo[0] = '\0';
5963 + c->useruserinfo[0] = '\0';
5967 @@ -3089,22 +4092,32 @@
5968 case Q931_STATUS_ENQUIRY:
5970 case Q931_SETUP_ACKNOWLEDGE:
5971 + if (c->t303timer) {
5972 + c->t303running = 0;
5973 + pri_schedule_del(pri, c->t303timer);
5981 + case Q931_RETRIEVE:
5986 + case Q931_SUSPEND:
5988 case Q931_USER_INFORMATION:
5990 case Q931_CONGESTION_CONTROL:
5992 case Q931_HOLD_ACKNOWLEDGE:
5993 case Q931_HOLD_REJECT:
5994 - case Q931_RETRIEVE:
5995 case Q931_RETRIEVE_ACKNOWLEDGE:
5996 case Q931_RETRIEVE_REJECT:
5998 case Q931_RESUME_ACKNOWLEDGE:
5999 case Q931_RESUME_REJECT:
6000 - case Q931_SUSPEND:
6001 case Q931_SUSPEND_ACKNOWLEDGE:
6002 case Q931_SUSPEND_REJECT:
6003 pri_error(pri, "!! Not yet handling pre-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
6004 @@ -3113,7 +4126,7 @@
6005 pri_error(pri, "!! Don't know how to post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
6006 q931_status(pri,c, PRI_CAUSE_MESSAGE_TYPE_NONEXIST);
6008 - q931_destroycall(pri,c->cr);
6009 + q931_destroycall(pri,c->cr,c->tei);
6012 memset(mandies, 0, sizeof(mandies));
6013 @@ -3193,12 +4206,19 @@
6015 for (x=0;x<MAX_MAND_IES;x++) {
6017 - /* check if there is no channel identification when we're configured as network -> that's not an error */
6018 - if (((pri->localtype != PRI_NETWORK) || (mh->msg != Q931_SETUP) || (mandies[x] != Q931_CHANNEL_IDENT)) &&
6019 - ((mh->msg != Q931_PROGRESS) || (mandies[x] != Q931_PROGRESS_INDICATOR))) {
6020 - pri_error(pri, "XXX Missing handling for mandatory IE %d (cs%d, %s) XXX\n", Q931_IE_IE(mandies[x]), Q931_IE_CODESET(mandies[x]), ie2str(mandies[x]));
6022 + /* check if there is no channel identification when we're configured as network -> that's not an error */
6024 + if (((mh->msg == Q931_SETUP) && (mandies[x] == Q931_CHANNEL_IDENT)) ||
6025 + ((mh->msg == Q931_PROGRESS) && (mandies[x] == Q931_PROGRESS_INDICATOR))) {
6026 + /* according to ets 300 102-1 a progress indicator is mandatory, but so what? ;-) */
6028 + pri_error(pri, "XXX Missing handling for mandatory IE %d (cs%d, %s) XXX\n", Q931_IE_IE(mandies[x]), Q931_IE_CODESET(mandies[x]), ie2str(mandies[x]));
6032 + pri_error(pri, "XXX Missing handling for mandatory IE %d (cs%d, %s) XXX\n", Q931_IE_IE(mandies[x]), Q931_IE_CODESET(mandies[x]), ie2str(mandies[x]));
6038 @@ -3207,7 +4227,7 @@
6041 q931_status(pri, c, PRI_CAUSE_MANDATORY_IE_MISSING);
6042 - q931_destroycall(pri, c->cr);
6043 + q931_destroycall(pri, c->cr, c->tei);
6046 c->ourcallstate = Q931_CALL_STATE_RESTART;
6047 @@ -3225,6 +4245,7 @@
6049 /* Must be new call */
6051 + pri_error(pri, "received SETUP message for call that is not a new call (retransmission). \n");
6054 if (c->progressmask & PRI_PROG_CALLER_NOT_ISDN)
6055 @@ -3242,16 +4263,20 @@
6056 pri->ev.ring.channel = c->channelno | (c->ds1no << 8) | (c->ds1explicit << 16);
6057 pri->ev.ring.callingpres = c->callerpres;
6058 pri->ev.ring.callingplan = c->callerplan;
6059 - pri->ev.ring.callingplanani = c->callerplanani;
6060 pri->ev.ring.callingplanrdnis = c->redirectingplan;
6061 pri->ev.ring.callingplanorigcalled = c->origcalledplan;
6062 pri->ev.ring.ani2 = c->ani2;
6063 libpri_copy_string(pri->ev.ring.callingani, c->callerani, sizeof(pri->ev.ring.callingani));
6064 + pri->ev.ring.callingplanani = c->callerplanani;
6065 libpri_copy_string(pri->ev.ring.callingnum, c->callernum, sizeof(pri->ev.ring.callingnum));
6066 libpri_copy_string(pri->ev.ring.callingname, c->callername, sizeof(pri->ev.ring.callingname));
6067 pri->ev.ring.calledplan = c->calledplan;
6068 libpri_copy_string(pri->ev.ring.callingsubaddr, c->callingsubaddr, sizeof(pri->ev.ring.callingsubaddr));
6069 - libpri_copy_string(pri->ev.ring.callednum, c->callednum, sizeof(pri->ev.ring.callednum));
6070 + if (!strlen(c->callednum) && strlen(c->digitbuf)) {
6071 + libpri_copy_string(pri->ev.ring.callednum, c->digitbuf, sizeof(pri->ev.ring.callednum));
6073 + libpri_copy_string(pri->ev.ring.callednum, c->callednum, sizeof(pri->ev.ring.callednum));
6075 libpri_copy_string(pri->ev.ring.origcalledname, c->origcalledname, sizeof(pri->ev.ring.origcalledname));
6076 libpri_copy_string(pri->ev.ring.origcallednum, c->origcallednum, sizeof(pri->ev.ring.origcallednum));
6077 libpri_copy_string(pri->ev.ring.redirectingnum, c->redirectingnum, sizeof(pri->ev.ring.redirectingnum));
6078 @@ -3261,11 +4286,13 @@
6079 pri->ev.ring.redirectingreason = c->redirectingreason;
6080 pri->ev.ring.origredirectingreason = c->origredirectingreason;
6081 pri->ev.ring.flexible = ! (c->chanflags & FLAG_EXCLUSIVE);
6082 - pri->ev.ring.cref = c->cr;
6083 + pri->ev.ring.tei = c->tei;
6084 pri->ev.ring.call = c;
6085 + pri->ev.ring.cref = c->cr;
6086 pri->ev.ring.layer1 = c->userl1;
6087 pri->ev.ring.complete = c->complete;
6088 pri->ev.ring.ctype = c->transcapability;
6089 + memcpy(pri->ev.ring.lowlayercompat, c->llc, sizeof(pri->ev.ring.lowlayercompat));
6090 pri->ev.ring.redirectingreason = c->redirectingreason;
6091 pri->ev.ring.progress = c->progress;
6092 pri->ev.ring.progressmask = c->progressmask;
6093 @@ -3275,6 +4302,9 @@
6094 q931_release_complete(pri,c,PRI_CAUSE_INVALID_CALL_REFERENCE);
6097 + if (pri->localtype == BRI_NETWORK_PTMP) {
6098 + l2c = q921_getcall(pri, c, tei);
6100 c->ourcallstate = Q931_CALL_STATE_CALL_DELIVERED;
6101 c->peercallstate = Q931_CALL_STATE_CALL_RECEIVED;
6102 pri->ev.e = PRI_EVENT_RINGING;
6103 @@ -3295,17 +4325,24 @@
6104 q931_status(pri, c, PRI_CAUSE_WRONG_MESSAGE);
6107 + /* TEI got the call */
6109 c->ourcallstate = Q931_CALL_STATE_ACTIVE;
6110 c->peercallstate = Q931_CALL_STATE_CONNECT_REQUEST;
6111 pri->ev.e = PRI_EVENT_ANSWER;
6112 pri->ev.answer.channel = c->channelno | (c->ds1no << 8) | (c->ds1explicit << 16);
6113 pri->ev.answer.cref = c->cr;
6114 pri->ev.answer.call = c;
6115 + pri->ev.answer.tei = c->tei;
6116 pri->ev.answer.progress = c->progress;
6117 pri->ev.answer.progressmask = c->progressmask;
6118 libpri_copy_string(pri->ev.answer.useruserinfo, c->useruserinfo, sizeof(pri->ev.ring.useruserinfo));
6119 c->useruserinfo[0] = '\0';
6120 q931_connect_acknowledge(pri, c);
6121 + if (pri->localtype == BRI_NETWORK_PTMP) {
6122 + /* Release all other TEIs */
6123 + q921_hangup(pri, c, tei);
6125 if (c->justsignalling) { /* Make sure WE release when we initiatie a signalling only connection */
6126 q931_release(pri, c, PRI_CAUSE_NORMAL_CLEARING);
6128 @@ -3313,23 +4350,43 @@
6129 return Q931_RES_HAVEEVENT;
6132 - q931_release_complete(pri,c,PRI_CAUSE_INVALID_CALL_REFERENCE);
6135 - pri->ev.e = PRI_EVENT_FACNAME;
6136 - libpri_copy_string(pri->ev.facname.callingname, c->callername, sizeof(pri->ev.facname.callingname));
6137 - libpri_copy_string(pri->ev.facname.callingnum, c->callernum, sizeof(pri->ev.facname.callingnum));
6138 - pri->ev.facname.channel = c->channelno | (c->ds1no << 8) | (c->ds1explicit << 16);
6139 - pri->ev.facname.cref = c->cr;
6140 - pri->ev.facname.call = c;
6142 - pri_message(pri, "Sending facility event (%s/%s)\n", pri->ev.facname.callingname, pri->ev.facname.callingnum);
6144 + if ((pri->localtype == PRI_CPE) || (pri->localtype == PRI_NETWORK)) {
6145 + q931_release_complete(pri,c,PRI_CAUSE_INVALID_CALL_REFERENCE);
6147 + // BRI uses the dummy cref for sservices like ccnr
6151 + if (c->facility > 0) {
6152 + pri->ev.e = PRI_EVENT_FACILITY;
6153 + pri->ev.facility.channel = c->channelno | (c->ds1no << 8);
6154 + pri->ev.facility.cref = c->cr;
6155 + pri->ev.facility.tei = c->tei;
6156 + pri->ev.facility.call = c;
6157 + switch (c->facility) {
6158 + case 0x06: /* ECT execute */
6159 + pri->ev.facility.operation = 0x06;
6161 + case 0x0D: /* CD */
6162 + pri->ev.facility.operation = 0x0D;
6163 + libpri_copy_string(pri->ev.facility.forwardnum, c->redirectingnum, sizeof(pri->ev.facility.forwardnum));
6166 + pri->ev.facility.operation = c->facility;
6169 + pri->ev.e = PRI_EVENT_FACNAME;
6170 + libpri_copy_string(pri->ev.facname.callingname, c->callername, sizeof(pri->ev.facname.callingname));
6171 + libpri_copy_string(pri->ev.facname.callingnum, c->callernum, sizeof(pri->ev.facname.callingname));
6172 + pri->ev.facname.channel = c->channelno | (c->ds1no << 8);
6173 + pri->ev.facname.cref = c->cr;
6174 + pri->ev.facname.call = c;
6176 return Q931_RES_HAVEEVENT;
6179 q931_status(pri, c, PRI_CAUSE_MANDATORY_IE_MISSING);
6180 - q931_destroycall(pri, c->cr);
6181 + q931_destroycall(pri, c->cr, c->tei);
6184 pri->ev.e = PRI_EVENT_PROGRESS;
6185 @@ -3347,6 +4404,11 @@
6186 q931_status(pri,c,PRI_CAUSE_WRONG_MESSAGE);
6189 + if (pri->localtype == BRI_NETWORK_PTMP) {
6190 + l2c = q921_getcall(pri, c, tei);
6192 + l2c->channel = c->channelno;
6194 pri->ev.proceeding.channel = c->channelno | (c->ds1no << 8) | (c->ds1explicit << 16);
6195 if (mh->msg == Q931_CALL_PROCEEDING) {
6196 pri->ev.e = PRI_EVENT_PROCEEDING;
6197 @@ -3364,16 +4426,21 @@
6200 if (c->ourcallstate != Q931_CALL_STATE_CONNECT_REQUEST) {
6201 + if ((c->ourcallstate == Q931_CALL_STATE_ACTIVE) && (c->con_acked == 0) && (network)) {
6202 + /* sending a CONNECT_ACKNOWLEDGE is optional for CPEs */
6204 q931_status(pri,c,PRI_CAUSE_WRONG_MESSAGE);
6209 c->ourcallstate = Q931_CALL_STATE_ACTIVE;
6210 c->peercallstate = Q931_CALL_STATE_ACTIVE;
6215 q931_status(pri, c, PRI_CAUSE_MANDATORY_IE_MISSING);
6216 - q931_destroycall(pri, c->cr);
6217 + q931_destroycall(pri, c->cr, c->tei);
6221 @@ -3410,31 +4477,69 @@
6226 + if (c->peercallstate != c->sugcallstate) {
6227 + pri_error(pri, "updating callstate, peercallstate %d to %d\n", c->peercallstate, c->sugcallstate);
6228 + c->peercallstate = c->sugcallstate;
6229 + if (c->sugcallstate != Q931_CALL_STATE_ACTIVE) {
6230 + /* pass hangup to upper layer! */
6232 + pri->ev.e = PRI_EVENT_HANGUP;
6233 + res = Q931_RES_HAVEEVENT;
6235 + } else if (c->sendhangupack) {
6236 + res = Q931_RES_HAVEEVENT;
6237 + pri->ev.e = PRI_EVENT_HANGUP_ACK;
6238 + q931_hangup(pri, c, c->cause);
6240 + q931_hangup(pri, c, c->cause);
6248 case Q931_RELEASE_COMPLETE:
6249 - c->ourcallstate = Q931_CALL_STATE_NULL;
6250 - c->peercallstate = Q931_CALL_STATE_NULL;
6251 - pri->ev.hangup.channel = c->channelno | (c->ds1no << 8) | (c->ds1explicit << 16);
6252 - pri->ev.hangup.cref = c->cr;
6253 - pri->ev.hangup.cause = c->cause;
6254 - pri->ev.hangup.call = c;
6255 - libpri_copy_string(pri->ev.hangup.useruserinfo, c->useruserinfo, sizeof(pri->ev.ring.useruserinfo));
6256 - c->useruserinfo[0] = '\0';
6257 - /* Free resources */
6259 - pri->ev.e = PRI_EVENT_HANGUP;
6260 - res = Q931_RES_HAVEEVENT;
6262 - } else if (c->sendhangupack) {
6263 - res = Q931_RES_HAVEEVENT;
6264 - pri->ev.e = PRI_EVENT_HANGUP_ACK;
6265 - pri_hangup(pri, c, c->cause);
6271 - q931_hangup(pri,c,c->cause);
6272 + if (pri->localtype != BRI_NETWORK_PTMP) {
6273 + /* only stop the T303 timer if WE are not a BRI PTMP network */
6274 + if (c->t303timer) {
6275 + c->t303running = 0;
6276 + pri_schedule_del(pri, c->t303timer);
6281 + if ((pri->localtype != BRI_NETWORK_PTMP) || (c->tei == tei)) {
6282 + c->ourcallstate = Q931_CALL_STATE_NULL;
6283 + c->peercallstate = Q931_CALL_STATE_NULL;
6284 + pri->ev.hangup.channel = c->channelno | (c->ds1no << 8) | (c->ds1explicit << 16);
6285 + pri->ev.hangup.cref = c->cr;
6286 + pri->ev.hangup.cause = c->cause;
6287 + pri->ev.hangup.call = c;
6288 + libpri_copy_string(pri->ev.hangup.useruserinfo, c->useruserinfo, sizeof(pri->ev.ring.useruserinfo));
6289 + c->useruserinfo[0] = '\0';
6290 + /* Free resources */
6292 + pri->ev.e = PRI_EVENT_HANGUP;
6293 + res = Q931_RES_HAVEEVENT;
6295 + } else if (c->sendhangupack) {
6296 + res = Q931_RES_HAVEEVENT;
6297 + pri->ev.e = PRI_EVENT_HANGUP_ACK;
6298 + pri_hangup(pri, c, c->cause, -1);
6304 + q931_hangup(pri,c,c->cause);
6307 + // ignoring relase_complete
6308 + res = q921_handle_hangup(pri,c,tei);
6315 @@ -3450,6 +4555,7 @@
6316 pri->ev.e = PRI_EVENT_HANGUP;
6317 pri->ev.hangup.channel = c->channelno | (c->ds1no << 8) | (c->ds1explicit << 16);
6318 pri->ev.hangup.cref = c->cr;
6319 + pri->ev.hangup.tei = c->tei;
6320 pri->ev.hangup.cause = c->cause;
6321 pri->ev.hangup.call = c;
6322 pri->ev.hangup.aoc_units = c->aoc_units;
6323 @@ -3478,9 +4584,16 @@
6324 pri->ev.e = PRI_EVENT_HANGUP_REQ;
6325 pri->ev.hangup.channel = c->channelno | (c->ds1no << 8) | (c->ds1explicit << 16);
6326 pri->ev.hangup.cref = c->cr;
6327 + pri->ev.hangup.tei = c->tei;
6328 pri->ev.hangup.cause = c->cause;
6329 pri->ev.hangup.call = c;
6330 pri->ev.hangup.aoc_units = c->aoc_units;
6331 + if (c->progressmask & PRI_PROG_INBAND_AVAILABLE) {
6332 + pri->ev.hangup.inband_progress = 1;
6334 + pri->ev.hangup.inband_progress = 0;
6336 + pri->ev.hangup.aoc_units = c->aoc_units;
6338 return Q931_RES_HAVEEVENT;
6340 @@ -3511,7 +4624,7 @@
6341 pri->ev.e = PRI_EVENT_INFO_RECEIVED;
6342 pri->ev.ring.call = c;
6343 pri->ev.ring.channel = c->channelno | (c->ds1no << 8) | (c->ds1explicit << 16);
6344 - libpri_copy_string(pri->ev.ring.callednum, c->callednum, sizeof(pri->ev.ring.callednum));
6345 + libpri_copy_string(pri->ev.ring.callednum, c->digits, sizeof(pri->ev.ring.callednum) );
6346 libpri_copy_string(pri->ev.ring.callingsubaddr, c->callingsubaddr, sizeof(pri->ev.ring.callingsubaddr));
6347 pri->ev.ring.complete = c->complete; /* this covers IE 33 (Sending Complete) */
6348 return Q931_RES_HAVEEVENT;
6349 @@ -3531,7 +4644,6 @@
6350 pri->ev.e = PRI_EVENT_SETUP_ACK;
6351 pri->ev.setup_ack.channel = c->channelno | (c->ds1no << 8) | (c->ds1explicit << 16);
6352 pri->ev.setup_ack.call = c;
6356 if (!cur->sent && cur->message == Q931_FACILITY) {
6357 @@ -3547,19 +4659,53 @@
6358 pri->ev.notify.channel = c->channelno;
6359 pri->ev.notify.info = c->notify;
6360 return Q931_RES_HAVEEVENT;
6362 + pri->ev.e = PRI_EVENT_HOLD_REQ;
6363 + pri->ev.hold_req.call = c;
6364 + pri->ev.hold_req.cref = c->cr;
6365 + pri->ev.hold_req.tei = c->tei;
6366 + pri->ev.hold_req.channel = c->channelno;
6367 + return Q931_RES_HAVEEVENT;
6369 + case Q931_RETRIEVE:
6370 + pri->ev.e = PRI_EVENT_RETRIEVE_REQ;
6371 + pri->ev.retrieve_req.call = c;
6372 + pri->ev.retrieve_req.cref = c->cr;
6373 + pri->ev.retrieve_req.tei = c->tei;
6374 + pri->ev.retrieve_req.channel = c->channelno;
6375 + return Q931_RES_HAVEEVENT;
6377 + case Q931_SUSPEND:
6378 + pri->ev.e = PRI_EVENT_SUSPEND_REQ;
6379 + pri->ev.suspend_req.call = c;
6380 + pri->ev.suspend_req.cref = c->cr;
6381 + pri->ev.suspend_req.tei = c->tei;
6382 + pri->ev.suspend_req.channel = c->channelno;
6383 + strncpy(pri->ev.suspend_req.callid, c->callid, sizeof(pri->ev.suspend_req.callid) - 1);
6384 + return Q931_RES_HAVEEVENT;
6387 + if (pri->localtype == BRI_NETWORK_PTMP) {
6388 + l2c = q921_getcall(pri, c, tei);
6391 + pri->ev.e = PRI_EVENT_RESUME_REQ;
6392 + pri->ev.resume_req.call = c;
6393 + pri->ev.resume_req.cref = c->cr;
6394 + pri->ev.resume_req.tei = c->tei;
6395 + pri->ev.resume_req.channel = c->channelno;
6396 + strncpy(pri->ev.resume_req.callid, c->callid, sizeof(pri->ev.resume_req.callid) - 1);
6397 + return Q931_RES_HAVEEVENT;
6399 case Q931_USER_INFORMATION:
6401 case Q931_CONGESTION_CONTROL:
6403 case Q931_HOLD_ACKNOWLEDGE:
6404 case Q931_HOLD_REJECT:
6405 - case Q931_RETRIEVE:
6406 case Q931_RETRIEVE_ACKNOWLEDGE:
6407 case Q931_RETRIEVE_REJECT:
6409 case Q931_RESUME_ACKNOWLEDGE:
6410 case Q931_RESUME_REJECT:
6411 - case Q931_SUSPEND:
6412 case Q931_SUSPEND_ACKNOWLEDGE:
6413 case Q931_SUSPEND_REJECT:
6414 pri_error(pri, "!! Not yet handling post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
6415 @@ -3569,7 +4715,7 @@
6416 pri_error(pri, "!! Don't know how to post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
6417 q931_status(pri,c, PRI_CAUSE_MESSAGE_TYPE_NONEXIST);
6419 - q931_destroycall(pri,c->cr);
6420 + q931_destroycall(pri,c->cr,c->tei);