From patchwork Thu Mar 6 19:23:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 870929 Received: from lahtoruutu.iki.fi (lahtoruutu.iki.fi [185.185.170.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0ABCF26E96F for ; Thu, 6 Mar 2025 19:23:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=185.185.170.37 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741289020; cv=pass; b=NF2Mx8uX46guKx+JfIr2tYdasOBByYkbr5HUb/9rBTfHpGlMG7eJiNtUGBL2H7P2LPtYFawUE5iXADEClXonYZI7sXomX7MQdN4+Pb8LhYtD8gxyRiYHL79+oHAJ1FKIUsHVe88z4qKXRzhRgjpGODE1r4BvRJsdakVZnkm/4Po= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741289020; c=relaxed/simple; bh=W5a8F5HNlBiuiPXzc/epgOQKIZbMjH5XVHitdO8H+vI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R01+UH0zYSVSFuwywfXjJWT3Y9/ISDvza+CPLCJg2T1b/WBAJ5dj6kCPY2tWWYsKA1kb32wFeP1q7PaQBa+UZywDrhMDTbaQAhQminRUXa93/fzOFid3HcsaTYC+kdghjhKpBUTBZNbW2fQwLN03hV3pYdtzGzRdM0mHI65UTv4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi; spf=pass smtp.mailfrom=iki.fi; dkim=pass (2048-bit key) header.d=iki.fi header.i=@iki.fi header.b=FVZEOalp; arc=pass smtp.client-ip=185.185.170.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iki.fi Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iki.fi header.i=@iki.fi header.b="FVZEOalp" Received: from monolith.lan (unknown [193.138.7.178]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4Z7zqD1Zlrz49Q47; Thu, 6 Mar 2025 21:23:36 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1741289016; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mwh6UqcG+jhVY1HsM9XalcRjs8/srX4OCt8aHBIoTMM=; b=FVZEOalpTaM356QIM2R6gkx3/qlMZEEzgwzFa7eXFxAIHQK9BfNhzpTk8X9GJTECSZMr5j zrfpVo2LtvxOMFMl/q/2llAn3SimqOAhEbNdS4CTwtBXDMkvx7FKw/lneuQddXWuFjjCTC q6vETdYhbx10g1cbiKl+z37xcF0N8fiuzqdLNhblpW0yT6JikQRE4FzwDQ/TRu/YJVtQlD pye1fdq1WmAECwC7mDRWNeBBzpMHmWkvwnul0W9Jzzp3NQzNlaSdaUL5kJe5xZBy4+L8Hk qxjqZ7nQ4qY5LiOS4lwpAdH8fFqiHHuGnWS0F7QHZTnUfge0l0GBt801gy1kBA== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1741289016; a=rsa-sha256; cv=none; b=kaitNleVGtZ//zpnZRFCnYwwzDUtpOhi8zGcv9oRGMn68GZu3ONwthFUg0/tk5wWsIyebN +bPZIuy1LSh5aXzXlzolRduPMzO6P3D1FLCTqO38/fU4Bw41PbfpOAKykCEhnV1ieRmDIl HUiztnsRlNGI08ZTxcpwQG7xUO6TQKDZI4SFuobGeM1DVbjYr2ZSyPEcY07gcyOaj4PJbs 7byUxyQPjzscnlVXA9DtOaIcGBijfjnz4WUpl5IPoaAOM/+7b+3f4sE9PW9HwzAu74J4is R1Efq1yKBnUXuoEZgkz7Qb4VdshiogcI1e6MA1J3tpsGQUpAMiJTgqk33jTRgw== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1741289016; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mwh6UqcG+jhVY1HsM9XalcRjs8/srX4OCt8aHBIoTMM=; b=UTEZQOhRmhQWsRrdr1E/OG/bQndMIlczJhlwb/OJhv3gzwYlyaGwQHJ6OzrP73Sx3YNTFT drEof0yI7QgE3Bkp8QbH+mmsIB53XZIt3j3LZGaRWHZhbr4+cyPCrBTjqyG7a4Xb/gmEtS pX9nWpDily4BZwibJnRL+zaAPKKs49Q5iH2JfOBP5RDNpKViF69RRyoICJjy8x/Xqe8AiI lnDt+yD4yXXHthn+YyB+yXwrTkcwZLJMoYfPu+sstmpHs7VFZYGz1Nf/KSBniezEuTWb1C JJY4/2Xf2+J5JwGvT7Zte60vrzYmyIXAGTDBd0EYQROpMm80C+25a5mcJ9QWPA== From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ 2/6] btdev: send SCO setup events to bthost Date: Thu, 6 Mar 2025 21:23:14 +0200 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Send required SCO setup events to bthost conns, so data can be passed to the linked connection. --- emulator/btdev.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index 51cb60a41..3542fdad5 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -1415,6 +1415,10 @@ done: send_event(dev, BT_HCI_EVT_CONN_COMPLETE, &cc, sizeof(cc)); + if (conn) + send_event(conn->link->dev, BT_HCI_EVT_CONN_COMPLETE, + &cc, sizeof(cc)); + return 0; } @@ -2824,6 +2828,10 @@ static int cmd_enhanced_setup_sync_conn_complete(struct btdev *dev, done: send_event(dev, BT_HCI_EVT_SYNC_CONN_COMPLETE, &cc, sizeof(cc)); + if (conn) + send_event(conn->link->dev, BT_HCI_EVT_SYNC_CONN_COMPLETE, + &cc, sizeof(cc)); + return 0; } @@ -2870,6 +2878,10 @@ static int cmd_setup_sync_conn_complete(struct btdev *dev, const void *data, done: send_event(dev, BT_HCI_EVT_SYNC_CONN_COMPLETE, &cc, sizeof(cc)); + if (conn) + send_event(conn->link->dev, BT_HCI_EVT_SYNC_CONN_COMPLETE, + &cc, sizeof(cc)); + return 0; } @@ -7674,7 +7686,7 @@ static void send_acl(struct btdev *dev, const void *data, uint16_t len) static void send_sco(struct btdev *dev, const void *data, uint16_t len) { - struct bt_hci_acl_hdr *hdr; + struct bt_hci_sco_hdr *hdr; struct iovec iov[2]; struct btdev_conn *conn; uint8_t pkt_type = BT_H4_SCO_PKT; @@ -7694,7 +7706,8 @@ static void send_sco(struct btdev *dev, const void *data, uint16_t len) if (dev->sco_flowctl) num_completed_packets(dev, conn->handle); - send_packet(conn->link->dev, iov, 2); + if (conn->link) + send_packet(conn->link->dev, iov, 2); } static void send_iso(struct btdev *dev, const void *data, uint16_t len) From patchwork Thu Mar 6 19:23:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 870928 Received: from lahtoruutu.iki.fi (lahtoruutu.iki.fi [185.185.170.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9230926FA4C for ; Thu, 6 Mar 2025 19:23:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=185.185.170.37 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741289020; cv=pass; b=kmF8y3YWa49bF1UbO3ONHiBCkV9g58BsWDNHZYYYgnGRdJ1+BQELob0EwYkGIqWT9iINZR20nzspjTGTc+3ARZjlDZlnHQ59gvqRPmwjm+1/Lckuf85Nwu3Jez2MZcxBJG9A/l1OVRaovog8jgPdUniAawhDbElA9ezWVKfshZQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741289020; c=relaxed/simple; bh=yumEmpbN2MEy4HR0ELu7efNuKnshv9gIxDx9RV7Q2+Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BeVwuoql1ZiOi94hC4mKczvuRlxX6LhurlW7X6NZKiIljqfEPPriTpy8LY3C8B9IobLilQpn1fm+92dyXkhGo71ExPrCZUs2GA/nIphe78ZaFNLXoM+NXWHbg56HaVVUpaAe1CZZEpC7si+IPPM9gF/GCyt2zkHf5IDybgsllVA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi; spf=pass smtp.mailfrom=iki.fi; dkim=pass (2048-bit key) header.d=iki.fi header.i=@iki.fi header.b=hk1ldA+1; arc=pass smtp.client-ip=185.185.170.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iki.fi Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iki.fi header.i=@iki.fi header.b="hk1ldA+1" Received: from monolith.lan (unknown [193.138.7.178]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4Z7zqD3J1Zz49Q4w; Thu, 6 Mar 2025 21:23:36 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1741289016; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GpfrvS38rqzSKds6++urKSjloPOYY0pqHouYeBAfW4M=; b=hk1ldA+1nbZOXL0ZD9PRmRrz1jF2+w4bo+Sug8TvZ1Ynltu3zpnV/xeSgZm1+LSa2i+x+Z mwO+mstfMl0bGKFYtbtDLcAvC8gDlDGAEiafWGpMi0oS5TnhIfgAy0slCxLI352qQ23y4l g2N6mtd8RqUWChhEWQWcSH/knt0BYRkxRwxkrbeJp4mUQIjOHJRuU/K+zEhOSnybJggdOo zLElhtKGyuN0f9QTQVAhz0UIwlV5iBPBEwWZCWDXeNSUkKXIXQ/D5rDECM3Rkb1uyTxW35 xHtSqWIUVw2RjqlYKGcJz/RpHl2ulIn2HLm5Aw+UKIkVcyWGUQGZ7dXcnq6BGA== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1741289016; a=rsa-sha256; cv=none; b=vhSmtX8NtTSQPwmTkswwEhULZK1gL4HWTOtCaCDhXYlpUNjO3O7mmYCN8MZPfXM+d5PX6q uwWcE/1bzQ7i1LC9/5q0ebpHaSe/0xxZl7he5hJraT7kZpKQ5LIujZtLwWuG1QaZwFYLsk XqvXSyaXYrCvqdV3CYca3CjG/i5pPNxKPdq3U52VD2DafNfHcMyIxsTzrsXYUDGM/z/KfD v7EsOqM/08JClfKhlwx9XLgDRzpGniieEWMBLy4Yb6Tm1F3cC5aZPYjWi16RMOs49GtVnl e3CVcow53wJs58QajTKiuNHkWfp0osUr0ULdQehy36VY6vCd+1DF0VnKHiKIbg== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1741289016; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GpfrvS38rqzSKds6++urKSjloPOYY0pqHouYeBAfW4M=; b=Ys0dmc4A3Z8NwHREmcf/S2TVsWLAqeHF+Ml3owqL7WE7DY7DWToTZeb8+ZDMc3/mRnbgdy dWb6hHeLKJlARjS9kAWhWOjpMkyRFW22q20Dzvzjo1L7FioUJut13iXIFQyyMSIkhTLVcW 1vQiCWzYqCMrojQRbHdm6j0GDdOa7+m+duGkkcNp1KekKjGrI+VruHL0U3XThGzqYa2a3/ IelChUMG01k6IExZyXMP3/IjwbS3SL3FnW2Qb6a68XTigWNzaYdWM9ueiOLX8FhZ8GwFig in41yKXvMWYp/zg98lXDTa3dGcC5f7PzZOG9K1TwrKzxKxd5SGm9yxVXZteUzQ== From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ 3/6] bthost: add hooks receiving SCO connections and data Date: Thu, 6 Mar 2025 21:23:15 +0200 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add hooks for new SCO connections and receiving SCO data. SCO connection accept/reject flow remains unimplemented. --- emulator/bthost.c | 130 +++++++++++++++++++++++++++++++++++++++++++++- emulator/bthost.h | 10 ++++ monitor/bt.h | 1 + 3 files changed, 139 insertions(+), 2 deletions(-) diff --git a/emulator/bthost.c b/emulator/bthost.c index a76b02ecc..5db750aae 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -39,6 +39,8 @@ #define acl_handle(h) (h & 0x0fff) #define acl_flags(h) (h >> 12) +#define sco_flags_status(f) (f & 0x03) + #define iso_flags_pb(f) (f & 0x0003) #define iso_flags_ts(f) ((f >> 2) & 0x0001) #define iso_flags_pack(pb, ts) (((pb) & 0x03) | (((ts) & 0x01) << 2)) @@ -138,8 +140,14 @@ struct rfcomm_chan_hook { struct rfcomm_chan_hook *next; }; +struct sco_hook { + bthost_sco_hook_func_t func; + void *user_data; + bthost_destroy_func_t destroy; +}; + struct iso_hook { - bthost_cid_hook_func_t func; + bthost_iso_hook_func_t func; void *user_data; bthost_destroy_func_t destroy; }; @@ -155,6 +163,7 @@ struct btconn { struct rcconn *rcconns; struct cid_hook *cid_hooks; struct rfcomm_chan_hook *rfcomm_chan_hooks; + struct sco_hook *sco_hook; struct iso_hook *iso_hook; struct btconn *next; void *smp_data; @@ -241,6 +250,8 @@ struct bthost { void *cmd_complete_data; bthost_new_conn_cb new_conn_cb; void *new_conn_data; + bthost_new_conn_cb new_sco_cb; + void *new_sco_data; bthost_accept_conn_cb accept_iso_cb; bthost_new_conn_cb new_iso_cb; void *new_iso_data; @@ -326,9 +337,13 @@ static void btconn_free(struct btconn *conn) free(hook); } + if (conn->sco_hook && conn->sco_hook->destroy) + conn->sco_hook->destroy(conn->sco_hook->user_data); + if (conn->iso_hook && conn->iso_hook->destroy) conn->iso_hook->destroy(conn->iso_hook->user_data); + free(conn->sco_hook); free(conn->iso_hook); free(conn->recv_data); free(conn); @@ -722,6 +737,30 @@ void bthost_add_cid_hook(struct bthost *bthost, uint16_t handle, uint16_t cid, conn->cid_hooks = hook; } +void bthost_add_sco_hook(struct bthost *bthost, uint16_t handle, + bthost_sco_hook_func_t func, void *user_data, + bthost_destroy_func_t destroy) +{ + struct sco_hook *hook; + struct btconn *conn; + + conn = bthost_find_conn(bthost, handle); + if (!conn || conn->sco_hook) + return; + + hook = malloc(sizeof(*hook)); + if (!hook) + return; + + memset(hook, 0, sizeof(*hook)); + + hook->func = func; + hook->user_data = user_data; + hook->destroy = destroy; + + conn->sco_hook = hook; +} + void bthost_add_iso_hook(struct bthost *bthost, uint16_t handle, bthost_iso_hook_func_t func, void *user_data, bthost_destroy_func_t destroy) @@ -1184,6 +1223,29 @@ static void init_conn(struct bthost *bthost, uint16_t handle, } } +static void init_sco(struct bthost *bthost, uint16_t handle, + const uint8_t *bdaddr, uint8_t addr_type) +{ + struct btconn *conn; + + bthost_debug(bthost, "SCO handle 0x%4.4x", handle); + + conn = malloc(sizeof(*conn)); + if (!conn) + return; + + memset(conn, 0, sizeof(*conn)); + conn->handle = handle; + memcpy(conn->bdaddr, bdaddr, 6); + conn->addr_type = addr_type; + + conn->next = bthost->conns; + bthost->conns = conn; + + if (bthost->new_sco_cb) + bthost->new_sco_cb(handle, bthost->new_sco_data); +} + static void evt_conn_complete(struct bthost *bthost, const void *data, uint8_t len) { @@ -1195,7 +1257,13 @@ static void evt_conn_complete(struct bthost *bthost, const void *data, if (ev->status) return; - init_conn(bthost, le16_to_cpu(ev->handle), ev->bdaddr, BDADDR_BREDR); + if (ev->link_type == 0x00) { + init_sco(bthost, le16_to_cpu(ev->handle), ev->bdaddr, + BDADDR_BREDR); + } else if (ev->link_type == 0x01) { + init_conn(bthost, le16_to_cpu(ev->handle), ev->bdaddr, + BDADDR_BREDR); + } } static void evt_disconn_complete(struct bthost *bthost, const void *data, @@ -1397,6 +1465,20 @@ static void evt_simple_pairing_complete(struct bthost *bthost, const void *data, return; } +static void evt_sync_conn_complete(struct bthost *bthost, const void *data, + uint8_t len) +{ + const struct bt_hci_evt_sync_conn_complete *ev = data; + + if (len < sizeof(*ev)) + return; + + if (ev->status) + return; + + init_sco(bthost, le16_to_cpu(ev->handle), ev->bdaddr, BDADDR_BREDR); +} + static void evt_le_conn_complete(struct bthost *bthost, const void *data, uint8_t len) { @@ -1705,6 +1787,10 @@ static void process_evt(struct bthost *bthost, const void *data, uint16_t len) evt_disconn_complete(bthost, param, hdr->plen); break; + case BT_HCI_EVT_SYNC_CONN_COMPLETE: + evt_sync_conn_complete(bthost, param, hdr->plen); + break; + case BT_HCI_EVT_NUM_COMPLETED_PACKETS: evt_num_completed_packets(bthost, param, hdr->plen); break; @@ -2947,6 +3033,36 @@ static void process_acl(struct bthost *bthost, const void *data, uint16_t len) } } +static void process_sco(struct bthost *bthost, const void *data, uint16_t len) +{ + const struct bt_hci_sco_hdr *sco_hdr = data; + uint16_t handle, sco_len; + uint8_t status; + struct btconn *conn; + struct sco_hook *hook; + + sco_len = le16_to_cpu(sco_hdr->dlen); + if (len != sizeof(*sco_hdr) + sco_len) + return; + + handle = acl_handle(sco_hdr->handle); + status = sco_flags_status(acl_flags(sco_hdr->handle)); + + conn = bthost_find_conn(bthost, handle); + if (!conn) { + bthost_debug(bthost, "Unknown handle: 0x%4.4x", handle); + return; + } + + bthost_debug(bthost, "SCO data: %u bytes", sco_len); + + hook = conn->sco_hook; + if (!hook) + return; + + hook->func(sco_hdr->data, sco_len, status, hook->user_data); +} + static void process_iso_data(struct bthost *bthost, struct btconn *conn, const void *data, uint16_t len) { @@ -3062,6 +3178,9 @@ void bthost_receive_h4(struct bthost *bthost, const void *data, uint16_t len) case BT_H4_ACL_PKT: process_acl(bthost, data + 1, len - 1); break; + case BT_H4_SCO_PKT: + process_sco(bthost, data + 1, len - 1); + break; case BT_H4_ISO_PKT: process_iso(bthost, data + 1, len - 1); break; @@ -3085,6 +3204,13 @@ void bthost_set_connect_cb(struct bthost *bthost, bthost_new_conn_cb cb, bthost->new_conn_data = user_data; } +void bthost_set_sco_cb(struct bthost *bthost, bthost_new_conn_cb cb, + void *user_data) +{ + bthost->new_sco_cb = cb; + bthost->new_sco_data = user_data; +} + void bthost_set_iso_cb(struct bthost *bthost, bthost_accept_conn_cb accept, bthost_new_conn_cb cb, void *user_data) { diff --git a/emulator/bthost.h b/emulator/bthost.h index 2c5b0d516..405d66bf0 100644 --- a/emulator/bthost.h +++ b/emulator/bthost.h @@ -51,6 +51,9 @@ typedef void (*bthost_new_conn_cb) (uint16_t handle, void *user_data); void bthost_set_connect_cb(struct bthost *bthost, bthost_new_conn_cb cb, void *user_data); +void bthost_set_sco_cb(struct bthost *bthost, bthost_new_conn_cb cb, + void *user_data); + void bthost_set_iso_cb(struct bthost *bthost, bthost_accept_conn_cb accept, bthost_new_conn_cb cb, void *user_data); @@ -69,6 +72,13 @@ typedef void (*bthost_cid_hook_func_t)(const void *data, uint16_t len, void bthost_add_cid_hook(struct bthost *bthost, uint16_t handle, uint16_t cid, bthost_cid_hook_func_t func, void *user_data); +typedef void (*bthost_sco_hook_func_t)(const void *data, uint16_t len, + uint8_t status, void *user_data); + +void bthost_add_sco_hook(struct bthost *bthost, uint16_t handle, + bthost_sco_hook_func_t func, void *user_data, + bthost_destroy_func_t destroy); + typedef void (*bthost_iso_hook_func_t)(const void *data, uint16_t len, void *user_data); diff --git a/monitor/bt.h b/monitor/bt.h index 6fb81abfe..e708e580f 100644 --- a/monitor/bt.h +++ b/monitor/bt.h @@ -523,6 +523,7 @@ struct bt_hci_acl_hdr { struct bt_hci_sco_hdr { uint16_t handle; uint8_t dlen; + uint8_t data[]; } __attribute__ ((packed)); struct bt_hci_iso_hdr { From patchwork Thu Mar 6 19:23:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 870927 Received: from lahtoruutu.iki.fi (lahtoruutu.iki.fi [185.185.170.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C04826FDB4 for ; Thu, 6 Mar 2025 19:23:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=185.185.170.37 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741289021; cv=pass; b=h5NXKJia3q24N9Wre4LleG1BpjFy7QSF3ATK7FNqT3vuXQaFYwtHtw3DK+YMlTMclB35nLkWoyeFwBbmboVJ5ieguATB/CreG4hkRlm6B79NXG/s6kbWPqGo0lEQtIwKzyf8rh5mNYc+w8qFIztg58RFAgQdGbR0MyScWHlEzsU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741289021; c=relaxed/simple; bh=UHL8Y0FIUzdxy/05MppI/Tb8Jpp2Ea2Dduvp9760H8c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OdVzBVf4uWqW9/d5FomU6A6sNxBZVMlgfIvIzXe1CyaoiJHCZ1i2yemQzhhKfIUOOhs7CJ5ODg7iNfSyh8OEPtt8xnv4lomaD7Gu5yKmcwClaiKrkmzbiPld9JOJjROs9X02cPuD0GPT2ujeSWr+eizSwVsTn9pn/2zazbb5m2Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi; spf=pass smtp.mailfrom=iki.fi; dkim=pass (2048-bit key) header.d=iki.fi header.i=@iki.fi header.b=cD5R5Nri; arc=pass smtp.client-ip=185.185.170.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iki.fi Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iki.fi header.i=@iki.fi header.b="cD5R5Nri" Received: from monolith.lan (unknown [193.138.7.178]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4Z7zqD6mRvz49Q73; Thu, 6 Mar 2025 21:23:36 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1741289017; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9rs7aDxlfWuzNdTmfEuBXwiMo4g9LKsIBtes+mX3GHo=; b=cD5R5NrifHlEWNURCsRuEB3pUb2iBn4CAN+xGXoY6t65XfB5ZsjQEWz0DmujRw2yiq2epP OZ6vm4jflW3HqzwzBG/sEkgEE1VHzbDic8Gz4uF+kpOej8tI8c7T92Okp6upAb5OBStpcR xVCtC81l4aHES3iU3EJx7Ru7JP6tvWQjoUhP81F8xHLI70ftHRpxWYUgRSDS16pvpHn5Z+ AsQBgtzPIw3R5OOyYN9InaeZp0BO0EhpnapJnqymLS9xlu10luKI5Lx65GLNIeCsk8wbDe 9DVxaJneuqzlDiB+6g8FvvKGiefsiSCxLPbY93PeYGCjXWs15YncHEG6TeBC4Q== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1741289017; a=rsa-sha256; cv=none; b=gxODig3fcHnKFDSVYj3IpDz8Qyqkqt5Rq+uS+GmC0FWUn8mjrzUhxdaKiemDIjgBof82rb qSITpqD4qUnjkPLiFqHz6x/uLOJkFbxQ0BnpHj0Q6Wgeq8chCS6kgSDdFdBfSCqTNo4rpT BvPGkbUJhPWUADTLcBgd9yy2nsHf94JEsvO+GBQFiJ4W7x/gtuQN3bYRXoY4I5SMOYrMT0 Mh0JkGKwYOFMvcH1liWUaelgaMPm4sH91zUXp9cZ3FXdjEdNXMlFlSSGQLtWSx9rps37AH tR6uKGd8A4VfGDKtdsZSBPNXJ+sQt1foeCfXYIADXjoAmIDHs5LIXTWxcnCCJg== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1741289017; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9rs7aDxlfWuzNdTmfEuBXwiMo4g9LKsIBtes+mX3GHo=; b=tlaXYv5uwCHpLSs8KGV73TfujiA2ETHdk1CJt/KlFADBc6BjsxA3RCxbysUIT+/jaizTCi KG0b6PU7BSaxN//3NtlxAf7cFK6i8p5R9hkCvwwRhJI7e9uJQzLPaZwDROekQHRivZiJnZ 3WRE45iOhG3HEIhL5P/gbhQkjlivJ3SbM++FhX5p2YbrT9ulAtx4KjdeuXSAsA8f0gGO+R EJXYedvUQc3gvWY/ATKSBL/yHdSlEPcgAEX/CH7/VtxveRmi79USoTjT3sMMHwqkTOLzGF 3E/3C2H5hniSs8Z9dWqVr4DBhis2rqGVZ9Zilt5W51+okkNUyFp99uP2F37f/w== From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ 5/6] btdev: support disabling commands Date: Thu, 6 Mar 2025 21:23:17 +0200 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add function to return command mask, so that it is possible to disable some in tests if needed. --- emulator/btdev.c | 5 +++++ emulator/btdev.h | 2 ++ emulator/hciemu.c | 14 ++++++++++++++ emulator/hciemu.h | 1 + 4 files changed, 22 insertions(+) diff --git a/emulator/btdev.c b/emulator/btdev.c index 3542fdad5..599df3430 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -7406,6 +7406,11 @@ uint8_t *btdev_get_features(struct btdev *btdev) return btdev->features; } +uint8_t *btdev_get_commands(struct btdev *btdev) +{ + return btdev->commands; +} + uint8_t btdev_get_scan_enable(struct btdev *btdev) { return btdev->scan_enable; diff --git a/emulator/btdev.h b/emulator/btdev.h index cad5f699f..a96c1a325 100644 --- a/emulator/btdev.h +++ b/emulator/btdev.h @@ -76,6 +76,8 @@ bool btdev_set_bdaddr(struct btdev *btdev, const uint8_t *bdaddr); uint8_t *btdev_get_features(struct btdev *btdev); +uint8_t *btdev_get_commands(struct btdev *btdev); + uint8_t btdev_get_scan_enable(struct btdev *btdev); uint8_t btdev_get_le_scan_enable(struct btdev *btdev); diff --git a/emulator/hciemu.c b/emulator/hciemu.c index f13b4bda1..ccc57aada 100644 --- a/emulator/hciemu.c +++ b/emulator/hciemu.c @@ -528,6 +528,20 @@ uint8_t *hciemu_get_features(struct hciemu *hciemu) return btdev_get_features(dev); } +uint8_t *hciemu_get_commands(struct hciemu *hciemu) +{ + struct btdev *dev; + + if (!hciemu || !hciemu->vhci) + return NULL; + + dev = vhci_get_btdev(hciemu->vhci); + if (!dev) + return NULL; + + return btdev_get_commands(dev); +} + const uint8_t *hciemu_get_central_bdaddr(struct hciemu *hciemu) { struct btdev *dev; diff --git a/emulator/hciemu.h b/emulator/hciemu.h index dba920fdd..9fbe34316 100644 --- a/emulator/hciemu.h +++ b/emulator/hciemu.h @@ -55,6 +55,7 @@ void hciemu_flush_client_events(struct hciemu *hciemu); const char *hciemu_get_address(struct hciemu *hciemu); uint8_t *hciemu_get_features(struct hciemu *hciemu); +uint8_t *hciemu_get_commands(struct hciemu *hciemu); const uint8_t *hciemu_get_central_bdaddr(struct hciemu *hciemu); const uint8_t *hciemu_get_client_bdaddr(struct hciemu *hciemu);