Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 429c5ae4 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

adb: Fix problems detecting adb in more complicated USB configurations.



Change-Id: Ib5b13960a1c75efc97abeca46204c85bba905c71
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent 8071a4bd
Loading
Loading
Loading
Loading
+63 −64
Original line number Diff line number Diff line
@@ -150,13 +150,13 @@ static void find_usb_device(const char *base,
        while((de = readdir(devdir))) {
            unsigned char devdesc[256];
            unsigned char* bufptr = devdesc;
            unsigned char* bufend;
            struct usb_device_descriptor* device;
            struct usb_config_descriptor* config;
            struct usb_interface_descriptor* interface;
            struct usb_endpoint_descriptor *ep1, *ep2;
            unsigned zero_mask = 0;
            unsigned vid, pid;
            int i, interfaces;
            size_t desclength;

            if(badname(de->d_name)) continue;
@@ -173,6 +173,7 @@ static void find_usb_device(const char *base,
            }

            desclength = adb_read(fd, devdesc, sizeof(devdesc));
            bufend = bufptr + desclength;

                // should have device and configuration descriptors, and atleast two endpoints
            if (desclength < USB_DT_DEVICE_SIZE + USB_DT_CONFIG_SIZE) {
@@ -203,17 +204,17 @@ static void find_usb_device(const char *base,
                continue;
            }

                // loop through all the interfaces and look for the ADB interface
            interfaces = config->bNumInterfaces;
            for (i = 0; i < interfaces; i++) {
                if (bufptr + USB_DT_ENDPOINT_SIZE > devdesc + desclength)
                    break;
                // loop through all the descriptors and look for the ADB interface
            while (bufptr < bufend) {
                unsigned char length = bufptr[0];
                unsigned char type = bufptr[1];

                if (type == USB_DT_INTERFACE) {
                    interface = (struct usb_interface_descriptor *)bufptr;
                bufptr += USB_DT_INTERFACE_SIZE;
                if (interface->bLength != USB_DT_INTERFACE_SIZE ||
                    interface->bDescriptorType != USB_DT_INTERFACE) {
                    D("usb_interface_descriptor not found\n");
                    bufptr += length;

                    if (length != USB_DT_INTERFACE_SIZE) {
                        D("interface descriptor has wrong size\n");
                        break;
                    }

@@ -248,7 +249,6 @@ static void find_usb_device(const char *base,
                            D("bulk endpoints not found\n");
                            continue;
                        }

                            /* aproto 01 needs 0 termination */
                        if(interface->bInterfaceProtocol == 0x01) {
                            zero_mask = ep1->wMaxPacketSize - 1;
@@ -265,13 +265,12 @@ static void find_usb_device(const char *base,

                        register_device_callback(devname, local_ep_in, local_ep_out,
                                interface->bInterfaceNumber, device->iSerialNumber, zero_mask);

                        break;
                    }
                } else {
                    // seek next interface descriptor
                    bufptr += (USB_DT_ENDPOINT_SIZE * interface->bNumEndpoints);
                    bufptr += length;
                }
            } // end of for
            } // end of while

            adb_close(fd);
        } // end of devdir while