Compare commits

..

5 commits

Author SHA1 Message Date
Péter Ujfalusi
9240cb9f6c
Merge 2185bc70a9 into 21e0adfa3b 2024-07-29 03:26:27 +08:00
Takashi Iwai
21e0adfa3b aseqdump: Add dump of UMP Mixed Data Set messages
Add the support for yet more UMP messages.  UMP Mixed Data Set
messages are the generic data containers withe the message type 5
(shared with 8-bit SysEx).

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-07-28 11:24:06 +02:00
Takashi Iwai
095b064af6 aseqdump: Use snd_ump_get_byte() helper
For simplifying code, use the new helper function snd_ump_get_byte()
for extracting a byte data for SysEx and co.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-07-28 10:45:18 +02:00
Takashi Iwai
e26aa680aa aplaymidi2: Use snd_ump_get_byte() helper
For simplifying code, use snd_ump_get_byte() to retrieve the meta text
data.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-07-28 10:45:11 +02:00
Takashi Iwai
0188f93f02 aseqdump: Correct the limit of UMP 7-bit SysEx bytes
UMP 7-bit SysEx can hold up to 6 bytes, not 14 bytes.

Fixes: 02b0c3af56 ("aseqdump: Avoid OOB access with broken SysEx UMP packets")
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-07-26 14:46:58 +02:00
2 changed files with 51 additions and 19 deletions

View file

@ -362,7 +362,7 @@ static void show_text(const uint32_t *ump)
len = 0; len = 0;
for (i = 0; i < 12 && len < (int)sizeof(textbuf); i++) { for (i = 0; i < 12 && len < (int)sizeof(textbuf); i++) {
textbuf[len] = fh->meta.data[i / 4] >> ((3 - (i % 4)) * 8); textbuf[len] = snd_ump_get_byte(ump, 4 + i);
if (!textbuf[len]) if (!textbuf[len])
break; break;
switch (textbuf[len]) { switch (textbuf[len]) {

View file

@ -664,8 +664,7 @@ static void dump_ump_system_event(const unsigned int *ump)
static unsigned char ump_sysex7_data(const unsigned int *ump, static unsigned char ump_sysex7_data(const unsigned int *ump,
unsigned int offset) unsigned int offset)
{ {
offset += 2; return snd_ump_get_byte(ump, offset + 2);
return (ump[offset / 4] >> ((3 - (offset & 3)) * 8)) & 0xff;
} }
static void dump_ump_sysex_status(const char *prefix, unsigned int status) static void dump_ump_sysex_status(const char *prefix, unsigned int status)
@ -698,8 +697,8 @@ static void dump_ump_sysex_event(const unsigned int *ump)
dump_ump_sysex_status("SysEx", snd_ump_sysex_msg_status(ump)); dump_ump_sysex_status("SysEx", snd_ump_sysex_msg_status(ump));
length = snd_ump_sysex_msg_length(ump); length = snd_ump_sysex_msg_length(ump);
printf(" length %d ", length); printf(" length %d ", length);
if (length > 14) if (length > 6)
length = 14; length = 6;
for (i = 0; i < length; i++) for (i = 0; i < length; i++)
printf("%s%02x", i ? ":" : "", ump_sysex7_data(ump, i)); printf("%s%02x", i ? ":" : "", ump_sysex7_data(ump, i));
printf("\n"); printf("\n");
@ -708,8 +707,7 @@ static void dump_ump_sysex_event(const unsigned int *ump)
static unsigned char ump_sysex8_data(const unsigned int *ump, static unsigned char ump_sysex8_data(const unsigned int *ump,
unsigned int offset) unsigned int offset)
{ {
offset += 3; return snd_ump_get_byte(ump, offset + 3);
return (ump[offset / 4] >> ((3 - (offset & 3)) * 8)) & 0xff;
} }
static void dump_ump_sysex8_event(const unsigned int *ump) static void dump_ump_sysex8_event(const unsigned int *ump)
@ -728,6 +726,45 @@ static void dump_ump_sysex8_event(const unsigned int *ump)
printf("\n"); printf("\n");
} }
static void dump_ump_mixed_data_event(const unsigned int *ump)
{
const snd_ump_msg_mixed_data_t *m =
(const snd_ump_msg_mixed_data_t *)ump;
int i;
printf("Group %2d, ", group_number(snd_ump_msg_group(ump)));
switch (snd_ump_sysex_msg_status(ump)) {
case SND_UMP_MIXED_DATA_SET_STATUS_HEADER:
printf("MDS Header id=0x%x, bytes=%d, chunk=%d/%d, manufacturer=0x%04x, device=0x%04x, sub_id=0x%04x 0x%04x\n",
m->header.mds_id, m->header.bytes,
m->header.chunk, m->header.chunks,
m->header.manufacturer, m->header.device,
m->header.sub_id_1, m->header.sub_id_2);
break;
case SND_UMP_MIXED_DATA_SET_STATUS_PAYLOAD:
printf("MDS Payload id=0x%x, ", m->payload.mds_id);
for (i = 0; i < 14; i++)
printf("%s%02x", i ? ":" : "",
snd_ump_get_byte(ump, i + 2));
printf("\n");
break;
default:
printf("Extended Data (status 0x%x)\n",
snd_ump_sysex_msg_status(ump));
break;
}
}
static void dump_ump_extended_data_event(const unsigned int *ump)
{
unsigned char status = snd_ump_sysex_msg_status(ump);
if (status < 4)
dump_ump_sysex8_event(ump);
else
dump_ump_mixed_data_event(ump);
}
static void print_ump_string(const unsigned int *ump, unsigned int fmt, static void print_ump_string(const unsigned int *ump, unsigned int fmt,
unsigned int offset, int maxlen) unsigned int offset, int maxlen)
{ {
@ -736,17 +773,12 @@ static void print_ump_string(const unsigned int *ump, unsigned int fmt,
int i = 0; int i = 0;
do { do {
buf[i] = (*ump >> (24 - offset)) & 0xff; buf[i] = snd_ump_get_byte(ump, offset);
if (!buf[i]) if (!buf[i])
break; break;
if (buf[i] < 0x20) if (buf[i] < 0x20)
buf[i] = '.'; buf[i] = '.';
if (offset == 24) { offset++;
offset = 0;
ump++;
} else {
offset += 8;
}
} while (++i < maxlen); } while (++i < maxlen);
buf[i] = 0; buf[i] = 0;
@ -780,12 +812,12 @@ static void dump_ump_stream_event(const unsigned int *ump)
break; break;
case SND_UMP_STREAM_MSG_STATUS_EP_NAME: case SND_UMP_STREAM_MSG_STATUS_EP_NAME:
printf("EP Name "); printf("EP Name ");
print_ump_string(ump, (ump[0] >> 26) & 3, 16, 14); print_ump_string(ump, (ump[0] >> 26) & 3, 2, 14);
printf("\n"); printf("\n");
break; break;
case SND_UMP_STREAM_MSG_STATUS_PRODUCT_ID: case SND_UMP_STREAM_MSG_STATUS_PRODUCT_ID:
printf("Product Id "); printf("Product Id ");
print_ump_string(ump, (ump[0] >> 26) & 3, 16, 14); print_ump_string(ump, (ump[0] >> 26) & 3, 2, 14);
printf("\n"); printf("\n");
break; break;
case SND_UMP_STREAM_MSG_STATUS_STREAM_CFG_REQUEST: case SND_UMP_STREAM_MSG_STATUS_STREAM_CFG_REQUEST:
@ -810,7 +842,7 @@ static void dump_ump_stream_event(const unsigned int *ump)
case SND_UMP_STREAM_MSG_STATUS_FB_NAME: case SND_UMP_STREAM_MSG_STATUS_FB_NAME:
printf("Product Id "); printf("Product Id ");
printf("FB Name #%02d ", (ump[0] >> 8) & 0xff); printf("FB Name #%02d ", (ump[0] >> 8) & 0xff);
print_ump_string(ump, (ump[0] >> 26) & 3, 24, 13); print_ump_string(ump, (ump[0] >> 26) & 3, 3, 13);
printf("\n"); printf("\n");
break; break;
case SND_UMP_STREAM_MSG_STATUS_START_CLIP: case SND_UMP_STREAM_MSG_STATUS_START_CLIP:
@ -959,7 +991,7 @@ static void dump_ump_flex_data_event(const unsigned int *ump)
if (fh->meta.status_bank == SND_UMP_FLEX_DATA_MSG_BANK_METADATA || if (fh->meta.status_bank == SND_UMP_FLEX_DATA_MSG_BANK_METADATA ||
fh->meta.status_bank == SND_UMP_FLEX_DATA_MSG_BANK_PERF_TEXT) { fh->meta.status_bank == SND_UMP_FLEX_DATA_MSG_BANK_PERF_TEXT) {
printf("Meta (%s) ", ump_meta_prefix(fh)); printf("Meta (%s) ", ump_meta_prefix(fh));
print_ump_string(ump + 1, fh->meta.format, 0, 12); print_ump_string(ump, fh->meta.format, 4, 12);
printf("\n"); printf("\n");
return; return;
} }
@ -995,7 +1027,7 @@ static void dump_ump_event(const snd_seq_ump_event_t *ev)
dump_ump_sysex_event(ev->ump); dump_ump_sysex_event(ev->ump);
break; break;
case SND_UMP_MSG_TYPE_EXTENDED_DATA: case SND_UMP_MSG_TYPE_EXTENDED_DATA:
dump_ump_sysex8_event(ev->ump); dump_ump_extended_data_event(ev->ump);
break; break;
case SND_UMP_MSG_TYPE_FLEX_DATA: case SND_UMP_MSG_TYPE_FLEX_DATA:
dump_ump_flex_data_event(ev->ump); dump_ump_flex_data_event(ev->ump);