Retrieve and store the device USB PID

This commit is contained in:
Geoffrey D. Bennett
2024-02-20 01:44:31 +10:30
parent 9544635e30
commit b4fc332f0a
2 changed files with 29 additions and 0 deletions

View File

@@ -564,6 +564,33 @@ static void alsa_subscribe(struct alsa_card *card) {
snd_ctl_poll_descriptors(card->handle, &card->pfd, 1);
}
static void alsa_get_usbid(struct alsa_card *card) {
char path[256];
snprintf(path, 256, "/proc/asound/card%d/usbid", card->num);
FILE *f = fopen(path, "r");
if (!f) {
fprintf(stderr, "can't open %s: %s\n", path, strerror(errno));
return;
}
int vid, pid;
int result = fscanf(f, "%04x:%04x", &vid, &pid);
fclose(f);
if (result != 2) {
fprintf(stderr, "can't read %s\n", path);
return;
}
if (vid != 0x1235) {
fprintf(stderr, "VID %04x != expected 0x1235 for Focusrite\n", vid);
return;
}
card->pid = pid;
}
// get the bus and device numbers from /proc/asound/cardxx/usbbus
// format is XXX/YYY
static int alsa_get_usbbus(struct alsa_card *card, int *bus, int *dev) {
@@ -748,6 +775,7 @@ static void alsa_scan_cards(void) {
alsa_get_elem_list(card);
alsa_subscribe(card);
alsa_get_usbid(card);
alsa_get_serial_number(card);
if (card->serial) {

View File

@@ -152,6 +152,7 @@ struct alsa_elem {
struct alsa_card {
int num;
char *device;
uint32_t pid;
char *serial;
char *name;
snd_ctl_t *handle;