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