• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022, sakumisu
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #ifndef USB_MTP_CONFIG_H
7 #define USB_MTP_CONFIG_H
8 
9 #include "usb_mtp.h"
10 
11 static const uint16_t VendExtDesc[] = { 'm', 'i', 'c', 'r', 'o', 's', 'o', 'f', 't', '.', 'c', 'o', 'm', ':', ' ', '1', '.', '0', ';', ' ', 0 }; /* last 2 bytes must be 0*/
12 
13 static const uint16_t SuppOP[] = { MTP_OP_GET_DEVICE_INFO, MTP_OP_OPEN_SESSION, MTP_OP_CLOSE_SESSION,
14                                    MTP_OP_GET_STORAGE_IDS, MTP_OP_GET_STORAGE_INFO, MTP_OP_GET_NUM_OBJECTS,
15                                    MTP_OP_GET_OBJECT_HANDLES, MTP_OP_GET_OBJECT_INFO, MTP_OP_GET_OBJECT,
16                                    MTP_OP_DELETE_OBJECT, MTP_OP_SEND_OBJECT_INFO, MTP_OP_SEND_OBJECT,
17                                    MTP_OP_GET_DEVICE_PROP_DESC, MTP_OP_GET_DEVICE_PROP_VALUE,
18                                    MTP_OP_SET_OBJECT_PROP_VALUE, MTP_OP_GET_OBJECT_PROP_VALUE,
19                                    MTP_OP_GET_OBJECT_PROPS_SUPPORTED, MTP_OP_GET_OBJECT_PROPLIST,
20                                    MTP_OP_GET_OBJECT_PROP_DESC, MTP_OP_GET_OBJECT_PROP_REFERENCES };
21 
22 static const uint16_t SuppEvents[] = { MTP_EVENT_OBJECTADDED };
23 
24 static const uint16_t DevicePropSupp[] = { MTP_DEV_PROP_DEVICE_FRIENDLY_NAME, MTP_DEV_PROP_BATTERY_LEVEL };
25 
26 static const uint16_t SuppCaptFormat[] = { MTP_OBJ_FORMAT_UNDEFINED, MTP_OBJ_FORMAT_ASSOCIATION, MTP_OBJ_FORMAT_TEXT };
27 
28 static const uint16_t SuppImgFormat[] = { MTP_OBJ_FORMAT_UNDEFINED, MTP_OBJ_FORMAT_TEXT, MTP_OBJ_FORMAT_ASSOCIATION,
29                                           MTP_OBJ_FORMAT_EXECUTABLE, MTP_OBJ_FORMAT_WAV, MTP_OBJ_FORMAT_MP3,
30                                           MTP_OBJ_FORMAT_EXIF_JPEG, MTP_OBJ_FORMAT_MPEG, MTP_OBJ_FORMAT_MP4_CONTAINER,
31                                           MTP_OBJ_FORMAT_WINDOWS_IMAGE_FORMAT, MTP_OBJ_FORMAT_PNG, MTP_OBJ_FORMAT_WMA,
32                                           MTP_OBJ_FORMAT_WMV };
33 
34 static const uint16_t Manuf[] = { 'C', 'h', 'e', 'r', 'r', 'y', 'U', 'S', 'B', 0 }; /* last 2 bytes must be 0*/
35 static const uint16_t Model[] = { 'C', 'h', 'e', 'r', 'r', 'y', 'U', 'S', 'B', 0 }; /* last 2 bytes must be 0*/
36 static const uint16_t DeviceVers[] = { 'V', '1', '.', '0', '0', 0 };                /* last 2 bytes must be 0*/
37 /*SerialNbr shall be 32 character hexadecimal string for legacy compatibility reasons */
38 static const uint16_t SerialNbr[] = { '0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', '0', '0',
39                                       '1', '0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', '0',
40                                       '0', '1', '0', '0', 0 }; /* last 2 bytes must be 0*/
41 
42 static const uint16_t DefaultFileName[] = { 'N', 'e', 'w', ' ', 'F', 'o', 'l', 'd', 'e', 'r', 0 };
43 
44 static const uint16_t DevicePropDefVal[] = { 'C', 'h', 'e', 'r', 'r', 'y', 'U', 'S', 'B', 0 }; /* last 2 bytes must be 0*/
45 static const uint16_t DevicePropCurDefVal[] = { 'C', 'h', 'e', 'r', 'r', 'y', 'U', 'S', 'B', 0 };
46 
47 /* required for all object format : storageID, objectFormat, ObjectCompressedSize,
48 persistent unique object identifier, name*/
49 static const uint16_t ObjectPropCode[] = { MTP_OB_PROP_STORAGE_ID, MTP_OB_PROP_OBJECT_FORMAT, MTP_OB_PROP_OBJECT_SIZE,
50                                            MTP_OB_PROP_OBJ_FILE_NAME, MTP_OB_PROP_PARENT_OBJECT, MTP_OB_PROP_NAME,
51                                            MTP_OB_PROP_PERS_UNIQ_OBJ_IDEN, MTP_OB_PROP_PROTECTION_STATUS };
52 
53 #define MTP_STORAGE_ID 0x00010001U /* SD card is inserted*/
54 
55 #define CONFIG_MTP_VEND_EXT_DESC_LEN        (sizeof(VendExtDesc) / 2U)
56 #define CONFIG_MTP_SUPP_OP_LEN              (sizeof(SuppOP) / 2U)
57 #define CONFIG_MTP_SUPP_EVENTS_LEN          (sizeof(SuppEvents) / 2U)
58 #define CONFIG_MTP_SUPP_DEVICE_PROP_LEN     (sizeof(DevicePropSupp) / 2U)
59 #define CONFIG_MTP_SUPP_CAPT_FORMAT_LEN     (sizeof(SuppCaptFormat) / 2U)
60 #define CONFIG_MTP_SUPP_IMG_FORMAT_LEN      (sizeof(SuppImgFormat) / 2U)
61 #define CONFIG_MTP_MANUF_LEN                (sizeof(Manuf) / 2U)
62 #define CONFIG_MTP_MODEL_LEN                (sizeof(Model) / 2U)
63 #define CONFIG_MTP_DEVICE_VERSION_LEN       (sizeof(DeviceVers) / 2U)
64 #define CONFIG_MTP_SERIAL_NBR_LEN           (sizeof(SerialNbr) / 2U)
65 #define CONFIG_MTP_SUPP_OBJ_PROP_LEN        (sizeof(ObjectPropCode) / 2U)
66 #define CONFIG_MTP_DEVICE_PROP_DESC_DEF_LEN (sizeof(DevicePropDefVal) / 2U)
67 #define CONFIG_MTP_DEVICE_PROP_DESC_CUR_LEN (sizeof(DevicePropCurDefVal) / 2U)
68 #define CONFIG_MTP_STORAGE_ID_LEN           1
69 #define CONFIG_MTP_OBJECT_HANDLE_LEN        100
70 
71 struct mtp_device_info {
72     uint16_t StandardVersion;
73     uint32_t VendorExtensionID;
74     uint16_t VendorExtensionVersion;
75     uint8_t VendorExtensionDesc_len;
76     uint16_t VendorExtensionDesc[CONFIG_MTP_VEND_EXT_DESC_LEN];
77     uint16_t FunctionalMode;
78     uint32_t OperationsSupported_len;
79     uint16_t OperationsSupported[CONFIG_MTP_SUPP_OP_LEN];
80     uint32_t EventsSupported_len;
81     uint16_t EventsSupported[CONFIG_MTP_SUPP_EVENTS_LEN];
82     uint32_t DevicePropertiesSupported_len;
83     uint16_t DevicePropertiesSupported[CONFIG_MTP_SUPP_DEVICE_PROP_LEN];
84     uint32_t CaptureFormats_len;
85     uint16_t CaptureFormats[CONFIG_MTP_SUPP_CAPT_FORMAT_LEN];
86     uint32_t ImageFormats_len;
87     uint16_t ImageFormats[CONFIG_MTP_SUPP_IMG_FORMAT_LEN];
88     uint8_t Manufacturer_len;
89     uint16_t Manufacturer[CONFIG_MTP_MANUF_LEN];
90     uint8_t Model_len;
91     uint16_t Model[CONFIG_MTP_MODEL_LEN];
92     uint8_t DeviceVersion_len;
93     uint16_t DeviceVersion[CONFIG_MTP_DEVICE_VERSION_LEN];
94     uint8_t SerialNumber_len;
95     uint16_t SerialNumber[CONFIG_MTP_SERIAL_NBR_LEN];
96 } __PACKED;
97 
98 struct mtp_object_props_support {
99     uint32_t ObjectPropCode_len;
100     uint16_t ObjectPropCode[CONFIG_MTP_SUPP_OBJ_PROP_LEN];
101 } __PACKED;
102 
103 struct mtp_device_prop_desc {
104     uint16_t DevicePropertyCode;
105     uint16_t DataType;
106     uint8_t GetSet;
107     uint8_t DefaultValue_len;
108     uint16_t DefaultValue[CONFIG_MTP_DEVICE_PROP_DESC_DEF_LEN];
109     uint8_t CurrentValue_len;
110     uint16_t CurrentValue[CONFIG_MTP_DEVICE_PROP_DESC_CUR_LEN];
111     uint8_t FormFlag;
112 } __PACKED;
113 
114 struct mtp_storage_id {
115     uint32_t StorageIDS_len;
116     uint32_t StorageIDS[CONFIG_MTP_STORAGE_ID_LEN];
117 } __PACKED;
118 
119 struct mtp_storage_info {
120     uint16_t StorageType;
121     uint16_t FilesystemType;
122     uint16_t AccessCapability;
123     uint64_t MaxCapability;
124     uint64_t FreeSpaceInBytes;
125     uint32_t FreeSpaceInObjects;
126     uint8_t StorageDescription;
127     uint8_t VolumeLabel;
128 } __PACKED;
129 
130 struct mtp_object_handle {
131     uint32_t ObjectHandle_len;
132     uint32_t ObjectHandle[CONFIG_MTP_OBJECT_HANDLE_LEN];
133 } __PACKED;
134 
135 struct mtp_object_info {
136     uint32_t Storage_id;
137     uint16_t ObjectFormat;
138     uint16_t ProtectionStatus;
139     uint32_t ObjectCompressedSize;
140     uint16_t ThumbFormat;
141     uint32_t ThumbCompressedSize;
142     uint32_t ThumbPixWidth;
143     uint32_t ThumbPixHeight;
144     uint32_t ImagePixWidth;
145     uint32_t ImagePixHeight;
146     uint32_t ImageBitDepth;
147     uint32_t ParentObject;
148     uint16_t AssociationType;
149     uint32_t AssociationDesc;
150     uint32_t SequenceNumber;
151     uint8_t Filename_len;
152     uint16_t Filename[255];
153     uint32_t CaptureDate;
154     uint32_t ModificationDate;
155     uint8_t Keywords;
156 } __PACKED;
157 
158 struct mtp_object_prop_desc {
159     uint16_t ObjectPropertyCode;
160     uint16_t DataType;
161     uint8_t GetSet;
162     uint8_t *DefValue;
163     uint32_t GroupCode;
164     uint8_t FormFlag;
165 } __PACKED;
166 
167 struct mtp_object_prop_element {
168     uint32_t ObjectHandle;
169     uint16_t PropertyCode;
170     uint16_t Datatype;
171     uint8_t *propval;
172 } __PACKED;
173 
174 struct mtp_object_prop_list {
175     uint32_t Properties_len;
176     struct mtp_object_prop_element Properties[CONFIG_MTP_SUPP_OBJ_PROP_LEN];
177 } __PACKED;
178 
179 #endif /* USB_MTP_CONFIG_H */