1 /******************************************************************************
2 
3   FileName:         Q931.h
4 
5   Contents:         Header and definition for the ITU-T Q.931 stack. The
6                     header contents the following parts:
7 
8                     - Definition of codes
9                     - Definition of information elements (Q931ie_).
10                     - Definition of messages (Q931mes_).
11                     - Definitian of variables (var_).
12                     - Function prototypes.
13 
14   Description:		The Q.931 stack provided here covers ITU-T Q.931 w/Q.932
15                     supplementary services for both PRI, BRI and variants.
16                     The stack is generic and designed to deal with variants as
17                     needed.
18 
19                     The stack uses the following interface functions:
20 
21                     - Q931Initialize	Initialize the Q.931 stack.
22                     - Q931Rx23			Receive a message from layer 2
23                     - Q931Tx32			Send a message to layer 2
24                     - Q931Rx43			Receive a message from layer 4 or above.
25                     - Q931Tx34			Send a message to layer 4 or above.
26                     - Q931TimeTick		Periodical timer processing.
27                     - Q931ErrorProc		Callback for stack error message.
28 
29                     The protocol is a module with no external dependencies and
30                     can easely be ported to any operating system like Windows,
31                     Linux, rtos and others.
32 
33   Related Files:	Q931.h				Q.931 Definitions
34                     Q931.c				Q.931 Interface Functions.
35                     Q931api.c			Low level L4 API functions.
36 
37                     Q932.h				Q.932 Suplementary Services
38                     Q932mes.c			Q.932 encoders/coders
39 
40                     Q931mes.c			Q.931 Message encoders/coders
41                     Q931ie.c			Q.931 IE encoders/coders
42                     Q931StateTE.c		Generic Q.931 TE State Engine
43                     Q931StateNT.c		Generic Q.931 NT State Engine
44 
45   Design Note 1:	For each variant please add separate files starting with
46                     the	variant short-name as follows:
47 
48                     <variant>.h			Spesific headers needed.
49                     <variant>mes.c		Message encoders/decores.
50                     <variant>ie.c		IE encoders/decoders.
51                     <variant>StateTE.c	TE side state engine.
52                     <variant>StateNT.c	NT side state engine.
53 
54   Design Note 2:	The stack is deliberatly made non-threading. Use 1
55                     thread per Trunk, but lock access from the timertick
56                     and rx, tx functions. And make sure the callbacks only
57                     dump messages to a queue, no time-consuming processing
58                     inside stack processing.
59 
60                     All stack processing is async 'fire and forget', meaning
61                     that there are not, and should not be any time-consuming
62                     processing within the stack-time. The best way to thread
63                     a stack is to use one single thread that signal 5 queues.
64 
65                     - Incoming L2 queue.
66                     - Incoming L4 queue.
67                     - Outgoing L2 queue.
68                     - Outgoing L4 queue.
69                     - Error/Trace queue.
70 
71   Design Note 3:	DSP optimization. The L3 (Rx23) can be called directly
72                     from a HDLC receiver without usage of queues for optimized
73                     processing. But keep in mind that Q.931 calls Tx34 or Tx32
74                     as part	of receiving a message from Layer 2.
75 
76   License/Copyright:
77 
78   Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
79   email:janvb@caselaboratories.com
80 
81   Redistribution and use in source and binary forms, with or without
82   modification, are permitted provided that the following conditions are
83   met:
84 
85     * Redistributions of source code must retain the above copyright notice,
86 	  this list of conditions and the following disclaimer.
87     * Redistributions in binary form must reproduce the above copyright notice,
88 	  this list of conditions and the following disclaimer in the documentation
89 	  and/or other materials provided with the distribution.
90     * Neither the name of the Case Labs, Ltd nor the names of its contributors
91 	  may be used to endorse or promote products derived from this software
92 	  without specific prior written permission.
93 
94   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
95   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
96   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
97   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
98   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
99   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
100   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
101   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
102   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
103   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
104   POSSIBILITY OF SUCH DAMAGE.
105 ******************************************************************************/
106 
107 #ifndef _Q931_NL
108 #define _Q931_NL
109 
110 /* uncomment the #define below to add x.25 support to the Q.931				*/
111 /* #define Q931_X25_SUPPORT */
112 
113 #include "stdio.h"
114 
115 #ifdef _MSC_VER
116 #pragma warning(disable:4100)
117 #ifndef strcasecmp
118 #define strcasecmp(s1, s2) _stricmp(s1, s2)
119 #endif
120 #endif
121 #include <string.h>
122 
123 
124 /*****************************************************************************
125 
126   Enum helper macros  <Need description of these macros>
127 
128 *****************************************************************************/
129 #define Q931_ENUM_NAMES(_NAME, _STRINGS) static const char * _NAME [] = { _STRINGS , NULL };
130 #define Q931_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (const char *name); const char * _FUNC2 (_TYPE type);
131 #define Q931_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX)	\
132 	_TYPE _FUNC1 (const char *name)								\
133 	{														\
134 		int i;												\
135 		_TYPE t = _MAX ;									\
136 															\
137 		for (i = 0; i < _MAX ; i++) {						\
138 			if (!strcasecmp(name, _STRINGS[i])) {			\
139 				t = (_TYPE) i;								\
140 				break;										\
141 			}												\
142 		}													\
143 															\
144 		return t;											\
145 	}														\
146 	const char * _FUNC2 (_TYPE type)						\
147 	{														\
148 		if (type > _MAX) {									\
149 			type = _MAX;									\
150 		}													\
151 		return _STRINGS[(int)type];							\
152 	}														\
153 
154 /*****************************************************************************
155 
156   Error Codes
157 
158 *****************************************************************************/
159 typedef enum {
160 	Q931E_NO_ERROR				=	0,
161 
162 	Q931E_UNKNOWN_MESSAGE		=	-3001,
163 	Q931E_ILLEGAL_IE			=	-3002,
164 	Q931E_UNKNOWN_IE			=	-3003,
165 	Q931E_BEARERCAP				=	-3004,
166 	Q931E_HLCOMP				=	-3005,
167 	Q931E_LLCOMP				=	-3006,
168 	Q931E_INTERNAL              =	-3007,
169 	Q931E_MISSING_CB            =	-3008,
170 	Q931E_UNEXPECTED_MESSAGE    =	-3009,
171 	Q931E_ILLEGAL_MESSAGE		=	-3010,
172 	Q931E_TOMANYCALLS           =	-3011,
173 	Q931E_INVALID_CRV           =	-3012,
174 	Q931E_CALLID                =	-3013,
175 	Q931E_CALLSTATE             =	-3014,
176 	Q931E_CALLEDSUB             =	-3015,
177 	Q931E_CALLEDNUM             =	-3016,
178 	Q931E_CALLINGNUM            =	-3017,
179 	Q931E_CALLINGSUB            =	-3018,
180 	Q931E_CAUSE                 =	-3019,
181 	Q931E_CHANID                =	-3020,
182 	Q931E_DATETIME              =	-3021,
183 	Q931E_DISPLAY               =	-3022,
184 	Q931E_KEYPADFAC             =	-3023,
185 	Q931E_NETFAC                =	-3024,
186 	Q931E_NOTIFIND              =	-3025,
187 	Q931E_PROGIND               =	-3026,
188 	Q931E_RESTARTIND            =	-3027,
189 	Q931E_SEGMENT               =	-3028,
190 	Q931E_SIGNAL                =	-3029,
191 	Q931E_GENERIC_DIGITS		=	-3030
192 } q931_error_t;
193 
194 /* The q931_error_t enum should be kept in sync with the q931_error_names array in Q931.c */
195 
196 const char *q931_error_to_name(q931_error_t error);
197 
198 /*****************************************************************************
199 
200 	Some speed optimization can be achieved by changing all variables to the
201 	word size of your processor. A 32 bit processor has to do a lot of extra
202 	work to read a packed 8 bit integer. Changing all fields to 32 bit integer
203 	will result in usage of some extra space, but will speed up the stack.
204 
205 	The stack has been designed to allow L3UCHAR etc. to be any size of 8 bit
206 	or larger.
207 
208 *****************************************************************************/
209 
210 #define L3UCHAR		unsigned char		/* Min 8 bit						*/
211 #define L3USHORT	unsigned short		/* Min 16 bit unsigned				*/
212 #define L3UINT		unsigned int		/* Min 16 bit unsigned	            */
213 #define L3INT       int                 /* Min 16 bit signed                */
214 #define L3ULONG		unsigned long		/* Min 32 bit						*/
215 #define L3BOOL      char				/* Min 1 bit, valuse 0 & 1 only		*/
216 
217 #define L3TRUE      1
218 #define L3FALSE     0
219 
220 /*****************************************************************************
221 
222   Global defines.
223 
224 *****************************************************************************/
225 
226 typedef L3USHORT ie;                /* Special data type to hold a dynamic  */
227                                     /* or optional information element as   */
228                                     /* part of a message struct. MSB = 1    */
229                                     /* indicate that the ie is present, the */
230                                     /* last 15 bits is an offset ( or the   */
231                                     /* value for single octet ) to the      */
232                                     /* struct holding the ie. Offset = 0    */
233                                     /* is buf[1] etc.                       */
234                                     /* ie == 0xffff indicates error         */
235 
236 /*****************************************************************************
237 
238 	MAXTRUNKS sets how many physical trunks this system might have. This
239 	number should be keept at a minimum since it will use global space.
240 
241 	It is recommended that you leave MAXCHPERTRUNK as is
242 
243 *****************************************************************************/
244 
245 #define	Q931_LOGBUFSIZE	1024		/* size of logging buffer		*/
246 
247 #define Q931L4BUF	1000		/* size of message buffer		*/
248 
249 #define Q931L2BUF	300		/* size of message buffer		*/
250 
251 #define Q931MAXTRUNKS	4		/* Total number of trunks that will be	*/
252 					/* processed by this instance of the	*/
253 					/* stack				*/
254 
255 #define Q931MAXCHPERTRUNK	32	/* Number of channels per trunk. The	*/
256 					/* stack uses a static set of 32	*/
257 					/* channels regardless if it is E1, T1	*/
258 					/* or BRI that actually is used.	*/
259 
260 #define Q931MAXCALLPERTRUNK	(Q931MAXCHPERTRUNK * 2)
261 					/* Number of max active CRV per trunk.  */
262 					/* Q.931 can have more calls than there */
263 					/* are channels.			*/
264 
265 
266 #define Q931_IS_BRI(x)		((x)->TrunkType == Q931_TrType_BRI || (x)->TrunkType == Q931_TrType_BRI_PTMP)
267 #define Q931_IS_PRI(x)		(!Q931_IS_BRI(x))
268 
269 #define Q931_IS_PTP(x)		((x)->TrunkType != Q931_TrType_BRI_PTMP)
270 #define Q931_IS_PTMP(X)		((x)->TrunkType == Q931_TrType_BRI_PTMP)
271 
272 #define Q931_BRI_MAX_CRV	127
273 #define Q931_PRI_MAX_CRV	32767
274 
275 /*****************************************************************************
276 
277   The following defines control the dialect switch tables and should only be
278   changed when a new dialect needs to be inserted into the stack.
279 
280   This stack uses an array of functions to know which function to call as
281   it receives a SETUP message etc. A new dialect can when choose to use
282   the proc etc. for standard Q.931 or insert a modified proc.
283 
284   This technique has also been used to distinguish between user and network
285   mode to make the code as easy to read and maintainable as possible.
286 
287   A message and IE index have been used to save space. These indexes allowes
288   the message or IE code to be used directly and will give back a new index
289   into the table.
290 
291 *****************************************************************************/
292 
293 /* WARNING! Initialize Q931CreateDialectCB[] will NULL when increasing the */
294 /* Q931MAXDLCT value to avoid Q931Initialize from crashing if one entry is */
295 /* not used.								   */
296 #define Q931MAXDLCT	8	/* Max dialects included in this        */
297 				/* compile. User and Network count as   */
298 				/* one dialect each.                    */
299 
300 #define Q931MAXMES	128		/* Number of messages				*/
301 #define Q931MAXIE	255		/* Number of IE					*/
302 #define Q931MAXUSEDIE	50		/* Maximum number of ie types per Dialect	*/
303 #define Q931MAXCODESETS	7		/* Maximum number of codests (by spec, 0-7)	*/
304 #define Q931MAXSTATE	100		/* Size of state tables			        */
305 #define Q931MAXTIMER	25		/* Maximum number of timers 			*/
306 
307 /*****************************************************************************
308 
309   Call States for ITU-T Q.931 TE (User Mode)
310 
311 *****************************************************************************/
312 
313 #define Q931_U0     0
314 #define Q931_U1     1
315 #define Q931_U2     2
316 #define Q931_U3     3
317 #define Q931_U4     4
318 #define Q931_U6     6
319 #define Q931_U7     7
320 #define Q931_U8     8
321 #define Q931_U9     9
322 #define Q931_U10    10
323 #define Q931_U11    11
324 #define Q931_U12    12
325 #define Q931_U15    15
326 #define Q931_U17    17
327 #define Q931_U19    19
328 #define Q931_U25    25
329 
330 /*****************************************************************************
331 
332   Call States for ITU-T Q.931 NT (Network Mode)
333 
334 *****************************************************************************/
335 #define Q931_N0     (0x0100 | 0)
336 #define Q931_N1     (0x0100 | 1)
337 #define Q931_N2     (0x0100 | 2)
338 #define Q931_N3     (0x0100 | 3)
339 #define Q931_N4     (0x0100 | 4)
340 #define Q931_N6     (0x0100 | 6)
341 #define Q931_N7     (0x0100 | 7)
342 #define Q931_N8     (0x0100 | 8)
343 #define Q931_N9     (0x0100 | 9)
344 #define Q931_N10    (0x0100 | 11)
345 #define Q931_N11    (0x0100 | 11)
346 #define Q931_N12    (0x0100 | 12)
347 #define Q931_N15    (0x0100 | 15)
348 #define Q931_N17    (0x0100 | 17)
349 #define Q931_N19    (0x0100 | 19)
350 #define Q931_N22    (0x0100 | 22)
351 #define Q931_N25    (0x0100 | 25)
352 
353 /*****************************************************************************
354 
355   Q.931 Message codes
356 
357 *****************************************************************************/
358 
359 #define Q931mes_ALERTING             0x01 /* 0000 0001                   */
360 #define Q931mes_CALL_PROCEEDING      0x02 /* 0000 0010                   */
361 #define Q931mes_CONNECT              0x07 /* 0000 0111                   */
362 #define Q931mes_CONNECT_ACKNOWLEDGE  0x0f /* 0000 1111                   */
363 #define Q931mes_PROGRESS             0x03 /* 0000 0011                   */
364 #define Q931mes_SETUP                0x05 /* 0000 0101                   */
365 #define Q931mes_SETUP_ACKNOWLEDGE    0x0d /* 0000 1101                   */
366 #define Q931mes_RESUME               0x26 /* 0010 0110                   */
367 #define Q931mes_RESUME_ACKNOWLEDGE   0x2e /* 0010 1110                   */
368 #define Q931mes_RESUME_REJECT        0x22 /* 0010 0010                   */
369 #define Q931mes_SUSPEND              0x25 /* 0010 0101                   */
370 #define Q931mes_SUSPEND_ACKNOWLEDGE  0x2d /* 0010 1101                   */
371 #define Q931mes_SUSPEND_REJECT       0x21 /* 0010 0001                   */
372 #define Q931mes_USER_INFORMATION     0x20 /* 0010 0000                   */
373 #define Q931mes_DISCONNECT           0x45 /* 0100 0101                   */
374 #define Q931mes_RELEASE              0x4d /* 0100 1101                   */
375 #define Q931mes_RELEASE_COMPLETE     0x5a /* 0101 1010                   */
376 #define Q931mes_RESTART              0x46 /* 0100 0110                   */
377 #define Q931mes_RESTART_ACKNOWLEDGE  0x4e /* 0100 1110                   */
378 #define Q931mes_CONGESTION_CONTROL   0x79 /* 0111 1001                   */
379 #define Q931mes_INFORMATION          0x7b /* 0111 1011                   */
380 #define Q931mes_NOTIFY               0x6e /* 0110 1110                   */
381 #define Q931mes_STATUS               0x7d /* 0111 1101                   */
382 #define Q931mes_STATUS_ENQUIRY       0x75 /* 0111 0101                   */
383 #define Q931mes_SEGMENT              0x60 /* 0110 0000                   */
384 
385 #define Q931mes_SERVICE              0x0f /* 0000 1111                   */
386 #define Q931mes_SERVICE_ACKNOWLEDGE  0x07 /* 0000 0111                   */
387 
388 
389 /**
390  * Generic Q.931 Timers
391  */
392 enum {
393 	Q931_TIMER_T300	= 1,		/* */
394 	Q931_TIMER_T301,
395 	Q931_TIMER_T302,
396 	Q931_TIMER_T303,
397 	Q931_TIMER_T304,
398 	Q931_TIMER_T305,
399 	Q931_TIMER_T306,
400 	Q931_TIMER_T307,
401 	Q931_TIMER_T308,
402 	Q931_TIMER_T309,
403 	Q931_TIMER_T310,
404 	Q931_TIMER_T311,
405 	Q931_TIMER_T312,
406 	Q931_TIMER_T313,
407 	Q931_TIMER_T314,
408 	Q931_TIMER_T315,
409 	Q931_TIMER_T316,
410 	Q931_TIMER_T317,
411 	Q931_TIMER_T318,
412 	Q931_TIMER_T319,
413 	Q931_TIMER_T320,
414 	Q931_TIMER_T321,
415 	Q931_TIMER_T322,
416 };
417 
418 /**
419  * Q.931 ToN
420  */
421 enum {
422 	Q931_TON_UNKNOWN		= 0x00,
423 	Q931_TON_INTERNATIONAL		= 0x01,
424 	Q931_TON_NATIONAL		= 0x02,
425 	Q931_TON_NETWORK_SPECIFIC	= 0x03,
426 	Q931_TON_SUBSCRIBER_NUMBER	= 0x04,
427 	Q931_TON_ABBREVIATED_NUMBER	= 0x06,
428 	Q931_TON_RESERVED		= 0x07
429 };
430 
431 /**
432  * Q.931 Numbering Plan
433  */
434 enum {
435 	Q931_NUMPLAN_UNKNOWN		= 0x00,
436 	Q931_NUMPLAN_E164		= 0x01,
437 	Q931_NUMPLAN_X121		= 0x03,
438 	Q931_NUMPLAN_F69		= 0x04,
439 	Q931_NUMPLAN_NATIONAL		= 0x08,
440 	Q931_NUMPLAN_PRIVATE		= 0x09,
441 	Q931_NUMPLAN_RESERVED		= 0x0e
442 };
443 
444 /**
445  * Q.931 Presentation Indicator
446  */
447 enum {
448 	Q931_PRES_ALLOWED		= 0x00,
449 	Q931_PRES_RESTRICTED		= 0x01,
450 	Q931_PRES_NOT_AVAILABLE		= 0x02,
451 	Q931_PRES_RESERVED		= 0x03
452 };
453 
454 /**
455  * Q.931 Screening Indicator
456  */
457 enum {
458 	Q931_SCREEN_USER_NOT_SCREENED		= 0x00,
459 	Q931_SCREEN_USER_VERIFIED_PASSED	= 0x01,
460 	Q931_SCREEN_USER_VERIFIED_FAILED	= 0x02,
461 	Q931_SCREEN_NETWORK			= 0x03
462 };
463 
464 /**
465  * Q.931 Coding Standard
466  */
467 enum {
468 	Q931_CODING_ITU		= 0x00,
469 	Q931_CODING_ISO		= 0x01,
470 	Q931_CODING_NATIONAL	= 0x02,
471 	Q931_CODING_NETWORK	= 0x03
472 };
473 
474 /**
475  * Q.931 High layer characteristik id
476  */
477 enum {
478 	Q931_HLCHAR_TELEPHONY	= 0x01,
479 	Q931_HLCHAR_FAX_G23	= 0x04,
480 	Q931_HLCHAR_FAX_G4	= 0x21,
481 	Q931_HLCHAR_FAX_G4II	= 0x24,
482 	Q931_HLCHAR_T102	= 0x32,
483 	Q931_HLCHAR_T101	= 0x33,
484 	Q931_HLCHAR_F60		= 0x35,
485 	Q931_HLCHAR_X400	= 0x38,
486 	Q931_HLCHAR_X200	= 0x41
487 };
488 
489 /**
490  * Q.931 User information layer 1 protocol
491  */
492 enum {
493 	Q931_UIL1P_V110		= 0x01,
494 	Q931_UIL1P_I460		= 0x01,
495 	Q931_UIL1P_X30		= 0x01,
496 
497 	Q931_UIL1P_G711U	= 0x02,
498 	Q931_UIL1P_G711A	= 0x03,
499 	Q931_UIL1P_G721		= 0x04,
500 
501 	Q931_UIL1P_H221		= 0x05,
502 	Q931_UIL1P_H242		= 0x05,
503 
504 	Q931_UIL1P_H223		= 0x06,
505 	Q931_UIL1P_H245		= 0x06,
506 
507 	Q931_UIL1P_RATE_ADAP	= 0x07,
508 
509 	Q931_UIL1P_V120		= 0x08,
510 	Q931_UIL1P_X31		= 0x09
511 };
512 
513 /**
514  * Q.931 Information Transfer Capability
515  */
516 enum {
517 	Q931_ITC_SPEECH			= 0x00,
518 	Q931_ITC_UNRESTRICTED		= 0x08,
519 	Q931_ITC_RESTRICTED		= 0x09,
520 	Q931_ITC_3K1_AUDIO		= 0x10,
521 	Q931_ITC_UNRESTRICTED_TONES	= 0x11,
522 	Q931_ITC_VIDEO			= 0x18
523 };
524 
525 /**
526  * Q.931 Information transfer rate
527  */
528 enum {
529 	Q931_ITR_PACKET	= 0x00,
530 	Q931_ITR_64K	= 0x10,
531 	Q931_ITR_128K	= 0x11,
532 	Q931_ITR_384K	= 0x13,
533 	Q931_ITR_1536K	= 0x15,
534 	Q931_ITR_1920K	= 0x17,
535 	Q931_ITR_MULTI	= 0x18
536 };
537 
538 /*****************************************************************************
539 
540   Struct:       Q931mes_Header
541 
542   Description:  Used to read the header & message code.
543 
544 *****************************************************************************/
545 typedef struct {
546 	L3UINT	Size;           /* Size of message in bytes             */
547 	L3UCHAR	ProtDisc;       /* Protocol Discriminator               */
548 	L3UCHAR	MesType;        /* Message type                         */
549 	L3UCHAR	CRVFlag;        /* Call reference value flag            */
550 	L3INT	CRV;            /* Call reference value                 */
551 
552 } Q931mes_Header;
553 
554 /*****************************************************************************
555 
556   Struct:       Q931mes_Generic
557 
558   Description:  Generic header containing all IE's. This is not used, but is
559 				provided in case a proprietary variant needs it.
560 
561 *****************************************************************************/
562 typedef struct {
563 	L3UINT		Size;           /* Size of message in bytes             */
564 	L3UCHAR		ProtDisc;       /* Protocol Discriminator               */
565 	L3UCHAR		MesType;        /* Message type                         */
566 	L3UCHAR		CRVFlag;        /* Call reference value flag            */
567 	L3INT		CRV;            /* Call reference value                 */
568 
569 	/* WARNING: don't touch anything above this line (TODO: use Q931mes_Header directly to make sure it's the same) */
570 
571 	L3UCHAR		Tei;            /* TEI                                  */
572 
573 	ie		Shift;
574 	ie		MoreData;
575 	ie		SendComplete;
576 	ie		CongestionLevel;
577 	ie		RepeatInd;
578 
579 	ie		Segment;        /* Segmented message                    */
580 	ie		BearerCap;      /* Bearer Capability                    */
581 	ie		Cause;          /* Cause                                */
582 	ie		CallState;      /* Call State                           */
583 	ie		CallID;			/* Call Identity                        */
584 	ie		ChanID;         /* Channel Identification               */
585 	ie		ChangeStatus;   /* Change Staus                         */
586 	ie		ProgInd;        /* Progress Indicator                   */
587 	ie		NetFac;         /* Network Spesific Facilities          */
588 	ie		NotifInd;       /* Notification Indicator               */
589 	ie		Display;        /* Display                              */
590 	ie		DateTime;       /* Date/Time                            */
591 	ie		KeypadFac;      /* Keypad Facility                      */
592 	ie		Signal;         /* Signal                               */
593 	ie		InfoRate;       /* Information rate                     */
594 	ie		EndEndTxDelay;  /* End to End Transmit Delay            */
595 	ie		TransDelSelInd; /* Transmit Delay Sel. and Ind.         */
596 	ie		PackParam;      /* Packed Layer Binary parameters       */
597 	ie		PackWinSize;    /* Packet Layer Window Size             */
598 	ie		PackSize;       /* Packed Size                          */
599 	ie		ClosedUserGrp;  /* Closed User Group                    */
600 	ie		RevChargeInd;   /* Reverse Charging Indicator           */
601 	ie		CalledNum;      /* Called Party Number                  */
602 	ie		CalledSub;      /* Called Party subaddress              */
603 	ie		CallingNum;     /* Calling Party Number                 */
604 	ie		CallingSub;     /* Calling Party Subaddress             */
605 	ie		RedirNum;       /* Redirection Number                   */
606 	ie		TransNetSel;    /* Transmit Network Selection           */
607 	ie		LLRepeatInd;    /* Repeat Indicator 2 LLComp            */
608 	ie		RestartWin;     /* Restart Window                       */
609 	ie		RestartInd;     /* Restart Indicator                    */
610 	ie		LLComp;         /* Low Layer Compatibility              */
611 	ie		HLComp;         /* High Layer Compatibility             */
612 	ie		UserUser;       /* User-user                            */
613 	ie		Escape;         /* Escape for extension                 */
614 	ie		Switchhook;
615 	ie		FeatAct;
616 	ie		FeatInd;
617 	ie		GenericDigits;
618 
619 	L3UCHAR		buf[1];			/* Buffer for IE's						*/
620 
621 } Q931mes_Generic;
622 
623 
624 /*****************************************************************************
625 
626   Struct:       Q931_TrunkInfo
627 
628   Description:  TrunkInfo is the struct entry used to store Q.931 related
629                 information and state for E1/T1/J1 trunks and associated
630                 channels in the system.
631 
632 				The user should store this information outside this stack
633 				and needs to feed the interface functions with a pointer to
634 				the TrunkInfo entry.
635 
636 *****************************************************************************/
637 typedef struct Q931_TrunkInfo Q931_TrunkInfo_t;
638 
639 typedef enum {
640     Q931_LOG_NONE = -1,
641     Q931_LOG_EMERG,
642     Q931_LOG_ALERT,
643     Q931_LOG_CRIT,
644     Q931_LOG_ERROR,
645     Q931_LOG_WARNING,
646     Q931_LOG_NOTICE,
647     Q931_LOG_INFO,
648     Q931_LOG_DEBUG
649 } Q931LogLevel_t;
650 
651 typedef L3INT (*Q931Tx34CB_t) (void *,L3UCHAR *, L3INT);
652 typedef L3INT (*Q931Tx32CB_t) (void *, L3INT, L3UCHAR, L3UCHAR *, L3INT);
653 typedef L3INT (*Q931ErrorCB_t) (void *,L3INT,L3INT,L3INT);
654 typedef L3INT (*Q931LogCB_t) (void *, Q931LogLevel_t, char *, L3INT);
655 
656 typedef enum {					/* Network/User Mode.			*/
657 	Q931_TE=0,				/*  0 : User Mode			*/
658 	Q931_NT=1				/*  1 : Network Mode			*/
659 } Q931NetUser_t;
660 
661 typedef enum {					/* Dialect enum                         */
662 	Q931_Dialect_Q931     = 0,
663 	Q931_Dialect_National = 2,
664 	Q931_Dialect_DMS      = 4,
665 	Q931_Dialect_5ESS     = 6,		/* Coming soon to a PRI stack near you! */
666 
667 	Q931_Dialect_Count
668 } Q931Dialect_t;
669 #define DIALECT_STRINGS "q931", "", "national", "", "dms", "", "5ess", ""
670 Q931_STR2ENUM_P(q931_str2Q931Dialect_type, q931_Q931Dialect_type2str, Q931Dialect_t)
671 
672 typedef enum {					/* Trunk Line Type.			*/
673 	Q931_TrType_E1 = 0,			/*  0 : E1 Trunk			*/
674 	Q931_TrType_T1 = 1,			/*  1 : T1 Trunk			*/
675 	Q931_TrType_J1 = 2,			/*  2 : J1 Trunk			*/
676 	Q931_TrType_BRI	= 3,			/*  3 : BRI Trunk			*/
677 	Q931_TrType_BRI_PTMP = 4		/*  4 : BRI PTMP Trunk			*/
678 } Q931_TrunkType_t;
679 
680 typedef enum {					/* Trunk State			*/
681 	Q931_TrState_NoAlignment=0,		/* Trunk not aligned		*/
682 	Q931_TrState_Aligning=1,		/* Aligning in progress		*/
683 	Q931_TrState_Aligned=2			/* Trunk Aligned		*/
684 } Q931_TrunkState_t;
685 
686 typedef enum {
687 	Q931_ChType_NotUsed=0,			/* Unused Channel						*/
688 	Q931_ChType_B=1,			/* B Channel (Voice)					*/
689 	Q931_ChType_D=2,			/* D Channel (Signalling)				*/
690 	Q931_ChType_Sync=3			/* Sync Channel							*/
691 } Q931_ChanType_t;
692 
693 struct Q931_Call
694 {
695 	L3UCHAR InUse;			/* Indicate if entry is in use.         */
696 					/*  0 = Not in Use                      */
697 					/*  1 = Active Call.                    */
698 
699 	L3UCHAR Tei;			/* Associated TEI 			*/
700 
701 	L3UCHAR BChan;			/* Associated B Channel.                */
702 					/* 0 - 31 valid B chan			*/
703 					/* 255 = Not allocated			*/
704 
705 	L3INT   CRV;			/* Associated CRV.                      */
706 
707 	L3UINT  State;			/* Call State.                          */
708 					/*  0 is Idle, but other values are	*/
709 					/*  defined per dialect.		*/
710 					/*  Default usage is 1-99 for TE and    */
711 					/*  101 - 199 for NT.			*/
712 
713 	L3ULONG Timer;			/* Timer in ms. The TimeTick will check		*/
714 					/* if this has exceeded the timeout, and	*/
715 					/* if so call the timers timeout proc.		*/
716 
717 	L3USHORT TimerID;		/* Timer Identification/State           */
718 					/* actual values defined by dialect	*/
719 					/*  0 : No timer running                */
720 					/*  ITU-T Q.931:301 - 322 Timer running */
721 };
722 
723 struct Q931_TrunkInfo
724 {
725 	Q931NetUser_t    NetUser;		/* Network/User Mode.                   */
726 	Q931_TrunkType_t TrunkType;		/* Trunk Line Type.                     */
727 	Q931Dialect_t    Dialect;		/* Q.931 Based dialect index.           */
728 
729 	Q931Tx34CB_t     Q931Tx34CBProc;
730 	Q931Tx32CB_t     Q931Tx32CBProc;
731 	Q931ErrorCB_t    Q931ErrorCBProc;
732 	Q931LogCB_t      Q931LogCBProc;
733 	void *PrivateData32;
734 	void *PrivateData34;
735 	void *PrivateDataLog;
736 
737 	Q931LogLevel_t   loglevel;
738 
739 	L3UCHAR     Enabled;            /* Enabled/Disabled                     */
740                                     /*  0 = Disabled                        */
741                                     /*  1 = Enabled                         */
742 
743 	Q931_TrunkState_t TrunkState;
744 
745     L3INT       LastCRV;            /* Last used crv for the trunk.         */
746 
747     L3UCHAR L3Buf[Q931L4BUF];		/* message buffer for messages to be    */
748                                     /* send from Q.931 L4.                  */
749 
750     L3UCHAR L2Buf[Q931L2BUF];		/* buffer for messages send to L2.      */
751 
752 	/* The auto flags below switch on/off automatic Ack messages. SETUP ACK */
753 	/* as an example can be sent by the stack in response to SETUP to buy   */
754 	/* time in processing on L4. Setting this to true will cause the stack  */
755 	/* to automatically send this.											*/
756 
757 	L3BOOL	autoSetupAck;			/* Indicate if the stack should send    */
758 									/* SETUP ACK or not. 0=No, 1 = Yes.		*/
759 
760 	L3BOOL  autoConnectAck;			/* Indicate if the stack should send    */
761 									/* CONNECT ACT or not. 0=No, 1=Yes.		*/
762 
763 	L3BOOL  autoRestartAck;			/* Indicate if the stack should send    */
764 									/* RESTART ACK or not. 0=No, 1=Yes.		*/
765 
766 	L3BOOL  autoServiceAck;			/* Indicate if the stack should send    */
767 									/* SERVICE ACK or not. 0=No, 1=Yes.		*/
768 
769 	/* channel array holding info per channel. Usually defined to 32		*/
770 	/* channels to fit an E1 since T1/J1 and BRI will fit inside a E1.		*/
771     struct _charray
772     {
773 		Q931_ChanType_t ChanType;	/* Unused, B, D, Sync */
774 
775         L3UCHAR Available;          /* Channel Available Flag               */
776                                     /*  0 : Avaiabled                       */
777                                     /*  1 : Used                            */
778 
779         L3INT   CRV;                /* Associated CRV                       */
780 
781     } ch[Q931MAXCHPERTRUNK];
782 
783 	/* Active Call information indentified by CRV. See Q931AllocateCRV for  */
784 	/* initialization of call table.					*/
785 	struct Q931_Call	call[Q931MAXCALLPERTRUNK];
786 };
787 
788 /*****************************************************************************
789 
790   Struct:		Q931State
791 
792   Description:	Define a Q931 State, legal events and next state for each
793 				event. Used to simplify the state engine logic. Each state
794 				engine defines its own state table and the logic need only
795 				call a helper function to check if the message is legal
796 				at this stage.
797 
798 *****************************************************************************/
799 typedef struct
800 {
801 	L3INT		State;
802 	L3INT		Message;
803 	L3UCHAR		Direction;
804 } Q931State;
805 
806 /*****************************************************************************
807 
808   Proc table external references.
809 
810   The proc tables are defined in Q931.c and initialized in Q931Initialize.
811 
812 *****************************************************************************/
813 typedef L3INT (q931proc_func_t) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *, L3INT);
814 
815 typedef L3INT (q931umes_func_t) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size);
816 typedef L3INT (q931pmes_func_t) (Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
817 
818 typedef L3INT (q931uie_func_t) (Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff);
819 typedef L3INT (q931pie_func_t) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet);
820 
821 typedef L3INT (q931timeout_func_t) (Q931_TrunkInfo_t *pTrunk, L3INT callIndex);
822 typedef L3ULONG q931timer_t;
823 
824 extern q931proc_func_t *Q931Proc[Q931MAXDLCT][Q931MAXMES];
825 
826 extern q931umes_func_t *Q931Umes[Q931MAXDLCT][Q931MAXMES];
827 extern q931pmes_func_t *Q931Pmes[Q931MAXDLCT][Q931MAXMES];
828 
829 extern q931uie_func_t *Q931Uie[Q931MAXDLCT][Q931MAXIE];
830 extern q931pie_func_t *Q931Pie[Q931MAXDLCT][Q931MAXIE];
831 
832 extern q931timeout_func_t *Q931Timeout[Q931MAXDLCT][Q931MAXTIMER];
833 extern q931timer_t         Q931Timer[Q931MAXDLCT][Q931MAXTIMER];
834 
835 
836 /*****************************************************************************
837 
838   Macro:        GetIETotoSize
839 
840   Syntax:       L3INT GetIETotSize(InfoElem ie);
841 
842   Description:  Compute the total size in bytes of an info element including
843                 size of 'header'.
844 
845 *****************************************************************************/
846 #define Q931GetIETotSize(ie) (((ie.InfoID & 0x80) != 0) ? 1 : ie.LenIE) + 2)
847 
848 /*****************************************************************************
849 
850   Macro:        IsIEPresent
851 
852   Syntax:       BOOL IsIEPresent(ie InfoElement);
853 
854   Description:  Return TRUE if the Information Element is included.
855 
856 *****************************************************************************/
857 #define Q931IsIEPresent(x) ((x & 0x8000) != 0)
858 
859 /*****************************************************************************
860 
861   Macro:        GetIEOffset and GetIEValue
862 
863   Syntax:       L3INT GetIEOffset(ie InfoElement)
864                 L3INT GetIEValue(ie InfoElement)
865 
866   Description:  Returns the offset (or the value )to the Information Element.
867 
868   Note:         GetIEValue assumes that the 15 lsb bit is the value of a
869                 single octet information element. This macro can not be used
870                 on a variable information element.
871 
872 *****************************************************************************/
873 #define Q931GetIEOffset(x) (x & 0x7fff)
874 #define Q931GetIEValue(x)  (x & 0x7fff)
875 
876 /*****************************************************************************
877 
878   Macro:        Q931GetIEPtr
879 
880   Syntax:       void * Q931GetIEPtr(ie InfoElement, L3UCHAR * Buf);
881 
882   Description:  Compute a Ptr to the information element.
883 
884 *****************************************************************************/
885 #define Q931GetIEPtr(ie,buf) ((void *)&buf[Q931GetIEOffset(ie)])
886 
887 /*****************************************************************************
888 
889   Macro:        SetIE
890 
891   Syntax:       void SetIE(ie InfoElement, L3INT Offset);
892 
893   Description:  Set an information element.
894 
895 *****************************************************************************/
896 #define Q931SetIE(x,o) { x = (ie)(o) | 0x8000; }
897 
898 /*****************************************************************************
899 
900   Macro:        IsQ931Ext
901 
902   Syntax        BOOL IsQ931Ext(L3UCHAR c)
903 
904   Description:  Return true Check if the msb (bit 8) is 0. This indicate
905                 that the octet is extended.
906 
907 *****************************************************************************/
908 #define IsQ931Ext(x) ((x & 0x80) == 0)
909 
910 /*****************************************************************************
911 
912   Macro:        ieGetOctet
913 
914   Syntax:       unsigned L3UCHAR ieGetOctet(L3INT e)
915 
916   Description:  Macro to fetch one byte from an integer. Mostly used to
917                 avoid warnings.
918 
919 *****************************************************************************/
920 #define ieGetOctet(x) ((L3UCHAR)(x))
921 
922 /*****************************************************************************
923 
924   Macro:        NoWarning
925 
926   Syntax:       void NoWarning(x)
927 
928   Description:  Macro to suppress unreferenced formal parameter warnings
929 
930                 Used during creation of the stack since the stack is
931                 developed for Warning Level 4 and this creates a lot of
932                 warning for the initial empty functions.
933 
934 *****************************************************************************/
935 #define NoWarning(x) (x = x)
936 
937 /*****************************************************************************
938 
939   External references. See Q931.c for details.
940 
941 *****************************************************************************/
942 
943 #include "Q931ie.h"
944 
945 #include "Q932.h"
946 
947 /*****************************************************************************
948 
949   Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c
950 
951 *****************************************************************************/
952 L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
953 L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
954 L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
955 L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
956 L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
957 L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
958 L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
959 L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
960 L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
961 L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
962 L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
963 L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
964 L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
965 L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
966 L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
967 L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
968 L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
969 L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
970 L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
971 L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
972 L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
973 L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
974 L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
975 L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
976 L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
977 L3INT Q931Pmes_Service(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
978 L3INT Q931Pmes_ServiceAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
979 
980 
981 L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
982 L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
983 L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
984 L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
985 L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
986 L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
987 L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
988 L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
989 L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
990 L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
991 L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
992 L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
993 L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
994 L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
995 L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
996 L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
997 L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
998 L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
999 L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
1000 L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
1001 L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
1002 L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
1003 L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
1004 L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
1005 L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O);
1006 L3INT Q931Umes_Service(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size);
1007 L3INT Q931Umes_ServiceAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size);
1008 
1009 
1010 /*****************************************************************************
1011 
1012   Q.931 Process Function Prototyping. Implemented in Q931StateTE.c
1013 
1014 *****************************************************************************/
1015 L3INT Q931ProcAlertingTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1016 L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1017 L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1018 L3INT Q931ProcConnectAckTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1019 L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1020 L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1021 L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1022 L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1023 L3INT Q931ProcResumeAckTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1024 L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1025 L3INT Q931ProcSuspendTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1026 L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1027 L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1028 L3INT Q931ProcUserInformationTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1029 L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1030 L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1031 L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1032 L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1033 L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1034 L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1035 L3INT Q931ProcInformationTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1036 L3INT Q931ProcNotifyTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1037 L3INT Q931ProcStatusTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1038 L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1039 L3INT Q931ProcSegmentTE(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1040 
1041 L3INT Q931ProcAlertingNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1042 L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1043 L3INT Q931ProcConnectNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1044 L3INT Q931ProcConnectAckNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1045 L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1046 L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1047 L3INT Q931ProcSetupAckNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1048 L3INT Q931ProcResumeNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1049 L3INT Q931ProcResumeAckNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1050 L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1051 L3INT Q931ProcSuspendNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1052 L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1053 L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1054 L3INT Q931ProcUserInformationNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1055 L3INT Q931ProcDisconnectNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1056 L3INT Q931ProcReleaseNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1057 L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1058 L3INT Q931ProcRestartNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1059 L3INT Q931ProcRestartAckNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1060 L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1061 L3INT Q931ProcInformationNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1062 L3INT Q931ProcNotifyNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1063 L3INT Q931ProcStatusNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1064 L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1065 L3INT Q931ProcSegmentNT(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1066 
1067 L3INT Q931ProcUnknownMessage(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1068 L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom);
1069 
1070 /*****************************************************************************
1071 
1072   Interface Function Prototypes. Implemented in Q931.c
1073 
1074 *****************************************************************************/
1075 void    Q931TimerTick(Q931_TrunkInfo_t *pTrunk);
1076 L3INT   Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * Mes, L3INT Size);
1077 L3INT   Q931Tx32Data(Q931_TrunkInfo_t *pTrunk, L3UCHAR bcast, L3UCHAR * Mes, L3INT Size);
1078 L3INT   Q931Rx43(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size);
1079 L3INT   Q931Tx34(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size);
1080 void    Q931SetError(Q931_TrunkInfo_t *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2);
1081 
1082 void	Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar);
1083 
1084 void    Q931CreateTE(L3UCHAR i);
1085 void    Q931CreateNT(L3UCHAR i);
1086 void    Q931SetMesCreateCB(L3INT (*callback)(void));
1087 void    Q931SetDialectCreateCB(L3INT (*callback)(L3INT));
1088 void    Q931SetHeaderSpace(L3INT space);
1089 
1090 void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, q931proc_func_t *Q931ProcFunc, q931umes_func_t *Q931UmesFunc, q931pmes_func_t *Q931PmesFunc);
1091 void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, q931pie_func_t *Q931PieProc, q931uie_func_t *Q931UieProc);
1092 void Q931SetTimeoutProc(L3UCHAR dialect, L3UCHAR timer, q931timeout_func_t *Q931TimeoutProc);
1093 void Q931SetTimerDefault(L3UCHAR dialect, L3UCHAR timer, q931timer_t timeout);
1094 
1095 void Q931Initialize(void);
1096 void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect));
1097 L3INT Q931InitMesSetup(Q931mes_Generic *p);
1098 L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes);
1099 L3INT Q931InitMesGeneric(Q931mes_Generic *pMes);
1100 
1101 L3INT	Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex);
1102 L3INT	Q931ReleaseCRV(Q931_TrunkInfo_t *pTrunk, L3INT CRV);
1103 L3INT	Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex);
1104 L3INT   Q931FindCRV(Q931_TrunkInfo_t *pTrunk, L3INT crv, L3INT *callindex);
1105 L3INT	Q931GetCallState(Q931_TrunkInfo_t *pTrunk, L3INT iCRV);
1106 L3INT	Q931StartTimer(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3USHORT iTimer);
1107 L3INT	Q931StopTimer(Q931_TrunkInfo_t *pTrunk, L3INT callindex, L3USHORT iTimer);
1108 L3INT	Q931SetState(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3INT iState);
1109 L3ULONG Q931GetTime(void);
1110 void    Q931SetGetTimeCB(L3ULONG (*callback)(void));
1111 void	Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir);
1112 L3BOOL	Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir);
1113 
1114 /*****************************************************************************
1115 
1116   Q.931 Low Level API Function Prototyping. Implemented in Q931API.c
1117 
1118 *****************************************************************************/
1119 ie Q931AppendIE(L3UCHAR *pm, L3UCHAR *pi);
1120 L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk);
1121 
1122 L3INT Q931InitIEBearerCap(Q931ie_BearerCap *p);
1123 L3INT Q931InitIEChanID(Q931ie_ChanID *p);
1124 L3INT Q931InitIEProgInd(Q931ie_ProgInd *p);
1125 L3INT Q931InitIENetFac(Q931ie_NetFac * pIE);
1126 L3INT Q931InitIEDisplay(Q931ie_Display * pIE);
1127 L3INT Q931InitIEDateTime(Q931ie_DateTime * pIE);
1128 L3INT Q931InitIEKeypadFac(Q931ie_KeypadFac * pIE);
1129 L3INT Q931InitIESignal(Q931ie_Signal * pIE);
1130 L3INT Q931InitIECallingNum(Q931ie_CallingNum * pIE);
1131 L3INT Q931InitIECallingSub(Q931ie_CallingSub * pIE);
1132 L3INT Q931InitIECalledNum(Q931ie_CalledNum * pIE);
1133 L3INT Q931InitIECalledSub(Q931ie_CalledSub * pIE);
1134 L3INT Q931InitIETransNetSel(Q931ie_TransNetSel * pIE);
1135 L3INT Q931InitIELLComp(Q931ie_LLComp * pIE);
1136 L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE);
1137 
1138 L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause);
1139 L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf);
1140 L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf);
1141 L3INT Q931AckConnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf);
1142 L3INT Q931AckSetup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf);
1143 L3INT Q931AckService(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf);
1144 
1145 L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk,
1146 						Q931Dialect_t Dialect,
1147 						Q931NetUser_t NetUser,
1148 						Q931_TrunkType_t TrunkType,
1149 						Q931Tx34CB_t Q931Tx34CBProc,
1150 						Q931Tx32CB_t Q931Tx32CBProc,
1151 						Q931ErrorCB_t Q931ErrorCBProc,
1152 						void *PrivateData32,
1153 						void *PrivateData34);
1154 
1155 L3INT Q931GetMesSize(Q931mes_Generic *pMes);
1156 L3INT Q931InitMesResume(Q931mes_Generic * pMes);
1157 
1158 L3INT Q931Log(Q931_TrunkInfo_t *trunk, Q931LogLevel_t level, const char *fmt, ...);
1159 void Q931SetLogCB(Q931_TrunkInfo_t *trunk, Q931LogCB_t func, void *priv);
1160 void Q931SetLogLevel(Q931_TrunkInfo_t *trunk, Q931LogLevel_t level);
1161 
1162 void Q931SetL4HeaderSpace(L3INT space);
1163 void Q931SetL2HeaderSpace(L3INT space);
1164 L3INT Q931ProcDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b,L3INT c);
1165 L3INT Q931UmesDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size);
1166 L3INT Q931UieDummy(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff);
1167 L3INT Q931PmesDummy(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
1168 L3INT Q931PieDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet);
1169 L3INT Q931TxDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT n);
1170 L3INT Q931ErrorDummy(void *priv, L3INT a, L3INT b, L3INT c);
1171 L3INT Q931TimeoutDummy(Q931_TrunkInfo_t *pTrunk, L3INT callIndex);
1172 
1173 L3INT Q931MesgHeader(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *mes, L3UCHAR *OBuf, L3INT Size, L3INT *IOff);
1174 
1175 #endif /* _Q931_NL */
1176