blob: d9b606022117fed5862247ad12c236b215e0bee9 [file] [log] [blame]
Jerry Zhang69b74502017-10-02 16:26:37 -07001/*
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#include "MtpDescriptors.h"
18
19namespace android {
20
21const struct usb_interface_descriptor mtp_interface_desc = {
22 .bLength = USB_DT_INTERFACE_SIZE,
23 .bDescriptorType = USB_DT_INTERFACE,
24 .bInterfaceNumber = 0,
25 .bNumEndpoints = 3,
26 .bInterfaceClass = USB_CLASS_STILL_IMAGE,
27 .bInterfaceSubClass = 1,
28 .bInterfaceProtocol = 1,
29 .iInterface = 1,
30};
31
32const struct usb_interface_descriptor ptp_interface_desc = {
33 .bLength = USB_DT_INTERFACE_SIZE,
34 .bDescriptorType = USB_DT_INTERFACE,
35 .bInterfaceNumber = 0,
36 .bNumEndpoints = 3,
37 .bInterfaceClass = USB_CLASS_STILL_IMAGE,
38 .bInterfaceSubClass = 1,
39 .bInterfaceProtocol = 1,
40};
41
42const struct usb_endpoint_descriptor_no_audio fs_sink = {
43 .bLength = USB_DT_ENDPOINT_SIZE,
44 .bDescriptorType = USB_DT_ENDPOINT,
45 .bEndpointAddress = 1 | USB_DIR_IN,
46 .bmAttributes = USB_ENDPOINT_XFER_BULK,
47 .wMaxPacketSize = MAX_PACKET_SIZE_FS,
48};
49
50const struct usb_endpoint_descriptor_no_audio fs_source = {
51 .bLength = USB_DT_ENDPOINT_SIZE,
52 .bDescriptorType = USB_DT_ENDPOINT,
53 .bEndpointAddress = 2 | USB_DIR_OUT,
54 .bmAttributes = USB_ENDPOINT_XFER_BULK,
55 .wMaxPacketSize = MAX_PACKET_SIZE_FS,
56};
57
58const struct usb_endpoint_descriptor_no_audio intr = {
59 .bLength = USB_DT_ENDPOINT_SIZE,
60 .bDescriptorType = USB_DT_ENDPOINT,
61 .bEndpointAddress = 3 | USB_DIR_IN,
62 .bmAttributes = USB_ENDPOINT_XFER_INT,
63 .wMaxPacketSize = MAX_PACKET_SIZE_EV,
64 .bInterval = 6,
65};
66
67const struct usb_endpoint_descriptor_no_audio hs_sink = {
68 .bLength = USB_DT_ENDPOINT_SIZE,
69 .bDescriptorType = USB_DT_ENDPOINT,
70 .bEndpointAddress = 1 | USB_DIR_IN,
71 .bmAttributes = USB_ENDPOINT_XFER_BULK,
72 .wMaxPacketSize = MAX_PACKET_SIZE_HS,
73};
74
75const struct usb_endpoint_descriptor_no_audio hs_source = {
76 .bLength = USB_DT_ENDPOINT_SIZE,
77 .bDescriptorType = USB_DT_ENDPOINT,
78 .bEndpointAddress = 2 | USB_DIR_OUT,
79 .bmAttributes = USB_ENDPOINT_XFER_BULK,
80 .wMaxPacketSize = MAX_PACKET_SIZE_HS,
81};
82
83const struct usb_endpoint_descriptor_no_audio ss_sink = {
84 .bLength = USB_DT_ENDPOINT_SIZE,
85 .bDescriptorType = USB_DT_ENDPOINT,
86 .bEndpointAddress = 1 | USB_DIR_IN,
87 .bmAttributes = USB_ENDPOINT_XFER_BULK,
88 .wMaxPacketSize = MAX_PACKET_SIZE_SS,
89};
90
91const struct usb_endpoint_descriptor_no_audio ss_source = {
92 .bLength = USB_DT_ENDPOINT_SIZE,
93 .bDescriptorType = USB_DT_ENDPOINT,
94 .bEndpointAddress = 2 | USB_DIR_OUT,
95 .bmAttributes = USB_ENDPOINT_XFER_BULK,
96 .wMaxPacketSize = MAX_PACKET_SIZE_SS,
97};
98
99const struct usb_ss_ep_comp_descriptor ss_sink_comp = {
100 .bLength = sizeof(ss_sink_comp),
101 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
102 .bMaxBurst = 6,
103};
104
105const struct usb_ss_ep_comp_descriptor ss_source_comp = {
106 .bLength = sizeof(ss_source_comp),
107 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
108 .bMaxBurst = 6,
109};
110
111const struct usb_ss_ep_comp_descriptor ss_intr_comp = {
112 .bLength = sizeof(ss_intr_comp),
113 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
114};
115
116const struct func_desc mtp_fs_descriptors = {
117 .intf = mtp_interface_desc,
118 .sink = fs_sink,
119 .source = fs_source,
120 .intr = intr,
121};
122
123const struct func_desc mtp_hs_descriptors = {
124 .intf = mtp_interface_desc,
125 .sink = hs_sink,
126 .source = hs_source,
127 .intr = intr,
128};
129
130const struct ss_func_desc mtp_ss_descriptors = {
131 .intf = mtp_interface_desc,
132 .sink = ss_sink,
133 .sink_comp = ss_sink_comp,
134 .source = ss_source,
135 .source_comp = ss_source_comp,
136 .intr = intr,
137 .intr_comp = ss_intr_comp,
138};
139
140const struct func_desc ptp_fs_descriptors = {
141 .intf = ptp_interface_desc,
142 .sink = fs_sink,
143 .source = fs_source,
144 .intr = intr,
145};
146
147const struct func_desc ptp_hs_descriptors = {
148 .intf = ptp_interface_desc,
149 .sink = hs_sink,
150 .source = hs_source,
151 .intr = intr,
152};
153
154const struct ss_func_desc ptp_ss_descriptors = {
155 .intf = ptp_interface_desc,
156 .sink = ss_sink,
157 .sink_comp = ss_sink_comp,
158 .source = ss_source,
159 .source_comp = ss_source_comp,
160 .intr = intr,
161 .intr_comp = ss_intr_comp,
162};
163
164const struct functionfs_strings mtp_strings = {
165 .header = {
166 .magic = htole32(FUNCTIONFS_STRINGS_MAGIC),
167 .length = htole32(sizeof(mtp_strings)),
168 .str_count = htole32(1),
169 .lang_count = htole32(1),
170 },
171 .lang0 = {
172 .code = htole16(0x0409),
173 .str1 = STR_INTERFACE,
174 },
175};
176
177const struct usb_os_desc_header mtp_os_desc_header = {
178 .interface = htole32(1),
179 .dwLength = htole32(sizeof(usb_os_desc_header) + sizeof(usb_ext_compat_desc)),
180 .bcdVersion = htole16(1),
181 .wIndex = htole16(4),
182 .bCount = htole16(1),
183 .Reserved = htole16(0),
184};
185
186const struct usb_ext_compat_desc mtp_os_desc_compat = {
187 .bFirstInterfaceNumber = 0,
188 .Reserved1 = htole32(1),
189 .CompatibleID = { 'M', 'T', 'P' },
190 .SubCompatibleID = {0},
191 .Reserved2 = {0},
192};
193
194const struct usb_ext_compat_desc ptp_os_desc_compat = {
195 .bFirstInterfaceNumber = 0,
196 .Reserved1 = htole32(1),
197 .CompatibleID = { 'P', 'T', 'P' },
198 .SubCompatibleID = {0},
199 .Reserved2 = {0},
200};
201
202const struct desc_v2 mtp_desc_v2 = {
203 .header = {
204 .magic = htole32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2),
205 .length = htole32(sizeof(struct desc_v2)),
206 .flags = FUNCTIONFS_HAS_FS_DESC | FUNCTIONFS_HAS_HS_DESC |
207 FUNCTIONFS_HAS_SS_DESC | FUNCTIONFS_HAS_MS_OS_DESC,
208 },
209 .fs_count = 4,
210 .hs_count = 4,
211 .ss_count = 7,
212 .os_count = 1,
213 .fs_descs = mtp_fs_descriptors,
214 .hs_descs = mtp_hs_descriptors,
215 .ss_descs = mtp_ss_descriptors,
216 .os_header = mtp_os_desc_header,
217 .os_desc = mtp_os_desc_compat,
218};
219
220const struct desc_v2 ptp_desc_v2 = {
221 .header = {
222 .magic = htole32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2),
223 .length = htole32(sizeof(struct desc_v2)),
224 .flags = FUNCTIONFS_HAS_FS_DESC | FUNCTIONFS_HAS_HS_DESC |
225 FUNCTIONFS_HAS_SS_DESC | FUNCTIONFS_HAS_MS_OS_DESC,
226 },
227 .fs_count = 4,
228 .hs_count = 4,
229 .ss_count = 7,
230 .os_count = 1,
231 .fs_descs = ptp_fs_descriptors,
232 .hs_descs = ptp_hs_descriptors,
233 .ss_descs = ptp_ss_descriptors,
234 .os_header = mtp_os_desc_header,
235 .os_desc = ptp_os_desc_compat,
236};
237
238const struct desc_v1 mtp_desc_v1 = {
239 .header = {
240 .magic = htole32(FUNCTIONFS_DESCRIPTORS_MAGIC),
241 .length = htole32(sizeof(struct desc_v1)),
242 .fs_count = 4,
243 .hs_count = 4,
244 },
245 .fs_descs = mtp_fs_descriptors,
246 .hs_descs = mtp_hs_descriptors,
247};
248
249const struct desc_v1 ptp_desc_v1 = {
250 .header = {
251 .magic = htole32(FUNCTIONFS_DESCRIPTORS_MAGIC),
252 .length = htole32(sizeof(struct desc_v1)),
253 .fs_count = 4,
254 .hs_count = 4,
255 },
256 .fs_descs = ptp_fs_descriptors,
257 .hs_descs = ptp_hs_descriptors,
258};
259
260}; // namespace android