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