Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3007903ybt; Mon, 22 Jun 2020 12:29:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHCbNESlGfr0bSu7KpzzOm8xb+Leh/8DUv6/8KscTBAFl9CihrJBeAtcf52IWFQA/x7di1 X-Received: by 2002:aa7:ce13:: with SMTP id d19mr19022935edv.355.1592854176177; Mon, 22 Jun 2020 12:29:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592854176; cv=none; d=google.com; s=arc-20160816; b=VZLh4SHt84JVOB+KC+9aWF7WgeLPOuNv+blpfT/sWfWuH5boEvVFGMrUCig7E+X4rW 5T6TUr/opFlRknsfH+Fbe2eX3YLoOBFpg98llUr18yi4q2FKMQio5xaCVoYmFUFQOOb/ CC9rvN4Tfv9s3eD81aXEhLakOSt70o1RFYIhEkGajF50gfBT1+ScQXU7vO917FTNiKdN m54im+j4TR2A+SjA78Mbzcdnh7uCuMtWXRMCLTVYs+5p8HVbReLSEbua3xIXlBAK5D/J E8pGWDBCjrhlop8Qf/L95Lsj7vJggUcJ7Dlm9bqOaItXLERwJYLBpb4MOIri4zc0Bc/0 mtOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=uG7ktmVmHhtH+zZNCHerRHEynF4USMtwuSPvt3ZKgAU=; b=RYHlWeb0VMmCPM7Vw4B4YIeGkrctW4CQEAS/EjaiZFttRx3+ZK5PP6vofQ/UMedqwf sYhaX+VeDCetcVry3hxgymKTY48r49//KrXDsALOX3CHntJAIUnzXCR7FHvk9a7CdP7Z ggSKF1DYO2FlGrZ3OmpY/iYM7nzXIDygWXKw01Cu+ZxwpU2ShZsUk8WPYwfO2vdQXyHs j0nhoE6GkQyM2paaWJLdS0QsGBw4O7WYi/kHEWlbR24woM7KXbt7On5sknvpZ58Q62nL 5ItKiKCJHVlRRBsDTUkhwMoJy6DF5axbQ0nxHm2HSP5zQfMVXf5JU2Brc2q7W9CFo91g Ef9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=koV2GwSq; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b23si1914217ejb.465.2020.06.22.12.29.11; Mon, 22 Jun 2020 12:29:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=koV2GwSq; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728228AbgFVT3H (ORCPT + 99 others); Mon, 22 Jun 2020 15:29:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728140AbgFVT3G (ORCPT ); Mon, 22 Jun 2020 15:29:06 -0400 Received: from mail-oi1-x241.google.com (mail-oi1-x241.google.com [IPv6:2607:f8b0:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B69E5C061573 for ; Mon, 22 Jun 2020 12:29:06 -0700 (PDT) Received: by mail-oi1-x241.google.com with SMTP id 25so16660507oiy.13 for ; Mon, 22 Jun 2020 12:29:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uG7ktmVmHhtH+zZNCHerRHEynF4USMtwuSPvt3ZKgAU=; b=koV2GwSqFxX8odhqiduXuq+eMkJQXPNf7fVi5bx9ClkKXvzVwG8fP4A0r+L5um7idO KEuff78NN5BQqdAax7Zs4+4OPvUjpQk7stoOOldcMM8jDQ3jGdzfD9d6xJqtu/EQC+tk mOt9iZO9H920rKpGMMgSA0NLiX7vRzuEAx6EdyU65qyIBzdDH41FOiK31EAhXMPQXxcT +veISPy5Y1E3NYofMg0xPHTlOsT1nvhtAvuWnOcNPMar4WBIKEgJaYQPDraOWCBL4sgR szzBE8jY0rnkl00I7QFOxmgnOAl3EP7z4o9inxuwopC+V3fUs+676QXgl9Zw3jQNPgDG voWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uG7ktmVmHhtH+zZNCHerRHEynF4USMtwuSPvt3ZKgAU=; b=TlcTJ/xk4V8I5VioCBbmPpMh5G6yQC2gxBXkG2v0aV7EdVngVg53blnnRCnuwrYs/i jPuFgPb9maEMhGrIFZv7dPUP3UVJv7nRpDkQePAGPXHjZWQ2oFShlsebQhRxiZHM99xv 3Io4jVep/PRZJA4Flzf71pyeJrhmYE+fSWlnzIJ58dhNnxPSusysE+VBKOEY/9JNu/wO 5AFy2H7LuuRhvuTBQu4yEz1YJQeqEIxVoKDZuvF2mtEUSP8qqYtBfXf27AqfHLR22o1C 22S4nVTE3RhmdZyc3nAjzo4C0e7XPOHl5NYLL7ZfQNDDzxQBPc5ktyaUamGiRFQ33EZp W8yw== X-Gm-Message-State: AOAM533HzlIjFG9K4xmpwItZAz5RoWLWtHpmavZPL5UY+SdUwd/fkpT+ AHGfg0blDDuOQG1CqhnT/k0KXX0xPeMk1k+2L2Q= X-Received: by 2002:aca:4f4f:: with SMTP id d76mr13059448oib.152.1592854146102; Mon, 22 Jun 2020 12:29:06 -0700 (PDT) MIME-Version: 1.0 References: <20200619183456.38696-1-tedd.an@linux.intel.com> In-Reply-To: <20200619183456.38696-1-tedd.an@linux.intel.com> From: Luiz Augusto von Dentz Date: Mon, 22 Jun 2020 12:28:54 -0700 Message-ID: Subject: Re: [PATCH V2 1/2] midi: Fix SysEx parser in MIDI plugin To: Tedd Ho-Jeong An Cc: "linux-bluetooth@vger.kernel.org" , Tedd Ho-Jeong An Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Tedd, On Fri, Jun 19, 2020 at 9:27 PM wrote: > > From: Tedd Ho-Jeong An > > The SysEx end of message parser didn't consider the fact that > timestampsLow are in the stream and it might have the EOX (F7) > byte as well. > > Fix that by always assuming the first system message byte is > the timestampLow. > > Future work would involve support other type of system message > bytes, such as real-time. > --- > profiles/midi/libmidi.c | 38 +++++++++++++++++++++++++++++++------- > 1 file changed, 31 insertions(+), 7 deletions(-) > > diff --git a/profiles/midi/libmidi.c b/profiles/midi/libmidi.c > index 4b4df799f..7d57e7335 100644 > --- a/profiles/midi/libmidi.c > +++ b/profiles/midi/libmidi.c > @@ -331,6 +331,30 @@ static size_t handle_end_of_sysex(struct midi_read_parser *parser, > return sysex_length + 1; /* +1 because of timestampLow */ > } > > +/* Searches the end of a SysEx message that contains a timestampLow > + * before the SysEx end byte. Returns the number of bytes of valid > + * SysEx payload in the buffer. > + */ > +static size_t sysex_eox_len(const uint8_t *data, size_t size) > +{ > + size_t i = 0; > + > + MIDI_ASSERT(size > 0); > + > + if (data[i] == 0xF0) > + i++; > + > + /* Search for timestamp low */ > + while (i < size) { > + if ((data[i] & 0x80)) { > + i++; > + break; > + } > + i++; > + } > + > + return (i < size && data[i] == 0xF7) ? i : 0; > +} > > > size_t midi_read_raw(struct midi_read_parser *parser, const uint8_t *data, > @@ -368,14 +392,14 @@ size_t midi_read_raw(struct midi_read_parser *parser, const uint8_t *data, > > /* System Common Messages */ > case 0xF0: /* SysEx Start */ { > - uint8_t *pos; > + size_t sysex_length; > > /* cleanup Running Status Message */ > parser->rstatus = 0; > > - /* Avoid parsing if SysEx is contained in one BLE packet */ > - if ((pos = memchr(data + i, 0xF7, size - i))) { > - const size_t sysex_length = pos - (data + i); > + sysex_length = sysex_eox_len(data + i, size - i); > + /* Search for End of SysEx message in one BLE message */ > + if (sysex_length > 0) { > midi_size = handle_end_of_sysex(parser, ev, data + i, > sysex_length); > } else { > @@ -424,10 +448,10 @@ size_t midi_read_raw(struct midi_read_parser *parser, const uint8_t *data, > > /* Check for SysEx messages */ > if (parser->sysex_stream.len > 0) { > - uint8_t *pos; > + size_t sysex_length; > > - if ((pos = memchr(data + i, 0xF7, size - i))) { > - const size_t sysex_length = pos - (data + i); > + sysex_length = sysex_eox_len(data + i, size - i); > + if (sysex_length > 0) { > midi_size = handle_end_of_sysex(parser, ev, data + i, > sysex_length); > } else { > -- > 2.25.4 > Applied, thanks. -- Luiz Augusto von Dentz