Linux bluetooth development
 help / color / mirror / Atom feed
From: Matthew Cash <matthew@matthew-cash.com>
To: linux-bluetooth@vger.kernel.org
Cc: Matthew Cash <matthew@matthew-cash.com>
Subject: [PATCH BlueZ] profiles/midi: Fix zero timestampHigh
Date: Sat, 27 Jun 2026 10:57:12 -0700	[thread overview]
Message-ID: <20260627175712.228564-1-matthew@matthew-cash.com> (raw)

BLE-MIDI timestampHigh can legitimately be zero. The MIDI parser used
timestamp_high == 0 to decide whether it had already consumed the packet
header, so packets starting with 0x80 0x80 caused the next running-status
payload byte to be consumed as another timestamp header.

Track whether timestampHigh has been read separately from its value so
packed MIDI events with zero timestampHigh are parsed correctly.
---
 profiles/midi/libmidi.c | 5 ++++-
 profiles/midi/libmidi.h | 2 ++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/profiles/midi/libmidi.c b/profiles/midi/libmidi.c
index 6f2914a8c..ef33f7dfd 100644
--- a/profiles/midi/libmidi.c
+++ b/profiles/midi/libmidi.c
@@ -110,6 +110,7 @@ int midi_read_init(struct midi_read_parser *parser)
 	parser->timestamp = 0;
 	parser->timestamp_low = 0;
 	parser->timestamp_high = 0;
+	parser->timestamp_high_set = false;
 
 	parser->sysex_stream.data = malloc(MIDI_SYSEX_MAX_SIZE);
 	if (!parser->sysex_stream.data)
@@ -355,8 +356,10 @@ size_t midi_read_raw(struct midi_read_parser *parser, const uint8_t *data,
 	size_t i = 0;
 	bool err = false;
 
-	if (parser->timestamp_high == 0)
+	if (!parser->timestamp_high_set) {
 		parser->timestamp_high = data[i++] & 0x3F;
+		parser->timestamp_high_set = true;
+	}
 
 	snd_midi_event_reset_encode(parser->midi_ev);
 
diff --git a/profiles/midi/libmidi.h b/profiles/midi/libmidi.h
index 41f522dd4..9d314cc11 100644
--- a/profiles/midi/libmidi.h
+++ b/profiles/midi/libmidi.h
@@ -83,6 +83,7 @@ struct midi_read_parser {
 	int16_t timestamp;               /* last MIDI-BLE timestamp */
 	int8_t timestamp_low;            /* MIDI-BLE timestampLow from the current packet */
 	int8_t timestamp_high;           /* MIDI-BLE timestampHigh from the current packet */
+	bool timestamp_high_set;         /* timestampHigh read for current packet */
 	struct midi_buffer sysex_stream; /* SysEx stream */
 	snd_midi_event_t *midi_ev;       /* midi<->seq event */
 };
@@ -100,6 +101,7 @@ static inline void midi_read_reset(struct midi_read_parser *parser)
 	parser->rstatus = 0;
 	parser->timestamp_low = 0;
 	parser->timestamp_high = 0;
+	parser->timestamp_high_set = false;
 }
 
 /* Parses raw BLE-MIDI messages and populates a sequencer event representing the
-- 
2.54.0


             reply	other threads:[~2026-06-27 18:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-27 17:57 Matthew Cash [this message]
2026-06-27 19:39 ` [BlueZ] profiles/midi: Fix zero timestampHigh bluez.test.bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260627175712.228564-1-matthew@matthew-cash.com \
    --to=matthew@matthew-cash.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox