Index: chan_mobile.c =================================================================== --- chan_mobile.c (revision 454) +++ chan_mobile.c (working copy) @@ -26,7 +26,7 @@ */ /*** MODULEINFO - bluetooth + ***/ #include @@ -514,7 +514,7 @@ chn->writeformat = prefformat; chn->readformat = prefformat; chn->tech_pvt = pvt; - ast_channel_set_fd(chn, 0, pvt->io_pipe[0]); + chn->fds[0] = pvt->io_pipe[0]; if (state == AST_STATE_RING) chn->rings = 1; ast_string_field_set(chn, language, "en"); @@ -613,7 +613,7 @@ return -1; } - ast_debug(1, "Calling %s on %s\n", dest, ast->name); + ast_log(LOG_DEBUG, "Calling %s on %s\n", dest, ast->name); if (pvt->type == MBL_TYPE_PHONE) { ast_copy_string(pvt->dial_number, dest_num, sizeof(pvt->dial_number)); @@ -638,7 +638,7 @@ } pvt = ast->tech_pvt; - ast_debug(1, "Hanging up device %s.\n", pvt->id); + ast_log(LOG_DEBUG, "Hanging up device %s.\n", pvt->id); close(pvt->io_pipe[0]); close(pvt->io_pipe[1]); @@ -698,7 +698,7 @@ if (pvt->type == MBL_TYPE_HEADSET) return 0; - ast_debug(1, "Dialed %c\n", digit); + ast_log(LOG_DEBUG, "Dialed %c\n", digit); switch(digit) { case '0': @@ -839,7 +839,7 @@ device = ast_strdupa(S_OR(data, "")); - ast_debug(1, "Checking device state for device %s\n", device); + ast_log(LOG_DEBUG, "Checking device state for device %s\n", device); AST_LIST_TRAVERSE(&devices, pvt, entry) { if (!strcmp(pvt->id, device)) @@ -913,13 +913,13 @@ return; } - ast_debug(1, "Alignment Detection result is [%-d %-d %-d %-d]\n", pvt->alignment_samples[0], pvt->alignment_samples[1], pvt->alignment_samples[2], pvt->alignment_samples[3]); + ast_log(LOG_DEBUG, "Alignment Detection result is [%-d %-d %-d %-d]\n", pvt->alignment_samples[0], pvt->alignment_samples[1], pvt->alignment_samples[2], pvt->alignment_samples[3]); a = abs(pvt->alignment_samples[1]) + abs(pvt->alignment_samples[2]) + abs(pvt->alignment_samples[3]); a /= 3; if (a > 100) { pvt->alignment_detection_triggered = 1; - ast_debug(1, "Alignment Detection Triggered.\n"); + ast_log(LOG_DEBUG, "Alignment Detection Triggered.\n"); } else pvt->do_alignment_detection = 0; @@ -937,7 +937,7 @@ int s; if ((s = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) { - ast_debug(1, "socket() failed (%d).\n", errno); + ast_log(LOG_DEBUG, "socket() failed (%d).\n", errno); return -1; } @@ -946,7 +946,7 @@ bacpy(&addr.rc_bdaddr, &src); addr.rc_channel = (uint8_t) 1; if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - ast_debug(1, "bind() failed (%d).\n", errno); + ast_log(LOG_DEBUG, "bind() failed (%d).\n", errno); close(s); return -1; } @@ -956,7 +956,7 @@ bacpy(&addr.rc_bdaddr, &dst); addr.rc_channel = remote_channel; if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - ast_debug(1, "connect() failed (%d).\n", errno); + ast_log(LOG_DEBUG, "connect() failed (%d).\n", errno); close(s); return -1; } @@ -972,12 +972,12 @@ ssize_t num_write; int len; - ast_debug(1, "rfcomm_write() (%s) [%s]\n", pvt->id, buf); + ast_log(LOG_DEBUG, "rfcomm_write() (%s) [%s]\n", pvt->id, buf); len = strlen(buf); p = buf; while (len > 0) { if ((num_write = write(pvt->rfcomm_socket, p, len)) == -1) { - ast_debug(1, "rfcomm_write() error [%d]\n", errno); + ast_log(LOG_DEBUG, "rfcomm_write() error [%d]\n", errno); return 0; } len -= num_write; @@ -1067,7 +1067,7 @@ int s; if ((s = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO)) < 0) { - ast_debug(1, "socket() failed (%d).\n", errno); + ast_log(LOG_DEBUG, "socket() failed (%d).\n", errno); return -1; } @@ -1075,7 +1075,7 @@ addr.sco_family = AF_BLUETOOTH; bacpy(&addr.sco_bdaddr, &src); if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - ast_debug(1, "bind() failed (%d).\n", errno); + ast_log(LOG_DEBUG, "bind() failed (%d).\n", errno); close(s); return -1; } @@ -1085,7 +1085,7 @@ bacpy(&addr.sco_bdaddr, &dst); if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - ast_debug(1, "sco connect() failed (%d).\n", errno); + ast_log(LOG_DEBUG, "sco connect() failed (%d).\n", errno); close(s); return -1; } @@ -1100,15 +1100,12 @@ int r; if (s == -1) { - ast_debug(2, "sco_write() not ready\n"); return 0; } - ast_debug(2, "sco_write()\n"); - r = write(s, buf, len); if (r == -1) { - ast_debug(1, "sco write error %d\n", errno); + ast_log(LOG_DEBUG, "sco write error %d\n", errno); return 0; } @@ -1122,15 +1119,14 @@ int r; if (s == -1) { - ast_debug(2, "sco_read() not ready\n"); return 0; } - ast_debug(2, "sco_read()\n"); - - r = read(s, buf, len); + //r = read(s, buf, len); + r = recv(s, buf, len, MSG_DONTWAIT); if (r == -1) { - ast_debug(1, "sco_read() error %d\n", errno); + if (errno != EAGAIN) + ast_log(LOG_DEBUG, "sco_read() error %d\n", errno); return 0; } @@ -1160,7 +1156,7 @@ port = 0; session = sdp_connect(BDADDR_ANY, &bdaddr, SDP_RETRY_IF_BUSY); if (!session) { - ast_debug(1, "sdp_connect() failed on device %s.\n", addr); + ast_log(LOG_DEBUG, "sdp_connect() failed on device %s.\n", addr); return 0; } @@ -1180,9 +1176,9 @@ sdp_record_free(sdprec); sdp_list_free(response_list, 0); } else - ast_debug(1, "No responses returned for device %s.\n", addr); + ast_log(LOG_DEBUG, "No responses returned for device %s.\n", addr); } else - ast_debug(1, "sdp_service_search_attr_req() failed on device %s.\n", addr); + ast_log(LOG_DEBUG, "sdp_service_search_attr_req() failed on device %s.\n", addr); sdp_list_free(search_list, 0); sdp_list_free(attrid_list, 0); @@ -1296,7 +1292,7 @@ s = rfcomm_read(pvt, buf, 0, t); if ((s > 0) && (buf[0] != 0x0) && (buf[0] != '\r')) { - ast_debug(1, "rfcomm_read() (%s) [%s]\n", pvt->id, buf); + ast_log(LOG_DEBUG, "rfcomm_read() (%s) [%s]\n", pvt->id, buf); switch (pvt->state) { case MBL_STATE_INIT: if (strstr(buf, "+BRSF:")) { @@ -1337,7 +1333,7 @@ sprintf(pvt->ciev_callsetup_3, "%d,3", callsetupp); if (callsetupp == 0) /* This phone has no call setup indication!! ... */ pvt->no_callsetup = 1; - ast_debug(1, "CIEV_CALL=%d CIEV_CALLSETUP=%d\n", callp, callsetupp); + ast_log(LOG_DEBUG, "CIEV_CALL=%d CIEV_CALLSETUP=%d\n", callp, callsetupp); } if (strstr(buf, "OK")) { rfcomm_write(pvt, "AT+CIND?\r"); @@ -1388,7 +1384,7 @@ case MBL_STATE_PREIDLE: /* Nothing handled here, wait for timeout, then off we go... */ break; case MBL_STATE_IDLE: - ast_debug(1, "Device %s [%s]\n", pvt->id, buf); + ast_log(LOG_DEBUG, "Device %s [%s]\n", pvt->id, buf); if (strstr(buf, "RING")) { pvt->state = MBL_STATE_RING; } else if (strstr(buf, "+CIEV:")) { @@ -1566,7 +1562,7 @@ pvt->state = MBL_STATE_RING2; } else if (pvt->state == MBL_STATE_HANGUP) { if (pvt->hangup_count == 6) { - ast_debug(1, "Device %s failed to hangup after 6 tries, disconnecting.\n", pvt->id); + ast_log(LOG_DEBUG, "Device %s failed to hangup after 6 tries, disconnecting.\n", pvt->id); monitor = 0; } rfcomm_write(pvt, "AT+CHUP\r"); @@ -1637,7 +1633,7 @@ s = rfcomm_read(pvt, buf, 0, t); if ((s > 0) && (buf[0] != 0x0) && (buf[0] != '\r')) { - ast_debug(1, "rfcomm_read() (%s) [%s]\n", pvt->id, buf); + ast_log(LOG_DEBUG, "rfcomm_read() (%s) [%s]\n", pvt->id, buf); switch (pvt->state) { case MBL_STATE_RING2: if (strstr(buf, "AT+CKPD=")) { @@ -1793,15 +1789,15 @@ return NULL; } while (1) { - ast_debug(1, "About to accept() socket.\n"); + ast_log(LOG_DEBUG, "About to accept() socket.\n"); addrlen = sizeof(struct sockaddr_sco); if ((ns = accept(adapter->sco_socket, (struct sockaddr *)&addr, &addrlen)) > -1) { - ast_debug(1, "accept()ed socket.\n"); + ast_log(LOG_DEBUG, "accept()ed socket.\n"); len = sizeof(so); getsockopt(ns, SOL_SCO, SCO_OPTIONS, &so, &len); ba2str(&addr.sco_bdaddr, saddr); - ast_debug(1, "Incoming Audio Connection from device %s MTU is %d\n", saddr, so.mtu); + ast_log(LOG_DEBUG, "Incoming Audio Connection from device %s MTU is %d\n", saddr, so.mtu); pvt = NULL; AST_LIST_TRAVERSE(&devices, pvt, entry) { @@ -1813,7 +1809,7 @@ close(pvt->sco_socket); pvt->sco_socket = ns; } else - ast_debug(1, "Could not find device for incoming Audio Connection.\n"); + ast_log(LOG_DEBUG, "Could not find device for incoming Audio Connection.\n"); } else { ast_log(LOG_ERROR, "accept() failed %d\n", errno); } @@ -1841,9 +1837,8 @@ uint16_t vs; struct hci_dev_req dr; char nadapters = 0; - struct ast_flags config_flags = { 0 }; - cfg = ast_config_load(MBL_CONFIG, config_flags); + cfg = ast_config_load(MBL_CONFIG); if (!cfg) return 0; @@ -1860,7 +1855,7 @@ address = ast_variable_retrieve(cfg, cat, "address"); master = ast_variable_retrieve(cfg, cat, "forcemaster"); aligndetect = ast_variable_retrieve(cfg, cat, "alignmentdetection"); - ast_debug(1, "Loading adapter %s %s.\n", id, address); + ast_log(LOG_DEBUG, "Loading adapter %s %s.\n", id, address); if (!ast_strlen_zero(id) && !ast_strlen_zero(address)) { if ((adapter = ast_malloc(sizeof(struct adapter_pvt)))) { ast_copy_string(adapter->id, id, sizeof(adapter->id)); @@ -1913,7 +1908,7 @@ cat = ast_category_browse(cfg, NULL); while (cat) { if (strcasecmp(cat, "general") && strcasecmp(cat, "adapter")) { - ast_debug(1, "Loading device %s.\n", cat); + ast_log(LOG_DEBUG, "Loading device %s.\n", cat); address = ast_variable_retrieve(cfg, cat, "address"); useadapter = ast_variable_retrieve(cfg, cat, "adapter"); port = ast_variable_retrieve(cfg, cat, "port"); @@ -1957,7 +1952,7 @@ if (!ast_strlen_zero(nocallsetup)) { if ((*nocallsetup == 'y') || (*nocallsetup == 'Y')) { pvt->no_callsetup = 1; - ast_debug(1, "Setting nocallsetup mode for device %s.\n", pvt->id); + ast_log(LOG_DEBUG, "Setting nocallsetup mode for device %s.\n", pvt->id); } } pvt->has_sms = 0;