blob: f362d80f42509298c8d130e04a9ba7477449b937 [file] [log] [blame]
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -05001/*
2 * Copyright (C) 2017 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_DESCRIPTORS_H
18#define MTP_DESCRIPTORS_H
19
20#include <linux/usb/ch9.h>
21#include <linux/usb/functionfs.h>
22#include <sys/endian.h>
23
24constexpr char FFS_MTP_EP0[] = "/dev/usb-ffs/mtp/ep0";
25constexpr char FFS_MTP_EP_IN[] = "/dev/usb-ffs/mtp/ep1";
26constexpr char FFS_MTP_EP_OUT[] = "/dev/usb-ffs/mtp/ep2";
27constexpr char FFS_MTP_EP_INTR[] = "/dev/usb-ffs/mtp/ep3";
28
29constexpr char FFS_PTP_EP0[] = "/dev/usb-ffs/ptp/ep0";
30constexpr char FFS_PTP_EP_IN[] = "/dev/usb-ffs/ptp/ep1";
31constexpr char FFS_PTP_EP_OUT[] = "/dev/usb-ffs/ptp/ep2";
32constexpr char FFS_PTP_EP_INTR[] = "/dev/usb-ffs/ptp/ep3";
33
34constexpr int MAX_PACKET_SIZE_FS = 64;
35constexpr int MAX_PACKET_SIZE_HS = 512;
36constexpr int MAX_PACKET_SIZE_SS = 1024;
37constexpr int MAX_PACKET_SIZE_EV = 28;
38
39struct func_desc {
40 struct usb_interface_descriptor intf;
41 struct usb_endpoint_descriptor_no_audio sink;
42 struct usb_endpoint_descriptor_no_audio source;
43 struct usb_endpoint_descriptor_no_audio intr;
44} __attribute__((packed));
45
46struct ss_func_desc {
47 struct usb_interface_descriptor intf;
48 struct usb_endpoint_descriptor_no_audio sink;
49 struct usb_ss_ep_comp_descriptor sink_comp;
50 struct usb_endpoint_descriptor_no_audio source;
51 struct usb_ss_ep_comp_descriptor source_comp;
52 struct usb_endpoint_descriptor_no_audio intr;
53 struct usb_ss_ep_comp_descriptor intr_comp;
54} __attribute__((packed));
55
56struct desc_v1 {
57 struct usb_functionfs_descs_head_v1 {
58 __le32 magic;
59 __le32 length;
60 __le32 fs_count;
61 __le32 hs_count;
62 } __attribute__((packed)) header;
63 struct func_desc fs_descs, hs_descs;
64} __attribute__((packed));
65
66struct desc_v2 {
67 struct usb_functionfs_descs_head_v2 header;
68 // The rest of the structure depends on the flags in the header.
69 __le32 fs_count;
70 __le32 hs_count;
71 __le32 ss_count;
72 __le32 os_count;
73 struct func_desc fs_descs, hs_descs;
74 struct ss_func_desc ss_descs;
75 struct usb_os_desc_header os_header;
76 struct usb_ext_compat_desc os_desc;
77} __attribute__((packed));
78
79// OS descriptor contents should not be changed. See b/64790536.
80static_assert(sizeof(struct desc_v2) == sizeof(usb_functionfs_descs_head_v2) +
81 16 + 2 * sizeof(struct func_desc) + sizeof(struct ss_func_desc) +
82 sizeof(usb_os_desc_header) + sizeof(usb_ext_compat_desc),
83 "Size of mtp descriptor is incorrect!");
84
85#define STR_INTERFACE "MTP"
86struct functionfs_lang {
87 __le16 code;
88 char str1[sizeof(STR_INTERFACE)];
89} __attribute__((packed));
90
91struct functionfs_strings {
92 struct usb_functionfs_strings_head header;
93 struct functionfs_lang lang0;
94} __attribute__((packed));
95
96extern const struct desc_v2 mtp_desc_v2;
97extern const struct desc_v2 ptp_desc_v2;
98extern const struct desc_v1 mtp_desc_v1;
99extern const struct desc_v1 ptp_desc_v1;
100extern const struct functionfs_strings mtp_strings;
101
102bool writeDescriptors(int fd, bool ptp);
103
104#endif // MTP_DESCRIPTORS_H