1 #ifndef __USBH_MTP_PTP_H__ 2 #define __USBH_MTP_PTP_H__ 3 4 #include <stdint.h> 5 6 #define PTP_USB_BULK_HDR_LEN ((2 * sizeof(uint32_t)) + (2 * sizeof(uint16_t))) 7 8 typedef struct { 9 uint32_t length; 10 uint16_t type; 11 uint16_t code; 12 uint32_t trans_id; 13 uint32_t param1; 14 uint32_t param2; 15 uint32_t param3; 16 uint32_t param4; 17 uint32_t param5; 18 } PTP_OpContainer_t; 19 20 typedef struct { 21 uint32_t length; 22 uint16_t type; 23 uint16_t code; 24 uint32_t trans_id; 25 uint8_t payload[4096]; 26 } PTP_DataContainer_t; 27 28 typedef struct { 29 uint32_t length; 30 uint16_t type; 31 uint16_t code; 32 uint32_t trans_id; 33 uint32_t param1; 34 uint32_t param2; 35 uint32_t param3; 36 uint32_t param4; 37 uint32_t param5; 38 } PTP_RespContainer_t; 39 40 /* PTP USB Asynchronous Event Interrupt Data Format */ 41 typedef struct { 42 uint32_t length; 43 uint16_t type; 44 uint16_t code; 45 uint32_t trans_id; 46 uint32_t param1; 47 uint32_t param2; 48 uint32_t param3; 49 } PTP_EventContainer_t; 50 51 52 /* Operation Codes */ 53 54 /* PTP v1.0 operation codes */ 55 #define PTP_OC_Undefined 0x1000U 56 #define PTP_OC_GetDeviceInfo 0x1001U 57 #define PTP_OC_OpenSession 0x1002U 58 #define PTP_OC_CloseSession 0x1003U 59 #define PTP_OC_GetStorageIDs 0x1004U 60 #define PTP_OC_GetStorageInfo 0x1005U 61 #define PTP_OC_GetNumObjects 0x1006U 62 #define PTP_OC_GetObjectHandles 0x1007U 63 #define PTP_OC_GetObjectInfo 0x1008U 64 #define PTP_OC_GetObject 0x1009U 65 #define PTP_OC_GetThumb 0x100AU 66 #define PTP_OC_DeleteObject 0x100BU 67 #define PTP_OC_SendObjectInfo 0x100CU 68 #define PTP_OC_SendObject 0x100DU 69 #define PTP_OC_InitiateCapture 0x100EU 70 #define PTP_OC_FormatStore 0x100FU 71 #define PTP_OC_ResetDevice 0x1010U 72 #define PTP_OC_SelfTest 0x1011U 73 #define PTP_OC_SetObjectProtection 0x1012U 74 #define PTP_OC_PowerDown 0x1013U 75 #define PTP_OC_GetDevicePropDesc 0x1014U 76 #define PTP_OC_GetDevicePropValue 0x1015U 77 #define PTP_OC_SetDevicePropValue 0x1016U 78 #define PTP_OC_ResetDevicePropValue 0x1017U 79 #define PTP_OC_TerminateOpenCapture 0x1018U 80 #define PTP_OC_MoveObject 0x1019U 81 #define PTP_OC_CopyObject 0x101AU 82 #define PTP_OC_GetPartialObject 0x101BU 83 #define PTP_OC_InitiateOpenCapture 0x101CU 84 85 /* PTP v1.1 operation codes */ 86 #define PTP_OC_StartEnumHandles 0x101DU 87 #define PTP_OC_EnumHandles 0x101EU 88 #define PTP_OC_StopEnumHandles 0x101FU 89 #define PTP_OC_GetVendorExtensionMaps 0x1020U 90 #define PTP_OC_GetVendorDeviceInfo 0x1021U 91 #define PTP_OC_GetResizedImageObject 0x1022U 92 #define PTP_OC_GetFilesystemManifest 0x1023U 93 #define PTP_OC_GetStreamInfo 0x1024U 94 #define PTP_OC_GetStream 0x1025U 95 96 /* Microsoft / MTP extension codes */ 97 #define PTP_OC_GetObjectPropsSupported 0x9801U 98 #define PTP_OC_GetObjectPropDesc 0x9802U 99 #define PTP_OC_GetObjectPropValue 0x9803U 100 #define PTP_OC_SetObjectPropValue 0x9804U 101 #define PTP_OC_GetObjPropList 0x9805U 102 #define PTP_OC_SetObjPropList 0x9806U 103 #define PTP_OC_GetInterdependendPropdesc 0x9807U 104 #define PTP_OC_SendObjectPropList 0x9808U 105 #define PTP_OC_GetObjectReferences 0x9810U 106 #define PTP_OC_SetObjectReferences 0x9811U 107 #define PTP_OC_UpdateDeviceFirmware 0x9812U 108 #define PTP_OC_Skip 0x9820U 109 110 111 /* Response Codes */ 112 113 /* PTP v1.0 response codes */ 114 #define PTP_RC_Undefined 0x2000U 115 #define PTP_RC_OK 0x2001U 116 #define PTP_RC_GeneralError 0x2002U 117 #define PTP_RC_SessionNotOpen 0x2003U 118 #define PTP_RC_InvalidTransactionID 0x2004U 119 #define PTP_RC_OperationNotSupported 0x2005U 120 #define PTP_RC_ParameterNotSupported 0x2006U 121 #define PTP_RC_IncompleteTransfer 0x2007U 122 #define PTP_RC_InvalidStorageId 0x2008U 123 #define PTP_RC_InvalidObjectHandle 0x2009U 124 #define PTP_RC_DevicePropNotSupported 0x200AU 125 #define PTP_RC_InvalidObjectFormatCode 0x200BU 126 #define PTP_RC_StoreFull 0x200CU 127 #define PTP_RC_ObjectWriteProtected 0x200DU 128 #define PTP_RC_StoreReadOnly 0x200EU 129 #define PTP_RC_AccessDenied 0x200FU 130 #define PTP_RC_NoThumbnailPresent 0x2010U 131 #define PTP_RC_SelfTestFailed 0x2011U 132 #define PTP_RC_PartialDeletion 0x2012U 133 #define PTP_RC_StoreNotAvailable 0x2013U 134 #define PTP_RC_SpecByFormatUnsupported 0x2014U 135 #define PTP_RC_NoValidObjectInfo 0x2015U 136 #define PTP_RC_InvalidCodeFormat 0x2016U 137 #define PTP_RC_UnknownVendorCode 0x2017U 138 #define PTP_RC_CaptureAlreadyTerminated 0x2018U 139 #define PTP_RC_DeviceBusy 0x2019U 140 #define PTP_RC_InvalidParentObject 0x201AU 141 #define PTP_RC_InvalidDevicePropFormat 0x201BU 142 #define PTP_RC_InvalidDevicePropValue 0x201CU 143 #define PTP_RC_InvalidParameter 0x201DU 144 #define PTP_RC_SessionAlreadyOpened 0x201EU 145 #define PTP_RC_TransactionCanceled 0x201FU 146 #define PTP_RC_SpecOfDestinationUnsupported 0x2020U 147 148 /* PTP v1.1 response codes */ 149 #define PTP_RC_InvalidEnumHandle 0x2021U 150 #define PTP_RC_NoStreamEnabled 0x2022U 151 #define PTP_RC_InvalidDataSet 0x2023U 152 153 154 /* USB container types */ 155 #define PTP_USB_CONTAINER_UNDEFINED 0x0000U 156 #define PTP_USB_CONTAINER_COMMAND 0x0001U 157 #define PTP_USB_CONTAINER_DATA 0x0002U 158 #define PTP_USB_CONTAINER_RESPONSE 0x0003U 159 #define PTP_USB_CONTAINER_EVENT 0x0004U 160 161 162 /* Transaction data phase description */ 163 #define PTP_DP_NODATA 0x0000U // no data phase 164 #define PTP_DP_SENDDATA 0x0001U // sending data 165 #define PTP_DP_GETDATA 0x0002U // receiving data 166 #define PTP_DP_DATA_MASK 0x00ffU // data phase mask 167 168 169 /* DeviceInfo data offset */ 170 #define PTP_di_StandardVersion 0U 171 #define PTP_di_VendorExtensionID 2U 172 #define PTP_di_VendorExtensionVersion 6U 173 #define PTP_di_VendorExtensionDesc 8U 174 #define PTP_di_FunctionalMode 8U 175 #define PTP_di_OperationsSupported 10U 176 177 /* Max info items size */ 178 #define PTP_SUPPORTED_OPERATIONS_NBR 100U 179 #define PTP_SUPPORTED_EVENTS_NBR 100U 180 #define PTP_SUPPORTED_PROPRIETIES_NBR 100U 181 #define PTP_CAPTURE_FORMATS_NBR 100U 182 #define PTP_IMAGE_FORMATS_NBR 100U 183 #define PTP_MAX_STR_SIZE 255U 184 185 /* PTP device info structure */ 186 typedef struct { 187 uint16_t StandardVersion; 188 uint32_t VendorExtensionID; 189 uint16_t VendorExtensionVersion; 190 uint8_t VendorExtensionDesc[PTP_MAX_STR_SIZE]; 191 uint16_t FunctionalMode; 192 uint32_t OperationsSupportedNbr; 193 uint16_t OperationsSupported[PTP_SUPPORTED_OPERATIONS_NBR]; 194 uint32_t EventsSupportedNbr; 195 uint16_t EventsSupported[PTP_SUPPORTED_EVENTS_NBR]; 196 uint32_t DevicePropertiesSupportedNbr; 197 uint16_t DevicePropertiesSupported[PTP_SUPPORTED_PROPRIETIES_NBR]; 198 uint32_t CaptureFormatsNbr; 199 uint16_t CaptureFormats[PTP_CAPTURE_FORMATS_NBR]; 200 uint32_t ImageFormatsNbr; 201 uint16_t ImageFormats[PTP_IMAGE_FORMATS_NBR]; 202 uint8_t Manufacturer[PTP_MAX_STR_SIZE]; 203 uint8_t Model[PTP_MAX_STR_SIZE]; 204 uint8_t DeviceVersion[PTP_MAX_STR_SIZE]; 205 uint8_t SerialNumber[PTP_MAX_STR_SIZE]; 206 } PTP_DeviceInfo_t; 207 208 209 #define PTP_MAX_STORAGE_UNITS_NBR 3 210 211 /* PTP storageIDs structute (returned by GetStorageIDs) */ 212 typedef struct { 213 uint32_t n; 214 uint32_t Storage[PTP_MAX_STORAGE_UNITS_NBR]; 215 } PTP_StorageIDs_t; 216 217 218 /* PTP StorageInfo structure (returned by GetStorageInfo) */ 219 #define PTP_si_StorageType 0U 220 #define PTP_si_FilesystemType 2U 221 #define PTP_si_AccessCapability 4U 222 #define PTP_si_MaxCapability 6U 223 #define PTP_si_FreeSpaceInBytes 14U 224 #define PTP_si_FreeSpaceInImages 22U 225 #define PTP_si_StorageDescription 26U 226 227 /* PTP Storage Types */ 228 #define PTP_ST_Undefined 0x0000U 229 #define PTP_ST_FixedROM 0x0001U 230 #define PTP_ST_RemovableROM 0x0002U 231 #define PTP_ST_FixedRAM 0x0003U 232 #define PTP_ST_RemovableRAM 0x0004U 233 234 /* PTP FilesystemType Values */ 235 #define PTP_FST_Undefined 0x0000U 236 #define PTP_FST_GenericFlat 0x0001U 237 #define PTP_FST_GenericHierarchical 0x0002U 238 #define PTP_FST_DCF 0x0003U 239 240 /* PTP StorageInfo AccessCapability Values */ 241 #define PTP_AC_ReadWrite 0x0000U 242 #define PTP_AC_ReadOnly 0x0001U 243 #define PTP_AC_ReadOnly_with_Object_Deletion 0x0002U 244 245 typedef struct { 246 uint16_t StorageType; 247 uint16_t FilesystemType; 248 uint16_t AccessCapability; 249 uint64_t MaxCapability; 250 uint64_t FreeSpaceInBytes; 251 uint32_t FreeSpaceInImages; 252 uint8_t StorageDescription[PTP_MAX_STR_SIZE]; 253 uint8_t VolumeLabel[PTP_MAX_STR_SIZE]; 254 } PTP_StorageInfo_t; 255 256 257 /* PTP Object Format Codes */ 258 /* ancillary formats */ 259 #define PTP_OFC_Undefined 0x3000U 260 #define PTP_OFC_Defined 0x3800U 261 #define PTP_OFC_Association 0x3001U 262 #define PTP_OFC_Script 0x3002U 263 #define PTP_OFC_Executable 0x3003U 264 #define PTP_OFC_Text 0x3004U 265 #define PTP_OFC_HTML 0x3005U 266 #define PTP_OFC_DPOF 0x3006U 267 #define PTP_OFC_AIFF 0x3007U 268 #define PTP_OFC_WAV 0x3008U 269 #define PTP_OFC_MP3 0x3009U 270 #define PTP_OFC_AVI 0x300AU 271 #define PTP_OFC_MPEG 0x300BU 272 #define PTP_OFC_ASF 0x300CU 273 #define PTP_OFC_QT 0x300DU /* guessing */ 274 /* image formats */ 275 #define PTP_OFC_EXIF_JPEG 0x3801U 276 #define PTP_OFC_TIFF_EP 0x3802U 277 #define PTP_OFC_FlashPix 0x3803U 278 #define PTP_OFC_BMP 0x3804U 279 #define PTP_OFC_CIFF 0x3805U 280 #define PTP_OFC_Undefined_0x3806 0x3806U 281 #define PTP_OFC_GIF 0x3807U 282 #define PTP_OFC_JFIF 0x3808U 283 #define PTP_OFC_PCD 0x3809U 284 #define PTP_OFC_PICT 0x380AU 285 #define PTP_OFC_PNG 0x380BU 286 #define PTP_OFC_Undefined_0x380C 0x380CU 287 #define PTP_OFC_TIFF 0x380DU 288 #define PTP_OFC_TIFF_IT 0x380EU 289 #define PTP_OFC_JP2 0x380FU 290 #define PTP_OFC_JPX 0x3810U 291 /* ptp v1.1 has only DNG new */ 292 #define PTP_OFC_DNG 0x3811U 293 294 /* MTP extensions */ 295 #define PTP_OFC_MTP_MediaCard 0xb211U 296 #define PTP_OFC_MTP_MediaCardGroup 0xb212U 297 #define PTP_OFC_MTP_Encounter 0xb213U 298 #define PTP_OFC_MTP_EncounterBox 0xb214U 299 #define PTP_OFC_MTP_M4A 0xb215U 300 #define PTP_OFC_MTP_ZUNEUNDEFINED 0xb217U/* Unknown file type */ 301 #define PTP_OFC_MTP_Firmware 0xb802U 302 #define PTP_OFC_MTP_WindowsImageFormat 0xb881U 303 #define PTP_OFC_MTP_UndefinedAudio 0xb900U 304 #define PTP_OFC_MTP_WMA 0xb901U 305 #define PTP_OFC_MTP_OGG 0xb902U 306 #define PTP_OFC_MTP_AAC 0xb903U 307 #define PTP_OFC_MTP_AudibleCod 0xb904U 308 #define PTP_OFC_MTP_FLAC 0xb906U 309 #define PTP_OFC_MTP_SamsungPlaylist 0xb909U 310 #define PTP_OFC_MTP_UndefinedVideo 0xb980U 311 #define PTP_OFC_MTP_WMV 0xb981U 312 #define PTP_OFC_MTP_MP4 0xb982U 313 #define PTP_OFC_MTP_MP2 0xb983U 314 #define PTP_OFC_MTP_3GP 0xb984U 315 #define PTP_OFC_MTP_UndefinedCollection 0xba00U 316 #define PTP_OFC_MTP_AbstractMultimediaAlbum 0xba01U 317 #define PTP_OFC_MTP_AbstractImageAlbum 0xba02U 318 #define PTP_OFC_MTP_AbstractAudioAlbum 0xba03U 319 #define PTP_OFC_MTP_AbstractVideoAlbum 0xba04U 320 #define PTP_OFC_MTP_AbstractAudioVideoPlaylist 0xba05U 321 #define PTP_OFC_MTP_AbstractContactGroup 0xba06U 322 #define PTP_OFC_MTP_AbstractMessageFolder 0xba07U 323 #define PTP_OFC_MTP_AbstractChapteredProduction 0xba08U 324 #define PTP_OFC_MTP_AbstractAudioPlaylist 0xba09U 325 #define PTP_OFC_MTP_AbstractVideoPlaylist 0xba0aU 326 #define PTP_OFC_MTP_AbstractMediacast 0xba0bU 327 #define PTP_OFC_MTP_WPLPlaylist 0xba10U 328 #define PTP_OFC_MTP_M3UPlaylist 0xba11U 329 #define PTP_OFC_MTP_MPLPlaylist 0xba12U 330 #define PTP_OFC_MTP_ASXPlaylist 0xba13U 331 #define PTP_OFC_MTP_PLSPlaylist 0xba14U 332 #define PTP_OFC_MTP_UndefinedDocument 0xba80U 333 #define PTP_OFC_MTP_AbstractDocument 0xba81U 334 #define PTP_OFC_MTP_XMLDocument 0xba82U 335 #define PTP_OFC_MTP_MSWordDocument 0xba83U 336 #define PTP_OFC_MTP_MHTCompiledHTMLDocument 0xba84U 337 #define PTP_OFC_MTP_MSExcelSpreadsheetXLS 0xba85U 338 #define PTP_OFC_MTP_MSPowerpointPresentationPPT 0xba86U 339 #define PTP_OFC_MTP_UndefinedMessage 0xbb00U 340 #define PTP_OFC_MTP_AbstractMessage 0xbb01U 341 #define PTP_OFC_MTP_UndefinedContact 0xbb80U 342 #define PTP_OFC_MTP_AbstractContact 0xbb81U 343 #define PTP_OFC_MTP_vCard2 0xbb82U 344 #define PTP_OFC_MTP_vCard3 0xbb83U 345 #define PTP_OFC_MTP_UndefinedCalendarItem 0xbe00U 346 #define PTP_OFC_MTP_AbstractCalendarItem 0xbe01U 347 #define PTP_OFC_MTP_vCalendar1 0xbe02U 348 #define PTP_OFC_MTP_vCalendar2 0xbe03U 349 #define PTP_OFC_MTP_UndefinedWindowsExecutable 0xbe80U 350 #define PTP_OFC_MTP_MediaCast 0xbe81U 351 #define PTP_OFC_MTP_Section 0xbe82U 352 353 /* MTP specific Object Properties */ 354 #define PTP_OPC_StorageID 0xDC01U 355 #define PTP_OPC_ObjectFormat 0xDC02U 356 #define PTP_OPC_ProtectionStatus 0xDC03U 357 #define PTP_OPC_ObjectSize 0xDC04U 358 #define PTP_OPC_AssociationType 0xDC05U 359 #define PTP_OPC_AssociationDesc 0xDC06U 360 #define PTP_OPC_ObjectFileName 0xDC07U 361 #define PTP_OPC_DateCreated 0xDC08U 362 #define PTP_OPC_DateModified 0xDC09U 363 #define PTP_OPC_Keywords 0xDC0AU 364 #define PTP_OPC_ParentObject 0xDC0BU 365 #define PTP_OPC_AllowedFolderContents 0xDC0CU 366 #define PTP_OPC_Hidden 0xDC0DU 367 #define PTP_OPC_SystemObject 0xDC0EU 368 #define PTP_OPC_PersistantUniqueObjectIdentifier 0xDC41U 369 #define PTP_OPC_SyncID 0xDC42U 370 #define PTP_OPC_PropertyBag 0xDC43U 371 #define PTP_OPC_Name 0xDC44U 372 #define PTP_OPC_CreatedBy 0xDC45U 373 #define PTP_OPC_Artist 0xDC46U 374 #define PTP_OPC_DateAuthored 0xDC47U 375 #define PTP_OPC_Description 0xDC48U 376 #define PTP_OPC_URLReference 0xDC49U 377 #define PTP_OPC_LanguageLocale 0xDC4AU 378 #define PTP_OPC_CopyrightInformation 0xDC4BU 379 #define PTP_OPC_Source 0xDC4CU 380 #define PTP_OPC_OriginLocation 0xDC4DU 381 #define PTP_OPC_DateAdded 0xDC4EU 382 #define PTP_OPC_NonConsumable 0xDC4FU 383 #define PTP_OPC_CorruptOrUnplayable 0xDC50U 384 #define PTP_OPC_ProducerSerialNumber 0xDC51U 385 #define PTP_OPC_RepresentativeSampleFormat 0xDC81U 386 #define PTP_OPC_RepresentativeSampleSize 0xDC82U 387 #define PTP_OPC_RepresentativeSampleHeight 0xDC83U 388 #define PTP_OPC_RepresentativeSampleWidth 0xDC84U 389 #define PTP_OPC_RepresentativeSampleDuration 0xDC85U 390 #define PTP_OPC_RepresentativeSampleData 0xDC86U 391 #define PTP_OPC_Width 0xDC87U 392 #define PTP_OPC_Height 0xDC88U 393 #define PTP_OPC_Duration 0xDC89U 394 #define PTP_OPC_Rating 0xDC8AU 395 #define PTP_OPC_Track 0xDC8BU 396 #define PTP_OPC_Genre 0xDC8CU 397 #define PTP_OPC_Credits 0xDC8DU 398 #define PTP_OPC_Lyrics 0xDC8EU 399 #define PTP_OPC_SubscriptionContentID 0xDC8FU 400 #define PTP_OPC_ProducedBy 0xDC90U 401 #define PTP_OPC_UseCount 0xDC91U 402 #define PTP_OPC_SkipCount 0xDC92U 403 #define PTP_OPC_LastAccessed 0xDC93U 404 #define PTP_OPC_ParentalRating 0xDC94U 405 #define PTP_OPC_MetaGenre 0xDC95U 406 #define PTP_OPC_Composer 0xDC96U 407 #define PTP_OPC_EffectiveRating 0xDC97U 408 #define PTP_OPC_Subtitle 0xDC98U 409 #define PTP_OPC_OriginalReleaseDate 0xDC99U 410 #define PTP_OPC_AlbumName 0xDC9AU 411 #define PTP_OPC_AlbumArtist 0xDC9BU 412 #define PTP_OPC_Mood 0xDC9CU 413 #define PTP_OPC_DRMStatus 0xDC9DU 414 #define PTP_OPC_SubDescription 0xDC9EU 415 #define PTP_OPC_IsCropped 0xDCD1U 416 #define PTP_OPC_IsColorCorrected 0xDCD2U 417 #define PTP_OPC_ImageBitDepth 0xDCD3U 418 #define PTP_OPC_Fnumber 0xDCD4U 419 #define PTP_OPC_ExposureTime 0xDCD5U 420 #define PTP_OPC_ExposureIndex 0xDCD6U 421 #define PTP_OPC_DisplayName 0xDCE0U 422 #define PTP_OPC_BodyText 0xDCE1U 423 #define PTP_OPC_Subject 0xDCE2U 424 #define PTP_OPC_Priority 0xDCE3U 425 #define PTP_OPC_GivenName 0xDD00U 426 #define PTP_OPC_MiddleNames 0xDD01U 427 #define PTP_OPC_FamilyName 0xDD02U 428 #define PTP_OPC_Prefix 0xDD03U 429 #define PTP_OPC_Suffix 0xDD04U 430 #define PTP_OPC_PhoneticGivenName 0xDD05U 431 #define PTP_OPC_PhoneticFamilyName 0xDD06U 432 #define PTP_OPC_EmailPrimary 0xDD07U 433 #define PTP_OPC_EmailPersonal1 0xDD08U 434 #define PTP_OPC_EmailPersonal2 0xDD09U 435 #define PTP_OPC_EmailBusiness1 0xDD0AU 436 #define PTP_OPC_EmailBusiness2 0xDD0BU 437 #define PTP_OPC_EmailOthers 0xDD0CU 438 #define PTP_OPC_PhoneNumberPrimary 0xDD0DU 439 #define PTP_OPC_PhoneNumberPersonal 0xDD0EU 440 #define PTP_OPC_PhoneNumberPersonal2 0xDD0FU 441 #define PTP_OPC_PhoneNumberBusiness 0xDD10U 442 #define PTP_OPC_PhoneNumberBusiness2 0xDD11U 443 #define PTP_OPC_PhoneNumberMobile 0xDD12U 444 #define PTP_OPC_PhoneNumberMobile2 0xDD13U 445 #define PTP_OPC_FaxNumberPrimary 0xDD14U 446 #define PTP_OPC_FaxNumberPersonal 0xDD15U 447 #define PTP_OPC_FaxNumberBusiness 0xDD16U 448 #define PTP_OPC_PagerNumber 0xDD17U 449 #define PTP_OPC_PhoneNumberOthers 0xDD18U 450 #define PTP_OPC_PrimaryWebAddress 0xDD19U 451 #define PTP_OPC_PersonalWebAddress 0xDD1AU 452 #define PTP_OPC_BusinessWebAddress 0xDD1BU 453 #define PTP_OPC_InstantMessengerAddress 0xDD1CU 454 #define PTP_OPC_InstantMessengerAddress2 0xDD1DU 455 #define PTP_OPC_InstantMessengerAddress3 0xDD1EU 456 #define PTP_OPC_PostalAddressPersonalFull 0xDD1FU 457 #define PTP_OPC_PostalAddressPersonalFullLine1 0xDD20U 458 #define PTP_OPC_PostalAddressPersonalFullLine2 0xDD21U 459 #define PTP_OPC_PostalAddressPersonalFullCity 0xDD22U 460 #define PTP_OPC_PostalAddressPersonalFullRegion 0xDD23U 461 #define PTP_OPC_PostalAddressPersonalFullPostalCode 0xDD24U 462 #define PTP_OPC_PostalAddressPersonalFullCountry 0xDD25U 463 #define PTP_OPC_PostalAddressBusinessFull 0xDD26U 464 #define PTP_OPC_PostalAddressBusinessLine1 0xDD27U 465 #define PTP_OPC_PostalAddressBusinessLine2 0xDD28U 466 #define PTP_OPC_PostalAddressBusinessCity 0xDD29U 467 #define PTP_OPC_PostalAddressBusinessRegion 0xDD2AU 468 #define PTP_OPC_PostalAddressBusinessPostalCode 0xDD2BU 469 #define PTP_OPC_PostalAddressBusinessCountry 0xDD2CU 470 #define PTP_OPC_PostalAddressOtherFull 0xDD2DU 471 #define PTP_OPC_PostalAddressOtherLine1 0xDD2EU 472 #define PTP_OPC_PostalAddressOtherLine2 0xDD2FU 473 #define PTP_OPC_PostalAddressOtherCity 0xDD30U 474 #define PTP_OPC_PostalAddressOtherRegion 0xDD31U 475 #define PTP_OPC_PostalAddressOtherPostalCode 0xDD32U 476 #define PTP_OPC_PostalAddressOtherCountry 0xDD33U 477 #define PTP_OPC_OrganizationName 0xDD34U 478 #define PTP_OPC_PhoneticOrganizationName 0xDD35U 479 #define PTP_OPC_Role 0xDD36U 480 #define PTP_OPC_Birthdate 0xDD37U 481 #define PTP_OPC_MessageTo 0xDD40U 482 #define PTP_OPC_MessageCC 0xDD41U 483 #define PTP_OPC_MessageBCC 0xDD42U 484 #define PTP_OPC_MessageRead 0xDD43U 485 #define PTP_OPC_MessageReceivedTime 0xDD44U 486 #define PTP_OPC_MessageSender 0xDD45U 487 #define PTP_OPC_ActivityBeginTime 0xDD50U 488 #define PTP_OPC_ActivityEndTime 0xDD51U 489 #define PTP_OPC_ActivityLocation 0xDD52U 490 #define PTP_OPC_ActivityRequiredAttendees 0xDD54U 491 #define PTP_OPC_ActivityOptionalAttendees 0xDD55U 492 #define PTP_OPC_ActivityResources 0xDD56U 493 #define PTP_OPC_ActivityAccepted 0xDD57U 494 #define PTP_OPC_Owner 0xDD5DU 495 #define PTP_OPC_Editor 0xDD5EU 496 #define PTP_OPC_Webmaster 0xDD5FU 497 #define PTP_OPC_URLSource 0xDD60U 498 #define PTP_OPC_URLDestination 0xDD61U 499 #define PTP_OPC_TimeBookmark 0xDD62U 500 #define PTP_OPC_ObjectBookmark 0xDD63U 501 #define PTP_OPC_ByteBookmark 0xDD64U 502 #define PTP_OPC_LastBuildDate 0xDD70U 503 #define PTP_OPC_TimetoLive 0xDD71U 504 #define PTP_OPC_MediaGUID 0xDD72U 505 #define PTP_OPC_TotalBitRate 0xDE91U 506 #define PTP_OPC_BitRateType 0xDE92U 507 #define PTP_OPC_SampleRate 0xDE93U 508 #define PTP_OPC_NumberOfChannels 0xDE94U 509 #define PTP_OPC_AudioBitDepth 0xDE95U 510 #define PTP_OPC_ScanDepth 0xDE97U 511 #define PTP_OPC_AudioWAVECodec 0xDE99U 512 #define PTP_OPC_AudioBitRate 0xDE9AU 513 #define PTP_OPC_VideoFourCCCodec 0xDE9BU 514 #define PTP_OPC_VideoBitRate 0xDE9CU 515 #define PTP_OPC_FramesPerThousandSeconds 0xDE9DU 516 #define PTP_OPC_KeyFrameDistance 0xDE9EU 517 #define PTP_OPC_BufferSize 0xDE9FU 518 #define PTP_OPC_EncodingQuality 0xDEA0U 519 #define PTP_OPC_EncodingProfile 0xDEA1U 520 #define PTP_OPC_BuyFlag 0xD901U 521 522 /* WiFi Provisioning MTP Extension property codes */ 523 #define PTP_OPC_WirelessConfigurationFile 0xB104U 524 525 526 /* PTP Association Types */ 527 #define PTP_AT_Undefined 0x0000U 528 #define PTP_AT_GenericFolder 0x0001U 529 #define PTP_AT_Album 0x0002U 530 #define PTP_AT_TimeSequence 0x0003U 531 #define PTP_AT_HorizontalPanoramic 0x0004U 532 #define PTP_AT_VerticalPanoramic 0x0005U 533 #define PTP_AT_2DPanoramic 0x0006U 534 #define PTP_AT_AncillaryData 0x0007U 535 536 537 #define PTP_MAX_HANDLER_NBR 0x255U 538 539 typedef struct { 540 uint32_t n; 541 uint32_t Handler[PTP_MAX_HANDLER_NBR]; 542 } PTP_ObjectHandles_t; 543 544 545 #define PTP_oi_StorageID 0U 546 #define PTP_oi_ObjectFormat 4U 547 #define PTP_oi_ProtectionStatus 6U 548 #define PTP_oi_ObjectCompressedSize 8U 549 #define PTP_oi_ThumbFormat 12U 550 #define PTP_oi_ThumbCompressedSize 14U 551 #define PTP_oi_ThumbPixWidth 18U 552 #define PTP_oi_ThumbPixHeight 22U 553 #define PTP_oi_ImagePixWidth 26U 554 #define PTP_oi_ImagePixHeight 30U 555 #define PTP_oi_ImageBitDepth 34U 556 #define PTP_oi_ParentObject 38U 557 #define PTP_oi_AssociationType 42U 558 #define PTP_oi_AssociationDesc 44U 559 #define PTP_oi_SequenceNumber 48U 560 #define PTP_oi_filenamelen 52U 561 #define PTP_oi_Filename 53U 562 563 typedef struct { 564 uint32_t StorageID; 565 uint16_t ObjectFormat; 566 uint16_t ProtectionStatus; 567 /* In the regular objectinfo this is 32bit, but we keep the general object size here 568 that also arrives via other methods and so use 64bit */ 569 uint64_t ObjectCompressedSize; 570 uint16_t ThumbFormat; 571 uint32_t ThumbCompressedSize; 572 uint32_t ThumbPixWidth; 573 uint32_t ThumbPixHeight; 574 uint32_t ImagePixWidth; 575 uint32_t ImagePixHeight; 576 uint32_t ImageBitDepth; 577 uint32_t ParentObject; 578 uint16_t AssociationType; 579 uint32_t AssociationDesc; 580 uint32_t SequenceNumber; 581 uint8_t Filename[PTP_MAX_STR_SIZE]; 582 uint32_t CaptureDate; 583 uint32_t ModificationDate; 584 uint8_t Keywords[PTP_MAX_STR_SIZE]; 585 } PTP_ObjectInfo_t; 586 587 588 /* Object Property Describing Dataset (DevicePropDesc) */ 589 typedef union _PTP_PropertyValue_t { 590 char str[PTP_MAX_STR_SIZE]; 591 uint8_t u8; 592 int8_t i8; 593 uint16_t u16; 594 int16_t i16; 595 uint32_t u32; 596 int32_t i32; 597 uint64_t u64; 598 int64_t i64; 599 struct array 600 { 601 uint32_t count; 602 union _PTP_PropertyValue_t *v; 603 } a; 604 } PTP_PropertyValue_t; 605 606 typedef struct { 607 PTP_PropertyValue_t MinimumValue; 608 PTP_PropertyValue_t MaximumValue; 609 PTP_PropertyValue_t StepSize; 610 } PTP_PropDescRangeForm_t; 611 612 /* Property Describing Dataset, Enum Form */ 613 typedef struct { 614 uint16_t NumberOfValues; 615 PTP_PropertyValue_t SupportedValue[PTP_SUPPORTED_PROPRIETIES_NBR]; 616 } PTP_PropDescEnumForm_t; 617 618 619 /* (MTP) Object Property pack/unpack */ 620 #define PTP_opd_ObjectPropertyCode 0U 621 #define PTP_opd_DataType 2U 622 #define PTP_opd_GetSet 4U 623 #define PTP_opd_FactoryDefaultValue 5U 624 625 typedef struct { 626 uint16_t ObjectPropertyCode; 627 uint16_t DataType; 628 uint8_t GetSet; 629 PTP_PropertyValue_t FactoryDefaultValue; 630 uint32_t GroupCode; 631 uint8_t FormFlag; 632 union 633 { 634 PTP_PropDescEnumForm_t Enum; 635 PTP_PropDescRangeForm_t Range; 636 } FORM; 637 } PTP_ObjectPropDesc_t; 638 639 640 /* Metadata lists for MTP operations */ 641 typedef struct { 642 uint16_t property; 643 uint16_t datatype; 644 uint32_t ObjectHandle; 645 PTP_PropertyValue_t propval; 646 } MTP_Properties_t; 647 648 649 /* Device Property Form Flag */ 650 #define PTP_DPFF_None 0x00U 651 #define PTP_DPFF_Range 0x01U 652 #define PTP_DPFF_Enumeration 0x02U 653 654 /* Object Property Codes used by MTP (first 3 are same as DPFF codes) */ 655 #define PTP_OPFF_None 0x00U 656 #define PTP_OPFF_Range 0x01U 657 #define PTP_OPFF_Enumeration 0x02U 658 #define PTP_OPFF_DateTime 0x03U 659 #define PTP_OPFF_FixedLengthArray 0x04U 660 #define PTP_OPFF_RegularExpression 0x05U 661 #define PTP_OPFF_ByteArray 0x06U 662 #define PTP_OPFF_LongString 0xFFU 663 664 665 /* Device Property pack/unpack */ 666 #define PTP_dpd_DevicePropertyCode 0U 667 #define PTP_dpd_DataType 2U 668 #define PTP_dpd_GetSet 4U 669 #define PTP_dpd_FactoryDefaultValue 5U 670 671 /* Device Property Describing Dataset (DevicePropDesc) */ 672 typedef struct 673 { 674 uint16_t DevicePropertyCode; 675 uint16_t DataType; 676 uint8_t GetSet; 677 PTP_PropertyValue_t FactoryDefaultValue; 678 PTP_PropertyValue_t CurrentValue; 679 uint8_t FormFlag; 680 union 681 { 682 PTP_PropDescEnumForm_t Enum; 683 PTP_PropDescRangeForm_t Range; 684 } FORM; 685 } PTP_DevicePropDesc_t; 686 687 688 /* DataType Codes */ 689 #define PTP_DTC_UNDEF 0x0000U 690 #define PTP_DTC_INT8 0x0001U 691 #define PTP_DTC_UINT8 0x0002U 692 #define PTP_DTC_INT16 0x0003U 693 #define PTP_DTC_UINT16 0x0004U 694 #define PTP_DTC_INT32 0x0005U 695 #define PTP_DTC_UINT32 0x0006U 696 #define PTP_DTC_INT64 0x0007U 697 #define PTP_DTC_UINT64 0x0008U 698 #define PTP_DTC_INT128 0x0009U 699 #define PTP_DTC_UINT128 0x000AU 700 701 #define PTP_DTC_ARRAY_MASK 0x4000U 702 703 #define PTP_DTC_AINT8 (PTP_DTC_ARRAY_MASK | PTP_DTC_INT8) 704 #define PTP_DTC_AUINT8 (PTP_DTC_ARRAY_MASK | PTP_DTC_UINT8) 705 #define PTP_DTC_AINT16 (PTP_DTC_ARRAY_MASK | PTP_DTC_INT16) 706 #define PTP_DTC_AUINT16 (PTP_DTC_ARRAY_MASK | PTP_DTC_UINT16) 707 #define PTP_DTC_AINT32 (PTP_DTC_ARRAY_MASK | PTP_DTC_INT32) 708 #define PTP_DTC_AUINT32 (PTP_DTC_ARRAY_MASK | PTP_DTC_UINT32) 709 #define PTP_DTC_AINT64 (PTP_DTC_ARRAY_MASK | PTP_DTC_INT64) 710 #define PTP_DTC_AUINT64 (PTP_DTC_ARRAY_MASK | PTP_DTC_UINT64) 711 #define PTP_DTC_AINT128 (PTP_DTC_ARRAY_MASK | PTP_DTC_INT128) 712 #define PTP_DTC_AUINT128 (PTP_DTC_ARRAY_MASK | PTP_DTC_UINT128) 713 714 #define PTP_DTC_STR 0xFFFFU 715 716 717 /* PTP Event Codes */ 718 #define PTP_EC_Undefined 0x4000U 719 #define PTP_EC_CancelTransaction 0x4001U 720 #define PTP_EC_ObjectAdded 0x4002U 721 #define PTP_EC_ObjectRemoved 0x4003U 722 #define PTP_EC_StoreAdded 0x4004U 723 #define PTP_EC_StoreRemoved 0x4005U 724 #define PTP_EC_DevicePropChanged 0x4006U 725 #define PTP_EC_ObjectInfoChanged 0x4007U 726 #define PTP_EC_DeviceInfoChanged 0x4008U 727 #define PTP_EC_RequestObjectTransfer 0x4009U 728 #define PTP_EC_StoreFull 0x400AU 729 #define PTP_EC_DeviceReset 0x400BU 730 #define PTP_EC_StorageInfoChanged 0x400CU 731 #define PTP_EC_CaptureComplete 0x400DU 732 #define PTP_EC_UnreportedStatus 0x400EU 733 734 735 void PTP_GetDevicePropValue(USBH_Info_t *phost, uint32_t *offset, uint32_t total, PTP_PropertyValue_t *value, uint16_t datatype); 736 737 void PTP_GetString(uint8_t *str, uint8_t *data, uint16_t *len); 738 739 uint32_t PTP_GetArray16(uint16_t *array, uint8_t *data, uint32_t offset); 740 uint32_t PTP_GetArray32(uint32_t *array, uint8_t *data, uint32_t offset); 741 742 void PTP_DecodeDeviceInfo(USBH_Info_t *phost, PTP_DeviceInfo_t *dev_info); 743 744 void PTP_DecodeStorageInfo(USBH_Info_t *phost, PTP_StorageInfo_t *storage_info); 745 746 void PTP_DecodeObjectInfo(USBH_Info_t *phost, PTP_ObjectInfo_t *object_info); 747 748 void PTP_DecodeObjectPropDesc(USBH_Info_t *phost, PTP_ObjectPropDesc_t *opd, uint32_t opdlen); 749 750 uint32_t PTP_DecodeObjectPropList(USBH_Info_t *phost, MTP_Properties_t *props, uint32_t len); 751 752 753 #define PTP_LE16(addr) *((uint16_t *)(addr)) 754 #define PTP_LE32(addr) *((uint32_t *)(addr)) 755 #define PTP_LE64(addr) *((uint64_t *)(addr)) 756 757 758 #endif // __USBH_MTP_PTP_H__ 759