From patchwork Fri Mar 7 18:00:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 871318 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (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 28DE81607A4 for ; Fri, 7 Mar 2025 18:02:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741370527; cv=pass; b=uc7+ia4hnsyVTLIbcy44hBxtwlFuKrhV9zIP3ZVLNcaVsleNwKpHYikMjCM3fHUfBytGc56VGOKpCtmTp852yqOdJqiz5d/tVOP1bo+9Pz7dvt7AwmpajyJ1ULBpvRx4EXMOqhDHlsczRXV5yUuAzxpa6m3ywCl0n4CC91jEjI4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741370527; c=relaxed/simple; bh=P4m1MKQuQvSe+2Vs/2C4cApBw6TtxxPt4pwfvA8KHHM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Zd31UhPrTTTK+cVHINyDIiWK9SBrLb+kYCvsNnvTnYtDaGRX50nLchuomZ+SNWsDXOAs7pe8UhU6Q5Y/cRW+mKzhXqDF6LQOuolJ4Mo9GRYYBaMTna00JoYpUIokWnbAM26Vau9EF/WUkqmCyw/1p0L93LoHzipksPmMFO4z8FY= 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 (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=VTYCLhOo; arc=pass smtp.client-ip=195.140.195.201 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 (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="VTYCLhOo" Received: from monolith.lan (unknown [193.138.7.158]) (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 meesny.iki.fi (Postfix) with ESMTPSA id 4Z8YyT1w9xzyRf; Fri, 7 Mar 2025 20:01:53 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1741370514; 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; bh=RSpVstkCNR6LOSw/Xo8iV2GsAxCL5LN5m23JRTo8o1E=; b=VTYCLhOoIqr4CeAAPHWJ5UUSV/Abf/orxAONNZN2YpwaPv2y8V3l53iW+mlTqTKBSsR8UY nPzV3mGEtzgcEJujWGRbWsrVg/KliMcB7+tHumj0yIIbrILviuM+0RkKMFApgFFxBZaGrH EmTsRqwvSQgooL9kzUyLtgHKBXhDZZA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1741370514; 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; bh=RSpVstkCNR6LOSw/Xo8iV2GsAxCL5LN5m23JRTo8o1E=; b=wW/HNSTm/Yvadn+SWy7sBdraOHHQtZuF3mEItIvLoVV+LgTAMQN8jpAtWyVmdj1+OLcIJC bjw6Tl91bxYV/3l0mXen2BfJdLJdOGCXgQGpZGbibOWsivUPA8GlPMekDmNidJQeMzfaTb 1je3VHaK6bPkLhpSedGIoLVdvMvgGvA= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1741370514; a=rsa-sha256; cv=none; b=dVgpbem0C417e7KglFGtVv3mdfjESkaLDlG7P+c2MLk14pZiUcxgR1oPNAnrqMxAJY8vke 3zMmptnuv+J8u8mcVK40jIqeJ0h85/OWeE7Wm5FZfAI9hH4G0ZzWiVoBm99e8nR9GQ/0+r BlXcJhhjeANg/Kn5nIgjcMnf6xStKh0= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ v3 1/6] btdev: Add support for Sync Flow Control Date: Fri, 7 Mar 2025 20:00:54 +0200 Message-ID: <747adb1a5f2a6b7b25e823bf22f8795f4c7c6322.1741370367.git.pav@iki.fi> X-Mailer: git-send-email 2.48.1 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz This adds support for Sync Flow Control by supporting command Write Sync Flow Control Enable: < HCI Command: Write Sync Fl.. (0x03|0x002f) plen 1 Flow control: Enabled (0x01) > HCI Event: Command Complete (0x0e) plen 4 Write Sync Flow Control Enable (0x03|0x002f) ncmd 1 Status: Success (0x00) To act according to the spec this enabled SCO data packets to be properly processed and generate Number of Completed Packets event: sco-tester[40]: < SCO Data TX:.. flags 0x00 dlen 9 > HCI Event: Number of Completed P.. (0x13) plen 5 Num handles: 1 Handle: 42 Address: 00:AA:01:01:00:00 (Intel Corporation) --- emulator/btdev.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/emulator/btdev.c b/emulator/btdev.c index 77d44ad84..713ec7acb 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -203,6 +203,7 @@ struct btdev { uint8_t ssp_debug_mode; uint8_t secure_conn_support; uint8_t host_flow_control; + uint8_t sco_flowctl; uint8_t le_supported; uint8_t le_simultaneous; uint8_t le_event_mask[8]; @@ -2398,6 +2399,20 @@ static int cmd_read_tx_power_level(struct btdev *dev, const void *data, return 0; } +static int cmd_write_sync_flowctl(struct btdev *dev, const void *data, + uint8_t len) +{ + const struct bt_hci_cmd_write_sync_flow_control *cmd = data; + uint8_t status = BT_HCI_ERR_SUCCESS; + + dev->sco_flowctl = cmd->enable; + + cmd_complete(dev, BT_HCI_CMD_WRITE_SYNC_FLOW_CONTROL, &status, + sizeof(status)); + + return 0; +} + static int cmd_read_num_iac(struct btdev *dev, const void *data, uint8_t len) { struct bt_hci_rsp_read_num_supported_iac rsp; @@ -2676,6 +2691,7 @@ static int cmd_enable_dut_mode(struct btdev *dev, const void *data, CMD(BT_HCI_CMD_READ_VOICE_SETTING, cmd_read_voice, NULL), \ CMD(BT_HCI_CMD_WRITE_VOICE_SETTING, cmd_write_voice, NULL), \ CMD(BT_HCI_CMD_READ_TX_POWER, cmd_read_tx_power_level, NULL), \ + CMD(BT_HCI_CMD_WRITE_SYNC_FLOW_CONTROL, cmd_write_sync_flowctl, NULL), \ CMD(BT_HCI_CMD_READ_NUM_SUPPORTED_IAC, cmd_read_num_iac, NULL), \ CMD(BT_HCI_CMD_READ_CURRENT_IAC_LAP, cmd_read_current_iac_lap, \ NULL), \ @@ -2739,6 +2755,7 @@ static void set_common_commands_bredr20(struct btdev *btdev) btdev->commands[9] |= 0x04; /* Read Voice Setting */ btdev->commands[9] |= 0x08; /* Write Voice Setting */ btdev->commands[10] |= 0x04; /* Read TX Power Level */ + btdev->commands[10] |= BIT(4); /* Write Sync Flow Control */ btdev->commands[11] |= 0x04; /* Read Number of Supported IAC */ btdev->commands[11] |= 0x08; /* Read Current IAC LAP */ btdev->commands[11] |= 0x10; /* Write Current IAC LAP */ @@ -7655,6 +7672,31 @@ static void send_acl(struct btdev *dev, const void *data, uint16_t len) send_packet(conn->link->dev, iov, 3); } +static void send_sco(struct btdev *dev, const void *data, uint16_t len) +{ + struct bt_hci_acl_hdr *hdr; + struct iovec iov[2]; + struct btdev_conn *conn; + uint8_t pkt_type = BT_H4_SCO_PKT; + + /* Packet type */ + iov[0].iov_base = &pkt_type; + iov[0].iov_len = sizeof(pkt_type); + + iov[1].iov_base = hdr = (void *) (data); + iov[1].iov_len = len; + + conn = queue_find(dev->conns, match_handle, + UINT_TO_PTR(acl_handle(hdr->handle))); + if (!conn) + return; + + if (dev->sco_flowctl) + num_completed_packets(dev, conn->handle); + + send_packet(conn->link->dev, iov, 2); +} + static void send_iso(struct btdev *dev, const void *data, uint16_t len) { struct bt_hci_acl_hdr *hdr; @@ -7702,6 +7744,9 @@ void btdev_receive_h4(struct btdev *btdev, const void *data, uint16_t len) case BT_H4_ACL_PKT: send_acl(btdev, data + 1, len - 1); break; + case BT_H4_SCO_PKT: + send_sco(btdev, data + 1, len - 1); + break; case BT_H4_ISO_PKT: send_iso(btdev, data + 1, len - 1); break; From patchwork Fri Mar 7 18:00:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 871711 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (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 1268118DB32 for ; Fri, 7 Mar 2025 18:02:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741370527; cv=pass; b=OZsktQkRsp4plaZqGuzCIpWYMGLaUw5IwLUYUHC6YCzr6H4DgeVFF1t1jZllnCa9s+XhqJCxSs+7UEpH2eeRviR66GQERcPSmzpy74ovinBM4iJQvMzyBp0On67xpeeWSeu6+spXjFDDRrn1K5rmE8vYcJ39Ri1otPUy4hxG4Cw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741370527; c=relaxed/simple; bh=C0Do90qKo6MgHxBYqxRrNbdZ9aCoL7YzKaA6KN1+P3Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CpOyyIQgKojCjzhB9Rl0PgTD43kmEvKJ+YheexYITjDrkaZB/fIdK8ZGLcevk2zfg5iaoIeGruY2TB112zY4EN7ZcECbQcsLhS1FpiSwDz4yOokxGgeZUti5RNkT+78bWHZ+IVx3R8N4409HSKl2pURL9fRh670xM0waqvFweOw= 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 (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=zQ47z9vF; arc=pass smtp.client-ip=195.140.195.201 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 (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="zQ47z9vF" Received: from monolith.lan (unknown [193.138.7.158]) (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 meesny.iki.fi (Postfix) with ESMTPSA id 4Z8YyW2glSzyVj; Fri, 7 Mar 2025 20:01:55 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1741370516; 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=ynk+1nk0EbYUQNFVWk54Al5Mp+u70Xg+2RDakbNJR9Q=; b=zQ47z9vFel/c37SBU3Djo7MSzFXUWpFZBn8aSUgbE9oppExeqMbbXohQPPmb44SQn47ZNS v6nETl5s9PUSBsr9N9IcxdPCPBMd/1DOBhIMFSFGYcFl66BSVn9oYdpafsw4ct+MfsAeiC IKy0A1ESMPHBaL/M36Du9DhTS10axZ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1741370516; 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=ynk+1nk0EbYUQNFVWk54Al5Mp+u70Xg+2RDakbNJR9Q=; b=mla6JSTXRDhG9w2raV9MCFaFFdwOQ32zntGunt1Jswiy8QyPMNtQsXc5js/X8GPBOwrVkh 7mttA8QpymShFpq30J+olrt4mzVcM0/cJ0Gvma2OtrX4OrrksOfb46hDQh9r//5MDAAF6F x9Nm/UJo4XzYHezEs+uIBYj+wth3cas= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1741370516; a=rsa-sha256; cv=none; b=iFx11iy3RD9o1I6g6ckQpn4chlYWOV+3AjNN/atYHsM71h5oosTJEZoWicyv3tiITxxrFp l66dYDNFIBBfblSAHJ66CFesyjvbZzN5IFbBLK8VQ/Ic2i67UN4gxq8+zGtQBM3OwAHvxH SXfttzVGtPw4qQrlGbs7pGJzijNYPTk= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ v3 2/6] btdev: send SCO setup events to bthost Date: Fri, 7 Mar 2025 20:00:55 +0200 Message-ID: <3be700331371fcf276b3dcf2fb6524513226b31a.1741370367.git.pav@iki.fi> X-Mailer: git-send-email 2.48.1 In-Reply-To: <747adb1a5f2a6b7b25e823bf22f8795f4c7c6322.1741370367.git.pav@iki.fi> References: <747adb1a5f2a6b7b25e823bf22f8795f4c7c6322.1741370367.git.pav@iki.fi> 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 713ec7acb..bd8ea0d7f 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -1412,6 +1412,10 @@ static int cmd_add_sco_conn(struct btdev *dev, const void *data, uint8_t len) 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 Fri Mar 7 18:00:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 871317 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (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 EEA0F18FC92 for ; Fri, 7 Mar 2025 18:02:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741370529; cv=pass; b=UYOwTuWHVXEnsleVyf0KAMk92G/wk0NGZHVtQsAyAUZyWjdkcLpgmjw/1N5WEDrjBFxUSQMz6zMTpd/5eCVMoIEUG2shjvf/fGip4zBi8a3w18Y9QHI6avOh1n8tksD8O2PAR/MQNxNC53bExzzBN2pMvsStcAO8dO+nyMu7LFs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741370529; c=relaxed/simple; bh=yumEmpbN2MEy4HR0ELu7efNuKnshv9gIxDx9RV7Q2+Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bOY6pUBPxT3xrH6OJ6exb5Exa8NOhU2COifSQySR4qWG4MgFX21zUNOcikpOl2gPNCZKE9sfGb85v5gfmg+XAcN17CmQGpKzLZr9bu/My62T9uocHRzvNDMURLHyc03G3sg69rNH6TaOyx/W4HhR22jtAcuWplQe9DQ0W2VBWW4= 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 (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=B5uw3yT3; arc=pass smtp.client-ip=195.140.195.201 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 (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="B5uw3yT3" Received: from monolith.lan (unknown [193.138.7.158]) (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 meesny.iki.fi (Postfix) with ESMTPSA id 4Z8YyX4D1BzylZ; Fri, 7 Mar 2025 20:01:56 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1741370517; 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=B5uw3yT3L6Vn2zd34DdBDZfSzgKLAflbMb+/keUw2KFMwR8pJaH1PSz87F43f3apDBMR4e uc8Hb2t0haO3T2fwwaKXmk+gDH/2G5EdbGrtoRHJvK3++15gXZhZUQaUa3De0xp47euJN9 xoaODADOfGRNJ04cHKoWlmKOajf/gyE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1741370517; 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=XFmjO48HQvkMZiJXuicWCMIW1wu4ttjLu4JusftXpHgJiEvxodVVobiYvFBV/awfPB/wSo fsap5VyvzyXwf5UU0CYY6MYpsp0Bx0bYifoJN3fvA1hrh4lS2Gh8Apj6GjAAG3xiGkET1C eB/MEjOy6WZ9mQZegHFksAVDiwEnRkA= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1741370517; a=rsa-sha256; cv=none; b=vy40ih0lmI0wk3ODg9eRQCKK5mt8Pe2QkJT27VFSCfyWaH7R4SZ8vk5AWt8OAFCFitw8WP Eo1V7MCHyKhA4AgoTc2gEkq9PBWyd9/cNQR81v7hqAtXmQlVloVMXi3tGMZq1geEfIB2qY XExmnh4o2H1UD88bYF78R718RHP23XE= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ v3 3/6] bthost: add hooks receiving SCO connections and data Date: Fri, 7 Mar 2025 20:00:56 +0200 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: <747adb1a5f2a6b7b25e823bf22f8795f4c7c6322.1741370367.git.pav@iki.fi> References: <747adb1a5f2a6b7b25e823bf22f8795f4c7c6322.1741370367.git.pav@iki.fi> 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 Fri Mar 7 18:00:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 871710 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (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 8F7DA217670 for ; Fri, 7 Mar 2025 18:02:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741370528; cv=pass; b=pQo98qbQU7SzBcIQ26A/6XAqgIwwasGTHtYxysq9WbRsmxNtddg50rhwHnXDoDnEftAg7rEnHU506XVsa1oRj9IAlIOUpfXB8DnUt/0b+SFc7GZGQGpDQE1I/Mmy3HKNUTn51h6KvEYYCsA0r7OC1uLcQUAMGJ/FpuKCHUirPuA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741370528; c=relaxed/simple; bh=c+9YHb+Y5QPv7Vrdwrl5MMvdX+TbvrCwyQcrVyClB2s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fogt84bvW2mk59ZPcQgF1lCMPyUReyqG1HFE7AcR8/RoiqTuigHMdCLFj99ltDIcGZ2J7mV6wE03ghBL6ZlK8fVerFsfzN4uNuQgbJVC98MHJu9DITlLrwJ+LwjR/+xIY6jkOpt/J7wY/8BpxcXSGU2hU92biIKmkL7NOuzANwk= 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 (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=sb58LVFf; arc=pass smtp.client-ip=195.140.195.201 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 (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="sb58LVFf" Received: from monolith.lan (unknown [193.138.7.158]) (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 meesny.iki.fi (Postfix) with ESMTPSA id 4Z8YyZ0YY7zyyf; Fri, 7 Mar 2025 20:01:57 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1741370518; 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=nSr0gtHfZEF48CpGo6uRjVwXU5NXO8qweUla6SKHKpk=; b=sb58LVFfWAVjzPpGu0QgHdW8uEolcqieZ+A/+wExaHTBrRy81ev764TIAlWHV9Yr8iIoYE F6k0D8P3TAm03nHEqkkKK+xkMVDhl/puL/jeJXQWvDxm0icPI/KO/spw1j181U2LPR86HE Tctd4BWYZdPQN0Ef/FaBK4dmDBkSb0k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1741370518; 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=nSr0gtHfZEF48CpGo6uRjVwXU5NXO8qweUla6SKHKpk=; b=wAs5sYDPkeKXlcN5zmioQjuDo0AMZJCrZUDe8C+SBxkeIcLmxxoCRuxOwqz/sYq/6E2PBl atmQgcl3A78c7YRYCkVw0ms0Dopvs7dYWoRoK1OEq8qHx9co+SQy4Om5oNocgS00vWuA88 au+p/F/b1Z5umaxvnm/NENPzdQJH5ZI= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1741370518; a=rsa-sha256; cv=none; b=b3M9YayElGAIqGyomD4DZRCwFlRsDsHb0qTsFQ/yaKZJ3suO4k5IulpfHgWTulK1XP7688 uzXwCLuAHaB0rDFvHTc5dBYWdKesYltKXPop1xVF3r7cOMJzzw3xxXb/tQwbO2rZSt/V0y zLz2cK+iXATDnzvrKy4E3Wvspur9qCg= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ v3 4/6] sco-tester: check sent SCO data is received at bthost Date: Fri, 7 Mar 2025 20:00:57 +0200 Message-ID: <82eb32fd199ab8d80dd4d5a02e3f6aa9926968bd.1741370367.git.pav@iki.fi> X-Mailer: git-send-email 2.48.1 In-Reply-To: <747adb1a5f2a6b7b25e823bf22f8795f4c7c6322.1741370367.git.pav@iki.fi> References: <747adb1a5f2a6b7b25e823bf22f8795f4c7c6322.1741370367.git.pav@iki.fi> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When sending data, also check that the data is received by bthost. --- tools/sco-tester.c | 47 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/tools/sco-tester.c b/tools/sco-tester.c index 7f37ca5cf..9886481ff 100644 --- a/tools/sco-tester.c +++ b/tools/sco-tester.c @@ -318,10 +318,51 @@ static void client_connectable_complete(uint16_t opcode, uint8_t status, tester_setup_complete(); } +static void bthost_recv_data(const void *buf, uint16_t len, uint8_t status, + void *user_data) +{ + struct test_data *data = user_data; + const struct sco_client_data *scodata = data->test_data; + + --data->step; + + tester_print("Client received %u bytes of data", len); + + if (scodata->send_data && (scodata->data_len != len || + memcmp(scodata->send_data, buf, len))) + tester_test_failed(); + else if (!data->step) + tester_test_passed(); +} + +static void bthost_sco_disconnected(void *user_data) +{ + struct test_data *data = user_data; + + tester_print("SCO handle 0x%04x disconnected", data->handle); + + data->handle = 0x0000; +} + +static void sco_new_conn(uint16_t handle, void *user_data) +{ + struct test_data *data = user_data; + struct bthost *host; + + tester_print("New client connection with handle 0x%04x", handle); + + data->handle = handle; + + host = hciemu_client_get_host(data->hciemu); + bthost_add_sco_hook(host, data->handle, bthost_recv_data, data, + bthost_sco_disconnected); +} + static void setup_powered_callback(uint8_t status, uint16_t length, const void *param, void *user_data) { struct test_data *data = tester_get_data(); + const struct sco_client_data *scodata = data->test_data; struct bthost *bthost; if (status != MGMT_STATUS_SUCCESS) { @@ -334,6 +375,9 @@ static void setup_powered_callback(uint8_t status, uint16_t length, bthost = hciemu_client_get_host(data->hciemu); bthost_set_cmd_complete_cb(bthost, client_connectable_complete, data); bthost_write_scan_enable(bthost, 0x03); + + if (scodata && scodata->send_data) + bthost_set_sco_cb(bthost, sco_new_conn, data); } static void setup_powered(const void *test_data) @@ -740,8 +784,6 @@ static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond, ssize_t ret = 0; unsigned int count; - data->step = 0; - sco_tx_timestamping(data, io); tester_print("Writing %u*%u bytes of data", @@ -751,6 +793,7 @@ static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond, ret = write(sk, scodata->send_data, scodata->data_len); if (scodata->data_len != ret) break; + data->step++; } if (scodata->data_len != ret) { tester_warn("Failed to write %u bytes: %zu %s (%d)", From patchwork Fri Mar 7 18:00:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 871709 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (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 9F023226D1D for ; Fri, 7 Mar 2025 18:02:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741370529; cv=pass; b=LnLTQ30LlnnC/BDftBYUNLnlPFNU6TqviR9U8H7sernTHgc6tkREFrYwQ39WzAw5mzKRe+dKi7VmPTGJmvRrYrtLzutrnCMjJJDDj/PzRkhCOvgmWFBzcGGa5E+IZdCL+ypgYsCdL+iMIdptfiMwFbUSR7NXVBPYw7UI59z2GVs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741370529; c=relaxed/simple; bh=ingKNGgrafJeyB8CphgJLmFQPmYlJEKviX6Rpk3AjQ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fTjh74/T8q1796+iCT8eBVZLUe50kkQCqbi5NvWeLVzhEHSfsoHO5biAeLH+3YbQdy+9rBxKG0vn041OaaaRw+lgH3ipzmeJZsFNttcPr3p99XgpJ3xRe2wT3opfjhXzL8k4+fD/q/IIf/my8GaRz/EasYsH2qYS3kXUFrS0zQk= 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 (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=BfWuH0Z+; arc=pass smtp.client-ip=195.140.195.201 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 (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="BfWuH0Z+" Received: from monolith.lan (unknown [193.138.7.158]) (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 meesny.iki.fi (Postfix) with ESMTPSA id 4Z8Yyb1qDgz103W; Fri, 7 Mar 2025 20:01:59 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1741370520; 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=ADY6fRBrm6ktynVpo1nOXmj14nqagKe6lrW6MOuduw0=; b=BfWuH0Z+Iy6Ly22eAht/eDjCUOPouMpbOK+ZVBKqDh6q+o9T4lwpKG/Feeiq5GdWPHDs7J 6L6HN9J+2vZFzoMsLGkrzkIRzLQ0ddJPD7BOkFWXnnwEGVXdfgnboN9E/MD01g15FsnAn1 PoGJfujfGsPedHuXw4Rfs7FC6+6eEqs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1741370520; 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=ADY6fRBrm6ktynVpo1nOXmj14nqagKe6lrW6MOuduw0=; b=QZINk8oIo+mbm9Ku6UNSyFrxeRbNCohFn+BCELffHSKYzrYOYxjxKTuL8k8sydWmMDug3S eTKZLQcYhoo2ZX4tBis0efqXJOKYKGIeOa+DwitoZqEb2olf6bI6R1QKz7XfpGSGl3x9by 6wS3BtWVPCErWVsfczGghncgXSIn660= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1741370520; a=rsa-sha256; cv=none; b=mQk8SCVVj5EFs5pEesCanmWrlHm2ARgXoVD7i/3IMRbcRpCameNb+3x7IwuwWqYNFJIBYQ F5itMshFAout7QRXNnvzZ9N0zOd5h3uHu4ECt7Fb/IJRBPMMVOpOPqYrLzJPjQee1/QfPE Y/Zo5VEBldZmUYu7+H4ifSxLKUEUnsc= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ v3 5/6] btdev: support disabling commands Date: Fri, 7 Mar 2025 20:00:58 +0200 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: <747adb1a5f2a6b7b25e823bf22f8795f4c7c6322.1741370367.git.pav@iki.fi> References: <747adb1a5f2a6b7b25e823bf22f8795f4c7c6322.1741370367.git.pav@iki.fi> 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 bd8ea0d7f..976c1125d 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); From patchwork Fri Mar 7 18:00:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 871316 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (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 54CFC18FC92 for ; Fri, 7 Mar 2025 18:02:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741370533; cv=pass; b=sYiWxAMdb++BVURO38rzZpS7cUEGajawb6pNiixGbVt42Z/3qawEOM8+ZJ4BTIjhMl82QMXqqwO0Umo3qC5qtGuJXuLLYmnxXh1REd0h0wiS21UiV7+BvuZFXNEdoDVkISxt4c/5EbOFO3BWBaRa9gMRp2MH1Wf1a8VHD38KB4A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741370533; c=relaxed/simple; bh=/Fzo39/9ZhDV+TUywjW2DcXfTejoY24HKWvQ2F7Oqq4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZdsWUP8d10yNOFeCavYqmMsSpdxvEoKy4au/ywUYKnXBwEHyl3k3U1MBNX5/9fnqXxJyg1NzfNPlkdZl9bh0u1mipNAkzfEvLEV7OZUAUuCQBO1HwQKZRytXqcLnJUDVEdjkBDyn71giVwauncs2BwqBGzUIfgDiePX3pdL2Er8= 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 (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=g4Qw1t3f; arc=pass smtp.client-ip=195.140.195.201 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 (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="g4Qw1t3f" Received: from monolith.lan (unknown [193.138.7.158]) (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 meesny.iki.fi (Postfix) with ESMTPSA id 4Z8Yyc3fCxz103y; Fri, 7 Mar 2025 20:02:00 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1741370521; 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=MREFb4djRsFP6R9QpHE8kACwNcT2YwjPF7/0t4b9oQA=; b=g4Qw1t3fOSJhooYDHF22F61ysOQ8ny3Y12MDp2O0Q3eFYx2x9uyVwIGr2gQ56GbIuusx/W VpmeuHWvT7zHBncis/136CyGV6F/gUX3LGab2s1CWH+YWPtoYMaZ/XXsFchso5avqT9vxO /7VIvP8bCWenNocouo0h7CFyj68Vwpw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1741370521; 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=MREFb4djRsFP6R9QpHE8kACwNcT2YwjPF7/0t4b9oQA=; b=qXWgnERfDyUyTefG0fzQJcUpIDLZshvXwckbI7r1AyUZykZiD2YLsFUfB/MOJ4luqF+Xjf zJj6ytXTNThbYWRMtMjHBapuha/8yyYrvSYlWUpXl/EQ4fNbKq477XAzEzlQwVj/vThSdv lQy6kNAYGxFdoLnBS0BsPug1BWfVvxo= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1741370521; a=rsa-sha256; cv=none; b=SaFn053VJsBfI6IHQ0gc6Rg9rFivHJDyNx7/aZaeicersYnxV0eS5/9P544muKg/4tPPGH y/HianpbkFn8ChJx0KcxEwkHwOIPSiRQoMGjd+vRADVrIlYiUcbf8WzB9pZdLnQVOfVe5R fYscjZIO7KXwwRaRMpB+gITePkqXrT0= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ v3 6/6] sco-tester: add tests for different SCO flow control modes Date: Fri, 7 Mar 2025 20:00:59 +0200 Message-ID: <29543241771689ab8c93d941615ad62d3b70cf60.1741370367.git.pav@iki.fi> X-Mailer: git-send-email 2.48.1 In-Reply-To: <747adb1a5f2a6b7b25e823bf22f8795f4c7c6322.1741370367.git.pav@iki.fi> References: <747adb1a5f2a6b7b25e823bf22f8795f4c7c6322.1741370367.git.pav@iki.fi> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Change "SCO CVSD Send - Success" to send multiple packets. Add tests SCO CVSD Send No Flowctl - Success SCO CVSD 1.1 Send - Success SCO CVSD 1.1 Send No Flowctl - Success --- tools/sco-tester.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/tools/sco-tester.c b/tools/sco-tester.c index 9886481ff..e6888348b 100644 --- a/tools/sco-tester.c +++ b/tools/sco-tester.c @@ -44,6 +44,7 @@ struct test_data { int sk; bool disable_esco; bool enable_codecs; + bool disable_sco_flowctl; int step; uint16_t handle; struct tx_tstamp_data tx_ts; @@ -196,6 +197,16 @@ static void read_index_list_callback(uint8_t status, uint16_t length, if (features) features[3] &= ~0x80; } + + if (data->disable_sco_flowctl) { + uint8_t *commands; + + tester_print("Disabling SCO flow control"); + + commands = hciemu_get_commands(data->hciemu); + if (commands) + commands[10] &= ~(BIT(3) | BIT(4)); + } } static void test_pre_setup(const void *test_data) @@ -240,7 +251,8 @@ static void test_data_free(void *test_data) free(data); } -#define test_sco_full(name, data, setup, func, _disable_esco, _enable_codecs) \ +#define test_sco_full(name, data, setup, func, _disable_esco, _enable_codecs, \ + _disable_sco_flowctl) \ do { \ struct test_data *user; \ user = malloc(sizeof(struct test_data)); \ @@ -254,19 +266,26 @@ static void test_data_free(void *test_data) user->step = 0; \ user->disable_esco = _disable_esco; \ user->enable_codecs = _enable_codecs; \ + user->disable_sco_flowctl = _disable_sco_flowctl; \ tester_add_full(name, data, \ test_pre_setup, setup, func, NULL, \ test_post_teardown, 2, user, test_data_free); \ } while (0) #define test_sco(name, data, setup, func) \ - test_sco_full(name, data, setup, func, false, false) + test_sco_full(name, data, setup, func, false, false, false) + +#define test_sco_no_flowctl(name, data, setup, func) \ + test_sco_full(name, data, setup, func, false, false, true) #define test_sco_11(name, data, setup, func) \ - test_sco_full(name, data, setup, func, true, false) + test_sco_full(name, data, setup, func, true, false, false) + +#define test_sco_11_no_flowctl(name, data, setup, func) \ + test_sco_full(name, data, setup, func, true, false, true) #define test_offload_sco(name, data, setup, func) \ - test_sco_full(name, data, setup, func, false, true) + test_sco_full(name, data, setup, func, false, true, false) static const struct sco_client_data connect_success = { .expect_err = 0 @@ -290,7 +309,8 @@ const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; static const struct sco_client_data connect_send_success = { .expect_err = 0, .data_len = sizeof(data), - .send_data = data + .send_data = data, + .repeat_send = 3 }; static const struct sco_client_data connect_send_tx_timestamping = { @@ -1112,10 +1132,19 @@ int main(int argc, char *argv[]) test_sco("SCO CVSD Send - Success", &connect_send_success, setup_powered, test_connect); + test_sco_no_flowctl("SCO CVSD Send No Flowctl - Success", + &connect_send_success, setup_powered, test_connect); + test_sco("SCO CVSD Send - TX Timestamping", &connect_send_tx_timestamping, setup_powered, test_connect); + test_sco_11("SCO CVSD 1.1 Send - Success", &connect_send_success, + setup_powered, test_connect); + + test_sco_11_no_flowctl("SCO CVSD 1.1 Send No Flowctl - Success", + &connect_send_success, setup_powered, test_connect); + test_offload_sco("Basic SCO Get Socket Option - Offload - Success", NULL, setup_powered, test_codecs_getsockopt);