MtpRequestPacket.cpp revision 16864bae0f51c32c456da2c43adf7a057c0c4882
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#include <stdio.h> 18#include <sys/types.h> 19#include <fcntl.h> 20 21#include "MtpRequestPacket.h" 22 23MtpRequestPacket::MtpRequestPacket() 24 : MtpPacket(512) 25{ 26} 27 28MtpRequestPacket::~MtpRequestPacket() { 29} 30 31#ifdef MTP_DEVICE 32int MtpRequestPacket::read(int fd) { 33 int ret = ::read(fd, mBuffer, mBufferSize); 34 if (ret >= 0) 35 mPacketSize = ret; 36 else 37 mPacketSize = 0; 38 return ret; 39} 40#endif 41 42#ifdef MTP_HOST 43 // write our buffer to the given endpoint (host mode) 44int MtpRequestPacket::write(struct usb_endpoint *ep) 45{ 46 putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize); 47 putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_COMMAND); 48 return transfer(ep, mBuffer, mPacketSize); 49} 50#endif 51