blob: 754e205aa249e936cf9c8a722e6d8fc7efdd7d5a [file] [log] [blame]
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -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 * Copyright (C) 2014 TeamWin - bigbiff and Dees_Troy mtp database conversion to C++
17 */
18
19#include <stdio.h>
20#include <sys/types.h>
21#include <fcntl.h>
22
23#include "MtpRequestPacket.h"
24#include "MtpDebug.h"
25
26#include <usbhost/usbhost.h>
27
28
29MtpRequestPacket::MtpRequestPacket()
30 : MtpPacket(512)
31{
32}
33
34MtpRequestPacket::~MtpRequestPacket() {
35}
36
37#ifdef MTP_DEVICE
38int MtpRequestPacket::read(int fd) {
39 MTPD("block1 fd: %d\n", fd);
40 int ret = ::read(fd, mBuffer, mBufferSize);
41 MTPD("block2\n");
42 if (ret >= 0)
43 mPacketSize = ret;
44 else
45 mPacketSize = 0;
46 return ret;
47}
48#endif
49
50#ifdef MTP_HOST
51 // write our buffer to the given endpoint (host mode)
52int MtpRequestPacket::write(struct usb_request *request)
53{
54 putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize);
55 putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_COMMAND);
56 request->buffer = mBuffer;
57 request->buffer_length = mPacketSize;
58 return transfer(request);
59}
60#endif
61