blob: 8ece580bbd381ac738fe5b35d60acd06f7021b31 [file] [log] [blame]
Mike Lockwood56118b52010-05-11 17:16:59 -04001/*
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
Mike Lockwood3e6616d2010-06-29 18:11:52 -040017#define LOG_TAG "MtpRequestPacket"
18
Mike Lockwood56118b52010-05-11 17:16:59 -040019#include <stdio.h>
20#include <sys/types.h>
21#include <fcntl.h>
22
23#include "MtpRequestPacket.h"
24
Mike Lockwood8d3257a2010-05-14 10:10:36 -040025namespace android {
26
Mike Lockwood56118b52010-05-11 17:16:59 -040027MtpRequestPacket::MtpRequestPacket()
28 : MtpPacket(512)
29{
30}
31
32MtpRequestPacket::~MtpRequestPacket() {
33}
34
35#ifdef MTP_DEVICE
36int MtpRequestPacket::read(int fd) {
37 int ret = ::read(fd, mBuffer, mBufferSize);
38 if (ret >= 0)
39 mPacketSize = ret;
40 else
41 mPacketSize = 0;
42 return ret;
43}
44#endif
45
46#ifdef MTP_HOST
47 // write our buffer to the given endpoint (host mode)
48int MtpRequestPacket::write(struct usb_endpoint *ep)
49{
50 putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize);
51 putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_COMMAND);
52 return transfer(ep, mBuffer, mPacketSize);
53}
54#endif
Mike Lockwood8d3257a2010-05-14 10:10:36 -040055
56} // namespace android