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