******************************************************************************/
void bta_ag_start_open(tBTA_AG_SCB* p_scb, const tBTA_AG_DATA& data) {
p_scb->peer_addr = data.api_open.bd_addr;
- p_scb->open_services = data.api_open.services;
p_scb->cli_sec_mask = data.api_open.sec_mask;
+ p_scb->open_services = p_scb->reg_services;
/* Check if RFCOMM has any incoming connection to avoid collision. */
RawAddress pending_bd_addr = RawAddress::kEmpty;
* Returns void
*
******************************************************************************/
-void BTA_AgOpen(uint16_t handle, const RawAddress& bd_addr, tBTA_SEC sec_mask,
- tBTA_SERVICE_MASK services) {
+void BTA_AgOpen(uint16_t handle, const RawAddress& bd_addr, tBTA_SEC sec_mask) {
tBTA_AG_DATA data = {};
data.api_open.bd_addr = bd_addr;
- data.api_open.services = services;
data.api_open.sec_mask = sec_mask;
do_in_bta_thread(FROM_HERE, base::Bind(&bta_ag_sm_execute_by_handle, handle,
BTA_AG_API_OPEN_EVT, data));
LOG(INFO) << __func__ << ": Resume connection to " << p_scb->peer_addr
<< ", handle" << bta_ag_scb_to_idx(p_scb);
tBTA_AG_DATA open_data = {.api_open.bd_addr = p_scb->peer_addr,
- .api_open.services = p_scb->open_services,
.api_open.sec_mask = p_scb->cli_sec_mask};
bta_ag_sm_execute(p_scb, BTA_AG_API_OPEN_EVT, open_data);
} else {
******************************************************************************/
static bt_status_t connect_int(RawAddress* bd_addr, uint16_t uuid) {
CHECK_BTHF_INIT();
- int i;
- for (i = 0; i < btif_max_hf_clients;) {
- if (((btif_hf_cb[i].state == BTHF_CONNECTION_STATE_CONNECTED) ||
- (btif_hf_cb[i].state == BTHF_CONNECTION_STATE_SLC_CONNECTED))) {
- i++;
- } else {
+ if (is_connected(bd_addr)) {
+ BTIF_TRACE_WARNING("%s: device %s is already connected", __func__,
+ bd_addr->ToString().c_str());
+ return BT_STATUS_BUSY;
+ }
+ btif_hf_cb_t* hf_cb = nullptr;
+ for (int i = 0; i < btif_max_hf_clients; i++) {
+ if (btif_hf_cb[i].state == BTHF_CONNECTION_STATE_DISCONNECTED) {
+ hf_cb = &btif_hf_cb[i];
break;
}
+ // Due to btif queue implementation, when connect_int is called, no btif
+ // control block should be in connecting state
+ // Crash here to prevent future code changes from breaking this mechanism
+ if (btif_hf_cb[i].state == BTHF_CONNECTION_STATE_CONNECTING) {
+ LOG(FATAL) << __func__ << ": " << btif_hf_cb[i].connected_bda
+ << ", handle " << btif_hf_cb[i].handle
+ << ", is still in connecting state " << btif_hf_cb[i].state;
+ }
}
-
- if (i == btif_max_hf_clients) {
+ if (hf_cb == nullptr) {
BTIF_TRACE_WARNING(
"%s: Cannot connect %s: maximum %d clients already connected", __func__,
bd_addr->ToString().c_str(), btif_max_hf_clients);
return BT_STATUS_BUSY;
}
- if (is_connected(bd_addr)) {
- BTIF_TRACE_WARNING("%s: device %s is already connected", __func__,
- bd_addr->ToString().c_str());
- return BT_STATUS_BUSY;
- }
-
- btif_hf_cb[i].state = BTHF_CONNECTION_STATE_CONNECTING;
- btif_hf_cb[i].connected_bda = *bd_addr;
-
- BTA_AgOpen(btif_hf_cb[i].handle, btif_hf_cb[i].connected_bda,
- BTIF_HF_SECURITY, BTIF_HF_SERVICES);
+ hf_cb->state = BTHF_CONNECTION_STATE_CONNECTING;
+ hf_cb->connected_bda = *bd_addr;
+ BTA_AgOpen(hf_cb->handle, hf_cb->connected_bda, BTIF_HF_SECURITY);
return BT_STATUS_SUCCESS;
}