1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #define LOG_TAG "MtpResponsePacket" 18 19 #include <stdio.h> 20 #include <sys/types.h> 21 #include <fcntl.h> 22 23 #include "IMtpHandle.h" 24 #include "MtpResponsePacket.h" 25 26 #include <usbhost/usbhost.h> 27 28 namespace android { 29 30 MtpResponsePacket::MtpResponsePacket() 31 : MtpPacket(512) 32 { 33 } 34 35 MtpResponsePacket::~MtpResponsePacket() { 36 } 37 38 #ifdef MTP_DEVICE 39 int MtpResponsePacket::write(IMtpHandle *h) { 40 putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize); 41 putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_RESPONSE); 42 int ret = h->write(mBuffer, mPacketSize); 43 return (ret < 0 ? ret : 0); 44 } 45 #endif 46 47 #ifdef MTP_HOST 48 int MtpResponsePacket::read(struct usb_request *request) { 49 request->buffer = mBuffer; 50 request->buffer_length = mBufferSize; 51 int ret = transfer(request); 52 if (ret >= 0) 53 mPacketSize = ret; 54 else 55 mPacketSize = 0; 56 return ret; 57 } 58 #endif 59 60 } // namespace android 61 62