From 621e2d92231d1bb5d04c0bcc5c247a750096f7b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Rymanowski?= Date: Fri, 17 Mar 2017 15:32:12 +0100 Subject: [PATCH] nimble/l2cap: Fix hs locking issue when sending le_credit_update X-Original-Commit: 0b3ea953da71eca84fdcbcfd7affbea2e615ce8e --- nimble/host/src/ble_l2cap_coc.c | 7 +++++-- nimble/host/src/ble_l2cap_sig.c | 6 +++--- nimble/host/src/ble_l2cap_sig_priv.h | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/nimble/host/src/ble_l2cap_coc.c b/nimble/host/src/ble_l2cap_coc.c index 87d830a4a..5c4b9afbf 100644 --- a/nimble/host/src/ble_l2cap_coc.c +++ b/nimble/host/src/ble_l2cap_coc.c @@ -222,7 +222,7 @@ ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan) * so since we have still buffer to handle it */ rx->credits = 1; - ble_l2cap_sig_le_credits(chan, rx->credits); + ble_l2cap_sig_le_credits(chan->conn_handle, chan->scid, rx->credits); } BLE_HS_LOG(DEBUG, "Received partial sdu_len=%d, credits left=%d\n", @@ -468,7 +468,10 @@ ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx) * to be able to send complete SDU. */ if (chan->coc_rx.credits < c->initial_credits) { - ble_l2cap_sig_le_credits(chan, c->initial_credits - chan->coc_rx.credits); + ble_hs_unlock(); + ble_l2cap_sig_le_credits(chan->conn_handle, chan->scid, + c->initial_credits - chan->coc_rx.credits); + ble_hs_lock(); chan->coc_rx.credits = c->initial_credits; } diff --git a/nimble/host/src/ble_l2cap_sig.c b/nimble/host/src/ble_l2cap_sig.c index d9e7c522c..1acfbadf9 100644 --- a/nimble/host/src/ble_l2cap_sig.c +++ b/nimble/host/src/ble_l2cap_sig.c @@ -1047,7 +1047,7 @@ ble_l2cap_sig_le_credits_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr, } int -ble_l2cap_sig_le_credits(struct ble_l2cap_chan *chan, uint16_t credits) +ble_l2cap_sig_le_credits(uint16_t conn_handle, uint16_t scid, uint16_t credits) { struct ble_l2cap_sig_le_credits *cmd; struct os_mbuf *txom; @@ -1059,10 +1059,10 @@ ble_l2cap_sig_le_credits(struct ble_l2cap_chan *chan, uint16_t credits) return BLE_HS_ENOMEM; } - cmd->scid = htole16(chan->scid); + cmd->scid = htole16(scid); cmd->credits = htole16(credits); - return ble_l2cap_sig_tx(chan->conn_handle, txom); + return ble_l2cap_sig_tx(conn_handle, txom); } #endif diff --git a/nimble/host/src/ble_l2cap_sig_priv.h b/nimble/host/src/ble_l2cap_sig_priv.h index 49d096c26..3af6f75e9 100644 --- a/nimble/host/src/ble_l2cap_sig_priv.h +++ b/nimble/host/src/ble_l2cap_sig_priv.h @@ -108,7 +108,8 @@ int ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu, struct os_mbuf *sdu_rx, ble_l2cap_event_fn *cb, void *cb_arg); int ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan); -int ble_l2cap_sig_le_credits(struct ble_l2cap_chan *chan, uint16_t credits); +int ble_l2cap_sig_le_credits(uint16_t conn_handle, uint16_t scid, + uint16_t credits); #else #define ble_l2cap_sig_coc_connect(conn_handle, psm, mtu, sdu_rx, cb, cb_arg) \ BLE_HS_ENOTSUP