blob: a1979d7aa5bf16943638bece062a7d2c0b9fa405 [file] [log] [blame]
Mike Lockwood16864ba2010-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
17#include <stdio.h>
18#include <sys/types.h>
19#include <fcntl.h>
20
21#include "MtpResponsePacket.h"
22
Mike Lockwood7850ef92010-05-14 10:10:36 -040023namespace android {
24
Mike Lockwood16864ba2010-05-11 17:16:59 -040025MtpResponsePacket::MtpResponsePacket()
26 : MtpPacket(512)
27{
28}
29
30MtpResponsePacket::~MtpResponsePacket() {
31}
32
33#ifdef MTP_DEVICE
34int MtpResponsePacket::write(int fd) {
35 putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize);
36 putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_RESPONSE);
37 int ret = ::write(fd, mBuffer, mPacketSize);
38 return (ret < 0 ? ret : 0);
39}
40#endif
41
42#ifdef MTP_HOST
43 // read our buffer from the given endpoint
44int MtpResponsePacket::read(struct usb_endpoint *ep) {
45 int ret = transfer(ep, mBuffer, mBufferSize);
46 if (ret >= 0)
47 mPacketSize = ret;
48 else
49 mPacketSize = 0;
50 return ret;
51}
52#endif
53
Mike Lockwood7850ef92010-05-14 10:10:36 -040054} // namespace android
Mike Lockwood16864ba2010-05-11 17:16:59 -040055