Skip to content

Commit

Permalink
swolisten: Add support for walking USB descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
ALTracer committed Aug 19, 2024
1 parent c43c128 commit 3a3558d
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions scripts/swolisten.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@

#define VID (0x1d50)
#define PID (0x6018)
#define INTERFACE (5)
#define ENDPOINT (0x85)
#define IFACE_STR "Black Magic Trace Capture"

#define TRANSFER_SIZE (64)
#define NUM_FIFOS 32
Expand Down Expand Up @@ -417,6 +416,7 @@ int usbFeeder(void)
unsigned char cbw[TRANSFER_SIZE];
libusb_device_handle *handle;
libusb_device *dev;
struct libusb_config_descriptor *config;
int size;

while (1)
Expand All @@ -435,10 +435,36 @@ int usbFeeder(void)
if (!(dev = libusb_get_device(handle)))
continue;

if (libusb_claim_interface (handle, INTERFACE)<0)
uint8_t bmp_interface = 0;
uint8_t bmp_endpoint = 0;

if (libusb_get_active_config_descriptor(dev, &config) < 0)
continue;

int interface_found = 0;
for (uint8_t if_num = 0; if_num < config->bNumInterfaces && !interface_found; if_num++) {
for (int alt_num = 0; alt_num < config->interface[if_num].num_altsetting && !interface_found; alt_num++) {
const struct libusb_interface_descriptor *i = &config->interface[if_num].altsetting[alt_num];
char itfString[256] = {0};

int ret = libusb_get_string_descriptor_ascii(handle, i->iInterface, (unsigned char*)itfString, 256);
if (ret < 0)
continue;
if (strcmp (itfString, IFACE_STR) != 0)
continue;

bmp_interface = i->bInterfaceNumber;
bmp_endpoint = i->endpoint[0].bEndpointAddress;
interface_found = 1;
}
}

libusb_free_config_descriptor(config);

if (libusb_claim_interface (handle, bmp_interface)<0)
continue;

while (0==libusb_bulk_transfer(handle, ENDPOINT, cbw, TRANSFER_SIZE, &size, 10))
while (0==libusb_bulk_transfer(handle, bmp_endpoint, cbw, TRANSFER_SIZE, &size, 10))
{
unsigned char *c=cbw;
if (options.dump)
Expand Down

0 comments on commit 3a3558d

Please sign in to comment.