Loading media/mtp/MtpDevice.cpp +16 −3 Original line number Diff line number Diff line Loading @@ -49,7 +49,8 @@ MtpDevice::MtpDevice(struct usb_device* device, int interface, mDeviceInfo(NULL), mID(usb_device_get_unique_id(device)), mSessionID(0), mTransactionID(0) mTransactionID(0), mReceivedResponse(false) { } Loading Loading @@ -513,6 +514,7 @@ fail: bool MtpDevice::sendRequest(MtpOperationCode operation) { LOGV("sendRequest: %s\n", MtpDebug::getOperationCodeName(operation)); mReceivedResponse = false; mRequest.setOperationCode(operation); if (mTransactionID > 0) mRequest.setTransactionID(mTransactionID++); Loading @@ -535,6 +537,14 @@ bool MtpDevice::readData() { int ret = mData.read(mEndpointIn); LOGV("readData returned %d\n", ret); if (ret >= MTP_CONTAINER_HEADER_SIZE) { if (mData.getContainerType() == MTP_CONTAINER_TYPE_RESPONSE) { LOGD("got response packet instead of data packet"); // we got a response packet rather than data // copy it to mResponse mResponse.copyFrom(mData); mReceivedResponse = true; return false; } mData.dump(); return true; } Loading @@ -552,12 +562,15 @@ bool MtpDevice::writeDataHeader(MtpOperationCode operation, int dataLength) { MtpResponseCode MtpDevice::readResponse() { LOGV("readResponse\n"); if (mReceivedResponse) { mReceivedResponse = false; return mResponse.getResponseCode(); } int ret = mResponse.read(mEndpointIn); if (ret >= MTP_CONTAINER_HEADER_SIZE) { mResponse.dump(); return mResponse.getResponseCode(); } else { } else { LOGD("readResponse failed\n"); return -1; } Loading media/mtp/MtpDevice.h +2 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,8 @@ private: MtpRequestPacket mRequest; MtpDataPacket mData; MtpResponsePacket mResponse; // set to true if we received a response packet instead of a data packet bool mReceivedResponse; // to ensure only one MTP transaction at a time Mutex mMutex; Loading media/mtp/MtpPacket.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,13 @@ void MtpPacket::dump() { LOGV("\n"); } void MtpPacket::copyFrom(const MtpPacket& src) { int length = src.mPacketSize; allocate(length); mPacketSize = length; memcpy(mBuffer, src.mBuffer, length); } uint16_t MtpPacket::getUInt16(int offset) const { return ((uint16_t)mBuffer[offset + 1] << 8) | (uint16_t)mBuffer[offset]; } Loading Loading @@ -113,6 +120,10 @@ void MtpPacket::setContainerCode(uint16_t code) { putUInt16(MTP_CONTAINER_CODE_OFFSET, code); } uint16_t MtpPacket::getContainerType() const { return getUInt16(MTP_CONTAINER_TYPE_OFFSET); } MtpTransactionID MtpPacket::getTransactionID() const { return getUInt32(MTP_CONTAINER_TRANSACTION_ID_OFFSET); } Loading media/mtp/MtpPacket.h +3 −0 Original line number Diff line number Diff line Loading @@ -43,10 +43,13 @@ public: void allocate(int length); void dump(); void copyFrom(const MtpPacket& src); uint16_t getContainerCode() const; void setContainerCode(uint16_t code); uint16_t getContainerType() const; MtpTransactionID getTransactionID() const; void setTransactionID(MtpTransactionID id); Loading Loading
media/mtp/MtpDevice.cpp +16 −3 Original line number Diff line number Diff line Loading @@ -49,7 +49,8 @@ MtpDevice::MtpDevice(struct usb_device* device, int interface, mDeviceInfo(NULL), mID(usb_device_get_unique_id(device)), mSessionID(0), mTransactionID(0) mTransactionID(0), mReceivedResponse(false) { } Loading Loading @@ -513,6 +514,7 @@ fail: bool MtpDevice::sendRequest(MtpOperationCode operation) { LOGV("sendRequest: %s\n", MtpDebug::getOperationCodeName(operation)); mReceivedResponse = false; mRequest.setOperationCode(operation); if (mTransactionID > 0) mRequest.setTransactionID(mTransactionID++); Loading @@ -535,6 +537,14 @@ bool MtpDevice::readData() { int ret = mData.read(mEndpointIn); LOGV("readData returned %d\n", ret); if (ret >= MTP_CONTAINER_HEADER_SIZE) { if (mData.getContainerType() == MTP_CONTAINER_TYPE_RESPONSE) { LOGD("got response packet instead of data packet"); // we got a response packet rather than data // copy it to mResponse mResponse.copyFrom(mData); mReceivedResponse = true; return false; } mData.dump(); return true; } Loading @@ -552,12 +562,15 @@ bool MtpDevice::writeDataHeader(MtpOperationCode operation, int dataLength) { MtpResponseCode MtpDevice::readResponse() { LOGV("readResponse\n"); if (mReceivedResponse) { mReceivedResponse = false; return mResponse.getResponseCode(); } int ret = mResponse.read(mEndpointIn); if (ret >= MTP_CONTAINER_HEADER_SIZE) { mResponse.dump(); return mResponse.getResponseCode(); } else { } else { LOGD("readResponse failed\n"); return -1; } Loading
media/mtp/MtpDevice.h +2 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,8 @@ private: MtpRequestPacket mRequest; MtpDataPacket mData; MtpResponsePacket mResponse; // set to true if we received a response packet instead of a data packet bool mReceivedResponse; // to ensure only one MTP transaction at a time Mutex mMutex; Loading
media/mtp/MtpPacket.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,13 @@ void MtpPacket::dump() { LOGV("\n"); } void MtpPacket::copyFrom(const MtpPacket& src) { int length = src.mPacketSize; allocate(length); mPacketSize = length; memcpy(mBuffer, src.mBuffer, length); } uint16_t MtpPacket::getUInt16(int offset) const { return ((uint16_t)mBuffer[offset + 1] << 8) | (uint16_t)mBuffer[offset]; } Loading Loading @@ -113,6 +120,10 @@ void MtpPacket::setContainerCode(uint16_t code) { putUInt16(MTP_CONTAINER_CODE_OFFSET, code); } uint16_t MtpPacket::getContainerType() const { return getUInt16(MTP_CONTAINER_TYPE_OFFSET); } MtpTransactionID MtpPacket::getTransactionID() const { return getUInt32(MTP_CONTAINER_TRANSACTION_ID_OFFSET); } Loading
media/mtp/MtpPacket.h +3 −0 Original line number Diff line number Diff line Loading @@ -43,10 +43,13 @@ public: void allocate(int length); void dump(); void copyFrom(const MtpPacket& src); uint16_t getContainerCode() const; void setContainerCode(uint16_t code); uint16_t getContainerType() const; MtpTransactionID getTransactionID() const; void setTransactionID(MtpTransactionID id); Loading