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

Commit 5bae7f61 authored by Mike Lockwood's avatar Mike Lockwood Committed by Mike Lockwood
Browse files

More work on PTP host support.



Change-Id: Ifbd5bd5efa3cdb750ae1a2aae38181457554d34d
Signed-off-by: default avatarMike Lockwood <mike@spruce.(none)>
parent ec4eff80
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -57,13 +57,17 @@ LOCAL_SRC_FILES:= \
                  MtpClient.cpp                         \
                  MtpDataPacket.cpp                     \
                  MtpDebug.cpp                          \
                  MtpDeviceInfo.cpp                     \
                  MtpPacket.cpp                         \
                  MtpRequestPacket.cpp                  \
                  MtpResponsePacket.cpp                 \
                  MtpStorageInfo.cpp                    \
                  MtpStringBuffer.cpp                   \
                  ../../libs/utils/VectorImpl.cpp       \
                  ../../libs/utils/SharedBuffer.cpp     \


LOCAL_STATIC_LIBRARIES := libusbhost
LOCAL_STATIC_LIBRARIES := libusbhost libcutils
LOCAL_LDLIBS := -lpthread

LOCAL_CFLAGS := -g -DMTP_HOST
+44 −16
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@

#include "MtpClient.h"
#include "MtpDebug.h"
#include "MtpDeviceInfo.h"
#include "MtpStorageInfo.h"
#include "MtpStringBuffer.h"

namespace android {
@@ -65,30 +67,55 @@ printf("openSession\n");
    return true;
}

bool MtpClient::getDeviceInfo() {
bool MtpClient::closeSession() {
    // FIXME
    return true;
}

MtpDeviceInfo* MtpClient::getDeviceInfo() {
    mRequest.reset();
    if (!sendRequest(MTP_OPERATION_GET_DEVICE_INFO))
        return false;
        return NULL;
    if (!readData())
        return false;
        return NULL;
    MtpResponseCode ret = readResponse();
printf("getDeviceInfo returned %04X\n", ret);
    if (ret == MTP_RESPONSE_OK) {
        MtpStringBuffer string;

        // fill in device info
        printf("MTP standard version: %d\n", mData.getUInt16());
        printf("MTP Vendor Extension ID: %d\n", mData.getUInt32());
        printf("MTP vendor extension version: %d\n", mData.getUInt16());
        mData.getString(string);
        printf("vendor extension desc %s\n", (const char *)string);
        MtpDeviceInfo* info = new MtpDeviceInfo;
        info->read(mData);
        return info;
    }
    return NULL;
}

        return true;
MtpStorageIDList* MtpClient::getStorageIDs() {
    mRequest.reset();
    if (!sendRequest(MTP_OPERATION_GET_STORAGE_IDS))
        return NULL;
    if (!readData())
        return NULL;
    MtpResponseCode ret = readResponse();
    if (ret == MTP_RESPONSE_OK) {
        return mData.getAUInt32();
    }
    return false;
    return NULL;
}

bool MtpClient::closeSession() {
    return true;
MtpStorageInfo* MtpClient::getStorageInfo(MtpStorageID storageID) {
    mRequest.reset();
    mRequest.setParameter(1, storageID);
    if (!sendRequest(MTP_OPERATION_GET_STORAGE_INFO))
        return NULL;
    if (!readData())
        return NULL;
    MtpResponseCode ret = readResponse();
printf("getStorageInfo returned %04X\n", ret);
    if (ret == MTP_RESPONSE_OK) {
        MtpStorageInfo* info = new MtpStorageInfo(storageID);
        info->read(mData);
        return info;
    }
    return NULL;
}

bool MtpClient::sendRequest(MtpOperationCode operation) {
@@ -111,6 +138,7 @@ bool MtpClient::sendData(MtpOperationCode operation) {
}

bool MtpClient::readData() {
    mData.reset();
    int ret = mData.read(mEndpointIn);
    printf("readData returned %d\n", ret);
    if (ret >= MTP_CONTAINER_HEADER_SIZE) {
+8 −4
Original line number Diff line number Diff line
@@ -20,12 +20,13 @@
#include "MtpRequestPacket.h"
#include "MtpDataPacket.h"
#include "MtpResponsePacket.h"
#include "mtp.h"

#include "MtpUtils.h"
#include "MtpTypes.h"

namespace android {

class MtpDeviceInfo;
class MtpStorageInfo;

class MtpClient {
private:
    struct usb_endpoint *mEndpointIn;
@@ -47,9 +48,12 @@ public:
    virtual             ~MtpClient();

    bool                openSession();
    bool                getDeviceInfo();
    bool                closeSession();

    MtpDeviceInfo*      getDeviceInfo();
    MtpStorageIDList*   getStorageIDs();
    MtpStorageInfo*     getStorageInfo(MtpStorageID storageID);

private:
    bool                sendRequest(MtpOperationCode operation);
    bool                sendData(MtpOperationCode operation);
+64 −0
Original line number Diff line number Diff line
@@ -75,6 +75,70 @@ void MtpDataPacket::getString(MtpStringBuffer& string)
    string.readFromPacket(this);
}

Int8List* MtpDataPacket::getAInt8() {
    Int8List* result = new Int8List;
    int count = getUInt32();
    for (int i = 0; i < count; i++)
        result->push(getInt8());
    return result;
}

UInt8List* MtpDataPacket::getAUInt8() {
    UInt8List* result = new UInt8List;
    int count = getUInt32();
    for (int i = 0; i < count; i++)
        result->push(getUInt8());
    return result;
}

Int16List* MtpDataPacket::getAInt16() {
    Int16List* result = new Int16List;
    int count = getUInt32();
    for (int i = 0; i < count; i++)
        result->push(getInt16());
    return result;
}

UInt16List* MtpDataPacket::getAUInt16() {
    UInt16List* result = new UInt16List;
    int count = getUInt32();
    for (int i = 0; i < count; i++)
        result->push(getUInt16());
    return result;
}

Int32List* MtpDataPacket::getAInt32() {
    Int32List* result = new Int32List;
    int count = getUInt32();
    for (int i = 0; i < count; i++)
        result->push(getInt32());
    return result;
}

UInt32List* MtpDataPacket::getAUInt32() {
    UInt32List* result = new UInt32List;
    int count = getUInt32();
    for (int i = 0; i < count; i++)
        result->push(getUInt32());
    return result;
}

Int64List* MtpDataPacket::getAInt64() {
    Int64List* result = new Int64List;
    int count = getUInt32();
    for (int i = 0; i < count; i++)
        result->push(getInt64());
    return result;
}

UInt64List* MtpDataPacket::getAUInt64() {
    UInt64List* result = new UInt64List;
    int count = getUInt32();
    for (int i = 0; i < count; i++)
        result->push(getUInt64());
    return result;
}

void MtpDataPacket::putInt8(int8_t value) {
    allocate(mOffset + 1);
    mBuffer[mOffset++] = (uint8_t)value;
+9 −0
Original line number Diff line number Diff line
@@ -46,6 +46,15 @@ public:
    inline int64_t      getInt64() { return (int64_t)getUInt64(); }
    void                getString(MtpStringBuffer& string);

    Int8List*           getAInt8();
    UInt8List*          getAUInt8();
    Int16List*          getAInt16();
    UInt16List*         getAUInt16();
    Int32List*          getAInt32();
    UInt32List*         getAUInt32();
    Int64List*          getAInt64();
    UInt64List*         getAUInt64();

    void                putInt8(int8_t value);
    void                putUInt8(uint8_t value);
    void                putInt16(int16_t value);
Loading