00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "isdn_lib_intern.h"
00016
00017
00018 #include "isdn_lib.h"
00019
00020 #include "ie.c"
00021
00022
00023 static void set_channel(struct misdn_bchannel *bc, int channel)
00024 {
00025
00026 cb_log(3,bc->port,"set_channel: bc->channel:%d channel:%d\n", bc->channel, channel);
00027
00028
00029 if (channel==0xff) {
00030
00031 channel=-1;
00032 }
00033
00034
00035 if (channel > 0 && bc->nt ) {
00036
00037 if (bc->channel && ( bc->channel != 0xff) ) {
00038 cb_log(0,bc->port,"We already have a channel (%d)\n", bc->channel);
00039 } else {
00040 bc->channel = channel;
00041 cb_event(EVENT_NEW_CHANNEL,bc,NULL);
00042 }
00043 }
00044
00045 if (channel > 0 && !bc->nt ) {
00046 bc->channel = channel;
00047 cb_event(EVENT_NEW_CHANNEL,bc,NULL);
00048 }
00049 }
00050
00051 static void parse_proceeding (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00052 {
00053 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00054 CALL_PROCEEDING_t *proceeding=(CALL_PROCEEDING_t*)((unsigned long)msg->data+ HEADER_LEN);
00055
00056
00057 {
00058 int exclusive, channel;
00059 dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)proceeding, &exclusive, &channel, nt,bc);
00060
00061 set_channel(bc,channel);
00062
00063 }
00064
00065 dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)proceeding, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
00066
00067
00068 #if DEBUG
00069 printf("Parsing PROCEEDING Msg\n");
00070 #endif
00071 }
00072 static msg_t *build_proceeding (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00073 {
00074 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00075 CALL_PROCEEDING_t *proceeding;
00076 msg_t *msg =(msg_t*)create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, bc?bc->l3_id:-1, sizeof(CALL_PROCEEDING_t) ,nt);
00077
00078 proceeding=(CALL_PROCEEDING_t*)((msg->data+HEADER_LEN));
00079
00080 enc_ie_channel_id(&proceeding->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
00081
00082 if (nt)
00083 enc_ie_progress(&proceeding->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);
00084
00085
00086 #if DEBUG
00087 printf("Building PROCEEDING Msg\n");
00088 #endif
00089 return msg;
00090 }
00091
00092 static void parse_alerting (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00093 {
00094 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00095 ALERTING_t *alerting=(ALERTING_t*)((unsigned long)(msg->data+HEADER_LEN));
00096
00097
00098 dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)alerting, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
00099
00100 #if DEBUG
00101 printf("Parsing ALERTING Msg\n");
00102 #endif
00103
00104
00105 }
00106
00107 static msg_t *build_alerting (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00108 {
00109 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00110 ALERTING_t *alerting;
00111 msg_t *msg =(msg_t*)create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, bc?bc->l3_id:-1, sizeof(ALERTING_t) ,nt);
00112
00113 alerting=(ALERTING_t*)((msg->data+HEADER_LEN));
00114
00115 enc_ie_channel_id(&alerting->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
00116
00117 if (nt)
00118 enc_ie_progress(&alerting->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);
00119 #if DEBUG
00120 printf("Building ALERTING Msg\n");
00121 #endif
00122 return msg;
00123 }
00124
00125
00126 static void parse_progress (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00127 {
00128 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00129 PROGRESS_t *progress=(PROGRESS_t*)((unsigned long)(msg->data+HEADER_LEN));
00130
00131
00132 dec_ie_progress(progress->PROGRESS, (Q931_info_t *)progress, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
00133
00134 #if DEBUG
00135 printf("Parsing PROGRESS Msg\n");
00136 #endif
00137 }
00138
00139 static msg_t *build_progress (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00140 {
00141 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00142 PROGRESS_t *progress;
00143 msg_t *msg =(msg_t*)create_l3msg(CC_PROGRESS | REQUEST, MT_PROGRESS, bc?bc->l3_id:-1, sizeof(PROGRESS_t) ,nt);
00144
00145 progress=(PROGRESS_t*)((msg->data+HEADER_LEN));
00146
00147 #if DEBUG
00148 printf("Building PROGRESS Msg\n");
00149 #endif
00150 return msg;
00151 }
00152
00153 static void parse_setup (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00154 {
00155 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00156 SETUP_t *setup= (SETUP_t*)((unsigned long)msg->data+HEADER_LEN);
00157 Q931_info_t *qi=(Q931_info_t*)((unsigned long)msg->data+HEADER_LEN);
00158
00159 #if DEBUG
00160 printf("Parsing SETUP Msg\n");
00161 #endif
00162 {
00163 int type,plan,present, screen;
00164 char id[32];
00165 dec_ie_calling_pn(setup->CALLING_PN, qi, &type, &plan, &present, &screen, id, sizeof(id)-1, nt,bc);
00166
00167 bc->onumplan=type;
00168 strcpy(bc->oad, id);
00169 switch (present) {
00170 case 0:
00171 bc->pres=0;
00172 break;
00173 case 1:
00174 bc->pres=1;
00175 break;
00176 default:
00177 bc->pres=0;
00178 }
00179 switch (screen) {
00180 case 0:
00181 break;
00182 default:
00183 ;
00184 }
00185 }
00186 {
00187 int type, plan;
00188 char number[32];
00189 dec_ie_called_pn(setup->CALLED_PN, (Q931_info_t *)setup, &type, &plan, number, sizeof(number)-1, nt,bc);
00190 strcpy(bc->dad, number);
00191 bc->dnumplan=type;
00192 }
00193 {
00194 char keypad[32];
00195 dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)setup, keypad, sizeof(keypad)-1, nt,bc);
00196 strcpy(bc->keypad, keypad);
00197 }
00198
00199 {
00200 dec_ie_complete(setup->COMPLETE, (Q931_info_t *)setup, &bc->sending_complete, nt,bc);
00201
00202 }
00203
00204 {
00205 int type, plan, present, screen, reason;
00206 char id[32];
00207 dec_ie_redir_nr(setup->REDIR_NR, (Q931_info_t *)setup, &type, &plan, &present, &screen, &reason, id, sizeof(id)-1, nt,bc);
00208
00209 strcpy(bc->rad, id);
00210 bc->rnumplan=type;
00211 }
00212 {
00213 int coding, capability, mode, rate, multi, user, async, urate, stopbits, dbits, parity;
00214 dec_ie_bearer(setup->BEARER, (Q931_info_t *)setup, &coding, &capability, &mode, &rate, &multi, &user, &async, &urate, &stopbits, &dbits, &parity, nt,bc);
00215 switch (capability) {
00216 case -1: bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED;
00217 break;
00218 case 0: bc->capability=INFO_CAPABILITY_SPEECH;
00219 break;
00220 case 18: bc->capability=INFO_CAPABILITY_VIDEO;
00221 break;
00222 case 8: bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED;
00223 bc->user1 = user;
00224 bc->urate = urate;
00225
00226 bc->rate = rate;
00227 bc->mode = mode;
00228 break;
00229 case 9: bc->capability=INFO_CAPABILITY_DIGITAL_RESTRICTED;
00230 break;
00231 default:
00232 break;
00233 }
00234
00235 switch(user) {
00236 case 2:
00237 bc->law=INFO_CODEC_ULAW;
00238 break;
00239 case 3:
00240 bc->law=INFO_CODEC_ALAW;
00241 break;
00242 default:
00243 bc->law=INFO_CODEC_ALAW;
00244
00245 }
00246
00247 bc->capability=capability;
00248 }
00249 {
00250 int exclusive, channel;
00251 dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)setup, &exclusive, &channel, nt,bc);
00252
00253 set_channel(bc,channel);
00254 }
00255
00256 {
00257 int protocol ;
00258 dec_ie_useruser(setup->USER_USER, (Q931_info_t *)setup, &protocol, bc->uu, &bc->uulen, nt,bc);
00259 if (bc->uulen) cb_log(1,bc->port,"USERUESRINFO:%s\n",bc->uu);
00260 else
00261 cb_log(1,bc->port,"NO USERUESRINFO\n");
00262 }
00263
00264 dec_ie_progress(setup->PROGRESS, (Q931_info_t *)setup, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
00265
00266 }
00267
00268 #define ANY_CHANNEL 0xff
00269 static msg_t *build_setup (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00270 {
00271 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00272 SETUP_t *setup;
00273 msg_t *msg =(msg_t*)create_l3msg(CC_SETUP | REQUEST, MT_SETUP, bc?bc->l3_id:-1, sizeof(SETUP_t) ,nt);
00274
00275 setup=(SETUP_t*)((msg->data+HEADER_LEN));
00276
00277 if (bc->channel == 0 || bc->channel == ANY_CHANNEL || bc->channel==-1)
00278 enc_ie_channel_id(&setup->CHANNEL_ID, msg, 0, bc->channel, nt,bc);
00279 else
00280 enc_ie_channel_id(&setup->CHANNEL_ID, msg, 1, bc->channel, nt,bc);
00281
00282
00283 {
00284 int type=bc->onumplan,plan=1,present=bc->pres,screen=bc->screen;
00285 enc_ie_calling_pn(&setup->CALLING_PN, msg, type, plan, present,
00286 screen, bc->oad, nt, bc);
00287 }
00288
00289 {
00290 if (bc->dad[0])
00291 enc_ie_called_pn(&setup->CALLED_PN, msg, bc->dnumplan, 1, bc->dad, nt,bc);
00292 }
00293
00294 {
00295 if (bc->rad[0])
00296 enc_ie_redir_nr(&setup->REDIR_NR, msg, 1, 1, bc->pres, bc->screen, 0, bc->rad, nt,bc);
00297 }
00298
00299 {
00300 if (bc->keypad[0])
00301 enc_ie_keypad(&setup->KEYPAD, msg, bc->keypad, nt,bc);
00302 }
00303
00304
00305 if (*bc->display) {
00306 enc_ie_display(&setup->DISPLAY, msg, bc->display, nt,bc);
00307 }
00308
00309 {
00310 int coding=0, capability, mode=0
00311 ,user, rate=0x10;
00312
00313 switch (bc->law) {
00314 case INFO_CODEC_ULAW: user=2;
00315 break;
00316 case INFO_CODEC_ALAW: user=3;
00317 break;
00318 default:
00319 user=3;
00320 }
00321
00322 switch (bc->capability) {
00323 case INFO_CAPABILITY_SPEECH: capability = 0;
00324 break;
00325 case INFO_CAPABILITY_DIGITAL_UNRESTRICTED: capability = 8;
00326 user=-1;
00327 mode=bc->mode;
00328 rate=bc->rate;
00329 break;
00330 case INFO_CAPABILITY_DIGITAL_RESTRICTED: capability = 9;
00331 user=-1;
00332 break;
00333 default:
00334 capability=bc->capability;
00335 }
00336
00337
00338
00339 enc_ie_bearer(&setup->BEARER, msg, coding, capability, mode, rate, -1, user, nt,bc);
00340 }
00341
00342 if (bc->sending_complete) {
00343 enc_ie_complete(&setup->BEARER,msg, bc->sending_complete, nt, bc);
00344 }
00345
00346 {
00347 int protocol=4;
00348 enc_ie_useruser(&setup->USER_USER, msg, protocol, bc->uu, bc->uulen, nt,bc);
00349 if (bc->uulen) cb_log(1,bc->port,"ENCODING USERUESRINFO:%s\n",bc->uu);
00350 else
00351 cb_log(1,bc->port,"NO USERUESRINFO ENCODED\n");
00352 }
00353
00354 #if DEBUG
00355 printf("Building SETUP Msg\n");
00356 #endif
00357 return msg;
00358 }
00359
00360 static void parse_connect (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00361 {
00362 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00363 CONNECT_t *connect=(CONNECT_t*)((unsigned long)(msg->data+HEADER_LEN));
00364
00365 int plan,pres,screen;
00366
00367 bc->ces = connect->ces;
00368 bc->ces = connect->ces;
00369
00370 dec_ie_progress(connect->PROGRESS, (Q931_info_t *)connect, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
00371
00372 dec_ie_connected_pn(connect->CONNECT_PN,(Q931_info_t *)connect, &bc->cpnnumplan, &plan, &pres, &screen, bc->cad, 31, nt, bc);
00373
00374
00375
00376
00377
00378 #if DEBUG
00379 printf("Parsing CONNECT Msg\n");
00380 #endif
00381 }
00382
00383 static msg_t *build_connect (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00384 {
00385 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00386 CONNECT_t *connect;
00387 msg_t *msg =(msg_t*)create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, bc?bc->l3_id:-1, sizeof(CONNECT_t) ,nt);
00388
00389 cb_log(6,bc->port,"BUILD_CONNECT: bc:%p bc->l3id:%d, nt:%d\n",bc,bc->l3_id,nt);
00390
00391 connect=(CONNECT_t*)((msg->data+HEADER_LEN));
00392
00393 if (nt) {
00394 time_t now;
00395 time(&now);
00396 enc_ie_date(&connect->DATE, msg, now, nt,bc);
00397 }
00398
00399 {
00400 int type=bc->cpnnumplan, plan=1, present=2, screen=0;
00401 enc_ie_connected_pn(&connect->CONNECT_PN, msg, type,plan, present, screen, bc->cad, nt , bc);
00402 }
00403
00404 #if DEBUG
00405 printf("Building CONNECT Msg\n");
00406 #endif
00407 return msg;
00408 }
00409
00410 static void parse_setup_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00411 {
00412 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00413 SETUP_ACKNOWLEDGE_t *setup_acknowledge=(SETUP_ACKNOWLEDGE_t*)((unsigned long)(msg->data+HEADER_LEN));
00414
00415 {
00416 int exclusive, channel;
00417 dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)setup_acknowledge, &exclusive, &channel, nt,bc);
00418
00419
00420 set_channel(bc, channel);
00421 }
00422
00423 dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)setup_acknowledge, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
00424 #if DEBUG
00425 printf("Parsing SETUP_ACKNOWLEDGE Msg\n");
00426 #endif
00427
00428
00429 }
00430
00431 static msg_t *build_setup_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00432 {
00433 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00434 SETUP_ACKNOWLEDGE_t *setup_acknowledge;
00435 msg_t *msg =(msg_t*)create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(SETUP_ACKNOWLEDGE_t) ,nt);
00436
00437 setup_acknowledge=(SETUP_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
00438
00439 enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
00440
00441 if (nt)
00442 enc_ie_progress(&setup_acknowledge->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);
00443
00444 #if DEBUG
00445 printf("Building SETUP_ACKNOWLEDGE Msg\n");
00446 #endif
00447 return msg;
00448 }
00449
00450 static void parse_connect_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00451 {
00452 #if DEBUG
00453 printf("Parsing CONNECT_ACKNOWLEDGE Msg\n");
00454 #endif
00455
00456
00457 }
00458
00459 static msg_t *build_connect_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00460 {
00461 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00462 CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
00463 msg_t *msg =(msg_t*)create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, bc?bc->l3_id:-1, sizeof(CONNECT_ACKNOWLEDGE_t) ,nt);
00464
00465 connect_acknowledge=(CONNECT_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
00466
00467 enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, msg, 1, bc->channel, nt,bc);
00468
00469 #if DEBUG
00470 printf("Building CONNECT_ACKNOWLEDGE Msg\n");
00471 #endif
00472 return msg;
00473 }
00474
00475 static void parse_user_information (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00476 {
00477 #if DEBUG
00478 printf("Parsing USER_INFORMATION Msg\n");
00479 #endif
00480
00481
00482 }
00483
00484 static msg_t *build_user_information (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00485 {
00486 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00487 USER_INFORMATION_t *user_information;
00488 msg_t *msg =(msg_t*)create_l3msg(CC_USER_INFORMATION | REQUEST, MT_USER_INFORMATION, bc?bc->l3_id:-1, sizeof(USER_INFORMATION_t) ,nt);
00489
00490 user_information=(USER_INFORMATION_t*)((msg->data+HEADER_LEN));
00491
00492 #if DEBUG
00493 printf("Building USER_INFORMATION Msg\n");
00494 #endif
00495 return msg;
00496 }
00497
00498 static void parse_suspend_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00499 {
00500 #if DEBUG
00501 printf("Parsing SUSPEND_REJECT Msg\n");
00502 #endif
00503
00504
00505 }
00506
00507 static msg_t *build_suspend_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00508 {
00509 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00510 SUSPEND_REJECT_t *suspend_reject;
00511 msg_t *msg =(msg_t*)create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, bc?bc->l3_id:-1, sizeof(SUSPEND_REJECT_t) ,nt);
00512
00513 suspend_reject=(SUSPEND_REJECT_t*)((msg->data+HEADER_LEN));
00514
00515 #if DEBUG
00516 printf("Building SUSPEND_REJECT Msg\n");
00517 #endif
00518 return msg;
00519 }
00520
00521 static void parse_resume_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00522 {
00523 #if DEBUG
00524 printf("Parsing RESUME_REJECT Msg\n");
00525 #endif
00526
00527
00528 }
00529
00530 static msg_t *build_resume_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00531 {
00532 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00533 RESUME_REJECT_t *resume_reject;
00534 msg_t *msg =(msg_t*)create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, bc?bc->l3_id:-1, sizeof(RESUME_REJECT_t) ,nt);
00535
00536 resume_reject=(RESUME_REJECT_t*)((msg->data+HEADER_LEN));
00537
00538 #if DEBUG
00539 printf("Building RESUME_REJECT Msg\n");
00540 #endif
00541 return msg;
00542 }
00543
00544 static void parse_hold (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00545 {
00546 #if DEBUG
00547 printf("Parsing HOLD Msg\n");
00548 #endif
00549
00550
00551 }
00552
00553 static msg_t *build_hold (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00554 {
00555 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00556 HOLD_t *hold;
00557 msg_t *msg =(msg_t*)create_l3msg(CC_HOLD | REQUEST, MT_HOLD, bc?bc->l3_id:-1, sizeof(HOLD_t) ,nt);
00558
00559 hold=(HOLD_t*)((msg->data+HEADER_LEN));
00560
00561 #if DEBUG
00562 printf("Building HOLD Msg\n");
00563 #endif
00564 return msg;
00565 }
00566
00567 static void parse_suspend (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00568 {
00569 #if DEBUG
00570 printf("Parsing SUSPEND Msg\n");
00571 #endif
00572
00573
00574 }
00575
00576 static msg_t *build_suspend (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00577 {
00578 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00579 SUSPEND_t *suspend;
00580 msg_t *msg =(msg_t*)create_l3msg(CC_SUSPEND | REQUEST, MT_SUSPEND, bc?bc->l3_id:-1, sizeof(SUSPEND_t) ,nt);
00581
00582 suspend=(SUSPEND_t*)((msg->data+HEADER_LEN));
00583
00584 #if DEBUG
00585 printf("Building SUSPEND Msg\n");
00586 #endif
00587 return msg;
00588 }
00589
00590 static void parse_resume (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00591 {
00592 #if DEBUG
00593 printf("Parsing RESUME Msg\n");
00594 #endif
00595
00596
00597 }
00598
00599 static msg_t *build_resume (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00600 {
00601 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00602 RESUME_t *resume;
00603 msg_t *msg =(msg_t*)create_l3msg(CC_RESUME | REQUEST, MT_RESUME, bc?bc->l3_id:-1, sizeof(RESUME_t) ,nt);
00604
00605 resume=(RESUME_t*)((msg->data+HEADER_LEN));
00606
00607 #if DEBUG
00608 printf("Building RESUME Msg\n");
00609 #endif
00610 return msg;
00611 }
00612
00613 static void parse_hold_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00614 {
00615 #if DEBUG
00616 printf("Parsing HOLD_ACKNOWLEDGE Msg\n");
00617 #endif
00618
00619
00620 }
00621
00622 static msg_t *build_hold_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00623 {
00624 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00625 HOLD_ACKNOWLEDGE_t *hold_acknowledge;
00626 msg_t *msg =(msg_t*)create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(HOLD_ACKNOWLEDGE_t) ,nt);
00627
00628 hold_acknowledge=(HOLD_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
00629
00630 #if DEBUG
00631 printf("Building HOLD_ACKNOWLEDGE Msg\n");
00632 #endif
00633 return msg;
00634 }
00635
00636 static void parse_suspend_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00637 {
00638 #if DEBUG
00639 printf("Parsing SUSPEND_ACKNOWLEDGE Msg\n");
00640 #endif
00641
00642
00643 }
00644
00645 static msg_t *build_suspend_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00646 {
00647 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00648 SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
00649 msg_t *msg =(msg_t*)create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(SUSPEND_ACKNOWLEDGE_t) ,nt);
00650
00651 suspend_acknowledge=(SUSPEND_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
00652
00653 #if DEBUG
00654 printf("Building SUSPEND_ACKNOWLEDGE Msg\n");
00655 #endif
00656 return msg;
00657 }
00658
00659 static void parse_resume_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00660 {
00661 #if DEBUG
00662 printf("Parsing RESUME_ACKNOWLEDGE Msg\n");
00663 #endif
00664
00665
00666 }
00667
00668 static msg_t *build_resume_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00669 {
00670 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00671 RESUME_ACKNOWLEDGE_t *resume_acknowledge;
00672 msg_t *msg =(msg_t*)create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(RESUME_ACKNOWLEDGE_t) ,nt);
00673
00674 resume_acknowledge=(RESUME_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
00675
00676 #if DEBUG
00677 printf("Building RESUME_ACKNOWLEDGE Msg\n");
00678 #endif
00679 return msg;
00680 }
00681
00682 static void parse_hold_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00683 {
00684 #if DEBUG
00685 printf("Parsing HOLD_REJECT Msg\n");
00686 #endif
00687
00688
00689 }
00690
00691 static msg_t *build_hold_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00692 {
00693 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00694 HOLD_REJECT_t *hold_reject;
00695 msg_t *msg =(msg_t*)create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, bc?bc->l3_id:-1, sizeof(HOLD_REJECT_t) ,nt);
00696
00697 hold_reject=(HOLD_REJECT_t*)((msg->data+HEADER_LEN));
00698
00699 #if DEBUG
00700 printf("Building HOLD_REJECT Msg\n");
00701 #endif
00702 return msg;
00703 }
00704
00705 static void parse_retrieve (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00706 {
00707 #if DEBUG
00708 printf("Parsing RETRIEVE Msg\n");
00709 #endif
00710
00711
00712 }
00713
00714 static msg_t *build_retrieve (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00715 {
00716 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00717 RETRIEVE_t *retrieve;
00718 msg_t *msg =(msg_t*)create_l3msg(CC_RETRIEVE | REQUEST, MT_RETRIEVE, bc?bc->l3_id:-1, sizeof(RETRIEVE_t) ,nt);
00719
00720 retrieve=(RETRIEVE_t*)((msg->data+HEADER_LEN));
00721
00722 #if DEBUG
00723 printf("Building RETRIEVE Msg\n");
00724 #endif
00725 return msg;
00726 }
00727
00728 static void parse_retrieve_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00729 {
00730 #if DEBUG
00731 printf("Parsing RETRIEVE_ACKNOWLEDGE Msg\n");
00732 #endif
00733
00734
00735 }
00736
00737 static msg_t *build_retrieve_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00738 {
00739 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00740 RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
00741 msg_t *msg =(msg_t*)create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(RETRIEVE_ACKNOWLEDGE_t) ,nt);
00742
00743 retrieve_acknowledge=(RETRIEVE_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
00744
00745 enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, msg, 1, bc->channel, nt,bc);
00746 #if DEBUG
00747 printf("Building RETRIEVE_ACKNOWLEDGE Msg\n");
00748 #endif
00749 return msg;
00750 }
00751
00752 static void parse_retrieve_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00753 {
00754 #if DEBUG
00755 printf("Parsing RETRIEVE_REJECT Msg\n");
00756 #endif
00757
00758
00759 }
00760
00761 static msg_t *build_retrieve_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00762 {
00763 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00764 RETRIEVE_REJECT_t *retrieve_reject;
00765 msg_t *msg =(msg_t*)create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, bc?bc->l3_id:-1, sizeof(RETRIEVE_REJECT_t) ,nt);
00766
00767 retrieve_reject=(RETRIEVE_REJECT_t*)((msg->data+HEADER_LEN));
00768
00769 #if DEBUG
00770 printf("Building RETRIEVE_REJECT Msg\n");
00771 #endif
00772 return msg;
00773 }
00774
00775 static void parse_disconnect (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00776 {
00777 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00778 DISCONNECT_t *disconnect=(DISCONNECT_t*)((unsigned long)(msg->data+HEADER_LEN));
00779 int location;
00780 int cause;
00781 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)(disconnect), &location, &cause, nt,bc);
00782 if (cause>0) bc->cause=cause;
00783
00784 dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)disconnect, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
00785 #if DEBUG
00786 printf("Parsing DISCONNECT Msg\n");
00787 #endif
00788
00789
00790 }
00791
00792 static msg_t *build_disconnect (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00793 {
00794 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00795 DISCONNECT_t *disconnect;
00796 msg_t *msg =(msg_t*)create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, bc?bc->l3_id:-1, sizeof(DISCONNECT_t) ,nt);
00797
00798 disconnect=(DISCONNECT_t*)((msg->data+HEADER_LEN));
00799
00800 enc_ie_cause(&disconnect->CAUSE, msg, (nt)?1:0, bc->out_cause,nt,bc);
00801 if (nt) enc_ie_progress(&disconnect->PROGRESS, msg, 0, nt?1:5, 8 ,nt,bc);
00802
00803 #if DEBUG
00804 printf("Building DISCONNECT Msg\n");
00805 #endif
00806 return msg;
00807 }
00808
00809 static void parse_restart (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00810 {
00811 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00812 RESTART_t *restart=(RESTART_t*)((unsigned long)(msg->data+HEADER_LEN));
00813
00814 struct misdn_stack *stack=get_stack_by_bc(bc);
00815
00816 #if DEBUG
00817 printf("Parsing RESTART Msg\n");
00818 #endif
00819
00820 {
00821 int exclusive, channel = 0;
00822 dec_ie_channel_id(restart->CHANNEL_ID, (Q931_info_t *)restart, &exclusive, &bc->restart_channel, nt,bc);
00823
00824 if (channel==0xff)
00825 channel=-1;
00826 cb_log(3, stack->port, "CC_RESTART Request on channel:%d on this port.\n");
00827 }
00828
00829
00830 }
00831
00832 static msg_t *build_restart (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00833 {
00834 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00835 RESTART_t *restart;
00836 msg_t *msg =(msg_t*)create_l3msg(CC_RESTART | REQUEST, MT_RESTART, bc?bc->l3_id:-1, sizeof(RESTART_t) ,nt);
00837
00838 restart=(RESTART_t*)((msg->data+HEADER_LEN));
00839
00840 #if DEBUG
00841 printf("Building RESTART Msg\n");
00842 #endif
00843 enc_ie_channel_id(&restart->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
00844
00845 cb_log(0,bc->port, "Restarting channel %d\n", bc->channel);
00846
00847 return msg;
00848 }
00849
00850 static void parse_release (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00851 {
00852 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00853 RELEASE_t *release=(RELEASE_t*)((unsigned long)(msg->data+HEADER_LEN));
00854 int location;
00855 int cause;
00856
00857 dec_ie_cause(release->CAUSE, (Q931_info_t *)(release), &location, &cause, nt,bc);
00858 if (cause>0) bc->cause=cause;
00859 #if DEBUG
00860 printf("Parsing RELEASE Msg\n");
00861 #endif
00862
00863
00864 }
00865
00866 static msg_t *build_release (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00867 {
00868 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00869 RELEASE_t *release;
00870 msg_t *msg =(msg_t*)create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, bc?bc->l3_id:-1, sizeof(RELEASE_t) ,nt);
00871
00872 release=(RELEASE_t*)((msg->data+HEADER_LEN));
00873
00874 if (bc->out_cause>= 0)
00875 enc_ie_cause(&release->CAUSE, msg, nt?1:0, bc->out_cause, nt,bc);
00876
00877 #if DEBUG
00878 printf("Building RELEASE Msg\n");
00879 #endif
00880 return msg;
00881 }
00882
00883 static void parse_release_complete (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00884 {
00885 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00886 RELEASE_COMPLETE_t *release_complete=(RELEASE_COMPLETE_t*)((unsigned long)(msg->data+HEADER_LEN));
00887 int location;
00888 int cause;
00889 iframe_t *frm = (iframe_t*) msg->data;
00890
00891 struct misdn_stack *stack=get_stack_by_bc(bc);
00892 mISDNuser_head_t *hh;
00893 hh=(mISDNuser_head_t*)msg->data;
00894
00895
00896
00897
00898 if (nt) {
00899 if (hh->prim == (CC_RELEASE_COMPLETE|CONFIRM)) {
00900 cb_log(0, stack->port, "CC_RELEASE_COMPLETE|CONFIRM [NT] \n");
00901 return;
00902 }
00903 } else {
00904 if (frm->prim == (CC_RELEASE_COMPLETE|CONFIRM)) {
00905 cb_log(0, stack->port, "CC_RELEASE_COMPLETE|CONFIRM [TE] \n");
00906 return;
00907 }
00908 }
00909 dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)(release_complete), &location, &cause, nt,bc);
00910 if (cause>0) bc->cause=cause;
00911
00912 #if DEBUG
00913 printf("Parsing RELEASE_COMPLETE Msg\n");
00914 #endif
00915 }
00916
00917 static msg_t *build_release_complete (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00918 {
00919 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
00920 RELEASE_COMPLETE_t *release_complete;
00921 msg_t *msg =(msg_t*)create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, bc?bc->l3_id:-1, sizeof(RELEASE_COMPLETE_t) ,nt);
00922
00923 release_complete=(RELEASE_COMPLETE_t*)((msg->data+HEADER_LEN));
00924
00925 enc_ie_cause(&release_complete->CAUSE, msg, nt?1:0, bc->out_cause, nt,bc);
00926
00927 #if DEBUG
00928 printf("Building RELEASE_COMPLETE Msg\n");
00929 #endif
00930 return msg;
00931 }
00932
00933 static void parse_facility (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00934 {
00935 int HEADER_LEN = nt ? mISDNUSER_HEAD_SIZE : mISDN_HEADER_LEN;
00936 FACILITY_t *facility = (FACILITY_t*)(msg->data+HEADER_LEN);
00937 Q931_info_t *qi = (Q931_info_t*)(msg->data+HEADER_LEN);
00938 unsigned char *p = NULL;
00939 int err;
00940
00941 #if DEBUG
00942 printf("Parsing FACILITY Msg\n");
00943 #endif
00944
00945 if (!bc->nt) {
00946 if (qi->QI_ELEMENT(facility))
00947 p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(facility) + 1;
00948 } else {
00949 p = facility->FACILITY;
00950 }
00951 if (!p)
00952 return;
00953
00954 err = decodeFac(p, &(bc->fac_in));
00955 if (err) {
00956 cb_log(1, bc->port, "Decoding FACILITY failed! (%d)\n", err);
00957 }
00958 }
00959
00960 static msg_t *build_facility (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
00961 {
00962 int len,
00963 HEADER_LEN = nt ? mISDNUSER_HEAD_SIZE : mISDN_HEADER_LEN;
00964 unsigned char *ie_fac,
00965 fac_tmp[256];
00966 msg_t *msg =(msg_t*)create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, bc?bc->l3_id:-1, sizeof(FACILITY_t) ,nt);
00967 FACILITY_t *facility = (FACILITY_t*)(msg->data+HEADER_LEN);
00968 Q931_info_t *qi;
00969
00970 #if DEBUG
00971 printf("Building FACILITY Msg\n");
00972 #endif
00973
00974 len = encodeFac(fac_tmp, &(bc->fac_out));
00975 if (len <= 0)
00976 return NULL;
00977
00978 ie_fac = msg_put(msg, len);
00979 if (bc->nt) {
00980 facility->FACILITY = ie_fac + 1;
00981 } else {
00982 qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
00983 qi->QI_ELEMENT(facility) = ie_fac - (unsigned char *)qi - sizeof(Q931_info_t);
00984 }
00985
00986 memcpy(ie_fac, fac_tmp, len);
00987
00988 if (*bc->display) {
00989 printf("Sending %s as Display\n", bc->display);
00990 enc_ie_display(&facility->DISPLAY, msg, bc->display, nt,bc);
00991 }
00992
00993 return msg;
00994 }
00995
00996 static void parse_notify (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
00997 {
00998 #if DEBUG
00999 printf("Parsing NOTIFY Msg\n");
01000 #endif
01001 }
01002
01003 static msg_t *build_notify (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01004 {
01005 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01006 NOTIFY_t *notify;
01007 msg_t *msg =(msg_t*)create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, bc?bc->l3_id:-1, sizeof(NOTIFY_t) ,nt);
01008
01009 notify=(NOTIFY_t*)((msg->data+HEADER_LEN));
01010
01011 #if DEBUG
01012 printf("Building NOTIFY Msg\n");
01013 #endif
01014 return msg;
01015 }
01016
01017 static void parse_status_enquiry (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01018 {
01019 #if DEBUG
01020 printf("Parsing STATUS_ENQUIRY Msg\n");
01021 #endif
01022 }
01023
01024 static msg_t *build_status_enquiry (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01025 {
01026 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01027 STATUS_ENQUIRY_t *status_enquiry;
01028 msg_t *msg =(msg_t*)create_l3msg(CC_STATUS_ENQUIRY | REQUEST, MT_STATUS_ENQUIRY, bc?bc->l3_id:-1, sizeof(STATUS_ENQUIRY_t) ,nt);
01029
01030 status_enquiry=(STATUS_ENQUIRY_t*)((msg->data+HEADER_LEN));
01031
01032 #if DEBUG
01033 printf("Building STATUS_ENQUIRY Msg\n");
01034 #endif
01035 return msg;
01036 }
01037
01038 static void parse_information (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01039 {
01040 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01041 INFORMATION_t *information=(INFORMATION_t*)((unsigned long)(msg->data+HEADER_LEN));
01042 {
01043 int type, plan;
01044 char number[32];
01045 char keypad[32];
01046 dec_ie_called_pn(information->CALLED_PN, (Q931_info_t *)information, &type, &plan, number, sizeof(number)-1, nt, bc);
01047 dec_ie_keypad(information->KEYPAD, (Q931_info_t *)information, keypad, sizeof(keypad)-1, nt, bc);
01048 strcpy(bc->info_dad, number);
01049 strcpy(bc->keypad,keypad);
01050 }
01051 #if DEBUG
01052 printf("Parsing INFORMATION Msg\n");
01053 #endif
01054 }
01055
01056 static msg_t *build_information (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01057 {
01058 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01059 INFORMATION_t *information;
01060 msg_t *msg =(msg_t*)create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, bc?bc->l3_id:-1, sizeof(INFORMATION_t) ,nt);
01061
01062 information=(INFORMATION_t*)((msg->data+HEADER_LEN));
01063
01064 {
01065 enc_ie_called_pn(&information->CALLED_PN, msg, 0, 1, bc->info_dad, nt,bc);
01066 }
01067
01068 {
01069 if (*bc->display) {
01070 printf("Sending %s as Display\n", bc->display);
01071 enc_ie_display(&information->DISPLAY, msg, bc->display, nt,bc);
01072 }
01073 }
01074
01075 #if DEBUG
01076 printf("Building INFORMATION Msg\n");
01077 #endif
01078 return msg;
01079 }
01080
01081 static void parse_status (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 STATUS_t *status=(STATUS_t*)((unsigned long)(msg->data+HEADER_LEN));
01085 int location;
01086 int cause;
01087
01088 dec_ie_cause(status->CAUSE, (Q931_info_t *)(status), &location, &cause, nt,bc);
01089 if (cause>0) bc->cause=cause;
01090 ;
01091
01092 #if DEBUG
01093 printf("Parsing STATUS Msg\n");
01094 #endif
01095 }
01096
01097 static msg_t *build_status (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01098 {
01099 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01100 STATUS_t *status;
01101 msg_t *msg =(msg_t*)create_l3msg(CC_STATUS | REQUEST, MT_STATUS, bc?bc->l3_id:-1, sizeof(STATUS_t) ,nt);
01102
01103 status=(STATUS_t*)((msg->data+HEADER_LEN));
01104
01105 #if DEBUG
01106 printf("Building STATUS Msg\n");
01107 #endif
01108 return msg;
01109 }
01110
01111 static void parse_timeout (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01112 {
01113 #if DEBUG
01114 printf("Parsing STATUS Msg\n");
01115 #endif
01116 }
01117
01118 static msg_t *build_timeout (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
01119 {
01120 int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
01121 STATUS_t *status;
01122 msg_t *msg =(msg_t*)create_l3msg(CC_STATUS | REQUEST, MT_STATUS, bc?bc->l3_id:-1, sizeof(STATUS_t) ,nt);
01123
01124 status=(STATUS_t*)((msg->data+HEADER_LEN));
01125
01126 #if DEBUG
01127 printf("Building STATUS Msg\n");
01128 #endif
01129 return msg;
01130 }
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140 struct isdn_msg msgs_g[] = {
01141 {CC_PROCEEDING,L3,EVENT_PROCEEDING,
01142 parse_proceeding,build_proceeding,
01143 "PROCEEDING"},
01144 {CC_ALERTING,L3,EVENT_ALERTING,
01145 parse_alerting,build_alerting,
01146 "ALERTING"},
01147 {CC_PROGRESS,L3,EVENT_PROGRESS,
01148 parse_progress,build_progress,
01149 "PROGRESS"},
01150 {CC_SETUP,L3,EVENT_SETUP,
01151 parse_setup,build_setup,
01152 "SETUP"},
01153 {CC_CONNECT,L3,EVENT_CONNECT,
01154 parse_connect,build_connect,
01155 "CONNECT"},
01156 {CC_SETUP_ACKNOWLEDGE,L3,EVENT_SETUP_ACKNOWLEDGE,
01157 parse_setup_acknowledge,build_setup_acknowledge,
01158 "SETUP_ACKNOWLEDGE"},
01159 {CC_CONNECT_ACKNOWLEDGE ,L3,EVENT_CONNECT_ACKNOWLEDGE ,
01160 parse_connect_acknowledge ,build_connect_acknowledge,
01161 "CONNECT_ACKNOWLEDGE "},
01162 {CC_USER_INFORMATION,L3,EVENT_USER_INFORMATION,
01163 parse_user_information,build_user_information,
01164 "USER_INFORMATION"},
01165 {CC_SUSPEND_REJECT,L3,EVENT_SUSPEND_REJECT,
01166 parse_suspend_reject,build_suspend_reject,
01167 "SUSPEND_REJECT"},
01168 {CC_RESUME_REJECT,L3,EVENT_RESUME_REJECT,
01169 parse_resume_reject,build_resume_reject,
01170 "RESUME_REJECT"},
01171 {CC_HOLD,L3,EVENT_HOLD,
01172 parse_hold,build_hold,
01173 "HOLD"},
01174 {CC_SUSPEND,L3,EVENT_SUSPEND,
01175 parse_suspend,build_suspend,
01176 "SUSPEND"},
01177 {CC_RESUME,L3,EVENT_RESUME,
01178 parse_resume,build_resume,
01179 "RESUME"},
01180 {CC_HOLD_ACKNOWLEDGE,L3,EVENT_HOLD_ACKNOWLEDGE,
01181 parse_hold_acknowledge,build_hold_acknowledge,
01182 "HOLD_ACKNOWLEDGE"},
01183 {CC_SUSPEND_ACKNOWLEDGE,L3,EVENT_SUSPEND_ACKNOWLEDGE,
01184 parse_suspend_acknowledge,build_suspend_acknowledge,
01185 "SUSPEND_ACKNOWLEDGE"},
01186 {CC_RESUME_ACKNOWLEDGE,L3,EVENT_RESUME_ACKNOWLEDGE,
01187 parse_resume_acknowledge,build_resume_acknowledge,
01188 "RESUME_ACKNOWLEDGE"},
01189 {CC_HOLD_REJECT,L3,EVENT_HOLD_REJECT,
01190 parse_hold_reject,build_hold_reject,
01191 "HOLD_REJECT"},
01192 {CC_RETRIEVE,L3,EVENT_RETRIEVE,
01193 parse_retrieve,build_retrieve,
01194 "RETRIEVE"},
01195 {CC_RETRIEVE_ACKNOWLEDGE,L3,EVENT_RETRIEVE_ACKNOWLEDGE,
01196 parse_retrieve_acknowledge,build_retrieve_acknowledge,
01197 "RETRIEVE_ACKNOWLEDGE"},
01198 {CC_RETRIEVE_REJECT,L3,EVENT_RETRIEVE_REJECT,
01199 parse_retrieve_reject,build_retrieve_reject,
01200 "RETRIEVE_REJECT"},
01201 {CC_DISCONNECT,L3,EVENT_DISCONNECT,
01202 parse_disconnect,build_disconnect,
01203 "DISCONNECT"},
01204 {CC_RESTART,L3,EVENT_RESTART,
01205 parse_restart,build_restart,
01206 "RESTART"},
01207 {CC_RELEASE,L3,EVENT_RELEASE,
01208 parse_release,build_release,
01209 "RELEASE"},
01210 {CC_RELEASE_COMPLETE,L3,EVENT_RELEASE_COMPLETE,
01211 parse_release_complete,build_release_complete,
01212 "RELEASE_COMPLETE"},
01213 {CC_FACILITY,L3,EVENT_FACILITY,
01214 parse_facility,build_facility,
01215 "FACILITY"},
01216 {CC_NOTIFY,L3,EVENT_NOTIFY,
01217 parse_notify,build_notify,
01218 "NOTIFY"},
01219 {CC_STATUS_ENQUIRY,L3,EVENT_STATUS_ENQUIRY,
01220 parse_status_enquiry,build_status_enquiry,
01221 "STATUS_ENQUIRY"},
01222 {CC_INFORMATION,L3,EVENT_INFORMATION,
01223 parse_information,build_information,
01224 "INFORMATION"},
01225 {CC_STATUS,L3,EVENT_STATUS,
01226 parse_status,build_status,
01227 "STATUS"},
01228 {CC_TIMEOUT,L3,EVENT_TIMEOUT,
01229 parse_timeout,build_timeout,
01230 "TIMEOUT"},
01231 {0,0,0,NULL,NULL,NULL}
01232 };
01233
01234 #define msgs_max (sizeof(msgs_g)/sizeof(struct isdn_msg))
01235
01236
01237 int isdn_msg_get_index(struct isdn_msg msgs[], msg_t *msg, int nt)
01238 {
01239 int i;
01240
01241 if (nt){
01242 mISDNuser_head_t *hh = (mISDNuser_head_t*)msg->data;
01243
01244 for (i=0; i< msgs_max -1; i++) {
01245 if ( (hh->prim&COMMAND_MASK)==(msgs[i].misdn_msg&COMMAND_MASK)) return i;
01246 }
01247
01248 } else {
01249 iframe_t *frm = (iframe_t*)msg->data;
01250
01251 for (i=0; i< msgs_max -1; i++)
01252 if ( (frm->prim&COMMAND_MASK)==(msgs[i].misdn_msg&COMMAND_MASK)) return i;
01253 }
01254
01255 return -1;
01256 }
01257
01258 int isdn_msg_get_index_by_event(struct isdn_msg msgs[], enum event_e event, int nt)
01259 {
01260 int i;
01261 for (i=0; i< msgs_max; i++)
01262 if ( event == msgs[i].event) return i;
01263
01264 cb_log(10,0, "get_index: event not found!\n");
01265
01266 return -1;
01267 }
01268
01269 enum event_e isdn_msg_get_event(struct isdn_msg msgs[], msg_t *msg, int nt)
01270 {
01271 int i=isdn_msg_get_index(msgs, msg, nt);
01272 if(i>=0) return msgs[i].event;
01273 return EVENT_UNKNOWN;
01274 }
01275
01276 char * isdn_msg_get_info(struct isdn_msg msgs[], msg_t *msg, int nt)
01277 {
01278 int i=isdn_msg_get_index(msgs, msg, nt);
01279 if(i>=0) return msgs[i].info;
01280 return NULL;
01281 }
01282
01283
01284 char EVENT_CLEAN_INFO[] = "CLEAN_UP";
01285 char EVENT_DTMF_TONE_INFO[] = "DTMF_TONE";
01286 char EVENT_NEW_L3ID_INFO[] = "NEW_L3ID";
01287 char EVENT_NEW_BC_INFO[] = "NEW_BC";
01288 char EVENT_PORT_ALARM_INFO[] = "ALARM";
01289 char EVENT_NEW_CHANNEL_INFO[] = "NEW_CHANNEL";
01290 char EVENT_BCHAN_DATA_INFO[] = "BCHAN_DATA";
01291 char EVENT_BCHAN_ACTIVATED_INFO[] = "BCHAN_ACTIVATED";
01292 char EVENT_TONE_GENERATE_INFO[] = "TONE_GENERATE";
01293 char EVENT_BCHAN_ERROR_INFO[] = "BCHAN_ERROR";
01294
01295 char * isdn_get_info(struct isdn_msg msgs[], enum event_e event, int nt)
01296 {
01297 int i=isdn_msg_get_index_by_event(msgs, event, nt);
01298
01299 if(i>=0) return msgs[i].info;
01300
01301 if (event == EVENT_CLEANUP) return EVENT_CLEAN_INFO;
01302 if (event == EVENT_DTMF_TONE) return EVENT_DTMF_TONE_INFO;
01303 if (event == EVENT_NEW_L3ID) return EVENT_NEW_L3ID_INFO;
01304 if (event == EVENT_NEW_BC) return EVENT_NEW_BC_INFO;
01305 if (event == EVENT_NEW_CHANNEL) return EVENT_NEW_CHANNEL_INFO;
01306 if (event == EVENT_BCHAN_DATA) return EVENT_BCHAN_DATA_INFO;
01307 if (event == EVENT_BCHAN_ACTIVATED) return EVENT_BCHAN_ACTIVATED_INFO;
01308 if (event == EVENT_TONE_GENERATE) return EVENT_TONE_GENERATE_INFO;
01309 if (event == EVENT_PORT_ALARM) return EVENT_PORT_ALARM_INFO;
01310 if (event == EVENT_BCHAN_ERROR) return EVENT_BCHAN_ERROR_INFO;
01311
01312 return NULL;
01313 }
01314
01315 int isdn_msg_parse_event(struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
01316 {
01317 int i=isdn_msg_get_index(msgs, msg, nt);
01318 if(i<0) return -1;
01319
01320 msgs[i].msg_parser(msgs, msg, bc, nt);
01321 return 0;
01322 }
01323
01324 msg_t * isdn_msg_build_event(struct isdn_msg msgs[], struct misdn_bchannel *bc, enum event_e event, int nt)
01325 {
01326 int i=isdn_msg_get_index_by_event(msgs, event, nt);
01327 if(i<0) return NULL;
01328
01329 return msgs[i].msg_builder(msgs, bc, nt);
01330 }