Loading system/internal_include/bt_target.h +5 −0 Original line number Diff line number Diff line Loading @@ -666,6 +666,11 @@ #define GATT_MAX_APPS 32 /* note: 2 apps used internally GATT and GAP */ #endif /* connection manager doesn't generate it's own IDs. Instead, all GATT clients * use their gatt_if to identify against conection manager. When stack tries to * create l2cap connection, it will use this fixed ID. */ #define CONN_MGR_ID_L2CAP (GATT_MAX_APPS + 10) #ifndef GATT_MAX_PHY_CHANNEL #define GATT_MAX_PHY_CHANNEL 7 #endif Loading system/stack/l2cap/l2c_ble.cc +21 −98 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ #include "l2cdefs.h" #include "log/log.h" #include "osi/include/osi.h" #include "stack/gatt/connection_manager.h" #include "stack_config.h" using base::StringPrintf; Loading @@ -56,29 +57,18 @@ static void l2cble_start_conn_update(tL2C_LCB* p_lcb); ******************************************************************************/ bool L2CA_CancelBleConnectReq(const RawAddress& rem_bda) { tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_LE); /* There can be only one BLE connection request outstanding at a time */ if (btm_ble_get_conn_st() == BLE_CONN_IDLE) { L2CAP_TRACE_WARNING("%s - no connection pending", __func__); tACL_CONN* p_acl = btm_bda_to_acl(rem_bda, BT_TRANSPORT_LE); if (p_acl) { if (p_lcb != NULL && p_lcb->link_state == LST_CONNECTING && !l2cb.is_ble_connecting) { if (p_lcb != NULL && p_lcb->link_state == LST_CONNECTING && !l2cb.is_ble_connecting) { L2CAP_TRACE_WARNING("%s - disconnecting the LE link", __func__); L2CA_RemoveFixedChnl(L2CAP_ATT_CID, rem_bda); return (true); } } return (false); } if (rem_bda != l2cb.ble_connecting_bda) { LOG(WARNING) << __func__ << " different BDA Connecting: " << l2cb.ble_connecting_bda << " Cancel: " << rem_bda; return (false); } btsnd_hcic_ble_create_conn_cancel(); gatt::connection_manager::direct_connect_remove(CONN_MGR_ID_L2CAP, rem_bda); /* Do not remove lcb if an LE link is already up as a peripheral */ if (p_lcb != NULL && Loading @@ -87,9 +77,6 @@ bool L2CA_CancelBleConnectReq(const RawAddress& rem_bda) { p_lcb->disc_reason = L2CAP_CONN_CANCEL; l2cu_release_lcb(p_lcb); } /* update state to be cancel, wait for connection cancel complete */ btm_ble_set_conn_st(BLE_CONN_CANCEL); return (true); } Loading Loading @@ -783,87 +770,23 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) { /** This function is to initate a direct connection. Returns true if connection * initiated, false otherwise. */ bool l2cble_create_conn(tL2C_LCB* p_lcb) { tBTM_SEC_DEV_REC* p_dev_rec = btm_find_or_alloc_dev(p_lcb->remote_bd_addr); tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb; uint16_t scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int; uint16_t scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win; RawAddress peer_addr; uint8_t peer_addr_type = BLE_ADDR_PUBLIC; uint8_t own_addr_type = BLE_ADDR_PUBLIC; /* There can be only one BLE connection request outstanding at a time */ if (p_dev_rec == NULL) { L2CAP_TRACE_WARNING("unknown device, can not initate connection"); return (false); } peer_addr_type = p_lcb->ble_addr_type; peer_addr = p_lcb->remote_bd_addr; #if (BLE_PRIVACY_SPT == TRUE) own_addr_type = btm_cb.ble_ctr_cb.privacy_mode ? BLE_ADDR_RANDOM : BLE_ADDR_PUBLIC; if (p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) { 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_RL_INIT); btm_random_pseudo_to_identity_addr(&peer_addr, &peer_addr_type); } else { btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, true); // If we have a current RPA, use that instead. if (!p_dev_rec->ble.cur_rand_addr.IsEmpty()) { peer_addr = p_dev_rec->ble.cur_rand_addr; } } #endif if (!btm_ble_topology_check(BTM_BLE_STATE_INIT)) { l2cu_release_lcb(p_lcb); L2CAP_TRACE_ERROR("initate direct connection fail, topology limitation"); return false; } btm_send_hci_create_connection( scan_int, /* uint16_t scan_int */ scan_win, /* uint16_t scan_win */ false, /* uint8_t white_list */ peer_addr_type, /* uint8_t addr_type_peer */ peer_addr, /* BD_ADDR bda_peer */ own_addr_type, /* uint8_t addr_type_own */ (uint16_t)( (p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.min_conn_int : BTM_BLE_CONN_INT_MIN_DEF), /* uint16_t conn_int_min */ (uint16_t)( (p_dev_rec->conn_params.max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.max_conn_int : BTM_BLE_CONN_INT_MAX_DEF), /* uint16_t conn_int_max */ (uint16_t)( (p_dev_rec->conn_params.slave_latency != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.slave_latency : BTM_BLE_CONN_SLAVE_LATENCY_DEF), /* uint16_t conn_latency */ (uint16_t)( (p_dev_rec->conn_params.supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.supervision_tout : BTM_BLE_CONN_TIMEOUT_DEF), /* conn_timeout */ 0, /* uint16_t min_len */ 0, /* uint16_t max_len */ p_lcb->initiating_phys); bool ret = gatt::connection_manager::direct_connect_add( CONN_MGR_ID_L2CAP, p_lcb->remote_bd_addr); if (!ret) return ret; p_lcb->link_state = LST_CONNECTING; // TODO(jpawlowski): these variables make no sense any more, as we might be // attempting multiple connections at same time. Get rid of them in next // patch. l2cb.is_ble_connecting = true; l2cb.ble_connecting_bda = p_lcb->remote_bd_addr; // TODO: we should not need this timer at all, the connection failure should // be reported from lower layer alarm_set_on_mloop(p_lcb->l2c_lcb_timer, L2CAP_BLE_LINK_CONNECT_TIMEOUT_MS, l2c_lcb_timer_timeout, p_lcb); btm_ble_set_conn_st(BLE_DIR_CONN); return (true); return true; } /******************************************************************************* Loading Loading
system/internal_include/bt_target.h +5 −0 Original line number Diff line number Diff line Loading @@ -666,6 +666,11 @@ #define GATT_MAX_APPS 32 /* note: 2 apps used internally GATT and GAP */ #endif /* connection manager doesn't generate it's own IDs. Instead, all GATT clients * use their gatt_if to identify against conection manager. When stack tries to * create l2cap connection, it will use this fixed ID. */ #define CONN_MGR_ID_L2CAP (GATT_MAX_APPS + 10) #ifndef GATT_MAX_PHY_CHANNEL #define GATT_MAX_PHY_CHANNEL 7 #endif Loading
system/stack/l2cap/l2c_ble.cc +21 −98 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ #include "l2cdefs.h" #include "log/log.h" #include "osi/include/osi.h" #include "stack/gatt/connection_manager.h" #include "stack_config.h" using base::StringPrintf; Loading @@ -56,29 +57,18 @@ static void l2cble_start_conn_update(tL2C_LCB* p_lcb); ******************************************************************************/ bool L2CA_CancelBleConnectReq(const RawAddress& rem_bda) { tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_LE); /* There can be only one BLE connection request outstanding at a time */ if (btm_ble_get_conn_st() == BLE_CONN_IDLE) { L2CAP_TRACE_WARNING("%s - no connection pending", __func__); tACL_CONN* p_acl = btm_bda_to_acl(rem_bda, BT_TRANSPORT_LE); if (p_acl) { if (p_lcb != NULL && p_lcb->link_state == LST_CONNECTING && !l2cb.is_ble_connecting) { if (p_lcb != NULL && p_lcb->link_state == LST_CONNECTING && !l2cb.is_ble_connecting) { L2CAP_TRACE_WARNING("%s - disconnecting the LE link", __func__); L2CA_RemoveFixedChnl(L2CAP_ATT_CID, rem_bda); return (true); } } return (false); } if (rem_bda != l2cb.ble_connecting_bda) { LOG(WARNING) << __func__ << " different BDA Connecting: " << l2cb.ble_connecting_bda << " Cancel: " << rem_bda; return (false); } btsnd_hcic_ble_create_conn_cancel(); gatt::connection_manager::direct_connect_remove(CONN_MGR_ID_L2CAP, rem_bda); /* Do not remove lcb if an LE link is already up as a peripheral */ if (p_lcb != NULL && Loading @@ -87,9 +77,6 @@ bool L2CA_CancelBleConnectReq(const RawAddress& rem_bda) { p_lcb->disc_reason = L2CAP_CONN_CANCEL; l2cu_release_lcb(p_lcb); } /* update state to be cancel, wait for connection cancel complete */ btm_ble_set_conn_st(BLE_CONN_CANCEL); return (true); } Loading Loading @@ -783,87 +770,23 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) { /** This function is to initate a direct connection. Returns true if connection * initiated, false otherwise. */ bool l2cble_create_conn(tL2C_LCB* p_lcb) { tBTM_SEC_DEV_REC* p_dev_rec = btm_find_or_alloc_dev(p_lcb->remote_bd_addr); tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb; uint16_t scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int; uint16_t scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win; RawAddress peer_addr; uint8_t peer_addr_type = BLE_ADDR_PUBLIC; uint8_t own_addr_type = BLE_ADDR_PUBLIC; /* There can be only one BLE connection request outstanding at a time */ if (p_dev_rec == NULL) { L2CAP_TRACE_WARNING("unknown device, can not initate connection"); return (false); } peer_addr_type = p_lcb->ble_addr_type; peer_addr = p_lcb->remote_bd_addr; #if (BLE_PRIVACY_SPT == TRUE) own_addr_type = btm_cb.ble_ctr_cb.privacy_mode ? BLE_ADDR_RANDOM : BLE_ADDR_PUBLIC; if (p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) { 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_RL_INIT); btm_random_pseudo_to_identity_addr(&peer_addr, &peer_addr_type); } else { btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, true); // If we have a current RPA, use that instead. if (!p_dev_rec->ble.cur_rand_addr.IsEmpty()) { peer_addr = p_dev_rec->ble.cur_rand_addr; } } #endif if (!btm_ble_topology_check(BTM_BLE_STATE_INIT)) { l2cu_release_lcb(p_lcb); L2CAP_TRACE_ERROR("initate direct connection fail, topology limitation"); return false; } btm_send_hci_create_connection( scan_int, /* uint16_t scan_int */ scan_win, /* uint16_t scan_win */ false, /* uint8_t white_list */ peer_addr_type, /* uint8_t addr_type_peer */ peer_addr, /* BD_ADDR bda_peer */ own_addr_type, /* uint8_t addr_type_own */ (uint16_t)( (p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.min_conn_int : BTM_BLE_CONN_INT_MIN_DEF), /* uint16_t conn_int_min */ (uint16_t)( (p_dev_rec->conn_params.max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.max_conn_int : BTM_BLE_CONN_INT_MAX_DEF), /* uint16_t conn_int_max */ (uint16_t)( (p_dev_rec->conn_params.slave_latency != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.slave_latency : BTM_BLE_CONN_SLAVE_LATENCY_DEF), /* uint16_t conn_latency */ (uint16_t)( (p_dev_rec->conn_params.supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.supervision_tout : BTM_BLE_CONN_TIMEOUT_DEF), /* conn_timeout */ 0, /* uint16_t min_len */ 0, /* uint16_t max_len */ p_lcb->initiating_phys); bool ret = gatt::connection_manager::direct_connect_add( CONN_MGR_ID_L2CAP, p_lcb->remote_bd_addr); if (!ret) return ret; p_lcb->link_state = LST_CONNECTING; // TODO(jpawlowski): these variables make no sense any more, as we might be // attempting multiple connections at same time. Get rid of them in next // patch. l2cb.is_ble_connecting = true; l2cb.ble_connecting_bda = p_lcb->remote_bd_addr; // TODO: we should not need this timer at all, the connection failure should // be reported from lower layer alarm_set_on_mloop(p_lcb->l2c_lcb_timer, L2CAP_BLE_LINK_CONNECT_TIMEOUT_MS, l2c_lcb_timer_timeout, p_lcb); btm_ble_set_conn_st(BLE_DIR_CONN); return (true); return true; } /******************************************************************************* Loading