blob: 0e58e0125dbe434db2c4f24e2b1e8a546de7dbdd [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 Lockwood215b6822011-01-04 14:48:57 -050025#include <usbhost/usbhost.h>
26
Mike Lockwood8d3257a2010-05-14 10:10:36 -040027namespace android {
28
Mike Lockwood56118b52010-05-11 17:16:59 -040029MtpRequestPacket::MtpRequestPacket()
30 : MtpPacket(512)
31{
32}
33
34MtpRequestPacket::~MtpRequestPacket() {
35}
36
37#ifdef MTP_DEVICE
38int MtpRequestPacket::read(int fd) {
39 int ret = ::read(fd, mBuffer, mBufferSize);
40 if (ret >= 0)
41 mPacketSize = ret;
42 else
43 mPacketSize = 0;
44 return ret;
45}
46#endif
47
48#ifdef MTP_HOST
49 // write our buffer to the given endpoint (host mode)
Mike Lockwood215b6822011-01-04 14:48:57 -050050int MtpRequestPacket::write(struct usb_request *request)
Mike Lockwood56118b52010-05-11 17:16:59 -040051{
52 putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize);
53 putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_COMMAND);
Mike Lockwood215b6822011-01-04 14:48:57 -050054 request->buffer = mBuffer;
55 request->buffer_length = mPacketSize;
56 return transfer(request);
Mike Lockwood56118b52010-05-11 17:16:59 -040057}
58#endif
Mike Lockwood8d3257a2010-05-14 10:10:36 -040059
60} // namespace android