summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarish Paryani <hparyani@broadcom.com>2012-03-07 16:36:03 -0800
committerMatthew Xie <mattx@google.com>2012-07-14 11:19:12 -0700
commit17706aa42214addb95ee4aea5177a8784960dfc1 (patch)
tree24ba3487fc2e4fed27e76043608e0a94451ce2b5
parentc625f0b1c42a6451796cd6867e2769cd0db28d93 (diff)
downloadexternal_bluetooth_bluedroid-17706aa42214addb95ee4aea5177a8784960dfc1.zip
external_bluetooth_bluedroid-17706aa42214addb95ee4aea5177a8784960dfc1.tar.gz
external_bluetooth_bluedroid-17706aa42214addb95ee4aea5177a8784960dfc1.tar.bz2
Disconnect before Unpair
Change-Id: Ib28372748df21d36d371d308975758f60df7aa28
-rwxr-xr-x[-rw-r--r--]bta/dm/bta_dm_act.c60
-rwxr-xr-x[-rw-r--r--]bta/dm/bta_dm_api.c24
-rwxr-xr-x[-rw-r--r--]bta/dm/bta_dm_int.h15
-rwxr-xr-x[-rw-r--r--]bta/dm/bta_dm_main.c2
-rwxr-xr-x[-rw-r--r--]bta/include/bta_api.h1
-rwxr-xr-x[-rw-r--r--]btif/include/btif_common.h1
-rwxr-xr-x[-rw-r--r--]btif/src/btif_dm.c29
7 files changed, 87 insertions, 45 deletions
diff --git a/bta/dm/bta_dm_act.c b/bta/dm/bta_dm_act.c
index 0f1875a..30a77e3 100644..100755
--- a/bta/dm/bta_dm_act.c
+++ b/bta/dm/bta_dm_act.c
@@ -607,6 +607,42 @@ void bta_dm_tx_inqpower(tBTA_DM_MSG *p_data)
/*******************************************************************************
**
+** Function bta_dm_remove_device
+**
+** Description Removes device, Disconnects ACL link if required.
+****
+*******************************************************************************/
+void bta_dm_remove_device (tBTA_DM_MSG *p_data)
+{
+ tBTA_DM_API_REMOVE_DEVICE *p_dev = &p_data->remove_dev;
+ int i;
+
+ if (BTM_IsAclConnectionUp(p_dev->bd_addr))
+ {
+ /* Take the link down first, and mark the device for removal when disconnected */
+ btm_remove_acl( p_dev->bd_addr) ;
+
+ for(i=0; i<bta_dm_cb.device_list.count; i++)
+ {
+ if(!bdcmp( bta_dm_cb.device_list.peer_device[i].peer_bdaddr, p_dev->bd_addr))
+ break;
+ }
+
+ if(i < bta_dm_cb.device_list.count)
+ {
+ bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_UNPAIRING;
+ }
+ }
+ else /* Ok to remove the device in application layer */
+ {
+ BTM_SecDeleteDevice(p_dev->bd_addr);
+ if( bta_dm_cb.p_sec_cback )
+ bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, p_dev->bd_addr);
+ }
+}
+
+/*******************************************************************************
+**
** Function bta_dm_add_device
**
** Description This function adds a Link Key to an security database entry.
@@ -3080,6 +3116,7 @@ void bta_dm_acl_change(tBTA_DM_MSG *p_data)
BOOLEAN is_new = p_data->acl_change.is_new;
BD_ADDR_PTR p_bda = p_data->acl_change.bd_addr;
BOOLEAN need_policy_change = FALSE;
+ BOOLEAN issue_unpair_cb = FALSE;
#if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
tBTA_DM_PEER_DEVICE *p_dev;
@@ -3181,18 +3218,20 @@ void bta_dm_acl_change(tBTA_DM_MSG *p_data)
if(bdcmp( bta_dm_cb.device_list.peer_device[i].peer_bdaddr, p_bda))
continue;
- for(; i<bta_dm_cb.device_list.count ; i++)
+ if( bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_UNPAIRING )
{
+ BTM_SecDeleteDevice(bta_dm_cb.device_list.peer_device[i].peer_bdaddr);
+ issue_unpair_cb = TRUE;
+ }
+ for(; i<bta_dm_cb.device_list.count ; i++)
+ {
memcpy(&bta_dm_cb.device_list.peer_device[i], &bta_dm_cb.device_list.peer_device[i+1], sizeof(bta_dm_cb.device_list.peer_device[i]));
-
- }
-
+ }
break;
-
}
if(bta_dm_cb.device_list.count)
- bta_dm_cb.device_list.count--;
+ bta_dm_cb.device_list.count--;
if(bta_dm_search_cb.wait_disc && !bdcmp(bta_dm_search_cb.peer_bdaddr, p_bda))
{
@@ -3209,22 +3248,23 @@ void bta_dm_acl_change(tBTA_DM_MSG *p_data)
if(bta_dm_cb.disabling)
{
-
if(!BTM_GetNumAclLinks())
{
bta_sys_stop_timer(&bta_dm_cb.disable_timer);
bta_dm_cb.disable_timer.p_cback = (TIMER_CBACK*)&bta_dm_disable_conn_down_timer_cback;
- /* start a timer to make sure that the profiles
- get the disconnect event */
+ /* start a timer to make sure that the profiles get the disconnect event */
bta_sys_start_timer(&bta_dm_cb.disable_timer, 0, 1000);
}
-
}
bdcpy(conn.link_down.bd_addr, p_bda);
conn.link_down.status = (UINT8) btm_get_acl_disc_reason_code();
if( bta_dm_cb.p_sec_cback )
+ {
bta_dm_cb.p_sec_cback(BTA_DM_LINK_DOWN_EVT, (tBTA_DM_SEC *)&conn);
+ if( issue_unpair_cb )
+ bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, (tBTA_DM_SEC *)&conn);
+ }
}
bta_dm_adjust_roles();
diff --git a/bta/dm/bta_dm_api.c b/bta/dm/bta_dm_api.c
index 97e4777..d798f5c 100644..100755
--- a/bta/dm/bta_dm_api.c
+++ b/bta/dm/bta_dm_api.c
@@ -734,26 +734,22 @@ void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
*******************************************************************************/
tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr)
{
+ tBTA_DM_API_REMOVE_DEVICE *p_msg;
- BOOLEAN device_ok_to_remove = TRUE;
-
- GKI_sched_lock();
-
- if (BTM_IsAclConnectionUp(bd_addr))
+ if ((p_msg = (tBTA_DM_API_REMOVE_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_REMOVE_DEVICE))) != NULL)
{
- /* Don't allow deletion while connection is active */
- device_ok_to_remove = FALSE;
+ memset (p_msg, 0, sizeof(tBTA_DM_API_REMOVE_DEVICE));
+
+ p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
+ bdcpy(p_msg->bd_addr, bd_addr);
+ bta_sys_sendmsg(p_msg);
}
- else /* Ok to remove the device in application layer */
+ else
{
- BTM_SecDeleteDevice(bd_addr);
+ return BTA_FAILURE;
}
- GKI_sched_unlock();
- if(device_ok_to_remove)
- return BTA_SUCCESS;
- else
- return BTA_FAILURE;
+ return BTA_SUCCESS;
}
/*******************************************************************************
diff --git a/bta/dm/bta_dm_int.h b/bta/dm/bta_dm_int.h
index 5f1da2a..6d220e7 100644..100755
--- a/bta/dm/bta_dm_int.h
+++ b/bta/dm/bta_dm_int.h
@@ -74,6 +74,8 @@ enum
BTA_DM_CI_RMT_OOB_EVT,
#endif /* BTM_OOB_INCLUDED */
+ BTA_DM_API_REMOVE_DEVICE_EVT,
+
#if BLE_INCLUDED == TRUE
BTA_DM_API_ADD_BLEKEY_EVT,
BTA_DM_API_ADD_BLEDEVICE_EVT,
@@ -383,6 +385,13 @@ typedef struct
BD_FEATURES features;
} tBTA_DM_API_ADD_DEVICE;
+/* data type for BTA_DM_API_REMOVE_ACL_EVT */
+typedef struct
+{
+ BT_HDR hdr;
+ BD_ADDR bd_addr;
+} tBTA_DM_API_REMOVE_DEVICE;
+
/* data type for BTA_DM_API_EXECUTE_CBACK_EVT */
typedef struct
{
@@ -506,6 +515,8 @@ typedef union
tBTA_DM_API_ADD_DEVICE add_dev;
+ tBTA_DM_API_REMOVE_DEVICE remove_dev;
+
tBTA_DM_API_SEARCH search;
tBTA_DM_API_DISCOVER discover;
@@ -575,7 +586,7 @@ typedef union
#define BTA_DM_NOT_CONNECTED 0
#define BTA_DM_CONNECTED 1
-
+#define BTA_DM_UNPAIRING 2
typedef UINT8 tBTA_DM_CONN_STATE;
@@ -885,6 +896,8 @@ extern void bta_dm_signal_strength(tBTA_DM_MSG *p_data);
extern void bta_dm_tx_inqpower(tBTA_DM_MSG *p_data);
extern void bta_dm_acl_change(tBTA_DM_MSG *p_data);
extern void bta_dm_add_device (tBTA_DM_MSG *p_data);
+extern void bta_dm_remove_device (tBTA_DM_MSG *p_data);
+
extern void bta_dm_pm_btm_status(tBTA_DM_MSG *p_data);
extern void bta_dm_pm_timer(tBTA_DM_MSG *p_data);
diff --git a/bta/dm/bta_dm_main.c b/bta/dm/bta_dm_main.c
index a3dd167..38bf0af 100644..100755
--- a/bta/dm/bta_dm_main.c
+++ b/bta/dm/bta_dm_main.c
@@ -72,6 +72,8 @@ const tBTA_DM_ACTION bta_dm_action[] =
bta_dm_ci_rmt_oob_act, /* 22 BTA_DM_CI_RMT_OOB_EVT */
#endif /* BTM_OOB_INCLUDED */
+ bta_dm_remove_device, /* BTA_DM_API_REMOVE_DEVICE_EVT */
+
#if BLE_INCLUDED == TRUE
bta_dm_add_blekey, /* BTA_DM_API_ADD_BLEKEY_EVT */
bta_dm_add_ble_device, /* BTA_DM_API_ADD_BLEDEVICE_EVT */
diff --git a/bta/include/bta_api.h b/bta/include/bta_api.h
index 8d7b71b..e8f5892 100644..100755
--- a/bta/include/bta_api.h
+++ b/bta/include/bta_api.h
@@ -402,6 +402,7 @@ typedef UINT8 tBTA_SIG_STRENGTH_MASK;
// btla-specific ++
#define BTA_DM_BLE_AUTH_CMPL_EVT 22 /* BLE Auth complete */
// btla-specific --
+#define BTA_DM_DEV_UNPAIRED_EVT 23
typedef UINT8 tBTA_DM_SEC_EVT;
diff --git a/btif/include/btif_common.h b/btif/include/btif_common.h
index f594ee4..a440802 100644..100755
--- a/btif/include/btif_common.h
+++ b/btif/include/btif_common.h
@@ -135,7 +135,6 @@ enum
BTIF_DM_CB_START = BTIF_SIG_CB_START(BTIF_DM),
BTIF_DM_CB_DISCOVERY_STARTED, /* Discovery has started */
BTIF_DM_CB_BONDING_STARTED, /* Bonding process has started */
- BTIF_DM_CB_REMOVED_BONDING /* Bonded device deleted */
};
/************************************************************************************
diff --git a/btif/src/btif_dm.c b/btif/src/btif_dm.c
index 8fbc31d..9626457 100644..100755
--- a/btif/src/btif_dm.c
+++ b/btif/src/btif_dm.c
@@ -679,7 +679,8 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)p_param;
tBTA_SERVICE_MASK service_mask;
uint32_t i;
-
+ bt_bdaddr_t bd_addr;
+
BTIF_TRACE_EVENT1("btif_dm_upstreams_cback ev: %d", event);
switch (event)
@@ -758,6 +759,13 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
case BTA_DM_SP_KEY_NOTIF_EVT:
btif_dm_ssp_key_notif_evt(&p_data->key_notif);
break;
+
+ case BTA_DM_DEV_UNPAIRED_EVT:
+ bdcpy(bd_addr.address, p_data->link_down.bd_addr);
+ btif_storage_remove_bonded_device(&bd_addr);
+ CHECK_CALL_CBACK(bt_hal_cbacks, bond_state_changed_cb, BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
+ break;
+
case BTA_DM_AUTHORIZE_EVT:
case BTA_DM_LINK_DOWN_EVT:
case BTA_DM_SIG_STRENGTH_EVT:
@@ -801,19 +809,6 @@ static void btif_dm_generic_evt(UINT16 event, char* p_param)
}
break;
- case BTIF_DM_CB_REMOVED_BONDING:
- {
- bt_bdaddr_t *bd_addr = (bt_bdaddr_t*)p_param;
- bt_status_t status;
-
- status = btif_storage_remove_bonded_device(bd_addr);
- ASSERTC(status == BT_STATUS_SUCCESS, "failed to delete bonded device", status);
-
- CHECK_CALL_CBACK(bt_hal_cbacks, bond_state_changed_cb,
- BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_NONE);
- }
- break;
-
default:
{
BTIF_TRACE_WARNING2("%s : Unknown event 0x%x", __FUNCTION__, event);
@@ -1051,14 +1046,10 @@ bt_status_t btif_dm_remove_bond(const bt_bdaddr_t *bd_addr)
BTIF_TRACE_DEBUG1("Successfully removed bonding with device: %s",
bd2str((bt_bdaddr_t *)bd_addr, &bdstr));
- /* Device shall be removed from the storage in the btif context */
- btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_REMOVED_BONDING,
- (char*)bd_addr, sizeof(bt_bdaddr_t), NULL);
}
else
{
- /* TODO: ACL is already up with this device, disconnect and then issue RemoveBond */
- BTIF_TRACE_WARNING0("ACL connection exists with device. Disconnect and issue remove bonding");
+ return BT_STATUS_FAIL;
}
return BT_STATUS_SUCCESS;
}