diff options
author | Harish Paryani <hparyani@broadcom.com> | 2012-03-07 16:36:03 -0800 |
---|---|---|
committer | Matthew Xie <mattx@google.com> | 2012-07-14 11:19:12 -0700 |
commit | 17706aa42214addb95ee4aea5177a8784960dfc1 (patch) | |
tree | 24ba3487fc2e4fed27e76043608e0a94451ce2b5 /bta/dm | |
parent | c625f0b1c42a6451796cd6867e2769cd0db28d93 (diff) | |
download | external_bluetooth_bluedroid-17706aa42214addb95ee4aea5177a8784960dfc1.zip external_bluetooth_bluedroid-17706aa42214addb95ee4aea5177a8784960dfc1.tar.gz external_bluetooth_bluedroid-17706aa42214addb95ee4aea5177a8784960dfc1.tar.bz2 |
Disconnect before Unpair
Change-Id: Ib28372748df21d36d371d308975758f60df7aa28
Diffstat (limited to 'bta/dm')
-rwxr-xr-x[-rw-r--r--] | bta/dm/bta_dm_act.c | 60 | ||||
-rwxr-xr-x[-rw-r--r--] | bta/dm/bta_dm_api.c | 24 | ||||
-rwxr-xr-x[-rw-r--r--] | bta/dm/bta_dm_int.h | 15 | ||||
-rwxr-xr-x[-rw-r--r--] | bta/dm/bta_dm_main.c | 2 |
4 files changed, 76 insertions, 25 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 */ |