blob: 1119f7d53f8e0cc0fac7587530b71cd0bf7dc799 [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#include <sys/ioctl.h>
23
24#ifdef MTP_DEVICE
25#include <linux/usb/f_mtp.h>
26#endif
27
28#include "MtpEventPacket.h"
29
30#include <usbhost/usbhost.h>
31
32
33MtpEventPacket::MtpEventPacket()
34 : MtpPacket(512)
35{
36}
37
38MtpEventPacket::~MtpEventPacket() {
39}
40
41#ifdef MTP_DEVICE
42int MtpEventPacket::write(int fd) {
43 struct mtp_event event;
44
45 putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize);
46 putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_EVENT);
47
48 event.data = mBuffer;
49 event.length = mPacketSize;
50 int ret = ::ioctl(fd, MTP_SEND_EVENT, (unsigned long)&event);
51 return (ret < 0 ? ret : 0);
52}
53#endif
54
55#ifdef MTP_HOST
56int MtpEventPacket::read(struct usb_request *request) {
57 request->buffer = mBuffer;
58 request->buffer_length = mBufferSize;
59 int ret = transfer(request);
60 if (ret >= 0)
61 mPacketSize = ret;
62 else
63 mPacketSize = 0;
64 return ret;
65}
66#endif
67
68