blob: 44ff0f3b696dfb3496c2027c48adc2bd69b2dc93 [file] [log] [blame]
Jerry Zhang487be612016-10-24 12:10:41 -07001/*
2 * Copyright (C) 2016 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#ifndef _MTP_FFS_HANDLE_H
18#define _MTP_FFS_HANDLE_H
19
20#include <android-base/unique_fd.h>
21#include <IMtpHandle.h>
22
23namespace android {
24
25class MtpFfsHandleTest;
26
27class MtpFfsHandle : public IMtpHandle {
28 friend class android::MtpFfsHandleTest;
29private:
30 int writeHandle(int fd, const void *data, int len);
31 int readHandle(int fd, void *data, int len);
32 int spliceReadHandle(int fd, int fd_out, int len);
33 bool initFunctionfs();
34 void closeConfig();
35 void closeEndpoints();
36
37 bool mPtp;
38
39 std::mutex mLock;
40
41 android::base::unique_fd mControl;
42 // "in" from the host's perspective => sink for mtp server
43 android::base::unique_fd mBulkIn;
44 // "out" from the host's perspective => source for mtp server
45 android::base::unique_fd mBulkOut;
46 android::base::unique_fd mIntr;
47
48 int mMaxWrite;
49 int mMaxRead;
50
Jerry Zhangcc9d0fd2017-01-27 10:29:59 -080051 std::vector<char> mBuffer1;
52 std::vector<char> mBuffer2;
53
Jerry Zhang487be612016-10-24 12:10:41 -070054public:
55 int read(void *data, int len);
56 int write(const void *data, int len);
57
58 int receiveFile(mtp_file_range mfr);
59 int sendFile(mtp_file_range mfr);
60 int sendEvent(mtp_event me);
61
62 int start();
63 void close();
64
65 int configure(bool ptp);
66
67 MtpFfsHandle();
68 ~MtpFfsHandle();
69};
70
71struct mtp_data_header {
72 /* length of packet, including this header */
73 __le32 length;
74 /* container type (2 for data packet) */
75 __le16 type;
76 /* MTP command code */
77 __le16 command;
78 /* MTP transaction ID */
79 __le32 transaction_id;
80};
81
82} // namespace android
83
84#endif // _MTP_FF_HANDLE_H
85