AVCT_TRACE_DEBUG("avct_l2c_connect_ind_cback: 0x%x, res: %d, ch_state: %d",
lcid, result, p_lcb->ch_state);
}
- /* Send L2CAP connect rsp */
- L2CA_ConnectRsp(bd_addr, id, lcid, result, 0);
+
+ /* If we reject the connection, send DisconnectReq */
+ if (result != L2CAP_CONN_OK) {
+ L2CA_DisconnectReq(lcid);
+ }
/* if result ok, proceed with connection */
if (result == L2CAP_CONN_OK) {
/* Set the FCR options: Browsing channel mandates ERTM */
ertm_info.preferred_mode = L2CAP_FCR_ERTM_MODE;
- /* Send L2CAP connect rsp */
- L2CA_ConnectRsp(bd_addr, id, lcid, result, 0);
+ /* If we reject the connection, send DisconnectReq */
+ if (result != L2CAP_CONN_OK) {
+ L2CA_DisconnectReq(lcid);
+ }
/* if result ok, proceed with connection */
if (result == L2CAP_CONN_OK) {
p_tbl = avdt_ad_tc_tbl_by_st(AVDT_CHAN_SIG, p_ccb, AVDT_AD_ST_SEC_ACP);
if (p_tbl == NULL) return;
- /* Send response to the L2CAP layer. */
- L2CA_ConnectRsp(*bd_addr, p_tbl->id, p_tbl->lcid, L2CAP_CONN_OK,
- L2CAP_CONN_OK);
-
/* store idx in LCID table, store LCID in routing table */
avdtp_cb.ad.lcid_tbl[p_tbl->lcid - L2CAP_BASE_APPL_CID] =
avdt_ad_tc_tbl_to_idx(p_tbl);
}
}
- /* Send L2CAP connect rsp */
- L2CA_ConnectRsp(bd_addr, id, lcid, result, 0);
+ /* If we reject the connection, send DisconnectReq */
+ if (result != L2CAP_CONN_OK) {
+ L2CA_DisconnectReq(lcid);
+ return;
+ }
/* if result ok, proceed with connection */
- if (result == L2CAP_CONN_OK) {
- /* store idx in LCID table, store LCID in routing table */
- avdtp_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID] =
- avdt_ad_tc_tbl_to_idx(p_tbl);
- avdtp_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].lcid = lcid;
+ /* store idx in LCID table, store LCID in routing table */
+ avdtp_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID] =
+ avdt_ad_tc_tbl_to_idx(p_tbl);
+ avdtp_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].lcid = lcid;
- /* transition to configuration state */
- p_tbl->state = AVDT_AD_ST_CFG;
- }
+ /* transition to configuration state */
+ p_tbl->state = AVDT_AD_ST_CFG;
}
static void avdt_on_l2cap_error(uint16_t lcid, uint16_t result) {
/* no more resources to handle the connection, reject the connection. */
if (!(bnep_cb.profile_registered) || (p_bcb) ||
((p_bcb = bnepu_allocate_bcb(bd_addr)) == NULL)) {
- L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_NO_PSM, 0);
+ L2CA_DisconnectReq(l2cap_cid);
return;
}
/* Save the L2CAP Channel ID. */
p_bcb->l2cap_cid = l2cap_cid;
- /* Send response to the L2CAP layer. */
- L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK);
-
/* Start timer waiting for config setup */
alarm_set_on_mloop(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS,
bnep_conn_timer_timeout, p_bcb);
p_ccb->rem_dev_address = bd_addr;
p_ccb->connection_id = l2cap_cid;
- /* Send response to the L2CAP layer. */
- if (p_ccb->transport == BT_TRANSPORT_BR_EDR)
- L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK);
-
if (p_ccb->transport == BT_TRANSPORT_LE) {
L2CA_ConnectLECocRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK,
L2CAP_CONN_OK, &p_ccb->local_coc_cfg);
result = L2CAP_CONN_NO_RESOURCES;
}
- /* Send L2CAP connect rsp */
- L2CA_ConnectRsp(bd_addr, id, lcid, result, 0);
-
- /* if result ok, proceed with connection */
- if (result != L2CAP_CONN_OK) return;
+ /* If we reject the connection, send DisconnectReq */
+ if (result != L2CAP_CONN_OK) {
+ L2CA_DisconnectReq(lcid);
+ return;
+ }
/* transition to configuration state */
gatt_set_ch_state(p_tcb, GATT_CH_CFG);
if (!hd_cb.allow_incoming) {
HIDD_TRACE_WARNING("%s: incoming connections not allowed, rejecting",
__func__);
- L2CA_ConnectRsp(bd_addr, id, cid, L2CAP_CONN_NO_RESOURCES, 0);
+ L2CA_DisconnectReq(cid);
+
return;
}
}
if (!accept) {
- L2CA_ConnectRsp(bd_addr, id, cid, L2CAP_CONN_NO_RESOURCES, 0);
+ L2CA_DisconnectReq(cid);
return;
}
p_hcon->ctrl_id = id;
p_hcon->disc_reason = HID_SUCCESS;
p_hcon->conn_state = HID_CONN_STATE_CONNECTING_INTR;
-
- L2CA_ConnectRsp(p_dev->addr, p_dev->conn.ctrl_id, p_dev->conn.ctrl_cid,
- L2CAP_CONN_OK, L2CAP_CONN_OK);
return;
}
// for INTR we go directly to config state
p_hcon->conn_state = HID_CONN_STATE_CONFIG;
p_hcon->intr_cid = cid;
-
- L2CA_ConnectRsp(bd_addr, id, cid, L2CAP_CONN_OK, L2CAP_CONN_OK);
}
static void hidd_on_l2cap_error(uint16_t lcid, uint16_t result) {
/* always add incoming connection device into HID database by default */
if (HID_HostAddDev(bd_addr, HID_SEC_REQUIRED, &i) != HID_SUCCESS) {
- L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_SECURITY_BLOCK, 0);
+ L2CA_DisconnectReq(l2cap_cid);
return;
}
}
if (!bAccept) {
- L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_NO_RESOURCES, 0);
+ L2CA_DisconnectReq(l2cap_cid);
return;
}
disc_reason (from
HID_ERR_AUTH_FAILED) */
p_hcon->conn_state = HID_CONN_STATE_CONNECTING_INTR;
-
- /* Send response to the L2CAP layer. */
- L2CA_ConnectRsp(p_dev->addr, p_dev->conn.ctrl_id, p_dev->conn.ctrl_cid,
- L2CAP_CONN_OK, L2CAP_CONN_OK);
return;
}
p_hcon->conn_state = HID_CONN_STATE_CONFIG;
p_hcon->intr_cid = l2cap_cid;
- /* Send response to the L2CAP layer. */
- L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK);
-
HIDH_TRACE_EVENT(
"HID-Host Rcvd L2CAP conn ind, sent config req, PSM: 0x%04x CID 0x%x",
psm, l2cap_cid);
static const char* l2c_csm_get_event_name(uint16_t event);
+// Send a connect response with result OK and adjust the state machine
+static void l2c_csm_send_connect_rsp(tL2C_CCB* p_ccb) {
+ l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_RSP, NULL);
+}
+
// Send a config request and adjust the state machine
static void l2c_csm_send_config_req(tL2C_CCB* p_ccb) {
tL2CAP_CFG_INFO config{};
L2CAP_TRACE_API("L2CAP - Calling Connect_Ind_Cb(), CID: 0x%04x",
p_ccb->local_cid);
+ l2c_csm_send_connect_rsp(p_ccb);
(*p_ccb->p_rcb->api.pL2CA_ConnectInd_Cb)(
p_ccb->p_lcb->remote_bd_addr, p_ccb->local_cid, p_ccb->p_rcb->psm,
p_ccb->remote_id);
L2CAP_TRACE_API("L2CAP - Calling Connect_Ind_Cb(), CID: 0x%04x",
p_ccb->local_cid);
+ l2c_csm_send_connect_rsp(p_ccb);
(*p_ccb->p_rcb->api.pL2CA_ConnectInd_Cb)(
p_ccb->p_lcb->remote_bd_addr, p_ccb->local_cid, p_ccb->p_rcb->psm,
p_ccb->remote_id);
}
if (p_mcb == nullptr) {
- L2CA_ConnectRsp(bd_addr, id, lcid, L2CAP_CONN_NO_RESOURCES, 0);
+ L2CA_DisconnectReq(lcid);
return;
}
p_mcb->lcid = lcid;
/* Peer gave up its connection request, make sure cleaning up L2CAP
* channel */
- L2CA_ConnectRsp(p_mcb->bd_addr, p_mcb->pending_id, p_mcb->pending_lcid,
- L2CAP_CONN_NO_RESOURCES, 0);
+ L2CA_DisconnectReq(p_mcb->pending_lcid);
p_mcb->pending_lcid = 0;
}
case RFC_MX_EVENT_CONN_IND:
rfc_timer_start(p_mcb, RFCOMM_CONN_TIMEOUT);
- L2CA_ConnectRsp(p_mcb->bd_addr, *((uint8_t*)p_data), p_mcb->lcid,
- L2CAP_CONN_OK, 0);
rfc_mx_send_config_req(p_mcb);
/* Save the BD Address and Channel ID. */
p_ccb->device_address = bd_addr;
p_ccb->connection_id = l2cap_cid;
-
- /* Send response to the L2CAP layer. */
- L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK);
}
static void sdp_on_l2cap_error(uint16_t l2cap_cid, uint16_t result) {