[ALSA] usb-audio: fix Emagic MIDI protocol handling
authorClemens Ladisch <clemens@ladisch.de>
Thu, 25 Aug 2005 09:10:05 +0000 (11:10 +0200)
committerJaroslav Kysela <perex@suse.cz>
Tue, 30 Aug 2005 06:47:34 +0000 (08:47 +0200)
USB generic driver
Emagic devices pad their packets not with 0xff bytes but with a 0xff
byte followed by garbage, so we have to stop at the first such byte.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
sound/usb/usbmidi.c

index d0d895df537572cd346b8362850bfd69ff1702b9..5f19b494923e0347d31558b0c91ccd903fabc2d0 100644 (file)
@@ -594,17 +594,20 @@ static void snd_usbmidi_emagic_finish_out(snd_usb_midi_out_endpoint_t* ep)
 static void snd_usbmidi_emagic_input(snd_usb_midi_in_endpoint_t* ep,
                                     uint8_t* buffer, int buffer_length)
 {
-       /* ignore padding bytes at end of buffer */
-       while (buffer_length > 0 && buffer[buffer_length - 1] == 0xff)
-               --buffer_length;
+       int i;
+
+       /* FF indicates end of valid data */
+       for (i = 0; i < buffer_length; ++i)
+               if (buffer[i] == 0xff) {
+                       buffer_length = i;
+                       break;
+               }
 
        /* handle F5 at end of last buffer */
        if (ep->seen_f5)
                goto switch_port;
 
        while (buffer_length > 0) {
-               int i;
-
                /* determine size of data until next F5 */
                for (i = 0; i < buffer_length; ++i)
                        if (buffer[i] == 0xf5)
@@ -671,6 +674,10 @@ static void snd_usbmidi_emagic_output(snd_usb_midi_out_endpoint_t* ep)
                                break;
                }
        }
+       if (buf_free < ep->max_transfer && buf_free > 0) {
+               *buf = 0xff;
+               --buf_free;
+       }
        ep->urb->transfer_buffer_length = ep->max_transfer - buf_free;
 }