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