00001
00012 #define GITKR_CAPI_C
00013
00014 #include "gitkrincludes.h"
00015
00016 #include <stdio.h>
00017 #include <stdlib.h>
00018 #include <unistd.h>
00019 #include <string.h>
00020 #include <sys/types.h>
00021
00022 #ifdef HAVE_CAPI20
00023
00024 #include <capi20.h>
00025
00032 CAPI_Info *capi_initialize(int max_logical_conn, int max_Bdata_blocks, int max_Bdata_length) {
00033 CAPI_Info *info;
00034
00035 info=calloc(1,sizeof(CAPI_Info));
00036
00037 capi_incoming_connected = (FALSE);
00038
00039 gitk_log1("Capi: Capi20 is installed if rc == 0. rc=%X",capi20_isinstalled());
00040
00041 info->capi_data_buf_size =((max_Bdata_length>0)?max_Bdata_length:CAPI_DEFAULT_MAX_B_DATA_SIZE);
00042 info->capi_num_bufs =((max_Bdata_blocks>0)?max_Bdata_blocks:CAPI_DEFAULT_MAX_B_DATA_BLOCKS);
00043 info->capi_num_logical_conn =((max_logical_conn>0)?max_logical_conn:CAPI_DEFAULT_LOGICAL_CONNECTIONS);
00044
00045 if(capi20_register(info->capi_num_logical_conn, info->capi_num_bufs, info->capi_data_buf_size, &(info->capi_appid)) != 0) {
00046 gitk_log("Capi: can't connect to capi20 service");
00047 capi_done(info);
00048 return(NULL);
00049 }
00050 return(info);
00051 }
00052
00060 gint capi_listen(CAPI_Info *info, unsigned long controller, unsigned long infomask, unsigned long cipmask, unsigned long cipmask2) {
00061 char buf[26];
00062
00063 info->controller = controller;
00064 info->plci = 0;
00065 info->ncci = 0;
00066 info->provide_dtmf = 0;
00067 info->msg_number = 0;
00068 info->listen = 0;
00069
00070
00071 buf[0] = 0x1A;
00072 buf[1] = 0x00;
00073 buf[2] = (unsigned char)info->capi_appid;
00074 buf[3] = (unsigned char)(info->capi_appid>>8);
00075 buf[4] = 0x05;
00076 buf[5] = 0x80;
00077 buf[6] = (unsigned char)info->msg_number;
00078 buf[7] = (unsigned char)(info->msg_number>>8);
00079 info->msg_number++;
00080 buf[8] = (unsigned char)controller;
00081 buf[9] = (unsigned char)(controller>>8);
00082 buf[10]= (unsigned char)(controller>>16);
00083 buf[11]= (unsigned char)(controller>>24);
00084
00085 buf[12]= (unsigned char)infomask;
00086 buf[13]= (unsigned char)(infomask>>8);
00087 buf[14]= (unsigned char)(infomask>>16);
00088 buf[15]= (unsigned char)(infomask>>24);
00089
00090 buf[16]= (unsigned char)cipmask;
00091 buf[17]= (unsigned char)(cipmask>>8);
00092 buf[18]= (unsigned char)(cipmask>>16);
00093 buf[19]= (unsigned char)(cipmask>>24);
00094
00095 buf[20]= (unsigned char)cipmask2;
00096 buf[21]= (unsigned char)(cipmask2>>8);
00097 buf[22]= (unsigned char)(cipmask2>>16);
00098 buf[23]= (unsigned char)(cipmask2>>24);
00099
00100 buf[24]= 0x00;
00101 buf[25]= 0x00;
00102 capi20_put_message(info->capi_appid,(void*)buf);
00103
00104 if (capi20_waitformessage(info->capi_appid, NULL) == 0){
00105 unsigned char* data=NULL;
00106 while(capi20_get_message(info->capi_appid,(void*)&data) == 0){
00107 if(data[4]==0x05 && data[5]==0x81){
00108
00109 if(data[12]==0 && data[13]==0){
00110 gitk_log("Capi: Listen erfolgreich angemeldet");
00111 info->listen = 1;
00112 }else{
00113 gitk_log2("Capi: Fehler bei LISTEN_REQ %X|%X", data[13], data[12]);
00114 info->listen = -1;
00115 }
00116 }
00117 if(info->listen)break;
00118 }
00119 }
00120 return info->listen;
00121 }
00122
00126 gboolean capi_wait_for_incoming_calls(CAPI_Info *info){
00127 unsigned char* data=NULL;
00128 gboolean stopp = FALSE;
00129 unsigned char buf[64];
00130 int i;
00131 unsigned rc = 0;
00132
00133 while(!stopp){
00134 if(capi20_waitformessage(info->capi_appid, NULL) == 0){
00135 while((rc = capi20_get_message(info->capi_appid,(void*)&data)) == 0){
00136 if(data[4]==0x02 && data[5]==0x82){
00137
00138 info->plci=data[8]+((data[9])<<8)+((data[10])<<16)+((data[11])<<24);
00139 gitk_log1("Capi: PLCI ist %ld", info->plci);
00140
00141 buf[0] = 0x1F;
00142 buf[1] = 0x00;
00143 buf[2] = (unsigned char)info->capi_appid;
00144 buf[3] = (unsigned char)(info->capi_appid>>8);
00145 buf[4] = 0x02;
00146 buf[5] = 0x83;
00147 buf[6] = data[6];
00148 buf[7] = data[7];
00149 buf[8] = (unsigned char)info->plci;
00150 buf[9] = (unsigned char)(info->plci>>8);
00151 buf[10]= (unsigned char)(info->plci>>16);
00152 buf[11]= (unsigned char)(info->plci>>24);
00153 buf[12]= 0x00;
00154 buf[13]= 0x00;
00155 buf[14]= 0x0C;
00156 buf[15]= 0x01;
00157 buf[16]= 0x00;
00158 buf[17]= 0x01;
00159 buf[18]= 0x00;
00160 buf[19]= 0x00;
00161 buf[20]= 0x00;
00162 buf[21]= 0x00;
00163 buf[22]= 0x00;
00164 buf[23]= 0x00;
00165 buf[24]= 0x02;
00166 buf[25]= 0x00;
00167 buf[26]= 0x00;
00168 buf[27]= 0x00;
00169 buf[28]= 0x00;
00170 buf[29]= 0x00;
00171 buf[30]= 0x00;
00172 capi20_put_message(info->capi_appid,(void*)buf);
00173 }
00174 else if(data[4]==0x03 && data[5]==0x82){
00175
00176 gitk_log("Capi: Verbindung zur Gegenstelle hergestellt");
00177
00178 buf[0] = 0x0C;
00179 buf[1] = 0x00;
00180 buf[2] = (unsigned char)info->capi_appid;
00181 buf[3] = (unsigned char)(info->capi_appid>>8);
00182 buf[4] = 0x03;
00183 buf[5] = 0x83;
00184 buf[6] = data[6];
00185 buf[7] = data[7];
00186 buf[8] = (unsigned char)info->plci;
00187 buf[9] = (unsigned char)(info->plci>>8);
00188 buf[10] = (unsigned char)(info->plci>>16);
00189 buf[11] = (unsigned char)(info->plci>>24);
00190 capi20_put_message(info->capi_appid,(void*)buf);
00191 }
00192 else if(data[4]==0x82 && data[5]==0x82){
00193
00194 info->ncci=data[8]+((data[9])<<8)+((data[10])<<16)+((data[11])<<24);
00195 gitk_log1("Capi: NCCI ist %ld", info->ncci);
00196
00197 buf[0] = 0x0F;
00198 buf[1] = 0x00;
00199 buf[2] = (unsigned char)info->capi_appid;
00200 buf[3] = (unsigned char)(info->capi_appid>>8);
00201 buf[4] = 0x82;
00202 buf[5] = 0x83;
00203 buf[6] = data[6];
00204 buf[7] = data[7];
00205 buf[8] = (unsigned char)info->ncci;
00206 buf[9] = (unsigned char)(info->ncci>>8);
00207 buf[10] = (unsigned char)(info->ncci>>16);
00208 buf[11] = (unsigned char)(info->ncci>>24);
00209 buf[12] = 0x00;
00210 buf[13] = 0x00;
00211 buf[14] = 0x00;
00212 capi20_put_message(info->capi_appid,(void*)buf);
00213 }
00214 else if(data[4]==0x83 && data[5]==0x82){
00215
00216 gitk_log("Capi: B3 Verbindung zur Gegenstelle hergestellt");
00217
00218 buf[0] = 0x0C;
00219 buf[1] = 0x00;
00220 buf[2] = (unsigned char)info->capi_appid;
00221 buf[3] = (unsigned char)(info->capi_appid>>8);
00222 buf[4] = 0x83;
00223 buf[5] = 0x83;
00224 buf[6] = data[6];
00225 buf[7] = data[7];
00226 buf[8] = (unsigned char)info->ncci;
00227 buf[9] = (unsigned char)(info->ncci>>8);
00228 buf[10] = (unsigned char)(info->ncci>>16);
00229 buf[11] = (unsigned char)(info->ncci>>24);
00230 capi20_put_message(info->capi_appid,(void*)buf);
00231
00232 buf[0] = 0x18;
00233 buf[1] = 0x00;
00234 buf[2] = (unsigned char)info->capi_appid;
00235 buf[3] = (unsigned char)(info->capi_appid>>8);
00236 buf[4] = 0x80;
00237 buf[5] = 0x80;
00238 buf[6] = (unsigned char)info->msg_number;
00239 buf[7] = (unsigned char)(info->msg_number>>8);
00240 info->msg_number++;
00241 buf[8] = (unsigned char)info->ncci;
00242 buf[9] = (unsigned char)(info->ncci>>8);
00243 buf[10] = (unsigned char)(info->ncci>>16);
00244 buf[11] = (unsigned char)(info->ncci>>24);
00245 buf[12] = 0x01;
00246 buf[13] = 0x00;
00247 buf[14] = 0x08;
00248 buf[15] = 0x01;
00249 buf[16] = 0x00;
00250 buf[17] = 0x28;
00251 buf[18] = 0x00;
00252 buf[19] = 0x28;
00253 buf[20] = 0x00;
00254 buf[21] = 0x00;
00255 buf[22] = 0x02;
00256 buf[23] = 0x00;
00257 buf[24] = 0x00;
00258 capi20_put_message(info->capi_appid,(void*)buf);
00259 }
00260 else if(data[4]==0x80 && data[5]==0x81){
00261
00262 if(data[12]==0 && data[13]==0)
00263 {
00264 gitk_log("Capi: Facility erfolgreich angemeldet");
00265 info->provide_dtmf = 1;
00266 stopp = TRUE;
00267 }else{
00268 gitk_log2("Capi: Fehler bei Facility %X|%X", data[13], data[12]);
00269 capi_exception(info, CAPI_NO_FACILITY);
00270 return FALSE;
00271 }
00272 }
00273 else if((data[4]==0x04 && data[5]==0x82) || (data[4]==0x84 && data[5]==0x82)){
00274 capi_passive_disconnect(info, data);
00275 stopp = TRUE;
00276 }
00277 else if(data[4]==0x08 && data[5]==0x82){
00278
00279 gitk_log("Capi: An INFO_IND was recieved");
00280
00281 buf[0] = 0x0C;
00282 buf[1] = 0x00;
00283 buf[2] = (unsigned char)info->capi_appid;
00284 buf[3] = (unsigned char)(info->capi_appid>>8);
00285 buf[4] = 0x08;
00286 buf[5] = 0x83;
00287 buf[6] = data[6];
00288 buf[7] = data[7];
00289 buf[8] = data[8];
00290 buf[9] = data[9];
00291 buf[10]= data[10];
00292 buf[11]= data[11];
00293 capi20_put_message(info->capi_appid,(void*)buf);
00294 }
00295 else{
00296
00297
00298 }
00299 if(stopp)break;
00300 }
00301 }
00302 }
00303 return TRUE;
00304 }
00305
00309 void capi_active_disconnect(CAPI_Info *info){
00310 unsigned char buf[64];
00311 if(info->ncci){
00312
00313 buf[0] = 0x0D;
00314 buf[1] = 0x00;
00315 buf[2] = (unsigned char)info->capi_appid;
00316 buf[3] = (unsigned char)(info->capi_appid>>8);
00317 buf[4] = 0x84;
00318 buf[5] = 0x80;
00319 buf[6] = (unsigned char)info->msg_number;
00320 buf[7] = (unsigned char)(info->msg_number>>8);
00321 info->msg_number++;
00322 buf[8] = (unsigned char)info->ncci;
00323 buf[9] = (unsigned char)(info->ncci>>8);
00324 buf[10] = (unsigned char)(info->ncci>>16);
00325 buf[11] = (unsigned char)(info->ncci>>24);
00326 buf[12]= 0x00;
00327 capi20_put_message(info->capi_appid,(void*)buf);
00328 info->ncci = 0;
00329 gitk_log("Capi: DISCONNECT_B3_REQ");
00330 capi_incoming_connected = (FALSE);
00331 }
00332 if(info->plci){
00333
00334 buf[0] = 0x0D;
00335 buf[1] = 0x00;
00336 buf[2] = (unsigned char)info->capi_appid;
00337 buf[3] = (unsigned char)(info->capi_appid>>8);
00338 buf[4] = 0x04;
00339 buf[5] = 0x80;
00340 buf[6] = (unsigned char)info->msg_number;
00341 buf[7] = (unsigned char)(info->msg_number>>8);
00342 info->msg_number++;
00343 buf[8] = (unsigned char)info->plci;
00344 buf[9] = (unsigned char)(info->plci>>8);
00345 buf[10]= (unsigned char)(info->plci>>16);
00346 buf[11]= (unsigned char)(info->plci>>24);
00347 buf[12]= 0x00;
00348 capi20_put_message(info->capi_appid,(void*)buf);
00349 info->plci = 0;
00350 gitk_log("Capi: DISCONNECT_REQ");
00351 capi_incoming_connected = (FALSE);
00352 }
00353 return;
00354 }
00355
00359 gint capi_passive_disconnect(CAPI_Info *info, unsigned char *data){
00360 unsigned char buf[64];
00361 gint rc = 0;
00362 if(data[4]==0x04 && data[5]==0x82){
00363
00364 gitk_log("Capi: Verbindung von Gegenstelle abgebrochen");
00365
00366 buf[0] = 0x0C;
00367 buf[1] = 0x00;
00368 buf[2] = (unsigned char)info->capi_appid;
00369 buf[3] = (unsigned char)(info->capi_appid>>8);
00370 buf[4] = 0x04;
00371 buf[5] = 0x83;
00372 buf[6] = data[6];
00373 buf[7] = data[7];
00374 buf[8] = (unsigned char)info->plci;
00375 buf[9] = (unsigned char)(info->plci>>8);
00376 buf[10] = (unsigned char)(info->plci>>16);
00377 buf[11] = (unsigned char)(info->plci>>24);
00378 capi20_put_message(info->capi_appid,(void*)buf);
00379 info->plci = 0;
00380 rc = 1;
00381 capi_incoming_connected = (FALSE);
00382 }
00383 if(data[4]==0x84 && data[5]==0x82){
00384
00385 gitk_log2("Capi: B3 Verbindung unterbrochen von Gegenstelle %X|%X", data[13], data[12]);
00386
00387 buf[0] = 0x0C;
00388 buf[1] = 0x00;
00389 buf[2] = (unsigned char)info->capi_appid;
00390 buf[3] = (unsigned char)(info->capi_appid>>8);
00391 buf[4] = 0x84;
00392 buf[5] = 0x83;
00393 buf[6] = data[6];
00394 buf[7] = data[7];
00395 buf[8] = (unsigned char)info->ncci;
00396 buf[9] = (unsigned char)(info->ncci>>8);
00397 buf[10] = (unsigned char)(info->ncci>>16);
00398 buf[11] = (unsigned char)(info->ncci>>24);
00399 capi20_put_message(info->capi_appid,(void*)buf);
00400 info->ncci = 0;
00401 capi_active_disconnect(info);
00402 rc = 1;
00403 capi_incoming_connected = (FALSE);
00404 }
00405 return rc;
00406 }
00407
00412 CAPI_Dtmf *capi_detect_dtmf(CAPI_Info *info, unsigned char *data){
00413 CAPI_Dtmf *dtmf_list = NULL;
00414 CAPI_Dtmf *dtmf = NULL;
00415 int i;
00416 static int old_space = 0, space = 0;
00417 unsigned char buf[64];
00418 if(data[4]==0x86 && data[5]==0x82)space++;
00419 if(data[4]==0x80 && data[5]==0x82){
00420
00421 dtmf_list = (CAPI_Dtmf*)calloc(data[14]+1, sizeof(CAPI_Dtmf));
00422 if(!dtmf_list){
00423 capi_exception(info, CAPI_NO_MEMORY);
00424 return (NULL);
00425 }
00426 dtmf = dtmf_list;
00427 dtmf_list->member.member_count = data[14];
00428 for(i=1;i<=data[14];i++){
00429 dtmf_list++;
00430 dtmf_list->member.dtmf_sign.msg_number=data[7]+((data[8])<<8);
00431 dtmf_list->member.dtmf_sign.timediff=space-old_space;
00432 dtmf_list->member.dtmf_sign.signcode=data[14+i];
00433
00434 old_space = space;
00435 }
00436
00437 buf[0] = 0x0C;
00438 buf[1] = 0x00;
00439 buf[2] = (unsigned char)info->capi_appid;
00440 buf[3] = (unsigned char)(info->capi_appid>>8);
00441 buf[4] = 0x80;
00442 buf[5] = 0x83;
00443 buf[6] = data[6];
00444 buf[7] = data[7];
00445 buf[8] = data[8];
00446 buf[9] = data[9];
00447 buf[10]= data[10];
00448 buf[11]= data[11];
00449 capi20_put_message(info->capi_appid,(void*)buf);
00450 }
00451 return dtmf;
00452 }
00453
00458 void capi_dummy_receive(CAPI_Info *info, unsigned char *data){
00459 CAPI_Data *pdata = NULL;
00460
00461 pdata = capi_receive_message(info, data);
00462 }
00463
00468 CAPI_Data *capi_receive_message(CAPI_Info *info, unsigned char *data){
00469 CAPI_Data *pdata = NULL;
00470 unsigned char buf[64];
00471 unsigned char *databuf = NULL;
00472
00473 if(data[4]==0x86 && data[5]==0x82){
00474
00475 pdata = calloc(1, sizeof(CAPI_Data));
00476 if(!pdata){
00477 capi_exception(info, CAPI_NO_MEMORY);
00478 return NULL;
00479 }
00480 pdata->data_length = data[16]+((data[17])<<8);
00481 pdata->data_addr = (unsigned char*)malloc(pdata->data_length);
00482 if(!pdata->data_addr){
00483 pdata = NULL;
00484 capi_exception(info, CAPI_NO_MEMORY);
00485 return NULL;
00486 }
00487 databuf = (unsigned char*)(data[12]+((data[13])<<8)+((data[14])<<16)+((data[15])<<24));
00488 if(!pdata->data_length){
00489 pdata = NULL;
00490 capi_exception(info, CAPI_NO_MEMORY);
00491 return NULL;
00492 }
00493 memcpy(pdata->data_addr, databuf, pdata->data_length);
00494
00495 buf[0] = 0x0E;
00496 buf[1] = 0x00;
00497 buf[2] = (unsigned char)info->capi_appid;
00498 buf[3] = (unsigned char)(info->capi_appid>>8);
00499 buf[4] = 0x86;
00500 buf[5] = 0x83;
00501 buf[6] = data[6];
00502 buf[7] = data[7];
00503 buf[8] = data[8];
00504 buf[9] = data[9];
00505 buf[10]= data[10];
00506 buf[11]= data[11];
00507 buf[12]= data[18];
00508 buf[13]= data[19];
00509 capi20_put_message(info->capi_appid,(void*)buf);
00510 }
00511 return pdata;
00512 }
00513
00519 gint capi_send_message(CAPI_Info *info, FT_Alaw *alaw, int breakable){
00520 int i = 0;
00521 int rest;
00522 unsigned char *rdata = NULL;
00523 gboolean stopp = FALSE;
00524 unsigned char *data = NULL;
00525 unsigned char buf[64];
00526
00527
00528 if(!alaw)return 0;
00529 rdata = (unsigned char *)malloc(2048);
00530 if (!rdata) {
00531 capi_exception(info, CAPI_NO_MEMORY);
00532 return -1;
00533 }
00534 if ((rest = alaw->num_samples-i) < 2048) {
00535 memcpy(rdata, alaw->samples+i, rest);
00536 i+=rest;
00537 stopp = TRUE;
00538 } else {
00539 rest=2048;
00540 memcpy(rdata, alaw->samples+i, rest);
00541 i+=rest;
00542 }
00543 buf[0] = 0x1E;
00544 buf[1] = 0x00;
00545 buf[2] = (unsigned char)info->capi_appid;
00546 buf[3] = (unsigned char)(info->capi_appid>>8);
00547 buf[4] = 0x86;
00548 buf[5] = 0x80;
00549 buf[6] = (unsigned char)info->msg_number;
00550 buf[7] = (unsigned char)(info->msg_number>>8);
00551 info->msg_number++;
00552 buf[8] = (unsigned char)info->ncci;
00553 buf[9] = (unsigned char)(info->ncci>>8);
00554 buf[10]= (unsigned char)(info->ncci>>16);
00555 buf[11]= (unsigned char)(info->ncci>>24);
00556 buf[12]= (unsigned char)(unsigned long)rdata;
00557 buf[13]= (unsigned char)((unsigned long)rdata>>8);
00558 buf[14]= (unsigned char)((unsigned long)rdata>>16);
00559 buf[15]= (unsigned char)((unsigned long)rdata>>24);
00560 buf[16]= (unsigned char)rest;
00561 buf[17]= (unsigned char)(rest>>8);
00562 buf[18]= (unsigned char)info->msg_number;
00563 buf[19]= (unsigned char)(info->msg_number>>8);
00564 buf[20]= 0x00;
00565 buf[21]= 0x00;
00566 buf[22]= 0x00;
00567 buf[23]= 0x00;
00568 buf[24]= 0x00;
00569 buf[25]= 0x00;
00570 buf[26]= 0x00;
00571 buf[27]= 0x00;
00572 buf[28]= 0x00;
00573 buf[29]= 0x00;
00574 capi20_put_message(info->capi_appid,(void*)buf);
00575 while(!stopp){
00576 if(capi20_waitformessage(info->capi_appid, NULL) == 0){
00577 while(capi20_get_message(info->capi_appid,(void*)&data) == 0){
00578 if(capi_passive_disconnect(info, data))stopp = TRUE;
00579 if(data[4] == 0x80 && data[5] == 0x82){
00580
00581
00582 if(breakable){
00583 stopp = TRUE;
00584 printf("Vom User abgebrochen\n");
00585 }
00586 }
00587 capi_dummy_receive(info, data);
00588 if(data[4] == 0x86 && data[5] == 0x81){
00589
00590
00591
00592 if(i<alaw->num_samples){
00593 if ((rest = alaw->num_samples-i) < 2048) {
00594 memcpy(rdata, alaw->samples+i, rest);
00595 i+=rest;
00596 stopp = TRUE;
00597 } else {
00598 rest=2048;
00599 memcpy(rdata, alaw->samples+i, rest);
00600 i+=rest;
00601 }
00602 buf[0] = 0x1E;
00603 buf[1] = 0x00;
00604 buf[2] = (unsigned char)info->capi_appid;
00605 buf[3] = (unsigned char)(info->capi_appid>>8);
00606 buf[4] = 0x86;
00607 buf[5] = 0x80;
00608 buf[6] = (unsigned char)info->msg_number;
00609 buf[7] = (unsigned char)(info->msg_number>>8);
00610 info->msg_number++;
00611 buf[8] = (unsigned char)info->ncci;
00612 buf[9] = (unsigned char)(info->ncci>>8);
00613 buf[10]= (unsigned char)(info->ncci>>16);
00614 buf[11]= (unsigned char)(info->ncci>>24);
00615 buf[12]= (unsigned char)(unsigned long)rdata;
00616 buf[13]= (unsigned char)((unsigned long)rdata>>8);
00617 buf[14]= (unsigned char)((unsigned long)rdata>>16);
00618 buf[15]= (unsigned char)((unsigned long)rdata>>24);
00619 buf[16]= (unsigned char)rest;
00620 buf[17]= (unsigned char)(rest>>8);
00621 buf[18]= (unsigned char)info->msg_number;
00622 buf[19]= (unsigned char)(info->msg_number>>8);
00623 buf[20]= 0x00;
00624 buf[21]= 0x00;
00625 buf[22]= 0x00;
00626 buf[23]= 0x00;
00627 buf[24]= 0x00;
00628 buf[25]= 0x00;
00629 buf[26]= 0x00;
00630 buf[27]= 0x00;
00631 buf[28]= 0x00;
00632 buf[29]= 0x00;
00633 capi20_put_message(info->capi_appid,(void*)buf);
00634 }
00635 }
00636 }
00637 }
00638 }
00639 return i;
00640 }
00641
00642 #endif //HAVE_CAPI20
00643
00647 void capi_done(CAPI_Info *info) {
00648
00649 #ifdef HAVE_CAPI20
00650
00651 if(!info) return;
00652 capi_active_disconnect(info);
00653 capi20_release(info->capi_appid);
00654 free(info);
00655 capi_incoming_connected = (FALSE);
00656
00657 #endif //HAVE_CAPI20
00658
00659 }
00660
00665 gint capi_dtmf_input_text(CAPI_Info *info, unsigned char *ucbuf){
00666 gint anz = 0, actual = 0;
00667 CAPI_Dtmf *dtmf_list = NULL;
00668 unsigned char signcode = '\0';
00669 int i;
00670 unsigned char *data = NULL;
00671 int key = 16;
00672 int key_offset = 0;
00673
00674 #ifdef HAVE_CAPI20
00675
00676 while(signcode!='#'){
00677 if(capi20_waitformessage(info->capi_appid, NULL) == 0){
00678 while(capi20_get_message(info->capi_appid,(void*)&data) == 0){
00679 if(!capi_passive_disconnect(info, data)){
00680 dtmf_list = capi_detect_dtmf(info, data);
00681 capi_dummy_receive(info, data);
00682 if(dtmf_list){
00683 actual=(dtmf_list++)->member.member_count;
00684
00685 for(i=0;i<actual;i++){
00686 if(dtmf_list->member.dtmf_sign.signcode!='#'){
00687 if(dtmf_list->member.dtmf_sign.timediff <= gitkr_phone_capi_betweendigits && key == key_of_char(dtmf_list->member.dtmf_sign.signcode)){
00688 key_offset += 1;
00689 key = key_of_char(dtmf_list->member.dtmf_sign.signcode);
00690 *(--ucbuf) = get_ascii_of_key(key, key_offset);
00691 ucbuf++;
00692 }else{
00693 key_offset = 0;
00694 key = key_of_char(dtmf_list->member.dtmf_sign.signcode);
00695 *(ucbuf++) = get_ascii_of_key(key, key_offset);
00696 anz++;
00697 }
00698 }else{
00699 signcode='#';
00700 *ucbuf = '\0';
00701 }
00702 }
00703 dtmf_list = NULL;
00704 }
00705 }else signcode = '#';
00706 }
00707 }
00708 }
00709
00710 #else
00711
00712 key = '\0';
00713 while(key != 13){
00714 if((key=gitkr_event_loop_getkey())==ERR) continue;
00715
00716 *(ucbuf++) = key;
00717 anz++;
00718 }
00719 *(ucbuf--) = '\0';
00720
00721 #endif //HAVE_CAPI20
00722
00723 return anz;
00724 }
00725
00730 gint capi_dtmf_input_arrow(CAPI_Info *info, unsigned char *ucbuf){
00731 CAPI_Dtmf *dtmf_list = NULL;
00732 unsigned int signcode = '\0';
00733 unsigned char *data = NULL;
00734 int key = 16;
00735
00736 #ifdef HAVE_CAPI20
00737
00738 while(signcode=='\0'){
00739 if(capi20_waitformessage(info->capi_appid, NULL) == 0){
00740 while(capi20_get_message(info->capi_appid,(void*)&data) == 0){
00741 if(!capi_passive_disconnect(info, data)){
00742 dtmf_list = capi_detect_dtmf(info, data);
00743 capi_dummy_receive(info, data);
00744 if(dtmf_list){
00745 key = key_of_char((++dtmf_list)->member.dtmf_sign.signcode);
00746 dtmf_list--;
00747 signcode = navigation(key, KEY_TABLE_ARROW);
00748 gitk_log1("signcode = %d", signcode);
00749 *ucbuf = signcode;
00750 dtmf_list = NULL;
00751 }else{
00752 signcode = '\0';
00753 }
00754 }else{
00755 signcode = 27;
00756 *ucbuf = 27;
00757 }
00758 }
00759 }
00760 }
00761
00762 #else
00763
00764 signcode = getchar();
00765
00766 #endif
00767
00768 return signcode;
00769 }
00770
00776 gint capi_text_output(CAPI_Info *info, unsigned char *ucbuf, FT_Info *ftinfo){
00777 gint anz = 0;
00778 FT_Wave *wave = NULL;
00779 FT_Alaw *alaw = NULL;
00780 unsigned char *buf = NULL;
00781
00782 gitk_log("capi_text_output() beg");
00783 if(!ucbuf || ucbuf[0] == '\0')return 0;
00784
00785
00786 buf = malloc(sizeof(unsigned char)*strlen(ucbuf));
00787 strcpy(buf, ucbuf);
00788
00789 #ifdef HAVE_CAPI20
00790
00791 alaw = (FT_Alaw*)malloc(sizeof(FT_Alaw));
00792 wave = festival_text2wave(ftinfo, buf);
00793 if(!wave)return 0;
00794 if(festival_wav2alaw(wave, alaw)<=0)return 0;
00795 anz = capi_send_message(info, alaw, 1);
00796 if(wave){
00797 if(wave->samples)wave->samples = NULL;
00798
00799 wave = NULL;
00800 }
00801 if(alaw){
00802 if(alaw->samples)free(alaw->samples);
00803 free(alaw);
00804 alaw = NULL;
00805 }
00806
00807 #else
00808
00809 festival_say_text(ftinfo, buf);
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819 #endif //HAVE_CAPI20
00820
00821 gitk_log("capi_text_output() end");
00822 return anz;
00823 }
00824
00829 void capi_exception(CAPI_Info *info, gint status){
00830 gitk_log1("exception detected %X", status);
00831 capi_done(info);
00832 }
00833
00839 gboolean capi_sound_output(CAPI_Info *info, gchar *filename, FT_Info *ftinfo){
00840 gint anz = 0;
00841 gint i;
00842 FT_Wave *wave = NULL;
00843 FT_Alaw *alaw = NULL;
00844 FILE *f1 = NULL;
00845
00846 gitk_log("capi_sound_output() beg");
00847
00848 #ifdef HAVE_CAPI20
00849
00850 alaw = (FT_Alaw*)malloc(sizeof(FT_Alaw));
00851 if(!alaw)return 0;
00852 wave = (FT_Wave*)malloc(sizeof(FT_Wave));
00853 if(!wave)return 0;
00854 gitk_log("alaw and wave allocated");
00855 f1 = fopen(filename, "rb");
00856 if(f1 == NULL){
00857 gitk_log("fopen failed");
00858 return FALSE;
00859 }
00860 fseek(f1, 0, SEEK_END);
00861 anz = ftell(f1);
00862 fseek(f1, 0, SEEK_SET);
00863 wave->num_samples = anz/2;
00864 wave->samples = malloc(sizeof(char)*anz);
00865 gitk_log("wave->samples allocated");
00866 wave->sample_rate = 16000;
00867 gitk_log2("samples = %d, anz = %d", fread(wave->samples, 1, anz, f1), anz);
00868 fclose(f1);
00869 gitk_log("after file reading");
00870 if(festival_wav2alaw(wave, alaw)<=0)return 0;
00871 anz = capi_send_message(info, alaw, 1);
00872
00873 if(wave){
00874 if(wave->samples)free(wave->samples);
00875 free(wave);
00876 }
00877 wave = NULL;
00878 if(alaw){
00879 if(alaw->samples)free(alaw->samples);
00880 free(alaw);
00881 }
00882 alaw = NULL;
00883
00884 #else
00885
00886 festival_play_wave(ftinfo, filename);
00887
00888 #endif //HAVE_CAPI20
00889
00890 gitk_log("capi_sound_output() beg");
00891 return TRUE;
00892 }
00893
00898 void capi_sound_beep(CAPI_Info *info, FT_Info *ftinfo){
00899 capi_sound_output(info, "/opt/gitk/gitk-renderer-phone/sounds/beep.wav", ftinfo);
00900
00901
00902 }
00903
00908 void capi_sound_standard(CAPI_Info *info, FT_Info *ftinfo){
00909 capi_sound_output(info, "/opt/gitk/gitk-renderer-phone/sounds/standard.wav", ftinfo);
00910
00911
00912 }
00913
00918 void capi_sound_ding(CAPI_Info *info, FT_Info *ftinfo){
00919 capi_sound_output(info, "/opt/gitk/gitk-renderer-phone/sounds/ding.wav", ftinfo);
00920
00921
00922 }
00923
00928 void capi_sound_error(CAPI_Info *info, FT_Info *ftinfo){
00929 capi_sound_output(info, "/opt/gitk/gitk-renderer-phone/sounds/error.wav", ftinfo);
00930
00931
00932 }
00933
00938 void capi_sound_question(CAPI_Info *info, FT_Info *ftinfo){
00939 capi_sound_output(info, "/opt/gitk/gitk-renderer-phone/sounds/question.wav", ftinfo);
00940
00941
00942 }
00943
00948 void capi_sound_notify(CAPI_Info *info, FT_Info *ftinfo){
00949 capi_sound_output(info, "/opt/gitk/gitk-renderer-phone/sounds/notify.wav", ftinfo);
00950
00951
00952 }
00953
00958 void capi_sound_indication(CAPI_Info *info, FT_Info *ftinfo){
00959 capi_sound_output(info, "/opt/gitk/gitk-renderer-phone/sounds/indication.wav", ftinfo);
00960
00961
00962 }
00963
00968 void capi_sound_dong(CAPI_Info *info, FT_Info *ftinfo){
00969 capi_sound_output(info, "/opt/gitk/gitk-renderer-phone/sounds/dong.wav", ftinfo);
00970
00971
00972 }
00973
00978 void capi_sound_critical(CAPI_Info *info, FT_Info *ftinfo){
00979 capi_sound_output(info, "/opt/gitk/gitk-renderer-phone/sounds/critical.wav", ftinfo);
00980
00981
00982 }