#include <string.h>
#include "bta_dm_int.h"
#include "l2c_api.h"
+#include <cutils/properties.h>
/*****************************************************************************
** Constants
void bta_ag_start_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
{
BD_ADDR pending_bd_addr;
+ tBTA_AG_RFC *p_buf;
/* store parameters */
if (p_data)
/* Check if RFCOMM has any incoming connection to avoid collision. */
if (PORT_IsOpening (pending_bd_addr))
{
+ char value[PROPERTY_VALUE_MAX];
+ if (property_get("persist.bt.max.hs.connections", value, "") &&
+ !strcmp(value, "2") )
+ {
+ // Abort the outgoing connection if incoming connection is from the same device
+ if (bdcmp (pending_bd_addr, p_scb->peer_addr) == 0)
+ {
+ APPL_TRACE_WARNING("%s: p_scb %x, abort outgoing conn, there is"\
+ " an incoming conn from dev %x:%x:%x:%x:%x:%x", __func__,
+ p_scb, p_scb->peer_addr[0], p_scb->peer_addr[1],
+ p_scb->peer_addr[2], p_scb->peer_addr[3], p_scb->peer_addr[4],
+ p_scb->peer_addr[5]);
+ // send ourselves close event for clean up
+ p_buf = (tBTA_AG_RFC *) osi_malloc(sizeof(tBTA_AG_RFC));
+ p_buf->hdr.event = BTA_AG_RFC_CLOSE_EVT;
+ p_buf->hdr.layer_specific = bta_ag_scb_to_idx(p_scb);
+ bta_sys_sendmsg(p_buf);
+ return;
+ }
+ }
/* Let the incoming connection goes through. */
/* Issue collision for this scb for now. */
/* We will decide what to do when we find incoming connetion later. */
tBTA_AG_SCB *ag_scb, *other_scb;
BD_ADDR dev_addr;
int status;
+ tBTA_AG_RFC *p_buf;
/* set role */
p_scb->role = BTA_AG_ACP;
if (bdcmp (dev_addr, ag_scb->peer_addr) == 0)
{
- /* If incoming and outgoing device are same, nothing more to do. */
- /* Outgoing conn will be aborted because we have successful incoming conn. */
+ char value[PROPERTY_VALUE_MAX];
+ /* Read the property if multi hf is enabled */
+ if (property_get("persist.bt.max.hs.connections", value, "") &&
+ !strcmp(value, "2") )
+ {
+ /* If incoming and outgoing device are same, nothing more to do. */
+ /* Outgoing conn will be aborted because we have successful incoming conn. */
+ APPL_TRACE_WARNING("%s: p_scb %x, abort outgoing conn,"\
+ "there is an incoming conn from dev %x:%x:%x:%x:%x:%x",
+ __func__, ag_scb, dev_addr[0], dev_addr[1], dev_addr[2],
+ dev_addr[3], dev_addr[4], dev_addr[5]);
+ if (ag_scb->conn_handle)
+ {
+ RFCOMM_RemoveConnection(ag_scb->conn_handle);
+ }
+
+ // send ourselves close event for clean up
+ // move back to OPENING state from INIT state so that clean up is done
+ ag_scb->state = 1;
+ p_buf = (tBTA_AG_RFC *) osi_malloc(sizeof(tBTA_AG_RFC));
+ p_buf->hdr.event = BTA_AG_RFC_CLOSE_EVT;
+ p_buf->hdr.layer_specific = bta_ag_scb_to_idx(ag_scb);
+ bta_sys_sendmsg(p_buf);
+ }
}
else
{
int i;
for (i = 0; i < btif_max_hf_clients; ++i)
{
- if ((bdcmp(bd_addr->address,
+ if (is_connected(bd_addr) && (bdcmp(bd_addr->address,
btif_hf_cb[i].connected_bda.address) == 0))
return i;
}
return BT_STATUS_FAIL;
}
- if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX))
+ if (idx != BTIF_HF_INVALID_IDX)
{
BTA_AgClose(btif_hf_cb[idx].handle);
return BT_STATUS_SUCCESS;
if (btif_hf_check_if_slc_connected() != BT_STATUS_SUCCESS)
return BT_STATUS_NOT_READY;
- if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX))
+ if (idx != BTIF_HF_INVALID_IDX)
{
BTA_AgAudioOpen(btif_hf_cb[idx].handle);
return BT_STATUS_FAIL;
}
- if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX))
+ if (idx != BTIF_HF_INVALID_IDX)
{
BTA_AgAudioClose(btif_hf_cb[idx].handle);
return BT_STATUS_SUCCESS;
tBTA_AG_RES_DATA ag_res;
memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA));
- if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX))
+ if (idx != BTIF_HF_INVALID_IDX)
{
ag_res.num = volume;
BTA_AgResult(btif_hf_cb[idx].handle,
return BT_STATUS_FAIL;
}
- if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX))
+ if (idx != BTIF_HF_INVALID_IDX)
{
tBTA_AG_RES_DATA ag_res;
return BT_STATUS_FAIL;
}
- if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX))
+ if (idx != BTIF_HF_INVALID_IDX)
{
tBTA_AG_RES_DATA ag_res;
return BT_STATUS_FAIL;
}
- if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX))
+ if (idx != BTIF_HF_INVALID_IDX)
{
/* Format the response and send */
memset (&ag_res, 0, sizeof (ag_res));
return BT_STATUS_FAIL;
}
- if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX))
+ if (idx != BTIF_HF_INVALID_IDX)
{
send_at_result((response_code == BTHF_AT_RESPONSE_OK) ? BTA_AG_OK_DONE
: BTA_AG_OK_ERROR, error_code, idx);
return BT_STATUS_FAIL;
}
- if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX))
+ if (idx != BTIF_HF_INVALID_IDX)
{
tBTA_AG_RES_DATA ag_res;
int xx;