blob: 8eed13a149e49e4dc6ccea16a9e9ca3c3dfc8f08 [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 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 "MtpResponsePacket.h"
24
25#include <usbhost/usbhost.h>
26
27
28MtpResponsePacket::MtpResponsePacket()
29 : MtpPacket(512)
30{
31}
32
33MtpResponsePacket::~MtpResponsePacket() {
34}
35
36#ifdef MTP_DEVICE
37int MtpResponsePacket::write(int fd) {
38 putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize);
39 putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_RESPONSE);
40 int ret = ::write(fd, mBuffer, mPacketSize);
41 return (ret < 0 ? ret : 0);
42}
43#endif
44
45#ifdef MTP_HOST
46int MtpResponsePacket::read(struct usb_request *request) {
47 request->buffer = mBuffer;
48 request->buffer_length = mBufferSize;
49 int ret = transfer(request);
50 if (ret >= 0)
51 mPacketSize = ret;
52 else
53 mPacketSize = 0;
54 return ret;
55}
56#endif
57
58