finish chan_misdn commit
[asterisk/asterisk.git] / channels / misdn / isdn_msg_parser.c
1 /*
2  * Chan_Misdn -- Channel Driver for Asterisk
3  *
4  * Interface to mISDN
5  *
6  * Copyright (C) 2004, Christian Richter
7  *
8  * Christian Richter <crich@beronet.com>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13
14
15 #include "isdn_lib.h"
16 #include "ie.c"
17
18
19 void parse_proceeding (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
20 {
21         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
22         CALL_PROCEEDING_t *proceeding=(CALL_PROCEEDING_t*)((unsigned long)msg->data+ HEADER_LEN);
23         {
24                 int  exclusive, channel;
25                 dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)proceeding, &exclusive, &channel, nt,bc);
26                 
27                 if (channel==0xff) /* any channel */
28                         channel=-1;
29     
30                 /*  ALERT: is that everytime true ?  */
31                 if (channel > 0 && bc->stack->mode == NT_MODE) 
32                         bc->channel = channel;
33         }
34         
35         dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)proceeding, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
36         
37 #if DEBUG 
38         printf("Parsing PROCEEDING Msg\n"); 
39 #endif
40
41  
42 }
43 msg_t *build_proceeding (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
44 {
45         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
46         CALL_PROCEEDING_t *proceeding;
47         msg_t *msg =(msg_t*)create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING,  bc?bc->l3_id:-1, sizeof(CALL_PROCEEDING_t) ,nt); 
48   
49         proceeding=(CALL_PROCEEDING_t*)((msg->data+HEADER_LEN));
50
51         enc_ie_channel_id(&proceeding->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
52   
53         if (nt) 
54                 enc_ie_progress(&proceeding->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);
55   
56
57 #if DEBUG 
58         printf("Building PROCEEDING Msg\n"); 
59 #endif
60         return msg; 
61 }
62 void print_proceeding (struct isdn_msg msgs[]) 
63 {
64 }
65
66 void parse_alerting (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
67 {
68         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN; 
69         ALERTING_t *alerting=(ALERTING_t*)((unsigned long)(msg->data+HEADER_LEN));
70         //Q931_info_t *qi=(Q931_info_t*)(msg->data+HEADER_LEN);
71         
72         dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)alerting, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
73         
74 #if DEBUG 
75         printf("Parsing ALERTING Msg\n"); 
76 #endif
77
78  
79 }
80 msg_t *build_alerting (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
81 {
82         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
83         ALERTING_t *alerting;
84         msg_t *msg =(msg_t*)create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING,  bc?bc->l3_id:-1, sizeof(ALERTING_t) ,nt); 
85   
86         alerting=(ALERTING_t*)((msg->data+HEADER_LEN)); 
87   
88         enc_ie_channel_id(&alerting->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
89         
90         if (nt) 
91                 enc_ie_progress(&alerting->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);
92 #if DEBUG 
93         printf("Building ALERTING Msg\n"); 
94 #endif
95         return msg; 
96 }
97 void print_alerting (struct isdn_msg msgs[]) 
98 {
99 }
100
101
102 void parse_progress (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
103 {
104         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
105         PROGRESS_t *progress=(PROGRESS_t*)((unsigned long)(msg->data+HEADER_LEN)); 
106         //Q931_info_t *qi=(Q931_info_t*)(msg->data+HEADER_LEN);  
107         
108         dec_ie_progress(progress->PROGRESS, (Q931_info_t *)progress, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
109         
110 #if DEBUG 
111         printf("Parsing PROGRESS Msg\n"); 
112 #endif
113 }
114
115 msg_t *build_progress (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
116 {
117         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
118         PROGRESS_t *progress;
119         msg_t *msg =(msg_t*)create_l3msg(CC_PROGRESS | REQUEST, MT_PROGRESS,  bc?bc->l3_id:-1, sizeof(PROGRESS_t) ,nt); 
120  
121         progress=(PROGRESS_t*)((msg->data+HEADER_LEN)); 
122
123 #if DEBUG 
124         printf("Building PROGRESS Msg\n"); 
125 #endif
126         return msg; 
127 }
128 void print_progress (struct isdn_msg msgs[]) 
129 {
130 }
131
132
133 void parse_setup (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
134
135         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
136         SETUP_t *setup= (SETUP_t*)((unsigned long)msg->data+HEADER_LEN);
137         Q931_info_t *qi=(Q931_info_t*)((unsigned long)msg->data+HEADER_LEN);
138
139 #if DEBUG 
140         printf("Parsing SETUP Msg\n"); 
141 #endif
142         {
143                 int type,plan,present, screen;
144                 char id[32];
145                 dec_ie_calling_pn(setup->CALLING_PN, qi, &type, &plan, &present, &screen, (unsigned char *)id, sizeof(id), nt,bc);
146
147                 bc->onumplan=type; 
148                 strcpy(bc->oad, id);
149                 switch (present) {
150                 case 0:
151 //                      cb_log(3, bc->stack->port, " --> Pres:0\n");
152                         bc->pres=0; /* screened */
153                         break;
154                 case 1:
155 //                      cb_log(3, bc->stack->port, " --> Pres:1\n");
156                         bc->pres=1; /* not screened */
157                         break;
158                 default:
159 //                      cb_log(3, bc->stack->port, " --> Pres:%d\n",present);
160                         bc->pres=0;
161                 }
162                 switch (screen) {
163                 case 0:
164 //                      cb_log(4, bc->stack->port, " --> Screen:0\n");
165                         break;
166                 default:
167 //                      cb_log(4, bc->stack->port, " --> Screen:%d\n",screen);
168                         ;
169                 } 
170         }
171         {
172                 int  type, plan;
173                 char number[32]; 
174                 dec_ie_called_pn(setup->CALLED_PN, (Q931_info_t *)setup, &type, &plan, (unsigned char *)number, sizeof(number), nt,bc);
175                 strcpy(bc->dad, number);
176                 bc->dnumplan=type; 
177         }
178         {
179                 char keypad[32];
180                 dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)setup, (unsigned char *)keypad, sizeof(keypad), nt,bc);
181                 strcpy(bc->keypad, keypad);
182         }
183
184         {
185                 int  sending_complete;
186                 dec_ie_complete(setup->COMPLETE, (Q931_info_t *)setup, &sending_complete, nt,bc);
187         }
188   
189         {
190                 int  type, plan, present, screen, reason;
191                 char id[32]; 
192                 dec_ie_redir_nr(setup->REDIR_NR, (Q931_info_t *)setup, &type, &plan, &present, &screen, &reason, (unsigned char *)id, sizeof(id), nt,bc);
193     
194                 strcpy(bc->rad, id);
195                 bc->rnumplan=type; 
196 //              cb_log(3, bc->stack->port, " --> Redirecting number (REDIR_NR): '%s'\n", id);
197         }
198         {
199                 int  coding, capability, mode, rate, multi, user, async, urate, stopbits, dbits, parity;
200                 dec_ie_bearer(setup->BEARER, (Q931_info_t *)setup, &coding, &capability, &mode, &rate, &multi, &user, &async, &urate, &stopbits, &dbits, &parity, nt,bc);
201                 switch (capability) {
202                 case -1: bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED; 
203 //                      cb_log(2, bc->stack->port, " --> cap -1 -> digital\n");
204                         break;
205                 case 0: bc->capability=INFO_CAPABILITY_SPEECH;
206 //                      cb_log(2, bc->stack->port, " --> cap speech\n");
207                         break;
208                 case 8: bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED;
209                         bc->user1 = user;
210                         bc->async = async;
211                         bc->urate = urate;
212                         
213                         bc->rate = rate;
214                         bc->mode = mode;
215                         
216 //                      cb_log(2, bc->stack->port, " --> cap unres Digital (user l1 %d, async %d, user rate %d\n", user, async, urate);
217                         break;
218                 case 9: bc->capability=INFO_CAPABILITY_DIGITAL_RESTRICTED;
219 //                      cb_log(2, bc->stack->port, " --> cap res Digital\n");
220                         break;
221                 default:
222 //                      cb_log(2, bc->stack->port, " --> cap Else\n");
223                         break;
224                 }
225
226                 switch(user) {
227                 case 2:
228                         bc->law=INFO_CODEC_ULAW;
229                         break;
230                 case 3:
231                         bc->law=INFO_CODEC_ALAW;
232                         break;
233                 default:
234                         bc->law=INFO_CODEC_ALAW;
235                         
236                 }
237                 
238                 bc->capability=capability; 
239         }
240         {
241                 int  exclusive, channel;
242                 dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)setup, &exclusive, &channel, nt,bc);
243                 if (channel==0xff) /* any channel */
244                         channel=-1;
245
246                 if (channel > 0) 
247                         bc->channel = channel;
248         }
249         
250         dec_ie_progress(setup->PROGRESS, (Q931_info_t *)setup, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
251         
252 }
253
254 #define ANY_CHANNEL 0xff /* IE attribut for 'any channel' */
255 msg_t *build_setup (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
256 {
257         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
258         SETUP_t *setup;
259         msg_t *msg =(msg_t*)create_l3msg(CC_SETUP | REQUEST, MT_SETUP,  bc?bc->l3_id:-1, sizeof(SETUP_t) ,nt); 
260   
261         setup=(SETUP_t*)((msg->data+HEADER_LEN)); 
262   
263 //      cb_log(2, bc->stack->port, " --> oad %s dad %s channel %d\n",bc->oad, bc->dad,bc->channel);
264         if (bc->channel == 0 || bc->channel == ANY_CHANNEL || bc->channel==-1)
265                 enc_ie_channel_id(&setup->CHANNEL_ID, msg, 0, bc->channel, nt,bc);
266         else
267                 enc_ie_channel_id(&setup->CHANNEL_ID, msg, 1, bc->channel, nt,bc);
268   
269         {
270                 int type=bc->onumplan,plan=1,present=bc->pres,screen=0;
271                 enc_ie_calling_pn(&setup->CALLING_PN, msg, type, plan, present,
272                                   screen, bc->oad, nt, bc);
273         }
274   
275         {
276                 if (bc->dad[0])
277                         enc_ie_called_pn(&setup->CALLED_PN, msg, bc->dnumplan, 1, bc->dad, nt,bc);
278         }
279   
280         if (*bc->display) {
281                 enc_ie_display(&setup->DISPLAY, msg, bc->display, nt,bc);
282         }
283   
284         {
285                 int coding=0, capability, mode=0 /*  2 for packet ! */
286                         ,user, rate=0x10;
287                 switch (bc->capability) {
288                 case INFO_CAPABILITY_SPEECH: capability = 0;
289 //                      cb_log(2, bc->stack->port, " --> Speech\n");
290                         break;
291                 case INFO_CAPABILITY_DIGITAL_UNRESTRICTED: capability = 8;
292 //                      cb_log(2, bc->stack->port, " --> cap unres Digital\n");
293                         break;
294                 case INFO_CAPABILITY_DIGITAL_RESTRICTED: capability = 9;
295 //                      cb_log(2, bc->stack->port, " --> cap res Digital\n");
296                         break;
297                 default:
298 //                      cb_log(2, bc->stack->port, " --> cap Speech\n");
299                         capability=bc->capability; 
300                 }
301                 
302                 switch (bc->law) {
303                 case INFO_CODEC_ULAW: user=2;
304 //                      cb_log(2, bc->stack->port, " --> Codec Ulaw\n");
305                         break;
306                 case INFO_CODEC_ALAW: user=3;
307 //                      cb_log(2, bc->stack->port, " --> Codec Alaw\n");
308                         break;
309                 default:
310                         user=3;
311                 }
312     
313                 enc_ie_bearer(&setup->BEARER, msg, coding, capability, mode, rate, -1, user, nt,bc);
314         }
315   
316 #if DEBUG 
317         printf("Building SETUP Msg\n"); 
318 #endif
319         return msg; 
320 }
321
322 void print_setup (struct isdn_msg msgs[]) 
323 {
324 }
325
326 void parse_connect (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
327 {
328         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
329         CONNECT_t *connect=(CONNECT_t*)((unsigned long)(msg->data+HEADER_LEN));
330   
331         bc->ces = connect->ces;
332         bc->ces = connect->ces;
333
334         dec_ie_progress(connect->PROGRESS, (Q931_info_t *)connect, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
335         
336 #if DEBUG 
337         printf("Parsing CONNECT Msg\n"); 
338 #endif
339 }
340 msg_t *build_connect (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
341 {
342         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
343         CONNECT_t *connect;
344         msg_t *msg =(msg_t*)create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT,  bc?bc->l3_id:-1, sizeof(CONNECT_t) ,nt); 
345   
346         connect=(CONNECT_t*)((msg->data+HEADER_LEN)); 
347
348         if (nt) {
349                 time_t now;
350                 time(&now);
351                 enc_ie_date(&connect->DATE, msg, now, nt,bc);
352         }
353   
354         {
355                 int type=0, plan=1, present=2, screen=0;
356                 enc_ie_connected_pn(&connect->CONNECT_PN, msg, type,plan, present, screen, (unsigned char*) bc->dad , nt , bc);
357         }
358
359 #if DEBUG 
360         printf("Building CONNECT Msg\n"); 
361 #endif
362         return msg; 
363 }
364 void print_connect (struct isdn_msg msgs[]) 
365 {
366 }
367
368
369 void parse_setup_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
370 {
371         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
372         SETUP_ACKNOWLEDGE_t *setup_acknowledge=(SETUP_ACKNOWLEDGE_t*)((unsigned long)(msg->data+HEADER_LEN));
373
374         {
375                 int  exclusive, channel;
376                 dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)setup_acknowledge, &exclusive, &channel, nt,bc);
377
378                 if (channel==0xff) /* any channel */
379                         channel=-1;
380
381                 if (channel > 0) 
382                         bc->channel = channel;
383         }
384         
385         dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)setup_acknowledge, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
386 #if DEBUG 
387         printf("Parsing SETUP_ACKNOWLEDGE Msg\n"); 
388 #endif
389
390  
391 }
392 msg_t *build_setup_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
393 {
394         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
395         SETUP_ACKNOWLEDGE_t *setup_acknowledge;
396         msg_t *msg =(msg_t*)create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE,  bc?bc->l3_id:-1, sizeof(SETUP_ACKNOWLEDGE_t) ,nt); 
397  
398         setup_acknowledge=(SETUP_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN)); 
399   
400         enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
401   
402         if (nt) 
403                 enc_ie_progress(&setup_acknowledge->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);
404   
405 #if DEBUG 
406         printf("Building SETUP_ACKNOWLEDGE Msg\n"); 
407 #endif
408         return msg; 
409 }
410
411 void print_setup_acknowledge (struct isdn_msg msgs[]) 
412 {
413 }
414
415 void parse_connect_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
416 {
417 #if DEBUG 
418         printf("Parsing CONNECT_ACKNOWLEDGE Msg\n"); 
419 #endif
420
421  
422 }
423 msg_t *build_connect_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
424 {
425         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
426         CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
427         msg_t *msg =(msg_t*)create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT,  bc?bc->l3_id:-1, sizeof(CONNECT_ACKNOWLEDGE_t) ,nt); 
428  
429         connect_acknowledge=(CONNECT_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN)); 
430   
431         enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, msg, 1, bc->channel, nt,bc);
432   
433 #if DEBUG 
434         printf("Building CONNECT_ACKNOWLEDGE Msg\n"); 
435 #endif
436         return msg; 
437 }
438 void print_connect_acknowledge (struct isdn_msg msgs[]) 
439 {
440 }
441
442
443 void parse_user_information (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
444 {
445 #if DEBUG 
446         printf("Parsing USER_INFORMATION Msg\n"); 
447 #endif
448
449  
450 }
451 msg_t *build_user_information (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
452 {
453         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
454         USER_INFORMATION_t *user_information;
455         msg_t *msg =(msg_t*)create_l3msg(CC_USER_INFORMATION | REQUEST, MT_USER_INFORMATION,  bc?bc->l3_id:-1, sizeof(USER_INFORMATION_t) ,nt); 
456  
457         user_information=(USER_INFORMATION_t*)((msg->data+HEADER_LEN)); 
458
459 #if DEBUG 
460         printf("Building USER_INFORMATION Msg\n"); 
461 #endif
462         return msg; 
463 }
464 void print_user_information (struct isdn_msg msgs[]) 
465 {
466 }
467
468
469 void parse_suspend_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
470 {
471 #if DEBUG 
472         printf("Parsing SUSPEND_REJECT Msg\n"); 
473 #endif
474
475  
476 }
477 msg_t *build_suspend_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
478 {
479         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
480         SUSPEND_REJECT_t *suspend_reject;
481         msg_t *msg =(msg_t*)create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT,  bc?bc->l3_id:-1, sizeof(SUSPEND_REJECT_t) ,nt); 
482  
483         suspend_reject=(SUSPEND_REJECT_t*)((msg->data+HEADER_LEN)); 
484
485 #if DEBUG 
486         printf("Building SUSPEND_REJECT Msg\n"); 
487 #endif
488         return msg; 
489 }
490 void print_suspend_reject (struct isdn_msg msgs[]) 
491 {
492 }
493
494
495 void parse_resume_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
496 {
497 #if DEBUG 
498         printf("Parsing RESUME_REJECT Msg\n"); 
499 #endif
500
501  
502 }
503 msg_t *build_resume_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
504 {
505         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
506         RESUME_REJECT_t *resume_reject;
507         msg_t *msg =(msg_t*)create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT,  bc?bc->l3_id:-1, sizeof(RESUME_REJECT_t) ,nt); 
508  
509         resume_reject=(RESUME_REJECT_t*)((msg->data+HEADER_LEN)); 
510
511 #if DEBUG 
512         printf("Building RESUME_REJECT Msg\n"); 
513 #endif
514         return msg; 
515 }
516 void print_resume_reject (struct isdn_msg msgs[]) 
517 {
518 }
519
520
521 void parse_hold (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
522 {
523 #if DEBUG 
524         printf("Parsing HOLD Msg\n"); 
525 #endif
526
527  
528 }
529 msg_t *build_hold (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
530 {
531         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
532         HOLD_t *hold;
533         msg_t *msg =(msg_t*)create_l3msg(CC_HOLD | REQUEST, MT_HOLD,  bc?bc->l3_id:-1, sizeof(HOLD_t) ,nt); 
534  
535         hold=(HOLD_t*)((msg->data+HEADER_LEN)); 
536
537 #if DEBUG 
538         printf("Building HOLD Msg\n"); 
539 #endif
540         return msg; 
541 }
542 void print_hold (struct isdn_msg msgs[]) 
543 {
544 }
545
546
547 void parse_suspend (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
548 {
549 #if DEBUG 
550         printf("Parsing SUSPEND Msg\n"); 
551 #endif
552
553  
554 }
555 msg_t *build_suspend (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
556 {
557         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
558         SUSPEND_t *suspend;
559         msg_t *msg =(msg_t*)create_l3msg(CC_SUSPEND | REQUEST, MT_SUSPEND,  bc?bc->l3_id:-1, sizeof(SUSPEND_t) ,nt); 
560  
561         suspend=(SUSPEND_t*)((msg->data+HEADER_LEN)); 
562
563 #if DEBUG 
564         printf("Building SUSPEND Msg\n"); 
565 #endif
566         return msg; 
567 }
568 void print_suspend (struct isdn_msg msgs[]) 
569 {
570 }
571
572
573 void parse_resume (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
574 {
575 #if DEBUG 
576         printf("Parsing RESUME Msg\n"); 
577 #endif
578
579  
580 }
581 msg_t *build_resume (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
582 {
583         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
584         RESUME_t *resume;
585         msg_t *msg =(msg_t*)create_l3msg(CC_RESUME | REQUEST, MT_RESUME,  bc?bc->l3_id:-1, sizeof(RESUME_t) ,nt); 
586  
587         resume=(RESUME_t*)((msg->data+HEADER_LEN)); 
588
589 #if DEBUG 
590         printf("Building RESUME Msg\n"); 
591 #endif
592         return msg; 
593 }
594 void print_resume (struct isdn_msg msgs[]) 
595 {
596 }
597
598
599 void parse_hold_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
600 {
601 #if DEBUG 
602         printf("Parsing HOLD_ACKNOWLEDGE Msg\n"); 
603 #endif
604
605  
606 }
607 msg_t *build_hold_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
608 {
609         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
610         HOLD_ACKNOWLEDGE_t *hold_acknowledge;
611         msg_t *msg =(msg_t*)create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE,  bc?bc->l3_id:-1, sizeof(HOLD_ACKNOWLEDGE_t) ,nt); 
612  
613         hold_acknowledge=(HOLD_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN)); 
614
615 #if DEBUG 
616         printf("Building HOLD_ACKNOWLEDGE Msg\n"); 
617 #endif
618         return msg; 
619 }
620 void print_hold_acknowledge (struct isdn_msg msgs[]) 
621 {
622 }
623
624
625 void parse_suspend_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
626 {
627 #if DEBUG 
628         printf("Parsing SUSPEND_ACKNOWLEDGE Msg\n"); 
629 #endif
630
631  
632 }
633 msg_t *build_suspend_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
634 {
635         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
636         SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
637         msg_t *msg =(msg_t*)create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE,  bc?bc->l3_id:-1, sizeof(SUSPEND_ACKNOWLEDGE_t) ,nt); 
638  
639         suspend_acknowledge=(SUSPEND_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN)); 
640
641 #if DEBUG 
642         printf("Building SUSPEND_ACKNOWLEDGE Msg\n"); 
643 #endif
644         return msg; 
645 }
646 void print_suspend_acknowledge (struct isdn_msg msgs[]) 
647 {
648 }
649
650
651 void parse_resume_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
652 {
653 #if DEBUG 
654         printf("Parsing RESUME_ACKNOWLEDGE Msg\n"); 
655 #endif
656
657  
658 }
659 msg_t *build_resume_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
660 {
661         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
662         RESUME_ACKNOWLEDGE_t *resume_acknowledge;
663         msg_t *msg =(msg_t*)create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE,  bc?bc->l3_id:-1, sizeof(RESUME_ACKNOWLEDGE_t) ,nt); 
664  
665         resume_acknowledge=(RESUME_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN)); 
666
667 #if DEBUG 
668         printf("Building RESUME_ACKNOWLEDGE Msg\n"); 
669 #endif
670         return msg; 
671 }
672 void print_resume_acknowledge (struct isdn_msg msgs[]) 
673 {
674 }
675
676
677 void parse_hold_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
678 {
679 #if DEBUG 
680         printf("Parsing HOLD_REJECT Msg\n"); 
681 #endif
682
683  
684 }
685 msg_t *build_hold_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
686 {
687         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
688         HOLD_REJECT_t *hold_reject;
689         msg_t *msg =(msg_t*)create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT,  bc?bc->l3_id:-1, sizeof(HOLD_REJECT_t) ,nt); 
690  
691         hold_reject=(HOLD_REJECT_t*)((msg->data+HEADER_LEN)); 
692
693 #if DEBUG 
694         printf("Building HOLD_REJECT Msg\n"); 
695 #endif
696         return msg; 
697 }
698 void print_hold_reject (struct isdn_msg msgs[]) 
699 {
700 }
701
702
703 void parse_retrieve (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
704 {
705 #if DEBUG 
706         printf("Parsing RETRIEVE Msg\n"); 
707 #endif
708
709  
710 }
711 msg_t *build_retrieve (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
712 {
713         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
714         RETRIEVE_t *retrieve;
715         msg_t *msg =(msg_t*)create_l3msg(CC_RETRIEVE | REQUEST, MT_RETRIEVE,  bc?bc->l3_id:-1, sizeof(RETRIEVE_t) ,nt); 
716  
717         retrieve=(RETRIEVE_t*)((msg->data+HEADER_LEN)); 
718
719 #if DEBUG 
720         printf("Building RETRIEVE Msg\n"); 
721 #endif
722         return msg; 
723 }
724 void print_retrieve (struct isdn_msg msgs[]) 
725 {
726 }
727
728
729 void parse_retrieve_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
730 {
731 #if DEBUG 
732         printf("Parsing RETRIEVE_ACKNOWLEDGE Msg\n"); 
733 #endif
734
735  
736 }
737 msg_t *build_retrieve_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
738 {
739         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
740         RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
741         msg_t *msg =(msg_t*)create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE,  bc?bc->l3_id:-1, sizeof(RETRIEVE_ACKNOWLEDGE_t) ,nt); 
742  
743         retrieve_acknowledge=(RETRIEVE_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN)); 
744
745         enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, msg, 1, bc->channel, nt,bc);
746 #if DEBUG 
747         printf("Building RETRIEVE_ACKNOWLEDGE Msg\n"); 
748 #endif
749         return msg; 
750 }
751 void print_retrieve_acknowledge (struct isdn_msg msgs[]) 
752 {
753 }
754
755
756 void parse_retrieve_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
757 {
758 #if DEBUG 
759         printf("Parsing RETRIEVE_REJECT Msg\n"); 
760 #endif
761
762  
763 }
764 msg_t *build_retrieve_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
765 {
766         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
767         RETRIEVE_REJECT_t *retrieve_reject;
768         msg_t *msg =(msg_t*)create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT,  bc?bc->l3_id:-1, sizeof(RETRIEVE_REJECT_t) ,nt); 
769  
770         retrieve_reject=(RETRIEVE_REJECT_t*)((msg->data+HEADER_LEN)); 
771
772 #if DEBUG 
773         printf("Building RETRIEVE_REJECT Msg\n"); 
774 #endif
775         return msg; 
776 }
777 void print_retrieve_reject (struct isdn_msg msgs[]) 
778 {
779 }
780
781
782 void parse_disconnect (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
783 {
784         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
785         DISCONNECT_t *disconnect=(DISCONNECT_t*)((unsigned long)(msg->data+HEADER_LEN));
786         int location;
787   
788         dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)(disconnect), &location, &bc->cause, nt,bc);
789
790         dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)disconnect, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
791 #if DEBUG 
792         printf("Parsing DISCONNECT Msg\n"); 
793 #endif
794
795  
796 }
797 msg_t *build_disconnect (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
798 {
799         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
800         DISCONNECT_t *disconnect;
801         msg_t *msg =(msg_t*)create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT,  bc?bc->l3_id:-1, sizeof(DISCONNECT_t) ,nt); 
802         
803         disconnect=(DISCONNECT_t*)((msg->data+HEADER_LEN)); 
804         
805         enc_ie_cause(&disconnect->CAUSE, msg, (nt)?1:0, bc->out_cause,nt,bc);
806         if (nt) enc_ie_progress(&disconnect->PROGRESS, msg, 0, nt?1:5, 8 ,nt,bc);
807   
808 #if DEBUG 
809         printf("Building DISCONNECT Msg\n"); 
810 #endif
811         return msg; 
812 }
813 void print_disconnect (struct isdn_msg msgs[]) 
814 {
815 }
816
817
818 void parse_restart (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
819 {
820         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
821         RESTART_t *restart=(RESTART_t*)((unsigned long)(msg->data+HEADER_LEN));
822   
823 #if DEBUG 
824         printf("Parsing RESTART Msg\n");
825 #endif
826   
827         {
828                 int  exclusive, channel;
829                 dec_ie_channel_id(restart->CHANNEL_ID, (Q931_info_t *)restart, &exclusive, &channel, nt,bc);
830                 if (channel==0xff) /* any channel */
831                         channel=-1;
832                 cb_log(0, bc->stack->port, "CC_RESTART Request on channel:%d on port:%d\n",bc->stack->port);
833         }
834   
835  
836 }
837 msg_t *build_restart (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
838 {
839         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
840         RESTART_t *restart;
841         msg_t *msg =(msg_t*)create_l3msg(CC_RESTART | REQUEST, MT_RESTART,  bc?bc->l3_id:-1, sizeof(RESTART_t) ,nt); 
842  
843         restart=(RESTART_t*)((msg->data+HEADER_LEN)); 
844
845 #if DEBUG 
846         printf("Building RESTART Msg\n"); 
847 #endif
848         return msg; 
849 }
850 void print_restart (struct isdn_msg msgs[]) 
851 {
852 }
853
854
855 void parse_release (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
856 {
857         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
858         RELEASE_t *release=(RELEASE_t*)((unsigned long)(msg->data+HEADER_LEN));
859         int location;
860   
861         dec_ie_cause(release->CAUSE, (Q931_info_t *)(release), &location, &bc->cause, nt,bc);
862 #if DEBUG 
863         printf("Parsing RELEASE Msg\n"); 
864 #endif
865
866  
867 }
868 msg_t *build_release (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
869 {
870         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
871         RELEASE_t *release;
872         msg_t *msg =(msg_t*)create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE,  bc?bc->l3_id:-1, sizeof(RELEASE_t) ,nt); 
873  
874         release=(RELEASE_t*)((msg->data+HEADER_LEN)); 
875   
876   
877         enc_ie_cause(&release->CAUSE, msg, nt?1:0, bc->out_cause, nt,bc);
878   
879 #if DEBUG 
880         printf("Building RELEASE Msg\n"); 
881 #endif
882         return msg; 
883 }
884 void print_release (struct isdn_msg msgs[]) 
885 {
886 }
887
888
889 void parse_release_complete (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
890 {
891         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
892         RELEASE_COMPLETE_t *release_complete=(RELEASE_COMPLETE_t*)((unsigned long)(msg->data+HEADER_LEN));
893         int location;
894         iframe_t *frm = (iframe_t*) msg->data;
895 #ifdef MISDNUSER_JOLLY
896         mISDNuser_head_t *hh;
897         hh=(mISDNuser_head_t*)msg->data;
898 #else
899         mISDN_head_t *hh;
900         hh=(mISDN_head_t*)msg->data;
901 #endif
902   
903         if (nt) {
904                 if (hh->prim == (CC_RELEASE_COMPLETE|CONFIRM)) {
905                         cb_log(0, bc->stack->port, "CC_RELEASE_COMPLETE|CONFIRM [NT] port:%d\n",bc->stack->port);
906                         return;
907                 }
908         } else {
909                 if (frm->prim == (CC_RELEASE_COMPLETE|CONFIRM)) {
910                         cb_log(0, bc->stack->port, "CC_RELEASE_COMPLETE|CONFIRM [TE] port:%d\n",bc->stack->port);
911                         return;
912                 }
913         }
914         dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)(release_complete), &location, &bc->cause, nt,bc);
915
916   
917 #if DEBUG 
918         printf("Parsing RELEASE_COMPLETE Msg\n"); 
919 #endif
920
921  
922 }
923 msg_t *build_release_complete (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
924 {
925         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
926         RELEASE_COMPLETE_t *release_complete;
927         msg_t *msg =(msg_t*)create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE,  bc?bc->l3_id:-1, sizeof(RELEASE_COMPLETE_t) ,nt); 
928  
929         release_complete=(RELEASE_COMPLETE_t*)((msg->data+HEADER_LEN)); 
930         
931         enc_ie_cause(&release_complete->CAUSE, msg, nt?1:0, bc->out_cause, nt,bc);
932   
933 #if DEBUG 
934         printf("Building RELEASE_COMPLETE Msg\n"); 
935 #endif
936         return msg; 
937 }
938 void print_release_complete (struct isdn_msg msgs[]) 
939 {
940 }
941
942
943 void parse_facility (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
944 {
945         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
946         FACILITY_t *facility=(FACILITY_t*)((unsigned long)(msg->data+HEADER_LEN)); 
947         Q931_info_t *qi=(Q931_info_t*)(msg->data+HEADER_LEN);  
948
949
950 #if DEBUG 
951         printf("Parsing FACILITY Msg\n"); 
952 #endif
953
954         {
955                 char fac[128];
956                 int facility_len;
957                 
958                 dec_ie_facility(facility->FACILITY, qi, fac, &facility_len,  nt, bc);
959         }
960                 
961  
962 }
963 msg_t *build_facility (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
964 {
965         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
966         FACILITY_t *facility;
967         msg_t *msg =(msg_t*)create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY,  bc?bc->l3_id:-1, sizeof(FACILITY_t) ,nt); 
968  
969         facility=(FACILITY_t*)((msg->data+HEADER_LEN)); 
970
971         {
972                 if (*bc->display) {
973                         printf("Sending %s as Display\n", bc->display);
974                         enc_ie_display(&facility->DISPLAY, msg, bc->display, nt,bc);
975                 }
976
977                 
978                 
979                 switch ( bc->facility ) {
980                 case FACILITY_CALLDEFLECT:
981                         enc_facility_calldeflect(&facility->FACILITY, msg, bc->facility_calldeflect_nr, nt, bc);
982                         
983                         break;
984                 case FACILITY_NONE:
985                         break;
986                 }
987                 
988         }
989         
990 #if DEBUG 
991         printf("Building FACILITY Msg\n"); 
992 #endif
993         return msg; 
994 }
995 void print_facility (struct isdn_msg msgs[]) 
996 {
997 }
998
999
1000 void parse_notify (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
1001 {
1002 #if DEBUG 
1003         printf("Parsing NOTIFY Msg\n"); 
1004 #endif
1005
1006  
1007 }
1008 msg_t *build_notify (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
1009 {
1010         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1011         NOTIFY_t *notify;
1012         msg_t *msg =(msg_t*)create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY,  bc?bc->l3_id:-1, sizeof(NOTIFY_t) ,nt); 
1013  
1014         notify=(NOTIFY_t*)((msg->data+HEADER_LEN)); 
1015
1016 #if DEBUG 
1017         printf("Building NOTIFY Msg\n"); 
1018 #endif
1019         return msg; 
1020 }
1021 void print_notify (struct isdn_msg msgs[]) 
1022 {
1023 }
1024
1025
1026 void parse_status_enquiry (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
1027 {
1028 #if DEBUG 
1029         printf("Parsing STATUS_ENQUIRY Msg\n"); 
1030 #endif
1031
1032  
1033 }
1034 msg_t *build_status_enquiry (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
1035 {
1036         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1037         STATUS_ENQUIRY_t *status_enquiry;
1038         msg_t *msg =(msg_t*)create_l3msg(CC_STATUS_ENQUIRY | REQUEST, MT_STATUS_ENQUIRY,  bc?bc->l3_id:-1, sizeof(STATUS_ENQUIRY_t) ,nt); 
1039  
1040         status_enquiry=(STATUS_ENQUIRY_t*)((msg->data+HEADER_LEN)); 
1041
1042 #if DEBUG 
1043         printf("Building STATUS_ENQUIRY Msg\n"); 
1044 #endif
1045         return msg; 
1046 }
1047 void print_status_enquiry (struct isdn_msg msgs[]) 
1048 {
1049 }
1050
1051
1052 void parse_information (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
1053 {
1054         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1055         INFORMATION_t *information=(INFORMATION_t*)((unsigned long)(msg->data+HEADER_LEN));
1056
1057         {
1058                 int  type, plan;
1059                 char number[32];
1060                 char keypad[32];
1061                 dec_ie_called_pn(information->CALLED_PN, (Q931_info_t *)information, &type, &plan, (unsigned char *)number, sizeof(number), nt,bc);
1062                 dec_ie_keypad(information->KEYPAD, (Q931_info_t *)information, (unsigned char *)keypad, sizeof(keypad), nt,bc);
1063                 strcpy(bc->info_dad, number);
1064                 strcpy(bc->keypad,keypad);
1065     
1066         }
1067 #if DEBUG 
1068         printf("Parsing INFORMATION Msg\n"); 
1069 #endif
1070
1071  
1072 }
1073 msg_t *build_information (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
1074 {
1075         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1076         INFORMATION_t *information;
1077         msg_t *msg =(msg_t*)create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION,  bc?bc->l3_id:-1, sizeof(INFORMATION_t) ,nt); 
1078  
1079         information=(INFORMATION_t*)((msg->data+HEADER_LEN)); 
1080   
1081         {
1082                 enc_ie_called_pn(&information->CALLED_PN, msg, 0, 1, bc->info_dad, nt,bc);
1083         }
1084
1085         {
1086                 if (*bc->display) {
1087                         printf("Sending %s as Display\n", bc->display);
1088                         enc_ie_display(&information->DISPLAY, msg, bc->display, nt,bc);
1089                 }
1090         }
1091   
1092 #if DEBUG 
1093         printf("Building INFORMATION Msg\n"); 
1094 #endif
1095         return msg; 
1096 }
1097 void print_information (struct isdn_msg msgs[]) 
1098 {
1099 }
1100
1101
1102 void parse_status (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
1103 {
1104         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1105         STATUS_t *status=(STATUS_t*)((unsigned long)(msg->data+HEADER_LEN));
1106         int location;
1107   
1108         dec_ie_cause(status->CAUSE, (Q931_info_t *)(status), &location, &bc->cause, nt,bc);
1109         ;
1110
1111 #if DEBUG 
1112         printf("Parsing STATUS Msg\n"); 
1113 #endif
1114
1115  
1116 }
1117 msg_t *build_status (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
1118 {
1119         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1120         STATUS_t *status;
1121         msg_t *msg =(msg_t*)create_l3msg(CC_STATUS | REQUEST, MT_STATUS,  bc?bc->l3_id:-1, sizeof(STATUS_t) ,nt); 
1122  
1123         status=(STATUS_t*)((msg->data+HEADER_LEN)); 
1124
1125 #if DEBUG 
1126         printf("Building STATUS Msg\n"); 
1127 #endif
1128         return msg; 
1129 }
1130 void print_status (struct isdn_msg msgs[]) 
1131 {
1132 }
1133
1134
1135 void parse_timeout (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
1136 {
1137 #if DEBUG 
1138         printf("Parsing STATUS Msg\n"); 
1139 #endif
1140
1141  
1142 }
1143 msg_t *build_timeout (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 
1144 {
1145         int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1146         STATUS_t *status;
1147         msg_t *msg =(msg_t*)create_l3msg(CC_STATUS | REQUEST, MT_STATUS,  bc?bc->l3_id:-1, sizeof(STATUS_t) ,nt); 
1148  
1149         status=(STATUS_t*)((msg->data+HEADER_LEN)); 
1150
1151 #if DEBUG 
1152         printf("Building STATUS Msg\n"); 
1153 #endif
1154         return msg; 
1155 }
1156 void print_timeout (struct isdn_msg msgs[]) 
1157 {
1158 }
1159
1160
1161 /************************************/
1162
1163
1164
1165
1166 /** Msg Array **/
1167
1168 struct isdn_msg msgs_g[] = {
1169         {CC_PROCEEDING,L3,EVENT_PROCEEDING,
1170          parse_proceeding,build_proceeding,print_proceeding,
1171          "PROCEEDING"},
1172         {CC_ALERTING,L3,EVENT_ALERTING,
1173          parse_alerting,build_alerting,print_alerting,
1174          "ALERTING"},
1175         {CC_PROGRESS,L3,EVENT_PROGRESS,
1176          parse_progress,build_progress,print_progress,
1177          "PROGRESS"},
1178         {CC_SETUP,L3,EVENT_SETUP,
1179          parse_setup,build_setup,print_setup,
1180          "SETUP"},
1181         {CC_CONNECT,L3,EVENT_CONNECT,
1182          parse_connect,build_connect,print_connect,
1183          "CONNECT"},
1184         {CC_SETUP_ACKNOWLEDGE,L3,EVENT_SETUP_ACKNOWLEDGE,
1185          parse_setup_acknowledge,build_setup_acknowledge,print_setup_acknowledge,
1186          "SETUP_ACKNOWLEDGE"},
1187         {CC_CONNECT_ACKNOWLEDGE ,L3,EVENT_CONNECT_ACKNOWLEDGE ,
1188          parse_connect_acknowledge ,build_connect_acknowledge ,print_connect_acknowledge ,
1189          "CONNECT_ACKNOWLEDGE "},
1190         {CC_USER_INFORMATION,L3,EVENT_USER_INFORMATION,
1191          parse_user_information,build_user_information,print_user_information,
1192          "USER_INFORMATION"},
1193         {CC_SUSPEND_REJECT,L3,EVENT_SUSPEND_REJECT,
1194          parse_suspend_reject,build_suspend_reject,print_suspend_reject,
1195          "SUSPEND_REJECT"},
1196         {CC_RESUME_REJECT,L3,EVENT_RESUME_REJECT,
1197          parse_resume_reject,build_resume_reject,print_resume_reject,
1198          "RESUME_REJECT"},
1199         {CC_HOLD,L3,EVENT_HOLD,
1200          parse_hold,build_hold,print_hold,
1201          "HOLD"},
1202         {CC_SUSPEND,L3,EVENT_SUSPEND,
1203          parse_suspend,build_suspend,print_suspend,
1204          "SUSPEND"},
1205         {CC_RESUME,L3,EVENT_RESUME,
1206          parse_resume,build_resume,print_resume,
1207          "RESUME"},
1208         {CC_HOLD_ACKNOWLEDGE,L3,EVENT_HOLD_ACKNOWLEDGE,
1209          parse_hold_acknowledge,build_hold_acknowledge,print_hold_acknowledge,
1210          "HOLD_ACKNOWLEDGE"},
1211         {CC_SUSPEND_ACKNOWLEDGE,L3,EVENT_SUSPEND_ACKNOWLEDGE,
1212          parse_suspend_acknowledge,build_suspend_acknowledge,print_suspend_acknowledge,
1213          "SUSPEND_ACKNOWLEDGE"},
1214         {CC_RESUME_ACKNOWLEDGE,L3,EVENT_RESUME_ACKNOWLEDGE,
1215          parse_resume_acknowledge,build_resume_acknowledge,print_resume_acknowledge,
1216          "RESUME_ACKNOWLEDGE"},
1217         {CC_HOLD_REJECT,L3,EVENT_HOLD_REJECT,
1218          parse_hold_reject,build_hold_reject,print_hold_reject,
1219          "HOLD_REJECT"},
1220         {CC_RETRIEVE,L3,EVENT_RETRIEVE,
1221          parse_retrieve,build_retrieve,print_retrieve,
1222          "RETRIEVE"},
1223         {CC_RETRIEVE_ACKNOWLEDGE,L3,EVENT_RETRIEVE_ACKNOWLEDGE,
1224          parse_retrieve_acknowledge,build_retrieve_acknowledge,print_retrieve_acknowledge,
1225          "RETRIEVE_ACKNOWLEDGE"},
1226         {CC_RETRIEVE_REJECT,L3,EVENT_RETRIEVE_REJECT,
1227          parse_retrieve_reject,build_retrieve_reject,print_retrieve_reject,
1228          "RETRIEVE_REJECT"},
1229         {CC_DISCONNECT,L3,EVENT_DISCONNECT,
1230          parse_disconnect,build_disconnect,print_disconnect,
1231          "DISCONNECT"},
1232         {CC_RESTART,L3,EVENT_RESTART,
1233          parse_restart,build_restart,print_restart,
1234          "RESTART"},
1235         {CC_RELEASE,L3,EVENT_RELEASE,
1236          parse_release,build_release,print_release,
1237          "RELEASE"},
1238         {CC_RELEASE_COMPLETE,L3,EVENT_RELEASE_COMPLETE,
1239          parse_release_complete,build_release_complete,print_release_complete,
1240          "RELEASE_COMPLETE"},
1241         {CC_FACILITY,L3,EVENT_FACILITY,
1242          parse_facility,build_facility,print_facility,
1243          "FACILITY"},
1244         {CC_NOTIFY,L3,EVENT_NOTIFY,
1245          parse_notify,build_notify,print_notify,
1246          "NOTIFY"},
1247         {CC_STATUS_ENQUIRY,L3,EVENT_STATUS_ENQUIRY,
1248          parse_status_enquiry,build_status_enquiry,print_status_enquiry,
1249          "STATUS_ENQUIRY"},
1250         {CC_INFORMATION,L3,EVENT_INFORMATION,
1251          parse_information,build_information,print_information,
1252          "INFORMATION"},
1253         {CC_STATUS,L3,EVENT_STATUS,
1254          parse_status,build_status,print_status,
1255          "STATUS"},
1256         {CC_TIMEOUT,L3,EVENT_TIMEOUT,
1257          parse_timeout,build_timeout,print_timeout,
1258          "TIMEOUT"},
1259         {0,0,0,NULL,NULL,NULL,NULL}
1260 };
1261
1262 #define msgs_max (sizeof(msgs_g)/sizeof(struct isdn_msg))
1263
1264 /** INTERFACE FCTS ***/
1265 int isdn_msg_get_index(struct isdn_msg msgs[], msg_t *msg, int nt)
1266 {
1267         int i;
1268
1269         if (nt){
1270 #ifdef MISDNUSER_JOLLY
1271                 mISDNuser_head_t *hh = (mISDNuser_head_t*)msg->data;
1272 #else
1273                 mISDN_head_t *hh = (mISDN_head_t*)msg->data;
1274 #endif
1275     
1276                 for (i=0; i< msgs_max -1; i++) 
1277                         if ( (hh->prim&COMMAND_MASK)==(msgs[i].misdn_msg&COMMAND_MASK)) return i;
1278     
1279         } else {
1280                 iframe_t *frm = (iframe_t*)msg->data;
1281     
1282                 for (i=0; i< msgs_max -1; i++) 
1283                         if ( (frm->prim&COMMAND_MASK)==(msgs[i].misdn_msg&COMMAND_MASK)) return i;
1284         }
1285
1286         return -1;
1287 }
1288
1289 int isdn_msg_get_index_by_event(struct isdn_msg msgs[], enum event_e event, int nt)
1290 {
1291         int i;
1292         for (i=0; i< msgs_max; i++) 
1293                 if ( event == msgs[i].event) return i;
1294
1295         cb_log(4,0, "get_index: EVENT NOT FOUND!!\n");
1296         
1297         return -1;
1298 }
1299
1300 enum event_e isdn_msg_get_event(struct isdn_msg msgs[], msg_t *msg, int nt)
1301 {
1302         int i=isdn_msg_get_index(msgs, msg, nt);
1303         if(i>=0) return msgs[i].event;
1304         return EVENT_UNKNOWN;
1305 }
1306
1307 char * isdn_msg_get_info(struct isdn_msg msgs[], msg_t *msg, int nt)
1308 {
1309         int i=isdn_msg_get_index(msgs, msg, nt);
1310         if(i>=0) return msgs[i].info;
1311         return NULL;
1312 }
1313
1314
1315 char EVENT_CLEAN_INFO[] = "CLEAN_UP";
1316 char EVENT_DTMF_TONE_INFO[] = "DTMF_TONE";
1317 char EVENT_NEW_L3ID_INFO[] = "NEW_L3ID";
1318 char EVENT_NEW_BC_INFO[] = "NEW_BC";
1319 char EVENT_BCHAN_DATA_INFO[] = "BCHAN_DATA";
1320
1321 char * isdn_get_info(struct isdn_msg msgs[], enum event_e event, int nt)
1322 {
1323         int i=isdn_msg_get_index_by_event(msgs, event, nt);
1324         
1325         if(i>=0) return msgs[i].info;
1326         
1327         if (event == EVENT_CLEANUP) return EVENT_CLEAN_INFO;
1328         if (event == EVENT_DTMF_TONE) return EVENT_DTMF_TONE_INFO;
1329         if (event == EVENT_NEW_L3ID) return EVENT_NEW_L3ID_INFO;
1330         if (event == EVENT_NEW_BC) return EVENT_NEW_BC_INFO;
1331         if (event == EVENT_BCHAN_DATA) return EVENT_BCHAN_DATA_INFO;
1332         
1333         return NULL;
1334 }
1335
1336 int isdn_msg_parse_event(struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
1337 {
1338         int i=isdn_msg_get_index(msgs, msg, nt);
1339         if(i<0) return -1;
1340
1341         msgs[i].msg_parser(msgs, msg, bc, nt);
1342         return 0;
1343 }
1344
1345 msg_t * isdn_msg_build_event(struct isdn_msg msgs[], struct misdn_bchannel *bc, enum event_e event, int nt)
1346 {
1347         int i=isdn_msg_get_index_by_event(msgs, event, nt);
1348         if(i<0) return NULL;
1349   
1350         return  msgs[i].msg_builder(msgs, bc, nt);
1351 }
1352