diff mbox series

[BlueZ] btdev: Fix LE CIS Established Event

Message ID 20230622190843.1242967-1-luiz.dentz@gmail.com (mailing list archive)
State Accepted
Commit 97a07d8485a3235cbefe9e78c5e596faf5c6be31
Headers show
Series [BlueZ] btdev: Fix LE CIS Established Event | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/BuildEll success Build ELL PASS
tedd_an/BluezMake success Bluez Make PASS
tedd_an/MakeCheck success Bluez Make Check PASS
tedd_an/MakeDistcheck success Make Distcheck PASS
tedd_an/CheckValgrind success Check Valgrind PASS
tedd_an/CheckSmatch warning CheckSparse WARNING emulator/btdev.c:417:29: warning: Variable length array is used.
tedd_an/bluezmakeextell success Make External ELL PASS
tedd_an/IncrementalBuild success Incremental Build PASS
tedd_an/ScanBuild success Scan Build PASS

Commit Message

Luiz Augusto von Dentz June 22, 2023, 7:08 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

LE CIS Established Event Transport Latency shall follow the formula from
the spec:

 BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 6, Part G
 page 3050:

 Transport_Latency_C_To_P = CIG_Sync_Delay + FT_C_To_P ×
 ISO_Interval - SDU_Interval_C_To_P
 Transport_Latency_P_To_C = CIG_Sync_Delay + FT_P_To_C ×
 ISO_Interval - SDU_Interval_P_To_C
---
 emulator/btdev.c | 43 +++++++++++++++++++++++++++++++------------
 1 file changed, 31 insertions(+), 12 deletions(-)

Comments

bluez.test.bot@gmail.com June 22, 2023, 8:17 p.m. UTC | #1
This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=759611

---Test result---

Test Summary:
CheckPatch                    PASS      0.41 seconds
GitLint                       PASS      0.27 seconds
BuildEll                      PASS      27.25 seconds
BluezMake                     PASS      1008.24 seconds
MakeCheck                     PASS      12.06 seconds
MakeDistcheck                 PASS      155.83 seconds
CheckValgrind                 PASS      254.00 seconds
CheckSmatch                   WARNING   343.13 seconds
bluezmakeextell               PASS      103.98 seconds
IncrementalBuild              PASS      869.61 seconds
ScanBuild                     PASS      1090.43 seconds

Details
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
emulator/btdev.c:417:29: warning: Variable length array is used.


---
Regards,
Linux Bluetooth
patchwork-bot+bluetooth@kernel.org June 22, 2023, 11 p.m. UTC | #2
Hello:

This patch was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Thu, 22 Jun 2023 12:08:43 -0700 you wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> LE CIS Established Event Transport Latency shall follow the formula from
> the spec:
> 
>  BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 6, Part G
>  page 3050:
> 
> [...]

Here is the summary with links:
  - [BlueZ] btdev: Fix LE CIS Established Event
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=97a07d8485a3

You are awesome, thank you!
diff mbox series

Patch

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 0a375febad68..d5450190c38e 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -5940,6 +5940,18 @@  static int cmd_create_cis(struct btdev *dev, const void *data, uint8_t len)
 	return 0;
 }
 
+static uint32_t le_cis_transport_latecy(uint8_t ft, uint8_t iso_interval,
+						uint8_t sdu_interval[3])
+{
+	uint32_t latency;
+	uint32_t interval = get_le24(sdu_interval);
+
+	/* Transport_Latency = FT × ISO_Interval - SDU_Interval */
+	latency = ft * (iso_interval * 1250) - interval;
+
+	return latency <= interval ? latency : interval;
+}
+
 static void le_cis_estabilished(struct btdev *dev, struct btdev_conn *conn,
 						uint8_t status)
 {
@@ -5959,25 +5971,32 @@  static void le_cis_estabilished(struct btdev *dev, struct btdev_conn *conn,
 		struct btdev *remote = conn->link->dev;
 		struct le_cig *le_cig = &remote->le_cig[cig_idx];
 
-		/* TODO: Figure out if these values makes sense */
-		memcpy(evt.cig_sync_delay, le_cig->params.c_interval,
-				sizeof(le_cig->params.c_interval));
-		memcpy(evt.cis_sync_delay, le_cig->params.p_interval,
-				sizeof(le_cig->params.p_interval));
-		memcpy(evt.c_latency, &le_cig->params.c_interval,
-				sizeof(le_cig->params.c_interval));
-		memcpy(evt.p_latency, &le_cig->params.p_interval,
-				sizeof(le_cig->params.p_interval));
+		memset(evt.cig_sync_delay, 0, sizeof(evt.cig_sync_delay));
+		memset(evt.cis_sync_delay, 0, sizeof(evt.cis_sync_delay));
+
 		evt.c_phy = le_cig->cis[cis_idx].c_phy;
 		evt.p_phy = le_cig->cis[cis_idx].p_phy;
 		evt.nse = 0x01;
 		evt.c_bn = 0x01;
 		evt.p_bn = 0x01;
-		evt.c_ft = 0x01;
-		evt.p_ft = 0x01;
+		evt.c_ft = 0x02;
+		evt.p_ft = 0x02;
 		evt.c_mtu = le_cig->cis[cis_idx].c_sdu;
 		evt.p_mtu = le_cig->cis[cis_idx].p_sdu;
-		evt.interval = (le_cig->params.c_latency + 1) / 1.25;
+		evt.interval = (le_cig->params.c_latency + 0.625) / 1.25;
+
+		/* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 6, Part G
+		 * page 3050:
+		 *
+		 * Transport_Latency_C_To_P = CIG_Sync_Delay + FT_C_To_P ×
+		 * ISO_Interval - SDU_Interval_C_To_P
+		 * Transport_Latency_P_To_C = CIG_Sync_Delay + FT_P_To_C ×
+		 * ISO_Interval - SDU_Interval_P_To_C
+		 */
+		put_le24(le_cis_transport_latecy(evt.c_ft, evt.interval,
+				le_cig->params.c_interval), evt.c_latency);
+		put_le24(le_cis_transport_latecy(evt.p_ft, evt.interval,
+				le_cig->params.p_interval), evt.p_latency);
 	}
 
 	le_meta_event(dev, BT_HCI_EVT_LE_CIS_ESTABLISHED, &evt, sizeof(evt));