diff --git a/nimble/host/src/ble_att_svr.c b/nimble/host/src/ble_att_svr.c index 145318f09d..c0e821e62b 100644 --- a/nimble/host/src/ble_att_svr.c +++ b/nimble/host/src/ble_att_svr.c @@ -625,6 +625,8 @@ static int ble_att_svr_tx_rsp(uint16_t conn_handle, uint16_t cid, int hs_status, struct os_mbuf *om, uint8_t att_op, uint8_t err_status, uint16_t err_handle) { + struct ble_l2cap_chan *chan; + struct ble_hs_conn *conn; int do_tx; if (hs_status != 0 && err_status == 0) { @@ -636,29 +638,43 @@ ble_att_svr_tx_rsp(uint16_t conn_handle, uint16_t cid, int hs_status, struct os_ if (do_tx) { if (hs_status == 0) { + conn = ble_hs_conn_find(conn_handle); + if (conn == NULL) { + hs_status = BLE_HS_ENOTCONN; + goto done; + } + + chan = ble_hs_conn_chan_find_by_scid(conn, cid); + if (chan == NULL) { + hs_status = BLE_HS_ENOENT; + goto done; + } + + ble_att_truncate_to_mtu(chan, om); hs_status = ble_att_tx(conn_handle, cid, om); om = NULL; if (hs_status) { err_status = BLE_ATT_ERR_UNLIKELY; } } + } - if (hs_status != 0) { - STATS_INC(ble_att_stats, error_rsp_tx); +done: + if (hs_status != 0) { + STATS_INC(ble_att_stats, error_rsp_tx); - /* Reuse om for error response. */ - if (om == NULL) { - om = ble_hs_mbuf_l2cap_pkt(); - } else { - os_mbuf_adj(om, OS_MBUF_PKTLEN(om)); - } - if (om != NULL) { - ble_att_svr_tx_error_rsp(conn_handle, cid, om, att_op, - err_handle, err_status); - om = NULL; - } - } + /* Reuse om for error response. */ + if (om == NULL) { + om = ble_hs_mbuf_l2cap_pkt(); + } else { + os_mbuf_adj(om, OS_MBUF_PKTLEN(om)); } + if (om != NULL) { + ble_att_svr_tx_error_rsp(conn_handle, cid, om, att_op, + err_handle, err_status); + om = NULL; + } +} /* Free mbuf if it was not consumed (i.e., if the send failed). */ os_mbuf_free_chain(om); diff --git a/nimble/host/src/ble_eatt.c b/nimble/host/src/ble_eatt.c index 96666c9d0f..c15f545b6d 100644 --- a/nimble/host/src/ble_eatt.c +++ b/nimble/host/src/ble_eatt.c @@ -476,8 +476,6 @@ ble_eatt_tx(uint16_t conn_handle, uint16_t cid, struct os_mbuf *txom) goto error; } - ble_att_truncate_to_mtu(eatt->chan, txom); - rc = ble_l2cap_send(eatt->chan, txom); if (rc == 0) { goto done;