Loading system/btif/src/btif_sock_rfc.cc +97 −110 Original line number Diff line number Diff line Loading @@ -489,15 +489,12 @@ static void on_cl_rfc_init(tBTA_JV_RFCOMM_CL_INIT* p_init, uint32_t id) { if (!slot) { LOG_ERROR("RFCOMM slot with id %u not found. p_init->status=%u", id, p_init->status); return; } if (p_init->status == BTA_JV_SUCCESS) { slot->rfc_handle = p_init->handle; } else { } else if (p_init->status != BTA_JV_SUCCESS) { LOG_WARN("INIT unsuccessful, status %u. Cleaning up slot with id %u", p_init->status, slot->id); cleanup_rfc_slot(slot); } else { slot->rfc_handle = p_init->handle; } } Loading @@ -508,26 +505,24 @@ static void on_srv_rfc_listen_started(tBTA_JV_RFCOMM_START* p_start, if (!slot) { LOG_ERROR("RFCOMM slot with id %u not found", id); return; } else if (p_start->status != BTA_JV_SUCCESS) { LOG_WARN("START unsuccessful, status %u. Cleaning up slot with id %u", p_start->status, slot->id); cleanup_rfc_slot(slot); return; } if (p_start->status == BTA_JV_SUCCESS) { slot->rfc_handle = p_start->handle; btif_sock_connection_logger( SOCKET_CONNECTION_STATE_LISTENING, slot->f.server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, slot->addr); log_socket_connection_state( slot->addr, slot->id, BTSOCK_RFCOMM, slot->f.server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, slot->addr); log_socket_connection_state(slot->addr, slot->id, BTSOCK_RFCOMM, android::bluetooth::SocketConnectionstateEnum:: SOCKET_CONNECTION_STATE_LISTENING, 0, 0, slot->app_uid, slot->scn, slot->f.server ? android::bluetooth::SOCKET_ROLE_LISTEN slot->f.server ? android::bluetooth::SOCKET_ROLE_LISTEN : android::bluetooth::SOCKET_ROLE_CONNECTION); } else { LOG_WARN("START unsuccessful, status %u. Cleaning up slot with id %u", p_start->status, slot->id); cleanup_rfc_slot(slot); } } static uint32_t on_srv_rfc_connect(tBTA_JV_RFCOMM_SRV_OPEN* p_open, Loading Loading @@ -609,7 +604,10 @@ static void on_rfc_close(UNUSED_ATTR tBTA_JV_RFCOMM_CLOSE* p_close, // rfc_handle already closed when receiving rfcomm close event from stack. rfc_slot_t* slot = find_rfc_slot_by_id(id); if (slot) { if (!slot) { LOG_WARN("RFCOMM slot with id %u not found.", id); return; } log_socket_connection_state( slot->addr, slot->id, BTSOCK_RFCOMM, android::bluetooth::SOCKET_CONNECTION_STATE_DISCONNECTING, 0, 0, Loading @@ -617,9 +615,6 @@ static void on_rfc_close(UNUSED_ATTR tBTA_JV_RFCOMM_CLOSE* p_close, slot->f.server ? android::bluetooth::SOCKET_ROLE_LISTEN : android::bluetooth::SOCKET_ROLE_CONNECTION); cleanup_rfc_slot(slot); } else { LOG_WARN("RFCOMM slot with id %u not found.", id); } } static void on_rfc_write_done(tBTA_JV_RFCOMM_WRITE* p, uint32_t id) { Loading @@ -633,17 +628,15 @@ static void on_rfc_write_done(tBTA_JV_RFCOMM_WRITE* p, uint32_t id) { std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* slot = find_rfc_slot_by_id(id); if (slot) { if (!slot) { LOG_ERROR("RFCOMM slot with id %u not found.", id); return; } app_uid = slot->app_uid; if (!slot->f.outgoing_congest) { if (!slot->f.outgoing_congest) btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_RD, slot->id); } slot->tx_bytes += p->len; } else { LOG_ERROR("RFCOMM slot with id %u not found.", id); } uid_set_add_tx(uid_set, app_uid, p->len); } Loading @@ -651,14 +644,15 @@ static void on_rfc_outgoing_congest(tBTA_JV_RFCOMM_CONG* p, uint32_t id) { std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* slot = find_rfc_slot_by_id(id); if (slot) { if (!slot) { LOG_ERROR("RFCOMM slot with id %u not found.", id); return; } slot->f.outgoing_congest = p->cong ? 1 : 0; if (!slot->f.outgoing_congest) btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_RD, slot->id); } else { LOG_ERROR("RFCOMM slot with id %u not found.", id); } } static uint32_t rfcomm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, Loading Loading @@ -719,46 +713,39 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) { rfc_slot_t* rs = find_rfc_slot_by_id(id); int new_scn = p_data->scn; if (rs && (new_scn != 0)) { if (!rs) { LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event); break; } else if (new_scn == 0) { LOG_ERROR( "Unable to allocate scn: all resources exhausted. slot found:%p", rs); cleanup_rfc_slot(rs); break; } rs->scn = new_scn; /* BTA_JvCreateRecordByUser will only create a record if a UUID is * specified, * else it just allocate a RFC channel and start the RFCOMM thread - * needed * for the java * layer to get a RFCOMM channel. * If uuid is null the create_sdp_record() will be called from Java when * it * has received the RFCOMM and L2CAP channel numbers through the * sockets.*/ // Send channel ID to java layer if (!send_app_scn(rs)) { // closed APPL_TRACE_DEBUG("send_app_scn() failed, close rs->id:%d", rs->id); LOG_DEBUG("send_app_scn() failed, closing rs->id:%d", rs->id); cleanup_rfc_slot(rs); } else { if (rs->is_service_uuid_valid) { // We already have data for SDP record, create it (RFC-only // profiles) BTA_JvCreateRecordByUser(rs->id); } else { APPL_TRACE_DEBUG( "is_service_uuid_valid==false - don't set SDP-record, " "just start the RFCOMM server", rs->id); } else if (!rs->is_service_uuid_valid) { /* If uuid is null, just allocate a RFC channel and start the RFCOMM * thread needed for the java layer to get a RFCOMM channel. * create_sdp_record() will be called from Java when it has received the * RFCOMM and L2CAP channel numbers through the sockets.*/ LOG_DEBUG( "is_service_uuid_valid==false - not setting SDP-record and just " "starting " "the RFCOMM server"); // now start the rfcomm server after sdp & channel # assigned BTA_JvRfcommStartServer(rs->security, rs->role, rs->scn, MAX_RFC_SESSION, rfcomm_cback, rs->id); } } } else if (rs) { APPL_TRACE_ERROR( "jv_dm_cback: Error: allocate channel %d, slot found:%p", rs->scn, rs); cleanup_rfc_slot(rs); } else { LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event); // BTA_JvCreateRecordByUser will only create a record if a UUID is // specified. RFC-only profiles BTA_JvCreateRecordByUser(rs->id); } break; } Loading @@ -771,16 +758,16 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) { std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* slot = find_rfc_slot_by_id(id); if (slot && create_server_sdp_record(slot)) { if (!slot) { LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event); } else if (create_server_sdp_record(slot)) { // Start the rfcomm server after sdp & channel # assigned. BTA_JvRfcommStartServer(slot->security, slot->role, slot->scn, MAX_RFC_SESSION, rfcomm_cback, slot->id); } else if (slot) { } else { APPL_TRACE_ERROR("jv_dm_cback: cannot start server, slot found:%p", slot); cleanup_rfc_slot(slot); } else { LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event); } break; } Loading @@ -788,31 +775,31 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) { case BTA_JV_DISCOVERY_COMP_EVT: { std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* slot = find_rfc_slot_by_id(id); if (p_data->disc_comp.status == BTA_JV_SUCCESS && p_data->disc_comp.scn) { if (slot && slot->f.doing_sdp_request) { // Establish the connection if we successfully looked up a channel // number to connect to. if (BTA_JvRfcommConnect(slot->security, slot->role, p_data->disc_comp.scn, slot->addr, rfcomm_cback, slot->id) == BTA_JV_SUCCESS) { slot->scn = p_data->disc_comp.scn; slot->f.doing_sdp_request = false; if (!send_app_scn(slot)) cleanup_rfc_slot(slot); } else { cleanup_rfc_slot(slot); } } else if (slot) { if (!slot) { LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event); } else if (!slot->f.doing_sdp_request) { // TODO(sharvil): this is really a logic error and we should probably // assert. LOG_ERROR( "%s SDP response returned but RFCOMM slot %d did not " "request SDP record.", __func__, id); } } else if (slot) { "SDP response returned but RFCOMM slot %d did not request SDP " "record.", id); } else if (p_data->disc_comp.status != BTA_JV_SUCCESS || !p_data->disc_comp.scn) { cleanup_rfc_slot(slot); } else if (BTA_JvRfcommConnect( slot->security, slot->role, p_data->disc_comp.scn, slot->addr, rfcomm_cback, slot->id) != BTA_JV_SUCCESS) { LOG_WARN("BTA_JvRfcommConnect() returned BTA_JV_FAILURE"); cleanup_rfc_slot(slot); } else { LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event); // Establish the connection if we successfully looked up a channel // number to connect to slot->scn = p_data->disc_comp.scn; slot->f.doing_sdp_request = false; if (!send_app_scn(slot)) { cleanup_rfc_slot(slot); } } // Find the next slot that needs to perform an SDP request and service it. Loading Loading
system/btif/src/btif_sock_rfc.cc +97 −110 Original line number Diff line number Diff line Loading @@ -489,15 +489,12 @@ static void on_cl_rfc_init(tBTA_JV_RFCOMM_CL_INIT* p_init, uint32_t id) { if (!slot) { LOG_ERROR("RFCOMM slot with id %u not found. p_init->status=%u", id, p_init->status); return; } if (p_init->status == BTA_JV_SUCCESS) { slot->rfc_handle = p_init->handle; } else { } else if (p_init->status != BTA_JV_SUCCESS) { LOG_WARN("INIT unsuccessful, status %u. Cleaning up slot with id %u", p_init->status, slot->id); cleanup_rfc_slot(slot); } else { slot->rfc_handle = p_init->handle; } } Loading @@ -508,26 +505,24 @@ static void on_srv_rfc_listen_started(tBTA_JV_RFCOMM_START* p_start, if (!slot) { LOG_ERROR("RFCOMM slot with id %u not found", id); return; } else if (p_start->status != BTA_JV_SUCCESS) { LOG_WARN("START unsuccessful, status %u. Cleaning up slot with id %u", p_start->status, slot->id); cleanup_rfc_slot(slot); return; } if (p_start->status == BTA_JV_SUCCESS) { slot->rfc_handle = p_start->handle; btif_sock_connection_logger( SOCKET_CONNECTION_STATE_LISTENING, slot->f.server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, slot->addr); log_socket_connection_state( slot->addr, slot->id, BTSOCK_RFCOMM, slot->f.server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, slot->addr); log_socket_connection_state(slot->addr, slot->id, BTSOCK_RFCOMM, android::bluetooth::SocketConnectionstateEnum:: SOCKET_CONNECTION_STATE_LISTENING, 0, 0, slot->app_uid, slot->scn, slot->f.server ? android::bluetooth::SOCKET_ROLE_LISTEN slot->f.server ? android::bluetooth::SOCKET_ROLE_LISTEN : android::bluetooth::SOCKET_ROLE_CONNECTION); } else { LOG_WARN("START unsuccessful, status %u. Cleaning up slot with id %u", p_start->status, slot->id); cleanup_rfc_slot(slot); } } static uint32_t on_srv_rfc_connect(tBTA_JV_RFCOMM_SRV_OPEN* p_open, Loading Loading @@ -609,7 +604,10 @@ static void on_rfc_close(UNUSED_ATTR tBTA_JV_RFCOMM_CLOSE* p_close, // rfc_handle already closed when receiving rfcomm close event from stack. rfc_slot_t* slot = find_rfc_slot_by_id(id); if (slot) { if (!slot) { LOG_WARN("RFCOMM slot with id %u not found.", id); return; } log_socket_connection_state( slot->addr, slot->id, BTSOCK_RFCOMM, android::bluetooth::SOCKET_CONNECTION_STATE_DISCONNECTING, 0, 0, Loading @@ -617,9 +615,6 @@ static void on_rfc_close(UNUSED_ATTR tBTA_JV_RFCOMM_CLOSE* p_close, slot->f.server ? android::bluetooth::SOCKET_ROLE_LISTEN : android::bluetooth::SOCKET_ROLE_CONNECTION); cleanup_rfc_slot(slot); } else { LOG_WARN("RFCOMM slot with id %u not found.", id); } } static void on_rfc_write_done(tBTA_JV_RFCOMM_WRITE* p, uint32_t id) { Loading @@ -633,17 +628,15 @@ static void on_rfc_write_done(tBTA_JV_RFCOMM_WRITE* p, uint32_t id) { std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* slot = find_rfc_slot_by_id(id); if (slot) { if (!slot) { LOG_ERROR("RFCOMM slot with id %u not found.", id); return; } app_uid = slot->app_uid; if (!slot->f.outgoing_congest) { if (!slot->f.outgoing_congest) btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_RD, slot->id); } slot->tx_bytes += p->len; } else { LOG_ERROR("RFCOMM slot with id %u not found.", id); } uid_set_add_tx(uid_set, app_uid, p->len); } Loading @@ -651,14 +644,15 @@ static void on_rfc_outgoing_congest(tBTA_JV_RFCOMM_CONG* p, uint32_t id) { std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* slot = find_rfc_slot_by_id(id); if (slot) { if (!slot) { LOG_ERROR("RFCOMM slot with id %u not found.", id); return; } slot->f.outgoing_congest = p->cong ? 1 : 0; if (!slot->f.outgoing_congest) btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_RD, slot->id); } else { LOG_ERROR("RFCOMM slot with id %u not found.", id); } } static uint32_t rfcomm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, Loading Loading @@ -719,46 +713,39 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) { rfc_slot_t* rs = find_rfc_slot_by_id(id); int new_scn = p_data->scn; if (rs && (new_scn != 0)) { if (!rs) { LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event); break; } else if (new_scn == 0) { LOG_ERROR( "Unable to allocate scn: all resources exhausted. slot found:%p", rs); cleanup_rfc_slot(rs); break; } rs->scn = new_scn; /* BTA_JvCreateRecordByUser will only create a record if a UUID is * specified, * else it just allocate a RFC channel and start the RFCOMM thread - * needed * for the java * layer to get a RFCOMM channel. * If uuid is null the create_sdp_record() will be called from Java when * it * has received the RFCOMM and L2CAP channel numbers through the * sockets.*/ // Send channel ID to java layer if (!send_app_scn(rs)) { // closed APPL_TRACE_DEBUG("send_app_scn() failed, close rs->id:%d", rs->id); LOG_DEBUG("send_app_scn() failed, closing rs->id:%d", rs->id); cleanup_rfc_slot(rs); } else { if (rs->is_service_uuid_valid) { // We already have data for SDP record, create it (RFC-only // profiles) BTA_JvCreateRecordByUser(rs->id); } else { APPL_TRACE_DEBUG( "is_service_uuid_valid==false - don't set SDP-record, " "just start the RFCOMM server", rs->id); } else if (!rs->is_service_uuid_valid) { /* If uuid is null, just allocate a RFC channel and start the RFCOMM * thread needed for the java layer to get a RFCOMM channel. * create_sdp_record() will be called from Java when it has received the * RFCOMM and L2CAP channel numbers through the sockets.*/ LOG_DEBUG( "is_service_uuid_valid==false - not setting SDP-record and just " "starting " "the RFCOMM server"); // now start the rfcomm server after sdp & channel # assigned BTA_JvRfcommStartServer(rs->security, rs->role, rs->scn, MAX_RFC_SESSION, rfcomm_cback, rs->id); } } } else if (rs) { APPL_TRACE_ERROR( "jv_dm_cback: Error: allocate channel %d, slot found:%p", rs->scn, rs); cleanup_rfc_slot(rs); } else { LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event); // BTA_JvCreateRecordByUser will only create a record if a UUID is // specified. RFC-only profiles BTA_JvCreateRecordByUser(rs->id); } break; } Loading @@ -771,16 +758,16 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) { std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* slot = find_rfc_slot_by_id(id); if (slot && create_server_sdp_record(slot)) { if (!slot) { LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event); } else if (create_server_sdp_record(slot)) { // Start the rfcomm server after sdp & channel # assigned. BTA_JvRfcommStartServer(slot->security, slot->role, slot->scn, MAX_RFC_SESSION, rfcomm_cback, slot->id); } else if (slot) { } else { APPL_TRACE_ERROR("jv_dm_cback: cannot start server, slot found:%p", slot); cleanup_rfc_slot(slot); } else { LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event); } break; } Loading @@ -788,31 +775,31 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) { case BTA_JV_DISCOVERY_COMP_EVT: { std::unique_lock<std::recursive_mutex> lock(slot_lock); rfc_slot_t* slot = find_rfc_slot_by_id(id); if (p_data->disc_comp.status == BTA_JV_SUCCESS && p_data->disc_comp.scn) { if (slot && slot->f.doing_sdp_request) { // Establish the connection if we successfully looked up a channel // number to connect to. if (BTA_JvRfcommConnect(slot->security, slot->role, p_data->disc_comp.scn, slot->addr, rfcomm_cback, slot->id) == BTA_JV_SUCCESS) { slot->scn = p_data->disc_comp.scn; slot->f.doing_sdp_request = false; if (!send_app_scn(slot)) cleanup_rfc_slot(slot); } else { cleanup_rfc_slot(slot); } } else if (slot) { if (!slot) { LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event); } else if (!slot->f.doing_sdp_request) { // TODO(sharvil): this is really a logic error and we should probably // assert. LOG_ERROR( "%s SDP response returned but RFCOMM slot %d did not " "request SDP record.", __func__, id); } } else if (slot) { "SDP response returned but RFCOMM slot %d did not request SDP " "record.", id); } else if (p_data->disc_comp.status != BTA_JV_SUCCESS || !p_data->disc_comp.scn) { cleanup_rfc_slot(slot); } else if (BTA_JvRfcommConnect( slot->security, slot->role, p_data->disc_comp.scn, slot->addr, rfcomm_cback, slot->id) != BTA_JV_SUCCESS) { LOG_WARN("BTA_JvRfcommConnect() returned BTA_JV_FAILURE"); cleanup_rfc_slot(slot); } else { LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event); // Establish the connection if we successfully looked up a channel // number to connect to slot->scn = p_data->disc_comp.scn; slot->f.doing_sdp_request = false; if (!send_app_scn(slot)) { cleanup_rfc_slot(slot); } } // Find the next slot that needs to perform an SDP request and service it. Loading