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