<div dir="ltr">This is what ChatGPT proposes:<br>#include <libusb-1.0/libusb.h><br>#include <stdio.h><br><br>void scan_devices(const char* target_string) {<br> libusb_device **devs;<br> libusb_context *ctx = NULL;<br> int r;<br> ssize_t cnt;<br><br> r = libusb_init(&ctx);<br> if (r < 0) return;<br><br> cnt = libusb_get_device_list(ctx, &devs);<br> if (cnt < 0) return;<br><br> for (ssize_t i = 0; i < cnt; i++) {<br> libusb_device *dev = devs[i];<br> libusb_device_handle *handle = NULL;<br><br> if (libusb_open(dev, &handle) == 0) {<br> // Iterate through all configurations and interfaces<br> struct libusb_config_descriptor *config;<br> libusb_get_config_descriptor(dev, 0, &config);<br><br> for (int j = 0; j < config->bNumInterfaces; j++) {<br> const struct libusb_interface *inter = &config->interface[j];<br> const struct libusb_interface_descriptor *interdesc = &inter->altsetting[0];<br> if (interdesc->iInterface) {<br> unsigned char buffer[256];<br> int len = libusb_get_string_descriptor_ascii(handle, interdesc->iInterface, buffer, sizeof(buffer));<br> if (len > 0) {<br> printf("Interface %d: %s\n", j, buffer);<br> if (strcmp((char*)buffer, target_string) == 0) {<br> // Match found<br> printf("Match found for interface %d\n", j);<br> }<br> }<br> }<br> }<br> libusb_free_config_descriptor(config);<br> libusb_close(handle);<br> }<br> }<br><br> libusb_free_device_list(devs, 1);<br> libusb_exit(ctx);<br>}<br><br>int main() {<br> scan_devices("Particular String");<br> return 0;<br>}<br><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 14, 2024 at 3:54 PM Muni Sekhar <<a href="mailto:munisekharrms@gmail.com">munisekharrms@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">HI all,<br>
<br>
USB devices can have multiple interfaces (functional units) that serve<br>
different purposes (e.g., data transfer, control, audio, etc.).<br>
<br>
Each interface can have an associated string descriptor (referred to<br>
as iInterface). The string descriptor provides a human-readable name<br>
or description for the interface.<br>
<br>
>From user space service utility, How to scan all the USB devices<br>
connected to the system and read each interface string<br>
descriptor(iInterface) and check whether it matches "Particular<br>
String" or not.<br>
<br>
The service program should trigger scanning all the USB devices on any<br>
USB device detection or removal. Can libusb be used for it?<br>
<br>
Any input would be appreciated.<br>
<br>
-- <br>
Thanks,<br>
Sekhar<br>
</blockquote></div>