From f7454622eaac287d20ab43013d7015fe42b894f8 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Thu, 9 Dec 2010 18:34:18 -0800 Subject: MTP host: Handle receiving a response packet instead of data packet. This will happen if the device needs to report an error rather than returning the data. Change-Id: I477512b3676c2f0518a85a4135832ed4475fbc2d Signed-off-by: Mike Lockwood --- media/mtp/MtpDevice.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'media/mtp/MtpDevice.cpp') diff --git a/media/mtp/MtpDevice.cpp b/media/mtp/MtpDevice.cpp index 8ad39dc..e058a5a 100644 --- a/media/mtp/MtpDevice.cpp +++ b/media/mtp/MtpDevice.cpp @@ -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) { } @@ -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++); @@ -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; } @@ -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; } -- cgit v1.1