*
******************************************************************************/
void bta_dm_ble_set_bg_conn_type(tBTA_DM_MSG* p_data) {
- BTM_BleSetBgConnType(p_data->ble_set_bd_conn_type.bg_conn_type,
- p_data->ble_set_bd_conn_type.p_select_cback);
+ BTM_BleStartAutoConn();
}
/*******************************************************************************
* BLE ADV data management API
******************************************************************************/
-/*******************************************************************************
- *
- * Function BTA_DmBleSetBgConnType
- *
- * Description This function is called to set BLE connectable mode for a
- * peripheral device.
- *
- * Parameters bg_conn_type: it can be auto connection, or selective
- * connection.
- * p_select_cback: callback function when selective connection
- * procedure is being used.
- *
- * Returns void
- *
- ******************************************************************************/
-void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type,
- tBTA_DM_BLE_SEL_CBACK* p_select_cback) {
- tBTA_DM_API_BLE_SET_BG_CONN_TYPE* p_msg =
- (tBTA_DM_API_BLE_SET_BG_CONN_TYPE*)osi_calloc(
- sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE));
+/**
+ * Set BLE connectable mode to auto connect
+ */
+void BTA_DmBleStartAutoConn() {
+ tBTA_DM_API_SET_NAME* p_msg =
+ (tBTA_DM_API_SET_NAME*)osi_calloc(sizeof(tBTA_DM_API_SET_NAME));
p_msg->hdr.event = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
- p_msg->bg_conn_type = bg_conn_type;
- p_msg->p_select_cback = p_select_cback;
-
bta_sys_sendmsg(p_msg);
}
tBTA_DM_BLE_SEC_GRANT res;
} tBTA_DM_API_BLE_SEC_GRANT;
-typedef struct {
- BT_HDR hdr;
- tBTA_DM_BLE_CONN_TYPE bg_conn_type;
- tBTA_DM_BLE_SEL_CBACK* p_select_cback;
-} tBTA_DM_API_BLE_SET_BG_CONN_TYPE;
-
/* set prefered BLE connection parameters for a device */
typedef struct {
BT_HDR hdr;
tBTA_DM_API_ADD_BLE_DEVICE add_ble_device;
tBTA_DM_API_PASSKEY_REPLY ble_passkey_reply;
tBTA_DM_API_BLE_SEC_GRANT ble_sec_grant;
- tBTA_DM_API_BLE_SET_BG_CONN_TYPE ble_set_bd_conn_type;
tBTA_DM_API_BLE_CONN_PARAMS ble_set_conn_params;
tBTA_DM_API_BLE_CONN_SCAN_PARAMS ble_set_conn_scan_params;
tBTA_DM_API_BLE_SCAN_PARAMS ble_set_scan_params;
BTA_GATTC_Open(bta_hh_cb.gatt_if, p_cb->addr, false, BTA_GATT_TRANSPORT_LE);
p_cb->in_bg_conn = true;
- BTA_DmBleSetBgConnType(BTA_DM_BLE_CONN_AUTO, NULL);
+ BTA_DmBleStartAutoConn();
}
return;
}
#define BTA_DM_SEC_REP_ATTEMPTS BTA_DM_AUTH_SMP_REPEATED_ATTEMPT
typedef uint8_t tBTA_DM_BLE_SEC_GRANT;
-#define BTA_DM_BLE_ONN_NONE BTM_BLE_CONN_NONE
-#define BTA_DM_BLE_CONN_AUTO BTM_BLE_CONN_AUTO
-#define BTA_DM_BLE_CONN_SELECTIVE BTM_BLE_CONN_SELECTIVE
-typedef uint8_t tBTA_DM_BLE_CONN_TYPE;
-
-typedef bool(tBTA_DM_BLE_SEL_CBACK)(BD_ADDR random_bda, uint8_t* p_remote_name);
-
/* Structure associated with BTA_DM_BLE_SEC_REQ_EVT */
typedef struct {
BD_ADDR bd_addr; /* peer address */
******************************************************************************/
extern void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res);
-/*******************************************************************************
- *
- * Function BTA_DmBleSetBgConnType
- *
- * Description This function is called to set BLE connectable mode for a
- * peripheral device.
- *
- * Parameters bg_conn_type: it can be auto connection, or selective
- * connection.
- * p_select_cback: callback function when selective connection
- * procedure is being used.
- *
- * Returns void
- *
- ******************************************************************************/
-extern void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type,
- tBTA_DM_BLE_SEL_CBACK* p_select_cback);
+/**
+ * Set BLE connectable mode to auto connect
+ */
+extern void BTA_DmBleStartAutoConn();
/*******************************************************************************
*
return;
}
}
- BTA_DmBleSetBgConnType(BTM_BLE_CONN_AUTO, NULL);
+ BTA_DmBleStartAutoConn();
}
// Determine transport
}
// Mark background connections
- if (!is_direct) BTA_DmBleSetBgConnType(BTM_BLE_CONN_AUTO, NULL);
+ if (!is_direct) BTA_DmBleStartAutoConn();
// Determine transport
if (transport_param != GATT_TRANSPORT_AUTO) {
/*******************************************************************************
*
- * Function btm_ble_start_select_conn
- *
- * Description This function is to start/stop selective connection
- * procedure.
- *
- * Parameters start: true to start; false to stop.
- * p_select_cback: callback function to return application
- * selection.
- *
- * Returns bool : selective connectino procedure is started.
- *
- ******************************************************************************/
-bool btm_ble_start_select_conn(bool start, tBTM_BLE_SEL_CBACK* p_select_cback) {
- tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb;
- uint32_t scan_int = p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF
- ? BTM_BLE_SCAN_FAST_INT
- : p_cb->scan_int;
- uint32_t scan_win = p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF
- ? BTM_BLE_SCAN_FAST_WIN
- : p_cb->scan_win;
-
- BTM_TRACE_EVENT("%s", __func__);
-
- if (start) {
- if (!BTM_BLE_IS_SCAN_ACTIVE(p_cb->scan_activity)) {
- if (p_select_cback != NULL)
- btm_cb.ble_ctr_cb.p_select_cback = p_select_cback;
-
- btm_execute_wl_dev_operation();
-
- btm_update_scanner_filter_policy(SP_ADV_WL);
- btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_PASS;
-
- /* Process advertising packets only from devices in the white list */
- if (btm_cb.cmn_ble_vsc_cb.extended_scan_support == 0) {
- /* use passive scan by default */
- btsnd_hcic_ble_set_scan_params(
- BTM_BLE_SCAN_MODE_PASS, scan_int, scan_win,
- p_cb->addr_mgnt_cb.own_addr_type, SP_ADV_WL);
- } else {
- btm_ble_send_extended_scan_params(
- BTM_BLE_SCAN_MODE_PASS, scan_int, scan_win,
- p_cb->addr_mgnt_cb.own_addr_type, SP_ADV_WL);
- }
-
- if (!btm_ble_topology_check(BTM_BLE_STATE_PASSIVE_SCAN)) {
- BTM_TRACE_ERROR(
- "peripheral device cannot initiate passive scan for a selective "
- "connection");
- return false;
- } else if (background_connections_pending()) {
-#if (BLE_PRIVACY_SPT == TRUE)
- btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN);
-#endif
- btsnd_hcic_ble_set_scan_enable(true,
- true); /* duplicate filtering enabled */
-
- /* mark up inquiry status flag */
- p_cb->scan_activity |= BTM_LE_SELECT_CONN_ACTIVE;
- p_cb->wl_state |= BTM_BLE_WL_SCAN;
- }
- } else {
- BTM_TRACE_ERROR(
- "scan active, can not start selective connection procedure");
- return false;
- }
- } else /* disable selective connection mode */
- {
- p_cb->scan_activity &= ~BTM_LE_SELECT_CONN_ACTIVE;
- p_cb->p_select_cback = NULL;
- p_cb->wl_state &= ~BTM_BLE_WL_SCAN;
-
- /* stop scanning */
- if (!BTM_BLE_IS_SCAN_ACTIVE(p_cb->scan_activity))
- btm_ble_stop_scan(); /* duplicate filtering enabled */
- }
- return true;
-}
-/*******************************************************************************
- *
- * Function btm_ble_initiate_select_conn
- *
- * Description This function is to start/stop selective connection
- * procedure.
- *
- * Parameters start: true to start; false to stop.
- * p_select_cback: callback function to return application
- * selection.
- *
- * Returns bool : selective connectino procedure is started.
- *
- ******************************************************************************/
-void btm_ble_initiate_select_conn(BD_ADDR bda) {
- BTM_TRACE_EVENT("btm_ble_initiate_select_conn");
-
- /* use direct connection procedure to initiate connection */
- if (!L2CA_ConnectFixedChnl(L2CAP_ATT_CID, bda)) {
- BTM_TRACE_ERROR("btm_ble_initiate_select_conn failed");
- }
-}
-/*******************************************************************************
- *
* Function btm_ble_suspend_bg_conn
*
* Description This function is to suspend an active background connection
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;
}
if (wl_state & BTM_BLE_WL_INIT) {
btm_ble_start_auto_conn(false);
}
- if (wl_state & BTM_BLE_WL_SCAN) {
- btm_ble_start_select_conn(false, NULL);
- }
if (wl_state & BTM_BLE_WL_ADV) {
btm_ble_stop_adv();
}
******************************************************************************/
bool btm_ble_resume_bg_conn(void) {
tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb;
- bool ret = false;
-
- if (p_cb->bg_conn_type != BTM_BLE_CONN_NONE) {
- if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO)
- ret = btm_ble_start_auto_conn(true);
-
- if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE)
- ret = btm_ble_start_select_conn(true, btm_cb.ble_ctr_cb.p_select_cback);
+ if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO) {
+ return btm_ble_start_auto_conn(true);
}
- return ret;
+ return false;
}
/*******************************************************************************
*
#define BTM_BLE_INQ_RESULT 0x01
#define BTM_BLE_OBS_RESULT 0x02
-#define BTM_BLE_SEL_CONN_RESULT 0x04
/* LE states combo bit to check */
const uint8_t btm_le_state_combo_tbl[BTM_BLE_STATE_MAX][BTM_BLE_STATE_MAX][2] =
#endif
}
-/*******************************************************************************
- *
- * Function BTM_BleSetBgConnType
- *
- * Description This function is called to set BLE connectable mode for a
- * peripheral device.
- *
- * Parameters bg_conn_type: it can be auto connection, or selective
- * connection.
- * p_select_cback: callback function when selective
- * connection procedure is being used.
- *
- * Returns void
- *
- ******************************************************************************/
-bool BTM_BleSetBgConnType(tBTM_BLE_CONN_TYPE bg_conn_type,
- tBTM_BLE_SEL_CBACK* p_select_cback) {
- bool started = true;
-
- BTM_TRACE_EVENT("BTM_BleSetBgConnType ");
- if (!controller_get_interface()->supports_ble()) return false;
-
- if (btm_cb.ble_ctr_cb.bg_conn_type != bg_conn_type) {
- switch (bg_conn_type) {
- case BTM_BLE_CONN_AUTO:
- btm_ble_start_auto_conn(true);
- break;
-
- case BTM_BLE_CONN_SELECTIVE:
- if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO) {
- btm_ble_start_auto_conn(false);
- }
- btm_ble_start_select_conn(true, p_select_cback);
- break;
-
- case BTM_BLE_CONN_NONE:
- if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO) {
- btm_ble_start_auto_conn(false);
- } else if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE) {
- btm_ble_start_select_conn(false, NULL);
- }
- started = true;
- break;
-
- default:
- BTM_TRACE_ERROR("invalid bg connection type : %d ", bg_conn_type);
- started = false;
- break;
- }
+/**
+ * Set BLE connectable mode to auto connect
+ */
+void BTM_BleStartAutoConn() {
+ BTM_TRACE_EVENT("%s", __func__);
+ if (!controller_get_interface()->supports_ble()) return;
- if (started) btm_cb.ble_ctr_cb.bg_conn_type = bg_conn_type;
+ if (btm_cb.ble_ctr_cb.bg_conn_type != BTM_BLE_CONN_AUTO) {
+ btm_ble_start_auto_conn(true);
+ btm_cb.ble_ctr_cb.bg_conn_type = BTM_BLE_CONN_AUTO;
}
- return started;
}
/*******************************************************************************
/* if selective connection is active, or inquiry is already active, reject it
*/
- if (BTM_BLE_IS_INQ_ACTIVE(p_ble_cb->scan_activity) ||
- BTM_BLE_IS_SEL_CONN_ACTIVE(p_ble_cb->scan_activity)) {
+ if (BTM_BLE_IS_INQ_ACTIVE(p_ble_cb->scan_activity)) {
BTM_TRACE_ERROR("LE Inquiry is active, can not start inquiry");
return (BTM_BUSY);
}
if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity))
rt |= BTM_BLE_OBS_RESULT;
- if (BTM_BLE_IS_SEL_CONN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity) &&
- (evt_type == BTM_BLE_CONNECT_EVT || evt_type == BTM_BLE_CONNECT_DIR_EVT))
- rt |= BTM_BLE_SEL_CONN_RESULT;
-
/* does not match filter condition */
if (p_cond->filter_cond_type == BTM_FILTER_COND_BD_ADDR &&
memcmp(bda, p_cond->filter_cond.bdaddr_cond, BD_ADDR_LEN) != 0) {
/*******************************************************************************
*
- * Function btm_send_sel_conn_callback
- *
- * Description send selection connection request callback.
- *
- * Parameters
- *
- * Returns void
- *
- ******************************************************************************/
-void btm_send_sel_conn_callback(BD_ADDR remote_bda, uint8_t evt_type,
- uint8_t data_len, uint8_t* data,
- UNUSED_ATTR uint8_t addr_type) {
- uint8_t len;
- uint8_t *p_dev_name, remname[31] = {0};
-
- if (btm_cb.ble_ctr_cb.p_select_cback == NULL ||
- /* non-connectable device */
- (evt_type != BTM_BLE_EVT_CONN_ADV &&
- evt_type != BTM_BLE_EVT_CONN_DIR_ADV))
- return;
-
- /* get the device name if exist in ADV data */
- if (data_len != 0) {
- p_dev_name = BTM_CheckAdvData(data, BTM_BLE_AD_TYPE_NAME_CMPL, &len);
-
- if (p_dev_name == NULL)
- p_dev_name = BTM_CheckAdvData(data, BTM_BLE_AD_TYPE_NAME_SHORT, &len);
-
- if (p_dev_name) memcpy(remname, p_dev_name, len);
- }
- /* allow connection */
- if ((*btm_cb.ble_ctr_cb.p_select_cback)(remote_bda, remname)) {
- /* terminate selective connection, initiate connection */
- btm_ble_initiate_select_conn(remote_bda);
- }
-}
-
-/*******************************************************************************
- *
* Function btm_ble_process_adv_pkt
*
* Description This function is called when adv packet report events are
btm_acl_update_busy_level(BTM_BLI_INQ_DONE_EVT);
}
}
- /* background connection in selective connection mode */
- if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE) {
- if (result & BTM_BLE_SEL_CONN_RESULT)
- btm_send_sel_conn_callback(bda, evt_type, data_len, data, addr_type);
- else {
- BTM_TRACE_DEBUG("None LE device, can not initiate selective connection");
- }
- } else {
- if (p_inq_results_cb && (result & BTM_BLE_INQ_RESULT)) {
- (p_inq_results_cb)((tBTM_INQ_RESULTS*)&p_i->inq_info.results,
- p_le_inq_cb->adv_data_cache);
- }
- if (p_obs_results_cb && (result & BTM_BLE_OBS_RESULT)) {
- (p_obs_results_cb)((tBTM_INQ_RESULTS*)&p_i->inq_info.results,
- p_le_inq_cb->adv_data_cache);
- }
+
+ if (p_inq_results_cb && (result & BTM_BLE_INQ_RESULT)) {
+ (p_inq_results_cb)((tBTM_INQ_RESULTS*)&p_i->inq_info.results,
+ p_le_inq_cb->adv_data_cache);
+ }
+ if (p_obs_results_cb && (result & BTM_BLE_OBS_RESULT)) {
+ (p_obs_results_cb)((tBTM_INQ_RESULTS*)&p_i->inq_info.results,
+ p_le_inq_cb->adv_data_cache);
}
}
BTM_BLE_DUPLICATE_ENABLE);
btm_update_scanner_filter_policy(SP_ADV_ALL);
-
- btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_SCAN;
}
/*******************************************************************************
*
/* background connection function */
extern bool btm_ble_suspend_bg_conn(void);
extern bool btm_ble_resume_bg_conn(void);
-extern void btm_ble_initiate_select_conn(BD_ADDR bda);
extern bool btm_ble_start_auto_conn(bool start);
-extern bool btm_ble_start_select_conn(bool start,
- tBTM_BLE_SEL_CBACK* p_select_cback);
+extern bool btm_ble_start_select_conn(bool start);
extern bool btm_ble_renew_bg_conn_params(bool add, BD_ADDR bd_addr);
extern void btm_write_dir_conn_wl(BD_ADDR target_addr);
extern void btm_ble_update_mode_operation(uint8_t link_role, BD_ADDR bda,
(((x)[0] & BLE_PUBLIC_ADDR_MSB_MASK) == BLE_PUBLIC_ADDR_MSB)
/* LE scan activity bit mask, continue with LE inquiry bits */
-/* selection connection is in progress */
-#define BTM_LE_SELECT_CONN_ACTIVE 0x40
/* observe is in progress */
#define BTM_LE_OBSERVE_ACTIVE 0x80
#define BTM_BLE_IS_SCAN_ACTIVE(x) ((x)&BTM_BLE_SCAN_ACTIVE_MASK)
#define BTM_BLE_IS_INQ_ACTIVE(x) ((x)&BTM_BLE_INQUIRY_MASK)
#define BTM_BLE_IS_OBS_ACTIVE(x) ((x)&BTM_LE_OBSERVE_ACTIVE)
-#define BTM_BLE_IS_SEL_CONN_ACTIVE(x) ((x)&BTM_LE_SELECT_CONN_ACTIVE)
/* BLE ADDR type ID bit */
#define BLE_ADDR_TYPE_ID_BIT 0x02
/* white list using state as a bit mask */
#define BTM_BLE_WL_IDLE 0
#define BTM_BLE_WL_INIT 1
-#define BTM_BLE_WL_SCAN 2
#define BTM_BLE_WL_ADV 4
typedef uint8_t tBTM_BLE_WL_STATE;
tBTM_BLE_CONN_TYPE bg_conn_type;
uint32_t scan_int;
uint32_t scan_win;
- tBTM_BLE_SEL_CBACK* p_select_cback;
/* white list information */
uint8_t white_list_avail_size;
btm_cb.ble_ctr_cb.conn_state = BLE_CONN_IDLE;
btm_cb.ble_ctr_cb.bg_conn_type = BTM_BLE_CONN_NONE;
- btm_cb.ble_ctr_cb.p_select_cback = NULL;
gatt_reset_bgdev_list();
btm_pm_reset();
******************************************************************************/
extern void BTM_BleLoadLocalKeys(uint8_t key_type, tBTM_BLE_LOCAL_KEYS* p_key);
-/*******************************************************************************
- *
- * Function BTM_BleSetBgConnType
- *
- * Description This function is called to set BLE background connection
- * procedure type. It can be auto connection, or selective
- * connection.
- *
- * Parameters conn_type: it can be auto connection, or selective
- * connection.
- * p_select_cback: callback function when selective connection
- * procedure is being used.
- *
- * Returns void
- *
- ******************************************************************************/
-extern bool BTM_BleSetBgConnType(tBTM_BLE_CONN_TYPE conn_type,
- tBTM_BLE_SEL_CBACK* p_select_cback);
+/**
+ * Set BLE connectable mode to auto connect
+ */
+extern void BTM_BleStartAutoConn();
/*******************************************************************************
*
typedef uint8_t BTM_BLE_RSSI_VALUE;
typedef uint16_t BTM_BLE_ADV_INFO_TIMESTAMP;
-enum { BTM_BLE_CONN_NONE, BTM_BLE_CONN_AUTO, BTM_BLE_CONN_SELECTIVE };
+enum { BTM_BLE_CONN_NONE, BTM_BLE_CONN_AUTO };
typedef uint8_t tBTM_BLE_CONN_TYPE;
#define ADV_INFO_PRESENT 0x00