--- /usr/src/chan_bluetooth/chan_bluetooth.c 2005-05-19 23:51:43.000000000 +0200 +++ /usr/src/bristuff-0.2.0-RC8n/asterisk-1.0.9/channels/chan_bluetooth.c 2005-08-24 13:17:43.000000000 +0200 @@ -8,6 +8,8 @@ * Adaptive Linux Solutions * * Copyright (C) 2004 Adaptive Linux Solutions + * + * Modifications by Chris Halls * * This program is free software, distributed under the terms of * the GNU General Public License @@ -247,6 +249,7 @@ int gain_speaker; /* Runtime: Gain Of Speaker */ int clip; /* Runtime: Supports CLID */ int colp; /* Runtime: Connected Line ID */ + int ccwa; /* Runtime: Call waiting ind enabled */ int elip; /* Runtime: (Ericsson) Supports CLID */ int eolp; /* Runtime: (Ericsson) Connected Line ID */ int ringing; /* Runtime: Device is ringing */ @@ -1180,8 +1183,13 @@ // ast->fds[0] = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO); ast->nativeformats = BLUETOOTH_FORMAT; +#if ASTERISK_VERSION_NUM > 010107 ast->rawreadformat = BLUETOOTH_FORMAT; ast->rawwriteformat = BLUETOOTH_FORMAT; +#else + ast->pvt->rawreadformat = BLUETOOTH_FORMAT; + ast->pvt->rawwriteformat = BLUETOOTH_FORMAT; +#endif ast->writeformat = BLUETOOTH_FORMAT; ast->readformat = BLUETOOTH_FORMAT; @@ -1202,11 +1210,13 @@ #endif strncpy(ast->context, context, sizeof(ast->context)-1); strncpy(ast->exten, number, sizeof(ast->exten) - 1); +#if ASTERISK_VERSION_NUM > 010107 if(0 == strcmp(number, "s")) { ast_set_callerid(ast, dev->cid_num, dev->cid_name, dev->cid_num); } - +#endif + ast->language[0] = '\0'; ast->fds[0] = dev->sco_pipe[0]; @@ -1445,6 +1455,14 @@ return 0; } +/* CHLD - Call hold and multiparty */ +static int +atcmd_chld_test(blt_dev_t * dev) +{ + send_atcmd(dev, "+CHLD: ()"); + return 0; +} + /* Set Language */ static int @@ -1472,6 +1490,15 @@ return 0; } +/* Call waiting event reporting */ +static int +atcmd_ccwa_set(blt_dev_t * dev, const char * arg, int len) +{ + dev->ccwa = atoi(arg); + return 0; +} + + /* CMER - Mobile Equipment Event Reporting */ static int @@ -1733,6 +1760,8 @@ { "+BRSF", atcmd_brsf_set, NULL, NULL, NULL, NULL }, { "+BVRA", atcmd_bvra_set, NULL, NULL, NULL, NULL }, { "+CCLK", NULL, atcmd_cclk_read, NULL, NULL, NULL }, + { "+CCWA", atcmd_ccwa_set, NULL, NULL, NULL, NULL }, + { "+CHLD", NULL, NULL, NULL, atcmd_chld_test, NULL }, { "+CHUP", NULL, NULL, atcmd_chup_execute, NULL, NULL }, { "+CIEV", NULL, NULL, NULL, NULL, ag_unsol_ciev }, { "+CIND", NULL, atcmd_cind_read, NULL, atcmd_cind_test, ag_unsol_cind }, @@ -3175,26 +3204,37 @@ if (monitor_thread != AST_PTHREADT_NULL) { if (ast_mutex_lock(&monitor_lock)) { - - if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) { - pthread_cancel(monitor_thread); - pthread_kill(monitor_thread, SIGURG); - fprintf(stderr, "Waiting for monitor thread to join...\n"); - pthread_join(monitor_thread, NULL); - fprintf(stderr, "joined\n"); - } - monitor_thread = AST_PTHREADT_STOP; - ast_mutex_unlock(&monitor_lock); - - } else { - - ast_log(LOG_WARNING, "Unable to lock the monitor\n"); - return -1; - + ast_log(LOG_WARNING, "Unable to lock the monitor\n"); + return -1; } + if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) { + pthread_cancel(monitor_thread); + pthread_kill(monitor_thread, SIGURG); + fprintf(stderr, "Waiting for monitor thread to join...\n"); + pthread_join(monitor_thread, NULL); + fprintf(stderr, "joined\n"); + } + monitor_thread = AST_PTHREADT_STOP; + ast_mutex_unlock(&monitor_lock); } + if (rfcomm_sock_ag != -1) { + fprintf(stderr, "Close sock_ag %d\n", rfcomm_sock_ag); + close(rfcomm_sock_ag); + rfcomm_sock_ag = -1; + } + if (rfcomm_sock_hs != -1) { + fprintf(stderr, "Close sock_hs %d\n", rfcomm_sock_hs); + close(rfcomm_sock_hs); + rfcomm_sock_hs = -1; + } + if (sco_socket != -1) { + fprintf(stderr, "Close sock_sco %d\n", sco_socket); + close(sco_socket); + sco_socket = -1; + } + fprintf(stderr, "Removing sdp records\n"); ast_unregister_atexit(remove_sdp_records); remove_sdp_records(); return 0; @@ -3244,36 +3284,45 @@ sess = sdp_connect(&local_bdaddr, BDADDR_LOCAL, SDP_RETRY_IF_BUSY); if ((rfcomm_sock_ag = rfcomm_listen(&local_bdaddr, rfcomm_channel_ag)) < 0) { + unload_module(); return -1; } - if ((rfcomm_sock_hs = rfcomm_listen(&local_bdaddr, rfcomm_channel_hs)) < 0) + if ((rfcomm_sock_hs = rfcomm_listen(&local_bdaddr, rfcomm_channel_hs)) < 0) { + unload_module(); return -1; + } - if ((sco_socket = sco_listen(&local_bdaddr)) < 0) + if ((sco_socket = sco_listen(&local_bdaddr)) < 0) { + unload_module(); return -1; + } if (!sess) { ast_log(LOG_ERROR, "Failed to connect to SDP server: %s\n", strerror(errno)); + unload_module(); return -1; } if (sdp_register(sess) != 0) { ast_log(LOG_ERROR, "Failed to register HeadsetAudioGateway in SDP\n"); + unload_module(); return -1; } sdp_close(sess); - if (restart_monitor() != 0) + if (restart_monitor() != 0) { + unload_module(); return -1; + } #if ASTERISK_VERSION_NUM <= 010107 if (ast_channel_register(BLT_CHAN_NAME, "Bluetooth Driver", BLUETOOTH_FORMAT, blt_request)) { #else if (ast_channel_register(&blt_tech)) { #endif - ast_log(LOG_ERROR, "Unable to register channel class BTL\n"); + ast_log(LOG_ERROR, "Unable to register channel class BLT\n"); __unload_module(); return -1; }