Diff between e9c1c41ac195c885341f7a2e4968a8c62e2ce91a and 698742c9dcc295c574a37885c4b5c5a1ca2b048c

Changed Files

File Additions Deletions Status
emulator/bthost.c +14 -9 modified

Full Patch

diff --git a/emulator/bthost.c b/emulator/bthost.c
index 6c616e8..5e83e14 100644
--- a/emulator/bthost.c
+++ b/emulator/bthost.c
@@ -1376,6 +1376,7 @@ static bool l2cap_conn_rsp(struct bthost *bthost, struct btconn *conn,
 				uint8_t ident, const void *data, uint16_t len)
 {
 	const struct bt_l2cap_pdu_conn_rsp *rsp = data;
+	struct bt_l2cap_pdu_config_req req;
 	struct l2conn *l2conn;
 
 	if (len < sizeof(*rsp))
@@ -1387,18 +1388,14 @@ static bool l2cap_conn_rsp(struct bthost *bthost, struct btconn *conn,
 	else
 		return false;
 
-	if (le16_to_cpu(rsp->result) == 0x0001) {
-		struct bt_l2cap_pdu_config_req req;
+	if (rsp->result)
+		return true;
 
-		memset(&req, 0, sizeof(req));
-		req.dcid = rsp->dcid;
+	memset(&req, 0, sizeof(req));
+	req.dcid = rsp->dcid;
 
-		l2cap_sig_send(bthost, conn, BT_L2CAP_PDU_CONFIG_REQ, 0,
+	l2cap_sig_send(bthost, conn, BT_L2CAP_PDU_CONFIG_REQ, 0,
 							&req, sizeof(req));
-	} else if (l2conn->psm == 0x0003 && !rsp->result && !rsp->status &&
-						bthost->rfcomm_conn_data) {
-		rfcomm_sabm_send(bthost, conn, l2conn, 1, 0);
-	}
 
 	return true;
 }
@@ -1434,10 +1431,18 @@ static bool l2cap_config_rsp(struct bthost *bthost, struct btconn *conn,
 				uint8_t ident, const void *data, uint16_t len)
 {
 	const struct bt_l2cap_pdu_config_rsp *rsp = data;
+	struct l2conn *l2conn;
 
 	if (len < sizeof(*rsp))
 		return false;
 
+	l2conn = btconn_find_l2cap_conn_by_scid(conn, rsp->scid);
+	if (!l2conn)
+		return false;
+
+	if (l2conn->psm == 0x0003 && !rsp->result && bthost->rfcomm_conn_data)
+		rfcomm_sabm_send(bthost, conn, l2conn, 1, 0);
+
 	return true;
 }