From 02cbe2d2319d87d35e7cea6cb8610c0b67034644 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Tue, 10 Nov 2020 14:54:10 -0800 Subject: [PATCH] bthost: Fix running request callbacks for remote requests Ident are only unique per request/response pair so if a remote request is initiated we shall not attempt to run the callback even if the ident matches. --- emulator/bthost.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/emulator/bthost.c b/emulator/bthost.c index 32676e179..f29bda06e 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -1678,6 +1678,19 @@ static void handle_pending_l2reqs(struct bthost *bthost, struct btconn *conn, } } +static bool l2cap_rsp(uint8_t code) +{ + switch (code) { + case BT_L2CAP_PDU_CMD_REJECT: + case BT_L2CAP_PDU_CONN_RSP: + case BT_L2CAP_PDU_CONFIG_RSP: + case BT_L2CAP_PDU_INFO_RSP: + return true; + } + + return false; +} + static void l2cap_sig(struct bthost *bthost, struct btconn *conn, const void *data, uint16_t len) { @@ -1741,7 +1754,8 @@ static void l2cap_sig(struct bthost *bthost, struct btconn *conn, ret = false; } - handle_pending_l2reqs(bthost, conn, hdr->ident, hdr->code, + if (l2cap_rsp(hdr->code)) + handle_pending_l2reqs(bthost, conn, hdr->ident, hdr->code, data + sizeof(*hdr), hdr_len); if (ret) @@ -1898,6 +1912,19 @@ static bool l2cap_ecred_conn_rsp(struct bthost *bthost, struct btconn *conn, return true; } +static bool l2cap_le_rsp(uint8_t code) +{ + switch (code) { + case BT_L2CAP_PDU_CMD_REJECT: + case BT_L2CAP_PDU_CONN_PARAM_RSP: + case BT_L2CAP_PDU_LE_CONN_RSP: + case BT_L2CAP_PDU_ECRED_CONN_RSP: + return true; + } + + return false; +} + static void l2cap_le_sig(struct bthost *bthost, struct btconn *conn, const void *data, uint16_t len) { @@ -1960,7 +1987,8 @@ static void l2cap_le_sig(struct bthost *bthost, struct btconn *conn, ret = false; } - handle_pending_l2reqs(bthost, conn, hdr->ident, hdr->code, + if (l2cap_le_rsp(hdr->code)) + handle_pending_l2reqs(bthost, conn, hdr->ident, hdr->code, data + sizeof(*hdr), hdr_len); if (ret) -- 2.47.3