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

Commit 3c51d6a9 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

MTP host fixes:



Add support for detecting android MTP devices
Fix problem reading data packet with header sent separately from payload.

Change-Id: I07b34af6783ebe2e63a317796ba0c8223df86edf
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent 108505b3
Loading
Loading
Loading
Loading
+52 −38
Original line number Diff line number Diff line
@@ -118,6 +118,21 @@ bool MtpClient::usbDeviceAdded(const char *devname) {
            {
                LOGD("Found camera: \"%s\" \"%s\"\n", usb_device_get_manufacturer_name(device),
                        usb_device_get_product_name(device));
            } else if (interface->bInterfaceClass == 0xFF &&
                    interface->bInterfaceSubClass == 0xFF &&
                    interface->bInterfaceProtocol == 0) {
                char* interfaceName = usb_device_get_string(device, interface->iInterface);
                if (!interfaceName || strcmp(interfaceName, "MTP"))
                    continue;
                // Looks like an android style MTP device
                LOGD("Found MTP device: \"%s\" \"%s\"\n", usb_device_get_manufacturer_name(device),
                        usb_device_get_product_name(device));
            } else {
                // not an MTP or PTP device
                continue;
            }

            // if we got here, then we have a likely MTP or PTP device

            // interface should be followed by three endpoints
            struct usb_endpoint_descriptor *ep;
@@ -165,7 +180,6 @@ bool MtpClient::usbDeviceAdded(const char *devname) {
            return mDone;
        }
    }
    }

    usb_device_close(device);
    return mDone;
+1 −1
Original line number Diff line number Diff line
@@ -372,7 +372,7 @@ int MtpDataPacket::writeDataHeader(int fd, uint32_t length) {
int MtpDataPacket::read(struct usb_endpoint *ep) {
    // first read the header
    int length = transfer(ep, mBuffer, mBufferSize);
    if (length > MTP_CONTAINER_HEADER_SIZE) {
    if (length >= MTP_CONTAINER_HEADER_SIZE) {
        // look at the length field to see if the data spans multiple packets
        uint32_t totalLength = MtpPacket::getUInt32(MTP_CONTAINER_LENGTH_OFFSET);
        while (totalLength > length) {