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