blob: cfc3930b5178b406327297bf46831e756f6722e7 [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#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
24namespace android {
25
26constexpr int MAX_PACKET_SIZE_FS = 64;
27constexpr int MAX_PACKET_SIZE_HS = 512;
28constexpr int MAX_PACKET_SIZE_SS = 1024;
29constexpr int MAX_PACKET_SIZE_EV = 28;
30
31struct func_desc {
32 struct usb_interface_descriptor intf;
33 struct usb_endpoint_descriptor_no_audio sink;
34 struct usb_endpoint_descriptor_no_audio source;
35 struct usb_endpoint_descriptor_no_audio intr;
36} __attribute__((packed));
37
38struct ss_func_desc {
39 struct usb_interface_descriptor intf;
40 struct usb_endpoint_descriptor_no_audio sink;
41 struct usb_ss_ep_comp_descriptor sink_comp;
42 struct usb_endpoint_descriptor_no_audio source;
43 struct usb_ss_ep_comp_descriptor source_comp;
44 struct usb_endpoint_descriptor_no_audio intr;
45 struct usb_ss_ep_comp_descriptor intr_comp;
46} __attribute__((packed));
47
48struct desc_v1 {
49 struct usb_functionfs_descs_head_v1 {
50 __le32 magic;
51 __le32 length;
52 __le32 fs_count;
53 __le32 hs_count;
54 } __attribute__((packed)) header;
55 struct func_desc fs_descs, hs_descs;
56} __attribute__((packed));
57
58struct desc_v2 {
59 struct usb_functionfs_descs_head_v2 header;
60 // The rest of the structure depends on the flags in the header.
61 __le32 fs_count;
62 __le32 hs_count;
63 __le32 ss_count;
64 __le32 os_count;
65 struct func_desc fs_descs, hs_descs;
66 struct ss_func_desc ss_descs;
67 struct usb_os_desc_header os_header;
68 struct usb_ext_compat_desc os_desc;
69} __attribute__((packed));
70
71// OS descriptor contents should not be changed. See b/64790536.
72static_assert(sizeof(struct desc_v2) == sizeof(usb_functionfs_descs_head_v2) +
73 16 + 2 * sizeof(struct func_desc) + sizeof(struct ss_func_desc) +
74 sizeof(usb_os_desc_header) + sizeof(usb_ext_compat_desc),
75 "Size of mtp descriptor is incorrect!");
76
77#define STR_INTERFACE "MTP"
78struct functionfs_lang {
79 __le16 code;
80 char str1[sizeof(STR_INTERFACE)];
81} __attribute__((packed));
82
83struct functionfs_strings {
84 struct usb_functionfs_strings_head header;
85 struct functionfs_lang lang0;
86} __attribute__((packed));
87
88extern const struct desc_v2 mtp_desc_v2;
89extern const struct desc_v2 ptp_desc_v2;
90extern const struct desc_v1 mtp_desc_v1;
91extern const struct desc_v1 ptp_desc_v1;
92extern const struct functionfs_strings mtp_strings;
93
94}; // namespace android
95
96#endif // MTP_DESCRIPTORS_H