00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "isdn_lib_intern.h"
00024
00025
00026 #include "isdn_lib.h"
00027
00028 #include "ie.c"
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 static void build_display_str(char *display, size_t display_length, int display_format, const char *name, const char *number)
00043 {
00044 display[0] = 0;
00045 switch (display_format) {
00046 default:
00047 case 0:
00048 break;
00049
00050 case 1:
00051 snprintf(display, display_length, "%s", name);
00052 break;
00053
00054 case 2:
00055 snprintf(display, display_length, "%s", number);
00056 break;
00057
00058 case 3:
00059 if (name[0] || number[0]) {
00060 snprintf(display, display_length, "\"%s\" <%s>", name, number);
00061 }
00062 break;
00063 }
00064 }
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 static void enc_ie_facility(unsigned char **ntmode, msg_t *msg, struct FacParm *fac, int nt)
00078 {
00079 int len;
00080 Q931_info_t *qi;
00081 unsigned char *p;
00082 unsigned char buf[256];
00083
00084 len = encodeFac(buf, fac);
00085 if (len <= 0) {
00086
00087
00088
00089
00090 fac->Function = Fac_None;
00091 return;
00092 }
00093
00094 p = msg_put(msg, len);
00095 if (nt) {
00096 *ntmode = p + 1;
00097 } else {
00098 qi = (Q931_info_t *) (msg->data + mISDN_HEADER_LEN);
00099 qi->QI_ELEMENT(facility) = p - (unsigned char *) qi - sizeof(Q931_info_t);
00100 }
00101
00102 memcpy(p, buf, len);
00103
00104
00105 fac->Function = Fac_None;
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 static void dec_ie_facility(unsigned char *p, Q931_info_t *qi, struct FacParm *fac, int nt, struct misdn_bchannel *bc)
00121 {
00122 fac->Function = Fac_None;
00123
00124 if (!nt) {
00125 p = NULL;
00126 if (qi->QI_ELEMENT(facility)) {
00127 p = (unsigned char *) qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(facility) + 1;
00128 }
00129 }
00130 if (!p) {
00131 return;
00132 }
00133
00134 if (decodeFac(p, fac)) {
00135 cb_log(3, bc->port, "Decoding facility ie failed! Unrecognized facility message?\n");
00136 }
00137 }
00138
00139
00140
00141 static void set_channel(struct misdn_bchannel *bc, int channel)
00142 {
00143
00144 cb_log(3,bc->port,"set_channel: bc->channel:%d channel:%d\n", bc->channel, channel);
00145
00146
00147 if (channel==0xff) {
00148
00149 channel=-1;
00150 }
00151
00152
00153 if (channel > 0 && bc->nt ) {
00154
00155 if (bc->channel && ( bc->channel != 0xff) ) {
00156 cb_log(0,bc->port,"We already have a channel (%d)\n", bc->channel);
00157 } else {
00158 bc->channel = channel;
00159 cb_event(EVENT_NEW_CHANNEL,bc,NULL);
00160 }
00161 }
00162
00163 if (channel > 0 && !bc->nt ) {
00164 bc->channel = channel;
00165 cb_event(EVENT_NEW_CHANNEL,bc,NULL);
00166 }
00167 }
00168
00169 static void parse_proceeding (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00170 {
00171 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00172 CALL_PROCEEDING_t *proceeding = (CALL_PROCEEDING_t *) (msg->data + HEADER_LEN);
00173
00174
00175 {
00176 int exclusive, channel;
00177 dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)proceeding, &exclusive, &channel, nt,bc);
00178
00179 set_channel(bc,channel);
00180
00181 }
00182
00183 dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)proceeding, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
00184
00185 dec_ie_facility(proceeding->FACILITY, (Q931_info_t *) proceeding, &bc->fac_in, nt, bc);
00186
00187
00188
00189 #ifdef DEBUG
00190 printf("Parsing PROCEEDING Msg\n");
00191 #endif
00192 }
00193 static msg_t *build_proceeding (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00194 {
00195 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00196 CALL_PROCEEDING_t *proceeding;
00197 msg_t *msg =(msg_t*)create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, bc?bc->l3_id:-1, sizeof(CALL_PROCEEDING_t) ,nt);
00198
00199 proceeding=(CALL_PROCEEDING_t*)((msg->data+HEADER_LEN));
00200
00201 enc_ie_channel_id(&proceeding->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
00202
00203 if (nt)
00204 enc_ie_progress(&proceeding->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);
00205
00206 if (bc->fac_out.Function != Fac_None) {
00207 enc_ie_facility(&proceeding->FACILITY, msg, &bc->fac_out, nt);
00208 }
00209
00210
00211
00212 #ifdef DEBUG
00213 printf("Building PROCEEDING Msg\n");
00214 #endif
00215 return msg;
00216 }
00217
00218 static void parse_alerting (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00219 {
00220 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00221 ALERTING_t *alerting = (ALERTING_t *) (msg->data + HEADER_LEN);
00222
00223
00224 dec_ie_facility(alerting->FACILITY, (Q931_info_t *) alerting, &bc->fac_in, nt, bc);
00225
00226
00227
00228 dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)alerting, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
00229
00230 #ifdef DEBUG
00231 printf("Parsing ALERTING Msg\n");
00232 #endif
00233
00234
00235 }
00236
00237 static msg_t *build_alerting (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00238 {
00239 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00240 ALERTING_t *alerting;
00241 msg_t *msg =(msg_t*)create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, bc?bc->l3_id:-1, sizeof(ALERTING_t) ,nt);
00242
00243 alerting=(ALERTING_t*)((msg->data+HEADER_LEN));
00244
00245 enc_ie_channel_id(&alerting->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
00246
00247 if (nt)
00248 enc_ie_progress(&alerting->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);
00249
00250 if (bc->fac_out.Function != Fac_None) {
00251 enc_ie_facility(&alerting->FACILITY, msg, &bc->fac_out, nt);
00252 }
00253
00254
00255
00256 #ifdef DEBUG
00257 printf("Building ALERTING Msg\n");
00258 #endif
00259 return msg;
00260 }
00261
00262
00263 static void parse_progress (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00264 {
00265 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00266 PROGRESS_t *progress = (PROGRESS_t *) (msg->data + HEADER_LEN);
00267
00268
00269 dec_ie_progress(progress->PROGRESS, (Q931_info_t *)progress, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
00270
00271 dec_ie_facility(progress->FACILITY, (Q931_info_t *) progress, &bc->fac_in, nt, bc);
00272
00273 #ifdef DEBUG
00274 printf("Parsing PROGRESS Msg\n");
00275 #endif
00276 }
00277
00278 static msg_t *build_progress (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00279 {
00280 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00281 PROGRESS_t *progress;
00282 msg_t *msg =(msg_t*)create_l3msg(CC_PROGRESS | REQUEST, MT_PROGRESS, bc?bc->l3_id:-1, sizeof(PROGRESS_t) ,nt);
00283
00284 progress=(PROGRESS_t*)((msg->data+HEADER_LEN));
00285
00286 if (bc->fac_out.Function != Fac_None) {
00287 enc_ie_facility(&progress->FACILITY, msg, &bc->fac_out, nt);
00288 }
00289
00290 #ifdef DEBUG
00291 printf("Building PROGRESS Msg\n");
00292 #endif
00293 return msg;
00294 }
00295
00296 #if defined(AST_MISDN_ENHANCEMENTS)
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 static void extract_setup_Bc_Hlc_Llc(SETUP_t *setup, int nt, struct misdn_bchannel *bc)
00308 {
00309 __u8 *p;
00310 Q931_info_t *qi;
00311
00312 qi = (Q931_info_t *) setup;
00313
00314
00315 if (nt) {
00316 p = (__u8 *) setup->BEARER;
00317 } else {
00318 if (qi->QI_ELEMENT(bearer_capability)) {
00319 p = (__u8 *) qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(bearer_capability) + 1;
00320 } else {
00321 p = NULL;
00322 }
00323 }
00324 if (!p || *p == 0 || sizeof(bc->setup_bc_hlc_llc.Bc.Contents) < *p) {
00325 bc->setup_bc_hlc_llc.Bc.Length = 0;
00326 } else {
00327 bc->setup_bc_hlc_llc.Bc.Length = *p;
00328 memcpy(bc->setup_bc_hlc_llc.Bc.Contents, p + 1, *p);
00329 }
00330
00331
00332 if (nt) {
00333 p = (__u8 *) setup->LLC;
00334 } else {
00335 if (qi->QI_ELEMENT(llc)) {
00336 p = (__u8 *) qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(llc) + 1;
00337 } else {
00338 p = NULL;
00339 }
00340 }
00341 if (!p || *p == 0 || sizeof(bc->setup_bc_hlc_llc.Llc.Contents) < *p) {
00342 bc->setup_bc_hlc_llc.Llc.Length = 0;
00343 } else {
00344 bc->setup_bc_hlc_llc.Llc.Length = *p;
00345 memcpy(bc->setup_bc_hlc_llc.Llc.Contents, p + 1, *p);
00346 }
00347
00348
00349 if (nt) {
00350 p = (__u8 *) setup->HLC;
00351 } else {
00352 if (qi->QI_ELEMENT(hlc)) {
00353 p = (__u8 *) qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(hlc) + 1;
00354 } else {
00355 p = NULL;
00356 }
00357 }
00358 if (!p || *p == 0 || sizeof(bc->setup_bc_hlc_llc.Hlc.Contents) < *p) {
00359 bc->setup_bc_hlc_llc.Hlc.Length = 0;
00360 } else {
00361 bc->setup_bc_hlc_llc.Hlc.Length = *p;
00362 memcpy(bc->setup_bc_hlc_llc.Hlc.Contents, p + 1, *p);
00363 }
00364 }
00365 #endif
00366
00367 static void parse_setup (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00368 {
00369 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00370 SETUP_t *setup = (SETUP_t *) (msg->data + HEADER_LEN);
00371 Q931_info_t *qi = (Q931_info_t *) (msg->data + HEADER_LEN);
00372 int type;
00373 int plan;
00374 int present;
00375 int screen;
00376 int reason;
00377
00378 #ifdef DEBUG
00379 printf("Parsing SETUP Msg\n");
00380 #endif
00381
00382 dec_ie_calling_pn(setup->CALLING_PN, qi, &type, &plan, &present, &screen, bc->caller.number, sizeof(bc->caller.number), nt, bc);
00383 bc->caller.number_type = type;
00384 bc->caller.number_plan = plan;
00385 switch (present) {
00386 default:
00387 case 0:
00388 bc->caller.presentation = 0;
00389 break;
00390 case 1:
00391 bc->caller.presentation = 1;
00392 break;
00393 case 2:
00394 bc->caller.presentation = 2;
00395 break;
00396 }
00397 if (0 <= screen) {
00398 bc->caller.screening = screen;
00399 } else {
00400 bc->caller.screening = 0;
00401 }
00402
00403 dec_ie_facility(setup->FACILITY, (Q931_info_t *) setup, &bc->fac_in, nt, bc);
00404
00405 dec_ie_called_pn(setup->CALLED_PN, (Q931_info_t *) setup, &type, &plan, bc->dialed.number, sizeof(bc->dialed.number), nt, bc);
00406 bc->dialed.number_type = type;
00407 bc->dialed.number_plan = plan;
00408
00409 dec_ie_keypad(setup->KEYPAD, (Q931_info_t *) setup, bc->keypad, sizeof(bc->keypad), nt, bc);
00410
00411 dec_ie_complete(setup->COMPLETE, (Q931_info_t *) setup, &bc->sending_complete, nt, bc);
00412
00413 dec_ie_redir_nr(setup->REDIR_NR, (Q931_info_t *) setup, &type, &plan, &present, &screen, &reason, bc->redirecting.from.number, sizeof(bc->redirecting.from.number), nt, bc);
00414 bc->redirecting.from.number_type = type;
00415 bc->redirecting.from.number_plan = plan;
00416 switch (present) {
00417 default:
00418 case 0:
00419 bc->redirecting.from.presentation = 0;
00420 break;
00421 case 1:
00422 bc->redirecting.from.presentation = 1;
00423 break;
00424 case 2:
00425 bc->redirecting.from.presentation = 2;
00426 break;
00427 }
00428 if (0 <= screen) {
00429 bc->redirecting.from.screening = screen;
00430 } else {
00431 bc->redirecting.from.screening = 0;
00432 }
00433 if (0 <= reason) {
00434 bc->redirecting.reason = reason;
00435 } else {
00436 bc->redirecting.reason = mISDN_REDIRECTING_REASON_UNKNOWN;
00437 }
00438
00439 {
00440 int coding, capability, mode, rate, multi, user, async, urate, stopbits, dbits, parity;
00441
00442 dec_ie_bearer(setup->BEARER, (Q931_info_t *)setup, &coding, &capability, &mode, &rate, &multi, &user, &async, &urate, &stopbits, &dbits, &parity, nt,bc);
00443 switch (capability) {
00444 case -1: bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED;
00445 break;
00446 case 0: bc->capability=INFO_CAPABILITY_SPEECH;
00447 break;
00448 case 18: bc->capability=INFO_CAPABILITY_VIDEO;
00449 break;
00450 case 8: bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED;
00451 bc->user1 = user;
00452 bc->urate = urate;
00453
00454 bc->rate = rate;
00455 bc->mode = mode;
00456 break;
00457 case 9: bc->capability=INFO_CAPABILITY_DIGITAL_RESTRICTED;
00458 break;
00459 default:
00460 break;
00461 }
00462
00463 switch(user) {
00464 case 2:
00465 bc->law=INFO_CODEC_ULAW;
00466 break;
00467 case 3:
00468 bc->law=INFO_CODEC_ALAW;
00469 break;
00470 default:
00471 bc->law=INFO_CODEC_ALAW;
00472
00473 }
00474
00475 bc->capability=capability;
00476 }
00477 {
00478 int exclusive, channel;
00479 dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)setup, &exclusive, &channel, nt,bc);
00480
00481 set_channel(bc,channel);
00482 }
00483
00484 {
00485 int protocol ;
00486 dec_ie_useruser(setup->USER_USER, (Q931_info_t *)setup, &protocol, bc->uu, &bc->uulen, nt,bc);
00487 if (bc->uulen) cb_log(1,bc->port,"USERUESRINFO:%s\n",bc->uu);
00488 else
00489 cb_log(1,bc->port,"NO USERUESRINFO\n");
00490 }
00491
00492 dec_ie_progress(setup->PROGRESS, (Q931_info_t *)setup, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
00493
00494 #if defined(AST_MISDN_ENHANCEMENTS)
00495 extract_setup_Bc_Hlc_Llc(setup, nt, bc);
00496 #endif
00497 }
00498
00499 #define ANY_CHANNEL 0xff
00500 static msg_t *build_setup (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00501 {
00502 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00503 SETUP_t *setup;
00504 msg_t *msg =(msg_t*)create_l3msg(CC_SETUP | REQUEST, MT_SETUP, bc?bc->l3_id:-1, sizeof(SETUP_t) ,nt);
00505 int is_ptp;
00506 enum FacFunction fac_type;
00507
00508 setup=(SETUP_t*)((msg->data+HEADER_LEN));
00509
00510 if (bc->channel == 0 || bc->channel == ANY_CHANNEL || bc->channel==-1)
00511 enc_ie_channel_id(&setup->CHANNEL_ID, msg, 0, bc->channel, nt,bc);
00512 else
00513 enc_ie_channel_id(&setup->CHANNEL_ID, msg, 1, bc->channel, nt,bc);
00514
00515 fac_type = bc->fac_out.Function;
00516 if (fac_type != Fac_None) {
00517 enc_ie_facility(&setup->FACILITY, msg, &bc->fac_out, nt);
00518 }
00519
00520 enc_ie_calling_pn(&setup->CALLING_PN, msg, bc->caller.number_type, bc->caller.number_plan,
00521 bc->caller.presentation, bc->caller.screening, bc->caller.number, nt, bc);
00522
00523 if (bc->dialed.number[0]) {
00524 enc_ie_called_pn(&setup->CALLED_PN, msg, bc->dialed.number_type, bc->dialed.number_plan, bc->dialed.number, nt, bc);
00525 }
00526
00527 switch (bc->outgoing_colp) {
00528 case 0:
00529 case 1:
00530 is_ptp = misdn_lib_is_ptp(bc->port);
00531 if (bc->redirecting.from.number[0]
00532 && ((!is_ptp && nt)
00533 || (is_ptp
00534 #if defined(AST_MISDN_ENHANCEMENTS)
00535
00536
00537
00538
00539
00540
00541 && fac_type != Fac_DivertingLegInformation2
00542 #endif
00543 ))) {
00544 #if 1
00545
00546 enc_ie_redir_nr(&setup->REDIR_NR, msg, bc->redirecting.from.number_type,
00547 bc->redirecting.from.number_plan, bc->redirecting.from.presentation, 0,
00548 bc->redirecting.reason, bc->redirecting.from.number, nt, bc);
00549 #else
00550
00551 enc_ie_redir_nr(&setup->REDIR_NR, msg, bc->redirecting.from.number_type,
00552 bc->redirecting.from.number_plan, bc->redirecting.from.presentation,
00553 bc->redirecting.from.screening, bc->redirecting.reason,
00554 bc->redirecting.from.number, nt, bc);
00555 #endif
00556 }
00557 break;
00558 default:
00559 break;
00560 }
00561
00562 if (bc->keypad[0]) {
00563 enc_ie_keypad(&setup->KEYPAD, msg, bc->keypad, nt,bc);
00564 }
00565
00566
00567
00568 if (*bc->display) {
00569 enc_ie_display(&setup->DISPLAY, msg, bc->display, nt, bc);
00570 } else if (nt && bc->caller.presentation == 0) {
00571 char display[sizeof(bc->display)];
00572
00573
00574 build_display_str(display, sizeof(display), bc->display_setup, bc->caller.name, bc->caller.number);
00575 if (display[0]) {
00576 enc_ie_display(&setup->DISPLAY, msg, display, nt, bc);
00577 }
00578 }
00579
00580 {
00581 int coding = 0;
00582 int capability;
00583 int mode = 0;
00584 int user;
00585 int rate = 0x10;
00586
00587 switch (bc->law) {
00588 case INFO_CODEC_ULAW: user=2;
00589 break;
00590 case INFO_CODEC_ALAW: user=3;
00591 break;
00592 default:
00593 user=3;
00594 }
00595
00596 switch (bc->capability) {
00597 case INFO_CAPABILITY_SPEECH: capability = 0;
00598 break;
00599 case INFO_CAPABILITY_DIGITAL_UNRESTRICTED: capability = 8;
00600 user=-1;
00601 mode=bc->mode;
00602 rate=bc->rate;
00603 break;
00604 case INFO_CAPABILITY_DIGITAL_RESTRICTED: capability = 9;
00605 user=-1;
00606 break;
00607 default:
00608 capability=bc->capability;
00609 }
00610
00611 enc_ie_bearer(&setup->BEARER, msg, coding, capability, mode, rate, -1, user, nt,bc);
00612 }
00613
00614 if (bc->sending_complete) {
00615 enc_ie_complete(&setup->COMPLETE,msg, bc->sending_complete, nt, bc);
00616 }
00617
00618 if (bc->uulen) {
00619 int protocol=4;
00620 enc_ie_useruser(&setup->USER_USER, msg, protocol, bc->uu, bc->uulen, nt,bc);
00621 cb_log(1,bc->port,"ENCODING USERUESRINFO:%s\n",bc->uu);
00622 }
00623
00624 #if defined(AST_MISDN_ENHANCEMENTS)
00625 extract_setup_Bc_Hlc_Llc(setup, nt, bc);
00626 #endif
00627
00628 #ifdef DEBUG
00629 printf("Building SETUP Msg\n");
00630 #endif
00631 return msg;
00632 }
00633
00634 static void parse_connect (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00635 {
00636 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00637 CONNECT_t *connect = (CONNECT_t *) (msg->data + HEADER_LEN);
00638 int type;
00639 int plan;
00640 int pres;
00641 int screen;
00642
00643 bc->ces = connect->ces;
00644
00645 dec_ie_progress(connect->PROGRESS, (Q931_info_t *)connect, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
00646
00647 dec_ie_connected_pn(connect->CONNECT_PN, (Q931_info_t *) connect, &type, &plan,
00648 &pres, &screen, bc->connected.number, sizeof(bc->connected.number), nt, bc);
00649 bc->connected.number_type = type;
00650 bc->connected.number_plan = plan;
00651 switch (pres) {
00652 default:
00653 case 0:
00654 bc->connected.presentation = 0;
00655 break;
00656 case 1:
00657 bc->connected.presentation = 1;
00658 break;
00659 case 2:
00660 bc->connected.presentation = 2;
00661 break;
00662 }
00663 if (0 <= screen) {
00664 bc->connected.screening = screen;
00665 } else {
00666 bc->connected.screening = 0;
00667 }
00668
00669 dec_ie_facility(connect->FACILITY, (Q931_info_t *) connect, &bc->fac_in, nt, bc);
00670
00671
00672
00673
00674
00675 #ifdef DEBUG
00676 printf("Parsing CONNECT Msg\n");
00677 #endif
00678 }
00679
00680 static msg_t *build_connect (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00681 {
00682 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00683 CONNECT_t *connect;
00684 msg_t *msg =(msg_t*)create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, bc?bc->l3_id:-1, sizeof(CONNECT_t) ,nt);
00685
00686 cb_log(6,bc->port,"BUILD_CONNECT: bc:%p bc->l3id:%d, nt:%d\n",bc,bc->l3_id,nt);
00687
00688 connect=(CONNECT_t*)((msg->data+HEADER_LEN));
00689
00690 if (nt) {
00691 time_t now;
00692 time(&now);
00693 enc_ie_date(&connect->DATE, msg, now, nt,bc);
00694 }
00695
00696 switch (bc->outgoing_colp) {
00697 case 0:
00698 case 1:
00699 enc_ie_connected_pn(&connect->CONNECT_PN, msg, bc->connected.number_type,
00700 bc->connected.number_plan, bc->connected.presentation,
00701 bc->connected.screening, bc->connected.number, nt, bc);
00702 break;
00703 default:
00704 break;
00705 }
00706
00707 if (nt && bc->connected.presentation == 0) {
00708 char display[sizeof(bc->display)];
00709
00710
00711 build_display_str(display, sizeof(display), bc->display_connected, bc->connected.name, bc->connected.number);
00712 if (display[0]) {
00713 enc_ie_display(&connect->DISPLAY, msg, display, nt, bc);
00714 }
00715 }
00716
00717 if (bc->fac_out.Function != Fac_None) {
00718 enc_ie_facility(&connect->FACILITY, msg, &bc->fac_out, nt);
00719 }
00720
00721 #ifdef DEBUG
00722 printf("Building CONNECT Msg\n");
00723 #endif
00724 return msg;
00725 }
00726
00727 static void parse_setup_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00728 {
00729 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00730 SETUP_ACKNOWLEDGE_t *setup_acknowledge = (SETUP_ACKNOWLEDGE_t *) (msg->data + HEADER_LEN);
00731
00732 {
00733 int exclusive, channel;
00734 dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)setup_acknowledge, &exclusive, &channel, nt,bc);
00735
00736
00737 set_channel(bc, channel);
00738 }
00739
00740 dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)setup_acknowledge, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
00741
00742 dec_ie_facility(setup_acknowledge->FACILITY, (Q931_info_t *) setup_acknowledge, &bc->fac_in, nt, bc);
00743
00744 #ifdef DEBUG
00745 printf("Parsing SETUP_ACKNOWLEDGE Msg\n");
00746 #endif
00747
00748
00749 }
00750
00751 static msg_t *build_setup_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00752 {
00753 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00754 SETUP_ACKNOWLEDGE_t *setup_acknowledge;
00755 msg_t *msg =(msg_t*)create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(SETUP_ACKNOWLEDGE_t) ,nt);
00756
00757 setup_acknowledge=(SETUP_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
00758
00759 enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
00760
00761 if (nt)
00762 enc_ie_progress(&setup_acknowledge->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);
00763
00764 if (bc->fac_out.Function != Fac_None) {
00765 enc_ie_facility(&setup_acknowledge->FACILITY, msg, &bc->fac_out, nt);
00766 }
00767
00768 #ifdef DEBUG
00769 printf("Building SETUP_ACKNOWLEDGE Msg\n");
00770 #endif
00771 return msg;
00772 }
00773
00774 static void parse_connect_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00775 {
00776 #ifdef DEBUG
00777 printf("Parsing CONNECT_ACKNOWLEDGE Msg\n");
00778 #endif
00779
00780
00781 }
00782
00783 static msg_t *build_connect_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00784 {
00785 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00786 CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
00787 msg_t *msg =(msg_t*)create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, bc?bc->l3_id:-1, sizeof(CONNECT_ACKNOWLEDGE_t) ,nt);
00788
00789 connect_acknowledge=(CONNECT_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
00790
00791 enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, msg, 1, bc->channel, nt,bc);
00792
00793 #ifdef DEBUG
00794 printf("Building CONNECT_ACKNOWLEDGE Msg\n");
00795 #endif
00796 return msg;
00797 }
00798
00799 static void parse_user_information (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00800 {
00801 #ifdef DEBUG
00802 printf("Parsing USER_INFORMATION Msg\n");
00803 #endif
00804
00805
00806 }
00807
00808 static msg_t *build_user_information (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00809 {
00810 msg_t *msg =(msg_t*)create_l3msg(CC_USER_INFORMATION | REQUEST, MT_USER_INFORMATION, bc?bc->l3_id:-1, sizeof(USER_INFORMATION_t) ,nt);
00811
00812 #ifdef DEBUG
00813 printf("Building USER_INFORMATION Msg\n");
00814 #endif
00815 return msg;
00816 }
00817
00818 static void parse_suspend_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00819 {
00820 #ifdef DEBUG
00821 printf("Parsing SUSPEND_REJECT Msg\n");
00822 #endif
00823
00824
00825 }
00826
00827 static msg_t *build_suspend_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00828 {
00829 msg_t *msg =(msg_t*)create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, bc?bc->l3_id:-1, sizeof(SUSPEND_REJECT_t) ,nt);
00830
00831 #ifdef DEBUG
00832 printf("Building SUSPEND_REJECT Msg\n");
00833 #endif
00834 return msg;
00835 }
00836
00837 static void parse_resume_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00838 {
00839 #ifdef DEBUG
00840 printf("Parsing RESUME_REJECT Msg\n");
00841 #endif
00842
00843
00844 }
00845
00846 static msg_t *build_resume_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00847 {
00848 msg_t *msg =(msg_t*)create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, bc?bc->l3_id:-1, sizeof(RESUME_REJECT_t) ,nt);
00849
00850 #ifdef DEBUG
00851 printf("Building RESUME_REJECT Msg\n");
00852 #endif
00853 return msg;
00854 }
00855
00856 static void parse_hold (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00857 {
00858 #ifdef DEBUG
00859 printf("Parsing HOLD Msg\n");
00860 #endif
00861
00862
00863 }
00864
00865 static msg_t *build_hold (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00866 {
00867 msg_t *msg =(msg_t*)create_l3msg(CC_HOLD | REQUEST, MT_HOLD, bc?bc->l3_id:-1, sizeof(HOLD_t) ,nt);
00868
00869 #ifdef DEBUG
00870 printf("Building HOLD Msg\n");
00871 #endif
00872 return msg;
00873 }
00874
00875 static void parse_suspend (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00876 {
00877 #ifdef DEBUG
00878 printf("Parsing SUSPEND Msg\n");
00879 #endif
00880
00881
00882 }
00883
00884 static msg_t *build_suspend (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00885 {
00886 msg_t *msg =(msg_t*)create_l3msg(CC_SUSPEND | REQUEST, MT_SUSPEND, bc?bc->l3_id:-1, sizeof(SUSPEND_t) ,nt);
00887
00888 #ifdef DEBUG
00889 printf("Building SUSPEND Msg\n");
00890 #endif
00891 return msg;
00892 }
00893
00894 static void parse_resume (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00895 {
00896 #ifdef DEBUG
00897 printf("Parsing RESUME Msg\n");
00898 #endif
00899
00900
00901 }
00902
00903 static msg_t *build_resume (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00904 {
00905 msg_t *msg =(msg_t*)create_l3msg(CC_RESUME | REQUEST, MT_RESUME, bc?bc->l3_id:-1, sizeof(RESUME_t) ,nt);
00906
00907 #ifdef DEBUG
00908 printf("Building RESUME Msg\n");
00909 #endif
00910 return msg;
00911 }
00912
00913 static void parse_hold_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00914 {
00915 #ifdef DEBUG
00916 printf("Parsing HOLD_ACKNOWLEDGE Msg\n");
00917 #endif
00918
00919
00920 }
00921
00922 static msg_t *build_hold_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00923 {
00924 msg_t *msg =(msg_t*)create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(HOLD_ACKNOWLEDGE_t) ,nt);
00925
00926 #ifdef DEBUG
00927 printf("Building HOLD_ACKNOWLEDGE Msg\n");
00928 #endif
00929 return msg;
00930 }
00931
00932 static void parse_suspend_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00933 {
00934 #ifdef DEBUG
00935 printf("Parsing SUSPEND_ACKNOWLEDGE Msg\n");
00936 #endif
00937
00938
00939 }
00940
00941 static msg_t *build_suspend_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00942 {
00943 msg_t *msg =(msg_t*)create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(SUSPEND_ACKNOWLEDGE_t) ,nt);
00944
00945 #ifdef DEBUG
00946 printf("Building SUSPEND_ACKNOWLEDGE Msg\n");
00947 #endif
00948 return msg;
00949 }
00950
00951 static void parse_resume_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00952 {
00953 #ifdef DEBUG
00954 printf("Parsing RESUME_ACKNOWLEDGE Msg\n");
00955 #endif
00956
00957
00958 }
00959
00960 static msg_t *build_resume_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00961 {
00962 msg_t *msg =(msg_t*)create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(RESUME_ACKNOWLEDGE_t) ,nt);
00963
00964 #ifdef DEBUG
00965 printf("Building RESUME_ACKNOWLEDGE Msg\n");
00966 #endif
00967 return msg;
00968 }
00969
00970 static void parse_hold_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00971 {
00972 #ifdef DEBUG
00973 printf("Parsing HOLD_REJECT Msg\n");
00974 #endif
00975
00976
00977 }
00978
00979 static msg_t *build_hold_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00980 {
00981 msg_t *msg =(msg_t*)create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, bc?bc->l3_id:-1, sizeof(HOLD_REJECT_t) ,nt);
00982
00983 #ifdef DEBUG
00984 printf("Building HOLD_REJECT Msg\n");
00985 #endif
00986 return msg;
00987 }
00988
00989 static void parse_retrieve (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00990 {
00991 #ifdef DEBUG
00992 printf("Parsing RETRIEVE Msg\n");
00993 #endif
00994
00995
00996 }
00997
00998 static msg_t *build_retrieve (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00999 {
01000 msg_t *msg =(msg_t*)create_l3msg(CC_RETRIEVE | REQUEST, MT_RETRIEVE, bc?bc->l3_id:-1, sizeof(RETRIEVE_t) ,nt);
01001
01002 #ifdef DEBUG
01003 printf("Building RETRIEVE Msg\n");
01004 #endif
01005 return msg;
01006 }
01007
01008 static void parse_retrieve_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01009 {
01010 #ifdef DEBUG
01011 printf("Parsing RETRIEVE_ACKNOWLEDGE Msg\n");
01012 #endif
01013
01014
01015 }
01016
01017 static msg_t *build_retrieve_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01018 {
01019 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01020 RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
01021 msg_t *msg =(msg_t*)create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(RETRIEVE_ACKNOWLEDGE_t) ,nt);
01022
01023 retrieve_acknowledge=(RETRIEVE_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
01024
01025 enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, msg, 1, bc->channel, nt,bc);
01026 #ifdef DEBUG
01027 printf("Building RETRIEVE_ACKNOWLEDGE Msg\n");
01028 #endif
01029 return msg;
01030 }
01031
01032 static void parse_retrieve_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01033 {
01034 #ifdef DEBUG
01035 printf("Parsing RETRIEVE_REJECT Msg\n");
01036 #endif
01037
01038
01039 }
01040
01041 static msg_t *build_retrieve_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01042 {
01043 msg_t *msg =(msg_t*)create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, bc?bc->l3_id:-1, sizeof(RETRIEVE_REJECT_t) ,nt);
01044
01045 #ifdef DEBUG
01046 printf("Building RETRIEVE_REJECT Msg\n");
01047 #endif
01048 return msg;
01049 }
01050
01051 static void parse_disconnect (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01052 {
01053 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01054 DISCONNECT_t *disconnect = (DISCONNECT_t *) (msg->data + HEADER_LEN);
01055 int location;
01056 int cause;
01057 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)(disconnect), &location, &cause, nt,bc);
01058 if (cause>0) bc->cause=cause;
01059
01060 dec_ie_facility(disconnect->FACILITY, (Q931_info_t *) disconnect, &bc->fac_in, nt, bc);
01061
01062 dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)disconnect, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
01063 #ifdef DEBUG
01064 printf("Parsing DISCONNECT Msg\n");
01065 #endif
01066
01067
01068 }
01069
01070 static msg_t *build_disconnect (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01071 {
01072 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01073 DISCONNECT_t *disconnect;
01074 msg_t *msg =(msg_t*)create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, bc?bc->l3_id:-1, sizeof(DISCONNECT_t) ,nt);
01075
01076 disconnect=(DISCONNECT_t*)((msg->data+HEADER_LEN));
01077
01078 enc_ie_cause(&disconnect->CAUSE, msg, (nt)?1:0, bc->out_cause,nt,bc);
01079 if (nt) {
01080 enc_ie_progress(&disconnect->PROGRESS, msg, 0, nt ? 1 : 5, 8, nt, bc);
01081 }
01082
01083 if (bc->fac_out.Function != Fac_None) {
01084 enc_ie_facility(&disconnect->FACILITY, msg, &bc->fac_out, nt);
01085 }
01086
01087 if (bc->uulen) {
01088 int protocol=4;
01089 enc_ie_useruser(&disconnect->USER_USER, msg, protocol, bc->uu, bc->uulen, nt,bc);
01090 cb_log(1,bc->port,"ENCODING USERUESRINFO:%s\n",bc->uu);
01091 }
01092
01093 #ifdef DEBUG
01094 printf("Building DISCONNECT Msg\n");
01095 #endif
01096 return msg;
01097 }
01098
01099 static void parse_restart (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01100 {
01101 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01102 RESTART_t *restart = (RESTART_t *) (msg->data + HEADER_LEN);
01103
01104 struct misdn_stack *stack=get_stack_by_bc(bc);
01105
01106 #ifdef DEBUG
01107 printf("Parsing RESTART Msg\n");
01108 #endif
01109
01110 {
01111 int exclusive;
01112 dec_ie_channel_id(restart->CHANNEL_ID, (Q931_info_t *)restart, &exclusive, &bc->restart_channel, nt,bc);
01113 cb_log(3, stack->port, "CC_RESTART Request on channel:%d on this port.\n", bc->restart_channel);
01114 }
01115
01116 }
01117
01118 static msg_t *build_restart (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01119 {
01120 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01121 RESTART_t *restart;
01122 msg_t *msg =(msg_t*)create_l3msg(CC_RESTART | REQUEST, MT_RESTART, bc?bc->l3_id:-1, sizeof(RESTART_t) ,nt);
01123
01124 restart=(RESTART_t*)((msg->data+HEADER_LEN));
01125
01126 #ifdef DEBUG
01127 printf("Building RESTART Msg\n");
01128 #endif
01129
01130 if (bc->channel > 0) {
01131 enc_ie_channel_id(&restart->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
01132 enc_ie_restart_ind(&restart->RESTART_IND, msg, 0x80, nt, bc);
01133 } else {
01134 enc_ie_restart_ind(&restart->RESTART_IND, msg, 0x87, nt, bc);
01135 }
01136
01137 cb_log(0,bc->port, "Restarting channel %d\n", bc->channel);
01138 return msg;
01139 }
01140
01141 static void parse_release (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01142 {
01143 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01144 RELEASE_t *release = (RELEASE_t *) (msg->data + HEADER_LEN);
01145 int location;
01146 int cause;
01147
01148 dec_ie_cause(release->CAUSE, (Q931_info_t *)(release), &location, &cause, nt,bc);
01149 if (cause>0) bc->cause=cause;
01150
01151 dec_ie_facility(release->FACILITY, (Q931_info_t *) release, &bc->fac_in, nt, bc);
01152
01153 #ifdef DEBUG
01154 printf("Parsing RELEASE Msg\n");
01155 #endif
01156
01157
01158 }
01159
01160 static msg_t *build_release (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01161 {
01162 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01163 RELEASE_t *release;
01164 msg_t *msg =(msg_t*)create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, bc?bc->l3_id:-1, sizeof(RELEASE_t) ,nt);
01165
01166 release=(RELEASE_t*)((msg->data+HEADER_LEN));
01167
01168 if (bc->out_cause>= 0)
01169 enc_ie_cause(&release->CAUSE, msg, nt?1:0, bc->out_cause, nt,bc);
01170
01171 if (bc->fac_out.Function != Fac_None) {
01172 enc_ie_facility(&release->FACILITY, msg, &bc->fac_out, nt);
01173 }
01174
01175 if (bc->uulen) {
01176 int protocol=4;
01177 enc_ie_useruser(&release->USER_USER, msg, protocol, bc->uu, bc->uulen, nt,bc);
01178 cb_log(1,bc->port,"ENCODING USERUESRINFO:%s\n",bc->uu);
01179 }
01180
01181 #ifdef DEBUG
01182 printf("Building RELEASE Msg\n");
01183 #endif
01184 return msg;
01185 }
01186
01187 static void parse_release_complete (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01188 {
01189 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01190 RELEASE_COMPLETE_t *release_complete = (RELEASE_COMPLETE_t *) (msg->data + HEADER_LEN);
01191 int location;
01192 int cause;
01193 iframe_t *frm = (iframe_t*) msg->data;
01194
01195 struct misdn_stack *stack=get_stack_by_bc(bc);
01196 mISDNuser_head_t *hh;
01197 hh=(mISDNuser_head_t*)msg->data;
01198
01199
01200
01201
01202 if (nt) {
01203 if (hh->prim == (CC_RELEASE_COMPLETE|CONFIRM)) {
01204 cb_log(0, stack->port, "CC_RELEASE_COMPLETE|CONFIRM [NT] \n");
01205 return;
01206 }
01207 } else {
01208 if (frm->prim == (CC_RELEASE_COMPLETE|CONFIRM)) {
01209 cb_log(0, stack->port, "CC_RELEASE_COMPLETE|CONFIRM [TE] \n");
01210 return;
01211 }
01212 }
01213 dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)(release_complete), &location, &cause, nt,bc);
01214 if (cause>0) bc->cause=cause;
01215
01216 dec_ie_facility(release_complete->FACILITY, (Q931_info_t *) release_complete, &bc->fac_in, nt, bc);
01217
01218 #ifdef DEBUG
01219 printf("Parsing RELEASE_COMPLETE Msg\n");
01220 #endif
01221 }
01222
01223 static msg_t *build_release_complete (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01224 {
01225 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01226 RELEASE_COMPLETE_t *release_complete;
01227 msg_t *msg =(msg_t*)create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, bc?bc->l3_id:-1, sizeof(RELEASE_COMPLETE_t) ,nt);
01228
01229 release_complete=(RELEASE_COMPLETE_t*)((msg->data+HEADER_LEN));
01230
01231 enc_ie_cause(&release_complete->CAUSE, msg, nt?1:0, bc->out_cause, nt,bc);
01232
01233 if (bc->fac_out.Function != Fac_None) {
01234 enc_ie_facility(&release_complete->FACILITY, msg, &bc->fac_out, nt);
01235 }
01236
01237 if (bc->uulen) {
01238 int protocol=4;
01239 enc_ie_useruser(&release_complete->USER_USER, msg, protocol, bc->uu, bc->uulen, nt,bc);
01240 cb_log(1,bc->port,"ENCODING USERUESRINFO:%s\n",bc->uu);
01241 }
01242
01243 #ifdef DEBUG
01244 printf("Building RELEASE_COMPLETE Msg\n");
01245 #endif
01246 return msg;
01247 }
01248
01249 static void parse_facility (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01250 {
01251 int HEADER_LEN = nt ? mISDNUSER_HEAD_SIZE : mISDN_HEADER_LEN;
01252 FACILITY_t *facility = (FACILITY_t*)(msg->data+HEADER_LEN);
01253 Q931_info_t *qi = (Q931_info_t*)(msg->data+HEADER_LEN);
01254 unsigned char *p = NULL;
01255 #if defined(AST_MISDN_ENHANCEMENTS)
01256 int description_code;
01257 int type;
01258 int plan;
01259 int present;
01260 char number[sizeof(bc->redirecting.to.number)];
01261 #endif
01262
01263 #ifdef DEBUG
01264 printf("Parsing FACILITY Msg\n");
01265 #endif
01266
01267 bc->fac_in.Function = Fac_None;
01268
01269 if (!bc->nt) {
01270 if (qi->QI_ELEMENT(facility))
01271 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(facility) + 1;
01272 } else {
01273 p = facility->FACILITY;
01274 }
01275 if (!p)
01276 return;
01277
01278 if (decodeFac(p, &bc->fac_in)) {
01279 cb_log(3, bc->port, "Decoding facility ie failed! Unrecognized facility message?\n");
01280 }
01281
01282 #if defined(AST_MISDN_ENHANCEMENTS)
01283 dec_ie_notify(facility->NOTIFY, qi, &description_code, nt, bc);
01284 if (description_code < 0) {
01285 bc->notify_description_code = mISDN_NOTIFY_CODE_INVALID;
01286 } else {
01287 bc->notify_description_code = description_code;
01288 }
01289
01290 dec_ie_redir_dn(facility->REDIR_DN, qi, &type, &plan, &present, number, sizeof(number), nt, bc);
01291 if (0 <= type) {
01292 bc->redirecting.to_changed = 1;
01293
01294 bc->redirecting.to.number_type = type;
01295 bc->redirecting.to.number_plan = plan;
01296 switch (present) {
01297 default:
01298 case 0:
01299 bc->redirecting.to.presentation = 0;
01300 break;
01301 case 1:
01302 bc->redirecting.to.presentation = 1;
01303 break;
01304 case 2:
01305 bc->redirecting.to.presentation = 2;
01306 break;
01307 }
01308 bc->redirecting.to.screening = 0;
01309 strcpy(bc->redirecting.to.number, number);
01310 }
01311 #endif
01312 }
01313
01314 static msg_t *build_facility (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01315 {
01316 int len;
01317 int HEADER_LEN;
01318 unsigned char *ie_fac;
01319 unsigned char fac_tmp[256];
01320 msg_t *msg;
01321 FACILITY_t *facility;
01322 Q931_info_t *qi;
01323
01324 #ifdef DEBUG
01325 printf("Building FACILITY Msg\n");
01326 #endif
01327
01328 len = encodeFac(fac_tmp, &(bc->fac_out));
01329 if (len <= 0) {
01330
01331
01332
01333
01334 bc->fac_out.Function = Fac_None;
01335
01336 #if defined(AST_MISDN_ENHANCEMENTS)
01337
01338 bc->notify_description_code = mISDN_NOTIFY_CODE_INVALID;
01339 bc->redirecting.to_changed = 0;
01340 #endif
01341 return NULL;
01342 }
01343
01344 msg = (msg_t *) create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, bc ? bc->l3_id : -1, sizeof(FACILITY_t), nt);
01345 HEADER_LEN = nt ? mISDNUSER_HEAD_SIZE : mISDN_HEADER_LEN;
01346 facility = (FACILITY_t *) (msg->data + HEADER_LEN);
01347
01348 ie_fac = msg_put(msg, len);
01349 if (bc->nt) {
01350 facility->FACILITY = ie_fac + 1;
01351 } else {
01352 qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
01353 qi->QI_ELEMENT(facility) = ie_fac - (unsigned char *)qi - sizeof(Q931_info_t);
01354 }
01355
01356 memcpy(ie_fac, fac_tmp, len);
01357
01358
01359 bc->fac_out.Function = Fac_None;
01360
01361 if (*bc->display) {
01362 #ifdef DEBUG
01363 printf("Sending %s as Display\n", bc->display);
01364 #endif
01365 enc_ie_display(&facility->DISPLAY, msg, bc->display, nt,bc);
01366 }
01367
01368 #if defined(AST_MISDN_ENHANCEMENTS)
01369 if (bc->notify_description_code != mISDN_NOTIFY_CODE_INVALID) {
01370 enc_ie_notify(&facility->NOTIFY, msg, bc->notify_description_code, nt, bc);
01371 bc->notify_description_code = mISDN_NOTIFY_CODE_INVALID;
01372 }
01373
01374 if (bc->redirecting.to_changed) {
01375 bc->redirecting.to_changed = 0;
01376 switch (bc->outgoing_colp) {
01377 case 0:
01378 case 1:
01379 enc_ie_redir_dn(&facility->REDIR_DN, msg, bc->redirecting.to.number_type,
01380 bc->redirecting.to.number_plan, bc->redirecting.to.presentation,
01381 bc->redirecting.to.number, nt, bc);
01382 break;
01383 default:
01384 break;
01385 }
01386 }
01387 #endif
01388
01389 return msg;
01390 }
01391
01392 #if defined(AST_MISDN_ENHANCEMENTS)
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404 static void parse_register(struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01405 {
01406 int HEADER_LEN;
01407 REGISTER_t *reg;
01408
01409 HEADER_LEN = nt ? mISDNUSER_HEAD_SIZE : mISDN_HEADER_LEN;
01410 reg = (REGISTER_t *) (msg->data + HEADER_LEN);
01411
01412
01413
01414
01415
01416
01417 dec_ie_facility(reg->FACILITY, (Q931_info_t *) reg, &bc->fac_in, nt, bc);
01418 }
01419 #endif
01420
01421 #if defined(AST_MISDN_ENHANCEMENTS)
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432 static msg_t *build_register(struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01433 {
01434 int HEADER_LEN;
01435 REGISTER_t *reg;
01436 msg_t *msg;
01437
01438 msg = (msg_t *) create_l3msg(CC_REGISTER | REQUEST, MT_REGISTER, bc ? bc->l3_id : -1, sizeof(REGISTER_t), nt);
01439 HEADER_LEN = nt ? mISDNUSER_HEAD_SIZE : mISDN_HEADER_LEN;
01440 reg = (REGISTER_t *) (msg->data + HEADER_LEN);
01441
01442 if (bc->fac_out.Function != Fac_None) {
01443 enc_ie_facility(®->FACILITY, msg, &bc->fac_out, nt);
01444 }
01445
01446 return msg;
01447 }
01448 #endif
01449
01450 static void parse_notify (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01451 {
01452 int HEADER_LEN = nt ? mISDNUSER_HEAD_SIZE : mISDN_HEADER_LEN;
01453 NOTIFY_t *notify = (NOTIFY_t *) (msg->data + HEADER_LEN);
01454 int description_code;
01455 int type;
01456 int plan;
01457 int present;
01458 char number[sizeof(bc->redirecting.to.number)];
01459
01460 #ifdef DEBUG
01461 printf("Parsing NOTIFY Msg\n");
01462 #endif
01463
01464 dec_ie_notify(notify->NOTIFY, (Q931_info_t *) notify, &description_code, nt, bc);
01465 if (description_code < 0) {
01466 bc->notify_description_code = mISDN_NOTIFY_CODE_INVALID;
01467 } else {
01468 bc->notify_description_code = description_code;
01469 }
01470
01471 dec_ie_redir_dn(notify->REDIR_DN, (Q931_info_t *) notify, &type, &plan, &present, number, sizeof(number), nt, bc);
01472 if (0 <= type) {
01473 bc->redirecting.to_changed = 1;
01474
01475 bc->redirecting.to.number_type = type;
01476 bc->redirecting.to.number_plan = plan;
01477 switch (present) {
01478 default:
01479 case 0:
01480 bc->redirecting.to.presentation = 0;
01481 break;
01482 case 1:
01483 bc->redirecting.to.presentation = 1;
01484 break;
01485 case 2:
01486 bc->redirecting.to.presentation = 2;
01487 break;
01488 }
01489 bc->redirecting.to.screening = 0;
01490 strcpy(bc->redirecting.to.number, number);
01491 }
01492 }
01493
01494 static msg_t *build_notify (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01495 {
01496 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01497 NOTIFY_t *notify;
01498 msg_t *msg =(msg_t*)create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, bc?bc->l3_id:-1, sizeof(NOTIFY_t) ,nt);
01499
01500 #ifdef DEBUG
01501 printf("Building NOTIFY Msg\n");
01502 #endif
01503
01504 notify = (NOTIFY_t *) (msg->data + HEADER_LEN);
01505
01506 enc_ie_notify(¬ify->NOTIFY, msg, bc->notify_description_code, nt, bc);
01507 bc->notify_description_code = mISDN_NOTIFY_CODE_INVALID;
01508
01509 if (bc->redirecting.to_changed) {
01510 bc->redirecting.to_changed = 0;
01511 switch (bc->outgoing_colp) {
01512 case 0:
01513 case 1:
01514 enc_ie_redir_dn(¬ify->REDIR_DN, msg, bc->redirecting.to.number_type,
01515 bc->redirecting.to.number_plan, bc->redirecting.to.presentation,
01516 bc->redirecting.to.number, nt, bc);
01517 break;
01518 default:
01519 break;
01520 }
01521 }
01522 return msg;
01523 }
01524
01525 static void parse_status_enquiry (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01526 {
01527 #ifdef DEBUG
01528 printf("Parsing STATUS_ENQUIRY Msg\n");
01529 #endif
01530 }
01531
01532 static msg_t *build_status_enquiry (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01533 {
01534 msg_t *msg =(msg_t*)create_l3msg(CC_STATUS_ENQUIRY | REQUEST, MT_STATUS_ENQUIRY, bc?bc->l3_id:-1, sizeof(STATUS_ENQUIRY_t) ,nt);
01535
01536 #ifdef DEBUG
01537 printf("Building STATUS_ENQUIRY Msg\n");
01538 #endif
01539 return msg;
01540 }
01541
01542 static void parse_information (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01543 {
01544 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01545 INFORMATION_t *information = (INFORMATION_t *) (msg->data + HEADER_LEN);
01546 int type, plan;
01547
01548 dec_ie_called_pn(information->CALLED_PN, (Q931_info_t *) information, &type, &plan, bc->info_dad, sizeof(bc->info_dad), nt, bc);
01549 dec_ie_keypad(information->KEYPAD, (Q931_info_t *) information, bc->keypad, sizeof(bc->keypad), nt, bc);
01550
01551 #ifdef DEBUG
01552 printf("Parsing INFORMATION Msg\n");
01553 #endif
01554 }
01555
01556 static msg_t *build_information (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01557 {
01558 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01559 INFORMATION_t *information;
01560 msg_t *msg =(msg_t*)create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, bc?bc->l3_id:-1, sizeof(INFORMATION_t) ,nt);
01561
01562 information=(INFORMATION_t*)((msg->data+HEADER_LEN));
01563
01564 enc_ie_called_pn(&information->CALLED_PN, msg, 0, 1, bc->info_dad, nt,bc);
01565
01566 {
01567 if (*bc->display) {
01568 #ifdef DEBUG
01569 printf("Sending %s as Display\n", bc->display);
01570 #endif
01571 enc_ie_display(&information->DISPLAY, msg, bc->display, nt,bc);
01572 }
01573 }
01574
01575 #ifdef DEBUG
01576 printf("Building INFORMATION Msg\n");
01577 #endif
01578 return msg;
01579 }
01580
01581 static void parse_status (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01582 {
01583 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01584 STATUS_t *status = (STATUS_t *) (msg->data + HEADER_LEN);
01585 int location;
01586 int cause;
01587
01588 dec_ie_cause(status->CAUSE, (Q931_info_t *)(status), &location, &cause, nt,bc);
01589 if (cause>0) bc->cause=cause;
01590
01591 #ifdef DEBUG
01592 printf("Parsing STATUS Msg\n");
01593 #endif
01594 }
01595
01596 static msg_t *build_status (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01597 {
01598 msg_t *msg =(msg_t*)create_l3msg(CC_STATUS | REQUEST, MT_STATUS, bc?bc->l3_id:-1, sizeof(STATUS_t) ,nt);
01599
01600 #ifdef DEBUG
01601 printf("Building STATUS Msg\n");
01602 #endif
01603 return msg;
01604 }
01605
01606 static void parse_timeout (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01607 {
01608 #ifdef DEBUG
01609 printf("Parsing STATUS Msg\n");
01610 #endif
01611 }
01612
01613 static msg_t *build_timeout (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01614 {
01615 msg_t *msg =(msg_t*)create_l3msg(CC_STATUS | REQUEST, MT_STATUS, bc?bc->l3_id:-1, sizeof(STATUS_t) ,nt);
01616
01617 #ifdef DEBUG
01618 printf("Building STATUS Msg\n");
01619 #endif
01620 return msg;
01621 }
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631 struct isdn_msg msgs_g[] = {
01632
01633
01634 { CC_PROCEEDING, EVENT_PROCEEDING, parse_proceeding, build_proceeding, "PROCEEDING" },
01635 { CC_ALERTING, EVENT_ALERTING, parse_alerting, build_alerting, "ALERTING" },
01636 { CC_PROGRESS, EVENT_PROGRESS, parse_progress, build_progress, "PROGRESS" },
01637 { CC_SETUP, EVENT_SETUP, parse_setup, build_setup, "SETUP" },
01638 #if defined(AST_MISDN_ENHANCEMENTS)
01639 { CC_REGISTER, EVENT_REGISTER, parse_register, build_register, "REGISTER" },
01640 #endif
01641 { CC_CONNECT, EVENT_CONNECT, parse_connect, build_connect, "CONNECT" },
01642 { CC_SETUP_ACKNOWLEDGE, EVENT_SETUP_ACKNOWLEDGE, parse_setup_acknowledge, build_setup_acknowledge, "SETUP_ACKNOWLEDGE" },
01643 { CC_CONNECT_ACKNOWLEDGE, EVENT_CONNECT_ACKNOWLEDGE, parse_connect_acknowledge, build_connect_acknowledge, "CONNECT_ACKNOWLEDGE " },
01644 { CC_USER_INFORMATION, EVENT_USER_INFORMATION, parse_user_information, build_user_information, "USER_INFORMATION" },
01645 { CC_SUSPEND_REJECT, EVENT_SUSPEND_REJECT, parse_suspend_reject, build_suspend_reject, "SUSPEND_REJECT" },
01646 { CC_RESUME_REJECT, EVENT_RESUME_REJECT, parse_resume_reject, build_resume_reject, "RESUME_REJECT" },
01647 { CC_HOLD, EVENT_HOLD, parse_hold, build_hold, "HOLD" },
01648 { CC_SUSPEND, EVENT_SUSPEND, parse_suspend, build_suspend, "SUSPEND" },
01649 { CC_RESUME, EVENT_RESUME, parse_resume, build_resume, "RESUME" },
01650 { CC_HOLD_ACKNOWLEDGE, EVENT_HOLD_ACKNOWLEDGE, parse_hold_acknowledge, build_hold_acknowledge, "HOLD_ACKNOWLEDGE" },
01651 { CC_SUSPEND_ACKNOWLEDGE, EVENT_SUSPEND_ACKNOWLEDGE, parse_suspend_acknowledge, build_suspend_acknowledge, "SUSPEND_ACKNOWLEDGE" },
01652 { CC_RESUME_ACKNOWLEDGE, EVENT_RESUME_ACKNOWLEDGE, parse_resume_acknowledge, build_resume_acknowledge, "RESUME_ACKNOWLEDGE" },
01653 { CC_HOLD_REJECT, EVENT_HOLD_REJECT, parse_hold_reject, build_hold_reject, "HOLD_REJECT" },
01654 { CC_RETRIEVE, EVENT_RETRIEVE, parse_retrieve, build_retrieve, "RETRIEVE" },
01655 { CC_RETRIEVE_ACKNOWLEDGE, EVENT_RETRIEVE_ACKNOWLEDGE, parse_retrieve_acknowledge, build_retrieve_acknowledge, "RETRIEVE_ACKNOWLEDGE" },
01656 { CC_RETRIEVE_REJECT, EVENT_RETRIEVE_REJECT, parse_retrieve_reject, build_retrieve_reject, "RETRIEVE_REJECT" },
01657 { CC_DISCONNECT, EVENT_DISCONNECT, parse_disconnect, build_disconnect, "DISCONNECT" },
01658 { CC_RESTART, EVENT_RESTART, parse_restart, build_restart, "RESTART" },
01659 { CC_RELEASE, EVENT_RELEASE, parse_release, build_release, "RELEASE" },
01660 { CC_RELEASE_COMPLETE, EVENT_RELEASE_COMPLETE, parse_release_complete, build_release_complete, "RELEASE_COMPLETE" },
01661 { CC_FACILITY, EVENT_FACILITY, parse_facility, build_facility, "FACILITY" },
01662 { CC_NOTIFY, EVENT_NOTIFY, parse_notify, build_notify, "NOTIFY" },
01663 { CC_STATUS_ENQUIRY, EVENT_STATUS_ENQUIRY, parse_status_enquiry, build_status_enquiry, "STATUS_ENQUIRY" },
01664 { CC_INFORMATION, EVENT_INFORMATION, parse_information, build_information, "INFORMATION" },
01665 { CC_STATUS, EVENT_STATUS, parse_status, build_status, "STATUS" },
01666 { CC_TIMEOUT, EVENT_TIMEOUT, parse_timeout, build_timeout, "TIMEOUT" },
01667 { 0, 0, NULL, NULL, NULL }
01668
01669 };
01670
01671 #define msgs_max (sizeof(msgs_g)/sizeof(struct isdn_msg))
01672
01673
01674 int isdn_msg_get_index(struct isdn_msg msgs[], msg_t *msg, int nt)
01675 {
01676 int i;
01677
01678 if (nt){
01679 mISDNuser_head_t *hh = (mISDNuser_head_t*)msg->data;
01680
01681 for (i=0; i< msgs_max -1; i++) {
01682 if ( (hh->prim&COMMAND_MASK)==(msgs[i].misdn_msg&COMMAND_MASK)) return i;
01683 }
01684
01685 } else {
01686 iframe_t *frm = (iframe_t*)msg->data;
01687
01688 for (i=0; i< msgs_max -1; i++)
01689 if ( (frm->prim&COMMAND_MASK)==(msgs[i].misdn_msg&COMMAND_MASK)) return i;
01690 }
01691
01692 return -1;
01693 }
01694
01695 int isdn_msg_get_index_by_event(struct isdn_msg msgs[], enum event_e event, int nt)
01696 {
01697 int i;
01698 for (i=0; i< msgs_max; i++)
01699 if ( event == msgs[i].event) return i;
01700
01701 cb_log(10,0, "get_index: event not found!\n");
01702
01703 return -1;
01704 }
01705
01706 enum event_e isdn_msg_get_event(struct isdn_msg msgs[], msg_t *msg, int nt)
01707 {
01708 int i=isdn_msg_get_index(msgs, msg, nt);
01709 if(i>=0) return msgs[i].event;
01710 return EVENT_UNKNOWN;
01711 }
01712
01713 char * isdn_msg_get_info(struct isdn_msg msgs[], msg_t *msg, int nt)
01714 {
01715 int i=isdn_msg_get_index(msgs, msg, nt);
01716 if(i>=0) return msgs[i].info;
01717 return NULL;
01718 }
01719
01720
01721 char EVENT_CLEAN_INFO[] = "CLEAN_UP";
01722 char EVENT_DTMF_TONE_INFO[] = "DTMF_TONE";
01723 char EVENT_NEW_L3ID_INFO[] = "NEW_L3ID";
01724 char EVENT_NEW_BC_INFO[] = "NEW_BC";
01725 char EVENT_PORT_ALARM_INFO[] = "ALARM";
01726 char EVENT_NEW_CHANNEL_INFO[] = "NEW_CHANNEL";
01727 char EVENT_BCHAN_DATA_INFO[] = "BCHAN_DATA";
01728 char EVENT_BCHAN_ACTIVATED_INFO[] = "BCHAN_ACTIVATED";
01729 char EVENT_TONE_GENERATE_INFO[] = "TONE_GENERATE";
01730 char EVENT_BCHAN_ERROR_INFO[] = "BCHAN_ERROR";
01731
01732 char * isdn_get_info(struct isdn_msg msgs[], enum event_e event, int nt)
01733 {
01734 int i=isdn_msg_get_index_by_event(msgs, event, nt);
01735
01736 if(i>=0) return msgs[i].info;
01737
01738 if (event == EVENT_CLEANUP) return EVENT_CLEAN_INFO;
01739 if (event == EVENT_DTMF_TONE) return EVENT_DTMF_TONE_INFO;
01740 if (event == EVENT_NEW_L3ID) return EVENT_NEW_L3ID_INFO;
01741 if (event == EVENT_NEW_BC) return EVENT_NEW_BC_INFO;
01742 if (event == EVENT_NEW_CHANNEL) return EVENT_NEW_CHANNEL_INFO;
01743 if (event == EVENT_BCHAN_DATA) return EVENT_BCHAN_DATA_INFO;
01744 if (event == EVENT_BCHAN_ACTIVATED) return EVENT_BCHAN_ACTIVATED_INFO;
01745 if (event == EVENT_TONE_GENERATE) return EVENT_TONE_GENERATE_INFO;
01746 if (event == EVENT_PORT_ALARM) return EVENT_PORT_ALARM_INFO;
01747 if (event == EVENT_BCHAN_ERROR) return EVENT_BCHAN_ERROR_INFO;
01748
01749 return NULL;
01750 }
01751
01752 int isdn_msg_parse_event(struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01753 {
01754 int i=isdn_msg_get_index(msgs, msg, nt);
01755 if(i<0) return -1;
01756
01757 msgs[i].msg_parser(msgs, msg, bc, nt);
01758 return 0;
01759 }
01760
01761 msg_t * isdn_msg_build_event(struct isdn_msg msgs[], struct misdn_bchannel *bc, enum event_e event, int nt)
01762 {
01763 int i=isdn_msg_get_index_by_event(msgs, event, nt);
01764 if(i<0) return NULL;
01765
01766 return msgs[i].msg_builder(msgs, bc, nt);
01767 }