am 9ca3fb82: build: Add missing copyright headers to new GN build files
* commit '9ca3fb824639c2f15c104ca99be872e0e55035cb':
build: Add missing copyright headers to new GN build files
diff --git a/bta/dm/bta_dm_act.c b/bta/dm/bta_dm_act.c
index 806aeec..98e2a59 100644
--- a/bta/dm/bta_dm_act.c
+++ b/bta/dm/bta_dm_act.c
@@ -583,57 +583,118 @@
/*******************************************************************************
**
-** Function bta_dm_remove_device
+** Function bta_dm_process_remove_device
**
** Description Removes device, Disconnects ACL link if required.
****
*******************************************************************************/
-void bta_dm_remove_device (tBTA_DM_MSG *p_data)
+void bta_dm_process_remove_device(BD_ADDR bd_addr)
{
- tBTA_DM_API_REMOVE_DEVICE *p_dev = &p_data->remove_dev;
- int i;
- tBTA_DM_SEC sec_event;
-
#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
- /* need to remove all pending background connection before unpair */
- BTA_GATTC_CancelOpen(0, p_dev->bd_addr, FALSE);
+ /* need to remove all pending background connection before unpair */
+ BTA_GATTC_CancelOpen(0, bd_addr, FALSE);
#endif
- if ( BTM_IsAclConnectionUp(p_dev->bd_addr, BT_TRANSPORT_LE) ||
- BTM_IsAclConnectionUp(p_dev->bd_addr, BT_TRANSPORT_BR_EDR))
- {
- APPL_TRACE_DEBUG("%s: ACL Up count %d", __FUNCTION__,bta_dm_cb.device_list.count);
- /* Take the link down first, and mark the device for removal when disconnected */
+ BTM_SecDeleteDevice(bd_addr);
- for(i=0; i<bta_dm_cb.device_list.count; i++)
+#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
+ /* remove all cached GATT information */
+ BTA_GATTC_Refresh(bd_addr);
+#endif
+
+ if (bta_dm_cb.p_sec_cback)
+ {
+ tBTA_DM_SEC sec_event;
+ bdcpy(sec_event.link_down.bd_addr, bd_addr);
+ /* No connection, set status to success (acl disc code not valid) */
+ sec_event.link_down.status = HCI_SUCCESS;
+ bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &sec_event);
+ }
+}
+
+/*******************************************************************************
+**
+** 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;
+ if (p_dev == NULL)
+ return;
+
+ BD_ADDR other_address;
+ bdcpy(other_address, p_dev->bd_addr);
+
+ /* If ACL exists for the device in the remove_bond message*/
+ BOOLEAN continue_delete_dev = FALSE;
+ UINT8 other_transport = BT_TRANSPORT_INVALID;
+
+ if (BTM_IsAclConnectionUp(p_dev->bd_addr, BT_TRANSPORT_LE) ||
+ BTM_IsAclConnectionUp(p_dev->bd_addr, BT_TRANSPORT_BR_EDR))
+ {
+ APPL_TRACE_DEBUG("%s: ACL Up count %d", __func__, bta_dm_cb.device_list.count);
+ continue_delete_dev = FALSE;
+
+ /* Take the link down first, and mark the device for removal when disconnected */
+ for(int 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))
+ if (!bdcmp(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, p_dev->bd_addr))
{
bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_UNPAIRING;
- btm_remove_acl( p_dev->bd_addr,bta_dm_cb.device_list.peer_device[i].transport);
- APPL_TRACE_DEBUG("%s:transport = %d", __FUNCTION__,
- bta_dm_cb.device_list.peer_device[i].transport);
+ btm_remove_acl( p_dev->bd_addr, bta_dm_cb.device_list.peer_device[i].transport);
+ APPL_TRACE_DEBUG("%s:transport = %d", __func__,
+ bta_dm_cb.device_list.peer_device[i].transport);
+
+ /* save the other transport to check if device is connected on other_transport */
+ if(bta_dm_cb.device_list.peer_device[i].transport == BT_TRANSPORT_LE)
+ other_transport = BT_TRANSPORT_BR_EDR;
+ else
+ other_transport = BT_TRANSPORT_LE;
break;
}
}
}
-
- else /* Ok to remove the device in application layer */
+ else
{
- BTM_SecDeleteDevice(p_dev->bd_addr);
-#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
- /* remove all cached GATT information */
- BTA_GATTC_Refresh(p_dev->bd_addr);
-#endif
+ continue_delete_dev = TRUE;
+ }
- if( bta_dm_cb.p_sec_cback )
+ // If it is DUMO device and device is paired as different address, unpair that device
+ // if different address
+ BOOLEAN continue_delete_other_dev = FALSE;
+ if ((other_transport && (BTM_ReadConnectedTransportAddress(other_address, other_transport))) ||
+ (!other_transport && (BTM_ReadConnectedTransportAddress(other_address, BT_TRANSPORT_BR_EDR) ||
+ BTM_ReadConnectedTransportAddress(other_address, BT_TRANSPORT_LE))))
+ {
+ continue_delete_other_dev = FALSE;
+ /* Take the link down first, and mark the device for removal when disconnected */
+ for(int i=0; i < bta_dm_cb.device_list.count; i++)
{
- bdcpy(sec_event.link_down.bd_addr, p_dev->bd_addr);
- /* No connection, set status to success (acl disc code not valid) */
- sec_event.link_down.status = HCI_SUCCESS;
- bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &sec_event);
+ if (!bdcmp(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, other_address))
+ {
+ bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_UNPAIRING;
+ btm_remove_acl(other_address,bta_dm_cb.device_list.peer_device[i].transport);
+ break;
+ }
}
}
+ else
+ {
+ APPL_TRACE_DEBUG("%s: continue to delete the other dev ", __func__);
+ continue_delete_other_dev = TRUE;
+ }
+
+ /* Delete the device mentioned in the msg */
+ if (continue_delete_dev)
+ bta_dm_process_remove_device(p_dev->bd_addr);
+
+ /* Delete the other paired device too */
+ BD_ADDR dummy_bda = {0};
+ if (continue_delete_other_dev && (bdcmp(other_address, dummy_bda) != 0))
+ bta_dm_process_remove_device(other_address);
}
/*******************************************************************************
@@ -5212,7 +5273,7 @@
{
if ((st = BTM_BleAdvFilterParamSetup(p_data->ble_scan_filt_param_setup.action,
p_data->ble_scan_filt_param_setup.filt_index,
- (tBTM_BLE_PF_FILT_PARAMS *)p_data->ble_scan_filt_param_setup.p_filt_params,
+ (tBTM_BLE_PF_FILT_PARAMS *)&p_data->ble_scan_filt_param_setup.filt_params,
p_data->ble_scan_filt_param_setup.p_target,
p_data->ble_scan_filt_param_setup.p_filt_param_cback,
p_data->ble_scan_filt_param_setup.ref_value)) == BTM_CMD_STARTED)
diff --git a/bta/dm/bta_dm_api.c b/bta/dm/bta_dm_api.c
index 9995e17..b6497de 100644
--- a/bta/dm/bta_dm_api.c
+++ b/bta/dm/bta_dm_api.c
@@ -1761,7 +1761,8 @@
p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_SETUP_EVT;
p_msg->action = action;
p_msg->filt_index = filt_index;
- p_msg->p_filt_params = p_filt_params;
+ if (p_filt_params)
+ memcpy(&p_msg->filt_params, p_filt_params, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
p_msg->p_filt_param_cback = p_cmpl_cback;
p_msg->ref_value = ref_value;
diff --git a/bta/dm/bta_dm_int.h b/bta/dm/bta_dm_int.h
index cabe88e..0adf8fc 100644
--- a/bta/dm/bta_dm_int.h
+++ b/bta/dm/bta_dm_int.h
@@ -624,7 +624,7 @@
BT_HDR hdr;
UINT8 action;
tBTA_DM_BLE_PF_FILT_INDEX filt_index;
- tBTA_DM_BLE_PF_FILT_PARAMS *p_filt_params;
+ tBTA_DM_BLE_PF_FILT_PARAMS filt_params;
tBLE_BD_ADDR *p_target;
tBTA_DM_BLE_PF_PARAM_CBACK *p_filt_param_cback;
tBTA_DM_BLE_REF_VALUE ref_value;
diff --git a/bta/gatt/bta_gattc_act.c b/bta/gatt/bta_gattc_act.c
index aa9fcae..b07c47b 100755
--- a/bta/gatt/bta_gattc_act.c
+++ b/bta/gatt/bta_gattc_act.c
@@ -37,6 +37,8 @@
#include "bta_hh_int.h"
#endif
+#include "btif/include/btif_debug_conn.h"
+
#include <string.h>
#include "osi/include/log.h"
@@ -1362,7 +1364,7 @@
**
** Function bta_gattc_write_cmpl
**
-** Description read complete
+** Description write complete
**
** Returns None.
**
@@ -1378,7 +1380,7 @@
if (p_data->p_cmpl != NULL)
{
- bta_gattc_handle2id(p_clcb->p_srcb, p_data->p_cmpl->handle,
+ bta_gattc_handle2id(p_clcb->p_srcb, p_data->p_cmpl->att_value.handle,
&cb_data.write.srvc_id, &cb_data.write.char_id,
&cb_data.write.descr_type);
}
@@ -1803,6 +1805,13 @@
__FUNCTION__, gattc_if, connected, conn_id, reason);
}
+ bt_bdaddr_t bdaddr;
+ bdcpy(bdaddr.address, bda);
+ if (connected)
+ btif_debug_conn_state(bdaddr, BTIF_DEBUG_CONNECTED, GATT_CONN_UNKNOWN);
+ else
+ btif_debug_conn_state(bdaddr, BTIF_DEBUG_DISCONNECTED, reason);
+
if ((p_buf = (tBTA_GATTC_DATA *) GKI_getbuf(sizeof(tBTA_GATTC_DATA))) != NULL)
{
memset(p_buf, 0, sizeof(tBTA_GATTC_DATA));
diff --git a/bta/gatt/bta_gatts_act.c b/bta/gatt/bta_gatts_act.c
index bdd7f29..faabde3 100644
--- a/bta/gatt/bta_gatts_act.c
+++ b/bta/gatt/bta_gatts_act.c
@@ -34,6 +34,7 @@
#include "bta_gatts_int.h"
#include "bta_gatts_co.h"
#include "btm_ble_api.h"
+#include "btif/include/btif_debug_conn.h"
#include <string.h>
static void bta_gatts_nv_save_cback(BOOLEAN is_saved, tGATTS_HNDL_RANGE *p_hndl_range);
@@ -923,6 +924,13 @@
APPL_TRACE_DEBUG("bta_gatts_conn_cback bda :%02x-%02x-%02x-%02x-%02x-%02x ",
bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
+ bt_bdaddr_t bdaddr;
+ bdcpy(bdaddr.address, bda);
+ if (connected)
+ btif_debug_conn_state(bdaddr, BTIF_DEBUG_CONNECTED, GATT_CONN_UNKNOWN);
+ else
+ btif_debug_conn_state(bdaddr, BTIF_DEBUG_DISCONNECTED, reason);
+
p_reg = bta_gatts_find_app_rcb_by_app_if(gatt_if);
if (p_reg && p_reg->p_cback)
diff --git a/btcore/Android.mk b/btcore/Android.mk
index 0356650..50006d4 100644
--- a/btcore/Android.mk
+++ b/btcore/Android.mk
@@ -33,6 +33,7 @@
src/counter.c \
src/device_class.c \
src/module.c \
+ src/osi_module.c \
src/property.c \
src/uuid.c
diff --git a/btcore/include/osi_module.h b/btcore/include/osi_module.h
new file mode 100644
index 0000000..964a3fa
--- /dev/null
+++ b/btcore/include/osi_module.h
@@ -0,0 +1,21 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 Google, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#pragma once
+
+static const char OSI_MODULE[] = "osi_module";
diff --git a/btcore/src/module.c b/btcore/src/module.c
index 03ba91f..745a368 100644
--- a/btcore/src/module.c
+++ b/btcore/src/module.c
@@ -67,32 +67,10 @@
pthread_mutex_destroy(&metadata_lock);
}
-/* TODO: remove these externs and explicit checks once dlsym is fixed */
-extern module_t bt_utils_module;
-extern module_t btif_config_module;
-extern module_t controller_module;
-extern module_t gki_module;
-extern module_t counter_module;
-extern module_t stack_config_module;
-extern module_t btsnoop_module;
-extern module_t hci_module;
-extern module_t bte_logmsg_module;
-
const module_t *get_module(const char *name) {
module_t* module = (module_t *)dlsym(RTLD_DEFAULT, name);
- if (module) return module;
-
- if (!strcmp(name, "bt_utils_module")) return &bt_utils_module;
- if (!strcmp(name, "btif_config_module")) return &btif_config_module;
- if (!strcmp(name, "controller_module")) return &controller_module;
- if (!strcmp(name, "gki_module")) return &gki_module;
- if (!strcmp(name, "counter_module")) return &counter_module;
- if (!strcmp(name, "stack_config_module")) return &stack_config_module;
- if (!strcmp(name, "btsnoop_module")) return &btsnoop_module;
- if (!strcmp(name, "hci_module")) return &hci_module;
- if (!strcmp(name, "bte_logmsg_module")) return &bte_logmsg_module;
-
- return NULL;
+ assert(module);
+ return module;
}
bool module_init(const module_t *module) {
diff --git a/btcore/src/osi_module.c b/btcore/src/osi_module.c
new file mode 100644
index 0000000..40c27d5
--- /dev/null
+++ b/btcore/src/osi_module.c
@@ -0,0 +1,44 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 Google, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#define LOG_TAG "bt_osi_module"
+
+#include "btcore/include/module.h"
+#include "btcore/include/osi_module.h"
+#include "osi/include/alarm.h"
+#include "osi/include/future.h"
+#include "osi/include/log.h"
+#include "osi/include/osi.h"
+
+future_t *osi_start_up(void) {
+ return NULL;
+}
+
+future_t *osi_shut_down(void) {
+ alarm_shutdown();
+ return NULL;
+}
+
+const module_t osi_module = {
+ .name = OSI_MODULE,
+ .init = NULL,
+ .start_up = osi_start_up,
+ .shut_down = osi_shut_down,
+ .clean_up = NULL,
+ .dependencies = {NULL}
+};
diff --git a/btif/include/btif_debug.h b/btif/include/btif_debug.h
new file mode 100644
index 0000000..d0fa0c7
--- /dev/null
+++ b/btif/include/btif_debug.h
@@ -0,0 +1,31 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#pragma once
+
+#include <stdint.h>
+
+// Debug API
+
+void btif_debug_init(void);
+void btif_debug_dump(int fd);
+
+// Debug helpers
+
+// Timestamp in us
+uint64_t btif_debug_ts(void);
diff --git a/btif/include/btif_debug_btsnoop.h b/btif/include/btif_debug_btsnoop.h
new file mode 100644
index 0000000..8c8ef0f
--- /dev/null
+++ b/btif/include/btif_debug_btsnoop.h
@@ -0,0 +1,43 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#pragma once
+
+#include <stdint.h>
+
+#define BTSNOOZ_CURRENT_VERSION 0x01
+
+// The preamble is stored un-encrypted as the first part
+// of the file.
+typedef struct btsnooz_preamble_t {
+ uint8_t version;
+ uint64_t last_timestamp_ms;
+} __attribute__((__packed__)) btsnooz_preamble_t;
+
+// One header for each HCI packet
+typedef struct btsnooz_header_t {
+ uint16_t length;
+ uint32_t delta_time_ms;
+ uint8_t type;
+} __attribute__((__packed__)) btsnooz_header_t;
+
+// Initializes btsnoop memory logging and registers
+void btif_debug_btsnoop_init(void);
+
+// Writes btsnoop data base64 encoded to fd
+void btif_debug_btsnoop_dump(int fd);
diff --git a/btif/include/btif_debug_conn.h b/btif/include/btif_debug_conn.h
new file mode 100644
index 0000000..bf1bd6a
--- /dev/null
+++ b/btif/include/btif_debug_conn.h
@@ -0,0 +1,34 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#pragma once
+
+#include <hardware/bluetooth.h>
+
+#include "gatt_api.h"
+
+typedef enum {
+ BTIF_DEBUG_CONNECTED = 1,
+ BTIF_DEBUG_DISCONNECTED
+} btif_debug_conn_state_t;
+
+// Report a connection state change
+void btif_debug_conn_state(const bt_bdaddr_t bda, const btif_debug_conn_state_t state,
+ const tGATT_DISCONN_REASON disconnect_reason);
+
+void btif_debug_conn_dump(int fd);
diff --git a/btif/include/btif_storage.h b/btif/include/btif_storage.h
index bf6a5ed..54dc5d6 100644
--- a/btif/include/btif_storage.h
+++ b/btif/include/btif_storage.h
@@ -349,33 +349,4 @@
bt_status_t btif_storage_get_remote_version(const bt_bdaddr_t *remote_bd_addr,
bt_remote_version_t *p_ver);
-/*******************************************************************************
-**
-** Function btif_storage_set_dmt_support_type
-**
-** Description Sets DMT support status for a remote device
-**
-** Returns BT_STATUS_SUCCESS if config update is successful
-** BT_STATUS_FAIL otherwise
-**
-*******************************************************************************/
-
-bt_status_t btif_storage_set_dmt_support_type(const bt_bdaddr_t *remote_bd_addr,
- BOOLEAN dmt_supported);
-
-
-
-/*******************************************************************************
-**
-** Function btif_storage_is_dmt_supported_device
-**
-** Description checks if a device supports Dual mode topology
-**
-** Returns TRUE if remote supports DMT else FALSE
-**
-*******************************************************************************/
-
-BOOLEAN btif_storage_is_dmt_supported_device(const bt_bdaddr_t *remote_bd_addr);
-
-
#endif /* BTIF_STORAGE_H */
diff --git a/btif/src/bluetooth.c b/btif/src/bluetooth.c
index 4558705..f842e5c 100644
--- a/btif/src/bluetooth.c
+++ b/btif/src/bluetooth.c
@@ -46,7 +46,9 @@
#define LOG_TAG "bt_bluedroid"
#include "btif_api.h"
+#include "btif_debug.h"
#include "btsnoop.h"
+#include "btsnoop_mem.h"
#include "bt_utils.h"
#include "osi/include/osi.h"
#include "osi/include/allocation_tracker.h"
@@ -128,6 +130,7 @@
bt_hal_cbacks = callbacks;
stack_manager_get_interface()->init_stack();
+ btif_debug_init();
return BT_STATUS_SUCCESS;
}
@@ -307,6 +310,11 @@
return BT_STATUS_SUCCESS;
}
+static void dump(int fd)
+{
+ btif_debug_dump(fd);
+}
+
static const void* get_profile_interface (const char *profile_id)
{
LOG_INFO("get_profile_interface %s", profile_id);
@@ -441,6 +449,7 @@
config_hci_snoop_log,
set_os_callouts,
read_energy_info,
+ dump
};
const bt_interface_t* bluetooth__get_bluetooth_interface ()
diff --git a/btif/src/btif_debug.c b/btif/src/btif_debug.c
new file mode 100644
index 0000000..bd7a844
--- /dev/null
+++ b/btif/src/btif_debug.c
@@ -0,0 +1,47 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#include <unistd.h>
+#include <sys/time.h>
+
+#include "btif/include/btif_debug.h"
+#include "btif/include/btif_debug_btsnoop.h"
+#include "btif/include/btif_debug_conn.h"
+#include "include/bt_target.h"
+
+void btif_debug_init(void) {
+#if defined(BTSNOOP_MEM) && (BTSNOOP_MEM == TRUE)
+ btif_debug_btsnoop_init();
+#endif
+}
+
+void btif_debug_dump(int fd) {
+ btif_debug_conn_dump(fd);
+#if defined(BTSNOOP_MEM) && (BTSNOOP_MEM == TRUE)
+ btif_debug_btsnoop_dump(fd);
+#endif
+
+ close(fd);
+}
+
+// TODO: Find a better place for this to enable additional re-use
+uint64_t btif_debug_ts(void) {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return (tv.tv_sec * 1000000LL) + tv.tv_usec;
+}
diff --git a/btif/src/btif_debug_btsnoop.c b/btif/src/btif_debug_btsnoop.c
new file mode 100644
index 0000000..1deda9c
--- /dev/null
+++ b/btif/src/btif_debug_btsnoop.c
@@ -0,0 +1,151 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#include <assert.h>
+#include <resolv.h>
+#include <zlib.h>
+
+#include "btif/include/btif_debug.h"
+#include "btif/include/btif_debug_btsnoop.h"
+#include "hci/include/btsnoop_mem.h"
+#include "include/bt_target.h"
+#include "osi/include/ringbuffer.h"
+
+#define REDUCE_HCI_TYPE_TO_SIGNIFICANT_BITS(type) (type >> 8)
+
+// Total btsnoop memory log buffer size
+#ifndef BTSNOOP_MEM_BUFFER_SIZE
+static const size_t BTSNOOP_MEM_BUFFER_SIZE = (128 * 1024);
+#endif
+
+// Block size for copying buffers (for compression/encoding etc.)
+static const size_t BLOCK_SIZE = 16384;
+
+// Maximum line length in bugreport (should be multiple of 4 for base64 output)
+static const uint8_t MAX_LINE_LENGTH = 128;
+
+static ringbuffer_t *buffer = NULL;
+static uint64_t last_timestamp_ms = 0;
+
+static void btsnoop_cb(const uint16_t type, const uint8_t *data, const size_t length) {
+ btsnooz_header_t header;
+
+ // Make room in the ring buffer
+
+ while (ringbuffer_available(buffer) < (length + sizeof(btsnooz_header_t))) {
+ ringbuffer_pop(buffer, (uint8_t *)&header, sizeof(btsnooz_header_t));
+ ringbuffer_delete(buffer, header.length - 1);
+ }
+
+ // Insert data
+
+ const uint64_t now = btif_debug_ts();
+
+ header.type = REDUCE_HCI_TYPE_TO_SIGNIFICANT_BITS(type);
+ header.length = length;
+ header.delta_time_ms = last_timestamp_ms ? now - last_timestamp_ms : 0;
+ last_timestamp_ms = now;
+
+ ringbuffer_insert(buffer, (uint8_t *)&header, sizeof(btsnooz_header_t));
+ ringbuffer_insert(buffer, data, length - 1);
+}
+
+static bool btsnoop_compress(ringbuffer_t *rb_dst, ringbuffer_t *rb_src) {
+ assert(rb_dst != NULL);
+ assert(rb_src != NULL);
+
+ z_stream zs = {0};
+ if (deflateInit(&zs, Z_DEFAULT_COMPRESSION) != Z_OK)
+ return false;
+
+ bool rc = true;
+ uint8_t block_src[BLOCK_SIZE];
+ uint8_t block_dst[BLOCK_SIZE];
+
+ while (ringbuffer_size(rb_src) > 0) {
+ zs.avail_in = ringbuffer_pop(rb_src, block_src, BLOCK_SIZE);
+ zs.next_in = block_src;
+
+ do {
+ zs.avail_out = BLOCK_SIZE;
+ zs.next_out = block_dst;
+
+ int err = deflate(&zs, ringbuffer_size(rb_src) == 0 ? Z_FINISH : Z_NO_FLUSH);
+ if (err == Z_STREAM_ERROR) {
+ rc = false;
+ break;
+ }
+
+ const size_t length = BLOCK_SIZE - zs.avail_out;
+ ringbuffer_insert(rb_dst, block_dst, length);
+ } while (zs.avail_out == 0);
+ }
+
+ deflateEnd(&zs);
+ return rc;
+}
+
+void btif_debug_btsnoop_init(void) {
+ if (buffer == NULL)
+ buffer = ringbuffer_init(BTSNOOP_MEM_BUFFER_SIZE);
+ btsnoop_mem_set_callback(btsnoop_cb);
+}
+
+void btif_debug_btsnoop_dump(int fd) {
+ dprintf(fd, "\n--- BEGIN:BTSNOOP_LOG_SUMMARY (%zu bytes in) ---\n", ringbuffer_size(buffer));
+
+ ringbuffer_t *ringbuffer = ringbuffer_init(BTSNOOP_MEM_BUFFER_SIZE);
+ if (ringbuffer == NULL) {
+ dprintf(fd, "%s Unable to allocate memory for compression", __func__);
+ return;
+ }
+
+ // Prepend preamble
+
+ btsnooz_preamble_t preamble;
+ preamble.version = BTSNOOZ_CURRENT_VERSION;
+ preamble.last_timestamp_ms = last_timestamp_ms;
+ ringbuffer_insert(ringbuffer, (uint8_t *)&preamble, sizeof(btsnooz_preamble_t));
+
+ // Compress data
+
+ bool rc = btsnoop_compress(ringbuffer, buffer);
+ if (rc == false) {
+ dprintf(fd, "%s Log compression failed", __func__);
+ goto error;
+ }
+
+ // Base64 encode & output
+
+ uint8_t b64_in[3] = {0};
+ char b64_out[5] = {0};
+
+ size_t i = sizeof(btsnooz_preamble_t);
+ while (ringbuffer_size(ringbuffer) > 0) {
+ size_t read = ringbuffer_pop(ringbuffer, b64_in, 3);
+ if (i > 0 && i % MAX_LINE_LENGTH == 0)
+ dprintf(fd, "\n");
+ i += b64_ntop(b64_in, read, b64_out, 5);
+ dprintf(fd, "%s", b64_out);
+ }
+
+ dprintf(fd, "\n--- END:BTSNOOP_LOG_SUMMARY (%zu bytes out) ---\n", i);
+
+error:
+ ringbuffer_free(ringbuffer);
+}
diff --git a/btif/src/btif_debug_conn.c b/btif/src/btif_debug_conn.c
new file mode 100644
index 0000000..8746203
--- /dev/null
+++ b/btif/src/btif_debug_conn.c
@@ -0,0 +1,109 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#include "btcore/include/bdaddr.h"
+#include "btif/include/btif_debug.h"
+#include "btif/include/btif_debug_conn.h"
+
+#define NUM_CONNECTION_EVENTS 16
+#define TEMP_BUFFER_SIZE 30
+
+typedef struct conn_event_t {
+ uint64_t ts;
+ btif_debug_conn_state_t state;
+ bt_bdaddr_t bda;
+ tGATT_DISCONN_REASON disconnect_reason;
+} conn_event_t;
+
+static conn_event_t connection_events[NUM_CONNECTION_EVENTS];
+static uint8_t current_event = 0;
+
+static char *format_ts(const uint64_t ts, char *buffer, int len) {
+ const uint64_t ms = ts / 1000;
+ const time_t secs = ms / 1000;
+ struct tm *ptm = localtime(&secs);
+
+ strftime(buffer, len, "%m-%d %H:%M:%S.%%03u", ptm);
+ snprintf(buffer, len, buffer, (uint16_t)(ms % 1000));
+
+ return buffer;
+}
+
+static char *format_state(const btif_debug_conn_state_t state) {
+ switch (state) {
+ case BTIF_DEBUG_CONNECTED:
+ return "CONNECTED ";
+ case BTIF_DEBUG_DISCONNECTED:
+ return "DISCONNECTED";
+ }
+ return "UNKNOWN";
+}
+
+static void next_event() {
+ ++current_event;
+ if (current_event == NUM_CONNECTION_EVENTS)
+ current_event = 0;
+}
+
+void btif_debug_conn_state(const bt_bdaddr_t bda, const btif_debug_conn_state_t state,
+ const tGATT_DISCONN_REASON disconnect_reason) {
+ next_event();
+
+ conn_event_t *evt = &connection_events[current_event];
+ evt->ts = btif_debug_ts();
+ evt->state = state;
+ evt->disconnect_reason = disconnect_reason;
+ memcpy(&evt->bda, &bda, sizeof(bt_bdaddr_t));
+}
+
+void btif_debug_conn_dump(int fd) {
+ const uint8_t current_event_local = current_event; // Cache to avoid threading issues
+ uint8_t dump_event = current_event_local;
+ char ts_buffer[TEMP_BUFFER_SIZE] = {0};
+ char name_buffer[TEMP_BUFFER_SIZE] = {0};
+
+ dprintf(fd, "\nConnection Events:\n");
+ if (connection_events[dump_event].ts == 0)
+ dprintf(fd, " None\n");
+
+ while (connection_events[dump_event].ts) {
+ conn_event_t *evt = &connection_events[dump_event];
+ dprintf(fd, " %s %s %s",
+ format_ts(evt->ts, ts_buffer, sizeof(ts_buffer)),
+ format_state(evt->state),
+ bdaddr_to_string(&evt->bda, name_buffer, sizeof(name_buffer))
+ );
+ if (evt->state == BTIF_DEBUG_DISCONNECTED)
+ dprintf(fd, " reason=%d", evt->disconnect_reason);
+ dprintf(fd,"\n");
+
+ // Go to previous event; wrap if needed
+ if (dump_event > 0)
+ --dump_event;
+ else
+ dump_event = NUM_CONNECTION_EVENTS - 1;
+
+ // Check if we dumped all events
+ if (dump_event == current_event_local)
+ break;
+ }
+}
diff --git a/btif/src/btif_dm.c b/btif/src/btif_dm.c
index 161fac8..711c414 100644
--- a/btif/src/btif_dm.c
+++ b/btif/src/btif_dm.c
@@ -1380,12 +1380,6 @@
ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device (inquiry)", status);
#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
status = btif_storage_set_remote_addr_type(&bdaddr, addr_type);
- if (( dev_type == BT_DEVICE_TYPE_DUMO)&&
- (p_search_data->inq_res.flag & BTA_BLE_DMT_CONTROLLER_SPT) &&
- (p_search_data->inq_res.flag & BTA_BLE_DMT_HOST_SPT))
- {
- btif_storage_set_dmt_support_type (&bdaddr, TRUE);
- }
ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote addr type (inquiry)", status);
#endif
/* Callback to notify upper layer of device */
@@ -1687,6 +1681,7 @@
}
/* clear control blocks */
memset(&pairing_cb, 0, sizeof(btif_dm_pairing_cb_t));
+ pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
/* This function will also trigger the adapter_properties_cb
** and bonded_devices_info_cb
@@ -1891,10 +1886,10 @@
memcpy(&ble_local_key_cb.id_keys.dhk[0],
&p_data->ble_id_keys.dhk[0], sizeof(BT_OCTET16));
btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.irk[0],
- BTIF_DM_LE_LOCAL_KEY_IR,
+ BTIF_DM_LE_LOCAL_KEY_IRK,
BT_OCTET16_LEN);
btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.ir[0],
- BTIF_DM_LE_LOCAL_KEY_IRK,
+ BTIF_DM_LE_LOCAL_KEY_IR,
BT_OCTET16_LEN);
btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.dhk[0],
BTIF_DM_LE_LOCAL_KEY_DHK,
@@ -2886,7 +2881,11 @@
{
status = BT_STATUS_SUCCESS;
state = BT_BOND_STATE_BONDED;
-
+ int addr_type;
+ bt_bdaddr_t bdaddr;
+ bdcpy(bdaddr.address, p_auth_cmpl->bd_addr);
+ if (btif_storage_get_remote_addr_type(&bdaddr, &addr_type) != BT_STATUS_SUCCESS)
+ btif_storage_set_remote_addr_type(&bdaddr, p_auth_cmpl->addr_type);
btif_dm_save_ble_bonding_keys();
BTA_GATTC_Refresh(bd_addr.address);
btif_dm_get_remote_services(&bd_addr);
diff --git a/btif/src/btif_gatt_client.c b/btif/src/btif_gatt_client.c
index df766c1..24e3dc9 100644
--- a/btif/src/btif_gatt_client.c
+++ b/btif/src/btif_gatt_client.c
@@ -584,13 +584,6 @@
}
- if (( p_btif_cb->device_type == BT_DEVICE_TYPE_DUMO)&&
- (p_btif_cb->flag & BTA_BLE_DMT_CONTROLLER_SPT) &&
- (p_btif_cb->flag & BTA_BLE_DMT_HOST_SPT))
- {
- btif_storage_set_dmt_support_type (&(p_btif_cb->bd_addr), TRUE);
- }
-
dev_type = p_btif_cb->device_type;
BTIF_STORAGE_FILL_PROPERTY(&properties,
BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
@@ -1146,8 +1139,7 @@
break;
case BT_DEVICE_TYPE_DUMO:
- if ((p_cb->transport == GATT_TRANSPORT_LE) &&
- (btif_storage_is_dmt_supported_device(&(p_cb->bd_addr)) == TRUE))
+ if (p_cb->transport == GATT_TRANSPORT_LE)
transport = BTA_GATT_TRANSPORT_LE;
else
transport = BTA_GATT_TRANSPORT_BR_EDR;
diff --git a/btif/src/btif_gatt_server.c b/btif/src/btif_gatt_server.c
index 1632b01..cd86f93 100644
--- a/btif/src/btif_gatt_server.c
+++ b/btif/src/btif_gatt_server.c
@@ -413,8 +413,7 @@
break;
case BT_DEVICE_TYPE_DUMO:
- if ((p_cb->transport == GATT_TRANSPORT_LE) &&
- (btif_storage_is_dmt_supported_device(&(p_cb->bd_addr)) == TRUE))
+ if (p_cb->transport == GATT_TRANSPORT_LE)
transport = BTA_GATT_TRANSPORT_LE;
else
transport = BTA_GATT_TRANSPORT_BR_EDR;
diff --git a/btif/src/btif_pan.c b/btif/src/btif_pan.c
index 6f9c70b..5b71e20 100644
--- a/btif/src/btif_pan.c
+++ b/btif/src/btif_pan.c
@@ -174,10 +174,10 @@
static bt_status_t btpan_jni_init(const btpan_callbacks_t* callbacks)
{
BTIF_TRACE_DEBUG("stack_initialized = %d, btpan_cb.enabled:%d", stack_initialized, btpan_cb.enabled);
- jni_initialized = true;
- if (!stack_initialized && !btpan_cb.enabled)
- btif_pan_init();
callback = *callbacks;
+ jni_initialized = TRUE;
+ if (stack_initialized && !btpan_cb.enabled)
+ btif_pan_init();
return BT_STATUS_SUCCESS;
}
diff --git a/btif/src/btif_rc.c b/btif/src/btif_rc.c
index 07e0c2c..1d3e12b 100644
--- a/btif/src/btif_rc.c
+++ b/btif/src/btif_rc.c
@@ -304,9 +304,6 @@
for (x = 0; key_map[x].name != NULL; x++)
ioctl(fd, UI_SET_KEYBIT, key_map[x].mapped_id);
- for(x = 0; x < KEY_MAX; x++)
- ioctl(fd, UI_SET_KEYBIT, x);
-
if (ioctl(fd, UI_DEV_CREATE, NULL) < 0) {
BTIF_TRACE_ERROR("%s Unable to create uinput device", __FUNCTION__);
close(fd);
diff --git a/btif/src/btif_storage.c b/btif/src/btif_storage.c
index d0aac7b..225c593 100644
--- a/btif/src/btif_storage.c
+++ b/btif/src/btif_storage.c
@@ -1651,67 +1651,3 @@
}
-/*******************************************************************************
-**
-** Function btif_storage_set_dmt_support_type
-**
-** Description Sets DMT support status for a remote device
-**
-** Returns BT_STATUS_SUCCESS if config update is successful
-** BT_STATUS_FAIL otherwise
-**
-*******************************************************************************/
-
-bt_status_t btif_storage_set_dmt_support_type(const bt_bdaddr_t *remote_bd_addr,
- BOOLEAN dmt_supported)
-{
- int ret;
- bdstr_t bdstr = {0};
- if(remote_bd_addr)
- {
- bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr));
- }
- else
- {
- BTIF_TRACE_ERROR("%s NULL BD Address", __FUNCTION__);
- return BT_STATUS_FAIL;
- }
-
- ret = btif_config_set_int(bdstr,"DMTSupported", (int)dmt_supported);
- return ret ? BT_STATUS_SUCCESS:BT_STATUS_FAIL;
-
-}
-
-/*******************************************************************************
-**
-** Function btif_storage_is_dmt_supported_device
-**
-** Description checks if a device supports Dual mode topology
-**
-** Returns TRUE if remote address is valid and supports DMT else FALSE
-**
-*******************************************************************************/
-
-BOOLEAN btif_storage_is_dmt_supported_device(const bt_bdaddr_t *remote_bd_addr)
-{
- int dmt_supported = 0;
- bdstr_t bdstr = {0};
- if(remote_bd_addr)
- bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr));
-
- if(remote_bd_addr)
- {
- bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr));
- }
- else
- {
- BTIF_TRACE_ERROR("%s NULL BD Address", __FUNCTION__);
- return FALSE;
- }
-
- btif_config_get_int(bdstr,"DMTSupported", &dmt_supported);
-
- return dmt_supported == 1 ? TRUE:FALSE;
-}
-
-
diff --git a/btif/src/stack_manager.c b/btif/src/stack_manager.c
index ff71b08..3b64648 100644
--- a/btif/src/stack_manager.c
+++ b/btif/src/stack_manager.c
@@ -24,6 +24,7 @@
#include "btif_common.h"
#include "device/include/controller.h"
#include "btcore/include/module.h"
+#include "btcore/include/osi_module.h"
#include "osi/include/osi.h"
#include "osi/include/log.h"
#include "osi/include/semaphore.h"
@@ -125,6 +126,7 @@
LOG_DEBUG("%s is bringing up the stack.", __func__);
hack_future = future_new();
+ module_start_up(get_module(OSI_MODULE));
// Include this for now to put btif config into a shutdown-able state
module_start_up(get_module(BTIF_CONFIG_MODULE));
bte_main_enable();
@@ -156,6 +158,8 @@
future_await(hack_future);
module_shut_down(get_module(CONTROLLER_MODULE)); // Doesn't do any work, just puts it in a restartable state
+ module_shut_down(get_module(OSI_MODULE));
+
LOG_DEBUG("%s finished.", __func__);
btif_thread_post(event_signal_stack_down, NULL);
}
diff --git a/hci/Android.mk b/hci/Android.mk
index 7c69464..af87285 100644
--- a/hci/Android.mk
+++ b/hci/Android.mk
@@ -4,6 +4,7 @@
LOCAL_SRC_FILES := \
src/btsnoop.c \
+ src/btsnoop_mem.c \
src/btsnoop_net.c \
src/buffer_allocator.c \
src/hci_audio.c \
diff --git a/hci/include/btsnoop_mem.h b/hci/include/btsnoop_mem.h
new file mode 100644
index 0000000..fd8c560
--- /dev/null
+++ b/hci/include/btsnoop_mem.h
@@ -0,0 +1,36 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#pragma once
+
+#include <stdint.h>
+
+#include "bt_types.h"
+
+// Callback invoked for each HCI packet.
+// Highlander mode - there can be only one...
+typedef void (*btsnoop_data_cb)(const uint16_t type, const uint8_t *p_data, const size_t len);
+
+// This call sets the (one and only) callback that will
+// be invoked once for each HCI packet/event.
+void btsnoop_mem_set_callback(btsnoop_data_cb cb);
+
+// This function is invoked every time an HCI packet
+// is sent/received. Packets will be filtered and then
+// forwarded to the |btsnoop_data_cb|.
+void btsnoop_mem_capture(const BT_HDR *p_buf);
diff --git a/hci/src/btsnoop.c b/hci/src/btsnoop.c
index 538fc95..990623e 100644
--- a/hci/src/btsnoop.c
+++ b/hci/src/btsnoop.c
@@ -32,7 +32,8 @@
#include <sys/time.h>
#include <unistd.h>
-#include "btsnoop.h"
+#include "hci/include/btsnoop.h"
+#include "hci/include/btsnoop_mem.h"
#include "bt_types.h"
#include "hci_layer.h"
#include "osi/include/log.h"
@@ -101,6 +102,8 @@
static void capture(const BT_HDR *buffer, bool is_received) {
const uint8_t *p = buffer->data + buffer->offset;
+ btsnoop_mem_capture(buffer);
+
if (logfile_fd == INVALID_FD)
return;
diff --git a/hci/src/btsnoop_mem.c b/hci/src/btsnoop_mem.c
new file mode 100644
index 0000000..55efc1b
--- /dev/null
+++ b/hci/src/btsnoop_mem.c
@@ -0,0 +1,61 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#include <assert.h>
+#include <time.h>
+
+#include "hci/include/btsnoop_mem.h"
+
+static btsnoop_data_cb data_callback = NULL;
+
+void btsnoop_mem_set_callback(btsnoop_data_cb cb) {
+ data_callback = cb;
+}
+
+void btsnoop_mem_capture(const BT_HDR *packet) {
+ if (!data_callback)
+ return;
+
+ assert(packet);
+
+ const uint8_t *data = &packet->data[packet->offset];
+ const uint16_t type = packet->event & BT_EVT_MASK;
+ size_t length = 0;
+
+ switch (type) {
+ case BT_EVT_TO_LM_HCI_CMD:
+ if (packet->len > 2)
+ length = data[2] + 4;
+ break;
+
+ case BT_EVT_TO_BTU_HCI_EVT:
+ if (packet->len > 1)
+ length = data[1] + 3;
+ break;
+
+ // Ignore data for privacy
+ case BT_EVT_TO_LM_HCI_ACL:
+ case BT_EVT_TO_LM_HCI_SCO:
+ case BT_EVT_TO_BTU_HCI_ACL:
+ case BT_EVT_TO_BTU_HCI_SCO:
+ break;
+ }
+
+ if (length)
+ (*data_callback)(type, data, length);
+}
diff --git a/include/bt_target.h b/include/bt_target.h
index 4fb2a0f..4efe890 100644
--- a/include/bt_target.h
+++ b/include/bt_target.h
@@ -1701,6 +1701,11 @@
**
******************************************************************************/
+/* Enable/disable BTSnoop memory logging */
+#ifndef BTSNOOP_MEM
+#define BTSNOOP_MEM TRUE
+#endif
+
#include "bt_trace.h"
#endif /* BT_TARGET_H */
diff --git a/main/Android.mk b/main/Android.mk
index 9f07e37..04d4332 100644
--- a/main/Android.mk
+++ b/main/Android.mk
@@ -24,6 +24,9 @@
../btif/src/btif_config.c \
../btif/src/btif_config_transcode.cpp \
../btif/src/btif_core.c \
+ ../btif/src/btif_debug.c \
+ ../btif/src/btif_debug_btsnoop.c \
+ ../btif/src/btif_debug_conn.c \
../btif/src/btif_dm.c \
../btif/src/btif_gatt.c \
../btif/src/btif_gatt_client.c \
@@ -107,7 +110,8 @@
$(LOCAL_PATH)/../audio_a2dp_hw \
$(LOCAL_PATH)/../utils/include \
$(bdroid_C_INCLUDES) \
- external/tinyxml2
+ external/tinyxml2 \
+ external/zlib
LOCAL_CFLAGS += -DBUILDCFG $(bdroid_CFLAGS) -Wno-error=maybe-uninitialized -Wno-error=uninitialized -Wno-error=unused-parameter
LOCAL_CONLYFLAGS := -std=c99
@@ -127,8 +131,13 @@
libdl \
liblog \
libpower \
+ libz
LOCAL_STATIC_LIBRARIES := \
+ libtinyxml2 \
+ libbt-qcom_sbc_decoder
+
+LOCAL_WHOLE_STATIC_LIBRARIES := \
libbt-brcm_bta \
libbt-brcm_gki \
libbt-brcm_stack \
@@ -136,9 +145,7 @@
libbt-hci \
libbt-utils \
libbtcore \
- libosi \
- libtinyxml2 \
- libbt-qcom_sbc_decoder
+ libosi
LOCAL_MODULE := bluetooth.default
LOCAL_MODULE_RELATIVE_PATH := hw
diff --git a/main/bte_main.c b/main/bte_main.c
index de62232..d08d6f6 100644
--- a/main/bte_main.c
+++ b/main/bte_main.c
@@ -44,13 +44,13 @@
#include "btsnoop.h"
#include "bt_utils.h"
#include "btcore/include/counter.h"
+#include "btcore/include/module.h"
#include "osi/include/fixed_queue.h"
#include "osi/include/future.h"
#include "gki.h"
#include "osi/include/hash_functions.h"
#include "osi/include/hash_map.h"
#include "hci_layer.h"
-#include "btcore/include/module.h"
#include "osi/include/osi.h"
#include "osi/include/log.h"
#include "stack_config.h"
diff --git a/osi/Android.mk b/osi/Android.mk
index c11f8fc..52dc2cf 100644
--- a/osi/Android.mk
+++ b/osi/Android.mk
@@ -43,11 +43,12 @@
./src/list.c \
./src/non_repeating_timer.c \
./src/reactor.c \
+ ./src/ringbuffer.c \
./src/semaphore.c \
./src/socket.c \
./src/thread.c
-LOCAL_CFLAGS := -std=c99 -Wall -Werror
+LOCAL_CFLAGS := -std=c99 -Wall -Werror -UNDEBUG
# Many .h files have redefined typedefs
LOCAL_CLANG_CFLAGS += -Wno-error=typedef-redefinition
LOCAL_MODULE := libosi
@@ -82,9 +83,10 @@
./test/hash_map_test.cpp \
./test/list_test.cpp \
./test/reactor_test.cpp \
+ ./test/ringbuffer_test.cpp \
./test/thread_test.cpp
-LOCAL_CFLAGS := -Wall -Werror
+LOCAL_CFLAGS := -Wall -UNDEBUG
LOCAL_MODULE := net_test_osi
LOCAL_MODULE_TAGS := tests
LOCAL_SHARED_LIBRARIES := liblog
diff --git a/osi/include/alarm.h b/osi/include/alarm.h
index b27e9a4..5a372dc 100644
--- a/osi/include/alarm.h
+++ b/osi/include/alarm.h
@@ -51,3 +51,7 @@
// will not be called if it hasn't already been called. This function is idempotent.
// |alarm| may not be NULL.
void alarm_cancel(alarm_t *alarm);
+
+// Shuts down the alarm dispatch callback. To be called during module/stack
+// shutdown only.
+void alarm_shutdown(void);
diff --git a/osi/include/ringbuffer.h b/osi/include/ringbuffer.h
new file mode 100644
index 0000000..8446d6c
--- /dev/null
+++ b/osi/include/ringbuffer.h
@@ -0,0 +1,60 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#pragma once
+
+#include <stdint.h>
+
+typedef struct ringbuffer_t ringbuffer_t;
+
+// NOTE:
+// None of the functions below are thread safe when it comes to accessing the
+// *rb pointer. It is *NOT* possible to insert and pop/delete at the same time.
+// Callers must protect the *rb pointer separately.
+
+// Create a ringbuffer with the specified size
+// Returns NULL if memory allocation failed. Resulting pointer must be freed
+// using |ringbuffer_free|.
+ringbuffer_t* ringbuffer_init(const size_t size);
+
+// Frees the ringbuffer structure and buffer
+// Save to call with NULL.
+void ringbuffer_free(ringbuffer_t *rb);
+
+// Returns remaining buffer size
+size_t ringbuffer_available(const ringbuffer_t *rb);
+
+// Returns size of data in buffer
+size_t ringbuffer_size(const ringbuffer_t *rb);
+
+// Attempts to insert up to |length| bytes of data at |p| into the buffer
+// Return actual number of bytes added. Can be less than |length| if buffer
+// is full.
+size_t ringbuffer_insert(ringbuffer_t *rb, const uint8_t *p, size_t length);
+
+// Peek |length| number of bytes from the ringbuffer into the buffer |p|
+// Return the actual number of bytes peeked. Can be less than |length| if
+// there is less than |length| data available.
+size_t ringbuffer_peek(const ringbuffer_t *rb, uint8_t *p, size_t length);
+
+// Does the same as |ringbuffer_peek|, but also advances the ring buffer head
+size_t ringbuffer_pop(ringbuffer_t *rb, uint8_t *p, size_t length);
+
+// Deletes |length| bytes from the ringbuffer starting from the head
+// Return actual number of bytes deleted.
+size_t ringbuffer_delete(ringbuffer_t *rb, size_t length);
diff --git a/osi/src/alarm.c b/osi/src/alarm.c
index 1ce58bc..6a10b83 100644
--- a/osi/src/alarm.c
+++ b/osi/src/alarm.c
@@ -70,6 +70,7 @@
// All alarm callbacks are dispatched from |callback_thread|
static thread_t *callback_thread;
+static bool callback_thread_active;
static semaphore_t *alarm_expired;
static bool lazy_initialize(void);
@@ -176,6 +177,26 @@
pthread_mutex_unlock(&alarm->callback_lock);
}
+void alarm_shutdown(void) {
+ // If lazy_initialize never ran there is nothing to do
+ if (!alarms)
+ return;
+
+ callback_thread_active = false;
+ semaphore_post(alarm_expired);
+ thread_free(callback_thread);
+ callback_thread = NULL;
+
+ semaphore_free(alarm_expired);
+ alarm_expired = NULL;
+ timer_delete(&timer);
+
+ list_free(alarms);
+ alarms = NULL;
+
+ pthread_mutex_destroy(&monitor);
+}
+
static bool lazy_initialize(void) {
assert(alarms == NULL);
@@ -202,6 +223,7 @@
return false;
}
+ callback_thread_active = true;
callback_thread = thread_new("alarm_callbacks");
if (!callback_thread) {
LOG_ERROR("%s unable to create alarm callback thread.", __func__);
@@ -256,6 +278,7 @@
// NOTE: must be called with monitor lock.
static void reschedule_root_alarm(void) {
+ bool timer_was_set = timer_set;
assert(alarms != NULL);
// If used in a zeroed state, disarms the timer
@@ -285,7 +308,7 @@
done:
timer_set = wakeup_time.it_value.tv_sec != 0 || wakeup_time.it_value.tv_nsec != 0;
- if (!timer_set) {
+ if (timer_was_set && !timer_set) {
bt_os_callouts->release_wake_lock(WAKE_LOCK_ID);
}
@@ -321,8 +344,10 @@
static void callback_dispatch(UNUSED_ATTR void *context) {
while (true) {
semaphore_wait(alarm_expired);
- pthread_mutex_lock(&monitor);
+ if (!callback_thread_active)
+ break;
+ pthread_mutex_lock(&monitor);
alarm_t *alarm;
// Take into account that the alarm may get cancelled before we get to it.
@@ -358,4 +383,6 @@
pthread_mutex_unlock(&alarm->callback_lock);
}
+
+ LOG_DEBUG("%s Callback thread exited", __func__);
}
diff --git a/osi/src/ringbuffer.c b/osi/src/ringbuffer.c
new file mode 100644
index 0000000..131f5b1
--- /dev/null
+++ b/osi/src/ringbuffer.c
@@ -0,0 +1,125 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include "osi/include/allocator.h"
+#include "osi/include/ringbuffer.h"
+
+struct ringbuffer_t {
+ size_t total;
+ size_t available;
+ uint8_t *base;
+ uint8_t *head;
+ uint8_t *tail;
+};
+
+ringbuffer_t* ringbuffer_init(const size_t size) {
+ ringbuffer_t* p = osi_calloc(sizeof(ringbuffer_t));
+ if (p == 0)
+ return NULL;
+
+ p->base = osi_calloc(size);
+ if (p->base == 0) {
+ osi_free(p);
+ return NULL;
+ }
+
+ p->head = p->tail = p->base;
+ p->total = p->available = size;
+
+ return p;
+}
+
+void ringbuffer_free(ringbuffer_t *rb) {
+ if (rb != NULL)
+ osi_free(rb->base);
+ osi_free(rb);
+}
+
+size_t ringbuffer_available(const ringbuffer_t *rb) {
+ assert(rb);
+ return rb->available;
+}
+
+size_t ringbuffer_size(const ringbuffer_t *rb) {
+ assert(rb);
+ return rb->total - rb->available;
+}
+
+size_t ringbuffer_insert(ringbuffer_t *rb, const uint8_t *p, size_t length) {
+ assert(rb);
+ assert(p);
+
+ if (length > ringbuffer_available(rb))
+ length = ringbuffer_available(rb);
+
+ for (size_t i = 0; i != length; ++i) {
+ *rb->tail++ = *p++;
+ if (rb->tail >= (rb->base + rb->total))
+ rb->tail = rb->base;
+ }
+
+ rb->available -= length;
+ return length;
+}
+
+size_t ringbuffer_delete(ringbuffer_t *rb, size_t length) {
+ assert(rb);
+
+ if (length > ringbuffer_size(rb))
+ length = ringbuffer_size(rb);
+
+ rb->head += length;
+ if (rb->head >= (rb->base + rb->total))
+ rb->head -= rb->total;
+
+ rb->available += length;
+ return length;
+}
+
+size_t ringbuffer_peek(const ringbuffer_t *rb, uint8_t *p, size_t length) {
+ assert(rb);
+ assert(p);
+
+ uint8_t *b = rb->head;
+ size_t copied = 0;
+
+ while (copied < length && copied < ringbuffer_size(rb)) {
+ *p++ = *b++;
+ if (b >= (rb->base + rb->total))
+ b = rb->base;
+ ++copied;
+ }
+
+ return copied;
+}
+
+size_t ringbuffer_pop(ringbuffer_t *rb, uint8_t *p, size_t length) {
+ assert(rb);
+ assert(p);
+
+ const size_t copied = ringbuffer_peek(rb, p, length);
+ rb->head += copied;
+ if (rb->head >= (rb->base + rb->total))
+ rb->head -= rb->total;
+
+ rb->available += copied;
+ return copied;
+}
diff --git a/osi/test/AlarmTestHarness.cpp b/osi/test/AlarmTestHarness.cpp
index a5f8d9c..ce7a62f 100644
--- a/osi/test/AlarmTestHarness.cpp
+++ b/osi/test/AlarmTestHarness.cpp
@@ -39,11 +39,6 @@
void AlarmTestHarness::SetUp() {
AllocationTestHarness::SetUp();
- // Make sure the alarm list is initialized, and the base list
- // allocation isn't taken into account.
- alarm_free(alarm_new());
- allocation_tracker_reset();
-
current_harness = this;
TIMER_INTERVAL_FOR_WAKELOCK_IN_MS = 100;
lock_count = 0;
@@ -57,6 +52,7 @@
}
void AlarmTestHarness::TearDown() {
+ alarm_shutdown();
timer_delete(timer);
AllocationTestHarness::TearDown();
}
diff --git a/osi/test/ringbuffer_test.cpp b/osi/test/ringbuffer_test.cpp
new file mode 100644
index 0000000..2ebdeca
--- /dev/null
+++ b/osi/test/ringbuffer_test.cpp
@@ -0,0 +1,139 @@
+#include <gtest/gtest.h>
+
+extern "C" {
+#include "ringbuffer.h"
+#include "osi.h"
+}
+
+TEST(RingbufferTest, test_new_simple) {
+ ringbuffer_t *rb = ringbuffer_init(4096);
+ ASSERT_TRUE(rb != NULL);
+ EXPECT_EQ(4096, ringbuffer_available(rb));
+ EXPECT_EQ(0, ringbuffer_size(rb));
+ ringbuffer_free(rb);
+}
+
+TEST(RingbufferTest, test_insert_basic) {
+ ringbuffer_t *rb = ringbuffer_init(16);
+
+ uint8_t buffer[10] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A};
+ ringbuffer_insert(rb, buffer, 10);
+ EXPECT_EQ(10, ringbuffer_size(rb));
+ EXPECT_EQ(6, ringbuffer_available(rb));
+
+ uint8_t peek[10] = {0};
+ size_t peeked = ringbuffer_peek(rb, peek, 10);
+ EXPECT_EQ(10, ringbuffer_size(rb)); // Ensure size doesn't change
+ EXPECT_EQ(6, ringbuffer_available(rb));
+ EXPECT_EQ(10, peeked);
+ ASSERT_TRUE(0 == memcmp(buffer, peek, peeked));
+
+ ringbuffer_free(rb);
+}
+
+TEST(RingbufferTest, test_insert_full) {
+ ringbuffer_t *rb = ringbuffer_init(5);
+
+ uint8_t aa[] = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA};
+ uint8_t bb[] = {0xBB, 0xBB, 0xBB, 0xBB, 0xBB};
+ uint8_t peek[5] = {0};
+
+ size_t added = ringbuffer_insert(rb, aa, 7);
+ EXPECT_EQ(5, added);
+ EXPECT_EQ(0, ringbuffer_available(rb));
+ EXPECT_EQ(5, ringbuffer_size(rb));
+
+ added = ringbuffer_insert(rb, bb, 5);
+ EXPECT_EQ(0, added);
+ EXPECT_EQ(0, ringbuffer_available(rb));
+ EXPECT_EQ(5, ringbuffer_size(rb));
+
+ size_t peeked = ringbuffer_peek(rb, peek, 5);
+ EXPECT_EQ(5, peeked);
+ EXPECT_EQ(0, ringbuffer_available(rb));
+ EXPECT_EQ(5, ringbuffer_size(rb));
+
+ ASSERT_TRUE(0 == memcmp(aa, peek, peeked));
+
+ ringbuffer_free(rb);
+}
+
+TEST(RingbufferTest, test_multi_insert_delete) {
+ ringbuffer_t *rb = ringbuffer_init(16);
+ EXPECT_EQ(16, ringbuffer_available(rb));
+ EXPECT_EQ(0, ringbuffer_size(rb));
+
+ // Insert some bytes
+
+ uint8_t aa[] = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA};
+ size_t added = ringbuffer_insert(rb, aa, sizeof(aa));
+ EXPECT_EQ(8, added);
+ EXPECT_EQ(8, ringbuffer_available(rb));
+ EXPECT_EQ(8, ringbuffer_size(rb));
+
+ uint8_t bb[] = {0xBB, 0xBB, 0xBB, 0xBB, 0xBB};
+ ringbuffer_insert(rb, bb, sizeof(bb));
+ EXPECT_EQ(3, ringbuffer_available(rb));
+ EXPECT_EQ(13, ringbuffer_size(rb));
+
+ uint8_t content[] = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB};
+ uint8_t peek[16] = {0};
+ size_t peeked = ringbuffer_peek(rb, peek, 16);
+ EXPECT_EQ(13, peeked);
+ ASSERT_TRUE(0 == memcmp(content, peek, peeked));
+
+ // Delete some bytes
+
+ ringbuffer_delete(rb, sizeof(aa));
+ EXPECT_EQ(11, ringbuffer_available(rb));
+ EXPECT_EQ(5, ringbuffer_size(rb));
+
+ // Add some more to wrap buffer
+
+ uint8_t cc[] = {0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC};
+ ringbuffer_insert(rb, cc, sizeof(cc));
+ EXPECT_EQ(2, ringbuffer_available(rb));
+ EXPECT_EQ(14, ringbuffer_size(rb));
+
+ uint8_t content2[] = {0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xCC, 0xCC};
+ peeked = ringbuffer_peek(rb, peek, 7);
+ EXPECT_EQ(7, peeked);
+ ASSERT_TRUE(0 == memcmp(content2, peek, peeked));
+
+ // Pop buffer
+
+ memset(peek, 0, 16);
+ size_t popped = ringbuffer_pop(rb, peek, 7);
+ EXPECT_EQ(7, popped);
+ EXPECT_EQ(9, ringbuffer_available(rb));
+ ASSERT_TRUE(0 == memcmp(content2, peek, peeked));
+
+ // Add more again to check head motion
+
+ uint8_t dd[] = { 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD };
+ added = ringbuffer_insert(rb, dd, sizeof(dd));
+ EXPECT_EQ(8, added);
+ EXPECT_EQ(1, ringbuffer_available(rb));
+
+ // Delete everything
+
+ ringbuffer_delete(rb, 16);
+ EXPECT_EQ(16, ringbuffer_available(rb));
+ EXPECT_EQ(0, ringbuffer_size(rb));
+
+ // Add small token
+
+ uint8_t ae[] = { 0xAE, 0xAE, 0xAE };
+ added = ringbuffer_insert(rb, ae, sizeof(ae));
+ EXPECT_EQ(13, ringbuffer_available(rb));
+
+ // Get everything
+
+ popped = ringbuffer_pop(rb, peek, 16);
+ EXPECT_EQ(added, popped);
+ EXPECT_EQ(16, ringbuffer_available(rb));
+ EXPECT_EQ(0, ringbuffer_size(rb));
+ ASSERT_TRUE(0 == memcmp(ae, peek, popped));
+
+ ringbuffer_free(rb);
+}
diff --git a/stack/btm/btm_ble.c b/stack/btm/btm_ble.c
index 8201c57..45f8e6f 100644
--- a/stack/btm/btm_ble.c
+++ b/stack/btm/btm_ble.c
@@ -621,11 +621,11 @@
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (remote_bda);
tBTM_INQ_INFO *p_inq_info = BTM_InqDbRead(remote_bda);
- *p_dev_type = BT_DEVICE_TYPE_BREDR;
*p_addr_type = BLE_ADDR_PUBLIC;
if (!p_dev_rec)
{
+ *p_dev_type = BT_DEVICE_TYPE_BREDR;
/* Check with the BT manager if details about remote device are known */
if (p_inq_info != NULL)
{
@@ -644,14 +644,79 @@
p_dev_rec->device_type = p_inq_info->results.device_type;
p_dev_rec->ble.ble_addr_type = p_inq_info->results.ble_addr_type;
}
- *p_dev_type = p_dev_rec->device_type;
- *p_addr_type = p_dev_rec->ble.ble_addr_type;
+ if (memcmp(p_dev_rec->bd_addr, remote_bda, BD_ADDR_LEN) == 0 &&
+ memcmp(p_dev_rec->ble.pseudo_addr, remote_bda, BD_ADDR_LEN) == 0)
+ {
+ *p_dev_type = p_dev_rec->device_type;
+ *p_addr_type = p_dev_rec->ble.ble_addr_type;
+ }
+ else if (memcmp(p_dev_rec->ble.pseudo_addr, remote_bda, BD_ADDR_LEN) == 0)
+ {
+ *p_dev_type = BT_DEVICE_TYPE_BLE;
+ *p_addr_type = p_dev_rec->ble.ble_addr_type;
+ }
+ else /* matching static adddress only */
+ {
+ *p_dev_type = BT_DEVICE_TYPE_BREDR;
+ *p_addr_type = BLE_ADDR_PUBLIC;
+ }
}
BTM_TRACE_DEBUG ("btm_find_dev_type - device_type = %d addr_type = %d", *p_dev_type , *p_addr_type);
}
+
+/*******************************************************************************
+**
+** Function BTM_ReadConnectedTransportAddress
+**
+** Description This function is called to read the paired device/address type of other device paired
+** corresponding to the BD_address
+**
+** Parameter remote_bda: remote device address, carry out the transport address
+** transport: active transport
+**
+** Return TRUE if an active link is identified; FALSE otherwise
+**
+*******************************************************************************/
+BOOLEAN BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, tBT_TRANSPORT transport)
+{
+ tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(remote_bda);
+ tACL_CONN *p = btm_bda_to_acl(remote_bda, transport);
+
+ /* if no device can be located, return */
+ if (p_dev_rec == NULL)
+ return FALSE;
+
+ if (transport == BT_TRANSPORT_BR_EDR)
+ {
+ if (btm_bda_to_acl(p_dev_rec->bd_addr, transport) != NULL)
+ {
+ memcpy(remote_bda, p_dev_rec->bd_addr, BD_ADDR_LEN);
+ return TRUE;
+ }
+ else if (p_dev_rec->device_type & BT_DEVICE_TYPE_BREDR)
+ {
+ memcpy(remote_bda, p_dev_rec->bd_addr, BD_ADDR_LEN);
+ }
+ else
+ memset(remote_bda, 0, BD_ADDR_LEN);
+ return FALSE;
+ }
+
+ if (transport == BT_TRANSPORT_LE)
+ {
+ memcpy(remote_bda, p_dev_rec->ble.pseudo_addr, BD_ADDR_LEN);
+ if (btm_bda_to_acl(p_dev_rec->ble.pseudo_addr, transport) != NULL)
+ return TRUE;
+ else
+ return FALSE;
+ }
+
+ return FALSE;
+}
+
/*******************************************************************************
**
** Function BTM_BleReceiverTest
@@ -995,6 +1060,10 @@
p_rec->ble.static_addr_type = p_keys->pid_key.addr_type;
p_rec->ble.key_type |= BTM_LE_KEY_PID;
BTM_TRACE_DEBUG("BTM_LE_KEY_PID key_type=0x%x save peer IRK", p_rec->ble.key_type);
+ /* update device record address as static address */
+ memcpy(p_rec->bd_addr, p_keys->pid_key.static_addr, BD_ADDR_LEN);
+ /* combine DUMO device security record if needed */
+ btm_consolidate_dev(p_rec);
break;
case BTM_LE_KEY_PCSRK:
@@ -1700,7 +1769,8 @@
if (!p_dev_rec)
{
/* There is no device record for new connection. Allocate one */
- p_dev_rec = btm_sec_alloc_dev (bda);
+ if ((p_dev_rec = btm_sec_alloc_dev (bda)) == NULL)
+ return;
}
else /* Update the timestamp for this device */
{
@@ -1711,6 +1781,8 @@
p_dev_rec->device_type |= BT_DEVICE_TYPE_BLE;
p_dev_rec->ble_hci_handle = handle;
p_dev_rec->ble.ble_addr_type = addr_type;
+ /* update pseudo address */
+ memcpy(p_dev_rec->ble.pseudo_addr, bda, BD_ADDR_LEN);
p_dev_rec->role_master = FALSE;
if (role == HCI_ROLE_MASTER)
@@ -1798,10 +1870,20 @@
else
{
role = HCI_ROLE_UNKNOWN;
-
if (status != HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT)
+ {
btm_ble_set_conn_st(BLE_CONN_IDLE);
+#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
+ btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, TRUE);
+#endif
}
+ else
+ {
+#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
+ btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE);
+#endif
+ }
+ }
btm_ble_update_mode_operation(role, bda, status);
}
@@ -1928,6 +2010,7 @@
if (res == BTM_SUCCESS)
{
+ p_dev_rec->device_type |= BT_DEVICE_TYPE_BLE;
p_dev_rec->sec_state = BTM_SEC_STATE_IDLE;
#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
/* add all bonded device into resolving list if IRK is available*/
@@ -2328,6 +2411,14 @@
{
memcpy(btm_cb.devcb.id_keys.irk, p->param_buf, BT_OCTET16_LEN);
btm_notify_new_key(BTM_BLE_KEY_TYPE_ID);
+
+#if BLE_PRIVACY_SPT == TRUE
+ /* if privacy is enabled, new RPA should be calculated */
+ if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE)
+ {
+ btm_gen_resolvable_private_addr((void *)btm_gen_resolve_paddr_low);
+ }
+#endif
}
else
{
diff --git a/stack/btm/btm_ble_addr.c b/stack/btm/btm_ble_addr.c
index b3a3b33..96fb050 100644
--- a/stack/btm/btm_ble_addr.c
+++ b/stack/btm/btm_ble_addr.c
@@ -429,30 +429,6 @@
*******************************************************************************/
/*******************************************************************************
**
-** Function btm_ble_map_bda_to_conn_bda
-**
-** Description This function map a BD address to the real connection address
-** and return the connection address type.
-*******************************************************************************/
-tBLE_ADDR_TYPE btm_ble_map_bda_to_conn_bda(BD_ADDR bd_addr)
-{
- tBTM_SEC_DEV_REC *p_dev_rec = NULL;
- BTM_TRACE_EVENT ("btm_ble_map_bda_to_conn_bda");
- if ((p_dev_rec = btm_find_dev (bd_addr)) != NULL &&
- (p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE)
- {
- if (p_dev_rec->ble.ble_addr_type != BLE_ADDR_PUBLIC)
- {
- memcpy(bd_addr, p_dev_rec->ble.static_addr, BD_ADDR_LEN);
- }
- return p_dev_rec->ble.ble_addr_type;
- }
- else
- return BLE_ADDR_PUBLIC;
-}
-
-/*******************************************************************************
-**
** Function btm_find_dev_by_identity_addr
**
** Description find the security record whose LE static address is matching
@@ -507,9 +483,6 @@
btm_ble_read_resolving_list_entry(p_dev_rec);
/* assign the original address to be the current report address */
- memcpy(bd_addr, p_dev_rec->bd_addr, BD_ADDR_LEN);
-
- /* assign the original address to be the current report address */
if (!btm_ble_init_pseudo_addr (p_dev_rec, bd_addr))
memcpy(bd_addr, p_dev_rec->ble.pseudo_addr, BD_ADDR_LEN);
diff --git a/stack/btm/btm_ble_bgconn.c b/stack/btm/btm_ble_bgconn.c
index 0e65e2b..9e7ce9c 100644
--- a/stack/btm/btm_ble_bgconn.c
+++ b/stack/btm/btm_ble_bgconn.c
@@ -380,17 +380,20 @@
btm_execute_wl_dev_operation();
#if BLE_PRIVACY_SPT == TRUE
- btm_ble_enable_resolving_list_for_platform();
+ btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_INIT);
#endif
- scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ?
+ scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF) ?
BTM_BLE_SCAN_SLOW_INT_1 : p_cb->scan_int;
- scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ?
+ scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ?
BTM_BLE_SCAN_SLOW_WIN_1 : p_cb->scan_win;
- if (btm_cb.ble_ctr_cb.enabled)
+
+#if BLE_PRIVACY_SPT == TRUE
+ if (btm_cb.ble_ctr_cb.rl_state != BTM_BLE_RL_IDLE)
{
own_addr_type |= BLE_ADDR_TYPE_ID_BIT;
peer_addr_type |= BLE_ADDR_TYPE_ID_BIT;
}
+#endif
if (!btsnd_hcic_ble_create_ll_conn (scan_int, /* UINT16 scan_int */
scan_win, /* UINT16 scan_win */
@@ -429,10 +432,8 @@
}
else
{
-#if 0
- BTM_TRACE_ERROR("conn_st = %d, not in auto conn state, can not stop.", p_cb->conn_state);
+ BTM_TRACE_DEBUG("conn_st = %d, not in auto conn state, cannot stop", p_cb->conn_state);
exec = FALSE;
-#endif
}
}
return exec;
@@ -454,9 +455,8 @@
BOOLEAN btm_ble_start_select_conn(BOOLEAN start,tBTM_BLE_SEL_CBACK *p_select_cback)
{
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
- UINT16 scan_int, scan_win;
-
- BTM_TRACE_EVENT ("btm_ble_start_select_conn");
+ UINT32 scan_int = p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int;
+ UINT32 scan_win = p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win;
scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int;
scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win;
@@ -488,6 +488,9 @@
}
else if (background_connections_pending())
{
+#if BLE_PRIVACY_SPT == TRUE
+ btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN);
+#endif
if (!btsnd_hcic_ble_set_scan_enable(TRUE, TRUE)) /* duplicate filtering enabled */
return FALSE;
@@ -549,19 +552,16 @@
** Returns none.
**
*******************************************************************************/
-void btm_ble_suspend_bg_conn(void)
+BOOLEAN btm_ble_suspend_bg_conn(void)
{
- tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
- BTM_TRACE_EVENT ("btm_ble_suspend_bg_conn");
+ BTM_TRACE_EVENT ("%s", __func__);
- if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO)
- {
- btm_ble_start_auto_conn(FALSE);
- }
- else if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE)
- {
- btm_ble_start_select_conn(FALSE, NULL);
- }
+ if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO)
+ return btm_ble_start_auto_conn(FALSE);
+ else if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE)
+ return btm_ble_start_select_conn(FALSE, NULL);
+
+ return FALSE;
}
/*******************************************************************************
**
diff --git a/stack/btm/btm_ble_gap.c b/stack/btm/btm_ble_gap.c
index 8912c25..154f047 100644
--- a/stack/btm/btm_ble_gap.c
+++ b/stack/btm/btm_ble_gap.c
@@ -303,9 +303,13 @@
tBTM_INQ_RESULTS_CB *p_results_cb, tBTM_CMPL_CB *p_cmpl_cb)
{
tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var;
- tBTM_STATUS status = BTM_WRONG_MODE;
+ tBTM_STATUS status = BTM_WRONG_MODE;
- BTM_TRACE_EVENT ("BTM_BleObserve : scan_type:%d",btm_cb.btm_inq_vars.scan_type);
+ UINT32 scan_interval = !p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval;
+ UINT32 scan_window = !p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window;
+
+ BTM_TRACE_EVENT ("%s : scan_type:%d, %d, %d", __func__, btm_cb.btm_inq_vars.scan_type,
+ p_inq->scan_interval, p_inq->scan_window);
if (!controller_get_interface()->supports_ble())
return BTM_ILLEGAL_VALUE;
@@ -315,7 +319,7 @@
/* shared inquiry database, do not allow observe if any inquiry is active */
if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity))
{
- BTM_TRACE_ERROR("Observe Already Active");
+ BTM_TRACE_ERROR("%s Observe Already Active", __func__);
return status;
}
@@ -326,24 +330,36 @@
/* scan is not started */
if (!BTM_BLE_IS_SCAN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity))
{
- p_inq->scan_type = (p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE) ? BTM_BLE_SCAN_MODE_ACTI: p_inq->scan_type;
- /* allow config scanning type */
- btsnd_hcic_ble_set_scan_params (p_inq->scan_type,
- (UINT16)(!p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval),
- (UINT16)(!p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window),
- btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type,
- BTM_BLE_DEFAULT_SFP); /* assume observe always not using white list */
+ /* allow config of scan type */
+ p_inq->scan_type = (p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE) ?
+ BTM_BLE_SCAN_MODE_ACTI: p_inq->scan_type;
+ /* assume observe always not using white list */
+ #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
+ /* enable resolving list */
+ btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN);
+ #endif
-#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
- /* enable resolving list */
- btm_ble_enable_resolving_list_for_platform();
-#endif
- status = btm_ble_start_scan(BTM_BLE_DUPLICATE_DISABLE);
+ if (cmn_ble_vsc_cb.extended_scan_support == 0)
+ {
+ btsnd_hcic_ble_set_scan_params(p_inq->scan_type, (UINT16)scan_interval,
+ (UINT16)scan_window,
+ btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type,
+ BTM_BLE_DEFAULT_SFP);
+ }
+ else
+ {
+ btm_ble_send_extended_scan_params(p_inq->scan_type, scan_interval, scan_window,
+ btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type,
+ BTM_BLE_DEFAULT_SFP);
+ }
+
+ p_inq->scan_duplicate_filter = BTM_BLE_DUPLICATE_DISABLE;
+ status = btm_ble_start_scan();
}
+
if (status == BTM_CMD_STARTED)
{
btm_cb.ble_ctr_cb.scan_activity |= BTM_LE_OBSERVE_ACTIVE;
-
if (duration != 0)
/* start observer timer */
btu_start_timer (&btm_cb.ble_ctr_cb.obs_timer_ent, BTU_TTYPE_BLE_OBSERVE, duration);
@@ -356,7 +372,7 @@
}
else
{
- BTM_TRACE_ERROR("Observe not active");
+ BTM_TRACE_ERROR("%s Observe not active", __func__);
}
return status;
@@ -414,6 +430,9 @@
else if (!start)
{
status = btm_ble_stop_adv();
+#if BLE_PRIVACY_SPT == TRUE
+ btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE);
+#endif
}
else
{
@@ -457,7 +476,7 @@
STREAM_TO_UINT8 (btm_cb.cmn_ble_vsc_cb.max_filter, p);
STREAM_TO_UINT8 (btm_cb.cmn_ble_vsc_cb.energy_support, p);
- if (BTM_NEW_VSC_CHIP_CAPBLTY_RSP_LEN == p_vcs_cplt_params->param_len)
+ if (btm_cb.cmn_ble_vsc_cb.version_supported == BTM_VSC_CHIP_CAPABILITY_M_VERSION)
{
STREAM_TO_UINT16 (btm_cb.cmn_ble_vsc_cb.version_supported, p);
STREAM_TO_UINT16 (btm_cb.cmn_ble_vsc_cb.total_trackable_advertisers, p);
@@ -465,9 +484,10 @@
btm_cb.cmn_ble_vsc_cb.values_read = TRUE;
}
- BTM_TRACE_DEBUG("btm_ble_vnd_cap_vsc_cmpl_cback: stat=%d, irk=%d, ADV ins:%d, rpa=%d, ener=%d",
- status,btm_cb.cmn_ble_vsc_cb.max_irk_list_sz, btm_cb.cmn_ble_vsc_cb.adv_inst_max,
- btm_cb.cmn_ble_vsc_cb.rpa_offloading, btm_cb.cmn_ble_vsc_cb.energy_support);
+ BTM_TRACE_DEBUG("%s: stat=%d, irk=%d, ADV ins:%d, rpa=%d, ener=%d, ext_scan=%d",
+ __func__, status, btm_cb.cmn_ble_vsc_cb.max_irk_list_sz,
+ btm_cb.cmn_ble_vsc_cb.adv_inst_max, btm_cb.cmn_ble_vsc_cb.rpa_offloading,
+ btm_cb.cmn_ble_vsc_cb.energy_support, btm_cb.cmn_ble_vsc_cb.extended_scan_support);
if (BTM_BleMaxMultiAdvInstanceCount() > 0)
btm_ble_multi_adv_init();
@@ -869,13 +889,17 @@
if ((p_dev_rec = btm_find_or_alloc_dev (p_cb->direct_bda.bda)) != NULL &&
p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT)
{
- btm_ble_enable_resolving_list();
+ btm_ble_enable_resolving_list(BTM_BLE_RL_ADV);
memcpy(p_peer_addr_ptr, p_dev_rec->ble.static_addr, BD_ADDR_LEN);
*p_peer_addr_type = p_dev_rec->ble.static_addr_type;
*p_own_addr_type = BLE_ADDR_RANDOM_ID;
return evt_type;
}
/* otherwise fall though as normal directed adv */
+ else
+ {
+ btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE);
+ }
}
#endif
/* direct adv mode does not have privacy, if privacy is not enabled */
@@ -909,13 +933,11 @@
/* resolving list is empty, not enabled */
*p_own_addr_type = BLE_ADDR_RANDOM;
}
-
/* privacy 1.1, or privacy 1.2, general discoverable/connectable mode, disable privacy in */
/* controller fall back to host based privacy */
else if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE)
{
*p_own_addr_type = BLE_ADDR_RANDOM;
- btm_ble_disable_resolving_list ();
}
#endif
@@ -1672,6 +1694,7 @@
else
status = btm_ble_stop_adv();
}
+
if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE)
{
p_cb->fast_adv_on = TRUE;
@@ -1679,6 +1702,12 @@
btu_start_timer (&p_cb->fast_adv_timer, BTU_TTYPE_BLE_GAP_FAST_ADV,
BTM_BLE_GAP_FAST_ADV_TOUT);
}
+ else
+ {
+#if BLE_PRIVACY_SPT == TRUE
+ btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE);
+#endif
+ }
/* set up stop advertising timer */
if (status == BTM_SUCCESS && mode == BTM_BLE_LIMITED_DISCOVERABLE)
@@ -1775,6 +1804,12 @@
btu_start_timer (&p_cb->fast_adv_timer, BTU_TTYPE_BLE_GAP_FAST_ADV,
BTM_BLE_GAP_FAST_ADV_TOUT);
}
+ else
+ {
+#if BLE_PRIVACY_SPT == TRUE
+ btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE);
+#endif
+ }
return status;
}
@@ -1820,9 +1855,10 @@
#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
/* enable IRK list */
- btm_ble_enable_resolving_list_for_platform();
+ btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN);
#endif
- status = btm_ble_start_scan(BTM_BLE_DUPLICATE_DISABLE);
+ p_ble_cb->inq_var.scan_duplicate_filter = BTM_BLE_DUPLICATE_DISABLE;
+ status = btm_ble_start_scan();
}
if (status == BTM_CMD_STARTED)
@@ -2703,13 +2739,13 @@
** Returns void
**
*******************************************************************************/
-tBTM_STATUS btm_ble_start_scan (UINT8 filter_enable)
+tBTM_STATUS btm_ble_start_scan(void)
{
tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var;
tBTM_STATUS status = BTM_CMD_STARTED;
/* start scan, disable duplicate filtering */
- if (!btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, filter_enable))
+ if (!btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, p_inq->scan_duplicate_filter))
{
status = BTM_NO_RESOURCES;
}
@@ -2864,15 +2900,12 @@
return BTM_WRONG_MODE;
#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
- /* When privacy 1.2 goes into general connection/discoverable mode, */
- /* disable controller privacy */
- if (p_cb->afp == AP_SCAN_CONN_ALL && btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_1_2)
- btm_ble_disable_resolving_list();
- else
- /* enable resolving list is desired*/
- btm_ble_enable_resolving_list_for_platform();
+ /* To relax resolving list, always have resolving list enabled, unless directed adv */
+ if (p_cb->evt_type != BTM_BLE_CONNECT_LO_DUTY_DIR_EVT &&
+ p_cb->evt_type != BTM_BLE_CONNECT_DIR_EVT)
+ /* enable resolving list is desired */
+ btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_ADV);
#endif
-
if (p_cb->afp != AP_SCAN_CONN_ALL)
{
btm_execute_wl_dev_operation();
@@ -3213,7 +3246,7 @@
{
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
- BTM_TRACE_EVENT ("btm_ble_init ");
+ BTM_TRACE_DEBUG("%s", __func__);
memset(p_cb, 0, sizeof(tBTM_BLE_CB));
memset(&(btm_cb.cmn_ble_vsc_cb), 0 , sizeof(tBTM_BLE_VSC_CB));
@@ -3229,7 +3262,7 @@
p_cb->inq_var.discoverable_mode = BTM_BLE_NON_DISCOVERABLE;
/* for background connection, reset connection params to be undefined */
- p_cb->scan_int = p_cb->scan_win = BTM_BLE_CONN_PARAM_UNDEF;
+ p_cb->scan_int = p_cb->scan_win = BTM_BLE_SCAN_PARAM_UNDEF;
p_cb->inq_var.evt_type = BTM_BLE_NON_CONNECT_EVT;
diff --git a/stack/btm/btm_ble_int.h b/stack/btm/btm_ble_int.h
index adf0837..79038b8 100644
--- a/stack/btm/btm_ble_int.h
+++ b/stack/btm/btm_ble_int.h
@@ -119,45 +119,42 @@
#define BTM_BLE_VALID_PRAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == BTM_BLE_CONN_PARAM_UNDEF))
-#define BTM_BLE_PRIVATE_ADDR_INT 900 /* 15 minutes minimum for
- random address refreshing */
+#define BTM_BLE_PRIVATE_ADDR_INT 900 /* 15 minutes minimum for random address refreshing */
typedef struct
{
+ UINT16 discoverable_mode;
+ UINT16 connectable_mode;
+ UINT32 scan_window;
+ UINT32 scan_interval;
+ UINT8 scan_type; /* current scan type: active or passive */
+ UINT8 scan_duplicate_filter; /* duplicate filter enabled for scan */
+ UINT16 adv_interval_min;
+ UINT16 adv_interval_max;
+ tBTM_BLE_AFP afp; /* advertising filter policy */
+ tBTM_BLE_SFP sfp; /* scanning filter policy */
- UINT16 discoverable_mode;
- UINT16 connectable_mode;
- UINT16 scan_window;
- UINT16 scan_interval;
- UINT8 scan_type; /* current scan type: active or passive */
- UINT16 adv_interval_min;
- UINT16 adv_interval_max;
- tBTM_BLE_AFP afp; /* advertising filter policy */
- tBTM_BLE_SFP sfp; /* scanning filter policy */
+ tBLE_ADDR_TYPE adv_addr_type;
+ UINT8 evt_type;
+ UINT8 adv_mode;
+ tBLE_BD_ADDR direct_bda;
+ tBTM_BLE_EVT directed_conn;
+ BOOLEAN fast_adv_on;
+ TIMER_LIST_ENT fast_adv_timer;
- tBLE_ADDR_TYPE adv_addr_type;
- UINT8 evt_type;
- UINT8 adv_mode;
- tBLE_BD_ADDR direct_bda;
- tBTM_BLE_EVT directed_conn;
- BOOLEAN fast_adv_on;
- TIMER_LIST_ENT fast_adv_timer;
-
- UINT8 adv_len;
- UINT8 adv_data_cache[BTM_BLE_CACHE_ADV_DATA_MAX];
+ UINT8 adv_len;
+ UINT8 adv_data_cache[BTM_BLE_CACHE_ADV_DATA_MAX];
/* inquiry BD addr database */
- UINT8 num_bd_entries;
- UINT8 max_bd_entries;
+ UINT8 num_bd_entries;
+ UINT8 max_bd_entries;
+ tBTM_BLE_LOCAL_ADV_DATA adv_data;
+ tBTM_BLE_ADV_CHNL_MAP adv_chnl_map;
-
- tBTM_BLE_LOCAL_ADV_DATA adv_data;
- tBTM_BLE_ADV_CHNL_MAP adv_chnl_map;
-
- TIMER_LIST_ENT inq_timer_ent;
- BOOLEAN scan_rsp;
- UINT8 state; /* Current state that the inquiry process is in */
- INT8 tx_power;
+ TIMER_LIST_ENT inq_timer_ent;
+ BOOLEAN scan_rsp;
+ UINT8 state; /* Current state that the inquiry process is in */
+ INT8 tx_power;
} tBTM_BLE_INQ_CB;
@@ -207,6 +204,13 @@
#define BTM_BLE_WL_ADV 4
typedef UINT8 tBTM_BLE_WL_STATE;
+/* resolving list using state as a bit mask */
+#define BTM_BLE_RL_IDLE 0
+#define BTM_BLE_RL_INIT 1
+#define BTM_BLE_RL_SCAN 2
+#define BTM_BLE_RL_ADV 4
+typedef UINT8 tBTM_BLE_RL_STATE;
+
/* BLE connection state */
#define BLE_CONN_IDLE 0
#define BLE_DIR_CONN 1
@@ -285,7 +289,7 @@
*/
typedef struct
{
- UINT8 scan_activity; /* LE scan activity mask */
+ UINT8 scan_activity; /* LE scan activity mask */
/*****************************************************
** BLE Inquiry
@@ -299,13 +303,13 @@
/* background connection procedure cb value */
tBTM_BLE_CONN_TYPE bg_conn_type;
- UINT16 scan_int;
- UINT16 scan_win;
+ UINT32 scan_int;
+ UINT32 scan_win;
tBTM_BLE_SEL_CBACK *p_select_cback;
/* white list information */
- UINT8 white_list_avail_size;
- tBTM_BLE_WL_STATE wl_state;
+ UINT8 white_list_avail_size;
+ tBTM_BLE_WL_STATE wl_state;
BUFFER_Q conn_pending_q;
tBTM_BLE_CONN_ST conn_state;
@@ -317,16 +321,19 @@
#if BLE_PRIVACY_SPT == TRUE
BOOLEAN mixed_mode; /* privacy 1.2 mixed mode is on or not */
- tBTM_PRIVACY_MODE privacy_mode; /* privacy mode */
- UINT8 resolving_list_avail_size; /* resolving list available size */
- UINT8 *irk_list_mask; /* IRK list availability mask, up to max entry bits */
- tBTM_BLE_RESOLVE_Q resolving_list_pend_q;
+ tBTM_PRIVACY_MODE privacy_mode; /* privacy mode */
+ UINT8 resolving_list_avail_size; /* resolving list available size */
+ tBTM_BLE_RESOLVE_Q resolving_list_pend_q; /* Resolving list queue */
+ tBTM_BLE_RL_STATE suspended_rl_state; /* Suspended resolving list state */
+ UINT8 *irk_list_mask; /* IRK list availability mask, up to max entry bits */
+ tBTM_BLE_RL_STATE rl_state; /* Resolving list state */
#endif
+
tBTM_BLE_WL_OP wl_op_q[BTM_BLE_MAX_BG_CONN_DEV_NUM];
/* current BLE link state */
- tBTM_BLE_STATE_MASK cur_states; /* bit mask of tBTM_BLE_STATE */
- UINT8 link_count[2]; /* total link count master and slave*/
+ tBTM_BLE_STATE_MASK cur_states; /* bit mask of tBTM_BLE_STATE */
+ UINT8 link_count[2]; /* total link count master and slave*/
} tBTM_BLE_CB;
#ifdef __cplusplus
@@ -359,7 +366,7 @@
tBTM_BLE_ADV_DATA *p_data);
extern tBTM_STATUS btm_ble_start_adv(void);
extern tBTM_STATUS btm_ble_stop_adv(void);
-extern tBTM_STATUS btm_ble_start_scan (UINT8 filter_enb);
+extern tBTM_STATUS btm_ble_start_scan(void);
extern void btm_ble_create_ll_conn_complete (UINT8 status);
/* LE security function from btm_sec.c */
@@ -400,7 +407,7 @@
extern void btm_ble_white_list_init(UINT8 white_list_size);
/* background connection function */
-extern void btm_ble_suspend_bg_conn(void);
+extern BOOLEAN btm_ble_suspend_bg_conn(void);
extern BOOLEAN btm_ble_resume_bg_conn(void);
extern void btm_ble_initiate_select_conn(BD_ADDR bda);
extern BOOLEAN btm_ble_start_auto_conn(BOOLEAN start);
@@ -433,9 +440,9 @@
extern void btm_ble_add_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len);
extern void btm_ble_clear_resolving_list_complete(UINT8 *p, UINT16 evt_len);
extern void btm_read_ble_resolving_list_size_complete (UINT8 *p, UINT16 evt_len);
-extern void btm_ble_enable_resolving_list(void);
-extern void btm_ble_disable_resolving_list(void);
-extern void btm_ble_enable_resolving_list_for_platform (void);
+extern void btm_ble_enable_resolving_list(UINT8);
+extern BOOLEAN btm_ble_disable_resolving_list(UINT8 rl_mask, BOOLEAN to_resume);
+extern void btm_ble_enable_resolving_list_for_platform (UINT8 rl_mask);
extern void btm_ble_resolving_list_init(UINT8 max_irk_list_sz);
extern void btm_ble_resolving_list_cleanup(void);
#endif
diff --git a/stack/btm/btm_ble_multi_adv.c b/stack/btm/btm_ble_multi_adv.c
index 1e90f0d..6ee3e94 100644
--- a/stack/btm/btm_ble_multi_adv.c
+++ b/stack/btm/btm_ble_multi_adv.c
@@ -357,7 +357,7 @@
btm_ble_multi_adv_vsc_cmpl_cback)) == BTM_CMD_STARTED)
{
/* start a periodical timer to refresh random addr */
- btu_stop_timer(&p_inst->raddr_timer_ent);
+ btu_stop_timer_oneshot(&p_inst->raddr_timer_ent);
p_inst->raddr_timer_ent.param = (TIMER_PARAM_TYPE) p_inst;
btu_start_timer_oneshot(&p_inst->raddr_timer_ent, BTU_TTYPE_BLE_RANDOM_ADDR,
BTM_BLE_PRIVATE_ADDR_INT);
@@ -739,7 +739,7 @@
== BTM_CMD_STARTED)
{
btm_ble_multi_adv_configure_rpa(&btm_multi_adv_cb.p_adv_inst[inst_id-1]);
- btu_stop_timer(&btm_multi_adv_cb.p_adv_inst[inst_id-1].raddr_timer_ent);
+ btu_stop_timer_oneshot(&btm_multi_adv_cb.p_adv_inst[inst_id-1].raddr_timer_ent);
btm_multi_adv_cb.p_adv_inst[inst_id-1].in_use = FALSE;
}
}
diff --git a/stack/btm/btm_ble_privacy.c b/stack/btm/btm_ble_privacy.c
index 9174116..fa5a8e0 100644
--- a/stack/btm/btm_ble_privacy.c
+++ b/stack/btm/btm_ble_privacy.c
@@ -138,18 +138,14 @@
*******************************************************************************/
void btm_ble_clear_irk_index(UINT8 index)
{
- tBTM_SEC_DEV_REC *p_dev_rec = &btm_cb.sec_dev_rec[0];
UINT8 byte;
UINT8 bit;
- for (UINT8 i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i ++, p_dev_rec++)
+ if (index < controller_get_interface()->get_ble_resolving_list_max_size())
{
- if (index < controller_get_interface()->get_ble_resolving_list_max_size())
- {
- byte = index / 8;
- bit = index % 8;
- btm_cb.ble_ctr_cb.irk_list_mask[byte] &= (~(1 << bit));
- }
+ byte = index / 8;
+ bit = index % 8;
+ btm_cb.ble_ctr_cb.irk_list_mask[byte] &= (~(1 << bit));
}
}
@@ -449,7 +445,7 @@
tBTM_STATUS btm_ble_remove_resolving_list_entry(tBTM_SEC_DEV_REC *p_dev_rec)
{
/* if controller does not support RPA offloading or privacy 1.2, skip */
- if (controller_get_interface()->get_ble_resolving_list_max_size())
+ if (controller_get_interface()->get_ble_resolving_list_max_size() == 0)
return BTM_WRONG_MODE;
tBTM_STATUS st = BTM_NO_RESOURCES;
@@ -560,6 +556,191 @@
return st;
}
+
+/*******************************************************************************
+**
+** Function btm_ble_suspend_resolving_list_activity
+**
+** Description This function suspends all resolving list activity, including
+** scan, initiating, and advertising, if resolving list is being
+** enabled.
+**
+** Parameters
+**
+** Returns TRUE if suspended; FALSE otherwise
+**
+*******************************************************************************/
+BOOLEAN btm_ble_suspend_resolving_list_activity(void)
+{
+ tBTM_BLE_CB *p_ble_cb = &btm_cb.ble_ctr_cb;
+
+ /* if resolving list is not enabled, do not need to terminate any activity */
+ /* if asking for stop all activity */
+ /* if already suspended */
+ if (p_ble_cb->suspended_rl_state != BTM_BLE_RL_IDLE)
+ return TRUE;
+
+ /* direct connection active, wait until it completed */
+ if (btm_ble_get_conn_st() == BLE_DIR_CONN)
+ {
+ BTM_TRACE_ERROR("resolving list can not be edited, EnQ now");
+ return FALSE;
+ }
+
+ p_ble_cb->suspended_rl_state = BTM_BLE_RL_IDLE;
+
+ if (p_ble_cb->inq_var.adv_mode == BTM_BLE_ADV_ENABLE)
+ {
+ btm_ble_stop_adv();
+ p_ble_cb->suspended_rl_state |= BTM_BLE_RL_ADV;
+ }
+
+ if (BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity))
+ {
+ btm_ble_stop_scan();
+ p_ble_cb->suspended_rl_state |= BTM_BLE_RL_SCAN;
+ }
+
+ if (btm_ble_suspend_bg_conn())
+ p_ble_cb->suspended_rl_state |= BTM_BLE_RL_INIT;
+
+ return TRUE;
+}
+
+/*******************************************************************************
+**
+** Function btm_ble_resume_resolving_list_activity
+**
+** Description This function resumes the resolving list activity, including
+** scanning, initiating, and advertising, if any of these
+** activities has been suspended earlier.
+**
+** Returns none
+**
+*******************************************************************************/
+void btm_ble_resume_resolving_list_activity(void)
+{
+ tBTM_BLE_CB *p_ble_cb = &btm_cb.ble_ctr_cb;
+
+ if (p_ble_cb->suspended_rl_state & BTM_BLE_RL_ADV)
+ btm_ble_start_adv();
+
+ if (p_ble_cb->suspended_rl_state & BTM_BLE_RL_SCAN)
+ btm_ble_start_scan();
+
+ if (p_ble_cb->suspended_rl_state & BTM_BLE_RL_INIT)
+ btm_ble_resume_bg_conn();
+
+ p_ble_cb->suspended_rl_state = BTM_BLE_RL_IDLE;
+}
+
+/*******************************************************************************
+**
+** Function btm_ble_vendor_enable_irk_feature
+**
+** Description This function is called to enable or disable the RRA
+** offloading feature.
+**
+** Parameters enable: enable or disable the RRA offloading feature
+**
+** Returns BTM_SUCCESS if successful
+**
+*******************************************************************************/
+tBTM_STATUS btm_ble_vendor_enable_irk_feature(BOOLEAN enable)
+{
+ UINT8 param[20], *p;
+ tBTM_STATUS st = BTM_MODE_UNSUPPORTED;
+
+ p = param;
+ memset(param, 0, 20);
+
+ /* select feature based on control block settings */
+ UINT8_TO_STREAM(p, BTM_BLE_META_IRK_ENABLE);
+ UINT8_TO_STREAM(p, enable ? 0x01 : 0x00);
+
+ st = BTM_VendorSpecificCommand (HCI_VENDOR_BLE_RPA_VSC, BTM_BLE_IRK_ENABLE_LEN,
+ param, btm_ble_resolving_list_vsc_op_cmpl);
+
+ return st;
+}
+
+/*******************************************************************************
+**
+** Function btm_ble_exe_disable_resolving_list
+**
+** Description execute resolving list disable
+**
+** Returns none
+**
+*******************************************************************************/
+BOOLEAN btm_ble_exe_disable_resolving_list(void)
+{
+ if (!btm_ble_suspend_resolving_list_activity())
+ return FALSE;
+
+ if (!controller_get_interface()->supports_ble_privacy())
+ btm_ble_vendor_enable_irk_feature(FALSE);
+ else
+ btsnd_hcic_ble_set_addr_resolution_enable(FALSE);
+
+ return TRUE;
+}
+
+/*******************************************************************************
+**
+** Function btm_ble_exe_enable_resolving_list
+**
+** Description enable LE resolve address list
+**
+** Returns none
+**
+*******************************************************************************/
+void btm_ble_exe_enable_resolving_list(void)
+{
+ if (!btm_ble_suspend_resolving_list_activity())
+ return;
+
+ if (!controller_get_interface()->supports_ble_privacy())
+ btm_ble_vendor_enable_irk_feature(TRUE);
+ else
+ btsnd_hcic_ble_set_addr_resolution_enable(TRUE);
+}
+
+/*******************************************************************************
+**
+** Function btm_ble_disable_resolving_list
+**
+** Description Disable LE Address resolution
+**
+** Returns none
+**
+*******************************************************************************/
+BOOLEAN btm_ble_disable_resolving_list(UINT8 rl_mask, BOOLEAN to_resume )
+{
+ UINT8 rl_state = btm_cb.ble_ctr_cb.rl_state;
+
+ /* if controller does not support RPA offloading or privacy 1.2, skip */
+ if (controller_get_interface()->get_ble_resolving_list_max_size()== 0)
+ return FALSE;
+
+ btm_cb.ble_ctr_cb.rl_state &= ~rl_mask;
+
+ if (rl_state != BTM_BLE_RL_IDLE && btm_cb.ble_ctr_cb.rl_state == BTM_BLE_RL_IDLE)
+ {
+ if (btm_ble_exe_disable_resolving_list())
+ {
+ if (to_resume)
+ btm_ble_resume_resolving_list_activity();
+
+ return TRUE;
+ }
+ else
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
/*******************************************************************************
**
** Function btm_ble_resolving_list_load_dev
@@ -574,6 +755,8 @@
BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec)
{
BOOLEAN rt = FALSE;
+ UINT8 rl_mask = btm_cb.ble_ctr_cb.rl_state;
+
BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d", __func__,
btm_cb.ble_ctr_cb.privacy_mode);
@@ -586,10 +769,9 @@
/* only add RPA enabled device into resolving list */
if (p_dev_rec != NULL && /* RPA is being used and PID is known */
- p_dev_rec->sec_flags & BTM_SEC_IN_USE &&
- ((p_dev_rec->ble.key_type & BTM_LE_KEY_PID) != 0 ||
- ((p_dev_rec->ble.key_type & BTM_LE_KEY_LID) != 0 &&
- btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE)))
+ (p_dev_rec->sec_flags & BTM_SEC_IN_USE) != 0 &&
+ ((p_dev_rec->ble.key_type & BTM_LE_KEY_PID) != 0 ||
+ (p_dev_rec->ble.key_type & BTM_LE_KEY_LID) != 0))
{
if (!(p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) &&
btm_ble_brcm_find_resolving_pending_entry(p_dev_rec->bd_addr,
@@ -597,36 +779,19 @@
{
if (btm_cb.ble_ctr_cb.resolving_list_avail_size > 0)
{
+ if (rl_mask)
+ {
+ if (!btm_ble_disable_resolving_list (rl_mask, FALSE))
+ return FALSE;
+ }
+
btm_ble_update_resolving_list(p_dev_rec->bd_addr, TRUE);
if (controller_get_interface()->supports_ble_privacy())
{
- UINT8 dummy_irk[HCIC_BLE_IRK_SIZE];
- memset(dummy_irk, 0, HCIC_BLE_IRK_SIZE);
-
- UINT8 *peer_irk;
- if (BTM_BLE_IS_RESOLVE_BDA(p_dev_rec->bd_addr))
- peer_irk = p_dev_rec->ble.keys.irk;
- else
- peer_irk = dummy_irk;
-
- UINT8 *local_irk;
- if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE)
- local_irk = btm_cb.devcb.id_keys.irk;
- else
- local_irk = dummy_irk;
-
BD_ADDR dummy_bda = {0};
- /* for device not assigning static address, use pseudo address as identity */
- peer_irk = p_dev_rec->ble.keys.irk;
- local_irk = btm_cb.devcb.id_keys.irk;
+ UINT8 *peer_irk = p_dev_rec->ble.keys.irk;
+ UINT8 *local_irk = btm_cb.devcb.id_keys.irk;
- // do not enter IRK if peer or local device does not have privacy turned on
- // disable, assume IRK indicate privacy could be enabled at any point,
- // warning: this could take up unnecessary spot in controller resolving list,
- // and could possible degrade performance; this could prevent conneccting
- // to peripheral device which has privacy disabled but IRK delivered per
- // standard privacy 1.2 requirement. Need FW mixed mode support to connect
- // to both RPA and static address.
if (memcmp(p_dev_rec->ble.static_addr, dummy_bda, BD_ADDR_LEN) == 0)
{
memcpy(p_dev_rec->ble.static_addr, p_dev_rec->bd_addr, BD_ADDR_LEN);
@@ -659,6 +824,10 @@
if (rt)
btm_ble_enq_resolving_list_pending(p_dev_rec->bd_addr,
BTM_BLE_META_ADD_IRK_ENTRY);
+
+ /* if resolving list has been turned on, re-enable it */
+ if (rl_mask)
+ btm_ble_enable_resolving_list(rl_mask);
}
}
else
@@ -687,7 +856,14 @@
*******************************************************************************/
void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC *p_dev_rec)
{
- btm_ble_update_resolving_list(p_dev_rec->bd_addr, FALSE);
+ UINT8 rl_mask = btm_cb.ble_ctr_cb.rl_state;
+
+ BTM_TRACE_EVENT ("%s", __func__);
+ if (rl_mask)
+ {
+ if (!btm_ble_disable_resolving_list (rl_mask, FALSE))
+ return;
+ }
if ((p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) &&
btm_ble_brcm_find_resolving_pending_entry(p_dev_rec->bd_addr,
@@ -700,57 +876,10 @@
{
BTM_TRACE_DEBUG("Device not in resolving list");
}
-}
-/*******************************************************************************
-**
-** Function btm_ble_vendor_enable_irk_feature
-**
-** Description This function is called to enable or disable the RRA
-** offloading feature.
-**
-** Parameters enable: enable or disable the RRA offloading feature
-**
-** Returns BTM_SUCCESS if successful
-**
-*******************************************************************************/
-tBTM_STATUS btm_ble_vendor_enable_irk_feature(BOOLEAN enable)
-{
- UINT8 param[20] = {0};
- UINT8 *p = param;
-
- /* select feature based on control block settings */
- UINT8_TO_STREAM(p, BTM_BLE_META_IRK_ENABLE);
- UINT8_TO_STREAM(p, enable ? 0x01 : 0x00);
-
- return BTM_VendorSpecificCommand (HCI_VENDOR_BLE_RPA_VSC, BTM_BLE_IRK_ENABLE_LEN,
- param, btm_ble_resolving_list_vsc_op_cmpl);
-}
-
-/*******************************************************************************
-**
-** Function btm_ble_disable_resolving_list
-**
-** Description disable LE resolve address feature
-**
-** Returns none
-**
-*******************************************************************************/
-void btm_ble_disable_resolving_list(void)
-{
- /* if controller does not support RPA offloading or privacy 1.2, skip */
- if (controller_get_interface()->get_ble_resolving_list_max_size() == 0)
- return;
-
- if (btm_cb.ble_ctr_cb.enabled)
- {
- if (!controller_get_interface()->supports_ble_privacy())
- btm_ble_vendor_enable_irk_feature(FALSE);
- else
- btsnd_hcic_ble_set_addr_resolution_enable(FALSE);
-
- btm_cb.ble_ctr_cb.enabled = FALSE;
- }
+ /* if resolving list has been turned on, re-enable it */
+ if (rl_mask)
+ btm_ble_enable_resolving_list(rl_mask);
}
/*******************************************************************************
@@ -762,17 +891,17 @@
** Returns none
**
*******************************************************************************/
-void btm_ble_enable_resolving_list(void)
+void btm_ble_enable_resolving_list(UINT8 rl_mask)
{
- if (!btm_cb.ble_ctr_cb.enabled &&
+ UINT8 rl_state = btm_cb.ble_ctr_cb.rl_state;
+
+ btm_cb.ble_ctr_cb.rl_state |= rl_mask;
+ if (rl_state == BTM_BLE_RL_IDLE &&
+ btm_cb.ble_ctr_cb.rl_state != BTM_BLE_RL_IDLE &&
controller_get_interface()->get_ble_resolving_list_max_size() != 0)
{
- if (!controller_get_interface()->supports_ble_privacy())
- btm_ble_vendor_enable_irk_feature(TRUE);
- else
- btsnd_hcic_ble_set_addr_resolution_enable(TRUE);
-
- btm_cb.ble_ctr_cb.enabled = TRUE;
+ btm_ble_exe_enable_resolving_list();
+ btm_ble_resume_resolving_list_activity();
}
}
@@ -802,7 +931,7 @@
** Returns none
**
*******************************************************************************/
-void btm_ble_enable_resolving_list_for_platform (void)
+void btm_ble_enable_resolving_list_for_platform (UINT8 rl_mask)
{
/* if controller does not support, skip */
if (controller_get_interface()->get_ble_resolving_list_max_size() == 0)
@@ -811,10 +940,10 @@
if (btm_cb.ble_ctr_cb.wl_state == BTM_BLE_WL_IDLE)
{
if (controller_get_interface()->get_ble_resolving_list_max_size() >
- btm_cb.ble_ctr_cb.resolving_list_avail_size)
- btm_ble_enable_resolving_list();
+ btm_cb.ble_ctr_cb.resolving_list_avail_size)
+ btm_ble_enable_resolving_list(rl_mask);
else
- btm_ble_disable_resolving_list();
+ btm_ble_disable_resolving_list(rl_mask, TRUE);
return;
}
@@ -824,11 +953,11 @@
if ((p_dev->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) &&
(p_dev->ble.in_controller_list & BTM_WHITE_LIST_BIT))
{
- btm_ble_enable_resolving_list();
+ btm_ble_enable_resolving_list(rl_mask);
return;
}
}
- btm_ble_disable_resolving_list();
+ btm_ble_disable_resolving_list(rl_mask, TRUE);
}
/*******************************************************************************
@@ -862,6 +991,7 @@
controller_get_interface()->set_ble_resolving_list_max_size(max_irk_list_sz);
btm_ble_clear_resolving_list();
+ btm_cb.ble_ctr_cb.resolving_list_avail_size = max_irk_list_sz;
}
/*******************************************************************************
diff --git a/stack/btm/btm_dev.c b/stack/btm/btm_dev.c
index 8817101..671d4a6 100644
--- a/stack/btm/btm_dev.c
+++ b/stack/btm/btm_dev.c
@@ -174,23 +174,23 @@
*******************************************************************************/
BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr)
{
- tBTM_SEC_DEV_REC *p_dev_rec;
+ tBTM_SEC_DEV_REC *p_dev_rec;
- if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE) || BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_BR_EDR))
+ if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE) ||
+ BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_BR_EDR))
{
- BTM_TRACE_WARNING("BTM_SecDeleteDevice FAILED: Cannot Delete when connection is active");
- return(FALSE);
+ BTM_TRACE_WARNING("%s FAILED: Cannot Delete when connection is active", __func__);
+ return FALSE;
}
- if ((p_dev_rec = btm_find_dev (bd_addr)) == NULL)
- return(FALSE);
+ if ((p_dev_rec = btm_find_dev(bd_addr)) != NULL)
+ {
+ btm_sec_free_dev(p_dev_rec);
+ /* Tell controller to get rid of the link key, if it has one stored */
+ BTM_DeleteStoredLinkKey (p_dev_rec->bd_addr, NULL);
+ }
- btm_sec_free_dev (p_dev_rec);
-
- /* Tell controller to get rid of the link key if it has one stored */
- BTM_DeleteStoredLinkKey (bd_addr, NULL);
-
- return(TRUE);
+ return TRUE;
}
/*******************************************************************************
diff --git a/stack/btm/btm_devctl.c b/stack/btm/btm_devctl.c
index e635cd1..3a70788 100644
--- a/stack/btm/btm_devctl.c
+++ b/stack/btm/btm_devctl.c
@@ -393,7 +393,7 @@
btm_cb.btm_def_link_policy &= ~HCI_ENABLE_PARK_MODE;
btm_sec_dev_reset ();
-#if ((BTM_EIR_SERVER_INCLUDED == TRUE)||(BTM_EIR_CLIENT_INCLUDED == TRUE))
+
if (HCI_LMP_INQ_RSSI_SUPPORTED(p_features))
{
if (HCI_EXT_INQ_RSP_SUPPORTED(p_features))
@@ -401,10 +401,7 @@
else
BTM_SetInquiryMode (BTM_INQ_RESULT_WITH_RSSI);
}
-#else
- if (HCI_LMP_INQ_RSSI_SUPPORTED(p_features))
- BTM_SetInquiryMode (BTM_INQ_RESULT_WITH_RSSI);
-#endif
+
#if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
if( HCI_NON_FLUSHABLE_PB_SUPPORTED(p_features))
l2cu_set_non_flushable_pbf(TRUE);
diff --git a/stack/btm/btm_sec.c b/stack/btm/btm_sec.c
index 309ae82..db2d300 100644
--- a/stack/btm/btm_sec.c
+++ b/stack/btm/btm_sec.c
@@ -246,6 +246,23 @@
/*******************************************************************************
**
+** Function BTM_SecRegisterLinkKeyNotificationCallback
+**
+** Description Application manager calls this function to register for
+** link key notification. When there is nobody registered
+** we should avoid changing link key
+**
+** Returns TRUE if registered OK, else FALSE
+**
+*******************************************************************************/
+BOOLEAN BTM_SecRegisterLinkKeyNotificationCallback (tBTM_LINK_KEY_CALLBACK *p_callback)
+{
+ btm_cb.api.p_link_key_callback = p_callback;
+ return TRUE;
+}
+
+/*******************************************************************************
+**
** Function BTM_SecAddRmtNameNotifyCallback
**
** Description Any profile can register to be notified when name of the
@@ -4201,7 +4218,7 @@
p_dev_rec->sec_flags &= ~ (BTM_SEC_LE_LINK_KEY_KNOWN);
p_dev_rec->ble.key_type = BTM_LE_KEY_NONE;
}
- btm_ble_link_encrypted(p_dev_rec->bd_addr, encr_enable);
+ btm_ble_link_encrypted(p_dev_rec->ble.pseudo_addr, encr_enable);
return;
}
else
diff --git a/stack/include/bt_types.h b/stack/include/bt_types.h
index e16f53f..85d41bf 100644
--- a/stack/include/bt_types.h
+++ b/stack/include/bt_types.h
@@ -508,7 +508,7 @@
typedef UINT8 tBLE_ADDR_TYPE;
#define BLE_ADDR_TYPE_MASK (BLE_ADDR_RANDOM | BLE_ADDR_PUBLIC)
-
+#define BT_TRANSPORT_INVALID 0
#define BT_TRANSPORT_BR_EDR 1
#define BT_TRANSPORT_LE 2
typedef UINT8 tBT_TRANSPORT;
diff --git a/stack/include/btm_api.h b/stack/include/btm_api.h
index a4d1ba3..6d14423 100644
--- a/stack/include/btm_api.h
+++ b/stack/include/btm_api.h
@@ -3125,6 +3125,18 @@
*******************************************************************************/
extern BOOLEAN BTM_SecRegister (tBTM_APPL_INFO *p_cb_info);
+/*******************************************************************************
+**
+** Function BTM_SecRegisterLinkKeyNotificationCallback
+**
+** Description Profiles can register to be notified when a new Link Key
+** is generated per connection.
+**
+** Returns TRUE if registered OK, else FALSE
+**
+*******************************************************************************/
+extern BOOLEAN BTM_SecRegisterLinkKeyNotificationCallback(
+ tBTM_LINK_KEY_CALLBACK *p_callback);
/*******************************************************************************
**
diff --git a/stack/include/btm_ble_api.h b/stack/include/btm_ble_api.h
index b941d15..c78f8a5 100644
--- a/stack/include/btm_ble_api.h
+++ b/stack/include/btm_ble_api.h
@@ -131,6 +131,7 @@
#define BTM_BLE_CONN_SUP_TOUT_MIN 0x000A
#define BTM_BLE_CONN_SUP_TOUT_MAX 0x0C80
#define BTM_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */
+#define BTM_BLE_SCAN_PARAM_UNDEF 0xffffffff
/* default connection parameters if not configured, use GAP recommend value for auto/selective connection */
/* default scan interval */
@@ -1416,6 +1417,23 @@
extern void BTM_ReadDevInfo (BD_ADDR remote_bda, tBT_DEVICE_TYPE *p_dev_type,
tBLE_ADDR_TYPE *p_addr_type);
+
+/*******************************************************************************
+**
+** Function BTM_ReadConnectedTransportAddress
+**
+** Description This function is called to read the paired device/address type of other device paired
+** corresponding to the BD_address
+**
+** Parameter remote_bda: remote device address, carry out the transport address
+** transport: active transport
+**
+** Return TRUE if an active link is identified; FALSE otherwise
+**
+*******************************************************************************/
+extern BOOLEAN BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda,
+ tBT_TRANSPORT transport);
+
/*******************************************************************************
**
** Function BTM_BleBroadcast
diff --git a/stack/l2cap/l2c_ble.c b/stack/l2cap/l2c_ble.c
index 75032b2..2460bd4 100644
--- a/stack/l2cap/l2c_ble.c
+++ b/stack/l2cap/l2c_ble.c
@@ -352,6 +352,10 @@
p_lcb->peer_chnl_mask[0] = L2CAP_FIXED_CHNL_ATT_BIT | L2CAP_FIXED_CHNL_BLE_SIG_BIT | L2CAP_FIXED_CHNL_SMP_BIT;
btm_ble_set_conn_st(BLE_CONN_IDLE);
+
+#if BLE_PRIVACY_SPT == TRUE
+ btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, TRUE);
+#endif
}
@@ -418,6 +422,10 @@
btm_acl_created (bda, NULL, p_dev_rec->sec_bd_name, handle, p_lcb->link_role, BT_TRANSPORT_LE);
+#if BLE_PRIVACY_SPT == TRUE
+ btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE);
+#endif
+
p_lcb->peer_chnl_mask[0] = L2CAP_FIXED_CHNL_ATT_BIT | L2CAP_FIXED_CHNL_BLE_SIG_BIT | L2CAP_FIXED_CHNL_SMP_BIT;
if (!HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED(controller_get_interface()->get_features_ble()->as_array))
@@ -688,8 +696,8 @@
return(FALSE);
}
- scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int;
- scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win;
+ scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int;
+ scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win;
peer_addr_type = p_lcb->ble_addr_type;
memcpy(peer_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN);
@@ -701,11 +709,11 @@
if (btm_cb.ble_ctr_cb.privacy_mode >= BTM_PRIVACY_1_2)
own_addr_type |= BLE_ADDR_TYPE_ID_BIT;
- btm_ble_enable_resolving_list();
+ btm_ble_enable_resolving_list(BTM_BLE_RL_INIT);
btm_random_pseudo_to_identity_addr(peer_addr, &peer_addr_type);
}
else
- btm_ble_disable_resolving_list();
+ btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, TRUE);
#endif
if (!btm_ble_topology_check(BTM_BLE_STATE_INIT))
diff --git a/stack/smp/smp_act.c b/stack/smp/smp_act.c
index 7c5bd8e..4adde96 100644
--- a/stack/smp/smp_act.c
+++ b/stack/smp/smp_act.c
@@ -178,10 +178,6 @@
p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK;
}
- SMP_TRACE_WARNING ("Cross transport key derivation is not supported");
- p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK;
- p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK;
-
SMP_TRACE_WARNING("set auth_req: 0x%02x, local_i_key: 0x%02x, local_r_key: 0x%02x",
p_cb->loc_auth_req, p_cb->local_i_key, p_cb->local_r_key);
@@ -814,7 +810,8 @@
if (p_cb->role == HCI_ROLE_SLAVE)
{
p_dev_rec->new_encryption_key_is_p256 = FALSE;
- p_cb->cb_evt = SMP_SEC_REQUEST_EVT;
+ /* shortcut to skip Security Grant step */
+ p_cb->cb_evt = SMP_BR_KEYS_REQ_EVT;
}
else /* Master receives pairing response */
{
@@ -911,8 +908,13 @@
if (!p_cb->local_i_key && !p_cb->local_r_key)
{
/* state check to prevent re-entrance */
- if (p_cb->smp_over_br)
- smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason);
+ if (smp_get_br_state() == SMP_BR_STATE_BOND_PENDING)
+ {
+ if (p_cb->total_tx_unacked == 0)
+ smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason);
+ else
+ p_cb->wait_for_authorization_complete = TRUE;
+ }
}
}
@@ -2024,10 +2026,6 @@
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status);
return;
}
-
- smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_LK, FALSE);
- SMP_TRACE_DEBUG("%s successfully completed", __FUNCTION__);
- smp_key_distribution(p_cb, NULL);
}
/*******************************************************************************
@@ -2085,8 +2083,12 @@
void smp_br_pairing_complete(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s", __func__);
- /* process the pairing complete */
- smp_proc_pairing_cmpl(p_cb);
+
+ if (p_cb->total_tx_unacked == 0)
+ {
+ /* process the pairing complete */
+ smp_proc_pairing_cmpl(p_cb);
+ }
}
#endif
diff --git a/stack/smp/smp_l2c.c b/stack/smp/smp_l2c.c
index 7ff278d..6f97742 100644
--- a/stack/smp/smp_l2c.c
+++ b/stack/smp/smp_l2c.c
@@ -216,11 +216,16 @@
if (p_cb->total_tx_unacked >= num_pkt)
p_cb->total_tx_unacked -= num_pkt;
else
- SMP_TRACE_ERROR("Unexpected %s: num_pkt = %d", __FUNCTION__,num_pkt);
+ SMP_TRACE_ERROR("Unexpected %s: num_pkt = %d", __func__,num_pkt);
UINT8 reason = SMP_SUCCESS;
if (p_cb->total_tx_unacked == 0 && p_cb->wait_for_authorization_complete)
- smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
+ {
+ if (cid == L2CAP_SMP_CID)
+ smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
+ else
+ smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason);
+ }
}
/*******************************************************************************